diff options
70 files changed, 2251 insertions, 1767 deletions
diff --git a/conf/fop.xconf b/conf/fop.xconf index c1bdc3ffb..2f638c2b2 100644 --- a/conf/fop.xconf +++ b/conf/fop.xconf @@ -111,7 +111,6 @@ the location of this file. <images mode="b+w" bits-per-pixel="8"/> <renderer-resolution>240</renderer-resolution> <resource-group-file>resources.afp</resource-group-file> - <goca-enabled/> <fonts> <!-- diff --git a/src/java/org/apache/fop/render/AbstractGenericSVGHandler.java b/src/java/org/apache/fop/render/AbstractGenericSVGHandler.java index 26b63079f..a06bd0f97 100644 --- a/src/java/org/apache/fop/render/AbstractGenericSVGHandler.java +++ b/src/java/org/apache/fop/render/AbstractGenericSVGHandler.java @@ -64,6 +64,7 @@ public abstract class AbstractGenericSVGHandler implements XMLHandler, RendererC /** * Render the SVG document. + * * @param context the renderer context * @param doc the SVG document * @throws IOException In case of an I/O error while painting the image @@ -84,12 +85,12 @@ public abstract class AbstractGenericSVGHandler implements XMLHandler, RendererC //Build the GVT tree final GraphicsNode root; - final String uri = getDocumentURI(doc); try { root = builder.build(ctx, doc); } catch (Exception e) { SVGEventProducer eventProducer = SVGEventProducer.Provider.get( context.getUserAgent().getEventBroadcaster()); + final String uri = getDocumentURI(doc); eventProducer.svgNotBuilt(this, e, uri); return; } @@ -123,6 +124,7 @@ public abstract class AbstractGenericSVGHandler implements XMLHandler, RendererC /** * Gets the document URI from a Document instance if possible. + * * @param doc the Document * @return the URI or null */ @@ -138,6 +140,7 @@ public abstract class AbstractGenericSVGHandler implements XMLHandler, RendererC /** * Override this method to update the renderer context if it needs special settings for * certain conditions. + * * @param context the renderer context */ protected void updateRendererContext(RendererContext context) { diff --git a/src/java/org/apache/fop/render/afp/AFPGraphics2D.java b/src/java/org/apache/fop/render/afp/AFPGraphics2D.java index 5b922fd26..517eb8dc1 100644 --- a/src/java/org/apache/fop/render/afp/AFPGraphics2D.java +++ b/src/java/org/apache/fop/render/afp/AFPGraphics2D.java @@ -218,24 +218,24 @@ public class AFPGraphics2D extends AbstractGraphics2D { // coordinates int type = iter.currentSegment(vals); if (type == PathIterator.SEG_MOVETO) { - log.debug("SEG_MOVETO"); +// log.debug("SEG_MOVETO"); openingCoords[0] = currCoords[0] = (int)Math.round(vals[0]); openingCoords[1] = currCoords[1] = (int)Math.round(vals[1]); } else { int numCoords; if (type == PathIterator.SEG_LINETO) { - log.debug("SEG_LINETO"); +// log.debug("SEG_LINETO"); numCoords = 2; } else if (type == PathIterator.SEG_QUADTO) { - log.debug("SEG_QUADTO"); +// log.debug("SEG_QUADTO"); numCoords = 4; } else if (type == PathIterator.SEG_CUBICTO) { - log.debug("SEG_CUBICTO"); +// log.debug("SEG_CUBICTO"); numCoords = 6; } else { // close of the graphics segment if (type == PathIterator.SEG_CLOSE) { - log.debug("SEG_CLOSE"); +// log.debug("SEG_CLOSE"); coords = new int[] { coords[coords.length - 2], coords[coords.length - 1], @@ -317,17 +317,13 @@ public class AFPGraphics2D extends AbstractGraphics2D { } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void draw(Shape shape) { log.debug("draw() shape=" + shape); doDrawing(shape, false); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void fill(Shape shape) { log.debug("fill() shape=" + shape); doDrawing(shape, true); @@ -345,9 +341,7 @@ public class AFPGraphics2D extends AbstractGraphics2D { ioe.printStackTrace(); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void drawString(String s, float x, float y) { try { if (customTextHandler != null && !textAsShapes) { @@ -360,78 +354,86 @@ public class AFPGraphics2D extends AbstractGraphics2D { } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public GraphicsConfiguration getDeviceConfiguration() { return new AFPGraphicsConfiguration(); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void copyArea(int x, int y, int width, int height, int dx, int dy) { log.debug("copyArea() NYI: "); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public Graphics create() { return new AFPGraphics2D(this); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void dispose() { this.graphicsObj = null; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public boolean drawImage(Image img, int x, int y, ImageObserver observer) { return drawImage(img, x, y, img.getWidth(observer), img.getHeight(observer), observer); } - /** - * {@inheritDoc} - */ +// private BufferedImage buildBufferedImage(Dimension size) { +// return new BufferedImage(size.width, size.height, +// BufferedImage.TYPE_INT_ARGB); +// } + + /** {@inheritDoc} */ public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) { - //TODO: this might be achieved by creating a new IOCA image (ImageObject) - // and placing it in an Overlay - but then stacking order would not be preserved. log.debug("drawImage(): NYI img=" + img + ", x=" + x + ", y=" + y + ", width=" + width + ", height=" + height + ", obs=" + observer); return false; +// Dimension size = new Dimension(width, height); +// BufferedImage buf = buildBufferedImage(size); +// +// java.awt.Graphics2D graphics2D = buf.createGraphics(); +// graphics2D.setComposite(AlphaComposite.SrcOver); +// graphics2D.setBackground(new Color(1, 1, 1, 0)); +// graphics2D.setPaint(new Color(1, 1, 1, 0)); +// graphics2D.fillRect(0, 0, width, height); +// graphics2D.clip(new Rectangle(0, 0, buf.getWidth(), buf.getHeight())); +// graphics2D.setComposite(gc.getComposite()); +// +// if (!graphics2D.drawImage(img, 0, 0, buf.getWidth(), buf.getHeight(), observer)) { +// return false; +// } +// +// ImageInfo info = new ImageInfo(null, "image/unknown"); +// +// ImageSize bufsize = new ImageSize(buf.getWidth(), buf.getHeight(), 72); +// info.setSize(bufsize); +// ImageRendered imgRend = new ImageRendered(info, buf, null); +// +// AFPDataStream afpDataStream = afpInfo.getAFPDataStream(); +// ImageObjectInfo imageObjectInfo = new ImageObjectInfo(); +// afpDataStream.createObject(imageObjectInfo); +// return true; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void drawRenderableImage(RenderableImage img, AffineTransform xform) { log.debug("drawRenderableImage() NYI: img=" + img + ", xform=" + xform); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void drawRenderedImage(RenderedImage img, AffineTransform xform) { log.debug("drawRenderedImage() NYI: img=" + img + ", xform=" + xform); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public FontMetrics getFontMetrics(Font f) { log.debug("getFontMetrics() NYI: f=" + f); return null; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void setXORMode(Color col) { log.debug("setXORMode() NYI: col=" + col); } @@ -449,6 +451,8 @@ public class AFPGraphics2D extends AbstractGraphics2D { } /** + * Returns the GOCA graphics object + * * @return the GOCA graphics object */ protected GraphicsObject getGraphicsObject() { @@ -456,18 +460,12 @@ public class AFPGraphics2D extends AbstractGraphics2D { } /** - * Sets the graphics object - * @param obj the graphics object + * Sets the GOCA graphics object + * + * @param obj the GOCA graphics object */ - protected void setGraphicsObject(GraphicsObject obj) { + public void setGraphicsObject(GraphicsObject obj) { this.graphicsObj = obj; } -// /** -// * Sets the SVG document URI -// * @param documentURI the SVG document URI -// */ -// public void setDocumentURI(String documentURI) { -// this.documentURI = documentURI; -// } }
\ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java b/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java index d4c1ff365..c8a20c5fe 100644 --- a/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java +++ b/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java @@ -19,20 +19,19 @@ package org.apache.fop.render.afp; +import java.awt.Dimension; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.io.IOException; -import org.apache.xmlgraphics.image.loader.ImageException; -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.java2d.Graphics2DImagePainter; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.fop.apps.FOUserAgent; import org.apache.fop.render.AbstractGraphics2DAdapter; import org.apache.fop.render.RendererContext; +import org.apache.fop.render.RendererContext.RendererContextWrapper; /** * Graphics2DAdapter implementation for AFP. @@ -52,27 +51,57 @@ public class AFPGraphics2DAdapter extends AbstractGraphics2DAdapter { public void paintImage(Graphics2DImagePainter painter, RendererContext context, int x, int y, int width, int height) throws IOException { - RendererContext.RendererContextWrapper wrappedContext - = new RendererContext.RendererContextWrapper(context); - AFPRenderer afp = (AFPRenderer)context.getRenderer(); - Boolean grayObj = (Boolean)context.getProperty(AFPRendererContextConstants.AFP_GRAYSCALE); - boolean gray = (grayObj != null ? grayObj.booleanValue() : false); - FOUserAgent userAgent = context.getUserAgent(); + AFPInfo afpInfo = AFPSVGHandler.getAFPInfo(context); + + final boolean textAsShapes = false; + AFPGraphics2D graphics = new AFPGraphics2D(textAsShapes); + graphics.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext()); - //Paint to a BufferedImage - int resolution = (int)Math.round(userAgent.getTargetResolution()); - BufferedImage bi - = paintToBufferedImage(painter, wrappedContext, resolution, gray, false); - ImageManager manager = userAgent.getFactory().getImageManager(); - ImageSessionContext sessionContext = userAgent.getImageSessionContext(); - AFPState state = (AFPState)context.getProperty(AFPRendererContextConstants.AFP_STATE); - try { - ImageInfo info = manager.getImageInfo(state.getImageUri(), sessionContext); - java.util.Map foreignAttributes = null; - afp.drawBufferedImage(info, bi, resolution, x, y, width, height, foreignAttributes); - } catch (ImageException e) { - log.error(e); + if (afpInfo.paintAsBitmap) { + //Fallback solution: Paint to a BufferedImage + int resolution = (int)Math.round(context.getUserAgent().getTargetResolution()); + RendererContextWrapper ctx = RendererContext.wrapRendererContext(context); + BufferedImage bi = paintToBufferedImage(painter, ctx, resolution, false, false); + + float scale = AFPRenderer.NORMAL_AFP_RESOLUTION + / context.getUserAgent().getTargetResolution(); + graphics.drawImage(bi, new AffineTransform(scale, 0, 0, scale, 0, 0), null); + } else { + // get the 'width' and 'height' attributes of the SVG document + Dimension dim = painter.getImageSize(); + float imw = (float)dim.getWidth() / 1000f; + float imh = (float)dim.getHeight() / 1000f; + + Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh); + painter.paint(graphics, area); } + +// RendererContext.RendererContextWrapper wrappedContext +// = new RendererContext.RendererContextWrapper(context); +//AFPRenderer renderer = (AFPRenderer)context.getRenderer(); +//Boolean grayObj = (Boolean)context.getProperty(AFPRendererContextConstants.AFP_GRAYSCALE); +//boolean gray = (grayObj != null ? grayObj.booleanValue() : false); +// +//FOUserAgent userAgent = context.getUserAgent(); +// +////Paint to a BufferedImage +//int resolution = (int)Math.round(userAgent.getTargetResolution()); +//BufferedImage bi +// = paintToBufferedImage(painter, wrappedContext, resolution, gray, false); +// +//ImageManager manager = userAgent.getFactory().getImageManager(); +//ImageSessionContext sessionContext = userAgent.getImageSessionContext(); +//AFPState state = (AFPState)context.getProperty(AFPRendererContextConstants.AFP_STATE); +//String uri = state.getImageUri(); +//try { +// ImageInfo info = manager.getImageInfo(uri, sessionContext); +// java.util.Map foreignAttributes = null; +// renderer.drawBufferedImage(info, bi, resolution, x, y, width, height, foreignAttributes); +//} catch (ImageException e) { +// log.error(e); +//} + +// painter.paint(g2d, area) } } diff --git a/src/java/org/apache/fop/render/afp/AFPInfo.java b/src/java/org/apache/fop/render/afp/AFPInfo.java index b12a46cb2..9a84ffa52 100644 --- a/src/java/org/apache/fop/render/afp/AFPInfo.java +++ b/src/java/org/apache/fop/render/afp/AFPInfo.java @@ -51,8 +51,12 @@ public final class AFPInfo { /** See AFP_STATE */ private AFPState afpState; + /** true if SVG should be rendered as a bitmap instead of natively */ + public boolean paintAsBitmap; + /** * Returns the width. + * * @return the width */ public int getWidth() { @@ -61,6 +65,7 @@ public final class AFPInfo { /** * Sets the width. + * * @param width The pageWidth to set */ public void setWidth(int width) { @@ -69,6 +74,7 @@ public final class AFPInfo { /** * Returns the height. + * * @return the height */ public int getHeight() { @@ -77,6 +83,7 @@ public final class AFPInfo { /** * Sets the height. + * * @param height The height to set */ public void setHeight(int height) { @@ -84,7 +91,9 @@ public final class AFPInfo { } /** - * @return Configuration the handler configuration + * Returns the handler configuration + * + * @return the handler configuration */ public Configuration getHandlerConfiguration() { return this.cfg; @@ -92,6 +101,7 @@ public final class AFPInfo { /** * Sets the handler configuration + * * @param cfg the handler configuration */ public void setHandlerConfiguration(Configuration cfg) { @@ -99,27 +109,35 @@ public final class AFPInfo { } /** - * @return FontInfo the font info + * Return the font info + * + * @return the font info */ public FontInfo getFontInfo() { return this.fontInfo; } /** - * @return Map the current page fonts + * Returns the current AFP state + * + * @return the current AFP state */ public AFPState getState() { return this.afpState; } /** - * @return AFPDataStream the afp datastream + * Returns the AFPDataStream the afp datastream + * + * @return the AFPDataStream the afp datastream */ public AFPDataStream getAFPDataStream() { return this.afpDataStream; } /** + * Returns true if supports color + * * @return true if supports color */ public boolean isColorSupported() { @@ -127,6 +145,8 @@ public final class AFPInfo { } /** + * Returns the current x position coordinate + * * @return the current x position coordinate */ protected int getX() { @@ -134,6 +154,8 @@ public final class AFPInfo { } /** + * Returns the current y position coordinate + * * @return the current y position coordinate */ protected int getY() { @@ -141,6 +163,8 @@ public final class AFPInfo { } /** + * Returns the resolution + * * @return the resolution */ protected int getResolution() { @@ -148,6 +172,7 @@ public final class AFPInfo { } /** + * Returns the number of bits per pixel to use * @return the number of bits per pixel to use */ protected int getBitsPerPixel() { @@ -156,6 +181,7 @@ public final class AFPInfo { /** * Sets the current x position coordinate + * * @param x the current x position coordinate */ protected void setX(int x) { @@ -164,6 +190,7 @@ public final class AFPInfo { /** * Sets the current y position coordinate + * * @param y the current y position coordinate */ protected void setY(int y) { @@ -172,6 +199,7 @@ public final class AFPInfo { /** * Sets the current font info + * * @param fontInfo the current font info */ protected void setFontInfo(FontInfo fontInfo) { @@ -180,6 +208,7 @@ public final class AFPInfo { /** * Sets the AFP state + * * @param state the AFP state */ public void setState(AFPState state) { @@ -188,12 +217,14 @@ public final class AFPInfo { /** * Sets the AFP datastream + * * @param dataStream the AFP datastream */ public void setAFPDataStream(AFPDataStream dataStream) { this.afpDataStream = dataStream; } + /** {@inheritDoc} */ public String toString() { return "width=" + width diff --git a/src/java/org/apache/fop/render/afp/AFPRenderer.java b/src/java/org/apache/fop/render/afp/AFPRenderer.java index 98d2440c1..6e5f7bed4 100644 --- a/src/java/org/apache/fop/render/afp/AFPRenderer.java +++ b/src/java/org/apache/fop/render/afp/AFPRenderer.java @@ -136,6 +136,9 @@ import org.apache.fop.render.afp.modca.PageObject; */ public class AFPRenderer extends AbstractPathOrientedRenderer { + /** Normal PDF resolution (72dpi) */ + public static final int NORMAL_AFP_RESOLUTION = 72; + private static final int X = 0; private static final int Y = 1; @@ -166,8 +169,6 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { /** drawing state */ private AFPState currentState = new AFPState(); - private boolean gocaEnabled = false; - /** * Constructor for AFPRenderer. */ @@ -226,7 +227,8 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { renderPageObjectExtensions(page); - getPages().put(page, getAFPDataStream().savePage()); + PageObject currentPage = getAFPDataStream().savePage(); + getPages().put(page, currentPage); } private Map/*<PageViewport, PageObject>*/ getPages() { @@ -987,6 +989,11 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { return MimeConstants.MIME_AFP; } + /** + * Returns the page segments map + * + * @return the page segments map + */ private Map/*<String,String>*/getPageSegments() { if (pageSegmentsMap == null) { pageSegmentsMap = new java.util.HashMap/*<String,String>*/(); @@ -1002,7 +1009,6 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { * the page object */ private void renderPageObjectExtensions(PageViewport pageViewport) { - this.pageSegmentsMap = null; if (pageViewport.getExtensionAttachments() != null && pageViewport.getExtensionAttachments().size() > 0) { @@ -1094,6 +1100,8 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { } /** + * Returns the current AFP state + * * @return the current AFP state */ protected AbstractState getState() { @@ -1103,21 +1111,6 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { return currentState; } - /** - * @param enabled - * true if AFP GOCA is enabled for SVG support - */ - protected void setGOCAEnabled(boolean enabled) { - this.gocaEnabled = enabled; - } - - /** - * @return true of AFP GOCA is enabled for SVG support - */ - protected boolean isGOCAEnabled() { - return this.gocaEnabled; - } - // TODO: remove this and use the superclass implementation /** {@inheritDoc} */ protected void renderReferenceArea(Block block) { diff --git a/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java b/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java index 660ac4332..30d59c4ae 100644 --- a/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java +++ b/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java @@ -37,7 +37,6 @@ import org.apache.fop.render.afp.fonts.FopCharacterSet; import org.apache.fop.render.afp.fonts.OutlineFont; import org.apache.fop.render.afp.fonts.RasterFont; import org.apache.fop.render.afp.modca.AFPDataStream; -import org.apache.fop.render.afp.modca.InterchangeSet; import org.apache.fop.util.LogUtil; /** @@ -47,6 +46,7 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator { /** * Default constructor + * * @param userAgent user agent */ public AFPRendererConfigurator(FOUserAgent userAgent) { @@ -183,6 +183,7 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator { /** * Builds a list of AFPFontInfo objects for use with the setup() method. + * * @param cfg Configuration object * @return List the newly created list of fonts * @throws ConfigurationException if something's wrong with the config data @@ -212,6 +213,7 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator { /** * Configure the AFP renderer. + * * @param renderer AFP renderer * @throws FOPException fop exception * @see org.apache.fop.render.PrintRendererConfigurator#configure(Renderer) @@ -252,12 +254,6 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator { // afpRenderer.getAFPDataStream().setInterchangeSet(interchangeSet); // } - // goca enabled - Configuration gocaSupportCfg = cfg.getChild("goca-enabled", false); - if (gocaSupportCfg != null) { - afpRenderer.setGOCAEnabled(true); - } - // a default external resource group file setting Configuration resourceGroupFileCfg = cfg.getChild("resource-group-file", false); @@ -271,7 +267,8 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator { } File resourceGroupFile = new File(resourceGroupDest); if (resourceGroupFile.canWrite()) { - afpRenderer.getAFPDataStream().setDefaultResourceGroupFile(resourceGroupFile); + AFPDataStream datastream = afpRenderer.getAFPDataStream(); + datastream.setDefaultResourceGroupFilePath(resourceGroupDest); } else { log.warn("Unable to write to default external resource group file '" + resourceGroupDest + "'"); diff --git a/src/java/org/apache/fop/render/afp/AFPSVGHandler.java b/src/java/org/apache/fop/render/afp/AFPSVGHandler.java index 9173a1d23..48307fea4 100644 --- a/src/java/org/apache/fop/render/afp/AFPSVGHandler.java +++ b/src/java/org/apache/fop/render/afp/AFPSVGHandler.java @@ -21,23 +21,27 @@ package org.apache.fop.render.afp; // FOP import java.awt.geom.AffineTransform; +import java.awt.geom.Dimension2D; import java.io.IOException; import java.util.Map; import org.apache.avalon.framework.configuration.Configuration; import org.apache.batik.bridge.BridgeContext; +import org.apache.batik.bridge.BridgeException; import org.apache.batik.bridge.GVTBuilder; import org.apache.batik.dom.AbstractDocument; import org.apache.batik.dom.svg.SVGDOMImplementation; import org.apache.batik.gvt.GraphicsNode; +import org.apache.fop.fo.extensions.ExtensionElementMapping; import org.apache.fop.render.AbstractGenericSVGHandler; import org.apache.fop.render.Renderer; import org.apache.fop.render.RendererContext; import org.apache.fop.render.RendererContextConstants; import org.apache.fop.render.afp.modca.AFPConstants; import org.apache.fop.render.afp.modca.AFPDataStream; -import org.apache.fop.render.afp.modca.GraphicsObject; +import org.apache.fop.svg.SVGEventProducer; import org.apache.fop.svg.SVGUserAgent; +import org.apache.xmlgraphics.util.QName; import org.w3c.dom.Document; /** @@ -50,10 +54,8 @@ public class AFPSVGHandler extends AbstractGenericSVGHandler { /** {@inheritDoc} */ public void handleXML(RendererContext context, Document doc, String ns) throws Exception { - AFPInfo afpi = getAFPInfo(context); - if (SVGDOMImplementation.SVG_NAMESPACE_URI.equals(ns)) { - renderSVGDocument(context, doc, afpi); + renderSVGDocument(context, doc); } } @@ -76,6 +78,13 @@ public class AFPSVGHandler extends AbstractGenericSVGHandler { AFPRendererContextConstants.AFP_STATE)); afpi.setAFPDataStream((AFPDataStream)context.getProperty( AFPRendererContextConstants.AFP_DATASTREAM)); + + Map foreign = (Map)context.getProperty(RendererContextConstants.FOREIGN_ATTRIBUTES); + QName qName = new QName(ExtensionElementMapping.URI, null, "conversion-mode"); + if (foreign != null + && "bitmap".equalsIgnoreCase((String)foreign.get(qName))) { + afpi.paintAsBitmap = true; + } return afpi; } @@ -84,28 +93,74 @@ public class AFPSVGHandler extends AbstractGenericSVGHandler { * * @param context the renderer context * @param doc the SVG document - * @param afpInfo the AFPInfo renderer parameters * @throws IOException In case of an I/O error while painting the image */ protected void renderSVGDocument(final RendererContext context, - final Document doc, AFPInfo afpInfo) throws IOException { - + final Document doc) throws IOException { + + AFPRenderer renderer = (AFPRenderer)context.getRenderer(); + AFPInfo afpInfo = getAFPInfo(context); + if (afpInfo.paintAsBitmap) { + try { + super.renderSVGDocument(context, doc); + } catch (IOException ioe) { + SVGEventProducer eventProducer = SVGEventProducer.Provider.get( + context.getUserAgent().getEventBroadcaster()); + eventProducer.svgRenderingError(this, ioe, getDocumentURI(doc)); + } + return; + } + + String uri = ((AbstractDocument)doc).getDocumentURI(); + AFPState currentState = (AFPState)renderer.getState(); + currentState.setImageUri(uri); + + // set the data object parameters + ObjectAreaInfo objectAreaInfo = new ObjectAreaInfo(); + + int x = (int)Math.round((afpInfo.getX() * 25.4f) / 1000f); + objectAreaInfo.setX(x); + + int y = (int)Math.round((afpInfo.getY() * 25.4f) / 1000f); + objectAreaInfo.setY(y); + + int resolution = afpInfo.getResolution(); + objectAreaInfo.setWidthRes(resolution); + objectAreaInfo.setHeightRes(resolution); + + int width = (int)Math.round((afpInfo.getWidth() * resolution) + / AFPConstants.DPI_72_MPTS); + objectAreaInfo.setWidth(width); + + int height = (int)Math.round((afpInfo.getHeight() * resolution) + / AFPConstants.DPI_72_MPTS); + objectAreaInfo.setHeight(height); + + DataObjectInfo dataObjectInfo = new GraphicsObjectInfo(); + dataObjectInfo.setUri(uri); + + // Configure Graphics2D implementation final boolean textAsShapes = false; AFPGraphics2D graphics = new AFPGraphics2D(textAsShapes); graphics.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext()); graphics.setAFPInfo(afpInfo); - GVTBuilder builder = new GVTBuilder(); + // Configure GraphicsObjectPainter with the Graphics2D implementation + GraphicsObjectPainter painter = new GraphicsObjectPainter(); + painter.setGraphics2D(graphics); + ((GraphicsObjectInfo)dataObjectInfo).setPainter(painter); boolean strokeText = false; Configuration cfg = afpInfo.getHandlerConfiguration(); if (cfg != null) { strokeText = cfg.getChild("stroke-text", true).getValueAsBoolean(strokeText); } - SVGUserAgent svgUserAgent = new SVGUserAgent(context.getUserAgent(), new AffineTransform()); - + SVGUserAgent svgUserAgent + = new SVGUserAgent(context.getUserAgent(), new AffineTransform()); + BridgeContext ctx = new BridgeContext(svgUserAgent); AFPTextHandler afpTextHandler = null; + //Controls whether text painted by Batik is generated using text or path operations if (!strokeText) { afpTextHandler = new AFPTextHandler(graphics); @@ -115,79 +170,52 @@ public class AFPSVGHandler extends AbstractGenericSVGHandler { AFPTextElementBridge tBridge = new AFPTextElementBridge(textPainter); ctx.putBridge(tBridge); } + + Map/*<QName, String>*/ foreignAttributes + = (Map/*<QName, String>*/)context.getProperty( + RendererContextConstants.FOREIGN_ATTRIBUTES); + dataObjectInfo.setResourceInfoFromForeignAttributes(foreignAttributes); + // Build the SVG DOM and provide the painter with it GraphicsNode root; + GVTBuilder builder = new GVTBuilder(); try { root = builder.build(ctx, doc); - } catch (Exception e) { - log.error("SVG graphic could not be built: " - + e.getMessage(), e); + painter.setGraphicsNode(root); + } catch (BridgeException e) { + SVGEventProducer eventProducer = SVGEventProducer.Provider.get( + context.getUserAgent().getEventBroadcaster()); + eventProducer.svgNotBuilt(this, e, uri); return; } - log.debug("Generating SVG at " - + afpInfo.getResolution() + "dpi."); - - int res = afpInfo.getResolution(); - double w = ctx.getDocumentSize().getWidth() * 1000f; - double h = ctx.getDocumentSize().getHeight() * 1000f; + + Dimension2D dim = ctx.getDocumentSize(); + double w = dim.getWidth() * 1000f; + double h = dim.getHeight() * 1000f; // convert to afp inches - double scaleX = ((afpInfo.getWidth() / w) * res) / AFPConstants.DPI_72; - double scaleY = ((afpInfo.getHeight() / h) * res) / AFPConstants.DPI_72; - double xOffset = (afpInfo.getX() * res) / AFPConstants.DPI_72_MPTS; - double yOffset = ((afpInfo.getHeight() - afpInfo.getY()) * res) / AFPConstants.DPI_72_MPTS; - - // Transformation matrix that establishes the local coordinate system for the SVG graphic - // in relation to the current coordinate system (note: y axis is inverted) + double scaleX = ((afpInfo.getWidth() / w) * resolution) / AFPConstants.DPI_72; + double scaleY = ((afpInfo.getHeight() / h) * resolution) / AFPConstants.DPI_72; + double xOffset = (afpInfo.getX() * resolution) / AFPConstants.DPI_72_MPTS; + double yOffset + = ((afpInfo.getHeight() - afpInfo.getY()) * resolution) / AFPConstants.DPI_72_MPTS; + + // Transformation matrix that establishes the local coordinate system + // for the SVG graphic in relation to the current coordinate system + // (note: y axis is inverted) AffineTransform trans = new AffineTransform(scaleX, 0, 0, -scaleY, xOffset, yOffset); graphics.setTransform(trans); - - int x = (int)Math.round((afpInfo.getX() * 25.4f) / 1000f); - int y = (int)Math.round((afpInfo.getY() * 25.4f) / 1000f); - int width = (int)Math.round((afpInfo.getWidth() * res) / AFPConstants.DPI_72_MPTS); - int height = (int)Math.round((afpInfo.getHeight() * res) / AFPConstants.DPI_72_MPTS); - - // set the data object parameters - DataObjectInfo dataObjectInfo = new DataObjectInfo(); - - String docUri = ((AbstractDocument)doc).getDocumentURI(); - dataObjectInfo.setUri(docUri); - ObjectAreaInfo objectAreaInfo = new ObjectAreaInfo(); - objectAreaInfo.setX(x); - objectAreaInfo.setY(y); - objectAreaInfo.setWidth(width); - objectAreaInfo.setHeight(height); - objectAreaInfo.setWidthRes(res); - objectAreaInfo.setHeightRes(res); - + // Set the object area info dataObjectInfo.setObjectAreaInfo(objectAreaInfo); - - Map/*<QName, String>*/ foreignAttributes - = (Map/*<QName, String>*/)context.getProperty( - RendererContextConstants.FOREIGN_ATTRIBUTES); - dataObjectInfo.setResourceInfoFromForeignAttributes(foreignAttributes); - AFPDataStream afpDataStream = afpInfo.getAFPDataStream(); - GraphicsObject graphicsObj = (GraphicsObject)afpDataStream.createObject(dataObjectInfo); - graphics.setGraphicsObject(graphicsObj); - - try { - root.paint(graphics); - } catch (Exception e) { - log.error("SVG graphic could not be rendered: " + e.getMessage(), e); - } - - graphics.dispose(); + // Create the object + afpInfo.getAFPDataStream().createObject(dataObjectInfo); } /** {@inheritDoc} */ public boolean supportsRenderer(Renderer renderer) { - if (renderer instanceof AFPRenderer) { - AFPRenderer afpRenderer = (AFPRenderer)renderer; - return afpRenderer.isGOCAEnabled(); - } - return false; + return (renderer instanceof AFPRenderer); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/afp/AFPState.java b/src/java/org/apache/fop/render/afp/AFPState.java index 404fa14da..ddcccdf00 100644 --- a/src/java/org/apache/fop/render/afp/AFPState.java +++ b/src/java/org/apache/fop/render/afp/AFPState.java @@ -29,36 +29,27 @@ public class AFPState extends org.apache.fop.render.AbstractState { private static Log log = LogFactory.getLog("org.apache.fop.render.afp.AFPState"); - /** - * The portrait rotation - */ + /** The portrait rotation */ private int portraitRotation = 0; - /** - * The landscape rotation - */ + /** The landscape rotation */ private int landscapeRotation = 270; - /** - * Flag to the set the output object type for images - */ + /** Flag to the set the output object type for images */ private boolean colorImages = false; - /** - * Default value for image depth - */ + /** Default value for image depth */ private int bitsPerPixel = 8; - /** - * The output resolution - */ + /** The output resolution */ private int resolution = 240; // 240 dpi - /** - * The current page - */ + /** The current page */ private AFPPageState pageState = new AFPPageState(); + /** Whether or not GOCA is used for handling SVG */ + private boolean goca = false; // false by default + /** * Sets the rotation to be used for portrait pages, valid values are 0 * (default), 90, 180, 270. @@ -79,6 +70,8 @@ public class AFPState extends org.apache.fop.render.AbstractState { } /** + * Returns the rotation to be used for portrait pages + * * @return the rotation to be used for portrait pages */ protected int getPortraitRotation() { @@ -104,6 +97,8 @@ public class AFPState extends org.apache.fop.render.AbstractState { } /** + * Returns the landscape rotation + * * @return the landscape rotation */ protected int getLandscapeRotation() { @@ -131,6 +126,8 @@ public class AFPState extends org.apache.fop.render.AbstractState { } /** + * Returns the number of bits per pixel + * * @return the number of bits per pixel */ public int getBitsPerPixel() { @@ -148,6 +145,8 @@ public class AFPState extends org.apache.fop.render.AbstractState { } /** + * Returns true if color images are to be used + * * @return true if color images are to be used */ protected boolean isColorImages() { @@ -182,6 +181,8 @@ public class AFPState extends org.apache.fop.render.AbstractState { } /** + * Returns the state of the current page + * * @return the state of the current page */ protected AFPPageState getPageState() { @@ -189,7 +190,26 @@ public class AFPState extends org.apache.fop.render.AbstractState { } /** + * Sets if GOCA is to be used for SVG handling + * + * @param value is true if GOCA is used for SVG handling + */ + public void setUseGOCA(boolean value) { + this.goca = value; + } + + /** + * Returns true if GOCA is enabled for SVG handling + * + * @return true if GOCA is enabled for SVG handling + */ + public boolean useGOCA() { + return this.goca; + } + + /** * Sets if the current painted shape is to be filled + * * @param fill true if the current painted shape is to be filled * @return true if the fill value has changed */ @@ -203,6 +223,7 @@ public class AFPState extends org.apache.fop.render.AbstractState { /** * Gets the current page fonts + * * @return the current page fonts */ protected AFPPageFonts getPageFonts() { @@ -211,6 +232,7 @@ public class AFPState extends org.apache.fop.render.AbstractState { /** * Increments and returns the page font count + * * @return the page font count */ public int incrementPageFontCount() { @@ -219,6 +241,7 @@ public class AFPState extends org.apache.fop.render.AbstractState { /** * Sets the page width + * * @param pageWidth the page width */ public void setPageWidth(int pageWidth) { @@ -226,6 +249,8 @@ public class AFPState extends org.apache.fop.render.AbstractState { } /** + * Returns the page width + * * @return the page width */ public int getPageWidth() { @@ -234,6 +259,7 @@ public class AFPState extends org.apache.fop.render.AbstractState { /** * Sets the page height + * * @param pageHeight the page height */ public void setPageHeight(int pageHeight) { @@ -241,6 +267,8 @@ public class AFPState extends org.apache.fop.render.AbstractState { } /** + * Returns the page height + * * @return the page height */ public int getPageHeight() { @@ -249,6 +277,7 @@ public class AFPState extends org.apache.fop.render.AbstractState { /** * Sets the uri of the current image + * * @param uri the uri of the current image */ protected void setImageUri(String uri) { @@ -257,6 +286,7 @@ public class AFPState extends org.apache.fop.render.AbstractState { /** * Gets the uri of the current image + * * @return the uri of the current image */ public String getImageUri() { @@ -291,6 +321,8 @@ public class AFPState extends org.apache.fop.render.AbstractState { private int fontCount = 0; /** + * Returns the page width + * * @return the page width */ protected int getWidth() { @@ -299,6 +331,7 @@ public class AFPState extends org.apache.fop.render.AbstractState { /** * Sets the page width + * * @param width the page width */ protected void setWidth(int width) { @@ -306,6 +339,8 @@ public class AFPState extends org.apache.fop.render.AbstractState { } /** + * Returns the page height + * * @return the page height */ protected int getHeight() { @@ -314,6 +349,7 @@ public class AFPState extends org.apache.fop.render.AbstractState { /** * Sets the page height + * * @param height the page height */ protected void setHeight(int height) { @@ -321,6 +357,8 @@ public class AFPState extends org.apache.fop.render.AbstractState { } /** + * Returns the page fonts + * * @return the page fonts */ protected AFPPageFonts getFonts() { @@ -329,6 +367,7 @@ public class AFPState extends org.apache.fop.render.AbstractState { /** * Sets the current page fonts + * * @param fonts the current page fonts */ protected void setFonts(AFPPageFonts fonts) { @@ -336,6 +375,8 @@ public class AFPState extends org.apache.fop.render.AbstractState { } /** + * Increments and returns the current page font count + * * @return increment and return the current page font count */ protected int incrementFontCount() { diff --git a/src/java/org/apache/fop/render/afp/DataObjectCache.java b/src/java/org/apache/fop/render/afp/DataObjectCache.java new file mode 100644 index 000000000..bd87cbb09 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/DataObjectCache.java @@ -0,0 +1,196 @@ +/* + * 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.render.afp; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.nio.MappedByteBuffer; +import java.nio.channels.FileChannel; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.fop.render.afp.modca.AbstractNamedAFPObject; +import org.apache.fop.render.afp.modca.DataObjectFactory; + +/** + * Caches and creates (as necessary using an instance of DataObjectFactory) + * descendants of AbstractDataObject + */ +public final class DataObjectCache { + + /** Static logging instance */ + private static final Log log = LogFactory.getLog(DataObjectCache.class); + + private static final String CACHE_FILENAME_PREFIX = "AFP_"; + + /** Static mapping of data object caches id --> cache */ + private static Map/*<Integer,DataObjectCache>*/ cacheMap + = new java.util.HashMap/*<Integer,DataObjectCache>*/(); + + + /** Mapping of data object uri --> cache entry */ + private Map/*<String,DataObjectCache.Entry>*/ cacheRecordMap + = new java.util.HashMap/*<String,DataObjectCache.Entry>*/(); + + /** Used for create data objects */ + private DataObjectFactory factory = new DataObjectFactory(); + + /** Used for storage of data objects */ + private RandomAccessFile raFile; + + /** File channel used for manipulating the temporary file */ + private FileChannel channel; + + /** The temporary cache file */ + private File tempFile; + + /** The cache id */ + private int id; + + /** The next file pointer position in the cache file */ + private long nextPos; + + /** + * Returns an instance of the cache + * + * @return an instance of the cache or null if failed + */ + public static DataObjectCache getInstance() { + synchronized (cacheMap) { + int id = System.identityHashCode(Thread.currentThread()); + Integer cacheKey = new Integer(id); + DataObjectCache cache = (DataObjectCache)cacheMap.get(cacheKey); + if (cache == null) { + try { + cache = new DataObjectCache(); + cacheMap.put(cacheKey, cache); + } catch (IOException e) { + log.error("Failed to create cache"); + } + } + return cache; + } + } + + /** + * Default constructor + */ + private DataObjectCache() throws IOException { + this.id = System.identityHashCode(Thread.currentThread()); + this.tempFile = File.createTempFile(CACHE_FILENAME_PREFIX + id, null); + this.raFile = new RandomAccessFile(tempFile, "rw"); + this.channel = raFile.getChannel(); + } + + /** + * Clears the data object cache + */ + public void clear() { + try { + raFile.close(); + tempFile.delete(); + } catch (IOException e) { + log.error("Failed to close temporary file"); + } + } + + /** + * Creates and adds a new data object and record to the cache as necessary. + * + * @param dataObjectInfo a data object info + * + * @return the name of the related data object + */ + public String put(DataObjectInfo dataObjectInfo) { + ResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); + Record record = (Record)cacheRecordMap.get(resourceInfo); + if (record == null) { + record = new Record(); + AbstractNamedAFPObject dataObj = factory.createObject(dataObjectInfo); + record.objectName = dataObj.getName(); + + ByteArrayOutputStream os = new ByteArrayOutputStream(); + try { + channel.position(nextPos); + record.position = channel.position(); + dataObj.write(os); + record.size = os.size(); + MappedByteBuffer byteBuffer + = channel.map(FileChannel.MapMode.READ_WRITE, record.position, record.size); + byteBuffer.put(os.toByteArray()); + channel.write(byteBuffer); + nextPos += record.size + 1; + } catch (IOException e) { + log.error("Failed to write cache record for '" + + resourceInfo + "', " + e.getMessage()); + } + cacheRecordMap.put(resourceInfo, record); + } + return record.objectName; + } + + /** + * Returns the written binary data of the AbstractDataObject from the cache file + * + * @param resourceInfo the data resource info + * @return the binary data of the AbstractDataObject or null if failed. + */ + public byte[] get(ResourceInfo resourceInfo) { + Record record = (Record)cacheRecordMap.get(resourceInfo); + if (record == null) { + throw new IllegalArgumentException("Unknown data object " + resourceInfo); + } + MappedByteBuffer byteBuffer = null; + try { + byteBuffer = channel.map(FileChannel.MapMode.READ_ONLY, record.position, record.size); + } catch (IOException e) { + log.error("Failed to read cache record for '" + resourceInfo + "', " + e.getMessage()); + return null; + } + if (byteBuffer.hasArray()) { + return byteBuffer.array(); + } else { + byte[] data = new byte[record.size]; + byteBuffer.get(data); + return data; + } + } + + /** + * Returns the data object factory + * + * @return the data object factory + */ + public DataObjectFactory getFactory() { + return this.factory; + } + + /** + * A cache record + */ + private class Record { + protected long position; + protected int size; + protected String objectName; + } +} diff --git a/src/java/org/apache/fop/render/afp/DataObjectInfo.java b/src/java/org/apache/fop/render/afp/DataObjectInfo.java index b25470551..021e5fef6 100644 --- a/src/java/org/apache/fop/render/afp/DataObjectInfo.java +++ b/src/java/org/apache/fop/render/afp/DataObjectInfo.java @@ -39,18 +39,14 @@ public class DataObjectInfo { private static final String RESOURCE_LEVEL = "afp:resource-level"; private static final String RESOURCE_GROUP_FILE = "afp:resource-group-file"; - private static final ResourceInfo DEFAULT_RESOURCE_INFO = new ResourceInfo(); - - private String uri; - /** the object area info */ private ObjectAreaInfo objectAreaInfo; /** object type entry */ - private ObjectType objectType; + private Registry.ObjectType objectType; /** resource info */ - private ResourceInfo resourceInfo = DEFAULT_RESOURCE_INFO; + private ResourceInfo resourceInfo; /** * Default constructor @@ -59,23 +55,8 @@ public class DataObjectInfo { } /** - * Sets the data object uri - * @param uri the data object uri - */ - public void setUri(String uri) { - this.uri = uri; - } - - - /** - * @return the uri of this data object - */ - public String getUri() { - return uri; - } - - /** * Sets the object type + * * @param objectType the object type */ public void setObjectType(Registry.ObjectType objectType) { @@ -83,6 +64,8 @@ public class DataObjectInfo { } /** + * Returns the object type MOD:CA Registry entry + * * @return the object type MOD:CA Registry entry */ public ObjectType getObjectType() { @@ -90,14 +73,20 @@ public class DataObjectInfo { } /** + * Returns the resource level at which this data object should reside + * * @return the resource level at which this data object should reside */ public ResourceInfo getResourceInfo() { + if (resourceInfo == null) { + this.resourceInfo = new ResourceInfo(); + } return resourceInfo; } /** * Sets the resource level at which this object should reside + * * @param resourceInfo the resource level at which this data object should reside */ public void setResourceInfo(ResourceInfo resourceInfo) { @@ -106,6 +95,7 @@ public class DataObjectInfo { /** * Sets the object area info + * * @param objectAreaInfo the object area info */ public void setObjectAreaInfo(ObjectAreaInfo objectAreaInfo) { @@ -113,6 +103,8 @@ public class DataObjectInfo { } /** + * Returns the object area info + * * @return the object area info */ public ObjectAreaInfo getObjectAreaInfo() { @@ -121,6 +113,7 @@ public class DataObjectInfo { /** * Sets the resource group settings using the given foreign attributes + * * @param foreignAttributes a mapping of element attributes names to values */ public void setResourceInfoFromForeignAttributes(Map/*<QName, String>*/ foreignAttributes) { @@ -165,7 +158,7 @@ public class DataObjectInfo { log.warn("overwritting external resource file: " + resourceExternalDest); } - resourceLevel.setExternalResourceGroupFile(resourceExternalGroupFile); + resourceLevel.setExternalFilePath(resourceExternalDest); } catch (SecurityException ex) { log.error("unable to gain read access to external resource file: " + resourceExternalDest); @@ -180,13 +173,28 @@ public class DataObjectInfo { } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public String toString() { - return "uri=" + uri - + (objectAreaInfo != null ? "objectAreaInfo=" + objectAreaInfo : "") + return (objectAreaInfo != null ? ", objectAreaInfo=" + objectAreaInfo : "") + (objectType != null ? ", objectType=" + objectType : "") + (resourceInfo != null ? ", resourceInfo=" + resourceInfo : ""); } + + /** + * Returns the uri of this data object + * + * @return the uri of this data object + */ + public String getUri() { + return getResourceInfo().getUri(); + } + + /** + * Sets the data object uri + * + * @param uri the data object uri + */ + public void setUri(String uri) { + getResourceInfo().setUri(uri); + } } diff --git a/src/java/org/apache/fop/render/afp/ExternalResourceGroupManager.java b/src/java/org/apache/fop/render/afp/ExternalResourceGroupManager.java new file mode 100644 index 000000000..205eb62fa --- /dev/null +++ b/src/java/org/apache/fop/render/afp/ExternalResourceGroupManager.java @@ -0,0 +1,100 @@ +package org.apache.fop.render.afp; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.Iterator; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.fop.render.afp.modca.ResourceGroup; + +/** + * Manages the use of resource groups (external and internal) + */ +public class ExternalResourceGroupManager { + + /** Static logging instance */ + protected static Log log = LogFactory.getLog(ExternalResourceGroupManager.class); + + /** A mapping of external resource destinations to resource groups */ + private Map/*<String,ResourceGroup>*/externalResourceGroups + = new java.util.HashMap/*<String,ResourceGroup>*/(); + + /** Sets the default resource group file */ + private String defaultResourceGroupFilePath; + + /** + * Default constructor + */ + public ExternalResourceGroupManager() { + } + + /** + * Sets the default resource group file + * + * @param resourceGroupFilePath the default resource group file path + */ + public void setDefaultResourceGroupFilePath(String resourceGroupFilePath) { + this.defaultResourceGroupFilePath = resourceGroupFilePath; + } + + /** + * Returns the corresponding resource group for the given resource level + * + * @param level the resource level + * @return the corresponding resource group for the given resource level + * or null if not found. + */ + public ResourceGroup getResourceGroup(ResourceLevel level) { + ResourceGroup resourceGroup = null; + // this resource info does not have an external resource group + // file definition + String filePath = level.getExternalFilePath(); + if (filePath != null) { + filePath = level.getExternalFilePath(); + resourceGroup = (ResourceGroup)externalResourceGroups.get(filePath); + if (resourceGroup == null) { + resourceGroup = new ResourceGroup(); + externalResourceGroups.put(filePath, resourceGroup); + } + } else if (defaultResourceGroupFilePath != null) { + // fallback to default resource group file + level.setExternalFilePath(defaultResourceGroupFilePath); + resourceGroup = getResourceGroup(level); + } + return resourceGroup; + } + + /** + * Writes out all external resource groups + */ + public void write() { + // write any external resources + Iterator it = externalResourceGroups.keySet().iterator(); + while (it.hasNext()) { + String filePath = (String)it.next(); + ResourceGroup resourceGroup + = (ResourceGroup)externalResourceGroups.get(filePath); + OutputStream os = null; + try { + log.debug("Writing external AFP resource file " + filePath); + os = new java.io.FileOutputStream(filePath); + resourceGroup.write(os); + } catch (IOException e) { + log.error( + "An error occurred when attempting to write external AFP resource file " + + filePath); + } finally { + if (os != null) { + try { + os.close(); + } catch (IOException e) { + log.error("Failed to close outputstream for external AFP resource file " + + filePath); + } + } + } + } + } +}
\ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/GraphicsObjectInfo.java b/src/java/org/apache/fop/render/afp/GraphicsObjectInfo.java new file mode 100644 index 000000000..108d7bfb6 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/GraphicsObjectInfo.java @@ -0,0 +1,46 @@ +/* + * 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.render.afp; + +/** + * A graphics object info which contains necessary painting objects + */ +public class GraphicsObjectInfo extends DataObjectInfo { + + private GraphicsObjectPainter painter; + + /** + * Returns the graphics painter + * + * @return the graphics painter + */ + public GraphicsObjectPainter getPainter() { + return painter; + } + + /** + * Sets the graphics painter + * + * @param graphicsPainter the graphics painter + */ + public void setPainter(GraphicsObjectPainter graphicsPainter) { + this.painter = graphicsPainter; + } +} diff --git a/src/java/org/apache/fop/render/afp/GraphicsObjectPainter.java b/src/java/org/apache/fop/render/afp/GraphicsObjectPainter.java new file mode 100644 index 000000000..c9c9f516a --- /dev/null +++ b/src/java/org/apache/fop/render/afp/GraphicsObjectPainter.java @@ -0,0 +1,100 @@ +/* + * 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$ */ + +/* + * 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.render.afp; + +import org.apache.batik.gvt.GraphicsNode; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.fop.render.afp.modca.GraphicsObject; + +/** + * A simple AFP Graphics 2D painter + */ +public class GraphicsObjectPainter { + /** Static logging instance */ + protected static Log log = LogFactory.getLog(GraphicsObjectPainter.class); + + private AFPGraphics2D graphics2D; + + private GraphicsNode root; + + /** + * Default constructor + */ + public GraphicsObjectPainter() { + } + + /** + * Returns the graphics 2D + * + * @return the graphics 2D + */ + public AFPGraphics2D getGraphics2D() { + return graphics2D; + } + + /** + * Sets the graphics 2D + * + * @param graphics the AFP graphics 2D + */ + public void setGraphics2D(AFPGraphics2D graphics) { + this.graphics2D = graphics; + } + + /** + * Sets the graphics node + * + * @param rootNode the graphics root node + */ + public void setGraphicsNode(GraphicsNode rootNode) { + this.root = rootNode; + } + + /** + * Paints the graphics object + * + * @param graphicsObj the graphics object + */ + public void paint(GraphicsObject graphicsObj) { + log.debug("Generating SVG"); + graphics2D.setGraphicsObject(graphicsObj); + root.paint(graphics2D); + graphics2D.dispose(); + } +}
\ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/ImageObjectInfo.java b/src/java/org/apache/fop/render/afp/ImageObjectInfo.java index f9bbc82cf..8a3d55150 100644 --- a/src/java/org/apache/fop/render/afp/ImageObjectInfo.java +++ b/src/java/org/apache/fop/render/afp/ImageObjectInfo.java @@ -41,6 +41,7 @@ public class ImageObjectInfo extends DataObjectInfo { /** * Sets the number of bits per pixel + * * @param bitsPerPixel the number of bits per pixel */ public void setBitsPerPixel(int bitsPerPixel) { @@ -49,6 +50,7 @@ public class ImageObjectInfo extends DataObjectInfo { /** * Sets if this image is color + * * @param color true if this is a color image */ public void setColor(boolean color) { @@ -57,6 +59,7 @@ public class ImageObjectInfo extends DataObjectInfo { /** * Sets the image data + * * @param data the image data */ public void setData(byte[] data) { @@ -65,6 +68,7 @@ public class ImageObjectInfo extends DataObjectInfo { /** * Sets the image mime type + * * @param mimeType the image mime type */ public void setMimeType(String mimeType) { @@ -72,6 +76,8 @@ public class ImageObjectInfo extends DataObjectInfo { } /** + * Returns the number of bits used per pixel + * * @return the number of bits used per pixel */ public int getBitsPerPixel() { @@ -79,6 +85,8 @@ public class ImageObjectInfo extends DataObjectInfo { } /** + * Returns true if this is a color image + * * @return true if this is a color image */ public boolean isColor() { @@ -86,6 +94,8 @@ public class ImageObjectInfo extends DataObjectInfo { } /** + * Returns the image data + * * @return the image data */ public byte[] getData() { @@ -93,13 +103,17 @@ public class ImageObjectInfo extends DataObjectInfo { } /** - * @return true of this image uses compression + * Returns true if this image uses compression + * + * @return true if this image uses compression */ public boolean hasCompression() { return compression > -1; } /** + * Returns the compression type + * * @return the compression type */ public int getCompression() { @@ -107,7 +121,8 @@ public class ImageObjectInfo extends DataObjectInfo { } /** - * Sets the compression used with this image + * Sets the compression used with this image + * * @param compression the type of compression used with this image */ public void setCompression(int compression) { @@ -115,6 +130,8 @@ public class ImageObjectInfo extends DataObjectInfo { } /** + * Returns the image data width + * * @return the image data width */ public int getDataWidth() { @@ -123,6 +140,7 @@ public class ImageObjectInfo extends DataObjectInfo { /** * Sets the image data width + * * @param imageDataWidth the image data width */ public void setDataWidth(int imageDataWidth) { @@ -130,6 +148,8 @@ public class ImageObjectInfo extends DataObjectInfo { } /** + * Returns the image data height + * * @return the image data height */ public int getDataHeight() { @@ -138,6 +158,7 @@ public class ImageObjectInfo extends DataObjectInfo { /** * Sets the image data height + * * @param imageDataHeight the image data height */ public void setDataHeight(int imageDataHeight) { @@ -145,6 +166,8 @@ public class ImageObjectInfo extends DataObjectInfo { } /** + * Returns the mime type of this image + * * @return the mime type of this image */ public String getMimeType() { @@ -153,6 +176,7 @@ public class ImageObjectInfo extends DataObjectInfo { /** * Sets whether or not this is info about a buffered image + * * @param buffered true if this is info about a buffered image */ public void setBuffered(boolean buffered) { @@ -160,15 +184,15 @@ public class ImageObjectInfo extends DataObjectInfo { } /** + * Returns true if this image info is about a buffered image + * * @return true if this image info is about a buffered image */ public boolean isBuffered() { return this.buffered; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public String toString() { return super.toString() + ", mimeType=" + mimeType diff --git a/src/java/org/apache/fop/render/afp/ObjectAreaInfo.java b/src/java/org/apache/fop/render/afp/ObjectAreaInfo.java index b6538b327..7c654519b 100644 --- a/src/java/org/apache/fop/render/afp/ObjectAreaInfo.java +++ b/src/java/org/apache/fop/render/afp/ObjectAreaInfo.java @@ -19,6 +19,10 @@ package org.apache.fop.render.afp; +/** + * A common class used to convey locations, + * dimensions and resolutions of data objects. + */ public class ObjectAreaInfo { private int x; private int y; @@ -30,6 +34,7 @@ public class ObjectAreaInfo { /** * Sets the x position of the data object + * * @param x the x position of the data object */ public void setX(int x) { @@ -38,6 +43,7 @@ public class ObjectAreaInfo { /** * Sets the y position of the data object + * * @param y the y position of the data object */ public void setY(int y) { @@ -46,6 +52,7 @@ public class ObjectAreaInfo { /** * Sets the data object width + * * @param width the width of the data object */ public void setWidth(int width) { @@ -54,6 +61,7 @@ public class ObjectAreaInfo { /** * Sets the data object height + * * @param height the height of the data object */ public void setHeight(int height) { @@ -62,6 +70,7 @@ public class ObjectAreaInfo { /** * Sets the width resolution + * * @param widthRes the width resolution */ public void setWidthRes(int widthRes) { @@ -70,6 +79,7 @@ public class ObjectAreaInfo { /** * Sets the height resolution + * * @param heightRes the height resolution */ public void setHeightRes(int heightRes) { @@ -77,6 +87,8 @@ public class ObjectAreaInfo { } /** + * Returns the x coordinate of this data object + * * @return the x coordinate of this data object */ public int getX() { @@ -84,6 +96,8 @@ public class ObjectAreaInfo { } /** + * Returns the y coordinate of this data object + * * @return the y coordinate of this data object */ public int getY() { @@ -91,6 +105,8 @@ public class ObjectAreaInfo { } /** + * Returns the width of this data object + * * @return the width of this data object */ public int getWidth() { @@ -98,6 +114,8 @@ public class ObjectAreaInfo { } /** + * Returns the height of this data object + * * @return the height of this data object */ public int getHeight() { @@ -105,6 +123,8 @@ public class ObjectAreaInfo { } /** + * Returns the width resolution of this data object + * * @return the width resolution of this data object */ public int getWidthRes() { @@ -112,6 +132,8 @@ public class ObjectAreaInfo { } /** + * Returns the height resolution of this data object + * * @return the height resolution of this data object */ public int getHeightRes() { @@ -119,6 +141,8 @@ public class ObjectAreaInfo { } /** + * Returns the rotation of this data object + * * @return the rotation of this data object */ public int getRotation() { @@ -127,15 +151,14 @@ public class ObjectAreaInfo { /** * Sets the data object rotation + * * @param rotation the data object rotation */ public void setRotation(int rotation) { this.rotation = rotation; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public String toString() { return "x=" + x + ", y=" + y diff --git a/src/java/org/apache/fop/render/afp/ResourceInfo.java b/src/java/org/apache/fop/render/afp/ResourceInfo.java index 5bdc9c674..67f03bfd2 100644 --- a/src/java/org/apache/fop/render/afp/ResourceInfo.java +++ b/src/java/org/apache/fop/render/afp/ResourceInfo.java @@ -23,19 +23,36 @@ package org.apache.fop.render.afp; * The level at which a resource is to reside in the AFP output */ public class ResourceInfo { + /** the uri of this resource */ + private String uri; - /** - * the reference name of this resource - */ + /** the reference name of this resource */ private String name = null; + /** the resource level (default to print-file) */ + private ResourceLevel level = new ResourceLevel(ResourceLevel.PRINT_FILE); + /** - * the resource level (default to print-file) + * Sets the data object uri + * + * @param uri the data object uri */ - private ResourceLevel level = new ResourceLevel(ResourceLevel.PRINT_FILE); + public void setUri(String uri) { + this.uri = uri; + } /** + * Returns the uri of this data object + * + * @return the uri of this data object + */ + public String getUri() { + return uri; + } + + /** * Sets the resource reference name + * * @param resourceName the resource reference name */ public void setName(String resourceName) { @@ -43,6 +60,8 @@ public class ResourceInfo { } /** + * Returns the resource reference name + * * @return the resource reference name */ public String getName() { @@ -50,14 +69,8 @@ public class ResourceInfo { } /** - * {@inheritDoc} - */ - public String toString() { - return "ResourceInfo(" + (name != null ? "name=" + name - + ", " : "") + "level=" + level + ")"; - } - - /** + * Returns the resource level + * * @return the resource level */ public ResourceLevel getLevel() { @@ -66,9 +79,41 @@ public class ResourceInfo { /** * Sets the resource level + * * @param resourceLevel the resource level */ public void setLevel(ResourceLevel resourceLevel) { this.level = resourceLevel; } + + /** {@inheritDoc} */ + public String toString() { + return "ResourceInfo(uri=" + uri + + (name != null ? ", name=" + name : "") + + (level != null ? ", level=" + level : "") + ")"; + } + + /** {@inheritDoc} */ + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if ((obj == null) || !(obj instanceof ResourceInfo)) { + return false; + } + + ResourceInfo ri = (ResourceInfo)obj; + return (uri == ri.uri || uri != null && uri.equals(ri.uri)) + && (name == ri.name || name != null && name.equals(ri.name)) + && (level == ri.level || level != null && level.equals(ri.level)); + } + + /** {@inheritDoc} */ + public int hashCode() { + int hash = 7; + hash = 31 * hash + (null == uri ? 0 : uri.hashCode()); + hash = 31 * hash + (null == name ? 0 : name.hashCode()); + hash = 31 * hash + (null == level ? 0 : level.hashCode()); + return hash; + } }
\ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/ResourceLevel.java b/src/java/org/apache/fop/render/afp/ResourceLevel.java index 37a8e6dce..205a483ff 100644 --- a/src/java/org/apache/fop/render/afp/ResourceLevel.java +++ b/src/java/org/apache/fop/render/afp/ResourceLevel.java @@ -19,12 +19,11 @@ package org.apache.fop.render.afp; -import java.io.File; - /** * A resource level */ public class ResourceLevel { + /** page level **/ public static final int PAGE = 0; @@ -48,19 +47,18 @@ public class ResourceLevel { private static final String[] NAMES = new String[] {NAME_PAGE, NAME_PAGE_GROUP, NAME_DOCUMENT, NAME_PRINT_FILE, NAME_EXTERNAL}; + - /** - * where the resource will reside in the AFP output - */ + + /** where the resource will reside in the AFP output */ private int level = PRINT_FILE; // default is print-file level - /** - * the external resource group file - */ - private File externalResourceGroupFile = null; + /** the external resource group file path */ + private String extFilePath = null; /** * Sets the resource placement level within the AFP output + * * @param lvl the resource level (page, page-group, document, print-file or external) * @return true if the resource level was successfully set */ @@ -80,13 +78,25 @@ public class ResourceLevel { /** * Main constructor + * * @param level the resource level */ public ResourceLevel(int level) { + setLevel(level); + } + + /** + * Sets the resource level + * + * @param level the resource level + */ + public void setLevel(int level) { this.level = level; } /** + * Returns true if this is a page level resource group + * * @return true if this is a page level resource group */ public boolean isPage() { @@ -94,6 +104,8 @@ public class ResourceLevel { } /** + * Returns true if this is a page group level resource group + * * @return true if this is a page group level resource group */ public boolean isPageGroup() { @@ -101,6 +113,8 @@ public class ResourceLevel { } /** + * Returns true if this is a document level resource group + * * @return true if this is a document level resource group */ public boolean isDocument() { @@ -108,6 +122,8 @@ public class ResourceLevel { } /** + * Returns true if this is an external level resource group + * * @return true if this is an external level resource group */ public boolean isExternal() { @@ -115,6 +131,8 @@ public class ResourceLevel { } /** + * Returns true if this is a print-file level resource group + * * @return true if this is a print-file level resource group */ public boolean isPrintFile() { @@ -122,39 +140,48 @@ public class ResourceLevel { } /** - * @return the external resource group file of this resource - */ - public File getExternalResourceGroupFile() { - return this.externalResourceGroupFile; - } - - /** + * Returns the destination file path of the external resource group file + * * @return the destination file path of the external resource group file */ - public String getExternalResourceGroupFilePath() { - if (externalResourceGroupFile != null) { - return externalResourceGroupFile.getAbsolutePath(); - } - return null; + public String getExternalFilePath() { + return this.extFilePath; } /** * Sets the external destination of the resource - * @param file the external resource group file + * + * @param filePath the external resource group file */ - public void setExternalResourceGroupFile(File file) { - this.externalResourceGroupFile = file; + public void setExternalFilePath(String filePath) { + this.extFilePath = filePath; } - /** - * @return true if this resource has a defined external resource group file destination - */ - public boolean hasExternalResourceGroupFile() { - return getExternalResourceGroupFile() != null; + /** {@inheritDoc} */ + public String toString() { + return NAMES[level] + (isExternal() ? ", file=" + extFilePath : ""); } + + /** {@inheritDoc} */ + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if ((obj == null) || !(obj instanceof ResourceLevel)) { + return false; + } + ResourceLevel rl = (ResourceLevel)obj; + return (level == level) + && (extFilePath == rl.extFilePath + || extFilePath != null && extFilePath.equals(rl.extFilePath)); + } + /** {@inheritDoc} */ - public String toString() { - return NAMES[level] + (isExternal() ? ", file=" + externalResourceGroupFile : ""); + public int hashCode() { + int hash = 7; + hash = 31 * hash + level; + hash = 31 * hash + (null == extFilePath ? 0 : extFilePath.hashCode()); + return hash; } }
\ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsChainedSegment.java b/src/java/org/apache/fop/render/afp/goca/GraphicsChainedSegment.java index 613a24a3d..9be20c4cb 100644 --- a/src/java/org/apache/fop/render/afp/goca/GraphicsChainedSegment.java +++ b/src/java/org/apache/fop/render/afp/goca/GraphicsChainedSegment.java @@ -31,9 +31,7 @@ import org.apache.fop.render.afp.tools.BinaryUtils; */ public final class GraphicsChainedSegment extends AbstractPreparedObjectContainer { - /** - * The maximum segment data length - */ + /** The maximum segment data length */ protected static final int MAX_DATA_LEN = 8192; /** the current area */ @@ -69,9 +67,7 @@ public final class GraphicsChainedSegment extends AbstractPreparedObjectContaine this.previous = previous; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public int getDataLength() { int dataLen = 14 + super.getDataLength(); if (previous == null) { @@ -84,9 +80,7 @@ public final class GraphicsChainedSegment extends AbstractPreparedObjectContaine return dataLen; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected int getNameLength() { return 4; } @@ -95,20 +89,20 @@ public final class GraphicsChainedSegment extends AbstractPreparedObjectContaine // private static final byte PROLOG = 4; // private static final byte APPEND_TO_EXISING = 48; - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { super.writeStart(os); int len = super.getDataLength(); byte[] segLen = BinaryUtils.convert(len, 2); + + byte[] nameBytes = getNameBytes(); byte[] data = new byte[] { 0x70, // BEGIN_SEGMENT 0x0C, // Length of following parameters - this.nameBytes[0], - this.nameBytes[1], - this.nameBytes[2], - this.nameBytes[3], + nameBytes[0], + nameBytes[1], + nameBytes[2], + nameBytes[3], 0x00, // FLAG1 (ignored) APPEND_NEW_SEGMENT, segLen[0], // SEGL @@ -120,17 +114,13 @@ public final class GraphicsChainedSegment extends AbstractPreparedObjectContaine }; // P/S NAME (predecessor name) if (previous != null) { - data[10] = previous.nameBytes[0]; - data[11] = previous.nameBytes[1]; - data[12] = previous.nameBytes[2]; - data[13] = previous.nameBytes[3]; + nameBytes = previous.getNameBytes(); + System.arraycopy(nameBytes, 0, data, 10, 4); } os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { // I am the first segment in the chain so write out the rest if (previous == null) { @@ -142,24 +132,18 @@ public final class GraphicsChainedSegment extends AbstractPreparedObjectContaine } } - /** - * Begins a graphics area (start of fill) - */ + /** Begins a graphics area (start of fill) */ protected void beginArea() { this.currentArea = new GraphicsArea(); super.addObject(currentArea); } - /** - * Ends a graphics area (end of fill) - */ + /** Ends a graphics area (end of fill) */ protected void endArea() { this.currentArea = null; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public PreparedAFPObject addObject(PreparedAFPObject drawingOrder) { if (currentArea != null) { currentArea.addObject(drawingOrder); @@ -169,9 +153,7 @@ public final class GraphicsChainedSegment extends AbstractPreparedObjectContaine return drawingOrder; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public String toString() { return "GraphicsChainedSegment(name=" + super.getName() + ")"; } diff --git a/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java b/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java index 8c2c1b958..8d640b998 100644 --- a/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java +++ b/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java @@ -20,7 +20,6 @@ package org.apache.fop.render.afp.modca; import java.awt.Color; -import java.io.File; import java.io.IOException; import java.io.OutputStream; import java.util.Iterator; @@ -32,9 +31,11 @@ import org.apache.commons.logging.LogFactory; import org.apache.fop.render.afp.AFPFontAttributes; import org.apache.fop.render.afp.AFPTextDataInfo; import org.apache.fop.render.afp.DataObjectInfo; +import org.apache.fop.render.afp.ExternalResourceGroupManager; import org.apache.fop.render.afp.ObjectAreaInfo; import org.apache.fop.render.afp.ResourceInfo; import org.apache.fop.render.afp.ResourceLevel; +import org.apache.fop.render.afp.DataObjectCache; import org.apache.fop.render.afp.fonts.AFPFont; import org.apache.fop.render.afp.modca.triplets.FullyQualifiedNameTriplet; import org.apache.fop.render.afp.tools.StringUtils; @@ -56,11 +57,8 @@ import org.apache.fop.render.afp.tools.StringUtils; */ public class AFPDataStream extends AbstractResourceGroupContainer { - /** - * Static logging instance - */ - protected static Log log = LogFactory - .getLog("org.apache.fop.render.afp.modca"); + /** Static logging instance */ + protected static Log log = LogFactory.getLog("org.apache.fop.render.afp.modca"); /** * Boolean completion indicator @@ -192,15 +190,7 @@ public class AFPDataStream extends AbstractResourceGroupContainer { this.outputStream = outputStream; } - /** - * The document is written/ended by invoking this method which creates an - * instance of the AFP Document object and registers the start with a - * validation map which ensures that methods are not invoked out of the - * correct sequence. - * - * @throws java.io.IOException - * throws an I/O exception of some sort has occurred - */ + /** {@inheritDoc} */ public void write() throws IOException { if (complete) { String msg = "Invalid state - document already ended."; @@ -220,7 +210,7 @@ public class AFPDataStream extends AbstractResourceGroupContainer { if (interchangeSet.supportsLevel2()) { // Write out any external resource groups - getExternalResourceGroupManager().writeExternalResources(); + getExternalResourceGroupManager().write(); // Write out any print-file level resources if (hasResources()) { @@ -241,6 +231,8 @@ public class AFPDataStream extends AbstractResourceGroupContainer { this.document = null; this.outputStream = null; + + DataObjectCache.getInstance().clear(); } /** @@ -295,18 +287,13 @@ public class AFPDataStream extends AbstractResourceGroupContainer { String overlayName = "OVL" + StringUtils.lpad(String.valueOf(++overlayCount), '0', 5); - this.currentOverlay = new Overlay(overlayName, width, height, widthRes, - heightRes, overlayRotation); - - if (interchangeSet.supportsLevel2()) { - ResourceObject resourceObject = new ResourceObject(overlayName); - resourceObject.setDataObject(currentOverlay); - getResourceGroup().addObject(resourceObject); - } + DataObjectCache cache = DataObjectCache.getInstance(); + DataObjectFactory factory = cache.getFactory(); + this.currentOverlay = factory.createOverlay( + overlayName, width, height, widthRes, heightRes, overlayRotation); currentPageObject.createIncludePageOverlay(overlayName, x, y, 0); currentPage = currentOverlay; -// setOffsets(0, 0, 0); } /** @@ -439,10 +426,10 @@ public class AFPDataStream extends AbstractResourceGroupContainer { * * @param dataObjectInfo * the data object info - * @return a data object */ - public AbstractNamedAFPObject createObject(DataObjectInfo dataObjectInfo) { - String uri = dataObjectInfo.getUri(); + public void createObject(DataObjectInfo dataObjectInfo) { + ResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); + String uri = resourceInfo.getUri(); if (uri == null) { uri = "/"; @@ -451,40 +438,50 @@ public class AFPDataStream extends AbstractResourceGroupContainer { // unique if (uri.endsWith("/")) { uri += "#" + (++instreamObjectCount); - dataObjectInfo.setUri(uri); + resourceInfo.setUri(uri); } - //Update placement with current state + // Update placement with current state ObjectAreaInfo areaInfo = dataObjectInfo.getObjectAreaInfo(); areaInfo.setX(areaInfo.getX()); areaInfo.setY(areaInfo.getY()); areaInfo.setRotation(this.rotation); + // Do we have a recognised/registered object type? Registry registry = Registry.getInstance(); Registry.ObjectType objectType = registry.getObjectType(dataObjectInfo); - // recognised object type if (objectType != null) { dataObjectInfo.setObjectType(objectType); + } + + DataObjectCache cache = DataObjectCache.getInstance(); + String includeName = cache.put(dataObjectInfo); - ResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); + if (objectType != null) { + ResourceLevel resourceLevel = resourceInfo.getLevel(); // is MO:DCA-L available? if (interchangeSet.supportsLevel2()) { - // can this data object use the include object (IOB) referencing + + // Can this data object use the include object (IOB) referencing // mechanism? if (objectType.canBeIncluded()) { + + // Create and return include + DataObjectFactory factory = cache.getFactory(); + IncludeObject includeObj = factory.createInclude(includeName, dataObjectInfo); + getCurrentPage().addObject(includeObj); + + // Record the resource cache key (uri) in the ResourceGroup ResourceGroup resourceGroup = getResourceGroup(resourceLevel); - IncludeObject includeObject = resourceGroup.createObject(dataObjectInfo); - - // add include to current page - getCurrentPage().addObject(includeObject); - return includeObject.getDataObject(); + resourceGroup.addObject(resourceInfo); + return; } else { - log.warn("data object located at '" + uri + "'" + log.warn("Data object located at '" + uri + "'" + " of type '" + objectType.getMimeType() + "'" + " cannot be included with an IOB so it will be embedded directly"); - } + } } else { if (resourceLevel.isExternal()) { log.warn(interchangeSet @@ -492,11 +489,8 @@ public class AFPDataStream extends AbstractResourceGroupContainer { } } } - // unrecognised/unsupported object type so create/embed data object - // directly in current page - AbstractNamedAFPObject dataObj = currentPageObject.createObject(dataObjectInfo); - getCurrentPage().addObject(dataObj); - return dataObj; + // Unrecognised/unsupported object type so add object reference directly in current page + currentPageObject.addObject(resourceInfo); } // /** @@ -713,6 +707,11 @@ public class AFPDataStream extends AbstractResourceGroupContainer { getCurrentPage().createNoOperation(content); } + /** + * Returns the current page group + * + * @return the current page group + */ private PageGroup getCurrentPageGroup() { if (currentPageGroup == null) { String pageGroupName = "PGP" @@ -747,8 +746,7 @@ public class AFPDataStream extends AbstractResourceGroupContainer { * Sets the rotation to be used for portrait pages, valid values are 0 * (default), 90, 180, 270. * - * @param pageRotation - * The rotation in degrees. + * @param pageRotation the rotation in degrees. */ public void setPortraitRotation(int pageRotation) { if (pageRotation == 0 || pageRotation == 90 || pageRotation == 180 @@ -764,8 +762,7 @@ public class AFPDataStream extends AbstractResourceGroupContainer { * Sets the rotation to be used for landscape pages, valid values are 0, 90, * 180, 270 (default). * - * @param pageRotation - * The rotation in degrees. + * @param pageRotation the rotation in degrees. */ public void setLandscapeRotation(int pageRotation) { if (pageRotation == 0 || pageRotation == 90 || pageRotation == 180 @@ -778,164 +775,57 @@ public class AFPDataStream extends AbstractResourceGroupContainer { } /** - * Returns the resource group for a given resource into - * - * @param level - * resource info - * @return a resource group container for the given resource info - */ - private ResourceGroup getResourceGroup(ResourceLevel level) { - ResourceGroup resourceGroup = null; - if (level.isPrintFile()) { - resourceGroup = getResourceGroup(); - } else if (level.isDocument()) { - resourceGroup = getDocument().getResourceGroup(); - } else if (level.isPageGroup()) { - resourceGroup = getCurrentPageGroup().getResourceGroup(); - } else if (level.isPage()) { - resourceGroup = currentPageObject.getResourceGroup(); - } else if (level.isExternal()) { - resourceGroup = getExternalResourceGroupManager() - .getExternalResourceGroup(level); - } - return resourceGroup; - } - - /** * Sets the default resource group file * - * @param resourceGroupFile - * the default resource group file + * @param filePath the default resource group file path */ - public void setDefaultResourceGroupFile(File resourceGroupFile) { - getExternalResourceGroupManager().setDefaultResourceGroupFile( - resourceGroupFile); + public void setDefaultResourceGroupFilePath(String filePath) { + getExternalResourceGroupManager().setDefaultResourceGroupFilePath(filePath); } /** + * Returns the external resource group manager + * * @return the resource group manager */ protected ExternalResourceGroupManager getExternalResourceGroupManager() { if (externalResourceGroupManager == null) { - this.externalResourceGroupManager = new ExternalResourceGroupManager(this); + this.externalResourceGroupManager = new ExternalResourceGroupManager(); } return this.externalResourceGroupManager; } /** - * Manages the use of resource groups (external and internal) + * Returns the resource group for a given resource info + * + * @param level a resource level + * @return a resource group for the given resource info */ - private final class ExternalResourceGroupManager { - /** - * A mapping of external resource destinations to resource groups - */ - private Map/*<File,ResourceGroup>*/externalResourceGroups = null; - - /** sets the default resource group file */ - private File defaultResourceGroupFile; - - /** the container of this manager */ - private AbstractResourceGroupContainer container; - - /** - * Main constructor - * - * @param container - * the container of this manager - */ - private ExternalResourceGroupManager( - AbstractResourceGroupContainer container) { - this.container = container; - } - - /** - * Sets the default resource group file - * - * @param resourceGroupFile - * the default resource group file - */ - private void setDefaultResourceGroupFile(File resourceGroupFile) { - this.defaultResourceGroupFile = resourceGroupFile; - } - - /** - * Writes out external AFP resources - */ - private void writeExternalResources() { - // write any external resources - Iterator it = getExternalResourceGroups().keySet().iterator(); - while (it.hasNext()) { - File resourceGroupFile = (File) it.next(); - ResourceGroup resourceGroup = (ResourceGroup) getExternalResourceGroups() - .get(resourceGroupFile); - OutputStream os = null; - try { - log.debug("Writing external AFP resource file " - + resourceGroupFile.getAbsolutePath()); - - os = new java.io.FileOutputStream(resourceGroupFile); - resourceGroup.write(os); - } catch (IOException e) { - log.error( - "An error occurred when attempting to write external AFP resource file " - + resourceGroupFile.getAbsolutePath()); - } finally { - if (os != null) { - try { - os.close(); - } catch (IOException e) { - log.error("Failed to close outputstream for external AFP resource file " - + resourceGroupFile.getAbsolutePath()); - } - } - } - } - } - - /** - * Returns the corresponding resource group for the given resource level - * - * @param level - * the resource level - * @return the corresponding resource group for the given resource level - */ - private ResourceGroup getExternalResourceGroup(ResourceLevel level) { - ResourceGroup resourceGroup; - // this resource info does not have an external resource group - // file definition - if (!level.hasExternalResourceGroupFile()) { - if (defaultResourceGroupFile != null) { - // fallback to default resource group file - level.setExternalResourceGroupFile(defaultResourceGroupFile); - resourceGroup = getExternalResourceGroup(level); - } else { - // use print-file level resource group in the absence - // of an external resource group file definition - resourceGroup = container.getResourceGroup(); - } - } else { - File resourceGroupFile = level - .getExternalResourceGroupFile(); - resourceGroup = (ResourceGroup)getExternalResourceGroups().get(resourceGroupFile); - if (resourceGroup == null) { - resourceGroup = new ResourceGroup(); - externalResourceGroups - .put(resourceGroupFile, resourceGroup); - } - } - return resourceGroup; - } - - private Map/*<File,ResourceGroup>*/getExternalResourceGroups() { - if (externalResourceGroups == null) { - externalResourceGroups = new java.util.HashMap/*<File,ResourceGroup>*/(); + private ResourceGroup getResourceGroup(ResourceLevel level) { + ResourceGroup resourceGroup = null; + if (level.isExternal()) { + resourceGroup = getExternalResourceGroupManager().getResourceGroup(level); + // use print-file level resource group in the absence + // of an external resource group file definition + if (resourceGroup == null) { + level.setLevel(ResourceLevel.PRINT_FILE); } - return externalResourceGroups; } + if (level.isPrintFile()) { + resourceGroup = getResourceGroup(); + } else if (level.isDocument()) { + resourceGroup = getDocument().getResourceGroup(); + } else if (level.isPageGroup()) { + resourceGroup = getCurrentPageGroup().getResourceGroup(); + } else if (level.isPage()) { + resourceGroup = currentPageObject.getResourceGroup(); + } + return resourceGroup; } /** * Sets the MO:DCA interchange set to use + * * @param interchangeSet the MO:DCA interchange set */ public void setInterchangeSet(InterchangeSet interchangeSet) { @@ -943,6 +833,8 @@ public class AFPDataStream extends AbstractResourceGroupContainer { } /** + * Returns the MO:DCA interchange set in use + * * @return the MO:DCA interchange set in use */ public InterchangeSet getInterchangeSet() { diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java index 9cad38ef5..d9f3d6d1a 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java @@ -35,13 +35,52 @@ import org.apache.commons.logging.LogFactory; */ public abstract class AbstractAFPObject implements Writable { + /** Static logging instance */ + protected static final Log log = LogFactory.getLog("org.apache.fop.render.afp.modca"); + + private static final byte SF_CLASS = (byte)0xD3; + + private static final byte[] SF = new byte[] { + 0x5A, // Structured field identifier + 0x00, // Length byte 1 + 0x10, // Length byte 2 + (byte) SF_CLASS, // Structured field id byte 1 + (byte) 0x00, // Structured field id byte 2 + (byte) 0x00, // Structured field id byte 3 + 0x00, // Flags + 0x00, // Reserved + 0x00, // Reserved + }; + /** - * Static logging instance + * Copies the template structured field data array to the given byte array + * + * @param data the structured field data byte array + * @param type the type code + * @param category the category code */ - protected static final Log log = LogFactory.getLog("org.apache.fop.render.afp.modca"); + protected void copySF(byte[] data, byte type, byte category) { + copySF(data, SF_CLASS, type, category); + } + + /** + * Copies the template structured field data array to the given byte array + * + * @param data the structured field data byte array + * @param clazz the class code + * @param type the type code + * @param category the category code + */ + protected void copySF(byte[] data, byte clazz, byte type, byte category) { + System.arraycopy(SF, 0, data, 0, SF.length); + data[3] = clazz; + data[4] = type; + data[5] = category; + } /** * Help method to write a set of AFPObjects to the AFP datastream. + * * @param objects a list of AFPObjects * @param os The stream to write to * @throws java.io.IOException an I/O exception of some sort has occurred. @@ -55,5 +94,146 @@ public abstract class AbstractAFPObject implements Writable { } } } + + /** structured field type codes */ + interface Type { + + // Attribute + byte ATTRIBUTE = (byte)0x0A; + + // Copy Count + byte COPY_COUNT = (byte)0xA2; + + // Descriptor + byte DESCRIPTOR = (byte)0xA6; + + // Control + byte CONTROL = (byte)0xA7; + + // Begin + byte BEGIN = (byte)0xA8; + + // End + byte END = (byte)0xA9; + + // Map + byte MAP = (byte)0xAB; + + // Position + byte POSITION = (byte)0xAC; + + // Process + byte PROCESS = (byte)0xAD; + + // Include + byte INCLUDE = (byte)0xAF; + + // Table + byte TABLE = (byte)0xB0; + + // Migration + byte MIGRATION = (byte)0xB1; + + // Variable + byte VARIABLE = (byte)0xB2; + + // Link + byte LINK = (byte)0xB4; + + // Data + byte DATA = (byte)0xEE; + } + + /** structured field category codes */ + interface Category { + + // Page Segment + byte PAGE_SEGMENT = (byte)0x5F; + + // Object Area + byte OBJECT_AREA = (byte)0x6B; + + // Color Attribute Table + byte COLOR_ATTRIBUTE_TABLE = (byte)0x77; + + // IM Image + byte IM_IMAGE = (byte)0x7B; + + // Medium + byte MEDIUM = (byte)0x88; + + // Coded Font + byte CODED_FONT = (byte)0x8A; + + // Process Element + byte PROCESS_ELEMENT = (byte)0x90; + + // Object Container + byte OBJECT_CONTAINER = (byte)0x92; + + // Presentation Text + byte PRESENTATION_TEXT = (byte)0x9B; + + // Index + byte INDEX = (byte)0xA7; + + // Document + byte DOCUMENT = (byte)0xA8; + + // Page Group + byte PAGE_GROUP = (byte)0xAD; + + // Page + byte PAGE = (byte)0xAF; + + // Graphics + byte GRAPHICS = (byte)0xBB; + + // Data Resource + byte DATA_RESOURCE = (byte)0xC3; + + // Document Environment Group (DEG) + byte DOCUMENT_ENVIRONMENT_GROUP = (byte)0xC4; + + // Resource Group + byte RESOURCE_GROUP = (byte)0xC6; + + // Object Environment Group (OEG) + byte OBJECT_ENVIRONMENT_GROUP = (byte)0xC7; + + // Active Environment Group (AEG) + byte ACTIVE_ENVIRONMENT_GROUP = (byte)0xC9; + + // Medium Map + byte MEDIUM_MAP = (byte)0xCC; + + // Form Map + byte FORM_MAP = (byte)0xCD; + + // Name Resource + byte NAME_RESOURCE = (byte)0xCE; + + // Page Overlay + byte PAGE_OVERLAY = (byte)0xD8; + + // Resource Environment Group (REG) + byte RESOURCE_ENVIROMENT_GROUP = (byte)0xD9; + + // Overlay + byte OVERLAY = (byte)0xDF; + + // Data Suppression + byte DATA_SUPRESSION = (byte)0xEA; + + // Bar Code + byte BARCODE = (byte)0xEB; + + // No Operation + byte NO_OPERATION = (byte)0xEE; + + // Image + byte IMAGE = (byte)0xFB; + } + } diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java index f52047b62..f666de38b 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java @@ -24,20 +24,18 @@ import java.io.OutputStream; import org.apache.fop.render.afp.ObjectAreaInfo; - /** * Abstract base class used by the ImageObject and GraphicsObject which both * have define an ObjectEnvironmentGroup */ public abstract class AbstractDataObject extends AbstractPreparedObjectContainer { - /** - * The object environment group - */ + /** The object environment group */ protected ObjectEnvironmentGroup objectEnvironmentGroup = null; /** * Named constructor + * * @param name data object name */ public AbstractDataObject(String name) { @@ -56,6 +54,7 @@ public abstract class AbstractDataObject extends AbstractPreparedObjectContainer /** * Gets the ObjectEnvironmentGroup + * * @return the object environment group */ protected ObjectEnvironmentGroup getObjectEnvironmentGroup() { @@ -67,15 +66,14 @@ public abstract class AbstractDataObject extends AbstractPreparedObjectContainer /** * Sets the ObjectEnvironmentGroup. + * * @param objectEnvironmentGroup The objectEnvironmentGroup to set */ public void setObjectEnvironmentGroup(ObjectEnvironmentGroup objectEnvironmentGroup) { this.objectEnvironmentGroup = objectEnvironmentGroup; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { if (objectEnvironmentGroup != null) { objectEnvironmentGroup.write(os); diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractDescriptor.java b/src/java/org/apache/fop/render/afp/modca/AbstractDescriptor.java index 6d827766e..f5bc933a3 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractDescriptor.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractDescriptor.java @@ -35,6 +35,7 @@ public abstract class AbstractDescriptor extends AbstractAFPObject { /** * Constructor a PresentationTextDescriptor for the specified * width and height. + * * @param width The width of the page. * @param height The height of the page. * @param widthResolution The width resolution of the page. diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractEnvironmentGroup.java b/src/java/org/apache/fop/render/afp/modca/AbstractEnvironmentGroup.java index 3f371d628..7e81e4934 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractEnvironmentGroup.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractEnvironmentGroup.java @@ -36,6 +36,7 @@ public abstract class AbstractEnvironmentGroup extends AbstractNamedAFPObject { /** * Main constructor + * * @param name the object name */ public AbstractEnvironmentGroup(String name) { @@ -52,6 +53,7 @@ public abstract class AbstractEnvironmentGroup extends AbstractNamedAFPObject { /** * Actually creates the MPO object. * Also creates the supporting object (an IPO) + * * @param name the name of the overlay to be used */ public void createOverlay(String name) { @@ -78,6 +80,7 @@ public abstract class AbstractEnvironmentGroup extends AbstractNamedAFPObject { /** * Getter method for the most recent MapPageOverlay added to the * Active Environment Group (returns null if no MapPageOverlay exist) + * * @return the most recent Map Coded Font */ private MapPageOverlay getCurrentMapPageOverlay() { @@ -88,9 +91,7 @@ public abstract class AbstractEnvironmentGroup extends AbstractNamedAFPObject { } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { super.writeContent(os); if (mapPageOverlays != null) { diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractNamedAFPObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractNamedAFPObject.java index 8e6127b8a..6ed3411bc 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractNamedAFPObject.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractNamedAFPObject.java @@ -35,11 +35,6 @@ public abstract class AbstractNamedAFPObject extends AbstractStructuredAFPObject protected String name = null; /** - * The name of the object in EBCIDIC bytes - */ - protected byte[] nameBytes; - - /** * Default constructor */ protected AbstractNamedAFPObject() { @@ -48,16 +43,26 @@ public abstract class AbstractNamedAFPObject extends AbstractStructuredAFPObject /** * Constructor for the ActiveEnvironmentGroup, this takes a * name parameter which should be 8 characters long. + * * @param name the object name */ protected AbstractNamedAFPObject(String name) { this.name = name; - if (name.length() < 8) { - name = (name + " ").substring(0, 8); - } else if (name.length() > 8) { - log.warn("Constructor:: name truncated to 8 chars" + name); - name = name.substring(0, 8); + } + + /** + * Returns the name as a byte array in EBCIDIC encoding + * + * @return the name as a byte array in EBCIDIC encoding + */ + protected byte[] getNameBytes() { + if (name.length() < DEFAULT_NAME_LENGTH) { + name = (name + " ").substring(0, DEFAULT_NAME_LENGTH); + } else if (name.length() > DEFAULT_NAME_LENGTH) { + log.warn("Constructor:: name truncated to " + DEFAULT_NAME_LENGTH + " chars" + name); + name = name.substring(0, DEFAULT_NAME_LENGTH); } + byte[] nameBytes = null; try { nameBytes = name.getBytes(AFPConstants.EBCIDIC_ENCODING); } catch (UnsupportedEncodingException usee) { @@ -66,17 +71,20 @@ public abstract class AbstractNamedAFPObject extends AbstractStructuredAFPObject "Constructor:: UnsupportedEncodingException translating the name " + name); } + return nameBytes; } - /** - * @return the name length of this object - */ - protected int getNameLength() { - return DEFAULT_NAME_LENGTH; + /** {@inheritDoc} */ + protected void copySF(byte[] data, byte type, byte category) { + super.copySF(data, type, category); + byte[] nameData = getNameBytes(); + System.arraycopy(nameData, 0, data, 9, nameData.length); } /** - * @return the name of the page group + * Returns the name of this object + * + * @return the name of this object */ public String getName() { return name; diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java index c5b2f3ea2..73c4b6821 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java @@ -22,9 +22,12 @@ package org.apache.fop.render.afp.modca; import java.awt.Color; import java.io.IOException; import java.io.OutputStream; +import java.util.Iterator; import java.util.List; import org.apache.fop.render.afp.AFPTextDataInfo; +import org.apache.fop.render.afp.DataObjectCache; +import org.apache.fop.render.afp.ResourceInfo; import org.apache.fop.render.afp.fonts.AFPFont; /** @@ -112,6 +115,7 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { /** * Named constructor + * * @param name the name of this page object */ public AbstractPageObject(String name) { @@ -218,6 +222,7 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { /** * Helper method to create a presentation text object * on the current page and to return the object. + * * @return the presentation text object */ private PresentationTextObject getPresentationTextObject() { @@ -305,6 +310,7 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { /** * Returns an indication if the page is complete + * * @return whether this page is complete */ public boolean isComplete() { @@ -313,6 +319,7 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { /** * Returns the height of the page + * * @return the height of the page */ public int getHeight() { @@ -321,6 +328,7 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { /** * Returns the width of the page + * * @return the width of the page */ public int getWidth() { @@ -329,15 +337,14 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { /** * Returns the rotation of the page + * * @return the rotation of the page */ public int getRotation() { return rotation; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { super.writeContent(os); if (this instanceof PageObject || this instanceof Overlay) { @@ -345,23 +352,37 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { } writeObjects(this.includePageSegments, os); writeObjects(this.tagLogicalElements, os); - writeObjects(this.objects, os); + + DataObjectCache cache = DataObjectCache.getInstance(); + + // Write objects from cache + Iterator it = objects.iterator(); + while (it.hasNext()) { + Object obj = it.next(); + if (obj instanceof Writable) { + Writable writableObject = (Writable)obj; + writableObject.write(os); + } else if (obj instanceof ResourceInfo) { + ResourceInfo resourceInfo = (ResourceInfo)obj; + byte[] data = cache.get(resourceInfo); + os.write(data); + } + } } /** - * Adds an AFP object to the resource group in this container + * Adds an AFP object reference to this page + * * @param obj an AFP object */ - protected void addObject(AbstractAFPObject obj) { + protected void addObject(Object obj) { if (objects == null) { - this.objects = new java.util.ArrayList/*<AbstractAFPObject>*/(); + this.objects = new java.util.ArrayList(); } objects.add(obj); } -// /** -// * {@inheritDoc} -// */ +// /** {@inheritDoc} */ // protected void addObject(AbstractAFPObject obj) { // if (obj instanceof DataObjectAccessor) { // DataObjectAccessor dataObjectAccessor = (DataObjectAccessor)obj; diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractPreparedAFPObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractPreparedAFPObject.java index d707384ed..16ed036f2 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractPreparedAFPObject.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractPreparedAFPObject.java @@ -41,15 +41,14 @@ implements PreparedAFPObject { /** * Named constructor + * * @param name the name of this AFP object */ public AbstractPreparedAFPObject(String name) { super(name); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { super.writeContent(os); // write triplets if (this.data != null) { @@ -83,6 +82,7 @@ implements PreparedAFPObject { /** * Sets the data + * * @param data the data */ protected void setData(byte[] data) { diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractPreparedObjectContainer.java b/src/java/org/apache/fop/render/afp/modca/AbstractPreparedObjectContainer.java index 3c2b3981d..03e646913 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractPreparedObjectContainer.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractPreparedObjectContainer.java @@ -30,9 +30,7 @@ import java.util.List; public abstract class AbstractPreparedObjectContainer extends AbstractNamedAFPObject implements PreparedAFPObject { - /** - * list of objects contained within this container - */ + /** list of objects contained within this container */ protected List/*<PreparedAFPObject>*/ objects = null; /** @@ -43,15 +41,14 @@ implements PreparedAFPObject { /** * Named constructor + * * @param name the name of the container */ protected AbstractPreparedObjectContainer(String name) { super(name); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { if (objects != null) { super.writeObjects(objects, os); @@ -67,16 +64,19 @@ implements PreparedAFPObject { /** * Adds a given prepared object to this container + * * @param preparedObject the prepared object * @return the drawingOrder if it was added, null otherwise */ public PreparedAFPObject addObject(PreparedAFPObject preparedObject) { - log.debug(this + " adding " + preparedObject); +// log.debug(this + " adding " + preparedObject); getObjects().add(preparedObject); return preparedObject; } /** + * Returns the current data length + * * @return the current data length of this container including * all enclosed objects (and their containers) */ diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractResourceEnvironmentGroupContainer.java b/src/java/org/apache/fop/render/afp/modca/AbstractResourceEnvironmentGroupContainer.java index 4a5785981..d56ebef9b 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractResourceEnvironmentGroupContainer.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractResourceEnvironmentGroupContainer.java @@ -36,6 +36,7 @@ public abstract class AbstractResourceEnvironmentGroupContainer /** * Main constructor + * * @param name the name of this resource container */ public AbstractResourceEnvironmentGroupContainer(String name) { @@ -44,6 +45,7 @@ public abstract class AbstractResourceEnvironmentGroupContainer /** * Adds a page to the resource container. + * * @param page - the Page object */ public void addPage(PageObject page) { @@ -52,6 +54,7 @@ public abstract class AbstractResourceEnvironmentGroupContainer /** * Adds a PageGroup to the resource container. + * * @param pageGroup the PageGroup object */ public void addPageGroup(PageGroup pageGroup) { @@ -68,9 +71,7 @@ public abstract class AbstractResourceEnvironmentGroupContainer addObject(new InvokeMediumMap(name)); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { super.writeContent(os); if (resourceEnvironmentGroup != null) { @@ -79,6 +80,8 @@ public abstract class AbstractResourceEnvironmentGroupContainer } /** + * Returns the resource environment group + * * @return the resource environment group */ protected ResourceEnvironmentGroup getResourceEnvironmentGroup() { diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractResourceGroupContainer.java b/src/java/org/apache/fop/render/afp/modca/AbstractResourceGroupContainer.java index 71cc4698b..55f3a89b1 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractResourceGroupContainer.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractResourceGroupContainer.java @@ -22,7 +22,7 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; import java.io.OutputStream; -import org.apache.fop.render.afp.DataObjectInfo; +//import org.apache.fop.render.afp.DataObjectInfo; /** * An abstract container of resource objects @@ -34,11 +34,6 @@ public abstract class AbstractResourceGroupContainer extends AbstractPageObject private ResourceGroup resourceGroup = null; /** - * The data object factory - */ - private DataObjectFactory dataObjectFactory = new DataObjectFactory(); - - /** * Default constructor */ public AbstractResourceGroupContainer() { @@ -47,6 +42,7 @@ public abstract class AbstractResourceGroupContainer extends AbstractPageObject /** * Named constructor + * * @param name the name of this resource container */ public AbstractResourceGroupContainer(String name) { @@ -102,14 +98,14 @@ public abstract class AbstractResourceGroupContainer extends AbstractPageObject return resourceGroup; } - /** - * Creates and returns a new data object - * @param dataObjectInfo the data object info - * @return a newly created data object - */ - public AbstractNamedAFPObject createObject(DataObjectInfo dataObjectInfo) { - return dataObjectFactory.create(dataObjectInfo); - } +// /** +// * Creates and returns a new data object +// * @param dataObjectInfo the data object info +// * @return a newly created data object +// */ +// public AbstractNamedAFPObject createObject(DataObjectInfo dataObjectInfo) { +// return dataObjectFactory.create(dataObjectInfo); +// } /** * {@inheritDoc} diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java index 1a23511f5..b3a3c7afb 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java @@ -38,8 +38,7 @@ import org.apache.fop.render.afp.modca.triplets.Triplet; /** * An abstract class encapsulating an MODCA structured object */ -public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { - +public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { /** * list of object triplets */ @@ -57,6 +56,8 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { } /** + * Returns the triplet data length + * * @return the triplet data length */ protected int getTripletDataLength() { @@ -74,6 +75,8 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { } /** + * Returns the triplet data + * * @return the triplet data * @throws IOException throws an I/O exception if one occurred */ @@ -88,6 +91,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { /** * Writes any triplet data + * * @param os The stream to write to * @throws IOException The stream to write to */ @@ -101,6 +105,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { /** * Helper method to write the start of the Object. + * * @param os The stream to write to * @throws IOException throws an I/O exception if one occurred */ @@ -109,7 +114,17 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { } /** + * Helper method to write the end of the Object. + * + * @param os The stream to write to + * @throws IOException an I/O exception if one occurred + */ + protected void writeEnd(OutputStream os) throws IOException { + } + + /** * Helper method to write the contents of the Object. + * * @param os The stream to write to * @throws IOException throws an I/O exception if one occurred */ @@ -118,15 +133,8 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { } /** - * Helper method to write the end of the Object. - * @param os The stream to write to - * @throws IOException an I/O exception if one occurred - */ - protected void writeEnd(OutputStream os) throws IOException { - } - - /** - * Accessor method to write the AFP datastream for the Image Object + * Accessor method to write the AFP datastream for this structure field object + * * @param os The stream to write to * @throws IOException in the event that an I/O exception occurred */ @@ -137,7 +145,8 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { } /** - * Returns the first matching triplet found in the structured field triplet list + * Returns the first matching triplet found in the structured field triplet list + * * @param tripletId the triplet identifier */ private Triplet getTriplet(byte tripletId) { @@ -152,6 +161,8 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { } /** + * Returns true of this structured field has the given triplet + * * @param tripletId the triplet identifier * @return true if the structured field has the given triplet */ @@ -161,6 +172,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { /** * Adds a triplet to this structured object + * * @param triplet the triplet to add */ private void addTriplet(Triplet triplet) { @@ -169,6 +181,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { /** * Adds a list of triplets to the triplets contained within this structured field + * * @param tripletCollection a collection of triplets */ private void addTriplets(Collection/*<Triplet>*/ tripletCollection) { @@ -177,9 +190,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { } } - /** - * @return the triplet list pertaining to this resource - */ + /** @return the triplet list pertaining to this resource */ protected List/*<Triplet>*/ getTriplets() { if (triplets == null) { triplets = new java.util.ArrayList(); @@ -189,6 +200,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { /** * Sets the fully qualified name of this resource + * * @param fqnType the fully qualified name type of this resource * @param fqnFormat the fully qualified name format of this resource * @param fqName the fully qualified name of this resource @@ -197,9 +209,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { addTriplet(new FullyQualifiedNameTriplet(fqnType, fqnFormat, fqName)); } - /** - * @return the fully qualified name of this triplet or null if it does not exist - */ + /** @return the fully qualified name of this triplet or null if it does not exist */ public String getFullyQualifiedName() { FullyQualifiedNameTriplet fqNameTriplet = (FullyQualifiedNameTriplet)getTriplet(Triplet.FULLY_QUALIFIED_NAME); @@ -212,6 +222,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { /** * Sets the objects classification + * * @param objectClass the classification of the object * @param objectType the MOD:CA registry object type entry for the given * object/component type of the object @@ -224,6 +235,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { /** * Sets the objects classification with the default structure flags + * * @param objectClass the classification of the object * @param objectType the MOD:CA registry object type entry for the given * object/component type of the object @@ -234,6 +246,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { /** * Sets the extent of an object area in the X and Y directions + * * @param x the x direction extent * @param y the y direction extent */ @@ -243,6 +256,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { /** * Sets the measurement units used to specify the units of measure + * * @param xRes units per base on the x-axis * @param yRes units per base on the y-axis */ @@ -252,6 +266,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { /** * Sets the mapping option + * * @param optionValue the mapping option value */ public void setMappingOption(byte optionValue) { @@ -260,6 +275,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { /** * Sets a comment on this resource + * * @param comment a comment string */ public void setComment(String comment) { diff --git a/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java b/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java index 4dd735ccc..916544603 100644 --- a/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java +++ b/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java @@ -77,6 +77,7 @@ public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { /** * Default constructor for the ActiveEnvironmentGroup. + * * @param width the page width * @param height the page height * @param widthRes the page width resolution @@ -89,6 +90,7 @@ public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { /** * Constructor for the ActiveEnvironmentGroup, this takes a * name parameter which must be 8 characters long. + * * @param name the active environment group name * @param width the page width * @param height the page height @@ -112,6 +114,7 @@ public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { /** * Set the position of the object area + * * @param x the x offset * @param y the y offset * @param rotation the rotation @@ -124,6 +127,7 @@ public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { /** * Accessor method to obtain the PageDescriptor object of the * active environment group. + * * @return the page descriptor object */ public PageDescriptor getPageDescriptor() { @@ -133,15 +137,14 @@ public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { /** * Accessor method to obtain the PresentationTextDataDescriptor object of * the active environment group. + * * @return the presentation text descriptor */ public PresentationTextDescriptor getPresentationTextDataDescriptor() { return presentationTextDataDescriptor; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void writeContent(OutputStream os) throws IOException { super.writeTriplets(os); @@ -161,43 +164,17 @@ public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA8; // Structured field id byte 2 - data[5] = (byte) 0xC9; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.BEGIN, Category.ACTIVE_ENVIRONMENT_GROUP); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA9; // Structured field id byte 2 - data[5] = (byte) 0xC9; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.END, Category.ACTIVE_ENVIRONMENT_GROUP); os.write(data); } @@ -208,15 +185,16 @@ public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { return mapCodedFonts; } - private List getMapDataResources() { - if (mapDataResources == null) { - mapDataResources = new java.util.ArrayList(); - } - return mapDataResources; - } +// private List getMapDataResources() { +// if (mapDataResources == null) { +// mapDataResources = new java.util.ArrayList(); +// } +// return mapDataResources; +// } /** * Method to create a map coded font object + * * @param fontRef the font number used as the resource identifier * @param font the font * @param size the point size of the font @@ -247,6 +225,7 @@ public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { /** * Getter method for the most recent MapCodedFont added to the * Active Environment Group (returns null if no MapCodedFonts exist) + * * @return the most recent Map Coded Font. */ private MapCodedFont getCurrentMapCodedFont() { @@ -258,11 +237,11 @@ public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { } } - /** - * Method to create a map data resource object - * @param dataObjectAccessor a data object accessor - */ - protected void createMapDataResource(DataObjectAccessor dataObjectAccessor) { - getMapDataResources().add(new MapDataResource(dataObjectAccessor)); - } +// /** +// * Method to create a map data resource object +// * @param dataObjectAccessor a data object accessor +// */ +// protected void createMapDataResource(DataObjectAccessor dataObjectAccessor) { +// getMapDataResources().add(new MapDataResource(dataObjectAccessor)); +// } }
\ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/DataObjectFactory.java b/src/java/org/apache/fop/render/afp/modca/DataObjectFactory.java index 7e3f41a53..0a5fb5bbe 100644 --- a/src/java/org/apache/fop/render/afp/modca/DataObjectFactory.java +++ b/src/java/org/apache/fop/render/afp/modca/DataObjectFactory.java @@ -19,24 +19,45 @@ package org.apache.fop.render.afp.modca; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.fop.render.afp.DataObjectInfo; +import org.apache.fop.render.afp.GraphicsObjectInfo; +import org.apache.fop.render.afp.GraphicsObjectPainter; import org.apache.fop.render.afp.ImageObjectInfo; import org.apache.fop.render.afp.ObjectAreaInfo; +import org.apache.fop.render.afp.ResourceInfo; +import org.apache.fop.render.afp.ResourceLevel; +import org.apache.fop.render.afp.modca.Registry.ObjectType; import org.apache.fop.render.afp.modca.triplets.FullyQualifiedNameTriplet; +import org.apache.fop.render.afp.modca.triplets.MappingOptionTriplet; +import org.apache.fop.render.afp.modca.triplets.ObjectClassificationTriplet; import org.apache.fop.render.afp.tools.StringUtils; import org.apache.xmlgraphics.image.codec.tiff.TIFFImage; /** - * Creator of MO;DCA data objects + * Creator of MO:DCA data objects */ public class DataObjectFactory { private static final String IMAGE_NAME_PREFIX = "IMG"; private static final String GRAPHIC_NAME_PREFIX = "GRA"; // private static final String BARCODE_NAME_PREFIX = "BAR"; // private static final String OTHER_NAME_PREFIX = "OTH"; + private static final String OBJECT_CONTAINER_NAME_PREFIX = "OC"; + private static final String RESOURCE_NAME_PREFIX = "RES"; private int imageCount = 0; private int graphicCount = 0; + private int objectContainerCount = 0; + private int resourceCount = 0; + + private Map/*<ResourceInfo,IncludeObject>*/ includeMap + = new java.util.HashMap/*<ResourceInfo,IncludeObject>*/(); + + /** Static logging instance */ + private static final Log log = LogFactory.getLog(DataObjectFactory.class); /** * Converts a byte array containing 24 bit RGB image data to a grayscale @@ -102,10 +123,11 @@ public class DataObjectFactory { /** * Helper method to create an image on the current container and to return * the object. + * * @param imageObjectInfo the image object info * @return a newly created image object */ - protected ImageObject createImage(ImageObjectInfo imageObjectInfo) { + private ImageObject createImage(ImageObjectInfo imageObjectInfo) { String name = IMAGE_NAME_PREFIX + StringUtils.lpad(String.valueOf(++imageCount), '0', 5); ImageObject imageObj = new ImageObject(name); @@ -144,36 +166,215 @@ public class DataObjectFactory { } /** - * Helper method to create a graphic in the current container and to return - * the object. - * @param info the data object info - * @return a newly created graphics object + * Creates and returns a new graphics object. + * + * @param graphicsObjectInfo the graphics object info + * @return a new graphics object */ - protected GraphicsObject createGraphic(DataObjectInfo info) { + private GraphicsObject createGraphic(GraphicsObjectInfo graphicsObjectInfo) { String name = GRAPHIC_NAME_PREFIX + StringUtils.lpad(String.valueOf(++graphicCount), '0', 5); GraphicsObject graphicsObj = new GraphicsObject(name); + + // paint the graphic using batik + GraphicsObjectPainter painter = graphicsObjectInfo.getPainter(); + painter.paint(graphicsObj); + return graphicsObj; } /** + * Creates and returns a new include object. + * + * @param name the name of this include object + * @param dataObjectInfo a data object info + * + * @return a new include object + */ + public IncludeObject createInclude(String name, DataObjectInfo dataObjectInfo) { + ResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); + IncludeObject includeObj = (IncludeObject)includeMap.get(resourceInfo); + if (includeObj == null) { + includeObj = new IncludeObject(name); + + Registry.ObjectType objectType = dataObjectInfo.getObjectType(); + if (objectType.isImage()) { + includeObj.setDataObjectType(IncludeObject.TYPE_IMAGE); + } else if (objectType.isGraphic()) { + includeObj.setDataObjectType(IncludeObject.TYPE_GRAPHIC); + // } else if (dataObject instanceof PageSegment) { + // includeObj.setDataObjectType(IncludeObject.TYPE_PAGE_SEGMENT); + } else { + includeObj.setDataObjectType(IncludeObject.TYPE_OTHER); + // Strip any object container + // AbstractNamedAFPObject dataObject = dataObjectAccessor.getDataObject(); + // if (dataObject instanceof ObjectContainer) { + // ObjectContainer objectContainer = (ObjectContainer)dataObject; + // dataObject = objectContainer.getDataObject(); + // } + } + +// includeObj.setFullyQualifiedName( +// FullyQualifiedNameTriplet.TYPE_REPLACE_FIRST_GID_NAME, +// FullyQualifiedNameTriplet.FORMAT_CHARSTR, +// dataObjectInfo.getUri()); + + includeObj.setObjectClassification( + ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT, + objectType); + + ObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo(); + + includeObj.setObjectArea(objectAreaInfo.getX(), objectAreaInfo.getY()); + + includeObj.setObjectAreaSize( + objectAreaInfo.getWidth(), objectAreaInfo.getHeight()); + + includeObj.setMeasurementUnits( + objectAreaInfo.getWidthRes(), objectAreaInfo.getHeightRes()); + + includeObj.setMappingOption(MappingOptionTriplet.SCALE_TO_FIT); + + includeMap.put(resourceInfo, includeObj); + } + + return includeObj; + } + + /** + * Creates and returns a new object container + * + * @return a new object container + */ + private ObjectContainer createObjectContainer() { + String name = OBJECT_CONTAINER_NAME_PREFIX + + StringUtils.lpad(String.valueOf(++objectContainerCount), '0', 6); + return new ObjectContainer(name); + } + + /** + * Creates and returns a new resource object + * + * @param resourceName the resource name + * @return a new resource object + */ + private ResourceObject createResource(String resourceName) { + return new ResourceObject(resourceName); + } + + /** + * Creates and returns a new resource object + * + * @return a new resource object + */ + private ResourceObject createResource() { + String name = RESOURCE_NAME_PREFIX + + StringUtils.lpad(String.valueOf(++resourceCount ), '0', 5); + return createResource(name); + } + + /** + * Creates and returns a new Overlay. + * + * @param overlayName + * the name of the overlay + * @param width + * the width of the overlay + * @param height + * the height of the overlay + * @param widthRes + * the width resolution of the overlay + * @param heightRes + * the height resolution of the overlay + * @param overlayRotation + * the rotation of the overlay + * + * @return a new overlay object + */ + public Overlay createOverlay(String overlayName, int width, int height, + int widthRes, int heightRes, int overlayRotation) { + Overlay overlay = new Overlay(overlayName, width, height, + overlayRotation, widthRes, heightRes); + return overlay; + } + + /** * Creates and returns a new data object + * * @param dataObjectInfo the data object info + * * @return a newly created data object */ - public AbstractDataObject create(DataObjectInfo dataObjectInfo) { - AbstractDataObject dataObject; + public AbstractNamedAFPObject createObject(DataObjectInfo dataObjectInfo) { + AbstractNamedAFPObject dataObj; + if (dataObjectInfo instanceof ImageObjectInfo) { - dataObject = createImage((ImageObjectInfo)dataObjectInfo); + dataObj = createImage((ImageObjectInfo)dataObjectInfo); + } else if (dataObjectInfo instanceof GraphicsObjectInfo) { + dataObj = createGraphic((GraphicsObjectInfo)dataObjectInfo); } else { - dataObject = createGraphic(dataObjectInfo); + throw new IllegalArgumentException("Unknown data object type: " + dataObjectInfo); } - dataObject.setViewport(dataObjectInfo.getObjectAreaInfo()); + + if (dataObj instanceof AbstractDataObject) { + ((AbstractDataObject)dataObj).setViewport(dataObjectInfo.getObjectAreaInfo()); + } + + dataObj.setFullyQualifiedName( + FullyQualifiedNameTriplet.TYPE_DATA_OBJECT_INTERNAL_RESOURCE_REF, + FullyQualifiedNameTriplet.FORMAT_CHARSTR, dataObj.getName()); - dataObject.setFullyQualifiedName( - FullyQualifiedNameTriplet.TYPE_DATA_OBJECT_INTERNAL_RESOURCE_REF, - FullyQualifiedNameTriplet.FORMAT_CHARSTR, dataObject.getName()); + ResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); + ResourceLevel resourceLevel = resourceInfo.getLevel(); - return dataObject; - } + if (resourceLevel.isPrintFile() || resourceLevel.isExternal()) { + + ObjectType objectType = dataObjectInfo.getObjectType(); + + if (objectType != null && objectType.canBeIncluded()) { + + // Wrap newly created data object in a resource object + // if it is to reside within a resource group at print-file or external level + if (resourceLevel.isPrintFile() || resourceLevel.isExternal()) { + ResourceObject resourceObj = null; + String resourceName = resourceInfo.getName(); + if (resourceName != null) { + resourceObj = createResource(resourceName); + } else { + resourceObj = createResource(); + } + + if (dataObj instanceof ObjectContainer) { + resourceObj.setType(ResourceObject.OBJECT_CONTAINER); + } else if (dataObj instanceof ImageObject) { + resourceObj.setType(ResourceObject.IMAGE_OBJECT); + } else if (dataObj instanceof GraphicsObject) { + resourceObj.setType(ResourceObject.GRAPHICS_OBJECT); + } else if (dataObj instanceof Document) { + resourceObj.setType(ResourceObject.DOCUMENT_OBJECT); + } else if (dataObj instanceof PageSegment) { + resourceObj.setType(ResourceObject.PAGE_SEGMENT_OBJECT); + } else if (dataObj instanceof Overlay) { + resourceObj.setType(ResourceObject.OVERLAY_OBJECT); + } else { + throw new UnsupportedOperationException( + "Unsupported resource object type " + dataObj); + } + + resourceObj.setObjectClassification( + ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT, + objectType); + + resourceObj.setDataObject(dataObj); + dataObj = resourceObj; + } + } else { + String uri = dataObjectInfo.getUri(); + log.warn("Data object '" + uri + "' not supported at " + + resourceLevel.toString() + " level, will be embedded in page."); + } + } + + return dataObj; + } } diff --git a/src/java/org/apache/fop/render/afp/modca/Document.java b/src/java/org/apache/fop/render/afp/modca/Document.java index efa022952..ae4a4b9fe 100644 --- a/src/java/org/apache/fop/render/afp/modca/Document.java +++ b/src/java/org/apache/fop/render/afp/modca/Document.java @@ -83,6 +83,7 @@ public final class Document extends AbstractResourceEnvironmentGroupContainer { /** * Returns an indication if the page group is complete + * * @return whether or not this page group is complete */ public boolean isComplete() { @@ -91,6 +92,7 @@ public final class Document extends AbstractResourceEnvironmentGroupContainer { /** * Accessor method to write the AFP datastream for document. + * * @param os The stream to write to * @throws java.io.IOException thrown if an I/O exception of some sort has occurred */ @@ -100,49 +102,21 @@ public final class Document extends AbstractResourceEnvironmentGroupContainer { } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA8; // Structured field id byte 2 - data[5] = (byte) 0xA8; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.BEGIN, Category.DOCUMENT); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA9; // Structured field id byte 2 - data[5] = (byte) 0xA8; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.END, Category.DOCUMENT); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public String toString() { return this.name; } diff --git a/src/java/org/apache/fop/render/afp/modca/GraphicsObject.java b/src/java/org/apache/fop/render/afp/modca/GraphicsObject.java index a73c9fc70..ccf05aa19 100644 --- a/src/java/org/apache/fop/render/afp/modca/GraphicsObject.java +++ b/src/java/org/apache/fop/render/afp/modca/GraphicsObject.java @@ -48,9 +48,7 @@ import org.apache.fop.render.afp.goca.GraphicsString; */ public class GraphicsObject extends AbstractDataObject { - /** - * The graphics data - */ + /** The graphics data */ private GraphicsData graphicsData = null; /** @@ -62,9 +60,7 @@ public class GraphicsObject extends AbstractDataObject { super(name); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void setViewport(ObjectAreaInfo objectAreaInfo) { super.setViewport(objectAreaInfo); getObjectEnvironmentGroup().setGraphicsData( @@ -76,62 +72,26 @@ public class GraphicsObject extends AbstractDataObject { objectAreaInfo.getY() + objectAreaInfo.getHeight()); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ + protected byte getCategoryCode() { + return (byte)0xBB; + } + + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { - super.writeStart(os); - byte[] data = new byte[] { - 0x5A, // Structured field identifier - 0x00, //sfLen[0], // Length byte 1 - 0x10, //sfLen[1], // Length byte 2 - (byte) 0xD3, // Structured field id byte 1 - (byte) 0xA8, // Structured field id byte 2 - (byte) 0xBB, // Structured field id byte 3 - 0x00, // Flags - 0x00, // Reserved - 0x00, // Reserved - super.nameBytes[0], // gdoName - super.nameBytes[1], - super.nameBytes[2], - super.nameBytes[3], - super.nameBytes[4], - super.nameBytes[5], - super.nameBytes[6], - super.nameBytes[7] - }; + byte[] data = new byte[17]; + copySF(data, Type.BEGIN, Category.GRAPHICS); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[] { - 0x5A, // Structured field identifier - 0x00, // sfLen[0], // Length byte 1 - 0x10, // sfLen[1], // Length byte 2 - (byte) 0xD3, // Structured field id byte 1 - (byte) 0xA9, // Structured field id byte 2 - (byte) 0xBB, // Structured field id byte 3 - 0x00, // Flags - 0x00, // Reserved - 0x00, // Reserved - super.nameBytes[0], // gdoName - super.nameBytes[1], - super.nameBytes[2], - super.nameBytes[3], - super.nameBytes[4], - super.nameBytes[5], - super.nameBytes[6], - super.nameBytes[7] - }; + byte[] data = new byte[17]; + copySF(data, Type.END, Category.GRAPHICS); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public PreparedAFPObject addObject(PreparedAFPObject drawingOrder) { if (graphicsData == null || (graphicsData.getDataLength() + drawingOrder.getDataLength()) @@ -144,6 +104,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Gets the current graphics data, creating a new one if necessary + * * @return the current graphics data */ private GraphicsData getData() { @@ -155,6 +116,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Creates a new graphics data + * * @return a newly created graphics data */ private GraphicsData newData() { @@ -165,6 +127,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Sets the current color + * * @param col the active color to use */ public void setColor(Color col) { @@ -173,6 +136,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Sets the current position + * * @param coords the x and y coordinates of the current position */ public void setCurrentPosition(int[] coords) { @@ -181,6 +145,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Sets the line width + * * @param multiplier the line width multiplier */ public void setLineWidth(int multiplier) { @@ -190,6 +155,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Sets the line type + * * @param type the line type */ public void setLineType(byte type) { @@ -199,6 +165,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Sets whether to fill the next shape + * * @param fill whether to fill the next shape */ public void setFill(boolean fill) { @@ -211,6 +178,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Sets the character set to use + * * @param fontReference the character set (font) reference */ public void setCharacterSet(int fontReference) { @@ -219,6 +187,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Adds a line at the given x/y coordinates + * * @param coords the x/y coordinates (can be a series) */ public void addLine(int[] coords) { @@ -227,6 +196,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Adds a box at the given coordinates + * * @param coords the x/y coordinates */ public void addBox(int[] coords) { @@ -235,6 +205,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Adds a fillet (curve) at the given coordinates + * * @param coords the x/y coordinates */ public void addFillet(int[] coords) { @@ -242,7 +213,8 @@ public class GraphicsObject extends AbstractDataObject { } /** - * Sets the arc parameters + * Sets the arc parameters + * * @param xmaj the maximum value of the x coordinate * @param ymin the minimum value of the y coordinate * @param xmin the minimum value of the x coordinate @@ -254,6 +226,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Adds an arc + * * @param x the x coordinate * @param y the y coordinate * @param mh the integer portion of the multiplier @@ -265,6 +238,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Adds an image + * * @param x the x coordinate * @param y the y coordinate * @param width the image width @@ -283,6 +257,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Adds a string + * * @param str the string * @param x the x coordinate * @param y the y coordinate @@ -310,9 +285,7 @@ public class GraphicsObject extends AbstractDataObject { } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public String toString() { return "GraphicsObject: " + getName(); } diff --git a/src/java/org/apache/fop/render/afp/modca/IMImageObject.java b/src/java/org/apache/fop/render/afp/modca/IMImageObject.java index 73abb2843..3af8b5c28 100644 --- a/src/java/org/apache/fop/render/afp/modca/IMImageObject.java +++ b/src/java/org/apache/fop/render/afp/modca/IMImageObject.java @@ -60,6 +60,7 @@ public class IMImageObject extends AbstractNamedAFPObject { /** * Constructor for the image object with the specified name, * the name must be a fixed length of eight characters. + * * @param name The name of the image. */ public IMImageObject(String name) { @@ -68,6 +69,7 @@ public class IMImageObject extends AbstractNamedAFPObject { /** * Sets the ImageOutputControl. + * * @param imageOutputControl The imageOutputControl to set */ public void setImageOutputControl(ImageOutputControl imageOutputControl) { @@ -76,6 +78,7 @@ public class IMImageObject extends AbstractNamedAFPObject { /** * Sets the ImageCellPosition. + * * @param imageCellPosition The imageCellPosition to set */ public void setImageCellPosition(ImageCellPosition imageCellPosition) { @@ -84,6 +87,7 @@ public class IMImageObject extends AbstractNamedAFPObject { /** * Sets the ImageInputDescriptor. + * * @param imageInputDescriptor The imageInputDescriptor to set */ public void setImageInputDescriptor(ImageInputDescriptor imageInputDescriptor) { @@ -92,15 +96,14 @@ public class IMImageObject extends AbstractNamedAFPObject { /** * Sets the ImageRastorData. + * * @param imageRasterData The imageRasterData to set */ public void setImageRasterData(ImageRasterData imageRasterData) { this.imageRasterData = imageRasterData; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { super.writeContent(os); if (imageOutputControl != null) { @@ -117,43 +120,17 @@ public class IMImageObject extends AbstractNamedAFPObject { } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA8; // Structured field id byte 2 - data[5] = (byte) 0x7B; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.BEGIN, Category.IM_IMAGE); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA9; // Structured field id byte 2 - data[5] = (byte) 0x7B; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.END, Category.IM_IMAGE); os.write(data); } } diff --git a/src/java/org/apache/fop/render/afp/modca/ImageCellPosition.java b/src/java/org/apache/fop/render/afp/modca/ImageCellPosition.java index c0eb77953..5f1f95932 100644 --- a/src/java/org/apache/fop/render/afp/modca/ImageCellPosition.java +++ b/src/java/org/apache/fop/render/afp/modca/ImageCellPosition.java @@ -69,26 +69,14 @@ public class ImageCellPosition extends AbstractAFPObject { yOffset = y; } - /** - * Accessor method to write the AFP datastream for the Image Cell Position - * @param os The stream to write to - * @throws java.io.IOException if an I/O exception occurred - */ + /** {@inheritDoc} */ public void write(OutputStream os) throws IOException { byte[] data = new byte[21]; - - data[0] = 0x5A; - - data[1] = 0x00; + copySF(data, Type.POSITION, Category.IM_IMAGE); + + data[1] = 0x00; // length data[2] = 0x14; - data[3] = (byte) 0xD3; - data[4] = (byte) 0xAC; - data[5] = (byte) 0x7B; - data[6] = 0x00; - data[7] = 0x00; - data[8] = 0x00; - /** * Specifies the offset along the Xp direction, in image points, * of this image cell from the IM image object area origin. diff --git a/src/java/org/apache/fop/render/afp/modca/ImageDataDescriptor.java b/src/java/org/apache/fop/render/afp/modca/ImageDataDescriptor.java index 45c029f71..243765727 100644 --- a/src/java/org/apache/fop/render/afp/modca/ImageDataDescriptor.java +++ b/src/java/org/apache/fop/render/afp/modca/ImageDataDescriptor.java @@ -27,35 +27,29 @@ import org.apache.fop.render.afp.tools.BinaryUtils; */ public class ImageDataDescriptor extends AbstractAFPObject { - private int _xresol = 0; - private int _yresol = 0; - private int _width = 0; - private int _height = 0; - + private int widthRes = 0; + private int heightRes = 0; + private int width = 0; + private int height = 0; + /** * Constructor for a ImageDataDescriptor for the specified * resolution, width and height. - * @param xresol The horizontal resolution of the image. - * @param yresol The vertical resolution of the image. + * + * @param widthRes The horizontal resolution of the image. + * @param heightRes The vertical resolution of the image. * @param width The width of the image. * @param height The height of the height. */ - public ImageDataDescriptor(int xresol, int yresol, int width, int height) { - - _xresol = xresol; - _yresol = yresol; - _width = width; - _height = height; - + public ImageDataDescriptor(int widthRes, int heightRes, int width, int height) { + this.widthRes = widthRes; + this.heightRes = heightRes; + this.width = width; + this.height = height; } - /** - * Accessor method to write the AFP datastream for the Image Data Descriptor - * @param os The stream to write to - * @throws java.io.IOException - */ - public void write(OutputStream os) - throws IOException { + /** {@inheritDoc} */ + public void write(OutputStream os) throws IOException { byte[] data = new byte[] { 0x5A, @@ -86,24 +80,22 @@ public class ImageDataDescriptor extends AbstractAFPObject { data[1] = l[0]; data[2] = l[1]; - byte[] x = BinaryUtils.convert(_xresol, 2); + byte[] x = BinaryUtils.convert(widthRes, 2); data[10] = x[0]; data[11] = x[1]; - byte[] y = BinaryUtils.convert(_yresol, 2); + byte[] y = BinaryUtils.convert(heightRes, 2); data[12] = y[0]; data[13] = y[1]; - byte[] w = BinaryUtils.convert(_width, 2); + byte[] w = BinaryUtils.convert(width, 2); data[14] = w[0]; data[15] = w[1]; - byte[] h = BinaryUtils.convert(_height, 2); + byte[] h = BinaryUtils.convert(height, 2); data[16] = h[0]; data[17] = h[1]; os.write(data); - } - } diff --git a/src/java/org/apache/fop/render/afp/modca/ImageInputDescriptor.java b/src/java/org/apache/fop/render/afp/modca/ImageInputDescriptor.java index a9aef38b9..370ec773d 100644 --- a/src/java/org/apache/fop/render/afp/modca/ImageInputDescriptor.java +++ b/src/java/org/apache/fop/render/afp/modca/ImageInputDescriptor.java @@ -36,11 +36,7 @@ public class ImageInputDescriptor extends AbstractAFPObject { private int resolution = 240; - /** - * Accessor method to write the AFP datastream for the Image Input Descriptor - * @param os The stream to write to - * @throws java.io.IOException if an I/O exception occurred - */ + /** {@inheritDoc} */ public void write(OutputStream os) throws IOException { byte[] data = new byte[45]; diff --git a/src/java/org/apache/fop/render/afp/modca/ImageObject.java b/src/java/org/apache/fop/render/afp/modca/ImageObject.java index 928a9790c..67935cb2c 100644 --- a/src/java/org/apache/fop/render/afp/modca/ImageObject.java +++ b/src/java/org/apache/fop/render/afp/modca/ImageObject.java @@ -38,6 +38,7 @@ public class ImageObject extends AbstractDataObject { /** * Constructor for the image object with the specified name, * the name must be a fixed length of eight characters. + * * @param name The name of the image. */ public ImageObject(String name) { @@ -46,6 +47,7 @@ public class ImageObject extends AbstractDataObject { /** * Set the dimensions of the image. + * * @param xresol the x resolution of the image * @param yresol the y resolution of the image * @param width the image width @@ -61,6 +63,7 @@ public class ImageObject extends AbstractDataObject { /** * Sets the image encoding. + * * @param encoding The image encoding. */ public void setImageEncoding(byte encoding) { @@ -72,6 +75,7 @@ public class ImageObject extends AbstractDataObject { /** * Sets the image compression. + * * @param compression The image compression. */ public void setImageCompression(byte compression) { @@ -83,6 +87,7 @@ public class ImageObject extends AbstractDataObject { /** * Sets the image IDE size. + * * @param size The IDE size. */ public void setImageIDESize(byte size) { @@ -94,6 +99,7 @@ public class ImageObject extends AbstractDataObject { /** * Sets the image IDE color model. + * * @param colorModel the IDE color model. */ public void setImageIDEColorModel(byte colorModel) { @@ -105,6 +111,7 @@ public class ImageObject extends AbstractDataObject { /** * Set the data of the image. + * * @param data The image data */ public void setImageData(byte[] data) { @@ -116,6 +123,7 @@ public class ImageObject extends AbstractDataObject { /** * Helper method to return the start of the image object. + * * @param len the length of this ipd start * @return byte[] The data stream. */ @@ -135,9 +143,14 @@ public class ImageObject extends AbstractDataObject { return data; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ + protected void writeStart(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.BEGIN, Category.IMAGE); + os.write(data); + } + + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { super.writeContent(os); if (imageSegment != null) { @@ -154,45 +167,10 @@ public class ImageObject extends AbstractDataObject { } } - /** - * {@inheritDoc} - */ - protected void writeStart(OutputStream os) throws IOException { - byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA8; // Structured field id byte 2 - data[5] = (byte) 0xFB; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } - os.write(data); - } - - /** - * Helper method to write the end of the Image Object. - * @param os The stream to write to - * @throws IOException in the event - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA9; // Structured field id byte 2 - data[5] = (byte) 0xFB; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.END, Category.IMAGE); os.write(data); } } diff --git a/src/java/org/apache/fop/render/afp/modca/ImageOutputControl.java b/src/java/org/apache/fop/render/afp/modca/ImageOutputControl.java index 0c38273de..4ba78f161 100644 --- a/src/java/org/apache/fop/render/afp/modca/ImageOutputControl.java +++ b/src/java/org/apache/fop/render/afp/modca/ImageOutputControl.java @@ -67,17 +67,11 @@ public class ImageOutputControl extends AbstractAFPObject { * The Y-axis offset. */ public ImageOutputControl(int x, int y) { - xCoord = x; yCoord = y; - } - /** - * Accessor method to write the AFP datastream for the Image Output Control - * @param os The stream to write to - * @throws java.io.IOException if an I/O exception occured - */ + /** {@inheritDoc} */ public void write(OutputStream os) throws IOException { byte[] data = new byte[33]; @@ -170,7 +164,6 @@ public class ImageOutputControl extends AbstractAFPObject { data[32] = (byte) 0xFF; os.write(data); - } /** diff --git a/src/java/org/apache/fop/render/afp/modca/ImageRasterData.java b/src/java/org/apache/fop/render/afp/modca/ImageRasterData.java index dd9c5f699..7bdadb6b6 100644 --- a/src/java/org/apache/fop/render/afp/modca/ImageRasterData.java +++ b/src/java/org/apache/fop/render/afp/modca/ImageRasterData.java @@ -58,11 +58,7 @@ public class ImageRasterData extends AbstractAFPObject { this.rasterData = data; } - /** - * Accessor method to write the AFP datastream for the Image Raster Data - * @param os The stream to write to - * @throws java.io.IOException if an I/O exception occurred - */ + /** {@inheritDoc} */ public void write(OutputStream os) throws IOException { byte[] data = new byte[9]; diff --git a/src/java/org/apache/fop/render/afp/modca/ImageSegment.java b/src/java/org/apache/fop/render/afp/modca/ImageSegment.java index 813dffed2..9a6c25ea0 100644 --- a/src/java/org/apache/fop/render/afp/modca/ImageSegment.java +++ b/src/java/org/apache/fop/render/afp/modca/ImageSegment.java @@ -18,6 +18,7 @@ /* $Id$ */ package org.apache.fop.render.afp.modca; + import java.io.IOException; import java.io.OutputStream; @@ -59,16 +60,14 @@ public class ImageSegment extends AbstractNamedAFPObject { super(name); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected int getNameLength() { return 4; } /** - * Sets the image size parameters - * resolution, hsize and vsize. + * Sets the image size parameters resolution, hsize and vsize. + * * @param hresol The horizontal resolution of the image. * @param vresol The vertical resolution of the image. * @param hsize The horizontal size of the image. @@ -83,6 +82,7 @@ public class ImageSegment extends AbstractNamedAFPObject { /** * Sets the image encoding. + * * @param encoding The image encoding. */ public void setImageEncoding(byte encoding) { @@ -94,6 +94,7 @@ public class ImageSegment extends AbstractNamedAFPObject { /** * Sets the image compression. + * * @param compression The image compression. */ public void setImageCompression(byte compression) { @@ -105,6 +106,7 @@ public class ImageSegment extends AbstractNamedAFPObject { /** * Sets the image IDE size. + * * @param size The IDE size. */ public void setImageIDESize(byte size) { @@ -116,6 +118,7 @@ public class ImageSegment extends AbstractNamedAFPObject { /** * Sets the image IDE color model. + * * @param colorModel the IDE color model. */ public void setImageIDEColorModel(byte colorModel) { @@ -127,6 +130,7 @@ public class ImageSegment extends AbstractNamedAFPObject { /** * Set the data of the image. + * * @param data the image data */ public void setImageData(byte[] data) { @@ -136,19 +140,16 @@ public class ImageSegment extends AbstractNamedAFPObject { imageContent.setImageData(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void writeContent(OutputStream os) throws IOException { if (imageContent != null) { imageContent.write(os); } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { + byte[] nameBytes = getNameBytes(); byte[] data = new byte[] { 0x70, // ID 0x04, // Length @@ -160,11 +161,8 @@ public class ImageSegment extends AbstractNamedAFPObject { os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[] { 0x71, // ID 0x00, // Length diff --git a/src/java/org/apache/fop/render/afp/modca/ImageSizeParameter.java b/src/java/org/apache/fop/render/afp/modca/ImageSizeParameter.java index f66b76853..0506b7bdc 100644 --- a/src/java/org/apache/fop/render/afp/modca/ImageSizeParameter.java +++ b/src/java/org/apache/fop/render/afp/modca/ImageSizeParameter.java @@ -48,11 +48,7 @@ public class ImageSizeParameter extends AbstractAFPObject { this.vSize = vsize; } - /** - * Accessor method to write the AFP datastream for the Image Size Parameter - * @param os The stream to write to - * @throws java.io.IOException if an I/O exception occured - */ + /** {@inheritDoc} */ public void write(OutputStream os) throws IOException { byte[] data = new byte[] { (byte)0x94, // ID = Image Size Parameter diff --git a/src/java/org/apache/fop/render/afp/modca/IncludeObject.java b/src/java/org/apache/fop/render/afp/modca/IncludeObject.java index 85cb283a8..807d66421 100644 --- a/src/java/org/apache/fop/render/afp/modca/IncludeObject.java +++ b/src/java/org/apache/fop/render/afp/modca/IncludeObject.java @@ -22,11 +22,6 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; import java.io.OutputStream; -import org.apache.fop.render.afp.DataObjectInfo; -import org.apache.fop.render.afp.ObjectAreaInfo; -import org.apache.fop.render.afp.modca.triplets.FullyQualifiedNameTriplet; -import org.apache.fop.render.afp.modca.triplets.MappingOptionTriplet; -import org.apache.fop.render.afp.modca.triplets.ObjectClassificationTriplet; import org.apache.fop.render.afp.tools.BinaryUtils; /** @@ -42,32 +37,32 @@ import org.apache.fop.render.afp.tools.BinaryUtils; * data objects in the page segment. * </p> */ -public class IncludeObject extends AbstractNamedAFPObject implements DataObjectAccessor { +public class IncludeObject extends AbstractNamedAFPObject { /** * the include object is of type page segment */ - protected static final byte TYPE_PAGE_SEGMENT = (byte)0x5F; + public static final byte TYPE_PAGE_SEGMENT = (byte)0x5F; /** * the include object is of type other */ - protected static final byte TYPE_OTHER = (byte)0x92; + public static final byte TYPE_OTHER = (byte)0x92; /** * the include object is of type graphic */ - protected static final byte TYPE_GRAPHIC = (byte)0xBB; + public static final byte TYPE_GRAPHIC = (byte)0xBB; /** * the included object is of type barcode */ - protected static final byte TYPE_BARCODE = (byte)0xEB; + public static final byte TYPE_BARCODE = (byte)0xEB; /** * the included object is of type image */ - protected static final byte TYPE_IMAGE = (byte)0xFB; + public static final byte TYPE_IMAGE = (byte)0xFB; /** * The object type (default is other) @@ -99,10 +94,10 @@ public class IncludeObject extends AbstractNamedAFPObject implements DataObjectA */ private int yContentOffset = 0; - /** - * the referenced data object - */ - private DataObjectAccessor dataObjectAccessor = null; +// /** +// * the referenced data object +// */ +// private DataObjectAccessor dataObjectAccessor = null; /** * Constructor for the include object with the specified name, the name must @@ -112,69 +107,69 @@ public class IncludeObject extends AbstractNamedAFPObject implements DataObjectA * @param name the name of this include object * @param dataObjectAccessor the data object accessor */ - public IncludeObject(String name, DataObjectAccessor dataObjectAccessor) { + public IncludeObject(String name/*, DataObjectAccessor dataObjectAccessor*/) { super(name); - this.dataObjectAccessor = dataObjectAccessor; - - AbstractNamedAFPObject dataObject = dataObjectAccessor.getDataObject(); - if (dataObject instanceof ImageObject) { - this.dataObjectType = TYPE_IMAGE; - } else if (dataObject instanceof GraphicsObject) { - this.dataObjectType = TYPE_GRAPHIC; - } else if (dataObject instanceof PageSegment) { - this.dataObjectType = TYPE_PAGE_SEGMENT; - } else { - this.dataObjectType = TYPE_OTHER; - // Strip any object container - if (dataObject instanceof ObjectContainer) { - ObjectContainer objectContainer = (ObjectContainer)dataObject; - dataObject = objectContainer.getDataObject(); - } - } - - DataObjectInfo dataObjectInfo = dataObjectAccessor.getDataObjectInfo(); - ObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo(); - setObjectArea(objectAreaInfo.getX(), objectAreaInfo.getY()); - - super.setFullyQualifiedName( - FullyQualifiedNameTriplet.TYPE_REPLACE_FIRST_GID_NAME, - FullyQualifiedNameTriplet.FORMAT_CHARSTR, - dataObjectInfo.getUri()); - - Registry registry = Registry.getInstance(); - Registry.ObjectType objectType = registry.getObjectType(dataObjectInfo); - super.setObjectClassification( - ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT, - objectType); +// this.dataObjectAccessor = dataObjectAccessor; - super.setMeasurementUnits(objectAreaInfo.getWidthRes(), objectAreaInfo.getHeightRes()); - - super.setMappingOption(MappingOptionTriplet.SCALE_TO_FIT); - - super.setObjectAreaSize(objectAreaInfo.getWidth(), objectAreaInfo.getHeight()); +// AbstractNamedAFPObject dataObject = dataObjectAccessor.getDataObject(); +// if (dataObject instanceof ImageObject) { +// this.dataObjectType = TYPE_IMAGE; +// } else if (dataObject instanceof GraphicsObject) { +// this.dataObjectType = TYPE_GRAPHIC; +// } else if (dataObject instanceof PageSegment) { +// this.dataObjectType = TYPE_PAGE_SEGMENT; +// } else { +// this.dataObjectType = TYPE_OTHER; +// // Strip any object container +// if (dataObject instanceof ObjectContainer) { +// ObjectContainer objectContainer = (ObjectContainer)dataObject; +// dataObject = objectContainer.getDataObject(); +// } +// } + +// DataObjectInfo dataObjectInfo = dataObjectAccessor.getDataObjectInfo(); +// ObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo(); +// setObjectArea(objectAreaInfo.getX(), objectAreaInfo.getY()); +// +// super.setFullyQualifiedName( +// FullyQualifiedNameTriplet.TYPE_REPLACE_FIRST_GID_NAME, +// FullyQualifiedNameTriplet.FORMAT_CHARSTR, +// dataObjectInfo.getUri()); +// +// Registry registry = Registry.getInstance(); +// Registry.ObjectType objectType = registry.getObjectType(dataObjectInfo); +// super.setObjectClassification( +// ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT, +// objectType); +// +// super.setMeasurementUnits(objectAreaInfo.getWidthRes(), objectAreaInfo.getHeightRes()); +// +// super.setMappingOption(MappingOptionTriplet.SCALE_TO_FIT); +// +// super.setObjectAreaSize(objectAreaInfo.getWidth(), objectAreaInfo.getHeight()); } - /** - * {@inheritDoc} - */ - public AbstractNamedAFPObject getDataObject() { - return dataObjectAccessor.getDataObject(); - } - - /** - * {@inheritDoc} - */ - public DataObjectInfo getDataObjectInfo() { - return dataObjectAccessor.getDataObjectInfo(); - } - - /** - * {@inheritDoc} - */ - public void setDataObjectInfo(DataObjectInfo dataObjectInfo) { - dataObjectAccessor.setDataObjectInfo(dataObjectInfo); - } +// /** +// * {@inheritDoc} +// */ +// public AbstractNamedAFPObject getDataObject() { +// return dataObjectAccessor.getDataObject(); +// } +// +// /** +// * {@inheritDoc} +// */ +// public DataObjectInfo getDataObjectInfo() { +// return dataObjectAccessor.getDataObjectInfo(); +// } +// +// /** +// * {@inheritDoc} +// */ +// public void setDataObjectInfo(DataObjectInfo dataObjectInfo) { +// dataObjectAccessor.setDataObjectInfo(dataObjectInfo); +// } /** * Sets the orientation to use for the Include Object. @@ -194,6 +189,7 @@ public class IncludeObject extends AbstractNamedAFPObject implements DataObjectA /** * Sets the x and y offset to the origin in the object area + * * @param x the X-axis origin of the object area * @param y the Y-axis origin of the object area */ @@ -203,7 +199,8 @@ public class IncludeObject extends AbstractNamedAFPObject implements DataObjectA } /** - * Sets the x and y offset of the content area to the object area + * Sets the x and y offset of the content area to the object area + * * @param x the X-axis origin defined in the object * @param y the Y-axis origin defined in the object */ @@ -213,30 +210,24 @@ public class IncludeObject extends AbstractNamedAFPObject implements DataObjectA } /** - * {@inheritDoc} + * Sets the data object type + * + * @param type the data object type */ + public void setDataObjectType(byte type) { + this.dataObjectType = type; + } + + /** {@inheritDoc} */ public void write(OutputStream os) throws IOException { byte[] data = new byte[36]; - data[0] = 0x5A; + super.copySF(data, Type.INCLUDE, Category.DATA_RESOURCE); // Set the total record length byte[] len = BinaryUtils.convert(35 + getTripletDataLength(), 2); //Ignore first byte data[1] = len[0]; data[2] = len[1]; - // Structured field ID for a IOB - data[3] = (byte) 0xD3; - data[4] = (byte) 0xAF; - data[5] = (byte) 0xC3; - - data[6] = 0x00; // Reserved - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } - data[17] = 0x00; // reserved data[18] = dataObjectType; @@ -330,9 +321,7 @@ public class IncludeObject extends AbstractNamedAFPObject implements DataObjectA os.write(tripletData); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public String toString() { return "IOB: " + this.getName(); } diff --git a/src/java/org/apache/fop/render/afp/modca/IncludePageOverlay.java b/src/java/org/apache/fop/render/afp/modca/IncludePageOverlay.java index 31021392e..540ebe7df 100644 --- a/src/java/org/apache/fop/render/afp/modca/IncludePageOverlay.java +++ b/src/java/org/apache/fop/render/afp/modca/IncludePageOverlay.java @@ -56,6 +56,7 @@ public class IncludePageOverlay extends AbstractNamedAFPObject { /** * Constructor for the Include Page Overlay + * * @param overlayName Name of the page segment * @param x The x position * @param y The y position @@ -63,6 +64,7 @@ public class IncludePageOverlay extends AbstractNamedAFPObject { */ public IncludePageOverlay(String overlayName, int x, int y, int orientation) { super(overlayName); + this.x = x; this.y = y; setOrientation(orientation); @@ -84,40 +86,25 @@ public class IncludePageOverlay extends AbstractNamedAFPObject { } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void write(OutputStream os) throws IOException { byte[] data = new byte[25]; //(9 +16) - data[0] = 0x5A; + copySF(data, Type.INCLUDE, Category.PAGE_OVERLAY); // Set the total record length byte[] len = BinaryUtils.convert(24, 2); //Ignore first byte data[1] = len[0]; data[2] = len[1]; - // Structured field ID for a IPO - data[3] = (byte) 0xD3; - data[4] = (byte) 0xAF; - data[5] = (byte) 0xD8; - - data[6] = 0x00; // Reserved - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } - - byte[] xcoord = BinaryUtils.convert(x, 3); - data[17] = xcoord[0]; // x coordinate - data[18] = xcoord[1]; - data[19] = xcoord[2]; + byte[] xPos = BinaryUtils.convert(x, 3); + data[17] = xPos[0]; // x coordinate + data[18] = xPos[1]; + data[19] = xPos[2]; - byte[] ycoord = BinaryUtils.convert(y, 3); - data[20] = ycoord[0]; // y coordinate - data[21] = ycoord[1]; - data[22] = ycoord[2]; + byte[] yPos = BinaryUtils.convert(y, 3); + data[20] = yPos[0]; // y coordinate + data[21] = yPos[1]; + data[22] = yPos[2]; switch (orientation) { case 90: diff --git a/src/java/org/apache/fop/render/afp/modca/IncludePageSegment.java b/src/java/org/apache/fop/render/afp/modca/IncludePageSegment.java index 4183b6717..b069f4f7a 100644 --- a/src/java/org/apache/fop/render/afp/modca/IncludePageSegment.java +++ b/src/java/org/apache/fop/render/afp/modca/IncludePageSegment.java @@ -45,56 +45,46 @@ public class IncludePageSegment extends AbstractNamedAFPObject { /** * The x position where we need to put this object on the page */ - private byte[] x; - + private int x; + /** * The y position where we need to put this object on the page */ - private byte[] y; - + private int y; + /** * Constructor for the Include Page Segment + * * @param name Name of the page segment * @param x The x position * @param y The y position */ public IncludePageSegment(String name, int x, int y) { super(name); - this.x = BinaryUtils.convert(x, 3); - this.y = BinaryUtils.convert(y, 3); + + this.x = x; + this.y = y; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void write(OutputStream os) throws IOException { - byte[] data = new byte[23]; //(9 +14) - - data[0] = 0x5A; + copySF(data, Type.INCLUDE, Category.PAGE_SEGMENT); // Set the total record length byte[] len = BinaryUtils.convert(22, 2); //Ignore first byte data[1] = len[0]; data[2] = len[1]; - // Structured field ID for a IPS - data[3] = (byte) 0xD3; - data[4] = (byte) 0xAF; - data[5] = (byte) 0x5F; - data[6] = 0x00; // Reserved - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved + byte[] xPos = BinaryUtils.convert(x, 3); + data[17] = xPos[0]; // x coordinate + data[18] = xPos[1]; + data[19] = xPos[2]; - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } - data[17] = x[0]; // x coordinate - data[18] = x[1]; - data[19] = x[2]; - data[20] = y[0]; // y coordinate - data[21] = y[1]; - data[22] = y[2]; + byte[] yPos = BinaryUtils.convert(y, 3); + data[20] = yPos[0]; // y coordinate + data[21] = yPos[1]; + data[22] = yPos[2]; os.write(data); } diff --git a/src/java/org/apache/fop/render/afp/modca/InterchangeSet.java b/src/java/org/apache/fop/render/afp/modca/InterchangeSet.java index 1ef72b3cf..4d52df3d3 100644 --- a/src/java/org/apache/fop/render/afp/modca/InterchangeSet.java +++ b/src/java/org/apache/fop/render/afp/modca/InterchangeSet.java @@ -46,6 +46,8 @@ public class InterchangeSet { private int value; /** + * Returns the interchange set value of a given string + * * @param str an interchange set value * @return an interchange set */ @@ -60,6 +62,7 @@ public class InterchangeSet { throw new IllegalArgumentException("Invalid MO:DCA interchange set :" + str); } } + /** * Main constructor * @@ -70,6 +73,8 @@ public class InterchangeSet { } /** + * Returns true if complies with MOD:CA interchange set 1 + * * @return true if complies with MOD:CA interchange set 1 */ protected boolean is1() { @@ -77,6 +82,8 @@ public class InterchangeSet { } /** + * Returns true if complies with MOD:CA interchange set 2 + * * @return true if complies with MOD:CA interchange set 2 */ public boolean is2() { @@ -84,20 +91,22 @@ public class InterchangeSet { } /** + * Returns true if complies with MOD:CA resource set + * * @return true if complies with MOD:CA resource set */ public boolean isResource() { return value == RESOURCE_SET; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public String toString() { return NAMES[value]; } /** + * Returns true if MOD:CA interchange set 2 (resource groups) is supported + * * @return true if MOD:CA interchange set 2 (resource groups) is supported */ public boolean supportsLevel2() { diff --git a/src/java/org/apache/fop/render/afp/modca/InvokeMediumMap.java b/src/java/org/apache/fop/render/afp/modca/InvokeMediumMap.java index f72ee4e23..fd41ce305 100644 --- a/src/java/org/apache/fop/render/afp/modca/InvokeMediumMap.java +++ b/src/java/org/apache/fop/render/afp/modca/InvokeMediumMap.java @@ -34,38 +34,24 @@ public class InvokeMediumMap extends AbstractNamedAFPObject { /** * Constructor for the Invoke Medium Map + * * @param name the name of the medium map */ public InvokeMediumMap(String name) { super(name); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void write(OutputStream os) throws IOException { byte[] data = new byte[17]; - - data[0] = 0x5A; + copySF(data, Type.MAP, Category.MEDIUM_MAP); // Set the total record length byte[] len = BinaryUtils.convert(16, 2); //Ignore first byte data[1] = len[0]; data[2] = len[1]; - // Structured field ID for a IPO - data[3] = (byte) 0xD3; - data[4] = (byte) 0xAB; - data[5] = (byte) 0xCC; - - data[6] = 0x00; // Reserved - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } os.write(data); } }
\ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/MapCodedFont.java b/src/java/org/apache/fop/render/afp/modca/MapCodedFont.java index 4518be9f1..13c76083f 100644 --- a/src/java/org/apache/fop/render/afp/modca/MapCodedFont.java +++ b/src/java/org/apache/fop/render/afp/modca/MapCodedFont.java @@ -56,9 +56,7 @@ public class MapCodedFont extends AbstractStructuredAFPObject { fontList = new java.util.ArrayList(); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void write(OutputStream os) throws IOException { byte[] startData = new byte[] { 0x5A, diff --git a/src/java/org/apache/fop/render/afp/modca/MapDataResource.java b/src/java/org/apache/fop/render/afp/modca/MapDataResource.java index 9b1abe06c..ae9df023f 100644 --- a/src/java/org/apache/fop/render/afp/modca/MapDataResource.java +++ b/src/java/org/apache/fop/render/afp/modca/MapDataResource.java @@ -34,6 +34,7 @@ import org.apache.fop.render.afp.tools.BinaryUtils; * required for presentation. */ public class MapDataResource extends AbstractStructuredAFPObject { + /** * Static default generated name reference */ @@ -41,6 +42,7 @@ public class MapDataResource extends AbstractStructuredAFPObject { /** * Main constructor + * * @param dataObjectAccessor a data object accessor */ public MapDataResource(DataObjectAccessor dataObjectAccessor) { @@ -49,7 +51,7 @@ public class MapDataResource extends AbstractStructuredAFPObject { ResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); ResourceLevel resourceLevel = resourceInfo.getLevel(); if (resourceLevel.isExternal()) { - String url = resourceLevel.getExternalResourceGroupFilePath(); + String url = resourceLevel.getExternalFilePath(); if (url != null) { super.setFullyQualifiedName( FullyQualifiedNameTriplet.TYPE_DATA_OBJECT_EXTERNAL_RESOURCE_REF, @@ -69,30 +71,20 @@ public class MapDataResource extends AbstractStructuredAFPObject { objectType); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void writeStart(OutputStream os) throws IOException { super.writeStart(os); + byte[] data = new byte[9]; + copySF(data, Type.MAP, Category.DATA_RESOURCE); byte[] len = BinaryUtils.convert(10 + getTripletDataLength(), 2); - byte[] data = new byte[] { - 0x5A, // Structured field identifier - len[0], // Length byte 1 - len[1], // Length byte 2 - (byte) 0xD3, // Structured field id byte 1 - (byte) 0xAB, // Structured field id byte 2 - (byte) 0xC3, // Structured field id byte 3 - 0x00, // Flags - 0x00, // Reserved - 0x00 // Reserved - }; + data[1] = len[0]; + data[2] = len[1]; + os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void writeContent(OutputStream os) throws IOException { // RGLength byte[] len = BinaryUtils.convert(2 + getTripletDataLength(), 2); diff --git a/src/java/org/apache/fop/render/afp/modca/ObjectAreaDescriptor.java b/src/java/org/apache/fop/render/afp/modca/ObjectAreaDescriptor.java index 95f7b0c45..dabe4ec20 100644 --- a/src/java/org/apache/fop/render/afp/modca/ObjectAreaDescriptor.java +++ b/src/java/org/apache/fop/render/afp/modca/ObjectAreaDescriptor.java @@ -33,6 +33,7 @@ public class ObjectAreaDescriptor extends AbstractDescriptor { /** * Construct an object area descriptor for the specified object width * and object height. + * * @param width The page width. * @param height The page height. * @param widthResolution The page width resolution. @@ -42,13 +43,8 @@ public class ObjectAreaDescriptor extends AbstractDescriptor { super(width, height, widthResolution, heightResolution); } - /** - * Accessor method to write the AFP datastream for the Object Area Descriptor - * @param os The stream to write to - * @throws java.io.IOException thrown if an I/O exception of some sort has occurred - */ - public void write(OutputStream os) - throws IOException { + /** {@inheritDoc} */ + public void write(OutputStream os) throws IOException { byte[] data = new byte[29]; data[0] = 0x5A; diff --git a/src/java/org/apache/fop/render/afp/modca/ObjectAreaPosition.java b/src/java/org/apache/fop/render/afp/modca/ObjectAreaPosition.java index 7ef00dede..d853be72a 100644 --- a/src/java/org/apache/fop/render/afp/modca/ObjectAreaPosition.java +++ b/src/java/org/apache/fop/render/afp/modca/ObjectAreaPosition.java @@ -33,9 +33,12 @@ public class ObjectAreaPosition extends AbstractAFPObject { private int x; private int y; private int rotation; - + private int xOffset; + private int yOffset; + /** * Construct an object area position for the specified object y, y position. + * * @param x The x coordinate. * @param y The y coordinate. * @param rotation The coordinate system rotation (must be 0, 90, 180, 270). @@ -46,50 +49,52 @@ public class ObjectAreaPosition extends AbstractAFPObject { this.rotation = rotation; } - /** - * Accessor method to write the AFP datastream for the Object Area Position - * @param os The stream to write to - * @throws java.io.IOException in the event that an I/O exception of some sort has occurred. - */ + /** {@inheritDoc} */ public void write(OutputStream os) throws IOException { + byte[] data = new byte[33]; + copySF(data, Type.POSITION, Category.OBJECT_AREA); + byte[] len = BinaryUtils.convert(32, 2); + data[1] = len[0]; // Length + data[2] = len[1]; + + data[9] = 0x01; // OAPosID = 1 + data[10] = 0x17; // RGLength = 23 + byte[] xcoord = BinaryUtils.convert(x, 3); + data[11] = xcoord[0]; // XoaOSet + data[12] = xcoord[1]; + data[13] = xcoord[2]; + byte[] ycoord = BinaryUtils.convert(y, 3); - byte[] data = new byte[] { - 0x5A, - len[0], // Length - len[1], // Length - (byte) 0xD3, - (byte) 0xAC, - (byte) 0x6B, - 0x00, // Flags - 0x00, // Reserved - 0x00, // Reserved - 0x01, // OAPosID = 1 - 0x17, // RGLength = 23 - xcoord[0], // XoaOSet - xcoord[1], - xcoord[2], - ycoord[0], // YoaOSet - ycoord[1], - ycoord[2], - (byte)(rotation / 2), // XoaOrent - 0x00, - (byte)(rotation / 2 + 45), // YoaOrent - 0x00, - 0x00, // Reserved - 0x00, // XocaOSet - 0x00, - 0x00, - 0x00, // YocaOSet - 0x00, - 0x00, - 0x00, // XocaOrent - 0x00, - 0x2D, // YocaOrent - 0x00, - 0x00, // RefCSys - }; + data[14] = ycoord[0]; // YoaOSet + data[15] = ycoord[1]; + data[16] = ycoord[2]; + + byte xorient = (byte)(rotation / 2); + data[17] = xorient; // XoaOrent + + byte yorient = (byte)(rotation / 2 + 45); + data[19] = yorient; // YoaOrent + + byte[] xoffset = BinaryUtils.convert(xOffset, 3); + data[22] = xoffset[0]; // XocaOSet + data[23] = xoffset[1]; + data[24] = xoffset[2]; + + byte[] yoffset = BinaryUtils.convert(yOffset, 3); + data[25] = yoffset[0]; // YocaOSet + data[26] = yoffset[1]; + data[27] = yoffset[2]; + + data[28] = 0x00; // XocaOrent + data[29] = 0x00; + + data[30] = 0x2D; // YocaOrent + data[31] = 0x00; + + data[32] = 0x01; // RefCSys + os.write(data); } }
\ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/ObjectContainer.java b/src/java/org/apache/fop/render/afp/modca/ObjectContainer.java index 599cb0b40..fc9edc4b7 100644 --- a/src/java/org/apache/fop/render/afp/modca/ObjectContainer.java +++ b/src/java/org/apache/fop/render/afp/modca/ObjectContainer.java @@ -31,24 +31,18 @@ import org.apache.fop.render.afp.tools.BinaryUtils; /** * Object containers are MO:DCA objects that envelop and carry object data. */ -public class ObjectContainer extends AbstractNamedAFPObject implements DataObjectAccessor { +public class ObjectContainer extends AbstractNamedAFPObject /*implements DataObjectAccessor*/ { private static final String DEFAULT_NAME = "OC000001"; - /** - * the data object - */ + /** the data object */ private AbstractDataObject dataObj = null; - /** - * the object data - */ + /** the object data */ private byte[] objectData = null; - /** - * the data object info - */ - private DataObjectInfo dataObjectInfo; +// /** the data object info */ +// private DataObjectInfo dataObjectInfo; /** * Default constructor @@ -59,6 +53,7 @@ public class ObjectContainer extends AbstractNamedAFPObject implements DataObjec /** * Main constructor + * * @param name the name of this object container */ public ObjectContainer(String name) { @@ -67,85 +62,61 @@ public class ObjectContainer extends AbstractNamedAFPObject implements DataObjec /** * Sets the data object for this object container + * * @param dataObj the data object to reside within this object container */ public void setDataObject(AbstractDataObject dataObj) { this.dataObj = dataObj; } - /** - * {@inheritDoc} - */ - public AbstractNamedAFPObject getDataObject() { - return this.dataObj; - } - - /** - * {@inheritDoc} - */ - public DataObjectInfo getDataObjectInfo() { - return this.dataObjectInfo; - } +// /** {@inheritDoc} */ +// public AbstractNamedAFPObject getDataObject() { +// return this.dataObj; +// } +// +// /** {@inheritDoc} */ +// public DataObjectInfo getDataObjectInfo() { +// return this.dataObjectInfo; +// } - /** - * {@inheritDoc} - */ - public void setDataObjectInfo(DataObjectInfo dataObjectInfo) { - this.dataObjectInfo = dataObjectInfo; - - Registry registry = Registry.getInstance(); - Registry.ObjectType objectType = registry.getObjectType(dataObjectInfo); - if (objectType != null) { - super.setObjectClassification( - ObjectClassificationTriplet.CLASS_TIME_VARIANT_PRESENTATION_OBJECT, - objectType); - } else { - log.warn("no object type for " + dataObjectInfo.getUri()); - } - super.setFullyQualifiedName( - FullyQualifiedNameTriplet.TYPE_REPLACE_FIRST_GID_NAME, - FullyQualifiedNameTriplet.FORMAT_CHARSTR, - dataObjectInfo.getUri()); - } +// /** {@inheritDoc} */ +// public void setDataObjectInfo(DataObjectInfo dataObjectInfo) { +// this.dataObjectInfo = dataObjectInfo; +// +// Registry registry = Registry.getInstance(); +// Registry.ObjectType objectType = registry.getObjectType(dataObjectInfo); +// if (objectType != null) { +// super.setObjectClassification( +// ObjectClassificationTriplet.CLASS_TIME_VARIANT_PRESENTATION_OBJECT, +// objectType); +// } else { +// log.warn("no object type for " + dataObjectInfo.getUri()); +// } +// super.setFullyQualifiedName( +// FullyQualifiedNameTriplet.TYPE_REPLACE_FIRST_GID_NAME, +// FullyQualifiedNameTriplet.FORMAT_CHARSTR, +// dataObjectInfo.getUri()); +// } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { - super.writeStart(os); - // create object data from data object ByteArrayOutputStream bos = new ByteArrayOutputStream(); dataObj.write(bos); this.objectData = bos.toByteArray(); + byte[] data = new byte[17]; + copySF(data, Type.BEGIN, Category.OBJECT_CONTAINER); + // Set the total record length byte[] len = BinaryUtils.convert(16 + getTripletDataLength(), 2); - byte[] data = new byte[] { - 0x5A, // Structured field identifier - len[0], // Length byte 1 - len[1], // Length byte 2 - (byte)0xD3, // Structured field id byte 1 - (byte)0xA8, // Structured field id byte 2 - (byte)0x92, // Structured field id byte 3 - 0x00, // Flags - 0x00, // Reserved - 0x00, // Reserved - nameBytes[0], - nameBytes[1], - nameBytes[2], - nameBytes[3], - nameBytes[4], - nameBytes[5], - nameBytes[6], - nameBytes[7] - }; + data[1] = len[0]; // Length byte 1 + data[2] = len[1]; // Length byte 2 + os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { super.writeContent(os); @@ -156,29 +127,10 @@ public class ObjectContainer extends AbstractNamedAFPObject implements DataObjec } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[] { - 0x5A, // Structured field identifier - 0x00, // Length byte 1 - 0x10, // Length byte 2 - (byte)0xD3, // Structured field id byte 1 - (byte)0xA9, // Structured field id byte 2 - (byte)0x92, // Structured field id byte 3 - 0x00, // Flags - 0x00, // Reserved - 0x00, // Reserved - nameBytes[0], - nameBytes[1], - nameBytes[2], - nameBytes[3], - nameBytes[4], - nameBytes[5], - nameBytes[6], - nameBytes[7], - }; + byte[] data = new byte[17]; + copySF(data, Type.END, Category.OBJECT_CONTAINER); os.write(data); } @@ -187,13 +139,12 @@ public class ObjectContainer extends AbstractNamedAFPObject implements DataObjec */ private class ObjectContainerData extends AbstractPreparedAFPObject { - /** - * The maximum object container data length - */ + /** The maximum object container data length */ private static final int MAX_DATA_LEN = 32759; /** * Main constructor + * * @param objData the object data */ public ObjectContainerData(byte[] objData, int startIndex) { @@ -208,7 +159,7 @@ public class ObjectContainer extends AbstractNamedAFPObject implements DataObjec data[2] = len[1]; // Length byte 2 data[3] = (byte)0xD3; // Structured field id byte 1 data[4] = (byte)0xEE; // Structured field id byte 2 - data[5] = (byte)0x92; // Structured field id byte 3 + data[5] = getCategoryCode(); // Structured field id byte 3 data[6] = 0x00; // Flags data[7] = 0x00; // Reserved data[8] = 0x00; // Reserved @@ -219,13 +170,21 @@ public class ObjectContainer extends AbstractNamedAFPObject implements DataObjec super.setData(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public String toString() { return "ObjectContainerData(" + (data != null ? "" + (data.length - 2) : "null") + ")"; } + + /** {@inheritDoc} */ + protected byte getCategoryCode() { + return (byte)0x92; + } + } + + /** {@inheritDoc} */ + protected byte getCategoryCode() { + return (byte)0x92; } } diff --git a/src/java/org/apache/fop/render/afp/modca/ObjectEnvironmentGroup.java b/src/java/org/apache/fop/render/afp/modca/ObjectEnvironmentGroup.java index 4b31da1f1..b2ef4fa20 100644 --- a/src/java/org/apache/fop/render/afp/modca/ObjectEnvironmentGroup.java +++ b/src/java/org/apache/fop/render/afp/modca/ObjectEnvironmentGroup.java @@ -73,6 +73,7 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { /** * Constructor for the ObjectEnvironmentGroup, this takes a * name parameter which must be 8 characters long. + * * @param name the object environment group name */ public ObjectEnvironmentGroup(String name) { @@ -81,6 +82,7 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { /** * Sets the object area parameters. + * * @param info the object area info */ public void setObjectArea(ObjectAreaInfo info) { @@ -93,6 +95,7 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { /** * Set the dimensions of the image. + * * @param xresol the x resolution of the image * @param yresol the y resolution of the image * @param width the image width @@ -104,6 +107,7 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { /** * Set the graphics data descriptor. + * * @param xresol the x resolution of the graphics window * @param yresol the y resolution of the graphics window * @param xlwind the left edge of the graphics window @@ -117,35 +121,14 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { xlwind, xrwind, ybwind, ytwind); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { - byte[] data = new byte[] { - 0x5A, // Structured field identifier - 0x00, // Length byte 1 - 0x10, // Length byte 2 - (byte) 0xD3, // Structured field id byte 1 - (byte) 0xA8, // Structured field id byte 2 - (byte) 0xC7, // Structured field id byte 3 - 0x00, // Flags - 0x00, // Reserved - 0x00, // Reserved - nameBytes[0], // Name - nameBytes[1], // - nameBytes[2], // - nameBytes[3], // - nameBytes[4], // - nameBytes[5], // - nameBytes[6], // - nameBytes[7] // - }; + byte[] data = new byte[17]; + copySF(data, Type.BEGIN, Category.OBJECT_ENVIRONMENT_GROUP); os.write(data); } - - /** - * {@inheritDoc} - */ + + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { super.writeContent(os); @@ -160,30 +143,11 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { graphicsDataDescriptor.write(os); } } - - /** - * {@inheritDoc} - */ + + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[] { - 0x5A, // Structured field identifier - 0x00, // Length byte 1 - 0x10, // Length byte 2 - (byte) 0xD3, // Structured field id byte 1 - (byte) 0xA9, // Structured field id byte 2 - (byte) 0xC7, // Structured field id byte 3 - 0x00, // Flags - 0x00, // Reserved - 0x00, // Reserved - nameBytes[0], // Name - nameBytes[1], // - nameBytes[2], // - nameBytes[3], // - nameBytes[4], // - nameBytes[5], // - nameBytes[6], // - nameBytes[7], // - }; + byte[] data = new byte[17]; + copySF(data, Type.END, Category.OBJECT_ENVIRONMENT_GROUP); os.write(data); } } diff --git a/src/java/org/apache/fop/render/afp/modca/Overlay.java b/src/java/org/apache/fop/render/afp/modca/Overlay.java index e7d3b87d0..74b42a281 100644 --- a/src/java/org/apache/fop/render/afp/modca/Overlay.java +++ b/src/java/org/apache/fop/render/afp/modca/Overlay.java @@ -53,43 +53,17 @@ public class Overlay extends AbstractPageObject { super(name, width, height, rotation, widthResolution, heightResolution); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA8; // Structured field id byte 2 - data[5] = (byte) 0xDF; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.BEGIN, Category.OVERLAY); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA9; // Structured field id byte 2 - data[5] = (byte) 0xDF; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.END, Category.OVERLAY); os.write(data); } } diff --git a/src/java/org/apache/fop/render/afp/modca/PageDescriptor.java b/src/java/org/apache/fop/render/afp/modca/PageDescriptor.java index e38c576d4..0ac029b99 100644 --- a/src/java/org/apache/fop/render/afp/modca/PageDescriptor.java +++ b/src/java/org/apache/fop/render/afp/modca/PageDescriptor.java @@ -33,6 +33,7 @@ public class PageDescriptor extends AbstractDescriptor { /** * Construct a page descriptor for the specified page width * and page height. + * * @param width The page width. * @param height The page height. * @param widthResolution The page width resolution @@ -42,13 +43,8 @@ public class PageDescriptor extends AbstractDescriptor { super(width, height, widthResolution, heightResolution); } - /** - * Accessor method to write the AFP datastream for the Page Descriptor - * @param os The stream to write to - * @throws java.io.IOException in the event that an I/O Exception occurred - */ - public void write(OutputStream os) - throws IOException { + /** {@inheritDoc} */ + public void write(OutputStream os) throws IOException { log.debug("width=" + width); log.debug("height=" + height); diff --git a/src/java/org/apache/fop/render/afp/modca/PageGroup.java b/src/java/org/apache/fop/render/afp/modca/PageGroup.java index 8131eb7b0..b1f3aabc1 100644 --- a/src/java/org/apache/fop/render/afp/modca/PageGroup.java +++ b/src/java/org/apache/fop/render/afp/modca/PageGroup.java @@ -91,57 +91,27 @@ public class PageGroup extends AbstractResourceEnvironmentGroupContainer { return complete; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { writeObjects(tagLogicalElements, os); super.writeContent(os); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA8; // Structured field id byte 2 - data[5] = (byte) 0xAD; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.BEGIN, Category.PAGE_GROUP); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA9; // Structured field id byte 2 - data[5] = (byte) 0xAD; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.END, Category.PAGE_GROUP); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public String toString() { return this.getName(); } diff --git a/src/java/org/apache/fop/render/afp/modca/PageObject.java b/src/java/org/apache/fop/render/afp/modca/PageObject.java index 1db9c4c41..c80f21deb 100644 --- a/src/java/org/apache/fop/render/afp/modca/PageObject.java +++ b/src/java/org/apache/fop/render/afp/modca/PageObject.java @@ -225,49 +225,21 @@ public class PageObject extends AbstractResourceGroupContainer { addObject(imImageObject); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA8; // Structured field id byte 2 - data[5] = (byte) 0xAF; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.BEGIN, Category.PAGE); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA9; // Structured field id byte 2 - data[5] = (byte) 0xAF; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.END, Category.PAGE); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public String toString() { return this.getName(); } diff --git a/src/java/org/apache/fop/render/afp/modca/PageSegment.java b/src/java/org/apache/fop/render/afp/modca/PageSegment.java index 92d3c4470..292deb1b1 100644 --- a/src/java/org/apache/fop/render/afp/modca/PageSegment.java +++ b/src/java/org/apache/fop/render/afp/modca/PageSegment.java @@ -35,6 +35,7 @@ public class PageSegment extends AbstractNamedAFPObject { /** * Main constructor + * * @param name the name of this object */ public PageSegment(String name) { @@ -42,6 +43,8 @@ public class PageSegment extends AbstractNamedAFPObject { } /** + * Returns a list of objects contained withing this page segment + * * @return a list of objects contained within this page segment */ public List/*<AbstractAFPObject>*/ getObjects() { @@ -53,63 +56,34 @@ public class PageSegment extends AbstractNamedAFPObject { /** * Adds a resource object (image/graphic) to this page segment + * * @param object the resource objec to add to this page segment */ public void addObject(AbstractAFPObject object) { getObjects().add(object); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA8; // Structured field id byte 2 - data[5] = (byte) 0x5F; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.BEGIN, Category.PAGE_SEGMENT); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { super.writeContent(os); writeObjects(objects, os); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA9; // Structured field id byte 2 - data[5] = (byte) 0x5F; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.END, Category.PAGE_SEGMENT); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public String toString() { return this.name; } diff --git a/src/java/org/apache/fop/render/afp/modca/PreprocessPresentationObject.java b/src/java/org/apache/fop/render/afp/modca/PreprocessPresentationObject.java index 688b9a28f..75442fb08 100644 --- a/src/java/org/apache/fop/render/afp/modca/PreprocessPresentationObject.java +++ b/src/java/org/apache/fop/render/afp/modca/PreprocessPresentationObject.java @@ -41,6 +41,7 @@ public class PreprocessPresentationObject extends AbstractStructuredAFPObject { /** * Main constructor + * * @param prePresObj the presentation object to be preprocessed */ public PreprocessPresentationObject(AbstractStructuredAFPObject prePresObj) { @@ -66,6 +67,7 @@ public class PreprocessPresentationObject extends AbstractStructuredAFPObject { /** * Sets the object orientations relative to media leading edge + * * @param orientation the object orientations relative to media leading edge */ public void setOrientation(byte orientation) { @@ -74,6 +76,7 @@ public class PreprocessPresentationObject extends AbstractStructuredAFPObject { /** * Sets the X axis origin for object content + * * @param xOffset the X axis origin for object content */ public void setXOffset(int xOffset) { @@ -82,15 +85,14 @@ public class PreprocessPresentationObject extends AbstractStructuredAFPObject { /** * Sets the Y axis origin for object content + * * @param yOffset the Y axis origin for object content */ public void setYOffset(int yOffset) { this.objYOffset = yOffset; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void writeStart(OutputStream os) throws IOException { super.writeStart(os); @@ -109,9 +111,7 @@ public class PreprocessPresentationObject extends AbstractStructuredAFPObject { os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void writeContent(OutputStream os) throws IOException { byte[] data = new byte[12]; byte[] l = BinaryUtils.convert(12 + getTripletDataLength(), 2); @@ -146,4 +146,9 @@ public class PreprocessPresentationObject extends AbstractStructuredAFPObject { // Triplets super.writeContent(os); } + + /** {@inheritDoc} */ + protected byte getCategoryCode() { + return (byte)0xC3; + } } diff --git a/src/java/org/apache/fop/render/afp/modca/PresentationTextDescriptor.java b/src/java/org/apache/fop/render/afp/modca/PresentationTextDescriptor.java index 10af1536e..706548d1a 100644 --- a/src/java/org/apache/fop/render/afp/modca/PresentationTextDescriptor.java +++ b/src/java/org/apache/fop/render/afp/modca/PresentationTextDescriptor.java @@ -50,6 +50,7 @@ public class PresentationTextDescriptor extends AbstractDescriptor { /** * Constructor a PresentationTextDescriptor for the specified * width and height. + * * @param width The width of the page. * @param height The height of the page. * @param widthResolution The width resolution of the page. @@ -60,13 +61,8 @@ public class PresentationTextDescriptor extends AbstractDescriptor { super(width, height, widthResolution, heightResolution); } - /** - * Accessor method to write the AFP datastream for the Presentation Text Descriptor - * @param os The stream to write to - * @throws java.io.IOException thrown if an I/O exception of some sort has occurred - */ - public void write(OutputStream os) - throws IOException { + /** {@inheritDoc} */ + public void write(OutputStream os) throws IOException { byte[] data = new byte[23]; data[0] = 0x5A; diff --git a/src/java/org/apache/fop/render/afp/modca/PresentationTextObject.java b/src/java/org/apache/fop/render/afp/modca/PresentationTextObject.java index 290a1e46a..88e29851f 100644 --- a/src/java/org/apache/fop/render/afp/modca/PresentationTextObject.java +++ b/src/java/org/apache/fop/render/afp/modca/PresentationTextObject.java @@ -171,6 +171,7 @@ public class PresentationTextObject extends AbstractNamedAFPObject { /** * Accessor method to write the AFP datastream for the PresentationTextObject. + * * @param os The stream to write to * @throws java.io.IOException thrown if an I/O exception of some sort has occurred */ @@ -182,49 +183,24 @@ public class PresentationTextObject extends AbstractNamedAFPObject { /** * Returns the name of this presentation text object + * * @return the name of this presentation text object */ public String getName() { return name; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA8; // Structured field id byte 2 - data[5] = (byte) 0x9B; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.BEGIN, Category.PRESENTATION_TEXT); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA9; // Structured field id byte 2 - data[5] = (byte) 0x9B; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.END, Category.PRESENTATION_TEXT); os.write(data); } @@ -247,9 +223,7 @@ public class PresentationTextObject extends AbstractNamedAFPObject { } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public String toString() { if (presentationTextDataList != null) { return presentationTextDataList.toString(); diff --git a/src/java/org/apache/fop/render/afp/modca/Registry.java b/src/java/org/apache/fop/render/afp/modca/Registry.java index fcff8060c..dc2941ca8 100644 --- a/src/java/org/apache/fop/render/afp/modca/Registry.java +++ b/src/java/org/apache/fop/render/afp/modca/Registry.java @@ -128,6 +128,32 @@ public final class Registry { MimeConstants.MIME_PCL ) ); + mimeEntryMap.put( + MimeConstants.MIME_SVG, + new ObjectType( + COMPID_EPS, + null, // no component id + "Scaleable Vector Graphics", + false, + MimeConstants.MIME_SVG + ) + ); + } + + /** + * Returns the Registry ObjectType for a given mimetype + * + * @param mimeType the object mime type + * @return the Registry ObjectType for a given data object info + */ + public Registry.ObjectType getObjectType(String mimeType) { + ObjectType entry = null; + if (mimeType != null) { + entry = (Registry.ObjectType)mimeEntryMap.get(mimeType); + } else { + log.info("mimetype '" + mimeType + "' not found"); + } + return entry; } /** @@ -141,15 +167,11 @@ public final class Registry { if (dataObjectInfo instanceof ImageObjectInfo) { ImageObjectInfo imageInfo = (ImageObjectInfo)dataObjectInfo; String mimeType = imageInfo.getMimeType(); - if (mimeType != null) { - entry = (Registry.ObjectType)mimeEntryMap.get(mimeType); - } else { - log.info("mimetype for " + dataObjectInfo + " is null"); - } + return getObjectType(mimeType); } return entry; } - + /** * Encapsulates a MOD:CA Registry Object Type entry */ @@ -215,6 +237,22 @@ public final class Registry { } /** + * @return true if this is an image type + */ + public boolean isImage() { + return mimeType == MimeConstants.MIME_TIFF + || mimeType == MimeConstants.MIME_GIF + || mimeType == MimeConstants.MIME_JPEG; + } + + /** + * @return true if this is a graphic type + */ + public boolean isGraphic() { + return mimeType == MimeConstants.MIME_SVG; + } + + /** * {@inheritDoc} */ public String toString() { diff --git a/src/java/org/apache/fop/render/afp/modca/ResourceEnvironmentGroup.java b/src/java/org/apache/fop/render/afp/modca/ResourceEnvironmentGroup.java index 219dfd8cb..1d66f560f 100644 --- a/src/java/org/apache/fop/render/afp/modca/ResourceEnvironmentGroup.java +++ b/src/java/org/apache/fop/render/afp/modca/ResourceEnvironmentGroup.java @@ -103,58 +103,32 @@ public class ResourceEnvironmentGroup extends AbstractEnvironmentGroup { /** * Returns an indication if the resource environment group is complete + * * @return whether or not this resource environment group is complete or not */ public boolean isComplete() { return complete; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA8; // Structured field id byte 2 - data[5] = (byte) 0xD9; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.BEGIN, Category.RESOURCE_ENVIROMENT_GROUP); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ + protected void writeEnd(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.END, Category.RESOURCE_ENVIROMENT_GROUP); + os.write(data); + } + + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { writeObjects(mapDataResources, os); writeObjects(mapPageOverlays, os); writeObjects(preProcessPresentationObjects, os); } - /** - * {@inheritDoc} - */ - protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA9; // Structured field id byte 2 - data[5] = (byte) 0xD9; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } - os.write(data); - } } diff --git a/src/java/org/apache/fop/render/afp/modca/ResourceGroup.java b/src/java/org/apache/fop/render/afp/modca/ResourceGroup.java index 1860d8ce7..baeefafd3 100644 --- a/src/java/org/apache/fop/render/afp/modca/ResourceGroup.java +++ b/src/java/org/apache/fop/render/afp/modca/ResourceGroup.java @@ -24,7 +24,9 @@ import java.io.OutputStream; import java.util.Collection; import java.util.Iterator; import java.util.Map; +import java.util.Set; +import org.apache.fop.render.afp.DataObjectCache; import org.apache.fop.render.afp.DataObjectInfo; import org.apache.fop.render.afp.ResourceInfo; import org.apache.fop.render.afp.ResourceLevel; @@ -35,15 +37,11 @@ import org.apache.fop.render.afp.tools.StringUtils; */ public final class ResourceGroup extends AbstractNamedAFPObject { - /** - * Default name for the resource group - */ + /** Default name for the resource group */ private static final String DEFAULT_NAME = "RG000001"; - /** - * Mapping of resource uri to data resource object (image/graphic) - */ - private Map/*<String,Writeable>*/ resourceMap = null; + /** Set of resource uri */ + private Set/*<String>*/ resourceSet = new java.util.HashSet/*<String>*/(); /** * Default constructor @@ -55,67 +53,62 @@ public final class ResourceGroup extends AbstractNamedAFPObject { /** * Constructor for the ResourceGroup, this takes a * name parameter which must be 8 characters long. + * * @param name the resource group name */ public ResourceGroup(String name) { super(name); } - - private static final String OBJECT_CONTAINER_NAME_PREFIX = "OC"; - - private ObjectContainer createObjectContainer() { - String name = OBJECT_CONTAINER_NAME_PREFIX - + StringUtils.lpad(String.valueOf(getResourceCount() + 1), '0', 6); - return new ObjectContainer(name); - } - - private DataObjectFactory dataObjectFactory = new DataObjectFactory(); - /** - * Creates a data object in this resource group - * @param dataObjectInfo the data object info - * @return an include object reference - */ - public IncludeObject createObject(DataObjectInfo dataObjectInfo) { - DataObjectAccessor dataObjectAccessor - = (DataObjectAccessor)getResourceMap().get(dataObjectInfo.getUri()); - ResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); - ResourceLevel resourceLevel = resourceInfo.getLevel(); - AbstractDataObject dataObj; - if (dataObjectAccessor == null) { - dataObj = dataObjectFactory.create(dataObjectInfo); - ObjectContainer objectContainer = null; - String resourceName = resourceInfo.getName(); - if (resourceName != null) { - objectContainer = new ObjectContainer(resourceName); - } else { - objectContainer = createObjectContainer(); - resourceName = objectContainer.getName(); - } - objectContainer.setDataObject(dataObj); - objectContainer.setDataObjectInfo(dataObjectInfo); - - // When located at print-file level or externally, - // wrap the object container in a resource object - if (resourceLevel.isPrintFile() || resourceLevel.isExternal()) { - ResourceObject resourceObject = new ResourceObject(resourceName); - resourceObject.setDataObject(objectContainer); - resourceObject.setDataObjectInfo(dataObjectInfo); - dataObjectAccessor = resourceObject; - } else { // Access data object through container - dataObjectAccessor = objectContainer; - } - - // Add to resource map - getResourceMap().put(dataObjectInfo.getUri(), dataObjectAccessor); - } - String name = dataObjectAccessor.getName(); - IncludeObject includeObj = new IncludeObject(name, dataObjectAccessor); - return includeObj; - } +// /** +// * Creates a data object in this resource group +// * +// * @param dataObjectInfo the data object info +// * @return an include object reference +// */ +// public IncludeObject createObject(DataObjectInfo dataObjectInfo) { +// String uri = dataObjectInfo.getUri(); +// resourceSet.get(); +// DataObjectAccessor dataObjectAccessor +// = (DataObjectAccessor)getResourceMap().getData(dataObjectInfo.getUri()); +// ResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); +// ResourceLevel resourceLevel = resourceInfo.getLevel(); +// AbstractDataObject dataObj; +// if (dataObjectAccessor == null) { +// dataObj = dataObjectFactory.createObject(dataObjectInfo); +// ObjectContainer objectContainer = null; +// String resourceName = resourceInfo.getName(); +// if (resourceName != null) { +// objectContainer = new ObjectContainer(resourceName); +// } else { +// objectContainer = createObjectContainer(); +// resourceName = objectContainer.getName(); +// } +// objectContainer.setDataObject(dataObj); +// objectContainer.setDataObjectInfo(dataObjectInfo); +// +// // When located at print-file level or externally, +// // wrap the object container in a resource object +// if (resourceLevel.isPrintFile() || resourceLevel.isExternal()) { +// ResourceObject resourceObject = new ResourceObject(resourceName); +// resourceObject.setDataObject(objectContainer); +// resourceObject.setDataObjectInfo(dataObjectInfo); +// dataObjectAccessor = resourceObject; +// } else { // Access data object through container +// dataObjectAccessor = objectContainer; +// } +// +// // Add to resource map +// getResourceMap().put(dataObjectInfo.getUri(), dataObjectAccessor); +// } +// String name = dataObjectAccessor.getName(); +// IncludeObject includeObj = dataObjectFactory.createInclude(dataObjectInfo); +// return includeObj; +// } /** * Checks if a named object is of a valid type to be added to a resource group + * * @param namedObj a named object * @return true if the named object is of a valid type to be added to a resource group */ @@ -131,26 +124,23 @@ public final class ResourceGroup extends AbstractNamedAFPObject { // || namedObj instanceof BarcodeObject ); } + /** - * Adds a named object to this resource group - * @param namedObj a named AFP object + * Add this object cache resource info to this resource group + * + * @param resourceInfo the resource info */ - protected void addObject(AbstractNamedAFPObject namedObj) { - if (isValidObjectType(namedObj)) { - getResourceMap().put(namedObj.getName(), namedObj); - } else { - throw new IllegalArgumentException("invalid object type " + namedObj); - } + public void addObject(ResourceInfo resourceInfo) { + resourceSet.add(resourceInfo); } /** + * Returns the number of resources contained in this resource group + * * @return the number of resources contained in this resource group */ public int getResourceCount() { - if (resourceMap != null) { - return resourceMap.size(); - } - return 0; + return resourceSet.size(); } /** @@ -161,78 +151,42 @@ public final class ResourceGroup extends AbstractNamedAFPObject { * @return true if the resource exists within this resource group */ public boolean resourceExists(String uri) { - return getResourceMap().containsKey(uri); + return resourceSet.contains(uri); } - /** - * Returns the list of resources - * @return the list of resources - */ - public Map/*<String, DataObjectAccessor>*/ getResourceMap() { - if (resourceMap == null) { - resourceMap = new java.util.HashMap/*<String, Writeable>*/(); - } - return resourceMap; - } - - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void writeContent(OutputStream os) throws IOException { - if (resourceMap != null) { - Collection includes = resourceMap.values(); - Iterator it = includes.iterator(); + Iterator it = resourceSet.iterator(); + if (it.hasNext()) { + DataObjectCache cache = DataObjectCache.getInstance(); while (it.hasNext()) { - Writable dataObject = (Writable)it.next(); - dataObject.write(os); + ResourceInfo resourceInfo = (ResourceInfo)it.next(); + byte[] data = cache.get(resourceInfo); + if (data != null) { + os.write(data); + } else { + log.error("data was null"); + } } } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA8; // Structured field id byte 2 - data[5] = (byte) 0xC6; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.BEGIN, Category.RESOURCE_GROUP); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA9; // Structured field id byte 2 - data[5] = (byte) 0xC6; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.END, Category.RESOURCE_GROUP); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public String toString() { - return this.name + " " + getResourceMap(); + return this.name + " " + resourceSet/*getResourceMap()*/; } } diff --git a/src/java/org/apache/fop/render/afp/modca/ResourceObject.java b/src/java/org/apache/fop/render/afp/modca/ResourceObject.java index e0ba1b4b7..6894bd426 100644 --- a/src/java/org/apache/fop/render/afp/modca/ResourceObject.java +++ b/src/java/org/apache/fop/render/afp/modca/ResourceObject.java @@ -22,9 +22,6 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; import java.io.OutputStream; -import org.apache.fop.render.afp.DataObjectInfo; -import org.apache.fop.render.afp.modca.triplets.FullyQualifiedNameTriplet; -import org.apache.fop.render.afp.modca.triplets.ObjectClassificationTriplet; import org.apache.fop.render.afp.modca.triplets.Triplet; import org.apache.fop.render.afp.tools.BinaryUtils; @@ -32,18 +29,10 @@ import org.apache.fop.render.afp.tools.BinaryUtils; * This resource structured field begins an envelope that is used to carry * resource objects in print-file-level (external) resource groups. */ -public class ResourceObject extends AbstractPreparedAFPObject implements DataObjectAccessor { +public class ResourceObject extends AbstractPreparedAFPObject { - /** - * the object container of this resource object - */ private AbstractNamedAFPObject namedObject; - - /** - * the data object info - */ - private DataObjectInfo dataObjectInfo; - + /** * Default constructor * @@ -55,102 +44,71 @@ public class ResourceObject extends AbstractPreparedAFPObject implements DataObj /** * Sets the data object referenced by this resource object + * * @param obj the named data object */ public void setDataObject(AbstractNamedAFPObject obj) { - this.namedObject = obj; - - String fqn = obj.getFullyQualifiedName(); - if (fqn != null) { - super.setFullyQualifiedName( - FullyQualifiedNameTriplet.TYPE_REPLACE_FIRST_GID_NAME, - FullyQualifiedNameTriplet.FORMAT_CHARSTR, - fqn); - } - - byte type; - if (obj instanceof ObjectContainer) { - type = ResourceObjectTypeTriplet.OBJECT_CONTAINER; - } else if (obj instanceof ImageObject) { - type = ResourceObjectTypeTriplet.IMAGE_OBJECT; - } else if (obj instanceof GraphicsObject) { - type = ResourceObjectTypeTriplet.GRAPHICS_OBJECT; - } else if (obj instanceof Document) { - type = ResourceObjectTypeTriplet.DOCUMENT_OBJECT; - } else if (obj instanceof PageSegment) { - type = ResourceObjectTypeTriplet.PAGE_SEGMENT_OBJECT; - } else if (obj instanceof Overlay) { - type = ResourceObjectTypeTriplet.OVERLAY_OBJECT; - } else { - throw new UnsupportedOperationException( - "Unsupported resource object type " + obj); - } - getTriplets().add(new ResourceObjectTypeTriplet(type)); + this.namedObject = obj; +// +// String fqn = obj.getFullyQualifiedName(); +// if (fqn != null) { +// super.setFullyQualifiedName( +// FullyQualifiedNameTriplet.TYPE_REPLACE_FIRST_GID_NAME, +// FullyQualifiedNameTriplet.FORMAT_CHARSTR, +// fqn); +// } +// +// byte type; +// if (obj instanceof ObjectContainer) { +// type = ResourceObjectTypeTriplet.OBJECT_CONTAINER; +// } else if (obj instanceof ImageObject) { +// type = ResourceObjectTypeTriplet.IMAGE_OBJECT; +// } else if (obj instanceof GraphicsObject) { +// type = ResourceObjectTypeTriplet.GRAPHICS_OBJECT; +// } else if (obj instanceof Document) { +// type = ResourceObjectTypeTriplet.DOCUMENT_OBJECT; +// } else if (obj instanceof PageSegment) { +// type = ResourceObjectTypeTriplet.PAGE_SEGMENT_OBJECT; +// } else if (obj instanceof Overlay) { +// type = ResourceObjectTypeTriplet.OVERLAY_OBJECT; +// } else { +// throw new UnsupportedOperationException( +// "Unsupported resource object type " + obj); +// } +// getTriplets().add(new ResourceObjectTypeTriplet(type)); } - /** - * {@inheritDoc} - */ - public AbstractNamedAFPObject getDataObject() { - return namedObject; - } - - /** - * {@inheritDoc} - */ - public DataObjectInfo getDataObjectInfo() { - return this.dataObjectInfo; - } - - /** - * {@inheritDoc} - */ - public void setDataObjectInfo(DataObjectInfo dataObjectInfo) { - this.dataObjectInfo = dataObjectInfo; +// /** {@inheritDoc} */ +// public void setDataObjectInfo(DataObjectInfo dataObjectInfo) { +// this.dataObjectInfo = dataObjectInfo; +// +// if (namedObject instanceof ObjectContainer) { +// Registry.ObjectType objectType = dataObjectInfo.getObjectType(); +// super.setObjectClassification( +// ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT, +// objectType); +// } +// } - if (namedObject instanceof ObjectContainer) { - Registry.ObjectType objectType = dataObjectInfo.getObjectType(); - super.setObjectClassification( - ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT, - objectType); - } - } - - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { super.writeStart(os); - + + byte[] data = new byte[19]; + copySF(data, Type.BEGIN, Category.NAME_RESOURCE); + // Set the total record length byte[] len = BinaryUtils.convert(18 + getTripletDataLength(), 2); - byte[] data = new byte[] { - 0x5A, // Structured field identifier - len[0], // Length byte 1 - len[1], // Length byte 2 - (byte)0xD3, // Structured field id byte 1 - (byte)0xA8, // Structured field id byte 2 - (byte)0xCE, // Structured field id byte 3 - 0x00, // Flags - 0x00, // Reserved - 0x00, // Reserved - nameBytes[0], - nameBytes[1], - nameBytes[2], - nameBytes[3], - nameBytes[4], - nameBytes[5], - nameBytes[6], - nameBytes[7], - 0x00, // Reserved - 0x00, // Reserved - }; + data[1] = len[0]; // Length byte 1 + data[2] = len[1]; // Length byte 2 + + // Set reserved bits + data[17] = 0x00; // Reserved + data[18] = 0x00; // Reserved os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { super.writeContent(os); // write triplets if (namedObject != null) { @@ -158,60 +116,48 @@ public class ResourceObject extends AbstractPreparedAFPObject implements DataObj } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[] { - 0x5A, // Structured field identifier - 0x00, // Length byte 1 - 0x10, // Length byte 2 - (byte)0xD3, // Structured field id byte 1 - (byte)0xA9, // Structured field id byte 2 - (byte)0xCE, // Structured field id byte 3 - 0x00, // Flags - 0x00, // Reserved - 0x00, // Reserved - nameBytes[0], - nameBytes[1], - nameBytes[2], - nameBytes[3], - nameBytes[4], - nameBytes[5], - nameBytes[6], - nameBytes[7], - }; + byte[] data = new byte[17]; + copySF(data, Type.END, Category.NAME_RESOURCE); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public String toString() { return this.getName(); } + /** + * Sets Resource Object Type triplet + * + * @param type the resource object type + */ + public void setType(byte type) { + getTriplets().add(new ResourceObjectTypeTriplet(type)); + } + + /** + * Resource object types + */ + protected static final byte GRAPHICS_OBJECT = 0x03; +// private static final byte BARCODE_OBJECT = 0x05; + protected static final byte IMAGE_OBJECT = 0x06; +// private static final byte FONT_CHARACTER_SET_OBJECT = 0x40; +// private static final byte CODE_PAGE_OBJECT = 0x41; +// private static final byte CODED_FONT_OBJECT = 0x42; + protected static final byte OBJECT_CONTAINER = (byte) 0x92; + protected static final byte DOCUMENT_OBJECT = (byte) 0xA8; + protected static final byte PAGE_SEGMENT_OBJECT = (byte) 0xFB; + protected static final byte OVERLAY_OBJECT = (byte) 0xFC; +// private static final byte PAGEDEF_OBJECT = (byte) 0xFD; +// private static final byte FORMDEF_OBJECT = (byte) 0xFE; + private class ResourceObjectTypeTriplet extends Triplet { private static final byte RESOURCE_OBJECT = 0x21; /** - * Resource object types - */ - private static final byte GRAPHICS_OBJECT = 0x03; -// private static final byte BARCODE_OBJECT = 0x05; - private static final byte IMAGE_OBJECT = 0x06; -// private static final byte FONT_CHARACTER_SET_OBJECT = 0x40; -// private static final byte CODE_PAGE_OBJECT = 0x41; -// private static final byte CODED_FONT_OBJECT = 0x42; - private static final byte OBJECT_CONTAINER = (byte) 0x92; - private static final byte DOCUMENT_OBJECT = (byte) 0xA8; - private static final byte PAGE_SEGMENT_OBJECT = (byte) 0xFB; - private static final byte OVERLAY_OBJECT = (byte) 0xFC; -// private static final byte PAGEDEF_OBJECT = (byte) 0xFD; -// private static final byte FORMDEF_OBJECT = (byte) 0xFE; - - /** * Main constructor * * @param type diff --git a/src/java/org/apache/fop/render/afp/modca/Writable.java b/src/java/org/apache/fop/render/afp/modca/Writable.java index beaa6e21c..aa9de2d43 100644 --- a/src/java/org/apache/fop/render/afp/modca/Writable.java +++ b/src/java/org/apache/fop/render/afp/modca/Writable.java @@ -26,9 +26,11 @@ import java.io.OutputStream; * Implementing object is able to write to an AFPDataStream */ public interface Writable { + /** * DataStream objects must implement the write() * method to write its data to the given OutputStream + * * @param outputStream The outputsteam stream * @throws java.io.IOException an I/O exception of some sort has occurred. */ diff --git a/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java b/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java index 51e13dde1..826f610c8 100644 --- a/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java +++ b/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java @@ -42,6 +42,7 @@ public class PDFRendererConfigurator extends PrintRendererConfigurator { /** * Default constructor + * * @param userAgent user agent */ public PDFRendererConfigurator(FOUserAgent userAgent) { @@ -52,6 +53,7 @@ public class PDFRendererConfigurator extends PrintRendererConfigurator { * Configure the PDF renderer. * Get the configuration to be used for pdf stream filters, * fonts etc. + * * @param renderer pdf renderer * @throws FOPException fop exception */ @@ -79,7 +81,8 @@ public class PDFRendererConfigurator extends PrintRendererConfigurator { if (s != null) { pdfRenderer.setXMode(PDFXMode.valueOf(s)); } - Configuration encryptionParamsConfig = cfg.getChild(PDFRenderer.ENCRYPTION_PARAMS, false); + Configuration encryptionParamsConfig + = cfg.getChild(PDFRenderer.ENCRYPTION_PARAMS, false); if (encryptionParamsConfig != null) { PDFEncryptionParams encryptionParams = new PDFEncryptionParams(); Configuration ownerPasswordConfig = encryptionParamsConfig.getChild( @@ -124,15 +127,18 @@ public class PDFRendererConfigurator extends PrintRendererConfigurator { if (s != null) { pdfRenderer.setOutputProfileURI(s); } - Configuration disableColorSpaceConfig = cfg.getChild(PDFRenderer.KEY_DISABLE_SRGB_COLORSPACE, false); + Configuration disableColorSpaceConfig = cfg.getChild( + PDFRenderer.KEY_DISABLE_SRGB_COLORSPACE, false); if (disableColorSpaceConfig != null) { - pdfRenderer.disableSRGBColorSpace = disableColorSpaceConfig.getValueAsBoolean(false); + pdfRenderer.disableSRGBColorSpace + = disableColorSpaceConfig.getValueAsBoolean(false); } } } /** * Builds a filter map from an Avalon Configuration object. + * * @param cfg the Configuration object * @return Map the newly built filter map * @throws ConfigurationException if a filter list is defined twice diff --git a/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java b/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java index cb7c7cf89..73b50e323 100644 --- a/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java +++ b/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java @@ -91,6 +91,7 @@ public class PDFSVGHandler extends AbstractGenericSVGHandler pdfi.currentYPosition = ((Integer)context.getProperty(YPOS)).intValue(); pdfi.cfg = (Configuration)context.getProperty(HANDLER_CONFIGURATION); Map foreign = (Map)context.getProperty(RendererContextConstants.FOREIGN_ATTRIBUTES); + QName qName = new QName(ExtensionElementMapping.URI, null, "conversion-mode"); if (foreign != null && "bitmap".equalsIgnoreCase((String)foreign.get(qName))) { |