]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-2919: NPE printing
authorSimon Steiner <ssteiner@apache.org>
Wed, 22 Jul 2020 11:11:17 +0000 (11:11 +0000)
committerSimon Steiner <ssteiner@apache.org>
Wed, 22 Jul 2020 11:11:17 +0000 (11:11 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1880145 13f79535-47bb-0310-9956-ffa450edef68

fop-core/src/main/java/org/apache/fop/render/java2d/Java2DRenderer.java
fop-core/src/test/java/org/apache/fop/render/java2d/Java2DRendererTestCase.java [new file with mode: 0644]

index 825dc37546665cc0006f3844a424842204ab7820..ca74068d8e1d21ca0772a88bf6e5c20702b2b1b8 100644 (file)
@@ -1004,12 +1004,14 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem
             // reset the current Positions
             currentBPPosition = 0;
             currentIPPosition = 0;
-
-            renderPageAreas(viewport.getPage());
+            super.renderPage(viewport);
             return PAGE_EXISTS;
         } catch (FOPException e) {
             log.error(e);
             return NO_SUCH_PAGE;
+        } catch (IOException e) {
+            log.error(e);
+            return NO_SUCH_PAGE;
         } finally {
             state = null;
         }
diff --git a/fop-core/src/test/java/org/apache/fop/render/java2d/Java2DRendererTestCase.java b/fop-core/src/test/java/org/apache/fop/render/java2d/Java2DRendererTestCase.java
new file mode 100644 (file)
index 0000000..8d22020
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+
+/* $Id: Java2DRenderer.java 1827168 2018-03-19 08:49:57Z ssteiner $ */
+package org.apache.fop.render.java2d;
+
+import java.awt.Rectangle;
+import java.awt.image.BufferedImage;
+import java.io.File;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.FopFactory;
+import org.apache.fop.area.BodyRegion;
+import org.apache.fop.area.CTM;
+import org.apache.fop.area.Page;
+import org.apache.fop.area.PageViewport;
+import org.apache.fop.area.RegionViewport;
+import org.apache.fop.fo.Constants;
+
+public class Java2DRendererTestCase {
+    @Test
+    public void testPrint() throws Exception {
+        FOUserAgent userAgent = FopFactory.newInstance(new File(".").toURI()).newFOUserAgent();
+        Java2DRenderer java2DRenderer = new Java2DRenderer(userAgent) {
+            public String getMimeType() {
+                return null;
+            }
+        };
+        PageViewport pageViewport = new PageViewport(new Rectangle(), 0, null, null, true);
+        pageViewport.setPageIndex(0);
+        Page page = new Page();
+        RegionViewport regionViewport = new RegionViewport(new Rectangle());
+        BodyRegion bodyRegion = new BodyRegion(Constants.FO_REGION_BODY, null, regionViewport, 0, 0);
+        bodyRegion.setCTM(new CTM());
+        bodyRegion.getMainReference().createSpan(true);
+        regionViewport.setRegionReference(bodyRegion);
+        page.setRegionViewport(Constants.FO_REGION_BODY, regionViewport);
+        pageViewport.setPage(page);
+        java2DRenderer.renderPage(pageViewport);
+        BufferedImage image = new BufferedImage(100, 50, BufferedImage.TYPE_INT_ARGB);
+        Assert.assertEquals(java2DRenderer.print(image.createGraphics(), null, 0), 0);
+    }
+}