xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sstei...@apache.org
Subject svn commit: r1717946 - in /xmlgraphics/fop/trunk: src/java/org/apache/fop/render/bitmap/ src/java/org/apache/fop/render/intermediate/ src/java/org/apache/fop/render/java2d/ src/java/org/apache/fop/render/pcl/ test/java/org/apache/fop/render/pdf/
Date Fri, 04 Dec 2015 12:18:50 GMT
Author: ssteiner
Date: Fri Dec  4 12:18:50 2015
New Revision: 1717946

URL: http://svn.apache.org/viewvc?rev=1717946&view=rev
Log:
FOP-2548: Support Barcode4J page number

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFContext.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFParser.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFRenderer.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DPainter.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java
    xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java?rev=1717946&r1=1717945&r2=1717946&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java
Fri Dec  4 12:18:50 2015
@@ -273,7 +273,7 @@ public abstract class AbstractBitmapDocu
         }
         graphics2D.scale(scale / 1000f, scale / 1000f);
 
-        return new Java2DPainter(graphics2D, getContext(), getFontInfo());
+        return new Java2DPainter(graphics2D, getContext(), getFontInfo(), this);
     }
 
     /**

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java?rev=1717946&r1=1717945&r2=1717946&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
Fri Dec  4 12:18:50 2015
@@ -188,7 +188,7 @@ public abstract class AbstractIFPainter<
         if (conversionMode != null) {
             hints.put(ImageHandlerUtil.CONVERSION_MODE, conversionMode);
         }
-
+        hints.put("page-number", documentHandler.getContext().getPageNumber());
         return hints;
     }
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFContext.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFContext.java?rev=1717946&r1=1717945&r2=1717946&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFContext.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFContext.java Fri Dec
 4 12:18:50 2015
@@ -57,6 +57,8 @@ public class IFContext {
 
     private int pageIndex = -1;
 
+    private int pageNumber = -1;
+
     /**
      * Main constructor.
      * @param ua the user agent
@@ -234,4 +236,11 @@ public class IFContext {
         return this.pageIndex;
     }
 
+    public int getPageNumber() {
+        return pageNumber;
+    }
+
+    public void setPageNumber(int pageNumber) {
+        this.pageNumber = pageNumber;
+    }
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFParser.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFParser.java?rev=1717946&r1=1717945&r2=1717946&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFParser.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFParser.java Fri Dec
 4 12:18:50 2015
@@ -523,6 +523,7 @@ public class IFParser implements IFConst
                 establishForeignAttributes(foreignAttributes);
                 documentHandler.startPage(index, name, pageMasterName,
                         new Dimension(width, height));
+                documentHandler.getContext().setPageNumber(Integer.parseInt(name));
                 resetForeignAttributes();
             }
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFRenderer.java?rev=1717946&r1=1717945&r2=1717946&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFRenderer.java Fri
Dec  4 12:18:50 2015
@@ -573,6 +573,7 @@ public class IFRenderer extends Abstract
 
             establishForeignAttributes(page.getForeignAttributes());
             documentHandler.getContext().setPageIndex(page.getPageIndex());
+            documentHandler.getContext().setPageNumber(page.getPageNumber());
             documentHandler.startPage(page.getPageIndex(), page.getPageNumberString(),
                     page.getSimplePageMasterName(), dim);
             resetForeignAttributes();

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DPainter.java?rev=1717946&r1=1717945&r2=1717946&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DPainter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DPainter.java Fri Dec
 4 12:18:50 2015
@@ -41,6 +41,7 @@ import org.apache.fop.render.intermediat
 import org.apache.fop.render.intermediate.BorderPainter;
 import org.apache.fop.render.intermediate.GraphicsPainter;
 import org.apache.fop.render.intermediate.IFContext;
+import org.apache.fop.render.intermediate.IFDocumentHandler;
 import org.apache.fop.render.intermediate.IFException;
 import org.apache.fop.render.intermediate.IFState;
 import org.apache.fop.traits.BorderProps;
@@ -51,7 +52,7 @@ import org.apache.fop.util.CharUtilities
  * {@link org.apache.fop.render.intermediate.IFPainter} implementation that paints on a Graphics2D
  * instance.
  */
-public class Java2DPainter extends AbstractIFPainter<Java2DDocumentHandler> {
+public class Java2DPainter extends AbstractIFPainter<IFDocumentHandler> {
 
     /** the IF context */
     protected IFContext ifContext;
@@ -74,7 +75,11 @@ public class Java2DPainter extends Abstr
      * @param fontInfo the font information
      */
     public Java2DPainter(Graphics2D g2d, IFContext context, FontInfo fontInfo) {
-        this(g2d, context, fontInfo, null);
+        this(g2d, context, fontInfo, new Java2DDocumentHandler());
+    }
+
+    public Java2DPainter(Graphics2D g2d, IFContext context, FontInfo fontInfo, IFDocumentHandler
documentHandler) {
+        this(g2d, context, fontInfo, null, documentHandler);
     }
 
     /**
@@ -86,7 +91,12 @@ public class Java2DPainter extends Abstr
      * @param state the IF state object
      */
     public Java2DPainter(Graphics2D g2d, IFContext context, FontInfo fontInfo, IFState state)
{
-        super(new Java2DDocumentHandler());
+        this(g2d, context, fontInfo, state, new Java2DDocumentHandler());
+    }
+
+    public Java2DPainter(Graphics2D g2d, IFContext context, FontInfo fontInfo, IFState state,
+                         IFDocumentHandler documentHandler) {
+        super(documentHandler);
         this.ifContext = context;
         if (state != null) {
             this.state = state.push();

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java?rev=1717946&r1=1717945&r2=1717946&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java Fri Dec
 4 12:18:50 2015
@@ -251,7 +251,7 @@ public class PCLDocumentHandler extends
         graphics2D.scale(scale / 1000f, scale / 1000f);
         graphics2D.translate(-printArea.x, -printArea.y);
 
-        return new Java2DPainter(graphics2D, getContext(), getFontInfo());
+        return new Java2DPainter(graphics2D, getContext(), getFontInfo(), this);
     }
 
     private BufferedImage createBufferedImage(int bitmapWidth, int bitmapHeight) {

Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java?rev=1717946&r1=1717945&r2=1717946&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java Fri
Dec  4 12:18:50 2015
@@ -20,7 +20,12 @@
 package org.apache.fop.render.pdf;
 
 import java.awt.Color;
+import java.awt.Dimension;
 import java.awt.Rectangle;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+
+import javax.xml.transform.stream.StreamResult;
 
 import org.junit.Test;
 
@@ -31,27 +36,32 @@ import static org.mockito.Mockito.verify
 import static org.mockito.Mockito.when;
 
 import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.FopFactory;
 import org.apache.fop.fo.Constants;
+import org.apache.fop.pdf.PDFDocument;
+import org.apache.fop.pdf.PDFProfile;
+import org.apache.fop.pdf.PDFStructElem;
+import org.apache.fop.render.RenderingContext;
 import org.apache.fop.render.intermediate.IFContext;
+import org.apache.fop.render.intermediate.IFException;
 import org.apache.fop.traits.BorderProps;
 
+import junit.framework.Assert;
+
 public class PDFPainterTestCase {
 
+    private FOUserAgent foUserAgent;
+    private  PDFContentGenerator pdfContentGenerator;
+    private PDFDocumentHandler pdfDocumentHandler;
+    private PDFPainter pdfPainter;
+    private PDFStructElem elem = new PDFStructElem();
+
     @Test
     public void testDrawBorderRect() throws Exception {
         // the goal of this test is to check that the drawing of rounded corners in PDF calls
         // PDFGraphicsPaiter.cubicBezierTo(); the check is done by verifying that a " c "
command is written
         // to the PDFContentGenerator
-        PDFContentGenerator pdfContentGenerator = mock(PDFContentGenerator.class);
-        FOUserAgent foUserAgent = mock(FOUserAgent.class);
-        when(foUserAgent.isAccessibilityEnabled()).thenReturn(false);
-        IFContext ifContext = mock(IFContext.class);
-        when(ifContext.getUserAgent()).thenReturn(foUserAgent);
-        PDFDocumentHandler pdfDocumentHandler = mock(PDFDocumentHandler.class);
-        when(pdfDocumentHandler.getGenerator()).thenReturn(pdfContentGenerator);
-        when(pdfDocumentHandler.getContext()).thenReturn(ifContext);
-        PDFLogicalStructureHandler pdfLogicalStructureHandler = mock(PDFLogicalStructureHandler.class);
-        PDFPainter pdfPainter = new PDFPainter(pdfDocumentHandler, pdfLogicalStructureHandler);
+        createPDFPainter(false);
         // build rectangle 200 x 50 (points, which are converted to milipoints)
         Rectangle rectangle = new Rectangle(0, 0, 200000, 50000);
         // build border properties: width 4pt, radius 30pt
@@ -63,4 +73,63 @@ public class PDFPainterTestCase {
         verify(pdfContentGenerator, times(16)).add(endsWith(" c "));
     }
 
+    private void createPDFPainter(boolean value) {
+        mockFOUserAgent(value);
+        mockPDFContentGenerator();
+        mockPDFDocumentHandler();
+        PDFLogicalStructureHandler handler = mock(PDFLogicalStructureHandler.class);
+        pdfPainter = new PDFPainter(pdfDocumentHandler, handler);
+    }
+
+    private void mockFOUserAgent(boolean value) {
+        foUserAgent = mock(FOUserAgent.class);
+        when(foUserAgent.isAccessibilityEnabled()).thenReturn(value);
+    }
+
+    private void mockPDFContentGenerator() {
+        pdfContentGenerator = mock(PDFContentGenerator.class);
+    }
+
+    private void mockPDFDocumentHandler() {
+        pdfDocumentHandler = mock(PDFDocumentHandler.class);
+        when(pdfDocumentHandler.getGenerator()).thenReturn(pdfContentGenerator);
+        IFContext ifContext = mock(IFContext.class);
+        when(ifContext.getUserAgent()).thenReturn(foUserAgent);
+        when(pdfDocumentHandler.getContext()).thenReturn(ifContext);
+        when(ifContext.getStructureTreeElement()).thenReturn(elem);
+    }
+
+    private PDFDocument createMockPDFDocument() {
+        PDFDocument pdfDoc = mock(PDFDocument.class);
+        when(pdfContentGenerator.getDocument()).thenReturn(pdfDoc);
+        when(pdfDocumentHandler.getPDFDocument()).thenReturn(pdfDoc);
+        when(pdfDoc.getProfile()).thenReturn(new PDFProfile(pdfDoc));
+        return pdfDoc;
+    }
+
+    @Test
+    public void testPageNumber() throws IFException {
+        FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI());
+        foUserAgent = fopFactory.newFOUserAgent();
+        pdfDocumentHandler = new PDFDocumentHandler(new IFContext(foUserAgent));
+        pdfDocumentHandler.setResult(new StreamResult(new ByteArrayOutputStream()));
+        pdfDocumentHandler.startDocument();
+        pdfDocumentHandler.startPage(0, "", "", new Dimension());
+        pdfDocumentHandler.getContext().setPageNumber(3);
+        MyPDFPainter pdfPainter = new MyPDFPainter(pdfDocumentHandler, null);
+        pdfPainter.drawImage("test/resources/images/cmyk.jpg", new Rectangle());
+        Assert.assertEquals(pdfPainter.renderingContext.getHints().get("page-number"), 3);
+    }
+
+    class MyPDFPainter extends PDFPainter {
+        protected RenderingContext renderingContext;
+        public MyPDFPainter(PDFDocumentHandler documentHandler, PDFLogicalStructureHandler
logicalStructureHandler) {
+            super(documentHandler, logicalStructureHandler);
+        }
+
+        protected RenderingContext createRenderingContext() {
+            renderingContext = super.createRenderingContext();
+            return renderingContext;
+        }
+    }
 }



---------------------------------------------------------------------
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