aboutsummaryrefslogtreecommitdiffstats
path: root/fop-core
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2023-09-13 12:43:32 +0100
committerSimon Steiner <ssteiner@apache.org>2023-09-13 12:43:32 +0100
commit7f01c67a96493fc5d6275a25414dd0841a2617b9 (patch)
tree9c3373da03d66a1da8d41373ed4cb8c005b22553 /fop-core
parentfa89ae7b7a349d7f015b6eeb650a839979a8eed0 (diff)
downloadxmlgraphics-fop-7f01c67a96493fc5d6275a25414dd0841a2617b9.tar.gz
xmlgraphics-fop-7f01c67a96493fc5d6275a25414dd0841a2617b9.zip
FOP-3148: NoSuchElementException when using font with no family name
Diffstat (limited to 'fop-core')
-rw-r--r--fop-core/src/main/java/org/apache/fop/svg/font/FOPFontFamilyResolverImpl.java7
-rw-r--r--fop-core/src/test/java/org/apache/fop/svg/font/FOPFontFamilyResolverTestCase.java9
2 files changed, 15 insertions, 1 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/svg/font/FOPFontFamilyResolverImpl.java b/fop-core/src/main/java/org/apache/fop/svg/font/FOPFontFamilyResolverImpl.java
index 4305838da..a4e743571 100644
--- a/fop-core/src/main/java/org/apache/fop/svg/font/FOPFontFamilyResolverImpl.java
+++ b/fop-core/src/main/java/org/apache/fop/svg/font/FOPFontFamilyResolverImpl.java
@@ -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));
diff --git a/fop-core/src/test/java/org/apache/fop/svg/font/FOPFontFamilyResolverTestCase.java b/fop-core/src/test/java/org/apache/fop/svg/font/FOPFontFamilyResolverTestCase.java
index d14752b90..4376779f9 100644
--- a/fop-core/src/test/java/org/apache/fop/svg/font/FOPFontFamilyResolverTestCase.java
+++ b/fop-core/src/test/java/org/apache/fop/svg/font/FOPFontFamilyResolverTestCase.java
@@ -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 {
@@ -80,6 +81,14 @@ public class FOPFontFamilyResolverTestCase {
}
@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);
FOPGVTFont font = family.deriveFont(10, Collections.emptyMap());