]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-3057: Allow fallback to non svg glyphs
authorSimon Steiner <ssteiner@apache.org>
Thu, 24 Mar 2022 12:33:35 +0000 (12:33 +0000)
committerSimon Steiner <ssteiner@apache.org>
Thu, 24 Mar 2022 12:33:35 +0000 (12:33 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1899170 13f79535-47bb-0310-9956-ffa450edef68

fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
fop-core/src/main/java/org/apache/fop/render/pdf/PDFPainter.java
fop-core/src/main/java/org/apache/fop/render/ps/PSPainter.java
fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java

index fbcd16487735eb8fa839094d7ebd37dc4f67e141..85e8435ef932bbd8eeb9fd0a32e0dbcd6aea38d1 100644 (file)
@@ -476,8 +476,18 @@ public abstract class AbstractIFPainter<T extends IFDocumentHandler> implements
         drawText(x, y, letterSpacing, wordSpacing, dp, text);
     }
 
-    protected void drawSVGText(MultiByteFont multiByteFont, FontTriplet triplet, int x, int y, String text,
-                               IFState state) throws IFException {
+    protected boolean drawSVGText(MultiByteFont multiByteFont, FontTriplet triplet, int x, int y, String text,
+                                  IFState state) throws IFException {
+        for (int i = 0; i < text.length();) {
+            int codepoint = text.codePointAt(i);
+            if (!Character.isWhitespace(codepoint)) {
+                SVGGlyphData svg = multiByteFont.getSVG(codepoint);
+                if (svg == null) {
+                    return false;
+                }
+            }
+            i += Character.charCount(codepoint);
+        }
         int sizeMillipoints = state.getFontSize();
         Font font = getFontInfo().getFontInstance(triplet, sizeMillipoints);
         int newx = x;
@@ -497,5 +507,6 @@ public abstract class AbstractIFPainter<T extends IFDocumentHandler> implements
             newx += font.getCharWidth(c);
             i += Character.charCount(c);
         }
+        return true;
     }
 }
index 114cb7ae72c4b864b7119c1abf3f7c2dbed516d7..bf5f67894e71afacea0239e83825241fbec101d3 100644 (file)
@@ -435,8 +435,12 @@ public class PDFPainter extends AbstractIFPainter<PDFDocumentHandler> {
         String fontKey = getFontInfo().getInternalFontKey(triplet);
         Typeface typeface = getTypeface(fontKey);
         if (typeface instanceof MultiByteFont && ((MultiByteFont) typeface).hasSVG()) {
-            drawSVGText((MultiByteFont) typeface, triplet, x, y, text, state);
-        } else if ((dp == null) || IFUtil.isDPOnlyDX(dp)) {
+            boolean success = drawSVGText((MultiByteFont) typeface, triplet, x, y, text, state);
+            if (success) {
+                return;
+            }
+        }
+        if ((dp == null) || IFUtil.isDPOnlyDX(dp)) {
             drawTextWithDX(x, y, text, triplet, letterSpacing,
                              wordSpacing, IFUtil.convertDPToDX(dp));
         } else {
index a7f0f455fe0fc890c9ce01a953682b000b014c2c..2eadfcaec04d8dc2a253e2a50aee22f3fa3e8e5f 100644 (file)
@@ -363,8 +363,10 @@ public class PSPainter extends AbstractIFPainter<PSDocumentHandler> {
             String fontKey = getFontKey(triplet);
             Typeface typeface = getTypeface(fontKey);
             if (typeface instanceof MultiByteFont && ((MultiByteFont) typeface).hasSVG()) {
-                drawSVGText((MultiByteFont) typeface, triplet, x, y, text, state);
-                return;
+                boolean success = drawSVGText((MultiByteFont) typeface, triplet, x, y, text, state);
+                if (success) {
+                    return;
+                }
             }
             beginTextObject();
             //TODO Ignored: state.getFontVariant()
index f95e9f3e2b2879b7466c971bcc9f04d84d3dc7a5..9fe1972a1f3c4e0d5884b4003c9c2b76b4f4d4c2 100644 (file)
@@ -366,6 +366,20 @@ public class PDFPainterTestCase {
         Assert.assertTrue(out.contains("1 0 0 rg"));
     }
 
+    @Test
+    public void testSVGFontFallback() throws IFException, IOException {
+        String out = drawSVGFont(null);
+        Assert.assertEquals(out, "<< /Length 1 0 R >>\n"
+                + "stream\n"
+                + "q\n"
+                + "1 0 0 -1 0 0 cm\n"
+                + "BT\n"
+                + "/f1 0.012 Tf\n"
+                + "1 0 0 -1 0 0 Tm [<0000000000000000>] TJ\n"
+                + "\n"
+                + "endstream");
+    }
+
     @Test
     public void testSVGFontScale() throws IFException, IOException {
         String out = drawSVGFont("<svg xmlns=\"http://www.w3.org/2000/svg\">\n"
@@ -388,9 +402,11 @@ public class PDFPainterTestCase {
         MultiByteFont font = new MultiByteFont(null, null);
         font.setWidthArray(new int[1]);
         Map<Integer, SVGGlyphData> svgs = new HashMap<>();
-        SVGGlyphData svgGlyph = new SVGGlyphData();
-        svgGlyph.setSVG(svg);
-        svgs.put(0, svgGlyph);
+        if (svg != null) {
+            SVGGlyphData svgGlyph = new SVGGlyphData();
+            svgGlyph.setSVG(svg);
+            svgs.put(0, svgGlyph);
+        }
         font.setSVG(svgs);
         font.setBBoxArray(new Rectangle[] {new Rectangle()});
         fi.addMetrics("f1", font);