@@ -75,12 +75,9 @@ public static FontProgram createFont() throws java.io.IOException {
75
75
76
76
/**
77
77
* Creates a new font program. This font program can be one of the 14 built in fonts,
78
- * a Type1 font referred to by an AFM or PFM file, a TrueType font (simple or one from collection) or
78
+ * a Type1 font referred to by an AFM or PFM file, a TrueType font or
79
79
* a CJK font from the Adobe Asian Font Pack.
80
- * TrueType fonts and CJK fonts can have an optional style modifier
81
- * appended to the name. These modifiers are: Bold, Italic and BoldItalic. An
82
- * example would be "STSong-Light,Bold". Note that this modifiers do not work if
83
- * the font is embedded. Fonts in TrueType Collections are addressed by index such as "msgothic.ttc,1".
80
+ * Fonts in TrueType Collections are addressed by index such as "msgothic.ttc,1".
84
81
* This would get the second font (indexes start at 0), in this case "MS PGothic".
85
82
* <p/>
86
83
* The fonts are cached and if they already exist they are extracted from the cache,
@@ -96,12 +93,9 @@ public static FontProgram createFont(String fontProgram) throws java.io.IOExcept
96
93
97
94
/**
98
95
* Creates a new font program. This font program can be one of the 14 built in fonts,
99
- * a Type1 font referred to by an AFM or PFM file, a TrueType font (simple or one from collection) or
96
+ * a Type1 font referred to by an AFM or PFM file, a TrueType font or
100
97
* a CJK font from the Adobe Asian Font Pack.
101
- * TrueType fonts and CJK fonts can have an optional style modifier
102
- * appended to the name. These modifiers are: Bold, Italic and BoldItalic. An
103
- * example would be "STSong-Light,Bold". Note that this modifiers do not work if
104
- * the font is embedded. Fonts in TrueType Collections are addressed by index such as "msgothic.ttc,1".
98
+ * Fonts in TrueType Collections are addressed by index such as "msgothic.ttc,1".
105
99
* This would get the second font (indexes start at 0), in this case "MS PGothic".
106
100
* <p/>
107
101
* The fonts are cached and if they already exist they are extracted from the cache,
@@ -118,12 +112,9 @@ public static FontProgram createFont(String fontProgram, boolean cached) throws
118
112
119
113
/**
120
114
* Creates a new font program. This font program can be one of the 14 built in fonts,
121
- * a Type1 font referred to by an AFM or PFM file, a TrueType font (simple only) or
115
+ * a Type1 font referred to by an AFM or PFM file, a TrueType font or
122
116
* a CJK font from the Adobe Asian Font Pack.
123
- * TrueType fonts and CJK fonts can have an optional style modifier
124
- * appended to the name. These modifiers are: Bold, Italic and BoldItalic. An
125
- * example would be "STSong-Light,Bold". Note that this modifiers do not work if
126
- * the font is embedded. Fonts in TrueType Collections are addressed by index such as "msgothic.ttc,1".
117
+ * Fonts in TrueType Collections are addressed by index such as "msgothic.ttc,1".
127
118
* This would get the second font (indexes start at 0), in this case "MS PGothic".
128
119
* <p/>
129
120
* The fonts are cached and if they already exist they are extracted from the cache,
@@ -139,12 +130,9 @@ public static FontProgram createFont(byte[] fontProgram) throws java.io.IOExcept
139
130
140
131
/**
141
132
* Creates a new font program. This font program can be one of the 14 built in fonts,
142
- * a Type 1 font referred to by an AFM or PFM file, a TrueType font (simple only) or
133
+ * a Type 1 font referred to by an AFM or PFM file, a TrueType font or
143
134
* a CJK font from the Adobe Asian Font Pack.
144
- * TrueType fonts and CJK fonts can have an optional style modifier
145
- * appended to the name. These modifiers are: Bold, Italic and BoldItalic. An
146
- * example would be "STSong-Light,Bold". Note that this modifiers do not work if
147
- * the font is embedded. Fonts in TrueType Collections are addressed by index such as "msgothic.ttc,1".
135
+ * Fonts in TrueType Collections are addressed by index such as "msgothic.ttc,1".
148
136
* This would get the second font (indexes start at 0), in this case "MS PGothic".
149
137
* <p/>
150
138
* The fonts are cached and if they already exist they are extracted from the cache,
@@ -199,14 +187,19 @@ public static FontProgram createFont(String name, byte[] fontProgram, boolean ca
199
187
}
200
188
}
201
189
} else {
202
- if (isBuiltinFonts14 || name .toLowerCase ().endsWith (".afm" ) || name .toLowerCase ().endsWith (".pfm" )) {
190
+ String fontFileExtension = null ;
191
+ int extensionBeginIndex = name .lastIndexOf ('.' );
192
+ if (extensionBeginIndex > 0 ) {
193
+ fontFileExtension = name .substring (extensionBeginIndex ).toLowerCase ();
194
+ }
195
+ if (isBuiltinFonts14 || ".afm" .equals (fontFileExtension ) || ".pfm" .equals (fontFileExtension )) {
203
196
fontBuilt = new Type1Font (name , null , null , null );
204
197
} else if (isCidFont ) {
205
198
fontBuilt = new CidFont (name , FontCache .getCompatibleCmaps (baseName ));
206
- } else if (baseName . toLowerCase (). endsWith ( ".ttf" ) || baseName . toLowerCase (). endsWith ( ".otf" ) || baseName . toLowerCase (). endsWith ( ".woff" )) {
207
- if (baseName . toLowerCase (). endsWith ( ".woff" )) {
199
+ } else if (".ttf" . equals ( fontFileExtension ) || ".otf" . equals ( fontFileExtension ) || ".woff" . equals ( fontFileExtension )) {
200
+ if (".woff" . equals ( fontFileExtension )) {
208
201
if (fontProgram == null ) {
209
- fontProgram = StreamUtil .inputStreamToArray (new FileInputStream (baseName ));
202
+ fontProgram = StreamUtil .inputStreamToArray (new FileInputStream (name ));
210
203
}
211
204
try {
212
205
fontProgram = WoffConverter .convert (fontProgram );
@@ -220,11 +213,11 @@ public static FontProgram createFont(String name, byte[] fontProgram, boolean ca
220
213
fontBuilt = new TrueTypeFont (name );
221
214
}
222
215
} else {
223
- int ttcSplit = baseName .toLowerCase ().indexOf (".ttc," );
216
+ int ttcSplit = name .toLowerCase ().indexOf (".ttc," );
224
217
if (ttcSplit > 0 ) {
225
218
try {
226
- String ttcName = baseName .substring (0 , ttcSplit + 4 );// count(.ttc) = 4
227
- int ttcIndex = Integer .parseInt (baseName .substring (ttcSplit + 5 ));// count(.ttc,) = 5)
219
+ String ttcName = name .substring (0 , ttcSplit + 4 ); // count(.ttc) = 4
220
+ int ttcIndex = Integer .parseInt (name .substring (ttcSplit + 5 )); // count(.ttc,) = 5)
228
221
fontBuilt = new TrueTypeFont (ttcName , ttcIndex );
229
222
} catch (NumberFormatException nfe ) {
230
223
throw new IOException (nfe .getMessage (), nfe );
0 commit comments