Author: ssteiner Date: Tue Feb 2 14:48:54 2021 New Revision: 1886124 URL: http://svn.apache.org/viewvc?rev=1886124&view=rev Log: FOP-2997: Double byte glyphs not working in SVG font
Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/MultiByteFont.java xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/truetype/SVGGlyphData.java xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/MultiByteFont.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/MultiByteFont.java?rev=1886124&r1=1886123&r2=1886124&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/MultiByteFont.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/MultiByteFont.java Tue Feb 2 14:48:54 2021 @@ -859,7 +859,7 @@ public class MultiByteFont extends CIDFo return null; } - public SVGGlyphData getSVG(char c) { + public SVGGlyphData getSVG(int c) { int gid = findGlyphIndex(c); return svgs.get(gid); } Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/truetype/SVGGlyphData.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/truetype/SVGGlyphData.java?rev=1886124&r1=1886123&r2=1886124&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/truetype/SVGGlyphData.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/truetype/SVGGlyphData.java Tue Feb 2 14:48:54 2021 @@ -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"); Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java?rev=1886124&r1=1886123&r2=1886124&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java Tue Feb 2 14:48:54 2021 @@ -478,7 +478,8 @@ public abstract class AbstractIFPainter< 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< drawImage(dataURL, boundingBox); } newx += font.getCharWidth(c); + i += Character.charCount(c); } } } Modified: xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java?rev=1886124&r1=1886123&r2=1886124&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java Tue Feb 2 14:48:54 2021 @@ -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(); } } --------------------------------------------------------------------- To unsubscribe, e-mail: fop-commits-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: fop-commits-h...@xmlgraphics.apache.org