495 AppendPDFObject(
"%PDF-1.5\n%\xDE\xAD\xBE\xEB\n");
498 AppendPDFObject(
"1 0 obj\n"
510 AppendPDFObject(
"3 0 obj\n"
512 " /BaseFont /GlyphLessFont\n"
513 " /DescendantFonts [ 4 0 R ]\n"
514 " /Encoding /Identity-H\n"
516 " /ToUnicode 6 0 R\n"
522 std::stringstream stream;
524 stream.imbue(std::locale::classic());
528 " /BaseFont /GlyphLessFont\n"
529 " /CIDToGIDMap 5 0 R\n"
532 " /Ordering (Identity)\n"
533 " /Registry (Adobe)\n"
536 " /FontDescriptor 7 0 R\n"
537 " /Subtype /CIDFontType2\n"
539 " /DW " << (1000 / kCharWidth) <<
"\n"
542 AppendPDFObject(stream.str().c_str());
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;
552 unsigned char *comp = zlibCompress(cidtogidmap.get(), kCIDToGIDMapSize, &len);
557 " /Length " << len <<
" /Filter /FlateDecode\n"
561 long objsize = stream.str().size();
562 AppendData(reinterpret_cast<char *>(comp), len);
565 const char *endstream_endobj =
569 objsize += strlen(endstream_endobj);
570 AppendPDFObjectDIY(objsize);
572 const char stream2[] =
573 "/CIDInit /ProcSet findresource begin\n"
578 " /Registry (Adobe)\n"
582 "/CMapName /Adobe-Identify-UCS def\n"
584 "1 begincodespacerange\n"
586 "endcodespacerange\n"
588 "<0000> <FFFF> <0000>\n"
591 "CMapName currentdict /CMap defineresource pop\n"
599 "<< /Length " << (
sizeof(stream2) - 1) <<
" >>\n"
600 "stream\n" << stream2 <<
603 AppendPDFObject(stream.str().c_str());
614 " /FontBBox [ 0 0 " << (1000 / kCharWidth) <<
" 1000 ]\n"
615 " /FontFile2 8 0 R\n"
616 " /FontName /GlyphLessFont\n"
619 " /Type /FontDescriptor\n"
622 AppendPDFObject(stream.str().c_str());
625 stream << datadir_.c_str() <<
"/pdf.ttf";
626 FILE *fp = fopen(stream.str().c_str(),
"rb");
628 tprintf(
"Cannot open file \"%s\"!\n", stream.str().c_str());
631 fseek(fp, 0, SEEK_END);
632 auto size = std::ftell(fp);
637 fseek(fp, 0, SEEK_SET);
638 const std::unique_ptr<char[]> buffer(
new char[size]);
649 " /Length " << size <<
"\n"
650 " /Length1 " << size <<
"\n"
654 objsize = stream.str().size();
658 objsize += strlen(endstream_endobj);
659 AppendPDFObjectDIY(objsize);