aboutsummaryrefslogtreecommitdiffstats
path: root/fop-core
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2021-02-02 14:48:54 +0000
committerSimon Steiner <ssteiner@apache.org>2021-02-02 14:48:54 +0000
commitd6a1aadd0d30263130cf746dd6b5f8b5b70d5348 (patch)
tree4f5e523d0b49583a24eb7bbd18e47a794e6e3d08 /fop-core
parent7e69c3661a8d009078600ea9acc091c84eb849fd (diff)
downloadxmlgraphics-fop-d6a1aadd0d30263130cf746dd6b5f8b5b70d5348.tar.gz
xmlgraphics-fop-d6a1aadd0d30263130cf746dd6b5f8b5b70d5348.zip
FOP-2997: Double byte glyphs not working in SVG font
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1886124 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'fop-core')
-rw-r--r--fop-core/src/main/java/org/apache/fop/fonts/MultiByteFont.java2
-rw-r--r--fop-core/src/main/java/org/apache/fop/fonts/truetype/SVGGlyphData.java2
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java4
-rw-r--r--fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java25
4 files changed, 25 insertions, 8 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/fonts/MultiByteFont.java b/fop-core/src/main/java/org/apache/fop/fonts/MultiByteFont.java
index 4f1263ebe..929b4bf6f 100644
--- a/fop-core/src/main/java/org/apache/fop/fonts/MultiByteFont.java
+++ b/fop-core/src/main/java/org/apache/fop/fonts/MultiByteFont.java
@@ -859,7 +859,7 @@ public class MultiByteFont extends CIDFont implements Substitutable, Positionabl
return null;
}
- public SVGGlyphData getSVG(char c) {
+ public SVGGlyphData getSVG(int c) {
int gid = findGlyphIndex(c);
return svgs.get(gid);
}
diff --git a/fop-core/src/main/java/org/apache/fop/fonts/truetype/SVGGlyphData.java b/fop-core/src/main/java/org/apache/fop/fonts/truetype/SVGGlyphData.java
index e46e50074..d018f5bf2 100644
--- a/fop-core/src/main/java/org/apache/fop/fonts/truetype/SVGGlyphData.java
+++ b/fop-core/src/main/java/org/apache/fop/fonts/truetype/SVGGlyphData.java
@@ -70,7 +70,7 @@ public class SVGGlyphData {
Element gElement = (Element) nodes.item(0);
if (gElement != null) {
String transform = gElement.getAttribute("transform");
- if (transform.contains("scale(")) {
+ if (transform.split("scale\\(").length == 3) {
String scaleStr = transform.split("scale\\(")[1].split("\\)")[0].trim();
scale = Float.parseFloat(scaleStr);
gElement.removeAttribute("transform");
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 44620ff61..e9499f881 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
@@ -478,7 +478,8 @@ public abstract class AbstractIFPainter<T extends IFDocumentHandler> implements
int sizeMillipoints = state.getFontSize();
Font font = getFontInfo().getFontInstance(triplet, sizeMillipoints);
int newx = x;
- for (char c : text.toCharArray()) {
+ for (int i = 0; i < text.length();) {
+ int c = text.codePointAt(i);
SVGGlyphData svg = multiByteFont.getSVG(c);
if (svg != null) {
int codePoint = font.mapCodePoint(c);
@@ -491,6 +492,7 @@ public abstract class AbstractIFPainter<T extends IFDocumentHandler> implements
drawImage(dataURL, boundingBox);
}
newx += font.getCharWidth(c);
+ i += Character.charCount(c);
}
}
}
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 aa0274d97..1fe4a76df 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
@@ -311,6 +311,24 @@ public class PDFPainterTestCase {
@Test
public void testSVGFont() throws IFException, IOException {
+ String out = drawSVGFont("<svg xmlns=\"http://www.w3.org/2000/svg\">\n"
+ + "<circle cx=\"50\" cy=\"50\" r=\"40\" stroke=\"black\" stroke-width=\"3\" fill=\"red\" />\n"
+ + "</svg>");
+ Assert.assertTrue(out.contains("0.00012 0 0 0.00012 0 0 cm"));
+ Assert.assertTrue(out.contains("1 0 0 rg"));
+ }
+
+ @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)\"/>"
+ + "<circle cx=\"50\" cy=\"50\" r=\"40\" stroke=\"black\" stroke-width=\"3\" fill=\"red\" />\n"
+ + "</svg>");
+ Assert.assertTrue(out.contains("0.00012 0 0 0.00012 0 0 cm"));
+ Assert.assertTrue(out.contains("1 0 0 rg"));
+ }
+
+ private String drawSVGFont(String svg) throws IFException, IOException {
FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI());
foUserAgent = fopFactory.newFOUserAgent();
PDFDocumentHandler pdfDocumentHandler = new PDFDocumentHandler(new IFContext(foUserAgent));
@@ -323,9 +341,7 @@ public class PDFPainterTestCase {
font.setWidthArray(new int[1]);
Map<Integer, SVGGlyphData> svgs = new HashMap<>();
SVGGlyphData svgGlyph = new SVGGlyphData();
- svgGlyph.setSVG("<svg xmlns=\"http://www.w3.org/2000/svg\">\n"
- + "<circle cx=\"50\" cy=\"50\" r=\"40\" stroke=\"black\" stroke-width=\"3\" fill=\"red\" />\n"
- + "</svg>");
+ svgGlyph.setSVG(svg);
svgs.put(0, svgGlyph);
font.setSVG(svgs);
font.setBBoxArray(new Rectangle[] {new Rectangle()});
@@ -338,7 +354,6 @@ public class PDFPainterTestCase {
filters.setDisableAllFilters(true);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
pdfPainter.generator.getStream().output(bos);
- Assert.assertTrue(bos.toString().contains("0.00012 0 0 0.00012 0 0 cm"));
- Assert.assertTrue(bos.toString().contains("1 0 0 rg"));
+ return bos.toString();
}
}