Skip to content

Commit bbb2e9e

Browse files
Snipxitext-teamcity
authored andcommitted
Use /ToUnicode when extracting simple TrueType fonts without explicit encoding
DEVSIX-1681 Autoported commit. Original commit hash: [d447044a1]
1 parent 2f439ca commit bbb2e9e

File tree

5 files changed

+9
-3
lines changed

5 files changed

+9
-3
lines changed

itext/itext.kernel/itext/kernel/font/DocTrueTypeFont.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ private DocTrueTypeFont(PdfDictionary fontDictionary)
7070
subtype = fontDictionary.GetAsName(PdfName.Subtype);
7171
}
7272

73-
internal static TrueTypeFont CreateFontProgram(PdfDictionary fontDictionary, FontEncoding fontEncoding) {
73+
internal static TrueTypeFont CreateFontProgram(PdfDictionary fontDictionary, FontEncoding fontEncoding, CMapToUnicode
74+
toUnicode) {
7475
iText.Kernel.Font.DocTrueTypeFont fontProgram = new iText.Kernel.Font.DocTrueTypeFont(fontDictionary);
7576
FillFontDescriptor(fontProgram, fontDictionary.GetAsDictionary(PdfName.FontDescriptor));
7677
PdfNumber firstCharNumber = fontDictionary.GetAsNumber(PdfName.FirstChar);
@@ -86,6 +87,11 @@ internal static TrueTypeFont CreateFontProgram(PdfDictionary fontDictionary, Fon
8687
if (glyph.HasValidUnicode() && fontEncoding.ConvertToByte(glyph.GetUnicode()) == i) {
8788
fontProgram.unicodeToGlyph.Put(glyph.GetUnicode(), glyph);
8889
}
90+
else {
91+
if (toUnicode != null) {
92+
glyph.SetChars(toUnicode.Lookup(i));
93+
}
94+
}
8995
if (widths[i] > 0) {
9096
glyphsWithWidths++;
9197
fontProgram.avgWidth += widths[i];

itext/itext.kernel/itext/kernel/font/PdfTrueTypeFont.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ internal PdfTrueTypeFont(PdfDictionary fontDictionary)
8080
newFont = false;
8181
CMapToUnicode toUni = FontUtil.ProcessToUnicode(fontDictionary.Get(PdfName.ToUnicode));
8282
fontEncoding = DocFontEncoding.CreateDocFontEncoding(fontDictionary.Get(PdfName.Encoding), toUni);
83-
fontProgram = DocTrueTypeFont.CreateFontProgram(fontDictionary, fontEncoding);
83+
fontProgram = DocTrueTypeFont.CreateFontProgram(fontDictionary, fontEncoding, toUni);
8484
embedded = ((IDocFontProgram)fontProgram).GetFontFile() != null;
8585
subset = false;
8686
}

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
76b261370b3e1689f7a7ec4eba6025f42ccacf03
1+
d447044a10cf9b74295cb6265d7959eda9830653

0 commit comments

Comments
 (0)