Skip to content

Commit

Permalink
FOP-3148: NoSuchElementException when using font with no family name
Browse files Browse the repository at this point in the history
  • Loading branch information
simonsteiner1984 committed Sep 13, 2023
1 parent fa89ae7 commit 7f01c67
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.io.InputStream;
import java.util.Map;
import java.util.Set;

import org.apache.batik.bridge.FontFace;
import org.apache.batik.gvt.font.GVTFontFace;
Expand Down Expand Up @@ -68,7 +69,11 @@ public FOPGVTFontFamily getFamilyThatCanDisplay(char c) {
Map<String, Typeface> fonts = fontInfo.getFonts();
for (Typeface font : fonts.values()) {
if (font.hasChar(c)) {
String fontFamily = font.getFamilyNames().iterator().next();
Set<String> familyNames = font.getFamilyNames();
String fontFamily = font.getFontName();
if (!familyNames.isEmpty()) {
fontFamily = familyNames.iterator().next();
}
return new FOPGVTFontFamily(fontInfo, fontFamily,
new FontTriplet(fontFamily, Font.STYLE_NORMAL, Font.WEIGHT_NORMAL),
new GVTFontFace(fontFamily));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.apache.batik.gvt.font.GVTFontFamily;
import org.apache.batik.gvt.font.GVTLineMetrics;

import org.apache.fop.fonts.CustomFont;
import org.apache.fop.fonts.FontInfo;

public class FOPFontFamilyResolverTestCase {
Expand Down Expand Up @@ -79,6 +80,14 @@ public void testGetFamilyThatCanDisplay() {
assertNull(family);
}

@Test
public void testGetFamilyThatCanDisplayNoFamily() {
CustomFont font = (CustomFont) fontInfo.getFonts().values().iterator().next();
font.setFamilyNames(Collections.<String>emptySet());
GVTFontFamily family = resolver.getFamilyThatCanDisplay('\u0180');
assertEquals(font.getFontName(), family.getFamilyName());
}

@Test
public void testDeriveFont() {
FOPGVTFontFamily family = resolver.resolve(FontInfoBuilder.DEJAVU_LGC_SERIF);
Expand Down

0 comments on commit 7f01c67

Please sign in to comment.