From 17bc8aa0870e3d6043ea2865e44fc2433dd5b36b Mon Sep 17 00:00:00 2001 From: Adrian Cumiskey Date: Mon, 27 Oct 2008 11:11:31 +0000 Subject: All AFP library classes without Renderer dependencies moved from org.apache.fop.renderer.afp.* to org.apache.fop.afp.*. AbstractNamedAFPObject now truncates names to the last x characters of the name string instead of the first x (where x is the name length of the structured field). Removed redundant package org.apache.fop.store. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@708134 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/afp/goca/GraphicsSetCharacterSet.java | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/java/org/apache/fop/afp/goca/GraphicsSetCharacterSet.java (limited to 'src/java/org/apache/fop/afp/goca/GraphicsSetCharacterSet.java') diff --git a/src/java/org/apache/fop/afp/goca/GraphicsSetCharacterSet.java b/src/java/org/apache/fop/afp/goca/GraphicsSetCharacterSet.java new file mode 100644 index 000000000..f4d04910a --- /dev/null +++ b/src/java/org/apache/fop/afp/goca/GraphicsSetCharacterSet.java @@ -0,0 +1,53 @@ +/* + * 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.afp.goca; + +import org.apache.fop.afp.modca.AbstractPreparedAFPObject; +import org.apache.fop.afp.util.BinaryUtils; + +/** + * Sets the current character set (font) to be used for following graphics strings + */ +public class GraphicsSetCharacterSet extends AbstractPreparedAFPObject { + + /** font character set reference */ + private final int fontReference; + + /** + * @param fontReference character set font reference + */ + public GraphicsSetCharacterSet(int fontReference) { + this.fontReference = fontReference; + prepareData(); + } + + /** {@inheritDoc} */ + protected void prepareData() { + super.data = new byte[] { + 0x38, // GSCS order code + BinaryUtils.convert(fontReference)[0] + }; + } + + /** {@inheritDoc} */ + public String toString() { + return "GraphicsSetCharacterSet(" + fontReference + ")"; + } +} \ No newline at end of file -- cgit v1.2.3 From 016ddc8aa591fde0adcaef76158f3f5ebcf6590a Mon Sep 17 00:00:00 2001 From: Adrian Cumiskey Date: Mon, 17 Nov 2008 15:26:06 +0000 Subject: Memory usage optimizations. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@718262 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/afp/AFPGraphics2D.java | 71 +++-- .../apache/fop/afp/AFPGraphicsConfiguration.java | 155 ---------- src/java/org/apache/fop/afp/AFPGraphicsDevice.java | 81 ------ src/java/org/apache/fop/afp/fonts/RasterFont.java | 2 +- .../apache/fop/afp/goca/AbstractGraphicsCoord.java | 54 ++-- .../afp/goca/AbstractGraphicsObjectContainer.java | 83 ++++++ .../fop/afp/goca/AbstractGraphicsString.java | 74 +++++ src/java/org/apache/fop/afp/goca/GraphicsArea.java | 8 +- src/java/org/apache/fop/afp/goca/GraphicsBox.java | 24 +- .../fop/afp/goca/GraphicsChainedSegment.java | 14 +- src/java/org/apache/fop/afp/goca/GraphicsData.java | 29 +- .../org/apache/fop/afp/goca/GraphicsFillet.java | 3 +- .../fop/afp/goca/GraphicsFilletRelative.java | 4 +- .../org/apache/fop/afp/goca/GraphicsFullArc.java | 31 +- .../org/apache/fop/afp/goca/GraphicsImage.java | 4 +- src/java/org/apache/fop/afp/goca/GraphicsLine.java | 4 +- .../apache/fop/afp/goca/GraphicsLineRelative.java | 2 +- .../fop/afp/goca/GraphicsSetCharacterSet.java | 21 +- .../apache/fop/afp/goca/GraphicsSetLineType.java | 24 +- .../apache/fop/afp/goca/GraphicsSetLineWidth.java | 20 +- .../org/apache/fop/afp/goca/GraphicsSetMix.java | 13 +- .../fop/afp/goca/GraphicsSetPatternSymbol.java | 21 +- .../fop/afp/goca/GraphicsSetProcessColor.java | 45 ++- .../org/apache/fop/afp/goca/GraphicsString.java | 93 ++---- .../fop/afp/goca/GraphicsStringRelative.java | 57 ++++ src/java/org/apache/fop/afp/ioca/ImageContent.java | 4 +- .../apache/fop/afp/modca/AbstractAFPObject.java | 77 +++++ .../apache/fop/afp/modca/AbstractDescriptor.java | 2 +- .../fop/afp/modca/AbstractNamedAFPObject.java | 2 +- .../fop/afp/modca/AbstractPreparedAFPObject.java | 96 ------ .../afp/modca/AbstractPreparedObjectContainer.java | 84 ------ .../fop/afp/modca/AbstractStructuredAFPObject.java | 324 --------------------- .../fop/afp/modca/AbstractStructuredObject.java | 69 +++++ .../afp/modca/AbstractTripletStructuredObject.java | 178 +++++++++++ .../org/apache/fop/afp/modca/GraphicsObject.java | 32 +- .../org/apache/fop/afp/modca/IncludeObject.java | 4 +- .../org/apache/fop/afp/modca/MapCodedFont.java | 2 +- .../org/apache/fop/afp/modca/MapContainerData.java | 6 +- .../org/apache/fop/afp/modca/MapDataResource.java | 4 +- .../apache/fop/afp/modca/ObjectAreaDescriptor.java | 44 +-- .../apache/fop/afp/modca/PreparedAFPObject.java | 34 --- .../afp/modca/PreprocessPresentationObject.java | 42 +-- .../afp/modca/PresentationEnvironmentControl.java | 79 ++--- src/java/org/apache/fop/afp/modca/Registry.java | 38 ++- .../org/apache/fop/afp/modca/ResourceObject.java | 106 +++---- .../apache/fop/afp/modca/StructuredDataObject.java | 33 +++ .../fop/afp/modca/triplets/AbstractTriplet.java | 120 ++++++++ .../fop/afp/modca/triplets/CommentTriplet.java | 52 ++++ .../modca/triplets/DescriptorPositionTriplet.java | 50 ++++ .../ExtendedResourceLocalIdentifierTriplet.java | 34 ++- .../modca/triplets/FullyQualifiedNameTriplet.java | 137 +++++---- .../afp/modca/triplets/MappingOptionTriplet.java | 39 ++- .../modca/triplets/MeasurementUnitsTriplet.java | 50 +++- .../afp/modca/triplets/ObjectAreaSizeTriplet.java | 58 ++-- .../modca/triplets/ObjectByteExtentTriplet.java | 23 +- .../triplets/ObjectClassificationTriplet.java | 136 +++++---- .../PresentationSpaceMixingRulesTriplet.java | 44 ++- .../PresentationSpaceResetMixingTriplet.java | 32 +- .../modca/triplets/ResourceObjectTypeTriplet.java | 37 ++- .../org/apache/fop/afp/modca/triplets/Triplet.java | 162 ----------- .../fop/afp/svg/AFPGraphicsConfiguration.java | 150 ++++++++++ .../org/apache/fop/afp/svg/AFPGraphicsDevice.java | 80 +++++ src/java/org/apache/fop/svg/PDFGraphics2D.java | 1 - 63 files changed, 1866 insertions(+), 1536 deletions(-) delete mode 100644 src/java/org/apache/fop/afp/AFPGraphicsConfiguration.java delete mode 100644 src/java/org/apache/fop/afp/AFPGraphicsDevice.java create mode 100644 src/java/org/apache/fop/afp/goca/AbstractGraphicsObjectContainer.java create mode 100644 src/java/org/apache/fop/afp/goca/AbstractGraphicsString.java create mode 100644 src/java/org/apache/fop/afp/goca/GraphicsStringRelative.java delete mode 100644 src/java/org/apache/fop/afp/modca/AbstractPreparedAFPObject.java delete mode 100644 src/java/org/apache/fop/afp/modca/AbstractPreparedObjectContainer.java delete mode 100644 src/java/org/apache/fop/afp/modca/AbstractStructuredAFPObject.java create mode 100644 src/java/org/apache/fop/afp/modca/AbstractStructuredObject.java create mode 100644 src/java/org/apache/fop/afp/modca/AbstractTripletStructuredObject.java delete mode 100644 src/java/org/apache/fop/afp/modca/PreparedAFPObject.java create mode 100644 src/java/org/apache/fop/afp/modca/StructuredDataObject.java create mode 100644 src/java/org/apache/fop/afp/modca/triplets/AbstractTriplet.java create mode 100644 src/java/org/apache/fop/afp/modca/triplets/CommentTriplet.java create mode 100644 src/java/org/apache/fop/afp/modca/triplets/DescriptorPositionTriplet.java delete mode 100644 src/java/org/apache/fop/afp/modca/triplets/Triplet.java create mode 100644 src/java/org/apache/fop/afp/svg/AFPGraphicsConfiguration.java create mode 100644 src/java/org/apache/fop/afp/svg/AFPGraphicsDevice.java (limited to 'src/java/org/apache/fop/afp/goca/GraphicsSetCharacterSet.java') diff --git a/src/java/org/apache/fop/afp/AFPGraphics2D.java b/src/java/org/apache/fop/afp/AFPGraphics2D.java index df233dafa..2494eba69 100644 --- a/src/java/org/apache/fop/afp/AFPGraphics2D.java +++ b/src/java/org/apache/fop/afp/AFPGraphics2D.java @@ -47,6 +47,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.fop.afp.goca.GraphicsSetLineType; import org.apache.fop.afp.modca.GraphicsObject; +import org.apache.fop.afp.svg.AFPGraphicsConfiguration; import org.apache.fop.fonts.FontInfo; import org.apache.fop.svg.NativeImageHandler; import org.apache.xmlgraphics.image.loader.ImageInfo; @@ -101,6 +102,9 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand /** Current AFP state */ private AFPPaintingState paintingState = null; + /** AFP graphics configuration */ + private final AFPGraphicsConfiguration graphicsConfig = new AFPGraphicsConfiguration(); + /** The AFP FontInfo */ private FontInfo fontInfo; @@ -246,8 +250,8 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand if (fill) { graphicsObj.beginArea(); } - AffineTransform trans = super.getTransform(); + AffineTransform trans = gc.getTransform(); PathIterator iter = shape.getPathIterator(trans); double[] dstPts = new double[6]; int[] coords = null; @@ -294,44 +298,39 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand mhr ); } else { - for (int[] openingCoords = new int[2], currCoords = new int[2]; - !iter.isDone(); iter.next()) { + for (int[] openingCoords = new int[2]; !iter.isDone(); iter.next()) { int type = iter.currentSegment(dstPts); - if (type == PathIterator.SEG_MOVETO) { - openingCoords[X] = currCoords[X] = (int)Math.round(dstPts[X]); - openingCoords[Y] = currCoords[Y] = (int)Math.round(dstPts[Y]); - graphicsObj.setCurrentPosition(openingCoords); + int numCoords; + if (type == PathIterator.SEG_MOVETO || type == PathIterator.SEG_LINETO) { + numCoords = 2; + } else if (type == PathIterator.SEG_QUADTO) { + numCoords = 4; + } else if (type == PathIterator.SEG_CUBICTO) { + numCoords = 6; } else { - int numCoords; - if (type == PathIterator.SEG_LINETO) { - numCoords = 2; - } else if (type == PathIterator.SEG_QUADTO) { - numCoords = 4; - } else if (type == PathIterator.SEG_CUBICTO) { - numCoords = 6; + // close of the graphics segment + if (type == PathIterator.SEG_CLOSE) { + // close segment by drawing to opening position + graphicsObj.addLine(openingCoords, true); } else { - // close of the graphics segment - if (type == PathIterator.SEG_CLOSE) { - graphicsObj.addLine(openingCoords, true); - } else { - log.debug("Unrecognised path iterator type: " - + type); - } - continue; - } - coords = new int[numCoords]; - for (int i = 0; i < numCoords; i++) { - coords[i] = (int) Math.round(dstPts[i]); + log.debug("Unrecognised path iterator type: " + + type); } - if (type == PathIterator.SEG_LINETO) { - graphicsObj.addLine(coords, true); - } else if (type == PathIterator.SEG_QUADTO - || type == PathIterator.SEG_CUBICTO) { - graphicsObj.addFillet(coords, true); - } - // update current position coordinates - currCoords[X] = coords[coords.length - 2]; - currCoords[Y] = coords[coords.length - 1]; + continue; + } + coords = new int[numCoords]; + for (int i = 0; i < numCoords; i++) { + coords[i] = (int) Math.round(dstPts[i]); + } + if (type == PathIterator.SEG_MOVETO) { + graphicsObj.setCurrentPosition(coords); + openingCoords[X] = coords[X]; + openingCoords[Y] = coords[Y]; + } else if (type == PathIterator.SEG_LINETO) { + graphicsObj.addLine(coords, true); + } else if (type == PathIterator.SEG_QUADTO + || type == PathIterator.SEG_CUBICTO) { + graphicsObj.addFillet(coords, true); } } } @@ -379,7 +378,7 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand /** {@inheritDoc} */ public GraphicsConfiguration getDeviceConfiguration() { - return new AFPGraphicsConfiguration(); + return graphicsConfig; } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/afp/AFPGraphicsConfiguration.java b/src/java/org/apache/fop/afp/AFPGraphicsConfiguration.java deleted file mode 100644 index 6c6d92098..000000000 --- a/src/java/org/apache/fop/afp/AFPGraphicsConfiguration.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * 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.afp; - -import java.awt.GraphicsDevice; -import java.awt.Rectangle; -import java.awt.Transparency; -import java.awt.geom.AffineTransform; -import java.awt.image.BufferedImage; -import java.awt.image.ColorModel; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.fop.svg.GraphicsConfiguration; - -/** - * Our implementation of the class that returns information about - * roughly what we can handle and want to see (alpha for example). - */ -public class AFPGraphicsConfiguration extends GraphicsConfiguration { - // We use this to get a good colormodel.. - private static final BufferedImage BI_WITH_ALPHA - = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); - // We use this to get a good colormodel.. - private static final BufferedImage BI_WITHOUT_ALPHA - = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); - - /** - * Construct a buffered image with an alpha channel, unless - * transparencty is OPAQUE (no alpha at all). - * - * @param width the width of the image - * @param height the height of the image - * @param transparency the alpha value of the image - * @return the new buffered image - */ - public BufferedImage createCompatibleImage(int width, int height, - int transparency) { - if (transparency == Transparency.OPAQUE) { - return new BufferedImage(width, height, - BufferedImage.TYPE_INT_RGB); - } else { - return new BufferedImage(width, height, - BufferedImage.TYPE_INT_ARGB); - } - } - - /** - * Construct a buffered image with an alpha channel. - * - * @param width the width of the image - * @param height the height of the image - * @return the new buffered image - */ - public BufferedImage createCompatibleImage(int width, int height) { - return new BufferedImage(width, height, - BufferedImage.TYPE_INT_ARGB); - } - - /** - * TODO: This should return the page bounds in Pts, - * I couldn't figure out how to get this for the current - * page from the PDFDocument (this still works for now, - * but it should be fixed...). - * - * @return the bounds of the PDF document page - */ - public Rectangle getBounds() { - return null; - } - - /** - * Return a good default color model for this 'device'. - * @return the colour model for the configuration - */ - public ColorModel getColorModel() { - return BI_WITH_ALPHA.getColorModel(); - } - - /** - * Return a good color model given transparency - * - * @param transparency the alpha value for the colour model - * @return the colour model for the configuration - */ - public ColorModel getColorModel(int transparency) { - if (transparency == Transparency.OPAQUE) { - return BI_WITHOUT_ALPHA.getColorModel(); - } else { - return BI_WITH_ALPHA.getColorModel(); - } - } - - private static final Log log = LogFactory.getLog(AFPGraphicsConfiguration.class); - - private AffineTransform defaultTransform = null; - private AffineTransform normalizingTransform = null; - private GraphicsDevice graphicsDevice = null; - - /** - * The default transform (1:1). - * - * @return the default transform for the configuration - */ - public AffineTransform getDefaultTransform() { - log.debug("getDefaultTransform()"); - if (defaultTransform == null) { - defaultTransform = new AffineTransform(); - } - return defaultTransform; - } - - /** - * The normalizing transform (1:1) (since we currently - * render images at 72dpi, which we might want to change - * in the future). - * - * @return the normalizing transform for the configuration - */ - public AffineTransform getNormalizingTransform() { - log.debug("getNormalizingTransform()"); - if (normalizingTransform == null) { - normalizingTransform = new AffineTransform(2, 0, 0, 2, 0, 0); - } - return normalizingTransform; - } - - /** - * {@inheritDoc} - */ - public GraphicsDevice getDevice() { - log.debug("getDevice()"); - if (graphicsDevice == null) { - graphicsDevice = new AFPGraphicsDevice(this); - } - return graphicsDevice; - } -} diff --git a/src/java/org/apache/fop/afp/AFPGraphicsDevice.java b/src/java/org/apache/fop/afp/AFPGraphicsDevice.java deleted file mode 100644 index 20270e426..000000000 --- a/src/java/org/apache/fop/afp/AFPGraphicsDevice.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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.afp; - -import java.awt.GraphicsConfiguration; -import java.awt.GraphicsDevice; - - -/** - * This implements the GraphicsDevice interface as appropriate for - * an AFPGraphics2D. - */ -public class AFPGraphicsDevice extends GraphicsDevice { - - /** - * The Graphics Config that created us... - */ - protected GraphicsConfiguration gc; - - /** - * Create a new AF{ graphics device. - * - * @param gc The graphics configuration we should reference - */ - public AFPGraphicsDevice(AFPGraphicsConfiguration gc) { - this.gc = gc; - } - - /** - * Return an array of our one GraphicsConfig - * - * @return an array containing the one graphics configuration - */ - public GraphicsConfiguration[] getConfigurations() { - return new GraphicsConfiguration[] {gc}; - } - - /** - * Return out sole GraphicsConfig. - * - * @return the graphics configuration that created this object - */ - public GraphicsConfiguration getDefaultConfiguration() { - return this.gc; - } - - /** - * Generate an IdString.. - * - * @return the ID string for this device, uses toString - */ - public String getIDstring() { - return toString(); - } - - /** - * Let the caller know that we are "a printer" - * - * @return the type which is always printer - */ - public int getType() { - return GraphicsDevice.TYPE_PRINTER; - } -} diff --git a/src/java/org/apache/fop/afp/fonts/RasterFont.java b/src/java/org/apache/fop/afp/fonts/RasterFont.java index 7582159c5..c36027913 100644 --- a/src/java/org/apache/fop/afp/fonts/RasterFont.java +++ b/src/java/org/apache/fop/afp/fonts/RasterFont.java @@ -35,7 +35,7 @@ import org.apache.commons.logging.LogFactory; public class RasterFont extends AFPFont { /** Static logging instance */ - protected static final Log log = LogFactory.getLog("org.apache.xmlgraphics.afp.fonts"); + protected static final Log log = LogFactory.getLog("org.apache.fop.afp.fonts"); private final Map/**/ charSets = new java.util.HashMap/**/(); diff --git a/src/java/org/apache/fop/afp/goca/AbstractGraphicsCoord.java b/src/java/org/apache/fop/afp/goca/AbstractGraphicsCoord.java index 3adcd9466..066940874 100644 --- a/src/java/org/apache/fop/afp/goca/AbstractGraphicsCoord.java +++ b/src/java/org/apache/fop/afp/goca/AbstractGraphicsCoord.java @@ -19,13 +19,18 @@ package org.apache.fop.afp.goca; -import org.apache.fop.afp.modca.AbstractPreparedAFPObject; +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.fop.afp.modca.AbstractNamedAFPObject; +import org.apache.fop.afp.modca.StructuredDataObject; import org.apache.fop.afp.util.BinaryUtils; /** * A base class encapsulating the structure of coordinate based GOCA objects */ -public abstract class AbstractGraphicsCoord extends AbstractPreparedAFPObject { +public abstract class AbstractGraphicsCoord extends AbstractNamedAFPObject + implements StructuredDataObject { /** array of x/y coordinates */ protected int[] coords = null; @@ -37,7 +42,6 @@ public abstract class AbstractGraphicsCoord extends AbstractPreparedAFPObject { */ public AbstractGraphicsCoord(int[] coords) { this.coords = coords; - prepareData(); } /** @@ -62,40 +66,48 @@ public abstract class AbstractGraphicsCoord extends AbstractPreparedAFPObject { this(new int[] {x1, y1, x2, y2}); } + /** {@inheritDoc} */ + public int getDataLength() { + return 2 + (coords.length * 2); + } + /** - * Returns the order code to use + * Returns the order code of this structured field * - * @return the order code to use + * @return the order code of this structured field */ - protected abstract byte getOrderCode(); + abstract byte getOrderCode(); /** - * Returns the length of this order code (typically this is the same as the coordinate length) + * Returns the coordinate data start index * - * @return the length of this order code + * @return the coordinate data start index */ - protected int getLength() { - return this.coords.length * 2; + int getCoordinateDataStartIndex() { + return 2; } /** - * Creates a newly created and initialized byte data + * Returns the coordinate data * - * @return a newly created and initialized byte data + * @return the coordinate data */ - protected byte[] createData() { - int len = getLength(); - byte[] data = new byte[len + 2]; - data[0] = getOrderCode(); // ORDER CODE - data[1] = (byte)len; // LENGTH + byte[] getData() { + int len = getDataLength(); + byte[] data = new byte[len]; + data[0] = getOrderCode(); + data[1] = (byte)(len - 2); + + if (coords != null) { + addCoords(data, getCoordinateDataStartIndex()); + } + return data; } /** {@inheritDoc} */ - protected void prepareData() { - super.data = createData(); - int fromIndex = data.length - getLength(); - addCoords(data, fromIndex); + public void writeToStream(OutputStream os) throws IOException { + os.write(getData()); } /** diff --git a/src/java/org/apache/fop/afp/goca/AbstractGraphicsObjectContainer.java b/src/java/org/apache/fop/afp/goca/AbstractGraphicsObjectContainer.java new file mode 100644 index 000000000..672193042 --- /dev/null +++ b/src/java/org/apache/fop/afp/goca/AbstractGraphicsObjectContainer.java @@ -0,0 +1,83 @@ +/* + * 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.afp.goca; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.Iterator; +import java.util.List; + +import org.apache.fop.afp.modca.AbstractNamedAFPObject; +import org.apache.fop.afp.modca.StructuredDataObject; + +/** + * A base container of prepared structured AFP objects + */ +public abstract class AbstractGraphicsObjectContainer extends AbstractNamedAFPObject +implements StructuredDataObject { + + /** list of objects contained within this container */ + protected List/**/ objects + = new java.util.ArrayList/**/(); + + /** + * Default constructor + */ + protected AbstractGraphicsObjectContainer() { + } + + /** + * Named constructor + * + * @param name the name of the container + */ + protected AbstractGraphicsObjectContainer(String name) { + super(name); + } + + /** {@inheritDoc} */ + protected void writeContent(OutputStream os) throws IOException { + writeObjects(objects, os); + } + + /** + * Adds a given graphics object to this container + * + * @param drawingOrder the graphics object + */ + public void addObject(StructuredDataObject drawingOrder) { + objects.add(drawingOrder); + } + + /** + * Returns the current data length + * + * @return the current data length of this container including + * all enclosed objects (and their containers) + */ + public int getDataLength() { + int dataLen = 0; + Iterator it = objects.iterator(); + while (it.hasNext()) { + dataLen += ((StructuredDataObject)it.next()).getDataLength(); + } + return dataLen; + } +} diff --git a/src/java/org/apache/fop/afp/goca/AbstractGraphicsString.java b/src/java/org/apache/fop/afp/goca/AbstractGraphicsString.java new file mode 100644 index 000000000..80882db8a --- /dev/null +++ b/src/java/org/apache/fop/afp/goca/AbstractGraphicsString.java @@ -0,0 +1,74 @@ +/* + * 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.afp.goca; + +import java.io.UnsupportedEncodingException; + +import org.apache.fop.afp.AFPConstants; + +public abstract class AbstractGraphicsString extends AbstractGraphicsCoord { + + /** Up to 255 bytes of character data */ + protected static final int MAX_STR_LEN = 255; + + /** the string to draw */ + protected final String str; + + /** + * Constructor (relative) + * + * @param str the text string + */ + public AbstractGraphicsString(String str) { + super(null); + if (str.length() > MAX_STR_LEN) { + str = str.substring(0, MAX_STR_LEN); + log.warn("truncated character string, longer than " + MAX_STR_LEN + " chars"); + } + this.str = str; + } + + /** + * Constructor (absolute) + * + * @param str the text string + * @param x the x coordinate + * @param y the y coordinate + */ + public AbstractGraphicsString(String str, int x, int y) { + super(x, y); + this.str = str; + } + + /** {@inheritDoc} */ + public int getDataLength() { + return 2 + str.length(); + } + + /** + * Returns the text string as an encoded byte array + * + * @return the text string as an encoded byte array + */ + protected byte[] getStringAsBytes() throws UnsupportedEncodingException { + return str.getBytes(AFPConstants.EBCIDIC_ENCODING); + } + +} diff --git a/src/java/org/apache/fop/afp/goca/GraphicsArea.java b/src/java/org/apache/fop/afp/goca/GraphicsArea.java index 2b6d8a804..3d3bafb45 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsArea.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsArea.java @@ -22,12 +22,11 @@ package org.apache.fop.afp.goca; import java.io.IOException; import java.io.OutputStream; -import org.apache.fop.afp.modca.AbstractPreparedObjectContainer; /** * A GOCA graphics area (container for filled shapes/objects) */ -public final class GraphicsArea extends AbstractPreparedObjectContainer { +public final class GraphicsArea extends AbstractGraphicsObjectContainer { private static final int RES1 = 1; private static final int BOUNDARY = 2; @@ -47,7 +46,6 @@ public final class GraphicsArea extends AbstractPreparedObjectContainer { /** {@inheritDoc} */ public int getDataLength() { - // start len + end len + data len return 4 + super.getDataLength(); } @@ -62,11 +60,11 @@ public final class GraphicsArea extends AbstractPreparedObjectContainer { /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { - byte[] endData = new byte[] { + byte[] data = new byte[] { (byte)0x60, // GEAR order code 0x00, // LENGTH }; - os.write(endData); + os.write(data); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/afp/goca/GraphicsBox.java b/src/java/org/apache/fop/afp/goca/GraphicsBox.java index 4f4947000..945697ec2 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsBox.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsBox.java @@ -19,6 +19,9 @@ package org.apache.fop.afp.goca; +import java.io.IOException; +import java.io.OutputStream; + /** * A GOCA graphics rectangular box */ @@ -34,28 +37,27 @@ public final class GraphicsBox extends AbstractGraphicsCoord { } /** {@inheritDoc} */ - protected byte getOrderCode() { - return (byte)0xC0; + public int getDataLength() { + return 12; } /** {@inheritDoc} */ - protected int getLength() { - return 10; + int getCoordinateDataStartIndex() { + return 4; } /** {@inheritDoc} */ - protected void prepareData() { - super.data = createData(); - final int fromIndex = 4; - addCoords(data, fromIndex); + byte getOrderCode() { + return (byte)0xC0; } /** {@inheritDoc} */ - protected byte[] createData() { - byte[] data = super.createData(); + public void writeToStream(OutputStream os) throws IOException { + byte[] data = getData(); data[2] = (byte)0x20; // CONTROL draw control flags data[3] = 0x00; // reserved - return data; + + os.write(data); } } \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/goca/GraphicsChainedSegment.java b/src/java/org/apache/fop/afp/goca/GraphicsChainedSegment.java index 8dab3d922..697d4f841 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsChainedSegment.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsChainedSegment.java @@ -22,14 +22,13 @@ package org.apache.fop.afp.goca; import java.io.IOException; import java.io.OutputStream; -import org.apache.fop.afp.modca.AbstractPreparedObjectContainer; -import org.apache.fop.afp.modca.PreparedAFPObject; +import org.apache.fop.afp.modca.StructuredDataObject; import org.apache.fop.afp.util.BinaryUtils; /** * A GOCA graphics segment */ -public final class GraphicsChainedSegment extends AbstractPreparedObjectContainer { +public final class GraphicsChainedSegment extends AbstractGraphicsObjectContainer { /** The maximum segment data length */ protected static final int MAX_DATA_LEN = 8192; @@ -83,12 +82,17 @@ public final class GraphicsChainedSegment extends AbstractPreparedObjectContaine return NAME_LENGTH; } + /** {@inheritDoc} */ + byte getOrderCode() { + return 0x70; + } + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { super.writeStart(os); byte[] data = new byte[14]; - data[0] = 0x70; // BEGIN_SEGMENT + data[0] = getOrderCode(); // BEGIN_SEGMENT data[1] = 0x0C; // Length of following parameters // segment name @@ -133,7 +137,7 @@ public final class GraphicsChainedSegment extends AbstractPreparedObjectContaine } /** {@inheritDoc} */ - public void addObject(PreparedAFPObject drawingOrder) { + public void addObject(StructuredDataObject drawingOrder) { if (currentArea != null) { currentArea.addObject(drawingOrder); } else { diff --git a/src/java/org/apache/fop/afp/goca/GraphicsData.java b/src/java/org/apache/fop/afp/goca/GraphicsData.java index ca5fef3f4..8b59436fc 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsData.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsData.java @@ -22,21 +22,20 @@ package org.apache.fop.afp.goca; import java.io.IOException; import java.io.OutputStream; -import org.apache.fop.afp.modca.AbstractPreparedObjectContainer; -import org.apache.fop.afp.modca.PreparedAFPObject; +import org.apache.fop.afp.modca.StructuredDataObject; import org.apache.fop.afp.util.BinaryUtils; import org.apache.fop.afp.util.StringUtils; /** * A GOCA graphics data */ -public final class GraphicsData extends AbstractPreparedObjectContainer { +public final class GraphicsData extends AbstractGraphicsObjectContainer { /** The maximum graphics data length */ public static final int MAX_DATA_LEN = 32767; /** The graphics segment */ - private GraphicsChainedSegment currentSegment = null; + private GraphicsChainedSegment segment = null; /** {@inheritDoc} */ public int getDataLength() { @@ -74,10 +73,10 @@ public final class GraphicsData extends AbstractPreparedObjectContainer { * @return the current graphics chained segment */ private GraphicsChainedSegment getSegment() { - if (currentSegment == null) { + if (segment == null) { newSegment(); } - return this.currentSegment; + return this.segment; } /** @@ -87,23 +86,23 @@ public final class GraphicsData extends AbstractPreparedObjectContainer { */ public GraphicsChainedSegment newSegment() { String name = createSegmentName(); - if (currentSegment == null) { - this.currentSegment = new GraphicsChainedSegment(name); + if (segment == null) { + this.segment = new GraphicsChainedSegment(name); } else { - this.currentSegment = new GraphicsChainedSegment(name, currentSegment); + this.segment = new GraphicsChainedSegment(name, segment); } - super.addObject(currentSegment); - return currentSegment; + super.addObject(segment); + return segment; } /** {@inheritDoc} */ - public void addObject(PreparedAFPObject drawingOrder) { - if (currentSegment == null - || (currentSegment.getDataLength() + drawingOrder.getDataLength()) + public void addObject(StructuredDataObject drawingOrder) { + if (segment == null + || (segment.getDataLength() + drawingOrder.getDataLength()) >= GraphicsChainedSegment.MAX_DATA_LEN) { newSegment(); } - currentSegment.addObject(drawingOrder); + segment.addObject(drawingOrder); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/afp/goca/GraphicsFillet.java b/src/java/org/apache/fop/afp/goca/GraphicsFillet.java index 40b98b0d3..b4fa17d65 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsFillet.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsFillet.java @@ -34,8 +34,7 @@ public final class GraphicsFillet extends AbstractGraphicsCoord { super(coords); } - /** {@inheritDoc} */ - protected byte getOrderCode() { + byte getOrderCode() { return (byte)0xC5; } diff --git a/src/java/org/apache/fop/afp/goca/GraphicsFilletRelative.java b/src/java/org/apache/fop/afp/goca/GraphicsFilletRelative.java index b0e408405..21a1c17d6 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsFilletRelative.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsFilletRelative.java @@ -19,6 +19,7 @@ package org.apache.fop.afp.goca; + /** * A GOCA graphics curved tangential line to a specified set of * straight lines drawn from the given position or current position @@ -35,8 +36,7 @@ public final class GraphicsFilletRelative extends AbstractGraphicsCoord { } /** {@inheritDoc} */ - protected byte getOrderCode() { + byte getOrderCode() { return (byte)0x85; } - } \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/goca/GraphicsFullArc.java b/src/java/org/apache/fop/afp/goca/GraphicsFullArc.java index 9d511e142..a4b6916ae 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsFullArc.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsFullArc.java @@ -19,12 +19,16 @@ package org.apache.fop.afp.goca; +import java.io.IOException; +import java.io.OutputStream; + import org.apache.fop.afp.util.BinaryUtils; /** * A GOCA graphics arc (circle/ellipse) */ public class GraphicsFullArc extends AbstractGraphicsCoord { + /** the integer portion of the multiplier */ private final int mh; @@ -43,27 +47,29 @@ public class GraphicsFullArc extends AbstractGraphicsCoord { super(x, y); this.mh = mh; this.mhr = mhr; - // integer portion of multiplier - data[data.length - 2] = BinaryUtils.convert(mh, 1)[0]; - // fractional portion of multiplier - data[data.length - 1] = BinaryUtils.convert(mhr, 1)[0]; } /** {@inheritDoc} */ - protected byte getOrderCode() { - return (byte)0xC7; + public int getDataLength() { + return 8; } /** {@inheritDoc} */ - protected int getLength() { - return super.getLength() + 2; + byte getOrderCode() { + return (byte)0xC7; } /** {@inheritDoc} */ - protected void prepareData() { - super.data = super.createData(); - final int fromIndex = 2; - super.addCoords(data, fromIndex); + public void writeToStream(OutputStream os) throws IOException { + byte[] data = getData(); + + // integer portion of multiplier + data[6] = BinaryUtils.convert(mh, 1)[0]; + + // fractional portion of multiplier + data[7] = BinaryUtils.convert(mhr, 1)[0]; + + os.write(data); } /** {@inheritDoc} */ @@ -75,4 +81,5 @@ public class GraphicsFullArc extends AbstractGraphicsCoord { + ", mhr=" + mhr + "}"; } + } \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/goca/GraphicsImage.java b/src/java/org/apache/fop/afp/goca/GraphicsImage.java index 24d4c78f8..94e9e9ab2 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsImage.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsImage.java @@ -22,13 +22,13 @@ package org.apache.fop.afp.goca; import java.io.IOException; import java.io.OutputStream; -import org.apache.fop.afp.modca.AbstractStructuredAFPObject; +import org.apache.fop.afp.modca.AbstractStructuredObject; import org.apache.fop.afp.util.BinaryUtils; /** * A GOCA Image */ -public class GraphicsImage extends AbstractStructuredAFPObject { +public class GraphicsImage extends AbstractStructuredObject { /** x coordinate */ private final int x; diff --git a/src/java/org/apache/fop/afp/goca/GraphicsLine.java b/src/java/org/apache/fop/afp/goca/GraphicsLine.java index 99f54b2d1..d8ff1afaa 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsLine.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsLine.java @@ -21,7 +21,7 @@ package org.apache.fop.afp.goca; /** * A GOCA graphics straight line drawn from the - * given position + * given absolute position */ public class GraphicsLine extends AbstractGraphicsCoord { @@ -35,7 +35,7 @@ public class GraphicsLine extends AbstractGraphicsCoord { } /** {@inheritDoc} */ - protected byte getOrderCode() { + byte getOrderCode() { return (byte)0xC1; } diff --git a/src/java/org/apache/fop/afp/goca/GraphicsLineRelative.java b/src/java/org/apache/fop/afp/goca/GraphicsLineRelative.java index 1eddc5129..43ffebf08 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsLineRelative.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsLineRelative.java @@ -35,7 +35,7 @@ public class GraphicsLineRelative extends AbstractGraphicsCoord { } /** {@inheritDoc} */ - protected byte getOrderCode() { + byte getOrderCode() { return (byte)0x81; } diff --git a/src/java/org/apache/fop/afp/goca/GraphicsSetCharacterSet.java b/src/java/org/apache/fop/afp/goca/GraphicsSetCharacterSet.java index f4d04910a..1561ecf83 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsSetCharacterSet.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsSetCharacterSet.java @@ -19,13 +19,18 @@ package org.apache.fop.afp.goca; -import org.apache.fop.afp.modca.AbstractPreparedAFPObject; +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.fop.afp.modca.AbstractNamedAFPObject; +import org.apache.fop.afp.modca.StructuredDataObject; import org.apache.fop.afp.util.BinaryUtils; /** * Sets the current character set (font) to be used for following graphics strings */ -public class GraphicsSetCharacterSet extends AbstractPreparedAFPObject { +public class GraphicsSetCharacterSet extends AbstractNamedAFPObject + implements StructuredDataObject { /** font character set reference */ private final int fontReference; @@ -35,19 +40,25 @@ public class GraphicsSetCharacterSet extends AbstractPreparedAFPObject { */ public GraphicsSetCharacterSet(int fontReference) { this.fontReference = fontReference; - prepareData(); } /** {@inheritDoc} */ - protected void prepareData() { - super.data = new byte[] { + public void writeToStream(OutputStream os) throws IOException { + byte[] data = new byte[] { 0x38, // GSCS order code BinaryUtils.convert(fontReference)[0] }; + os.write(data); + } + + /** {@inheritDoc} */ + public int getDataLength() { + return 2; } /** {@inheritDoc} */ public String toString() { return "GraphicsSetCharacterSet(" + fontReference + ")"; } + } \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/goca/GraphicsSetLineType.java b/src/java/org/apache/fop/afp/goca/GraphicsSetLineType.java index 0093885a6..3479bf4e5 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsSetLineType.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsSetLineType.java @@ -19,12 +19,17 @@ package org.apache.fop.afp.goca; -import org.apache.fop.afp.modca.AbstractPreparedAFPObject; +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.fop.afp.modca.AbstractNamedAFPObject; +import org.apache.fop.afp.modca.StructuredDataObject; /** * Sets the value of the current line type attribute when stroking GOCA shapes (structured fields) */ -public class GraphicsSetLineType extends AbstractPreparedAFPObject { +public class GraphicsSetLineType extends AbstractNamedAFPObject +implements StructuredDataObject { /** the default line type */ public static final byte DEFAULT = 0x00; // normally SOLID @@ -63,15 +68,20 @@ public class GraphicsSetLineType extends AbstractPreparedAFPObject { */ public GraphicsSetLineType(byte type) { this.type = type; - prepareData(); } /** {@inheritDoc} */ - protected void prepareData() { - super.data = new byte[] { - 0x18, // GSLW order code - type // line type + public int getDataLength() { + return 2; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = new byte[] { + 0x18, // GSLW order code + type // line type }; + os.write(data); } private static final String[] TYPES = { diff --git a/src/java/org/apache/fop/afp/goca/GraphicsSetLineWidth.java b/src/java/org/apache/fop/afp/goca/GraphicsSetLineWidth.java index 863cbf50d..09ed0d7dc 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsSetLineWidth.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsSetLineWidth.java @@ -19,12 +19,17 @@ package org.apache.fop.afp.goca; -import org.apache.fop.afp.modca.AbstractPreparedAFPObject; +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.fop.afp.modca.AbstractNamedAFPObject; +import org.apache.fop.afp.modca.StructuredDataObject; /** * Sets the line width to use when stroking GOCA shapes (structured fields) */ -public class GraphicsSetLineWidth extends AbstractPreparedAFPObject { +public class GraphicsSetLineWidth extends AbstractNamedAFPObject implements StructuredDataObject { + /** line width multiplier */ private int multiplier = 1; @@ -35,15 +40,20 @@ public class GraphicsSetLineWidth extends AbstractPreparedAFPObject { */ public GraphicsSetLineWidth(int multiplier) { this.multiplier = multiplier; - prepareData(); } /** {@inheritDoc} */ - protected void prepareData() { - super.data = new byte[] { + public int getDataLength() { + return 2; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = new byte[] { 0x19, // GSLW order code (byte)multiplier // MH (line-width) }; + os.write(data); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/afp/goca/GraphicsSetMix.java b/src/java/org/apache/fop/afp/goca/GraphicsSetMix.java index 339620271..0058a5013 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsSetMix.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsSetMix.java @@ -19,9 +19,12 @@ package org.apache.fop.afp.goca; -import org.apache.fop.afp.modca.AbstractPreparedAFPObject; +import java.io.IOException; +import java.io.OutputStream; -public class GraphicsSetMix extends AbstractPreparedAFPObject { +import org.apache.fop.afp.modca.AbstractNamedAFPObject; + +public class GraphicsSetMix extends AbstractNamedAFPObject { public static final byte MODE_DEFAULT = 0x00; public static final byte MODE_OVERPAINT = 0x02; @@ -36,15 +39,15 @@ public class GraphicsSetMix extends AbstractPreparedAFPObject { */ public GraphicsSetMix(byte mode) { this.mode = mode; - prepareData(); } /** {@inheritDoc} */ - protected void prepareData() { - super.data = new byte[] { + public void writeToStream(OutputStream os) throws IOException { + byte[] data = new byte[] { 0x0C, // GSMX order code mode // MODE (mix mode value) }; + os.write(data); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/afp/goca/GraphicsSetPatternSymbol.java b/src/java/org/apache/fop/afp/goca/GraphicsSetPatternSymbol.java index f0e6845be..0d74aa9d3 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsSetPatternSymbol.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsSetPatternSymbol.java @@ -19,12 +19,18 @@ package org.apache.fop.afp.goca; -import org.apache.fop.afp.modca.AbstractPreparedAFPObject; +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.fop.afp.modca.AbstractNamedAFPObject; +import org.apache.fop.afp.modca.StructuredDataObject; /** * Sets the pattern symbol to use when filling following GOCA structured fields */ -public class GraphicsSetPatternSymbol extends AbstractPreparedAFPObject { +public class GraphicsSetPatternSymbol extends AbstractNamedAFPObject +implements StructuredDataObject { + /** dotted density 1 */ public static final byte DOTTED_DENSITY_1 = 0x01; @@ -86,15 +92,20 @@ public class GraphicsSetPatternSymbol extends AbstractPreparedAFPObject { */ public GraphicsSetPatternSymbol(byte symb) { this.symbol = symb; - prepareData(); } /** {@inheritDoc} */ - protected void prepareData() { - super.data = new byte[] { + public int getDataLength() { + return 2; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = new byte[] { 0x28, // GSPT order code symbol }; + os.write(data); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/afp/goca/GraphicsSetProcessColor.java b/src/java/org/apache/fop/afp/goca/GraphicsSetProcessColor.java index 6ec1e50ee..41ddeaa96 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsSetProcessColor.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsSetProcessColor.java @@ -21,16 +21,22 @@ package org.apache.fop.afp.goca; import java.awt.Color; import java.awt.color.ColorSpace; +import java.io.IOException; +import java.io.OutputStream; -import org.apache.fop.afp.modca.AbstractPreparedAFPObject; +import org.apache.fop.afp.modca.AbstractNamedAFPObject; +import org.apache.fop.afp.modca.StructuredDataObject; /** * Sets the current processing color for the following GOCA structured fields */ -public class GraphicsSetProcessColor extends AbstractPreparedAFPObject { - /** the color to set */ +public class GraphicsSetProcessColor extends AbstractNamedAFPObject +implements StructuredDataObject { + private final Color color; + private final float[] colorComponents; + /** * Main constructor * @@ -38,11 +44,22 @@ public class GraphicsSetProcessColor extends AbstractPreparedAFPObject { */ public GraphicsSetProcessColor(Color color) { this.color = color; - prepareData(); + this.colorComponents = color.getColorComponents(null); + } + + /** {@inheritDoc} */ + public int getDataLength() { + return 12 + colorComponents.length; } /** {@inheritDoc} */ - protected void prepareData() { + byte getOrderCode() { + return (byte)0xB2; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + // COLSPCE byte colspace; int colSpaceType = color.getColorSpace().getType(); @@ -56,16 +73,15 @@ public class GraphicsSetProcessColor extends AbstractPreparedAFPObject { } // COLSIZE(S) - float[] colcomp = color.getColorComponents(null); byte[] colsizes = new byte[] {0x00, 0x00, 0x00, 0x00}; - for (int i = 0; i < colcomp.length; i++) { + for (int i = 0; i < colorComponents.length; i++) { colsizes[i] = (byte)8; } - int len = 10 + colcomp.length; - super.data = new byte[len + 2]; - data[0] = (byte)0xB2; // GSPCOL order code - data[1] = (byte)len; // LEN + int len = getDataLength(); + byte[] data = new byte[len]; + data[0] = getOrderCode(); // GSPCOL order code + data[1] = (byte)(len - 2); // LEN data[2] = 0x00; // reserved; must be zero data[3] = colspace; // COLSPCE data[4] = 0x00; // reserved; must be zero @@ -76,10 +92,13 @@ public class GraphicsSetProcessColor extends AbstractPreparedAFPObject { data[9] = colsizes[1]; data[10] = colsizes[2]; data[11] = colsizes[3]; + // COLVALUE(S) - for (int i = 0; i < colcomp.length; i++) { - data[i + 12] = (byte)(colcomp[i] * 255); + for (int i = 0; i < colorComponents.length; i++) { + data[i + 12] = (byte)(colorComponents[i] * 255); } + + os.write(data); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/afp/goca/GraphicsString.java b/src/java/org/apache/fop/afp/goca/GraphicsString.java index 0fa14bb6d..c08da64ec 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsString.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsString.java @@ -19,41 +19,13 @@ package org.apache.fop.afp.goca; -import java.io.UnsupportedEncodingException; - -import org.apache.fop.afp.AFPConstants; -import org.apache.fop.afp.modca.AbstractPreparedAFPObject; -import org.apache.fop.afp.util.BinaryUtils; +import java.io.IOException; +import java.io.OutputStream; /** * A GOCA graphics string */ -public class GraphicsString extends AbstractPreparedAFPObject { - /** Up to 255 bytes of character data */ - private static final int MAX_STR_LEN = 255; - - /** drawn from the current position */ - private boolean fromCurrentPosition = false; - - /** the string to draw */ - private String str = null; - - /** x coordinate */ - private int x; - - /** y coordinate */ - private int y; - - /** - * Constructor - * - * @param str the character string - */ - public GraphicsString(String str) { - this.str = str; - fromCurrentPosition = true; - prepareData(); - } +public class GraphicsString extends AbstractGraphicsString { /** * Constructor @@ -63,53 +35,30 @@ public class GraphicsString extends AbstractPreparedAFPObject { * @param y the y coordinate */ public GraphicsString(String str, int x, int y) { - this.str = str; - this.x = x; - this.y = y; - prepareData(); + super(str, x, y); + } + + /** {@inheritDoc} */ + byte getOrderCode() { + return (byte)0xC3; } /** {@inheritDoc} */ - protected void prepareData() { - int maxStrLen = MAX_STR_LEN - (fromCurrentPosition ? 0 : 4); - if (str.length() > maxStrLen) { - str = str.substring(0, maxStrLen); - log.warn("truncated character string, longer than " + maxStrLen + " chars"); - } - byte[] strData = null; - try { - strData = str.getBytes(AFPConstants.EBCIDIC_ENCODING); - } catch (UnsupportedEncodingException ex) { - log.error("unsupported encoding: " + ex.getMessage()); - } - int len = strData.length; - if (fromCurrentPosition) { - data = new byte[len + 2]; - data[0] = (byte)0x83; - data[1] = (byte)len; - System.arraycopy(strData, 0, data, 2, strData.length); - } else { - len += 4; // x/y coordinates - byte[] osx = BinaryUtils.convert(x, 2); - byte[] osy = BinaryUtils.convert(y, 2); - data = new byte[len + 2]; - data[0] = (byte)0xC3; - data[1] = (byte)len; - data[2] = osx[0]; - data[3] = osx[1]; - data[4] = osy[0]; - data[5] = osy[1]; - System.arraycopy(strData, 0, data, 6, strData.length); - } + public int getDataLength() { + return super.getDataLength() + (coords.length * 2); + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = getData(); + byte[] strData = getStringAsBytes(); + System.arraycopy(strData, 0, data, 6, strData.length); + + os.write(data); } /** {@inheritDoc} */ public String toString() { - String string = "GraphicsString{str='" + str + "'"; - if (!fromCurrentPosition) { - string += ",x=" + x + ",y=" + y; - } - string += "}"; - return string; + return "GraphicsString{x=" + coords[0] + ", y=" + coords[1] + "str='" + str + "'" + "}"; } } \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/goca/GraphicsStringRelative.java b/src/java/org/apache/fop/afp/goca/GraphicsStringRelative.java new file mode 100644 index 000000000..af0c05b5d --- /dev/null +++ b/src/java/org/apache/fop/afp/goca/GraphicsStringRelative.java @@ -0,0 +1,57 @@ +/* + * 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.afp.goca; + +import java.io.IOException; +import java.io.OutputStream; + +/** + * A GOCA graphics string + */ +public class GraphicsStringRelative extends AbstractGraphicsString { + + /** + * Constructor + * + * @param str the character string + */ + public GraphicsStringRelative(String str) { + super(str); + } + + /** {@inheritDoc} */ + byte getOrderCode() { + return (byte)0x83; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = getData(); + byte[] strData = getStringAsBytes(); + System.arraycopy(strData, 0, data, 2, strData.length); + os.write(data); + } + + /** {@inheritDoc} */ + public String toString() { + return "GraphicsStringRelative{str='" + str + "'" + "}"; + } + +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/ioca/ImageContent.java b/src/java/org/apache/fop/afp/ioca/ImageContent.java index fc8ce0944..6cfddab94 100644 --- a/src/java/org/apache/fop/afp/ioca/ImageContent.java +++ b/src/java/org/apache/fop/afp/ioca/ImageContent.java @@ -22,12 +22,12 @@ package org.apache.fop.afp.ioca; import java.io.IOException; import java.io.OutputStream; -import org.apache.fop.afp.modca.AbstractStructuredAFPObject; +import org.apache.fop.afp.modca.AbstractStructuredObject; /** * An IOCA Image Content */ -public class ImageContent extends AbstractStructuredAFPObject { +public class ImageContent extends AbstractStructuredObject { /** * The CCITT T.4 Group 3 Coding Standard (G3 MH-Modified Huffman) is a diff --git a/src/java/org/apache/fop/afp/modca/AbstractAFPObject.java b/src/java/org/apache/fop/afp/modca/AbstractAFPObject.java index 9e1e107f3..f34ac7d00 100644 --- a/src/java/org/apache/fop/afp/modca/AbstractAFPObject.java +++ b/src/java/org/apache/fop/afp/modca/AbstractAFPObject.java @@ -20,6 +20,7 @@ package org.apache.fop.afp.modca; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; import java.util.Collection; import java.util.Iterator; @@ -27,6 +28,7 @@ import java.util.Iterator; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.fop.afp.Streamable; +import org.apache.fop.afp.util.BinaryUtils; /** * This is the base class for all data stream objects. Page objects are @@ -100,6 +102,81 @@ public abstract class AbstractAFPObject implements Streamable { } } + /** + * Reads data chunks from an inputstream + * and then formats them with a structured header to a given outputstream + * + * @param dataHeader the header data + * @param lengthOffset offset of length field in data chunk + * @param maxChunkLength the maximum chunk length + * @param inputStream the inputstream to read from + * @param outputStream the outputstream to write to + * @throws IOException thrown if an I/O exception of some sort has occurred. + */ + protected static void copyChunks(byte[] dataHeader, int lengthOffset, + int maxChunkLength, InputStream inputStream, OutputStream outputStream) + throws IOException { + int headerLen = dataHeader.length - lengthOffset; + // length field is just before data so do not include in data length + if (headerLen == 2) { + headerLen = 0; + } + byte[] data = new byte[maxChunkLength]; + int numBytesRead = 0; + while ((numBytesRead = inputStream.read(data, 0, maxChunkLength)) > 0) { + byte[] len = BinaryUtils.convert(headerLen + numBytesRead, 2); + dataHeader[lengthOffset] = len[0]; // Length byte 1 + dataHeader[lengthOffset + 1] = len[1]; // Length byte 2 + outputStream.write(dataHeader); + outputStream.write(data, 0, numBytesRead); + } + } + + /** + * Writes data chunks to a given outputstream + * + * @param data the data byte array + * @param dataHeader the header data + * @param lengthOffset offset of length field in data chunk + * @param maxChunkLength the maximum chunk length + * @param os the outputstream to write to + * @throws IOException thrown if an I/O exception of some sort has occurred. + */ + protected static void writeChunksToStream(byte[] data, byte[] dataHeader, + int lengthOffset, int maxChunkLength, OutputStream os) throws IOException { + int dataLength = data.length; + int numFullChunks = dataLength / maxChunkLength; + int lastChunkLength = dataLength % maxChunkLength; + + int headerLen = dataHeader.length - lengthOffset; + // length field is just before data so do not include in data length + if (headerLen == 2) { + headerLen = 0; + } + + byte[] len; + int off = 0; + if (numFullChunks > 0) { + // write out full data chunks + len = BinaryUtils.convert(headerLen + maxChunkLength, 2); + dataHeader[lengthOffset] = len[0]; // Length byte 1 + dataHeader[lengthOffset + 1] = len[1]; // Length byte 2 + for (int i = 0; i < numFullChunks; i++, off += maxChunkLength) { + os.write(dataHeader); + os.write(data, off, maxChunkLength); + } + } + + if (lastChunkLength > 0) { + // write last data chunk + len = BinaryUtils.convert(headerLen + lastChunkLength, 2); + dataHeader[lengthOffset] = len[0]; // Length byte 1 + dataHeader[lengthOffset + 1] = len[1]; // Length byte 2 + os.write(dataHeader); + os.write(data, off, lastChunkLength); + } + } + /** structured field type codes */ public interface Type { diff --git a/src/java/org/apache/fop/afp/modca/AbstractDescriptor.java b/src/java/org/apache/fop/afp/modca/AbstractDescriptor.java index f3734cfb7..c471794e9 100644 --- a/src/java/org/apache/fop/afp/modca/AbstractDescriptor.java +++ b/src/java/org/apache/fop/afp/modca/AbstractDescriptor.java @@ -22,7 +22,7 @@ package org.apache.fop.afp.modca; /** * Base class for AFP descriptor objects */ -public abstract class AbstractDescriptor extends AbstractStructuredAFPObject { +public abstract class AbstractDescriptor extends AbstractTripletStructuredObject { /** width of this descriptor */ protected int width = 0; /** height of this descriptor */ diff --git a/src/java/org/apache/fop/afp/modca/AbstractNamedAFPObject.java b/src/java/org/apache/fop/afp/modca/AbstractNamedAFPObject.java index de02f13d3..c3c158825 100644 --- a/src/java/org/apache/fop/afp/modca/AbstractNamedAFPObject.java +++ b/src/java/org/apache/fop/afp/modca/AbstractNamedAFPObject.java @@ -27,7 +27,7 @@ import org.apache.fop.afp.AFPConstants; * This is the base class for all named data stream objects. * A named data stream object has an 8 byte EBCIDIC name. */ -public abstract class AbstractNamedAFPObject extends AbstractStructuredAFPObject { +public abstract class AbstractNamedAFPObject extends AbstractTripletStructuredObject { private static final int DEFAULT_NAME_LENGTH = 8; diff --git a/src/java/org/apache/fop/afp/modca/AbstractPreparedAFPObject.java b/src/java/org/apache/fop/afp/modca/AbstractPreparedAFPObject.java deleted file mode 100644 index 10a516318..000000000 --- a/src/java/org/apache/fop/afp/modca/AbstractPreparedAFPObject.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * 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.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; - -/** - * A base class that carries out early preparation of structured field data - * for the AFP object (so the data length can be pre-calculated) - */ -public abstract class AbstractPreparedAFPObject extends AbstractNamedAFPObject -implements PreparedAFPObject { - - /** structured field data to be written */ - protected byte[] data = null; - - /** - * Default constructor - */ - public AbstractPreparedAFPObject() { - } - - /** - * Named constructor - * - * @param name the name of this AFP object - */ - public AbstractPreparedAFPObject(String name) { - super(name); - } - - /** {@inheritDoc} */ - protected void writeContent(OutputStream os) throws IOException { - super.writeContent(os); // write triplets - if (this.data != null) { - os.write(this.data); - } - } - - /** - * Return the start data length of this structured field - * - * @return the start data length of this structured field - */ - protected int getStartDataLength() { - return 0; - } - - /** - * Return the data length of the structured field data of this AFP object - * - * @return the data length of the structured field data of this AFP object - */ - public int getDataLength() { - if (this.data != null) { - return this.data.length; - } - return 0; - } - - /** - * Return the structured field length - * - * @return the structured field length - */ - protected int getLength() { - return getStartDataLength() + getTripletDataLength() + getDataLength(); - } - - /** - * Sets the data - * - * @param data the data - */ - protected void setData(byte[] data) { - this.data = data; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/modca/AbstractPreparedObjectContainer.java b/src/java/org/apache/fop/afp/modca/AbstractPreparedObjectContainer.java deleted file mode 100644 index 9019a6acc..000000000 --- a/src/java/org/apache/fop/afp/modca/AbstractPreparedObjectContainer.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.Iterator; -import java.util.List; - -/** - * A base container of prepared structured AFP objects - */ -public abstract class AbstractPreparedObjectContainer extends AbstractNamedAFPObject -implements PreparedAFPObject { - - /** list of objects contained within this container */ - protected List/**/ objects - = new java.util.ArrayList/**/(); - - /** - * Default constructor - */ - protected AbstractPreparedObjectContainer() { - } - - /** - * Named constructor - * - * @param name the name of the container - */ - protected AbstractPreparedObjectContainer(String name) { - super(name); - } - - /** {@inheritDoc} */ - protected void writeContent(OutputStream os) throws IOException { - writeObjects(objects, os); - } - - /** - * Adds a given prepared object to this container - * - * @param preparedObject the prepared object - */ - public void addObject(PreparedAFPObject preparedObject) { - objects.add(preparedObject); - } - - /** - * Returns the current data length - * - * @return the current data length of this container including - * all enclosed objects (and their containers) - */ - public int getDataLength() { - int dataLen = 0; - Iterator it = objects.iterator(); - while (it.hasNext()) { - Object obj = it.next(); - if (obj instanceof PreparedAFPObject) { - PreparedAFPObject prepObj = (PreparedAFPObject)obj; - dataLen += prepObj.getDataLength(); - } - } - return dataLen; - } -} diff --git a/src/java/org/apache/fop/afp/modca/AbstractStructuredAFPObject.java b/src/java/org/apache/fop/afp/modca/AbstractStructuredAFPObject.java deleted file mode 100644 index 9bfc11095..000000000 --- a/src/java/org/apache/fop/afp/modca/AbstractStructuredAFPObject.java +++ /dev/null @@ -1,324 +0,0 @@ -/* - * 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.afp.modca; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -import org.apache.commons.io.output.ByteArrayOutputStream; -import org.apache.fop.afp.modca.Registry.ObjectType; -import org.apache.fop.afp.modca.triplets.FullyQualifiedNameTriplet; -import org.apache.fop.afp.modca.triplets.ObjectClassificationTriplet; -import org.apache.fop.afp.modca.triplets.Triplet; -import org.apache.fop.afp.util.BinaryUtils; - -/** - * An abstract class encapsulating an MODCA structured object - */ -public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { - /** - * list of object triplets - */ - protected List/**/ triplets = null; - - /** - * triplet data created from triplet list - */ - protected byte[] tripletData = null; - - /** - * Default constructor - */ - protected AbstractStructuredAFPObject() { - } - - /** - * Returns the triplet data length - * - * @return the triplet data length - */ - protected int getTripletDataLength() { - if (tripletData == null) { - try { - getTripletData(); - } catch (IOException e) { - log.error("failed to get triplet data"); - } - } - if (tripletData != null) { - return tripletData.length; - } - return 0; - } - - /** - * Returns the triplet data - * - * @return the triplet data - * @throws IOException throws an I/O exception if one occurred - */ - protected byte[] getTripletData() throws IOException { - if (tripletData == null && triplets != null) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - writeObjects(triplets, baos); - this.tripletData = baos.toByteArray(); - triplets = null; // gc - } - return this.tripletData; - } - - /** - * Writes any triplet data - * - * @param os The stream to write to - * @throws IOException The stream to write to - */ - protected void writeTriplets(OutputStream os) throws IOException { - if (tripletData != null) { - os.write(tripletData); - } else if (triplets != null) { - writeObjects(triplets, os); - triplets = null; // gc - } - } - - /** - * 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 - */ - protected void writeStart(OutputStream os) throws IOException { - 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 - */ - protected void writeContent(OutputStream os) throws IOException { - writeTriplets(os); - } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - writeStart(os); - writeContent(os); - writeEnd(os); - } - - /** - * Returns the first matching triplet found in the structured field triplet list - * - * @param tripletId the triplet identifier - */ - private Triplet getTriplet(byte tripletId) { - Iterator it = getTriplets().iterator(); - while (it.hasNext()) { - Triplet triplet = (Triplet)it.next(); - if (triplet.getId() == tripletId) { - return triplet; - } - } - return null; - } - - /** - * 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 - */ - public boolean hasTriplet(byte tripletId) { - return getTriplet(tripletId) != null; - } - - /** - * Adds a triplet to this structured object - * - * @param triplet the triplet to add - */ - protected void addTriplet(Triplet triplet) { - getTriplets().add(triplet); - } - - /** - * Adds a list of triplets to the triplets contained within this structured field - * - * @param tripletCollection a collection of triplets - */ - public void addTriplets(Collection/**/ tripletCollection) { - if (tripletCollection != null) { - getTriplets().addAll(tripletCollection); - } - } - - /** @return the triplet list pertaining to this resource */ - protected List/**/ getTriplets() { - if (triplets == null) { - triplets = new java.util.ArrayList(); - } - return triplets; - } - - /** - * 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 - */ - public void setFullyQualifiedName(byte fqnType, byte fqnFormat, String fqName) { - addTriplet(new FullyQualifiedNameTriplet(fqnType, fqnFormat, fqName)); - } - - /** @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); - if (fqNameTriplet != null) { - return fqNameTriplet.getFullyQualifiedName(); - } - log.warn(this + " has no fully qualified name"); - return null; - } - - /** - * 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 - * @param dataInContainer whether the data resides in the container - * @param containerHasOEG whether the container has an object environment group - * @param dataInOCD whether the data resides in a object container data structured field - */ - public void setObjectClassification( - byte objectClass, ObjectType objectType, - boolean dataInContainer, boolean containerHasOEG, boolean dataInOCD) { - addTriplet( - new ObjectClassificationTriplet( - objectClass, objectType, dataInContainer, containerHasOEG, dataInOCD)); - } - - /** - * Sets a comment on this resource - * - * @param comment a comment string - */ - public void setComment(String comment) { - try { - addTriplet(new Triplet(Triplet.COMMENT, comment)); - } catch (UnsupportedEncodingException e) { - log.error(e.getMessage()); - } - } - - /** - * Reads data chunks from an inputstream - * and then formats them with a structured header to a given outputstream - * - * @param dataHeader the header data - * @param lengthOffset offset of length field in data chunk - * @param maxChunkLength the maximum chunk length - * @param inputStream the inputstream to read from - * @param outputStream the outputstream to write to - * @throws IOException thrown if an I/O exception of some sort has occurred. - */ - protected static void copyChunks(byte[] dataHeader, int lengthOffset, - int maxChunkLength, InputStream inputStream, OutputStream outputStream) - throws IOException { - int headerLen = dataHeader.length - lengthOffset; - // length field is just before data so do not include in data length - if (headerLen == 2) { - headerLen = 0; - } - byte[] data = new byte[maxChunkLength]; - int numBytesRead = 0; - while ((numBytesRead = inputStream.read(data, 0, maxChunkLength)) > 0) { - byte[] len = BinaryUtils.convert(headerLen + numBytesRead, 2); - dataHeader[lengthOffset] = len[0]; // Length byte 1 - dataHeader[lengthOffset + 1] = len[1]; // Length byte 2 - outputStream.write(dataHeader); - outputStream.write(data, 0, numBytesRead); - } - } - - /** - * Writes data chunks to a given outputstream - * - * @param data the data byte array - * @param dataHeader the header data - * @param lengthOffset offset of length field in data chunk - * @param maxChunkLength the maximum chunk length - * @param os the outputstream to write to - * @throws IOException thrown if an I/O exception of some sort has occurred. - */ - protected static void writeChunksToStream(byte[] data, byte[] dataHeader, - int lengthOffset, int maxChunkLength, OutputStream os) throws IOException { - int dataLength = data.length; - int numFullChunks = dataLength / maxChunkLength; - int lastChunkLength = dataLength % maxChunkLength; - - int headerLen = dataHeader.length - lengthOffset; - // length field is just before data so do not include in data length - if (headerLen == 2) { - headerLen = 0; - } - - byte[] len; - int off = 0; - if (numFullChunks > 0) { - // write out full data chunks - len = BinaryUtils.convert(headerLen + maxChunkLength, 2); - dataHeader[lengthOffset] = len[0]; // Length byte 1 - dataHeader[lengthOffset + 1] = len[1]; // Length byte 2 - for (int i = 0; i < numFullChunks; i++, off += maxChunkLength) { - os.write(dataHeader); - os.write(data, off, maxChunkLength); - } - } - - if (lastChunkLength > 0) { - // write last data chunk - len = BinaryUtils.convert(headerLen + lastChunkLength, 2); - dataHeader[lengthOffset] = len[0]; // Length byte 1 - dataHeader[lengthOffset + 1] = len[1]; // Length byte 2 - os.write(dataHeader); - os.write(data, off, lastChunkLength); - } - } -} diff --git a/src/java/org/apache/fop/afp/modca/AbstractStructuredObject.java b/src/java/org/apache/fop/afp/modca/AbstractStructuredObject.java new file mode 100644 index 000000000..e848583b5 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/AbstractStructuredObject.java @@ -0,0 +1,69 @@ +/* + * 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.afp.modca; + +import java.io.IOException; +import java.io.OutputStream; + +/** + * An abstract class encapsulating an MODCA structured object + */ +public abstract class AbstractStructuredObject extends AbstractAFPObject { + + /** + * Default constructor + */ + protected AbstractStructuredObject() { + } + + /** + * 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 + */ + protected void writeStart(OutputStream os) throws IOException { + } + + /** + * 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 + */ + protected void writeContent(OutputStream os) throws IOException { + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + writeStart(os); + writeContent(os); + writeEnd(os); + } +} diff --git a/src/java/org/apache/fop/afp/modca/AbstractTripletStructuredObject.java b/src/java/org/apache/fop/afp/modca/AbstractTripletStructuredObject.java new file mode 100644 index 000000000..c1686d07c --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/AbstractTripletStructuredObject.java @@ -0,0 +1,178 @@ +/* + * 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.afp.modca; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import org.apache.fop.afp.modca.Registry.ObjectType; +import org.apache.fop.afp.modca.triplets.AbstractTriplet; +import org.apache.fop.afp.modca.triplets.CommentTriplet; +import org.apache.fop.afp.modca.triplets.FullyQualifiedNameTriplet; +import org.apache.fop.afp.modca.triplets.ObjectClassificationTriplet; + +public class AbstractTripletStructuredObject extends AbstractStructuredObject { + + /** list of object triplets */ + protected List/**/ triplets = new java.util.ArrayList/**/(); + + /** + * Returns the triplet data length + * + * @return the triplet data length + */ + protected int getTripletDataLength() { + int dataLength = 0; + if (hasTriplets()) { + Iterator it = triplets.iterator(); + while (it.hasNext()) { + AbstractTriplet triplet = (AbstractTriplet)it.next(); + dataLength += triplet.getDataLength(); + } + } + return dataLength; + } + + /** + * Returns true when this structured field contains triplets + * + * @return true when this structured field contains triplets + */ + public boolean hasTriplets() { + return triplets.size() > 0; + } + + /** + * Writes any triplet data + * + * @param os The stream to write to + * @throws IOException The stream to write to + */ + protected void writeTriplets(OutputStream os) throws IOException { + if (hasTriplets()) { + writeObjects(triplets, os); + triplets = null; // gc + } + } + + /** + * Returns the first matching triplet found in the structured field triplet list + * + * @param tripletId the triplet identifier + */ + private AbstractTriplet getTriplet(byte tripletId) { + Iterator it = getTriplets().iterator(); + while (it.hasNext()) { + AbstractTriplet triplet = (AbstractTriplet)it.next(); + if (triplet.getId() == tripletId) { + return triplet; + } + } + return null; + } + + /** + * 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 + */ + public boolean hasTriplet(byte tripletId) { + return getTriplet(tripletId) != null; + } + + /** + * Adds a triplet to this structured object + * + * @param triplet the triplet to add + */ + protected void addTriplet(AbstractTriplet triplet) { + triplets.add(triplet); + } + + /** + * Adds a list of triplets to the triplets contained within this structured field + * + * @param tripletCollection a collection of triplets + */ + public void addTriplets(Collection/**/ tripletCollection) { + if (tripletCollection != null) { + triplets.addAll(tripletCollection); + } + } + + /** @return the triplet list pertaining to this resource */ + protected List/**/ getTriplets() { + return triplets; + } + + /** + * 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 + */ + public void setFullyQualifiedName(byte fqnType, byte fqnFormat, String fqName) { + addTriplet(new FullyQualifiedNameTriplet(fqnType, fqnFormat, fqName)); + } + + /** @return the fully qualified name of this triplet or null if it does not exist */ + public String getFullyQualifiedName() { + FullyQualifiedNameTriplet fqNameTriplet + = (FullyQualifiedNameTriplet)getTriplet(AbstractTriplet.FULLY_QUALIFIED_NAME); + if (fqNameTriplet != null) { + return fqNameTriplet.getFullyQualifiedName(); + } + log.warn(this + " has no fully qualified name"); + return null; + } + + /** + * 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 + * @param dataInContainer whether the data resides in the container + * @param containerHasOEG whether the container has an object environment group + * @param dataInOCD whether the data resides in a object container data structured field + */ + public void setObjectClassification( + byte objectClass, ObjectType objectType, + boolean dataInContainer, boolean containerHasOEG, boolean dataInOCD) { + addTriplet( + new ObjectClassificationTriplet( + objectClass, objectType, dataInContainer, containerHasOEG, dataInOCD)); + } + + /** + * Sets a comment on this resource + * + * @param commentString a comment string + */ + public void setComment(String commentString) { + addTriplet(new CommentTriplet(AbstractTriplet.COMMENT, commentString)); + } + +} diff --git a/src/java/org/apache/fop/afp/modca/GraphicsObject.java b/src/java/org/apache/fop/afp/modca/GraphicsObject.java index 3848ca4c3..da6079d33 100644 --- a/src/java/org/apache/fop/afp/modca/GraphicsObject.java +++ b/src/java/org/apache/fop/afp/modca/GraphicsObject.java @@ -51,11 +51,11 @@ import org.apache.fop.afp.goca.GraphicsString; public class GraphicsObject extends AbstractDataObject { /** The graphics data */ - private GraphicsData currentGraphicsData = null; + private GraphicsData data = null; /** list of objects contained within this container */ - protected List/**/ objects - = new java.util.ArrayList/**/(); + protected List/**/ objects + = new java.util.ArrayList/**/(); /** * Default constructor @@ -85,13 +85,13 @@ public class GraphicsObject extends AbstractDataObject { } /** {@inheritDoc} */ - public void addObject(PreparedAFPObject drawingOrder) { - if (currentGraphicsData == null - || (currentGraphicsData.getDataLength() + drawingOrder.getDataLength()) + public void addObject(StructuredDataObject drawingOrder) { + if (data == null + || (data.getDataLength() + drawingOrder.getDataLength()) >= GraphicsData.MAX_DATA_LEN) { newData(); } - currentGraphicsData.addObject(drawingOrder); + data.addObject(drawingOrder); } /** @@ -100,10 +100,10 @@ public class GraphicsObject extends AbstractDataObject { * @return the current graphics data */ private GraphicsData getData() { - if (this.currentGraphicsData == null) { + if (this.data == null) { return newData(); } - return this.currentGraphicsData; + return this.data; } /** @@ -112,9 +112,9 @@ public class GraphicsObject extends AbstractDataObject { * @return a newly created graphics data */ private GraphicsData newData() { - this.currentGraphicsData = factory.createGraphicsData(); - objects.add(currentGraphicsData); - return currentGraphicsData; + this.data = factory.createGraphicsData(); + objects.add(data); + return data; } /** @@ -284,18 +284,18 @@ public class GraphicsObject extends AbstractDataObject { * Begins a graphics area (start of fill) */ public void beginArea() { - if (currentGraphicsData == null) { + if (data == null) { newData(); } - currentGraphicsData.beginArea(); + data.beginArea(); } /** * Ends a graphics area (end of fill) */ public void endArea() { - if (currentGraphicsData != null) { - currentGraphicsData.endArea(); + if (data != null) { + data.endArea(); } } diff --git a/src/java/org/apache/fop/afp/modca/IncludeObject.java b/src/java/org/apache/fop/afp/modca/IncludeObject.java index c0ab5c640..2dff6bd87 100644 --- a/src/java/org/apache/fop/afp/modca/IncludeObject.java +++ b/src/java/org/apache/fop/afp/modca/IncludeObject.java @@ -238,9 +238,7 @@ public class IncludeObject extends AbstractNamedAFPObject { os.write(data); // Write triplet for FQN internal/external object reference - if (tripletData != null) { - os.write(tripletData); - } + writeTriplets(os); } private String getObjectTypeName() { diff --git a/src/java/org/apache/fop/afp/modca/MapCodedFont.java b/src/java/org/apache/fop/afp/modca/MapCodedFont.java index 159aa200a..01e9abc6f 100644 --- a/src/java/org/apache/fop/afp/modca/MapCodedFont.java +++ b/src/java/org/apache/fop/afp/modca/MapCodedFont.java @@ -41,7 +41,7 @@ import org.apache.fop.afp.util.BinaryUtils; * the Map Coded Font structured field specifies a set of resource attributes * for the coded font. */ -public class MapCodedFont extends AbstractStructuredAFPObject { +public class MapCodedFont extends AbstractStructuredObject { /** * The collection of map coded fonts (maximum of 254) diff --git a/src/java/org/apache/fop/afp/modca/MapContainerData.java b/src/java/org/apache/fop/afp/modca/MapContainerData.java index dba7616a8..8411592aa 100644 --- a/src/java/org/apache/fop/afp/modca/MapContainerData.java +++ b/src/java/org/apache/fop/afp/modca/MapContainerData.java @@ -29,7 +29,7 @@ import org.apache.fop.afp.util.BinaryUtils; * The Map Container Data structured field specifies how a presentation data object * that is carried in an Object Container is mapped into its object area. */ -public class MapContainerData extends AbstractStructuredAFPObject { +public class MapContainerData extends AbstractTripletStructuredObject { /** * Main constructor @@ -45,13 +45,15 @@ public class MapContainerData extends AbstractStructuredAFPObject { byte[] data = new byte[11]; copySF(data, Type.MAP, Category.OBJECT_CONTAINER); int tripletLen = getTripletDataLength(); + byte[] len = BinaryUtils.convert(10 + tripletLen, 2); data[1] = len[0]; data[2] = len[1]; + len = BinaryUtils.convert(2 + tripletLen, 2); data[9] = len[0]; data[10] = len[1]; os.write(data); - os.write(tripletData); + writeTriplets(os); } } diff --git a/src/java/org/apache/fop/afp/modca/MapDataResource.java b/src/java/org/apache/fop/afp/modca/MapDataResource.java index 7bebc4c07..566f60ce5 100644 --- a/src/java/org/apache/fop/afp/modca/MapDataResource.java +++ b/src/java/org/apache/fop/afp/modca/MapDataResource.java @@ -28,7 +28,7 @@ import org.apache.fop.afp.util.BinaryUtils; * The Map Data Resource structured field specifies resources that are * required for presentation. */ -public class MapDataResource extends AbstractStructuredAFPObject { +public class MapDataResource extends AbstractTripletStructuredObject { /** * Main constructor @@ -53,6 +53,6 @@ public class MapDataResource extends AbstractStructuredAFPObject { data[10] = len[1]; os.write(data); - os.write(tripletData); + writeTriplets(os); } } diff --git a/src/java/org/apache/fop/afp/modca/ObjectAreaDescriptor.java b/src/java/org/apache/fop/afp/modca/ObjectAreaDescriptor.java index 21c21e39f..80d7f746f 100644 --- a/src/java/org/apache/fop/afp/modca/ObjectAreaDescriptor.java +++ b/src/java/org/apache/fop/afp/modca/ObjectAreaDescriptor.java @@ -22,11 +22,10 @@ package org.apache.fop.afp.modca; import java.io.IOException; import java.io.OutputStream; -import org.apache.commons.io.output.ByteArrayOutputStream; +import org.apache.fop.afp.modca.triplets.DescriptorPositionTriplet; import org.apache.fop.afp.modca.triplets.MeasurementUnitsTriplet; import org.apache.fop.afp.modca.triplets.ObjectAreaSizeTriplet; import org.apache.fop.afp.modca.triplets.PresentationSpaceResetMixingTriplet; -import org.apache.fop.afp.modca.triplets.Triplet; import org.apache.fop.afp.util.BinaryUtils; /** @@ -48,40 +47,27 @@ public class ObjectAreaDescriptor extends AbstractDescriptor { super(width, height, widthRes, heightRes); } - /** {@inheritDoc} */ - protected byte[] getTripletData() throws IOException { - if (tripletData == null) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - // Specifies the associated ObjectAreaPosition structured field - final byte oapId = 0x01; - Triplet triplet = new Triplet(Triplet.DESCRIPTOR_POSITION, oapId); - triplet.writeToStream(baos); - - triplet = new MeasurementUnitsTriplet(widthRes, heightRes); - triplet.writeToStream(baos); - - triplet = new ObjectAreaSizeTriplet(width, height); - triplet.writeToStream(baos); - - triplet = new PresentationSpaceResetMixingTriplet( - PresentationSpaceResetMixingTriplet.NOT_RESET); - triplet.writeToStream(baos); - - this.tripletData = baos.toByteArray(); - } - return this.tripletData; - } + private static final byte oapId = 0x01; /** {@inheritDoc} */ - public void writeStart(OutputStream os) throws IOException { - super.writeStart(os); + public void writeToStream(OutputStream os) throws IOException { + // add triplets + addTriplet(new DescriptorPositionTriplet(oapId)); + addTriplet(new MeasurementUnitsTriplet(widthRes, heightRes)); + addTriplet(new ObjectAreaSizeTriplet(width, height)); + addTriplet(new PresentationSpaceResetMixingTriplet( + PresentationSpaceResetMixingTriplet.NOT_RESET)); + byte[] data = new byte[9]; copySF(data, Type.DESCRIPTOR, Category.OBJECT_AREA); - byte[] len = BinaryUtils.convert(data.length + tripletData.length - 1, 2); + + int tripletDataLength = getTripletDataLength(); + byte[] len = BinaryUtils.convert(data.length + tripletDataLength, 2); data[1] = len[0]; // Length data[2] = len[1]; os.write(data); + + writeTriplets(os); } } diff --git a/src/java/org/apache/fop/afp/modca/PreparedAFPObject.java b/src/java/org/apache/fop/afp/modca/PreparedAFPObject.java deleted file mode 100644 index 2771515bf..000000000 --- a/src/java/org/apache/fop/afp/modca/PreparedAFPObject.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.afp.modca; - -/** - * An AFP object which is able to know its own data length before write() - */ -public interface PreparedAFPObject { - - /** - * Returns the current data length of this container - * - * @return the current data length of this container including - * all enclosed GOCA drawing objects - */ - int getDataLength(); -} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/modca/PreprocessPresentationObject.java b/src/java/org/apache/fop/afp/modca/PreprocessPresentationObject.java index b1f95e236..279b31201 100644 --- a/src/java/org/apache/fop/afp/modca/PreprocessPresentationObject.java +++ b/src/java/org/apache/fop/afp/modca/PreprocessPresentationObject.java @@ -5,9 +5,9 @@ * 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. @@ -27,24 +27,24 @@ import org.apache.fop.afp.util.BinaryUtils; /** * The Preprocess Presentation Object structured field specifies presentation - * parameters for a data object that has been mapped as a resource. + * parameters for a data object that has been mapped as a resource. */ -public class PreprocessPresentationObject extends AbstractStructuredAFPObject { +public class PreprocessPresentationObject extends AbstractTripletStructuredObject { private static final byte TYPE_OTHER = (byte)0x92; private static final byte TYPE_OVERLAY = (byte)0xDF; private static final byte TYPE_IMAGE = (byte)0xFB; - + private byte objType = TYPE_OTHER; private byte objOrent = 0; // object always processed at 0 degree orientation private int objXOffset = -1; private int objYOffset = -1; - + /** * Main constructor - * - * @param prePresObj the presentation object to be preprocessed + * + * @param prePresObj the presentation object to be preprocessed */ - public PreprocessPresentationObject(AbstractStructuredAFPObject prePresObj) { + public PreprocessPresentationObject(AbstractTripletStructuredObject prePresObj) { if (prePresObj instanceof ImageObject || prePresObj instanceof Overlay) { if (prePresObj instanceof ImageObject) { this.objType = TYPE_IMAGE; @@ -52,40 +52,40 @@ public class PreprocessPresentationObject extends AbstractStructuredAFPObject { this.objType = TYPE_OVERLAY; } setFullyQualifiedName( - FullyQualifiedNameTriplet.TYPE_BEGIN_RESOURCE_OBJECT_REF, + FullyQualifiedNameTriplet.TYPE_BEGIN_RESOURCE_OBJECT_REF, FullyQualifiedNameTriplet.FORMAT_CHARSTR, prePresObj.getFullyQualifiedName()); } else { this.objType = TYPE_OTHER; } } - + public static final byte ORIENTATION_ZERO_DEGREES = 1; public static final byte ORIENTATION_90_DEGREES = 2; public static final byte ORIENTATION_180_DEGREES = 4; public static final byte ORIENTATION_270_DEGREES = 8; - + /** * Sets the object orientations relative to media leading edge - * + * * @param orientation the object orientations relative to media leading edge */ public void setOrientation(byte orientation) { - objOrent = (byte)orientation; + objOrent = orientation; } - + /** * Sets the X axis origin for object content - * + * * @param xOffset the X axis origin for object content */ public void setXOffset(int xOffset) { - this.objXOffset = xOffset; + this.objXOffset = xOffset; } - + /** * Sets the Y axis origin for object content - * + * * @param yOffset the Y axis origin for object content */ public void setYOffset(int yOffset) { @@ -105,7 +105,7 @@ public class PreprocessPresentationObject extends AbstractStructuredAFPObject { os.write(data); } - + /** {@inheritDoc} */ public void writeContent(OutputStream os) throws IOException { byte[] data = new byte[12]; @@ -137,7 +137,7 @@ public class PreprocessPresentationObject extends AbstractStructuredAFPObject { data[11] = (byte)0xFF; // YocaOset } os.write(data); - + // Triplets super.writeContent(os); } diff --git a/src/java/org/apache/fop/afp/modca/PresentationEnvironmentControl.java b/src/java/org/apache/fop/afp/modca/PresentationEnvironmentControl.java index 49b33c0ef..a2ebe22f6 100644 --- a/src/java/org/apache/fop/afp/modca/PresentationEnvironmentControl.java +++ b/src/java/org/apache/fop/afp/modca/PresentationEnvironmentControl.java @@ -22,7 +22,6 @@ package org.apache.fop.afp.modca; import java.io.IOException; import java.io.OutputStream; -import org.apache.fop.afp.modca.triplets.Triplet; import org.apache.fop.afp.util.BinaryUtils; /** @@ -30,7 +29,7 @@ import org.apache.fop.afp.util.BinaryUtils; * affect the rendering of presentation data and the appearance that is to be assumed * by the presentation device. */ -public class PresentationEnvironmentControl extends AbstractStructuredAFPObject { +public class PresentationEnvironmentControl extends AbstractTripletStructuredObject { /** * Main constructor @@ -38,27 +37,6 @@ public class PresentationEnvironmentControl extends AbstractStructuredAFPObject public PresentationEnvironmentControl() { } - /** - * Sets the object offset - */ - public void setObjectOffset() { - addTriplet(new ObjectOffsetTriplet()); - } - - /** - * Sets the rendering intent - */ - public void setRenderingIntent() { - addTriplet(new RenderingIntentTriplet()); - } - - /** - * Sets the device appearance - */ - public void setDeviceAppearance() { - addTriplet(new DeviceAppearanceTriplet()); - } - /** {@inheritDoc} */ public void writeToStream(OutputStream os) throws IOException { byte[] data = new byte[11]; @@ -71,27 +49,50 @@ public class PresentationEnvironmentControl extends AbstractStructuredAFPObject data[10] = 0x00; // Reserved; must be zero os.write(data); - os.write(tripletData); + + writeTriplets(os); } +// /** +// * Sets the object offset +// */ +// public void setObjectOffset() { +// addTriplet(new ObjectOffsetTriplet()); +// } +// +// /** +// * Sets the rendering intent +// */ +// public void setRenderingIntent() { +// addTriplet(new RenderingIntentTriplet()); +// } +// +// /** +// * Sets the device appearance +// */ +// public void setDeviceAppearance() { +// addTriplet(new DeviceAppearanceTriplet()); +// } + + // TODO - private class DeviceAppearanceTriplet extends Triplet { - public DeviceAppearanceTriplet() { - super(Triplet.DEVICE_APPEARANCE); - } - } +// private class DeviceAppearanceTriplet extends AbstractTriplet { +// public DeviceAppearanceTriplet() { +// super(AbstractTriplet.DEVICE_APPEARANCE); +// } +// } // TODO - private class RenderingIntentTriplet extends Triplet { - public RenderingIntentTriplet() { - super(Triplet.RENDERING_INTENT); - } - } +// private class RenderingIntentTriplet extends AbstractTriplet { +// public RenderingIntentTriplet() { +// super(AbstractTriplet.RENDERING_INTENT); +// } +// } // TODO - private class ObjectOffsetTriplet extends Triplet { - public ObjectOffsetTriplet() { - super(Triplet.OBJECT_OFFSET); - } - } +// private class ObjectOffsetTriplet extends AbstractTriplet { +// public ObjectOffsetTriplet() { +// super(AbstractTriplet.OBJECT_OFFSET); +// } +// } } diff --git a/src/java/org/apache/fop/afp/modca/Registry.java b/src/java/org/apache/fop/afp/modca/Registry.java index 23c72cd39..481a72afd 100644 --- a/src/java/org/apache/fop/afp/modca/Registry.java +++ b/src/java/org/apache/fop/afp/modca/Registry.java @@ -30,6 +30,7 @@ public final class Registry { /** IOB supported object types */ private static final byte COMPID_IOCA_FS10 = 5; private static final byte COMPID_IOCA_FS11 = 11; + private static final byte COMPID_IOCA_FS40 = 55; private static final byte COMPID_IOCA_FS45 = 12; private static final byte COMPID_EPS = 13; private static final byte COMPID_TIFF = 14; @@ -38,6 +39,9 @@ public final class Registry { private static final byte COMPID_PDF_SINGLE_PAGE = 25; private static final byte COMPID_PCL_PAGE_OBJECT = 34; + private static final byte COMPID_TRUETYPE_OPENTYPE_FONT_RESOURCE_OBJECT = 51; + private static final byte COMPID_TRUETYPE_OPENTYPE_FONT_COLLECTION_RESOURCE_OBJECT = 53; + /** mime type entry mapping */ private final java.util.Map/**/ mimeObjectTypeMap = Collections.synchronizedMap( @@ -91,6 +95,16 @@ public final class Registry { MimeConstants.MIME_AFP_IOCA_FS11 ) ); +// mimeObjectTypeMap.put( +// MimeConstants.MIME_AFP_IOCA_FS40, +// new ObjectType( +// COMPID_IOCA_FS40, +// new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x37}, +// "IOCA FS40", +// true, +// MimeConstants.MIME_AFP_IOCA_FS40 +// ) +//); mimeObjectTypeMap.put( MimeConstants.MIME_AFP_IOCA_FS45, new ObjectType( @@ -160,6 +174,26 @@ public final class Registry { MimeConstants.MIME_PCL ) ); +// mimeObjectTypeMap.put( +// null, +// new ObjectType( +// COMPID_TRUETYPE_OPENTYPE_FONT_RESOURCE_OBJECT, +// new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x33}, +// "TrueType/OpenType Font Resource Object", +// true, +// null +// ) +// ); +// mimeObjectTypeMap.put( +// null, +// new ObjectType( +// COMPID_TRUETYPE_OPENTYPE_FONT_COLLECTION_RESOURCE_OBJECT, +// new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x35}, +// "TrueType/OpenType Font Collection Resource Object", +// true, +// null +// ) +// ); } /** @@ -193,11 +227,11 @@ public final class Registry { */ public ObjectType(byte componentId, byte[] oid, String name, boolean includable, String mimeType) { + this.componentId = componentId; + this.oid = oid; this.name = name; this.includable = includable; this.mimeType = mimeType; - this.componentId = componentId; - this.oid = oid; } /** diff --git a/src/java/org/apache/fop/afp/modca/ResourceObject.java b/src/java/org/apache/fop/afp/modca/ResourceObject.java index a5b551e07..0f555a42e 100644 --- a/src/java/org/apache/fop/afp/modca/ResourceObject.java +++ b/src/java/org/apache/fop/afp/modca/ResourceObject.java @@ -22,14 +22,50 @@ package org.apache.fop.afp.modca; import java.io.IOException; import java.io.OutputStream; -import org.apache.fop.afp.modca.triplets.Triplet; +import org.apache.fop.afp.modca.triplets.ResourceObjectTypeTriplet; import org.apache.fop.afp.util.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 { +public class ResourceObject extends AbstractNamedAFPObject { + + /** graphics object type */ + public static final byte TYPE_GRAPHIC = 0x03; + + /** barcode object type */ + public static final byte TYPE_BARCODE = 0x05; + + /** image object type */ + public static final byte TYPE_IMAGE = 0x06; + + /** font character set type */ + public static final byte TYPE_FONT_CHARACTER_SET = 0x40; + + /** code page type */ + public static final byte TYPE_CODE_PAGE = 0x41; + + /** coded font type */ + public static final byte TYPE_CODED_FONT = 0x42; + + /** object container type */ + public static final byte TYPE_OBJECT_CONTAINER = (byte) 0x92; + + /** document object type */ + public static final byte TYPE_DOCUMENT = (byte) 0xA8; + + /** page segment object type */ + public static final byte TYPE_PAGE_SEGMENT = (byte) 0xFB; + + /** overlay object type */ + public static final byte TYPE_OVERLAY_OBJECT = (byte) 0xFC; + + /** page def type */ + public static final byte TYPE_PAGEDEF = (byte) 0xFD; + + /** form def type */ + public static final byte TYPE_FORMDEF = (byte) 0xFE; private AbstractNamedAFPObject namedObject; @@ -45,10 +81,10 @@ public class ResourceObject extends AbstractPreparedAFPObject { /** * Sets the data object referenced by this resource object * - * @param obj the named data object + * @param namedObject the named data object */ - public void setDataObject(AbstractNamedAFPObject obj) { - this.namedObject = obj; + public void setDataObject(AbstractNamedAFPObject namedObject) { + this.namedObject = namedObject; } /** @@ -78,11 +114,13 @@ public class ResourceObject extends AbstractPreparedAFPObject { data[18] = 0x00; // Reserved os.write(data); + + // Write triplets + writeTriplets(os); } /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { - super.writeContent(os); // write triplets if (namedObject != null) { namedObject.writeToStream(os); } @@ -109,60 +147,4 @@ public class ResourceObject extends AbstractPreparedAFPObject { getTriplets().add(new ResourceObjectTypeTriplet(type)); } - /** graphics object type */ - public static final byte TYPE_GRAPHIC = 0x03; - - /** barcode object type */ - public static final byte TYPE_BARCODE = 0x05; - - /** image object type */ - public static final byte TYPE_IMAGE = 0x06; - - /** font character set type */ - public static final byte TYPE_FONT_CHARACTER_SET = 0x40; - - /** code page type */ - public static final byte TYPE_CODE_PAGE = 0x41; - - /** coded font type */ - public static final byte TYPE_CODED_FONT = 0x42; - - /** object container type */ - public static final byte TYPE_OBJECT_CONTAINER = (byte) 0x92; - - /** document object type */ - public static final byte TYPE_DOCUMENT = (byte) 0xA8; - - /** page segment object type */ - public static final byte TYPE_PAGE_SEGMENT = (byte) 0xFB; - - /** overlay object type */ - public static final byte TYPE_OVERLAY_OBJECT = (byte) 0xFC; - - /** page def type */ - public static final byte TYPE_PAGEDEF = (byte) 0xFD; - - /** form def type */ - public static final byte TYPE_FORMDEF = (byte) 0xFE; - - - /** resource object type triplet */ - private class ResourceObjectTypeTriplet extends Triplet { - - private static final byte RESOURCE_OBJECT = 0x21; - - /** - * Main constructor - * - * @param objectType the resource object type - */ - public ResourceObjectTypeTriplet(byte objectType) { - super(RESOURCE_OBJECT, - new byte[] { - objectType, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Constant Data - } - ); - } - } } diff --git a/src/java/org/apache/fop/afp/modca/StructuredDataObject.java b/src/java/org/apache/fop/afp/modca/StructuredDataObject.java new file mode 100644 index 000000000..f95810ff2 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/StructuredDataObject.java @@ -0,0 +1,33 @@ +/* + * 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.afp.modca; + +/** + * An AFP object which is able to know its own data length before writeToStream() + */ +public interface StructuredDataObject { + + /** + * Returns the data length of this structured field + * + * @return the data length of this structured field + */ + int getDataLength(); +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/modca/triplets/AbstractTriplet.java b/src/java/org/apache/fop/afp/modca/triplets/AbstractTriplet.java new file mode 100644 index 000000000..63914eb73 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/triplets/AbstractTriplet.java @@ -0,0 +1,120 @@ +/* + * 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.afp.modca.triplets; + +import org.apache.fop.afp.Streamable; +import org.apache.fop.afp.modca.StructuredDataObject; + +/** + * A simple implementation of a MOD:CA triplet + */ +public abstract class AbstractTriplet implements Streamable, StructuredDataObject { + public static final byte CODED_GRAPHIC_CHARACTER_SET_GLOBAL_IDENTIFIER = 0x01; + + /** Triplet identifiers */ + public static final byte FULLY_QUALIFIED_NAME = 0x02; + public static final byte MAPPING_OPTION = 0x04; + public static final byte OBJECT_CLASSIFICATION = 0x10; + public static final byte MODCA_INTERCHANGE_SET = 0x18; + public static final byte FONT_DESCRIPTOR_SPECIFICATION = 0x1F; + public static final byte OBJECT_FUNCTION_SET_SPECIFICATION = 0x21; + public static final byte EXTENDED_RESOURCE_LOCAL_IDENTIFIER = 0x22; + public static final byte RESOURCE_LOCAL_IDENTIFIER = 0x24; + public static final byte RESOURCE_SECTION_NUMBER = 0x25; + public static final byte CHARACTER_ROTATION = 0x26; + public static final byte OBJECT_BYTE_OFFSET = 0x2D; + public static final byte ATTRIBUTE_VALUE = 0x36; + public static final byte DESCRIPTOR_POSITION = 0x43; + public static final byte MEDIA_EJECT_CONTROL = 0x45; + public static final byte PAGE_OVERLAY_CONDITIONAL_PROCESSING = 0x46; + public static final byte RESOURCE_USAGE_ATTRIBUTE = 0x47; + public static final byte MEASUREMENT_UNITS = 0x4B; + public static final byte OBJECT_AREA_SIZE = 0x4C; + public static final byte AREA_DEFINITION = 0x4D; + public static final byte COLOR_SPECIFICATION = 0x4E; + public static final byte ENCODING_SCHEME_ID = 0x50; + public static final byte MEDIUM_MAP_PAGE_NUMBER = 0x56; + public static final byte OBJECT_BYTE_EXTENT = 0x57; + public static final byte OBJECT_STRUCTURED_FIELD_OFFSET = 0x58; + public static final byte OBJECT_STRUCTURED_FIELD_EXTENT = 0x59; + public static final byte OBJECT_OFFSET = 0x5A; + public static final byte FONT_HORIZONTAL_SCALE_FACTOR = 0x5D; + public static final byte OBJECT_COUNT = 0x5E; + public static final byte OBJECT_DATE_AND_TIMESTAMP = 0x62; + public static final byte COMMENT = 0x65; + public static final byte MEDIUM_ORIENTATION = 0x68; + public static final byte RESOURCE_OBJECT_INCLUDE = 0x6C; + public static final byte PRESENTATION_SPACE_RESET_MIXING = 0x70; + public static final byte PRESENTATION_SPACE_MIXING_RULE = 0x71; + public static final byte UNIVERSAL_DATE_AND_TIMESTAMP = 0x72; + public static final byte TONER_SAVER = 0x74; + public static final byte COLOR_FIDELITY = 0x75; + public static final byte FONT_FIDELITY = 0x78; + public static final byte ATTRIBUTE_QUALIFIER = (byte)0x80; + public static final byte PAGE_POSITION_INFORMATION = (byte)0x81; + public static final byte PARAMETER_VALUE = (byte)0x82; + public static final byte PRESENTATION_CONTROL = (byte)0x83; + public static final byte FONT_RESOLUTION_AND_METRIC_TECHNOLOGY = (byte)0x84; + public static final byte FINISHING_OPERATION = (byte)0x85; + public static final byte TEXT_FIDELITY = (byte)0x86; + public static final byte MEDIA_FIDELITY = (byte)0x87; + public static final byte FINISHING_FIDELITY = (byte)0x88; + public static final byte DATA_OBJECT_FONT_DESCRIPTOR = (byte)0x8B; + public static final byte LOCALE_SELECTOR = (byte)0x8C; + public static final byte UP3I_FINISHING_OPERATION = (byte)0x8E; + public static final byte COLOR_MANAGEMENT_RESOURCE_DESCRIPTOR = (byte)0x91; + public static final byte RENDERING_INTENT = (byte)0x95; + public static final byte CMR_TAG_FIDELITY = (byte)0x96; + public static final byte DEVICE_APPEARANCE = (byte)0x97; + + /** the triplet identifier */ + protected final byte id; + + /** + * Constructor + * + * @param id the triplet identifier (see static definitions above) + */ + public AbstractTriplet(byte id) { + this.id = id; + } + + /** + * Returns the triplet identifier + * + * @return the triplet identifier + */ + public byte getId() { + return this.id; + } + + /** + * Returns the structured triplet data array + * + * @return the structured triplet data array + */ + public byte[] getData() { + int dataLen = getDataLength(); + byte[] data = new byte[dataLen]; + data[0] = (byte)dataLen; + data[1] = id; + return data; + } +} diff --git a/src/java/org/apache/fop/afp/modca/triplets/CommentTriplet.java b/src/java/org/apache/fop/afp/modca/triplets/CommentTriplet.java new file mode 100644 index 000000000..9b15de8c1 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/triplets/CommentTriplet.java @@ -0,0 +1,52 @@ +/* + * 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.afp.modca.triplets; + +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.fop.afp.AFPConstants; + +/** + * An inline comment triplet. + */ +public class CommentTriplet extends AbstractTriplet { + + private final String commentString; + + public CommentTriplet(byte id, String commentString) { + super(id); + this.commentString = commentString; + } + + /** {@inheritDoc} */ + public int getDataLength() { + return 2 + commentString.length(); + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = getData(); + byte[] strData = commentString.getBytes(AFPConstants.EBCIDIC_ENCODING); + System.arraycopy(strData, 0, data, 2, strData.length); + os.write(data); + } + +} diff --git a/src/java/org/apache/fop/afp/modca/triplets/DescriptorPositionTriplet.java b/src/java/org/apache/fop/afp/modca/triplets/DescriptorPositionTriplet.java new file mode 100644 index 000000000..61b279b5c --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/triplets/DescriptorPositionTriplet.java @@ -0,0 +1,50 @@ +/* + * 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.afp.modca.triplets; + +import java.io.IOException; +import java.io.OutputStream; + +public class DescriptorPositionTriplet extends AbstractTriplet { + + private final byte oapId; + + /** + * Main constructor + * + * @param oapId the object area position id + */ + public DescriptorPositionTriplet(byte oapId) { + super(DESCRIPTOR_POSITION); + this.oapId = oapId; + } + + /** {@inheritDoc} */ + public int getDataLength() { + return 3; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = getData(); + data[2] = oapId; + os.write(data); + } +} diff --git a/src/java/org/apache/fop/afp/modca/triplets/ExtendedResourceLocalIdentifierTriplet.java b/src/java/org/apache/fop/afp/modca/triplets/ExtendedResourceLocalIdentifierTriplet.java index a6059d3ec..af9452fcb 100644 --- a/src/java/org/apache/fop/afp/modca/triplets/ExtendedResourceLocalIdentifierTriplet.java +++ b/src/java/org/apache/fop/afp/modca/triplets/ExtendedResourceLocalIdentifierTriplet.java @@ -19,6 +19,9 @@ package org.apache.fop.afp.modca.triplets; +import java.io.IOException; +import java.io.OutputStream; + import org.apache.fop.afp.util.BinaryUtils; /** @@ -27,7 +30,7 @@ import org.apache.fop.afp.util.BinaryUtils; * resource name by a map structured field, such as a Map Data Resource structured * field, or a Map Media Type structured field. */ -public class ExtendedResourceLocalIdentifierTriplet extends Triplet { +public class ExtendedResourceLocalIdentifierTriplet extends AbstractTriplet { /** the image resource type */ public static final byte TYPE_IMAGE_RESOURCE = 0x10; @@ -38,6 +41,12 @@ public class ExtendedResourceLocalIdentifierTriplet extends Triplet { /** the retired value type */ public static final byte TYPE_MEDIA_RESOURCE = 0x40; + /** the resource type */ + private final byte type; + + /** the resource local id */ + private final int localId; + /** * Main constructor * @@ -45,11 +54,22 @@ public class ExtendedResourceLocalIdentifierTriplet extends Triplet { * @param localId the resource local id */ public ExtendedResourceLocalIdentifierTriplet(byte type, int localId) { - super(Triplet.EXTENDED_RESOURCE_LOCAL_IDENTIFIER); - byte[] data = new byte[5]; - data[0] = type; - byte[] resLID = BinaryUtils.convert(localId, 4); - System.arraycopy(resLID, 0, data, 1, resLID.length); - super.setData(data); + super(AbstractTriplet.EXTENDED_RESOURCE_LOCAL_IDENTIFIER); + this.type = type; + this.localId = localId; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = getData(); + data[2] = type; + byte[] resLID = BinaryUtils.convert(localId, 4); // 4 bytes + System.arraycopy(resLID, 0, data, 3, resLID.length); + os.write(data); + } + + /** {@inheritDoc} */ + public int getDataLength() { + return 7; } } diff --git a/src/java/org/apache/fop/afp/modca/triplets/FullyQualifiedNameTriplet.java b/src/java/org/apache/fop/afp/modca/triplets/FullyQualifiedNameTriplet.java index a949124c8..55653457c 100644 --- a/src/java/org/apache/fop/afp/modca/triplets/FullyQualifiedNameTriplet.java +++ b/src/java/org/apache/fop/afp/modca/triplets/FullyQualifiedNameTriplet.java @@ -5,9 +5,9 @@ * 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. @@ -19,105 +19,107 @@ package org.apache.fop.afp.modca.triplets; +import java.io.IOException; +import java.io.OutputStream; import java.io.UnsupportedEncodingException; import org.apache.fop.afp.AFPConstants; /** * A Fully Qualified Name triplet enable the identification and referencing of - * objects using Gloabl Identifiers (GIDs). + * objects using Gloabl Identifiers (GIDs). */ -public class FullyQualifiedNameTriplet extends Triplet { +public class FullyQualifiedNameTriplet extends AbstractTriplet { // Specifies how the GID will be used /** This GID replaces the first parameter in the structured field that contains a GID name. */ public static final byte TYPE_REPLACE_FIRST_GID_NAME = 0x01; - + /** This triplet contains the name of a font family. */ public static final byte TYPE_FONT_FAMILY_NAME = 0x07; - + /** This triplet contains the name of a font typeface. */ public static final byte TYPE_FONT_TYPEFACE_NAME = 0x08; - + /** This triplet specifies a reference to the MO:DCA resource hierarchy. */ public static final byte TYPE_MODCA_RESOURCE_HIERARCHY_REF = 0x09; - + /** The triplet contains a GID reference to a begin resource group structured field. */ public static final byte TYPE_BEGIN_RESOURCE_GROUP_REF = 0x0A; - + /** The triplet contains a GID reference to a document attribute. */ public static final byte TYPE_ATTRIBUTE_GID = 0x0B; - + /** The triplet contains the GID of a process element. */ public static final byte TYPE_PROCESS_ELEMENT_GID = 0x0C; - + /** The triplet contains a reference to a begin page group structured field. */ public static final byte TYPE_BEGIN_PAGE_GROUP_REF = 0x0D; - + /** The triplet contains a reference to a media type. */ public static final byte TYPE_MEDIA_TYPE_REF = 0x11; - + /** The triplet contains a reference to a color management resource. */ public static final byte TYPE_COLOR_MANAGEMENT_RESOURCE_REF = 0x41; /** The triplet contains a reference to a data-object font file that defines a base font. */ public static final byte TYPE_DATA_OBJECT_FONT_BASE_FONT_ID = 0x6E; - + /** The triplet contains a reference to a data-object font file that defines a linked font. */ public static final byte TYPE_DATA_OBJECT_FONT_LINKED_FONT_ID = 0x7E; - - /** The triplet contains a reference to a begin document structured field. */ + + /** The triplet contains a reference to a begin document structured field. */ public static final byte TYPE_BEGIN_DOCUMENT_REF = (byte)0x83; - + /** * The triplet contains a reference to a begin structured field associated with a resource; * or contains a GID reference to a coded font. */ public static final byte TYPE_BEGIN_RESOURCE_OBJECT_REF = (byte)0x84; - + /** * The triplet contains a GID reference to a code page that specifies the code points and * graphic character names for a coded font. */ public static final byte TYPE_CODE_PAGE_NAME_REF = (byte)0x85; - - /** + + /** * The triplet contains a GID name reference to a font character set that specifies * a set of graphics characters. */ public static final byte TYPE_FONT_CHARSET_NAME_REF = (byte)0x86; - + /** The triplet contains a GID reference to a begin page structured field. */ public static final byte TYPE_BEGIN_PAGE_REF = (byte)0x87; - + /** The triplet contains a GID reference to a begin medium map structured field. */ public static final byte TYPE_BEGIN_MEDIUM_MAP_REF = (byte)0x8D; - + /** * The triplet contains a GID reference to a coded font, which identifies a specific * code page and a specific font character set. */ public static final byte TYPE_CODED_FONT_NAME_REF = (byte)0x8E; - + /** The triplet contains a GID reference to a begin document index structured field. */ - public static final byte TYPE_BEGIN_DOCUMENT_INDEX_REF = (byte)0x98; - + public static final byte TYPE_BEGIN_DOCUMENT_INDEX_REF = (byte)0x98; + /** The triplet contains a GID reference to a begin overlay structured field. */ public static final byte TYPE_BEGIN_OVERLAY_REF = (byte)0xB0; - + /** The triplet contains a GID reference to a resource used by a data object. */ public static final byte TYPE_DATA_OBJECT_INTERNAL_RESOURCE_REF = (byte)0xBE; - + /** The triplet contains a GID reference to an index element structured field. */ public static final byte TYPE_INDEX_ELEMENT_GID = (byte)0xCA; - + /** * The triplet contains a reference to other object data which may or may * not be defined by an IBM presentation architecture. */ public static final byte TYPE_OTHER_OBJECT_DATA_REF = (byte)0xCE; - + /** * The triplet contains a reference to a resource used by a data object. * The GID may be a filename or any other identifier associated with the @@ -127,44 +129,71 @@ public class FullyQualifiedNameTriplet extends Triplet { */ public static final byte TYPE_DATA_OBJECT_EXTERNAL_RESOURCE_REF = (byte)0xDE; - + // GID Format - + /** The GID is a character encoded name. */ public static final byte FORMAT_CHARSTR = (byte)0x00; - + /** the GID is a ASN.1 object identifier (OID). */ public static final byte FORMAT_OID = (byte)0x10; /** the GID is a uniform resource locator (URL). */ public static final byte FORMAT_URL = (byte)0x20; - - private String fqName; - - /** - * @return the actual fully qualified name of this triplet - */ - public String getFullyQualifiedName() { - return fqName; - } + /** the fully qualified name type */ + private final byte type; + + /** the fully qualified name format */ + private final byte format; + + /** the actual fully qualified name */ + private final String fqName; /** * Main constructor - * + * * @param type the fully qualified name type * @param format the fully qualified name format * @param fqName the fully qualified name */ public FullyQualifiedNameTriplet(byte type, byte format, String fqName) { super(FULLY_QUALIFIED_NAME); - + this.type = type; + this.format = format; this.fqName = fqName; + } + /** + * Returns the actual fully qualified name + * + * @return the actual fully qualified name + */ + public String getFullyQualifiedName() { + return fqName; + } + + /** {@inheritDoc} */ + public String toString() { + return this.fqName; + } + + /** {@inheritDoc} */ + public int getDataLength() { + return 4 + fqName.length(); + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = getData(); + data[2] = type; + data[3] = format; + + // FQName byte[] fqNameBytes; - String encoding = AFPConstants.EBCIDIC_ENCODING; + String encoding = AFPConstants.EBCIDIC_ENCODING; if (format == FORMAT_URL) { - encoding = AFPConstants.US_ASCII_ENCODING; + encoding = AFPConstants.US_ASCII_ENCODING; } try { fqNameBytes = fqName.getBytes(encoding); @@ -172,20 +201,8 @@ public class FullyQualifiedNameTriplet extends Triplet { throw new IllegalArgumentException( encoding + " encoding failed"); } + System.arraycopy(fqNameBytes, 0, data, 4, fqNameBytes.length); - byte[] data = new byte[2 + fqNameBytes.length]; - data[0] = type; - data[1] = format; - // FQName - System.arraycopy(fqNameBytes, 0, data, 2, fqNameBytes.length); - - super.setData(data); - } - - /** - * {@inheritDoc} - */ - public String toString() { - return this.fqName; + os.write(data); } } \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/modca/triplets/MappingOptionTriplet.java b/src/java/org/apache/fop/afp/modca/triplets/MappingOptionTriplet.java index 9fe6dad79..0d20d0227 100644 --- a/src/java/org/apache/fop/afp/modca/triplets/MappingOptionTriplet.java +++ b/src/java/org/apache/fop/afp/modca/triplets/MappingOptionTriplet.java @@ -5,9 +5,9 @@ * 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. @@ -19,10 +19,13 @@ package org.apache.fop.afp.modca.triplets; +import java.io.IOException; +import java.io.OutputStream; + /** * Specifies the mapping of data object presentation space to object area */ -public class MappingOptionTriplet extends Triplet { +public class MappingOptionTriplet extends AbstractTriplet { /** * the data object is placed in the upper left corner, all data must be presented * within the object area extents @@ -34,35 +37,51 @@ public class MappingOptionTriplet extends Triplet { * the object area extents will be presented but data that falls outside will not be presented */ public static final byte POSITION_AND_TRIM = 0x10; - + /** * the data object is centred and symmetrically scaled up or down * while preserving aspect ratio */ public static final byte SCALE_TO_FIT = 0x20; - + /** * the data object is centred, all data that falls within the object area extents * will be presented but data that falls outside will not be presented */ public static final byte CENTER_AND_TRIM = 0x30; - + // public static final byte MIGRATION_MAPPING_1 = 0x41; // public static final byte MIGRATION_MAPPING_2 = 0x42; // public static final byte MIGRATION_MAPPING_3 = 0x50; - + /** the data object is centred, aspect ratio is not always preserved */ public static final byte SCALE_TO_FILL = 0x60; - + /** used to map ip3i print data objects */ public static final byte UP3I_PRINT_DATA = 0x70; + private final byte mapValue; + /** * Main constructor - * + * * @param mapValue the mapping option to use */ public MappingOptionTriplet(byte mapValue) { - super(Triplet.MAPPING_OPTION, mapValue); + super(AbstractTriplet.MAPPING_OPTION); + this.mapValue = mapValue; + } + + /** {@inheritDoc} */ + public int getDataLength() { + return 3; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = getData(); + data[2] = mapValue; + + os.write(data); } } diff --git a/src/java/org/apache/fop/afp/modca/triplets/MeasurementUnitsTriplet.java b/src/java/org/apache/fop/afp/modca/triplets/MeasurementUnitsTriplet.java index d39dc5f96..68d3fc40c 100644 --- a/src/java/org/apache/fop/afp/modca/triplets/MeasurementUnitsTriplet.java +++ b/src/java/org/apache/fop/afp/modca/triplets/MeasurementUnitsTriplet.java @@ -5,9 +5,9 @@ * 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. @@ -19,36 +19,54 @@ package org.apache.fop.afp.modca.triplets; +import java.io.IOException; +import java.io.OutputStream; + import org.apache.fop.afp.util.BinaryUtils; /** * The Measurement Units triplet is used to specify the units of measure * for a presentation space */ -public class MeasurementUnitsTriplet extends Triplet { +public class MeasurementUnitsTriplet extends AbstractTriplet { - private static final byte TEN_INCHES = 0x00; + private static final byte TEN_INCHES = 0x00; private static final byte TEN_CM = 0x01; - + private final int xRes; + private final int yRes; + /** * Main constructor - * + * * @param xRes units per base on the x-axis * @param yRes units per base on the y-axis */ public MeasurementUnitsTriplet(int xRes, int yRes) { super(MEASUREMENT_UNITS); - //TODO: units correct? + this.xRes = xRes; + this.yRes = yRes; + } + + /** {@inheritDoc} */ + public int getDataLength() { + return 8; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = getData(); + + data[2] = TEN_INCHES; // XoaBase + data[3] = TEN_INCHES; // YoaBase + byte[] xUnits = BinaryUtils.convert(xRes * 10, 2); + data[4] = xUnits[0]; // XoaUnits (x units per unit base) + data[5] = xUnits[1]; + byte[] yUnits = BinaryUtils.convert(yRes * 10, 2); - byte[] data = new byte[] { - TEN_INCHES, // XoaBase - TEN_INCHES, // YoaBase - xUnits[0], // XoaUnits (x units per unit base) - xUnits[1], - yUnits[0], // YoaUnits (y units per unit base) - yUnits[1] - }; - super.setData(data); + data[6] = yUnits[0]; // YoaUnits (y units per unit base) + data[7] = yUnits[1]; + + os.write(data); } } diff --git a/src/java/org/apache/fop/afp/modca/triplets/ObjectAreaSizeTriplet.java b/src/java/org/apache/fop/afp/modca/triplets/ObjectAreaSizeTriplet.java index 64fba23c9..3d408639e 100644 --- a/src/java/org/apache/fop/afp/modca/triplets/ObjectAreaSizeTriplet.java +++ b/src/java/org/apache/fop/afp/modca/triplets/ObjectAreaSizeTriplet.java @@ -5,9 +5,9 @@ * 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. @@ -19,44 +19,66 @@ package org.apache.fop.afp.modca.triplets; +import java.io.IOException; +import java.io.OutputStream; + import org.apache.fop.afp.util.BinaryUtils; /** * The Object Area Size triplet is used to specify the extent of an object area * in the X and Y directions */ -public class ObjectAreaSizeTriplet extends Triplet { +public class ObjectAreaSizeTriplet extends AbstractTriplet { + + private final int x; + private final int y; + private final byte type; /** * Main constructor - * + * * @param x the object area extent for the X axis * @param y the object area extent for the Y axis * @param type the object area size type */ public ObjectAreaSizeTriplet(int x, int y, byte type) { - super(Triplet.OBJECT_AREA_SIZE); - byte[] xOASize = BinaryUtils.convert(x, 3); - byte[] yOASize = BinaryUtils.convert(y, 3); - byte[] data = new byte[] { - type, // SizeType - xOASize[0], // XoaSize - Object area extent for X axis - xOASize[1], - xOASize[2], - yOASize[0], // YoaSize - Object area extent for Y axis - yOASize[1], - yOASize[2] - }; - super.setData(data); + super(AbstractTriplet.OBJECT_AREA_SIZE); + this.x = x; + this.y = y; + this.type = type; } /** * Main constructor - * + * * @param x the object area extent for the X axis * @param y the object area extent for the Y axis */ public ObjectAreaSizeTriplet(int x, int y) { this(x, y, (byte)0x02); } + + /** {@inheritDoc} */ + public int getDataLength() { + return 9; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = getData(); + + data[2] = type; // SizeType + + byte[] xOASize = BinaryUtils.convert(x, 3); + data[3] = xOASize[0]; // XoaSize - Object area extent for X axis + data[4] = xOASize[1]; + data[5] = xOASize[2]; + + byte[] yOASize = BinaryUtils.convert(y, 3); + data[6] = yOASize[0]; // YoaSize - Object area extent for Y axis + data[7] = yOASize[1]; + data[8] = yOASize[2]; + + os.write(data); + } } diff --git a/src/java/org/apache/fop/afp/modca/triplets/ObjectByteExtentTriplet.java b/src/java/org/apache/fop/afp/modca/triplets/ObjectByteExtentTriplet.java index 355fe8288..3aaa6969a 100644 --- a/src/java/org/apache/fop/afp/modca/triplets/ObjectByteExtentTriplet.java +++ b/src/java/org/apache/fop/afp/modca/triplets/ObjectByteExtentTriplet.java @@ -19,12 +19,17 @@ package org.apache.fop.afp.modca.triplets; +import java.io.IOException; +import java.io.OutputStream; + import org.apache.fop.afp.util.BinaryUtils; /** * The Object Byte Extent triplet is used to specify the number of bytes contained in an object */ -public class ObjectByteExtentTriplet extends Triplet { +public class ObjectByteExtentTriplet extends AbstractTriplet { + + private final int byteExt; /** * Main constructor @@ -33,7 +38,19 @@ public class ObjectByteExtentTriplet extends Triplet { */ public ObjectByteExtentTriplet(int byteExt) { super(OBJECT_BYTE_EXTENT); - byte[] data = BinaryUtils.convert(byteExt, 4); - super.setData(data); + this.byteExt = byteExt; + } + + /** {@inheritDoc} */ + public int getDataLength() { + return 6; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = getData(); + byte[] extData = BinaryUtils.convert(byteExt, 4); + System.arraycopy(extData, 0, data, 2, extData.length); + os.write(data); } } diff --git a/src/java/org/apache/fop/afp/modca/triplets/ObjectClassificationTriplet.java b/src/java/org/apache/fop/afp/modca/triplets/ObjectClassificationTriplet.java index 1692339ac..346dddaab 100644 --- a/src/java/org/apache/fop/afp/modca/triplets/ObjectClassificationTriplet.java +++ b/src/java/org/apache/fop/afp/modca/triplets/ObjectClassificationTriplet.java @@ -19,7 +19,8 @@ package org.apache.fop.afp.modca.triplets; -import java.io.UnsupportedEncodingException; +import java.io.IOException; +import java.io.OutputStream; import org.apache.fop.afp.AFPConstants; import org.apache.fop.afp.modca.Registry.ObjectType; @@ -29,7 +30,7 @@ import org.apache.fop.afp.util.StringUtils; * The Object Classification is used to classify and identify object data. * The object data may or may not be defined by an IBM presentation architecture */ -public class ObjectClassificationTriplet extends Triplet { +public class ObjectClassificationTriplet extends AbstractTriplet { /** * The scope of this object is the including page or overlay @@ -64,6 +65,28 @@ public class ObjectClassificationTriplet extends Triplet { */ public static final byte CLASS_DATA_OBJECT_FONT = 0x41; + /** the object class */ + private final byte objectClass; + + /** the object type */ + private final ObjectType objectType; + + /** whether the container has an object environment group */ + private final boolean containerHasOEG; + + /** whether the data resides within the container */ + private final boolean dataInContainer; + + /** whether the data resides within the object container data */ + private final boolean dataInOCD; + + /** the object level (version) */ + private final String objectLevel; + + /** the company/organization name */ + private final String companyName; + + /** * Main constructor * @@ -79,11 +102,6 @@ public class ObjectClassificationTriplet extends Triplet { this(objectClass, objectType, dataInContainer, containerHasOEG, dataInOCD, null, null); } - - private static final int OBJECT_LEVEL_LEN = 8; - private static final int OBJECT_TYPE_NAME_LEN = 32; - private static final int COMPANY_NAME_LEN = 32; - /** * Fully parameterized constructor * @@ -100,56 +118,16 @@ public class ObjectClassificationTriplet extends Triplet { String objLev, String compName) { super(OBJECT_CLASSIFICATION); + this.objectClass = objectClass; if (objectType == null) { throw new IllegalArgumentException("MO:DCA Registry object type is null"); } - - byte[] data = new byte[94]; - data[0] = 0x00; // reserved (must be zero) - data[1] = objectClass; // ObjClass - data[2] = 0x00; // reserved (must be zero) - data[3] = 0x00; // reserved (must be zero) - - // StrucFlgs - Information on the structure of the object container - byte[] strucFlgs = getStrucFlgs(dataInContainer, containerHasOEG, dataInOCD); - data[4] = strucFlgs[0]; - data[5] = strucFlgs[1]; - - byte[] oid = objectType.getOID(); - // RegObjId - MOD:CA-registered ASN.1 OID for object type (8-23) - System.arraycopy(oid, 0, data, 6, oid.length); - - // ObjTpName - name of object type (24-55) - byte[] objTpName; - try { - objTpName = StringUtils.rpad(objectType.getName(), ' ', OBJECT_TYPE_NAME_LEN).getBytes( - AFPConstants.EBCIDIC_ENCODING); - System.arraycopy(objTpName, 0, data, 22, objTpName.length); - } catch (UnsupportedEncodingException e) { - throw new IllegalArgumentException("an encoding exception occurred"); - } - - // ObjLev - release level or version number of object type (56-63) - byte[] objectLevel; - try { - objectLevel = StringUtils.rpad(objLev, ' ', OBJECT_LEVEL_LEN).getBytes( - AFPConstants.EBCIDIC_ENCODING); - } catch (UnsupportedEncodingException e) { - throw new IllegalArgumentException("an encoding exception occurred"); - } - System.arraycopy(objectLevel, 0, data, 54, objectLevel.length); - - // CompName - name of company or organization that owns object definition (64-95) - byte[] companyName; - try { - companyName = StringUtils.rpad(compName, ' ', COMPANY_NAME_LEN).getBytes( - AFPConstants.EBCIDIC_ENCODING); - } catch (UnsupportedEncodingException e) { - throw new IllegalArgumentException("an encoding exception occurred"); - } - System.arraycopy(companyName, 0, data, 62, companyName.length); - - super.setData(data); + this.objectType = objectType; + this.dataInContainer = dataInContainer; + this.containerHasOEG = containerHasOEG; + this.dataInOCD = dataInOCD; + this.objectLevel = objLev; + this.companyName = compName; } /** @@ -161,7 +139,7 @@ public class ObjectClassificationTriplet extends Triplet { * * @return the byte value of this structure */ - public byte[] getStrucFlgs(boolean dataInContainer, boolean containerHasOEG, + public byte[] getStructureFlagsAsBytes(boolean dataInContainer, boolean containerHasOEG, boolean dataInOCD) { byte[] strucFlgs = new byte[2]; // Object Container (BOC/EOC) @@ -185,4 +163,52 @@ public class ObjectClassificationTriplet extends Triplet { strucFlgs[1] = 0x00; return strucFlgs; } + + /** {@inheritDoc} */ + public int getDataLength() { + return 95; + } + + private static final int OBJECT_LEVEL_LEN = 8; + private static final int OBJECT_TYPE_NAME_LEN = 32; + private static final int COMPANY_NAME_LEN = 32; + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = getData(); + data[2] = 0x00; // reserved (must be zero) + data[3] = objectClass; // ObjClass + data[4] = 0x00; // reserved (must be zero) + data[5] = 0x00; // reserved (must be zero) + + // StrucFlgs - Information on the structure of the object container + byte[] structureFlagsBytes = getStructureFlagsAsBytes(dataInContainer, containerHasOEG, dataInOCD); + data[6] = structureFlagsBytes[0]; + data[7] = structureFlagsBytes[1]; + + byte[] objectIdBytes = objectType.getOID(); + // RegObjId - MOD:CA-registered ASN.1 OID for object type (8-23) + System.arraycopy(objectIdBytes, 0, data, 8, objectIdBytes.length); + + // ObjTpName - name of object type (24-55) + byte[] objectTypeNameBytes; + objectTypeNameBytes + = StringUtils.rpad(objectType.getName(), ' ', OBJECT_TYPE_NAME_LEN).getBytes( + AFPConstants.EBCIDIC_ENCODING); + System.arraycopy(objectTypeNameBytes, 0, data, 24, objectTypeNameBytes.length); + + // ObjLev - release level or version number of object type (56-63) + byte[] objectLevelBytes; + objectLevelBytes = StringUtils.rpad(objectLevel, ' ', OBJECT_LEVEL_LEN).getBytes( + AFPConstants.EBCIDIC_ENCODING); + System.arraycopy(objectLevelBytes, 0, data, 56, objectLevelBytes.length); + + // CompName - name of company or organization that owns object definition (64-95) + byte[] companyNameBytes; + companyNameBytes = StringUtils.rpad(companyName, ' ', COMPANY_NAME_LEN).getBytes( + AFPConstants.EBCIDIC_ENCODING); + System.arraycopy(companyNameBytes, 0, data, 64, companyNameBytes.length); + + os.write(data); + } } \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/modca/triplets/PresentationSpaceMixingRulesTriplet.java b/src/java/org/apache/fop/afp/modca/triplets/PresentationSpaceMixingRulesTriplet.java index 0f087e4fd..b93ec5477 100644 --- a/src/java/org/apache/fop/afp/modca/triplets/PresentationSpaceMixingRulesTriplet.java +++ b/src/java/org/apache/fop/afp/modca/triplets/PresentationSpaceMixingRulesTriplet.java @@ -5,9 +5,9 @@ * 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. @@ -19,28 +19,31 @@ package org.apache.fop.afp.modca.triplets; +import java.io.IOException; +import java.io.OutputStream; + /** * This triplet is used to specify the resulting appearance when data in a new * presentation space is merged with data in an existing presentation space. */ -public class PresentationSpaceMixingRulesTriplet extends Triplet { +public class PresentationSpaceMixingRulesTriplet extends AbstractTriplet { - /** background on background mixing rule */ + /** background on background mixing rule */ public static final byte RULE_BACK_ON_BACK = 0x70; - /** background on foreground mixing rule */ + /** background on foreground mixing rule */ public static final byte RULE_BACK_ON_FORE = 0x71; - /** foreground on background mixing rule */ + /** foreground on background mixing rule */ public static final byte RULE_FORE_ON_BACK = 0x72; - /** foreground on foreground mixing rule */ + /** foreground on foreground mixing rule */ public static final byte RULE_FORE_ON_FORE = 0x73; - + /** overpaint */ public static final byte OVERPAINT = (byte)0x01; - + /** underpaint */ public static final byte UNDERPAINT = (byte)0x02; @@ -49,14 +52,29 @@ public class PresentationSpaceMixingRulesTriplet extends Triplet { /** MO:DCA default mixing */ public static final byte DEFAULT = (byte)0xFF; - - + + /** the mixing rules */ + private final byte[] rules; + /** * Main constructor - * + * * @param rules the mixing rules */ public PresentationSpaceMixingRulesTriplet(byte[] rules) { - super(PRESENTATION_SPACE_MIXING_RULE, rules); + super(PRESENTATION_SPACE_MIXING_RULE); + this.rules = rules; + } + + /** {@inheritDoc} */ + public int getDataLength() { + return 2 + rules.length; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = getData(); + System.arraycopy(rules, 0, data, 2, rules.length); + os.write(data); } } diff --git a/src/java/org/apache/fop/afp/modca/triplets/PresentationSpaceResetMixingTriplet.java b/src/java/org/apache/fop/afp/modca/triplets/PresentationSpaceResetMixingTriplet.java index 38041f140..cecd40910 100644 --- a/src/java/org/apache/fop/afp/modca/triplets/PresentationSpaceResetMixingTriplet.java +++ b/src/java/org/apache/fop/afp/modca/triplets/PresentationSpaceResetMixingTriplet.java @@ -5,9 +5,9 @@ * 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. @@ -19,30 +19,48 @@ package org.apache.fop.afp.modca.triplets; +import java.io.IOException; +import java.io.OutputStream; + /** * This triplet is used to specify the resulting appearance when data in a new * presentation space is merged with data in an existing presentation space. */ -public class PresentationSpaceResetMixingTriplet extends Triplet { +public class PresentationSpaceResetMixingTriplet extends AbstractTriplet { /** * Do not reset to the color of the medium prior to * placing data into this MO:DCA presentation space. */ public static final byte NOT_RESET = 0x00; - + /** * Reset to the color of the medium prior to placing * data into this MO:DCA presentation space. */ public static final byte RESET = 0x01; - + + private final byte backgroundMixFlag; + /** * Main constructor - * + * * @param backgroundMixFlag the background mixing flag */ public PresentationSpaceResetMixingTriplet(byte backgroundMixFlag) { - super(PRESENTATION_SPACE_RESET_MIXING, backgroundMixFlag); + super(PRESENTATION_SPACE_RESET_MIXING); + this.backgroundMixFlag = backgroundMixFlag; + } + + /** {@inheritDoc} */ + public int getDataLength() { + return 3; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = getData(); + data[2] = backgroundMixFlag; + os.write(data); } } diff --git a/src/java/org/apache/fop/afp/modca/triplets/ResourceObjectTypeTriplet.java b/src/java/org/apache/fop/afp/modca/triplets/ResourceObjectTypeTriplet.java index 784975c43..ecc12122d 100644 --- a/src/java/org/apache/fop/afp/modca/triplets/ResourceObjectTypeTriplet.java +++ b/src/java/org/apache/fop/afp/modca/triplets/ResourceObjectTypeTriplet.java @@ -5,9 +5,9 @@ * 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. @@ -19,3 +19,36 @@ package org.apache.fop.afp.modca.triplets; +import java.io.IOException; +import java.io.OutputStream; + +/** resource object type triplet */ +public class ResourceObjectTypeTriplet extends AbstractTriplet { + + private static final byte RESOURCE_OBJECT = 0x21; + + /** the resource object type */ + private final byte objectType; + + /** + * Main constructor + * + * @param objectType the resource object type + */ + public ResourceObjectTypeTriplet(byte objectType) { + super(RESOURCE_OBJECT); + this.objectType = objectType; + } + + /** {@inheritDoc} */ + public int getDataLength() { + return 10; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = getData(); + data[2] = objectType; + os.write(data); + } +} diff --git a/src/java/org/apache/fop/afp/modca/triplets/Triplet.java b/src/java/org/apache/fop/afp/modca/triplets/Triplet.java deleted file mode 100644 index b7f51466b..000000000 --- a/src/java/org/apache/fop/afp/modca/triplets/Triplet.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * 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.afp.modca.triplets; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; - -import org.apache.fop.afp.AFPConstants; -import org.apache.fop.afp.Streamable; - -/** - * A simple implementation of a MOD:CA triplet - */ -public class Triplet implements Streamable { - public static final byte CODED_GRAPHIC_CHARACTER_SET_GLOBAL_IDENTIFIER = 0x01; - - /** Triplet identifiers */ - public static final byte FULLY_QUALIFIED_NAME = 0x02; - public static final byte MAPPING_OPTION = 0x04; - public static final byte OBJECT_CLASSIFICATION = 0x10; - public static final byte MODCA_INTERCHANGE_SET = 0x18; - public static final byte FONT_DESCRIPTOR_SPECIFICATION = 0x1F; - public static final byte OBJECT_FUNCTION_SET_SPECIFICATION = 0x21; - public static final byte EXTENDED_RESOURCE_LOCAL_IDENTIFIER = 0x22; - public static final byte RESOURCE_LOCAL_IDENTIFIER = 0x24; - public static final byte RESOURCE_SECTION_NUMBER = 0x25; - public static final byte CHARACTER_ROTATION = 0x26; - public static final byte OBJECT_BYTE_OFFSET = 0x2D; - public static final byte ATTRIBUTE_VALUE = 0x36; - public static final byte DESCRIPTOR_POSITION = 0x43; - public static final byte MEDIA_EJECT_CONTROL = 0x45; - public static final byte PAGE_OVERLAY_CONDITIONAL_PROCESSING = 0x46; - public static final byte RESOURCE_USAGE_ATTRIBUTE = 0x47; - public static final byte MEASUREMENT_UNITS = 0x4B; - public static final byte OBJECT_AREA_SIZE = 0x4C; - public static final byte AREA_DEFINITION = 0x4D; - public static final byte COLOR_SPECIFICATION = 0x4E; - public static final byte ENCODING_SCHEME_ID = 0x50; - public static final byte MEDIUM_MAP_PAGE_NUMBER = 0x56; - public static final byte OBJECT_BYTE_EXTENT = 0x57; - public static final byte OBJECT_STRUCTURED_FIELD_OFFSET = 0x58; - public static final byte OBJECT_STRUCTURED_FIELD_EXTENT = 0x59; - public static final byte OBJECT_OFFSET = 0x5A; - public static final byte FONT_HORIZONTAL_SCALE_FACTOR = 0x5D; - public static final byte OBJECT_COUNT = 0x5E; - public static final byte OBJECT_DATE_AND_TIMESTAMP = 0x62; - public static final byte COMMENT = 0x65; - public static final byte MEDIUM_ORIENTATION = 0x68; - public static final byte RESOURCE_OBJECT_INCLUDE = 0x6C; - public static final byte PRESENTATION_SPACE_RESET_MIXING = 0x70; - public static final byte PRESENTATION_SPACE_MIXING_RULE = 0x71; - public static final byte UNIVERSAL_DATE_AND_TIMESTAMP = 0x72; - public static final byte TONER_SAVER = 0x74; - public static final byte COLOR_FIDELITY = 0x75; - public static final byte FONT_FIDELITY = 0x78; - public static final byte ATTRIBUTE_QUALIFIER = (byte)0x80; - public static final byte PAGE_POSITION_INFORMATION = (byte)0x81; - public static final byte PARAMETER_VALUE = (byte)0x82; - public static final byte PRESENTATION_CONTROL = (byte)0x83; - public static final byte FONT_RESOLUTION_AND_METRIC_TECHNOLOGY = (byte)0x84; - public static final byte FINISHING_OPERATION = (byte)0x85; - public static final byte TEXT_FIDELITY = (byte)0x86; - public static final byte MEDIA_FIDELITY = (byte)0x87; - public static final byte FINISHING_FIDELITY = (byte)0x88; - public static final byte DATA_OBJECT_FONT_DESCRIPTOR = (byte)0x8B; - public static final byte LOCALE_SELECTOR = (byte)0x8C; - public static final byte UP3I_FINISHING_OPERATION = (byte)0x8E; - public static final byte COLOR_MANAGEMENT_RESOURCE_DESCRIPTOR = (byte)0x91; - public static final byte RENDERING_INTENT = (byte)0x95; - public static final byte CMR_TAG_FIDELITY = (byte)0x96; - public static final byte DEVICE_APPEARANCE = (byte)0x97; - - /** the triplet identifier */ - private final byte id; - - /** the triplet's data contents */ - private byte[] data; - - /** - * Main constructor - * - * @param id the triplet identifier (see static definitions above) - * @param data the data item contained in this triplet - */ - public Triplet(byte id, byte[] data) { - this(id); - setData(data); - } - - /** - * Constructor - * - * @param id the triplet identifier (see static definitions above) - */ - public Triplet(byte id) { - this.id = id; - } - - /** - * Constructor - * - * @param id the triplet identifier (see static definitions above) - * @param content the content byte data - */ - public Triplet(byte id, byte content) { - this(id, new byte[] {content}); - } - - /** - * Constructor - * - * @param id the triplet identifier (see static definitions above) - * @param data the data item (in String form) contained in this triplet - * @throws UnsupportedEncodingException EBCIDIC encoding is not supported - */ - public Triplet(byte id, String data) throws UnsupportedEncodingException { - this(id, data.getBytes(AFPConstants.EBCIDIC_ENCODING)); - } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - os.write((byte)data.length + 2); - os.write(id); - os.write(data); - } - - /** - * Returns the triplet identifier - * - * @return the triplet identifier - */ - public byte getId() { - return this.id; - } - - /** - * Sets the data contents of this triplet - * - * @param data the data contents - */ - protected void setData(byte[] data) { - this.data = data; - } -} diff --git a/src/java/org/apache/fop/afp/svg/AFPGraphicsConfiguration.java b/src/java/org/apache/fop/afp/svg/AFPGraphicsConfiguration.java new file mode 100644 index 000000000..76d6396e3 --- /dev/null +++ b/src/java/org/apache/fop/afp/svg/AFPGraphicsConfiguration.java @@ -0,0 +1,150 @@ +/* + * 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.afp.svg; + +import java.awt.GraphicsDevice; +import java.awt.Rectangle; +import java.awt.Transparency; +import java.awt.geom.AffineTransform; +import java.awt.image.BufferedImage; +import java.awt.image.ColorModel; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.fop.svg.GraphicsConfiguration; + +/** + * Our implementation of the class that returns information about + * roughly what we can handle and want to see (alpha for example). + */ +public class AFPGraphicsConfiguration extends GraphicsConfiguration { + // We use this to get a good colormodel.. + private static final BufferedImage BI_WITH_ALPHA + = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); + // We use this to get a good colormodel.. + private static final BufferedImage BI_WITHOUT_ALPHA + = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); + + /** + * Construct a buffered image with an alpha channel, unless + * transparencty is OPAQUE (no alpha at all). + * + * @param width the width of the image + * @param height the height of the image + * @param transparency the alpha value of the image + * @return the new buffered image + */ + public BufferedImage createCompatibleImage(int width, int height, + int transparency) { + if (transparency == Transparency.OPAQUE) { + return new BufferedImage(width, height, + BufferedImage.TYPE_INT_RGB); + } else { + return new BufferedImage(width, height, + BufferedImage.TYPE_INT_ARGB); + } + } + + /** + * Construct a buffered image with an alpha channel. + * + * @param width the width of the image + * @param height the height of the image + * @return the new buffered image + */ + public BufferedImage createCompatibleImage(int width, int height) { + return new BufferedImage(width, height, + BufferedImage.TYPE_INT_ARGB); + } + + /** + * TODO: This should return the page bounds in Pts, + * I couldn't figure out how to get this for the current + * page (this still works for now, + * but it should be fixed...). + * + * @return the bounds of the page + */ + public Rectangle getBounds() { + return null; + } + + /** + * Return a good default color model for this 'device'. + * @return the colour model for the configuration + */ + public ColorModel getColorModel() { + return BI_WITH_ALPHA.getColorModel(); + } + + /** + * Return a good color model given transparency + * + * @param transparency the alpha value for the colour model + * @return the colour model for the configuration + */ + public ColorModel getColorModel(int transparency) { + if (transparency == Transparency.OPAQUE) { + return BI_WITHOUT_ALPHA.getColorModel(); + } else { + return BI_WITH_ALPHA.getColorModel(); + } + } + + private static final Log log = LogFactory.getLog(AFPGraphicsConfiguration.class); + + private AffineTransform defaultTransform = null; + private AffineTransform normalizingTransform = null; + private final GraphicsDevice graphicsDevice = new AFPGraphicsDevice(this);; + + /** + * The default transform (1:1). + * + * @return the default transform for the configuration + */ + public AffineTransform getDefaultTransform() { + log.debug("getDefaultTransform()"); + if (defaultTransform == null) { + defaultTransform = new AffineTransform(); + } + return defaultTransform; + } + + /** + * The normalizing transform (1:1) (since we currently + * render images at 72dpi, which we might want to change + * in the future). + * + * @return the normalizing transform for the configuration + */ + public AffineTransform getNormalizingTransform() { + log.debug("getNormalizingTransform()"); + if (normalizingTransform == null) { + normalizingTransform = new AffineTransform(2, 0, 0, 2, 0, 0); + } + return normalizingTransform; + } + + /** {@inheritDoc} */ + public GraphicsDevice getDevice() { + log.debug("getDevice()"); + return graphicsDevice; + } +} diff --git a/src/java/org/apache/fop/afp/svg/AFPGraphicsDevice.java b/src/java/org/apache/fop/afp/svg/AFPGraphicsDevice.java new file mode 100644 index 000000000..daa25aaa0 --- /dev/null +++ b/src/java/org/apache/fop/afp/svg/AFPGraphicsDevice.java @@ -0,0 +1,80 @@ +/* + * 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.afp.svg; + +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; + +/** + * This implements the GraphicsDevice interface as appropriate for + * an AFPGraphics2D. + */ +public class AFPGraphicsDevice extends GraphicsDevice { + + /** + * The Graphics Config that created us... + */ + protected GraphicsConfiguration gc; + + /** + * Create a new AF{ graphics device. + * + * @param gc The graphics configuration we should reference + */ + public AFPGraphicsDevice(AFPGraphicsConfiguration gc) { + this.gc = gc; + } + + /** + * Return an array of our one GraphicsConfig + * + * @return an array containing the one graphics configuration + */ + public GraphicsConfiguration[] getConfigurations() { + return new GraphicsConfiguration[] {gc}; + } + + /** + * Return out sole GraphicsConfig. + * + * @return the graphics configuration that created this object + */ + public GraphicsConfiguration getDefaultConfiguration() { + return this.gc; + } + + /** + * Generate an IdString.. + * + * @return the ID string for this device, uses toString + */ + public String getIDstring() { + return toString(); + } + + /** + * Let the caller know that we are "a printer" + * + * @return the type which is always printer + */ + public int getType() { + return GraphicsDevice.TYPE_PRINTER; + } +} diff --git a/src/java/org/apache/fop/svg/PDFGraphics2D.java b/src/java/org/apache/fop/svg/PDFGraphics2D.java index f8a0bd415..ab0ece2a7 100644 --- a/src/java/org/apache/fop/svg/PDFGraphics2D.java +++ b/src/java/org/apache/fop/svg/PDFGraphics2D.java @@ -101,7 +101,6 @@ import org.apache.xmlgraphics.java2d.GraphicContext; * @see org.apache.batik.ext.awt.g2d.AbstractGraphics2D */ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHandler { - private static final AffineTransform IDENTITY_TRANSFORM = new AffineTransform(); /** The number of decimal places. */ -- cgit v1.2.3 From 8a08b69ee6049677c1578a9c0791140caf6a1d6a Mon Sep 17 00:00:00 2001 From: Adrian Cumiskey Date: Thu, 20 Nov 2008 16:38:44 +0000 Subject: SetCurrentPosition fix for line drawing. AbstractPaintingState push(), pushAll(), pop(), popAll() renamed to save(), saveAll() and restore(), restoreAll(). Some Javadoc improvements/updates. Added Completable, Startable object writing interfaces. StructuredDataObject interface renamed to StructuredData. High level DataStream class moved from afp.modca to afp package. Graphics*Relative objects removed and feature provided by absolute implementation. GraphicsArea broken into GraphicsAreaBegin and GraphicsAreaEnd since areas are able to span more than one segment. Improvement in SetLineWidth thickness precision. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@719274 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/afp/AFPBorderPainter.java | 19 +- .../org/apache/fop/afp/AFPDataObjectFactory.java | 3 + src/java/org/apache/fop/afp/AFPGraphics2D.java | 156 ++++-- src/java/org/apache/fop/afp/AFPPaintingState.java | 19 +- .../org/apache/fop/afp/AFPRectanglePainter.java | 24 +- .../org/apache/fop/afp/AFPResourceManager.java | 1 - src/java/org/apache/fop/afp/AFPStreamer.java | 1 - src/java/org/apache/fop/afp/AFPUnitConverter.java | 14 +- .../org/apache/fop/afp/AbstractAFPPainter.java | 16 +- src/java/org/apache/fop/afp/BorderPaintInfo.java | 121 ----- .../org/apache/fop/afp/BorderPaintingInfo.java | 121 +++++ src/java/org/apache/fop/afp/Completable.java | 40 ++ src/java/org/apache/fop/afp/DataStream.java | 600 +++++++++++++++++++++ src/java/org/apache/fop/afp/Factory.java | 9 +- src/java/org/apache/fop/afp/PaintInfo.java | 27 - src/java/org/apache/fop/afp/PaintingInfo.java | 27 + .../org/apache/fop/afp/RectanglePaintInfo.java | 84 --- .../org/apache/fop/afp/RectanglePaintingInfo.java | 84 +++ src/java/org/apache/fop/afp/Startable.java | 40 ++ src/java/org/apache/fop/afp/StructuredData.java | 33 ++ .../apache/fop/afp/goca/AbstractGraphicsCoord.java | 59 +- .../fop/afp/goca/AbstractGraphicsDrawingOrder.java | 60 +++ .../AbstractGraphicsDrawingOrderContainer.java | 158 ++++++ .../afp/goca/AbstractGraphicsObjectContainer.java | 83 --- .../fop/afp/goca/AbstractGraphicsString.java | 74 --- src/java/org/apache/fop/afp/goca/GraphicsArea.java | 74 --- .../org/apache/fop/afp/goca/GraphicsAreaBegin.java | 69 +++ .../org/apache/fop/afp/goca/GraphicsAreaEnd.java | 53 ++ .../fop/afp/goca/GraphicsChainedSegment.java | 60 +-- .../fop/afp/goca/GraphicsCharacterString.java | 114 ++++ src/java/org/apache/fop/afp/goca/GraphicsData.java | 89 ++- .../org/apache/fop/afp/goca/GraphicsFillet.java | 11 +- .../fop/afp/goca/GraphicsFilletRelative.java | 42 -- .../org/apache/fop/afp/goca/GraphicsImage.java | 37 +- src/java/org/apache/fop/afp/goca/GraphicsLine.java | 20 +- .../apache/fop/afp/goca/GraphicsLineRelative.java | 42 -- .../fop/afp/goca/GraphicsSetCharacterSet.java | 12 +- .../apache/fop/afp/goca/GraphicsSetLineType.java | 13 +- .../apache/fop/afp/goca/GraphicsSetLineWidth.java | 12 +- .../org/apache/fop/afp/goca/GraphicsSetMix.java | 17 +- .../fop/afp/goca/GraphicsSetPatternSymbol.java | 23 +- .../fop/afp/goca/GraphicsSetProcessColor.java | 6 +- .../org/apache/fop/afp/goca/GraphicsString.java | 64 --- .../fop/afp/goca/GraphicsStringRelative.java | 57 -- .../org/apache/fop/afp/ioca/ImageCellPosition.java | 27 +- src/java/org/apache/fop/afp/ioca/ImageContent.java | 28 +- .../apache/fop/afp/ioca/ImageInputDescriptor.java | 5 +- .../apache/fop/afp/ioca/ImageOutputControl.java | 8 +- .../org/apache/fop/afp/ioca/ImageRasterData.java | 7 +- .../apache/fop/afp/modca/AbstractAFPObject.java | 12 +- .../apache/fop/afp/modca/AbstractDataObject.java | 35 +- .../fop/afp/modca/AbstractNamedAFPObject.java | 13 +- .../apache/fop/afp/modca/AbstractPageObject.java | 24 +- .../afp/modca/AbstractResourceGroupContainer.java | 5 +- .../afp/modca/AbstractTripletStructuredObject.java | 3 + src/java/org/apache/fop/afp/modca/DataStream.java | 593 -------------------- src/java/org/apache/fop/afp/modca/Document.java | 6 +- .../org/apache/fop/afp/modca/GraphicsObject.java | 178 +++--- .../org/apache/fop/afp/modca/MapCodedFont.java | 6 +- .../fop/afp/modca/ObjectEnvironmentGroup.java | 8 +- src/java/org/apache/fop/afp/modca/PageGroup.java | 2 +- .../fop/afp/modca/ResourceEnvironmentGroup.java | 54 +- .../fop/afp/modca/StreamedResourceGroup.java | 24 +- .../apache/fop/afp/modca/StructuredDataObject.java | 33 -- .../fop/afp/modca/triplets/AbstractTriplet.java | 4 +- .../modca/triplets/DescriptorPositionTriplet.java | 3 + .../modca/triplets/ResourceObjectTypeTriplet.java | 2 +- .../org/apache/fop/afp/svg/AFPBridgeContext.java | 3 + .../apache/fop/afp/svg/AFPImageElementBridge.java | 3 + src/java/org/apache/fop/afp/svg/package.html | 23 + src/java/org/apache/fop/afp/util/package.html | 23 + src/java/org/apache/fop/pdf/PDFPaintingState.java | 2 +- .../fop/render/afp/AFPGraphics2DAdapter.java | 4 +- src/java/org/apache/fop/render/afp/AFPInfo.java | 6 +- .../org/apache/fop/render/afp/AFPRenderer.java | 20 +- .../org/apache/fop/render/afp/AFPSVGHandler.java | 4 +- .../org/apache/fop/render/pdf/PDFRenderer.java | 10 +- .../org/apache/fop/render/pdf/PDFSVGHandler.java | 4 +- .../apache/fop/svg/AbstractFOPBridgeContext.java | 3 + src/java/org/apache/fop/svg/PDFGraphics2D.java | 12 +- .../org/apache/fop/util/AbstractPaintingState.java | 29 +- 81 files changed, 2089 insertions(+), 1825 deletions(-) delete mode 100644 src/java/org/apache/fop/afp/BorderPaintInfo.java create mode 100644 src/java/org/apache/fop/afp/BorderPaintingInfo.java create mode 100644 src/java/org/apache/fop/afp/Completable.java create mode 100644 src/java/org/apache/fop/afp/DataStream.java delete mode 100644 src/java/org/apache/fop/afp/PaintInfo.java create mode 100644 src/java/org/apache/fop/afp/PaintingInfo.java delete mode 100644 src/java/org/apache/fop/afp/RectanglePaintInfo.java create mode 100644 src/java/org/apache/fop/afp/RectanglePaintingInfo.java create mode 100644 src/java/org/apache/fop/afp/Startable.java create mode 100644 src/java/org/apache/fop/afp/StructuredData.java create mode 100644 src/java/org/apache/fop/afp/goca/AbstractGraphicsDrawingOrder.java create mode 100644 src/java/org/apache/fop/afp/goca/AbstractGraphicsDrawingOrderContainer.java delete mode 100644 src/java/org/apache/fop/afp/goca/AbstractGraphicsObjectContainer.java delete mode 100644 src/java/org/apache/fop/afp/goca/AbstractGraphicsString.java delete mode 100644 src/java/org/apache/fop/afp/goca/GraphicsArea.java create mode 100644 src/java/org/apache/fop/afp/goca/GraphicsAreaBegin.java create mode 100644 src/java/org/apache/fop/afp/goca/GraphicsAreaEnd.java create mode 100644 src/java/org/apache/fop/afp/goca/GraphicsCharacterString.java delete mode 100644 src/java/org/apache/fop/afp/goca/GraphicsFilletRelative.java delete mode 100644 src/java/org/apache/fop/afp/goca/GraphicsLineRelative.java delete mode 100644 src/java/org/apache/fop/afp/goca/GraphicsString.java delete mode 100644 src/java/org/apache/fop/afp/goca/GraphicsStringRelative.java delete mode 100644 src/java/org/apache/fop/afp/modca/DataStream.java delete mode 100644 src/java/org/apache/fop/afp/modca/StructuredDataObject.java create mode 100644 src/java/org/apache/fop/afp/svg/package.html create mode 100644 src/java/org/apache/fop/afp/util/package.html (limited to 'src/java/org/apache/fop/afp/goca/GraphicsSetCharacterSet.java') diff --git a/src/java/org/apache/fop/afp/AFPBorderPainter.java b/src/java/org/apache/fop/afp/AFPBorderPainter.java index 86960b7ff..4c56c0def 100644 --- a/src/java/org/apache/fop/afp/AFPBorderPainter.java +++ b/src/java/org/apache/fop/afp/AFPBorderPainter.java @@ -21,7 +21,6 @@ package org.apache.fop.afp; import java.awt.geom.AffineTransform; -import org.apache.fop.afp.modca.DataStream; import org.apache.fop.fo.Constants; import org.apache.fop.util.ColorUtil; @@ -33,16 +32,16 @@ public class AFPBorderPainter extends AbstractAFPPainter { /** * Main constructor * - * @param state the AFP painting state converter + * @param paintingState the AFP painting state converter * @param dataStream the AFP datastream */ - public AFPBorderPainter(AFPPaintingState state, DataStream dataStream) { - super(state, dataStream); + public AFPBorderPainter(AFPPaintingState paintingState, DataStream dataStream) { + super(paintingState, dataStream); } /** {@inheritDoc} */ - public void paint(PaintInfo paintInfo) { - BorderPaintInfo borderPaintInfo = (BorderPaintInfo)paintInfo; + public void paint(PaintingInfo paintInfo) { + BorderPaintingInfo borderPaintInfo = (BorderPaintingInfo)paintInfo; float w = borderPaintInfo.getX2() - borderPaintInfo.getX1(); float h = borderPaintInfo.getY2() - borderPaintInfo.getY1(); if ((w < 0) || (h < 0)) { @@ -52,15 +51,15 @@ public class AFPBorderPainter extends AbstractAFPPainter { int pageWidth = dataStream.getCurrentPage().getWidth(); int pageHeight = dataStream.getCurrentPage().getHeight(); - AFPUnitConverter unitConv = state.getUnitConverter(); - AffineTransform at = state.getData().getTransform(); + AFPUnitConverter unitConv = paintingState.getUnitConverter(); + AffineTransform at = paintingState.getData().getTransform(); float x1 = unitConv.pt2units(borderPaintInfo.getX1()); float y1 = unitConv.pt2units(borderPaintInfo.getY1()); float x2 = unitConv.pt2units(borderPaintInfo.getX2()); float y2 = unitConv.pt2units(borderPaintInfo.getY2()); - switch (state.getRotation()) { + switch (paintingState.getRotation()) { case 0: x1 += at.getTranslateX(); y1 += at.getTranslateY(); @@ -89,7 +88,7 @@ public class AFPBorderPainter extends AbstractAFPPainter { AFPLineDataInfo lineDataInfo = new AFPLineDataInfo(); lineDataInfo.setColor(borderPaintInfo.getColor()); - lineDataInfo.setRotation(state.getRotation()); + lineDataInfo.setRotation(paintingState.getRotation()); lineDataInfo.x1 = Math.round(x1); lineDataInfo.y1 = Math.round(y1); if (borderPaintInfo.isHorizontal()) { diff --git a/src/java/org/apache/fop/afp/AFPDataObjectFactory.java b/src/java/org/apache/fop/afp/AFPDataObjectFactory.java index c333f5987..5463a336b 100644 --- a/src/java/org/apache/fop/afp/AFPDataObjectFactory.java +++ b/src/java/org/apache/fop/afp/AFPDataObjectFactory.java @@ -132,8 +132,11 @@ public class AFPDataObjectFactory { Rectangle2D area = graphicsObjectInfo.getArea(); g2d.scale(1, -1); g2d.translate(0, -area.getHeight()); + painter.paint(g2d, area); + graphicsObj.setComplete(true); + // return painted graphics object return graphicsObj; } diff --git a/src/java/org/apache/fop/afp/AFPGraphics2D.java b/src/java/org/apache/fop/afp/AFPGraphics2D.java index 0a8161a3b..e8eebce43 100644 --- a/src/java/org/apache/fop/afp/AFPGraphics2D.java +++ b/src/java/org/apache/fop/afp/AFPGraphics2D.java @@ -28,9 +28,11 @@ import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.GraphicsConfiguration; import java.awt.Image; +import java.awt.Paint; import java.awt.Rectangle; import java.awt.Shape; import java.awt.Stroke; +import java.awt.TexturePaint; import java.awt.geom.AffineTransform; import java.awt.geom.Ellipse2D; import java.awt.geom.Line2D; @@ -83,6 +85,9 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand private static final int Y2 = 3; + private static final int X3 = 4; + + private static final int Y3 = 5; /** graphics object */ private GraphicsObject graphicsObj = null; @@ -188,7 +193,7 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand // set line width float lineWidth = basicStroke.getLineWidth(); - getGraphicsObject().setLineWidth(Math.round(lineWidth * 2)); + graphicsObj.setLineWidth(Math.round(lineWidth / 2)); // set line type/style (note: this is an approximation at best!) float[] dashArray = basicStroke.getDashArray(); @@ -219,13 +224,40 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand } } } - getGraphicsObject().setLineType(type); + graphicsObj.setLineType(type); } } else { log.warn("Unsupported Stroke: " + stroke.getClass().getName()); } } + /** + * Apply the java paint to the AFP. + * This takes the java paint sets up the appropriate AFP commands + * for the drawing with that paint. + * Currently this supports the gradients and patterns from batik. + * + * @param paint the paint to convert to AFP + * @param fill true if the paint should be set for filling + * @return true if the paint is handled natively, false if the paint should be rasterized + */ + private boolean applyPaint(Paint paint, boolean fill) { + if (paint instanceof Color) { + return true; + } + log.debug("NYI: applyPaint() " + paint + " fill=" + fill); + if (paint instanceof TexturePaint) { +// TexturePaint texturePaint = (TexturePaint)paint; +// BufferedImage bufferedImage = texturePaint.getImage(); +// AffineTransform at = paintingState.getTransform(); +// int x = (int)Math.round(at.getTranslateX()); +// int y = (int)Math.round(at.getTranslateY()); +// drawImage(bufferedImage, x, y, null); + } + return false; + } + + /** * Handle the Batik drawing event * @@ -239,25 +271,22 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand graphicsObj.newSegment(); } - Color color = getColor(); - if (paintingState.setColor(color)) { - graphicsObj.setColor(color); - } + graphicsObj.setColor(gc.getColor()); - Stroke stroke = getStroke(); - applyStroke(stroke); + applyPaint(gc.getPaint(), fill); if (fill) { graphicsObj.beginArea(); + } else { + applyStroke(gc.getStroke()); } AffineTransform trans = gc.getTransform(); PathIterator iter = shape.getPathIterator(trans); - double[] dstPts = new double[6]; - int[] coords = null; if (shape instanceof Line2D) { + double[] dstPts = new double[6]; iter.currentSegment(dstPts); - coords = new int[4]; + int[] coords = new int[4]; coords[X1] = (int) Math.round(dstPts[X]); coords[Y1] = (int) Math.round(dstPts[Y]); iter.next(); @@ -266,8 +295,9 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand coords[Y2] = (int) Math.round(dstPts[Y]); graphicsObj.addLine(coords); } else if (shape instanceof Rectangle2D) { + double[] dstPts = new double[6]; iter.currentSegment(dstPts); - coords = new int[4]; + int[] coords = new int[4]; coords[X2] = (int) Math.round(dstPts[X]); coords[Y2] = (int) Math.round(dstPts[Y]); iter.next(); @@ -277,6 +307,7 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand coords[Y1] = (int) Math.round(dstPts[Y]); graphicsObj.addBox(coords); } else if (shape instanceof Ellipse2D) { + double[] dstPts = new double[6]; Ellipse2D elip = (Ellipse2D) shape; double scale = trans.getScaleX(); double radiusWidth = elip.getWidth() / 2; @@ -298,56 +329,73 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand mhr ); } else { - for (int[] openingCoords = new int[2]; !iter.isDone(); iter.next()) { - int type = iter.currentSegment(dstPts); - int numCoords; - if (type == PathIterator.SEG_MOVETO || type == PathIterator.SEG_LINETO) { - numCoords = 2; - } else if (type == PathIterator.SEG_QUADTO) { - numCoords = 4; - } else if (type == PathIterator.SEG_CUBICTO) { - numCoords = 6; - } else { - // close of the graphics segment - if (type == PathIterator.SEG_CLOSE) { - // close segment by drawing to opening position - graphicsObj.addLine(openingCoords, true); - } else { - log.debug("Unrecognised path iterator type: " - + type); - } - continue; - } - coords = new int[numCoords]; - for (int i = 0; i < numCoords; i++) { - coords[i] = (int) Math.round(dstPts[i]); - } - if (type == PathIterator.SEG_MOVETO) { - graphicsObj.setCurrentPosition(coords); - openingCoords[X] = coords[X]; - openingCoords[Y] = coords[Y]; - } else if (type == PathIterator.SEG_LINETO) { - graphicsObj.addLine(coords, true); - } else if (type == PathIterator.SEG_QUADTO - || type == PathIterator.SEG_CUBICTO) { - graphicsObj.addFillet(coords, true); - } - } + processPathIterator(iter); } + if (fill) { graphicsObj.endArea(); } } + /** + * Processes a path iterator generating the necessary painting operations. + * + * @param iter PathIterator to process + */ + private void processPathIterator(PathIterator iter) { + double[] dstPts = new double[6]; + for (int[] openingCoords = new int[2]; !iter.isDone(); iter.next()) { + switch (iter.currentSegment(dstPts)) { + case PathIterator.SEG_LINETO: + graphicsObj.addLine(new int[] { + (int)Math.round(dstPts[X]), + (int)Math.round(dstPts[Y]) + }, true); + break; + case PathIterator.SEG_QUADTO: + graphicsObj.addFillet(new int[] { + (int)Math.round(dstPts[X1]), + (int)Math.round(dstPts[Y1]), + (int)Math.round(dstPts[X2]), + (int)Math.round(dstPts[Y2]) + }, true); + break; + case PathIterator.SEG_CUBICTO: + graphicsObj.addFillet(new int[] { + (int)Math.round(dstPts[X1]), + (int)Math.round(dstPts[Y1]), + (int)Math.round(dstPts[X2]), + (int)Math.round(dstPts[Y2]), + (int)Math.round(dstPts[X3]), + (int)Math.round(dstPts[Y3]) + }, true); + break; + case PathIterator.SEG_MOVETO: + openingCoords = new int[] { + (int)Math.round(dstPts[X]), + (int)Math.round(dstPts[Y]) + }; + graphicsObj.setCurrentPosition(openingCoords); + break; + case PathIterator.SEG_CLOSE: + graphicsObj.addLine(openingCoords, true); + break; + default: + log.debug("Unrecognised path iterator type"); + break; + } + } + } + /** {@inheritDoc} */ public void draw(Shape shape) { -// log.debug("draw() shape=" + shape); + log.debug("draw() shape=" + shape); doDrawing(shape, false); } /** {@inheritDoc} */ public void fill(Shape shape) { -// log.debug("fill() shape=" + shape); + log.debug("fill() shape=" + shape); doDrawing(shape, true); } @@ -381,11 +429,6 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand return graphicsConfig; } - /** {@inheritDoc} */ - public void copyArea(int x, int y, int width, int height, int dx, int dy) { - log.debug("copyArea() NYI: "); - } - /** {@inheritDoc} */ public Graphics create() { return new AFPGraphics2D(this); @@ -643,4 +686,9 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand log.debug("NYI: addNativeImage() "+ "image=" + image + ",x=" + x + ",y=" + y + ",width=" + width + ",height=" + height); } + + /** {@inheritDoc} */ + public void copyArea(int x, int y, int width, int height, int dx, int dy) { + log.debug("copyArea() NYI: "); + } } diff --git a/src/java/org/apache/fop/afp/AFPPaintingState.java b/src/java/org/apache/fop/afp/AFPPaintingState.java index cb78fb36e..bf710b18d 100644 --- a/src/java/org/apache/fop/afp/AFPPaintingState.java +++ b/src/java/org/apache/fop/afp/AFPPaintingState.java @@ -27,7 +27,8 @@ import org.apache.fop.util.AbstractPaintingState; /** * This keeps information about the current painting state when writing to an AFP datastream. */ -public class AFPPaintingState extends org.apache.fop.util.AbstractPaintingState implements Cloneable { +public class AFPPaintingState extends org.apache.fop.util.AbstractPaintingState +implements Cloneable { private static final long serialVersionUID = 8206711712452344473L; @@ -337,14 +338,14 @@ public class AFPPaintingState extends org.apache.fop.util.AbstractPaintingState /** {@inheritDoc} */ public Object clone() { - AFPPaintingState state = (AFPPaintingState)super.clone(); - state.pagePaintingState = (AFPPagePaintingState)this.pagePaintingState.clone(); - state.portraitRotation = this.portraitRotation; - state.landscapeRotation = this.landscapeRotation; - state.bitsPerPixel = this.bitsPerPixel; - state.colorImages = this.colorImages; - state.resolution = this.resolution; - return state; + AFPPaintingState paintingState = (AFPPaintingState)super.clone(); + paintingState.pagePaintingState = (AFPPagePaintingState)this.pagePaintingState.clone(); + paintingState.portraitRotation = this.portraitRotation; + paintingState.landscapeRotation = this.landscapeRotation; + paintingState.bitsPerPixel = this.bitsPerPixel; + paintingState.colorImages = this.colorImages; + paintingState.resolution = this.resolution; + return paintingState; } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/afp/AFPRectanglePainter.java b/src/java/org/apache/fop/afp/AFPRectanglePainter.java index 81915a190..e2bad6159 100644 --- a/src/java/org/apache/fop/afp/AFPRectanglePainter.java +++ b/src/java/org/apache/fop/afp/AFPRectanglePainter.java @@ -21,37 +21,39 @@ package org.apache.fop.afp; import java.awt.geom.AffineTransform; -import org.apache.fop.afp.modca.DataStream; +/** + * A painter of rectangles in AFP + */ public class AFPRectanglePainter extends AbstractAFPPainter { /** * Main constructor * - * @param state the AFP painting state - * @param dataStream the afp datastream + * @param paintingState the AFP painting state + * @param dataStream the AFP datastream */ - public AFPRectanglePainter(AFPPaintingState state, DataStream dataStream) { - super(state, dataStream); + public AFPRectanglePainter(AFPPaintingState paintingState, DataStream dataStream) { + super(paintingState, dataStream); } /** {@inheritDoc} */ - public void paint(PaintInfo paintInfo) { - RectanglePaintInfo rectanglePaintInfo = (RectanglePaintInfo)paintInfo; + public void paint(PaintingInfo paintInfo) { + RectanglePaintingInfo rectanglePaintInfo = (RectanglePaintingInfo)paintInfo; int pageWidth = dataStream.getCurrentPage().getWidth(); int pageHeight = dataStream.getCurrentPage().getHeight(); - AFPUnitConverter unitConv = state.getUnitConverter(); + AFPUnitConverter unitConv = paintingState.getUnitConverter(); float width = unitConv.pt2units(rectanglePaintInfo.getWidth()); float height = unitConv.pt2units(rectanglePaintInfo.getHeight()); float x = unitConv.pt2units(rectanglePaintInfo.getX()); float y = unitConv.pt2units(rectanglePaintInfo.getY()); - AffineTransform at = state.getData().getTransform(); + AffineTransform at = paintingState.getData().getTransform(); AFPLineDataInfo lineDataInfo = new AFPLineDataInfo(); - lineDataInfo.color = state.getColor(); - lineDataInfo.rotation = state.getRotation(); + lineDataInfo.color = paintingState.getColor(); + lineDataInfo.rotation = paintingState.getRotation(); lineDataInfo.thickness = Math.round(height); switch (lineDataInfo.rotation) { diff --git a/src/java/org/apache/fop/afp/AFPResourceManager.java b/src/java/org/apache/fop/afp/AFPResourceManager.java index 21de78250..ec5890e39 100644 --- a/src/java/org/apache/fop/afp/AFPResourceManager.java +++ b/src/java/org/apache/fop/afp/AFPResourceManager.java @@ -25,7 +25,6 @@ import java.util.Map; import org.apache.fop.afp.modca.AbstractDataObject; import org.apache.fop.afp.modca.AbstractNamedAFPObject; -import org.apache.fop.afp.modca.DataStream; import org.apache.fop.afp.modca.IncludeObject; import org.apache.fop.afp.modca.Registry; import org.apache.fop.afp.modca.ResourceGroup; diff --git a/src/java/org/apache/fop/afp/AFPStreamer.java b/src/java/org/apache/fop/afp/AFPStreamer.java index 269e6ae08..007259cd4 100644 --- a/src/java/org/apache/fop/afp/AFPStreamer.java +++ b/src/java/org/apache/fop/afp/AFPStreamer.java @@ -31,7 +31,6 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.fop.afp.modca.DataStream; import org.apache.fop.afp.modca.ResourceGroup; import org.apache.fop.afp.modca.StreamedResourceGroup; diff --git a/src/java/org/apache/fop/afp/AFPUnitConverter.java b/src/java/org/apache/fop/afp/AFPUnitConverter.java index c5f37d25f..3195ba70f 100644 --- a/src/java/org/apache/fop/afp/AFPUnitConverter.java +++ b/src/java/org/apache/fop/afp/AFPUnitConverter.java @@ -29,15 +29,15 @@ import java.awt.geom.AffineTransform; public class AFPUnitConverter { /** the AFP state */ - private final AFPPaintingState state; + private final AFPPaintingState paintingState; /** * Unit converter * - * @param state the AFP painting state + * @param paintingState the AFP painting state */ - public AFPUnitConverter(AFPPaintingState state) { - this.state = state; + public AFPUnitConverter(AFPPaintingState paintingState) { + this.paintingState = paintingState; } /** @@ -89,7 +89,7 @@ public class AFPUnitConverter { * @return transformed point */ public float pt2units(float pt) { - return pt / ((float)AFPConstants.DPI_72 / state.getResolution()); + return pt / ((float)AFPConstants.DPI_72 / paintingState.getResolution()); } /** @@ -99,14 +99,14 @@ public class AFPUnitConverter { * @return transformed point */ public float mpt2units(float mpt) { - return mpt / ((float)AFPConstants.DPI_72_MPTS / state.getResolution()); + return mpt / ((float)AFPConstants.DPI_72_MPTS / paintingState.getResolution()); } private int[] transformPoints(float[] srcPts, float[] dstPts, boolean milli) { if (dstPts == null) { dstPts = new float[srcPts.length]; } - AffineTransform at = state.getData().getTransform(); + AffineTransform at = paintingState.getData().getTransform(); at.transform(srcPts, 0, dstPts, 0, srcPts.length / 2); int[] coords = new int[srcPts.length]; for (int i = 0; i < srcPts.length; i++) { diff --git a/src/java/org/apache/fop/afp/AbstractAFPPainter.java b/src/java/org/apache/fop/afp/AbstractAFPPainter.java index 72c6c56e1..576b8bb11 100644 --- a/src/java/org/apache/fop/afp/AbstractAFPPainter.java +++ b/src/java/org/apache/fop/afp/AbstractAFPPainter.java @@ -21,24 +21,26 @@ package org.apache.fop.afp; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.fop.afp.modca.DataStream; +/** + * A base AFP painter + */ public abstract class AbstractAFPPainter { /** Static logging instance */ protected static Log log = LogFactory.getLog("org.apache.xmlgraphics.afp"); protected final DataStream dataStream; - protected final AFPPaintingState state; + protected final AFPPaintingState paintingState; /** * Main constructor * - * @param state the afp state - * @param dataStream the afp datastream + * @param paintingState the AFP painting state + * @param dataStream the AFP Datastream */ - public AbstractAFPPainter(AFPPaintingState state, DataStream dataStream) { - this.state = state; + public AbstractAFPPainter(AFPPaintingState paintingState, DataStream dataStream) { + this.paintingState = paintingState; this.dataStream = dataStream; } @@ -47,5 +49,5 @@ public abstract class AbstractAFPPainter { * * @param paintInfo the painting information */ - public abstract void paint(PaintInfo paintInfo); + public abstract void paint(PaintingInfo paintInfo); } diff --git a/src/java/org/apache/fop/afp/BorderPaintInfo.java b/src/java/org/apache/fop/afp/BorderPaintInfo.java deleted file mode 100644 index 74252b7b9..000000000 --- a/src/java/org/apache/fop/afp/BorderPaintInfo.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * 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.afp; - -import java.awt.Color; - - -/** - * Border painting information - */ -public class BorderPaintInfo implements PaintInfo { - private final float x1; - private final float y1; - private final float x2; - private final float y2; - private final boolean isHorizontal; - private final int style; - private final Color color; - - /** - * Main constructor - * - * @param x1 the x1 coordinate - * @param y1 the y1 coordinate - * @param x2 the x2 coordinate - * @param y2 the y2 coordinate - * @param isHorizontal true when the border line is horizontal - * @param style the border style - * @param color the border color - */ - public BorderPaintInfo(float x1, float y1, float x2, float y2, - boolean isHorizontal, int style, Color color) { - this.x1 = x1; - this.y1 = y1; - this.x2 = x2; - this.y2 = y2; - this.isHorizontal = isHorizontal; - this.style = style; - this.color = color; - } - - /** - * Returns the x1 coordinate - * - * @return the x1 coordinate - */ - public float getX1() { - return x1; - } - - /** - * Returns the y1 coordinate - * - * @return the y1 coordinate - */ - public float getY1() { - return y1; - } - - /** - * Returns the x2 coordinate - * - * @return the x2 coordinate - */ - public float getX2() { - return x2; - } - - /** - * Returns the y2 coordinate - * - * @return the y2 coordinate - */ - public float getY2() { - return y2; - } - - /** - * Returns true when this is a horizontal line - * - * @return true when this is a horizontal line - */ - public boolean isHorizontal() { - return isHorizontal; - } - - /** - * Returns the style - * - * @return the style - */ - public int getStyle() { - return style; - } - - /** - * Returns the color - * - * @return the color - */ - public Color getColor() { - return color; - } -} diff --git a/src/java/org/apache/fop/afp/BorderPaintingInfo.java b/src/java/org/apache/fop/afp/BorderPaintingInfo.java new file mode 100644 index 000000000..4917c7bc0 --- /dev/null +++ b/src/java/org/apache/fop/afp/BorderPaintingInfo.java @@ -0,0 +1,121 @@ +/* + * 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.afp; + +import java.awt.Color; + +/** + * Border painting information + */ +public class BorderPaintingInfo implements PaintingInfo { + + private final float x1; + private final float y1; + private final float x2; + private final float y2; + private final boolean isHorizontal; + private final int style; + private final Color color; + + /** + * Main constructor + * + * @param x1 the x1 coordinate + * @param y1 the y1 coordinate + * @param x2 the x2 coordinate + * @param y2 the y2 coordinate + * @param isHorizontal true when the border line is horizontal + * @param style the border style + * @param color the border color + */ + public BorderPaintingInfo(float x1, float y1, float x2, float y2, + boolean isHorizontal, int style, Color color) { + this.x1 = x1; + this.y1 = y1; + this.x2 = x2; + this.y2 = y2; + this.isHorizontal = isHorizontal; + this.style = style; + this.color = color; + } + + /** + * Returns the x1 coordinate + * + * @return the x1 coordinate + */ + public float getX1() { + return x1; + } + + /** + * Returns the y1 coordinate + * + * @return the y1 coordinate + */ + public float getY1() { + return y1; + } + + /** + * Returns the x2 coordinate + * + * @return the x2 coordinate + */ + public float getX2() { + return x2; + } + + /** + * Returns the y2 coordinate + * + * @return the y2 coordinate + */ + public float getY2() { + return y2; + } + + /** + * Returns true when this is a horizontal line + * + * @return true when this is a horizontal line + */ + public boolean isHorizontal() { + return isHorizontal; + } + + /** + * Returns the style + * + * @return the style + */ + public int getStyle() { + return style; + } + + /** + * Returns the color + * + * @return the color + */ + public Color getColor() { + return color; + } +} diff --git a/src/java/org/apache/fop/afp/Completable.java b/src/java/org/apache/fop/afp/Completable.java new file mode 100644 index 000000000..e1fc764dd --- /dev/null +++ b/src/java/org/apache/fop/afp/Completable.java @@ -0,0 +1,40 @@ +/* + * 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.afp; + +/** + * Set and expose the internal completeness of an object. + */ +public interface Completable { + + /** + * Sets whether or not this object is complete or not + * + * @param complete true if this object is complete + */ + void setComplete(boolean complete); + + /** + * Returns true if this object is complete + * + * @return true if this object is complete + */ + boolean isComplete(); +} diff --git a/src/java/org/apache/fop/afp/DataStream.java b/src/java/org/apache/fop/afp/DataStream.java new file mode 100644 index 000000000..34a7f0f9d --- /dev/null +++ b/src/java/org/apache/fop/afp/DataStream.java @@ -0,0 +1,600 @@ +/* + * 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.afp; + +import java.awt.Color; +import java.awt.Point; +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.afp.fonts.AFPFont; +import org.apache.fop.afp.fonts.AFPFontAttributes; +import org.apache.fop.afp.modca.AbstractPageObject; +import org.apache.fop.afp.modca.Document; +import org.apache.fop.afp.modca.InterchangeSet; +import org.apache.fop.afp.modca.Overlay; +import org.apache.fop.afp.modca.PageGroup; +import org.apache.fop.afp.modca.PageObject; +import org.apache.fop.afp.modca.ResourceGroup; +import org.apache.fop.afp.modca.TagLogicalElementBean; +import org.apache.fop.afp.modca.triplets.FullyQualifiedNameTriplet; + +/** + * A data stream is a continuous ordered stream of data elements and objects + * conforming to a given format. Application programs can generate data streams + * destined for a presentation service, archive library, presentation device or + * another application program. The strategic presentation data stream + * architectures used is Mixed Object Document Content Architecture (MO:DCA). + * + * The MO:DCA architecture defines the data stream used by applications to + * describe documents and object envelopes for interchange with other + * applications and application services. Documents defined in the MO:DCA format + * may be archived in a database, then later retrieved, viewed, annotated and + * printed in local or distributed systems environments. Presentation fidelity + * is accommodated by including resource objects in the documents that reference + * them. + */ +public class DataStream { + + /** Static logging instance */ + protected static final Log log = LogFactory.getLog("org.apache.xmlgraphics.afp"); + + /** Boolean completion indicator */ + private boolean complete = false; + + /** The AFP document object */ + private Document document = null; + + /** The current page group object */ + private PageGroup currentPageGroup = null; + + /** The current page object */ + private PageObject currentPageObject = null; + + /** The current overlay object */ + private Overlay currentOverlay = null; + + /** The current page */ + private AbstractPageObject currentPage = null; + + /** The MO:DCA interchange set in use (default to MO:DCA-P IS/2 set) */ + private InterchangeSet interchangeSet + = InterchangeSet.valueOf(InterchangeSet.MODCA_PRESENTATION_INTERCHANGE_SET_2); + + private final Factory factory; + + private OutputStream outputStream; + + /** the afp painting state */ + private final AFPPaintingState paintingState; + + /** + * Default constructor for the AFPDocumentStream. + * + * @param factory the resource factory + * @param paintingState the AFP painting state + * @param outputStream the outputstream to write to + */ + public DataStream(Factory factory, AFPPaintingState paintingState, OutputStream outputStream) { + this.paintingState = paintingState; + this.factory = factory; + this.outputStream = outputStream; + } + + /** + * Returns the outputstream + * + * @return the outputstream + */ + public OutputStream getOutputStream() { + return this.outputStream; + } + + /** + * Returns the document object + * + * @return the document object + */ + private Document getDocument() { + return this.document; + } + + /** + * Returns the current page + * + * @return the current page + */ + public AbstractPageObject getCurrentPage() { + return this.currentPage; + } + + /** + * The document is started by invoking this method which creates an instance + * of the AFP Document object. + * + * @param name + * the name of this document. + */ + public void setDocumentName(String name) { + if (name != null) { + getDocument().setFullyQualifiedName( + FullyQualifiedNameTriplet.TYPE_BEGIN_DOCUMENT_REF, + FullyQualifiedNameTriplet.FORMAT_CHARSTR, name); + } + } + + /** + * Helper method to mark the end of the current document. + * + * @throws IOException thrown if an I/O exception of some sort has occurred + */ + public void endDocument() throws IOException { + if (complete) { + String msg = "Invalid state - document already ended."; + log.warn("endDocument():: " + msg); + throw new IllegalStateException(msg); + } + + if (currentPageObject != null) { + // End the current page if necessary + endPage(); + } + + if (currentPageGroup != null) { + // End the current page group if necessary + endPageGroup(); + } + + // Write out document + if (document != null) { + document.endDocument(); + document.writeToStream(this.outputStream); + } + + this.outputStream.flush(); + + this.complete = true; + + this.document = null; + + this.outputStream = null; + } + + /** + * Start a new page. When processing has finished on the current page, the + * {@link #endPage()}method must be invoked to mark the page ending. + * + * @param pageWidth + * the width of the page + * @param pageHeight + * the height of the page + * @param pageRotation + * the rotation of the page + * @param pageWidthRes + * the width resolution of the page + * @param pageHeightRes + * the height resolution of the page + */ + public void startPage(int pageWidth, int pageHeight, int pageRotation, + int pageWidthRes, int pageHeightRes) { + currentPageObject = factory.createPage(pageWidth, pageHeight, + pageRotation, pageWidthRes, pageHeightRes); + currentPage = currentPageObject; + currentOverlay = null; + } + + /** + * Start a new overlay. When processing has finished on the current overlay, + * the {@link #endOverlay()}method must be invoked to mark the overlay + * ending. + * + * @param x + * the x position of the overlay on the page + * @param y + * the y position of the overlay on the page + * @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 + */ + public void startOverlay(int x, int y, int width, int height, int widthRes, + int heightRes, int overlayRotation) { + this.currentOverlay = factory.createOverlay( + width, height, widthRes, heightRes, overlayRotation); + + String overlayName = currentOverlay.getName(); + currentPageObject.createIncludePageOverlay(overlayName, x, y, 0); + currentPage = currentOverlay; + } + + /** + * Helper method to mark the end of the current overlay. + * + * @throws IOException thrown if an I/O exception of some sort has occurred + */ + public void endOverlay() throws IOException { + if (currentOverlay != null) { + currentOverlay.endPage(); + currentOverlay = null; + currentPage = currentPageObject; + } + } + + /** + * Helper method to save the current page. + * + * @return current page object that was saved + */ + public PageObject savePage() { + PageObject pageObject = currentPageObject; + if (currentPageGroup != null) { + currentPageGroup.addPage(currentPageObject); + } else { + document.addPage(currentPageObject); + } + currentPageObject = null; + currentPage = null; + return pageObject; + } + + /** + * Helper method to restore the current page. + * + * @param pageObject + * page object + */ + public void restorePage(PageObject pageObject) { + currentPageObject = pageObject; + currentPage = pageObject; + } + + /** + * Helper method to mark the end of the current page. + * + * @throws IOException thrown if an I/O exception of some sort has occurred + */ + public void endPage() throws IOException { + if (currentPageObject != null) { + currentPageObject.endPage(); + if (currentPageGroup != null) { + currentPageGroup.addPage(currentPageObject); + currentPageGroup.writeToStream(this.outputStream); + } else { + document.addPage(currentPageObject); + document.writeToStream(this.outputStream); + } + currentPageObject = null; + currentPage = null; + } + } + + /** + * Creates the given page fonts in the current page + * + * @param pageFonts + * a collection of AFP font attributes + */ + public void addFontsToCurrentPage(Map pageFonts) { + Iterator iter = pageFonts.values().iterator(); + while (iter.hasNext()) { + AFPFontAttributes afpFontAttributes = (AFPFontAttributes) iter + .next(); + createFont(afpFontAttributes.getFontReference(), afpFontAttributes + .getFont(), afpFontAttributes.getPointSize()); + } + } + + /** + * Helper method to create a map coded font object on the current page, this + * method delegates the construction of the map coded font object to the + * active environment group on the current page. + * + * @param fontReference + * the font number used as the resource identifier + * @param font + * the font + * @param size + * the point size of the font + */ + public void createFont(int fontReference, AFPFont font, int size) { + currentPage.createFont(fontReference, font, size); + } + + /** + * Returns a point on the current page + * + * @param x the X-coordinate + * @param y the Y-coordinate + * @return a point on the current page + */ + private Point getPoint(int x, int y) { + Point p = new Point(); + int rotation = paintingState.getRotation(); + switch (rotation) { + case 90: + p.x = y; + p.y = currentPage.getWidth() - x; + break; + case 180: + p.x = currentPage.getWidth() - x; + p.y = currentPage.getHeight() - y; + break; + case 270: + p.x = currentPage.getHeight() - y; + p.y = x; + break; + default: + p.x = x; + p.y = y; + break; + } + return p; + } + + /** + * Helper method to create text on the current page, this method delegates + * to the current presentation text object in order to construct the text. + * + * @param textDataInfo + * the afp text data + */ + public void createText(AFPTextDataInfo textDataInfo) { + int rotation = paintingState.getRotation(); + if (rotation != 0) { + textDataInfo.setRotation(rotation); + Point p = getPoint(textDataInfo.getX(), textDataInfo.getY()); + textDataInfo.setX(p.x); + textDataInfo.setY(p.y); + } + currentPage.createText(textDataInfo); + } + + /** + * Method to create a line on the current page. + * + * @param lineDataInfo the line data information. + */ + public void createLine(AFPLineDataInfo lineDataInfo) { + currentPage.createLine(lineDataInfo); + } + + /** + * This method will create shading on the page using the specified + * coordinates (the shading contrast is controlled via the red, green, blue + * parameters, by converting this to grey scale). + * + * @param x + * the x coordinate of the shading + * @param y + * the y coordinate of the shading + * @param w + * the width of the shaded area + * @param h + * the height of the shaded area + * @param col + * the shading color + */ + public void createShading(int x, int y, int w, int h, Color col) { + currentPageObject.createShading(x, y, w, h, col.getRed(), col.getGreen(), col.getBlue()); + } + + /** + * Helper method which allows creation of the MPO object, via the AEG. And + * the IPO via the Page. (See actual object for descriptions.) + * + * @param name + * the name of the static overlay + */ + public void createIncludePageOverlay(String name) { + currentPageObject.createIncludePageOverlay(name, 0, 0, paintingState.getRotation()); + currentPageObject.getActiveEnvironmentGroup().createOverlay(name); + } + + /** + * Helper method which allows creation of the IMM object. + * + * @param name + * the name of the medium map + */ + public void createInvokeMediumMap(String name) { + currentPageGroup.createInvokeMediumMap(name); + } + + /** + * Creates an IncludePageSegment on the current page. + * + * @param name + * the name of the include page segment + * @param x + * the x coordinate for the overlay + * @param y + * the y coordinate for the overlay + */ + public void createIncludePageSegment(String name, int x, int y) { + int xOrigin; + int yOrigin; + int orientation = paintingState.getRotation(); + switch (orientation) { + case 90: + xOrigin = currentPage.getWidth() - y; + yOrigin = x; + break; + case 180: + xOrigin = currentPage.getWidth() - x; + yOrigin = currentPage.getHeight() - y; + break; + case 270: + xOrigin = y; + yOrigin = currentPage.getHeight() - x; + break; + default: + xOrigin = x; + yOrigin = y; + break; + } + currentPage.createIncludePageSegment(name, xOrigin, yOrigin); + } + + /** + * Creates a TagLogicalElement on the current page. + * + * @param attributes + * the array of key value pairs. + */ + public void createPageTagLogicalElement(TagLogicalElementBean[] attributes) { + for (int i = 0; i < attributes.length; i++) { + String name = attributes[i].getKey(); + String value = attributes[i].getValue(); + currentPage.createTagLogicalElement(name, value); + } + } + + /** + * Creates a TagLogicalElement on the current page group. + * + * @param attributes + * the array of key value pairs. + */ + public void createPageGroupTagLogicalElement(TagLogicalElementBean[] attributes) { + for (int i = 0; i < attributes.length; i++) { + String name = attributes[i].getKey(); + String value = attributes[i].getValue(); + currentPageGroup.createTagLogicalElement(name, value); + } + } + + /** + * Creates a TagLogicalElement on the current page or page group + * + * @param name + * The tag name + * @param value + * The tag value + */ + public void createTagLogicalElement(String name, String value) { + if (currentPageGroup != null) { + currentPageGroup.createTagLogicalElement(name, value); + } else { + currentPage.createTagLogicalElement(name, value); + } + } + + /** + * Creates a NoOperation item + * + * @param content + * byte data + */ + public void createNoOperation(String content) { + currentPage.createNoOperation(content); + } + + /** + * Returns the current page group + * + * @return the current page group + */ + public PageGroup getCurrentPageGroup() { + return this.currentPageGroup; + } + + /** + * Start a new document. + * + * @throws IOException thrown if an I/O exception of some sort has occurred + */ + public void startDocument() throws IOException { + this.document = factory.createDocument(); + document.writeToStream(this.outputStream); + } + + /** + * Start a new page group. When processing has finished on the current page + * group the {@link #endPageGroup()}method must be invoked to mark the page + * group ending. + * + * @throws IOException thrown if an I/O exception of some sort has occurred + */ + public void startPageGroup() throws IOException { + endPageGroup(); + this.currentPageGroup = factory.createPageGroup(); + } + + /** + * Helper method to mark the end of the page group. + * + * @throws IOException thrown if an I/O exception of some sort has occurred + */ + public void endPageGroup() throws IOException { + if (currentPageGroup != null) { + currentPageGroup.endPageGroup(); + document.addPageGroup(currentPageGroup); + document.writeToStream(outputStream); + currentPageGroup = null; + } + } + + /** + * Sets the MO:DCA interchange set to use + * + * @param interchangeSet the MO:DCA interchange set + */ + public void setInterchangeSet(InterchangeSet interchangeSet) { + this.interchangeSet = interchangeSet; + } + + /** + * Returns the MO:DCA interchange set in use + * + * @return the MO:DCA interchange set in use + */ + public InterchangeSet getInterchangeSet() { + return this.interchangeSet; + } + + /** + * Returns the resource group for a given resource info + * + * @param level a resource level + * @return a resource group for the given resource info + */ + public ResourceGroup getResourceGroup(AFPResourceLevel level) { + ResourceGroup resourceGroup = null; + if (level.isDocument()) { + resourceGroup = document.getResourceGroup(); + } else if (level.isPageGroup()) { + resourceGroup = currentPageGroup.getResourceGroup(); + } else if (level.isPage()) { + resourceGroup = currentPageObject.getResourceGroup(); + } + return resourceGroup; + } + +} diff --git a/src/java/org/apache/fop/afp/Factory.java b/src/java/org/apache/fop/afp/Factory.java index ef7426330..a278a5761 100644 --- a/src/java/org/apache/fop/afp/Factory.java +++ b/src/java/org/apache/fop/afp/Factory.java @@ -30,7 +30,6 @@ import org.apache.fop.afp.ioca.ImageSegment; import org.apache.fop.afp.ioca.ImageSizeParameter; import org.apache.fop.afp.modca.ActiveEnvironmentGroup; import org.apache.fop.afp.modca.ContainerDataDescriptor; -import org.apache.fop.afp.modca.DataStream; import org.apache.fop.afp.modca.Document; import org.apache.fop.afp.modca.GraphicsDataDescriptor; import org.apache.fop.afp.modca.GraphicsObject; @@ -62,7 +61,7 @@ import org.apache.fop.afp.modca.TagLogicalElement; import org.apache.fop.afp.util.StringUtils; /** - * Creator of MO:DCA data objects (mostly) + * Creator of MO:DCA structured field objects */ public class Factory { @@ -392,12 +391,12 @@ public class Factory { /** * Creates a new {@link DataStream} * - * @param state the AFP painting state + * @param paintingState the AFP painting state * @param outputStream an outputstream to write to * @return a new {@link DataStream} */ - public DataStream createDataStream(AFPPaintingState state, OutputStream outputStream) { - DataStream dataStream = new DataStream(this, state, outputStream); + public DataStream createDataStream(AFPPaintingState paintingState, OutputStream outputStream) { + DataStream dataStream = new DataStream(this, paintingState, outputStream); return dataStream; } diff --git a/src/java/org/apache/fop/afp/PaintInfo.java b/src/java/org/apache/fop/afp/PaintInfo.java deleted file mode 100644 index 2b11d0e3e..000000000 --- a/src/java/org/apache/fop/afp/PaintInfo.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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.afp; - -/** - * Generic painting information interface - */ -public interface PaintInfo { - -} diff --git a/src/java/org/apache/fop/afp/PaintingInfo.java b/src/java/org/apache/fop/afp/PaintingInfo.java new file mode 100644 index 000000000..e53f28306 --- /dev/null +++ b/src/java/org/apache/fop/afp/PaintingInfo.java @@ -0,0 +1,27 @@ +/* + * 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.afp; + +/** + * Generic painting information interface + */ +public interface PaintingInfo { + +} diff --git a/src/java/org/apache/fop/afp/RectanglePaintInfo.java b/src/java/org/apache/fop/afp/RectanglePaintInfo.java deleted file mode 100644 index f0fae0317..000000000 --- a/src/java/org/apache/fop/afp/RectanglePaintInfo.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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.afp; - - -/** - * Filled rectangle painting information - */ -public class RectanglePaintInfo implements PaintInfo { - - private final float x; - private final float y; - private final float width; - private final float height; - - /** - * Main constructor - * - * @param x the x coordinate - * @param y the y coordinate - * @param width the width - * @param height the height - */ - public RectanglePaintInfo(float x, float y, float width, float height) { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - } - - /** - * Returns the x coordinate - * - * @return the x coordinate - */ - protected float getX() { - return x; - } - - /** - * Returns the y coordinate - * - * @return the y coordinate - */ - protected float getY() { - return y; - } - - /** - * Returns the width - * - * @return the width - */ - protected float getWidth() { - return width; - } - - /** - * Returns the height - * - * @return the height - */ - protected float getHeight() { - return height; - } - -} diff --git a/src/java/org/apache/fop/afp/RectanglePaintingInfo.java b/src/java/org/apache/fop/afp/RectanglePaintingInfo.java new file mode 100644 index 000000000..64503d0b8 --- /dev/null +++ b/src/java/org/apache/fop/afp/RectanglePaintingInfo.java @@ -0,0 +1,84 @@ +/* + * 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.afp; + + +/** + * Filled rectangle painting information + */ +public class RectanglePaintingInfo implements PaintingInfo { + + private final float x; + private final float y; + private final float width; + private final float height; + + /** + * Main constructor + * + * @param x the x coordinate + * @param y the y coordinate + * @param width the width + * @param height the height + */ + public RectanglePaintingInfo(float x, float y, float width, float height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } + + /** + * Returns the x coordinate + * + * @return the x coordinate + */ + protected float getX() { + return x; + } + + /** + * Returns the y coordinate + * + * @return the y coordinate + */ + protected float getY() { + return y; + } + + /** + * Returns the width + * + * @return the width + */ + protected float getWidth() { + return width; + } + + /** + * Returns the height + * + * @return the height + */ + protected float getHeight() { + return height; + } + +} diff --git a/src/java/org/apache/fop/afp/Startable.java b/src/java/org/apache/fop/afp/Startable.java new file mode 100644 index 000000000..fd05b8455 --- /dev/null +++ b/src/java/org/apache/fop/afp/Startable.java @@ -0,0 +1,40 @@ +/* + * 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.afp; + +/** + * Set and expose whether an object has started or not. + */ +public interface Startable { + + /** + * Sets whether or not this object has started or not + * + * @param complete true if this object has started + */ + void setStarted(boolean started); + + /** + * Returns true if this object has started + * + * @return true if this object has started + */ + boolean isStarted(); +} diff --git a/src/java/org/apache/fop/afp/StructuredData.java b/src/java/org/apache/fop/afp/StructuredData.java new file mode 100644 index 000000000..99555b39b --- /dev/null +++ b/src/java/org/apache/fop/afp/StructuredData.java @@ -0,0 +1,33 @@ +/* + * 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.afp; + +/** + * An AFP object which is able to know its own data length prior to writeToStream() + */ +public interface StructuredData { + + /** + * Returns the data length of this structured field + * + * @return the data length of this structured field + */ + int getDataLength(); +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/goca/AbstractGraphicsCoord.java b/src/java/org/apache/fop/afp/goca/AbstractGraphicsCoord.java index 066940874..3d8495667 100644 --- a/src/java/org/apache/fop/afp/goca/AbstractGraphicsCoord.java +++ b/src/java/org/apache/fop/afp/goca/AbstractGraphicsCoord.java @@ -22,26 +22,40 @@ package org.apache.fop.afp.goca; import java.io.IOException; import java.io.OutputStream; -import org.apache.fop.afp.modca.AbstractNamedAFPObject; -import org.apache.fop.afp.modca.StructuredDataObject; import org.apache.fop.afp.util.BinaryUtils; /** * A base class encapsulating the structure of coordinate based GOCA objects */ -public abstract class AbstractGraphicsCoord extends AbstractNamedAFPObject - implements StructuredDataObject { +public abstract class AbstractGraphicsCoord extends AbstractGraphicsDrawingOrder { /** array of x/y coordinates */ protected int[] coords = null; + protected boolean relative = false; + /** * Constructor * * @param coords the x/y coordinates for this object */ public AbstractGraphicsCoord(int[] coords) { - this.coords = coords; + if (coords == null) { + relative = true; + } else { + this.coords = coords; + } + } + + /** + * Constructor + * + * @param coords the x/y coordinates for this object + * @param relative + */ + public AbstractGraphicsCoord(int[] coords, boolean relative) { + this(coords); + this.relative = relative; } /** @@ -68,16 +82,9 @@ public abstract class AbstractGraphicsCoord extends AbstractNamedAFPObject /** {@inheritDoc} */ public int getDataLength() { - return 2 + (coords.length * 2); + return 2 + (coords != null ? coords.length * 2 : 0); } - /** - * Returns the order code of this structured field - * - * @return the order code of this structured field - */ - abstract byte getOrderCode(); - /** * Returns the coordinate data start index * @@ -93,15 +100,10 @@ public abstract class AbstractGraphicsCoord extends AbstractNamedAFPObject * @return the coordinate data */ byte[] getData() { - int len = getDataLength(); - byte[] data = new byte[len]; - data[0] = getOrderCode(); - data[1] = (byte)(len - 2); - + byte[] data = super.getData(); if (coords != null) { addCoords(data, getCoordinateDataStartIndex()); } - return data; } @@ -125,16 +127,6 @@ public abstract class AbstractGraphicsCoord extends AbstractNamedAFPObject } } - /** - * Returns the short name of this GOCA object - * - * @return the short name of this GOCA object - */ - public String getName() { - String className = getClass().getName(); - return className.substring(className.lastIndexOf(".") + 1); - } - /** {@inheritDoc} */ public String toString() { String coordsStr = ""; @@ -145,4 +137,13 @@ public abstract class AbstractGraphicsCoord extends AbstractNamedAFPObject coordsStr = coordsStr.substring(0, coordsStr.length() - 1); return getName() + "{" + coordsStr + "}"; } + + /** + * Returns true if this is a relative drawing order + * + * @return true if this is a relative drawing order + */ + protected boolean isRelative() { + return this.relative; + } } \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/goca/AbstractGraphicsDrawingOrder.java b/src/java/org/apache/fop/afp/goca/AbstractGraphicsDrawingOrder.java new file mode 100644 index 000000000..0d8f793c0 --- /dev/null +++ b/src/java/org/apache/fop/afp/goca/AbstractGraphicsDrawingOrder.java @@ -0,0 +1,60 @@ +/* + * 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.afp.goca; + +import org.apache.fop.afp.StructuredData; +import org.apache.fop.afp.modca.AbstractAFPObject; + +/** + * A base GOCA drawing order + */ +public abstract class AbstractGraphicsDrawingOrder extends AbstractAFPObject + implements StructuredData { + + /** + * Returns the order code of this structured field + * + * @return the order code of this structured field + */ + abstract byte getOrderCode(); + + /** + * Returns the coordinate data + * + * @return the coordinate data + */ + byte[] getData() { + int len = getDataLength(); + byte[] data = new byte[len]; + data[0] = getOrderCode(); + data[1] = (byte)(len - 2); + return data; + } + + /** + * Returns the short name of this GOCA object + * + * @return the short name of this GOCA object + */ + public String getName() { + String className = getClass().getName(); + return className.substring(className.lastIndexOf(".") + 1); + } +} diff --git a/src/java/org/apache/fop/afp/goca/AbstractGraphicsDrawingOrderContainer.java b/src/java/org/apache/fop/afp/goca/AbstractGraphicsDrawingOrderContainer.java new file mode 100644 index 000000000..34398b094 --- /dev/null +++ b/src/java/org/apache/fop/afp/goca/AbstractGraphicsDrawingOrderContainer.java @@ -0,0 +1,158 @@ +/* + * 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.afp.goca; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import org.apache.fop.afp.Completable; +import org.apache.fop.afp.Startable; +import org.apache.fop.afp.StructuredData; +import org.apache.fop.afp.modca.AbstractNamedAFPObject; + +/** + * A base container of prepared structured AFP objects + */ +public abstract class AbstractGraphicsDrawingOrderContainer extends AbstractNamedAFPObject +implements StructuredData, Completable, Startable { + + /** list of objects contained within this container */ + protected List/**/ objects + = new java.util.ArrayList/**/(); + + /** object is complete */ + private boolean complete = false; + + /** object has started */ + private boolean started = false; + + /** + * Default constructor + */ + protected AbstractGraphicsDrawingOrderContainer() { + } + + /** + * Named constructor + * + * @param name the name of the container + */ + protected AbstractGraphicsDrawingOrderContainer(String name) { + super(name); + } + + /** {@inheritDoc} */ + protected void writeStart(OutputStream os) throws IOException { + setStarted(true); + } + + /** {@inheritDoc} */ + protected void writeContent(OutputStream os) throws IOException { + writeObjects(objects, os); + } + + /** + * Adds a given graphics object to this container + * + * @param object the structured data object + */ + public void addObject(StructuredData object) { + objects.add(object); + } + + /** + * Adds all the contents of a given graphics container to this container + * + * @param graphicsContainer a graphics container + */ + public void addAll(AbstractGraphicsDrawingOrderContainer graphicsContainer) { + Collection/**/ objects = graphicsContainer.getObjects(); + objects.addAll(objects); + } + + /** + * Returns all the objects in this container + * + * @return all the objects in this container + */ + private Collection getObjects() { + return this.objects; + } + + /** + * Removes the last drawing order from this container and returns it + * + * @return the last drawing order from this container or null if empty + */ + public StructuredData removeLast() { + int lastIndex = objects.size() - 1; + StructuredData object = null; + if (lastIndex > -1) { + object = (StructuredData)objects.get(lastIndex); + objects.remove(lastIndex); + } + return object; + } + + /** + * Returns the current data length + * + * @return the current data length of this container including + * all enclosed objects (and their containers) + */ + public int getDataLength() { + int dataLen = 0; + Iterator it = objects.iterator(); + while (it.hasNext()) { + dataLen += ((StructuredData)it.next()).getDataLength(); + } + return dataLen; + } + + /** {@inheritDoc} */ + public void setComplete(boolean complete) { + Iterator it = objects.iterator(); + while (it.hasNext()) { + Object object = it.next(); + if (object instanceof Completable) { + ((Completable)object).setComplete(true); + } + } + this.complete = true; + } + + /** {@inheritDoc} */ + public boolean isComplete() { + return this.complete; + } + + /** {@inheritDoc} */ + public boolean isStarted() { + return this.started; + } + + /** {@inheritDoc} */ + public void setStarted(boolean started) { + this.started = started; + } +} diff --git a/src/java/org/apache/fop/afp/goca/AbstractGraphicsObjectContainer.java b/src/java/org/apache/fop/afp/goca/AbstractGraphicsObjectContainer.java deleted file mode 100644 index 672193042..000000000 --- a/src/java/org/apache/fop/afp/goca/AbstractGraphicsObjectContainer.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.afp.goca; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.Iterator; -import java.util.List; - -import org.apache.fop.afp.modca.AbstractNamedAFPObject; -import org.apache.fop.afp.modca.StructuredDataObject; - -/** - * A base container of prepared structured AFP objects - */ -public abstract class AbstractGraphicsObjectContainer extends AbstractNamedAFPObject -implements StructuredDataObject { - - /** list of objects contained within this container */ - protected List/**/ objects - = new java.util.ArrayList/**/(); - - /** - * Default constructor - */ - protected AbstractGraphicsObjectContainer() { - } - - /** - * Named constructor - * - * @param name the name of the container - */ - protected AbstractGraphicsObjectContainer(String name) { - super(name); - } - - /** {@inheritDoc} */ - protected void writeContent(OutputStream os) throws IOException { - writeObjects(objects, os); - } - - /** - * Adds a given graphics object to this container - * - * @param drawingOrder the graphics object - */ - public void addObject(StructuredDataObject drawingOrder) { - objects.add(drawingOrder); - } - - /** - * Returns the current data length - * - * @return the current data length of this container including - * all enclosed objects (and their containers) - */ - public int getDataLength() { - int dataLen = 0; - Iterator it = objects.iterator(); - while (it.hasNext()) { - dataLen += ((StructuredDataObject)it.next()).getDataLength(); - } - return dataLen; - } -} diff --git a/src/java/org/apache/fop/afp/goca/AbstractGraphicsString.java b/src/java/org/apache/fop/afp/goca/AbstractGraphicsString.java deleted file mode 100644 index 80882db8a..000000000 --- a/src/java/org/apache/fop/afp/goca/AbstractGraphicsString.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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.afp.goca; - -import java.io.UnsupportedEncodingException; - -import org.apache.fop.afp.AFPConstants; - -public abstract class AbstractGraphicsString extends AbstractGraphicsCoord { - - /** Up to 255 bytes of character data */ - protected static final int MAX_STR_LEN = 255; - - /** the string to draw */ - protected final String str; - - /** - * Constructor (relative) - * - * @param str the text string - */ - public AbstractGraphicsString(String str) { - super(null); - if (str.length() > MAX_STR_LEN) { - str = str.substring(0, MAX_STR_LEN); - log.warn("truncated character string, longer than " + MAX_STR_LEN + " chars"); - } - this.str = str; - } - - /** - * Constructor (absolute) - * - * @param str the text string - * @param x the x coordinate - * @param y the y coordinate - */ - public AbstractGraphicsString(String str, int x, int y) { - super(x, y); - this.str = str; - } - - /** {@inheritDoc} */ - public int getDataLength() { - return 2 + str.length(); - } - - /** - * Returns the text string as an encoded byte array - * - * @return the text string as an encoded byte array - */ - protected byte[] getStringAsBytes() throws UnsupportedEncodingException { - return str.getBytes(AFPConstants.EBCIDIC_ENCODING); - } - -} diff --git a/src/java/org/apache/fop/afp/goca/GraphicsArea.java b/src/java/org/apache/fop/afp/goca/GraphicsArea.java deleted file mode 100644 index 3d3bafb45..000000000 --- a/src/java/org/apache/fop/afp/goca/GraphicsArea.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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.afp.goca; - -import java.io.IOException; -import java.io.OutputStream; - - -/** - * A GOCA graphics area (container for filled shapes/objects) - */ -public final class GraphicsArea extends AbstractGraphicsObjectContainer { - - private static final int RES1 = 1; - private static final int BOUNDARY = 2; - private static final int NO_BOUNDARY = 0; - - /** draw boundary lines around this area */ - private boolean drawBoundary = false; - - /** - * Sets whether boundary lines are drawn - * - * @param drawBoundaryLines whether boundary lines are drawn - */ - public void setDrawBoundaryLines(boolean drawBoundaryLines) { - this.drawBoundary = drawBoundaryLines; - } - - /** {@inheritDoc} */ - public int getDataLength() { - return 4 + super.getDataLength(); - } - - /** {@inheritDoc} */ - protected void writeStart(OutputStream os) throws IOException { - byte[] data = new byte[] { - (byte)0x68, // GBAR order code - (byte)(RES1 + (drawBoundary ? BOUNDARY : NO_BOUNDARY)) - }; - os.write(data); - } - - /** {@inheritDoc} */ - protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[] { - (byte)0x60, // GEAR order code - 0x00, // LENGTH - }; - os.write(data); - } - - /** {@inheritDoc} */ - public String toString() { - return "GraphicsArea{drawBoundary=" + drawBoundary + "}"; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/goca/GraphicsAreaBegin.java b/src/java/org/apache/fop/afp/goca/GraphicsAreaBegin.java new file mode 100644 index 000000000..fc66fa8cd --- /dev/null +++ b/src/java/org/apache/fop/afp/goca/GraphicsAreaBegin.java @@ -0,0 +1,69 @@ +/* + * 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.afp.goca; + +import java.io.IOException; +import java.io.OutputStream; + +/** + * The beginning of a filled region (graphics area). + */ +public class GraphicsAreaBegin extends AbstractGraphicsDrawingOrder { + + private static final int RES1 = 1; + private static final int BOUNDARY = 2; + private static final int NO_BOUNDARY = 0; + + /** draw boundary lines around this area */ + private boolean drawBoundary = false; + + /** + * Sets whether boundary lines are drawn + * + * @param drawBoundaryLines whether boundary lines are drawn + */ + public void setDrawBoundaryLines(boolean drawBoundaryLines) { + this.drawBoundary = drawBoundaryLines; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = new byte[] { + getOrderCode(), // GBAR order code + (byte)(RES1 + (drawBoundary ? BOUNDARY : NO_BOUNDARY)) + }; + os.write(data); + } + + /** {@inheritDoc} */ + public int getDataLength() { + return 2; + } + + /** {@inheritDoc} */ + public String toString() { + return "GraphicsAreaBegin{drawBoundary=" + drawBoundary + "}"; + } + + /** {@inheritDoc} */ + byte getOrderCode() { + return 0x68; + } +} diff --git a/src/java/org/apache/fop/afp/goca/GraphicsAreaEnd.java b/src/java/org/apache/fop/afp/goca/GraphicsAreaEnd.java new file mode 100644 index 000000000..12f14bfa4 --- /dev/null +++ b/src/java/org/apache/fop/afp/goca/GraphicsAreaEnd.java @@ -0,0 +1,53 @@ +/* + * 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.afp.goca; + +import java.io.IOException; +import java.io.OutputStream; + +/** + * The end of a filled region (graphics area). + */ +public class GraphicsAreaEnd extends AbstractGraphicsDrawingOrder { + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = new byte[] { + getOrderCode(), // GEAR order code + 0x00, // LENGTH + }; + os.write(data); + } + + /** {@inheritDoc} */ + public int getDataLength() { + return 2; + } + + /** {@inheritDoc} */ + public String toString() { + return "GraphicsAreaEnd"; + } + + /** {@inheritDoc} */ + byte getOrderCode() { + return 0x60; + } +} diff --git a/src/java/org/apache/fop/afp/goca/GraphicsChainedSegment.java b/src/java/org/apache/fop/afp/goca/GraphicsChainedSegment.java index 697d4f841..8a92db296 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsChainedSegment.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsChainedSegment.java @@ -22,25 +22,17 @@ package org.apache.fop.afp.goca; import java.io.IOException; import java.io.OutputStream; -import org.apache.fop.afp.modca.StructuredDataObject; import org.apache.fop.afp.util.BinaryUtils; /** * A GOCA graphics segment */ -public final class GraphicsChainedSegment extends AbstractGraphicsObjectContainer { +public final class GraphicsChainedSegment extends AbstractGraphicsDrawingOrderContainer { /** The maximum segment data length */ protected static final int MAX_DATA_LEN = 8192; - /** the current area */ - private GraphicsArea currentArea = null; - - /** the previous segment in the chain */ - private GraphicsChainedSegment previous = null; - - /** the next segment in the chain */ - private GraphicsChainedSegment next = null; + private byte[] predecessorNameBytes; /** * Main constructor @@ -57,13 +49,12 @@ public final class GraphicsChainedSegment extends AbstractGraphicsObjectContaine * * @param name * the name of this graphics segment - * @param previous - * the previous graphics segment in this chain + * @param predecessorNameBytes + * the name of the predecessor in this chain */ - public GraphicsChainedSegment(String name, GraphicsChainedSegment previous) { + public GraphicsChainedSegment(String name, byte[] predecessorNameBytes) { super(name); - previous.next = this; - this.previous = previous; + this.predecessorNameBytes = predecessorNameBytes; } /** {@inheritDoc} */ @@ -88,9 +79,7 @@ public final class GraphicsChainedSegment extends AbstractGraphicsObjectContaine } /** {@inheritDoc} */ - protected void writeStart(OutputStream os) throws IOException { - super.writeStart(os); - + public void writeToStream(OutputStream os) throws IOException { byte[] data = new byte[14]; data[0] = getOrderCode(); // BEGIN_SEGMENT data[1] = 0x0C; // Length of following parameters @@ -108,41 +97,12 @@ public final class GraphicsChainedSegment extends AbstractGraphicsObjectContaine data[9] = len[1]; // P/S NAME (predecessor name) - if (previous != null) { - nameBytes = previous.getNameBytes(); - System.arraycopy(nameBytes, 0, data, 10, NAME_LENGTH); + if (predecessorNameBytes != null) { + System.arraycopy(predecessorNameBytes, 0, data, 10, NAME_LENGTH); } os.write(data); - } - - /** {@inheritDoc} */ - protected void writeEnd(OutputStream os) throws IOException { - // I am the first segment in the chain so write out the rest - if (previous == null) { - for (GraphicsChainedSegment segment = next; segment != null; segment = segment.next) { - segment.writeToStream(os); - } - } // else nothing todo - } - /** Begins a graphics area (start of fill) */ - protected void beginArea() { - this.currentArea = new GraphicsArea(); - super.addObject(currentArea); - } - - /** Ends a graphics area (end of fill) */ - protected void endArea() { - this.currentArea = null; - } - - /** {@inheritDoc} */ - public void addObject(StructuredDataObject drawingOrder) { - if (currentArea != null) { - currentArea.addObject(drawingOrder); - } else { - super.addObject(drawingOrder); - } + writeObjects(objects, os); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/afp/goca/GraphicsCharacterString.java b/src/java/org/apache/fop/afp/goca/GraphicsCharacterString.java new file mode 100644 index 000000000..70039d167 --- /dev/null +++ b/src/java/org/apache/fop/afp/goca/GraphicsCharacterString.java @@ -0,0 +1,114 @@ +/* + * 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.afp.goca; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; + +import org.apache.fop.afp.AFPConstants; + +/** + * A GOCA graphics string + */ +public class GraphicsCharacterString extends AbstractGraphicsCoord { + + /** Up to 255 bytes of character data */ + protected static final int MAX_STR_LEN = 255; + + /** the string to draw */ + protected final String str; + + /** + * Constructor (absolute positioning) + * + * @param str the character string + * @param x the x coordinate + * @param y the y coordinate + */ + public GraphicsCharacterString(String str, int x, int y) { + super(x, y); + this.str = truncate(str); + } + + /** + * Constructor (relative positioning) + * + * @param str the character string + * @param x the x coordinate + * @param y the y coordinate + */ + public GraphicsCharacterString(String str) { + super(null); + this.str = truncate(str); + } + + /** {@inheritDoc} */ + byte getOrderCode() { + if (isRelative()) { + return (byte)0x83; + } else { + return (byte)0xC3; + } + } + + /** {@inheritDoc} */ + public int getDataLength() { + return super.getDataLength() + str.length(); + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = getData(); + byte[] strData = getStringAsBytes(); + System.arraycopy(strData, 0, data, 6, strData.length); + os.write(data); + } + + /** + * Truncates the string as necessary + * + * @param str a character string + * @return a possibly truncated string + */ + private String truncate(String str) { + if (str.length() > MAX_STR_LEN) { + str = str.substring(0, MAX_STR_LEN); + log.warn("truncated character string, longer than " + MAX_STR_LEN + " chars"); + } + return str; + } + + /** + * Returns the text string as an encoded byte array + * + * @return the text string as an encoded byte array + */ + private byte[] getStringAsBytes() throws UnsupportedEncodingException { + return str.getBytes(AFPConstants.EBCIDIC_ENCODING); + } + + /** {@inheritDoc} */ + public String toString() { + return "GraphicsCharacterString{" + + (coords != null ? "x=" + coords[0] + ", y=" + coords[1] : "") + + "str='" + str + "'" + "}"; + } +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/goca/GraphicsData.java b/src/java/org/apache/fop/afp/goca/GraphicsData.java index 8b59436fc..89be8dd94 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsData.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsData.java @@ -22,38 +22,30 @@ package org.apache.fop.afp.goca; import java.io.IOException; import java.io.OutputStream; -import org.apache.fop.afp.modca.StructuredDataObject; +import org.apache.fop.afp.StructuredData; import org.apache.fop.afp.util.BinaryUtils; import org.apache.fop.afp.util.StringUtils; /** * A GOCA graphics data */ -public final class GraphicsData extends AbstractGraphicsObjectContainer { +public final class GraphicsData extends AbstractGraphicsDrawingOrderContainer { - /** The maximum graphics data length */ + /** the maximum graphics data length */ public static final int MAX_DATA_LEN = 32767; - /** The graphics segment */ - private GraphicsChainedSegment segment = null; - - /** {@inheritDoc} */ - public int getDataLength() { - return 8 + super.getDataLength(); - } + /** the graphics segment */ + private GraphicsChainedSegment currentSegment = null; /** - * Begins a graphics area (start of fill) + * Main constructor */ - public void beginArea() { - getSegment().beginArea(); + public GraphicsData() { } - /** - * Ends a graphics area (end of fill) - */ - public void endArea() { - getSegment().endArea(); + /** {@inheritDoc} */ + public int getDataLength() { + return 8 + super.getDataLength(); } /** @@ -61,48 +53,47 @@ public final class GraphicsData extends AbstractGraphicsObjectContainer { * * @return a new segment name */ - private String createSegmentName() { + public String createSegmentName() { return StringUtils.lpad(String.valueOf( (super.objects != null ? super.objects.size() : 0) + 1), '0', 4); } - /** - * Returns the current graphics segment, creating one if one does not exist - * - * @return the current graphics chained segment - */ - private GraphicsChainedSegment getSegment() { - if (segment == null) { - newSegment(); - } - return this.segment; - } - /** * Creates a new graphics segment * * @return a newly created graphics segment */ public GraphicsChainedSegment newSegment() { - String name = createSegmentName(); - if (segment == null) { - this.segment = new GraphicsChainedSegment(name); + String segmentName = createSegmentName(); + if (currentSegment == null) { + currentSegment = new GraphicsChainedSegment(segmentName); } else { - this.segment = new GraphicsChainedSegment(name, segment); + currentSegment.setComplete(true); + currentSegment = new GraphicsChainedSegment(segmentName, currentSegment.getNameBytes()); } - super.addObject(segment); - return segment; + super.addObject(currentSegment); + return currentSegment; } /** {@inheritDoc} */ - public void addObject(StructuredDataObject drawingOrder) { - if (segment == null - || (segment.getDataLength() + drawingOrder.getDataLength()) - >= GraphicsChainedSegment.MAX_DATA_LEN) { + public void addObject(StructuredData object) { + if (currentSegment == null + || (currentSegment.getDataLength() + object.getDataLength()) + >= GraphicsChainedSegment.MAX_DATA_LEN) { newSegment(); } - segment.addObject(drawingOrder); + currentSegment.addObject(object); + } + + /** + * Removes the current segment from this graphics data + * + * @return the current segment from this graphics data + */ + public StructuredData removeCurrentSegment() { + this.currentSegment = null; + return super.removeLast(); } /** {@inheritDoc} */ @@ -115,13 +106,21 @@ public final class GraphicsData extends AbstractGraphicsObjectContainer { data[2] = len[1]; // Length byte 2 os.write(data); - // get first segment in chain and write (including all its connected segments) - GraphicsChainedSegment firstSegment = (GraphicsChainedSegment)objects.get(0); - firstSegment.writeToStream(os); + writeObjects(objects, os); } /** {@inheritDoc} */ public String toString() { return "GraphicsData"; } + + /** + * Adds the given segment to this graphics data + * + * @param segment a graphics chained segment + */ + public void addSegment(GraphicsChainedSegment segment) { + currentSegment = segment; + super.addObject(currentSegment); + } } \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/goca/GraphicsFillet.java b/src/java/org/apache/fop/afp/goca/GraphicsFillet.java index b4fa17d65..294be6d9b 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsFillet.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsFillet.java @@ -30,12 +30,17 @@ public final class GraphicsFillet extends AbstractGraphicsCoord { * * @param coords the x/y coordinates for this object */ - public GraphicsFillet(int[] coords) { - super(coords); + public GraphicsFillet(int[] coords, boolean relative) { + super(coords, relative); } + /** {@inheritDoc} */ byte getOrderCode() { - return (byte)0xC5; + if (isRelative()) { + return (byte)0x85; + } else { + return (byte)0xC5; + } } } \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/goca/GraphicsFilletRelative.java b/src/java/org/apache/fop/afp/goca/GraphicsFilletRelative.java deleted file mode 100644 index 21a1c17d6..000000000 --- a/src/java/org/apache/fop/afp/goca/GraphicsFilletRelative.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.afp.goca; - - -/** - * A GOCA graphics curved tangential line to a specified set of - * straight lines drawn from the given position or current position - */ -public final class GraphicsFilletRelative extends AbstractGraphicsCoord { - - /** - * Constructor - * - * @param coords the x/y coordinates for this object - */ - public GraphicsFilletRelative(int[] coords) { - super(coords); - } - - /** {@inheritDoc} */ - byte getOrderCode() { - return (byte)0x85; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/goca/GraphicsImage.java b/src/java/org/apache/fop/afp/goca/GraphicsImage.java index 94e9e9ab2..3b1dafeea 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsImage.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsImage.java @@ -22,13 +22,15 @@ package org.apache.fop.afp.goca; import java.io.IOException; import java.io.OutputStream; -import org.apache.fop.afp.modca.AbstractStructuredObject; import org.apache.fop.afp.util.BinaryUtils; /** * A GOCA Image */ -public class GraphicsImage extends AbstractStructuredObject { +public class GraphicsImage extends AbstractGraphicsDrawingOrder { + + /** the maximum image data length */ + public static final short MAX_DATA_LEN = 255; /** x coordinate */ private final int x; @@ -63,13 +65,23 @@ public class GraphicsImage extends AbstractStructuredObject { } /** {@inheritDoc} */ - protected void writeStart(OutputStream os) throws IOException { + public int getDataLength() { + //TODO: + return 0; + } + + byte getOrderCode() { + return (byte)0xD1; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { byte[] xcoord = BinaryUtils.convert(x, 2); byte[] ycoord = BinaryUtils.convert(y, 2); byte[] w = BinaryUtils.convert(width, 2); byte[] h = BinaryUtils.convert(height, 2); - byte[] data = new byte[] { - (byte) 0xD1, // GBIMG order code + byte[] startData = new byte[] { + getOrderCode(), // GBIMG order code (byte) 0x0A, // LENGTH xcoord[0], xcoord[1], @@ -82,28 +94,19 @@ public class GraphicsImage extends AbstractStructuredObject { h[0], // HEIGHT h[1] // }; - os.write(data); - } - - /** the maximum image data length */ - public static final short MAX_DATA_LEN = 255; + os.write(startData); - /** {@inheritDoc} */ - protected void writeContent(OutputStream os) throws IOException { byte[] dataHeader = new byte[] { (byte) 0x92 // GIMD }; final int lengthOffset = 1; writeChunksToStream(imageData, dataHeader, lengthOffset, MAX_DATA_LEN, os); - } - /** {@inheritDoc} */ - protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[] { + byte[] endData = new byte[] { (byte) 0x93, // GEIMG order code 0x00 // LENGTH }; - os.write(data); + os.write(endData); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/afp/goca/GraphicsLine.java b/src/java/org/apache/fop/afp/goca/GraphicsLine.java index d8ff1afaa..17bd43ce0 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsLine.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsLine.java @@ -19,6 +19,9 @@ package org.apache.fop.afp.goca; +import java.io.IOException; +import java.io.OutputStream; + /** * A GOCA graphics straight line drawn from the * given absolute position @@ -29,14 +32,25 @@ public class GraphicsLine extends AbstractGraphicsCoord { * Constructor * * @param coords the x/y coordinates for this object + * + * @param relative is this a relative drawing order */ - public GraphicsLine(int[] coords) { - super(coords); + public GraphicsLine(int[] coords, boolean relative) { + super(coords, relative); } /** {@inheritDoc} */ byte getOrderCode() { - return (byte)0xC1; + if (isRelative()) { + return (byte)0x81; + } else { + return (byte)0xC1; + } } + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = getData(); + os.write(data); + } } \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/goca/GraphicsLineRelative.java b/src/java/org/apache/fop/afp/goca/GraphicsLineRelative.java deleted file mode 100644 index 43ffebf08..000000000 --- a/src/java/org/apache/fop/afp/goca/GraphicsLineRelative.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.afp.goca; - -/** - * A GOCA graphics straight line drawn from the - * relative from the current position. - */ -public class GraphicsLineRelative extends AbstractGraphicsCoord { - - /** - * Constructor - * - * @param coords the x/y coordinates for this object - */ - public GraphicsLineRelative(int[] coords) { - super(coords); - } - - /** {@inheritDoc} */ - byte getOrderCode() { - return (byte)0x81; - } - -} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/goca/GraphicsSetCharacterSet.java b/src/java/org/apache/fop/afp/goca/GraphicsSetCharacterSet.java index 1561ecf83..b3d1158fe 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsSetCharacterSet.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsSetCharacterSet.java @@ -22,15 +22,12 @@ package org.apache.fop.afp.goca; import java.io.IOException; import java.io.OutputStream; -import org.apache.fop.afp.modca.AbstractNamedAFPObject; -import org.apache.fop.afp.modca.StructuredDataObject; import org.apache.fop.afp.util.BinaryUtils; /** * Sets the current character set (font) to be used for following graphics strings */ -public class GraphicsSetCharacterSet extends AbstractNamedAFPObject - implements StructuredDataObject { +public class GraphicsSetCharacterSet extends AbstractGraphicsDrawingOrder { /** font character set reference */ private final int fontReference; @@ -45,7 +42,7 @@ public class GraphicsSetCharacterSet extends AbstractNamedAFPObject /** {@inheritDoc} */ public void writeToStream(OutputStream os) throws IOException { byte[] data = new byte[] { - 0x38, // GSCS order code + getOrderCode(), // GSCS order code BinaryUtils.convert(fontReference)[0] }; os.write(data); @@ -61,4 +58,9 @@ public class GraphicsSetCharacterSet extends AbstractNamedAFPObject return "GraphicsSetCharacterSet(" + fontReference + ")"; } + /** {@inheritDoc} */ + byte getOrderCode() { + return 0x38; + } + } \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/goca/GraphicsSetLineType.java b/src/java/org/apache/fop/afp/goca/GraphicsSetLineType.java index 3479bf4e5..b6512f57c 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsSetLineType.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsSetLineType.java @@ -22,14 +22,10 @@ package org.apache.fop.afp.goca; import java.io.IOException; import java.io.OutputStream; -import org.apache.fop.afp.modca.AbstractNamedAFPObject; -import org.apache.fop.afp.modca.StructuredDataObject; - /** * Sets the value of the current line type attribute when stroking GOCA shapes (structured fields) */ -public class GraphicsSetLineType extends AbstractNamedAFPObject -implements StructuredDataObject { +public class GraphicsSetLineType extends AbstractGraphicsDrawingOrder { /** the default line type */ public static final byte DEFAULT = 0x00; // normally SOLID @@ -78,7 +74,7 @@ implements StructuredDataObject { /** {@inheritDoc} */ public void writeToStream(OutputStream os) throws IOException { byte[] data = new byte[] { - 0x18, // GSLW order code + getOrderCode(), // GSLW order code type // line type }; os.write(data); @@ -93,4 +89,9 @@ implements StructuredDataObject { public String toString() { return "GraphicsSetLineType{type=" + TYPES[type] + "}"; } + + /** {@inheritDoc} */ + byte getOrderCode() { + return 0x18; + } } \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/goca/GraphicsSetLineWidth.java b/src/java/org/apache/fop/afp/goca/GraphicsSetLineWidth.java index 09ed0d7dc..96eac0677 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsSetLineWidth.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsSetLineWidth.java @@ -22,13 +22,10 @@ package org.apache.fop.afp.goca; import java.io.IOException; import java.io.OutputStream; -import org.apache.fop.afp.modca.AbstractNamedAFPObject; -import org.apache.fop.afp.modca.StructuredDataObject; - /** * Sets the line width to use when stroking GOCA shapes (structured fields) */ -public class GraphicsSetLineWidth extends AbstractNamedAFPObject implements StructuredDataObject { +public class GraphicsSetLineWidth extends AbstractGraphicsDrawingOrder { /** line width multiplier */ private int multiplier = 1; @@ -50,7 +47,7 @@ public class GraphicsSetLineWidth extends AbstractNamedAFPObject implements Stru /** {@inheritDoc} */ public void writeToStream(OutputStream os) throws IOException { byte[] data = new byte[] { - 0x19, // GSLW order code + getOrderCode(), // GSLW order code (byte)multiplier // MH (line-width) }; os.write(data); @@ -60,4 +57,9 @@ public class GraphicsSetLineWidth extends AbstractNamedAFPObject implements Stru public String toString() { return "GraphicsSetLineWidth{multiplier=" + multiplier + "}"; } + + /** {@inheritDoc} */ + byte getOrderCode() { + return 0x19; + } } \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/goca/GraphicsSetMix.java b/src/java/org/apache/fop/afp/goca/GraphicsSetMix.java index 0058a5013..dfb5ae0d2 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsSetMix.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsSetMix.java @@ -22,9 +22,10 @@ package org.apache.fop.afp.goca; import java.io.IOException; import java.io.OutputStream; -import org.apache.fop.afp.modca.AbstractNamedAFPObject; - -public class GraphicsSetMix extends AbstractNamedAFPObject { +/** + * Sets the foreground mix mode. + */ +public class GraphicsSetMix extends AbstractGraphicsDrawingOrder { public static final byte MODE_DEFAULT = 0x00; public static final byte MODE_OVERPAINT = 0x02; @@ -55,4 +56,14 @@ public class GraphicsSetMix extends AbstractNamedAFPObject { return "GraphicsSetMix{mode=" + mode + "}"; } + /** {@inheritDoc} */ + byte getOrderCode() { + return 0x0C; + } + + /** {@inheritDoc} */ + public int getDataLength() { + return 2; + } + } diff --git a/src/java/org/apache/fop/afp/goca/GraphicsSetPatternSymbol.java b/src/java/org/apache/fop/afp/goca/GraphicsSetPatternSymbol.java index 0d74aa9d3..3d6cf7cd6 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsSetPatternSymbol.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsSetPatternSymbol.java @@ -22,14 +22,10 @@ package org.apache.fop.afp.goca; import java.io.IOException; import java.io.OutputStream; -import org.apache.fop.afp.modca.AbstractNamedAFPObject; -import org.apache.fop.afp.modca.StructuredDataObject; - /** * Sets the pattern symbol to use when filling following GOCA structured fields */ -public class GraphicsSetPatternSymbol extends AbstractNamedAFPObject -implements StructuredDataObject { +public class GraphicsSetPatternSymbol extends AbstractGraphicsDrawingOrder { /** dotted density 1 */ public static final byte DOTTED_DENSITY_1 = 0x01; @@ -83,15 +79,15 @@ implements StructuredDataObject { public static final byte BLANK = 0x40; // processed same as NO_FILL /** the graphics pattern symbol to use */ - private final byte symbol; + private final byte pattern; /** * Main constructor * * @param symb the pattern symbol to use */ - public GraphicsSetPatternSymbol(byte symb) { - this.symbol = symb; + public GraphicsSetPatternSymbol(byte pattern) { + this.pattern = pattern; } /** {@inheritDoc} */ @@ -102,8 +98,8 @@ implements StructuredDataObject { /** {@inheritDoc} */ public void writeToStream(OutputStream os) throws IOException { byte[] data = new byte[] { - 0x28, // GSPT order code - symbol + getOrderCode(), // GSPT order code + pattern }; os.write(data); } @@ -111,6 +107,11 @@ implements StructuredDataObject { /** {@inheritDoc} */ public String toString() { return "GraphicsSetPatternSymbol(fill=" - + (symbol == SOLID_FILL ? true : false) + ")"; + + (pattern == SOLID_FILL ? true : false) + ")"; + } + + /** {@inheritDoc} */ + byte getOrderCode() { + return 0x28; } } \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/goca/GraphicsSetProcessColor.java b/src/java/org/apache/fop/afp/goca/GraphicsSetProcessColor.java index 41ddeaa96..05a6ee5d1 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsSetProcessColor.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsSetProcessColor.java @@ -24,14 +24,10 @@ import java.awt.color.ColorSpace; import java.io.IOException; import java.io.OutputStream; -import org.apache.fop.afp.modca.AbstractNamedAFPObject; -import org.apache.fop.afp.modca.StructuredDataObject; - /** * Sets the current processing color for the following GOCA structured fields */ -public class GraphicsSetProcessColor extends AbstractNamedAFPObject -implements StructuredDataObject { +public class GraphicsSetProcessColor extends AbstractGraphicsDrawingOrder { private final Color color; diff --git a/src/java/org/apache/fop/afp/goca/GraphicsString.java b/src/java/org/apache/fop/afp/goca/GraphicsString.java deleted file mode 100644 index c08da64ec..000000000 --- a/src/java/org/apache/fop/afp/goca/GraphicsString.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.afp.goca; - -import java.io.IOException; -import java.io.OutputStream; - -/** - * A GOCA graphics string - */ -public class GraphicsString extends AbstractGraphicsString { - - /** - * Constructor - * - * @param str the character string - * @param x the x coordinate - * @param y the y coordinate - */ - public GraphicsString(String str, int x, int y) { - super(str, x, y); - } - - /** {@inheritDoc} */ - byte getOrderCode() { - return (byte)0xC3; - } - - /** {@inheritDoc} */ - public int getDataLength() { - return super.getDataLength() + (coords.length * 2); - } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - byte[] data = getData(); - byte[] strData = getStringAsBytes(); - System.arraycopy(strData, 0, data, 6, strData.length); - - os.write(data); - } - - /** {@inheritDoc} */ - public String toString() { - return "GraphicsString{x=" + coords[0] + ", y=" + coords[1] + "str='" + str + "'" + "}"; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/goca/GraphicsStringRelative.java b/src/java/org/apache/fop/afp/goca/GraphicsStringRelative.java deleted file mode 100644 index af0c05b5d..000000000 --- a/src/java/org/apache/fop/afp/goca/GraphicsStringRelative.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.afp.goca; - -import java.io.IOException; -import java.io.OutputStream; - -/** - * A GOCA graphics string - */ -public class GraphicsStringRelative extends AbstractGraphicsString { - - /** - * Constructor - * - * @param str the character string - */ - public GraphicsStringRelative(String str) { - super(str); - } - - /** {@inheritDoc} */ - byte getOrderCode() { - return (byte)0x83; - } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - byte[] data = getData(); - byte[] strData = getStringAsBytes(); - System.arraycopy(strData, 0, data, 2, strData.length); - os.write(data); - } - - /** {@inheritDoc} */ - public String toString() { - return "GraphicsStringRelative{str='" + str + "'" + "}"; - } - -} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/ioca/ImageCellPosition.java b/src/java/org/apache/fop/afp/ioca/ImageCellPosition.java index 0728ad98f..97489a9b1 100644 --- a/src/java/org/apache/fop/afp/ioca/ImageCellPosition.java +++ b/src/java/org/apache/fop/afp/ioca/ImageCellPosition.java @@ -31,38 +31,27 @@ import org.apache.fop.afp.util.BinaryUtils; */ public class ImageCellPosition extends AbstractAFPObject { - /** - * Offset of image cell in X direction - */ + /** offset of image cell in X direction */ private int xOffset = 0; - /** - * Offset of image cell in Y direction - */ + /** offset of image cell in Y direction */ private int yOffset = 0; - /** - * Size of image cell in X direction - */ + /** size of image cell in X direction */ private final byte[] xSize = new byte[] {(byte)0xFF, (byte)0xFF}; - /** - * Size of image cell in Y direction - */ + /** size of image cell in Y direction */ private final byte[] ySize = new byte[] {(byte)0xFF, (byte)0xFF}; - /** - * Size of fill rectangle in X direction - */ + /** size of fill rectangle in X direction */ private final byte[] xFillSize = new byte[] {(byte)0xFF, (byte)0xFF}; - /** - * Size of fill rectangle in Y direction - */ + /** size of fill rectangle in Y direction */ private final byte[] yFillSize = new byte[] {(byte)0xFF, (byte)0xFF}; /** - * Constructor for the ImageCellPosition + * Main Constructor + * * @param x The offset of image cell in X direction * @param y The offset of image cell in Y direction */ diff --git a/src/java/org/apache/fop/afp/ioca/ImageContent.java b/src/java/org/apache/fop/afp/ioca/ImageContent.java index 6cfddab94..028d08475 100644 --- a/src/java/org/apache/fop/afp/ioca/ImageContent.java +++ b/src/java/org/apache/fop/afp/ioca/ImageContent.java @@ -53,38 +53,26 @@ public class ImageContent extends AbstractStructuredObject { */ public static final byte COMPID_G3_MMR = (byte)0x82; - /** - * The image size parameter - */ + /** the image size parameter */ private ImageSizeParameter imageSizeParameter = null; - /** - * The image encoding - */ + /** the image encoding */ private byte encoding = (byte)0x03; - /** - * The image ide size - */ + /** the image ide size */ private byte size = 1; - /** - * The image compression - */ + /** the image compression */ private byte compression = (byte)0xC0; - /** - * The image color model - */ + /** the image color model */ private byte colorModel = (byte)0x01; - /** - * The image data - */ + /** the image data */ private byte[] data; /** - * Constructor for the image content + * Main Constructor */ public ImageContent() { } @@ -169,7 +157,7 @@ public class ImageContent extends AbstractStructuredObject { 0x00 // length }; final int lengthOffset = 2; - writeChunksToStream(this.data, dataHeader, lengthOffset, MAX_DATA_LEN, os); + writeChunksToStream(data, dataHeader, lengthOffset, MAX_DATA_LEN, os); } } diff --git a/src/java/org/apache/fop/afp/ioca/ImageInputDescriptor.java b/src/java/org/apache/fop/afp/ioca/ImageInputDescriptor.java index f3351933c..af237a467 100644 --- a/src/java/org/apache/fop/afp/ioca/ImageInputDescriptor.java +++ b/src/java/org/apache/fop/afp/ioca/ImageInputDescriptor.java @@ -32,12 +32,9 @@ import org.apache.fop.afp.util.BinaryUtils; */ public class ImageInputDescriptor extends AbstractAFPObject { - /** - * The resolution of the raster image (default 240) - */ + /** the resolution of the raster image (default 240) */ private int resolution = 240; - /** {@inheritDoc} */ public void writeToStream(OutputStream os) throws IOException { diff --git a/src/java/org/apache/fop/afp/ioca/ImageOutputControl.java b/src/java/org/apache/fop/afp/ioca/ImageOutputControl.java index 8574f445b..3d500b3fd 100644 --- a/src/java/org/apache/fop/afp/ioca/ImageOutputControl.java +++ b/src/java/org/apache/fop/afp/ioca/ImageOutputControl.java @@ -33,9 +33,7 @@ import org.apache.fop.afp.util.BinaryUtils; */ public class ImageOutputControl extends AbstractAFPObject { - /** - * The orientation of the image - */ + /** the orientation of the image */ private int orientation = 0; /** @@ -50,9 +48,7 @@ public class ImageOutputControl extends AbstractAFPObject { */ private int yCoord = 0; - /** - * Map an image point to a single presentation device - */ + /** map an image point to a single presentation device */ private boolean singlePoint = true; /** diff --git a/src/java/org/apache/fop/afp/ioca/ImageRasterData.java b/src/java/org/apache/fop/afp/ioca/ImageRasterData.java index 115472bd8..50f44d39d 100644 --- a/src/java/org/apache/fop/afp/ioca/ImageRasterData.java +++ b/src/java/org/apache/fop/afp/ioca/ImageRasterData.java @@ -23,8 +23,6 @@ import java.io.IOException; import java.io.OutputStream; import org.apache.fop.afp.modca.AbstractAFPObject; -import org.apache.fop.afp.modca.AbstractAFPObject.Category; -import org.apache.fop.afp.modca.AbstractAFPObject.Type; import org.apache.fop.afp.util.BinaryUtils; /** @@ -49,13 +47,12 @@ import org.apache.fop.afp.util.BinaryUtils; */ public class ImageRasterData extends AbstractAFPObject { - /** - * The image raster data - */ + /** the image raster data */ private final byte[] rasterData; /** * Constructor for the image raster data object + * * @param data The raster image data */ public ImageRasterData(byte[] data) { diff --git a/src/java/org/apache/fop/afp/modca/AbstractAFPObject.java b/src/java/org/apache/fop/afp/modca/AbstractAFPObject.java index f34ac7d00..f1b76c447 100644 --- a/src/java/org/apache/fop/afp/modca/AbstractAFPObject.java +++ b/src/java/org/apache/fop/afp/modca/AbstractAFPObject.java @@ -82,13 +82,13 @@ public abstract class AbstractAFPObject implements Streamable { } /** - * Help method to write a set of AFPObjects to the AFP datastream. + * Writes a collection of Streamable 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. */ - protected void writeObjects(Collection/**/ objects, OutputStream os) + protected void writeObjects(Collection/**/ objects, OutputStream os) throws IOException { if (objects != null && objects.size() > 0) { Iterator it = objects.iterator(); @@ -103,14 +103,14 @@ public abstract class AbstractAFPObject implements Streamable { } /** - * Reads data chunks from an inputstream - * and then formats them with a structured header to a given outputstream + * Reads data chunks from an InputStream + * and then formats them with a structured header to a given OutputStream * * @param dataHeader the header data * @param lengthOffset offset of length field in data chunk * @param maxChunkLength the maximum chunk length - * @param inputStream the inputstream to read from - * @param outputStream the outputstream to write to + * @param inputStream the InputStream to read from + * @param outputStream the OutputStream to write to * @throws IOException thrown if an I/O exception of some sort has occurred. */ protected static void copyChunks(byte[] dataHeader, int lengthOffset, diff --git a/src/java/org/apache/fop/afp/modca/AbstractDataObject.java b/src/java/org/apache/fop/afp/modca/AbstractDataObject.java index c7b987a9e..ec1b45be6 100644 --- a/src/java/org/apache/fop/afp/modca/AbstractDataObject.java +++ b/src/java/org/apache/fop/afp/modca/AbstractDataObject.java @@ -26,13 +26,15 @@ import org.apache.fop.afp.AFPDataObjectInfo; import org.apache.fop.afp.AFPObjectAreaInfo; import org.apache.fop.afp.AFPResourceInfo; import org.apache.fop.afp.AFPResourceLevel; +import org.apache.fop.afp.Completable; import org.apache.fop.afp.Factory; +import org.apache.fop.afp.Startable; /** * Abstract base class used by the ImageObject and GraphicsObject which both * have define an ObjectEnvironmentGroup */ -public abstract class AbstractDataObject extends AbstractNamedAFPObject { +public abstract class AbstractDataObject extends AbstractNamedAFPObject implements Startable, Completable { /** the object environment group */ protected ObjectEnvironmentGroup objectEnvironmentGroup = null; @@ -40,6 +42,12 @@ public abstract class AbstractDataObject extends AbstractNamedAFPObject { /** the object factory */ protected final Factory factory; + /** the completion status of this object */ + private boolean complete; + + /** the starting status of this object */ + private boolean started; + /** * Named constructor * @@ -97,12 +105,35 @@ public abstract class AbstractDataObject extends AbstractNamedAFPObject { return objectEnvironmentGroup; } + /** {@inheritDoc} */ + protected void writeStart(OutputStream os) throws IOException { + setStarted(true); + } + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { - super.writeContent(os); // write triplets if (objectEnvironmentGroup != null) { objectEnvironmentGroup.writeToStream(os); } } + /** {@inheritDoc} */ + public void setStarted(boolean started) { + this.started = started; + } + + /** {@inheritDoc} */ + public boolean isStarted() { + return this.started; + } + + /** {@inheritDoc} */ + public void setComplete(boolean complete) { + this.complete = complete; + } + + /** {@inheritDoc} */ + public boolean isComplete() { + return this.complete; + } } diff --git a/src/java/org/apache/fop/afp/modca/AbstractNamedAFPObject.java b/src/java/org/apache/fop/afp/modca/AbstractNamedAFPObject.java index c3c158825..4e0dbc349 100644 --- a/src/java/org/apache/fop/afp/modca/AbstractNamedAFPObject.java +++ b/src/java/org/apache/fop/afp/modca/AbstractNamedAFPObject.java @@ -66,7 +66,7 @@ public abstract class AbstractNamedAFPObject extends AbstractTripletStructuredOb * * @return the name as a byte array in EBCIDIC encoding */ - protected byte[] getNameBytes() { + public byte[] getNameBytes() { int afpNameLen = getNameLength(); int nameLen = name.length(); if (nameLen < afpNameLen) { @@ -103,7 +103,16 @@ public abstract class AbstractNamedAFPObject extends AbstractTripletStructuredOb * @return the name of this object */ public String getName() { - return name; + return this.name; + } + + /** + * Sets the name of this object + * + * @param name the object name + */ + public void setName(String name) { + this.name = name; } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/afp/modca/AbstractPageObject.java b/src/java/org/apache/fop/afp/modca/AbstractPageObject.java index d7252c390..c7559a87f 100644 --- a/src/java/org/apache/fop/afp/modca/AbstractPageObject.java +++ b/src/java/org/apache/fop/afp/modca/AbstractPageObject.java @@ -25,6 +25,7 @@ import java.util.List; import org.apache.fop.afp.AFPLineDataInfo; import org.apache.fop.afp.AFPTextDataInfo; +import org.apache.fop.afp.Completable; import org.apache.fop.afp.Factory; import org.apache.fop.afp.fonts.AFPFont; @@ -48,7 +49,7 @@ import org.apache.fop.afp.fonts.AFPFont; * in page state. * */ -public abstract class AbstractPageObject extends AbstractNamedAFPObject { +public abstract class AbstractPageObject extends AbstractNamedAFPObject implements Completable { /** The active environment group for the page */ protected ActiveEnvironmentGroup activeEnvironmentGroup = null; @@ -183,7 +184,7 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { if (currentPresentationTextObject != null) { currentPresentationTextObject.endControlSequence(); } - complete = true; + setComplete(true); } /** @@ -293,15 +294,6 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { return activeEnvironmentGroup; } - /** - * Returns an indication if the page is complete - * - * @return whether this page is complete - */ - public boolean isComplete() { - return complete; - } - /** * Returns the height of the page * @@ -343,4 +335,14 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { public void addObject(Object obj) { objects.add(obj); } + + /** {@inheritDoc} */ + public void setComplete(boolean complete) { + this.complete = complete; + } + + /** {@inheritDoc} */ + public boolean isComplete() { + return this.complete; + } } diff --git a/src/java/org/apache/fop/afp/modca/AbstractResourceGroupContainer.java b/src/java/org/apache/fop/afp/modca/AbstractResourceGroupContainer.java index 860c6b56a..9dcd56277 100644 --- a/src/java/org/apache/fop/afp/modca/AbstractResourceGroupContainer.java +++ b/src/java/org/apache/fop/afp/modca/AbstractResourceGroupContainer.java @@ -24,6 +24,7 @@ import java.io.OutputStream; import java.util.Collection; import java.util.Iterator; +import org.apache.fop.afp.Completable; import org.apache.fop.afp.Factory; import org.apache.fop.afp.Streamable; @@ -109,7 +110,7 @@ implements Streamable { * * @return the resource group in this resource group container */ - protected ResourceGroup getResourceGroup() { + public ResourceGroup getResourceGroup() { if (resourceGroup == null) { resourceGroup = factory.createResourceGroup(); } @@ -162,6 +163,6 @@ implements Streamable { * @return true if this object can be written */ protected boolean canWrite(AbstractAFPObject obj) { - return obj instanceof AbstractPageObject && ((AbstractPageObject)obj).isComplete(); + return obj instanceof AbstractPageObject && ((Completable)obj).isComplete(); } } diff --git a/src/java/org/apache/fop/afp/modca/AbstractTripletStructuredObject.java b/src/java/org/apache/fop/afp/modca/AbstractTripletStructuredObject.java index c1686d07c..a14af2967 100644 --- a/src/java/org/apache/fop/afp/modca/AbstractTripletStructuredObject.java +++ b/src/java/org/apache/fop/afp/modca/AbstractTripletStructuredObject.java @@ -31,6 +31,9 @@ import org.apache.fop.afp.modca.triplets.CommentTriplet; import org.apache.fop.afp.modca.triplets.FullyQualifiedNameTriplet; import org.apache.fop.afp.modca.triplets.ObjectClassificationTriplet; +/** + * A MODCA structured object base class providing support for Triplets + */ public class AbstractTripletStructuredObject extends AbstractStructuredObject { /** list of object triplets */ diff --git a/src/java/org/apache/fop/afp/modca/DataStream.java b/src/java/org/apache/fop/afp/modca/DataStream.java deleted file mode 100644 index 00d2b6f16..000000000 --- a/src/java/org/apache/fop/afp/modca/DataStream.java +++ /dev/null @@ -1,593 +0,0 @@ -/* - * 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.afp.modca; - -import java.awt.Color; -import java.awt.Point; -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.afp.AFPLineDataInfo; -import org.apache.fop.afp.AFPPaintingState; -import org.apache.fop.afp.AFPResourceLevel; -import org.apache.fop.afp.AFPTextDataInfo; -import org.apache.fop.afp.Factory; -import org.apache.fop.afp.fonts.AFPFont; -import org.apache.fop.afp.fonts.AFPFontAttributes; -import org.apache.fop.afp.modca.triplets.FullyQualifiedNameTriplet; - -/** - * A data stream is a continuous ordered stream of data elements and objects - * conforming to a given format. Application programs can generate data streams - * destined for a presentation service, archive library, presentation device or - * another application program. The strategic presentation data stream - * architectures used is Mixed Object Document Content Architecture (MO:DCA). - * - * The MO:DCA architecture defines the data stream used by applications to - * describe documents and object envelopes for interchange with other - * applications and application services. Documents defined in the MO:DCA format - * may be archived in a database, then later retrieved, viewed, annotated and - * printed in local or distributed systems environments. Presentation fidelity - * is accommodated by including resource objects in the documents that reference - * them. - */ -public class DataStream { - - /** Static logging instance */ - protected static final Log log = LogFactory.getLog("org.apache.xmlgraphics.afp.modca"); - - /** Boolean completion indicator */ - private boolean complete = false; - - /** The AFP document object */ - private Document document = null; - - /** The current page group object */ - private PageGroup currentPageGroup = null; - - /** The current page object */ - private PageObject currentPageObject = null; - - /** The current overlay object */ - private Overlay currentOverlay = null; - - /** The current page */ - private AbstractPageObject currentPage = null; - - /** The MO:DCA interchange set in use (default to MO:DCA-P IS/2 set) */ - private InterchangeSet interchangeSet - = InterchangeSet.valueOf(InterchangeSet.MODCA_PRESENTATION_INTERCHANGE_SET_2); - - private final Factory factory; - - private OutputStream outputStream; - - /** the afp painting state */ - private final AFPPaintingState state; - - /** - * Default constructor for the AFPDocumentStream. - * - * @param factory the resource factory - * @param state the AFP painting state - * @param outputStream the outputstream to write to - */ - public DataStream(Factory factory, AFPPaintingState state, OutputStream outputStream) { - this.state = state; - this.factory = factory; - this.outputStream = outputStream; - } - - /** - * Returns the outputstream - * - * @return the outputstream - */ - public OutputStream getOutputStream() { - return this.outputStream; - } - - /** - * Returns the document object - * - * @return the document object - */ - private Document getDocument() { - return this.document; - } - - /** - * Returns the current page - * - * @return the current page - */ - public AbstractPageObject getCurrentPage() { - return this.currentPage; - } - - /** - * The document is started by invoking this method which creates an instance - * of the AFP Document object. - * - * @param name - * the name of this document. - */ - public void setDocumentName(String name) { - if (name != null) { - getDocument().setFullyQualifiedName( - FullyQualifiedNameTriplet.TYPE_BEGIN_DOCUMENT_REF, - FullyQualifiedNameTriplet.FORMAT_CHARSTR, name); - } - } - - /** {@inheritDoc} */ - public void endDocument() throws IOException { - if (complete) { - String msg = "Invalid state - document already ended."; - log.warn("endDocument():: " + msg); - throw new IllegalStateException(msg); - } - - if (currentPageObject != null) { - // End the current page if necessary - endPage(); - } - - if (currentPageGroup != null) { - // End the current page group if necessary - endPageGroup(); - } - - // Write out document - if (document != null) { - document.endDocument(); - document.writeToStream(this.outputStream); - } - - this.outputStream.flush(); - - this.complete = true; - - this.document = null; - - this.outputStream = null; - } - - /** - * Start a new page. When processing has finished on the current page, the - * {@link #endPage()}method must be invoked to mark the page ending. - * - * @param pageWidth - * the width of the page - * @param pageHeight - * the height of the page - * @param pageRotation - * the rotation of the page - * @param pageWidthRes - * the width resolution of the page - * @param pageHeightRes - * the height resolution of the page - */ - public void startPage(int pageWidth, int pageHeight, int pageRotation, - int pageWidthRes, int pageHeightRes) { - currentPageObject = factory.createPage(pageWidth, pageHeight, - pageRotation, pageWidthRes, pageHeightRes); - currentPage = currentPageObject; - currentOverlay = null; - } - - /** - * Start a new overlay. When processing has finished on the current overlay, - * the {@link #endOverlay()}method must be invoked to mark the overlay - * ending. - * - * @param x - * the x position of the overlay on the page - * @param y - * the y position of the overlay on the page - * @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 - */ - public void startOverlay(int x, int y, int width, int height, int widthRes, - int heightRes, int overlayRotation) { - this.currentOverlay = factory.createOverlay( - width, height, widthRes, heightRes, overlayRotation); - - String overlayName = currentOverlay.getName(); - currentPageObject.createIncludePageOverlay(overlayName, x, y, 0); - currentPage = currentOverlay; - } - - /** - * Helper method to mark the end of the current overlay. - * - * @throws IOException thrown if an I/O exception of some sort has occurred - */ - public void endOverlay() throws IOException { - if (currentOverlay != null) { - currentOverlay.endPage(); - currentOverlay = null; - currentPage = currentPageObject; - } - } - - /** - * Helper method to save the current page. - * - * @return current page object that was saved - */ - public PageObject savePage() { - PageObject pageObject = currentPageObject; - if (currentPageGroup != null) { - currentPageGroup.addPage(currentPageObject); - } else { - document.addPage(currentPageObject); - } - currentPageObject = null; - currentPage = null; - return pageObject; - } - - /** - * Helper method to restore the current page. - * - * @param pageObject - * page object - */ - public void restorePage(PageObject pageObject) { - currentPageObject = pageObject; - currentPage = pageObject; - } - - /** - * Helper method to mark the end of the current page. - * - * @throws IOException thrown if an I/O exception of some sort has occurred - */ - public void endPage() throws IOException { - if (currentPageObject != null) { - currentPageObject.endPage(); - if (currentPageGroup != null) { - currentPageGroup.addPage(currentPageObject); - currentPageGroup.writeToStream(this.outputStream); - } else { - document.addPage(currentPageObject); - document.writeToStream(this.outputStream); - } - currentPageObject = null; - currentPage = null; - } - } - - /** - * Creates the given page fonts in the current page - * - * @param pageFonts - * a collection of AFP font attributes - */ - public void addFontsToCurrentPage(Map pageFonts) { - Iterator iter = pageFonts.values().iterator(); - while (iter.hasNext()) { - AFPFontAttributes afpFontAttributes = (AFPFontAttributes) iter - .next(); - createFont(afpFontAttributes.getFontReference(), afpFontAttributes - .getFont(), afpFontAttributes.getPointSize()); - } - } - - /** - * Helper method to create a map coded font object on the current page, this - * method delegates the construction of the map coded font object to the - * active environment group on the current page. - * - * @param fontReference - * the font number used as the resource identifier - * @param font - * the font - * @param size - * the point size of the font - */ - public void createFont(int fontReference, AFPFont font, int size) { - currentPage.createFont(fontReference, font, size); - } - - /** - * Returns a point on the current page - * - * @param x the X-coordinate - * @param y the Y-coordinate - * @return a point on the current page - */ - private Point getPoint(int x, int y) { - Point p = new Point(); - int rotation = state.getRotation(); - switch (rotation) { - case 90: - p.x = y; - p.y = currentPage.getWidth() - x; - break; - case 180: - p.x = currentPage.getWidth() - x; - p.y = currentPage.getHeight() - y; - break; - case 270: - p.x = currentPage.getHeight() - y; - p.y = x; - break; - default: - p.x = x; - p.y = y; - break; - } - return p; - } - - /** - * Helper method to create text on the current page, this method delegates - * to the current presentation text object in order to construct the text. - * - * @param textDataInfo - * the afp text data - */ - public void createText(AFPTextDataInfo textDataInfo) { - int rotation = state.getRotation(); - if (rotation != 0) { - textDataInfo.setRotation(rotation); - Point p = getPoint(textDataInfo.getX(), textDataInfo.getY()); - textDataInfo.setX(p.x); - textDataInfo.setY(p.y); - } - currentPage.createText(textDataInfo); - } - - /** - * Method to create a line on the current page. - * - * @param lineDataInfo the line data information. - */ - public void createLine(AFPLineDataInfo lineDataInfo) { - currentPage.createLine(lineDataInfo); - } - - /** - * This method will create shading on the page using the specified - * coordinates (the shading contrast is controlled via the red, green, blue - * parameters, by converting this to grey scale). - * - * @param x - * the x coordinate of the shading - * @param y - * the y coordinate of the shading - * @param w - * the width of the shaded area - * @param h - * the height of the shaded area - * @param col - * the shading color - */ - public void createShading(int x, int y, int w, int h, Color col) { - currentPageObject.createShading(x, y, w, h, col.getRed(), col.getGreen(), col.getBlue()); - } - - /** - * Helper method which allows creation of the MPO object, via the AEG. And - * the IPO via the Page. (See actual object for descriptions.) - * - * @param name - * the name of the static overlay - */ - public void createIncludePageOverlay(String name) { - currentPageObject.createIncludePageOverlay(name, 0, 0, state.getRotation()); - currentPageObject.getActiveEnvironmentGroup().createOverlay(name); - } - - /** - * Helper method which allows creation of the IMM object. - * - * @param name - * the name of the medium map - */ - public void createInvokeMediumMap(String name) { - currentPageGroup.createInvokeMediumMap(name); - } - - /** - * Creates an IncludePageSegment on the current page. - * - * @param name - * the name of the include page segment - * @param x - * the x coordinate for the overlay - * @param y - * the y coordinate for the overlay - */ - public void createIncludePageSegment(String name, int x, int y) { - int xOrigin; - int yOrigin; - int orientation = state.getRotation(); - switch (orientation) { - case 90: - xOrigin = currentPage.getWidth() - y; - yOrigin = x; - break; - case 180: - xOrigin = currentPage.getWidth() - x; - yOrigin = currentPage.getHeight() - y; - break; - case 270: - xOrigin = y; - yOrigin = currentPage.getHeight() - x; - break; - default: - xOrigin = x; - yOrigin = y; - break; - } - currentPage.createIncludePageSegment(name, xOrigin, yOrigin); - } - - /** - * Creates a TagLogicalElement on the current page. - * - * @param attributes - * the array of key value pairs. - */ - public void createPageTagLogicalElement(TagLogicalElementBean[] attributes) { - for (int i = 0; i < attributes.length; i++) { - String name = attributes[i].getKey(); - String value = attributes[i].getValue(); - currentPage.createTagLogicalElement(name, value); - } - } - - /** - * Creates a TagLogicalElement on the current page group. - * - * @param attributes - * the array of key value pairs. - */ - public void createPageGroupTagLogicalElement(TagLogicalElementBean[] attributes) { - for (int i = 0; i < attributes.length; i++) { - String name = attributes[i].getKey(); - String value = attributes[i].getValue(); - currentPageGroup.createTagLogicalElement(name, value); - } - } - - /** - * Creates a TagLogicalElement on the current page or page group - * - * @param name - * The tag name - * @param value - * The tag value - */ - public void createTagLogicalElement(String name, String value) { - if (currentPageGroup != null) { - currentPageGroup.createTagLogicalElement(name, value); - } else { - currentPage.createTagLogicalElement(name, value); - } - } - - /** - * Creates a NoOperation item - * - * @param content - * byte data - */ - public void createNoOperation(String content) { - currentPage.createNoOperation(content); - } - - /** - * Returns the current page group - * - * @return the current page group - */ - public PageGroup getCurrentPageGroup() { - return this.currentPageGroup; - } - - /** - * Start a new document. - * - * @throws IOException thrown if an I/O exception of some sort has occurred - */ - public void startDocument() throws IOException { - this.document = factory.createDocument(); - document.writeToStream(this.outputStream); - } - - /** - * Start a new page group. When processing has finished on the current page - * group the {@link #endPageGroup()}method must be invoked to mark the page - * group ending. - * - * @throws IOException thrown if an I/O exception of some sort has occurred - */ - public void startPageGroup() throws IOException { - endPageGroup(); - this.currentPageGroup = factory.createPageGroup(); - } - - /** - * Helper method to mark the end of the page group. - * - * @throws IOException thrown if an I/O exception of some sort has occurred - */ - public void endPageGroup() throws IOException { - if (currentPageGroup != null) { - currentPageGroup.endPageGroup(); - document.addPageGroup(currentPageGroup); - document.writeToStream(outputStream); - currentPageGroup = null; - } - } - - /** - * Sets the MO:DCA interchange set to use - * - * @param interchangeSet the MO:DCA interchange set - */ - public void setInterchangeSet(InterchangeSet interchangeSet) { - this.interchangeSet = interchangeSet; - } - - /** - * Returns the MO:DCA interchange set in use - * - * @return the MO:DCA interchange set in use - */ - public InterchangeSet getInterchangeSet() { - return this.interchangeSet; - } - - /** - * Returns the resource group for a given resource info - * - * @param level a resource level - * @return a resource group for the given resource info - */ - public ResourceGroup getResourceGroup(AFPResourceLevel level) { - ResourceGroup resourceGroup = null; - if (level.isDocument()) { - resourceGroup = document.getResourceGroup(); - } else if (level.isPageGroup()) { - resourceGroup = currentPageGroup.getResourceGroup(); - } else if (level.isPage()) { - resourceGroup = currentPageObject.getResourceGroup(); - } - return resourceGroup; - } - -} diff --git a/src/java/org/apache/fop/afp/modca/Document.java b/src/java/org/apache/fop/afp/modca/Document.java index bb0dbebe3..02a7b64e1 100644 --- a/src/java/org/apache/fop/afp/modca/Document.java +++ b/src/java/org/apache/fop/afp/modca/Document.java @@ -69,11 +69,7 @@ public final class Document extends AbstractResourceEnvironmentGroupContainer { complete = true; } - /** - * Returns an indication if the page group is complete - * - * @return whether or not this page group is complete - */ + /** {@inheritDoc} */ public boolean isComplete() { return complete; } diff --git a/src/java/org/apache/fop/afp/modca/GraphicsObject.java b/src/java/org/apache/fop/afp/modca/GraphicsObject.java index da6079d33..710e7364b 100644 --- a/src/java/org/apache/fop/afp/modca/GraphicsObject.java +++ b/src/java/org/apache/fop/afp/modca/GraphicsObject.java @@ -22,18 +22,24 @@ package org.apache.fop.afp.modca; import java.awt.Color; import java.io.IOException; import java.io.OutputStream; +import java.util.Iterator; import java.util.List; import org.apache.fop.afp.AFPDataObjectInfo; import org.apache.fop.afp.AFPObjectAreaInfo; +import org.apache.fop.afp.Completable; import org.apache.fop.afp.Factory; +import org.apache.fop.afp.StructuredData; +import org.apache.fop.afp.goca.GraphicsAreaBegin; +import org.apache.fop.afp.goca.GraphicsAreaEnd; import org.apache.fop.afp.goca.GraphicsBox; +import org.apache.fop.afp.goca.GraphicsChainedSegment; +import org.apache.fop.afp.goca.GraphicsCharacterString; import org.apache.fop.afp.goca.GraphicsData; import org.apache.fop.afp.goca.GraphicsFillet; -import org.apache.fop.afp.goca.GraphicsFilletRelative; import org.apache.fop.afp.goca.GraphicsFullArc; +import org.apache.fop.afp.goca.GraphicsImage; import org.apache.fop.afp.goca.GraphicsLine; -import org.apache.fop.afp.goca.GraphicsLineRelative; import org.apache.fop.afp.goca.GraphicsSetArcParameters; import org.apache.fop.afp.goca.GraphicsSetCharacterSet; import org.apache.fop.afp.goca.GraphicsSetCurrentPosition; @@ -41,7 +47,6 @@ import org.apache.fop.afp.goca.GraphicsSetLineType; import org.apache.fop.afp.goca.GraphicsSetLineWidth; import org.apache.fop.afp.goca.GraphicsSetPatternSymbol; import org.apache.fop.afp.goca.GraphicsSetProcessColor; -import org.apache.fop.afp.goca.GraphicsString; /** * Top-level GOCA graphics object. @@ -51,12 +56,27 @@ import org.apache.fop.afp.goca.GraphicsString; public class GraphicsObject extends AbstractDataObject { /** The graphics data */ - private GraphicsData data = null; + private GraphicsData currentData = null; /** list of objects contained within this container */ protected List/**/ objects = new java.util.ArrayList/**/(); + /** the current color */ + private Color currentColor; + + /** the current line type */ + private byte currentLineType; + + /** the current line width */ + private int currentLineWidth; + + /** the current fill pattern */ + private byte currentPatternSymbol; + + /** the current character set */ + private int currentCharacterSet; + /** * Default constructor * @@ -85,13 +105,18 @@ public class GraphicsObject extends AbstractDataObject { } /** {@inheritDoc} */ - public void addObject(StructuredDataObject drawingOrder) { - if (data == null - || (data.getDataLength() + drawingOrder.getDataLength()) - >= GraphicsData.MAX_DATA_LEN) { + public void addObject(StructuredData object) { + if (currentData == null) { newData(); + } else if (currentData.getDataLength() + object.getDataLength() + >= GraphicsData.MAX_DATA_LEN) { + // graphics data full so transfer current incomplete segment to new data + GraphicsChainedSegment currentSegment + = (GraphicsChainedSegment)currentData.removeCurrentSegment(); + currentSegment.setName(newData().createSegmentName()); + currentData.addSegment(currentSegment); } - data.addObject(drawingOrder); + currentData.addObject(object); } /** @@ -100,10 +125,10 @@ public class GraphicsObject extends AbstractDataObject { * @return the current graphics data */ private GraphicsData getData() { - if (this.data == null) { + if (this.currentData == null) { return newData(); } - return this.data; + return this.currentData; } /** @@ -112,9 +137,12 @@ public class GraphicsObject extends AbstractDataObject { * @return a newly created graphics data */ private GraphicsData newData() { - this.data = factory.createGraphicsData(); - objects.add(data); - return data; + if (currentData != null) { + currentData.setComplete(true); + } + this.currentData = factory.createGraphicsData(); + objects.add(currentData); + return currentData; } /** @@ -123,7 +151,10 @@ public class GraphicsObject extends AbstractDataObject { * @param color the active color to use */ public void setColor(Color color) { - addObject(new GraphicsSetProcessColor(color)); + if (!color.equals(currentColor)) { + this.currentColor = color; + addObject(new GraphicsSetProcessColor(color)); + } } /** @@ -138,43 +169,60 @@ public class GraphicsObject extends AbstractDataObject { /** * Sets the line width * - * @param multiplier the line width multiplier + * @param lineWidth the line width multiplier */ - public void setLineWidth(int multiplier) { - GraphicsSetLineWidth graphicsSetLineWidth = new GraphicsSetLineWidth(multiplier); - addObject(graphicsSetLineWidth); + public void setLineWidth(int lineWidth) { + if (lineWidth != currentLineWidth) { + currentLineWidth = lineWidth; + addObject(new GraphicsSetLineWidth(lineWidth)); + } } /** * Sets the line type * - * @param type the line type + * @param lineType the line type */ - public void setLineType(byte type) { - GraphicsSetLineType graphicsSetLineType = new GraphicsSetLineType(type); - addObject(graphicsSetLineType); + public void setLineType(byte lineType) { + if (lineType != currentLineType) { + currentLineType = lineType; + addObject(new GraphicsSetLineType(lineType)); + } } /** - * Sets whether to fill the next shape + * Sets whether the following shape is to be filled * - * @param fill whether to fill the next shape + * @param fill true if the following shape is to be filled */ public void setFill(boolean fill) { - GraphicsSetPatternSymbol graphicsSetPattern = new GraphicsSetPatternSymbol( - fill ? GraphicsSetPatternSymbol.SOLID_FILL - : GraphicsSetPatternSymbol.NO_FILL - ); - addObject(graphicsSetPattern); + setPatternSymbol(fill ? + GraphicsSetPatternSymbol.SOLID_FILL : + GraphicsSetPatternSymbol.NO_FILL); + } + + /** + * Sets the fill pattern of the next shape + * + * @param the fill pattern of the next shape + */ + public void setPatternSymbol(byte patternSymbol) { + if (currentPatternSymbol != patternSymbol) { + currentPatternSymbol = patternSymbol; + addObject(new GraphicsSetPatternSymbol(patternSymbol)); + } } /** * Sets the character set to use * - * @param fontReference the character set (font) reference + * @param characterSet the character set (font) reference */ - public void setCharacterSet(int fontReference) { - addObject(new GraphicsSetCharacterSet(fontReference)); + public void setCharacterSet(int characterSet) { + if (currentCharacterSet != characterSet) { + currentCharacterSet = characterSet; + addObject(new GraphicsSetCharacterSet(characterSet)); + } } /** @@ -193,11 +241,7 @@ public class GraphicsObject extends AbstractDataObject { * @param relative relative true for a line at current position (relative to) */ public void addLine(int[] coords, boolean relative) { - if (relative) { - addObject(new GraphicsLineRelative(coords)); - } else { - addObject(new GraphicsLine(coords)); - } + addObject(new GraphicsLine(coords, relative)); } /** @@ -222,14 +266,10 @@ public class GraphicsObject extends AbstractDataObject { * Adds a fillet (curve) at the given coordinates * * @param coords the x/y coordinates - * @param relative relative true for a fillet at current position (relative to) + * @param relative relative true for a fillet (curve) at current position (relative to) */ public void addFillet(int[] coords, boolean relative) { - if (relative) { - addObject(new GraphicsFilletRelative(coords)); - } else { - addObject(new GraphicsFillet(coords)); - } + addObject(new GraphicsFillet(coords, relative)); } /** @@ -245,7 +285,7 @@ public class GraphicsObject extends AbstractDataObject { } /** - * Adds an arc + * Adds a full arc * * @param x the x coordinate * @param y the y coordinate @@ -256,18 +296,18 @@ public class GraphicsObject extends AbstractDataObject { addObject(new GraphicsFullArc(x, y, mh, mhr)); } -// /** -// * Adds an image -// * -// * @param x the x coordinate -// * @param y the y coordinate -// * @param width the image width -// * @param height the image height -// * @param imgData the image data -// */ -// public void addImage(int x, int y, int width, int height, byte[] imgData) { -// addObject(new GraphicsImage(x, y, width, height, imgData)); -// } + /** + * Adds an image + * + * @param x the x coordinate + * @param y the y coordinate + * @param width the image width + * @param height the image height + * @param imgData the image data + */ + public void addImage(int x, int y, int width, int height, byte[] imgData) { + addObject(new GraphicsImage(x, y, width, height, imgData)); + } /** * Adds a string @@ -277,26 +317,21 @@ public class GraphicsObject extends AbstractDataObject { * @param y the y coordinate */ public void addString(String str, int x, int y) { - addObject(new GraphicsString(str, x, y)); + addObject(new GraphicsCharacterString(str, x, y)); } /** * Begins a graphics area (start of fill) */ public void beginArea() { - if (data == null) { - newData(); - } - data.beginArea(); + addObject(new GraphicsAreaBegin()); } /** * Ends a graphics area (end of fill) */ public void endArea() { - if (data != null) { - data.endArea(); - } + addObject(new GraphicsAreaEnd()); } /** {@inheritDoc} */ @@ -311,8 +346,19 @@ public class GraphicsObject extends AbstractDataObject { getData().newSegment(); } + /** {@inheritDoc} */ + public void setComplete(boolean complete) { + Iterator it = objects.iterator(); + while (it.hasNext()) { + Completable completedObject = (Completable)it.next(); + completedObject.setComplete(true); + } + super.setComplete(complete); + } + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { + super.writeStart(os); byte[] data = new byte[17]; copySF(data, Type.BEGIN, Category.GRAPHICS); os.write(data); @@ -321,7 +367,7 @@ public class GraphicsObject extends AbstractDataObject { /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { super.writeContent(os); - super.writeObjects(objects, os); + writeObjects(objects, os); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/afp/modca/MapCodedFont.java b/src/java/org/apache/fop/afp/modca/MapCodedFont.java index 01e9abc6f..54b4d1796 100644 --- a/src/java/org/apache/fop/afp/modca/MapCodedFont.java +++ b/src/java/org/apache/fop/afp/modca/MapCodedFont.java @@ -43,14 +43,12 @@ import org.apache.fop.afp.util.BinaryUtils; */ public class MapCodedFont extends AbstractStructuredObject { - /** - * The collection of map coded fonts (maximum of 254) - */ + /** the collection of map coded fonts (maximum of 254) */ private final List/**/ fontList = new java.util.ArrayList/**/(); /** - * Constructor for the MapCodedFont + * Main constructor */ public MapCodedFont() { } diff --git a/src/java/org/apache/fop/afp/modca/ObjectEnvironmentGroup.java b/src/java/org/apache/fop/afp/modca/ObjectEnvironmentGroup.java index 8cb610d9e..883a5446d 100644 --- a/src/java/org/apache/fop/afp/modca/ObjectEnvironmentGroup.java +++ b/src/java/org/apache/fop/afp/modca/ObjectEnvironmentGroup.java @@ -38,13 +38,13 @@ import org.apache.fop.afp.util.BinaryUtils; public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { /** the PresentationEnvironmentControl for the object environment group */ - private PresentationEnvironmentControl presentationEnvironmentControl = null; + private PresentationEnvironmentControl presentationEnvironmentControl; /** the ObjectAreaDescriptor for the object environment group */ - private ObjectAreaDescriptor objectAreaDescriptor = null; + private ObjectAreaDescriptor objectAreaDescriptor; /** the ObjectAreaPosition for the object environment group */ - private ObjectAreaPosition objectAreaPosition = null; + private ObjectAreaPosition objectAreaPosition; /** the DataDescriptor for the object environment group */ private AbstractDescriptor dataDescriptor; @@ -95,6 +95,8 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { data[2] = len[1]; os.write(data); + + writeTriplets(os); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/afp/modca/PageGroup.java b/src/java/org/apache/fop/afp/modca/PageGroup.java index 47e378d72..13be9745e 100644 --- a/src/java/org/apache/fop/afp/modca/PageGroup.java +++ b/src/java/org/apache/fop/afp/modca/PageGroup.java @@ -74,7 +74,7 @@ public class PageGroup extends AbstractResourceEnvironmentGroupContainer { /** * Method to mark the end of the page group. */ - protected void endPageGroup() { + public void endPageGroup() { complete = true; } diff --git a/src/java/org/apache/fop/afp/modca/ResourceEnvironmentGroup.java b/src/java/org/apache/fop/afp/modca/ResourceEnvironmentGroup.java index cb0653ddd..2e4f57314 100644 --- a/src/java/org/apache/fop/afp/modca/ResourceEnvironmentGroup.java +++ b/src/java/org/apache/fop/afp/modca/ResourceEnvironmentGroup.java @@ -5,9 +5,9 @@ * 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. @@ -23,34 +23,27 @@ import java.io.IOException; import java.io.OutputStream; import java.util.List; +import org.apache.fop.afp.Completable; + /** * A Resource Environment Group contains a set of resources for a document * or for a group of pages in a document. */ -public class ResourceEnvironmentGroup extends AbstractEnvironmentGroup { - /** - * Default name for the resource group - */ +public class ResourceEnvironmentGroup extends AbstractEnvironmentGroup implements Completable { + + /** default name for the resource group */ private static final String DEFAULT_NAME = "REG00001"; - /** - * The maps data resources contained in this resource environment group - */ + /** the maps data resources contained in this resource environment group */ private List/**/ mapDataResources = null; - - /** - * The maps page overlays contained in this resource environment group - */ + + /** the maps page overlays contained in this resource environment group */ private List mapPageOverlays = null; - - /** - * The pre-process presentation objects contained in this resource environment group - */ + + /** the pre-process presentation objects contained in this resource environment group */ private List/**/ preProcessPresentationObjects = null; - /** - * The resource environment group state - */ + /** the resource environment group state */ private boolean complete = false; /** @@ -100,16 +93,7 @@ public class ResourceEnvironmentGroup extends AbstractEnvironmentGroup { // createOverlay(obj.get); // getPreprocessPresentationObjects().add(new PreprocessPresentationObject(obj)); // } - - /** - * 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} */ protected void writeStart(OutputStream os) throws IOException { byte[] data = new byte[17]; @@ -131,4 +115,14 @@ public class ResourceEnvironmentGroup extends AbstractEnvironmentGroup { writeObjects(preProcessPresentationObjects, os); } + /** {@inheritDoc} */ + public void setComplete(boolean complete) { + this.complete = complete; + } + + /** {@inheritDoc} */ + public boolean isComplete() { + return complete; + } + } diff --git a/src/java/org/apache/fop/afp/modca/StreamedResourceGroup.java b/src/java/org/apache/fop/afp/modca/StreamedResourceGroup.java index d6ab741b6..65df33ae4 100644 --- a/src/java/org/apache/fop/afp/modca/StreamedResourceGroup.java +++ b/src/java/org/apache/fop/afp/modca/StreamedResourceGroup.java @@ -22,10 +22,12 @@ package org.apache.fop.afp.modca; import java.io.IOException; import java.io.OutputStream; +import org.apache.fop.afp.Completable; + /** * A print-file resource group */ -public class StreamedResourceGroup extends ResourceGroup { +public class StreamedResourceGroup extends ResourceGroup implements Completable { /** the outputstream to write to */ private final OutputStream os; @@ -72,15 +74,6 @@ public class StreamedResourceGroup extends ResourceGroup { complete = true; } - /** - * Returns true if this resource group is complete - * - * @return true if this resource group is complete - */ - public boolean isComplete() { - return this.complete; - } - /** * Returns the outputstream * @@ -89,4 +82,15 @@ public class StreamedResourceGroup extends ResourceGroup { public OutputStream getOutputStream() { return this.os; } + + /** {@inheritDoc} */ + public void setComplete(boolean complete) { + this.complete = complete; + } + + /** {@inheritDoc} */ + public boolean isComplete() { + return this.complete; + } + } \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/modca/StructuredDataObject.java b/src/java/org/apache/fop/afp/modca/StructuredDataObject.java deleted file mode 100644 index f95810ff2..000000000 --- a/src/java/org/apache/fop/afp/modca/StructuredDataObject.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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.afp.modca; - -/** - * An AFP object which is able to know its own data length before writeToStream() - */ -public interface StructuredDataObject { - - /** - * Returns the data length of this structured field - * - * @return the data length of this structured field - */ - int getDataLength(); -} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/modca/triplets/AbstractTriplet.java b/src/java/org/apache/fop/afp/modca/triplets/AbstractTriplet.java index 63914eb73..4e75d4204 100644 --- a/src/java/org/apache/fop/afp/modca/triplets/AbstractTriplet.java +++ b/src/java/org/apache/fop/afp/modca/triplets/AbstractTriplet.java @@ -20,12 +20,12 @@ package org.apache.fop.afp.modca.triplets; import org.apache.fop.afp.Streamable; -import org.apache.fop.afp.modca.StructuredDataObject; +import org.apache.fop.afp.StructuredData; /** * A simple implementation of a MOD:CA triplet */ -public abstract class AbstractTriplet implements Streamable, StructuredDataObject { +public abstract class AbstractTriplet implements Streamable, StructuredData { public static final byte CODED_GRAPHIC_CHARACTER_SET_GLOBAL_IDENTIFIER = 0x01; /** Triplet identifiers */ diff --git a/src/java/org/apache/fop/afp/modca/triplets/DescriptorPositionTriplet.java b/src/java/org/apache/fop/afp/modca/triplets/DescriptorPositionTriplet.java index 61b279b5c..cff6400af 100644 --- a/src/java/org/apache/fop/afp/modca/triplets/DescriptorPositionTriplet.java +++ b/src/java/org/apache/fop/afp/modca/triplets/DescriptorPositionTriplet.java @@ -22,6 +22,9 @@ package org.apache.fop.afp.modca.triplets; import java.io.IOException; import java.io.OutputStream; +/** + * Associates an ObjectAreaPosition with and ObjectAreaDescriptor structured field + */ public class DescriptorPositionTriplet extends AbstractTriplet { private final byte oapId; diff --git a/src/java/org/apache/fop/afp/modca/triplets/ResourceObjectTypeTriplet.java b/src/java/org/apache/fop/afp/modca/triplets/ResourceObjectTypeTriplet.java index ecc12122d..e4b13177d 100644 --- a/src/java/org/apache/fop/afp/modca/triplets/ResourceObjectTypeTriplet.java +++ b/src/java/org/apache/fop/afp/modca/triplets/ResourceObjectTypeTriplet.java @@ -22,7 +22,7 @@ package org.apache.fop.afp.modca.triplets; import java.io.IOException; import java.io.OutputStream; -/** resource object type triplet */ +/** A Resource Object Type Triplet */ public class ResourceObjectTypeTriplet extends AbstractTriplet { private static final byte RESOURCE_OBJECT = 0x21; diff --git a/src/java/org/apache/fop/afp/svg/AFPBridgeContext.java b/src/java/org/apache/fop/afp/svg/AFPBridgeContext.java index 039c1ab91..48c1001ef 100644 --- a/src/java/org/apache/fop/afp/svg/AFPBridgeContext.java +++ b/src/java/org/apache/fop/afp/svg/AFPBridgeContext.java @@ -31,6 +31,9 @@ import org.apache.fop.svg.AbstractFOPBridgeContext; import org.apache.xmlgraphics.image.loader.ImageManager; import org.apache.xmlgraphics.image.loader.ImageSessionContext; +/** + * An AFP specific implementation of a Batik BridgeContext + */ public class AFPBridgeContext extends AbstractFOPBridgeContext { private final AFPGraphics2D g2d; diff --git a/src/java/org/apache/fop/afp/svg/AFPImageElementBridge.java b/src/java/org/apache/fop/afp/svg/AFPImageElementBridge.java index de677e7ab..63661940d 100644 --- a/src/java/org/apache/fop/afp/svg/AFPImageElementBridge.java +++ b/src/java/org/apache/fop/afp/svg/AFPImageElementBridge.java @@ -22,6 +22,9 @@ package org.apache.fop.afp.svg; import org.apache.fop.svg.AbstractFOPImageElementBridge; import org.apache.xmlgraphics.image.loader.ImageFlavor; +/** + * An AFP specific implementation of a Batik SVGImageElementBridge + */ public class AFPImageElementBridge extends AbstractFOPImageElementBridge { private final ImageFlavor[] supportedFlavors = new ImageFlavor[] diff --git a/src/java/org/apache/fop/afp/svg/package.html b/src/java/org/apache/fop/afp/svg/package.html new file mode 100644 index 000000000..bd24b246f --- /dev/null +++ b/src/java/org/apache/fop/afp/svg/package.html @@ -0,0 +1,23 @@ + + + +org.apache.fop.afp.modca.svg Package + +

Contains a collection of AFP specific Batik bridges.

+ + \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/util/package.html b/src/java/org/apache/fop/afp/util/package.html new file mode 100644 index 000000000..525bdbe2a --- /dev/null +++ b/src/java/org/apache/fop/afp/util/package.html @@ -0,0 +1,23 @@ + + + +org.apache.fop.afp.modca.triplets Package + +

Contains a collection of useful AFP utility classes.

+ + \ No newline at end of file diff --git a/src/java/org/apache/fop/pdf/PDFPaintingState.java b/src/java/org/apache/fop/pdf/PDFPaintingState.java index 7dd876c25..11dfc635a 100644 --- a/src/java/org/apache/fop/pdf/PDFPaintingState.java +++ b/src/java/org/apache/fop/pdf/PDFPaintingState.java @@ -170,7 +170,7 @@ public class PDFPaintingState extends org.apache.fop.util.AbstractPaintingState * This call should be used when the q operator is used * so that the state is known when popped. */ - public void push() { + public void save() { AbstractData data = getData(); AbstractData copy = (AbstractData)data.clone(); data.clearTransform(); diff --git a/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java b/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java index 8e43d1c28..becafda23 100644 --- a/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java +++ b/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java @@ -61,7 +61,7 @@ public class AFPGraphics2DAdapter extends AbstractGraphics2DAdapter { final boolean textAsShapes = false; AFPGraphics2D g2d = afpInfo.createGraphics2D(textAsShapes); - paintingState.push(); + paintingState.save(); //Fallback solution: Paint to a BufferedImage if (afpInfo.paintAsBitmap()) { @@ -95,7 +95,7 @@ public class AFPGraphics2DAdapter extends AbstractGraphics2DAdapter { resourceManager.createObject(graphicsObjectInfo); } - paintingState.pop(); + paintingState.restore(); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/afp/AFPInfo.java b/src/java/org/apache/fop/render/afp/AFPInfo.java index 59050b66d..fb1ec87a8 100644 --- a/src/java/org/apache/fop/render/afp/AFPInfo.java +++ b/src/java/org/apache/fop/render/afp/AFPInfo.java @@ -215,10 +215,10 @@ public final class AFPInfo { /** * Sets the AFP state * - * @param state the AFP state + * @param paintingState the AFP state */ - public void setPaintingState(AFPPaintingState state) { - this.paintingState = state; + public void setPaintingState(AFPPaintingState paintingState) { + this.paintingState = paintingState; } /** diff --git a/src/java/org/apache/fop/render/afp/AFPRenderer.java b/src/java/org/apache/fop/render/afp/AFPRenderer.java index b85dd96f9..918c67e33 100644 --- a/src/java/org/apache/fop/render/afp/AFPRenderer.java +++ b/src/java/org/apache/fop/render/afp/AFPRenderer.java @@ -41,13 +41,13 @@ import org.apache.fop.afp.AFPRectanglePainter; import org.apache.fop.afp.AFPResourceManager; import org.apache.fop.afp.AFPTextDataInfo; import org.apache.fop.afp.AFPUnitConverter; -import org.apache.fop.afp.BorderPaintInfo; -import org.apache.fop.afp.RectanglePaintInfo; +import org.apache.fop.afp.BorderPaintingInfo; +import org.apache.fop.afp.DataStream; +import org.apache.fop.afp.RectanglePaintingInfo; import org.apache.fop.afp.fonts.AFPFont; import org.apache.fop.afp.fonts.AFPFontAttributes; import org.apache.fop.afp.fonts.AFPFontCollection; import org.apache.fop.afp.fonts.AFPPageFonts; -import org.apache.fop.afp.modca.DataStream; import org.apache.fop.afp.modca.PageObject; import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; @@ -171,9 +171,9 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { */ public AFPRenderer() { super(); + this.imageHandlerRegistry = new AFPImageHandlerRegistry(); this.resourceManager = new AFPResourceManager(); this.paintingState = new AFPPaintingState(); - this.imageHandlerRegistry = new AFPImageHandlerRegistry(); this.unitConv = paintingState.getUnitConverter(); } @@ -335,13 +335,13 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { /** {@inheritDoc} */ public void drawBorderLine(float x1, float y1, float x2, float y2, boolean horz, boolean startOrBefore, int style, Color col) { - BorderPaintInfo borderPaintInfo = new BorderPaintInfo(x1, y1, x2, y2, horz, style, col); + BorderPaintingInfo borderPaintInfo = new BorderPaintingInfo(x1, y1, x2, y2, horz, style, col); borderPainter.paint(borderPaintInfo); } /** {@inheritDoc} */ public void fillRect(float x, float y, float width, float height) { - RectanglePaintInfo rectanglePaintInfo = new RectanglePaintInfo(x, y, width, height); + RectanglePaintingInfo rectanglePaintInfo = new RectanglePaintingInfo(x, y, width, height); rectanglePainter.paint(rectanglePaintInfo); } @@ -485,23 +485,23 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { /** {@inheritDoc} */ public void restoreStateStackAfterBreakOut(List breakOutList) { log.debug("Block.FIXED --> restoring context after break-out"); - paintingState.pushAll(breakOutList); + paintingState.saveAll(breakOutList); } /** {@inheritDoc} */ protected List breakOutOfStateStack() { log.debug("Block.FIXED --> break out"); - return paintingState.popAll(); + return paintingState.restoreAll(); } /** {@inheritDoc} */ public void saveGraphicsState() { - paintingState.push(); + paintingState.save(); } /** {@inheritDoc} */ public void restoreGraphicsState() { - paintingState.pop(); + paintingState.restore(); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/afp/AFPSVGHandler.java b/src/java/org/apache/fop/render/afp/AFPSVGHandler.java index bf74b4053..9deea77b4 100644 --- a/src/java/org/apache/fop/render/afp/AFPSVGHandler.java +++ b/src/java/org/apache/fop/render/afp/AFPSVGHandler.java @@ -125,7 +125,7 @@ public class AFPSVGHandler extends AbstractGenericSVGHandler { int height = afpInfo.getHeight(); int resolution = afpInfo.getResolution(); - paintingState.push(); // save + paintingState.save(); // save AFPObjectAreaInfo objectAreaInfo = createObjectAreaInfo(paintingState, x, y, width, height, resolution); @@ -140,7 +140,7 @@ public class AFPSVGHandler extends AbstractGenericSVGHandler { AFPResourceManager resourceManager = afpInfo.getResourceManager(); resourceManager.createObject(graphicsObjectInfo); - paintingState.pop(); // resume + paintingState.restore(); // resume } private AFPObjectAreaInfo createObjectAreaInfo(AFPPaintingState paintingState, diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderer.java b/src/java/org/apache/fop/render/pdf/PDFRenderer.java index ba3d89195..e31f1eaea 100644 --- a/src/java/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/java/org/apache/fop/render/pdf/PDFRenderer.java @@ -640,7 +640,7 @@ public class PDFRenderer extends AbstractPathOrientedRenderer { /** {@inheritDoc} */ protected void saveGraphicsState() { endTextObject(); - paintingState.push(); + paintingState.save(); currentStream.add("q\n"); } @@ -648,7 +648,7 @@ public class PDFRenderer extends AbstractPathOrientedRenderer { endTextObject(); currentStream.add("Q\n"); if (popState) { - paintingState.pop(); + paintingState.restore(); } } @@ -1099,7 +1099,7 @@ public class PDFRenderer extends AbstractPathOrientedRenderer { AbstractPaintingState.AbstractData data; while (true) { data = paintingState.getData(); - if (paintingState.pop() == null) { + if (paintingState.restore() == null) { break; } if (breakOutList.size() == 0) { @@ -1747,7 +1747,7 @@ public class PDFRenderer extends AbstractPathOrientedRenderer { public void renderLeader(Leader area) { renderInlineAreaBackAndBorders(area); - paintingState.push(); + paintingState.save(); saveGraphicsState(); int style = area.getRuleStyle(); float startx = (currentIPPosition + area.getBorderAndPaddingWidthStart()) / 1000f; @@ -1805,7 +1805,7 @@ public class PDFRenderer extends AbstractPathOrientedRenderer { } restoreGraphicsState(); - paintingState.pop(); + paintingState.restore(); beginTextObject(); super.renderLeader(area); } diff --git a/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java b/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java index e83579728..5d027aefe 100644 --- a/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java +++ b/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java @@ -243,7 +243,7 @@ public class PDFSVGHandler extends AbstractGenericSVGHandler pdfInfo.currentStream.add("%SVG start\n"); //Save state and update coordinate system for the SVG image - pdfInfo.pdfPaintingState.push(); + pdfInfo.pdfPaintingState.save(); pdfInfo.pdfPaintingState.concatenate(imageTransform); //Now that we have the complete transformation matrix for the image, we can update the @@ -262,7 +262,7 @@ public class PDFSVGHandler extends AbstractGenericSVGHandler context.getUserAgent().getEventBroadcaster()); eventProducer.svgRenderingError(this, e, getDocumentURI(doc)); } - pdfInfo.pdfPaintingState.pop(); + pdfInfo.pdfPaintingState.restore(); renderer.restoreGraphicsState(); pdfInfo.currentStream.add("%SVG end\n"); } diff --git a/src/java/org/apache/fop/svg/AbstractFOPBridgeContext.java b/src/java/org/apache/fop/svg/AbstractFOPBridgeContext.java index be1c3c122..ae4d67516 100644 --- a/src/java/org/apache/fop/svg/AbstractFOPBridgeContext.java +++ b/src/java/org/apache/fop/svg/AbstractFOPBridgeContext.java @@ -30,6 +30,9 @@ import org.apache.fop.fonts.FontInfo; import org.apache.xmlgraphics.image.loader.ImageManager; import org.apache.xmlgraphics.image.loader.ImageSessionContext; +/** + * A FOP base implementation of a Batik BridgeContext. + */ public abstract class AbstractFOPBridgeContext extends BridgeContext { /** The font list. */ diff --git a/src/java/org/apache/fop/svg/PDFGraphics2D.java b/src/java/org/apache/fop/svg/PDFGraphics2D.java index ab0ece2a7..5053209e3 100644 --- a/src/java/org/apache/fop/svg/PDFGraphics2D.java +++ b/src/java/org/apache/fop/svg/PDFGraphics2D.java @@ -608,7 +608,7 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand if (newClip || newTransform) { currentStream.write("q\n"); - paintingState.push(); + paintingState.save(); if (newTransform) { concatMatrix(tranvals); } @@ -634,7 +634,7 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand if (newClip || newTransform) { currentStream.write("Q\n"); - paintingState.pop(); + paintingState.restore(); } return; } @@ -646,7 +646,7 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand doDrawing(false, true, false); if (newClip || newTransform) { currentStream.write("Q\n"); - paintingState.pop(); + paintingState.restore(); } } @@ -1614,7 +1614,7 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand if (newClip || newTransform) { currentStream.write("q\n"); - paintingState.push(); + paintingState.save(); if (newTransform) { concatMatrix(tranvals); } @@ -1638,7 +1638,7 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand if (newClip || newTransform) { currentStream.write("Q\n"); - paintingState.pop(); + paintingState.restore(); } return; } @@ -1651,7 +1651,7 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand iter.getWindingRule() == PathIterator.WIND_EVEN_ODD); if (newClip || newTransform) { currentStream.write("Q\n"); - paintingState.pop(); + paintingState.restore(); } } diff --git a/src/java/org/apache/fop/util/AbstractPaintingState.java b/src/java/org/apache/fop/util/AbstractPaintingState.java index e712ce74f..4fb6b173c 100644 --- a/src/java/org/apache/fop/util/AbstractPaintingState.java +++ b/src/java/org/apache/fop/util/AbstractPaintingState.java @@ -28,9 +28,8 @@ import java.util.Iterator; import java.util.List; import java.util.Stack; - /** - * A base class which holds information about the current rendering state. + * A base class which holds information about the current painting state. */ public abstract class AbstractPaintingState implements Cloneable, Serializable { @@ -278,23 +277,23 @@ public abstract class AbstractPaintingState implements Cloneable, Serializable { /** - * Push the current painting state onto the stack. + * Save the current painting state. + * This pushes the current painting state onto the stack. * This call should be used when the Q operator is used * so that the state is known when popped. */ - public void push() { + public void save() { AbstractData copy = (AbstractData)getData().clone(); stateStack.push(copy); } /** - * Pop the painting state from the stack and set current values to popped state. - * This should be called when a Q operator is used so - * the state is restored to the correct values. + * Restore the current painting state. + * This pops the painting state from the stack and sets current values to popped state. * * @return the restored state, null if the stack is empty */ - public AbstractData pop() { + public AbstractData restore() { if (!stateStack.isEmpty()) { setData((AbstractData)stateStack.pop()); return this.data; @@ -304,30 +303,32 @@ public abstract class AbstractPaintingState implements Cloneable, Serializable { } /** - * Pushes all painting state data in the given list to the stack + * Save all painting state data. + * This pushes all painting state data in the given list to the stack * * @param dataList a state data list */ - public void pushAll(List/**/ dataList) { + public void saveAll(List/**/ dataList) { Iterator it = dataList.iterator(); while (it.hasNext()) { // save current data on stack - push(); + save(); setData((AbstractData)it.next()); } } /** - * Pops all painting state data from the stack + * Restore all painting state data. + * This pops all painting state data from the stack * * @return a list of state data popped from the stack */ - public List/**/ popAll() { + public List/**/ restoreAll() { List/**/ dataList = new java.util.ArrayList/**/(); AbstractData data; while (true) { data = getData(); - if (pop() == null) { + if (restore() == null) { break; } // insert because of stack-popping -- cgit v1.2.3