]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
added support for IMM Extension on fo:simple-page-master element in the AFP Renderer
authorChris Bowditch <cbowditch@apache.org>
Tue, 4 Aug 2009 15:44:16 +0000 (15:44 +0000)
committerChris Bowditch <cbowditch@apache.org>
Tue, 4 Aug 2009 15:44:16 +0000 (15:44 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@800852 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/trunk/output.xml
src/java/org/apache/fop/render/afp/AFPDocumentHandler.java
src/java/org/apache/fop/render/afp/AFPRenderer.java
src/java/org/apache/fop/render/afp/extensions/AFPInvokeMediumMapElement.java
status.xml

index 6dec9171a926b51ae4ce61615b02bca66a3924bf..9c88c27d027ce14d65f7d182a9f55082f7250236 100644 (file)
@@ -857,10 +857,10 @@ out = proc.getOutputStream();]]></source>
 ]]></source>
         <p>
           The invoke-medium-map element is allowed as child of fo:page-sequence (page group
-          level). It is NOT supported on document level (fo:root), yet. FOP also doesn't support
-          specifying medium maps inside XML (using BMM/EMM). It can only reference an existing
-          medium map by name. The medium map has to be constructed through different means and
-          available on the target platform.
+          level) or fo:simple-page-master. It is NOT supported on document level (fo:root), yet. 
+          FOP also doesn't support specifying medium maps inside XML (using BMM/EMM). It can 
+          only reference an existing medium map by name. The medium map has to be constructed 
+          through different means and available on the target platform.
         </p>
       </section>
       <section id="afp-form-maps">
index d8a2d04e965b05ef184085416731ed9666ed0ff2..073d43e201defae6e20694ee71f2edbb8a9fc26d 100644 (file)
@@ -77,6 +77,9 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler
     private Map/*<String,String>*/pageSegmentMap
         = new java.util.HashMap/*<String,String>*/();
 
+    /** Medium Map referenced on previous page **/
+    private String lastMediumMap;
+
     private static final int LOC_ELSEWHERE = 0;
     private static final int LOC_FOLLOWING_PAGE_SEQUENCE = 1;
     private static final int LOC_IN_PAGE_HEADER = 2;
@@ -299,15 +302,19 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler
                 }
             }
         } else if (extension instanceof AFPInvokeMediumMap) {
-            if (this.location != LOC_FOLLOWING_PAGE_SEQUENCE) {
+            if (this.location != LOC_FOLLOWING_PAGE_SEQUENCE
+                    && this.location != LOC_IN_PAGE_HEADER) {
+
                 throw new IFException(
-                    "AFP IMM extension must be between page-sequence and the first page: "
-                        + extension, null);
+                    "AFP IMM extension must be between page-sequence"
+                    + " and the first page or child of page-header: "
+                    + extension, null);
             }
             AFPInvokeMediumMap imm = (AFPInvokeMediumMap)extension;
             String mediumMap = imm.getName();
-            if (mediumMap != null) {
+            if (mediumMap != null && !mediumMap.equals(lastMediumMap)) {
                 dataStream.createInvokeMediumMap(mediumMap);
+                lastMediumMap = mediumMap;
             }
         } else if (extension instanceof AFPIncludeFormMap) {
             AFPIncludeFormMap formMap = (AFPIncludeFormMap)extension;
index e23cf7825a7efe5172a0ce2c0ab4db8eae0ff5b8..e106ac712b26d3cf1f62a234a974f4b355af6623 100644 (file)
@@ -181,6 +181,9 @@ public class AFPRenderer extends AbstractPathOrientedRenderer implements AFPCust
     /** the shading mode for filled rectangles */
     private AFPShadingMode shadingMode = AFPShadingMode.COLOR;
 
+    /** medium map referenced used on previous page **/
+    private String lastMediumMap;
+
     /**
      * Constructor for AFPRenderer.
      */
@@ -380,6 +383,9 @@ public class AFPRenderer extends AbstractPathOrientedRenderer implements AFPCust
 
             int resolution = paintingState.getResolution();
 
+            // IMM should occur before BPG
+            renderInvokeMediumMap(pageViewport);
+
             dataStream.startPage(pageWidth, pageHeight, pageRotation,
                     resolution, resolution);
 
@@ -703,6 +709,35 @@ public class AFPRenderer extends AbstractPathOrientedRenderer implements AFPCust
         return MimeConstants.MIME_AFP;
     }
 
+    /**
+     * checks for IMM Extension and renders if found and different
+     * from previous page
+     *
+     * @param pageViewport the page object
+     */
+    private void renderInvokeMediumMap(PageViewport pageViewport) {
+         if (pageViewport.getExtensionAttachments() != null
+                && pageViewport.getExtensionAttachments().size() > 0) {
+             Iterator it = pageViewport.getExtensionAttachments().iterator();
+             while (it.hasNext()) {
+                 ExtensionAttachment attachment = (ExtensionAttachment) it.next();
+                 if (AFPExtensionAttachment.CATEGORY.equals(attachment.getCategory())) {
+                     AFPExtensionAttachment aea = (AFPExtensionAttachment)attachment;
+                     if (AFPElementMapping.INVOKE_MEDIUM_MAP.equals(aea.getElementName())) {
+                         AFPInvokeMediumMap imm = (AFPInvokeMediumMap)attachment;
+                         String mediumMap = imm.getName();
+                         if (mediumMap != null) {
+                             if (!mediumMap.equals(lastMediumMap)) {
+                                dataStream.createInvokeMediumMap(mediumMap);
+                                 lastMediumMap = mediumMap;
+                             }
+                         }
+                     }
+                 }
+             }
+         }
+    }
+
     /**
      * Method to render the page extension.
      * <p>
@@ -720,27 +755,29 @@ public class AFPRenderer extends AbstractPathOrientedRenderer implements AFPCust
             while (it.hasNext()) {
                 ExtensionAttachment attachment = (ExtensionAttachment) it.next();
                 if (AFPPageSetup.CATEGORY.equals(attachment.getCategory())) {
-                    AFPPageSetup aps = (AFPPageSetup) attachment;
-                    String element = aps.getElementName();
-                    if (AFPElementMapping.INCLUDE_PAGE_OVERLAY.equals(element)) {
-                        String overlay = aps.getName();
-                        if (overlay != null) {
-                            dataStream.createIncludePageOverlay(overlay);
-                        }
-                    } else if (AFPElementMapping.INCLUDE_PAGE_SEGMENT
-                            .equals(element)) {
-                        String name = aps.getName();
-                        String source = aps.getValue();
-                        pageSegmentMap.put(source, name);
-                    } else if (AFPElementMapping.TAG_LOGICAL_ELEMENT
-                            .equals(element)) {
-                        String name = aps.getName();
-                        String value = aps.getValue();
-                        dataStream.createTagLogicalElement(name, value);
-                    } else if (AFPElementMapping.NO_OPERATION.equals(element)) {
-                        String content = aps.getContent();
-                        if (content != null) {
-                            dataStream.createNoOperation(content);
+                    if (attachment instanceof AFPPageSetup) {
+                        AFPPageSetup aps = (AFPPageSetup) attachment;
+                        String element = aps.getElementName();
+                        if (AFPElementMapping.INCLUDE_PAGE_OVERLAY.equals(element)) {
+                            String overlay = aps.getName();
+                            if (overlay != null) {
+                                dataStream.createIncludePageOverlay(overlay);
+                            }
+                        } else if (AFPElementMapping.INCLUDE_PAGE_SEGMENT
+                                .equals(element)) {
+                            String name = aps.getName();
+                            String source = aps.getValue();
+                            pageSegmentMap.put(source, name);
+                        } else if (AFPElementMapping.TAG_LOGICAL_ELEMENT
+                                .equals(element)) {
+                            String name = aps.getName();
+                            String value = aps.getValue();
+                            dataStream.createTagLogicalElement(name, value);
+                        } else if (AFPElementMapping.NO_OPERATION.equals(element)) {
+                            String content = aps.getContent();
+                            if (content != null) {
+                                dataStream.createNoOperation(content);
+                            }
                         }
                     }
                 }
index 99805edd4245b0a7533a45c0e5fb5c6b472fc286..f36bd3e12b7e9a996855e4b54bf24285801a045d 100644 (file)
@@ -26,8 +26,8 @@ import org.apache.fop.fo.extensions.ExtensionAttachment;
 
 /**
  * This class represents an AFP-specific extension element to embed Invoke Medium Map (IMM)
- * fields at the beginning of a page group. The element is optional and expected as a direct child
- * of an fo:page-sequence.
+ * fields at the beginning of a page group or just prior to a Page. The element is optional
+ * and expected as a direct child of an fo:page-sequence or fo:simple-page-master
  */
 public class AFPInvokeMediumMapElement extends AbstractAFPExtensionObject {
 
@@ -42,7 +42,9 @@ public class AFPInvokeMediumMapElement extends AbstractAFPExtensionObject {
     /** {@inheritDoc} */
     protected void startOfNode() throws FOPException {
         super.startOfNode();
-        if (parent.getNameId() != Constants.FO_PAGE_SEQUENCE) {
+        if (parent.getNameId() != Constants.FO_PAGE_SEQUENCE
+                && parent.getNameId() != Constants.FO_SIMPLE_PAGE_MASTER) {
+            
             invalidChildError(getLocator(), parent.getName(), getNamespaceURI(), getName(),
                 "rule.childOfPageSequence");
         }
index 21ce1b8dd27e10d31cec11515321fa459b01faf7..8eae1a9cfaacd5ace0538a4054988a1642ac8e07 100644 (file)
@@ -58,6 +58,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="CB" type="add">
+        AFP Output: Added support for IMM Extension on fo:simple-page-master.
+      </action>
       <action context="Renderers" dev="JM" type="add" fixes-bug="47311" due-to="Peter Coppens">
         Added an initial set of extensions for prepress support (fox:bleed, fox:crop-offset,
         fox:crop-box and fox:scale). This is currently supported only by PDF and Java2D renderers.