From 0cd45a6cbb6e76f94d1e6fdcb287cdeaa8e68c99 Mon Sep 17 00:00:00 2001 From: Simon Steiner Date: Wed, 27 May 2020 11:48:14 +0000 Subject: [PATCH] FOP-2941: SVG container with stroke=black has an unexpected border git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1878158 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/render/ps/PSTextPainter.java | 3 +++ .../apache/fop/svg/NativeTextPainterTest.java | 3 ++- .../apache/fop/svg/PSTextPainterTestCase.java | 17 ++++++++++++----- .../resources/org/apache/fop/svg/watermark.svg | 9 +++++++++ 4 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 fop-core/src/test/resources/org/apache/fop/svg/watermark.svg diff --git a/fop-core/src/main/java/org/apache/fop/render/ps/PSTextPainter.java b/fop-core/src/main/java/org/apache/fop/render/ps/PSTextPainter.java index 57397efc6..8c643b7a5 100644 --- a/fop-core/src/main/java/org/apache/fop/render/ps/PSTextPainter.java +++ b/fop-core/src/main/java/org/apache/fop/render/ps/PSTextPainter.java @@ -420,6 +420,9 @@ public class PSTextPainter extends NativeTextPainter { private void paintStrokedGlyphs(PSGraphics2D g2d, TextUtil textUtil, Paint strokePaint, Stroke stroke) throws IOException { + if (currentGlyphs.toString().trim().isEmpty()) { + return; + } applyColor(strokePaint); PSGraphics2D.applyStroke(stroke, gen); diff --git a/fop-core/src/test/java/org/apache/fop/svg/NativeTextPainterTest.java b/fop-core/src/test/java/org/apache/fop/svg/NativeTextPainterTest.java index 5344e6a54..aa3019c9c 100644 --- a/fop-core/src/test/java/org/apache/fop/svg/NativeTextPainterTest.java +++ b/fop-core/src/test/java/org/apache/fop/svg/NativeTextPainterTest.java @@ -40,13 +40,14 @@ import org.apache.fop.svg.font.FOPFontFamilyResolverImpl; abstract class NativeTextPainterTest { - protected final void runTest(String testcase, OperatorValidator validator) throws Exception { + protected final Graphics2D runTest(String testcase, OperatorValidator validator) throws Exception { FontInfo fontInfo = createFontInfo(); BridgeContext bridgeContext = createBridgeContext(fontInfo); GraphicsNode svg = loadSVG(bridgeContext, testcase); Graphics2D g2d = createGraphics2D(fontInfo, validator); svg.paint(g2d); validator.end(); + return g2d; } private FontInfo createFontInfo() { diff --git a/fop-core/src/test/java/org/apache/fop/svg/PSTextPainterTestCase.java b/fop-core/src/test/java/org/apache/fop/svg/PSTextPainterTestCase.java index 2b716e348..7a2eb7027 100644 --- a/fop-core/src/test/java/org/apache/fop/svg/PSTextPainterTestCase.java +++ b/fop-core/src/test/java/org/apache/fop/svg/PSTextPainterTestCase.java @@ -20,12 +20,13 @@ package org.apache.fop.svg; import java.awt.Graphics2D; +import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.OutputStream; +import org.junit.Assert; import org.junit.Test; -import org.apache.commons.io.output.NullOutputStream; - import org.apache.batik.bridge.TextPainter; import org.apache.xmlgraphics.java2d.GraphicContext; @@ -40,13 +41,12 @@ public class PSTextPainterTestCase extends NativeTextPainterTest { private static class OperatorCheckingPSGraphics2D extends PSGraphics2D { OperatorCheckingPSGraphics2D(FontInfo fontInfo, final OperatorValidator validator) { - super(false, new PSGenerator(new NullOutputStream()) { - + super(false, new PSGenerator(new ByteArrayOutputStream()) { @Override public void writeln(String cmd) throws IOException { + super.writeln(cmd); validator.check(cmd); } - }); } } @@ -74,4 +74,11 @@ public class PSTextPainterTestCase extends NativeTextPainterTest { .addOperatorMatch("xshow", "(C)\n[0] xshow")); } + @Test + public void testWatermark() throws Exception { + PSGraphics2D g2d = (PSGraphics2D) runTest("watermark.svg", + new OperatorValidator().addOperatorMatch("GS", "GS")); + OutputStream os = g2d.getPSGenerator().getOutputStream(); + Assert.assertFalse(os.toString().contains("( ) false charpath")); + } } diff --git a/fop-core/src/test/resources/org/apache/fop/svg/watermark.svg b/fop-core/src/test/resources/org/apache/fop/svg/watermark.svg new file mode 100644 index 000000000..fc2c6d97e --- /dev/null +++ b/fop-core/src/test/resources/org/apache/fop/svg/watermark.svg @@ -0,0 +1,9 @@ + + + + + + Copy + + + -- 2.39.5