xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gad...@apache.org
Subject svn commit: r1342792 - in /xmlgraphics/fop/trunk: src/java/org/apache/fop/render/ps/PSPainter.java status.xml test/java/org/apache/fop/render/ps/PSPainterTestCase.java
Date Fri, 25 May 2012 20:02:21 GMT
Author: gadams
Date: Fri May 25 20:02:21 2012
New Revision: 1342792

URL: http://svn.apache.org/viewvc?rev=1342792&view=rev
Log:
Bugzilla #53294: Fix invalid PostScript file being created when font-size is 0. Submitted
by Robert Meyer.

Added:
    xmlgraphics/fop/trunk/test/java/org/apache/fop/render/ps/PSPainterTestCase.java
Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java
    xmlgraphics/fop/trunk/status.xml

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java?rev=1342792&r1=1342791&r2=1342792&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java Fri May 25 20:02:21
2012
@@ -74,10 +74,14 @@ public class PSPainter extends AbstractI
      * @param documentHandler the parent document handler
      */
     public PSPainter(PSDocumentHandler documentHandler) {
+        this(documentHandler, IFState.create());
+    }
+
+    protected PSPainter(PSDocumentHandler documentHandler, IFState state) {
         super();
         this.documentHandler = documentHandler;
         this.borderPainter = new PSBorderPainter(documentHandler.gen);
-        this.state = IFState.create();
+        this.state = state;
     }
 
     /** {@inheritDoc} */
@@ -346,6 +350,10 @@ public class PSPainter extends AbstractI
     public void drawText(int x, int y, int letterSpacing, int wordSpacing,
             int[][] dp, String text) throws IFException {
         try {
+            //Do not draw text if font-size is 0 as it creates an invalid PostScript file
+            if (state.getFontSize() == 0) {
+                return;
+            }
             PSGenerator generator = getGenerator();
             generator.useColor(state.getTextColor());
             beginTextObject();

Modified: xmlgraphics/fop/trunk/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=1342792&r1=1342791&r2=1342792&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Fri May 25 20:02:21 2012
@@ -63,6 +63,9 @@
       documents. Example: the fix of marks layering will be such a case when it's done.
     -->
     <release version="FOP Trunk" date="TBD">
+      <action context="Renderers" dev="GA" type="fix" fixes-bug="53294" due-to="Robert
Meyer">
+        Fix invalid PostScript file being created when font-size is 0.
+      </action>
       <action context="Docs" dev="GA" type="update">
         Update FAQ and New Bug documentation.
       </action>

Added: xmlgraphics/fop/trunk/test/java/org/apache/fop/render/ps/PSPainterTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/render/ps/PSPainterTestCase.java?rev=1342792&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/render/ps/PSPainterTestCase.java (added)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/render/ps/PSPainterTestCase.java Fri May
25 20:02:21 2012
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.fop.render.ps;
+
+import java.io.IOException;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.verification.VerificationMode;
+
+import org.apache.xmlgraphics.ps.PSGenerator;
+
+import org.apache.fop.render.intermediate.IFState;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+public class PSPainterTestCase {
+
+    private PSDocumentHandler docHandler;
+    private PSPainter psPainter;
+    private PSGenerator gen;
+    private IFState state;
+
+    @Before
+    public void setup() {
+        docHandler = new PSDocumentHandler();
+        gen = mock(PSGenerator.class);
+        docHandler.gen = gen;
+        state = IFState.create();
+        psPainter = new PSPainter(docHandler, state);
+    }
+
+    @Test
+    public void testNonZeroFontSize() throws IOException {
+        testFontSize(6, times(1));
+    }
+
+    @Test
+    public void testZeroFontSize() throws IOException {
+        testFontSize(0, never());
+    }
+
+    private void testFontSize(int fontSize, VerificationMode test) throws IOException {
+        state.setFontSize(fontSize);
+        try {
+            psPainter.drawText(10, 10, 2, 2, null, "Test");
+        } catch (Exception ex) {
+            //Expected
+        }
+        verify(gen, test).useColor(state.getTextColor());
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org


Mime
View raw message