@@ -43,7 +43,7 @@ This file is part of the iText (R) project.
43
43
*/
44
44
package com .itextpdf .kernel .font ;
45
45
46
- import com .itextpdf .io . logs . IoLogMessageConstant ;
46
+ import com .itextpdf .commons . utils . MessageFormatUtil ;
47
47
import com .itextpdf .io .font .CFFFontSubset ;
48
48
import com .itextpdf .io .font .CMapEncoding ;
49
49
import com .itextpdf .io .font .CidFont ;
@@ -56,14 +56,14 @@ This file is part of the iText (R) project.
56
56
import com .itextpdf .io .font .cmap .CMapToUnicode ;
57
57
import com .itextpdf .io .font .otf .Glyph ;
58
58
import com .itextpdf .io .font .otf .GlyphLine ;
59
+ import com .itextpdf .io .logs .IoLogMessageConstant ;
59
60
import com .itextpdf .io .source .ByteArrayOutputStream ;
60
61
import com .itextpdf .io .source .ByteBuffer ;
61
62
import com .itextpdf .io .source .OutputStream ;
62
- import com .itextpdf .commons .utils .MessageFormatUtil ;
63
63
import com .itextpdf .io .util .StreamUtil ;
64
64
import com .itextpdf .io .util .TextUtil ;
65
- import com .itextpdf .kernel .exceptions .PdfException ;
66
65
import com .itextpdf .kernel .exceptions .KernelExceptionMessageConstant ;
66
+ import com .itextpdf .kernel .exceptions .PdfException ;
67
67
import com .itextpdf .kernel .pdf .PdfArray ;
68
68
import com .itextpdf .kernel .pdf .PdfDictionary ;
69
69
import com .itextpdf .kernel .pdf .PdfLiteral ;
@@ -74,6 +74,7 @@ This file is part of the iText (R) project.
74
74
import com .itextpdf .kernel .pdf .PdfStream ;
75
75
import com .itextpdf .kernel .pdf .PdfString ;
76
76
import com .itextpdf .kernel .pdf .PdfVersion ;
77
+
77
78
import java .io .IOException ;
78
79
import java .util .ArrayList ;
79
80
import java .util .List ;
@@ -164,9 +165,11 @@ public class PdfType0Font extends PdfFont {
164
165
PdfObject cmap = fontDictionary .get (PdfName .Encoding );
165
166
PdfObject toUnicode = fontDictionary .get (PdfName .ToUnicode );
166
167
CMapToUnicode toUnicodeCMap = FontUtil .processToUnicode (toUnicode );
167
- if (cmap .isName () && (PdfEncodings .IDENTITY_H .equals (((PdfName ) cmap ).getValue ()) || PdfEncodings .IDENTITY_V .equals (((PdfName ) cmap ).getValue ()))) {
168
+ if (cmap .isName () && (PdfEncodings .IDENTITY_H .equals (((PdfName ) cmap ).getValue ()) ||
169
+ PdfEncodings .IDENTITY_V .equals (((PdfName ) cmap ).getValue ()))) {
168
170
if (toUnicodeCMap == null ) {
169
- String uniMap = getUniMapFromOrdering (getOrdering (cidFont ));
171
+ String uniMap = getUniMapFromOrdering (getOrdering (cidFont ),
172
+ PdfEncodings .IDENTITY_H .equals (((PdfName ) cmap ).getValue ()));
170
173
toUnicodeCMap = FontUtil .getToUnicodeFromUniMap (uniMap );
171
174
if (toUnicodeCMap == null ) {
172
175
toUnicodeCMap = FontUtil .getToUnicodeFromUniMap (PdfEncodings .IDENTITY_H );
@@ -180,7 +183,7 @@ public class PdfType0Font extends PdfFont {
180
183
embedded = ((IDocFontProgram ) fontProgram ).getFontFile () != null ;
181
184
} else {
182
185
String cidFontName = cidFont .getAsName (PdfName .BaseFont ).getValue ();
183
- String uniMap = getUniMapFromOrdering (getOrdering (cidFont ));
186
+ String uniMap = getUniMapFromOrdering (getOrdering (cidFont ), true );
184
187
if (uniMap != null && uniMap .startsWith ("Uni" ) && CidFontProperties .isCidFont (cidFontName , uniMap )) {
185
188
try {
186
189
fontProgram = FontProgramFactory .createFont (cidFontName );
@@ -201,10 +204,12 @@ public class PdfType0Font extends PdfFont {
201
204
}
202
205
if (fontProgram == null ) {
203
206
throw new PdfException (MessageFormatUtil .format (
204
- KernelExceptionMessageConstant .CANNOT_RECOGNISE_DOCUMENT_FONT_WITH_ENCODING , cidFontName , cmap ));
207
+ KernelExceptionMessageConstant .CANNOT_RECOGNISE_DOCUMENT_FONT_WITH_ENCODING ,
208
+ cidFontName , cmap ));
205
209
}
206
210
}
207
- // DescendantFonts is a one-element array specifying the CIDFont dictionary that is the descendant of this Type 0 font.
211
+ // DescendantFonts is a one-element array specifying the CIDFont dictionary
212
+ // that is the descendant of this Type 0 font.
208
213
PdfDictionary cidFontDictionary = fontDictionary .getAsArray (PdfName .DescendantFonts ).getAsDictionary (0 );
209
214
// Required according to the spec
210
215
PdfName subtype = cidFontDictionary .getAsName (PdfName .Subtype );
@@ -219,6 +224,41 @@ public class PdfType0Font extends PdfFont {
219
224
subset = false ;
220
225
}
221
226
227
+ public static String getUniMapFromOrdering (String ordering , boolean horizontal ) {
228
+ String result = null ;
229
+ switch (ordering ) {
230
+ case "CNS1" :
231
+ result = "UniCNS-UTF16-" ;
232
+ break ;
233
+ case "Japan1" :
234
+ result = "UniJIS-UTF16-" ;
235
+ break ;
236
+ case "Korea1" :
237
+ result = "UniKS-UTF16-" ;
238
+ break ;
239
+ case "GB1" :
240
+ result = "UniGB-UTF16-" ;
241
+ break ;
242
+ case "Identity" :
243
+ result = "Identity-" ;
244
+ break ;
245
+ default :
246
+ return null ;
247
+ }
248
+ if (horizontal ) {
249
+ return result + 'H' ;
250
+ }
251
+ return result + 'V' ;
252
+ }
253
+
254
+ /**
255
+ * Get Unicode mapping name from ordering.
256
+ * @param ordering the text ordering to base to unicode mapping on
257
+ * @return Unicode mapping name
258
+ * @deprecated Replaced by {@link #getUniMapFromOrdering(String, boolean)}
259
+ * for proper handling of IDENTITY_V encoding.
260
+ */
261
+ @ Deprecated
222
262
public static String getUniMapFromOrdering (String ordering ) {
223
263
switch (ordering ) {
224
264
case "CNS1" :
@@ -841,18 +881,18 @@ private PdfObject generateWidthsArray() {
841
881
public PdfStream getToUnicode () {
842
882
OutputStream <ByteArrayOutputStream > stream = new OutputStream <>(new ByteArrayOutputStream ());
843
883
stream .writeString ("/CIDInit /ProcSet findresource begin\n " +
844
- "12 dict begin\n " +
845
- "begincmap\n " +
846
- "/CIDSystemInfo\n " +
847
- "<< /Registry (Adobe)\n " +
848
- "/Ordering (UCS)\n " +
849
- "/Supplement 0\n " +
850
- ">> def\n " +
851
- "/CMapName /Adobe-Identity-UCS def\n " +
852
- "/CMapType 2 def\n " +
853
- "1 begincodespacerange\n " +
854
- "<0000><FFFF>\n " +
855
- "endcodespacerange\n " );
884
+ "12 dict begin\n " +
885
+ "begincmap\n " +
886
+ "/CIDSystemInfo\n " +
887
+ "<< /Registry (Adobe)\n " +
888
+ "/Ordering (UCS)\n " +
889
+ "/Supplement 0\n " +
890
+ ">> def\n " +
891
+ "/CMapName /Adobe-Identity-UCS def\n " +
892
+ "/CMapType 2 def\n " +
893
+ "1 begincodespacerange\n " +
894
+ "<0000><FFFF>\n " +
895
+ "endcodespacerange\n " );
856
896
857
897
//accumulate long tag into a subset and write it.
858
898
ArrayList <Glyph > glyphGroup = new ArrayList <>(100 );
@@ -937,4 +977,4 @@ private static String normalizeEncoding(String encoding) {
937
977
? PdfEncodings .IDENTITY_H
938
978
: encoding ;
939
979
}
940
- }
980
+ }
0 commit comments