From a30e3c29fd55d4d1b70f386180a8e7936a9dd799 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Tue, 22 Sep 2009 10:39:43 +0000 Subject: Trying to clear up afp:include-page-segment as there are questions every now and then. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@817584 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/trunk/output.xml | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/documentation/content/xdocs/trunk') diff --git a/src/documentation/content/xdocs/trunk/output.xml b/src/documentation/content/xdocs/trunk/output.xml index 9c88c27d0..0ae9d586b 100644 --- a/src/documentation/content/xdocs/trunk/output.xml +++ b/src/documentation/content/xdocs/trunk/output.xml @@ -796,6 +796,17 @@ out = proc.getOutputStream();]]> fo:external-graphic elements and if it is identical (string matching is used) in the generated AFP the external graphic is replaced by a reference to the given resource.

+

+ The effect here is that whenever FOP encounters the URI specified in the extension, + it will effectively generate code to include the page segment with the given name + instead of embedding the image referenced by the URI. The URI is still required as + the underlying image serves as a provider for the intrinsic size of the image + (At the moment, FOP is unable to extract the intrinsic size of the page segment from + an AFP resource file). For the image to appear in an AFP viewer or to be printed, the + AFP resource must be available on the target device. FOP does not embed the page + segment in the generated file. Please also note that page segments cannot be scaled. + They are always rendered in their intrinsic size. +

Tag Logical Element (TLE) Extension -- cgit v1.2.3 From b6638c65c94d5afb8ca0f6ea0b37632cf8fb11be Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Fri, 2 Oct 2009 09:19:12 +0000 Subject: Added support for creating thumbnails or preview bitmaps of fixed size for PNG and TIFF output. Documentation update for bitmap output. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@820939 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/trunk/output.xml | 84 ++++++++++++++++++---- .../bitmap/AbstractBitmapDocumentHandler.java | 70 ++++++++++++++++-- .../render/bitmap/BitmapRendererConfigurator.java | 5 +- status.xml | 4 ++ 4 files changed, 142 insertions(+), 21 deletions(-) (limited to 'src/documentation/content/xdocs/trunk') diff --git a/src/documentation/content/xdocs/trunk/output.xml b/src/documentation/content/xdocs/trunk/output.xml index 0ae9d586b..972fc1f19 100644 --- a/src/documentation/content/xdocs/trunk/output.xml +++ b/src/documentation/content/xdocs/trunk/output.xml @@ -1033,8 +1033,13 @@ out = proc.getOutputStream();]]>

Currently, two output formats are supported: PNG and TIFF. TIFF produces one file with multiple pages, while PNG output produces one file per - page. The quality of the bitmap depends on the target resolution setting - on the FOUserAgent. + page. Note: FOP can only produce multiple files (with PNG output) if + you can set a java.io.File indicating the primary PNG file + using the FOUserAgent.setOutputFile(File) method. +

+

+ The quality of the bitmap depends on the target resolution setting + on the FOUserAgent and on further settings described below.

Configuration @@ -1042,15 +1047,52 @@ out = proc.getOutputStream();]]> The TIFF and PNG renderer configuration currently allows the following settings:

+ rgba true + white + true + quality ]]>

- The default value for the "transparent-page-background" setting is "false" which - paints an opaque, white background for the whole image. If you set this to true, + The default value for the "color-mode" setting is "rgba" which + is equivalent to a 24bit RGB image with an 8bit alpha channel for transparency. + Valid values are: +

+
    +
  • rgba: RGB with alpha channel (24bit + 8bit = 32bit)
  • +
  • rgb: RGB (24bit)
  • +
  • gray: gray (8bit)
  • +
  • bi-level (or binary): bi-level (1bit)
  • +
+

+ Please note that there is currently no dithering or error diffusion available for bi-level + bitmap output. +

+

+ The default value for the "transparent-page-background" setting is + "false" which paints an opaque, white background for the whole image. + If you set this to "true", no such background will be painted and you will get a transparent image if an alpha channel is available in the output format.

+

+ The default value for the "background-color" setting is "white". + The color specifies in which color the page background is painted. It will only be + painted if "transparent-page-background" is not set to "true". + All XSL-FO colors (including color functions) can be used. +

+

+ The default value for the "anti-aliasing" setting is "true". + You can set this value to "false" to disable anti-aliasing and + thus improve rendering speeds a bit at the loss of some image quality. +

+

+ The default value for the "rendering" setting is "true". + You can set this value to "false" to improve rendering speeds a bit + at the loss of some image quality. If this setting has an actual effect depends + on the JVM's Java2D backend. +

TIFF-specific Configuration @@ -1071,17 +1113,22 @@ out = proc.getOutputStream();]]> actual codecs being available. Here is a list of possible values:

    -
  • NONE (no compression)
  • -
  • PackBits (RLE, run-length encoding)
  • -
  • JPEG
  • -
  • Deflate
  • -
  • LZW
  • -
  • ZLib
  • -
  • CCITT T.4 (Fax Group 3)
  • -
  • CCITT T.6 (Fax Group 4)
  • +
  • NONE (no compression)
  • +
  • PackBits (RLE, run-length encoding)
  • +
  • JPEG
  • +
  • Deflate
  • +
  • LZW
  • +
  • ZLib
  • +
  • CCITT T.4 (Fax Group 3)
  • +
  • CCITT T.6 (Fax Group 4)
+

+ This setting may override any setting made using the "color-mode". For example, if + "CCITT T.6" is selected, the color mode is automatically forced to "bi-level" because + this compression format only supports bi-level images. +

- If you want to use CCITT compression, please make sure you've got a J2SE 1.4 or later and + If you want to use CCITT compression, please make sure you've got Java Advanced Imaging Image I/O Tools @@ -1090,6 +1137,17 @@ out = proc.getOutputStream();]]> Deflate and JPEG compression for writing.
+
+ Runtime Rendering Options +

+ The IF-based bitmap output implementations support a rendering option with the key + "target-bitmap-size" (value: java.awt.Dimension) that allows to force the pages to + be proportionally fit into a bitmap of a given size. This can be used to produce + thumbnails or little preview images of the individual pages. An example: +

+ +
TXT diff --git a/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java b/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java index 3449ffe7e..e4606858b 100644 --- a/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java +++ b/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java @@ -22,9 +22,11 @@ package org.apache.fop.render.bitmap; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.RenderingHints; +import java.awt.geom.Point2D; import java.awt.image.BufferedImage; import java.io.IOException; import java.io.OutputStream; +import java.util.Map; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; @@ -53,6 +55,13 @@ public abstract class AbstractBitmapDocumentHandler extends AbstractBinaryWritin /** logging instance */ private static Log log = LogFactory.getLog(AbstractBitmapDocumentHandler.class); + /** + * Rendering Options key for the controlling the required bitmap size to create. + * This is used to create thumbnails, for example. If used, the target resolution is ignored. + * Value type: java.awt.Dimension (size in pixels) + */ + public static final String TARGET_BITMAP_SIZE = "target-bitmap-size"; + private ImageWriter imageWriter; private MultiImageWriter multiImageWriter; @@ -66,6 +75,7 @@ public abstract class AbstractBitmapDocumentHandler extends AbstractBinaryWritin private BitmapRenderingSettings bitmapSettings = new BitmapRenderingSettings(); private double scaleFactor = 1.0; + private Dimension targetBitmapSize; /** * Default constructor. @@ -94,6 +104,9 @@ public abstract class AbstractBitmapDocumentHandler extends AbstractBinaryWritin //Set target resolution int dpi = Math.round(context.getUserAgent().getTargetResolution()); getSettings().getWriterParams().setResolution(dpi); + + Map renderingOptions = getUserAgent().getRendererOptions(); + setTargetBitmapSize((Dimension)renderingOptions.get(TARGET_BITMAP_SIZE)); } /** {@inheritDoc} */ @@ -113,6 +126,17 @@ public abstract class AbstractBitmapDocumentHandler extends AbstractBinaryWritin setFontInfo(fi); } + /** + * Sets the target bitmap size (in pixels) of the bitmap that should be produced. Normally, + * the bitmap size is calculated automatically based on the page size and the target + * resolution. But for example, if you want to create thumbnails or small preview bitmaps + * from pages it is more practical (and efficient) to set the required bitmap size. + * @param size the target bitmap size (in pixels) + */ + public void setTargetBitmapSize(Dimension size) { + this.targetBitmapSize = size; + } + //---------------------------------------------------------------------------------------------- /** {@inheritDoc} */ @@ -176,13 +200,43 @@ public abstract class AbstractBitmapDocumentHandler extends AbstractBinaryWritin /** {@inheritDoc} */ public IFPainter startPageContent() throws IFException { - double scale = scaleFactor - * (25.4f / FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION) - / getUserAgent().getTargetPixelUnitToMillimeter(); - int bitmapWidth = (int) ((this.currentPageDimensions.width * scale / 1000f) + 0.5f); - int bitmapHeight = (int) ((this.currentPageDimensions.height * scale / 1000f) + 0.5f); + int bitmapWidth; + int bitmapHeight; + double scale; + Point2D offset = null; + if (targetBitmapSize != null) { + //Fit the generated page proportionally into the given rectangle (in pixels) + double scale2w = 1000 * targetBitmapSize.width + / this.currentPageDimensions.getWidth(); + double scale2h = 1000 * targetBitmapSize.height + / this.currentPageDimensions.getHeight(); + bitmapWidth = targetBitmapSize.width; + bitmapHeight = targetBitmapSize.height; + + //Centering the page in the given bitmap + offset = new Point2D.Double(); + if (scale2w < scale2h) { + scale = scale2w; + double h = this.currentPageDimensions.height * scale / 1000; + offset.setLocation(0, (bitmapHeight - h) / 2.0); + } else { + scale = scale2h; + double w = this.currentPageDimensions.width * scale / 1000; + offset.setLocation((bitmapWidth - w) / 2.0, 0); + } + } else { + //Normal case: just scale according to the target resolution + scale = scaleFactor + * getUserAgent().getTargetResolution() + / FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION; + bitmapWidth = (int) ((this.currentPageDimensions.width * scale / 1000f) + 0.5f); + bitmapHeight = (int) ((this.currentPageDimensions.height * scale / 1000f) + 0.5f); + } + + //Set up bitmap to paint on this.currentImage = createBufferedImage(bitmapWidth, bitmapHeight); Graphics2D graphics2D = this.currentImage.createGraphics(); + // draw page background if (!getSettings().hasTransparentPageBackground()) { graphics2D.setBackground(getSettings().getPageBackgroundColor()); @@ -190,6 +244,7 @@ public abstract class AbstractBitmapDocumentHandler extends AbstractBinaryWritin graphics2D.fillRect(0, 0, bitmapWidth, bitmapHeight); } + //Set rendering hints graphics2D.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); if (getSettings().isAntiAliasingEnabled() @@ -213,6 +268,11 @@ public abstract class AbstractBitmapDocumentHandler extends AbstractBinaryWritin } graphics2D.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); + + //Set up initial coordinate system for the page + if (offset != null) { + graphics2D.translate(offset.getX(), offset.getY()); + } graphics2D.scale(scale / 1000f, scale / 1000f); return new Java2DPainter(graphics2D, getContext(), getFontInfo()); diff --git a/src/java/org/apache/fop/render/bitmap/BitmapRendererConfigurator.java b/src/java/org/apache/fop/render/bitmap/BitmapRendererConfigurator.java index 5237dbe35..1b6c43700 100644 --- a/src/java/org/apache/fop/render/bitmap/BitmapRendererConfigurator.java +++ b/src/java/org/apache/fop/render/bitmap/BitmapRendererConfigurator.java @@ -19,7 +19,6 @@ package org.apache.fop.render.bitmap; -import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.util.List; @@ -80,8 +79,6 @@ public class BitmapRendererConfigurator extends Java2DRendererConfigurator if (background != null) { settings.setPageBackgroundColor( ColorUtil.parseColorString(this.userAgent, background)); - } else { - settings.setPageBackgroundColor(Color.WHITE); } } @@ -106,6 +103,8 @@ public class BitmapRendererConfigurator extends Java2DRendererConfigurator settings.setBufferedImageType(BufferedImage.TYPE_BYTE_GRAY); } else if ("binary".equalsIgnoreCase(color)) { settings.setBufferedImageType(BufferedImage.TYPE_BYTE_BINARY); + } else if ("bi-level".equalsIgnoreCase(color)) { + settings.setBufferedImageType(BufferedImage.TYPE_BYTE_BINARY); } else { throw new FOPException("Invalid value for color-mode: " + color); } diff --git a/status.xml b/status.xml index ab87355c0..3cbf7e4ff 100644 --- a/status.xml +++ b/status.xml @@ -58,6 +58,10 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + Added support for creating thumbnails or preview bitmaps of fixed size for PNG and TIFF + output. + Added support for the #CMYK pseudo-profile supported by some commercial XSL implementations on the rgb-icc() function. -- cgit v1.2.3 From 7cc06986c0f4ed07c17604642248437a4ce0569a Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Fri, 2 Oct 2009 15:31:14 +0000 Subject: Added support for specifying referenced fonts per renderer in addition to the general match list. If any of the two match lists (if specified) match a font, it is not embedded. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@821058 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/trunk/fonts.xml | 7 ++++ .../org/apache/fop/fonts/FontInfoConfigurator.java | 21 ++++++++--- src/java/org/apache/fop/fonts/FontManager.java | 12 +++++- .../apache/fop/fonts/FontManagerConfigurator.java | 19 +++++++--- .../fop/render/afp/AFPRendererConfigurator.java | 43 ++++++++++++++++------ status.xml | 4 ++ 6 files changed, 82 insertions(+), 24 deletions(-) (limited to 'src/documentation/content/xdocs/trunk') diff --git a/src/documentation/content/xdocs/trunk/fonts.xml b/src/documentation/content/xdocs/trunk/fonts.xml index 9fa34552b..df2ed72b8 100644 --- a/src/documentation/content/xdocs/trunk/fonts.xml +++ b/src/documentation/content/xdocs/trunk/fonts.xml @@ -467,6 +467,13 @@ So, in the above snippet "Helvetica" and all variants of the "DejaVu" font family are referenced. If you want to reference all fonts, just specify font-family=".*".

+

+ The referenced-fonts element can be placed either inside the general + fonts element (right under the root) or in the fonts element + under the renderer configuration. In the first case, matches apply to all renderers. + In the second case, matches only apply to the renderer where the element was specified. + Both cases can be used at the same time. +

Various notes related to embedded fonts:

diff --git a/src/java/org/apache/fop/fonts/FontInfoConfigurator.java b/src/java/org/apache/fop/fonts/FontInfoConfigurator.java index 208c32803..e0d52ad43 100644 --- a/src/java/org/apache/fop/fonts/FontInfoConfigurator.java +++ b/src/java/org/apache/fop/fonts/FontInfoConfigurator.java @@ -33,6 +33,7 @@ import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.apache.fop.apps.FOPException; import org.apache.fop.fonts.autodetect.FontFileFinder; import org.apache.fop.fonts.autodetect.FontInfoFinder; @@ -83,7 +84,7 @@ public class FontInfoConfigurator { } FontAdder fontAdder = new FontAdder(fontManager, fontResolver, listener); - + // native o/s search (autodetect) configuration boolean autodetectFonts = (fonts.getChild("auto-detect", false) != null); if (autodetectFonts) { @@ -93,7 +94,7 @@ public class FontInfoConfigurator { // Add configured directories to FontInfo addDirectories(fonts, fontAdder, fontInfoList); - + // Add configured fonts to FontInfo FontCache fontCache = fontManager.getFontCache(); addFonts(fonts, fontCache, fontInfoList); @@ -101,6 +102,14 @@ public class FontInfoConfigurator { // Update referenced fonts (fonts which are not to be embedded) fontManager.updateReferencedFonts(fontInfoList); + // Renderer-specific referenced fonts + Configuration referencedFontsCfg = fonts.getChild("referenced-fonts", false); + if (referencedFontsCfg != null) { + FontTriplet.Matcher matcher = FontManagerConfigurator.createFontsMatcher( + referencedFontsCfg, strict); + fontManager.updateReferencedFonts(fontInfoList, matcher); + } + // Update font cache if it has changed if (fontCache != null && fontCache.hasChanged()) { fontCache.save(); @@ -112,7 +121,7 @@ public class FontInfoConfigurator { } } } - + private void addDirectories(Configuration fontsCfg, FontAdder fontAdder, List/**/ fontInfoList) throws FOPException { // directory (multiple font) configuration @@ -131,7 +140,7 @@ public class FontInfoConfigurator { new FOPException("directory defined without value"), strict); continue; } - + // add fonts found in directory FontFileFinder fontFileFinder = new FontFileFinder(recursive ? -1 : 1); List/**/ fontURLList; @@ -145,7 +154,7 @@ public class FontInfoConfigurator { } /** - * Populates the font info list from the fonts configuration + * Populates the font info list from the fonts configuration * @param fontsCfg a fonts configuration * @param fontCache a font cache * @param fontInfoList a font info list @@ -163,7 +172,7 @@ public class FontInfoConfigurator { } } } - + private static void closeSource(Source src) { if (src instanceof StreamSource) { StreamSource streamSource = (StreamSource)src; diff --git a/src/java/org/apache/fop/fonts/FontManager.java b/src/java/org/apache/fop/fonts/FontManager.java index 41df6bedd..cfce0fd69 100644 --- a/src/java/org/apache/fop/fonts/FontManager.java +++ b/src/java/org/apache/fop/fonts/FontManager.java @@ -190,11 +190,21 @@ public class FontManager { } /** - * Updates the referenced font list + * Updates the referenced font list using the FontManager's referenced fonts matcher + * ({@link #getReferencedFontsMatcher()}). * @param fontInfoList a font info list */ public void updateReferencedFonts(List fontInfoList) { Matcher matcher = getReferencedFontsMatcher(); + updateReferencedFonts(fontInfoList, matcher); + } + + /** + * Updates the referenced font list. + * @param fontInfoList a font info list + * @param matcher the font triplet matcher to use + */ + public void updateReferencedFonts(List fontInfoList, Matcher matcher) { if (matcher == null) { return; //No referenced fonts } diff --git a/src/java/org/apache/fop/fonts/FontManagerConfigurator.java b/src/java/org/apache/fop/fonts/FontManagerConfigurator.java index 43945b8f8..68dd869f5 100644 --- a/src/java/org/apache/fop/fonts/FontManagerConfigurator.java +++ b/src/java/org/apache/fop/fonts/FontManagerConfigurator.java @@ -93,16 +93,25 @@ public class FontManagerConfigurator { // referenced fonts (fonts which are not to be embedded) Configuration referencedFontsCfg = fontsCfg.getChild("referenced-fonts", false); if (referencedFontsCfg != null) { - createReferencedFontsMatcher(referencedFontsCfg, strict, fontManager); + FontTriplet.Matcher matcher = createFontsMatcher( + referencedFontsCfg, strict); + fontManager.setReferencedFontsMatcher(matcher); } } } - private static void createReferencedFontsMatcher(Configuration referencedFontsCfg, - boolean strict, FontManager fontManager) throws FOPException { + /** + * Creates a font triplet matcher from a configuration object. + * @param cfg the configuration object + * @param strict true for strict configuraton error handling + * @return the font matcher + * @throws FOPException if an error occurs while building the matcher + */ + public static FontTriplet.Matcher createFontsMatcher( + Configuration cfg, boolean strict) throws FOPException { List matcherList = new java.util.ArrayList(); - Configuration[] matches = referencedFontsCfg.getChildren("match"); + Configuration[] matches = cfg.getChildren("match"); for (int i = 0; i < matches.length; i++) { try { matcherList.add(new FontFamilyRegExFontTripletMatcher( @@ -115,7 +124,7 @@ public class FontManagerConfigurator { FontTriplet.Matcher orMatcher = new OrFontTripletMatcher( (FontTriplet.Matcher[])matcherList.toArray( new FontTriplet.Matcher[matcherList.size()])); - fontManager.setReferencedFontsMatcher(orMatcher); + return orMatcher; } private static class OrFontTripletMatcher implements FontTriplet.Matcher { diff --git a/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java b/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java index 007dd3861..071357b82 100644 --- a/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java +++ b/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java @@ -43,6 +43,7 @@ import org.apache.fop.apps.FOUserAgent; import org.apache.fop.fonts.FontCollection; import org.apache.fop.fonts.FontInfo; import org.apache.fop.fonts.FontManager; +import org.apache.fop.fonts.FontManagerConfigurator; import org.apache.fop.fonts.FontTriplet; import org.apache.fop.fonts.FontUtil; import org.apache.fop.fonts.Typeface; @@ -71,9 +72,7 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator throws ConfigurationException { FontManager fontManager = this.userAgent.getFactory().getFontManager(); - FontTriplet.Matcher referencedFontsMatcher = fontManager.getReferencedFontsMatcher(); - boolean embeddable = true; Configuration[] triple = fontCfg.getChildren("font-triplet"); List/**/ tripletList = new java.util.ArrayList/**/(); if (triple.length == 0) { @@ -85,9 +84,6 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator FontTriplet triplet = new FontTriplet(triple[j].getAttribute("name"), triple[j].getAttribute("style"), weight); - if (referencedFontsMatcher != null && referencedFontsMatcher.matches(triplet)) { - embeddable = false; - } tripletList.add(triplet); } @@ -142,7 +138,6 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator // Create a new font object RasterFont font = new RasterFont(name); - font.setEmbeddable(embeddable); Configuration[] rasters = afpFontCfg.getChildren("afp-raster-font"); if (rasters.length == 0) { @@ -220,7 +215,6 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator } // Create a new font object OutlineFont font = new OutlineFont(name, characterSet); - font.setEmbeddable(embeddable); return new AFPFontInfo(font, tripletList); } else { log.error("No or incorrect type attribute"); @@ -236,24 +230,49 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator * @throws ConfigurationException if something's wrong with the config data */ private List/**/ buildFontListFromConfiguration(Configuration cfg) - throws ConfigurationException { + throws FOPException, ConfigurationException { + + Configuration fonts = cfg.getChild("fonts"); + FontManager fontManager = this.userAgent.getFactory().getFontManager(); + + // General matcher + FontTriplet.Matcher referencedFontsMatcher = fontManager.getReferencedFontsMatcher(); + // Renderer-specific matcher + FontTriplet.Matcher localMatcher = null; + + // Renderer-specific referenced fonts + Configuration referencedFontsCfg = fonts.getChild("referenced-fonts", false); + if (referencedFontsCfg != null) { + localMatcher = FontManagerConfigurator.createFontsMatcher( + referencedFontsCfg, this.userAgent.getFactory().validateUserConfigStrictly()); + } + List/**/ fontList = new java.util.ArrayList(); - Configuration[] font = cfg.getChild("fonts").getChildren("font"); + Configuration[] font = fonts.getChildren("font"); final String fontPath = null; for (int i = 0; i < font.length; i++) { AFPFontInfo afi = buildFont(font[i], fontPath); if (afi != null) { if (log.isDebugEnabled()) { log.debug("Adding font " + afi.getAFPFont().getFontName()); - List/**/ fontTriplets = afi.getFontTriplets(); - for (int j = 0; j < fontTriplets.size(); ++j) { - FontTriplet triplet = (FontTriplet) fontTriplets.get(j); + } + List/**/ fontTriplets = afi.getFontTriplets(); + for (int j = 0; j < fontTriplets.size(); ++j) { + FontTriplet triplet = (FontTriplet) fontTriplets.get(j); + if (log.isDebugEnabled()) { log.debug(" Font triplet " + triplet.getName() + ", " + triplet.getStyle() + ", " + triplet.getWeight()); } + + if (referencedFontsMatcher.matches(triplet) + || (localMatcher != null && localMatcher.matches(triplet))) { + afi.getAFPFont().setEmbeddable(false); + break; + } } + fontList.add(afi); } } diff --git a/status.xml b/status.xml index 3cbf7e4ff..da9c16522 100644 --- a/status.xml +++ b/status.xml @@ -58,6 +58,10 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + Added support for specifying referenced fonts per renderer in addition to the general + match list. + Added support for creating thumbnails or preview bitmaps of fixed size for PNG and TIFF output. -- cgit v1.2.3 From de3f6e8dd080ab546e4b3b15119509228dc03a2b Mon Sep 17 00:00:00 2001 From: Chris Bowditch Date: Mon, 12 Oct 2009 07:26:03 +0000 Subject: add support for positioning Page Overlay in AFP Renderer/Painter git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@824249 13f79535-47bb-0310-9956-ffa450edef68 --- lib/xmlgraphics-commons-1.4svn.jar | Bin 552758 -> 554968 bytes src/documentation/content/xdocs/trunk/output.xml | 5 +- src/java/org/apache/fop/afp/DataStream.java | 6 +- .../apache/fop/render/afp/AFPDocumentHandler.java | 19 ++-- .../org/apache/fop/render/afp/AFPRenderer.java | 17 ++-- .../render/afp/extensions/AFPElementMapping.java | 2 +- .../fop/render/afp/extensions/AFPPageOverlay.java | 107 +++++++++++++++++++++ .../afp/extensions/AFPPageOverlayElement.java | 97 +++++++++++++++++++ status.xml | 3 + 9 files changed, 239 insertions(+), 17 deletions(-) create mode 100644 src/java/org/apache/fop/render/afp/extensions/AFPPageOverlay.java create mode 100644 src/java/org/apache/fop/render/afp/extensions/AFPPageOverlayElement.java (limited to 'src/documentation/content/xdocs/trunk') diff --git a/lib/xmlgraphics-commons-1.4svn.jar b/lib/xmlgraphics-commons-1.4svn.jar index 7624e0a42..3b0a7230e 100644 Binary files a/lib/xmlgraphics-commons-1.4svn.jar and b/lib/xmlgraphics-commons-1.4svn.jar differ diff --git a/src/documentation/content/xdocs/trunk/output.xml b/src/documentation/content/xdocs/trunk/output.xml index 972fc1f19..0516d05ea 100644 --- a/src/documentation/content/xdocs/trunk/output.xml +++ b/src/documentation/content/xdocs/trunk/output.xml @@ -766,13 +766,14 @@ out = proc.getOutputStream();]]> - + ... ]]>

The mandatory name attribute must refer to an 8 character (space padded) resource name that - must be known in the AFP processing environment.

+ must be known in the AFP processing environment. Optional x and y attributes can be specified + to place the Overlay at an offset from the top left of the page.

Page Segment (IPS) Extension diff --git a/src/java/org/apache/fop/afp/DataStream.java b/src/java/org/apache/fop/afp/DataStream.java index cb68af94e..b8da317ef 100644 --- a/src/java/org/apache/fop/afp/DataStream.java +++ b/src/java/org/apache/fop/afp/DataStream.java @@ -485,9 +485,11 @@ public class DataStream { * * @param name * the name of the static overlay + * @param x x-coordinate + * @param y y-coordinate */ - public void createIncludePageOverlay(String name) { - currentPageObject.createIncludePageOverlay(name, 0, 0, paintingState.getRotation()); + public void createIncludePageOverlay(String name, int x, int y) { + currentPageObject.createIncludePageOverlay(name, x, y, paintingState.getRotation()); currentPageObject.getActiveEnvironmentGroup().createOverlay(name); } diff --git a/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java b/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java index 8ccee5b70..1f7a732d1 100644 --- a/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java +++ b/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java @@ -47,6 +47,7 @@ import org.apache.fop.render.afp.extensions.AFPElementMapping; import org.apache.fop.render.afp.extensions.AFPIncludeFormMap; import org.apache.fop.render.afp.extensions.AFPInvokeMediumMap; import org.apache.fop.render.afp.extensions.AFPPageSetup; +import org.apache.fop.render.afp.extensions.AFPPageOverlay; import org.apache.fop.render.intermediate.AbstractBinaryWritingIFDocumentHandler; import org.apache.fop.render.intermediate.IFDocumentHandler; import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator; @@ -286,12 +287,7 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler "AFP page setup extension encountered outside the page header: " + aps, null); } - 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)) { + if (AFPElementMapping.INCLUDE_PAGE_SEGMENT.equals(element)) { String name = aps.getName(); String source = aps.getValue(); pageSegmentMap.put(source, name); @@ -302,6 +298,17 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler } } } + } else if (extension instanceof AFPPageOverlay) { + AFPPageOverlay ipo = (AFPPageOverlay)extension; + if (this.location != LOC_IN_PAGE_HEADER) { + throw new IFException( + "AFP page overlay extension encountered outside the page header: " + ipo, + null); + } + String overlay = ipo.getName(); + if (overlay != null) { + dataStream.createIncludePageOverlay(overlay, ipo.getX(), ipo.getY()); + } } else if (extension instanceof AFPInvokeMediumMap) { if (this.location != LOC_FOLLOWING_PAGE_SEQUENCE && this.location != LOC_IN_PAGE_HEADER) { diff --git a/src/java/org/apache/fop/render/afp/AFPRenderer.java b/src/java/org/apache/fop/render/afp/AFPRenderer.java index e106ac712..f019c6a47 100644 --- a/src/java/org/apache/fop/render/afp/AFPRenderer.java +++ b/src/java/org/apache/fop/render/afp/AFPRenderer.java @@ -91,6 +91,7 @@ import org.apache.fop.render.afp.extensions.AFPExtensionAttachment; import org.apache.fop.render.afp.extensions.AFPIncludeFormMap; import org.apache.fop.render.afp.extensions.AFPInvokeMediumMap; import org.apache.fop.render.afp.extensions.AFPPageSetup; +import org.apache.fop.render.afp.extensions.AFPPageOverlay; /** * This is an implementation of a FOP Renderer that renders areas to AFP. @@ -758,12 +759,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer implements AFPCust 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 + if (AFPElementMapping.INCLUDE_PAGE_SEGMENT .equals(element)) { String name = aps.getName(); String source = aps.getValue(); @@ -779,6 +775,15 @@ public class AFPRenderer extends AbstractPathOrientedRenderer implements AFPCust dataStream.createNoOperation(content); } } + } else if (attachment instanceof AFPPageOverlay) { + AFPPageOverlay ipo = (AFPPageOverlay) attachment; + String element = ipo.getElementName(); + if (AFPElementMapping.INCLUDE_PAGE_OVERLAY.equals(element)) { + String overlay = ipo.getName(); + if (overlay != null) { + dataStream.createIncludePageOverlay(overlay, ipo.getX(), ipo.getY()); + } + } } } } diff --git a/src/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java b/src/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java index cb5478340..d77e21db2 100755 --- a/src/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java +++ b/src/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java @@ -97,7 +97,7 @@ public class AFPElementMapping extends ElementMapping { static class AFPIncludePageOverlayMaker extends ElementMapping.Maker { public FONode make(FONode parent) { - return new AFPPageSetupElement(parent, INCLUDE_PAGE_OVERLAY); + return new AFPPageOverlayElement(parent, INCLUDE_PAGE_OVERLAY); } } diff --git a/src/java/org/apache/fop/render/afp/extensions/AFPPageOverlay.java b/src/java/org/apache/fop/render/afp/extensions/AFPPageOverlay.java new file mode 100644 index 000000000..68a626aae --- /dev/null +++ b/src/java/org/apache/fop/render/afp/extensions/AFPPageOverlay.java @@ -0,0 +1,107 @@ +/* + * 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: AFPIncludeFormMap.java 798207 2009-07-27 16:33:01Z jeremias $ */ + +package org.apache.fop.render.afp.extensions; + +import java.net.URI; + +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + +import org.apache.fop.fo.extensions.ExtensionAttachment; + +/** + * This extension allows to include an AFP Page Overlay resource. It is implemented as an extension + * attachment ({@link ExtensionAttachment}). + */ +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 + */ + private int x = 0; + + /** + * The y coordinate + */ + private int y = 0; + + /** + * Default constructor. + */ + public AFPPageOverlay() { + super(AFPElementMapping.INCLUDE_PAGE_OVERLAY); + } + + /** + * returns X coordinate + * @return x integer + */ + public int getX() { + return x; + } + + /** + * Sets the X coordinate + * @param x The integer to be set. + */ + public void setX(int x) { + this.x = x; + } + + /** + * returns Y coordinate + * @return y integer + */ + public int getY() { + return y; + } + + /** + * Sets the Y coordinate + * @param y The integer to be set. + */ + public void setY(int y) { + this.y = y; + } + + /** {@inheritDoc} */ + public void toSAX(ContentHandler handler) throws SAXException { + AttributesImpl atts = new AttributesImpl(); + if (name != null && name.length() > 0) { + atts.addAttribute(null, ATT_NAME, ATT_NAME, "CDATA", name); + } + handler.startElement(CATEGORY, elementName, elementName, atts); + handler.endElement(CATEGORY, elementName, elementName); + } + + /** {@inheritDoc} */ + public String toString() { + return getClass().getName() + "(element-name=" + getElementName() + + " name=" + getName() + " x=" + getX() + " y=" + getY() + ")"; + } +} diff --git a/src/java/org/apache/fop/render/afp/extensions/AFPPageOverlayElement.java b/src/java/org/apache/fop/render/afp/extensions/AFPPageOverlayElement.java new file mode 100644 index 000000000..c025f4972 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/extensions/AFPPageOverlayElement.java @@ -0,0 +1,97 @@ +/* + * 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: AFPPageSetupElement.java 798207 2009-07-27 16:33:01Z jeremias $ */ + +package org.apache.fop.render.afp.extensions; + +import org.xml.sax.Attributes; +import org.xml.sax.Locator; + +import org.apache.fop.apps.FOPException; +import org.apache.fop.fo.Constants; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.PropertyList; +import org.apache.fop.fo.extensions.ExtensionAttachment; +import org.apache.fop.afp.AFPPaintingState; +import org.apache.fop.afp.AFPUnitConverter; +import org.apache.xmlgraphics.util.UnitConv; + +/** + * This class extends the org.apache.fop.render.afp.extensions.AbstractAFPExtensionObject class. + * This object will be used to map the page overlay object in AFPElementMapping. + *

+ */ +public class AFPPageOverlayElement extends AbstractAFPExtensionObject { + + private static final String ATT_X = "x"; + private static final String ATT_Y = "y"; + + /** + * Constructs an AFP object (called by Maker). + * + * @param parent the parent formatting object + * @param name the name of the afp element + */ + public AFPPageOverlayElement(FONode parent, String name) { + super(parent, name); + } + + private AFPPageOverlay getPageSetupAttachment() { + return (AFPPageOverlay)getExtensionAttachment(); + } + + /** {@inheritDoc} */ + protected void startOfNode() throws FOPException { + super.startOfNode(); + if (AFPElementMapping.INCLUDE_PAGE_OVERLAY.equals(getLocalName())) { + if (parent.getNameId() != Constants.FO_SIMPLE_PAGE_MASTER + && parent.getNameId() != Constants.FO_PAGE_SEQUENCE) { + invalidChildError(getLocator(), parent.getName(), getNamespaceURI(), getName(), + "rule.childOfPageSequenceOrSPM"); + } + } else { + if (parent.getNameId() != Constants.FO_SIMPLE_PAGE_MASTER) { + invalidChildError(getLocator(), parent.getName(), getNamespaceURI(), getName(), + "rule.childOfSPM"); + } + } + } + + + /** {@inheritDoc} */ + public void processNode(String elementName, Locator locator, + Attributes attlist, PropertyList propertyList) + throws FOPException { + super.processNode(elementName, locator, attlist, propertyList); + AFPPageOverlay pageOverlay = getPageSetupAttachment(); + if (AFPElementMapping.INCLUDE_PAGE_OVERLAY.equals(elementName)) { + // convert user specific units to mpts and set the coordinates for the page overlay + AFPPaintingState paintingState = new AFPPaintingState(); + AFPUnitConverter unitConverter = new AFPUnitConverter(paintingState); + int x = (int)unitConverter.mpt2units(UnitConv.convert(attlist.getValue(ATT_X))); + int y = (int)unitConverter.mpt2units(UnitConv.convert(attlist.getValue(ATT_Y))); + pageOverlay.setX(x); + pageOverlay.setY(y); + } + } + + /** {@inheritDoc} */ + protected ExtensionAttachment instantiateExtensionAttachment() { + return new AFPPageOverlay(); + } +} diff --git a/status.xml b/status.xml index da9c16522..e9256ffe2 100644 --- a/status.xml +++ b/status.xml @@ -58,6 +58,9 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + Added support for positioning Page Overlays in AFP Output + Added support for specifying referenced fonts per renderer in addition to the general match list. -- cgit v1.2.3