You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2009/02/05 11:40:52 UTC

svn commit: r741068 - in /xmlgraphics/fop/trunk: ./ src/documentation/content/xdocs/trunk/ src/java/org/apache/fop/afp/ src/java/org/apache/fop/render/afp/

Author: jeremias
Date: Thu Feb  5 10:40:52 2009
New Revision: 741068

URL: http://svn.apache.org/viewvc?rev=741068&view=rev
Log:
AFP Output: Added a configuration option to override the resource level defaults in the code. The chosen defaults in code may not always be the best. For example, a user reported that they can't use print-level images for some reason and it is not possible to switch on inlining for background images.

Added:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPResourceLevelDefaults.java   (with props)
Modified:
    xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/output.xml
    xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPGraphics2D.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPResourceInfo.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPResourceManager.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRenderer.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRendererContext.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AbstractAFPImageHandlerRawStream.java
    xmlgraphics/fop/trunk/status.xml

Modified: xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/output.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/output.xml?rev=741068&r1=741067&r2=741068&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/output.xml (original)
+++ xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/output.xml Thu Feb  5 10:40:52 2009
@@ -657,6 +657,26 @@
 ]]></source>
       <note>Be careful when using this option not to overwrite existing resource files from previous rendering runs.</note>
       </section>
+      <section id="afp-resource-level-defaults">
+        <title>Resource Level Defaults</title>
+        <p>
+          By default, bitmap image objects (or page segments derived from them) are put in the
+          print-file-level resource group and GOCA graphics are inlined for compatibility with
+          the AFP Workbench tool.
+        </p>
+        <p>
+          It is possible to override these defaults, either per image (see the
+          <link href="#afp-foreign-attributes-resource">afp:resource-level</link>
+          extension attribute below) or by specifying different defaults in the configuration:
+        </p>
+        <source><![CDATA[
+<default-resource-levels goca="print-file" bitmap="inline"/>]]></source>
+        <p>
+          "goca" refers to GOCA graphics and "bitmap" refers to IOCA images. The possible values
+          for the attributes are "inline" and "print-file". In the future,
+          additional possibilities may be added.
+        </p>
+      </section>
     </section>
     <section id="afp-extensions">
       <title>Extensions</title>
@@ -772,8 +792,10 @@
 ]]></source>
         <p>The resource-level attribute where the resource object will reside in the AFP output datastream.
         The possible values for this are "inline", "print-file" and "external".
-        When no resource-level attribute is provided, resources are by default placed at "print-file" level.
-        When "external" is used a resource-group-file attribute must also be specified.</p>
+        When "external" is used a resource-group-file attribute must also be specified.
+        Please refer to the <link href="#afp-resource-level-defaults">Resource Level Defaults</link>
+        above to see what is used if the resource-level attribute is not specified.
+        </p>
         <p></p>
       </section>
     </section>

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPGraphics2D.java?rev=741068&r1=741067&r2=741068&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPGraphics2D.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPGraphics2D.java Thu Feb  5 10:40:52 2009
@@ -47,11 +47,7 @@
 import org.apache.commons.io.output.ByteArrayOutputStream;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.fop.afp.goca.GraphicsSetLineType;
-import org.apache.fop.afp.modca.GraphicsObject;
-import org.apache.fop.afp.svg.AFPGraphicsConfiguration;
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.svg.NativeImageHandler;
+
 import org.apache.xmlgraphics.image.loader.ImageInfo;
 import org.apache.xmlgraphics.image.loader.ImageSize;
 import org.apache.xmlgraphics.image.loader.impl.ImageRendered;
@@ -62,6 +58,12 @@
 import org.apache.xmlgraphics.ps.ImageEncodingHelper;
 import org.apache.xmlgraphics.util.MimeConstants;
 
+import org.apache.fop.afp.goca.GraphicsSetLineType;
+import org.apache.fop.afp.modca.GraphicsObject;
+import org.apache.fop.afp.svg.AFPGraphicsConfiguration;
+import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.svg.NativeImageHandler;
+
 /**
  * This is a concrete implementation of <tt>AbstractGraphics2D</tt> (and
  * therefore of <tt>Graphics2D</tt>) which is able to generate GOCA byte
@@ -128,10 +130,10 @@
             AFPResourceManager resourceManager, AFPResourceInfo resourceInfo,
             FontInfo fontInfo) {
         super(textAsShapes);
-        this.paintingState = paintingState;
-        this.resourceManager = resourceManager;
-        this.resourceInfo = resourceInfo;
-        this.fontInfo = fontInfo;
+        setPaintingState(paintingState);
+        setResourceManager(resourceManager);
+        setResourceInfo(resourceInfo);
+        setFontInfo(fontInfo);
     }
 
     /**
@@ -157,7 +159,7 @@
      *
      * @param resourceManager the AFP resource manager
      */
-    public void setResourceManager(AFPResourceManager resourceManager) {
+    private void setResourceManager(AFPResourceManager resourceManager) {
         this.resourceManager = resourceManager;
     }
 
@@ -166,11 +168,65 @@
      *
      * @param resourceInfo the AFP resource info
      */
-    public void setResourceInfo(AFPResourceInfo resourceInfo) {
+    private void setResourceInfo(AFPResourceInfo resourceInfo) {
         this.resourceInfo = resourceInfo;
     }
 
     /**
+     * Returns the GOCA graphics object
+     *
+     * @return the GOCA graphics object
+     */
+    public GraphicsObject getGraphicsObject() {
+        return this.graphicsObj;
+    }
+
+    /**
+     * Sets the GOCA graphics object
+     *
+     * @param obj the GOCA graphics object
+     */
+    public void setGraphicsObject(GraphicsObject obj) {
+        this.graphicsObj = obj;
+    }
+
+    /**
+     * Sets the AFP painting state
+     *
+     * @param paintingState the AFP painting state
+     */
+    private void setPaintingState(AFPPaintingState paintingState) {
+        this.paintingState = paintingState;
+    }
+
+    /**
+     * Returns the AFP painting state
+     *
+     * @return the AFP painting state
+     */
+    public AFPPaintingState getPaintingState() {
+        return this.paintingState;
+    }
+
+    /**
+     * Sets the FontInfo
+     *
+     * @param fontInfo the FontInfo
+     */
+    private void setFontInfo(FontInfo fontInfo) {
+        this.fontInfo = fontInfo;
+    }
+
+    /**
+     * Returns the FontInfo
+     *
+     * @return the FontInfo
+     */
+    public FontInfo getFontInfo() {
+        return this.fontInfo;
+    }
+
+    /**
      * Sets the GraphicContext
      *
      * @param gc
@@ -614,60 +670,6 @@
         this.customTextHandler = handler;
     }
 
-    /**
-     * Returns the GOCA graphics object
-     *
-     * @return the GOCA graphics object
-     */
-    public GraphicsObject getGraphicsObject() {
-        return this.graphicsObj;
-    }
-
-    /**
-     * Sets the GOCA graphics object
-     *
-     * @param obj the GOCA graphics object
-     */
-    public void setGraphicsObject(GraphicsObject obj) {
-        this.graphicsObj = obj;
-    }
-
-    /**
-     * Sets the AFP painting state
-     *
-     * @param paintingState the AFP painting state
-     */
-    public void setPaintingState(AFPPaintingState paintingState) {
-        this.paintingState = paintingState;
-    }
-
-    /**
-     * Returns the AFP painting state
-     *
-     * @return the AFP painting state
-     */
-    public AFPPaintingState getPaintingState() {
-        return this.paintingState;
-    }
-
-    /**
-     * Sets the FontInfo
-     *
-     * @param the FontInfo
-     */
-    public void setFontInfo(FontInfo fontInfo) {
-        this.fontInfo = fontInfo;
-    }
-
-    /**
-     * Returns the FontInfo
-     *
-     * @return the FontInfo
-     */
-    public FontInfo getFontInfo() {
-        return this.fontInfo;
-    }
-
     /** {@inheritDoc} */
     public void drawRenderableImage(RenderableImage img, AffineTransform xform) {
         log.debug("drawRenderableImage() NYI: img=" + img + ", xform=" + xform);

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPResourceInfo.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPResourceInfo.java?rev=741068&r1=741067&r2=741068&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPResourceInfo.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPResourceInfo.java Thu Feb  5 10:40:52 2009
@@ -26,10 +26,12 @@
  * The level at which a resource is to reside in the AFP output
  */
 public class AFPResourceInfo {
-    private static final AFPResourceLevel DEFAULT_LEVEL
+
+    /** the general default resource level */
+    public static final AFPResourceLevel DEFAULT_LEVEL
         = new AFPResourceLevel(AFPResourceLevel.PRINT_FILE);
 
-    /** the uri of this resource */
+    /** the URI of this resource */
     private String uri = null;
 
     /**
@@ -48,18 +50,18 @@
     private boolean levelChanged = false;
 
     /**
-     * Sets the data object uri
+     * Sets the data object URI.
      *
-     * @param uri the data object uri
+     * @param uri the data object URI
      */
     public void setUri(String uri) {
         this.uri = uri;
     }
 
     /**
-     * Returns the uri of this data object
+     * Returns the URI of this data object.
      *
-     * @return the uri of this data object
+     * @return the URI of this data object
      */
     public String getUri() {
         return uri;

Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPResourceLevelDefaults.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPResourceLevelDefaults.java?rev=741068&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPResourceLevelDefaults.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPResourceLevelDefaults.java Thu Feb  5 10:40:52 2009
@@ -0,0 +1,110 @@
+/*
+ * 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$ */
+
+package org.apache.fop.afp;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.fop.afp.modca.ResourceObject;
+
+/**
+ * This class holds resource levels defaults for the various resource types.
+ */
+public class AFPResourceLevelDefaults {
+
+    private static final Map RESOURCE_TYPE_NAMES = new java.util.HashMap();
+
+    static {
+        //Map to be extended as need arises:
+        registerResourceTypeName("goca", ResourceObject.TYPE_GRAPHIC);
+        registerResourceTypeName("bitmap", ResourceObject.TYPE_IMAGE);
+    }
+
+    private static void registerResourceTypeName(String name, byte type) {
+        RESOURCE_TYPE_NAMES.put(name.toLowerCase(), new Byte(type));
+    }
+
+    private static byte getResourceType(String resourceTypeName) {
+        Byte result = (Byte)RESOURCE_TYPE_NAMES.get(resourceTypeName.toLowerCase());
+        if (result == null) {
+            throw new IllegalArgumentException("Unknown resource type name: " + resourceTypeName);
+        }
+        return result.byteValue();
+    }
+
+    private Map defaultResourceLevels = new java.util.HashMap();
+
+    /**
+     * Creates a new instance with default values.
+     */
+    public AFPResourceLevelDefaults() {
+        // level not explicitly set/changed so default to inline for GOCA graphic objects
+        // (due to a bug in the IBM AFP Workbench Viewer (2.04.01.07), hard copy works just fine)
+        setDefaultResourceLevel(ResourceObject.TYPE_GRAPHIC,
+                new AFPResourceLevel(AFPResourceLevel.INLINE));
+    }
+
+    /**
+     * Sets the default resource level for a particular resource type.
+     * @param type the resource type name
+     * @param level the resource level
+     */
+    public void setDefaultResourceLevel(String type, AFPResourceLevel level) {
+        setDefaultResourceLevel(getResourceType(type), level);
+    }
+
+    /**
+     * Sets the default resource level for a particular resource type.
+     * @param type the resource type ({@link ResourceObject}.TYPE_*)
+     * @param level the resource level
+     */
+    public void setDefaultResourceLevel(byte type, AFPResourceLevel level) {
+        this.defaultResourceLevels.put(new Byte(type), level);
+    }
+
+    /**
+     * Returns the default resource level for a particular resource type.
+     * @param type the resource type ({@link ResourceObject}.TYPE_*)
+     * @return the default resource level
+     */
+    public AFPResourceLevel getDefaultResourceLevel(byte type) {
+        AFPResourceLevel result = (AFPResourceLevel)this.defaultResourceLevels.get(new Byte(type));
+        if (result == null) {
+            result = AFPResourceInfo.DEFAULT_LEVEL;
+        }
+        return result;
+    }
+
+    /**
+     * Allows to merge the values from one instance into another. Values from the instance passed
+     * in as a parameter override values of this instance.
+     * @param other the other instance to get the defaults from
+     */
+    public void mergeFrom(AFPResourceLevelDefaults other) {
+        Iterator iter = other.defaultResourceLevels.entrySet().iterator();
+        while (iter.hasNext()) {
+            Map.Entry entry = (Map.Entry)iter.next();
+            Byte type = (Byte)entry.getKey();
+            AFPResourceLevel level = (AFPResourceLevel)entry.getValue();
+            this.defaultResourceLevels.put(type, level);
+        }
+    }
+
+}

Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPResourceLevelDefaults.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPResourceLevelDefaults.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPResourceManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPResourceManager.java?rev=741068&r1=741067&r2=741068&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPResourceManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPResourceManager.java Thu Feb  5 10:40:52 2009
@@ -53,6 +53,8 @@
 
     private Map pageSegmentMap = new java.util.HashMap();
 
+    private AFPResourceLevelDefaults resourceLevelDefaults = new AFPResourceLevelDefaults();
+
     /**
      * Main constructor
      */
@@ -218,4 +220,20 @@
         currentPage.createIncludePageSegment(pageSegmentName, x, y, createHardPageSegments);
     }
 
+    /**
+     * Sets resource level defaults. The existing defaults over merged with the ones passed in
+     * as parameter.
+     * @param defaults the new defaults
+     */
+    public void setResourceLevelDefaults(AFPResourceLevelDefaults defaults) {
+        this.resourceLevelDefaults.mergeFrom(defaults);
+    }
+
+    /**
+     * Returns the resource level defaults in use with this resource manager.
+     * @return the resource level defaults
+     */
+    public AFPResourceLevelDefaults getResourceLevelDefaults() {
+        return this.resourceLevelDefaults;
+    }
 }
\ No newline at end of file

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java?rev=741068&r1=741067&r2=741068&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java Thu Feb  5 10:40:52 2009
@@ -21,16 +21,17 @@
 
 import java.io.IOException;
 
+import org.apache.xmlgraphics.image.loader.ImageFlavor;
+import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
+import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
+import org.apache.xmlgraphics.util.MimeConstants;
+
 import org.apache.fop.afp.AFPDataObjectInfo;
 import org.apache.fop.afp.AFPGraphics2D;
 import org.apache.fop.afp.AFPGraphicsObjectInfo;
 import org.apache.fop.afp.AFPPaintingState;
 import org.apache.fop.afp.AFPResourceInfo;
-import org.apache.fop.afp.AFPResourceLevel;
-import org.apache.xmlgraphics.image.loader.ImageFlavor;
-import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
-import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
-import org.apache.xmlgraphics.util.MimeConstants;
+import org.apache.fop.afp.modca.ResourceObject;
 
 /**
  * PDFImageHandler implementation which handles Graphics2D images.
@@ -65,10 +66,9 @@
                 = (AFPGraphicsObjectInfo)super.generateDataObjectInfo(rendererImageInfo);
 
             AFPResourceInfo resourceInfo = graphicsObjectInfo.getResourceInfo();
-            //level not explicitly set/changed so default to inline for GOCA graphic objects
-            // (due to a bug in the IBM AFP Workbench Viewer (2.04.01.07), hard copy works just fine)
             if (!resourceInfo.levelChanged()) {
-                resourceInfo.setLevel(new AFPResourceLevel(AFPResourceLevel.INLINE));
+                resourceInfo.setLevel(afpInfo.getResourceManager().getResourceLevelDefaults()
+                        .getDefaultResourceLevel(ResourceObject.TYPE_GRAPHIC));
             }
 
             // set mime type (unsupported by MOD:CA registry)

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java?rev=741068&r1=741067&r2=741068&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java Thu Feb  5 10:40:52 2009
@@ -40,6 +40,8 @@
 import org.apache.fop.afp.AFPImageObjectInfo;
 import org.apache.fop.afp.AFPObjectAreaInfo;
 import org.apache.fop.afp.AFPPaintingState;
+import org.apache.fop.afp.AFPResourceInfo;
+import org.apache.fop.afp.modca.ResourceObject;
 import org.apache.fop.util.bitmap.BitmapImageUtil;
 
 /**
@@ -64,6 +66,13 @@
         AFPRendererContext rendererContext
             = (AFPRendererContext)rendererImageInfo.getRendererContext();
         AFPInfo afpInfo = rendererContext.getInfo();
+
+        AFPResourceInfo resourceInfo = imageObjectInfo.getResourceInfo();
+        if (!resourceInfo.levelChanged()) {
+            resourceInfo.setLevel(afpInfo.getResourceManager().getResourceLevelDefaults()
+                    .getDefaultResourceLevel(ResourceObject.TYPE_IMAGE));
+        }
+
         AFPPaintingState paintingState = afpInfo.getPaintingState();
         int resolution = paintingState.getResolution();
         int maxPixelSize = paintingState.getBitsPerPixel();
@@ -77,7 +86,8 @@
         ImageSize intrinsicSize = imageInfo.getSize();
 
         boolean useFS10 = (maxPixelSize == 1) || BitmapImageUtil.isMonochromeImage(renderedImage);
-        boolean usePageSegments = useFS10 && !imageObjectInfo.getResourceInfo().getLevel().isInline();
+        boolean usePageSegments = useFS10
+                    && !resourceInfo.getLevel().isInline();
 
         ImageSize effIntrinsicSize = intrinsicSize;
         if (usePageSegments) {
@@ -99,7 +109,8 @@
                             + " to " + resampledDim);
                 }
                 renderedImage = BitmapImageUtil.convertToMonochrome(renderedImage, resampledDim);
-                effIntrinsicSize = new ImageSize(resampledDim.width, resampledDim.height, resolution);
+                effIntrinsicSize = new ImageSize(
+                        resampledDim.width, resampledDim.height, resolution);
             }
         }
         if (useFS10) {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRenderer.java?rev=741068&r1=741067&r2=741068&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRenderer.java Thu Feb  5 10:40:52 2009
@@ -33,11 +33,20 @@
 import java.util.List;
 import java.util.Map;
 
+import org.apache.xmlgraphics.image.loader.ImageException;
+import org.apache.xmlgraphics.image.loader.ImageFlavor;
+import org.apache.xmlgraphics.image.loader.ImageInfo;
+import org.apache.xmlgraphics.image.loader.ImageManager;
+import org.apache.xmlgraphics.image.loader.ImageSessionContext;
+import org.apache.xmlgraphics.image.loader.util.ImageUtil;
+import org.apache.xmlgraphics.ps.ImageEncodingHelper;
+
 import org.apache.fop.afp.AFPBorderPainter;
 import org.apache.fop.afp.AFPDataObjectInfo;
 import org.apache.fop.afp.AFPEventProducer;
 import org.apache.fop.afp.AFPPaintingState;
 import org.apache.fop.afp.AFPRectanglePainter;
+import org.apache.fop.afp.AFPResourceLevelDefaults;
 import org.apache.fop.afp.AFPResourceManager;
 import org.apache.fop.afp.AFPTextDataInfo;
 import org.apache.fop.afp.AFPUnitConverter;
@@ -72,13 +81,6 @@
 import org.apache.fop.render.RendererContext;
 import org.apache.fop.render.afp.extensions.AFPElementMapping;
 import org.apache.fop.render.afp.extensions.AFPPageSetup;
-import org.apache.xmlgraphics.image.loader.ImageException;
-import org.apache.xmlgraphics.image.loader.ImageFlavor;
-import org.apache.xmlgraphics.image.loader.ImageInfo;
-import org.apache.xmlgraphics.image.loader.ImageManager;
-import org.apache.xmlgraphics.image.loader.ImageSessionContext;
-import org.apache.xmlgraphics.image.loader.util.ImageUtil;
-import org.apache.xmlgraphics.ps.ImageEncodingHelper;
 
 /**
  * This is an implementation of a FOP Renderer that renders areas to AFP.
@@ -744,6 +746,15 @@
         resourceManager.setDefaultResourceGroupFilePath(filePath);
     }
 
+    /**
+     * Sets the resource level defaults. The object passed in provides information which resource
+     * level shall be used by default for various kinds of resources.
+     * @param defaults the resource level defaults
+     */
+    public void setResourceLevelDefaults(AFPResourceLevelDefaults defaults) {
+        resourceManager.setResourceLevelDefaults(defaults);
+    }
+
     /** {@inheritDoc} */
     protected void establishTransformationMatrix(AffineTransform at) {
         saveGraphicsState();

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java?rev=741068&r1=741067&r2=741068&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java Thu Feb  5 10:40:52 2009
@@ -25,6 +25,8 @@
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 
+import org.apache.fop.afp.AFPResourceLevel;
+import org.apache.fop.afp.AFPResourceLevelDefaults;
 import org.apache.fop.afp.fonts.AFPFontInfo;
 import org.apache.fop.afp.fonts.CharacterSet;
 import org.apache.fop.afp.fonts.FopCharacterSet;
@@ -282,6 +284,26 @@
                                 + resourceGroupDest + "'");
                 }
             }
+
+            Configuration defaultResourceLevelCfg = cfg.getChild("default-resource-levels", false);
+            if (defaultResourceLevelCfg != null) {
+                AFPResourceLevelDefaults defaults = new AFPResourceLevelDefaults();
+                String[] types = defaultResourceLevelCfg.getAttributeNames();
+                for (int i = 0, c = types.length; i < c; i++) {
+                    String type = types[i];
+                    try {
+                        String level = defaultResourceLevelCfg.getAttribute(type);
+                        defaults.setDefaultResourceLevel(type, AFPResourceLevel.valueOf(level));
+                    } catch (IllegalArgumentException iae) {
+                        LogUtil.handleException(log, iae,
+                                userAgent.getFactory().validateUserConfigStrictly());
+                    } catch (ConfigurationException e) {
+                        LogUtil.handleException(log, e,
+                                userAgent.getFactory().validateUserConfigStrictly());
+                    }
+                }
+                afpRenderer.setResourceLevelDefaults(defaults);
+            }
         }
     }
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRendererContext.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRendererContext.java?rev=741068&r1=741067&r2=741068&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRendererContext.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRendererContext.java Thu Feb  5 10:40:52 2009
@@ -22,10 +22,11 @@
 import java.util.Map;
 
 import org.apache.avalon.framework.configuration.Configuration;
+
 import org.apache.fop.afp.AFPPaintingState;
 import org.apache.fop.afp.AFPResourceInfo;
-import org.apache.fop.afp.AFPResourceLevel;
 import org.apache.fop.afp.AFPResourceManager;
+import org.apache.fop.afp.modca.ResourceObject;
 import org.apache.fop.render.AbstractRenderer;
 import org.apache.fop.render.RendererContext;
 import org.apache.fop.render.RendererContextConstants;
@@ -72,9 +73,12 @@
                 = new AFPForeignAttributeReader();
             AFPResourceInfo resourceInfo
                 = foreignAttributeReader.getResourceInfo(foreignAttributes);
-            // default to inline level if painted as GOCA
-            if (!resourceInfo.levelChanged() && !paintAsBitmap) {
-                resourceInfo.setLevel(new AFPResourceLevel(AFPResourceLevel.INLINE));
+            // set default resource level if an explicit one hasn't been set
+            if (!resourceInfo.levelChanged()) {
+                byte resourceType = paintAsBitmap
+                    ? ResourceObject.TYPE_IMAGE : ResourceObject.TYPE_GRAPHIC;
+                resourceInfo.setLevel(info.getResourceManager().getResourceLevelDefaults()
+                        .getDefaultResourceLevel(resourceType));
             }
             info.setResourceInfo(resourceInfo);
         }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AbstractAFPImageHandlerRawStream.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AbstractAFPImageHandlerRawStream.java?rev=741068&r1=741067&r2=741068&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AbstractAFPImageHandlerRawStream.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AbstractAFPImageHandlerRawStream.java Thu Feb  5 10:40:52 2009
@@ -23,13 +23,17 @@
 import java.io.InputStream;
 
 import org.apache.commons.io.IOUtils;
-import org.apache.fop.afp.AFPDataObjectInfo;
-import org.apache.fop.afp.AFPObjectAreaInfo;
-import org.apache.fop.afp.AFPPaintingState;
+
 import org.apache.xmlgraphics.image.loader.ImageInfo;
 import org.apache.xmlgraphics.image.loader.ImageSize;
 import org.apache.xmlgraphics.image.loader.impl.ImageRawStream;
 
+import org.apache.fop.afp.AFPDataObjectInfo;
+import org.apache.fop.afp.AFPObjectAreaInfo;
+import org.apache.fop.afp.AFPPaintingState;
+import org.apache.fop.afp.AFPResourceInfo;
+import org.apache.fop.afp.modca.ResourceObject;
+
 /**
  * A base abstract AFP raw stream image handler
  */
@@ -39,12 +43,22 @@
     public AFPDataObjectInfo generateDataObjectInfo(
             AFPRendererImageInfo rendererImageInfo) throws IOException {
         AFPDataObjectInfo dataObjectInfo = super.generateDataObjectInfo(rendererImageInfo);
+        AFPRendererContext rendererContext
+            = (AFPRendererContext)rendererImageInfo.getRendererContext();
+        AFPInfo afpInfo = rendererContext.getInfo();
 
         ImageInfo imageInfo = rendererImageInfo.getImageInfo();
         String mimeType = imageInfo.getMimeType();
         if (mimeType != null) {
             dataObjectInfo.setMimeType(mimeType);
         }
+
+        AFPResourceInfo resourceInfo = dataObjectInfo.getResourceInfo();
+        if (!resourceInfo.levelChanged()) {
+            resourceInfo.setLevel(afpInfo.getResourceManager().getResourceLevelDefaults()
+                    .getDefaultResourceLevel(ResourceObject.TYPE_IMAGE));
+        }
+
         ImageRawStream rawStream = (ImageRawStream) rendererImageInfo.getImage();
         InputStream inputStream = rawStream.createInputStream();
         try {
@@ -65,9 +79,6 @@
 
         // set object area info
         AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo();
-        AFPRendererContext rendererContext
-            = (AFPRendererContext)rendererImageInfo.getRendererContext();
-        AFPInfo afpInfo = rendererContext.getInfo();
         AFPPaintingState paintingState = afpInfo.getPaintingState();
         int resolution = paintingState.getResolution();
         objectAreaInfo.setWidthRes(resolution);

Modified: xmlgraphics/fop/trunk/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=741068&r1=741067&r2=741068&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Thu Feb  5 10:40:52 2009
@@ -58,6 +58,10 @@
       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="JM" type="add">
+        AFP Output: Added a configuration option to override the resource level defaults in the
+        code.
+      </action>
       <action context="Code" dev="VH" type="fix" fixes-bug="46638">
         MinOptMaxUtil.toMinOptMax was converting LengthRangeProperty objects into illegal MinOptMax 
         objects (in some cases opt could be inferior to min).



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org