Bug when drawing text using truetype font with difference encoding loaded from pdf
A PDF parsing, modification and creation library.
Brought to you by:
domseichter
https://sourceforge.net/p/podofo/mailman/message/36484599/
When using font created by function with signature "PdfFont PdfMemDocument::GetFont( PdfObject pObject )" for drawing text then not all characters outside of base encoding are rendered if specified font uses difference encoding for these characters.
Also StringWidth function is not working correctly with such fonts.
Test case where widths in output should be same or at least very similar (and all characters should be rendered in pdf viewer) but are not:
PdfMemDocument doc; PdfPage *page = doc.CreatePage({0, 0, 500, 800}); PdfFont *font = doc.CreateFont("Verdana", false, false, false, PdfEncodingFactory::GlobalWin1250EncodingInstance()); PdfPainter p; p.SetPage(page); p.SetFont(font); p.DrawText(10, 780, (const pdf_utf8*)"ČŘĎ"); p.FinishPage(); doc.Write("doc.pdf"); printf("Width of 'ČŘĎ' using newly created font is: %f\n", font->GetFontMetrics()->StringWidth((const pdf_utf8*)"ČŘĎ")); PdfMemDocument doc2("doc.pdf"); PdfPage *page2 = doc2.GetPage(0); PdfFont *font2 = doc2.GetFont(page2->GetFromResources("Font", font->GetIdentifier())); PdfPainter p2; p2.SetPage(page2); p2.SetFont(font2); p2.DrawText(10, 760, (const pdf_utf8*)"ČŘĎ"); p2.FinishPage(); doc2.Write("doc2.pdf"); printf("Width of 'ČŘĎ' using loaded font is: %f\n", font2->GetFontMetrics()->StringWidth((const pdf_utf8*)"ČŘĎ"));
Thanks for the patch. I committed it as [r2039].
Related
Commit: [r2039]