aboutsummaryrefslogtreecommitdiffstats
path: root/fop-core/src
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2022-03-24 12:33:35 +0000
committerSimon Steiner <ssteiner@apache.org>2022-03-24 12:33:35 +0000
commita6adcb5046713803e441beb25cd9f7c3260e00fd (patch)
tree20c7fbaeb507df8bbfc445d67922d11d1a6cc2ae /fop-core/src
parentef84640cc1f7020a4d2090923ea0e35be45a6743 (diff)
downloadxmlgraphics-fop-a6adcb5046713803e441beb25cd9f7c3260e00fd.tar.gz
xmlgraphics-fop-a6adcb5046713803e441beb25cd9f7c3260e00fd.zip
FOP-3057: Allow fallback to non svg glyphs
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1899170 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'fop-core/src')
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java15
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/pdf/PDFPainter.java8
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/ps/PSPainter.java6
-rw-r--r--fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java22
4 files changed, 42 insertions, 9 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java b/fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
index fbcd16487..85e8435ef 100644
--- a/fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
+++ b/fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
@@ -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;
}
}
diff --git a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFPainter.java b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFPainter.java
index 114cb7ae7..bf5f67894 100644
--- a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFPainter.java
+++ b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFPainter.java
@@ -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 {
diff --git a/fop-core/src/main/java/org/apache/fop/render/ps/PSPainter.java b/fop-core/src/main/java/org/apache/fop/render/ps/PSPainter.java
index a7f0f455f..2eadfcaec 100644
--- a/fop-core/src/main/java/org/apache/fop/render/ps/PSPainter.java
+++ b/fop-core/src/main/java/org/apache/fop/render/ps/PSPainter.java
@@ -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()
diff --git a/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java b/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java
index f95e9f3e2..9fe1972a1 100644
--- a/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java
+++ b/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java
@@ -367,6 +367,20 @@ public class PDFPainterTestCase {
}
@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"
+ "<g transform=\"translate(0 0) translate(0 0) scale(50)\"/>"
@@ -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);