diff options
author | Jeremias Maerki <jeremias@apache.org> | 2009-01-16 14:35:12 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2009-01-16 14:35:12 +0000 |
commit | 1cf035b8733c3fa00d3d9a19e40e41fdea5db13d (patch) | |
tree | 20d8d0941707d50168a91e35172125ab431ae1e2 | |
parent | 9750aafda3d39663dff1c917cab624e2157206c2 (diff) | |
download | xmlgraphics-fop-1cf035b8733c3fa00d3d9a19e40e41fdea5db13d.tar.gz xmlgraphics-fop-1cf035b8733c3fa00d3d9a19e40e41fdea5db13d.zip |
Added support for the AFP Extensions.
Added default font setup.
Added a last-resort font selection fallback for cases where an IF file was not created with the right font set.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign@735028 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/java/org/apache/fop/render/afp/AFPDocumentHandler.java | 76 | ||||
-rw-r--r-- | src/java/org/apache/fop/render/afp/AFPPainter.java | 13 |
2 files changed, 78 insertions, 11 deletions
diff --git a/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java b/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java index b99ccf0c8..e9d4615be 100644 --- a/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java +++ b/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java @@ -23,6 +23,7 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.geom.AffineTransform; import java.io.IOException; +import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -31,8 +32,15 @@ import org.apache.fop.afp.AFPPaintingState; import org.apache.fop.afp.AFPResourceManager; import org.apache.fop.afp.AFPUnitConverter; import org.apache.fop.afp.DataStream; +import org.apache.fop.afp.fonts.AFPFontCollection; import org.apache.fop.afp.fonts.AFPPageFonts; import org.apache.fop.apps.MimeConstants; +import org.apache.fop.fonts.FontCollection; +import org.apache.fop.fonts.FontEventAdapter; +import org.apache.fop.fonts.FontInfo; +import org.apache.fop.fonts.FontManager; +import org.apache.fop.render.afp.extensions.AFPElementMapping; +import org.apache.fop.render.afp.extensions.AFPPageSetup; import org.apache.fop.render.intermediate.AbstractBinaryWritingIFDocumentHandler; import org.apache.fop.render.intermediate.IFContext; import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator; @@ -60,6 +68,12 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler /** the AFP datastream */ private DataStream dataStream; + /** the map of page segments */ + private Map/*<String,String>*/pageSegmentMap + = new java.util.HashMap/*<String,String>*/(); + + private boolean inPageHeader; + /** * Default constructor. */ @@ -89,6 +103,19 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler return new AFPRendererConfigurator(getUserAgent()); } + /** {@inheritDoc} */ + public void setDefaultFontInfo(FontInfo fontInfo) { + FontManager fontManager = getUserAgent().getFactory().getFontManager(); + FontCollection[] fontCollections = new FontCollection[] { + new AFPFontCollection(getUserAgent().getEventBroadcaster(), null) + }; + + FontInfo fi = (fontInfo != null ? fontInfo : new FontInfo()); + fi.setEventListener(new FontEventAdapter(getUserAgent().getEventBroadcaster())); + fontManager.setup(fi, fontCollections); + setFontInfo(fi); + } + AFPPaintingState getPaintingState() { return this.paintingState; } @@ -168,6 +195,7 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler public void startPage(int index, String name, String pageMasterName, Dimension size) throws IFException { paintingState.clear(); + pageSegmentMap.clear(); AffineTransform baseTransform = getBaseTransform(); paintingState.concatenate(baseTransform); @@ -183,20 +211,17 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler dataStream.startPage(pageWidth, pageHeight, pageRotation, resolution, resolution); - - //TODO Handle page extensions - //renderPageObjectExtensions(pageViewport); - } /** {@inheritDoc} */ public void startPageHeader() throws IFException { super.startPageHeader(); - + this.inPageHeader = true; } /** {@inheritDoc} */ public void endPageHeader() throws IFException { + this.inPageHeader = false; super.endPageHeader(); } @@ -225,12 +250,33 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler /** {@inheritDoc} */ public void handleExtensionObject(Object extension) throws IFException { - /* - try { - } catch (IOException ioe) { - throw new IFException("I/O error in handleExtensionObject()", ioe); + if (extension instanceof AFPPageSetup) { + AFPPageSetup aps = (AFPPageSetup)extension; + if (!inPageHeader) { + throw new IFException( + "AFP page setup extension encountered outside the page header: " + aps, null); + } + String element = aps.getElementName(); + if (AFPElementMapping.INCLUDE_PAGE_OVERLAY.equals(element)) { + String overlay = aps.getName(); + if (overlay != null) { + dataStream.createIncludePageOverlay(overlay); + } + } else if (AFPElementMapping.INCLUDE_PAGE_SEGMENT.equals(element)) { + String name = aps.getName(); + String source = aps.getValue(); + pageSegmentMap.put(source, name); + } else if (AFPElementMapping.TAG_LOGICAL_ELEMENT.equals(element)) { + String name = aps.getName(); + String value = aps.getValue(); + dataStream.createTagLogicalElement(name, value); + } else if (AFPElementMapping.NO_OPERATION.equals(element)) { + String content = aps.getContent(); + if (content != null) { + dataStream.createNoOperation(content); + } + } } - */ } // ---=== AFPCustomizable ===--- @@ -265,4 +311,14 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler resourceManager.setDefaultResourceGroupFilePath(filePath); } + /** + * Returns the page segment name for a given URI if it actually represents a page segment. + * Otherwise, it just returns null. + * @param uri the URI that identifies the page segment + * @return the page segment name or null if there's no page segment for the given URI + */ + String getPageSegmentNameFor(String uri) { + return (String)pageSegmentMap.get(uri); + } + } diff --git a/src/java/org/apache/fop/render/afp/AFPPainter.java b/src/java/org/apache/fop/render/afp/AFPPainter.java index 45d0ddaad..d22ea8326 100644 --- a/src/java/org/apache/fop/render/afp/AFPPainter.java +++ b/src/java/org/apache/fop/render/afp/AFPPainter.java @@ -186,7 +186,14 @@ public class AFPPainter extends AbstractIFPainter { /** {@inheritDoc} */ public void drawImage(String uri, Rectangle rect) throws IFException { - drawImageUsingURI(uri, rect); + String name = documentHandler.getPageSegmentNameFor(uri); + if (name != null) { + float[] srcPts = {rect.x, rect.y}; + int[] coords = unitConv.mpts2units(srcPts); + getDataStream().createIncludePageSegment(name, coords[X], coords[Y]); + } else { + drawImageUsingURI(uri, rect); + } } /** {@inheritDoc} */ @@ -314,6 +321,10 @@ public class AFPPainter extends AbstractIFPainter { state.getFontFamily(), state.getFontStyle(), state.getFontWeight()); //TODO Ignored: state.getFontVariant() String fontKey = getFontInfo().getInternalFontKey(triplet); + if (fontKey == null) { + fontKey = getFontInfo().getInternalFontKey( + new FontTriplet("any", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL)); + } // register font as necessary Map/*<String,FontMetrics>*/ fontMetricMap = documentHandler.getFontInfo().getFonts(); |