Skip to content

Commit 34b48c4

Browse files
authored
GH-427 font substitution tweaks (#432)
1 parent ab946c4 commit 34b48c4

File tree

3 files changed

+36
-26
lines changed

3 files changed

+36
-26
lines changed

core/core-awt/src/main/java/org/icepdf/core/pobjects/fonts/FontManager.java

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* more fonts which is extremely important on Linux systems.</p>
3838
* <p>It is possible to specify other directories to search for fonts via the
3939
* readSystemFonts methods extraFontPaths parameter {@link #readSystemFonts}.
40-
* Reading all of an operating systems font's can be time consuming. To help
40+
* Reading all of an operating systems font's can be time-consuming. To help
4141
* speed up this process the method getFontProperties exports font data via a
4242
* Properties object. The font Properties object can then be saved to disk or
4343
* be read back into the FontManager via the setFontProperties method. </p>
@@ -68,19 +68,29 @@ public class FontManager {
6868
{"Bookman-Light", "URWBookmanL-Ligh", "Arial"},
6969
{"Bookman-LightItalic", "URWBookmanL-LighItal", "Arial"},
7070
{"Courier", "NimbusMonL-Regu", "Nimbus Mono L", "CourierNew", "CourierNewPSMT"},
71-
{"Courier-Oblique", "NimbusMonL-ReguObli", "Nimbus Mono L", "Courier,Italic", "CourierNew-Italic", "CourierNew,Italic", "CourierNewPS-ItalicMT"},
72-
{"Courier-Bold", "NimbusMonL-Bold", "Nimbus Mono L", "Courier,Bold", "CourierNew,Bold", "CourierNew-Bold", "CourierNewPS-BoldMT"},
73-
{"Courier-BoldOblique", "NimbusMonL-BoldObli", "Nimbus Mono L", "Courier,BoldItalic", "CourierNew-BoldItalic", "CourierNew,BoldItalic", "CourierNewPS-BoldItalicMT"},
71+
{"Courier-Oblique", "NimbusMonL-ReguObli", "Nimbus Mono L", "Courier,Italic", "CourierNew-Italic"
72+
, "CourierNew,Italic", "CourierNewPS-ItalicMT"},
73+
{"Courier-Bold", "NimbusMonL-Bold", "Nimbus Mono L", "Courier,Bold", "CourierNew,Bold",
74+
"CourierNew-Bold", "CourierNewPS-BoldMT"},
75+
{"Courier-BoldOblique", "NimbusMonL-BoldObli", "Nimbus Mono L", "Courier,BoldItalic", "CourierNew" +
76+
"-BoldItalic", "CourierNew,BoldItalic", "CourierNewPS-BoldItalicMT"},
7477
{"AvantGarde-Book", "URWGothicL-Book", "Arial"},
7578
{"AvantGarde-BookOblique", "URWGothicL-BookObli", "Arial"},
7679
{"AvantGarde-Demi", "URWGothicL-Demi", "Arial"},
7780
{"AvantGarde-DemiOblique", "URWGothicL-DemiObli", "Arial"},
7881
{"Helvetica", "Helvetica", "Arial", "ArialMT", "NimbusSanL-Regu", "Nimbus Sans L"},
79-
{"Helvetica-Oblique", "NimbusSanL-ReguItal", "Nimbus Sans L", "Helvetica,Italic", "Helvetica-Italic", "Arial,Italic", "Arial-Italic", "Arial-ItalicMT"},
80-
{"Helvetica-Bold", "Helvetica,Bold", "Arial,Bold", "Arial-Bold", "Arial-BoldMT", "NimbusSanL-Bold", "Nimbus Sans L"},
81-
{"Helvetica-BoldOblique", "NimbusSanL-BoldItal", "Helvetica-BlackOblique", "Nimbus Sans L", "Helvetica,BoldItalic", "Helvetica-BoldItalic", "Arial,BoldItalic", "Arial-BoldItalic", "Arial-BoldItalicMT"},
82-
{"Helvetica-Black", "Helvetica,Bold", "Arial,Bold", "Arial-Bold", "Arial-BoldMT", "NimbusSanL-Bold", "Nimbus Sans L"},
83-
{"Helvetica-BlackOblique", "NimbusSanL-BoldItal", "Helvetica-BlackOblique", "Nimbus Sans L", "Helvetica,BoldItalic", "Helvetica-BoldItalic", "Arial,BoldItalic", "Arial-BoldItalic", "Arial-BoldItalicMT"},
82+
{"Helvetica-Oblique", "NimbusSanL-ReguItal", "Nimbus Sans L", "Helvetica,Italic", "Helvetica" +
83+
"-Italic", "Arial,Italic", "Arial-Italic", "Arial-ItalicMT"},
84+
{"Helvetica-Bold", "Helvetica,Bold", "Arial,Bold", "Arial-Bold", "Arial-BoldMT", "NimbusSanL-Bold"
85+
, "Nimbus Sans L"},
86+
{"Helvetica-BoldOblique", "NimbusSanL-BoldItal", "Helvetica-BlackOblique", "Nimbus Sans L",
87+
"Helvetica,BoldItalic", "Helvetica-BoldItalic", "Arial,BoldItalic", "Arial-BoldItalic",
88+
"Arial-BoldItalicMT"},
89+
{"Helvetica-Black", "Helvetica,Bold", "Arial,Bold", "Arial-Bold", "Arial-BoldMT", "NimbusSanL" +
90+
"-Bold", "Nimbus Sans L"},
91+
{"Helvetica-BlackOblique", "NimbusSanL-BoldItal", "Helvetica-BlackOblique", "Nimbus Sans L",
92+
"Helvetica,BoldItalic", "Helvetica-BoldItalic", "Arial,BoldItalic", "Arial-BoldItalic",
93+
"Arial-BoldItalicMT"},
8494
{"Helvetica-Narrow", "NimbusSanL-ReguCond", "Nimbus Sans L"},
8595
{"Helvetica-Narrow-Oblique", "NimbusSanL-ReguCondItal", "Nimbus Sans L"},
8696
{"Helvetica-Narrow-Bold", "NimbusSanL-BoldCond", "Nimbus Sans L"},
@@ -97,10 +107,14 @@ public class FontManager {
97107
{"NewCenturySchlbk-Italic", "CenturySchL-Ital", "Arial"},
98108
{"NewCenturySchlbk-Bold", "CenturySchL-Bold", "Arial"},
99109
{"NewCenturySchlbk-BoldItalic", "CenturySchL-BoldItal", "Arial"},
100-
{"Times-Roman", "NimbusRomNo9L-Regu", "Nimbus Roman No9 L", "TimesNewRoman", "TimesNewRomanPSMT", "TimesNewRomanPS"},
101-
{"Times-Italic", "NimbusRomNo9L-ReguItal", "Nimbus Roman No9 L", "TimesNewRoman,Italic", "TimesNewRoman-Italic", "TimesNewRomanPS-Italic", "TimesNewRomanPS-ItalicMT"},
102-
{"Times-Bold", "NimbusRomNo9L-Medi", "Nimbus Roman No9 L", "TimesNewRoman,Bold", "TimesNewRoman-Bold", "TimesNewRomanPS-Bold", "TimesNewRomanPS-BoldMT"},
103-
{"Times-BoldItalic", "NimbusRomNo9L-MediItal", "Nimbus Roman No9 L", "TimesNewRoman,BoldItalic", "TimesNewRoman-BoldItalic", "TimesNewRomanPS-BoldItalic", "TimesNewRomanPS-BoldItalicMT"},
110+
{"Times-Roman", "NimbusRomNo9L-Regu", "Nimbus Roman No9 L", "TimesNewRoman", "TimesNewRomanPSMT",
111+
"TimesNewRomanPS"},
112+
{"Times-Italic", "NimbusRomNo9L-ReguItal", "Nimbus Roman No9 L", "TimesNewRoman,Italic",
113+
"TimesNewRoman-Italic", "TimesNewRomanPS-Italic", "TimesNewRomanPS-ItalicMT"},
114+
{"Times-Bold", "NimbusRomNo9L-Medi", "Nimbus Roman No9 L", "TimesNewRoman,Bold", "TimesNewRoman" +
115+
"-Bold", "TimesNewRomanPS-Bold", "TimesNewRomanPS-BoldMT"},
116+
{"Times-BoldItalic", "NimbusRomNo9L-MediItal", "Nimbus Roman No9 L", "TimesNewRoman,BoldItalic",
117+
"TimesNewRoman-BoldItalic", "TimesNewRomanPS-BoldItalic", "TimesNewRomanPS-BoldItalicMT"},
104118
{"Symbol", "StandardSymL", "Standard Symbols L"},
105119
{"ZapfChancery-MediumItalic", "URWChanceryL-MediItal", "Arial"},
106120
{"ZapfDingbats", "Dingbats", "Zapf-Dingbats"}
@@ -191,11 +205,12 @@ public class FontManager {
191205
"opensymbol",
192206
"starsymbol",
193207
"symbolmt",
208+
"notosanssymbols",
194209
"arial-black",
195210
"arial-blackitalic",
196211
"new",
197212
// mapping issue with standard ascii, not sure why, TimesNewRomanPSMT is ok.
198-
"timesnewromanps",
213+
// "timesnewromanps",
199214
// doesn't seem to the correct cid mapping otf version anyways.
200215
"kozminpro-regular"
201216
);
@@ -344,7 +359,8 @@ public void clearFontList() {
344359
}
345360

346361
/**
347-
* <p>Reads font from the specified array of file paths only, no . This font data is used to substitute fonts which are not
362+
* <p>Reads font from the specified array of file paths only, no . This font data is used to substitute fonts
363+
* which are not
348364
* embedded inside a PDF document.</p>
349365
*
350366
* @param extraFontPaths array String object where each entry represents
@@ -585,7 +601,7 @@ private FontFile getAsianInstance(List<Object[]> fontList, String name, String[]
585601
fontList = new ArrayList<>(150);
586602
}
587603

588-
FontFile font = null;
604+
FontFile font;
589605
if (list != null) {
590606
// search for know list of fonts
591607
for (int i = list.length - 1; i >= 0; i--) {
@@ -796,7 +812,7 @@ private FontFile findFont(List<Object[]> fontList, String fontName, int flags) {
796812
for (int i = fontList.size() - 1; i >= 0; i--) {
797813
fontData = fontList.get(i);
798814
baseName = (String) fontData[FONT_NAME];
799-
familyName = (String) fontData[FONT_FAMILY];
815+
familyName = ((String) fontData[FONT_FAMILY]).replaceAll("(?i)(psmt|ps|mt)$", "");
800816
path = (String) fontData[FONT_PATH];
801817
if (logger.isLoggable(Level.FINEST)) {
802818
logger.finest(baseName + " : " + familyName + " : " + name);

core/core-awt/src/main/java/org/icepdf/core/util/FontUtil.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,21 +131,14 @@ public static String removeBaseFontSubset(String name) {
131131
}
132132

133133
/**
134-
* Utility method for normailing strings, to lowercase and remove any spaces.
134+
* Utility method for normalizing strings, to lowercase and remove any spaces.
135135
*
136136
* @param name base name of font
137137
* @return normalized copy of string.
138138
*/
139139
public static String normalizeString(String name) {
140140
name = guessFamily(name);
141-
StringBuilder normalized = new StringBuilder(name.toLowerCase());
142-
for (int k = normalized.length() - 1; k >= 0; k--) {
143-
if (normalized.charAt(k) == 32) {
144-
normalized.deleteCharAt(k);
145-
k--;
146-
}
147-
}
148-
return normalized.toString();
141+
return name.toLowerCase().replaceAll("\\s+", "");
149142
}
150143

151144
}

viewer/viewer-awt/src/main/java/org/icepdf/ri/util/FontPropertiesManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public void loadProperties() {
128128
public void clearProperties() {
129129
try {
130130
prefs.clear();
131+
fontManager.clearFontList();
131132
} catch (BackingStoreException e) {
132133
if (logger.isLoggable(Level.WARNING)) {
133134
logger.log(Level.WARNING, "Error reading system paths:", e);

0 commit comments

Comments
 (0)