<images mode="b+w" bits-per-pixel="8"/>
<renderer-resolution>240</renderer-resolution>
<resource-group-file>resources.afp</resource-group-file>
- <goca-enabled/>
<fonts>
<!--
/**
* 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
//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;
}
/**
* Gets the document URI from a Document instance if possible.
+ *
* @param doc the Document
* @return the URI or null
*/
/**
* 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) {
// 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],
}
}
- /**
- * {@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);
ioe.printStackTrace();
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void drawString(String s, float x, float y) {
try {
if (customTextHandler != null && !textAsShapes) {
}
}
- /**
- * {@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);
}
}
/**
+ * Returns the GOCA graphics object
+ *
* @return the GOCA graphics object
*/
protected GraphicsObject getGraphicsObject() {
}
/**
- * 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
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.
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)
}
}
/** 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() {
/**
* Sets the width.
+ *
* @param width The pageWidth to set
*/
public void setWidth(int width) {
/**
* Returns the height.
+ *
* @return the height
*/
public int getHeight() {
/**
* Sets the height.
+ *
* @param height The height to set
*/
public void setHeight(int height) {
}
/**
- * @return Configuration the handler configuration
+ * Returns the handler configuration
+ *
+ * @return the handler configuration
*/
public Configuration getHandlerConfiguration() {
return this.cfg;
/**
* Sets the handler configuration
+ *
* @param cfg the handler configuration
*/
public void setHandlerConfiguration(Configuration cfg) {
}
/**
- * @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() {
}
/**
+ * Returns the current x position coordinate
+ *
* @return the current x position coordinate
*/
protected int getX() {
}
/**
+ * Returns the current y position coordinate
+ *
* @return the current y position coordinate
*/
protected int getY() {
}
/**
+ * Returns the resolution
+ *
* @return the resolution
*/
protected int getResolution() {
}
/**
+ * Returns the number of bits per pixel to use
* @return the number of bits per pixel to use
*/
protected int getBitsPerPixel() {
/**
* Sets the current x position coordinate
+ *
* @param x the current x position coordinate
*/
protected void setX(int x) {
/**
* Sets the current y position coordinate
+ *
* @param y the current y position coordinate
*/
protected void setY(int y) {
/**
* Sets the current font info
+ *
* @param fontInfo the current font info
*/
protected void setFontInfo(FontInfo fontInfo) {
/**
* Sets the AFP state
+ *
* @param state the AFP state
*/
public void setState(AFPState state) {
/**
* Sets the AFP datastream
+ *
* @param dataStream the AFP datastream
*/
public void setAFPDataStream(AFPDataStream dataStream) {
this.afpDataStream = dataStream;
}
+
/** {@inheritDoc} */
public String toString() {
return "width=" + width
*/
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;
/** drawing state */
private AFPState currentState = new AFPState();
- private boolean gocaEnabled = false;
-
/**
* Constructor for AFPRenderer.
*/
renderPageObjectExtensions(page);
- getPages().put(page, getAFPDataStream().savePage());
+ PageObject currentPage = getAFPDataStream().savePage();
+ getPages().put(page, currentPage);
}
private Map/*<PageViewport, PageObject>*/ getPages() {
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>*/();
* the page object
*/
private void renderPageObjectExtensions(PageViewport pageViewport) {
-
this.pageSegmentsMap = null;
if (pageViewport.getExtensionAttachments() != null
&& pageViewport.getExtensionAttachments().size() > 0) {
}
/**
+ * Returns the current AFP state
+ *
* @return the current AFP state
*/
protected AbstractState getState() {
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) {
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;
/**
/**
* Default constructor
+ *
* @param userAgent user agent
*/
public AFPRendererConfigurator(FOUserAgent userAgent) {
/**
* 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
/**
* Configure the AFP renderer.
+ *
* @param renderer AFP renderer
* @throws FOPException fop exception
* @see org.apache.fop.render.PrintRendererConfigurator#configure(Renderer)
// 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);
}
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 + "'");
// 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;
/**
/** {@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);
}
}
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;
}
*
* @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);
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} */
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.
}
/**
+ * Returns the rotation to be used for portrait pages
+ *
* @return the rotation to be used for portrait pages
*/
protected int getPortraitRotation() {
}
/**
+ * Returns the landscape rotation
+ *
* @return the landscape rotation
*/
protected int getLandscapeRotation() {
}
/**
+ * Returns the number of bits per pixel
+ *
* @return the number of bits per pixel
*/
public int getBitsPerPixel() {
}
/**
+ * Returns true if color images are to be used
+ *
* @return true if color images are to be used
*/
protected boolean isColorImages() {
}
/**
+ * Returns the state of the current page
+ *
* @return the state of the current page
*/
protected AFPPageState getPageState() {
return this.pageState;
}
+ /**
+ * 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
*/
/**
* Gets the current page fonts
+ *
* @return the current page fonts
*/
protected AFPPageFonts getPageFonts() {
/**
* Increments and returns the page font count
+ *
* @return the page font count
*/
public int incrementPageFontCount() {
/**
* Sets the page width
+ *
* @param pageWidth the page width
*/
public void setPageWidth(int pageWidth) {
}
/**
+ * Returns the page width
+ *
* @return the page width
*/
public int getPageWidth() {
/**
* Sets the page height
+ *
* @param pageHeight the page height
*/
public void setPageHeight(int pageHeight) {
}
/**
+ * Returns the page height
+ *
* @return the page height
*/
public int getPageHeight() {
/**
* Sets the uri of the current image
+ *
* @param uri the uri of the current image
*/
protected void setImageUri(String uri) {
/**
* Gets the uri of the current image
+ *
* @return the uri of the current image
*/
public String getImageUri() {
private int fontCount = 0;
/**
+ * Returns the page width
+ *
* @return the page width
*/
protected int getWidth() {
/**
* Sets the page width
+ *
* @param width the page width
*/
protected void setWidth(int width) {
}
/**
+ * Returns the page height
+ *
* @return the page height
*/
protected int getHeight() {
/**
* Sets the page height
+ *
* @param height the page height
*/
protected void setHeight(int height) {
}
/**
+ * Returns the page fonts
+ *
* @return the page fonts
*/
protected AFPPageFonts getFonts() {
/**
* Sets the current page fonts
+ *
* @param fonts the current page fonts
*/
protected void setFonts(AFPPageFonts fonts) {
}
/**
+ * Increments and returns the current page font count
+ *
* @return increment and return the current page font count
*/
protected int incrementFontCount() {
--- /dev/null
+/*
+ * 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;
+ }
+}
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
public 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) {
}
/**
+ * Returns the object type MOD:CA Registry entry
+ *
* @return the object type MOD:CA Registry entry
*/
public ObjectType getObjectType() {
}
/**
+ * 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) {
/**
* Sets the object area info
+ *
* @param objectAreaInfo the object area info
*/
public void setObjectAreaInfo(ObjectAreaInfo objectAreaInfo) {
}
/**
+ * Returns the object area info
+ *
* @return the object area info
*/
public ObjectAreaInfo getObjectAreaInfo() {
/**
* 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) {
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);
}
}
- /**
- * {@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);
+ }
}
--- /dev/null
+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
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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
/**
* Sets the number of bits per pixel
+ *
* @param bitsPerPixel the number of bits per pixel
*/
public void setBitsPerPixel(int bitsPerPixel) {
/**
* Sets if this image is color
+ *
* @param color true if this is a color image
*/
public void setColor(boolean color) {
/**
* Sets the image data
+ *
* @param data the image data
*/
public void setData(byte[] data) {
/**
* Sets the image mime type
+ *
* @param mimeType the image mime type
*/
public void setMimeType(String mimeType) {
}
/**
+ * Returns the number of bits used per pixel
+ *
* @return the number of bits used per pixel
*/
public int getBitsPerPixel() {
}
/**
+ * Returns true if this is a color image
+ *
* @return true if this is a color image
*/
public boolean isColor() {
}
/**
+ * Returns the image data
+ *
* @return the image data
*/
public byte[] getData() {
}
/**
- * @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() {
}
/**
- * 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) {
}
/**
+ * Returns the image data width
+ *
* @return the image data width
*/
public int getDataWidth() {
/**
* Sets the image data width
+ *
* @param imageDataWidth the image data width
*/
public void setDataWidth(int imageDataWidth) {
}
/**
+ * Returns the image data height
+ *
* @return the image data height
*/
public int getDataHeight() {
/**
* Sets the image data height
+ *
* @param imageDataHeight the image data height
*/
public void setDataHeight(int imageDataHeight) {
}
/**
+ * Returns the mime type of this image
+ *
* @return the mime type of this image
*/
public String getMimeType() {
/**
* 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) {
}
/**
+ * 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
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;
/**
* Sets the x position of the data object
+ *
* @param x the x position of the data object
*/
public void setX(int x) {
/**
* Sets the y position of the data object
+ *
* @param y the y position of the data object
*/
public void setY(int y) {
/**
* Sets the data object width
+ *
* @param width the width of the data object
*/
public void setWidth(int width) {
/**
* Sets the data object height
+ *
* @param height the height of the data object
*/
public void setHeight(int height) {
/**
* Sets the width resolution
+ *
* @param widthRes the width resolution
*/
public void setWidthRes(int widthRes) {
/**
* Sets the height resolution
+ *
* @param heightRes the height resolution
*/
public void setHeightRes(int heightRes) {
}
/**
+ * Returns the x coordinate of this data object
+ *
* @return the x coordinate of this data object
*/
public int getX() {
}
/**
+ * Returns the y coordinate of this data object
+ *
* @return the y coordinate of this data object
*/
public int getY() {
}
/**
+ * Returns the width of this data object
+ *
* @return the width of this data object
*/
public int getWidth() {
}
/**
+ * Returns the height of this data object
+ *
* @return the height of this data object
*/
public int getHeight() {
}
/**
+ * Returns the width resolution of this data object
+ *
* @return the width resolution of this data object
*/
public int getWidthRes() {
}
/**
+ * Returns the height resolution of this data object
+ *
* @return the height resolution of this data object
*/
public int getHeightRes() {
}
/**
+ * Returns the rotation of this data object
+ *
* @return the rotation of this data object
*/
public int getRotation() {
/**
* 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
* 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) {
}
/**
+ * Returns the resource reference name
+ *
* @return the resource reference name
*/
public String getName() {
}
/**
- * {@inheritDoc}
- */
- public String toString() {
- return "ResourceInfo(" + (name != null ? "name=" + name
- + ", " : "") + "level=" + level + ")";
- }
-
- /**
+ * Returns the resource level
+ *
* @return the resource level
*/
public ResourceLevel getLevel() {
/**
* 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
package org.apache.fop.render.afp;
-import java.io.File;
-
/**
* A resource level
*/
public class ResourceLevel {
+
/** page level **/
public static final int PAGE = 0;
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
*/
/**
* 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() {
}
/**
+ * 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() {
}
/**
+ * Returns true if this is a document level resource group
+ *
* @return true if this is a document level resource group
*/
public boolean isDocument() {
}
/**
+ * Returns true if this is an external level resource group
+ *
* @return true if this is an external level resource group
*/
public boolean isExternal() {
}
/**
+ * 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() {
}
/**
- * @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
*/
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 */
this.previous = previous;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public int getDataLength() {
int dataLen = 14 + super.getDataLength();
if (previous == null) {
return dataLen;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
protected int getNameLength() {
return 4;
}
// 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
};
// 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) {
}
}
- /**
- * 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);
return drawingOrder;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public String toString() {
return "GraphicsChainedSegment(name=" + super.getName() + ")";
}
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;
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;
*/
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
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.";
if (interchangeSet.supportsLevel2()) {
// Write out any external resource groups
- getExternalResourceGroupManager().writeExternalResources();
+ getExternalResourceGroupManager().write();
// Write out any print-file level resources
if (hasResources()) {
this.document = null;
this.outputStream = null;
+
+ DataObjectCache.getInstance().clear();
}
/**
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);
}
/**
*
* @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 = "/";
// 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
}
}
}
- // 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);
}
// /**
getCurrentPage().createNoOperation(content);
}
+ /**
+ * Returns the current page group
+ *
+ * @return the current page group
+ */
private PageGroup getCurrentPageGroup() {
if (currentPageGroup == null) {
String pageGroupName = "PGP"
* 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
* 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
}
}
- /**
- * 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) {
}
/**
+ * Returns the MO:DCA interchange set in use
+ *
* @return the MO:DCA interchange set in use
*/
public InterchangeSet getInterchangeSet() {
*/
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.
}
}
}
+
+ /** 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;
+ }
+
}
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) {
/**
* Gets the ObjectEnvironmentGroup
+ *
* @return the object environment group
*/
protected ObjectEnvironmentGroup getObjectEnvironmentGroup() {
/**
* 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);
/**
* 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.
/**
* Main constructor
+ *
* @param name the object name
*/
public AbstractEnvironmentGroup(String name) {
/**
* 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) {
/**
* 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() {
}
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
protected void writeContent(OutputStream os) throws IOException {
super.writeContent(os);
if (mapPageOverlays != null) {
*/
protected String name = null;
- /**
- * The name of the object in EBCIDIC bytes
- */
- protected byte[] nameBytes;
-
/**
* Default constructor
*/
/**
* 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) {
"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;
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;
/**
/**
* Named constructor
+ *
* @param name the name of this page object
*/
public AbstractPageObject(String name) {
/**
* 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() {
/**
* Returns an indication if the page is complete
+ *
* @return whether this page is complete
*/
public boolean isComplete() {
/**
* Returns the height of the page
+ *
* @return the height of the page
*/
public int getHeight() {
/**
* Returns the width of the page
+ *
* @return the width of the page
*/
public int getWidth() {
/**
* 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) {
}
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;
/**
* 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) {
/**
* Sets the data
+ *
* @param data the data
*/
protected void setData(byte[] data) {
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;
/**
/**
* 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);
/**
* 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)
*/
/**
* Main constructor
+ *
* @param name the name of this resource container
*/
public AbstractResourceEnvironmentGroupContainer(String name) {
/**
* Adds a page to the resource container.
+ *
* @param page - the Page object
*/
public void addPage(PageObject page) {
/**
* Adds a PageGroup to the resource container.
+ *
* @param pageGroup the PageGroup object
*/
public void addPageGroup(PageGroup pageGroup) {
addObject(new InvokeMediumMap(name));
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
protected void writeContent(OutputStream os) throws IOException {
super.writeContent(os);
if (resourceEnvironmentGroup != null) {
}
/**
+ * Returns the resource environment group
+ *
* @return the resource environment group
*/
protected ResourceEnvironmentGroup getResourceEnvironmentGroup() {
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
*/
private ResourceGroup resourceGroup = null;
- /**
- * The data object factory
- */
- private DataObjectFactory dataObjectFactory = new DataObjectFactory();
-
/**
* Default constructor
*/
/**
* Named constructor
+ *
* @param name the name of this resource container
*/
public AbstractResourceGroupContainer(String name) {
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}
/**
* An abstract class encapsulating an MODCA structured object
*/
-public abstract class AbstractStructuredAFPObject extends AbstractAFPObject {
-
+public abstract class AbstractStructuredAFPObject extends AbstractAFPObject {
/**
* list of object triplets
*/
}
/**
+ * Returns the triplet data length
+ *
* @return the triplet data length
*/
protected int getTripletDataLength() {
}
/**
+ * Returns the triplet data
+ *
* @return the triplet data
* @throws IOException throws an I/O exception if one occurred
*/
/**
* Writes any triplet data
+ *
* @param os The stream to write to
* @throws IOException The stream to write to
*/
/**
* 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
*/
getTripletData();
}
+ /**
+ * 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
*/
}
/**
- * 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
*/
}
/**
- * 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) {
}
/**
+ * 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
*/
/**
* Adds a triplet to this structured object
+ *
* @param triplet the triplet to add
*/
private void addTriplet(Triplet triplet) {
/**
* 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) {
}
}
- /**
- * @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();
/**
* 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
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);
/**
* 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
/**
* 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
/**
* 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
*/
/**
* 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
*/
/**
* Sets the mapping option
+ *
* @param optionValue the mapping option value
*/
public void setMappingOption(byte optionValue) {
/**
* Sets a comment on this resource
+ *
* @param comment a comment string
*/
public void setComment(String comment) {
/**
* Default constructor for the ActiveEnvironmentGroup.
+ *
* @param width the page width
* @param height the page height
* @param widthRes the page width resolution
/**
* 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
/**
* Set the position of the object area
+ *
* @param x the x offset
* @param y the y offset
* @param rotation the rotation
/**
* Accessor method to obtain the PageDescriptor object of the
* active environment group.
+ *
* @return the page descriptor object
*/
public PageDescriptor getPageDescriptor() {
/**
* 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);
}
}
- /**
- * {@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);
}
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
/**
* 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() {
}
}
- /**
- * 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
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
/**
* 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);
}
/**
- * 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;
+ }
}
/**
* Returns an indication if the page group is complete
+ *
* @return whether or not this page group is complete
*/
public boolean isComplete() {
/**
* 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
*/
}
}
- /**
- * {@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;
}
*/
public class GraphicsObject extends AbstractDataObject {
- /**
- * The graphics data
- */
+ /** The graphics data */
private GraphicsData graphicsData = null;
/**
super(name);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void setViewport(ObjectAreaInfo objectAreaInfo) {
super.setViewport(objectAreaInfo);
getObjectEnvironmentGroup().setGraphicsData(
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())
/**
* Gets the current graphics data, creating a new one if necessary
+ *
* @return the current graphics data
*/
private GraphicsData getData() {
/**
* Creates a new graphics data
+ *
* @return a newly created graphics data
*/
private GraphicsData newData() {
/**
* Sets the current color
+ *
* @param col the active color to use
*/
public void setColor(Color col) {
/**
* Sets the current position
+ *
* @param coords the x and y coordinates of the current position
*/
public void setCurrentPosition(int[] coords) {
/**
* Sets the line width
+ *
* @param multiplier the line width multiplier
*/
public void setLineWidth(int multiplier) {
/**
* Sets the line type
+ *
* @param type the line type
*/
public void setLineType(byte type) {
/**
* Sets whether to fill the next shape
+ *
* @param fill whether to fill the next shape
*/
public void setFill(boolean fill) {
/**
* Sets the character set to use
+ *
* @param fontReference the character set (font) reference
*/
public void setCharacterSet(int fontReference) {
/**
* Adds a line at the given x/y coordinates
+ *
* @param coords the x/y coordinates (can be a series)
*/
public void addLine(int[] coords) {
/**
* Adds a box at the given coordinates
+ *
* @param coords the x/y coordinates
*/
public void addBox(int[] coords) {
/**
* Adds a fillet (curve) at the given coordinates
+ *
* @param coords the x/y coordinates
*/
public void addFillet(int[] coords) {
}
/**
- * 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
/**
* Adds an arc
+ *
* @param x the x coordinate
* @param y the y coordinate
* @param mh the integer portion of the multiplier
/**
* Adds an image
+ *
* @param x the x coordinate
* @param y the y coordinate
* @param width the image width
/**
* Adds a string
+ *
* @param str the string
* @param x the x coordinate
* @param y the y coordinate
}
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public String toString() {
return "GraphicsObject: " + getName();
}
/**
* 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) {
/**
* Sets the ImageOutputControl.
+ *
* @param imageOutputControl The imageOutputControl to set
*/
public void setImageOutputControl(ImageOutputControl imageOutputControl) {
/**
* Sets the ImageCellPosition.
+ *
* @param imageCellPosition The imageCellPosition to set
*/
public void setImageCellPosition(ImageCellPosition imageCellPosition) {
/**
* Sets the ImageInputDescriptor.
+ *
* @param imageInputDescriptor The imageInputDescriptor to set
*/
public void setImageInputDescriptor(ImageInputDescriptor imageInputDescriptor) {
/**
* 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) {
}
}
- /**
- * {@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);
}
}
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.
*/
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,
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);
-
}
-
}
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];
/**
* 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) {
/**
* 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
/**
* Sets the image encoding.
+ *
* @param encoding The image encoding.
*/
public void setImageEncoding(byte encoding) {
/**
* Sets the image compression.
+ *
* @param compression The image compression.
*/
public void setImageCompression(byte compression) {
/**
* Sets the image IDE size.
+ *
* @param size The IDE size.
*/
public void setImageIDESize(byte size) {
/**
* Sets the image IDE color model.
+ *
* @param colorModel the IDE color model.
*/
public void setImageIDEColorModel(byte colorModel) {
/**
* Set the data of the image.
+ *
* @param data The image data
*/
public void setImageData(byte[] data) {
/**
* Helper method to return the start of the image object.
+ *
* @param len the length of this ipd start
* @return byte[] The data stream.
*/
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) {
}
}
- /**
- * {@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);
}
}
* 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];
data[32] = (byte) 0xFF;
os.write(data);
-
}
/**
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];
/* $Id$ */
package org.apache.fop.render.afp.modca;
+
import java.io.IOException;
import java.io.OutputStream;
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.
/**
* Sets the image encoding.
+ *
* @param encoding The image encoding.
*/
public void setImageEncoding(byte encoding) {
/**
* Sets the image compression.
+ *
* @param compression The image compression.
*/
public void setImageCompression(byte compression) {
/**
* Sets the image IDE size.
+ *
* @param size The IDE size.
*/
public void setImageIDESize(byte size) {
/**
* Sets the image IDE color model.
+ *
* @param colorModel the IDE color model.
*/
public void setImageIDEColorModel(byte colorModel) {
/**
* Set the data of the image.
+ *
* @param data the image data
*/
public void setImageData(byte[] data) {
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
os.write(data);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
protected void writeEnd(OutputStream os) throws IOException {
-
byte[] data = new byte[] {
0x71, // ID
0x00, // Length
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
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;
/**
* 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)
*/
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
* @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.
/**
* 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
*/
}
/**
- * 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
*/
}
/**
- * {@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;
os.write(tripletData);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public String toString() {
return "IOB: " + this.getName();
}
/**
* Constructor for the Include Page Overlay
+ *
* @param overlayName Name of the page segment
* @param x The x position
* @param y The y position
*/
public IncludePageOverlay(String overlayName, int x, int y, int orientation) {
super(overlayName);
+
this.x = x;
this.y = y;
setOrientation(orientation);
}
}
- /**
- * {@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:
/**
* 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);
}
private int value;
/**
+ * Returns the interchange set value of a given string
+ *
* @param str an interchange set value
* @return an interchange set
*/
throw new IllegalArgumentException("Invalid MO:DCA interchange set :" + str);
}
}
+
/**
* Main constructor
*
}
/**
+ * Returns true if complies with MOD:CA interchange set 1
+ *
* @return true if complies with MOD:CA interchange set 1
*/
protected boolean is1() {
}
/**
+ * Returns true if complies with MOD:CA interchange set 2
+ *
* @return true if complies with MOD:CA interchange set 2
*/
public boolean is2() {
}
/**
+ * 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() {
/**
* 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
fontList = new java.util.ArrayList();
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void write(OutputStream os) throws IOException {
byte[] startData = new byte[] {
0x5A,
* required for presentation.
*/
public class MapDataResource extends AbstractStructuredAFPObject {
+
/**
* Static default generated name reference
*/
/**
* Main constructor
+ *
* @param dataObjectAccessor a data object accessor
*/
public MapDataResource(DataObjectAccessor dataObjectAccessor) {
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,
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);
/**
* 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.
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;
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).
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
/**
* 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
/**
* Main constructor
+ *
* @param name the name of this object container
*/
public ObjectContainer(String name) {
/**
* 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);
}
}
- /**
- * {@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);
}
*/
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) {
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
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;
}
}
/**
* 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) {
/**
* Sets the object area parameters.
+ *
* @param info the object area info
*/
public void setObjectArea(ObjectAreaInfo info) {
/**
* 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
/**
* 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
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);
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);
}
}
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);
}
}
/**
* 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
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);
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();
}
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();
}
/**
* Main constructor
+ *
* @param name the name of this object
*/
public PageSegment(String name) {
}
/**
+ * Returns a list of objects contained withing this page segment
+ *
* @return a list of objects contained within this page segment
*/
public List/*<AbstractAFPObject>*/ getObjects() {
/**
* 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;
}
/**
* Main constructor
+ *
* @param prePresObj the presentation object to be preprocessed
*/
public PreprocessPresentationObject(AbstractStructuredAFPObject prePresObj) {
/**
* Sets the object orientations relative to media leading edge
+ *
* @param orientation the object orientations relative to media leading edge
*/
public void setOrientation(byte orientation) {
/**
* Sets the X axis origin for object content
+ *
* @param xOffset the X axis origin for object content
*/
public void setXOffset(int xOffset) {
/**
* 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);
os.write(data);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void writeContent(OutputStream os) throws IOException {
byte[] data = new byte[12];
byte[] l = BinaryUtils.convert(12 + getTripletDataLength(), 2);
// Triplets
super.writeContent(os);
}
+
+ /** {@inheritDoc} */
+ protected byte getCategoryCode() {
+ return (byte)0xC3;
+ }
}
/**
* 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.
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;
/**
* 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
*/
/**
* 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);
}
}
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public String toString() {
if (presentationTextDataList != null) {
return presentationTextDataList.toString();
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;
}
/**
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
*/
return this.mimeType;
}
+ /**
+ * @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}
*/
/**
* 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);
- }
}
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;
*/
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
/**
* 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
*/
// || 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();
}
/**
* @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()*/;
}
}
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;
* 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
*
/**
* 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) {
}
}
- /**
- * {@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
*
* 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.
*/
/**
* Default constructor
+ *
* @param userAgent user agent
*/
public PDFRendererConfigurator(FOUserAgent userAgent) {
* Configure the PDF renderer.
* Get the configuration to be used for pdf stream filters,
* fonts etc.
+ *
* @param renderer pdf renderer
* @throws FOPException fop exception
*/
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(
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
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))) {