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 2011/04/22 08:43:22 UTC

svn commit: r1095874 - 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: Fri Apr 22 06:43:22 2011
New Revision: 1095874

URL: http://svn.apache.org/viewvc?rev=1095874&view=rev
Log:
AFP GOCA: Added option to disable GOCA and to control text painting inside GOCA graphics.

Modified:
    xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/output.xml
    xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPPaintingState.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPCustomizable.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerSVG.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.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=1095874&r1=1095873&r2=1095874&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/output.xml (original)
+++ xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/output.xml Fri Apr 22 06:43:22 2011
@@ -784,6 +784,29 @@ Note that the value of the encoding attr
         <source><![CDATA[
       <images mode="b+w" bits-per-pixel="1" dithering-quality="maximum"/>]]></source>
       </section>
+      <section id="afp-goca-config">
+        <title>GOCA (Vector Graphics)</title>
+        <p>
+          Not all AFP implementations support GOCA. Some also have bugs related to GOCA. Therefore,
+          it is desirable to have some control over the generation of GOCA graphics.
+        </p>
+        <p>
+          GOCA is enabled by default. You can disable GOCA entirely in which case the AFP support
+          falls back to generating bitmaps for vector graphics. Example:
+        </p>
+        <source><![CDATA[
+      <goca enabled="false"/>]]></source>
+        <p>
+          Some AFP implementations have trouble rendering text in GOCA. You can instruct the AFP
+          support to render text as shapes (i.e. use vector graphics to paint text). Example: 
+        </p>
+        <source><![CDATA[
+      <goca enabled="true" text="shapes"/>]]></source>
+        <p>
+          If you disable GOCA or let text render as shapes, the size of the generated AFP usually
+          increases considerably.
+        </p>
+      </section>
       <section id="afp-shading-config">
         <title>Shading</title>
         <p>

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPPaintingState.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPPaintingState.java?rev=1095874&r1=1095873&r2=1095874&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPPaintingState.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPPaintingState.java Fri Apr 22 06:43:22 2011
@@ -73,6 +73,11 @@ public class AFPPaintingState extends or
     /** the output resolution */
     private int resolution = 240; // 240 dpi
 
+    /** determines whether GOCA is enabled or disabled  */
+    private boolean gocaEnabled = true;
+    /** determines whether to stroke text in GOCA mode or to use text operators where possible */
+    private boolean strokeGocaText = false;
+
     /** the current page */
     private transient AFPPagePaintingState pagePaintingState = new AFPPagePaintingState();
 
@@ -276,12 +281,46 @@ public class AFPPaintingState extends or
         return this.resolution;
     }
 
+    /**
+     * Controls whether GOCA is enabled or disabled.
+     * @param enabled true if GOCA is enabled, false if it is disabled
+     */
+    public void setGOCAEnabled(boolean enabled) {
+        this.gocaEnabled = enabled;
+    }
+
+    /**
+     * Indicates whether GOCA is enabled or disabled.
+     * @return true if GOCA is enabled, false if GOCA is disabled
+     */
+    public boolean isGOCAEnabled() {
+        return this.gocaEnabled;
+    }
+
+    /**
+     * Controls whether to stroke text in GOCA mode or to use text operators where possible.
+     * @param stroke true to stroke, false to paint with text operators where possible
+     */
+    public void setStrokeGOCAText(boolean stroke) {
+        this.strokeGocaText = stroke;
+    }
+
+    /**
+     * Indicates whether to stroke text in GOCA mode or to use text operators where possible.
+     * @return true to stroke, false to paint with text operators where possible
+     */
+    public boolean isStrokeGOCAText() {
+        return this.strokeGocaText;
+    }
+
     /** {@inheritDoc} */
+    @Override
     protected AbstractData instantiateData() {
         return new AFPData();
     }
 
     /** {@inheritDoc} */
+    @Override
     protected AbstractPaintingState instantiate() {
         return new AFPPaintingState();
     }
@@ -423,6 +462,7 @@ public class AFPPaintingState extends or
     }
 
     /** {@inheritDoc} */
+    @Override
     public Object clone() {
         AFPPaintingState paintingState = (AFPPaintingState) super.clone();
         paintingState.pagePaintingState = (AFPPagePaintingState) this.pagePaintingState.clone();
@@ -436,6 +476,7 @@ public class AFPPaintingState extends or
     }
 
     /** {@inheritDoc} */
+    @Override
     public String toString() {
         return "AFPPaintingState{" + "portraitRotation=" + portraitRotation
                 + ", landscapeRotation=" + landscapeRotation + ", colorImages=" + colorImages
@@ -548,6 +589,7 @@ public class AFPPaintingState extends or
         }
 
         /** {@inheritDoc} */
+        @Override
         public Object clone() {
             AFPPagePaintingState state = new AFPPagePaintingState();
             state.width = this.width;
@@ -559,6 +601,7 @@ public class AFPPaintingState extends or
         }
 
         /** {@inheritDoc} */
+        @Override
         public String toString() {
             return "AFPPagePaintingState{width=" + width + ", height=" + height + ", orientation="
                     + orientation + ", fonts=" + fonts + ", fontCount=" + fontCount + "}";
@@ -577,6 +620,7 @@ public class AFPPaintingState extends or
         private String imageUri = null;
 
         /** {@inheritDoc} */
+        @Override
         public Object clone() {
             AFPData obj = (AFPData) super.clone();
             obj.filled = this.filled;
@@ -585,12 +629,14 @@ public class AFPPaintingState extends or
         }
 
         /** {@inheritDoc} */
+        @Override
         public String toString() {
             return "AFPData{" + super.toString() + ", filled=" + filled + ", imageUri=" + imageUri
                     + "}";
         }
 
         /** {@inheritDoc} */
+        @Override
         protected AbstractData instantiate() {
             return new AFPData();
         }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPCustomizable.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPCustomizable.java?rev=1095874&r1=1095873&r2=1095874&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPCustomizable.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPCustomizable.java Fri Apr 22 06:43:22 2011
@@ -87,6 +87,30 @@ public interface AFPCustomizable {
     int getResolution();
 
     /**
+     * Controls whether GOCA is enabled or disabled.
+     * @param enabled true if GOCA is enabled, false if it is disabled
+     */
+     void setGOCAEnabled(boolean enabled);
+
+    /**
+     * Indicates whether GOCA is enabled or disabled.
+     * @return true if GOCA is enabled, false if GOCA is disabled
+     */
+    boolean isGOCAEnabled();
+
+    /**
+     * Controls whether to stroke text in GOCA mode or to use text operators where possible.
+     * @param stroke true to stroke, false to paint with text operators where possible
+     */
+    void setStrokeGOCAText(boolean stroke);
+
+    /**
+     * Indicates whether to stroke text in GOCA mode or to use text operators where possible.
+     * @return true to stroke, false to paint with text operators where possible
+     */
+    boolean isStrokeGOCAText();
+
+    /**
      * Sets the default resource group file path
      * @param filePath the default resource group file path
      */

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java?rev=1095874&r1=1095873&r2=1095874&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java Fri Apr 22 06:43:22 2011
@@ -415,6 +415,26 @@ public class AFPDocumentHandler extends 
     }
 
     /** {@inheritDoc} */
+    public void setGOCAEnabled(boolean enabled) {
+        this.paintingState.setGOCAEnabled(enabled);
+    }
+
+    /** {@inheritDoc} */
+    public boolean isGOCAEnabled() {
+        return this.paintingState.isGOCAEnabled();
+    }
+
+    /** {@inheritDoc} */
+    public void setStrokeGOCAText(boolean stroke) {
+        this.paintingState.setStrokeGOCAText(stroke);
+    }
+
+    /** {@inheritDoc} */
+    public boolean isStrokeGOCAText() {
+        return this.paintingState.isStrokeGOCAText();
+    }
+
+    /** {@inheritDoc} */
     public void setDefaultResourceGroupFilePath(String filePath) {
         resourceManager.setDefaultResourceGroupFilePath(filePath);
     }

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=1095874&r1=1095873&r2=1095874&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 Fri Apr 22 06:43:22 2011
@@ -26,8 +26,6 @@ import java.io.IOException;
 import org.apache.xmlgraphics.image.loader.Image;
 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;
@@ -74,6 +72,7 @@ public class AFPImageHandlerGraphics2D e
     }
 
     /** {@inheritDoc} */
+    @Override
     protected AFPDataObjectInfo createDataObjectInfo() {
         return new AFPGraphicsObjectInfo();
     }
@@ -104,13 +103,13 @@ public class AFPImageHandlerGraphics2D e
 
         // Image content
         ImageGraphics2D imageG2D = (ImageGraphics2D)image;
-        boolean textAsShapes = false; //TODO Make configurable
+        final boolean textAsShapes = paintingState.isStrokeGOCAText();
         AFPGraphics2D g2d = new AFPGraphics2D(
                 textAsShapes,
                 afpContext.getPaintingState(),
                 afpContext.getResourceManager(),
                 graphicsObjectInfo.getResourceInfo(),
-                afpContext.getFontInfo());
+                (textAsShapes ? null : afpContext.getFontInfo()));
         g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
 
         graphicsObjectInfo.setGraphics2D(g2d);
@@ -127,6 +126,10 @@ public class AFPImageHandlerGraphics2D e
         boolean supported = (image == null || image instanceof ImageGraphics2D)
                 && targetContext instanceof AFPRenderingContext;
         if (supported) {
+            AFPRenderingContext afpContext = (AFPRenderingContext)targetContext;
+            if (!afpContext.getPaintingState().isGOCAEnabled()) {
+                return false;
+            }
             String mode = (String)targetContext.getHint(ImageHandlerUtil.CONVERSION_MODE);
             if (ImageHandlerUtil.isConversionModeBitmap(mode)) {
                 //Disabling this image handler automatically causes a bitmap to be generated

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerSVG.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerSVG.java?rev=1095874&r1=1095873&r2=1095874&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerSVG.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerSVG.java Fri Apr 22 06:43:22 2011
@@ -82,16 +82,16 @@ public class AFPImageHandlerSVG implemen
         setDefaultToInlineResourceLevel(graphicsObjectInfo);
 
         // Create a new AFPGraphics2D
-        final boolean textAsShapes = false; //afpInfo.strokeText(); //TODO make configurable
+        AFPPaintingState paintingState = afpContext.getPaintingState();
+        final boolean textAsShapes = paintingState.isStrokeGOCAText();
         AFPGraphics2D g2d = new AFPGraphics2D(
                 textAsShapes,
                 afpContext.getPaintingState(),
                 afpContext.getResourceManager(),
                 resourceInfo,
-                afpContext.getFontInfo());
+                (textAsShapes ? null : afpContext.getFontInfo()));
         g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
 
-        AFPPaintingState paintingState = g2d.getPaintingState();
         paintingState.setImageUri(image.getInfo().getOriginalURI());
 
         // Create an AFPBridgeContext
@@ -167,6 +167,10 @@ public class AFPImageHandlerSVG implemen
                 && image.getFlavor().isCompatible(BatikImageFlavors.SVG_DOM)))
                 && targetContext instanceof AFPRenderingContext;
         if (supported) {
+            AFPRenderingContext afpContext = (AFPRenderingContext)targetContext;
+            if (!afpContext.getPaintingState().isGOCAEnabled()) {
+                return false;
+            }
             String mode = (String)targetContext.getHint(ImageHandlerUtil.CONVERSION_MODE);
             if (ImageHandlerUtil.isConversionModeBitmap(mode)) {
                 //Disabling this image handler automatically causes a bitmap to be generated

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=1095874&r1=1095873&r2=1095874&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 Fri Apr 22 06:43:22 2011
@@ -76,7 +76,7 @@ public class AFPRendererConfigurator ext
         FontManager fontManager = this.userAgent.getFactory().getFontManager();
 
         Configuration[] triple = fontCfg.getChildren("font-triplet");
-        List/*<FontTriplet>*/ tripletList = new java.util.ArrayList/*<FontTriplet>*/();
+        List<FontTriplet> tripletList = new java.util.ArrayList<FontTriplet>();
         if (triple.length == 0) {
             log.error("Mandatory font configuration element '<font-triplet...' is missing");
             return null;
@@ -184,8 +184,8 @@ public class AFPRendererConfigurator ext
 
                 if (base14 != null) {
                     try {
-                        Class clazz = Class.forName("org.apache.fop.fonts.base14."
-                                + base14);
+                        Class<?> clazz = Class.forName(
+                                "org.apache.fop.fonts.base14." + base14);
                         try {
                             Typeface tf = (Typeface)clazz.newInstance();
                             font.addCharacterSet(sizeMpt,
@@ -223,7 +223,7 @@ public class AFPRendererConfigurator ext
             String base14 = afpFontCfg.getAttribute("base14-font", null);
             if (base14 != null) {
                 try {
-                    Class clazz = Class.forName("org.apache.fop.fonts.base14."
+                    Class<?> clazz = Class.forName("org.apache.fop.fonts.base14."
                             + base14);
                     try {
                         Typeface tf = (Typeface)clazz.newInstance();
@@ -291,7 +291,7 @@ public class AFPRendererConfigurator ext
      * @return List the newly created list of fonts
      * @throws ConfigurationException if something's wrong with the config data
      */
-    private List/*<AFPFontInfo>*/ buildFontListFromConfiguration(Configuration cfg)
+    private List<AFPFontInfo> buildFontListFromConfiguration(Configuration cfg)
     throws FOPException, ConfigurationException {
 
         Configuration fonts = cfg.getChild("fonts");
@@ -309,7 +309,7 @@ public class AFPRendererConfigurator ext
                     referencedFontsCfg, this.userAgent.getFactory().validateUserConfigStrictly());
         }
 
-        List/*<AFPFontInfo>*/ fontList = new java.util.ArrayList();
+        List<AFPFontInfo> fontList = new java.util.ArrayList<AFPFontInfo>();
         Configuration[] font = fonts.getChildren("font");
         final String fontPath = null;
         for (int i = 0; i < font.length; i++) {
@@ -352,6 +352,7 @@ public class AFPRendererConfigurator ext
      *
      * @param renderer not used
      */
+    @Override
     public void configure(Renderer renderer) {
         throw new UnsupportedOperationException();
     }
@@ -400,6 +401,16 @@ public class AFPRendererConfigurator ext
                 shadingCfg.getValue(AFPShadingMode.COLOR.getName()));
         customizable.setShadingMode(shadingMode);
 
+        // GOCA Support
+        Configuration gocaCfg = cfg.getChild("goca");
+        boolean gocaEnabled = gocaCfg.getAttributeAsBoolean(
+                "enabled", customizable.isGOCAEnabled());
+        customizable.setGOCAEnabled(gocaEnabled);
+        String gocaText = gocaCfg.getAttribute(
+                "text", customizable.isStrokeGOCAText() ? "stroke" : "default");
+        customizable.setStrokeGOCAText("stroke".equalsIgnoreCase(gocaText)
+                || "shapes".equalsIgnoreCase(gocaText));
+
         // renderer resolution
         Configuration rendererResolutionCfg = cfg.getChild("renderer-resolution", false);
         if (rendererResolutionCfg != null) {
@@ -415,8 +426,8 @@ public class AFPRendererConfigurator ext
                 resourceGroupDest = resourceGroupFileCfg.getValue();
                 if (resourceGroupDest != null) {
                     File resourceGroupFile = new File(resourceGroupDest);
-                    resourceGroupFile.createNewFile();
-                    if (resourceGroupFile.canWrite()) {
+                    boolean created = resourceGroupFile.createNewFile();
+                    if (created && resourceGroupFile.canWrite()) {
                         customizable.setDefaultResourceGroupFilePath(resourceGroupDest);
                     } else {
                         log.warn("Unable to write to default external resource group file '"
@@ -454,6 +465,7 @@ public class AFPRendererConfigurator ext
     }
 
     /** {@inheritDoc} */
+    @Override
     public void configure(IFDocumentHandler documentHandler) throws FOPException {
         Configuration cfg = super.getRendererConfig(documentHandler.getMimeType());
         if (cfg != null) {
@@ -463,15 +475,16 @@ public class AFPRendererConfigurator ext
     }
 
     /** {@inheritDoc} */
+    @Override
     public void setupFontInfo(IFDocumentHandler documentHandler, FontInfo fontInfo)
             throws FOPException {
         FontManager fontManager = userAgent.getFactory().getFontManager();
-        List fontCollections = new java.util.ArrayList();
+        List<FontCollection> fontCollections = new java.util.ArrayList<FontCollection>();
 
         Configuration cfg = super.getRendererConfig(documentHandler.getMimeType());
         if (cfg != null) {
             try {
-                List fontList = buildFontListFromConfiguration(cfg);
+                List<AFPFontInfo> fontList = buildFontListFromConfiguration(cfg);
                 fontCollections.add(new AFPFontCollection(
                         userAgent.getEventBroadcaster(), fontList));
             } catch (ConfigurationException e) {
@@ -483,7 +496,7 @@ public class AFPRendererConfigurator ext
         }
 
         fontManager.setup(fontInfo,
-                (FontCollection[])fontCollections.toArray(
+                fontCollections.toArray(
                         new FontCollection[fontCollections.size()]));
         documentHandler.setFontInfo(fontInfo);
     }

Modified: xmlgraphics/fop/trunk/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=1095874&r1=1095873&r2=1095874&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Fri Apr 22 06:43:22 2011
@@ -59,6 +59,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="JM" type="add">
+        AFP GOCA: Added option to disable GOCA and to control text painting inside GOCA graphics.
+      </action>
       <action context="Renderers" dev="JM" type="fix">
         AFP GOCA: Work-around for InfoPrint's AFP implementation which seems to lose
         the character set state over Graphics Data (GAD) boundaries.



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