Issue 940 in pdfium: No encoding specified for fonts

55 views
Skip to first unread message

intrasec… via monorail

unread,
Nov 22, 2017, 10:51:16 AM11/22/17
to pdfiu...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 940 by intrasec...@gmail.com: No encoding specified for fonts
https://bugs.chromium.org/p/pdfium/issues/detail?id=940

What steps will reproduce the problem?

I insert text in a pdf using :
FPDFPageObj_NewTextObj
FPDFText_SetText
FPDFPageObj_Transform
FPDFPage_InsertObject
FPDFPage_GenerateContent



What is the expected output? What do you see instead?

I have a problem for special characters.
For example "é" is displayed as "Ø".


What version of the product are you using? On what operating system?

latest pdfium, Windows 10

Please provide any additional information below.

What we found is that in the description in the font in the pdf, the encoding is missing (I expected to have Encoding/WinAnsiEncoding). For example :

6 0 obj
<</BaseFont/Courier/Subtype/Type1/Type/Font>>
endobj

When no encoding is specified, it means StandardEncoding. FPDFText_SetText takes UTF16-LE strings and manipulates them as WinAnsiEncoding.

I managed to make it work in my case by modifying CPDF_PageContentGenerator::ProcessText
In this function I added after this comment :
// In this case we assume it must be a standard font

this :
// get font encoding
ByteString encoding = pFont->GetFontDict()->GetStringFor("Encoding");
if (!encoding.IsEmpty())
{
fontDict->SetNewFor<CPDF_Name>("Encoding", encoding);
}


Is there another way ?
I also thought of modifing the text sent to FPDFText_SetText, making a conversion from WinAnsiEncoding to StandardEncoding.



Patch :
--------------- core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp ---------------
index 593680e7f..4af7fd8e7 100644
@@ -379,6 +379,14 @@ void CPDF_PageContentGenerator::ProcessText(std::ostringstream* buf,
fontDict->SetNewFor<CPDF_Name>("Type", "Font");
fontDict->SetNewFor<CPDF_Name>("Subtype", fontD.type);
fontDict->SetNewFor<CPDF_Name>("BaseFont", fontD.baseFont);
+
+ // get font encoding
+ ByteString encoding = pFont->GetFontDict()->GetStringFor("Encoding");
+ if (!encoding.IsEmpty())
+ {
+ fontDict->SetNewFor<CPDF_Name>("Encoding", encoding);
+ }
+
CPDF_Object* pDict = m_pDocument->AddIndirectObject(std::move(fontDict));
dwObjNum = pDict->GetObjNum();
}


--
You received this message because:
1. The project was configured to send all issue notifications to this address

You may adjust your notification preferences at:
https://bugs.chromium.org/hosting/settings

dsincl… via monorail

unread,
Nov 22, 2017, 4:37:55 PM11/22/17
to pdfiu...@googlegroups.com
Updates:
Cc: n...@chromium.org

Comment #1 on issue 940 by dsin...@chromium.org: No encoding specified for fonts
https://bugs.chromium.org/p/pdfium/issues/detail?id=940#c1

(No comment was entered for this change.)
Reply all
Reply to author
Forward
0 new messages