@@ -71,12 +71,9 @@ public static FontProgram CreateFont() {
7171 /// <summary>Creates a new font program.</summary>
7272 /// <remarks>
7373 /// Creates a new font program. This font program can be one of the 14 built in fonts,
74- /// a Type1 font referred to by an AFM or PFM file, a TrueType font (simple or one from collection) or
74+ /// a Type1 font referred to by an AFM or PFM file, a TrueType font or
7575 /// a CJK font from the Adobe Asian Font Pack.
76- /// TrueType fonts and CJK fonts can have an optional style modifier
77- /// appended to the name. These modifiers are: Bold, Italic and BoldItalic. An
78- /// example would be "STSong-Light,Bold". Note that this modifiers do not work if
79- /// the font is embedded. Fonts in TrueType Collections are addressed by index such as "msgothic.ttc,1".
76+ /// Fonts in TrueType Collections are addressed by index such as "msgothic.ttc,1".
8077 /// This would get the second font (indexes start at 0), in this case "MS PGothic".
8178 /// <p/>
8279 /// The fonts are cached and if they already exist they are extracted from the cache,
@@ -97,12 +94,9 @@ public static FontProgram CreateFont(String fontProgram) {
9794 /// <summary>Creates a new font program.</summary>
9895 /// <remarks>
9996 /// Creates a new font program. This font program can be one of the 14 built in fonts,
100- /// a Type1 font referred to by an AFM or PFM file, a TrueType font (simple or one from collection) or
97+ /// a Type1 font referred to by an AFM or PFM file, a TrueType font or
10198 /// a CJK font from the Adobe Asian Font Pack.
102- /// TrueType fonts and CJK fonts can have an optional style modifier
103- /// appended to the name. These modifiers are: Bold, Italic and BoldItalic. An
104- /// example would be "STSong-Light,Bold". Note that this modifiers do not work if
105- /// the font is embedded. Fonts in TrueType Collections are addressed by index such as "msgothic.ttc,1".
99+ /// Fonts in TrueType Collections are addressed by index such as "msgothic.ttc,1".
106100 /// This would get the second font (indexes start at 0), in this case "MS PGothic".
107101 /// <p/>
108102 /// The fonts are cached and if they already exist they are extracted from the cache,
@@ -124,12 +118,9 @@ public static FontProgram CreateFont(String fontProgram, bool cached) {
124118 /// <summary>Creates a new font program.</summary>
125119 /// <remarks>
126120 /// Creates a new font program. This font program can be one of the 14 built in fonts,
127- /// a Type1 font referred to by an AFM or PFM file, a TrueType font (simple only) or
121+ /// a Type1 font referred to by an AFM or PFM file, a TrueType font or
128122 /// a CJK font from the Adobe Asian Font Pack.
129- /// TrueType fonts and CJK fonts can have an optional style modifier
130- /// appended to the name. These modifiers are: Bold, Italic and BoldItalic. An
131- /// example would be "STSong-Light,Bold". Note that this modifiers do not work if
132- /// the font is embedded. Fonts in TrueType Collections are addressed by index such as "msgothic.ttc,1".
123+ /// Fonts in TrueType Collections are addressed by index such as "msgothic.ttc,1".
133124 /// This would get the second font (indexes start at 0), in this case "MS PGothic".
134125 /// <p/>
135126 /// The fonts are cached and if they already exist they are extracted from the cache,
@@ -150,12 +141,9 @@ public static FontProgram CreateFont(byte[] fontProgram) {
150141 /// <summary>Creates a new font program.</summary>
151142 /// <remarks>
152143 /// Creates a new font program. This font program can be one of the 14 built in fonts,
153- /// a Type 1 font referred to by an AFM or PFM file, a TrueType font (simple only) or
144+ /// a Type 1 font referred to by an AFM or PFM file, a TrueType font or
154145 /// a CJK font from the Adobe Asian Font Pack.
155- /// TrueType fonts and CJK fonts can have an optional style modifier
156- /// appended to the name. These modifiers are: Bold, Italic and BoldItalic. An
157- /// example would be "STSong-Light,Bold". Note that this modifiers do not work if
158- /// the font is embedded. Fonts in TrueType Collections are addressed by index such as "msgothic.ttc,1".
146+ /// Fonts in TrueType Collections are addressed by index such as "msgothic.ttc,1".
159147 /// This would get the second font (indexes start at 0), in this case "MS PGothic".
160148 /// <p/>
161149 /// The fonts are cached and if they already exist they are extracted from the cache,
@@ -212,20 +200,24 @@ public static FontProgram CreateFont(String name, byte[] fontProgram, bool cache
212200 }
213201 }
214202 else {
215- if ( isBuiltinFonts14 || name . ToLowerInvariant ( ) . EndsWith ( ".afm" ) || name . ToLowerInvariant ( ) . EndsWith ( ".pfm"
216- ) ) {
203+ String fontFileExtension = null ;
204+ int extensionBeginIndex = name . LastIndexOf ( '.' ) ;
205+ if ( extensionBeginIndex > 0 ) {
206+ fontFileExtension = name . Substring ( extensionBeginIndex ) . ToLowerInvariant ( ) ;
207+ }
208+ if ( isBuiltinFonts14 || ".afm" . Equals ( fontFileExtension ) || ".pfm" . Equals ( fontFileExtension ) ) {
217209 fontBuilt = new Type1Font ( name , null , null , null ) ;
218210 }
219211 else {
220212 if ( isCidFont ) {
221213 fontBuilt = new CidFont ( name , FontCache . GetCompatibleCmaps ( baseName ) ) ;
222214 }
223215 else {
224- if ( baseName . ToLowerInvariant ( ) . EndsWith ( ".ttf" ) || baseName . ToLowerInvariant ( ) . EndsWith ( ".otf" ) || baseName
225- . ToLowerInvariant ( ) . EndsWith ( ".woff" ) ) {
226- if ( baseName . ToLowerInvariant ( ) . EndsWith ( ".woff" ) ) {
216+ if ( ".ttf" . Equals ( fontFileExtension ) || ".otf" . Equals ( fontFileExtension ) || ".woff" . Equals ( fontFileExtension
217+ ) ) {
218+ if ( ".woff" . Equals ( fontFileExtension ) ) {
227219 if ( fontProgram == null ) {
228- fontProgram = StreamUtil . InputStreamToArray ( new FileStream ( baseName , FileMode . Open , FileAccess . Read ) ) ;
220+ fontProgram = StreamUtil . InputStreamToArray ( new FileStream ( name , FileMode . Open , FileAccess . Read ) ) ;
229221 }
230222 try {
231223 fontProgram = WoffConverter . Convert ( fontProgram ) ;
@@ -242,13 +234,13 @@ public static FontProgram CreateFont(String name, byte[] fontProgram, bool cache
242234 }
243235 }
244236 else {
245- int ttcSplit = baseName . ToLowerInvariant ( ) . IndexOf ( ".ttc," , StringComparison . Ordinal ) ;
237+ int ttcSplit = name . ToLowerInvariant ( ) . IndexOf ( ".ttc," , StringComparison . Ordinal ) ;
246238 if ( ttcSplit > 0 ) {
247239 try {
248- String ttcName = baseName . JSubstring ( 0 , ttcSplit + 4 ) ;
249- //count(.ttc) = 4
250- int ttcIndex = System . Convert . ToInt32 ( baseName . Substring ( ttcSplit + 5 ) ) ;
251- //count(.ttc,) = 5)
240+ String ttcName = name . JSubstring ( 0 , ttcSplit + 4 ) ;
241+ // count(.ttc) = 4
242+ int ttcIndex = System . Convert . ToInt32 ( name . Substring ( ttcSplit + 5 ) ) ;
243+ // count(.ttc,) = 5)
252244 fontBuilt = new TrueTypeFont ( ttcName , ttcIndex ) ;
253245 }
254246 catch ( FormatException nfe ) {
0 commit comments