]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-3148: NoSuchElementException when using font with no family name
authorSimon Steiner <ssteiner@apache.org>
Wed, 13 Sep 2023 11:43:32 +0000 (12:43 +0100)
committerSimon Steiner <ssteiner@apache.org>
Wed, 13 Sep 2023 11:43:32 +0000 (12:43 +0100)
fop-core/src/main/java/org/apache/fop/svg/font/FOPFontFamilyResolverImpl.java
fop-core/src/test/java/org/apache/fop/svg/font/FOPFontFamilyResolverTestCase.java

index 4305838daea1e1df9858b124185a1d8c9b92a5a3..a4e74357191af3c9f584e6c0252cc155d8ee1459 100644 (file)
@@ -21,6 +21,7 @@ package org.apache.fop.svg.font;
 
 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;
@@ -68,7 +69,11 @@ public class FOPFontFamilyResolverImpl implements FOPFontFamilyResolver {
         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));
index d14752b90a12f60ceba1ce5f712734fc48c62dab..4376779f98f2045348e603a022175fd69dabbd32 100644 (file)
@@ -42,6 +42,7 @@ import static org.junit.Assert.assertTrue;
 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 {
@@ -79,6 +80,14 @@ public class FOPFontFamilyResolverTestCase {
         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);