]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-2911: Add endpage event for FO to IF
authorSimon Steiner <ssteiner@apache.org>
Tue, 11 Feb 2020 13:41:06 +0000 (13:41 +0000)
committerSimon Steiner <ssteiner@apache.org>
Tue, 11 Feb 2020 13:41:06 +0000 (13:41 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1873909 13f79535-47bb-0310-9956-ffa450edef68

fop-core/src/main/java/org/apache/fop/render/intermediate/IFSerializer.java
fop-core/src/test/java/org/apache/fop/render/intermediate/IFSerializerTestCase.java

index dd8a946c2c0b1e010f6a470a23afedc9bff196b5..d12c13b35f0f3b9e63f51e35f2150c2489a54804 100644 (file)
@@ -40,9 +40,11 @@ import org.apache.xmlgraphics.util.QName;
 import org.apache.xmlgraphics.util.XMLizable;
 
 import org.apache.fop.accessibility.StructureTreeEventHandler;
+import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.fo.extensions.InternalElementMapping;
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.render.DefaultRendererConfigurator;
+import org.apache.fop.render.RendererEventProducer;
 import org.apache.fop.render.RenderingContext;
 import org.apache.fop.render.intermediate.IFRendererConfig.IFRendererConfigParser;
 import org.apache.fop.render.intermediate.IFStructureTreeBuilder.IFStructureTreeElement;
@@ -85,6 +87,7 @@ implements IFConstants, IFPainter, IFDocumentNavigationHandler {
     private String currentID = "";
 
     private IFStructureTreeBuilder structureTreeBuilder;
+    private int pageNumberEnded;
 
     public IFSerializer(IFContext context) {
         super(context);
@@ -384,6 +387,11 @@ implements IFConstants, IFPainter, IFDocumentNavigationHandler {
         } catch (SAXException e) {
             throw new IFException("SAX error in endPage()", e);
         }
+        if (mimicHandler != null) {
+            pageNumberEnded++;
+            FOUserAgent userAgent = mimicHandler.getContext().getUserAgent();
+            RendererEventProducer.Provider.get(userAgent.getEventBroadcaster()).endPage(this, pageNumberEnded);
+        }
     }
 
     //---=== IFPainter ===---
index 0340c190eb3abdd3e9d1e91c2fc87f3a739da881..0dbcddbdfcdb6b1ea63a1ba8ed452925670eb376 100644 (file)
@@ -20,6 +20,9 @@
 package org.apache.fop.render.intermediate;
 
 import java.awt.Rectangle;
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.xml.transform.sax.SAXResult;
 
@@ -38,6 +41,9 @@ import org.apache.xmlgraphics.image.loader.ImageManager;
 import org.apache.xmlgraphics.image.loader.ImageSessionContext;
 
 import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.FopFactory;
+import org.apache.fop.events.EventChecker;
+import org.apache.fop.render.afp.AFPDocumentHandler;
 
 public class IFSerializerTestCase {
 
@@ -90,4 +96,16 @@ public class IFSerializerTestCase {
         verify(imageManager).closeImage(eq(IMAGE), any(ImageSessionContext.class));
     }
 
+    @Test
+    public void testPageEvent() throws IFException {
+        FOUserAgent userAgent = FopFactory.newInstance(new File(".").toURI()).newFOUserAgent();
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.put("number", 1);
+        EventChecker eventChecker = new EventChecker("org.apache.fop.render.RendererEventProducer.endPage", params);
+        userAgent.getEventBroadcaster().addEventListener(eventChecker);
+        sut.mimicDocumentHandler(new AFPDocumentHandler(new IFContext(userAgent)));
+        sut.setResult(new SAXResult(new DefaultHandler()));
+        sut.endPage();
+        eventChecker.end();
+    }
 }