@@ -463,18 +463,31 @@ namespace pdflib
463463
464464 std::string pdf_resource<PAGE_FONT>::get_correct_character(uint32_t c)
465465 {
466- // sometimes , a font has differences-map and a cmap
466+ // Sometimes , a font has differences-map and a cmap
467467 // defined at the same time. So far, it seems that the
468468 // differences should take precedent over the cmap. This
469- // is however not really clear (eg p 292)
469+ // is however not really clear (eg p 292). Notice also that
470+ // we init the cmap before we init the difference and that the
471+ // difference inherits the content of a the cmap. It is a bit
472+ // messy and unclear her.
473+
474+ /*
475+ if(diff_numb_to_char.count(c)>0 and cmap_numb_to_char.count(c)>0)
476+ {
477+ LOG_S(WARNING) << "there might be some confusion here: "
478+ << "diff["<<c<<"]: " << diff_numb_to_char.at(c) << " "
479+ << "cmap["<<c<<"]: " << cmap_numb_to_char.at(c);
480+ }
481+ */
482+
470483 if (diff_initialized and diff_numb_to_char.count (c)>0 )
471484 {
472485 return diff_numb_to_char.at (c);
473486 }
474487 else if (cmap_initialized and cmap_numb_to_char.count (c)>0 )
475488 {
476489 return cmap_numb_to_char.at (c);
477- }
490+ }
478491 else if (bfonts.has_corresponding_font (font_name))
479492 {
480493 // check if the font-name is registered as a 'special' font, eg
@@ -878,6 +891,7 @@ namespace pdflib
878891 }
879892
880893
894+
881895 /*
882896 void pdf_resource<PAGE_FONT>::init_fontfile3()
883897 {
@@ -911,18 +925,35 @@ namespace pdflib
911925 auto buffer = qpdf_obj.getRawStreamData();
912926
913927 LOG_S(INFO) << "buffer-size: " << buffer->getSize();
914- LOG_S(INFO) << "buffer: " << buffer->getBuffer();
928+ //LOG_S(INFO) << "buffer: " << buffer->getBuffer();
929+
930+ std::string filename = "fontfile.zip";
931+ std::ofstream outFile(filename, std::ios::binary);
932+ if (!outFile) {
933+ LOG_S(ERROR) << "opening file for writing: " << filename << std::endl;
934+ return;
935+ }
936+
937+ outFile.write(reinterpret_cast<const char*>(buffer->getBuffer()), buffer->getSize());
938+ outFile.close();
939+
940+ if (!outFile) {
941+ LOG_S(ERROR) << "Error occurred while writing to the file: " << filename << std::endl;
942+ } else {
943+ LOG_S(INFO) << "Buffer successfully written to " << filename << std::endl;
944+ }
915945 }
916946
917947 {
918- auto buffer = qpdf_obj.getStreamData(qpdf_dl_generalized);
948+ auto buffer = qpdf_obj.getStreamData(qpdf_dl_generalized);
919949
920- LOG_S(INFO) << "buffer-size: " << buffer->getSize();
921- LOG_S(INFO) << "buffer: " << buffer->getBuffer();
950+ LOG_S(INFO) << "buffer-size: " << buffer->getSize();
951+ // LOG_S(INFO) << "buffer: " << buffer->getBuffer();
922952 }
923953
924- assert(false);
954+ // assert(false);
925955 }
956+
926957 else if(utils::json::has(keys_0, desc_font))
927958 {
928959 auto qpdf_obj = qpdf_desc_font.getKey("/FontDescriptor").getKey("/FontFile3");
@@ -963,8 +994,9 @@ namespace pdflib
963994 else
964995 {
965996 LOG_S(WARNING) << "fontfile3 is not a stream ...";
966- }
997+ }
967998 }
999+
9681000 else
9691001 {
9701002 LOG_S(WARNING) << "no fontfile3 detected ...";
@@ -1616,6 +1648,7 @@ namespace pdflib
16161648 // Create a regex object
16171649 std::regex re_01 (R"( \/(.+)\.(.+))" );
16181650 std::regex re_02 (R"( (\/)?(uni|UNI)([0-9A-Ea-e]{4}))" );
1651+ std::regex re_03 (R"( (\/)(g|G)\d+)" );
16191652
16201653 if (utils::json::has (keys, json_font))
16211654 {
@@ -1654,10 +1687,13 @@ namespace pdflib
16541687 }
16551688 else
16561689 {}
1690+
1691+ LOG_S (INFO) << name << " , in cmap: " << cmap_numb_to_char.count (numb) << " , #-names: " << name_to_descr.size () << " , type: " << subtype;
16571692
1658- if (name_to_descr.count (name)==1 and // only for TYPE_3 fonts
1693+ if (subtype==TYPE_3 and // name_to_descr.count(name)==1 and // only for TYPE_3 fonts
16591694 cmap_numb_to_char.count (numb)==1 )
16601695 {
1696+ LOG_S (WARNING) << " overloading difference from cmap" ;
16611697 diff_numb_to_char[numb] = cmap_numb_to_char[numb];
16621698 }
16631699
@@ -1739,6 +1775,13 @@ namespace pdflib
17391775 << diff_numb_to_char[numb]
17401776 << " (from " << name << " )" ;
17411777 }
1778+ else if (std::regex_match (name, match, re_03) and cmap_numb_to_char.count (numb)==1 ) // if the name is of type /g23 of /G23 and we have a match in the cmap
1779+ {
1780+ LOG_S (WARNING) << " overloading difference from cmap" ;
1781+ diff_numb_to_char[numb] = cmap_numb_to_char[numb];
1782+ // diff_numb_to_char[numb] = name;
1783+ // LOG_S(ERROR) << "weird differences["<<numb<<"] -> " << name;
1784+ }
17421785 else
17431786 {
17441787 diff_numb_to_char[numb] = name;
0 commit comments