diff options
Diffstat (limited to 'src/java/org/apache/fop/render')
5 files changed, 82 insertions, 18 deletions
diff --git a/src/java/org/apache/fop/render/afp/AFPCustomizable.java b/src/java/org/apache/fop/render/afp/AFPCustomizable.java index 93aaa8b1a..04f3a6eeb 100644 --- a/src/java/org/apache/fop/render/afp/AFPCustomizable.java +++ b/src/java/org/apache/fop/render/afp/AFPCustomizable.java @@ -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 */ diff --git a/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java b/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java index 87651defd..f45baaff6 100644 --- a/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java +++ b/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java @@ -415,6 +415,26 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler } /** {@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); } diff --git a/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java b/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java index 07b712ceb..f60e271cb 100644 --- a/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java +++ b/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java @@ -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 extends AFPImageHandler implements ImageH } /** {@inheritDoc} */ + @Override protected AFPDataObjectInfo createDataObjectInfo() { return new AFPGraphicsObjectInfo(); } @@ -104,13 +103,13 @@ public class AFPImageHandlerGraphics2D extends AFPImageHandler implements ImageH // 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 extends AFPImageHandler implements ImageH 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 diff --git a/src/java/org/apache/fop/render/afp/AFPImageHandlerSVG.java b/src/java/org/apache/fop/render/afp/AFPImageHandlerSVG.java index 4e4e1de31..834304f6b 100644 --- a/src/java/org/apache/fop/render/afp/AFPImageHandlerSVG.java +++ b/src/java/org/apache/fop/render/afp/AFPImageHandlerSVG.java @@ -82,16 +82,16 @@ public class AFPImageHandlerSVG implements ImageHandler { 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 implements ImageHandler { && 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 diff --git a/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java b/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java index 8d4b3370c..8cc381c18 100644 --- a/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java +++ b/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java @@ -76,7 +76,7 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator 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 extends PrintRendererConfigurator 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 extends PrintRendererConfigurator 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 extends PrintRendererConfigurator * @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 extends PrintRendererConfigurator 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 extends PrintRendererConfigurator * * @param renderer not used */ + @Override public void configure(Renderer renderer) { throw new UnsupportedOperationException(); } @@ -400,6 +401,16 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator 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 extends PrintRendererConfigurator 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 extends PrintRendererConfigurator } /** {@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 extends PrintRendererConfigurator } /** {@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 extends PrintRendererConfigurator } fontManager.setup(fontInfo, - (FontCollection[])fontCollections.toArray( + fontCollections.toArray( new FontCollection[fontCollections.size()])); documentHandler.setFontInfo(fontInfo); } |