Skip to content

Commit aa0c6fe

Browse files
committed
Revert "Improve font characteristics parsing at FontSelector level"
This reverts commit a0654a1.
1 parent 6c1b613 commit aa0c6fe

File tree

3 files changed

+12
-43
lines changed

3 files changed

+12
-43
lines changed

layout/src/main/java/com/itextpdf/layout/font/FontSelector.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,31 +130,31 @@ public int compare(FontInfo o1, FontInfo o2) {
130130
// It's important to mention that at the FontProvider level we add the default font-family
131131
// which is to be processed if for all provided font-families the score is 0.
132132
for (int i = 0; i < fontFamilies.size() && res == 0; i++) {
133-
final FontCharacteristics fc = fontStyles.get(i);
133+
FontCharacteristics fc = fontStyles.get(i);
134134
String fontFamily = fontFamilies.get(i);
135+
136+
if ("monospace".equalsIgnoreCase(fontFamily)) {
137+
fc.setMonospaceFlag(true);
138+
}
135139
boolean isLastFontFamilyToBeProcessed = i == fontFamilies.size() - 1;
136140
res = characteristicsSimilarity(fontFamily, fc, o2, isLastFontFamilyToBeProcessed) - characteristicsSimilarity(fontFamily, fc, o1, isLastFontFamilyToBeProcessed);
137141
}
138142
return res;
139143
}
140144

141-
private static FontCharacteristics parseFontStyle(String fontFamily, FontCharacteristics defaultFc) {
142-
if (defaultFc == null) {
143-
defaultFc = new FontCharacteristics();
145+
private static FontCharacteristics parseFontStyle(String fontFamily, FontCharacteristics fc) {
146+
if (fc == null) {
147+
fc = new FontCharacteristics();
144148
}
145-
final FontCharacteristics parsedFc = new FontCharacteristics(defaultFc);
146-
if (parsedFc.isUndefined()) {
147-
if ("monospace".equalsIgnoreCase(fontFamily)) {
148-
parsedFc.setMonospaceFlag(true);
149-
}
149+
if (fc.isUndefined()) {
150150
if (fontFamily.contains("bold")) {
151-
parsedFc.setBoldFlag(true);
151+
fc.setBoldFlag(true);
152152
}
153153
if (fontFamily.contains("italic") || fontFamily.contains("oblique")) {
154-
parsedFc.setItalicFlag(true);
154+
fc.setItalicFlag(true);
155155
}
156156
}
157-
return parsedFc;
157+
return fc;
158158
}
159159

160160
/**

layout/src/test/java/com/itextpdf/layout/FontSelectorTest.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,37 +1063,6 @@ public void openSansOutOfNotBoldFontWeightTest() {
10631063
new FontSelector(set.getFonts(), fontFamilies, fc).bestMatch().getDescriptor().getFontName());
10641064
}
10651065

1066-
@Test
1067-
public void fontCharacteristicIsUnmodifiedTest() {
1068-
FontSet set = getOpenSansFontSet();
1069-
1070-
List<String> fontFamilies = new ArrayList<>();
1071-
fontFamilies.add("OpenSans italic");
1072-
fontFamilies.add("OpenSans bold");
1073-
1074-
FontCharacteristics fc = new FontCharacteristics();
1075-
FontCharacteristics expectedFc = new FontCharacteristics(fc);
1076-
1077-
// previously font characteristics might have been updated while sorting fonts
1078-
new FontSelector(set.getFonts(), fontFamilies, fc);
1079-
1080-
Assert.assertEquals(expectedFc, fc);
1081-
}
1082-
1083-
@Test
1084-
public void fontCharacteristicsNullTest() {
1085-
FontSet set = getOpenSansFontSet();
1086-
1087-
List<String> fontFamilies = new ArrayList<>();
1088-
fontFamilies.add("test");
1089-
1090-
FontCharacteristics fc = null;
1091-
FontSelector fontSelector = new FontSelector(set.getFonts(), fontFamilies, fc);
1092-
1093-
// We expect default font characteristics to be used, e.g. as a result regular font must be the best
1094-
Assert.assertEquals("OpenSans-Regular", fontSelector.bestMatch().getDescriptor().getFontName());
1095-
}
1096-
10971066
private void checkSelector(Collection<FontInfo> fontInfoCollection, String fontFamily,
10981067
String expectedNormal, String expectedBold, String expectedItalic, String expectedBoldItalic) {
10991068
List<String> fontFamilies = new ArrayList<>();

0 commit comments

Comments
 (0)