@@ -154,9 +154,9 @@ public class PdfType0Font extends PdfFont {
154154 newFont = false ;
155155 PdfDictionary cidFont = fontDictionary .getAsArray (PdfName .DescendantFonts ).getAsDictionary (0 );
156156 PdfObject cmap = fontDictionary .get (PdfName .Encoding );
157+ PdfObject toUnicode = fontDictionary .get (PdfName .ToUnicode );
158+ CMapToUnicode toUnicodeCMap = FontUtil .processToUnicode (toUnicode );
157159 if (cmap .isName () && (PdfEncodings .IDENTITY_H .equals (((PdfName )cmap ).getValue ()) || PdfEncodings .IDENTITY_V .equals (((PdfName )cmap ).getValue ()))) {
158- PdfObject toUnicode = fontDictionary .get (PdfName .ToUnicode );
159- CMapToUnicode toUnicodeCMap = FontUtil .processToUnicode (toUnicode );
160160 if (toUnicodeCMap == null ) {
161161 String uniMap = getUniMapFromOrdering (getOrdering (cidFont ));
162162 toUnicodeCMap = FontUtil .getToUnicodeFromUniMap (uniMap );
@@ -173,8 +173,7 @@ public class PdfType0Font extends PdfFont {
173173 } else {
174174 String cidFontName = cidFont .getAsName (PdfName .BaseFont ).getValue ();
175175 String uniMap = getUniMapFromOrdering (getOrdering (cidFont ));
176- if (uniMap != null && uniMap .startsWith ("Uni" )
177- && CidFontProperties .isCidFont (cidFontName , uniMap )) {
176+ if (uniMap != null && uniMap .startsWith ("Uni" ) && CidFontProperties .isCidFont (cidFontName , uniMap )) {
178177 try {
179178 fontProgram = FontProgramFactory .createFont (cidFontName );
180179 cmapEncoding = createCMap (cmap , uniMap );
@@ -184,7 +183,9 @@ public class PdfType0Font extends PdfFont {
184183 cmapEncoding = null ;
185184 }
186185 } else {
187- CMapToUnicode toUnicodeCMap = FontUtil .getToUnicodeFromUniMap (uniMap );
186+ if (toUnicodeCMap == null ) {
187+ toUnicodeCMap = FontUtil .getToUnicodeFromUniMap (uniMap );
188+ }
188189 if (toUnicodeCMap != null ) {
189190 fontProgram = DocTrueTypeFont .createFontProgram (cidFont , toUnicodeCMap );
190191 cmapEncoding = createCMap (cmap , uniMap );
0 commit comments