]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-3039: AFP include-page-overlay missing X and Y via IF
authorSimon Steiner <ssteiner@apache.org>
Tue, 7 Dec 2021 08:18:20 +0000 (08:18 +0000)
committerSimon Steiner <ssteiner@apache.org>
Tue, 7 Dec 2021 08:18:20 +0000 (08:18 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1895653 13f79535-47bb-0310-9956-ffa450edef68

fop-core/src/main/java/org/apache/fop/render/afp/extensions/AFPExtensionHandler.java
fop-core/src/main/java/org/apache/fop/render/afp/extensions/AFPPageOverlay.java
fop-core/src/main/java/org/apache/fop/render/afp/extensions/AFPPageOverlayElement.java
fop-core/src/test/java/org/apache/fop/render/afp/PageOverlayTestCase.java

index abf6e359ed59c78f668d2f40778e8f5b44ab87f9..b3cc0a4cb951751647edeb658b5a3993ed8abe2c 100644 (file)
@@ -95,11 +95,20 @@ public class AFPExtensionHandler extends DefaultHandler
                 }
                 this.returnedObject = formMap;
             } else if (AFPElementMapping.INCLUDE_PAGE_OVERLAY.equals(localName)) {
-                this.returnedObject = new AFPPageOverlay();
+                AFPPageOverlay afpPageOverlay = new AFPPageOverlay();
+                this.returnedObject = afpPageOverlay;
                 String name = lastAttributes.getValue("name");
                 if (name != null) {
                     returnedObject.setName(name);
                 }
+                String x = lastAttributes.getValue("x");
+                if (x != null) {
+                    afpPageOverlay.setX(Integer.parseInt(x));
+                }
+                String y = lastAttributes.getValue("y");
+                if (y != null) {
+                    afpPageOverlay.setY(Integer.parseInt(y));
+                }
             } else if (AFPElementMapping.INCLUDE_PAGE_SEGMENT.equals(localName)) {
                 AFPPageSegmentSetup pageSetupExtn = null;
 
index 7af76b649062a778a94f87bab5a4160145589422..b44d57cd048af33f493069cd1e8f4715c6319621 100644 (file)
@@ -23,6 +23,9 @@ import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.AttributesImpl;
 
+import static org.apache.fop.render.afp.extensions.AFPPageOverlayElement.ATT_X;
+import static org.apache.fop.render.afp.extensions.AFPPageOverlayElement.ATT_Y;
+
 /**
  * This extension allows to include an AFP Page Overlay resource. It is implemented as an extension
  * attachment ({@link org.apache.fop.fo.extensions.ExtensionAttachment}).
@@ -31,11 +34,6 @@ public class AFPPageOverlay extends AFPExtensionAttachment {
 
     private static final long serialVersionUID = 8548056652642588919L;
 
-    /** X coordinate attribute */
-    protected static final String ATT_X = "X";
-    /** X coordinate attribute */
-    protected static final String ATT_Y = "Y";
-
     /**
      * The x coordinate
      */
@@ -91,6 +89,8 @@ public class AFPPageOverlay extends AFPExtensionAttachment {
         if (name != null && name.length() > 0) {
             atts.addAttribute("", ATT_NAME, ATT_NAME, "CDATA", name);
         }
+        atts.addAttribute(null, ATT_X, ATT_X, "CDATA", String.valueOf(x));
+        atts.addAttribute(null, ATT_Y, ATT_Y, "CDATA", String.valueOf(y));
         handler.startElement(CATEGORY, elementName, elementName, atts);
         handler.endElement(CATEGORY, elementName, elementName);
     }
index 1ab259e69d4a035b722212bd2aa9a832efc87a1b..bd221ad58cda626716ce730fd3c15661fc379fb1 100644 (file)
@@ -39,8 +39,8 @@ import org.apache.fop.fo.extensions.ExtensionAttachment;
  */
 public class AFPPageOverlayElement extends AbstractAFPExtensionObject {
 
-    private static final String ATT_X = "x";
-    private static final String ATT_Y = "y";
+    protected static final String ATT_X = "x";
+    protected static final String ATT_Y = "y";
 
     /**
      * Constructs an AFP object (called by Maker).
index 673c643136ada53131f99ea8dd9050fa4b082277..dc908eb59cf67913287ab62b4a3e37aaa722baae 100644 (file)
@@ -27,9 +27,13 @@ import javax.xml.transform.stream.StreamResult;
 
 import org.junit.Assert;
 import org.junit.Test;
+import org.xml.sax.helpers.AttributesImpl;
 
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.FopFactory;
+import org.apache.fop.render.afp.extensions.AFPElementMapping;
+import org.apache.fop.render.afp.extensions.AFPExtensionAttachment;
+import org.apache.fop.render.afp.extensions.AFPExtensionHandler;
 import org.apache.fop.render.afp.extensions.AFPPageOverlay;
 import org.apache.fop.render.intermediate.IFContext;
 
@@ -69,4 +73,18 @@ public class PageOverlayTestCase {
         new AFPParser(true).read(new ByteArrayInputStream(outputStream.toByteArray()), sb);
         return sb.toString();
     }
+
+    @Test
+    public void testXY() throws Exception {
+        AFPExtensionHandler extensionHandler = new AFPExtensionHandler();
+        AttributesImpl attributes = new AttributesImpl();
+        attributes.addAttribute(null, null, "x", null, "1");
+        attributes.addAttribute(null, null, "y", null, "1");
+        extensionHandler.startElement(AFPExtensionAttachment.CATEGORY, AFPElementMapping.INCLUDE_PAGE_OVERLAY, null,
+                attributes);
+        extensionHandler.endElement(AFPExtensionAttachment.CATEGORY, AFPElementMapping.INCLUDE_PAGE_OVERLAY, null);
+        AFPPageOverlay pageOverlay = (AFPPageOverlay) extensionHandler.getObject();
+        Assert.assertEquals(pageOverlay.getX(), 1);
+        Assert.assertEquals(pageOverlay.getY(), 1);
+    }
 }