Skip to content

Commit afba3ca

Browse files
committed
Rename FontFactory to FontProgramFactory
1 parent 0e1dbef commit afba3ca

File tree

10 files changed

+79
-89
lines changed

10 files changed

+79
-89
lines changed

io/src/main/java/com/itextpdf/io/font/FontFactory.java renamed to io/src/main/java/com/itextpdf/io/font/FontProgramFactory.java

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ This file is part of the iText (R) project.
5353
/**
5454
* Provides methods for creating various types of fonts.
5555
*/
56-
public class FontFactory {
56+
public final class FontProgramFactory {
57+
58+
private FontProgramFactory() {
59+
}
5760

5861
private static FontRegisterProvider fontRegisterProvider = new FontRegisterProvider();
5962

@@ -203,7 +206,7 @@ public static FontProgram createFont(String font, boolean cached) throws java.io
203206
*
204207
* @param font the true type font or the afm in a byte array
205208
* an exception if the font is not recognized. Note that even if true an exception may be thrown in some circumstances.
206-
* This parameter is useful for FontFactory that may have to check many invalid font names before finding the right one
209+
* This parameter is useful for FontProgramFactory that may have to check many invalid font names before finding the right one
207210
* @return returns a new font. This font may come from the cache but only if cached
208211
* is true, otherwise it will always be created new
209212
*/
@@ -470,18 +473,17 @@ public static FontProgram createRegisteredFont(String fontName) throws java.io.I
470473
* @param fullName the font name
471474
* @param path the font path
472475
*/
473-
public static void registerFamily(String familyName, String fullName, String path) {
474-
fontRegisterProvider.registerFamily(familyName, fullName, path);
476+
public static void registerFontFamily(String familyName, String fullName, String path) {
477+
fontRegisterProvider.registerFontFamily(familyName, fullName, path);
475478
}
476479

477480
/**
478481
* Register a ttf- or a ttc-file.
479482
*
480483
* @param path the path to a ttf- or ttc-file
481484
*/
482-
483-
public static void register(String path) {
484-
register(path, null);
485+
public static void registerFont(String path) {
486+
registerFont(path, null);
485487
}
486488

487489
/**
@@ -490,9 +492,8 @@ public static void register(String path) {
490492
* @param path the path to a font file
491493
* @param alias the alias you want to use for the font
492494
*/
493-
494-
public static void register(String path, String alias) {
495-
fontRegisterProvider.register(path, alias);
495+
public static void registerFont(String path, String alias) {
496+
fontRegisterProvider.registerFont(path, alias);
496497
}
497498

498499
/**
@@ -501,8 +502,8 @@ public static void register(String path, String alias) {
501502
* @param dir the directory
502503
* @return the number of fonts registered
503504
*/
504-
public static int registerDirectory(String dir) {
505-
return fontRegisterProvider.registerDirectory(dir);
505+
public static int registerFontDirectory(String dir) {
506+
return fontRegisterProvider.registerFontDirectory(dir);
506507
}
507508

508509
/**
@@ -511,16 +512,15 @@ public static int registerDirectory(String dir) {
511512
*
512513
* @return the number of fonts registered
513514
*/
514-
public static int registerSystemDirectories() {
515-
return fontRegisterProvider.registerSystemDirectories();
515+
public static int registerSystemFontDirectories() {
516+
return fontRegisterProvider.registerSystemFontDirectories();
516517
}
517518

518519
/**
519520
* Gets a set of registered font names.
520521
*
521522
* @return a set of registered fonts
522523
*/
523-
524524
public static Set<String> getRegisteredFonts() {
525525
return fontRegisterProvider.getRegisteredFonts();
526526
}
@@ -530,20 +530,8 @@ public static Set<String> getRegisteredFonts() {
530530
*
531531
* @return a set of registered font families
532532
*/
533-
534-
public static Set<String> getRegisteredFamilies() {
535-
return fontRegisterProvider.getRegisteredFamilies();
536-
}
537-
538-
/**
539-
* Gets a set of registered font names.
540-
*
541-
* @param fontname of a font that may or may not be registered
542-
* @return true if a given font is registered
543-
*/
544-
545-
public static boolean contains(String fontname) {
546-
return fontRegisterProvider.isRegistered(fontname);
533+
public static Set<String> getRegisteredFontFamilies() {
534+
return fontRegisterProvider.getRegisteredFontFamilies();
547535
}
548536

549537
/**
@@ -552,8 +540,7 @@ public static boolean contains(String fontname) {
552540
* @param fontname the name of the font that has to be checked.
553541
* @return true if the font is found
554542
*/
555-
556-
public static boolean isRegistered(String fontname) {
557-
return fontRegisterProvider.isRegistered(fontname);
543+
public static boolean isRegisteredFont(String fontname) {
544+
return fontRegisterProvider.isRegisteredFont(fontname);
558545
}
559546
}

io/src/main/java/com/itextpdf/io/font/FontRegisterProvider.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,12 @@ protected FontProgram getFontProgram(String fontName, boolean cached) throws jav
184184
fontName = fontNames.get(fontName.toLowerCase());
185185
// the font is not registered as truetype font
186186
if (fontName != null) {
187-
fontProgram = FontFactory.createFont(fontName, cached);
187+
fontProgram = FontProgramFactory.createFont(fontName, cached);
188188
}
189189
if (fontProgram == null) {
190190
try {
191191
// the font is a type 1 font or CJK font
192-
fontProgram = FontFactory.createFont(fontName, cached);
192+
fontProgram = FontProgramFactory.createFont(fontName, cached);
193193
} catch (IOException ignored) {
194194
}
195195
}
@@ -204,7 +204,7 @@ protected FontProgram getFontProgram(String fontName, boolean cached) throws jav
204204
* @param fullName the font name
205205
* @param path the font path
206206
*/
207-
public void registerFamily(String familyName, String fullName, String path) {
207+
public void registerFontFamily(String familyName, String fullName, String path) {
208208
if (path != null)
209209
fontNames.put(fullName, path);
210210
List<String> tmp;
@@ -246,8 +246,8 @@ public void registerFamily(String familyName, String fullName, String path) {
246246
* @param path the path to a ttf- or ttc-file
247247
*/
248248

249-
public void register(String path) {
250-
register(path, null);
249+
public void registerFont(String path) {
250+
registerFont(path, null);
251251
}
252252

253253
/**
@@ -257,10 +257,10 @@ public void register(String path) {
257257
* @param alias the alias you want to use for the font
258258
*/
259259

260-
public void register(String path, String alias) {
260+
public void registerFont(String path, String alias) {
261261
try {
262262
if (path.toLowerCase().endsWith(".ttf") || path.toLowerCase().endsWith(".otf") || path.toLowerCase().indexOf(".ttc,") > 0) {
263-
FontProgram fontProgram = FontFactory.createFont(path);
263+
FontProgram fontProgram = FontProgramFactory.createFont(path);
264264
Object[] allNames = new Object[]{fontProgram.getFontNames().getFontName(), fontProgram.getFontNames().getFamilyName(), fontProgram.getFontNames().getFullName()};
265265
fontNames.put(((String) allNames[0]).toLowerCase(), path);
266266
if (alias != null) {
@@ -281,7 +281,7 @@ public void register(String path, String alias) {
281281
saveCopyOfRegularFont(lcName, path);
282282
}
283283
}
284-
String fullName = null;
284+
String fullName;
285285
String familyName = null;
286286
names = (String[][]) allNames[1]; //family name
287287
for (int k = 0; k < TTFamilyOrder.length; k += 3) {
@@ -303,7 +303,7 @@ public void register(String path, String alias) {
303303
if (fullName.equals(lastName))
304304
continue;
305305
lastName = fullName;
306-
registerFamily(familyName, fullName, null);
306+
registerFontFamily(familyName, fullName, null);
307307
break;
308308
}
309309
}
@@ -315,14 +315,14 @@ public void register(String path, String alias) {
315315
}
316316
TrueTypeCollection ttc = new TrueTypeCollection(path, PdfEncodings.WINANSI);
317317
for (int i = 0; i < ttc.getTTCSize(); i++) {
318-
register(path + "," + i);
318+
registerFont(path + "," + i);
319319
}
320320
} else if (path.toLowerCase().endsWith(".afm") || path.toLowerCase().endsWith(".pfm")) {
321-
FontProgram fontProgram = FontFactory.createFont(path, false);
321+
FontProgram fontProgram = FontProgramFactory.createFont(path, false);
322322
String fullName = fontProgram.getFontNames().getFullName()[0][3].toLowerCase();
323323
String familyName = fontProgram.getFontNames().getFamilyName()[0][3].toLowerCase();
324324
String psName =fontProgram.getFontNames().getFontName().toLowerCase();
325-
registerFamily(familyName, fullName, null);
325+
registerFontFamily(familyName, fullName, null);
326326
fontNames.put(psName, path);
327327
fontNames.put(fullName, path);
328328
}
@@ -351,8 +351,8 @@ protected boolean saveCopyOfRegularFont(String regularFontName, String path) {
351351
* @param dir the directory
352352
* @return the number of fonts registered
353353
*/
354-
public int registerDirectory(String dir) {
355-
return registerDirectory(dir, false);
354+
public int registerFontDirectory(String dir) {
355+
return registerFontDirectory(dir, false);
356356
}
357357

358358
/**
@@ -362,7 +362,7 @@ public int registerDirectory(String dir) {
362362
* @param scanSubdirectories recursively scan subdirectories if <code>true</true>
363363
* @return the number of fonts registered
364364
*/
365-
public int registerDirectory(String dir, boolean scanSubdirectories) {
365+
public int registerFontDirectory(String dir, boolean scanSubdirectories) {
366366
LOGGER.debug(MessageFormat.format("Registering directory {0}, looking for fonts", dir));
367367
int count = 0;
368368
try {
@@ -376,11 +376,11 @@ public int registerDirectory(String dir, boolean scanSubdirectories) {
376376
/* Only register Type 1 fonts with matching .pfb files */
377377
String pfb = file.substring(0, file.length() - 4) + ".pfb";
378378
if (FileUtil.fileExists(pfb)) {
379-
register(file, null);
379+
registerFont(file, null);
380380
++count;
381381
}
382382
} else if (".ttf".equals(suffix) || ".otf".equals(suffix) || ".ttc".equals(suffix)) {
383-
register(file, null);
383+
registerFont(file, null);
384384
++count;
385385
}
386386
} catch (Exception e) {
@@ -399,7 +399,7 @@ public int registerDirectory(String dir, boolean scanSubdirectories) {
399399
*
400400
* @return the number of fonts registered
401401
*/
402-
public int registerSystemDirectories() {
402+
public int registerSystemFontDirectories() {
403403
int count = 0;
404404
String[] withSubDirs = {
405405
FileUtil.getFontsDir(),
@@ -410,15 +410,15 @@ public int registerSystemDirectories() {
410410
"/usr/X11R6/lib/X11/fonts"
411411
};
412412
for (String directory : withSubDirs) {
413-
count += registerDirectory(directory, true);
413+
count += registerFontDirectory(directory, true);
414414
}
415415

416416
String[] withoutSubDirs = {
417417
"/Library/Fonts",
418418
"/System/Library/Fonts"
419419
};
420420
for (String directory : withoutSubDirs) {
421-
count += registerDirectory(directory, false);
421+
count += registerFontDirectory(directory, false);
422422
}
423423

424424
return count;
@@ -440,7 +440,7 @@ public Set<String> getRegisteredFonts() {
440440
* @return a set of registered font families
441441
*/
442442

443-
public Set<String> getRegisteredFamilies() {
443+
public Set<String> getRegisteredFontFamilies() {
444444
return fontFamilies.keySet();
445445
}
446446

@@ -449,7 +449,7 @@ public Set<String> getRegisteredFamilies() {
449449
* @param fontname the name of the font that has to be checked.
450450
* @return true if the font is found
451451
*/
452-
public boolean isRegistered(String fontname) {
452+
public boolean isRegisteredFont(String fontname) {
453453
return fontNames.containsKey(fontname.toLowerCase());
454454
}
455455
}

io/src/main/java/com/itextpdf/io/font/TrueTypeCollection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ public FontProgram getFontByTccIndex(int ttcIndex) throws java.io.IOException {
9090
}
9191

9292
if (ttcPath != null) {
93-
return FontFactory.createFont(ttcPath, ttcIndex, cached);
93+
return FontProgramFactory.createFont(ttcPath, ttcIndex, cached);
9494
} else {
95-
return FontFactory.createFont(ttc, ttcIndex, cached);
95+
return FontProgramFactory.createFont(ttc, ttcIndex, cached);
9696
}
9797
}
9898

io/src/main/java/com/itextpdf/io/image/ImageDataFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ public final class ImageDataFactory {
7070
private static final byte[] tiff_2 = new byte[]{'I', 'I', 42, 0};
7171
private static final byte[] jbig2 = new byte[]{(byte) 0x97, 'J', 'B', '2', '\r', '\n', 0x1a, '\n'};
7272

73+
private ImageDataFactory() {
74+
}
75+
7376
public static ImageData create(byte[] bytes, boolean recoverImage) {
7477
return createImageInstance(bytes, recoverImage);
7578
}

io/src/test/java/com/itextpdf/io/font/FontProgramTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ public class FontProgramTest {
1313
@Test
1414
public void exceptionMessageTest() throws IOException {
1515
try {
16-
FontFactory.createFont("some-font.ttf");
16+
FontProgramFactory.createFont("some-font.ttf");
1717
} catch (com.itextpdf.io.IOException ex) {
1818
Assert.assertEquals("font.file some-font.ttf not.found", ex.getMessage());
1919
}
2020
}
2121

2222
@Test
2323
public void boldTest() throws IOException {
24-
FontProgram fp = FontFactory.createFont(FontConstants.HELVETICA);
24+
FontProgram fp = FontProgramFactory.createFont(FontConstants.HELVETICA);
2525
fp.setBold(true);
2626
Assert.assertTrue("Bold expected", (fp.getPdfFontFlags() & (1 << 18)) != 0);
2727
fp.setBold(false);

kernel/src/main/java/com/itextpdf/kernel/font/DocType1Font.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ This file is part of the iText (R) project.
4545
package com.itextpdf.kernel.font;
4646

4747
import com.itextpdf.io.font.FontEncoding;
48-
import com.itextpdf.io.font.FontFactory;
48+
import com.itextpdf.io.font.FontProgramFactory;
4949
import com.itextpdf.io.font.Type1Font;
5050
import com.itextpdf.io.font.cmap.CMapToUnicode;
5151
import com.itextpdf.io.font.otf.Glyph;
@@ -81,7 +81,7 @@ static Type1Font createFontProgram(PdfDictionary fontDictionary, FontEncoding fo
8181
try {
8282
//if there are no font modifiers, cached font could be used,
8383
//otherwise a new instance should be created.
84-
type1StdFont = (Type1Font)FontFactory.createRegisteredFont(baseFont);
84+
type1StdFont = (Type1Font) FontProgramFactory.createRegisteredFont(baseFont);
8585
} catch (Exception e) {
8686
type1StdFont = null;
8787
}

0 commit comments

Comments
 (0)