494 {
495 AppendPDFObject("%PDF-1.5\n%\xDE\xAD\xBE\xEB\n");
496
497
498 AppendPDFObject("1 0 obj\n"
499 "<<\n"
500 " /Type /Catalog\n"
501 " /Pages 2 0 R\n"
502 ">>\nendobj\n");
503
504
505
506
507 AppendPDFObject("");
508
509
510 AppendPDFObject("3 0 obj\n"
511 "<<\n"
512 " /BaseFont /GlyphLessFont\n"
513 " /DescendantFonts [ 4 0 R ]\n"
514 " /Encoding /Identity-H\n"
515 " /Subtype /Type0\n"
516 " /ToUnicode 6 0 R\n"
517 " /Type /Font\n"
518 ">>\n"
519 "endobj\n");
520
521
522 std::stringstream stream;
523
524 stream.imbue(std::locale::classic());
525 stream <<
526 "4 0 obj\n"
527 "<<\n"
528 " /BaseFont /GlyphLessFont\n"
529 " /CIDToGIDMap 5 0 R\n"
530 " /CIDSystemInfo\n"
531 " <<\n"
532 " /Ordering (Identity)\n"
533 " /Registry (Adobe)\n"
534 " /Supplement 0\n"
535 " >>\n"
536 " /FontDescriptor 7 0 R\n"
537 " /Subtype /CIDFontType2\n"
538 " /Type /Font\n"
539 " /DW " << (1000 / kCharWidth) << "\n"
540 ">>\n"
541 "endobj\n";
542 AppendPDFObject(stream.str().c_str());
543
544
545 const int kCIDToGIDMapSize = 2 * (1 << 16);
546 const std::unique_ptr<unsigned char[]> cidtogidmap(
547 new unsigned char[kCIDToGIDMapSize]);
548 for (int i = 0; i < kCIDToGIDMapSize; i++) {
549 cidtogidmap[i] = (i % 2) ? 1 : 0;
550 }
551 size_t len;
552 unsigned char *comp = zlibCompress(cidtogidmap.get(), kCIDToGIDMapSize, &len);
553 stream.str("");
554 stream <<
555 "5 0 obj\n"
556 "<<\n"
557 " /Length " << len << " /Filter /FlateDecode\n"
558 ">>\n"
559 "stream\n";
561 long objsize = stream.str().size();
562 AppendData(
reinterpret_cast<char *
>(comp), len);
563 objsize += len;
564 lept_free(comp);
565 const char *endstream_endobj =
566 "endstream\n"
567 "endobj\n";
569 objsize += strlen(endstream_endobj);
570 AppendPDFObjectDIY(objsize);
571
572 const char stream2[] =
573 "/CIDInit /ProcSet findresource begin\n"
574 "12 dict begin\n"
575 "begincmap\n"
576 "/CIDSystemInfo\n"
577 "<<\n"
578 " /Registry (Adobe)\n"
579 " /Ordering (UCS)\n"
580 " /Supplement 0\n"
581 ">> def\n"
582 "/CMapName /Adobe-Identify-UCS def\n"
583 "/CMapType 2 def\n"
584 "1 begincodespacerange\n"
585 "<0000> <FFFF>\n"
586 "endcodespacerange\n"
587 "1 beginbfrange\n"
588 "<0000> <FFFF> <0000>\n"
589 "endbfrange\n"
590 "endcmap\n"
591 "CMapName currentdict /CMap defineresource pop\n"
592 "end\n"
593 "end\n";
594
595
596 stream.str("");
597 stream <<
598 "6 0 obj\n"
599 "<< /Length " << (sizeof(stream2) - 1) << " >>\n"
600 "stream\n" << stream2 <<
601 "endstream\n"
602 "endobj\n";
603 AppendPDFObject(stream.str().c_str());
604
605
606 stream.str("");
607 stream <<
608 "7 0 obj\n"
609 "<<\n"
610 " /Ascent 1000\n"
611 " /CapHeight 1000\n"
612 " /Descent -1\n"
613 " /Flags 5\n"
614 " /FontBBox [ 0 0 " << (1000 / kCharWidth) << " 1000 ]\n"
615 " /FontFile2 8 0 R\n"
616 " /FontName /GlyphLessFont\n"
617 " /ItalicAngle 0\n"
618 " /StemV 80\n"
619 " /Type /FontDescriptor\n"
620 ">>\n"
621 "endobj\n";
622 AppendPDFObject(stream.str().c_str());
623
624 stream.str("");
625 stream << datadir_.c_str() << "/pdf.ttf";
626 FILE *fp = fopen(stream.str().c_str(), "rb");
627 if (!fp) {
628 tprintf(
"Cannot open file \"%s\"!\n", stream.str().c_str());
629 return false;
630 }
631 fseek(fp, 0, SEEK_END);
632 auto size = std::ftell(fp);
633 if (size < 0) {
634 fclose(fp);
635 return false;
636 }
637 fseek(fp, 0, SEEK_SET);
638 const std::unique_ptr<char[]> buffer(new char[size]);
640 fclose(fp);
641 return false;
642 }
643 fclose(fp);
644
645 stream.str("");
646 stream <<
647 "8 0 obj\n"
648 "<<\n"
649 " /Length " << size << "\n"
650 " /Length1 " << size << "\n"
651 ">>\n"
652 "stream\n";
654 objsize = stream.str().size();
656 objsize += size;
658 objsize += strlen(endstream_endobj);
659 AppendPDFObjectDIY(objsize);
660 return true;
661}
DLLSYM void tprintf(const char *format,...)
bool DeSerialize(FILE *fp, char *data, size_t n)