From: Adrian Cumiskey Date: Mon, 27 Oct 2008 11:11:31 +0000 (+0000) Subject: All AFP library classes without Renderer dependencies moved from org.apache.fop.rende... X-Git-Tag: fop-1_0~376^2~36 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=17bc8aa0870e3d6043ea2865e44fc2433dd5b36b;p=xmlgraphics-fop.git 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 --- diff --git a/build.xml b/build.xml index 7ab83df21..1b550b0b7 100644 --- a/build.xml +++ b/build.xml @@ -612,7 +612,7 @@ list of possible build targets. - + diff --git a/src/java/org/apache/fop/AbstractState.java b/src/java/org/apache/fop/AbstractState.java new file mode 100644 index 000000000..851c50e76 --- /dev/null +++ b/src/java/org/apache/fop/AbstractState.java @@ -0,0 +1,465 @@ +/* + * 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; + +import java.awt.Color; +import java.awt.geom.AffineTransform; +import java.io.Serializable; +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; +import java.util.Stack; + + +/** + * A base class which holds information about the current rendering state. + */ +public abstract class AbstractState implements Cloneable, Serializable { + + /** current state data */ + private AbstractData currentData = null; + + /** the state stack */ + private StateStack stateStack = null; + + /** + * Instantiates a new state data object + * + * @return a new state data object + */ + protected abstract AbstractData instantiateData(); + + /** + * Instantiates a new state object + * + * @return a new state object + */ + protected abstract AbstractState instantiateState(); + + /** + * Returns the currently valid state + * + * @return the currently valid state + */ + public AbstractData getData() { + if (currentData == null) { + currentData = instantiateData(); + } + return currentData; + } + + /** + * Set the current color. + * Check if the new color is a change and then set the current color. + * + * @param col the color to set + * @return true if the color has changed + */ + public boolean setColor(Color col) { + if (!col.equals(getData().color)) { + getData().color = col; + return true; + } + return false; + } + + /** + * Get the color. + * + * @return the color + */ + public Color getColor() { + if (getData().color == null) { + getData().color = Color.black; + } + return getData().color; + } + + /** + * Get the background color. + * + * @return the background color + */ + public Color getBackColor() { + if (getData().backColor == null) { + getData().backColor = Color.white; + } + return getData().backColor; + } + + /** + * Set the current background color. + * Check if the new background color is a change and then set the current background color. + * + * @param col the background color to set + * @return true if the color has changed + */ + public boolean setBackColor(Color col) { + if (!col.equals(getData().backColor)) { + getData().backColor = col; + return true; + } + return false; + } + + /** + * Set the current font name + * + * @param internalFontName the internal font name + * @return true if the font name has changed + */ + public boolean setFontName(String internalFontName) { + if (!internalFontName.equals(getData().fontName)) { + getData().fontName = internalFontName; + return true; + } + return false; + } + + /** + * Gets the current font name + * + * @return the current font name + */ + public String getFontName() { + return getData().fontName; + } + + /** + * Gets the current font size + * + * @return the current font size + */ + public int getFontSize() { + return getData().fontSize; + } + + /** + * Set the current font size. + * Check if the font size is a change and then set the current font size. + * + * @param size the font size to set + * @return true if the font size has changed + */ + public boolean setFontSize(int size) { + if (size != getData().fontSize) { + getData().fontSize = size; + return true; + } + return false; + } + + /** + * Set the current line width. + * + * @param width the line width in points + * @return true if the line width has changed + */ + public boolean setLineWidth(float width) { + if (getData().lineWidth != width) { + getData().lineWidth = width; + return true; + } + return false; + } + + /** + * Returns the current line width + * + * @return the current line width + */ + public float getLineWidth() { + return getData().lineWidth; + } + + /** + * Sets the dash array (line type) for the current basic stroke + * + * @param dash the line dash array + * @return true if the dash array has changed + */ + public boolean setDashArray(float[] dash) { + if (!Arrays.equals(dash, getData().dashArray)) { + getData().dashArray = dash; + return true; + } + return false; + } + + /** + * Get the current transform. + * This gets the combination of all transforms in the + * current state. + * + * @return the calculate combined transform for the current state + */ + public AffineTransform getTransform() { + AffineTransform at = new AffineTransform(); + for (Iterator iter = getStateStack().iterator(); iter.hasNext();) { + AbstractData data = (AbstractData)iter.next(); + AffineTransform stackTrans = data.getTransform(); + at.concatenate(stackTrans); + } + AffineTransform currentTrans = getData().getTransform(); + at.concatenate(currentTrans); + return at; + } + + /** + * Check the current transform. + * The transform for the current state is the combination of all + * transforms in the current state. The parameter is compared + * against this current transform. + * + * @param tf the transform the check against + * @return true if the new transform is different then the current transform + */ + public boolean checkTransform(AffineTransform tf) { + return !tf.equals(getData().getTransform()); + } + + /** + * Get a copy of the base transform for the page. Used to translate + * IPP/BPP values into X,Y positions when positioning is "fixed". + * + * @return the base transform, or null if the state stack is empty + */ + public AffineTransform getBaseTransform() { + if (getStateStack().isEmpty()) { + return null; + } else { + AbstractData baseData = (AbstractData)getStateStack().get(0); + return (AffineTransform) baseData.getTransform().clone(); + } + } + + /** + * Concatenates the given AffineTransform to the current one. + * + * @param at the transform to concatenate to the current level transform + */ + public void concatenate(AffineTransform at) { + getData().concatenate(at); + } + + /** + * Resets the current AffineTransform. + */ + public void resetTransform() { + getData().resetTransform(); + } + + /** + * Push the current 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() { + AbstractData copy = (AbstractData)getData().clone(); + getStateStack().push(copy); + } + + /** + * Pop the 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. + * + * @return the restored state, null if the stack is empty + */ + public AbstractData pop() { + if (!getStateStack().isEmpty()) { + this.currentData = (AbstractData)getStateStack().pop(); + return this.currentData; + } else { + return null; + } + } + + /** + * Clears the state stack + */ + public void clear() { + getStateStack().clear(); + currentData = null; + } + + /** + * Return the state stack + * + * @return the state stack + */ + protected Stack/**/ getStateStack() { + if (stateStack == null) { + stateStack = new StateStack(); + } + return stateStack; + } + + /** {@inheritDoc} */ + public Object clone() { + AbstractState state = instantiateState(); + state.stateStack = new StateStack(this.stateStack); + state.currentData = (AbstractData)this.currentData.clone(); + return state; + } + + /** {@inheritDoc} */ + public String toString() { + return ", stateStack=" + stateStack + + ", currentData=" + currentData; + } + + /** + * A base state data holding object + */ + public abstract class AbstractData implements Cloneable, Serializable { + + private static final long serialVersionUID = 5208418041189828624L; + + /** The current color */ + private Color color = null; + + /** The current background color */ + private Color backColor = null; + + /** The current font name */ + private String fontName = null; + + /** The current font size */ + private int fontSize = 0; + + /** The current line width */ + private float lineWidth = 0; + + /** The dash array for the current basic stroke (line type) */ + private float[] dashArray = null; + + /** The current transform */ + private AffineTransform transform = null; + + /** + * Concatenate the given AffineTransform with the current thus creating + * a new viewport. Note that all concatenation operations are logged + * so they can be replayed if necessary (ex. for block-containers with + * "fixed" positioning. + * + * @param at Transformation to perform + */ + public void concatenate(AffineTransform at) { + getTransform().concatenate(at); + } + + /** + * Get the current AffineTransform. + * + * @return the current transform + */ + public AffineTransform getTransform() { + if (transform == null) { + transform = new AffineTransform(); + } + return transform; + } + + /** + * Resets the current AffineTransform. + */ + public void resetTransform() { + transform = getBaseTransform(); +// transform = new AffineTransform(); + } + + /** + * Returns the derived rotation from the current transform + * + * @return the derived rotation from the current transform + */ + public int getDerivedRotation() { + AffineTransform at = getTransform(); + double sx = at.getScaleX(); + double sy = at.getScaleY(); + double shx = at.getShearX(); + double shy = at.getShearY(); + int rotation = 0; + if (sx == 0 && sy == 0 && shx > 0 && shy < 0) { + rotation = 270; + } else if (sx < 0 && sy < 0 && shx == 0 && shy == 0) { + rotation = 180; + } else if (sx == 0 && sy == 0 && shx < 0 && shy > 0) { + rotation = 90; + } else { + rotation = 0; + } + return rotation; + } + + /** {@inheritDoc} */ + public Object clone() { + AbstractData data = instantiateData(); + data.color = this.color; + data.backColor = this.backColor; + data.fontName = this.fontName; + data.fontSize = this.fontSize; + data.lineWidth = this.lineWidth; + data.dashArray = this.dashArray; + data.transform = new AffineTransform(this.transform); + return data; + } + + /** {@inheritDoc} */ + public String toString() { + return "color=" + color + + ", backColor=" + backColor + + ", fontName=" + fontName + + ", fontSize=" + fontSize + + ", lineWidth=" + lineWidth + + ", dashArray=" + dashArray + + ", transform=" + transform; + } + } + + /** + * No copy constructor for java.util.Stack so extended and implemented one. + */ + private class StateStack extends java.util.Stack { + + private static final long serialVersionUID = 4897178211223823041L; + + /** + * Default constructor + */ + public StateStack() { + super(); + } + + /** + * Copy constructor + * + * @param c initial contents of stack + */ + public StateStack(Collection c) { + elementCount = c.size(); + // 10% for growth + elementData = new Object[ + (int)Math.min((elementCount * 110L) / 100, Integer.MAX_VALUE)]; + c.toArray(elementData); + } + } +} diff --git a/src/java/org/apache/fop/afp/AFPAbstractGraphicsObjectPainter.java b/src/java/org/apache/fop/afp/AFPAbstractGraphicsObjectPainter.java new file mode 100644 index 000000000..8c5e84012 --- /dev/null +++ b/src/java/org/apache/fop/afp/AFPAbstractGraphicsObjectPainter.java @@ -0,0 +1,62 @@ +/* + * 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 org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.fop.afp.modca.GraphicsObject; +import org.apache.xmlgraphics.java2d.Graphics2DImagePainter; + +/** + * A simple AFP Graphics 2D painter + */ +public abstract class AFPAbstractGraphicsObjectPainter implements Graphics2DImagePainter { + /** Static logging instance */ + protected static Log log = LogFactory.getLog(AFPAbstractGraphicsObjectPainter.class); + + private final AFPGraphics2D graphics2D; + + /** + * Default constructor + */ + public AFPAbstractGraphicsObjectPainter() { + final boolean textAsShapes = false; + this.graphics2D = new AFPGraphics2D(textAsShapes); + } + + /** + * Constructor + * + * @param graphics the afp graphics 2d implementation + */ + public AFPAbstractGraphicsObjectPainter(AFPGraphics2D graphics) { + this.graphics2D = graphics; + } + + /** + * Sets the GOCA Graphics Object + * + * @param graphicsObject the GOCA Graphics Object + */ + public void setGraphicsObject(GraphicsObject graphicsObject) { + this.graphics2D.setGraphicsObject(graphicsObject); + } + +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/AFPBorderPainter.java b/src/java/org/apache/fop/afp/AFPBorderPainter.java new file mode 100644 index 000000000..96f9ae78f --- /dev/null +++ b/src/java/org/apache/fop/afp/AFPBorderPainter.java @@ -0,0 +1,195 @@ +/* + * 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.geom.AffineTransform; + +import org.apache.fop.afp.modca.DataStream; +import org.apache.fop.fo.Constants; +import org.apache.fop.util.ColorUtil; + +/** + * Handles the drawing of borders/lines in AFP + */ +public class AFPBorderPainter extends AbstractAFPPainter { + + /** + * Main constructor + * + * @param state the unit converter + * @param dataStream the afp datastream + */ + public AFPBorderPainter(AFPState state, DataStream dataStream) { + super(state, dataStream); + } + + /** {@inheritDoc} */ + public void paint(PaintInfo paintInfo) { + BorderPaintInfo borderPaintInfo = (BorderPaintInfo)paintInfo; + float w = borderPaintInfo.getX2() - borderPaintInfo.getX1(); + float h = borderPaintInfo.getY2() - borderPaintInfo.getY1(); + if ((w < 0) || (h < 0)) { + log.error("Negative extent received. Border won't be painted."); + return; + } + + int pageWidth = dataStream.getCurrentPage().getWidth(); + int pageHeight = dataStream.getCurrentPage().getHeight(); + AFPUnitConverter unitConv = state.getUnitConverter(); + AffineTransform at = state.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()) { + case 0: + x1 += at.getTranslateX(); + y1 += at.getTranslateY(); + x2 += at.getTranslateX(); + y2 += at.getTranslateY(); + break; + case 90: + x1 += at.getTranslateY(); + y1 += (float) (pageWidth - at.getTranslateX()); + x2 += at.getTranslateY(); + y2 += (float) (pageWidth - at.getTranslateX()); + break; + case 180: + x1 += (float) (pageWidth - at.getTranslateX()); + y1 += (float) (pageHeight - at.getTranslateY()); + x2 += (float) (pageWidth - at.getTranslateX()); + y2 += (float) (pageHeight - at.getTranslateY()); + break; + case 270: + x1 = (float) (pageHeight - at.getTranslateY()); + y1 += (float) at.getTranslateX(); + x2 += x1; + y2 += (float) at.getTranslateX(); + break; + } + + AFPLineDataInfo lineDataInfo = new AFPLineDataInfo(); + lineDataInfo.setColor(borderPaintInfo.getColor()); + lineDataInfo.setRotation(state.getRotation()); + lineDataInfo.x1 = Math.round(x1); + lineDataInfo.y1 = Math.round(y1); + if (borderPaintInfo.isHorizontal()) { + lineDataInfo.setThickness(Math.round(y2 - y1)); + } else { + lineDataInfo.setThickness(Math.round(x2 - x1)); + } + + // handle border-*-style + switch (borderPaintInfo.getStyle()) { + case Constants.EN_DOUBLE: + if (borderPaintInfo.isHorizontal()) { + lineDataInfo.x2 = Math.round(x2); + lineDataInfo.y2 = lineDataInfo.y1; + dataStream.createLine(lineDataInfo); + lineDataInfo.y1 += Math.round((lineDataInfo.thickness / 3) * 2); + dataStream.createLine(lineDataInfo); + } else { + lineDataInfo.x2 = lineDataInfo.x1; + lineDataInfo.y2 = Math.round(y2); + dataStream.createLine(lineDataInfo); + lineDataInfo.x1 += Math.round((lineDataInfo.thickness / 3) * 2); + dataStream.createLine(lineDataInfo); + } + break; + case Constants.EN_DASHED: + int thick = lineDataInfo.thickness * 3; + if (borderPaintInfo.isHorizontal()) { + lineDataInfo.x2 = lineDataInfo.x1 + thick; + lineDataInfo.y2 = lineDataInfo.y1; + int ex2 = Math.round(x2); + while (lineDataInfo.x1 + thick < ex2) { + dataStream.createLine(lineDataInfo); + lineDataInfo.x1 += 2 * thick; + lineDataInfo.x2 = lineDataInfo.x1 + thick; + } + } else { + lineDataInfo.x2 = lineDataInfo.x1; + lineDataInfo.y2 = lineDataInfo.y1 + thick; + int ey2 = Math.round(y2); + while (lineDataInfo.y1 + thick < ey2) { + dataStream.createLine(lineDataInfo); + lineDataInfo.y1 += 2 * thick; + lineDataInfo.y2 = lineDataInfo.y1 + thick; + } + } + break; + case Constants.EN_DOTTED: + if (borderPaintInfo.isHorizontal()) { + lineDataInfo.x2 = lineDataInfo.x1 + lineDataInfo.thickness; + lineDataInfo.y2 = lineDataInfo.y1; + int ex2 = Math.round(x2); + while (lineDataInfo.x1 + lineDataInfo.thickness < ex2) { + dataStream.createLine(lineDataInfo); + lineDataInfo.x1 += 3 * lineDataInfo.thickness; + lineDataInfo.x2 = lineDataInfo.x1 + lineDataInfo.thickness; + } + } else { + lineDataInfo.x2 = lineDataInfo.x1; + lineDataInfo.y2 = lineDataInfo.y1 + lineDataInfo.thickness; + int ey2 = Math.round(y2); + while (lineDataInfo.y1 + lineDataInfo.thickness < ey2) { + dataStream.createLine(lineDataInfo); + lineDataInfo.y1 += 3 * lineDataInfo.thickness; + lineDataInfo.y2 = lineDataInfo.y1 + lineDataInfo.thickness; + } + } + break; + case Constants.EN_GROOVE: + case Constants.EN_RIDGE: + //TODO + lineDataInfo.x2 = Math.round(x2); + float colFactor = (borderPaintInfo.getStyle() == Constants.EN_GROOVE ? 0.4f : -0.4f); + float h3 = (y2 - y1) / 3; + lineDataInfo.color = ColorUtil.lightenColor(borderPaintInfo.getColor(), -colFactor); + lineDataInfo.thickness = Math.round(h3); + lineDataInfo.y1 = lineDataInfo.y2 = Math.round(y1); + dataStream.createLine(lineDataInfo); + lineDataInfo.color = borderPaintInfo.getColor(); + lineDataInfo.y1 = lineDataInfo.y2 = Math.round(y1 + h3); + dataStream.createLine(lineDataInfo); + lineDataInfo.color = ColorUtil.lightenColor(borderPaintInfo.getColor(), colFactor); + lineDataInfo.y1 = lineDataInfo.y2 = Math.round(y1 + h3 + h3); + dataStream.createLine(lineDataInfo); + break; + case Constants.EN_HIDDEN: + break; + case Constants.EN_INSET: + case Constants.EN_OUTSET: + case Constants.EN_SOLID: + default: + if (borderPaintInfo.isHorizontal()) { + lineDataInfo.x2 = Math.round(x2); + lineDataInfo.y2 = lineDataInfo.y1; + } else { + lineDataInfo.x2 = lineDataInfo.x1; + lineDataInfo.y2 = Math.round(y2); + } + dataStream.createLine(lineDataInfo); + } + } + +} diff --git a/src/java/org/apache/fop/afp/AFPConstants.java b/src/java/org/apache/fop/afp/AFPConstants.java new file mode 100644 index 000000000..3462ddfe6 --- /dev/null +++ b/src/java/org/apache/fop/afp/AFPConstants.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; + +/** + * Constants used by the AFP renderer. + * + */ +public interface AFPConstants { + + /** + * The encoding to use to convert to EBCIDIC + */ + String EBCIDIC_ENCODING = "Cp1146"; + + /** + * The encoding to use to convert to ASCII + */ + String ASCII_ENCODING = "Cp1252"; + + /** + * The encoding to use to convert to US ASCII (7 bit) + */ + String US_ASCII_ENCODING = "US-ASCII"; + + /** + * The scaling of the default transform is set to + * approximately 72 user space coordinates per square inch + */ + int DPI_72 = 72; + + /** + * 72dpi in millipoints + */ + int DPI_72_MPTS = DPI_72 * 1000; +} diff --git a/src/java/org/apache/fop/afp/AFPDataObjectFactory.java b/src/java/org/apache/fop/afp/AFPDataObjectFactory.java new file mode 100644 index 000000000..d2e5a7a62 --- /dev/null +++ b/src/java/org/apache/fop/afp/AFPDataObjectFactory.java @@ -0,0 +1,255 @@ +/* + * 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.geom.Rectangle2D; + +import org.apache.fop.afp.ioca.ImageContent; +import org.apache.fop.afp.modca.AbstractDataObject; +import org.apache.fop.afp.modca.AbstractNamedAFPObject; +import org.apache.fop.afp.modca.Document; +import org.apache.fop.afp.modca.GraphicsObject; +import org.apache.fop.afp.modca.ImageObject; +import org.apache.fop.afp.modca.IncludeObject; +import org.apache.fop.afp.modca.ObjectContainer; +import org.apache.fop.afp.modca.Overlay; +import org.apache.fop.afp.modca.PageSegment; +import org.apache.fop.afp.modca.Registry; +import org.apache.fop.afp.modca.ResourceObject; +import org.apache.fop.afp.modca.triplets.MappingOptionTriplet; +import org.apache.fop.afp.modca.triplets.ObjectClassificationTriplet; +import org.apache.xmlgraphics.image.codec.tiff.TIFFImage; +import org.apache.xmlgraphics.java2d.Graphics2DImagePainter; + +/** + * Factory for high level data objects (Image/Graphics etc) + */ +public class AFPDataObjectFactory { + + private final Factory factory; + + /** + * Main constructor + * + * @param factory an object factory + */ + public AFPDataObjectFactory(Factory factory) { + this.factory = factory; + } + + /** + * Creates and configures an ObjectContainer. + * + * @param dataObjectInfo the object container info + * @return a newly created Object Container + */ + public ObjectContainer createObjectContainer(AFPDataObjectInfo dataObjectInfo) { + ObjectContainer objectContainer = factory.createObjectContainer(); + + // set object classification + Registry.ObjectType objectType = dataObjectInfo.getObjectType(); + AFPResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); + AFPResourceLevel resourceLevel = resourceInfo.getLevel(); + final boolean dataInContainer = true; + final boolean containerHasOEG = resourceLevel.isInline(); + final boolean dataInOCD = true; + objectContainer.setObjectClassification( + ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT, + objectType, dataInContainer, containerHasOEG, dataInOCD); + + objectContainer.setInputStream(dataObjectInfo.getInputStream()); + return objectContainer; + } + + /** + * Creates and configures an IOCA Image Object. + * + * @param imageObjectInfo the image object info + * @return a newly created IOCA Image Object + */ + public ImageObject createImage(AFPImageObjectInfo imageObjectInfo) { + // IOCA bitmap image + ImageObject imageObj = factory.createImageObject(); + if (imageObjectInfo.hasCompression()) { + int compression = imageObjectInfo.getCompression(); + switch (compression) { + case TIFFImage.COMP_FAX_G3_1D: + imageObj.setEncoding(ImageContent.COMPID_G3_MH); + break; + case TIFFImage.COMP_FAX_G3_2D: + imageObj.setEncoding(ImageContent.COMPID_G3_MR); + break; + case TIFFImage.COMP_FAX_G4_2D: + imageObj.setEncoding(ImageContent.COMPID_G3_MMR); + break; + default: + throw new IllegalStateException( + "Invalid compression scheme: " + compression); + } + } + + if (imageObjectInfo.isColor()) { + imageObj.setIDESize((byte) 24); + } else { + imageObj.setIDESize((byte) imageObjectInfo.getBitsPerPixel()); + } + imageObj.setData(imageObjectInfo.getData()); + + return imageObj; + } + + /** + * Creates and returns a new graphics object. + * + * @param graphicsObjectInfo the graphics object info + * @return a new graphics object + */ + public GraphicsObject createGraphic(AFPGraphicsObjectInfo graphicsObjectInfo) { + // set newly created graphics object in g2d + GraphicsObject graphicsObj = factory.createGraphicsObject(); + AFPGraphics2D g2d = graphicsObjectInfo.getGraphics2D(); + g2d.setGraphicsObject(graphicsObj); + + // paint to graphics object + Graphics2DImagePainter painter = graphicsObjectInfo.getPainter(); + Rectangle2D area = graphicsObjectInfo.getArea(); + painter.paint(g2d, area); + + // return painted graphics object + return graphicsObj; + } + + /** + * Creates and returns a new include object. + * + * @param includeName the include name + * @param dataObjectInfo a data object info + * + * @return a new include object + */ + public IncludeObject createInclude(String includeName, AFPDataObjectInfo dataObjectInfo) { + IncludeObject includeObj = factory.createInclude(includeName); + + if (dataObjectInfo instanceof AFPImageObjectInfo) { + // IOCA image object + includeObj.setObjectType(IncludeObject.TYPE_IMAGE); + } else if (dataObjectInfo instanceof AFPGraphicsObjectInfo) { + // graphics object + includeObj.setObjectType(IncludeObject.TYPE_GRAPHIC); + } else { + // object container + includeObj.setObjectType(IncludeObject.TYPE_OTHER); + + // set mandatory object classification (type other) + Registry.ObjectType objectType = dataObjectInfo.getObjectType(); + if (objectType != null) { + // set object classification + final boolean dataInContainer = true; + final boolean containerHasOEG = false; // environment parameters set in include + final boolean dataInOCD = true; + includeObj.setObjectClassification( + // object scope not defined + ObjectClassificationTriplet.CLASS_TIME_VARIANT_PRESENTATION_OBJECT, + objectType, dataInContainer, containerHasOEG, dataInOCD); + } else { + throw new IllegalStateException( + "Failed to set Object Classification Triplet on Object Container."); + } + } + + AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo(); + + int xOffset = objectAreaInfo.getX(); + int yOffset = objectAreaInfo.getY(); + includeObj.setObjectAreaOffset(xOffset, yOffset); + + int width = objectAreaInfo.getWidth(); + int height = objectAreaInfo.getHeight(); + includeObj.setObjectAreaSize(width, height); + + int rotation = objectAreaInfo.getRotation(); + includeObj.setObjectAreaOrientation(rotation); + + int widthRes = objectAreaInfo.getWidthRes(); + int heightRes = objectAreaInfo.getHeightRes(); + includeObj.setMeasurementUnits(widthRes, heightRes); + + includeObj.setMappingOption(MappingOptionTriplet.SCALE_TO_FIT); + + return includeObj; + } + + /** + * Creates a resource object wrapper for named includable data objects + * + * @param namedObj an named object + * @param resourceInfo resource information + * @param objectType the object type + * @return a new resource object wrapper + */ + public ResourceObject createResource(AbstractNamedAFPObject namedObj, + AFPResourceInfo resourceInfo, Registry.ObjectType objectType) { + ResourceObject resourceObj = null; + String resourceName = resourceInfo.getName(); + if (resourceName != null) { + resourceObj = factory.createResource(resourceName); + } else { + resourceObj = factory.createResource(); + } + + if (namedObj instanceof Document) { + resourceObj.setType(ResourceObject.TYPE_DOCUMENT); + } else if (namedObj instanceof PageSegment) { + resourceObj.setType(ResourceObject.TYPE_PAGE_SEGMENT); + } else if (namedObj instanceof Overlay) { + resourceObj.setType(ResourceObject.TYPE_OVERLAY_OBJECT); + } else if (namedObj instanceof AbstractDataObject) { + AbstractDataObject dataObj = (AbstractDataObject)namedObj; + if (namedObj instanceof ObjectContainer) { + resourceObj.setType(ResourceObject.TYPE_OBJECT_CONTAINER); + + // set object classification + final boolean dataInContainer = true; + final boolean containerHasOEG = false; // must be included + final boolean dataInOCD = true; + // mandatory triplet for object container + resourceObj.setObjectClassification( + ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT, + objectType, dataInContainer, containerHasOEG, dataInOCD); + } else if (namedObj instanceof ImageObject) { + // ioca image type + resourceObj.setType(ResourceObject.TYPE_IMAGE); + } else if (namedObj instanceof GraphicsObject) { + resourceObj.setType(ResourceObject.TYPE_GRAPHIC); + } else { + throw new UnsupportedOperationException( + "Unsupported resource object for data object type " + dataObj); + } + } else { + throw new UnsupportedOperationException( + "Unsupported resource object type " + namedObj); + } + + // set the resource information/classification on the data object + resourceObj.setDataObject(namedObj); + return resourceObj; + } + +} diff --git a/src/java/org/apache/fop/afp/AFPDataObjectInfo.java b/src/java/org/apache/fop/afp/AFPDataObjectInfo.java new file mode 100644 index 000000000..c618a53fc --- /dev/null +++ b/src/java/org/apache/fop/afp/AFPDataObjectInfo.java @@ -0,0 +1,206 @@ +/* + * 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.io.InputStream; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.fop.afp.modca.Registry; + +/** + * A list of parameters associated with an AFP data objects + */ +public class AFPDataObjectInfo { + private static final Log log = LogFactory.getLog("org.apache.xmlgraphics.afp"); + + /** the object area info */ + private AFPObjectAreaInfo objectAreaInfo; + + /** resource info */ + private AFPResourceInfo resourceInfo; + + /** the data object width */ + private int dataWidth; + + /** the data object height */ + private int dataHeight; + + /** the object data in an inputstream */ + private InputStream inputStream; + + /** the object registry mimetype */ + private String mimeType; + + /** + * Default constructor + */ + public AFPDataObjectInfo() { + } + + /** + * Sets the image mime type + * + * @param mimeType the image mime type + */ + public void setMimeType(String mimeType) { + this.mimeType = mimeType; + } + + /** + * Returns the mime type of this data object + * + * @return the mime type of this data object + */ + public String getMimeType() { + return mimeType; + } + + /** + * Convenience method to return the object type + * + * @return the object type + */ + public Registry.ObjectType getObjectType() { + return Registry.getInstance().getObjectType(getMimeType()); + } + + /** + * Returns the resource level at which this data object should reside + * + * @return the resource level at which this data object should reside + */ + public AFPResourceInfo getResourceInfo() { + if (resourceInfo == null) { + this.resourceInfo = new AFPResourceInfo(); + } + return resourceInfo; + } + + /** + * Sets the resource level at which this object should reside + * + * @param resourceInfo the resource level at which this data object should reside + */ + public void setResourceInfo(AFPResourceInfo resourceInfo) { + this.resourceInfo = resourceInfo; + } + + /** + * Sets the object area info + * + * @param objectAreaInfo the object area info + */ + public void setObjectAreaInfo(AFPObjectAreaInfo objectAreaInfo) { + this.objectAreaInfo = objectAreaInfo; + } + + /** + * Returns the object area info + * + * @return the object area info + */ + public AFPObjectAreaInfo getObjectAreaInfo() { + return this.objectAreaInfo; + } + + /** {@inheritDoc} */ + public String toString() { + return "AFPDataObjectInfo{" + + "mimeType=" + mimeType + + ", dataWidth=" + dataWidth + + ", dataHeight=" + dataHeight + + (objectAreaInfo != null ? ", objectAreaInfo=" + objectAreaInfo : "") + + (resourceInfo != null ? ", resourceInfo=" + resourceInfo : ""); + } + + /** + * Returns the uri of this data object + * + * @return the uri of this data object + */ + public String getUri() { + return getResourceInfo().getUri(); + } + + /** + * Sets the data object uri + * + * @param uri the data object uri + */ + public void setUri(String uri) { + getResourceInfo().setUri(uri); + } + + /** + * Returns the image data width + * + * @return the image data width + */ + public int getDataWidth() { + return dataWidth; + } + + /** + * Sets the image data width + * + * @param imageDataWidth the image data width + */ + public void setDataWidth(int imageDataWidth) { + this.dataWidth = imageDataWidth; + } + + /** + * Returns the image data height + * + * @return the image data height + */ + public int getDataHeight() { + return dataHeight; + } + + /** + * Sets the image data height + * + * @param imageDataHeight the image data height + */ + public void setDataHeight(int imageDataHeight) { + this.dataHeight = imageDataHeight; + } + + /** + * Sets the object data inputstream + * + * @param inputStream the object data inputstream + */ + public void setInputStream(InputStream inputStream) { + this.inputStream = inputStream; + } + + /** + * Returns the object data inputstream + * + * @return the object data inputstream + */ + public InputStream getInputStream() { + return this.inputStream; + } + +} diff --git a/src/java/org/apache/fop/afp/AFPForeignAttributeReader.java b/src/java/org/apache/fop/afp/AFPForeignAttributeReader.java new file mode 100644 index 000000000..710c24533 --- /dev/null +++ b/src/java/org/apache/fop/afp/AFPForeignAttributeReader.java @@ -0,0 +1,126 @@ +/* + * 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.io.File; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.fop.render.afp.extensions.AFPElementMapping; +import org.apache.xmlgraphics.util.QName; + +/** + * Parses any AFP foreign attributes + */ +public class AFPForeignAttributeReader { + private static final Log log = LogFactory.getLog("org.apache.xmlgraphics.afp"); + + /** the resource-name attribute */ + public static final String RESOURCE_NAME = "afp:resource-name"; + + /** the resource-level attribute */ + public static final String RESOURCE_LEVEL = "afp:resource-level"; + + /** the resource-group-file attribute */ + public static final String RESOURCE_GROUP_FILE = "afp:resource-group-file"; + + /** + * Main constructor + */ + public AFPForeignAttributeReader() { + } + + /** + * Returns the resource information + * + * @param foreignAttributes the foreign attributes + * @return the resource information + */ + public AFPResourceInfo getResourceInfo(Map/**/ foreignAttributes) { + AFPResourceInfo resourceInfo = new AFPResourceInfo(); + if (foreignAttributes != null && !foreignAttributes.isEmpty()) { + QName resourceNameKey = new QName(AFPElementMapping.NAMESPACE, RESOURCE_NAME); + String resourceName = (String)foreignAttributes.get(resourceNameKey); + if (resourceName != null) { + resourceInfo.setName(resourceName); + } + AFPResourceLevel level = getResourceLevel(foreignAttributes); + if (level != null) { + resourceInfo.setLevel(level); + } + } + return resourceInfo; + } + + /** + * Returns the resource level + * + * @param foreignAttributes the foreign attributes + * @return the resource level + */ + public AFPResourceLevel getResourceLevel(Map/**/ foreignAttributes) { + AFPResourceLevel resourceLevel = null; + if (foreignAttributes != null && !foreignAttributes.isEmpty()) { + QName resourceLevelKey = new QName(AFPElementMapping.NAMESPACE, RESOURCE_LEVEL); + if (foreignAttributes.containsKey(resourceLevelKey)) { + String levelString = (String)foreignAttributes.get(resourceLevelKey); + resourceLevel = AFPResourceLevel.valueOf(levelString); + // if external get resource group file attributes + if (resourceLevel != null && resourceLevel.isExternal()) { + QName resourceGroupFileKey = new QName(AFPElementMapping.NAMESPACE, + RESOURCE_GROUP_FILE); + String resourceGroupFile + = (String)foreignAttributes.get(resourceGroupFileKey); + if (resourceGroupFile == null) { + String msg = RESOURCE_GROUP_FILE + " not specified"; + log.error(msg); + throw new UnsupportedOperationException(msg); + } + File resourceExternalGroupFile = new File(resourceGroupFile); + SecurityManager security = System.getSecurityManager(); + try { + if (security != null) { + security.checkWrite(resourceExternalGroupFile.getPath()); + } + } catch (SecurityException ex) { + String msg = "unable to gain write access to external resource file: " + + resourceGroupFile; + log.error(msg); + } + + try { + boolean exists = resourceExternalGroupFile.exists(); + if (exists) { + log.warn("overwriting external resource file: " + + resourceGroupFile); + } + resourceLevel.setExternalFilePath(resourceGroupFile); + } catch (SecurityException ex) { + String msg = "unable to gain read access to external resource file: " + + resourceGroupFile; + log.error(msg); + } + } + } + } + return resourceLevel; + } +} diff --git a/src/java/org/apache/fop/afp/AFPGraphics2D.java b/src/java/org/apache/fop/afp/AFPGraphics2D.java new file mode 100644 index 000000000..21114bb88 --- /dev/null +++ b/src/java/org/apache/fop/afp/AFPGraphics2D.java @@ -0,0 +1,612 @@ +/* + * 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.AlphaComposite; +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.GraphicsConfiguration; +import java.awt.Image; +import java.awt.Rectangle; +import java.awt.Shape; +import java.awt.Stroke; +import java.awt.geom.AffineTransform; +import java.awt.geom.Ellipse2D; +import java.awt.geom.Line2D; +import java.awt.geom.PathIterator; +import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; +import java.awt.image.ImageObserver; +import java.awt.image.RenderedImage; +import java.awt.image.renderable.RenderableImage; +import java.io.IOException; + +import org.apache.commons.io.output.ByteArrayOutputStream; +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.fonts.FontInfo; +import org.apache.xmlgraphics.image.loader.ImageInfo; +import org.apache.xmlgraphics.image.loader.ImageSize; +import org.apache.xmlgraphics.image.loader.impl.ImageRendered; +import org.apache.xmlgraphics.java2d.AbstractGraphics2D; +import org.apache.xmlgraphics.java2d.GraphicContext; +import org.apache.xmlgraphics.java2d.StrokingTextHandler; +import org.apache.xmlgraphics.java2d.TextHandler; +import org.apache.xmlgraphics.ps.ImageEncodingHelper; +import org.apache.xmlgraphics.util.MimeConstants; + +/** + * This is a concrete implementation of AbstractGraphics2D (and + * therefore of Graphics2D) which is able to generate GOCA byte + * codes. + * + * @see org.apache.xmlgraphics.java2d.AbstractGraphics2D + */ +public class AFPGraphics2D extends AbstractGraphics2D { + + private static final Log log = LogFactory.getLog(AFPGraphics2D.class); + + private static final int X = 0; + + private static final int Y = 1; + + private static final int X1 = 0; + + private static final int Y1 = 1; + + private static final int X2 = 2; + + private static final int Y2 = 3; + + + /** graphics object */ + private GraphicsObject graphicsObj = null; + + /** Fallback text handler */ + protected TextHandler fallbackTextHandler = new StrokingTextHandler(this); + + /** Custom text handler */ + protected TextHandler customTextHandler = null; + + /** AFP resource manager */ + private AFPResourceManager resourceManager = null; + + /** AFP resource info */ + private AFPResourceInfo resourceInfo = null; + + /** Current AFP state */ + private AFPState state = null; + + /** The AFP FontInfo */ + private FontInfo fontInfo; + + /** + * Main constructor + * + * @param textAsShapes + * if true, all text is turned into shapes in the convertion. No + * text is output. + * + */ + public AFPGraphics2D(boolean textAsShapes) { + super(textAsShapes); + } + + /** + * Copy Constructor + * + * @param g2d + * a AFPGraphics2D whose properties should be copied + */ + public AFPGraphics2D(AFPGraphics2D g2d) { + super(g2d); + this.graphicsObj = g2d.graphicsObj; + this.fallbackTextHandler = g2d.fallbackTextHandler; + this.customTextHandler = g2d.customTextHandler; + this.resourceManager = g2d.resourceManager; + this.resourceInfo = g2d.resourceInfo; + this.state = g2d.state; + } + + /** + * Sets the AFP resource manager + * + * @param resourceManager the AFP resource manager + */ + public void setResourceManager(AFPResourceManager resourceManager) { + this.resourceManager = resourceManager; + } + + /** + * Sets the AFP resource info + * + * @param resourceInfo the AFP resource info + */ + public void setResourceInfo(AFPResourceInfo resourceInfo) { + this.resourceInfo = resourceInfo; + } + + /** + * Sets the GraphicContext + * + * @param gc + * GraphicContext to use + */ + public void setGraphicContext(GraphicContext gc) { + this.gc = gc; + } + + /** + * Apply the stroke to the AFP graphics object. + * This takes the java stroke and outputs the appropriate settings + * to the AFP graphics object so that the stroke attributes are handled. + * + * @param stroke the java stroke + */ + protected void applyStroke(Stroke stroke) { + if (stroke instanceof BasicStroke) { + BasicStroke basicStroke = (BasicStroke) stroke; + float lineWidth = basicStroke.getLineWidth(); + if (state.setLineWidth(lineWidth)) { + getGraphicsObject().setLineWidth(Math.round(lineWidth * 2)); + } + // note: this is an approximation at best! + float[] dashArray = basicStroke.getDashArray(); + if (state.setDashArray(dashArray)) { + byte type = GraphicsSetLineType.DEFAULT; // normally SOLID + if (dashArray != null) { + type = GraphicsSetLineType.DOTTED; // default to plain DOTTED if dashed line + // float offset = basicStroke.getDashPhase(); + if (dashArray.length == 2) { + if (dashArray[0] < dashArray[1]) { + type = GraphicsSetLineType.SHORT_DASHED; + } else if (dashArray[0] > dashArray[1]) { + type = GraphicsSetLineType.LONG_DASHED; + } + } else if (dashArray.length == 4) { + if (dashArray[0] > dashArray[1] + && dashArray[2] < dashArray[3]) { + type = GraphicsSetLineType.DASH_DOT; + } else if (dashArray[0] < dashArray[1] + && dashArray[2] < dashArray[3]) { + type = GraphicsSetLineType.DOUBLE_DOTTED; + } + } else if (dashArray.length == 6) { + if (dashArray[0] > dashArray[1] + && dashArray[2] < dashArray[3] + && dashArray[4] < dashArray[5]) { + type = GraphicsSetLineType.DASH_DOUBLE_DOTTED; + } + } + } + getGraphicsObject().setLineType(type); + } + } else { + log.warn("Unsupported Stroke: " + stroke.getClass().getName()); + } + } + + /** + * Handle the Batik drawing event + * + * @param shape + * the shape to draw + * @param fill + * true if the shape is to be drawn filled + */ + private void doDrawing(Shape shape, boolean fill) { + getGraphicsObject(); + if (!fill) { + graphicsObj.newSegment(); + } + + Color color = getColor(); + if (state.setColor(color)) { + graphicsObj.setColor(color); + } + + Stroke stroke = getStroke(); + applyStroke(stroke); + + if (fill) { + graphicsObj.beginArea(); + } + AffineTransform trans = super.getTransform(); + + PathIterator iter = shape.getPathIterator(trans); + double[] dstPts = new double[6]; + int[] coords = null; + if (shape instanceof Line2D) { + iter.currentSegment(dstPts); + coords = new int[4]; + coords[X1] = (int) Math.round(dstPts[X]); + coords[Y1] = (int) Math.round(dstPts[Y]); + iter.next(); + iter.currentSegment(dstPts); + coords[X2] = (int) Math.round(dstPts[X]); + coords[Y2] = (int) Math.round(dstPts[Y]); + graphicsObj.addLine(coords); + } else if (shape instanceof Rectangle2D) { + iter.currentSegment(dstPts); + coords = new int[4]; + coords[X2] = (int) Math.round(dstPts[X]); + coords[Y2] = (int) Math.round(dstPts[Y]); + iter.next(); + iter.next(); + iter.currentSegment(dstPts); + coords[X1] = (int) Math.round(dstPts[X]); + coords[Y1] = (int) Math.round(dstPts[Y]); + graphicsObj.addBox(coords); + } else if (shape instanceof Ellipse2D) { + Ellipse2D elip = (Ellipse2D) shape; + double scale = trans.getScaleX(); + double radiusWidth = elip.getWidth() / 2; + double radiusHeight = elip.getHeight() / 2; + graphicsObj.setArcParams( + (int)Math.round(radiusWidth * scale), + (int)Math.round(radiusHeight * scale), + 0, + 0 + ); + double[] srcPts = new double[] {elip.getCenterX(), elip.getCenterY()}; + trans.transform(srcPts, 0, dstPts, 0, 1); + final int mh = 1; + final int mhr = 0; + graphicsObj.addFullArc( + (int)Math.round(dstPts[X]), + (int)Math.round(dstPts[Y]), + mh, + mhr + ); + } else { + // graphics segment opening coordinates (x,y) + // current position coordinates (x,y) + for (int[] openingCoords = new int[2], currCoords = new int[2]; + !iter.isDone(); iter.next()) { + // round the coordinate values and combine with current position + // coordinates + 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]); + } 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; + } else { + // close of the graphics segment + if (type == PathIterator.SEG_CLOSE) { + coords = new int[] { + coords[coords.length - 2], //prev X + coords[coords.length - 1], //prev Y + openingCoords[X], + openingCoords[Y] + }; + graphicsObj.addLine(coords); + } else { + log.debug("Unrecognised path iterator type: " + + type); + } + continue; + } + // combine current position coordinates with new graphics + // segment coordinates + coords = new int[numCoords + 2]; + coords[X] = currCoords[X]; + coords[Y] = currCoords[Y]; + for (int i = 0; i < numCoords; i++) { + coords[i + 2] = (int) Math.round(dstPts[i]); + } + if (type == PathIterator.SEG_LINETO) { + graphicsObj.addLine(coords); + } else if (type == PathIterator.SEG_QUADTO + || type == PathIterator.SEG_CUBICTO) { + graphicsObj.addFillet(coords); + } + // update current position coordinates + currCoords[X] = coords[coords.length - 2]; + currCoords[Y] = coords[coords.length - 1]; + } + } + } + if (fill) { + graphicsObj.endArea(); + } + } + + /** {@inheritDoc} */ + public void draw(Shape shape) { +// log.debug("draw() shape=" + shape); + doDrawing(shape, false); + } + + /** {@inheritDoc} */ + public void fill(Shape shape) { +// log.debug("fill() shape=" + shape); + doDrawing(shape, true); + } + + /** + * Central handler for IOExceptions for this class. + * + * @param ioe + * IOException to handle + */ + public void handleIOException(IOException ioe) { + // TODO Surely, there's a better way to do this. + log.error(ioe.getMessage()); + ioe.printStackTrace(); + } + + /** {@inheritDoc} */ + public void drawString(String str, float x, float y) { + try { + if (customTextHandler != null && !textAsShapes) { + customTextHandler.drawString(str, x, y); + } else { + fallbackTextHandler.drawString(str, x, y); + } + } catch (IOException ioe) { + handleIOException(ioe); + } + } + + /** {@inheritDoc} */ + public GraphicsConfiguration getDeviceConfiguration() { + return new AFPGraphicsConfiguration(); + } + + /** {@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); + } + + /** {@inheritDoc} */ + public void dispose() { + this.graphicsObj = null; + } + + /** {@inheritDoc} */ + public boolean drawImage(Image img, int x, int y, ImageObserver observer) { + return drawImage(img, x, y, img.getWidth(observer), img.getHeight(observer), observer); + } + + private BufferedImage buildBufferedImage(Dimension size) { + return new BufferedImage(size.width, size.height, + BufferedImage.TYPE_INT_ARGB); + } + + private AFPImageObjectInfo getImageObjectInfo( + RenderedImage img, int x, int y, int width, int height) throws IOException { + ImageInfo imageInfo = new ImageInfo(null, "image/unknown"); + ImageSize size = new ImageSize(img.getWidth(), img.getHeight(), 72); + imageInfo.setSize(size); + + ImageRendered imageRendered = new ImageRendered(imageInfo, img, null); + RenderedImage renderedImage = imageRendered.getRenderedImage(); + + // create image object info + AFPImageObjectInfo imageObjectInfo = new AFPImageObjectInfo(); + + imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS45); + + imageObjectInfo.setBitsPerPixel(state.getBitsPerPixel()); + + imageObjectInfo.setResourceInfo(resourceInfo); + + int dataHeight = renderedImage.getHeight(); + imageObjectInfo.setDataHeight(dataHeight); + + int dataWidth = renderedImage.getWidth(); + imageObjectInfo.setDataWidth(dataWidth); + + boolean colorImages = state.isColorImages(); + imageObjectInfo.setColor(colorImages); + + ByteArrayOutputStream boas = new ByteArrayOutputStream(); + ImageEncodingHelper.encodeRenderedImageAsRGB(renderedImage, boas); + byte[] imageData = boas.toByteArray(); + + // convert to grayscale + if (!colorImages) { + boas.reset(); + int bitsPerPixel = state.getBitsPerPixel(); + imageObjectInfo.setBitsPerPixel(bitsPerPixel); + ImageEncodingHelper.encodeRGBAsGrayScale( + imageData, dataWidth, dataHeight, bitsPerPixel, boas); + imageData = boas.toByteArray(); + } + imageObjectInfo.setData(imageData); + + if (imageInfo != null) { + imageObjectInfo.setUri(imageInfo.getOriginalURI()); + } + + // create object area info + AFPObjectAreaInfo objectAreaInfo = new AFPObjectAreaInfo(); + + AffineTransform at = gc.getTransform(); + float[] srcPts = new float[] {x, y}; + float[] dstPts = new float[srcPts.length]; + at.transform(srcPts, 0, dstPts, 0, 1); + objectAreaInfo.setX(Math.round(dstPts[X])); + objectAreaInfo.setY(Math.round(dstPts[Y])); + + AFPUnitConverter unitConv = state.getUnitConverter(); + + int w = Math.round(unitConv.pt2units(width)); + objectAreaInfo.setWidth(w); + + int h = Math.round(unitConv.pt2units(height)); + objectAreaInfo.setHeight(h); + + int resolution = state.getResolution(); + objectAreaInfo.setWidthRes(resolution); + objectAreaInfo.setHeightRes(resolution); + + imageObjectInfo.setObjectAreaInfo(objectAreaInfo); + + return imageObjectInfo; + } + + /** {@inheritDoc} */ + public boolean drawImage(Image img, int x, int y, int width, int height, + ImageObserver observer) { + + // draw with AWT Graphics2D + Dimension size = new Dimension(width, height); + BufferedImage bufferedImage = buildBufferedImage(size); + + java.awt.Graphics2D g2d = bufferedImage.createGraphics(); + g2d.setComposite(AlphaComposite.SrcOver); + + Color color = new Color(1, 1, 1, 0); + g2d.setBackground(color); + g2d.setPaint(color); + + g2d.fillRect(0, 0, width, height); + + int bufferedWidth = bufferedImage.getWidth(); + int bufferedHeight = bufferedImage.getHeight(); + Rectangle clipRect = new Rectangle(0, 0, bufferedWidth, bufferedHeight); + g2d.clip(clipRect); + + g2d.setComposite(gc.getComposite()); + + boolean drawn = g2d.drawImage(img, 0, 0, bufferedWidth, bufferedHeight, observer); + g2d.dispose(); + + if (drawn) { + try { + // get image object info + AFPImageObjectInfo imageObjectInfo = getImageObjectInfo(bufferedImage, x, y, width, height); + + // create image resource + resourceManager.createObject(imageObjectInfo); + return true; + } catch (IOException ioe) { + handleIOException(ioe); + } + } + return false; + } + + /** {@inheritDoc} */ + public void drawRenderableImage(RenderableImage img, AffineTransform xform) { + log.debug("drawRenderableImage() NYI: img=" + img + ", xform=" + xform); + } + + /** {@inheritDoc} */ + public void drawRenderedImage(RenderedImage img, AffineTransform xform) { + log.debug("drawRenderedImage() NYI: img=" + img + ", xform=" + xform); + } + + /** {@inheritDoc} */ + public FontMetrics getFontMetrics(Font f) { + log.debug("getFontMetrics() NYI: f=" + f); + return null; + } + + /** {@inheritDoc} */ + public void setXORMode(Color col) { + log.debug("setXORMode() NYI: col=" + col); + } + + /** + * Sets a custom TextHandler implementation that is responsible for painting + * text. The default TextHandler paints all text as shapes. A custom + * implementation can implement text painting using text painting operators. + * + * @param handler + * the custom TextHandler implementation + */ + public void setCustomTextHandler(TextHandler handler) { + this.customTextHandler = handler; + } + + /** + * Returns the GOCA graphics object + * + * @return the GOCA graphics object + */ + public GraphicsObject getGraphicsObject() { + return this.graphicsObj; + } + + /** + * Sets the GOCA graphics object + * + * @param obj the GOCA graphics object + */ + public void setGraphicsObject(GraphicsObject obj) { + this.graphicsObj = obj; + } + + /** + * Sets the AFP state + * + * @param state the AFP state + */ + public void setState(AFPState state) { + this.state = state; + } + + /** + * Returns the AFP state + * + * @return the AFP state + */ + public AFPState getState() { + return this.state; + } + + /** + * Sets the FontInfo + * + * @param the FontInfo + */ + public void setFontInfo(FontInfo fontInfo) { + this.fontInfo = fontInfo; + } + + /** + * Returns the FontInfo + * + * @return the FontInfo + */ + public FontInfo getFontInfo() { + return this.fontInfo; + } +} diff --git a/src/java/org/apache/fop/afp/AFPGraphicsConfiguration.java b/src/java/org/apache/fop/afp/AFPGraphicsConfiguration.java new file mode 100644 index 000000000..6c6d92098 --- /dev/null +++ b/src/java/org/apache/fop/afp/AFPGraphicsConfiguration.java @@ -0,0 +1,155 @@ +/* + * 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 new file mode 100644 index 000000000..20270e426 --- /dev/null +++ b/src/java/org/apache/fop/afp/AFPGraphicsDevice.java @@ -0,0 +1,81 @@ +/* + * 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/AFPGraphicsObjectInfo.java b/src/java/org/apache/fop/afp/AFPGraphicsObjectInfo.java new file mode 100644 index 000000000..df0ef55c5 --- /dev/null +++ b/src/java/org/apache/fop/afp/AFPGraphicsObjectInfo.java @@ -0,0 +1,105 @@ +/* + * 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.geom.Rectangle2D; + +import org.apache.xmlgraphics.java2d.Graphics2DImagePainter; +import org.apache.xmlgraphics.util.MimeConstants; + +/** + * A graphics object info which contains necessary painting objects + */ +public class AFPGraphicsObjectInfo extends AFPDataObjectInfo { + + /** the graphics object painter implementation */ + private Graphics2DImagePainter painter; + + /** the graphics object area */ + private Rectangle2D area; + + /** the AFP graphics 2d implementation */ + private AFPGraphics2D g2d; + + /** + * Returns the graphics painter + * + * @return the graphics painter + */ + public Graphics2DImagePainter getPainter() { + return this.painter; + } + + /** + * Sets the graphics painter + * + * @param graphicsPainter the graphics painter + */ + public void setPainter(Graphics2DImagePainter graphicsPainter) { + this.painter = graphicsPainter; + } + + /** + * Returns the graphics area + * + * @return the graphics area + */ + public Rectangle2D getArea() { + return this.area; + } + + /** + * Sets the graphics area area + * + * @param area the graphics object area + */ + public void setArea(Rectangle2D area) { + this.area = area; + } + + /** + * Sets the AFP graphics 2D implementation + * + * @param g2d the AFP graphics 2D implementation + */ + public void setGraphics2D(AFPGraphics2D g2d) { + this.g2d = g2d; + } + + /** + * Returns the AFP graphics 2D implementation + * + * @return the AFP graphics 2D implementation + */ + public AFPGraphics2D getGraphics2D() { + return this.g2d; + } + + /** {@inheritDoc} */ + public String toString() { + return "GraphicsObjectInfo{" + super.toString() + "}"; + } + + /** {@inheritDoc} */ + public String getMimeType() { + return MimeConstants.MIME_SVG; + } + +} diff --git a/src/java/org/apache/fop/afp/AFPImageObjectInfo.java b/src/java/org/apache/fop/afp/AFPImageObjectInfo.java new file mode 100644 index 000000000..561ad438b --- /dev/null +++ b/src/java/org/apache/fop/afp/AFPImageObjectInfo.java @@ -0,0 +1,136 @@ +/* + * 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; + + +/** + * A list of parameters associated with an image + */ +public class AFPImageObjectInfo extends AFPDataObjectInfo { + /** number of bits per pixel used */ + private int bitsPerPixel; + + /** is this a color image? */ + private boolean color; + + /** compression type if any */ + private int compression = -1; + + /** the object data in a byte array */ + private byte[] data; + + /** + * Default constructor + */ + public AFPImageObjectInfo() { + super(); + } + + /** + * Sets the number of bits per pixel + * + * @param bitsPerPixel the number of bits per pixel + */ + public void setBitsPerPixel(int bitsPerPixel) { + this.bitsPerPixel = bitsPerPixel; + } + + /** + * Sets if this image is color + * + * @param color true if this is a color image + */ + public void setColor(boolean color) { + this.color = color; + } + + /** + * Returns the number of bits used per pixel + * + * @return the number of bits used per pixel + */ + public int getBitsPerPixel() { + return bitsPerPixel; + } + + /** + * Returns true if this is a color image + * + * @return true if this is a color image + */ + public boolean isColor() { + return color; + } + + /** + * Returns true if this image uses compression + * + * @return true if this image uses compression + */ + public boolean hasCompression() { + return compression > -1; + } + + /** + * Returns the compression type + * + * @return the compression type + */ + public int getCompression() { + return compression; + } + + /** + * Sets the compression used with this image + * + * @param compression the type of compression used with this image + */ + public void setCompression(int compression) { + this.compression = compression; + } + + /** + * Sets the object data + * + * @param data the object data + */ + public void setData(byte[] data) { + this.data = data; + } + + /** + * Returns the object data + * + * @return the object data + */ + public byte[] getData() { + return this.data; + } + + /** {@inheritDoc} */ + public String toString() { + return "AFPImageObjectInfo{" + super.toString() + + ", compression=" + compression + + ", color=" + color + + ", bitsPerPixel=" + bitsPerPixel + + "}"; + } + +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/AFPLineDataInfo.java b/src/java/org/apache/fop/afp/AFPLineDataInfo.java new file mode 100644 index 000000000..f3acf4f71 --- /dev/null +++ b/src/java/org/apache/fop/afp/AFPLineDataInfo.java @@ -0,0 +1,192 @@ +/* + * 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; + +/** Line data information */ +public class AFPLineDataInfo { + + /** the x1 coordinate */ + int x1; + + /** the y1 coordinate */ + int y1; + + /** the x2 coordinate */ + int x2; + + /** the y2 coordinate */ + int y2; + + /** the thickness */ + int thickness; + + /** the painting color */ + Color color; + + /** the rotation */ + int rotation = 0; + + /** + * Default constructor + */ + public AFPLineDataInfo() { + } + + /** + * Returns the X1 coordinate + * + * @return the X1 coordinate + */ + public int getX1() { + return x1; + } + + /** + * Sets the X1 coordinate + * + * @param x1 the X1 coordinate + */ + public void setX1(int x1) { + this.x1 = x1; + } + + /** + * Returns the Y1 coordinate + * + * @return the Y1 coordinate + */ + public int getY1() { + return y1; + } + + /** + * Sets the Y1 coordinate + * + * @param y1 the Y1 coordinate + */ + public void setY1(int y1) { + this.y1 = y1; + } + + /** + * Returns the X2 coordinate + * + * @return the X2 coordinate + */ + public int getX2() { + return x2; + } + + /** + * Sets the X2 coordinate + * + * @param x2 the X2 coordinate + */ + public void setX2(int x2) { + this.x2 = x2; + } + + /** + * Returns the Y2 coordinate + * + * @return the Y2 coordinate + */ + public int getY2() { + return y2; + } + + /** + * Sets the Y2 coordinate + * + * @param y2 the Y2 coordinate + */ + public void setY2(int y2) { + this.y2 = y2; + } + + /** + * Returns the line thickness + * + * @return the line thickness + */ + public int getThickness() { + return thickness; + } + + /** + * Sets the line thickness + * + * @param thickness the line thickness + */ + public void setThickness(int thickness) { + this.thickness = thickness; + } + + /** + * Returns line color + * + * @return the line color + */ + public Color getColor() { + return color; + } + + /** + * Sets the line color + * + * @param color the line color + */ + public void setColor(Color color) { + this.color = color; + } + + /** + * Returns line rotation + * + * @return the line rotation + */ + public int getRotation() { + return rotation; + } + + /** + * Sets the line rotation + * + * @param rotation the line rotation + */ + public void setRotation(int rotation) { + this.rotation = rotation; + } + + /** {@inheritDoc} */ + public String toString() { + return "AFPLineDataInfo{x1=" + x1 + + ", y1=" + y1 + + ", x2=" + x2 + + ", y2=" + y2 + + ", thickness=" + thickness + + ", color=" + color + + ", rotation=" + rotation + + "}"; + } + +} diff --git a/src/java/org/apache/fop/afp/AFPObjectAreaInfo.java b/src/java/org/apache/fop/afp/AFPObjectAreaInfo.java new file mode 100644 index 000000000..963424470 --- /dev/null +++ b/src/java/org/apache/fop/afp/AFPObjectAreaInfo.java @@ -0,0 +1,172 @@ +/* + * 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; + +/** + * A common class used to convey locations, + * dimensions and resolutions of data objects. + */ +public class AFPObjectAreaInfo { + private int x; + private int y; + private int width; + private int height; + private int widthRes; + private int heightRes; + private int rotation = 0; + + /** + * Sets the x position of the data object + * + * @param x the x position of the data object + */ + public void setX(int x) { + this.x = x; + } + + /** + * Sets the y position of the data object + * + * @param y the y position of the data object + */ + public void setY(int y) { + this.y = y; + } + + /** + * Sets the data object width + * + * @param width the width of the data object + */ + public void setWidth(int width) { + this.width = width; + } + + /** + * Sets the data object height + * + * @param height the height of the data object + */ + public void setHeight(int height) { + this.height = height; + } + + /** + * Sets the width resolution + * + * @param widthRes the width resolution + */ + public void setWidthRes(int widthRes) { + this.widthRes = widthRes; + } + + /** + * Sets the height resolution + * + * @param heightRes the height resolution + */ + public void setHeightRes(int heightRes) { + this.heightRes = heightRes; + } + + /** + * Returns the x coordinate of this data object + * + * @return the x coordinate of this data object + */ + public int getX() { + return x; + } + + /** + * Returns the y coordinate of this data object + * + * @return the y coordinate of this data object + */ + public int getY() { + return y; + } + + /** + * Returns the width of this data object + * + * @return the width of this data object + */ + public int getWidth() { + return width; + } + + /** + * Returns the height of this data object + * + * @return the height of this data object + */ + public int getHeight() { + return height; + } + + /** + * Returns the width resolution of this data object + * + * @return the width resolution of this data object + */ + public int getWidthRes() { + return widthRes; + } + + /** + * Returns the height resolution of this data object + * + * @return the height resolution of this data object + */ + public int getHeightRes() { + return heightRes; + } + + /** + * Returns the rotation of this data object + * + * @return the rotation of this data object + */ + public int getRotation() { + return rotation; + } + + /** + * Sets the data object rotation + * + * @param rotation the data object rotation + */ + public void setRotation(int rotation) { + this.rotation = rotation; + } + + /** {@inheritDoc} */ + public String toString() { + return "x=" + x + + ", y=" + y + + ", width=" + width + + ", height=" + height + + ", widthRes=" + widthRes + + ", heightRes=" + heightRes + + ", rotation=" + rotation; + } + +} diff --git a/src/java/org/apache/fop/afp/AFPPageFonts.java b/src/java/org/apache/fop/afp/AFPPageFonts.java new file mode 100644 index 000000000..41fce731d --- /dev/null +++ b/src/java/org/apache/fop/afp/AFPPageFonts.java @@ -0,0 +1,67 @@ +/* + * 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 org.apache.fop.afp.fonts.AFPFont; +import org.apache.fop.afp.fonts.AFPFontAttributes; + + +/** + * Holds the current page fonts + */ +public class AFPPageFonts extends java.util.HashMap { + private static final long serialVersionUID = -4991896259427109041L; + + /** + * Default constructor + */ + public AFPPageFonts() { + super(); + } + + /** + * Parameterized constructor + * + * @param fonts an existing set of afp page fonts + */ + public AFPPageFonts(AFPPageFonts fonts) { + super(fonts); + } + + /** + * Registers a font on the current page and returns font attributes + * + * @param fontName the internal font name + * @param font the AFPFont + * @param fontSize the font point size + * @return newly registered AFPFontAttributes + */ + public AFPFontAttributes registerFont(String fontName, AFPFont font, int fontSize) { + String pageFontKey = fontName + "_" + fontSize; + AFPFontAttributes afpFontAttributes = (AFPFontAttributes)super.get(pageFontKey); + // Add to page font mapping if not already present + if (afpFontAttributes == null) { + afpFontAttributes = new AFPFontAttributes(fontName, font, fontSize); + super.put(pageFontKey, afpFontAttributes); + afpFontAttributes.setFontReference(super.size()); + } + return afpFontAttributes; + } +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/AFPRectanglePainter.java b/src/java/org/apache/fop/afp/AFPRectanglePainter.java new file mode 100644 index 000000000..56c60b440 --- /dev/null +++ b/src/java/org/apache/fop/afp/AFPRectanglePainter.java @@ -0,0 +1,82 @@ +/* + * 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.geom.AffineTransform; + +import org.apache.fop.afp.modca.DataStream; + +public class AFPRectanglePainter extends AbstractAFPPainter { + + /** + * Main constructor + * + * @param state the afp state + * @param dataStream the afp datastream + */ + public AFPRectanglePainter(AFPState state, DataStream dataStream) { + super(state, dataStream); + } + + /** {@inheritDoc} */ + public void paint(PaintInfo paintInfo) { + RectanglePaintInfo rectanglePaintInfo = (RectanglePaintInfo)paintInfo; + int pageWidth = dataStream.getCurrentPage().getWidth(); + int pageHeight = dataStream.getCurrentPage().getHeight(); + + AFPUnitConverter unitConv = state.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(); + + AFPLineDataInfo lineDataInfo = new AFPLineDataInfo(); + lineDataInfo.color = state.getColor(); + lineDataInfo.rotation = state.getRotation(); + lineDataInfo.thickness = Math.round(height); + + switch (lineDataInfo.rotation) { + case 0: + lineDataInfo.x1 = Math.round((float)at.getTranslateX() + x); + lineDataInfo.y1 = lineDataInfo.y2 = Math.round((float)at.getTranslateY() + y); + lineDataInfo.x2 = Math.round((float)at.getTranslateX() + x + width); + break; + case 90: + lineDataInfo.x1 = Math.round((float)at.getTranslateY() + x); + lineDataInfo.y1 = lineDataInfo.y2 + = pageWidth - Math.round((float)at.getTranslateX()) + Math.round(y); + lineDataInfo.x2 = Math.round(width + (float)at.getTranslateY() + x); + break; + case 180: + lineDataInfo.x1 = pageWidth - Math.round((float)at.getTranslateX() - x); + lineDataInfo.y1 = lineDataInfo.y2 = pageHeight - Math.round((float)at.getTranslateY() - y); + lineDataInfo.x2 = pageWidth - Math.round((float)at.getTranslateX() - x - width); + break; + case 270: + lineDataInfo.x1 = pageHeight - Math.round((float)at.getTranslateY() - x); + lineDataInfo.y1 = lineDataInfo.y2 = Math.round((float)at.getTranslateX() + y); + lineDataInfo.x2 = lineDataInfo.x1 + Math.round(width - x); + break; + } + dataStream.createLine(lineDataInfo); + } +} diff --git a/src/java/org/apache/fop/afp/AFPResourceInfo.java b/src/java/org/apache/fop/afp/AFPResourceInfo.java new file mode 100644 index 000000000..729339fa4 --- /dev/null +++ b/src/java/org/apache/fop/afp/AFPResourceInfo.java @@ -0,0 +1,141 @@ +/* + * 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; + + +/** + * The level at which a resource is to reside in the AFP output + */ +public class AFPResourceInfo { + private static final AFPResourceLevel DEFAULT_LEVEL + = new AFPResourceLevel(AFPResourceLevel.PRINT_FILE); + + /** the uri of this resource */ + private String uri = null; + + /** the reference name of this resource */ + private String name = null; + + /** the resource level of this resource */ + private AFPResourceLevel level = DEFAULT_LEVEL; + + /** true when the resource level was changed */ + private boolean levelChanged = false; + + /** + * Sets the data object uri + * + * @param uri the data object uri + */ + public void setUri(String uri) { + this.uri = uri; + } + + /** + * Returns the uri of this data object + * + * @return the uri of this data object + */ + public String getUri() { + return uri; + } + + /** + * Sets the resource reference name + * + * @param resourceName the resource reference name + */ + public void setName(String resourceName) { + this.name = resourceName; + } + + /** + * Returns the resource reference name + * + * @return the resource reference name + */ + public String getName() { + return this.name; + } + + /** + * Returns the resource level + * + * @return the resource level + */ + public AFPResourceLevel getLevel() { + if (level == null) { + return DEFAULT_LEVEL; + } + return this.level; + } + + /** + * Sets the resource level + * + * @param resourceLevel the resource level + */ + public void setLevel(AFPResourceLevel resourceLevel) { + this.level = resourceLevel; + levelChanged = true; + } + + /** + * Returns true when the resource level was set + * + * @return true when the resource level was set + */ + public boolean levelChanged() { + return levelChanged; + } + + /** {@inheritDoc} */ + public String toString() { + return "AFPResourceInfo{uri=" + uri + + (name != null ? ", name=" + name : "") + + (level != null ? ", level=" + level : "") + + "}"; + + } + + /** {@inheritDoc} */ + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if ((obj == null) || !(obj instanceof AFPResourceInfo)) { + return false; + } + + AFPResourceInfo ri = (AFPResourceInfo)obj; + return (uri == ri.uri || uri != null && uri.equals(ri.uri)) + && (name == ri.name || name != null && name.equals(ri.name)) + && (level == ri.level || level != null && level.equals(ri.level)); + } + + /** {@inheritDoc} */ + public int hashCode() { + int hash = 7; + hash = 31 * hash + (null == uri ? 0 : uri.hashCode()); + hash = 31 * hash + (null == name ? 0 : name.hashCode()); + hash = 31 * hash + (null == level ? 0 : level.hashCode()); + return hash; + } +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/AFPResourceLevel.java b/src/java/org/apache/fop/afp/AFPResourceLevel.java new file mode 100644 index 000000000..85cdefb4b --- /dev/null +++ b/src/java/org/apache/fop/afp/AFPResourceLevel.java @@ -0,0 +1,201 @@ +/* + * 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; + +/** + * A resource level + */ +public class AFPResourceLevel { + + /** directly in page **/ + public static final int INLINE = 0; + + /** page level **/ + public static final int PAGE = 1; + + /** page group level **/ + public static final int PAGE_GROUP = 2; + + /** document level **/ + public static final int DOCUMENT = 3; + + /** print file level **/ + public static final int PRINT_FILE = 4; + + /** external level **/ + public static final int EXTERNAL = 5; + + private static final String NAME_INLINE = "inline"; + private static final String NAME_PAGE = "page"; + private static final String NAME_PAGE_GROUP = "page-group"; + private static final String NAME_DOCUMENT = "document"; + private static final String NAME_PRINT_FILE = "print-file"; + private static final String NAME_EXTERNAL = "external"; + + private static final String[] NAMES = new String[] { + NAME_INLINE, NAME_PAGE, NAME_PAGE_GROUP, NAME_DOCUMENT, NAME_PRINT_FILE, NAME_EXTERNAL + }; + + + /** where the resource will reside in the AFP output */ + private int level = PRINT_FILE; // default is print-file level + + /** the external resource group file path */ + private String extFilePath = null; + + /** + * Sets the resource placement level within the AFP output + * + * @param levelString the resource level (page, page-group, document, print-file or external) + * @return true if the resource level was successfully set + */ + public static AFPResourceLevel valueOf(String levelString) { + if (levelString != null) { + levelString = levelString.toLowerCase(); + AFPResourceLevel resourceLevel = null; + for (int i = 0; i < NAMES.length; i++) { + if (NAMES[i].equals(levelString)) { + resourceLevel = new AFPResourceLevel(i); + break; + } + } + return resourceLevel; + } + return null; + } + + /** + * Main constructor + * + * @param level the resource level + */ + public AFPResourceLevel(int level) { + setLevel(level); + } + + /** + * Sets the resource level + * + * @param level the resource level + */ + public void setLevel(int level) { + this.level = level; + } + + /** + * Returns true if this is at page level + * + * @return true if this is at page level + */ + public boolean isPage() { + return level == PAGE; + } + + /** + * Returns true if this is at page group level + * + * @return true if this is at page group level + */ + public boolean isPageGroup() { + return level == PAGE_GROUP; + } + + /** + * Returns true if this is at document level + * + * @return true if this is at document level + */ + public boolean isDocument() { + return level == DOCUMENT; + } + + /** + * Returns true if this is at external level + * + * @return true if this is at external level + */ + public boolean isExternal() { + return level == EXTERNAL; + } + + /** + * Returns true if this is at print-file level + * + * @return true if this is at print-file level + */ + public boolean isPrintFile() { + return level == PRINT_FILE; + } + + /** + * Returns true if this resource level is inline + * + * @return true if this resource level is inline + */ + public boolean isInline() { + return level == INLINE; + } + + /** + * Returns the destination file path of the external resource group file + * + * @return the destination file path of the external resource group file + */ + public String getExternalFilePath() { + return this.extFilePath; + } + + /** + * Sets the external destination of the resource + * + * @param filePath the external resource group file + */ + public void setExternalFilePath(String filePath) { + this.extFilePath = filePath; + } + + /** {@inheritDoc} */ + public String toString() { + return NAMES[level] + (isExternal() ? ", file=" + extFilePath : ""); + } + + /** {@inheritDoc} */ + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if ((obj == null) || !(obj instanceof AFPResourceLevel)) { + return false; + } + + AFPResourceLevel rl = (AFPResourceLevel)obj; + return (level == level) + && (extFilePath == rl.extFilePath + || extFilePath != null && extFilePath.equals(rl.extFilePath)); + } + + /** {@inheritDoc} */ + public int hashCode() { + int hash = 7; + hash = 31 * hash + level; + hash = 31 * hash + (null == extFilePath ? 0 : extFilePath.hashCode()); + return hash; + } +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/AFPResourceManager.java b/src/java/org/apache/fop/afp/AFPResourceManager.java new file mode 100644 index 000000000..111238be8 --- /dev/null +++ b/src/java/org/apache/fop/afp/AFPResourceManager.java @@ -0,0 +1,188 @@ +/* + * 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.io.IOException; +import java.io.OutputStream; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +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; + +/** + * Manages the creation and storage of document resources + */ +public class AFPResourceManager { + /** Static logging instance */ + private static final Log log = LogFactory.getLog(AFPResourceManager.class); + + /** The AFP datastream (document tree) */ + private DataStream dataStream; + + /** Resource creation factory */ + private final Factory factory; + + private final AFPStreamer streamer; + + private final AFPDataObjectFactory dataObjectFactory; + + /** Maintain a reference count of instream objects for referencing purposes */ + private int instreamObjectCount = 0; + + /** a mapping of resourceInfo --> include name */ + private final Map/**/ includeNameMap + = new java.util.HashMap()/**/; + + /** + * Main constructor + */ + public AFPResourceManager() { + this.factory = new Factory(); + this.streamer = new AFPStreamer(factory); + this.dataObjectFactory = new AFPDataObjectFactory(factory); + } + + /** + * Sets the outputstream + * + * @param state the afp state + * @param outputStream the outputstream + */ + public void createDataStream(AFPState state, OutputStream outputStream) { + this.dataStream = streamer.createDataStream(state); + streamer.setOutputStream(outputStream); + } + + /** + * Returns the AFP DataStream + * + * @return the AFP DataStream + */ + public DataStream getDataStream() { + return this.dataStream; + } + + /** + * Tells the streamer to write + * + * @throws IOException thrown if an I/O exception of some sort has occurred. + */ + public void writeToStream() throws IOException { + streamer.close(); + } + + /** + * Sets the default resource group file path + * + * @param filePath the default resource group file path + */ + + public void setDefaultResourceGroupFilePath(String filePath) { + streamer.setDefaultResourceGroupFilePath(filePath); + } + + /** + * Creates a new data object in the AFP datastream + * + * @param dataObjectInfo the data object info + * + * @throws IOException thrown if an I/O exception of some sort has occurred. + */ + public void createObject(AFPDataObjectInfo dataObjectInfo) throws IOException { + AbstractNamedAFPObject namedObj = null; + + AFPResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); + String uri = resourceInfo.getUri(); + if (uri == null) { + uri = "/"; + } + // if this is an instream data object adjust the uri to ensure that its unique + if (uri.endsWith("/")) { + uri += "#" + (++instreamObjectCount); + resourceInfo.setUri(uri); + } + + String objectName = (String)includeNameMap.get(resourceInfo); + if (objectName == null) { + boolean useInclude = true; + Registry.ObjectType objectType = null; + + // new resource so create + if (dataObjectInfo instanceof AFPImageObjectInfo) { + AFPImageObjectInfo imageObjectInfo = (AFPImageObjectInfo)dataObjectInfo; + namedObj = dataObjectFactory.createImage(imageObjectInfo); + } else if (dataObjectInfo instanceof AFPGraphicsObjectInfo) { + AFPGraphicsObjectInfo graphicsObjectInfo = (AFPGraphicsObjectInfo)dataObjectInfo; + namedObj = dataObjectFactory.createGraphic(graphicsObjectInfo); + } else { + // natively embedded object + namedObj = dataObjectFactory.createObjectContainer(dataObjectInfo); + objectType = dataObjectInfo.getObjectType(); + useInclude = objectType != null && objectType.isIncludable(); + } + + // set data object viewport (i.e. position, rotation, dimension, resolution) + if (namedObj instanceof AbstractDataObject) { + AbstractDataObject dataObj = (AbstractDataObject)namedObj; + dataObj.setViewport(dataObjectInfo); + } + + AFPResourceLevel resourceLevel = resourceInfo.getLevel(); + ResourceGroup resourceGroup = streamer.getResourceGroup(resourceLevel); + useInclude &= resourceGroup != null; + if (useInclude) { + // if it is to reside within a resource group at print-file or external level + if (resourceLevel.isPrintFile() || resourceLevel.isExternal()) { + // wrap newly created data object in a resource object + namedObj = dataObjectFactory.createResource(namedObj, resourceInfo, objectType); + } + + // add data object into its resource group destination + resourceGroup.addObject(namedObj); + + // create the include object + objectName = namedObj.getName(); + IncludeObject includeObject + = dataObjectFactory.createInclude(objectName, dataObjectInfo); + + // add an include to the current page + dataStream.getCurrentPage().addObject(includeObject); + + // record mapping of resource info to data object resource name + includeNameMap.put(resourceInfo, objectName); + } else { + // not to be included so inline data object directly into the current page + dataStream.getCurrentPage().addObject(namedObj); + } + } else { + // an existing data resource so reference it by adding an include to the current page + IncludeObject includeObject + = dataObjectFactory.createInclude(objectName, dataObjectInfo); + dataStream.getCurrentPage().addObject(includeObject); + } + } + +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/AFPState.java b/src/java/org/apache/fop/afp/AFPState.java new file mode 100644 index 000000000..9de3a0c05 --- /dev/null +++ b/src/java/org/apache/fop/afp/AFPState.java @@ -0,0 +1,511 @@ +/* + * 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 org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.fop.AbstractState; + +/** + * This keeps information about the current state when writing to an AFP datastream. + */ +public class AFPState extends org.apache.fop.AbstractState implements Cloneable { + + private static final long serialVersionUID = 8206711712452344473L; + + private static Log log = LogFactory.getLog("org.apache.xmlgraphics.afp"); + + /** the portrait rotation */ + private int portraitRotation = 0; + + /** the landscape rotation */ + private int landscapeRotation = 270; + + /** color image support */ + private boolean colorImages = false; + + /** images are supported in this AFP environment */ + private boolean nativeImages = false; + + /** default value for image depth */ + private int bitsPerPixel = 8; + + /** the output resolution */ + private int resolution = 240; // 240 dpi + + /** the current page */ + private AFPPageState pageState = new AFPPageState(); + +// /** reference orientation */ +// private int orientation = 0; + + /** a unit converter */ + private final transient AFPUnitConverter unitConv = new AFPUnitConverter(this); + + /** + * Sets the rotation to be used for portrait pages, valid values are 0 + * (default), 90, 180, 270. + * + * @param rotation + * The rotation in degrees. + */ + public void setPortraitRotation(int rotation) { + if (rotation == 0 || rotation == 90 || rotation == 180 + || rotation == 270) { + portraitRotation = rotation; + } else { + throw new IllegalArgumentException( + "The portrait rotation must be one" + + " of the values 0, 90, 180, 270"); + + } + } + + /** + * Returns the rotation to be used for portrait pages + * + * @return the rotation to be used for portrait pages + */ + protected int getPortraitRotation() { + return this.portraitRotation; + } + + /** + * Sets the rotation to be used for landscape pages, valid values are 0, 90, + * 180, 270 (default). + * + * @param rotation + * The rotation in degrees. + */ + public void setLandscapeRotation(int rotation) { + if (rotation == 0 || rotation == 90 || rotation == 180 + || rotation == 270) { + landscapeRotation = rotation; + } else { + throw new IllegalArgumentException( + "The landscape rotation must be one" + + " of the values 0, 90, 180, 270"); + } + } + + /** + * Returns the landscape rotation + * + * @return the landscape rotation + */ + protected int getLandscapeRotation() { + return this.landscapeRotation; + } + + /** + * Sets the number of bits used per pixel + * + * @param bitsPerPixel + * number of bits per pixel + */ + public void setBitsPerPixel(int bitsPerPixel) { + switch (bitsPerPixel) { + case 1: + case 4: + case 8: + this.bitsPerPixel = bitsPerPixel; + break; + default: + log.warn("Invalid bits_per_pixel value, must be 1, 4 or 8."); + this.bitsPerPixel = 8; + break; + } + } + + /** + * Returns the number of bits per pixel + * + * @return the number of bits per pixel + */ + public int getBitsPerPixel() { + return this.bitsPerPixel; + } + + /** + * Sets whether images are color or not + * + * @param colorImages + * color image output + */ + public void setColorImages(boolean colorImages) { + this.colorImages = colorImages; + } + + /** + * Returns true if color images are to be used + * + * @return true if color images are to be used + */ + public boolean isColorImages() { + return this.colorImages; + } + + /** + * Sets whether images are natively supported or not in the AFP environment + * + * @param nativeImages true if images are natively supported in this AFP environment + */ + public void setNativeImages(boolean nativeImages) { + this.nativeImages = nativeImages; + } + + /** + * Returns true if images are supported natively in this AFP environment + * + * @return true if images are supported natively in this AFP environment + */ + public boolean isNativeImages() { + return this.nativeImages; + } + + /** + * Sets the output/device resolution + * + * @param resolution + * the output resolution (dpi) + */ + public void setResolution(int resolution) { + if (log.isDebugEnabled()) { + log.debug("renderer-resolution set to: " + resolution + "dpi"); + } + this.resolution = resolution; + } + + /** + * Returns the output/device resolution. + * + * @return the resolution in dpi + */ + public int getResolution() { + return this.resolution; + } + + /** {@inheritDoc} */ + protected AbstractData instantiateData() { + return new AFPData(); + } + + /** {@inheritDoc} */ + protected AbstractState instantiateState() { + return new AFPState(); + } + + /** + * Returns the state of the current page + * + * @return the state of the current page + */ + protected AFPPageState getPageState() { + return this.pageState; + } + + /** + * Sets if the current painted shape is to be filled + * + * @param fill true if the current painted shape is to be filled + * @return true if the fill value has changed + */ + protected boolean setFill(boolean fill) { + if (fill != ((AFPData)getData()).filled) { + ((AFPData)getData()).filled = fill; + return true; + } + return false; + } + + /** + * Gets the current page fonts + * + * @return the current page fonts + */ + public AFPPageFonts getPageFonts() { + return pageState.getFonts(); + } + + /** + * Increments and returns the page font count + * + * @return the page font count + */ + public int incrementPageFontCount() { + return pageState.incrementFontCount(); + } + + /** + * Sets the page width + * + * @param pageWidth the page width + */ + public void setPageWidth(int pageWidth) { + pageState.setWidth(pageWidth); + } + + /** + * Returns the page width + * + * @return the page width + */ + public int getPageWidth() { + return pageState.getWidth(); + } + + /** + * Sets the page height + * + * @param pageHeight the page height + */ + public void setPageHeight(int pageHeight) { + pageState.setHeight(pageHeight); + } + + /** + * Returns the page height + * + * @return the page height + */ + public int getPageHeight() { + return pageState.getHeight(); + } + + /** + * Returns the page rotation + * + * @return the page rotation + */ + public int getPageRotation() { + return pageState.getOrientation(); + } + + /** + * Sets the uri of the current image + * + * @param uri the uri of the current image + */ + public void setImageUri(String uri) { + ((AFPData)getData()).imageUri = uri; + } + + /** + * Gets the uri of the current image + * + * @return the uri of the current image + */ + public String getImageUri() { + return ((AFPData)getData()).imageUri; + } + + /** + * Returns the currently derived rotation + * + * @return the currently derived rotation + */ + public int getRotation() { + return getData().getDerivedRotation(); + } + + /** + * Returns the unit converter + * + * @return the unit converter + */ + public AFPUnitConverter getUnitConverter() { + return this.unitConv; + } + + /** {@inheritDoc} */ + public Object clone() { + AFPState state = (AFPState)super.clone(); + state.pageState = (AFPPageState)this.pageState.clone(); + state.portraitRotation = this.portraitRotation; + state.landscapeRotation = this.landscapeRotation; + state.bitsPerPixel = this.bitsPerPixel; + state.colorImages = this.colorImages; + state.resolution = this.resolution; + return state; + } + + /** {@inheritDoc} */ + public String toString() { + return "AFPState{" + "portraitRotation=" + portraitRotation + + ", landscapeRotation=" + landscapeRotation + + ", colorImages=" + colorImages + + ", bitsPerPixel=" + bitsPerPixel + + ", resolution=" + resolution + + ", pageState=" + pageState + + super.toString() + + "}"; + } + + /** + * Page level state data + */ + private class AFPPageState implements Cloneable { + /** page width */ + private int width = 0; + + /** page height */ + private int height = 0; + + /** page fonts */ + private AFPPageFonts fonts = new AFPPageFonts(); + + /** page font count */ + private int fontCount = 0; + + /** page orientation */ + private int orientation = 0; + + /** + * Returns the page width + * + * @return the page width + */ + protected int getWidth() { + return width; + } + + /** + * Sets the page width + * + * @param width the page width + */ + protected void setWidth(int width) { + this.width = width; + } + + /** + * Returns the page height + * + * @return the page height + */ + protected int getHeight() { + return height; + } + + /** + * Sets the page height + * + * @param height the page height + */ + protected void setHeight(int height) { + this.height = height; + } + + /** + * Returns the page fonts + * + * @return the page fonts + */ + protected AFPPageFonts getFonts() { + return fonts; + } + + /** + * Sets the current page fonts + * + * @param fonts the current page fonts + */ + protected void setFonts(AFPPageFonts fonts) { + this.fonts = fonts; + } + + /** + * Increments and returns the current page font count + * + * @return increment and return the current page font count + */ + protected int incrementFontCount() { + return ++fontCount; + } + + /** + * Returns the current page orientation + * + * @return the current page orientation + */ + protected int getOrientation() { + return orientation; + } + + /** + * Sets the current page orientation + * + * @param orientation the current page orientation + */ + protected void setOrientation(int orientation) { + this.orientation = orientation; + } + + /** {@inheritDoc} */ + public Object clone() { + AFPPageState state = new AFPPageState(); + state.width = this.width; + state.height = this.height; + state.orientation = this.orientation; + state.fonts = new AFPPageFonts(this.fonts); + state.fontCount = this.fontCount; + return state; + } + + /** {@inheritDoc} */ + public String toString() { + return "AFPPageState{width=" + width + + ", height=" + height + + ", orientation=" + orientation + + ", fonts=" + fonts + + ", fontCount=" + fontCount + + "}"; + } + } + + /** + * Block level state data + */ + private class AFPData extends org.apache.fop.AbstractState.AbstractData { + private static final long serialVersionUID = -1789481244175275686L; + + /** The current fill status */ + private boolean filled = false; + + private String imageUri = null; + + /** {@inheritDoc} */ + public Object clone() { + AFPData obj = (AFPData)super.clone(); + obj.filled = this.filled; + obj.imageUri = this.imageUri; + return obj; + } + + /** {@inheritDoc} */ + public String toString() { + return "AFPData{" + super.toString() + + ", filled=" + filled + + ", imageUri=" + imageUri + + "}"; + } + } + +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/AFPStreamer.java b/src/java/org/apache/fop/afp/AFPStreamer.java new file mode 100644 index 000000000..42dcf4412 --- /dev/null +++ b/src/java/org/apache/fop/afp/AFPStreamer.java @@ -0,0 +1,216 @@ +/* + * 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.io.BufferedOutputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.RandomAccessFile; +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.modca.DataStream; +import org.apache.fop.afp.modca.ResourceGroup; +import org.apache.fop.afp.modca.StreamedResourceGroup; + +/** + * Manages the streaming of the AFP output + */ +public class AFPStreamer implements Streamable { + /** Static logging instance */ + private static final Log log = LogFactory.getLog(AFPStreamer.class); + + private static final String AFPDATASTREAM_TEMP_FILE_PREFIX = "AFPDataStream_"; + + private static final int BUFFER_SIZE = 4096; + + private static final String DEFAULT_EXTERNAL_RESOURCE_FILENAME = "resources.afp"; + + + private final Factory factory; + + /** A mapping of external resource destinations to resource groups */ + private final Map/**/pathResourceGroupMap + = new java.util.HashMap/**/(); + + private StreamedResourceGroup printFileResourceGroup; + + /** Sets the default resource group file path */ + private String defaultResourceGroupFilePath = DEFAULT_EXTERNAL_RESOURCE_FILENAME; + + private File tempFile; + + /** temporary document outputstream */ + private OutputStream documentOutputStream; + + /** the final outputstream */ + private OutputStream outputStream; + + private RandomAccessFile documentFile; + + private DataStream dataStream; + + /** + * Main constructor + * + * @param factory a factory + */ + public AFPStreamer(Factory factory) { + this.factory = factory; + } + + /** + * Creates a new DataStream + * @param state the afp state + * + * @return a new {@link DataStream} + */ + public DataStream createDataStream(AFPState state) { + try { + this.tempFile = File.createTempFile(AFPDATASTREAM_TEMP_FILE_PREFIX, null); + this.documentFile = new RandomAccessFile(tempFile, "rw"); + this.documentOutputStream = new BufferedOutputStream( + new FileOutputStream(documentFile.getFD())); + this.dataStream = factory.createDataStream(state, documentOutputStream); + } catch (IOException e) { + log.error(e.getMessage()); + } + return dataStream; + } + + /** + * Sets the default resource group file path + * + * @param filePath the default resource group file path + */ + public void setDefaultResourceGroupFilePath(String filePath) { + this.defaultResourceGroupFilePath = filePath; + } + + /** + * 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.isInline()) { // no resource group for inline level + return null; + } + if (level.isExternal()) { + String filePath = level.getExternalFilePath(); + if (filePath == null) { + log.warn("No file path provided for external resource, using default."); + filePath = defaultResourceGroupFilePath; + } + resourceGroup = (ResourceGroup)pathResourceGroupMap.get(filePath); + if (resourceGroup == null) { + OutputStream os = null; + try { + os = new BufferedOutputStream(new FileOutputStream(filePath)); + } catch (FileNotFoundException fnfe) { + log.error("Failed to create/open external resource group file '" + + filePath + "'"); + } finally { + if (os != null) { + resourceGroup = factory.createStreamedResourceGroup(os); + pathResourceGroupMap.put(filePath, resourceGroup); + } + } + } + } else if (level.isPrintFile()) { + if (printFileResourceGroup == null) { + // use final outputstream for print-file resource group + printFileResourceGroup = factory.createStreamedResourceGroup(outputStream); + } + resourceGroup = printFileResourceGroup; + } else { + // resource group in afp document datastream + resourceGroup = dataStream.getResourceGroup(level); + } + return resourceGroup; + } + + /** + * Closes off the AFP stream writing the document stream + * + * @throws IOException if an an I/O exception of some sort has occurred + */ + public void close() throws IOException { + // write out any external resource groups + Iterator it = pathResourceGroupMap.entrySet().iterator(); + while (it.hasNext()) { + StreamedResourceGroup resourceGroup = (StreamedResourceGroup)it.next(); + resourceGroup.close(); + } + + // close any open print-file resource group + if (printFileResourceGroup != null) { + printFileResourceGroup.close(); + } + + // write out document + writeToStream(outputStream); + + outputStream.close(); + + // delete temporary file + tempFile.delete(); + } + + /** + * Sets the final outputstream + * + * @param outputStream an outputstream + */ + public void setOutputStream(OutputStream outputStream) { + this.outputStream = outputStream; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + int len = (int)documentFile.length(); + int numChunks = len / BUFFER_SIZE; + int remainingChunkSize = len % BUFFER_SIZE; + byte[] buffer; + + documentFile.seek(0); + if (numChunks > 0) { + buffer = new byte[BUFFER_SIZE]; + for (int i = 0; i < numChunks; i++) { + documentFile.read(buffer, 0, BUFFER_SIZE); + os.write(buffer, 0, BUFFER_SIZE); + } + } else { + buffer = new byte[remainingChunkSize]; + } + if (remainingChunkSize > 0) { + documentFile.read(buffer, 0, remainingChunkSize); + os.write(buffer, 0, remainingChunkSize); + } + os.flush(); + } +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/AFPTextDataInfo.java b/src/java/org/apache/fop/afp/AFPTextDataInfo.java new file mode 100644 index 000000000..3e87fc473 --- /dev/null +++ b/src/java/org/apache/fop/afp/AFPTextDataInfo.java @@ -0,0 +1,202 @@ +/* + * 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; + +/** + * Text data information + */ +public class AFPTextDataInfo { + + private int fontReference; + + private int x; + + private int y; + + private Color color; + + private int variableSpaceCharacterIncrement; + + private int interCharacterAdjustment; + + private byte[] data; + + private int rotation; + + /** + * Returns the font reference + * + * @return the font reference + */ + public int getFontReference() { + return fontReference; + } + + /** + * Sets the font reference + * + * @param fontReference the font reference + */ + public void setFontReference(int fontReference) { + this.fontReference = fontReference; + } + + /** + * Returns the x coordinate + * + * @return the x coordinate + */ + public int getX() { + return x; + } + + /** + * Sets the X coordinate + * + * @param x the X coordinate + */ + public void setX(int x) { + this.x = x; + } + + /** + * Returns the y coordinate + * + * @return the y coordinate + */ + public int getY() { + return y; + } + + /** + * Sets the Y coordinate + * + * @param y the Y coordinate + */ + public void setY(int y) { + this.y = y; + } + + /** + * Returns the color + * + * @return the color + */ + public Color getColor() { + return color; + } + + /** + * Sets the color + * + * @param color the color + */ + public void setColor(Color color) { + this.color = color; + } + + /** + * Return the variable space character increment + * + * @return the variable space character increment + */ + public int getVariableSpaceCharacterIncrement() { + return variableSpaceCharacterIncrement; + } + + /** + * Sets the variable space character increment + * + * @param variableSpaceCharacterIncrement the variable space character increment + */ + public void setVariableSpaceCharacterIncrement( + int variableSpaceCharacterIncrement) { + this.variableSpaceCharacterIncrement = variableSpaceCharacterIncrement; + } + + /** + * Return the inter character adjustment + * + * @return the inter character adjustment + */ + public int getInterCharacterAdjustment() { + return interCharacterAdjustment; + } + + /** + * Sets the inter character adjustment + * + * @param interCharacterAdjustment the inter character adjustment + */ + public void setInterCharacterAdjustment(int interCharacterAdjustment) { + this.interCharacterAdjustment = interCharacterAdjustment; + } + + /** + * Return the text data + * + * @return the text data + */ + public byte[] getData() { + return data; + } + + /** + * Sets the text data + * + * @param data the text orientation + */ + public void setData(byte[] data) { + this.data = data; + } + + /** + * Sets the text orientation + * + * @param rotation the text rotation + */ + public void setRotation(int rotation) { + this.rotation = rotation; + } + + /** + * Returns the text rotation + * + * @return the text rotation + */ + public int getRotation() { + return this.rotation; + } + + /** {@inheritDoc} */ + public String toString() { + return "TextDataInfo{fontReference=" + fontReference + + ", x=" + x + + ", y=" + y + + ", color=" + color + + ", vsci=" + variableSpaceCharacterIncrement + + ", ica=" + interCharacterAdjustment + + ", orientation=" + rotation + + ", data=" + data + + "}"; + } +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/AFPTextHandler.java b/src/java/org/apache/fop/afp/AFPTextHandler.java new file mode 100644 index 000000000..3dee6ca2e --- /dev/null +++ b/src/java/org/apache/fop/afp/AFPTextHandler.java @@ -0,0 +1,104 @@ +/* + * 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.io.IOException; + +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.GraphicsObject; +import org.apache.fop.fonts.Font; +import org.apache.fop.fonts.FontInfo; +import org.apache.xmlgraphics.java2d.TextHandler; + +/** + * Specialized TextHandler implementation that the AFPGraphics2D class delegates to to paint text + * using AFP GOCA text operations. + */ +public class AFPTextHandler implements TextHandler { + + /** logging instance */ + private static Log log = LogFactory.getLog(AFPTextHandler.class); + + private AFPGraphics2D g2d = null; + + /** Overriding FontState */ + protected Font overrideFont = null; + + /** + * Main constructor. + * @param g2d the PSGraphics2D instance this instances is used by + */ + public AFPTextHandler(AFPGraphics2D g2d) { + this.g2d = g2d; + } + + /** + * Return the font information associated with this object + * @return the FontInfo object + */ + public FontInfo getFontInfo() { + return g2d.getFontInfo(); + } + + /** + * Add a text string to the current data object of the AFP datastream. + * The text is painted using text operations. + * {@inheritDoc} + */ + public void drawString(String str, float x, float y) throws IOException { + log.debug("drawString() str=" + str + ", x=" + x + ", y=" + y); + GraphicsObject graphicsObj = g2d.getGraphicsObject(); + Color col = g2d.getColor(); + + AFPState state = g2d.getState(); + if (state.setColor(col)) { + graphicsObj.setColor(col); + } + if (overrideFont != null) { + FontInfo fontInfo = getFontInfo(); + AFPPageFonts pageFonts = state.getPageFonts(); + String internalFontName = overrideFont.getFontName(); + int fontSize = overrideFont.getFontSize(); + if (state.setFontName(internalFontName) || state.setFontSize(fontSize)) { + AFPFont font = (AFPFont)fontInfo.getFonts().get(internalFontName); + AFPFontAttributes afpFontAttributes = pageFonts.registerFont( + internalFontName, + font, + fontSize + ); + int fontReference = afpFontAttributes.getFontReference(); + graphicsObj.setCharacterSet(fontReference); + } + } + graphicsObj.addString(str, Math.round(x), Math.round(y)); + } + + /** + * Sets the overriding font. + * @param overrideFont Overriding Font to set + */ + public void setOverrideFont(Font overrideFont) { + this.overrideFont = overrideFont; + } +} diff --git a/src/java/org/apache/fop/afp/AFPUnitConverter.java b/src/java/org/apache/fop/afp/AFPUnitConverter.java new file mode 100644 index 000000000..69282fc18 --- /dev/null +++ b/src/java/org/apache/fop/afp/AFPUnitConverter.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.geom.AffineTransform; + + + +/** + * AFP Unit converter + */ +public class AFPUnitConverter { + + /** the AFP state */ + private final AFPState state; + + /** + * Unit converter + * + * @param state the AFP state + */ + public AFPUnitConverter(AFPState state) { + this.state = state; + } + + /** + * Converts millipoints to units + * + * @param srcPts source points + * @param dstPts destination points + * @return transformed points + */ + public int[] mpts2units(float[] srcPts, float[] dstPts) { + return transformPoints(srcPts, dstPts, true); + } + + /** + * Converts points to units + * + * @param srcPts source points + * @param dstPts destination points + * @return transformed points + */ + public int[] pts2units(float[] srcPts, float[] dstPts) { + return transformPoints(srcPts, dstPts, false); + } + + /** + * Converts millipoints to units + * + * @param srcPts source points + * @return transformed points + */ + public int[] mpts2units(float[] srcPts) { + return transformPoints(srcPts, null, true); + } + + /** + * Converts points to units + * + * @param srcPts source points + * @return transformed points + */ + public int[] pts2units(float[] srcPts) { + return transformPoints(srcPts, null, false); + } + + /** + * Converts point to unit + * + * @param pt point + * @return transformed point + */ + public float pt2units(float pt) { + return pt / ((float)AFPConstants.DPI_72 / state.getResolution()); + } + + /** + * Converts millipoint to unit + * + * @param mpt millipoint + * @return transformed point + */ + public float mpt2units(float mpt) { + return mpt / ((float)AFPConstants.DPI_72_MPTS / state.getResolution()); + } + + private int[] transformPoints(float[] srcPts, float[] dstPts, boolean milli) { + if (dstPts == null) { + dstPts = new float[srcPts.length]; + } + AffineTransform at = state.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++) { + if (!milli) { + dstPts[i] *= 1000; + } + coords[i] = Math.round(dstPts[i]); + } + return coords; + } + +} diff --git a/src/java/org/apache/fop/afp/AbstractAFPPainter.java b/src/java/org/apache/fop/afp/AbstractAFPPainter.java new file mode 100644 index 000000000..ba6d49fc6 --- /dev/null +++ b/src/java/org/apache/fop/afp/AbstractAFPPainter.java @@ -0,0 +1,51 @@ +/* + * 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 org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.fop.afp.modca.DataStream; + +public abstract class AbstractAFPPainter { + + /** Static logging instance */ + protected static Log log = LogFactory.getLog("org.apache.xmlgraphics.afp"); + + protected final DataStream dataStream; + protected final AFPState state; + + /** + * Main constructor + * + * @param state the afp state + * @param dataStream the afp datastream + */ + public AbstractAFPPainter(AFPState state, DataStream dataStream) { + this.state = state; + this.dataStream = dataStream; + } + + /** + * Paints the painting item + * + * @param paintInfo the painting information + */ + public abstract void paint(PaintInfo paintInfo); +} diff --git a/src/java/org/apache/fop/afp/BorderPaintInfo.java b/src/java/org/apache/fop/afp/BorderPaintInfo.java new file mode 100644 index 000000000..74252b7b9 --- /dev/null +++ b/src/java/org/apache/fop/afp/BorderPaintInfo.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 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/Factory.java b/src/java/org/apache/fop/afp/Factory.java new file mode 100644 index 000000000..840d7b4e8 --- /dev/null +++ b/src/java/org/apache/fop/afp/Factory.java @@ -0,0 +1,636 @@ +/* + * 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.io.OutputStream; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.fop.afp.goca.GraphicsData; +import org.apache.fop.afp.ioca.ImageContent; +import org.apache.fop.afp.ioca.ImageRasterData; +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; +import org.apache.fop.afp.modca.IMImageObject; +import org.apache.fop.afp.modca.ImageDataDescriptor; +import org.apache.fop.afp.modca.ImageObject; +import org.apache.fop.afp.modca.IncludeObject; +import org.apache.fop.afp.modca.IncludePageSegment; +import org.apache.fop.afp.modca.InvokeMediumMap; +import org.apache.fop.afp.modca.MapCodedFont; +import org.apache.fop.afp.modca.MapContainerData; +import org.apache.fop.afp.modca.MapDataResource; +import org.apache.fop.afp.modca.ObjectAreaDescriptor; +import org.apache.fop.afp.modca.ObjectAreaPosition; +import org.apache.fop.afp.modca.ObjectContainer; +import org.apache.fop.afp.modca.ObjectEnvironmentGroup; +import org.apache.fop.afp.modca.Overlay; +import org.apache.fop.afp.modca.PageDescriptor; +import org.apache.fop.afp.modca.PageGroup; +import org.apache.fop.afp.modca.PageObject; +import org.apache.fop.afp.modca.PresentationEnvironmentControl; +import org.apache.fop.afp.modca.PresentationTextDescriptor; +import org.apache.fop.afp.modca.PresentationTextObject; +import org.apache.fop.afp.modca.ResourceEnvironmentGroup; +import org.apache.fop.afp.modca.ResourceGroup; +import org.apache.fop.afp.modca.ResourceObject; +import org.apache.fop.afp.modca.StreamedResourceGroup; +import org.apache.fop.afp.modca.TagLogicalElement; +import org.apache.fop.afp.util.StringUtils; + +/** + * Creator of MO:DCA data objects (mostly) + */ +public class Factory { + + /** Static logging instance */ + private static final Log log = LogFactory.getLog(Factory.class); + + private static final String OBJECT_ENVIRONMENT_GROUP_NAME_PREFIX = "OEG"; + + private static final String ACTIVE_ENVIRONMENT_GROUP_NAME_PREFIX = "AEG"; + + private static final String IMAGE_NAME_PREFIX = "IMG"; + + private static final String GRAPHIC_NAME_PREFIX = "GRA"; + + private static final String BARCODE_NAME_PREFIX = "BAR"; + +// private static final String OTHER_NAME_PREFIX = "OTH"; + + private static final String OBJECT_CONTAINER_NAME_PREFIX = "OC"; + + private static final String RESOURCE_NAME_PREFIX = "RES"; + + private static final String RESOURCE_GROUP_NAME_PREFIX = "RG"; + + private static final String PAGE_GROUP_NAME_PREFIX = "PGP"; + + private static final String PAGE_NAME_PREFIX = "PGN"; + + private static final String OVERLAY_NAME_PREFIX = "OVL"; + + private static final String PRESENTATION_TEXT_NAME_PREFIX = "PT"; + + private static final String DOCUMENT_NAME_PREFIX = "DOC"; + + private static final String IM_IMAGE_NAME_PREFIX = "IMIMG"; + + private static final String IMAGE_SEGMENT_NAME_PREFIX = "IS"; + + + /** the page group count */ + private int pageGroupCount = 0; + + /** the page count */ + private int pageCount = 0; + + /** the image count */ + private int imageCount = 0; + + /** the im image count */ + private int imImageCount = 0; + + /** the image segment count */ + private int imageSegmentCount = 0; + + /** the graphic count */ + private int graphicCount = 0; + + /** the object container count */ + private int objectContainerCount = 0; + + /** the resource count */ + private int resourceCount = 0; + + /** the resource group count */ + private int resourceGroupCount = 0; + + /** the overlay count */ + private int overlayCount = 0; + + /** the presentation text object count */ + private int textObjectCount = 0; + + /** the active environment group count */ + private int activeEnvironmentGroupCount = 0; + + /** the document count */ + private int documentCount = 0; + + /** the object environment group count */ + private int objectEnvironmentGroupCount = 0; + + /** + * Main constructor + */ + public Factory() { + } + + /** + * Creates a new IOCA {@link ImageObject} + * + * @return a new {@link ImageObject} + */ + public ImageObject createImageObject() { + String name = IMAGE_NAME_PREFIX + + StringUtils.lpad(String.valueOf(++imageCount), '0', 5); + ImageObject imageObject = new ImageObject(this, name); + return imageObject; + } + + /** + * Creates an IOCA {@link IMImageObject} + * + * @return a new {@link IMImageObject} + */ + public IMImageObject createIMImageObject() { + String name = IM_IMAGE_NAME_PREFIX + + StringUtils.lpad(String.valueOf(++imImageCount), '0', 3); + IMImageObject imImageObject = new IMImageObject(name); + return imImageObject; + } + + /** + * Creates a new GOCA {@link GraphicsObject} + * + * @return a new {@link GraphicsObject} + */ + public GraphicsObject createGraphicsObject() { + String name = GRAPHIC_NAME_PREFIX + + StringUtils.lpad(String.valueOf(++graphicCount), '0', 5); + GraphicsObject graphicsObj = new GraphicsObject(this, name); + return graphicsObj; + } + + /** + * Creates a new MO:DCA {@link ObjectContainer} + * + * @return a new {@link ObjectContainer} + */ + public ObjectContainer createObjectContainer() { + String name = OBJECT_CONTAINER_NAME_PREFIX + + StringUtils.lpad(String.valueOf(++objectContainerCount), '0', 6); + return new ObjectContainer(this, name); + } + + /** + * Creates a new MO:DCA {@link ResourceObject} + * + * @param resourceName the resource object name + * @return a new {@link ResourceObject} + */ + public ResourceObject createResource(String resourceName) { + return new ResourceObject(resourceName); + } + + /** + * Creates a new MO:DCA {@link ResourceObject} + * + * @return a new {@link ResourceObject} + */ + public ResourceObject createResource() { + String name = RESOURCE_NAME_PREFIX + + StringUtils.lpad(String.valueOf(++resourceCount), '0', 5); + return createResource(name); + } + + /** + * Creates a new MO:DCA {@link PageGroup} + * + * @return a new {@link PageGroup} + */ + public PageGroup createPageGroup() { + String name = PAGE_GROUP_NAME_PREFIX + + StringUtils.lpad(String.valueOf(++pageGroupCount), '0', 5); + return new PageGroup(this, name); + } + + /** + * Creates a new MO:DCA {@link ActiveEnvironmentGroup} + * + * @param width the page width + * @param height the page height + * @param widthRes the page width resolution + * @param heightRes the page height resolution + * @return a new {@link ActiveEnvironmentGroup} + */ + public ActiveEnvironmentGroup createActiveEnvironmentGroup( + int width, int height, int widthRes, int heightRes) { + String name = ACTIVE_ENVIRONMENT_GROUP_NAME_PREFIX + + StringUtils.lpad(String.valueOf(++activeEnvironmentGroupCount ), '0', 5); + return new ActiveEnvironmentGroup(this, name, width, height, widthRes, heightRes); + } + + /** + * Creates a new MO:DCA {@link ResourceGroup} + * + * @return a new {@link ResourceGroup} + */ + public ResourceGroup createResourceGroup() { + String name = RESOURCE_GROUP_NAME_PREFIX + + StringUtils.lpad(String.valueOf(++resourceGroupCount), '0', 6); + return new ResourceGroup(name); + } + + /** + * Creates a new MO:DCA {@link StreamedResourceGroup} + * + * @param os the outputstream of the streamed resource group + * @return a new {@link StreamedResourceGroup} + */ + public StreamedResourceGroup createStreamedResourceGroup(OutputStream os) { + String name = RESOURCE_GROUP_NAME_PREFIX + + StringUtils.lpad(String.valueOf(++resourceGroupCount), '0', 6); + return new StreamedResourceGroup(name, os); + } + + /** + * Creates a new MO:DCA {@link PageObject}. + * + * @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 + * + * @return a new {@link PageObject} + */ + public PageObject createPage(int pageWidth, int pageHeight, int pageRotation, + int pageWidthRes, int pageHeightRes) { + String pageName = PAGE_NAME_PREFIX + + StringUtils.lpad(String.valueOf(++pageCount), '0', 5); + return new PageObject(this, pageName, pageWidth, pageHeight, + pageRotation, pageWidthRes, pageHeightRes); + } + + + /** + * Creates a new MO:DCA {@link PresentationTextObject}. + * + * @return a new {@link PresentationTextObject} + */ + public PresentationTextObject createPresentationTextObject() { + String textObjectName = PRESENTATION_TEXT_NAME_PREFIX + + StringUtils.lpad(String.valueOf(++textObjectCount), '0', 6); + return new PresentationTextObject(textObjectName); + } + + + /** + * Creates a new MO:DCA {@link Overlay}. + * + * @param width + * the width of the overlay + * @param height + * the height of the overlay + * @param widthRes + * the width resolution of the overlay + * @param heightRes + * the height resolution of the overlay + * @param overlayRotation + * the rotation of the overlay + * + * @return a new {@link Overlay}. + */ + public Overlay createOverlay(int width, int height, + int widthRes, int heightRes, int overlayRotation) { + String overlayName = OVERLAY_NAME_PREFIX + + StringUtils.lpad(String.valueOf(++overlayCount), '0', 5); + Overlay overlay = new Overlay(this, overlayName, width, height, + overlayRotation, widthRes, heightRes); + return overlay; + } + + /** + * Creates a MO:DCA {@link Document} + * + * @return a new {@link Document} + */ + public Document createDocument() { + String documentName = DOCUMENT_NAME_PREFIX + + StringUtils.lpad(String.valueOf(++documentCount), '0', 5); + Document document = new Document(this, documentName); + return document; + } + + /** + * Creates a MO:DCA {@link MapCodedFont} + * + * @return a new {@link MapCodedFont} + */ + public MapCodedFont createMapCodedFont() { + MapCodedFont mapCodedFont = new MapCodedFont(); + return mapCodedFont; + } + + /** + * Creates a MO:DCA {@link IncludePageSegment} + * + * @param name the page segment name + * @param x the x coordinate + * @param y the y coordinate + * + * @return a new {@link IncludePageSegment} + */ + public IncludePageSegment createIncludePageSegment(String name, int x, int y) { + IncludePageSegment includePageSegment = new IncludePageSegment(name, x, y); + return includePageSegment; + } + + /** + * Creates a MO:DCA {@link IncludeObject} + * + * @param name the name of this include object + * @return a new {@link IncludeObject} + */ + public IncludeObject createInclude(String name) { + IncludeObject includeObject = new IncludeObject(name); + return includeObject; + } + + /** + * Creates a MO:DCA {@link TagLogicalElement} + * + * @param name name of the element + * @param value value of the element + * @return a new {@link TagLogicalElement} + */ + public TagLogicalElement createTagLogicalElement(String name, String value) { + TagLogicalElement tle = new TagLogicalElement(name, value); + return tle; + } + + /** + * Creates a new {@link DataStream} + * + * @param state the afp state + * @param outputStream an outputstream to write to + * @return a new {@link DataStream} + */ + public DataStream createDataStream(AFPState state, OutputStream outputStream) { + DataStream dataStream = new DataStream(this, state, outputStream); + return dataStream; + } + + /** + * Creates a new MO:DCA {@link PageDescriptor} + * + * @param width the page width. + * @param height the page height. + * @param widthRes the page width resolution. + * @param heightRes the page height resolution. + * @return a new {@link PageDescriptor} + */ + public PageDescriptor createPageDescriptor(int width, int height, int widthRes, int heightRes) { + PageDescriptor pageDescriptor = new PageDescriptor(width, height, widthRes, heightRes); + return pageDescriptor; + } + + /** + * Returns a new MO:DCA {@link ObjectEnvironmentGroup} + * + * @return a new {@link ObjectEnvironmentGroup} + */ + public ObjectEnvironmentGroup createObjectEnvironmentGroup() { + String oegName = OBJECT_ENVIRONMENT_GROUP_NAME_PREFIX + + StringUtils.lpad(String.valueOf(++objectEnvironmentGroupCount), '0', 5); + ObjectEnvironmentGroup objectEnvironmentGroup = new ObjectEnvironmentGroup(oegName); + return objectEnvironmentGroup; + } + + /** + * Creates a new GOCA {@link GraphicsData} + * + * @return a new {@link GraphicsData} + */ + public GraphicsData createGraphicsData() { + GraphicsData graphicsData = new GraphicsData(); + return graphicsData; + } + + /** + * Creates a new {@link ObjectAreaDescriptor} + * + * @param width the object width. + * @param height the object height. + * @param widthRes the object width resolution. + * @param heightRes the object height resolution. + * @return a new {@link ObjectAreaDescriptor} + */ + public ObjectAreaDescriptor createObjectAreaDescriptor( + int width, int height, int widthRes, int heightRes) { + ObjectAreaDescriptor objectAreaDescriptor + = new ObjectAreaDescriptor(width, height, widthRes, heightRes); + return objectAreaDescriptor; + } + + /** + * Creates a new {@link ObjectAreaPosition} + * + * @param x the x coordinate. + * @param y the y coordinate. + * @param rotation the coordinate system rotation (must be 0, 90, 180, 270). + * @return a new {@link ObjectAreaPosition} + */ + public ObjectAreaPosition createObjectAreaPosition(int x, int y, + int rotation) { + ObjectAreaPosition objectAreaPosition = new ObjectAreaPosition( + x, y, rotation); + return objectAreaPosition; + } + + /** + * Creates a new {@link ImageDataDescriptor} + * + * @param width the image width + * @param height the image height + * @param widthRes the x resolution of the image + * @param heightRes the y resolution of the image + * @return a new {@link ImageDataDescriptor} + */ + public ImageDataDescriptor createImageDataDescriptor( + int width, int height, int widthRes, int heightRes) { + ImageDataDescriptor imageDataDescriptor = new ImageDataDescriptor( + width, height, widthRes, heightRes); + return imageDataDescriptor; + } + + /** + * Creates a new GOCA {@link GraphicsDataDescriptor} + * + * @param xlwind the left edge of the graphics window + * @param xrwind the right edge of the graphics window + * @param ybwind the top edge of the graphics window + * @param ytwind the bottom edge of the graphics window + * @param widthRes the x resolution of the graphics window + * @param heightRes the y resolution of the graphics window + * @return a new {@link GraphicsDataDescriptor} + */ + public GraphicsDataDescriptor createGraphicsDataDescriptor( + int xlwind, int xrwind, int ybwind, int ytwind, int widthRes, int heightRes) { + GraphicsDataDescriptor graphicsDataDescriptor = new GraphicsDataDescriptor( + xlwind, xrwind, ybwind, ytwind, widthRes, heightRes); + return graphicsDataDescriptor; + } + + /** + * Creates a new MO:DCA {@link ContainerDataDescriptor} + * + * @param dataWidth the container data width + * @param dataHeight the container data height + * @param widthRes the container data width resolution + * @param heightRes the container data height resolution + * @return a new {@link ContainerDataDescriptor} + */ + public ContainerDataDescriptor createContainerDataDescriptor( + int dataWidth, int dataHeight, int widthRes, int heightRes) { + ContainerDataDescriptor containerDataDescriptor + = new ContainerDataDescriptor(dataWidth, dataHeight, widthRes, heightRes); + return containerDataDescriptor; + } + + /** + * Creates a new MO:DCA {@link MapContainerData} + * + * @param optionValue the option value + * @return a new {@link MapContainerData} + */ + public MapContainerData createMapContainerData(byte optionValue) { + MapContainerData mapContainerData = new MapContainerData(optionValue); + return mapContainerData; + } + + /** + * Creates a new MO:DCA {@link MapDataResource} + * + * @return a new {@link MapDataResource} + */ + public MapDataResource createMapDataResource() { + MapDataResource mapDataResource = new MapDataResource(); + return mapDataResource; + } + + /** + * Creates a new PTOCA {@link PresentationTextDescriptor} + * + * @return a new {@link PresentationTextDescriptor} + */ + public PresentationTextDescriptor createPresentationTextDataDescriptor( + int width, int height, int widthRes, int heightRes) { + PresentationTextDescriptor presentationTextDescriptor + = new PresentationTextDescriptor(width, height, + widthRes, heightRes); + return presentationTextDescriptor; + } + + /** + * Creates a new MO:DCA {@link PresentationEnvironmentControl} + * + * @return a new {@link PresentationEnvironmentControl} + */ + public PresentationEnvironmentControl createPresentationEnvironmentControl() { + PresentationEnvironmentControl presentationEnvironmentControl + = new PresentationEnvironmentControl(); + return presentationEnvironmentControl; + } + + /** + * Creates a new MO:DCA {@link InvokeMediumMap} + * + * @param name the object name + * @return a new {@link InvokeMediumMap} + */ + public InvokeMediumMap createInvokeMediumMap(String name) { + InvokeMediumMap invokeMediumMap = new InvokeMediumMap(name); + return invokeMediumMap; + } + + /** + * Creates a new MO:DCA {@link ResourceEnvironmentGroup} + * + * @return a new {@link ResourceEnvironmentGroup} + */ + public ResourceEnvironmentGroup createResourceEnvironmentGroup() { + ResourceEnvironmentGroup resourceEnvironmentGroup = new ResourceEnvironmentGroup(); + return resourceEnvironmentGroup; + } + + /** + * Creates a new IOCA {@link ImageSegment} + * + * @return a new {@link ImageSegment} + */ + public ImageSegment createImageSegment() { + String name = IMAGE_SEGMENT_NAME_PREFIX + + StringUtils.lpad(String.valueOf(++imageSegmentCount), '0', 2); + ImageSegment imageSegment = new ImageSegment(this, name); + return imageSegment; + } + + /** + * Creates an new IOCA {@link ImageContent} + * + * @return an {@link ImageContent} + */ + public ImageContent createImageContent() { + ImageContent imageContent = new ImageContent(); + return imageContent; + } + + /** + * Creates a new IOCA {@link ImageRasterData} + * + * @param rasterData raster data + * @return a new {@link ImageRasterData} + */ + public ImageRasterData createImageRasterData(byte[] rasterData) { + ImageRasterData imageRasterData = new ImageRasterData(rasterData); + return imageRasterData; + } + + /** + * Creates an new IOCA {@link ImageSizeParameter}. + * + * @param hsize The horizontal size of the image. + * @param vsize The vertical size of the image. + * @param hresol The horizontal resolution of the image. + * @param vresol The vertical resolution of the image. + * @return a new {@link ImageSizeParameter} + */ + public ImageSizeParameter createImageSizeParameter(int hsize, int vsize, + int hresol, int vresol) { + ImageSizeParameter imageSizeParameter + = new ImageSizeParameter(hsize, vsize, hresol, vresol); + return imageSizeParameter; + } + +} diff --git a/src/java/org/apache/fop/afp/PaintInfo.java b/src/java/org/apache/fop/afp/PaintInfo.java new file mode 100644 index 000000000..2b11d0e3e --- /dev/null +++ b/src/java/org/apache/fop/afp/PaintInfo.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 PaintInfo { + +} diff --git a/src/java/org/apache/fop/afp/RectanglePaintInfo.java b/src/java/org/apache/fop/afp/RectanglePaintInfo.java new file mode 100644 index 000000000..f0fae0317 --- /dev/null +++ b/src/java/org/apache/fop/afp/RectanglePaintInfo.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 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/Streamable.java b/src/java/org/apache/fop/afp/Streamable.java new file mode 100644 index 000000000..cd731ab47 --- /dev/null +++ b/src/java/org/apache/fop/afp/Streamable.java @@ -0,0 +1,38 @@ +/* + * 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.io.IOException; +import java.io.OutputStream; + +/** + * Implementing object is able to write to an OutputStream + */ +public interface Streamable { + + /** + * DataStream objects must implement the writeToStream() + * method to write its data to the given OutputStream + * + * @param os the outputsteam stream + * @throws java.io.IOException an I/O exception of some sort has occurred. + */ + void writeToStream(OutputStream os) throws IOException; +} diff --git a/src/java/org/apache/fop/afp/fonts/AFPBase12FontCollection.java b/src/java/org/apache/fop/afp/fonts/AFPBase12FontCollection.java new file mode 100644 index 000000000..c39bf5e1e --- /dev/null +++ b/src/java/org/apache/fop/afp/fonts/AFPBase12FontCollection.java @@ -0,0 +1,157 @@ +/* + * 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.fonts; + +import org.apache.fop.fonts.Base14Font; +import org.apache.fop.fonts.Font; +import org.apache.fop.fonts.FontCollection; +import org.apache.fop.fonts.FontInfo; +import org.apache.fop.fonts.base14.Courier; +import org.apache.fop.fonts.base14.CourierBold; +import org.apache.fop.fonts.base14.CourierBoldOblique; +import org.apache.fop.fonts.base14.CourierOblique; +import org.apache.fop.fonts.base14.Helvetica; +import org.apache.fop.fonts.base14.HelveticaBold; +import org.apache.fop.fonts.base14.HelveticaOblique; +import org.apache.fop.fonts.base14.TimesBold; +import org.apache.fop.fonts.base14.TimesBoldItalic; +import org.apache.fop.fonts.base14.TimesItalic; +import org.apache.fop.fonts.base14.TimesRoman; + +/** + * Sets up a typical Base 12 font configuration for AFP + */ +public class AFPBase12FontCollection implements FontCollection { + + /** standard raster font sizes */ + private static final int[] RASTER_SIZES = {6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 24, 30, 36}; + + /** standard raster font charset references */ + private static final String[] CHARSET_REF = { + "60", "70", "80", "90", "00", "A0", "B0", "D0", "F0", "H0", "J0", "N0", "T0", "Z0"}; + + private void addCharacterSet(RasterFont font, String charsetName, Base14Font base14) { + for (int i = 0; i < RASTER_SIZES.length; i++) { + int size = RASTER_SIZES[i]; + FopCharacterSet characterSet = new FopCharacterSet( + CharacterSet.DEFAULT_CODEPAGE, CharacterSet.DEFAULT_ENCODING, + charsetName + CHARSET_REF[i], size, base14); + font.addCharacterSet(size, characterSet); + } + } + + private int addFontProperties(FontInfo fontInfo, AFPFont font, + String[] names, String style, int weight, int num) { + String internalFontKey = "F" + num; + fontInfo.addMetrics(internalFontKey, font); + fontInfo.addFontProperties(internalFontKey, names, style, weight); + num++; + return num; + } + + /** {@inheritDoc} */ + public int setup(int start, FontInfo fontInfo) { + + /** + * Add the base 12 fonts (Helvetica, Times and Courier) + * + * Note: this default font configuration may not be available + * on your AFP environment. + */ + int num = start; + RasterFont font = null; + + /** standard font family reference names for Helvetica font */ + final String[] helveticaNames = {"Helvetica", "Arial", "sans-serif"}; + font = new RasterFont("Helvetica"); + addCharacterSet(font, "C0H200", new Helvetica()); + num = addFontProperties(fontInfo, font, helveticaNames, + Font.STYLE_NORMAL, Font.WEIGHT_NORMAL, num); + + font = new RasterFont("Helvetica Italic"); + addCharacterSet(font, "C0H300", new HelveticaOblique()); + num = addFontProperties(fontInfo, font, helveticaNames, + Font.STYLE_ITALIC, Font.WEIGHT_NORMAL, num); + + font = new RasterFont("Helvetica (Semi) Bold"); + addCharacterSet(font, "C0H400", new HelveticaBold()); + num = addFontProperties(fontInfo, font, helveticaNames, + Font.STYLE_NORMAL, Font.WEIGHT_BOLD, num); + + font = new RasterFont("Helvetica Italic (Semi) Bold"); + addCharacterSet(font, "C0H500", new HelveticaOblique()); + num = addFontProperties(fontInfo, font, helveticaNames, + Font.STYLE_ITALIC, Font.WEIGHT_BOLD, num); + + + /** standard font family reference names for Times font */ + + /** any is treated as serif */ + final String[] timesNames = {"Times", "TimesRoman", "Times Roman", "Times-Roman", + "Times New Roman", "TimesNewRoman", "serif", "any"}; + + font = new RasterFont("Times Roman"); + addCharacterSet(font, "CON200", new TimesRoman()); + num = addFontProperties(fontInfo, font, timesNames, + Font.STYLE_NORMAL, Font.WEIGHT_NORMAL, num); + + font = new RasterFont("Times Roman Italic"); + addCharacterSet(font, "CON300", new TimesItalic()); + num = addFontProperties(fontInfo, font, timesNames, + Font.STYLE_ITALIC, Font.WEIGHT_NORMAL, num); + + font = new RasterFont("Times Roman Bold"); + addCharacterSet(font, "CON400", new TimesBold()); + num = addFontProperties(fontInfo, font, timesNames, + Font.STYLE_NORMAL, Font.WEIGHT_BOLD, num); + + font = new RasterFont("Times Roman Italic Bold"); + addCharacterSet(font, "CON500", new TimesBoldItalic()); + num = addFontProperties(fontInfo, font, timesNames, + Font.STYLE_ITALIC, Font.WEIGHT_BOLD, num); + + + /** standard font family reference names for Courier font */ + final String[] courierNames = {"Courier", "monospace"}; + + font = new RasterFont("Courier"); + addCharacterSet(font, "C04200", new Courier()); + num = addFontProperties(fontInfo, font, courierNames, + Font.STYLE_NORMAL, Font.WEIGHT_NORMAL, num); + + font = new RasterFont("Courier Italic"); + addCharacterSet(font, "C04300", new CourierOblique()); + num = addFontProperties(fontInfo, font, courierNames, + Font.STYLE_ITALIC, Font.WEIGHT_NORMAL, num); + + font = new RasterFont("Courier Bold"); + addCharacterSet(font, "C04400", new CourierBold()); + num = addFontProperties(fontInfo, font, courierNames, + Font.STYLE_NORMAL, Font.WEIGHT_BOLD, num); + + font = new RasterFont("Courier Italic Bold"); + addCharacterSet(font, "C04500", new CourierBoldOblique()); + num = addFontProperties(fontInfo, font, courierNames, + Font.STYLE_ITALIC, Font.WEIGHT_BOLD, num); + + return num; + } + +} diff --git a/src/java/org/apache/fop/afp/fonts/AFPFont.java b/src/java/org/apache/fop/afp/fonts/AFPFont.java new file mode 100644 index 000000000..dc8f9c315 --- /dev/null +++ b/src/java/org/apache/fop/afp/fonts/AFPFont.java @@ -0,0 +1,113 @@ +/* + * 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.fonts; + +import java.util.Map; +import java.util.Set; + +import org.apache.fop.fonts.FontType; +import org.apache.fop.fonts.Typeface; + + +/** + * All implementations of AFP fonts should extend this base class, + * the object implements the FontMetrics information. + *

+ */ +public abstract class AFPFont extends Typeface { + + /** The font name */ + protected String name; + + /** + * Constructor for the base font requires the name. + * @param name the name of the font + */ + public AFPFont(String name) { + this.name = name; + } + + /** {@inheritDoc} */ + public String getFontName() { + return this.name; + } + + /** {@inheritDoc} */ + public String getEmbedFontName() { + return this.name; + } + + /** {@inheritDoc} */ + public String getFullName() { + return getFontName(); + } + + /** {@inheritDoc} */ + public Set getFamilyNames() { + Set s = new java.util.HashSet(); + s.add(this.name); + return s; + } + + /** + * Returns the type of the font. + * @return the font type + */ + public FontType getFontType() { + return FontType.OTHER; + } + + /** + * Indicates if the font has kerning information. + * @return True, if kerning is available. + */ + public boolean hasKerningInfo() { + return false; + } + + /** + * Returns the kerning map for the font. + * @return the kerning map + */ + public Map getKerningInfo() { + return null; + } + + /** + * Returns the character set for a given size + * @param size the font size + * @return the character set object + */ + public abstract CharacterSet getCharacterSet(int size); + + /** + * Determines whether this font contains a particular character/glyph. + * @param c character to check + * @return True if the character is supported, False otherwise + */ + public boolean hasChar(char c) { + return true; + } + + /** {@inheritDoc} */ + public String toString() { + return "name=" + name; + } +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/fonts/AFPFontAttributes.java b/src/java/org/apache/fop/afp/fonts/AFPFontAttributes.java new file mode 100644 index 000000000..1dd22c66a --- /dev/null +++ b/src/java/org/apache/fop/afp/fonts/AFPFontAttributes.java @@ -0,0 +1,105 @@ +/* + * 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.fonts; + +/** + * This class encapsulates the font attributes that need to be included + * in the AFP data stream. This class does not assist in converting the + * font attributes to AFP code pages and character set values. + * + */ +public class AFPFontAttributes { + + /** + * The font reference + */ + private int fontReference; + + /** + * The font key + */ + private final String fontKey; + + /** + * The font + */ + private final AFPFont font; + + /** + * The point size + */ + private final int pointSize; + + /** + * Constructor for the AFPFontAttributes + * @param fontKey the font key + * @param font the font + * @param pointSize the point size + */ + public AFPFontAttributes(String fontKey, AFPFont font, int pointSize) { + this.fontKey = fontKey; + this.font = font; + this.pointSize = pointSize; + } + + /** + * @return the font + */ + public AFPFont getFont() { + return font; + } + + /** + * @return the FontKey attribute + */ + public String getFontKey() { + return fontKey + pointSize; + } + + /** + * @return the point size attribute + */ + public int getPointSize() { + return pointSize; + } + + /** + * @return the FontReference attribute + */ + public int getFontReference() { + return fontReference; + } + + /** + * Sets the FontReference attribute + * @param fontReference the FontReference to set + */ + public void setFontReference(int fontReference) { + this.fontReference = fontReference; + } + + /** {@inheritDoc} */ + public String toString() { + return "fontReference=" + fontReference + + ", fontKey=" + fontKey + + ", font=" + font + + ", pointSize=" + pointSize; + } +} diff --git a/src/java/org/apache/fop/afp/fonts/AFPFontCollection.java b/src/java/org/apache/fop/afp/fonts/AFPFontCollection.java new file mode 100644 index 000000000..f7216eb11 --- /dev/null +++ b/src/java/org/apache/fop/afp/fonts/AFPFontCollection.java @@ -0,0 +1,92 @@ +/* + * 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.fonts; + +import java.util.Iterator; +import java.util.List; + +import org.apache.fop.events.EventBroadcaster; +import org.apache.fop.fonts.Font; +import org.apache.fop.fonts.FontCollection; +import org.apache.fop.fonts.FontInfo; +import org.apache.fop.fonts.FontTriplet; +import org.apache.fop.render.afp.AFPEventProducer; + +/** + * A base collection of AFP fonts + */ +public class AFPFontCollection implements FontCollection { + + private final EventBroadcaster eventBroadcaster; + + private final List/**/ fontInfoList; + + /** + * Main constructor + * + * @param eventBroadcaster the event broadcaster + * @param fontInfoList the font info list + */ + public AFPFontCollection(EventBroadcaster eventBroadcaster, + List/**/ fontInfoList) { + this.eventBroadcaster = eventBroadcaster; + this.fontInfoList = fontInfoList; + } + + /** {@inheritDoc} */ + public int setup(int start, FontInfo fontInfo) { + int num = 1; + AFPEventProducer eventProducer = AFPEventProducer.Provider.get(eventBroadcaster); + if (fontInfoList != null && fontInfoList.size() > 0) { + for (Iterator it = fontInfoList.iterator(); it.hasNext();) { + AFPFontInfo afpFontInfo = (AFPFontInfo)it.next(); + AFPFont afpFont = afpFontInfo.getAFPFont(); + List/**/ tripletList = afpFontInfo.getFontTriplets(); + for (Iterator it2 = tripletList.iterator(); it2.hasNext();) { + FontTriplet triplet = (FontTriplet)it2.next(); + fontInfo.addFontProperties("F" + num, + triplet.getName(), triplet.getStyle(), triplet.getWeight()); + fontInfo.addMetrics("F" + num, afpFont); + num++; + } + } + if (fontInfo.fontLookup("any", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL) == null) { + eventProducer.warnMissingDefaultFont(this, Font.STYLE_NORMAL, Font.WEIGHT_NORMAL); + } + if (fontInfo.fontLookup("any", Font.STYLE_ITALIC, Font.WEIGHT_NORMAL) == null) { + eventProducer.warnMissingDefaultFont(this, Font.STYLE_ITALIC, Font.WEIGHT_NORMAL); + } + if (fontInfo.fontLookup("any", Font.STYLE_NORMAL, Font.WEIGHT_BOLD) == null) { + eventProducer.warnMissingDefaultFont(this, Font.STYLE_ITALIC, Font.WEIGHT_BOLD); + } + if (fontInfo.fontLookup("any", Font.STYLE_ITALIC, Font.WEIGHT_BOLD) == null) { + eventProducer.warnMissingDefaultFont(this, Font.STYLE_ITALIC, Font.WEIGHT_BOLD); + } + } else { + eventProducer.warnDefaultFontSetup(this); + + // Go with a default base 12 configuration for AFP environments + FontCollection base12FontCollection = new AFPBase12FontCollection(); + num = base12FontCollection.setup(num, fontInfo); + } + return num; + } + +} diff --git a/src/java/org/apache/fop/afp/fonts/AFPFontInfo.java b/src/java/org/apache/fop/afp/fonts/AFPFontInfo.java new file mode 100644 index 000000000..0259435c6 --- /dev/null +++ b/src/java/org/apache/fop/afp/fonts/AFPFontInfo.java @@ -0,0 +1,63 @@ +/* + * 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.fonts; + +import java.util.List; + + +/** + * FontInfo contains meta information on fonts + */ +public class AFPFontInfo { + + private AFPFont font; + private List/**/ tripletList; + + /** + * Main constructor + * + * @param afpFont The AFP Font + * @param tripletList List of font triplets to associate with this font + */ + public AFPFontInfo(AFPFont afpFont, List/**/ tripletList) { + this.font = afpFont; + this.tripletList = tripletList; + } + + /** + * Returns the afp font + * + * @return the afp font + */ + public AFPFont getAFPFont() { + return font; + } + + /** + * Returns the list of font triplets associated with this font. + * + * @return List of font triplets + */ + public List/**/ getFontTriplets() { + return tripletList; + } + +} + diff --git a/src/java/org/apache/fop/afp/fonts/AFPFontReader.java b/src/java/org/apache/fop/afp/fonts/AFPFontReader.java new file mode 100644 index 000000000..16c341ac4 --- /dev/null +++ b/src/java/org/apache/fop/afp/fonts/AFPFontReader.java @@ -0,0 +1,592 @@ +/* + * 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.fonts; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FilenameFilter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.fop.afp.AFPConstants; +import org.apache.fop.afp.util.StructuredFieldReader; + +/** + * The AFPFontReader is responsible for reading the font attributes from binary + * code page files and the character set metric files. In IBM font structure, a + * code page maps each character of text to the characters in a character set. + * Each character is translated into a code point. When the character is + * printed, each code point is matched to a character ID on the code page + * specified. The character ID is then matched to the image (raster pattern or + * outline pattern) of the character in the character set specified. The image + * in the character set is the image that is printed in the document. To be a + * valid code page for a particular character set, all character IDs in the code + * page must be included in that character set.

This class will read the + * font information from the binary code page files and character set metric + * files in order to determine the correct metrics to use when rendering the + * formatted object.

+ * + * @author Pete Townsend + */ +public final class AFPFontReader { + + /** + * Static logging instance + */ + protected static final Log log = LogFactory.getLog("org.apache.xmlgraphics.afp.fonts"); + + /** + * Template used to convert lists to arrays. + */ + private static final CharacterSetOrientation[] EMPTY_CSO_ARRAY = new CharacterSetOrientation[0]; + + /** Codepage MO:DCA structured field. */ + private static final byte[] CODEPAGE_SF = new byte[] { + (byte) 0xD3, (byte) 0xA8, (byte) 0x87}; + + /** Character table MO:DCA structured field. */ + private static final byte[] CHARACTER_TABLE_SF = new byte[] { + (byte) 0xD3, (byte) 0x8C, (byte) 0x87}; + + /** Font control MO:DCA structured field. */ + private static final byte[] FONT_CONTROL_SF = new byte[] { + (byte) 0xD3, (byte) 0xA7, (byte) 0x89 }; + + /** Font orientation MO:DCA structured field. */ + private static final byte[] FONT_ORIENTATION_SF = new byte[] { + (byte) 0xD3, (byte) 0xAE, (byte) 0x89 }; + + /** Font position MO:DCA structured field. */ + private static final byte[] FONT_POSITION_SF = new byte[] { + (byte) 0xD3, (byte) 0xAC, (byte) 0x89 }; + + /** Font index MO:DCA structured field. */ + private static final byte[] FONT_INDEX_SF = new byte[] { + (byte) 0xD3, (byte) 0x8C, (byte) 0x89 }; + + /** + * The conversion factor to millipoints for 240 dpi + */ + private static final int FOP_100_DPI_FACTOR = 1; + + /** + * The conversion factor to millipoints for 240 dpi + */ + private static final int FOP_240_DPI_FACTOR = 300000; + + /** + * The conversion factor to millipoints for 300 dpi + */ + private static final int FOP_300_DPI_FACTOR = 240000; + + /** + * The encoding to use to convert from EBCIDIC to ASCII + */ + private static final String ASCII_ENCODING = "UTF8"; + + /** + * The collection of code pages + */ + private final Map/*>*/ codePages + = new java.util.HashMap/*>*/(); + + /** + * Returns an InputStream to a given file path and filename + * + * @param path the file path + * @param filename the file name + * @return an inputStream + * + * @throws IOException in the event that an I/O exception of some sort has occurred + */ + private InputStream openInputStream(String path, String filename) throws IOException { + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + if (classLoader == null) { + classLoader = AFPFontReader.class.getClassLoader(); + } + + URL url = classLoader.getResource(path); + + if (url == null) { + try { + File file = new File(path); + url = file.toURI().toURL(); + if (url == null) { + String msg = "file not found " + filename + " in classpath: " + path; + log.error(msg); + throw new FileNotFoundException(msg); + } + } catch (MalformedURLException ex) { + String msg = "file not found " + filename + " in classpath: " + path; + log.error(msg); + throw new FileNotFoundException(msg); + } + } + + File directory = new File(url.getPath()); + if (!directory.canRead()) { + String msg = "Failed to read directory " + url.getPath(); + log.error(msg); + throw new FileNotFoundException(msg); + } + + final String filterpattern = filename.trim(); + FilenameFilter filter = new FilenameFilter() { + public boolean accept(File dir, String name) { + return name.startsWith(filterpattern); + } + }; + + File[] files = directory.listFiles(filter); + + if (files.length < 1) { + String msg = "file search for " + filename + " located " + + files.length + " files"; + log.error(msg); + throw new FileNotFoundException(msg); + } else if (files.length > 1) { + String msg = "file search for " + filename + " located " + + files.length + " files"; + log.warn(msg); + } + + InputStream inputStream = files[0].toURI().toURL().openStream(); + + if (inputStream == null) { + String msg = "AFPFontReader:: getInputStream():: file not found for " + filename; + log.error(msg); + throw new FileNotFoundException(msg); + } + + return inputStream; + } + + /** + * Closes the inputstream + * + * @param inputStream the inputstream to close + */ + private void closeInputStream(InputStream inputStream) { + try { + if (inputStream != null) { + inputStream.close(); + } + } catch (Exception ex) { + // Lets log at least! + log.error(ex.getMessage()); + } + } + + /** + * Load the font details and metrics into the CharacterSetMetric object, + * this will use the actual afp code page and character set files to load + * the object with the necessary metrics. + * + * @param characterSet the CharacterSetMetric object to populate + * @throws IOException if an I/O exception of some sort has occurred. + */ + public void loadCharacterSetMetric(CharacterSet characterSet) throws IOException { + + InputStream inputStream = null; + + try { + + /** + * Get the code page which contains the character mapping + * information to map the unicode character id to the graphic + * chracter global identifier. + */ + String codePageId = new String(characterSet.getCodePage()); + String path = characterSet.getPath(); + + Map/**/ codePage = (Map/**/)codePages.get(codePageId); + + if (codePage == null) { + codePage = loadCodePage(codePageId, characterSet.getEncoding(), path); + codePages.put(codePageId, codePage); + } + + /** + * Load the character set metric information, no need to cache this + * information as it should be cached by the objects that wish to + * load character set metric information. + */ + final String characterSetName = characterSet.getName(); + + inputStream = openInputStream(path, characterSetName); + + StructuredFieldReader structuredFieldReader = new StructuredFieldReader(inputStream); + + // Process D3A789 Font Control + FontControl fontControl = processFontControl(structuredFieldReader); + + if (fontControl != null) { + //process D3AE89 Font Orientation + CharacterSetOrientation[] characterSetOrientations + = processFontOrientation(structuredFieldReader); + + int dpi = fontControl.getDpi(); + + //process D3AC89 Font Position + processFontPosition(structuredFieldReader, characterSetOrientations, dpi); + + //process D38C89 Font Index (per orientation) + for (int i = 0; i < characterSetOrientations.length; i++) { + processFontIndex(structuredFieldReader, + characterSetOrientations[i], codePage, dpi); + characterSet.addCharacterSetOrientation(characterSetOrientations[i]); + } + } else { + throw new IOException( + "Failed to read font control structured field in character set " + + characterSetName); + } + + } finally { + closeInputStream(inputStream); + } + + } + + /** + * Load the code page information from the appropriate file. The file name + * to load is determined by the code page name and the file extension 'CDP'. + * + * @param codePage + * the code page identifier + * @param encoding + * the encoding to use for the character decoding + * @returns a code page mapping + */ + private Map/**/ loadCodePage(String codePage, String encoding, + String path) throws IOException { + + // Create the HashMap to store code page information + Map/**/ codePages = new java.util.HashMap/**/(); + + InputStream inputStream = null; + try { + inputStream = openInputStream(path, codePage.trim()); + + StructuredFieldReader structuredFieldReader = new StructuredFieldReader(inputStream); + byte[] data = structuredFieldReader.getNext(CHARACTER_TABLE_SF); + + int position = 0; + byte[] gcgiBytes = new byte[8]; + byte[] charBytes = new byte[1]; + + // Read data, ignoring bytes 0 - 2 + for (int index = 3; index < data.length; index++) { + if (position < 8) { + // Build the graphic character global identifier key + gcgiBytes[position] = data[index]; + position++; + } else if (position == 9) { + position = 0; + // Set the character + charBytes[0] = data[index]; + String gcgiString = new String(gcgiBytes, + AFPConstants.EBCIDIC_ENCODING); + String charString = new String(charBytes, encoding); +// int value = charString.charAt(0); + codePages.put(gcgiString, charString); + } else { + position++; + } + } + } finally { + closeInputStream(inputStream); + } + + return codePages; + } + + /** + * Process the font control details using the structured field reader. + * + * @param structuredFieldReader + * the structured field reader + */ + private FontControl processFontControl(StructuredFieldReader structuredFieldReader) + throws IOException { + + byte[] fncData = structuredFieldReader.getNext(FONT_CONTROL_SF); + +// int position = 0; + FontControl fontControl = null; + if (fncData != null) { + fontControl = new FontControl(); + + if (fncData[7] == (byte) 0x02) { + fontControl.setRelative(true); + } + + int dpi = (((fncData[9] & 0xFF) << 8) + (fncData[10] & 0xFF)) / 10; + + fontControl.setDpi(dpi); + } + return fontControl; + } + + /** + * Process the font orientation details from using the structured field + * reader. + * + * @param structuredFieldReader + * the structured field reader + */ + private CharacterSetOrientation[] processFontOrientation( + StructuredFieldReader structuredFieldReader) throws IOException { + + byte[] data = structuredFieldReader.getNext(FONT_ORIENTATION_SF); + + int position = 0; + byte[] fnoData = new byte[26]; + + List orientations = new java.util.ArrayList(); + + // Read data, ignoring bytes 0 - 2 + for (int index = 3; index < data.length; index++) { + // Build the font orientation record + fnoData[position] = data[index]; + position++; + + if (position == 26) { + + position = 0; + + int orientation = 0; + + switch (fnoData[2]) { + case 0x00: + orientation = 0; + break; + case 0x2D: + orientation = 90; + break; + case 0x5A: + orientation = 180; + break; + case (byte) 0x87: + orientation = 270; + break; + default: + System.out.println("ERROR: Oriantation"); + } + + CharacterSetOrientation cso = new CharacterSetOrientation( + orientation); + orientations.add(cso); + + } + } + + return (CharacterSetOrientation[]) orientations + .toArray(EMPTY_CSO_ARRAY); + } + + /** + * Populate the CharacterSetOrientation object in the suplied array with the + * font position details using the supplied structured field reader. + * + * @param structuredFieldReader + * the structured field reader + * @param characterSetOrientations + * the array of CharacterSetOrientation objects + */ + private void processFontPosition(StructuredFieldReader structuredFieldReader, + CharacterSetOrientation[] characterSetOrientations, int dpi) throws IOException { + + byte[] data = structuredFieldReader.getNext(FONT_POSITION_SF); + + int position = 0; + byte[] fpData = new byte[26]; + + int characterSetOrientationIndex = 0; + int fopFactor = 0; + + switch (dpi) { + case 100: + fopFactor = FOP_100_DPI_FACTOR; + break; + case 240: + fopFactor = FOP_240_DPI_FACTOR; + break; + case 300: + fopFactor = FOP_300_DPI_FACTOR; + break; + default: + String msg = "Unsupported font resolution of " + dpi + " dpi."; + log.error(msg); + throw new IOException(msg); + } + + // Read data, ignoring bytes 0 - 2 + for (int index = 3; index < data.length; index++) { + if (position < 22) { + // Build the font orientation record + fpData[position] = data[index]; + } else if (position == 22) { + + position = 0; + + CharacterSetOrientation characterSetOrientation + = characterSetOrientations[characterSetOrientationIndex]; + + int xHeight = ((fpData[2] & 0xFF) << 8) + (fpData[3] & 0xFF); + int capHeight = ((fpData[4] & 0xFF) << 8) + (fpData[5] & 0xFF); + int ascHeight = ((fpData[6] & 0xFF) << 8) + (fpData[7] & 0xFF); + int dscHeight = ((fpData[8] & 0xFF) << 8) + (fpData[9] & 0xFF); + + dscHeight = dscHeight * -1; + + characterSetOrientation.setXHeight(xHeight * fopFactor); + characterSetOrientation.setCapHeight(capHeight * fopFactor); + characterSetOrientation.setAscender(ascHeight * fopFactor); + characterSetOrientation.setDescender(dscHeight * fopFactor); + + characterSetOrientationIndex++; + + fpData[position] = data[index]; + + } + + position++; + } + + } + + /** + * Process the font index details for the character set orientation. + * + * @param structuredFieldReader + * the structured field reader + * @param cso + * the CharacterSetOrientation object to populate + * @param codepage + * the map of code pages + */ + private void processFontIndex(StructuredFieldReader structuredFieldReader, + CharacterSetOrientation cso, Map/**/ codepage, int dpi) + throws IOException { + + byte[] data = structuredFieldReader.getNext(FONT_INDEX_SF); + + int fopFactor = 0; + + switch (dpi) { + case 100: + fopFactor = FOP_100_DPI_FACTOR; + break; + case 240: + fopFactor = FOP_240_DPI_FACTOR; + break; + case 300: + fopFactor = FOP_300_DPI_FACTOR; + break; + default: + String msg = "Unsupported font resolution of " + dpi + " dpi."; + log.error(msg); + throw new IOException(msg); + } + + int position = 0; + + byte[] gcgid = new byte[8]; + byte[] fiData = new byte[20]; + + int lowest = 255; + int highest = 0; + + // Read data, ignoring bytes 0 - 2 + for (int index = 3; index < data.length; index++) { + if (position < 8) { + gcgid[position] = data[index]; + position++; + } else if (position < 27) { + fiData[position - 8] = data[index]; + position++; + } else if (position == 27) { + + fiData[position - 8] = data[index]; + + position = 0; + + String gcgiString = new String(gcgid, AFPConstants.EBCIDIC_ENCODING); + + String idx = (String) codepage.get(gcgiString); + + if (idx != null) { + + int cidx = idx.charAt(0); + int width = ((fiData[0] & 0xFF) << 8) + (fiData[1] & 0xFF); + + if (cidx < lowest) { + lowest = cidx; + } + + if (cidx > highest) { + highest = cidx; + } + + int a = (width * fopFactor); + + cso.setWidth(cidx, a); + + } + + } + } + + cso.setFirstChar(lowest); + cso.setLastChar(highest); + + } + + private class FontControl { + + private int dpi; + + private boolean isRelative = false; + + public int getDpi() { + return dpi; + } + + public void setDpi(int i) { + dpi = i; + } + + public boolean isRelative() { + return isRelative; + } + + public void setRelative(boolean b) { + isRelative = b; + } + } + +} diff --git a/src/java/org/apache/fop/afp/fonts/CharacterSet.java b/src/java/org/apache/fop/afp/fonts/CharacterSet.java new file mode 100644 index 000000000..31b53bf08 --- /dev/null +++ b/src/java/org/apache/fop/afp/fonts/CharacterSet.java @@ -0,0 +1,318 @@ +/* + * 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.fonts; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.fop.afp.AFPConstants; +import org.apache.fop.afp.util.StringUtils; + +/** + * The IBM Font Object Content Architecture (FOCA) supports presentation + * of character shapes by defining their characteristics, which include + * font description information for identifying the characters, font metric + * information for positioning the characters, and character shape information + * for presenting the character images. + *

+ * Presenting a graphic character on a presentation surface requires + * information on the rotation and position of character on the physical + * or logical page. + *

+ * This class proivdes font metric information for a particular font + * as identified by the character set name. This information is obtained + * directly from the AFP font files which must be installed in the path + * specified in the afp-fonts xml definition file. + *

+ */ +public class CharacterSet { + + /** Static logging instance */ + protected static final Log log = LogFactory.getLog(CharacterSet.class.getName()); + + /** default codepage */ + public static final String DEFAULT_CODEPAGE = "T1V10500"; + + /** default encoding */ + public static final String DEFAULT_ENCODING = "Cp500"; + + private static final int MAX_NAME_LEN = 8; + + + /** The code page to which the character set relates */ + protected String codePage; + + /** The encoding used for the code page */ + protected String encoding; + + /** The character set relating to the font */ + protected String name; + + /** The path to the installed fonts */ + protected String path; + + /** Indicator as to whether to metrics have been loaded */ + private boolean isMetricsLoaded = false; + + /** The current orientation (currently only 0 is supported by FOP) */ + private final String currentOrientation = "0"; + + /** The collection of objects for each orientation */ + private Map characterSetOrientations = null; + + /** + * Constructor for the CharacterSetMetric object, the character set is used + * to load the font information from the actual AFP font. + * + * @param codePage the code page identifier + * @param encoding the encoding of the font + * @param name the character set name + * @param path the path to the installed afp fonts + */ + public CharacterSet(String codePage, String encoding, String name, String path) { + if (name.length() > MAX_NAME_LEN) { + String msg = "Character set name '" + name + "' must be a maximum of " + + MAX_NAME_LEN + " characters"; + log.error("Constructor:: " + msg); + throw new IllegalArgumentException(msg); + } + + if (name.length() < MAX_NAME_LEN) { + this.name = StringUtils.rpad(name, ' ', MAX_NAME_LEN); + } else { + this.name = name; + } + this.codePage = codePage; + this.encoding = encoding; + this.path = path; + + this.characterSetOrientations = new java.util.HashMap(4); + } + + /** + * Add character set metric information for the different orientations + * + * @param cso the metrics for the orientation + */ + public void addCharacterSetOrientation(CharacterSetOrientation cso) { + characterSetOrientations.put( + String.valueOf(cso.getOrientation()), + cso); + } + + /** + * Ascender height is the distance from the character baseline to the + * top of the character box. A negative ascender height signifies that + * all of the graphic character is below the character baseline. For + * a character rotation other than 0, ascender height loses its + * meaning when the character is lying on its side or is upside down + * with respect to normal viewing orientation. For the general case, + * Ascender Height is the characters most positive y-axis value. + * For bounded character boxes, for a given character having an + * ascender, ascender height and baseline offset are equal. + * + * @return the ascender value in millipoints + */ + public int getAscender() { + load(); + return getCharacterSetOrientation().getAscender(); + } + + /** + * Cap height is the average height of the uppercase characters in + * a font. This value is specified by the designer of a font and is + * usually the height of the uppercase M. + * + * @return the cap height value in millipoints + */ + public int getCapHeight() { + load(); + return getCharacterSetOrientation().getCapHeight(); + } + + /** + * Descender depth is the distance from the character baseline to + * the bottom of a character box. A negative descender depth signifies + * that all of the graphic character is above the character baseline. + * + * @return the descender value in millipoints + */ + public int getDescender() { + load(); + return getCharacterSetOrientation().getDescender(); + } + + /** + * Returns the first character in the character set + * + * @return the first character in the character set + */ + public int getFirstChar() { + load(); + return getCharacterSetOrientation().getFirstChar(); + } + + /** + * Returns the last character in the character set + * + * @return the last character in the character set + */ + public int getLastChar() { + load(); + return getCharacterSetOrientation().getLastChar(); + } + + /** + * Returns the path where the font resources are installed + * + * @return the path where the font resources are installed + */ + public String getPath() { + return path; + } + + /** + * Get the width (in 1/1000ths of a point size) of all characters + * + * @return the widths of all characters + */ + public int[] getWidths() { + load(); + return getCharacterSetOrientation().getWidths(); + } + + /** + * XHeight refers to the height of the lower case letters above the baseline. + * + * @return the typical height of characters + */ + public int getXHeight() { + load(); + return getCharacterSetOrientation().getXHeight(); + } + + /** + * Get the width (in 1/1000ths of a point size) of the character + * identified by the parameter passed. + * + * @param character the character from which the width will be calculated + * @return the width of the character + */ + public int getWidth(int character) { + load(); + return getCharacterSetOrientation().getWidth(character); + } + + /** + * Lazy creation of the character metrics, the afp font file will only + * be processed on a method call requiring the metric information. + */ + private void load() { + if (!isMetricsLoaded) { + AFPFontReader afpFontReader = new AFPFontReader(); + try { + afpFontReader.loadCharacterSetMetric(this); + isMetricsLoaded = true; + } catch (IOException e) { + String msg = "Failed to load the character set metrics for code page " + codePage; + log.error(msg); + throw new RuntimeException(e.getMessage()); + } + } + } + + /** + * Returns the AFP character set identifier + * + * @return the AFP character set identifier + */ + public String getName() { + return name; + } + + /** + * Returns the AFP character set identifier as a byte array + * + * @return the AFP character set identifier as a byte array + */ + public byte[] getNameBytes() { + byte[] nameBytes = null; + try { + nameBytes = name.getBytes(AFPConstants.EBCIDIC_ENCODING); + } catch (UnsupportedEncodingException usee) { + nameBytes = name.getBytes(); + log.warn( + "UnsupportedEncodingException translating the name " + name); + } + return nameBytes; + } + + /** + * Returns the AFP code page identifier + * + * @return the AFP code page identifier + */ + public String getCodePage() { + return codePage; + } + + /** + * Returns the AFP code page encoding + * + * @return the AFP code page encoding + */ + public String getEncoding() { + return encoding; + } + + /** + * Helper method to return the current CharacterSetOrientation, note + * that FOP does not yet implement the "reference-orientation" + * attribute therefore we always use the orientation zero degrees, + * Other orientation information is captured for use by a future + * implementation (whenever FOP implement the mechanism). This is also + * the case for landscape prints which use an orientation of 270 degrees, + * in 99.9% of cases the font metrics will be the same as the 0 degrees + * therefore the implementation currently will always use 0 degrees. + * + * @return characterSetOrentation The current orientation metrics. + */ + private CharacterSetOrientation getCharacterSetOrientation() { + CharacterSetOrientation c + = (CharacterSetOrientation) characterSetOrientations.get(currentOrientation); + return c; + } + + /** + * Map a Unicode character to a code point in the font. + * The code tables are already converted to Unicode therefore + * we can use the identity mapping. + * + * @param c character to map + * @return the mapped character + */ + public char mapChar(char c) { + return c; + } + +} diff --git a/src/java/org/apache/fop/afp/fonts/CharacterSetOrientation.java b/src/java/org/apache/fop/afp/fonts/CharacterSetOrientation.java new file mode 100644 index 000000000..88e99eccf --- /dev/null +++ b/src/java/org/apache/fop/afp/fonts/CharacterSetOrientation.java @@ -0,0 +1,275 @@ +/* + * 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.fonts; + +/** + * The IBM Font Object Content Architecture (FOCA) supports presentation + * of character shapes by defining their characteristics, which include + * Font-Description information for identifying the characters, Font-Metric + * information for positioning the characters, and Character-Shape + * information for presenting the character images. + * + * Presenting a graphic character on a presentation surface requires + * that you communicate this information clearly to rotate and position + * characters correctly on the physical or logical page. + * + * This class provides font metric information for a particular font + * as by the orientation. + * + * This information is obtained directly from the AFP font files which must + * be installed in the classpath under in the location specified by the path + * attribute in the afp-font.xml file. + *

+ */ +public class CharacterSetOrientation { + + /** + * The code page to which the character set relates + */ + private String codePage; + + /** + * The encoding used for the code page + */ + private String encoding; + + /** + * The ascender height for the character set + */ + private int ascender; + + /** + * The descender depth for the character set + */ + private int descender; + + /** + * The height of capital letters + */ + private int capHeight; + + /** + * The characters in the charcater set + */ + private int[] chars = new int[256]; + + /** + * The height of lowercase letters + */ + private int xHeight; + + /** + * The first character + */ + private int firstChar; + + /** + * The last character + */ + private int lastChar; + + + /** + * The character set orientation + */ + private int orientation = 0; + + /** + * Constructor for the CharacterSetOrientation, the orientation is + * expressed as the degrees rotation (i.e 0, 90, 180, 270) + * @param orientation the character set orientation + */ + public CharacterSetOrientation(int orientation) { + this.orientation = orientation; + } + + /** + * Ascender height is the distance from the character baseline to the + * top of the character box. A negative ascender height signifies that + * all of the graphic character is below the character baseline. For + * a character rotation other than 0, ascender height loses its + * meaning when the character is lying on its side or is upside down + * with respect to normal viewing orientation. For the general case, + * Ascender Height is the character�s most positive y-axis value. + * For bounded character boxes, for a given character having an + * ascender, ascender height and baseline offset are equal. + * @return the ascender value in millipoints + */ + public int getAscender() { + return ascender; + } + + /** + * Cap height is the average height of the uppercase characters in + * a font. This value is specified by the designer of a font and is + * usually the height of the uppercase M. + * @return the cap height value in millipoints + */ + public int getCapHeight() { + return capHeight; + } + + /** + * Descender depth is the distance from the character baseline to + * the bottom of a character box. A negative descender depth signifies + * that all of the graphic character is above the character baseline. + * @return the descender value in millipoints + */ + public int getDescender() { + return descender; + } + + /** + * The first character in the character set + * @return the first character + */ + public int getFirstChar() { + return firstChar; + } + + /** + * The last character in the character set + * @return the last character + */ + public int getLastChar() { + return lastChar; + } + + /** + * The orientation for these metrics in the character set + * @return the orientation + */ + public int getOrientation() { + return orientation; + } + + /** + * Get the width (in 1/1000ths of a point size) of all characters + * in this character set. + * @return the widths of all characters + */ + public int[] getWidths() { + int arr[] = new int[(getLastChar() - getFirstChar()) + 1]; + System.arraycopy(chars, getFirstChar(), arr, 0, (getLastChar() - getFirstChar()) + 1); + return arr; + } + + /** + * XHeight refers to the height of the lower case letters above + * the baseline. + * @return heightX the typical height of characters + */ + public int getXHeight() { + return xHeight; + } + + /** + * Get the width (in 1/1000ths of a point size) of the character + * identified by the parameter passed. + * @param characterIndex the character to evaluate + * @return the widths of the character + */ + public int getWidth(int characterIndex) { + if (characterIndex >= chars.length) { + throw new IllegalArgumentException("Invalid character index: " + + characterIndex + ", maximum is " + (chars.length - 1)); + } + return chars[characterIndex]; + } + + /** + * Ascender height is the distance from the character baseline to the + * top of the character box. A negative ascender height signifies that + * all of the graphic character is below the character baseline. For + * a character rotation other than 0, ascender height loses its + * meaning when the character is lying on its side or is upside down + * with respect to normal viewing orientation. For the general case, + * Ascender Height is the character�s most positive y-axis value. + * For bounded character boxes, for a given character having an + * ascender, ascender height and baseline offset are equal. + * @param ascender the ascender to set + */ + public void setAscender(int ascender) { + this.ascender = ascender; + } + + /** + * Cap height is the average height of the uppercase characters in + * a font. This value is specified by the designer of a font and is + * usually the height of the uppercase M. + * @param capHeight the cap height to set + */ + public void setCapHeight(int capHeight) { + this.capHeight = capHeight; + } + + /** + * Descender depth is the distance from the character baseline to + * the bottom of a character box. A negative descender depth signifies + * that all of the graphic character is above the character baseline. + * @param descender the descender value in millipoints + */ + public void setDescender(int descender) { + this.descender = descender; + } + + /** + * The first character in the character set + * @param firstChar the first character + */ + public void setFirstChar(int firstChar) { + this.firstChar = firstChar; + } + + /** + * The last character in the character set + * @param lastChar the last character + */ + public void setLastChar(int lastChar) { + this.lastChar = lastChar; + } + + /** + * Set the width (in 1/1000ths of a point size) of the character + * identified by the parameter passed. + * @param character the character for which the width is being set + * @param width the widths of the character + */ + public void setWidth(int character, int width) { + + if (character >= chars.length) { + // Increase the size of the array if necessary + int arr[] = new int[(character - firstChar) + 1]; + System.arraycopy(chars, 0, arr, 0, chars.length); + chars = arr; + } + chars[character] = width; + + } + + /** + * XHeight refers to the height of the lower case letters above + * the baseline. + * @param xHeight the typical height of characters + */ + public void setXHeight(int xHeight) { + this.xHeight = xHeight; + } +} diff --git a/src/java/org/apache/fop/afp/fonts/FontRuntimeException.java b/src/java/org/apache/fop/afp/fonts/FontRuntimeException.java new file mode 100644 index 000000000..86e41707f --- /dev/null +++ b/src/java/org/apache/fop/afp/fonts/FontRuntimeException.java @@ -0,0 +1,48 @@ +/* + * 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.fonts; + +/** + * A runtime exception for handling fatal errors in processing fonts. + *

+ */ +public class FontRuntimeException extends RuntimeException { + + private static final long serialVersionUID = -2217420523816384707L; + + /** + * Constructs a FontRuntimeException with the specified message. + * @param msg the exception mesaage + */ + public FontRuntimeException(String msg) { + super(msg); + } + + /** + * Constructs a FontRuntimeException with the specified message + * wrapping the underlying exception. + * @param msg the exception mesaage + * @param t the underlying exception + */ + public FontRuntimeException(String msg, Throwable t) { + super(msg, t); + } + +} diff --git a/src/java/org/apache/fop/afp/fonts/FopCharacterSet.java b/src/java/org/apache/fop/afp/fonts/FopCharacterSet.java new file mode 100644 index 000000000..49e536eab --- /dev/null +++ b/src/java/org/apache/fop/afp/fonts/FopCharacterSet.java @@ -0,0 +1,141 @@ +/* + * 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.fonts; + +import org.apache.fop.fonts.Typeface; + +/** + * A Character set for a normal FOP font

+ */ +public class FopCharacterSet extends CharacterSet { + + /** The character set for this font */ + private Typeface charSet = null; + private int size = 0; + + /** + * Constructor for the CharacterSetMetric object, the character set is used + * to load the font information from the actual AFP font. + * @param codePage the code page identifier + * @param encoding the encoding of the font + * @param name the character set name + * @param size the font size + * @param charSet the fop character set + */ + public FopCharacterSet( + String codePage, + String encoding, + String name, + int size, + Typeface charSet) { + + super(codePage, encoding, name, null); + this.charSet = charSet; + this.size = size * 1000; + } + + /** + * Ascender height is the distance from the character baseline to the + * top of the character box. A negative ascender height signifies that + * all of the graphic character is below the character baseline. For + * a character rotation other than 0, ascender height loses its + * meaning when the character is lying on its side or is upside down + * with respect to normal viewing orientation. For the general case, + * Ascender Height is the character�s most positive y-axis value. + * For bounded character boxes, for a given character having an + * ascender, ascender height and baseline offset are equal. + * @return the ascender value in millipoints + */ + public int getAscender() { + return charSet.getAscender(size); + } + + /** + * Cap height is the average height of the uppercase characters in + * a font. This value is specified by the designer of a font and is + * usually the height of the uppercase M. + * @return the cap height value in millipoints + */ + public int getCapHeight() { + return charSet.getCapHeight(size); + } + + /** + * Descender depth is the distance from the character baseline to + * the bottom of a character box. A negative descender depth signifies + * that all of the graphic character is above the character baseline. + * @return the descender value in millipoints + */ + public int getDescender() { + return charSet.getDescender(size); + } + + /** + * The first character in the character set + * @return the first character + */ + public int getFirstChar() { + return 0; + } + + /** + * The last character in the character set + * @return the last character + */ + public int getLastChar() { + return 0; + } + + /** + * Get the width (in 1/1000ths of a point size) of all characters + * @return the widths of all characters + */ + public int[] getWidths() { + return charSet.getWidths(); + } + + /** + * XHeight refers to the height of the lower case letters above the baseline. + * @return the typical height of characters + */ + public int getXHeight() { + return charSet.getXHeight(size); + } + + /** + * Get the width (in 1/1000ths of a point size) of the character + * identified by the parameter passed. + * @param character the character from which the width will be calculated + * @return the width of the character + */ + public int getWidth(int character) { + return charSet.getWidth(character, size); + } + + /** + * Map a Unicode character to a code point in the font. + * @param c character to map + * @return the mapped character + */ + public char mapChar(char c) { + return charSet.mapChar(c); + } + +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/fonts/OutlineFont.java b/src/java/org/apache/fop/afp/fonts/OutlineFont.java new file mode 100644 index 000000000..28f2df6c4 --- /dev/null +++ b/src/java/org/apache/fop/afp/fonts/OutlineFont.java @@ -0,0 +1,182 @@ +/* + * 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.fonts; + + +/** + * A font defined as a set of lines and curves as opposed to a bitmap font. An + * outline font can be scaled to any size and otherwise transformed more easily + * than a bitmap font, and with more attractive results.

+ * + */ +public class OutlineFont extends AFPFont { + + /** The character set for this font */ + private CharacterSet charSet = null; + + /** + * Constructor for an outline font. + * + * @param name + * the name of the font + * @param charSet + * the chracter set + */ + public OutlineFont(String name, CharacterSet charSet) { + super(name); + this.charSet = charSet; + } + + /** + * Get the character set metrics. + * + * @return the character set + */ + public CharacterSet getCharacterSet() { + + return charSet; + + } + + /** + * Get the character set metrics. + * @param size ignored + * @return the character set + */ + public CharacterSet getCharacterSet(int size) { + + return charSet; + + } + + /** + * Get the first character in this font. + * @return the first character in this font + */ + public int getFirstChar() { + return charSet.getFirstChar(); + } + + /** + * Get the last character in this font. + * @return the last character in this font + */ + public int getLastChar() { + return charSet.getLastChar(); + } + + /** + * The ascender is the part of a lowercase letter that extends above the + * "x-height" (the height of the letter "x"), such as "d", "t", or "h". Also + * used to denote the part of the letter extending above the x-height. + * + * @param size + * the point size + * @return the ascender for the given size + */ + public int getAscender(int size) { + return charSet.getAscender() / 1000 * size; + } + + /** + * Obtains the height of capital letters for the specified point size. + * + * @param size + * the point size + * @return the cap height for the given size + */ + public int getCapHeight(int size) { + return charSet.getCapHeight() / 1000 * size; + } + + /** + * The descender is the part of a lowercase letter that extends below the + * base line, such as "g", "j", or "p". Also used to denote the part of the + * letter extending below the base line. + * + * @param size + * the point size + * @return the descender for the given size + */ + public int getDescender(int size) { + return charSet.getDescender() / 1000 * size; + } + + /** + * The "x-height" (the height of the letter "x"). + * + * @param size + * the point size + * @return the x height for the given size + */ + public int getXHeight(int size) { + return charSet.getXHeight() / 1000 * size; + } + + /** + * Obtain the width of the character for the specified point size. + * @param character the character + * @param size point size + * @return the width of the character for the specified point size + */ + public int getWidth(int character, int size) { + return charSet.getWidth(character) / 1000 * size; + } + + /** + * Get the getWidth (in 1/1000ths of a point size) of all characters in this + * character set. + * + * @param size + * the point size + * @return the widths of all characters + */ + public int[] getWidths(int size) { + int[] widths = charSet.getWidths(); + for (int i = 0; i < widths.length; i++) { + widths[i] = widths[i] / 1000 * size; + } + return widths; + } + + /** + * Get the getWidth (in 1/1000ths of a point size) of all characters in this + * character set. + * + * @return the widths of all characters + */ + public int[] getWidths() { + return getWidths(1000); + } + + /** + * Map a Unicode character to a code point in the font. + * @param c character to map + * @return the mapped character + */ + public char mapChar(char c) { + return charSet.mapChar(c); + } + + /** {@inheritDoc} */ + public String getEncodingName() { + return charSet.getEncoding(); + } +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/fonts/RasterFont.java b/src/java/org/apache/fop/afp/fonts/RasterFont.java new file mode 100644 index 000000000..7582159c5 --- /dev/null +++ b/src/java/org/apache/fop/afp/fonts/RasterFont.java @@ -0,0 +1,238 @@ +/* + * 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.fonts; + +import java.util.Iterator; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * A font where each character is stored as an array of pixels (a bitmap). Such + * fonts are not easily scalable, in contrast to vectored fonts. With this type + * of font, the font metrics information is held in character set files (one for + * each size and style).

+ * + */ +public class RasterFont extends AFPFont { + + /** Static logging instance */ + protected static final Log log = LogFactory.getLog("org.apache.xmlgraphics.afp.fonts"); + + private final Map/**/ charSets + = new java.util.HashMap/**/(); + + private CharacterSet charSet = null; + + /** + * Constructor for the raster font requires the name, weight and style + * attribute to be available as this forms the key to the font. + * + * @param name + * the name of the font + */ + public RasterFont(String name) { + super(name); + } + + /** + * Adds the character set for the given point size + * @param size point size + * @param characterSet character set + */ + public void addCharacterSet(int size, CharacterSet characterSet) { + this.charSets.put(String.valueOf(size), characterSet); + this.charSet = characterSet; + } + + /** Describes the unit millipoint. */ + public static final String MPT = "mpt"; + + /** + * Get the character set metrics for the specified point size. + * + * @param size the point size + * @return the character set metrics + */ + public CharacterSet getCharacterSet(int size) { + + String pointsize = String.valueOf(size / 1000); + CharacterSet csm = (CharacterSet) charSets.get(pointsize); + if (csm == null) { + csm = (CharacterSet) charSets.get(size + MPT); + } + if (csm == null) { + // Get char set with nearest font size + int distance = Integer.MAX_VALUE; + for (Iterator it = charSets.entrySet().iterator(); it.hasNext();) { + Map.Entry me = (Map.Entry)it.next(); + String key = (String)me.getKey(); + if (!key.endsWith(MPT)) { + int mpt = Integer.parseInt(key) * 1000; + if (Math.abs(size - mpt) < distance) { + distance = Math.abs(size - mpt); + pointsize = (String)me.getKey(); + csm = (CharacterSet)me.getValue(); + } + } + } + if (csm != null) { + charSets.put(size + MPT, csm); + String msg = "No " + (size / 1000) + "pt font " + getFontName() + + " found, substituted with " + pointsize + "pt font"; + log.warn(msg); + } + } + if (csm == null) { + String msg = "No font found for font " + getFontName() + + " with point size " + pointsize; + log.error(msg); + throw new FontRuntimeException(msg); + } + return csm; + + } + + /** + * Get the first character in this font. + * @return the first character in this font. + */ + public int getFirstChar() { + Iterator it = charSets.values().iterator(); + if (it.hasNext()) { + CharacterSet csm = (CharacterSet) it.next(); + return csm.getFirstChar(); + } else { + String msg = "getFirstChar() - No character set found for font:" + getFontName(); + log.error(msg); + throw new FontRuntimeException(msg); + } + } + + /** + * Get the last character in this font. + * @return the last character in this font. + */ + public int getLastChar() { + + Iterator it = charSets.values().iterator(); + if (it.hasNext()) { + CharacterSet csm = (CharacterSet) it.next(); + return csm.getLastChar(); + } else { + String msg = "getLastChar() - No character set found for font:" + getFontName(); + log.error(msg); + throw new FontRuntimeException(msg); + } + + } + + /** + * The ascender is the part of a lowercase letter that extends above the + * "x-height" (the height of the letter "x"), such as "d", "t", or "h". Also + * used to denote the part of the letter extending above the x-height. + * + * @param size the point size + * @return the ascender for the given point size + */ + public int getAscender(int size) { + return getCharacterSet(size).getAscender(); + } + + /** + * Obtains the height of capital letters for the specified point size. + * + * @param size the point size + * @return the cap height for the specified point size + */ + public int getCapHeight(int size) { + return getCharacterSet(size).getCapHeight(); + } + + /** + * The descender is the part of a lowercase letter that extends below the + * base line, such as "g", "j", or "p". Also used to denote the part of the + * letter extending below the base line. + * + * @param size the point size + * @return the descender for the specified point size + */ + public int getDescender(int size) { + return getCharacterSet(size).getDescender(); + } + + /** + * The "x-height" (the height of the letter "x"). + * + * @param size the point size + * @return the x height for the given point size + */ + public int getXHeight(int size) { + return getCharacterSet(size).getXHeight(); + } + + /** + * Obtain the width of the character for the specified point size. + * @param character the character + * @param size the point size + * @return the width for the given point size + */ + public int getWidth(int character, int size) { + return getCharacterSet(size).getWidth(character); + } + + /** + * Get the getWidth (in 1/1000ths of a point size) of all characters in this + * character set. + * + * @param size + * the point size + * @return the widths of all characters + */ + public int[] getWidths(int size) { + return getCharacterSet(size).getWidths(); + } + + /** + * Get the getWidth (in 1/1000ths of a point size) of all characters in this + * character set. + * + * @return the widths of all characters + */ + public int[] getWidths() { + return getWidths(1000); + } + + /** + * Map a Unicode character to a code point in the font. + * @param c character to map + * @return the mapped character + */ + public char mapChar(char c) { + return charSet.mapChar(c); + } + + /** {@inheritDoc} */ + public String getEncodingName() { + return charSet.getEncoding(); + } + +} diff --git a/src/java/org/apache/fop/afp/goca/AbstractGraphicsCoord.java b/src/java/org/apache/fop/afp/goca/AbstractGraphicsCoord.java new file mode 100644 index 000000000..6f993b840 --- /dev/null +++ b/src/java/org/apache/fop/afp/goca/AbstractGraphicsCoord.java @@ -0,0 +1,137 @@ +/* + * 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; + +/** + * A base class encapsulating the structure of coordinate based GOCA objects + */ +public abstract class AbstractGraphicsCoord extends AbstractPreparedAFPObject { + + /** array of x/y coordinates */ + protected int[] coords = null; + + /** + * Constructor + * + * @param coords the x/y coordinates for this object + */ + public AbstractGraphicsCoord(int[] coords) { + this.coords = coords; + prepareData(); + } + + /** + * Constructor + * + * @param x the x coordinate for this object + * @param y the y coordinate for this object + */ + public AbstractGraphicsCoord(int x, int y) { + this(new int[] {x, y}); + } + + /** + * Constructor + * + * @param x1 the x1 coordinate for this object + * @param y1 the y1 coordinate for this object + * @param x2 the x2 coordinate for this object + * @param y2 the y2 coordinate for this object + */ + public AbstractGraphicsCoord(int x1, int y1, int x2, int y2) { + this(new int[] {x1, y1, x2, y2}); + } + + /** + * Returns the order code to use + * + * @return the order code to use + */ + protected abstract byte getOrderCode(); + + /** + * Returns the length of this order code (typically this is the same as the coordinate length) + * + * @return the length of this order code + * + */ + protected int getLength() { + return this.coords.length * 2; + } + + /** + * Creates a newly created and initialized byte data + * + * @return a newly created and initialized byte data + */ + protected byte[] createData() { + int len = getLength(); + byte[] data = new byte[len + 2]; + data[0] = getOrderCode(); // ORDER CODE + data[1] = (byte)len; // LENGTH + return data; + } + + /** {@inheritDoc} */ + protected void prepareData() { + super.data = createData(); + int fromIndex = data.length - getLength(); + addCoords(data, fromIndex); + } + + /** + * Adds the coordinates to the structured field data + * + * @param data the structured field data + * @param fromIndex the start index + */ + protected void addCoords(byte[] data, int fromIndex) { + // X/Y POS + for (int i = 0; i < coords.length; i++, fromIndex += 2) { + byte[] coord = BinaryUtils.convert(coords[i], 2); + data[fromIndex] = coord[0]; + data[fromIndex + 1] = coord[1]; + } + } + + /** + * 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 = ""; + for (int i = 0; i < coords.length; i++) { + coordsStr += (i % 2 == 0) ? "x" : "y"; + coordsStr += (i / 2) + "=" + coords[i] + ","; + } + coordsStr = coordsStr.substring(0, coordsStr.length() - 1); + return getName() + "{" + coordsStr + "}"; + } +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/goca/GraphicsArea.java b/src/java/org/apache/fop/afp/goca/GraphicsArea.java new file mode 100644 index 000000000..2b6d8a804 --- /dev/null +++ b/src/java/org/apache/fop/afp/goca/GraphicsArea.java @@ -0,0 +1,76 @@ +/* + * 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 org.apache.fop.afp.modca.AbstractPreparedObjectContainer; + +/** + * A GOCA graphics area (container for filled shapes/objects) + */ +public final class GraphicsArea extends AbstractPreparedObjectContainer { + + 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() { + // start len + end len + data len + 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[] endData = new byte[] { + (byte)0x60, // GEAR order code + 0x00, // LENGTH + }; + os.write(endData); + } + + /** {@inheritDoc} */ + public String toString() { + return "GraphicsArea{drawBoundary=" + drawBoundary + "}"; + } +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/goca/GraphicsBox.java b/src/java/org/apache/fop/afp/goca/GraphicsBox.java new file mode 100644 index 000000000..4f4947000 --- /dev/null +++ b/src/java/org/apache/fop/afp/goca/GraphicsBox.java @@ -0,0 +1,61 @@ +/* + * 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 rectangular box + */ +public final class GraphicsBox extends AbstractGraphicsCoord { + + /** + * Constructor + * + * @param coords the x/y coordinates for this object + */ + public GraphicsBox(int[] coords) { + super(coords); + } + + /** {@inheritDoc} */ + protected byte getOrderCode() { + return (byte)0xC0; + } + + /** {@inheritDoc} */ + protected int getLength() { + return 10; + } + + /** {@inheritDoc} */ + protected void prepareData() { + super.data = createData(); + final int fromIndex = 4; + addCoords(data, fromIndex); + } + + /** {@inheritDoc} */ + protected byte[] createData() { + byte[] data = super.createData(); + data[2] = (byte)0x20; // CONTROL draw control flags + data[3] = 0x00; // reserved + return 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 new file mode 100644 index 000000000..8dab3d922 --- /dev/null +++ b/src/java/org/apache/fop/afp/goca/GraphicsChainedSegment.java @@ -0,0 +1,148 @@ +/* + * 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 org.apache.fop.afp.modca.AbstractPreparedObjectContainer; +import org.apache.fop.afp.modca.PreparedAFPObject; +import org.apache.fop.afp.util.BinaryUtils; + +/** + * A GOCA graphics segment + */ +public final class GraphicsChainedSegment extends AbstractPreparedObjectContainer { + + /** 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; + + /** + * Main constructor + * + * @param name + * the name of this graphics segment + */ + public GraphicsChainedSegment(String name) { + super(name); + } + + /** + * Constructor + * + * @param name + * the name of this graphics segment + * @param previous + * the previous graphics segment in this chain + */ + public GraphicsChainedSegment(String name, GraphicsChainedSegment previous) { + super(name); + previous.next = this; + this.previous = previous; + } + + /** {@inheritDoc} */ + public int getDataLength() { + return 14 + super.getDataLength(); + } + + private static final byte APPEND_NEW_SEGMENT = 0; +// private static final byte PROLOG = 4; +// private static final byte APPEND_TO_EXISING = 48; + + private static final int NAME_LENGTH = 4; + + /** {@inheritDoc} */ + protected int getNameLength() { + return NAME_LENGTH; + } + + /** {@inheritDoc} */ + protected void writeStart(OutputStream os) throws IOException { + super.writeStart(os); + + byte[] data = new byte[14]; + data[0] = 0x70; // BEGIN_SEGMENT + data[1] = 0x0C; // Length of following parameters + + // segment name + byte[] nameBytes = getNameBytes(); + System.arraycopy(nameBytes, 0, data, 2, NAME_LENGTH); + + data[6] = 0x00; // FLAG1 (ignored) + data[7] = APPEND_NEW_SEGMENT; + + int dataLength = super.getDataLength(); + byte[] len = BinaryUtils.convert(dataLength, 2); + data[8] = len[0]; // SEGL + data[9] = len[1]; + + // P/S NAME (predecessor name) + if (previous != null) { + nameBytes = previous.getNameBytes(); + System.arraycopy(nameBytes, 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(PreparedAFPObject drawingOrder) { + if (currentArea != null) { + currentArea.addObject(drawingOrder); + } else { + super.addObject(drawingOrder); + } + } + + /** {@inheritDoc} */ + public String toString() { + return "GraphicsChainedSegment(name=" + super.getName() + ")"; + } +} \ 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 new file mode 100644 index 000000000..ca5fef3f4 --- /dev/null +++ b/src/java/org/apache/fop/afp/goca/GraphicsData.java @@ -0,0 +1,128 @@ +/* + * 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 org.apache.fop.afp.modca.AbstractPreparedObjectContainer; +import org.apache.fop.afp.modca.PreparedAFPObject; +import org.apache.fop.afp.util.BinaryUtils; +import org.apache.fop.afp.util.StringUtils; + +/** + * A GOCA graphics data + */ +public final class GraphicsData extends AbstractPreparedObjectContainer { + + /** The maximum graphics data length */ + public static final int MAX_DATA_LEN = 32767; + + /** The graphics segment */ + private GraphicsChainedSegment currentSegment = null; + + /** {@inheritDoc} */ + public int getDataLength() { + return 8 + super.getDataLength(); + } + + /** + * Begins a graphics area (start of fill) + */ + public void beginArea() { + getSegment().beginArea(); + } + + /** + * Ends a graphics area (end of fill) + */ + public void endArea() { + getSegment().endArea(); + } + + /** + * Returns a new segment name + * + * @return a new segment name + */ + private 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 (currentSegment == null) { + newSegment(); + } + return this.currentSegment; + } + + /** + * Creates a new graphics segment + * + * @return a newly created graphics segment + */ + public GraphicsChainedSegment newSegment() { + String name = createSegmentName(); + if (currentSegment == null) { + this.currentSegment = new GraphicsChainedSegment(name); + } else { + this.currentSegment = new GraphicsChainedSegment(name, currentSegment); + } + super.addObject(currentSegment); + return currentSegment; + } + + /** {@inheritDoc} */ + public void addObject(PreparedAFPObject drawingOrder) { + if (currentSegment == null + || (currentSegment.getDataLength() + drawingOrder.getDataLength()) + >= GraphicsChainedSegment.MAX_DATA_LEN) { + newSegment(); + } + currentSegment.addObject(drawingOrder); + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = new byte[9]; + copySF(data, SF_CLASS, Type.DATA, Category.GRAPHICS); + int dataLength = getDataLength(); + byte[] len = BinaryUtils.convert(dataLength, 2); + data[1] = len[0]; // Length byte 1 + 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); + } + + /** {@inheritDoc} */ + public String toString() { + return "GraphicsData"; + } +} \ 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 new file mode 100644 index 000000000..40b98b0d3 --- /dev/null +++ b/src/java/org/apache/fop/afp/goca/GraphicsFillet.java @@ -0,0 +1,42 @@ +/* + * 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 GraphicsFillet extends AbstractGraphicsCoord { + + /** + * Constructor + * + * @param coords the x/y coordinates for this object + */ + public GraphicsFillet(int[] coords) { + super(coords); + } + + /** {@inheritDoc} */ + protected byte getOrderCode() { + return (byte)0xC5; + } + +} \ 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 new file mode 100644 index 000000000..9d511e142 --- /dev/null +++ b/src/java/org/apache/fop/afp/goca/GraphicsFullArc.java @@ -0,0 +1,78 @@ +/* + * 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.util.BinaryUtils; + +/** + * A GOCA graphics arc (circle/ellipse) + */ +public class GraphicsFullArc extends AbstractGraphicsCoord { + /** the integer portion of the multiplier */ + private final int mh; + + /** the fractional portion of the multiplier */ + private final int mhr; + + /** + * Constructor + * + * @param x the x coordinate of the center of the circle/ellipse + * @param y the y coordinate of the center of the circle/ellipse + * @param mh the integer portion of the multiplier + * @param mhr the fractional portion of the multiplier + */ + public GraphicsFullArc(int x, int y, int mh, int mhr) { + 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; + } + + /** {@inheritDoc} */ + protected int getLength() { + return super.getLength() + 2; + } + + /** {@inheritDoc} */ + protected void prepareData() { + super.data = super.createData(); + final int fromIndex = 2; + super.addCoords(data, fromIndex); + } + + /** {@inheritDoc} */ + public String toString() { + return "GraphicsFullArc{" + + ", centerx=" + coords[0] + + ", centery=" + coords[1] + + ", mh=" + mh + + ", 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 new file mode 100644 index 000000000..24d4c78f8 --- /dev/null +++ b/src/java/org/apache/fop/afp/goca/GraphicsImage.java @@ -0,0 +1,117 @@ +/* + * 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 org.apache.fop.afp.modca.AbstractStructuredAFPObject; +import org.apache.fop.afp.util.BinaryUtils; + +/** + * A GOCA Image + */ +public class GraphicsImage extends AbstractStructuredAFPObject { + + /** x coordinate */ + private final int x; + + /** y coordinate */ + private final int y; + + /** width */ + private final int width; + + /** height */ + private final int height; + + /** image data */ + private final byte[] imageData; + + /** + * Main constructor + * + * @param x the x coordinate of the image + * @param y the y coordinate of the image + * @param width the image width + * @param height the image height + * @param imageData the image data + */ + public GraphicsImage(int x, int y, int width, int height, byte[] imageData) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + this.imageData = imageData; + } + + /** {@inheritDoc} */ + protected void writeStart(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) 0x0A, // LENGTH + xcoord[0], + xcoord[1], + ycoord[0], + ycoord[1], + 0x00, // FORMAT + 0x00, // RES + w[0], // WIDTH + w[1], // + h[0], // HEIGHT + h[1] // + }; + os.write(data); + } + + /** the maximum image data length */ + public static final short MAX_DATA_LEN = 255; + + /** {@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) 0x93, // GEIMG order code + 0x00 // LENGTH + }; + os.write(data); + } + + /** {@inheritDoc} */ + public String toString() { + return "GraphicsImage{x=" + x + + ", y=" + y + + ", width=" + width + + ", height=" + height + + "}"; + } +} diff --git a/src/java/org/apache/fop/afp/goca/GraphicsLine.java b/src/java/org/apache/fop/afp/goca/GraphicsLine.java new file mode 100644 index 000000000..319a9a122 --- /dev/null +++ b/src/java/org/apache/fop/afp/goca/GraphicsLine.java @@ -0,0 +1,43 @@ +/* + * 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 + * given position or current position. + */ +public class GraphicsLine extends AbstractGraphicsCoord { + + /** + * Constructor + * + * @param coords the x/y coordinates for this object + */ + public GraphicsLine(int[] coords) { + super(coords); + } + + /** {@inheritDoc} */ + protected byte getOrderCode() { + return (byte)0xC1; + } + +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/goca/GraphicsSetArcParameters.java b/src/java/org/apache/fop/afp/goca/GraphicsSetArcParameters.java new file mode 100644 index 000000000..693cf21a9 --- /dev/null +++ b/src/java/org/apache/fop/afp/goca/GraphicsSetArcParameters.java @@ -0,0 +1,51 @@ +/* + * 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; + +/** + * Sets the arc parameters for a GOCA graphics arc (circle/ellipse) + */ +public class GraphicsSetArcParameters extends AbstractGraphicsCoord { + + /** + * Constructor + * + * @param xmaj x coordinate of the major axis point + * @param ymin y coordinate of the minor axis point + * @param xmin x coordinate of the minor axis point + * @param ymaj y coordinate of the major axis point + */ + public GraphicsSetArcParameters(int xmaj, int ymin, int xmin, int ymaj) { + super(xmaj, ymin, xmin, ymaj); + } + + /** {@inheritDoc} */ + protected byte getOrderCode() { + return 0x22; + } + + /** {@inheritDoc} */ + public String toString() { + return getName() + "{xmaj=" + coords[0] + + ",ymin=" + coords[1] + + ",xmin=" + coords[2] + + ",ymaj=" + coords[3] + "}"; + } +} \ 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 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 diff --git a/src/java/org/apache/fop/afp/goca/GraphicsSetCurrentPosition.java b/src/java/org/apache/fop/afp/goca/GraphicsSetCurrentPosition.java new file mode 100644 index 000000000..675c2f034 --- /dev/null +++ b/src/java/org/apache/fop/afp/goca/GraphicsSetCurrentPosition.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.goca; + +/** + * Sets the current painting position of the graphics object + */ +public class GraphicsSetCurrentPosition extends AbstractGraphicsCoord { + + /** + * Constructor + * + * @param coords the x/y coordinates for this object + */ + public GraphicsSetCurrentPosition(int[] coords) { + super(coords); + } + + /** {@inheritDoc} */ + protected byte getOrderCode() { + return (byte)0x21; + } +} \ 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 new file mode 100644 index 000000000..0093885a6 --- /dev/null +++ b/src/java/org/apache/fop/afp/goca/GraphicsSetLineType.java @@ -0,0 +1,86 @@ +/* + * 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; + +/** + * Sets the value of the current line type attribute when stroking GOCA shapes (structured fields) + */ +public class GraphicsSetLineType extends AbstractPreparedAFPObject { + + /** the default line type */ + public static final byte DEFAULT = 0x00; // normally SOLID + + /** the default line type */ + public static final byte DOTTED = 0x01; + + /** short dashed line type */ + public static final byte SHORT_DASHED = 0x02; + + /** dashed dotted line type */ + public static final byte DASH_DOT = 0x03; + + /** double dotted line type */ + public static final byte DOUBLE_DOTTED = 0x04; + + /** long dashed line type */ + public static final byte LONG_DASHED = 0x05; + + /** dash double dotted line type */ + public static final byte DASH_DOUBLE_DOTTED = 0x06; + + /** solid line type */ + public static final byte SOLID = 0x07; + + /** invisible line type */ + public static final byte INVISIBLE = 0x08; + + /** line type */ + private byte type = DEFAULT; + + /** + * Main constructor + * + * @param type line type + */ + public GraphicsSetLineType(byte type) { + this.type = type; + prepareData(); + } + + /** {@inheritDoc} */ + protected void prepareData() { + super.data = new byte[] { + 0x18, // GSLW order code + type // line type + }; + } + + private static final String[] TYPES = { + "default (solid)", "dotted", "short dashed", "dash dotted", "double dotted", + "long dashed", "dash double dotted", "solid", "invisible" + }; + + /** {@inheritDoc} */ + public String toString() { + return "GraphicsSetLineType{type=" + TYPES[type] + "}"; + } +} \ 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 new file mode 100644 index 000000000..863cbf50d --- /dev/null +++ b/src/java/org/apache/fop/afp/goca/GraphicsSetLineWidth.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; + +/** + * Sets the line width to use when stroking GOCA shapes (structured fields) + */ +public class GraphicsSetLineWidth extends AbstractPreparedAFPObject { + /** line width multiplier */ + private int multiplier = 1; + + /** + * Main constructor + * + * @param multiplier the line width multiplier + */ + public GraphicsSetLineWidth(int multiplier) { + this.multiplier = multiplier; + prepareData(); + } + + /** {@inheritDoc} */ + protected void prepareData() { + super.data = new byte[] { + 0x19, // GSLW order code + (byte)multiplier // MH (line-width) + }; + } + + /** {@inheritDoc} */ + public String toString() { + return "GraphicsSetLineWidth{multiplier=" + multiplier + "}"; + } +} \ 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 new file mode 100644 index 000000000..339620271 --- /dev/null +++ b/src/java/org/apache/fop/afp/goca/GraphicsSetMix.java @@ -0,0 +1,55 @@ +/* + * 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; + +public class GraphicsSetMix extends AbstractPreparedAFPObject { + + public static final byte MODE_DEFAULT = 0x00; + public static final byte MODE_OVERPAINT = 0x02; + + /** the mix mode value */ + private final byte mode; + + /** + * Main constructor + * + * @param mode the mix mode value + */ + public GraphicsSetMix(byte mode) { + this.mode = mode; + prepareData(); + } + + /** {@inheritDoc} */ + protected void prepareData() { + super.data = new byte[] { + 0x0C, // GSMX order code + mode // MODE (mix mode value) + }; + } + + /** {@inheritDoc} */ + public String toString() { + return "GraphicsSetMix{mode=" + mode + "}"; + } + +} diff --git a/src/java/org/apache/fop/afp/goca/GraphicsSetPatternSymbol.java b/src/java/org/apache/fop/afp/goca/GraphicsSetPatternSymbol.java new file mode 100644 index 000000000..f0e6845be --- /dev/null +++ b/src/java/org/apache/fop/afp/goca/GraphicsSetPatternSymbol.java @@ -0,0 +1,105 @@ +/* + * 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; + +/** + * Sets the pattern symbol to use when filling following GOCA structured fields + */ +public class GraphicsSetPatternSymbol extends AbstractPreparedAFPObject { + /** dotted density 1 */ + public static final byte DOTTED_DENSITY_1 = 0x01; + + /** dotted density 2 */ + public static final byte DOTTED_DENSITY_2 = 0x02; + + /** dotted density 3 */ + public static final byte DOTTED_DENSITY_3 = 0x03; + + /** dotted density 4 */ + public static final byte DOTTED_DENSITY_4 = 0x04; + + /** dotted density 5 */ + public static final byte DOTTED_DENSITY_5 = 0x05; + + /** dotted density 6 */ + public static final byte DOTTED_DENSITY_6 = 0x06; + + /** dotted density 7 */ + public static final byte DOTTED_DENSITY_7 = 0x07; + + /** dotted density 8 */ + public static final byte DOTTED_DENSITY_8 = 0x08; + + /** dotted density 9 */ + public static final byte VERTICAL_LINES = 0x09; + + /** horizontal lines */ + public static final byte HORIZONTAL_LINES = 0x0A; + + /** diagonal lines, bottom left to top right 1 */ + public static final byte DIAGONAL_LINES_BLTR_1 = 0x0B; + + /** diagonal lines, bottom left to top right 2 */ + public static final byte DIAGONAL_LINES_BLTR_2 = 0x0C; + + /** diagonal lines, top left to bottom right 1 */ + public static final byte DIAGONAL_LINES_TLBR_1 = 0x0D; + + /** diagonal lines, top left to bottom right 2 */ + public static final byte DIAGONAL_LINES_TLBR_2 = 0x0E; + + /** no fill */ + public static final byte NO_FILL = 0x0F; + + /** solid fill */ + public static final byte SOLID_FILL = 0x10; + + /** blank (same as no fill) */ + public static final byte BLANK = 0x40; // processed same as NO_FILL + + /** the graphics pattern symbol to use */ + private final byte symbol; + + /** + * Main constructor + * + * @param symb the pattern symbol to use + */ + public GraphicsSetPatternSymbol(byte symb) { + this.symbol = symb; + prepareData(); + } + + /** {@inheritDoc} */ + protected void prepareData() { + super.data = new byte[] { + 0x28, // GSPT order code + symbol + }; + } + + /** {@inheritDoc} */ + public String toString() { + return "GraphicsSetPatternSymbol(fill=" + + (symbol == SOLID_FILL ? true : false) + ")"; + } +} \ 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 new file mode 100644 index 000000000..6ec1e50ee --- /dev/null +++ b/src/java/org/apache/fop/afp/goca/GraphicsSetProcessColor.java @@ -0,0 +1,89 @@ +/* + * 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.awt.Color; +import java.awt.color.ColorSpace; + +import org.apache.fop.afp.modca.AbstractPreparedAFPObject; + +/** + * Sets the current processing color for the following GOCA structured fields + */ +public class GraphicsSetProcessColor extends AbstractPreparedAFPObject { + /** the color to set */ + private final Color color; + + /** + * Main constructor + * + * @param color the color to set + */ + public GraphicsSetProcessColor(Color color) { + this.color = color; + prepareData(); + } + + /** {@inheritDoc} */ + protected void prepareData() { + // COLSPCE + byte colspace; + int colSpaceType = color.getColorSpace().getType(); + if (colSpaceType == ColorSpace.TYPE_CMYK) { + colspace = 0x04; + } else if (colSpaceType == ColorSpace.TYPE_RGB) { + colspace = 0x01; + } else { + log.error("unsupported colorspace " + colSpaceType); + colspace = 0x01; + } + + // COLSIZE(S) + float[] colcomp = color.getColorComponents(null); + byte[] colsizes = new byte[] {0x00, 0x00, 0x00, 0x00}; + for (int i = 0; i < colcomp.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 + data[2] = 0x00; // reserved; must be zero + data[3] = colspace; // COLSPCE + data[4] = 0x00; // reserved; must be zero + data[5] = 0x00; // reserved; must be zero + data[6] = 0x00; // reserved; must be zero + data[7] = 0x00; // reserved; must be zero + data[8] = colsizes[0]; // COLSIZE(S) + 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); + } + } + + /** {@inheritDoc} */ + public String toString() { + return "GraphicsSetProcessColor(col=" + color + ")"; + } +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/goca/GraphicsString.java b/src/java/org/apache/fop/afp/goca/GraphicsString.java new file mode 100644 index 000000000..0fa14bb6d --- /dev/null +++ b/src/java/org/apache/fop/afp/goca/GraphicsString.java @@ -0,0 +1,115 @@ +/* + * 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; +import org.apache.fop.afp.modca.AbstractPreparedAFPObject; +import org.apache.fop.afp.util.BinaryUtils; + +/** + * 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(); + } + + /** + * Constructor + * + * @param str the character string + * @param x the x coordinate + * @param y the y coordinate + */ + public GraphicsString(String str, int x, int y) { + this.str = str; + this.x = x; + this.y = y; + prepareData(); + } + + /** {@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); + } + } + + /** {@inheritDoc} */ + public String toString() { + String string = "GraphicsString{str='" + str + "'"; + if (!fromCurrentPosition) { + string += ",x=" + x + ",y=" + y; + } + string += "}"; + return string; + } +} \ 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 new file mode 100644 index 000000000..0728ad98f --- /dev/null +++ b/src/java/org/apache/fop/afp/ioca/ImageCellPosition.java @@ -0,0 +1,174 @@ +/* + * 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.ioca; + +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.fop.afp.modca.AbstractAFPObject; +import org.apache.fop.afp.util.BinaryUtils; + +/** + * The IM Image Cell Position structured field specifies the placement, + * size, and replication of IM image cells. + */ +public class ImageCellPosition extends AbstractAFPObject { + + /** + * Offset of image cell in X direction + */ + private int xOffset = 0; + + /** + * Offset of image cell in Y direction + */ + private int yOffset = 0; + + /** + * Size of image cell in X direction + */ + private final byte[] xSize = new byte[] {(byte)0xFF, (byte)0xFF}; + + /** + * Size of image cell in Y direction + */ + private final byte[] ySize = new byte[] {(byte)0xFF, (byte)0xFF}; + + /** + * Size of fill rectangle in X direction + */ + private final byte[] xFillSize = new byte[] {(byte)0xFF, (byte)0xFF}; + + /** + * Size of fill rectangle in Y direction + */ + private final byte[] yFillSize = new byte[] {(byte)0xFF, (byte)0xFF}; + + /** + * Constructor for the ImageCellPosition + * @param x The offset of image cell in X direction + * @param y The offset of image cell in Y direction + */ + public ImageCellPosition(int x, int y) { + xOffset = x; + yOffset = y; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = new byte[21]; + copySF(data, Type.POSITION, Category.IM_IMAGE); + + data[1] = 0x00; // length + data[2] = 0x14; + + /** + * Specifies the offset along the Xp direction, in image points, + * of this image cell from the IM image object area origin. + */ + byte[] x1 = BinaryUtils.convert(xOffset, 2); + data[9] = x1[0]; + data[10] = x1[1]; + + /** + * Specifies the offset along the Yp direction, in image points, + * of this image cell from the IM image object area origin. + */ + byte[] x2 = BinaryUtils.convert(yOffset, 2); + data[11] = x2[0]; + data[12] = x2[1]; + + data[13] = xSize[0]; + data[14] = xSize[1]; + + data[15] = ySize[0]; + data[16] = ySize[1]; + + data[17] = xFillSize[0]; + data[18] = xFillSize[1]; + + data[19] = yFillSize[0]; + data[20] = yFillSize[1]; + + os.write(data); + } + + /** + * Specifies the extent in the X direction, in image points, + * of this image cell. A value of X'FFFF' indicates that the + * default extent specified in bytes 28 and 29 of the Image + * Input Descriptor (IID) is to be used. + * + * @param xcSize The size to set. + */ + public void setXSize(int xcSize) { + byte[] x = BinaryUtils.convert(xcSize, 2); + xSize[0] = x[0]; + xSize[1] = x[1]; + } + + /** + * Specifies the extent of the fill rectangle in the X direction, + * in image points. This value can be smaller than, equal to, or + * larger than the image cell extent in the X direction (XCSize). + * A value of X'FFFF' indicates that the image cell X-extent should + * be used as the fill rectangle X-extent. The fill rectangle is + * filled in the X direction by repeating the image cell in the + * X direction. The image cell can be truncated to fit the rectangle. + * + * @param size The size to set. + */ + public void setXFillSize(int size) { + byte[] x = BinaryUtils.convert(size, 2); + this.xFillSize[0] = x[0]; + this.xFillSize[1] = x[1]; + } + + /** + * Specifies the extent in the Y direction, in image points, + * of this image cell. A value of X'FFFF' indicates that the + * default extent specified in bytes 30 and 31 of the Image + * Input Descriptor (IID) is to be used. + * + * @param size The size to set. + */ + public void setYSize(int size) { + byte[] x = BinaryUtils.convert(size, 2); + this.ySize[0] = x[0]; + this.ySize[1] = x[1]; + } + + /** + * Specifies the extent of the fill rectangle in the Y direction, + * in image points. This value can be smaller than, equal to, or + * larger than the image cell extent in the Y direction (YCSize). + * A value of X'FFFF' indicates that the image cell Y-extent should + * be used as the fill rectangle Y-extent. The fill rectangle is + * filled in the Y direction by repeating the image cell in the + * Y direction. The image cell can be truncated to fit the rectangle. + * + * @param size The size to set. + */ + public void setYFillSize(int size) { + byte[] x = BinaryUtils.convert(size, 2); + this.yFillSize[0] = x[0]; + this.yFillSize[1] = x[1]; + } +} \ 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 new file mode 100644 index 000000000..27147d511 --- /dev/null +++ b/src/java/org/apache/fop/afp/ioca/ImageContent.java @@ -0,0 +1,277 @@ +/* + * 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.ioca; + +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.fop.afp.modca.AbstractStructuredAFPObject; + +/** + */ +public class ImageContent extends AbstractStructuredAFPObject { + + /** + * The CCITT T.4 Group 3 Coding Standard (G3 MH-Modified Huffman) is a + * compression method standardized by the International Telegraph and + * Telephone Consultative Committee (CCITT) for facsimile. It enables + * one-dimensional compression. + */ + public static final byte COMPID_G3_MH = (byte)0x80; + + /** + * The CCITT T.4 Group 3 Coding Option (G3 MR-Modified READ) is a + * compression method standardized by the International Telegraph and + * Telephone Consultative Committee (CCITT) for facsimile. It enables + * two-dimensional compression. + */ + public static final byte COMPID_G3_MR = (byte)0x81; + + /** + * The CCITT T.6 Group 4 Coding Standard (G4 MMR-Modified Modified READ) is a + * compression method standardized by the International Telegraph and + * Telephone Consultative Committee (CCITT) for facsimile. It enables + * two-dimensional compression. + */ + public static final byte COMPID_G3_MMR = (byte)0x82; + + /** + * The image size parameter + */ + private ImageSizeParameter imageSizeParameter = null; + + /** + * The image encoding + */ + private byte encoding = (byte)0x03; + + /** + * The image ide size + */ + private byte size = 1; + + /** + * The image compression + */ + private byte compression = (byte)0xC0; + + /** + * The image color model + */ + private byte colorModel = (byte)0x01; + + /** + * The image data + */ + private byte[] data; + + /** + * Constructor for the image content + */ + public ImageContent() { + } + + /** + * Sets the image size parameter + * + * @param imageSizeParameter the image size parameter. + */ + public void setImageSizeParameter(ImageSizeParameter imageSizeParameter) { + this.imageSizeParameter = imageSizeParameter; + } + + /** + * Sets the image encoding. + * + * @param enc The image encoding. + */ + public void setImageEncoding(byte enc) { + this.encoding = enc; + } + + /** + * Sets the image compression. + * + * @param comp The image compression. + */ + public void setImageCompression(byte comp) { + this.compression = comp; + } + + /** + * Sets the image IDE size. + * + * @param s The IDE size. + */ + public void setImageIDESize(byte s) { + this.size = s; + } + + /** + * Sets the image IDE color model. + * + * @param color the IDE color model. + */ + public void setImageIDEColorModel(byte color) { + this.colorModel = color; + } + + /** + * Set the data image store information. + * + * @param imageData the image data + */ + public void setImageData(byte[] imageData) { + this.data = imageData; + } + + private static final int MAX_DATA_LEN = 65535; + + /** {@inheritDoc} */ + protected void writeContent(OutputStream os) throws IOException { + if (imageSizeParameter != null) { + imageSizeParameter.writeToStream(os); + } + + // TODO convert to triplet/parameter class + os.write(getImageEncodingParameter()); + + os.write(getImageIDESizeParameter()); + + os.write(getIDEStructureParameter()); + + os.write(getExternalAlgorithmParameter()); + + // Image Data + if (data != null) { + final byte[] dataHeader = new byte[] { + (byte)0xFE, // ID + (byte)0x92, // ID + 0x00, // length + 0x00 // length + }; + final int lengthOffset = 2; + writeChunksToStream(this.data, dataHeader, lengthOffset, MAX_DATA_LEN, os); + } + } + + /** {@inheritDoc} */ + protected void writeStart(OutputStream os) throws IOException { + final byte[] startData = new byte[] { + (byte)0x91, // ID + 0x01, // Length + (byte)0xff, // Object Type = IOCA Image Object + }; + os.write(startData); + } + + /** {@inheritDoc} */ + protected void writeEnd(OutputStream os) throws IOException { + final byte[] endData = new byte[] { + (byte)0x93, // ID + 0x00, // Length + }; + os.write(endData); + } + + /** + * Helper method to return the image encoding parameter. + * + * @return byte[] The data stream. + */ + private byte[] getImageEncodingParameter() { + final byte[] encodingData = new byte[] { + (byte)0x95, // ID + 0x02, // Length + encoding, + 0x01, // RECID + }; + return encodingData; + } + + /** + * Helper method to return the external algorithm parameter. + * + * @return byte[] The data stream. + */ + private byte[] getExternalAlgorithmParameter() { + if (encoding == (byte)0x83 && compression != 0) { + final byte[] extAlgData = new byte[] { + (byte)0x95, // ID + 0x00, // Length + 0x10, // ALGTYPE = Compression Algorithm + 0x00, // Reserved + (byte)0x83, // COMPRID = JPEG + 0x00, // Reserved + 0x00, // Reserved + 0x00, // Reserved + compression, // MARKER + 0x00, // Reserved + 0x00, // Reserved + 0x00, // Reserved + }; + extAlgData[1] = (byte)(extAlgData.length - 2); + return extAlgData; + } + return new byte[0]; + } + + /** + * Helper method to return the image encoding parameter. + * + * @return byte[] The data stream. + */ + private byte[] getImageIDESizeParameter() { + final byte[] ideSizeData = new byte[] { + (byte)0x96, // ID + 0x01, // Length + size, + }; + return ideSizeData; + } + + /** + * Helper method to return the external algorithm parameter. + * + * @return byte[] The data stream. + */ + private byte[] getIDEStructureParameter() { + if (colorModel != 0 && size == 24) { + final byte bits = (byte)(size / 3); + final byte[] ideStructData = new byte[] { + (byte)0x9B, // ID + 0x00, // Length + 0x00, // FLAGS + 0x00, // Reserved + colorModel, // COLOR MODEL + 0x00, // Reserved + 0x00, // Reserved + 0x00, // Reserved + bits, + bits, + bits, + }; + ideStructData[1] = (byte)(ideStructData.length - 2); + return ideStructData; + } + return new byte[0]; + } + +} diff --git a/src/java/org/apache/fop/afp/ioca/ImageInputDescriptor.java b/src/java/org/apache/fop/afp/ioca/ImageInputDescriptor.java new file mode 100644 index 000000000..f3351933c --- /dev/null +++ b/src/java/org/apache/fop/afp/ioca/ImageInputDescriptor.java @@ -0,0 +1,138 @@ +/* + * 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.ioca; + +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.fop.afp.modca.AbstractAFPObject; +import org.apache.fop.afp.util.BinaryUtils; + +/** + * The IM Image Input Descriptor structured field contains the + * descriptor data for an IM image data object. This data specifies + * the resolution, size, and color of the IM image. + */ +public class ImageInputDescriptor extends AbstractAFPObject { + + /** + * The resolution of the raster image (default 240) + */ + private int resolution = 240; + + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + + byte[] data = new byte[45]; + copySF(data, Type.DESCRIPTOR, Category.IM_IMAGE); + + data[1] = 0x00; // length + data[2] = 0x2C; + + // Constant data. + data[9] = 0x00; + data[10] = 0x00; + data[11] = 0x09; + data[12] = 0x60; + data[13] = 0x09; + data[14] = 0x60; + data[15] = 0x00; + data[16] = 0x00; + data[17] = 0x00; + data[18] = 0x00; + data[19] = 0x00; + data[20] = 0x00; + + // X Base (Fixed x00) + data[21] = 0x00; + // Y Base (Fixed x00) + data[22] = 0x00; + + byte[] imagepoints = BinaryUtils.convert(resolution * 10, 2); + + /** + * Specifies the number of image points per unit base for the X axis + * of the image. This value is ten times the resolution of the image + * in the X direction. + */ + data[23] = imagepoints[0]; + data[24] = imagepoints[1]; + + /** + * Specifies the number of image points per unit base for the Y axis + * of the image. This value is ten times the resolution of the image + * in the Y direction. + */ + data[25] = imagepoints[0]; + data[26] = imagepoints[1]; + + /** + * Specifies the extent in the X direction, in image points, of an + * non-celled (simple) image. + */ + data[27] = 0x00; + data[28] = 0x01; + + /** + * Specifies the extent in the Y direction, in image points, of an + * non-celled (simple) image. + */ + data[29] = 0x00; + data[30] = 0x01; + + // Constant Data + data[31] = 0x00; + data[32] = 0x00; + data[33] = 0x00; + data[34] = 0x00; + data[35] = 0x2D; + data[36] = 0x00; + + // Default size of image cell in X direction + data[37] = 0x00; + data[38] = 0x01; + + // Default size of image cell in Y direction + data[39] = 0x00; + data[40] = 0x01; + + // Constant Data + data[41] = 0x00; + data[42] = 0x01; + + // Image Color + data[43] = (byte)0xFF; + data[44] = (byte)0xFF; + + os.write(data); + } + + /** + * Sets the resolution information for the raster image + * the default value is a resolution of 240 dpi. + * + * @param resolution The resolution value + */ + public void setResolution(int resolution) { + this.resolution = resolution; + } + +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/ioca/ImageOutputControl.java b/src/java/org/apache/fop/afp/ioca/ImageOutputControl.java new file mode 100644 index 000000000..8574f445b --- /dev/null +++ b/src/java/org/apache/fop/afp/ioca/ImageOutputControl.java @@ -0,0 +1,200 @@ +/* + * 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.ioca; + +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.fop.afp.modca.AbstractAFPObject; +import org.apache.fop.afp.util.BinaryUtils; + +/** + * The IM Image Output Control structured field specifies the position and + * orientation of the IM image object area and the mapping of the image points + * to presentation device pels. + * + */ +public class ImageOutputControl extends AbstractAFPObject { + + /** + * The orientation of the image + */ + private int orientation = 0; + + /** + * Specifies the offset, along the X-axis, of the IM image object area + * origin to the origin of the including page + */ + private int xCoord = 0; + + /** + * Specifies the offset, along the Y-axis, of the IM image object area + * origin to the origin of the including page + */ + private int yCoord = 0; + + /** + * Map an image point to a single presentation device + */ + private boolean singlePoint = true; + + /** + * Constructor for the ImageOutputControl The x parameter specifies the + * offset, along the X-axis, of the IM image object area origin to the + * origin of the including page and the y parameter specifies the offset + * along the Y-axis. The offset is specified in image points and is resolved + * using the units of measure specified for the image in the IID structured + * field. + * + * @param x + * The X-axis offset. + * @param y + * The Y-axis offset. + */ + public ImageOutputControl(int x, int y) { + xCoord = x; + yCoord = y; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + + byte[] data = new byte[33]; + + data[0] = 0x5A; + data[1] = 0x00; + data[2] = 0x20; + data[3] = (byte) 0xD3; + data[4] = (byte) 0xA7; + data[5] = (byte) 0x7B; + data[6] = 0x00; + data[7] = 0x00; + data[8] = 0x00; + + // XoaOset + byte[] x1 = BinaryUtils.convert(xCoord, 3); + data[9] = x1[0]; + data[10] = x1[1]; + data[11] = x1[2]; + + // YoaOset + byte[] x2 = BinaryUtils.convert(yCoord, 3); + data[12] = x2[0]; + data[13] = x2[1]; + data[14] = x2[2]; + + switch (orientation) { + case 0: + // 0 and 90 degrees respectively + data[15] = 0x00; + data[16] = 0x00; + data[17] = 0x2D; + data[18] = 0x00; + break; + case 90: + // 90 and 180 degrees respectively + data[15] = 0x2D; + data[16] = 0x00; + data[17] = 0x5A; + data[18] = 0x00; + break; + case 180: + // 180 and 270 degrees respectively + data[15] = 0x5A; + data[16] = 0x00; + data[17] = (byte) 0x87; + data[18] = 0x00; + break; + case 270: + // 270 and 0 degrees respectively + data[15] = (byte) 0x87; + data[16] = 0x00; + data[17] = 0x00; + data[18] = 0x00; + break; + default: + // 0 and 90 degrees respectively + data[15] = 0x00; + data[16] = 0x00; + data[17] = 0x2D; + data[18] = 0x00; + break; + + } + + // Constant Data + data[19] = 0x00; + data[20] = 0x00; + data[21] = 0x00; + data[22] = 0x00; + data[23] = 0x00; + data[24] = 0x00; + data[25] = 0x00; + data[26] = 0x00; + + if (singlePoint) { + data[27] = 0x03; + data[28] = (byte) 0xE8; + data[29] = 0x03; + data[30] = (byte) 0xE8; + } else { + data[27] = 0x07; + data[28] = (byte) 0xD0; + data[29] = 0x07; + data[30] = (byte) 0xD0; + } + + // Constant Data + data[31] = (byte) 0xFF; + data[32] = (byte) 0xFF; + + os.write(data); + } + + /** + * Sets the orientation which specifies the amount of clockwise rotation of + * the IM image object area. + * + * @param orientation + * The orientation to set. + */ + public void setOrientation(int orientation) { + + if (orientation == 0 || orientation == 90 || orientation == 180 + || orientation == 270) { + this.orientation = orientation; + } else { + throw new IllegalArgumentException( + "The orientation must be one of the values 0, 90, 180, 270"); + } + } + + /** + * Sets the singlepoint, if true map an image point to a single presentation + * device pel in the IM image object area. If false map an image point to + * two presentation device pels in the IM image object area (double-dot) + * + * @param singlepoint + * Use the singlepoint basis when true. + */ + public void setSinglepoint(boolean singlepoint) { + singlePoint = singlepoint; + } +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/ioca/ImageRasterData.java b/src/java/org/apache/fop/afp/ioca/ImageRasterData.java new file mode 100644 index 000000000..115472bd8 --- /dev/null +++ b/src/java/org/apache/fop/afp/ioca/ImageRasterData.java @@ -0,0 +1,77 @@ +/* + * 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.ioca; + +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; + +/** + * Contains the image points that define the IM image raster pattern. + * + * A raster pattern is the array of presentation device pels that forms + * the image. The image data is uncompressed. Bits are grouped into + * bytes and are ordered from left to right within each byte. Each bit + * in the image data represents an image point and is mapped to + * presentation device pels as specified in the IOC structured field. + * A bit with value B'1' indicates a significant image point; a bit + * with value B'0' indicates an insignificant image point. + * Image points are recorded from left to right in rows that represents + * scan lines (X direction), and rows representing scan lines are + * recorded from top to bottom (Y direction). When the image is + * presented, all image points in a row are presented before any + * image points in the next sequential row are presented, and all rows + * have the same number of image points. If the total number of image + * points is not a multiple of 8, the last byte of the image data is + * padded to a byte boundary. The padding bits do not represent image + * points and are ignored by presentation devices. + */ +public class ImageRasterData extends AbstractAFPObject { + + /** + * 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) { + this.rasterData = data; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = new byte[9]; + copySF(data, Type.DATA, Category.IM_IMAGE); + // The size of the structured field + byte[] len = BinaryUtils.convert(rasterData.length + 8, 2); + data[1] = len[0]; + data[2] = len[1]; + os.write(data); + + os.write(rasterData); + } +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/ioca/ImageRasterPattern.java b/src/java/org/apache/fop/afp/ioca/ImageRasterPattern.java new file mode 100644 index 000000000..789eeb950 --- /dev/null +++ b/src/java/org/apache/fop/afp/ioca/ImageRasterPattern.java @@ -0,0 +1,759 @@ +/* + * 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.ioca; + +/** + * Raster data is a grid of cells covering an area of interest. + * Each pixel, the smallest unit of information in the grid, displays + * a unique attribute. This static class generates raster data for different + * shades of grey (betweeen 0 and 16) the lower the number being the + * darker the shade. The image data dimensions are 64 x 8. + */ +public class ImageRasterPattern { + + /** + * The Raster Pattern for Greyscale 16 + */ + private static final byte[] GREYSCALE16 = new byte[] { + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + }; + + /** + * The Raster Pattern for Greyscale 15 + */ + private static final byte[] GREYSCALE15 = new byte[] { + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + }; + + /** + * The Raster Pattern for Greyscale 14 + */ + private static final byte[] GREYSCALE14 = new byte[] { + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x44, + 0x44, + 0x44, + 0x44, + 0x44, + 0x44, + 0x44, + 0x44, + }; + + + /** + * The Raster Pattern for Greyscale 13 + */ + private static final byte[] GREYSCALE13 = new byte[] { + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + }; + + /** + * The Raster Pattern for Greyscale 12 + */ + private static final byte[] GREYSCALE12 = new byte[] { + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + }; + + /** + * The Raster Pattern for Greyscale 11 + */ + private static final byte[] GREYSCALE11 = new byte[] { + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x44, + 0x44, + 0x44, + 0x44, + 0x44, + 0x44, + 0x44, + 0x44, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + }; + + /** + * The Raster Pattern for Greyscale 10 + */ + private static final byte[] GREYSCALE10 = new byte[] { + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + 0x44, + 0x44, + 0x44, + 0x44, + 0x44, + 0x44, + 0x44, + 0x44, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + }; + + /** + * The Raster Pattern for Greyscale 9 + */ + private static final byte[] GREYSCALE09 = new byte[] { + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + }; + + /** + * The Raster Pattern for Greyscale 8 + */ + private static final byte[] GREYSCALE08 = new byte[] { + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + }; + + + /** + * The Raster Pattern for Greyscale 7 + */ + private static final byte[] GREYSCALE07 = new byte[] { + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + }; + + + /** + * The Raster Pattern for Greyscale 6 + */ + private static final byte[] GREYSCALE06 = new byte[] { + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + (byte)0xEE, + (byte)0xEE, + (byte)0xEE, + (byte)0xEE, + (byte)0xEE, + (byte)0xEE, + (byte)0xEE, + (byte)0xEE, + }; + + /** + * The Raster Pattern for Greyscale 5 + */ + private static final byte[] GREYSCALE05 = new byte[] { + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xEE, + (byte)0xEE, + (byte)0xEE, + (byte)0xEE, + (byte)0xEE, + (byte)0xEE, + (byte)0xEE, + (byte)0xEE, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + }; + + + /** + * The Raster Pattern for Greyscale 4 + */ + private static final byte[] GREYSCALE04 = new byte[] { + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xAA, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + }; + + /** + * The Raster Pattern for Greyscale 3 + */ + private static final byte[] GREYSCALE03 = new byte[] { + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + 0x55, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xBB, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + }; + + /** + * The Raster Pattern for Greyscale 2 + */ + private static final byte[] GREYSCALE02 = new byte[] { + 0x77, + 0x77, + 0x77, + 0x77, + 0x77, + 0x77, + 0x77, + 0x77, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xDD, + (byte)0xDD, + (byte)0xDD, + (byte)0xDD, + (byte)0xDD, + (byte)0xDD, + (byte)0xDD, + (byte)0xDD, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + }; + + + /** + * The Raster Pattern for Greyscale 1 + */ + private static final byte[] GREYSCALE01 = new byte[] { + 0x77, + 0x77, + 0x77, + 0x77, + 0x77, + 0x77, + 0x77, + 0x77, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + }; + + + /** + * The Raster Pattern for Greyscale 00 + */ + private static final byte[] GREYSCALE00 = new byte[] { + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + (byte)0xFF, + }; + + /** + * Static method to return the raster image data for the + * grey scale specified. The scale should be between 0 (darkest) + * and 16 (lightest). + * @param greyscale The grey scale value (0 - 16) + * @return the raster data byte array for the given greyscale value + */ + public static byte[] getRasterData(int greyscale) { + + int repeat = 16; + + byte[] greypattern = new byte[32]; + byte[] rasterdata = new byte[32 * repeat]; + + switch (greyscale) { + case 0: + System.arraycopy(GREYSCALE00, 0, greypattern, 0, 32); + break; + case 1: + System.arraycopy(GREYSCALE01, 0, greypattern, 0, 32); + break; + case 2: + System.arraycopy(GREYSCALE02, 0, greypattern, 0, 32); + break; + case 3: + System.arraycopy(GREYSCALE03, 0, greypattern, 0, 32); + break; + case 4: + System.arraycopy(GREYSCALE04, 0, greypattern, 0, 32); + break; + case 5: + System.arraycopy(GREYSCALE05, 0, greypattern, 0, 32); + break; + case 6: + System.arraycopy(GREYSCALE06, 0, greypattern, 0, 32); + break; + case 7: + System.arraycopy(GREYSCALE07, 0, greypattern, 0, 32); + break; + case 8: + System.arraycopy(GREYSCALE08, 0, greypattern, 0, 32); + break; + case 9: + System.arraycopy(GREYSCALE09, 0, greypattern, 0, 32); + break; + case 10: + System.arraycopy(GREYSCALE10, 0, greypattern, 0, 32); + break; + case 11: + System.arraycopy(GREYSCALE11, 0, greypattern, 0, 32); + break; + case 12: + System.arraycopy(GREYSCALE12, 0, greypattern, 0, 32); + break; + case 13: + System.arraycopy(GREYSCALE13, 0, greypattern, 0, 32); + break; + case 14: + System.arraycopy(GREYSCALE14, 0, greypattern, 0, 32); + break; + case 15: + System.arraycopy(GREYSCALE15, 0, greypattern, 0, 32); + break; + case 16: + System.arraycopy(GREYSCALE16, 0, greypattern, 0, 32); + break; + default : + System.arraycopy(GREYSCALE00, 0, greypattern, 0, 32); + break; + } + + for (int i = 0; i < repeat; i++) { + System.arraycopy(greypattern, 0, rasterdata, i * 32, 32); + } + return rasterdata; + } +} diff --git a/src/java/org/apache/fop/afp/ioca/ImageSegment.java b/src/java/org/apache/fop/afp/ioca/ImageSegment.java new file mode 100644 index 000000000..eab8b931a --- /dev/null +++ b/src/java/org/apache/fop/afp/ioca/ImageSegment.java @@ -0,0 +1,161 @@ +/* + * 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.ioca; + +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.fop.afp.Factory; +import org.apache.fop.afp.modca.AbstractNamedAFPObject; + +/** + * An Image Segment is represented by a set of self-defining fields, fields + * that describe their own contents. It starts with a Begin Segment, and + * ends with an End Segment. + * + * Between the Begin Segment and End Segment is the image information to + * be processed, called the Image Content. + * + * Only one Image Content can exist within a single IOCA Image Segment. + */ +public class ImageSegment extends AbstractNamedAFPObject { + + /** + * The ImageContent for the image segment + */ + private ImageContent imageContent = null; + + private final Factory factory; + + /** + * Constructor for the image segment with the specified name, + * the name must be a fixed length of eight characters. + * @param factory the object factory + * + * @param name the name of the image. + */ + public ImageSegment(Factory factory, String name) { + super(name); + this.factory = factory; + } + + private ImageContent getImageContent() { + if (imageContent == null) { + this.imageContent = factory.createImageContent(); + } + return imageContent; + } + + /** + * Sets the image size parameters resolution, hsize and vsize. + * + * @param hsize The horizontal size of the image. + * @param vsize The vertical size of the image. + * @param hresol The horizontal resolution of the image. + * @param vresol The vertical resolution of the image. + */ + public void setImageSize(int hsize, int vsize, int hresol, int vresol) { + ImageSizeParameter imageSizeParameter + = factory.createImageSizeParameter(hsize, vsize, hresol, vresol); + getImageContent().setImageSizeParameter(imageSizeParameter); + } + + /** + * Sets the image encoding. + * + * @param encoding The image encoding. + */ + public void setEncoding(byte encoding) { + getImageContent().setImageEncoding(encoding); + } + + /** + * Sets the image compression. + * + * @param compression The image compression. + */ + public void setCompression(byte compression) { + getImageContent().setImageCompression(compression); + } + + /** + * Sets the image IDE size. + * + * @param size The IDE size. + */ + public void setIDESize(byte size) { + getImageContent().setImageIDESize(size); + } + + /** + * Sets the image IDE color model. + * + * @param colorModel the IDE color model. + */ + public void setIDEColorModel(byte colorModel) { + getImageContent().setImageIDEColorModel(colorModel); + } + + /** + * Set the data image data. + * + * @param data the image data + */ + public void setData(byte[] data) { + getImageContent().setImageData(data); + } + + /** {@inheritDoc} */ + public void writeContent(OutputStream os) throws IOException { + if (imageContent != null) { + imageContent.writeToStream(os); + } + } + + private static final int NAME_LENGTH = 4; + + /** {@inheritDoc} */ + protected int getNameLength() { + return NAME_LENGTH; + } + + /** {@inheritDoc} */ + protected void writeStart(OutputStream os) throws IOException { + byte[] nameBytes = getNameBytes(); + byte[] data = new byte[] { + 0x70, // ID + 0x04, // Length + nameBytes[0], // Name byte 1 + nameBytes[1], // Name byte 2 + nameBytes[2], // Name byte 3 + nameBytes[3], // Name byte 4 + }; + os.write(data); + } + + /** {@inheritDoc} */ + protected void writeEnd(OutputStream os) throws IOException { + byte[] data = new byte[] { + 0x71, // ID + 0x00, // Length + }; + os.write(data); + } +} diff --git a/src/java/org/apache/fop/afp/ioca/ImageSizeParameter.java b/src/java/org/apache/fop/afp/ioca/ImageSizeParameter.java new file mode 100644 index 000000000..38e7d9e56 --- /dev/null +++ b/src/java/org/apache/fop/afp/ioca/ImageSizeParameter.java @@ -0,0 +1,88 @@ +/* + * 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.ioca; + +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.fop.afp.modca.AbstractAFPObject; +import org.apache.fop.afp.util.BinaryUtils; + +/** + * Describes the measurement characteristics of the image when it is created. + */ +public class ImageSizeParameter extends AbstractAFPObject { + + private int hSize = 0; + private int vSize = 0; + private int hRes = 0; + private int vRes = 0; + + /** + * Constructor for a ImageSizeParameter for the specified + * resolution, hsize and vsize. + * + * @param hsize The horizontal size of the image. + * @param vsize The vertical size of the image. + * @param hresol The horizontal resolution of the image. + * @param vresol The vertical resolution of the image. + */ + public ImageSizeParameter(int hsize, int vsize, int hresol, int vresol) { + this.hSize = hsize; + this.vSize = vsize; + this.hRes = hresol; + this.vRes = vresol; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = new byte[] { + (byte)0x94, // ID = Image Size Parameter + 0x09, // Length + 0x00, // Unit base - 10 Inches + 0x00, // HRESOL + 0x00, // + 0x00, // VRESOL + 0x00, // + 0x00, // HSIZE + 0x00, // + 0x00, // VSIZE + 0x00, // + }; + + byte[] x = BinaryUtils.convert(hRes, 2); + data[3] = x[0]; + data[4] = x[1]; + + byte[] y = BinaryUtils.convert(vRes, 2); + data[5] = y[0]; + data[6] = y[1]; + + byte[] w = BinaryUtils.convert(hSize, 2); + data[7] = w[0]; + data[8] = w[1]; + + byte[] h = BinaryUtils.convert(vSize, 2); + data[9] = h[0]; + data[10] = h[1]; + + os.write(data); + } +} diff --git a/src/java/org/apache/fop/afp/modca/AbstractAFPObject.java b/src/java/org/apache/fop/afp/modca/AbstractAFPObject.java new file mode 100644 index 000000000..9e1e107f3 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/AbstractAFPObject.java @@ -0,0 +1,244 @@ +/* + * 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 org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.fop.afp.Streamable; + +/** + * This is the base class for all data stream objects. Page objects are + * responsible for building and generating the binary datastream in an + * AFP format. + */ +public abstract class AbstractAFPObject implements Streamable { + + /** Static logging instance */ + protected static final Log log = LogFactory.getLog("org.apache.xmlgraphics.afp.modca"); + + /** the structured field class id */ + protected static final byte SF_CLASS = (byte)0xD3; + + private static final byte[] SF_HEADER = new byte[] { + 0x5A, // Structured field identifier + 0x00, // Length byte 1 + 0x10, // Length byte 2 + SF_CLASS, // Structured field id byte 1 + (byte) 0x00, // Structured field id byte 2 + (byte) 0x00, // Structured field id byte 3 + 0x00, // Flags + 0x00, // Reserved + 0x00, // Reserved + }; + + /** + * Copies the template structured field data array to the given byte array + * + * @param data the structured field data byte array + * @param type the type code + * @param category the category code + */ + protected void copySF(byte[] data, byte type, byte category) { + copySF(data, SF_CLASS, type, category); + } + + /** + * Copies the template structured field data array to the given byte array + * + * @param data the structured field data byte array + * @param clazz the class code + * @param type the type code + * @param category the category code + */ + protected static void copySF(byte[] data, byte clazz, byte type, byte category) { + System.arraycopy(SF_HEADER, 0, data, 0, SF_HEADER.length); + data[3] = clazz; + data[4] = type; + data[5] = category; + } + + /** + * Help method to write a set of AFPObjects to the AFP datastream. + * + * @param objects a list of AFPObjects + * @param os The stream to write to + * @throws java.io.IOException an I/O exception of some sort has occurred. + */ + protected void writeObjects(Collection/**/ objects, OutputStream os) + throws IOException { + if (objects != null && objects.size() > 0) { + Iterator it = objects.iterator(); + while (it.hasNext()) { + Object object = it.next(); + if (object instanceof Streamable) { + ((Streamable)object).writeToStream(os); + it.remove(); // once written, immediately remove the object + } + } + } + } + + /** structured field type codes */ + public interface Type { + + /** Attribute */ + byte ATTRIBUTE = (byte)0x0A; + + /** Copy Count */ + byte COPY_COUNT = (byte)0xA2; + + /** Descriptor */ + byte DESCRIPTOR = (byte)0xA6; + + /** Control */ + byte CONTROL = (byte)0xA7; + + /** Begin */ + byte BEGIN = (byte)0xA8; + + /** End */ + byte END = (byte)0xA9; + + /** Map */ + byte MAP = (byte)0xAB; + + /** Position */ + byte POSITION = (byte)0xAC; + + /** Process */ + byte PROCESS = (byte)0xAD; + + /** Include */ + byte INCLUDE = (byte)0xAF; + + /** Table */ + byte TABLE = (byte)0xB0; + + /** Migration */ + byte MIGRATION = (byte)0xB1; + + /** Variable */ + byte VARIABLE = (byte)0xB2; + + /** Link */ + byte LINK = (byte)0xB4; + + /** Data */ + byte DATA = (byte)0xEE; + } + + /** structured field category codes */ + public interface Category { + + /** Page Segment */ + byte PAGE_SEGMENT = (byte)0x5F; + + /** Object Area */ + byte OBJECT_AREA = (byte)0x6B; + + /** Color Attribute Table */ + byte COLOR_ATTRIBUTE_TABLE = (byte)0x77; + + /** IM Image */ + byte IM_IMAGE = (byte)0x7B; + + /** Medium */ + byte MEDIUM = (byte)0x88; + + /** Coded Font */ + byte CODED_FONT = (byte)0x8A; + + /** Process Element */ + byte PROCESS_ELEMENT = (byte)0x90; + + /** Object Container */ + byte OBJECT_CONTAINER = (byte)0x92; + + /** Presentation Text */ + byte PRESENTATION_TEXT = (byte)0x9B; + + /** Index */ + byte INDEX = (byte)0xA7; + + /** Document */ + byte DOCUMENT = (byte)0xA8; + + /** Page Group */ + byte PAGE_GROUP = (byte)0xAD; + + /** Page */ + byte PAGE = (byte)0xAF; + + /** Graphics */ + byte GRAPHICS = (byte)0xBB; + + /** Data Resource */ + byte DATA_RESOURCE = (byte)0xC3; + + /** Document Environment Group (DEG) */ + byte DOCUMENT_ENVIRONMENT_GROUP = (byte)0xC4; + + /** Resource Group */ + byte RESOURCE_GROUP = (byte)0xC6; + + /** Object Environment Group (OEG) */ + byte OBJECT_ENVIRONMENT_GROUP = (byte)0xC7; + + /** Active Environment Group (AEG) */ + byte ACTIVE_ENVIRONMENT_GROUP = (byte)0xC9; + + /** Medium Map */ + byte MEDIUM_MAP = (byte)0xCC; + + /** Form Map */ + byte FORM_MAP = (byte)0xCD; + + /** Name Resource */ + byte NAME_RESOURCE = (byte)0xCE; + + /** Page Overlay */ + byte PAGE_OVERLAY = (byte)0xD8; + + /** Resource Environment Group (REG) */ + byte RESOURCE_ENVIROMENT_GROUP = (byte)0xD9; + + /** Overlay */ + byte OVERLAY = (byte)0xDF; + + /** Data Suppression */ + byte DATA_SUPRESSION = (byte)0xEA; + + /** Bar Code */ + byte BARCODE = (byte)0xEB; + + /** No Operation */ + byte NO_OPERATION = (byte)0xEE; + + /** Image */ + byte IMAGE = (byte)0xFB; + } + +} + diff --git a/src/java/org/apache/fop/afp/modca/AbstractDataObject.java b/src/java/org/apache/fop/afp/modca/AbstractDataObject.java new file mode 100644 index 000000000..c7b987a9e --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/AbstractDataObject.java @@ -0,0 +1,108 @@ +/* + * 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 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.Factory; + +/** + * Abstract base class used by the ImageObject and GraphicsObject which both + * have define an ObjectEnvironmentGroup + */ +public abstract class AbstractDataObject extends AbstractNamedAFPObject { + + /** the object environment group */ + protected ObjectEnvironmentGroup objectEnvironmentGroup = null; + + /** the object factory */ + protected final Factory factory; + + /** + * Named constructor + * + * @param factory the object factory + * @param name data object name + */ + public AbstractDataObject(Factory factory, String name) { + super(name); + this.factory = factory; + } + + /** + * Sets the object view port (area position and size). + * + * @param dataObjectInfo + * the object area info + */ + public void setViewport(AFPDataObjectInfo dataObjectInfo) { + AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo(); + + // object area descriptor + int width = objectAreaInfo.getWidth(); + int height = objectAreaInfo.getHeight(); + int widthRes = objectAreaInfo.getWidthRes(); + int heightRes = objectAreaInfo.getHeightRes(); + ObjectAreaDescriptor objectAreaDescriptor + = factory.createObjectAreaDescriptor(width, height, widthRes, heightRes); + getObjectEnvironmentGroup().setObjectAreaDescriptor(objectAreaDescriptor); + + // object area position + AFPResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); + AFPResourceLevel resourceLevel = resourceInfo.getLevel(); + ObjectAreaPosition objectAreaPosition = null; + if (resourceLevel.isInline()) { + int x = objectAreaInfo.getX(); + int y = objectAreaInfo.getY(); + int rotation = objectAreaInfo.getRotation(); + objectAreaPosition = factory.createObjectAreaPosition(x, y, rotation); + } else { + // positional values are specified in the oaOffset of the include object + objectAreaPosition = factory.createObjectAreaPosition(0, 0, 0); + } + getObjectEnvironmentGroup().setObjectAreaPosition(objectAreaPosition); + } + + /** + * Gets the ObjectEnvironmentGroup + * + * @return the object environment group + */ + public ObjectEnvironmentGroup getObjectEnvironmentGroup() { + if (objectEnvironmentGroup == null) { + this.objectEnvironmentGroup = factory.createObjectEnvironmentGroup(); + } + return objectEnvironmentGroup; + } + + /** {@inheritDoc} */ + protected void writeContent(OutputStream os) throws IOException { + super.writeContent(os); // write triplets + if (objectEnvironmentGroup != null) { + objectEnvironmentGroup.writeToStream(os); + } + } + +} diff --git a/src/java/org/apache/fop/afp/modca/AbstractDescriptor.java b/src/java/org/apache/fop/afp/modca/AbstractDescriptor.java new file mode 100644 index 000000000..f3734cfb7 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/AbstractDescriptor.java @@ -0,0 +1,64 @@ +/* + * 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; + +/** + * Base class for AFP descriptor objects + */ +public abstract class AbstractDescriptor extends AbstractStructuredAFPObject { + /** width of this descriptor */ + protected int width = 0; + /** height of this descriptor */ + protected int height = 0; + /** width resolution of this descriptor */ + protected int widthRes = 0; + /** height resolution of this descriptor */ + protected int heightRes = 0; + + /** + * Default constructor + */ + public AbstractDescriptor() { + } + + /** + * Constructor a PresentationTextDescriptor for the specified + * width and height. + * + * @param width The width of the page. + * @param height The height of the page. + * @param widthRes The width resolution of the page. + * @param heightRes The height resolution of the page. + */ + public AbstractDescriptor(int width, int height, int widthRes, int heightRes) { + this.width = width; + this.height = height; + this.widthRes = widthRes; + this.heightRes = heightRes; + } + + /** {@inheritDoc} */ + public String toString() { + return "width=" + width + + ", height=" + height + + ", widthRes=" + widthRes + + ", heightRes=" + heightRes; + } +} diff --git a/src/java/org/apache/fop/afp/modca/AbstractEnvironmentGroup.java b/src/java/org/apache/fop/afp/modca/AbstractEnvironmentGroup.java new file mode 100644 index 000000000..a58bba1f0 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/AbstractEnvironmentGroup.java @@ -0,0 +1,101 @@ +/* + * 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.List; + +/** + * A base class that encapsulates common features of + * ActiveEnvironmentGroup and ResourceEnvironmentGroup + */ +public abstract class AbstractEnvironmentGroup extends AbstractNamedAFPObject { + + /** + * The collection of MapPageOverlay objects + */ + protected List mapPageOverlays = null; + + /** + * Main constructor + * + * @param name the object name + */ + public AbstractEnvironmentGroup(String name) { + super(name); + } + + private List getMapPageOverlays() { + if (mapPageOverlays == null) { + mapPageOverlays = new java.util.ArrayList(); + } + return mapPageOverlays; + } + + /** + * Actually creates the MPO object. + * Also creates the supporting object (an IPO) + * + * @param name the name of the overlay to be used + */ + public void createOverlay(String name) { + MapPageOverlay mpo = getCurrentMapPageOverlay(); + if (mpo == null) { + mpo = new MapPageOverlay(); + getMapPageOverlays().add(mpo); + } + + try { + mpo.addOverlay(name); + } catch (MaximumSizeExceededException msee) { + mpo = new MapPageOverlay(); + getMapPageOverlays().add(mpo); + try { + mpo.addOverlay(name); + } catch (MaximumSizeExceededException ex) { + // Should never happen (but log just in case) + log.error("createOverlay():: resulted in a MaximumSizeExceededException"); + } + } + } + + /** + * Getter method for the most recent MapPageOverlay added to the + * Active Environment Group (returns null if no MapPageOverlay exist) + * + * @return the most recent Map Coded Font + */ + private MapPageOverlay getCurrentMapPageOverlay() { + if (mapPageOverlays != null && mapPageOverlays.size() > 0) { + return (MapPageOverlay) mapPageOverlays.get(mapPageOverlays.size() - 1); + } else { + return null; + } + } + + /** {@inheritDoc} */ + protected void writeContent(OutputStream os) throws IOException { + super.writeContent(os); + if (mapPageOverlays != null) { + writeObjects(mapPageOverlays, os); + } + } +} diff --git a/src/java/org/apache/fop/afp/modca/AbstractNamedAFPObject.java b/src/java/org/apache/fop/afp/modca/AbstractNamedAFPObject.java new file mode 100644 index 000000000..de02f13d3 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/AbstractNamedAFPObject.java @@ -0,0 +1,113 @@ +/* + * 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.UnsupportedEncodingException; + +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 { + + private static final int DEFAULT_NAME_LENGTH = 8; + + /** + * The actual name of the object + */ + protected String name = null; + + /** + * Default constructor + */ + protected AbstractNamedAFPObject() { + } + + /** + * Constructor for the ActiveEnvironmentGroup, this takes a + * name parameter which should be 8 characters long. + * + * @param name the object name + */ + protected AbstractNamedAFPObject(String name) { + this.name = name; + } + + /** + * Returns the name length + * + * @return the name length + */ + protected int getNameLength() { + return DEFAULT_NAME_LENGTH; + } + + /** + * Returns the name as a byte array in EBCIDIC encoding + * + * @return the name as a byte array in EBCIDIC encoding + */ + protected byte[] getNameBytes() { + int afpNameLen = getNameLength(); + int nameLen = name.length(); + if (nameLen < afpNameLen) { + name = (name + " ").substring(0, afpNameLen); + } else if (name.length() > afpNameLen) { + String truncatedName = name.substring(nameLen - afpNameLen, nameLen); + log.warn("Constructor:: name '" + name + "'" + + " truncated to " + afpNameLen + " chars" + + " ('" + truncatedName + "')"); + name = truncatedName; + } + byte[] nameBytes = null; + try { + nameBytes = name.getBytes(AFPConstants.EBCIDIC_ENCODING); + } catch (UnsupportedEncodingException usee) { + nameBytes = name.getBytes(); + log.warn( + "Constructor:: UnsupportedEncodingException translating the name " + + name); + } + return nameBytes; + } + + /** {@inheritDoc} */ + protected void copySF(byte[] data, byte type, byte category) { + super.copySF(data, type, category); + byte[] nameData = getNameBytes(); + System.arraycopy(nameData, 0, data, 9, nameData.length); + } + + /** + * Returns the name of this object + * + * @return the name of this object + */ + public String getName() { + return name; + } + + /** {@inheritDoc} */ + public String toString() { + return getName(); + } +} diff --git a/src/java/org/apache/fop/afp/modca/AbstractPageObject.java b/src/java/org/apache/fop/afp/modca/AbstractPageObject.java new file mode 100644 index 000000000..d7252c390 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/AbstractPageObject.java @@ -0,0 +1,346 @@ +/* + * 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.List; + +import org.apache.fop.afp.AFPLineDataInfo; +import org.apache.fop.afp.AFPTextDataInfo; +import org.apache.fop.afp.Factory; +import org.apache.fop.afp.fonts.AFPFont; + +/** + * Pages contain the data objects that comprise a presentation document. Each + * page has a set of data objects associated with it. Each page within a + * document is independent from any other page, and each must establish its own + * environment parameters. + * + * The page is the level in the document component hierarchy that is used for + * printing or displaying a document's content. The data objects contained in + * the page envelope in the data stream are presented when the page is + * presented. Each data object has layout information associated with it that + * directs the placement and orientation of the data on the page. In addition, + * each page contains layout information that specifies the measurement units, + * page width, and page depth. + * + * A page is initiated by a begin page structured field and terminated by an end + * page structured field. Structured fields that define objects and active + * environment groups or that specify attributes of the page may be encountered + * in page state. + * + */ +public abstract class AbstractPageObject extends AbstractNamedAFPObject { + + /** The active environment group for the page */ + protected ActiveEnvironmentGroup activeEnvironmentGroup = null; + + /** The current presentation text object */ + private PresentationTextObject currentPresentationTextObject = null; + + /** The list of tag logical elements */ + protected List/**/ tagLogicalElements = null; + + /** The list of the include page segments */ + protected List/**/ includePageSegments = null; + + /** The list of objects within this resource container */ + protected List/**/ objects = new java.util.ArrayList(); + + /** The page width */ + private int width; + + /** The page height */ + private int height; + + /** The page rotation */ + protected int rotation = 0; + + /** The page state */ + protected boolean complete = false; + + /** The width resolution */ + private int widthRes; + + /** The height resolution */ + private int heightRes; + + /** the object factory */ + protected final Factory factory; + + /** + * Default constructor + * + * @param factory the object factory + */ + public AbstractPageObject(Factory factory) { + this.factory = factory; + } + + /** + * Main constructor + * + * @param factory the object factory + * @param name the name of this page object + */ + public AbstractPageObject(Factory factory, String name) { + super(name); + this.factory = factory; + } + + /** + * Construct a new page object for the specified name argument, the page + * name should be an 8 character identifier. + * + * @param factory + * the object factory. + * @param name + * the name of the page. + * @param width + * the width of the page. + * @param height + * the height of the page. + * @param rotation + * the rotation of the page. + * @param widthRes + * the width resolution of the page. + * @param heightRes + * the height resolution of the page. + */ + public AbstractPageObject(Factory factory, + String name, int width, int height, int rotation, + int widthRes, int heightRes) { + super(name); + + this.factory = factory; + this.width = width; + this.height = height; + this.rotation = rotation; + this.widthRes = widthRes; + this.heightRes = heightRes; + } + + /** + * 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 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) { + getActiveEnvironmentGroup().createFont(fontReference, font, size, 0); + } + + /** + * Helper method to create a line on the current page, this method delegates + * to the presentation text object in order to construct the line. + * + * @param lineDataInfo the line data information. + */ + public void createLine(AFPLineDataInfo lineDataInfo) { + getPresentationTextObject().createLineData(lineDataInfo); + } + + /** + * Helper method to create text on the current page, this method delegates + * to the presentation text object in order to construct the text. + * + * @param textDataInfo + * the afp text data + */ + public void createText(AFPTextDataInfo textDataInfo) { + getPresentationTextObject().createTextData(textDataInfo); + } + + /** + * Helper method to mark the end of the page. This should end the control + * sequence on the current presentation text object. + */ + public void endPage() { + if (currentPresentationTextObject != null) { + currentPresentationTextObject.endControlSequence(); + } + complete = true; + } + + /** + * Ends the presentation text object + */ + protected void endPresentationObject() { + if (currentPresentationTextObject != null) { + currentPresentationTextObject.endControlSequence(); + currentPresentationTextObject = null; + } + } + + /** + * Helper method to create a presentation text object + * on the current page and to return the object. + * + * @return the presentation text object + */ + private PresentationTextObject getPresentationTextObject() { + if (currentPresentationTextObject == null) { + PresentationTextObject presentationTextObject + = factory.createPresentationTextObject(); + addObject(presentationTextObject); + this.currentPresentationTextObject = presentationTextObject; + } + return currentPresentationTextObject; + } + + /** + * Creates a TagLogicalElement on the page. + * + * @param name + * the name of the tag + * @param value + * the value of the tag + */ + public void createTagLogicalElement(String name, String value) { + TagLogicalElement tle = new TagLogicalElement(name, value); + if (tagLogicalElements == null) { + tagLogicalElements = new java.util.ArrayList/**/(); + } + tagLogicalElements.add(tle); + } + + /** + * Creates a NoOperation on the page. + * + * @param content the byte data + */ + public void createNoOperation(String content) { + addObject(new NoOperation(content)); + } + + /** + * Creates an IncludePageSegment on the current page. + * + * @param name + * the name of the page segment + * @param x + * the x coordinate of the page segment. + * @param y + * the y coordinate of the page segment. + */ + public void createIncludePageSegment(String name, int x, int y) { + IncludePageSegment ips = factory.createIncludePageSegment(name, x, y); + getIncludePageSegments().add(ips); + } + + /** + * Returns the include page segments list + * + * @return the include page segments list + */ + private List getIncludePageSegments() { + if (this.includePageSegments == null) { + this.includePageSegments = new java.util.ArrayList/**/(); + } + return this.includePageSegments; + } + + /** + * Returns the ActiveEnvironmentGroup associated with this page. + * + * @return the ActiveEnvironmentGroup object + */ + public ActiveEnvironmentGroup getActiveEnvironmentGroup() { + if (activeEnvironmentGroup == null) { + // every page object must have an ActiveEnvironmentGroup + this.activeEnvironmentGroup + = factory.createActiveEnvironmentGroup(width, height, widthRes, heightRes); + + if (rotation != 0) { + switch (rotation) { + case 90: + activeEnvironmentGroup.setObjectAreaPosition(width, 0, rotation); + break; + case 180: + activeEnvironmentGroup.setObjectAreaPosition(width, height, rotation); + break; + case 270: + activeEnvironmentGroup.setObjectAreaPosition(0, height, rotation); + break; + default: + } + } + } + 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 + * + * @return the height of the page + */ + public int getHeight() { + return height; + } + + /** + * Returns the width of the page + * + * @return the width of the page + */ + public int getWidth() { + return width; + } + + /** + * Returns the rotation of the page + * + * @return the rotation of the page + */ + public int getRotation() { + return rotation; + } + + /** {@inheritDoc} */ + protected void writeContent(OutputStream os) throws IOException { + super.writeContent(os); + writeObjects(this.objects, os); + } + + /** + * Adds an AFP object reference to this page + * + * @param obj an AFP object + */ + public void addObject(Object obj) { + objects.add(obj); + } +} diff --git a/src/java/org/apache/fop/afp/modca/AbstractPreparedAFPObject.java b/src/java/org/apache/fop/afp/modca/AbstractPreparedAFPObject.java new file mode 100644 index 000000000..10a516318 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/AbstractPreparedAFPObject.java @@ -0,0 +1,96 @@ +/* + * 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 new file mode 100644 index 000000000..9019a6acc --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/AbstractPreparedObjectContainer.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.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/AbstractResourceEnvironmentGroupContainer.java b/src/java/org/apache/fop/afp/modca/AbstractResourceEnvironmentGroupContainer.java new file mode 100644 index 000000000..baba170f7 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/AbstractResourceEnvironmentGroupContainer.java @@ -0,0 +1,99 @@ +/* + * 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 org.apache.fop.afp.Factory; + + +/** + * An abstract class which encapsulates the common features of + * Document and PageGroup resource containers + */ +public abstract class AbstractResourceEnvironmentGroupContainer + extends AbstractResourceGroupContainer { + + /** + * The resource environment group used to store complex resources + */ + protected ResourceEnvironmentGroup resourceEnvironmentGroup = null; + + /** + * Main constructor + * + * @param factory the object factory + * @param name the name of this resource container + */ + public AbstractResourceEnvironmentGroupContainer( + Factory factory, String name) { + super(factory, name); + } + + /** + * Adds a page to the resource container. + * + * @param page - the Page object + */ + public void addPage(PageObject page) { + addObject(page); + } + + /** + * Adds a PageGroup to the resource container. + * + * @param pageGroup the PageGroup object + */ + public void addPageGroup(PageGroup pageGroup) { + addObject(pageGroup); + } + + /** + * Creates an InvokeMediaMap on the page. + * + * @param name + * the name of the media map + */ + public void createInvokeMediumMap(String name) { + InvokeMediumMap invokeMediumMap = factory.createInvokeMediumMap(name); + addObject(invokeMediumMap); + } + + /** {@inheritDoc} */ + protected void writeContent(OutputStream os) throws IOException { + super.writeContent(os); + if (resourceEnvironmentGroup != null) { + resourceEnvironmentGroup.writeToStream(os); + } + } + + /** + * Returns the resource environment group + * + * @return the resource environment group + */ + protected ResourceEnvironmentGroup getResourceEnvironmentGroup() { + if (resourceEnvironmentGroup == null) { + this.resourceEnvironmentGroup = factory.createResourceEnvironmentGroup(); + } + return this.resourceEnvironmentGroup; + } +} diff --git a/src/java/org/apache/fop/afp/modca/AbstractResourceGroupContainer.java b/src/java/org/apache/fop/afp/modca/AbstractResourceGroupContainer.java new file mode 100644 index 000000000..860c6b56a --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/AbstractResourceGroupContainer.java @@ -0,0 +1,167 @@ +/* + * 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 org.apache.fop.afp.Factory; +import org.apache.fop.afp.Streamable; + + +/** + * An abstract container of resource objects + */ +public abstract class AbstractResourceGroupContainer extends AbstractPageObject +implements Streamable { + + /** The container started state */ + protected boolean started = false; + + /** the resource group object */ + protected ResourceGroup resourceGroup = null; + + /** + * Default constructor + * + * @param factory the object factory + */ + public AbstractResourceGroupContainer(Factory factory) { + super(factory); + } + + /** + * Named constructor + * + * @param factory the object factory + * @param name the name of this resource container + */ + public AbstractResourceGroupContainer(Factory factory, String name) { + super(factory, name); + } + + /** + * Construct a new page object for the specified name argument, the page + * name should be an 8 character identifier. + * + * @param factory + * the object factory + * @param name + * the name of the page. + * @param width + * the width of the page. + * @param height + * the height of the page. + * @param rotation + * the rotation of the page. + * @param widthRes + * the width resolution of the page. + * @param heightRes + * the height resolution of the page. + */ + public AbstractResourceGroupContainer(Factory factory, + String name, int width, int height, int rotation, int widthRes, int heightRes) { + super(factory, name, width, height, rotation, widthRes, heightRes); + } + + /** + * Return the number of resources in this container + * + * @return the number of resources in this container + */ + protected int getResourceCount() { + if (resourceGroup != null) { + return resourceGroup.getResourceCount(); + } + return 0; + } + + /** + * Returns true if this resource group container contains resources + * + * @return true if this resource group container contains resources + */ + protected boolean hasResources() { + return resourceGroup != null && resourceGroup.getResourceCount() > 0; + } + + /** + * Returns the resource group in this resource group container + * + * @return the resource group in this resource group container + */ + protected ResourceGroup getResourceGroup() { + if (resourceGroup == null) { + resourceGroup = factory.createResourceGroup(); + } + return resourceGroup; + } + +// /** {@inheritDoc} */ +// protected void writeContent(OutputStream os) throws IOException { +// if (resourceGroup != null) { +// resourceGroup.writeToStream(os); +// } +// super.writeContent(os); +// } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + if (!started) { + writeStart(os); + started = true; + } + + writeContent(os); + + if (complete) { + writeEnd(os); + } + } + + /** {@inheritDoc} */ + protected void writeObjects(Collection/**/ objects, OutputStream os) + throws IOException { + if (objects != null && objects.size() > 0) { + Iterator it = objects.iterator(); + while (it.hasNext()) { + AbstractAFPObject ao = (AbstractAFPObject)it.next(); + if (canWrite(ao)) { + ao.writeToStream(os); + it.remove(); + } else { + break; + } + } + } + } + + /** + * Returns true if this object can be written + * + * @param obj an AFP object + * @return true if this object can be written + */ + protected boolean canWrite(AbstractAFPObject obj) { + return obj instanceof AbstractPageObject && ((AbstractPageObject)obj).isComplete(); + } +} diff --git a/src/java/org/apache/fop/afp/modca/AbstractStructuredAFPObject.java b/src/java/org/apache/fop/afp/modca/AbstractStructuredAFPObject.java new file mode 100644 index 000000000..9bfc11095 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/AbstractStructuredAFPObject.java @@ -0,0 +1,324 @@ +/* + * 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/ActiveEnvironmentGroup.java b/src/java/org/apache/fop/afp/modca/ActiveEnvironmentGroup.java new file mode 100644 index 000000000..ddc986be3 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/ActiveEnvironmentGroup.java @@ -0,0 +1,221 @@ +/* + * 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.List; + +import org.apache.fop.afp.Factory; +import org.apache.fop.afp.fonts.AFPFont; + +/** + * An Active Environment Group (AEG) is associated with each page, + * and is contained in the page's begin-end envelope in the data stream. + * The active environment group contains layout and formatting information + * that defines the measurement units and size of the page, and may contain + * resource information. + * + * Any objects that are required for page presentation and that are to be + * treated as resource objects must be mapped with a map structured field + * in the AEG. The scope of an active environment group is the scope of its + * containing page or overlay. + * + */ +public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { + + /** The collection of MapCodedFont objects */ + private final List/**/ mapCodedFonts + = new java.util.ArrayList/**/(); + + /** the collection of MapDataResource objects */ + private final List mapDataResources = null; + + /** the Object Area Descriptor for the active environment group */ + private ObjectAreaDescriptor objectAreaDescriptor = null; + + /** the Object Area Position for the active environment group */ + private ObjectAreaPosition objectAreaPosition = null; + + /** the PresentationTextDescriptor for the active environment group */ + private PresentationTextDescriptor presentationTextDataDescriptor = null; + + /** the PageDescriptor for the active environment group */ + private PageDescriptor pageDescriptor = null; + + /** the resource manager */ + private final Factory factory; + + /** + * Constructor for the ActiveEnvironmentGroup, this takes a + * name parameter which must be 8 characters long. + * + * @param factory the object factory + * @param name the active environment group name + * @param width the page width + * @param height the page height + * @param widthRes the page width resolution + * @param heightRes the page height resolution + */ + public ActiveEnvironmentGroup(Factory factory, + String name, int width, int height, int widthRes, int heightRes) { + super(name); + + this.factory = factory; + + // Create PageDescriptor + this.pageDescriptor + = factory.createPageDescriptor(width, height, widthRes, heightRes); + + // Create ObjectAreaDescriptor + this.objectAreaDescriptor + = factory.createObjectAreaDescriptor(width, height, widthRes, heightRes); + + // Create PresentationTextDataDescriptor + this.presentationTextDataDescriptor + = factory.createPresentationTextDataDescriptor(width, height, + widthRes, heightRes); + } + + /** + * Set the position of the object area + * + * @param x the x offset + * @param y the y offset + * @param rotation the rotation + */ + public void setObjectAreaPosition(int x, int y, int rotation) { + this.objectAreaPosition = factory.createObjectAreaPosition(x, y, rotation); + } + + /** + * Accessor method to obtain the PageDescriptor object of the + * active environment group. + * + * @return the page descriptor object + */ + public PageDescriptor getPageDescriptor() { + return pageDescriptor; + } + + /** + * Accessor method to obtain the PresentationTextDataDescriptor object of + * the active environment group. + * + * @return the presentation text descriptor + */ + public PresentationTextDescriptor getPresentationTextDataDescriptor() { + return presentationTextDataDescriptor; + } + + /** {@inheritDoc} */ + public void writeContent(OutputStream os) throws IOException { + super.writeTriplets(os); + + writeObjects(mapCodedFonts, os); + writeObjects(mapDataResources, os); + writeObjects(mapPageOverlays, os); + + if (pageDescriptor != null) { + pageDescriptor.writeToStream(os); + } + if (objectAreaDescriptor != null && objectAreaPosition != null) { + objectAreaDescriptor.writeToStream(os); + objectAreaPosition.writeToStream(os); + } + if (presentationTextDataDescriptor != null) { + presentationTextDataDescriptor.writeToStream(os); + } + } + + /** {@inheritDoc} */ + protected void writeStart(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.BEGIN, Category.ACTIVE_ENVIRONMENT_GROUP); + os.write(data); + } + + /** {@inheritDoc} */ + protected void writeEnd(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.END, Category.ACTIVE_ENVIRONMENT_GROUP); + os.write(data); + } + + /** + * Method to create a map coded font object + * + * @param fontRef the font number used as the resource identifier + * @param font the font + * @param size the point size of the font + * @param orientation the orientation of the font (e.g. 0, 90, 180, 270) + */ + public void createFont(int fontRef, AFPFont font, int size, int orientation) { + MapCodedFont mapCodedFont = getCurrentMapCodedFont(); + if (mapCodedFont == null) { + mapCodedFont = factory.createMapCodedFont(); + mapCodedFonts.add(mapCodedFont); + } + + try { + mapCodedFont.addFont(fontRef, font, size, orientation); + } catch (MaximumSizeExceededException msee) { + mapCodedFont = factory.createMapCodedFont(); + mapCodedFonts.add(mapCodedFont); + + try { + mapCodedFont.addFont(fontRef, font, size, orientation); + } catch (MaximumSizeExceededException ex) { + // Should never happen (but log just in case) + log.error("createFont():: resulted in a MaximumSizeExceededException"); + } + } + } + + /** + * Getter method for the most recent MapCodedFont added to the + * Active Environment Group (returns null if no MapCodedFonts exist) + * + * @return the most recent Map Coded Font. + */ + private MapCodedFont getCurrentMapCodedFont() { + int size = mapCodedFonts.size(); + if (size > 0) { + return (MapCodedFont)mapCodedFonts.get(size - 1); + } else { + return null; + } + } + +// private List getMapDataResources() { +// if (mapDataResources == null) { +// mapDataResources = new java.util.ArrayList(); +// } +// return mapDataResources; +//} + +// /** +// * Method to create a map data resource object +// * @param dataObjectAccessor a data object accessor +// */ +// protected void createMapDataResource(DataObjectAccessor dataObjectAccessor) { +// getMapDataResources().add(new MapDataResource(dataObjectAccessor)); +// } +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/modca/ContainerDataDescriptor.java b/src/java/org/apache/fop/afp/modca/ContainerDataDescriptor.java new file mode 100644 index 000000000..0f99d6624 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/ContainerDataDescriptor.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.modca; + +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.fop.afp.util.BinaryUtils; + +/** + * Container data descriptor (to maintain compatibility with pre-year 2000 applications) + */ +public class ContainerDataDescriptor extends AbstractDescriptor { + + /** + * Main constructor + * + * @param width the container data width + * @param height the container data height + * @param widthRes the container width resolution + * @param heightRes the container height resolution + */ + public ContainerDataDescriptor(int width, int height, int widthRes, + int heightRes) { + super(width, height, widthRes, heightRes); + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = new byte[21]; + copySF(data, Type.DESCRIPTOR, Category.OBJECT_CONTAINER); + + // SF length + byte[] len = BinaryUtils.convert(data.length - 1, 2); + data[1] = len[0]; + data[2] = len[1]; + + // XocBase = 10 inches + data[9] = 0x00; + + // YocBase = 10 inches + data[10] = 0x00; + + // XocUnits + byte[] xdpi = BinaryUtils.convert(widthRes * 10, 2); + data[11] = xdpi[0]; + data[12] = xdpi[1]; + + // YocUnits + byte[] ydpi = BinaryUtils.convert(heightRes * 10, 2); + data[13] = ydpi[0]; + data[14] = ydpi[1]; + + // XocSize + byte[] xsize = BinaryUtils.convert(width, 3); + data[15] = xsize[0]; + data[16] = xsize[1]; + data[17] = xsize[2]; + + // YocSize + byte[] ysize = BinaryUtils.convert(height, 3); + data[18] = ysize[0]; + data[19] = ysize[1]; + data[20] = ysize[2]; + } + +} diff --git a/src/java/org/apache/fop/afp/modca/DataStream.java b/src/java/org/apache/fop/afp/modca/DataStream.java new file mode 100644 index 000000000..c1c5e12a7 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/DataStream.java @@ -0,0 +1,593 @@ +/* + * 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.AFPResourceLevel; +import org.apache.fop.afp.AFPState; +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 state */ + private final AFPState state; + + /** + * Default constructor for the AFPDocumentStream. + * + * @param factory the resource factory + * @param state the afp state + * @param outputStream the outputstream to write to + */ + public DataStream(Factory factory, AFPState 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 new file mode 100644 index 000000000..bb0dbebe3 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/Document.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.afp.modca; + +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.fop.afp.Factory; + +/** + * The document is the highest level of the MO:DCA data-stream document + * component hierarchy. Documents can be made up of pages, and the pages, which + * are at the intermediate level, can be made up of objects. Objects are at the + * lowest level, and can be bar codes, graphics, images, and presentation text. + * + * At each level of the hierarchy certain sets of MO:DCA data structures, called + * structured fields, are permissible. The document, pages and objects are + * bounded by structured fields that define their beginnings and their ends. + * These structured fields, called begin-end pairs, provide an envelope for the + * data-stream components. This feature enables a processor of the data stream + * that is not fully compliant with the architecture to bypass those objects + * that are beyond its scope, and to process the data stream to the best of its + * abilities. + * + * A presentation document is one that has been formatted and is intended for + * presentation, usually on a printer or display device. A data stream + * containing a presentation document should produce the same document content + * in the same format on different printers or display devices dependent, + * however, on the capabilities of each of the printers or display devices. A + * presentation document can reference resources that are to be included as part + * of the document to be presented. + * + */ +public final class Document extends AbstractResourceEnvironmentGroupContainer { + + /** + * Constructor for the document object. + * + * @param factory + * the object factory + * @param name + * the name of the document + */ + public Document(Factory factory, String name) { + super(factory, name); + } + + /** + * Method to mark the end of the page group. + */ + public void endDocument() { + complete = true; + } + + /** + * Returns an indication if the page group is complete + * + * @return whether or not this page group is complete + */ + public boolean isComplete() { + return complete; + } + + /** {@inheritDoc} */ + protected void writeStart(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.BEGIN, Category.DOCUMENT); + os.write(data); + } + + /** {@inheritDoc} */ + protected void writeEnd(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.END, Category.DOCUMENT); + os.write(data); + } + + /** {@inheritDoc} */ + public String toString() { + return this.name; + } + +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/modca/GraphicsDataDescriptor.java b/src/java/org/apache/fop/afp/modca/GraphicsDataDescriptor.java new file mode 100644 index 000000000..5495e2e9c --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/GraphicsDataDescriptor.java @@ -0,0 +1,152 @@ +/* + * 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 org.apache.fop.afp.util.BinaryUtils; + +/** + * GOCA Graphics Data Descriptor + */ +public class GraphicsDataDescriptor extends AbstractDescriptor { + + private final int xlwind; + + private final int xrwind; + + private final int ybwind; + + private final int ytwind; + + /** + * Main constructor + * + * @param xlwind + * the left edge of the graphics window + * @param xrwind + * the right edge of the graphics window + * @param ybwind + * the top edge of the graphics window + * @param ytwind + * the bottom edge of the graphics window + * @param widthRes + * the width resolution of the graphics window + * @param heightRes + * the height resolution of the graphics window + */ + public GraphicsDataDescriptor(int xlwind, int xrwind, int ybwind, + int ytwind, int widthRes, int heightRes) { + this.xlwind = xlwind; + this.xrwind = xrwind; + this.ybwind = ybwind; + this.ytwind = ytwind; + super.widthRes = widthRes; + super.heightRes = heightRes; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] headerData = new byte[9]; + copySF(headerData, Type.DESCRIPTOR, Category.GRAPHICS); + + byte[] drawingOrderSubsetData = getDrawingOrderSubset(); + + byte[] windowSpecificationData = getWindowSpecification(); + + byte[] len = BinaryUtils.convert(headerData.length + + drawingOrderSubsetData.length + + windowSpecificationData.length - 1, 2); + headerData[1] = len[0]; + headerData[2] = len[1]; + + os.write(headerData); + os.write(drawingOrderSubsetData); + os.write(windowSpecificationData); + } + + /** + * Returns the drawing order subset data + * + * @return the drawing order subset data + */ + private byte[] getDrawingOrderSubset() { + final byte[] data = new byte[] { + // Drawing order subset + (byte) 0xF7, + 7, // LENGTH + (byte) 0xB0, // drawing order subset + 0x00, // reserved (must be zero) + 0x00, // reserved (must be zero) + 0x02, // SUBLEV + 0x00, // VERSION 0 + 0x01, // LENGTH (of following field) + 0x00 // GEOM + }; + return data; + } + + private static final int ABS = 2; + private static final int IMGRES = 8; + + /** + * Returns the window specification data + * + * @return the window specification data + */ + private byte[] getWindowSpecification() { + byte[] xlcoord = BinaryUtils.convert(xlwind, 2); + byte[] xrcoord = BinaryUtils.convert(xrwind, 2); + byte[] xbcoord = BinaryUtils.convert(ybwind, 2); + byte[] ytcoord = BinaryUtils.convert(ytwind, 2); + byte[] xResol = BinaryUtils.convert(widthRes * 10, 2); + byte[] yResol = BinaryUtils.convert(heightRes * 10, 2); + byte[] imxyres = xResol; + + // Window specification + final byte[] data = new byte[] { + (byte) 0xF6, + 18, // LENGTH + (ABS + IMGRES), // FLAGS (ABS) + 0x00, // reserved (must be zero) + 0x00, // CFORMAT (coordinate format - 16bit high byte first signed) + 0x00, // UBASE (unit base - ten inches) + + xResol[0], // XRESOL + xResol[1], + yResol[0], // YRESOL + yResol[1], + + imxyres[0], // IMXYRES (Number of image points per ten inches + imxyres[1], // in X and Y directions) + + xlcoord[0], // XLWIND + xlcoord[1], + xrcoord[0], // XRWIND + xrcoord[1], + xbcoord[0], // YBWIND + xbcoord[1], + ytcoord[0], // YTWIND + ytcoord[1] + }; + return data; + } +} diff --git a/src/java/org/apache/fop/afp/modca/GraphicsObject.java b/src/java/org/apache/fop/afp/modca/GraphicsObject.java new file mode 100644 index 000000000..8b76dde15 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/GraphicsObject.java @@ -0,0 +1,303 @@ +/* + * 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.io.IOException; +import java.io.OutputStream; +import java.util.List; + +import org.apache.fop.afp.AFPDataObjectInfo; +import org.apache.fop.afp.AFPObjectAreaInfo; +import org.apache.fop.afp.Factory; +import org.apache.fop.afp.goca.GraphicsBox; +import org.apache.fop.afp.goca.GraphicsData; +import org.apache.fop.afp.goca.GraphicsFillet; +import org.apache.fop.afp.goca.GraphicsFullArc; +import org.apache.fop.afp.goca.GraphicsLine; +import org.apache.fop.afp.goca.GraphicsSetArcParameters; +import org.apache.fop.afp.goca.GraphicsSetCharacterSet; +import org.apache.fop.afp.goca.GraphicsSetCurrentPosition; +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. + * + * Acts as container and factory of all other graphic objects + */ +public class GraphicsObject extends AbstractDataObject { + + /** The graphics data */ + private GraphicsData currentGraphicsData = null; + + /** list of objects contained within this container */ + protected List/**/ objects + = new java.util.ArrayList/**/(); + + /** + * Default constructor + * + * @param factory the object factory + * @param name the name of graphics object + */ + public GraphicsObject(Factory factory, String name) { + super(factory, name); + } + + /** {@inheritDoc} */ + public void setViewport(AFPDataObjectInfo dataObjectInfo) { + super.setViewport(dataObjectInfo); + + AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo(); + int width = objectAreaInfo.getWidth(); + int height = objectAreaInfo.getHeight(); + int widthRes = objectAreaInfo.getWidthRes(); + int heightRes = objectAreaInfo.getHeightRes(); + final int leftEdge = 0; + final int topEdge = 0; + GraphicsDataDescriptor graphicsDataDescriptor = factory.createGraphicsDataDescriptor( + leftEdge, width, topEdge, height, widthRes, heightRes); + + getObjectEnvironmentGroup().setDataDescriptor(graphicsDataDescriptor); + } + + /** {@inheritDoc} */ + public void addObject(PreparedAFPObject drawingOrder) { + if (currentGraphicsData == null + || (currentGraphicsData.getDataLength() + drawingOrder.getDataLength()) + >= GraphicsData.MAX_DATA_LEN) { + newData(); + } + currentGraphicsData.addObject(drawingOrder); + } + + /** + * Gets the current graphics data, creating a new one if necessary + * + * @return the current graphics data + */ + private GraphicsData getData() { + if (this.currentGraphicsData == null) { + return newData(); + } + return this.currentGraphicsData; + } + + /** + * Creates a new graphics data + * + * @return a newly created graphics data + */ + private GraphicsData newData() { + this.currentGraphicsData = factory.createGraphicsData(); + objects.add(currentGraphicsData); + return currentGraphicsData; + } + + /** + * Sets the current color + * + * @param color the active color to use + */ + public void setColor(Color color) { + addObject(new GraphicsSetProcessColor(color)); + } + + /** + * Sets the current position + * + * @param coords the x and y coordinates of the current position + */ + public void setCurrentPosition(int[] coords) { + addObject(new GraphicsSetCurrentPosition(coords)); + } + + /** + * Sets the line width + * + * @param multiplier the line width multiplier + */ + public void setLineWidth(int multiplier) { + GraphicsSetLineWidth graphicsSetLineWidth = new GraphicsSetLineWidth(multiplier); + addObject(graphicsSetLineWidth); + } + + /** + * Sets the line type + * + * @param type the line type + */ + public void setLineType(byte type) { + GraphicsSetLineType graphicsSetLineType = new GraphicsSetLineType(type); + addObject(graphicsSetLineType); + } + + /** + * Sets whether to fill the next shape + * + * @param fill whether to fill the next shape + */ + public void setFill(boolean fill) { + GraphicsSetPatternSymbol graphicsSetPattern = new GraphicsSetPatternSymbol( + fill ? GraphicsSetPatternSymbol.SOLID_FILL + : GraphicsSetPatternSymbol.NO_FILL + ); + addObject(graphicsSetPattern); + } + + /** + * Sets the character set to use + * + * @param fontReference the character set (font) reference + */ + public void setCharacterSet(int fontReference) { + addObject(new GraphicsSetCharacterSet(fontReference)); + } + + /** + * Adds a line at the given x/y coordinates + * + * @param coords the x/y coordinates (can be a series) + */ + public void addLine(int[] coords) { + addObject(new GraphicsLine(coords)); + } + + /** + * Adds a box at the given coordinates + * + * @param coords the x/y coordinates + */ + public void addBox(int[] coords) { + addObject(new GraphicsBox(coords)); + } + + /** + * Adds a fillet (curve) at the given coordinates + * + * @param coords the x/y coordinates + */ + public void addFillet(int[] coords) { + addObject(new GraphicsFillet(coords)); + } + + /** + * Sets the arc parameters + * + * @param xmaj the maximum value of the x coordinate + * @param ymin the minimum value of the y coordinate + * @param xmin the minimum value of the x coordinate + * @param ymaj the maximum value of the y coordinate + */ + public void setArcParams(int xmaj, int ymin, int xmin, int ymaj) { + addObject(new GraphicsSetArcParameters(xmaj, ymin, xmin, ymaj)); + } + + /** + * Adds an arc + * + * @param x the x coordinate + * @param y the y coordinate + * @param mh the integer portion of the multiplier + * @param mhr the fractional portion of the multiplier + */ + public void addFullArc(int x, int y, int mh, int mhr) { + 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 a string + * + * @param str the string + * @param x the x coordinate + * @param y the y coordinate + */ + public void addString(String str, int x, int y) { + addObject(new GraphicsString(str, x, y)); + } + + /** + * Begins a graphics area (start of fill) + */ + public void beginArea() { + if (currentGraphicsData == null) { + newData(); + } + currentGraphicsData.beginArea(); + } + + /** + * Ends a graphics area (end of fill) + */ + public void endArea() { + if (currentGraphicsData != null) { + currentGraphicsData.endArea(); + } + } + + /** {@inheritDoc} */ + public String toString() { + return "GraphicsObject: " + getName(); + } + + /** + * Creates a new graphics segment + */ + public void newSegment() { + getData().newSegment(); + } + + /** {@inheritDoc} */ + protected void writeStart(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.BEGIN, Category.GRAPHICS); + os.write(data); + } + + /** {@inheritDoc} */ + protected void writeContent(OutputStream os) throws IOException { + super.writeContent(os); + super.writeObjects(objects, os); + } + + /** {@inheritDoc} */ + protected void writeEnd(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.END, Category.GRAPHICS); + os.write(data); + } +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/modca/IMImageObject.java b/src/java/org/apache/fop/afp/modca/IMImageObject.java new file mode 100644 index 000000000..a09042441 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/IMImageObject.java @@ -0,0 +1,141 @@ +/* + * 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 org.apache.fop.afp.ioca.ImageCellPosition; +import org.apache.fop.afp.ioca.ImageInputDescriptor; +import org.apache.fop.afp.ioca.ImageOutputControl; +import org.apache.fop.afp.ioca.ImageRasterData; + +/** + * An IM image data object specifies the contents of a raster image and + * its placement on a page, overlay, or page segment. An IM image can be + * either simple or complex. A simple image is composed of one or more Image + * Raster Data (IRD) structured fields that define the raster pattern for the + * entire image. A complex image is divided into regions called image cells. + * Each image cell is composed of one or more IRD structured fields that define + * the raster pattern for the image cell, and one Image Cell Position (ICP) + * structured field that defines the position of the image cell relative to + * the origin of the entire image. Each ICP also specifies the size of the + * image cell and a fill rectangle into which the cell is replicated. + *

+ */ +public class IMImageObject extends AbstractNamedAFPObject { + + /** + * The image output control + */ + private ImageOutputControl imageOutputControl = null; + + /** + * The image input descriptor + */ + private ImageInputDescriptor imageInputDescriptor = null; + + /** + * The image cell position + */ + private ImageCellPosition imageCellPosition = null; + + /** + * The image rastor data + */ + private ImageRasterData imageRasterData = null; + + /** + * Constructor for the image object with the specified name, + * the name must be a fixed length of eight characters. + * + * @param name The name of the image. + */ + public IMImageObject(String name) { + super(name); + } + + /** + * Sets the ImageOutputControl. + * + * @param imageOutputControl The imageOutputControl to set + */ + public void setImageOutputControl(ImageOutputControl imageOutputControl) { + this.imageOutputControl = imageOutputControl; + } + + /** + * Sets the ImageCellPosition. + * + * @param imageCellPosition The imageCellPosition to set + */ + public void setImageCellPosition(ImageCellPosition imageCellPosition) { + this.imageCellPosition = imageCellPosition; + } + + /** + * Sets the ImageInputDescriptor. + * + * @param imageInputDescriptor The imageInputDescriptor to set + */ + public void setImageInputDescriptor(ImageInputDescriptor imageInputDescriptor) { + this.imageInputDescriptor = imageInputDescriptor; + } + + /** + * Sets the ImageRastorData. + * + * @param imageRasterData The imageRasterData to set + */ + public void setImageRasterData(ImageRasterData imageRasterData) { + this.imageRasterData = imageRasterData; + } + + /** {@inheritDoc} */ + protected void writeContent(OutputStream os) throws IOException { + super.writeContent(os); + if (imageOutputControl != null) { + imageOutputControl.writeToStream(os); + } + if (imageInputDescriptor != null) { + imageInputDescriptor.writeToStream(os); + } + if (imageCellPosition != null) { + imageCellPosition.writeToStream(os); + } + if (imageRasterData != null) { + imageRasterData.writeToStream(os); + } + } + + /** {@inheritDoc} */ + protected void writeStart(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.BEGIN, Category.IM_IMAGE); + os.write(data); + } + + /** {@inheritDoc} */ + protected void writeEnd(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.END, Category.IM_IMAGE); + os.write(data); + } +} diff --git a/src/java/org/apache/fop/afp/modca/ImageDataDescriptor.java b/src/java/org/apache/fop/afp/modca/ImageDataDescriptor.java new file mode 100644 index 000000000..07976e18a --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/ImageDataDescriptor.java @@ -0,0 +1,78 @@ +/* + * 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 org.apache.fop.afp.util.BinaryUtils; + +/** + * ImageDataDescriptor + */ +public class ImageDataDescriptor extends AbstractDescriptor { + + /** + * Constructor for a ImageDataDescriptor for the specified + * resolution, width and height. + * + * @param width The width of the image. + * @param height The height of the height. + * @param widthRes The horizontal resolution of the image. + * @param heightRes The vertical resolution of the image. + */ + public ImageDataDescriptor(int width, int height, int widthRes, int heightRes) { + super(width, height, widthRes, heightRes); + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = new byte[22]; + copySF(data, Type.DESCRIPTOR, Category.IMAGE); + + // SF length + byte[] len = BinaryUtils.convert(data.length - 1, 2); + data[1] = len[0]; + data[2] = len[1]; + + byte[] x = BinaryUtils.convert(widthRes, 2); + data[10] = x[0]; + data[11] = x[1]; + + byte[] y = BinaryUtils.convert(heightRes, 2); + data[12] = y[0]; + data[13] = y[1]; + + byte[] w = BinaryUtils.convert(width, 2); + data[14] = w[0]; + data[15] = w[1]; + + byte[] h = BinaryUtils.convert(height, 2); + data[16] = h[0]; + data[17] = h[1]; + + data[18] = (byte)0xF7; // ID = Set IOCA Function Set + data[19] = 0x02; // Length + data[20] = 0x01; // Category = Function set identifier + data[21] = 0x0B; // FCNSET = IOCA FS 11 + + os.write(data); + } +} diff --git a/src/java/org/apache/fop/afp/modca/ImageObject.java b/src/java/org/apache/fop/afp/modca/ImageObject.java new file mode 100644 index 000000000..8ab56691f --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/ImageObject.java @@ -0,0 +1,154 @@ +/* + * 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 org.apache.commons.io.output.ByteArrayOutputStream; +import org.apache.fop.afp.AFPDataObjectInfo; +import org.apache.fop.afp.AFPImageObjectInfo; +import org.apache.fop.afp.AFPObjectAreaInfo; +import org.apache.fop.afp.Factory; +import org.apache.fop.afp.ioca.ImageSegment; + +/** + * An IOCA Image Data Object + */ +public class ImageObject extends AbstractDataObject { + + private static final int MAX_DATA_LEN = 32759; + + /** the image segment */ + private ImageSegment imageSegment = null; + + /** + * Constructor for the image object with the specified name, + * the name must be a fixed length of eight characters. + * + * @param name The name of the image. + * @param factory the resource manager + */ + public ImageObject(Factory factory, String name) { + super(factory, name); + } + + private ImageSegment getImageSegment() { + if (imageSegment == null) { + this.imageSegment = factory.createImageSegment(); + } + return imageSegment; + } + + /** {@inheritDoc} */ + public void setViewport(AFPDataObjectInfo dataObjectInfo) { + super.setViewport(dataObjectInfo); + + AFPImageObjectInfo imageObjectInfo = (AFPImageObjectInfo)dataObjectInfo; + int dataWidth = imageObjectInfo.getDataWidth(); + int dataHeight = imageObjectInfo.getDataHeight(); + + AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo(); + int widthRes = objectAreaInfo.getWidthRes(); + int heightRes = objectAreaInfo.getHeightRes(); + + ImageDataDescriptor imageDataDescriptor + = factory.createImageDataDescriptor(dataWidth, dataHeight, widthRes, heightRes); + getObjectEnvironmentGroup().setDataDescriptor(imageDataDescriptor); + + getImageSegment().setImageSize(dataWidth, dataHeight, widthRes, heightRes); + } + + /** + * Sets the image encoding. + * + * @param encoding The image encoding. + */ + public void setEncoding(byte encoding) { + getImageSegment().setEncoding(encoding); + } + + /** + * Sets the image compression. + * + * @param compression The image compression. + */ + public void setCompression(byte compression) { + getImageSegment().setCompression(compression); + } + + /** + * Sets the image IDE size. + * + * @param size The IDE size. + */ + public void setIDESize(byte size) { + getImageSegment().setIDESize(size); + } + + /** + * Sets the image IDE color model. + * + * @param colorModel the IDE color model. + */ + public void setIDEColorModel(byte colorModel) { + getImageSegment().setIDEColorModel(colorModel); + } + + /** + * Set the data of the image. + * + * @param data the image data + */ + public void setData(byte[] data) { + getImageSegment().setData(data); + } + + /** {@inheritDoc} */ + protected void writeStart(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.BEGIN, Category.IMAGE); + os.write(data); + } + + /** {@inheritDoc} */ + protected void writeContent(OutputStream os) throws IOException { + super.writeContent(os); + + if (imageSegment != null) { + final byte[] dataHeader = new byte[9]; + copySF(dataHeader, SF_CLASS, Type.DATA, Category.IMAGE); + final int lengthOffset = 1; + + // TODO save memory! + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + imageSegment.writeToStream(baos); + byte[] data = baos.toByteArray(); + writeChunksToStream(data, dataHeader, lengthOffset, MAX_DATA_LEN, os); + } + } + + /** {@inheritDoc} */ + protected void writeEnd(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.END, Category.IMAGE); + os.write(data); + } +} diff --git a/src/java/org/apache/fop/afp/modca/IncludeObject.java b/src/java/org/apache/fop/afp/modca/IncludeObject.java new file mode 100644 index 000000000..c0ab5c640 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/IncludeObject.java @@ -0,0 +1,303 @@ +/* + * 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 org.apache.fop.afp.modca.triplets.MappingOptionTriplet; +import org.apache.fop.afp.modca.triplets.MeasurementUnitsTriplet; +import org.apache.fop.afp.modca.triplets.ObjectAreaSizeTriplet; +import org.apache.fop.afp.util.BinaryUtils; + +/** + * An Include Object structured field references an object on a page or overlay. + * It optionally contains parameters that identify the object and that specify + * presentation parameters such as object position, size, orientation, mapping, + * and default color. + *

+ * Where the presentation parameters conflict with parameters specified in the + * object's environment group (OEG), the parameters in the Include Object + * structured field override. If the referenced object is a page segment, the + * IOB parameters override the corresponding environment group parameters on all + * data objects in the page segment. + *

+ */ +public class IncludeObject extends AbstractNamedAFPObject { + + /** the object referenced is of type page segment */ + public static final byte TYPE_PAGE_SEGMENT = (byte)0x5F; + + /** the object referenced is of type other */ + public static final byte TYPE_OTHER = (byte)0x92; + + /** the object referenced is of type graphic */ + public static final byte TYPE_GRAPHIC = (byte)0xBB; + + /** the object referenced is of type barcode */ + public static final byte TYPE_BARCODE = (byte)0xEB; + + /** the object referenced is of type image */ + public static final byte TYPE_IMAGE = (byte)0xFB; + + + /** the object type referenced (default is other) */ + private byte objectType = TYPE_OTHER; + + /** the X-axis origin of the object area */ + private int xoaOset = 0; + + /** the Y-axis origin of the object area */ + private int yoaOset = 0; + + /** the orientation of the referenced object */ + private int oaOrent = 0; + + /** the X-axis origin defined in the object */ + private int xocaOset = -1; + + /** the Y-axis origin defined in the object */ + private int yocaOset = -1; + + /** + * Constructor for the include object with the specified name, the name must + * be a fixed length of eight characters and is the name of the referenced + * object. + * + * @param name the name of this include object + */ + public IncludeObject(String name) { + super(name); + } + + /** + * Sets the orientation to use for the Include Object. + * + * @param orientation + * The orientation (0,90, 180, 270) + */ + public void setObjectAreaOrientation(int orientation) { + if (orientation == 0 || orientation == 90 || orientation == 180 + || orientation == 270) { + this.oaOrent = orientation; + } else { + throw new IllegalArgumentException( + "The orientation must be one of the values 0, 90, 180, 270"); + } + } + + /** + * Sets the x and y offset to the origin in the object area + * + * @param x the X-axis origin of the object area + * @param y the Y-axis origin of the object area + */ + public void setObjectAreaOffset(int x, int y) { + this.xoaOset = x; + this.yoaOset = y; + } + + /** + * Sets the x and y offset of the content area to the object area + * used in conjunction with the {@link MappingOptionTriplet.POSITION} and + * {@link MappingOptionTriplet.POSITION_AND_TRIM}. + * + * @param x the X-axis origin defined in the object + * @param y the Y-axis origin defined in the object + */ + public void setContentAreaOffset(int x, int y) { + this.xocaOset = x; + this.yocaOset = y; + } + + /** + * Sets the data object type + * + * @param type the data object type + */ + public void setObjectType(byte type) { + this.objectType = type; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = new byte[36]; + super.copySF(data, Type.INCLUDE, Category.DATA_RESOURCE); + + // Set the total record length + int tripletDataLength = getTripletDataLength(); + byte[] len = BinaryUtils.convert(35 + tripletDataLength, 2); //Ignore first byte + data[1] = len[0]; + data[2] = len[1]; + + data[17] = 0x00; // reserved + data[18] = objectType; + + //XoaOset (object area) + if (xoaOset > -1) { + byte[] x = BinaryUtils.convert(xoaOset, 3); + data[19] = x[0]; + data[20] = x[1]; + data[21] = x[2]; + } else { + data[19] = (byte)0xFF; + data[20] = (byte)0xFF; + data[21] = (byte)0xFF; + } + + // YoaOset (object area) + if (yoaOset > -1) { + byte[] y = BinaryUtils.convert(yoaOset, 3); + data[22] = y[0]; + data[23] = y[1]; + data[24] = y[2]; + } else { + data[22] = (byte)0xFF; + data[23] = (byte)0xFF; + data[24] = (byte)0xFF; + } + + // XoaOrent/YoaOrent + switch (oaOrent) { + case -1: // use x/y axis orientation defined in object + data[25] = (byte)0xFF; // x axis rotation + data[26] = (byte)0xFF; // + data[27] = (byte)0xFF; // y axis rotation + data[28] = (byte)0xFF; + break; + case 90: + data[25] = 0x2D; + data[26] = 0x00; + data[27] = 0x5A; + data[28] = 0x00; + break; + case 180: + data[25] = 0x5A; + data[25] = 0x00; + data[27] = (byte)0x87; + data[28] = 0x00; + break; + case 270: + data[25] = (byte)0x87; + data[26] = 0x00; + data[27] = 0x00; + data[28] = 0x00; + break; + default: // 0 degrees + data[25] = 0x00; + data[26] = 0x00; + data[27] = 0x2D; + data[28] = 0x00; + break; + } + + // XocaOset (object content) + if (xocaOset > -1) { + byte[] x = BinaryUtils.convert(xocaOset, 3); + data[29] = x[0]; + data[30] = x[1]; + data[31] = x[2]; + } else { + data[29] = (byte)0xFF; + data[30] = (byte)0xFF; + data[31] = (byte)0xFF; + } + + // YocaOset (object content) + if (yocaOset > -1) { + byte[] y = BinaryUtils.convert(yocaOset, 3); + data[32] = y[0]; + data[33] = y[1]; + data[34] = y[2]; + } else { + data[32] = (byte)0xFF; + data[33] = (byte)0xFF; + data[34] = (byte)0xFF; + } + // RefCSys (Reference coordinate system) + data[35] = 0x01; // Page or overlay coordinate system + + // Write structured field data + os.write(data); + + // Write triplet for FQN internal/external object reference + if (tripletData != null) { + os.write(tripletData); + } + } + + private String getObjectTypeName() { + String objectTypeName = null; + if (objectType == TYPE_PAGE_SEGMENT) { + objectTypeName = "page segment"; + } else if (objectType == TYPE_OTHER) { + objectTypeName = "other"; + } else if (objectType == TYPE_GRAPHIC) { + objectTypeName = "graphic"; + } else if (objectType == TYPE_BARCODE) { + objectTypeName = "barcode"; + } else if (objectType == TYPE_IMAGE) { + objectTypeName = "image"; + } + return objectTypeName; + } + + /** {@inheritDoc} */ + public String toString() { + return "IncludeObject{name=" + this.getName() + + ", objectType=" + getObjectTypeName() + + ", xoaOset=" + xoaOset + + ", yoaOset=" + yoaOset + + ", oaOrent" + oaOrent + + ", xocaOset=" + xocaOset + + ", yocaOset=" + yocaOset + + "}"; + } + + /** + * Sets the mapping option + * + * @param optionValue the mapping option value + */ + public void setMappingOption(byte optionValue) { + addTriplet(new MappingOptionTriplet(optionValue)); + } + + /** + * Sets the extent of an object area in the X and Y directions + * + * @param x the x direction extent + * @param y the y direction extent + */ + public void setObjectAreaSize(int x, int y) { + addTriplet(new ObjectAreaSizeTriplet(x, y)); + } + + /** + * Sets the measurement units used to specify the units of measure + * + * @param xRes units per base on the x-axis + * @param yRes units per base on the y-axis + */ + public void setMeasurementUnits(int xRes, int yRes) { + addTriplet(new MeasurementUnitsTriplet(xRes, xRes)); + } + +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/modca/IncludePageOverlay.java b/src/java/org/apache/fop/afp/modca/IncludePageOverlay.java new file mode 100644 index 000000000..44f0edc5b --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/IncludePageOverlay.java @@ -0,0 +1,129 @@ +/* + * 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 org.apache.fop.afp.util.BinaryUtils; + +/** + * + * The Include Page Overlay structured field references an overlay resource + * definition that is to be positioned on the page. A page overlay can be + * referenced at any time during the page state, but not during an object state. + * The overlay contains its own active environment group definition. + * + * Note: There is no need for the triplets, so I have ignored them. + * + * A real example of where this will be used is for static overlays, such as an + * address on the page. + * + */ +public class IncludePageOverlay extends AbstractNamedAFPObject { + + /** + * The x coordinate + */ + private int x = 0; + + /** + * The y coordinate + */ + private int y = 0; + + /** + * The orientation + */ + private int orientation = 0; + + /** + * Constructor for the Include Page Overlay + * + * @param overlayName Name of the page segment + * @param x The x position + * @param y The y position + * @param orientation The orientation + */ + public IncludePageOverlay(String overlayName, int x, int y, int orientation) { + super(overlayName); + + this.x = x; + this.y = y; + setOrientation(orientation); + } + + /** + * Sets the orientation to use for the overlay. + * + * @param orientation + * The orientation (0,90, 180, 270) + */ + public void setOrientation(int orientation) { + if (orientation == 0 || orientation == 90 || orientation == 180 + || orientation == 270) { + this.orientation = orientation; + } else { + throw new IllegalArgumentException( + "The orientation must be one of the values 0, 90, 180, 270"); + } + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = new byte[25]; //(9 +16) + copySF(data, Type.INCLUDE, Category.PAGE_OVERLAY); + + // Set the total record length + byte[] len = BinaryUtils.convert(24, 2); //Ignore first byte + data[1] = len[0]; + data[2] = len[1]; + + byte[] xPos = BinaryUtils.convert(x, 3); + data[17] = xPos[0]; // x coordinate + data[18] = xPos[1]; + data[19] = xPos[2]; + + byte[] yPos = BinaryUtils.convert(y, 3); + data[20] = yPos[0]; // y coordinate + data[21] = yPos[1]; + data[22] = yPos[2]; + + switch (orientation) { + case 90: + data[23] = 0x2D; + data[24] = 0x00; + break; + case 180: + data[23] = 0x5A; + data[24] = 0x00; + break; + case 270: + data[23] = (byte) 0x87; + data[24] = 0x00; + break; + default: + data[23] = 0x00; + data[24] = 0x00; + break; + } + os.write(data); + } +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/modca/IncludePageSegment.java b/src/java/org/apache/fop/afp/modca/IncludePageSegment.java new file mode 100644 index 000000000..7355e3b1a --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/IncludePageSegment.java @@ -0,0 +1,91 @@ +/* + * 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 org.apache.fop.afp.util.BinaryUtils; + +/** + * The Include Page Segment structured field references a page segment resource + * object that is to be presented on the page or overlay presentation space. The IPS + * specifies a reference point on the including page or overlay coordinate system that + * may be used to position objects contained in the page segment. A page segment + * can be referenced at any time during page or overlay state, but not during an + * object state. The page segment inherits the active environment group definition of + * the including page or overlay. + * + * Note : No use for Triplets. + * + * A 'real' example for where this will be used is for + * the dynamic placing of overlay objects, such as signatures + * that may have to be placed at different positions on a document. + * + */ +public class IncludePageSegment extends AbstractNamedAFPObject { + + /** + * The x position where we need to put this object on the page + */ + private int x; + + /** + * The y position where we need to put this object on the page + */ + private int y; + + /** + * Constructor for the Include Page Segment + * + * @param name Name of the page segment + * @param x The x position + * @param y The y position + */ + public IncludePageSegment(String name, int x, int y) { + super(name); + + this.x = x; + this.y = y; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = new byte[23]; //(9 +14) + copySF(data, Type.INCLUDE, Category.PAGE_SEGMENT); + + // Set the total record length + byte[] len = BinaryUtils.convert(22, 2); //Ignore first byte + data[1] = len[0]; + data[2] = len[1]; + + byte[] xPos = BinaryUtils.convert(x, 3); + data[17] = xPos[0]; // x coordinate + data[18] = xPos[1]; + data[19] = xPos[2]; + + byte[] yPos = BinaryUtils.convert(y, 3); + data[20] = yPos[0]; // y coordinate + data[21] = yPos[1]; + data[22] = yPos[2]; + + os.write(data); + } +} diff --git a/src/java/org/apache/fop/afp/modca/InterchangeSet.java b/src/java/org/apache/fop/afp/modca/InterchangeSet.java new file mode 100644 index 000000000..28a4da42b --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/InterchangeSet.java @@ -0,0 +1,115 @@ +/* + * 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; + +/** + * MO:DCA Interchange Set + */ +public class InterchangeSet { + /** interchange set 1 string value */ + public static final String MODCA_PRESENTATION_INTERCHANGE_SET_1 = "MO:DCA-P IS/1"; + + /** interchange set 2 string value */ + public static final String MODCA_PRESENTATION_INTERCHANGE_SET_2 = "MO:DCA-P IS/2"; + + /** resource interchange set string value */ + public static final String MODCA_RESOURCE_INTERCHANGE_SET = "MO:DCA-L"; + + private static final String[] NAMES = { + MODCA_PRESENTATION_INTERCHANGE_SET_1, + MODCA_PRESENTATION_INTERCHANGE_SET_2, + MODCA_RESOURCE_INTERCHANGE_SET + }; + + private static final int SET_1 = 0; + private static final int SET_2 = 1; + private static final int RESOURCE_SET = 2; + + /** the actual interchange set in use */ + private int value; + + /** + * Returns the interchange set value of a given string + * + * @param str an interchange set value + * @return an interchange set + */ + public static InterchangeSet valueOf(String str) { + if (MODCA_PRESENTATION_INTERCHANGE_SET_1.equals(str)) { + return new InterchangeSet(SET_1); + } else if (MODCA_PRESENTATION_INTERCHANGE_SET_2.equals(str)) { + return new InterchangeSet(SET_2); + } else if (MODCA_RESOURCE_INTERCHANGE_SET.equals(str)) { + return new InterchangeSet(RESOURCE_SET); + } else { + throw new IllegalArgumentException("Invalid MO:DCA interchange set :" + str); + } + } + + /** + * Main constructor + * + * @param value the interchange set value + */ + public InterchangeSet(int value) { + this.value = value; + } + + /** + * Returns true if complies with MOD:CA interchange set 1 + * + * @return true if complies with MOD:CA interchange set 1 + */ + protected boolean is1() { + return value == SET_1; + } + + /** + * Returns true if complies with MOD:CA interchange set 2 + * + * @return true if complies with MOD:CA interchange set 2 + */ + public boolean is2() { + return value == SET_2; + } + + /** + * Returns true if complies with MOD:CA resource set + * + * @return true if complies with MOD:CA resource set + */ + public boolean isResource() { + return value == RESOURCE_SET; + } + + /** {@inheritDoc} */ + public String toString() { + return NAMES[value]; + } + + /** + * Returns true if MOD:CA interchange set 2 (resource groups) is supported + * + * @return true if MOD:CA interchange set 2 (resource groups) is supported + */ + public boolean supportsLevel2() { + return is2() || isResource(); + } +} diff --git a/src/java/org/apache/fop/afp/modca/InvokeMediumMap.java b/src/java/org/apache/fop/afp/modca/InvokeMediumMap.java new file mode 100644 index 000000000..f910a0b9c --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/InvokeMediumMap.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.modca; + +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.fop.afp.util.BinaryUtils; + +/** + * The Invoke Medium Map structured field identifies the Medium Map that is to + * become active for the document. An Invoke Medium Map structured field affects + * the document's current environment. The Medium Map's effect on current environment + * parameter values lasts until a new Medium Map is invoked. + */ +public class InvokeMediumMap extends AbstractNamedAFPObject { + + /** + * Constructor for the Invoke Medium Map + * + * @param name the name of the medium map + */ + public InvokeMediumMap(String name) { + super(name); + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + + byte[] data = new byte[17]; + copySF(data, Type.MAP, Category.MEDIUM_MAP); + + // Set the total record length + byte[] len = BinaryUtils.convert(16, 2); //Ignore first byte + data[1] = len[0]; + data[2] = len[1]; + + os.write(data); + } +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/modca/MapCodedFont.java b/src/java/org/apache/fop/afp/modca/MapCodedFont.java new file mode 100644 index 000000000..fb9637678 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/MapCodedFont.java @@ -0,0 +1,273 @@ +/* + * 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.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; +import java.util.Iterator; +import java.util.List; + +import org.apache.fop.afp.AFPConstants; +import org.apache.fop.afp.fonts.AFPFont; +import org.apache.fop.afp.fonts.CharacterSet; +import org.apache.fop.afp.fonts.FontRuntimeException; +import org.apache.fop.afp.fonts.OutlineFont; +import org.apache.fop.afp.fonts.RasterFont; +import org.apache.fop.afp.util.BinaryUtils; + +/** + * The Map Coded Font structured field maps a unique coded font resource local + * ID, which may be embedded one or more times within an object's data and + * descriptor, to the identifier of a coded font resource object. Additionally, + * the Map Coded Font structured field specifies a set of resource attributes + * for the coded font. + */ +public class MapCodedFont extends AbstractStructuredAFPObject { + + /** + * The collection of map coded fonts (maximum of 254) + */ + private final List/**/ fontList = new java.util.ArrayList(); + + /** + * Constructor for the MapCodedFont + */ + public MapCodedFont() { + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + byte[] startData = new byte[9]; + copySF(startData, Type.MAP, Category.CODED_FONT); + baos.write(startData); + + Iterator iter = fontList.iterator(); + while (iter.hasNext()) { + FontDefinition fd = (FontDefinition) iter.next(); + + // Start of repeating groups (occurs 1 to 254) + baos.write(0x00); + + if (fd.scale == 0) { + // Raster Font + baos.write(0x22); // Length of 34 + } else { + // Outline Font + baos.write(0x3A); // Length of 58 + } + + // Font Character Set Name Reference + baos.write(0x0C); + baos.write(0x02); + baos.write((byte) 0x86); + baos.write(0x00); + baos.write(fd.characterSet); + + // Font Code Page Name Reference + baos.write(0x0C); + baos.write(0x02); + baos.write((byte) 0x85); + baos.write(0x00); + baos.write(fd.codePage); + + // Character Rotation + baos.write(0x04); + baos.write(0x26); + baos.write(fd.orientation); + baos.write(0x00); + + // Resource Local Identifier + baos.write(0x04); + baos.write(0x24); + baos.write(0x05); + baos.write(fd.fontReferenceKey); + + if (fd.scale != 0) { + // Outline Font (triplet '1F') + baos.write(0x14); + baos.write(0x1F); + baos.write(0x00); + baos.write(0x00); + + baos.write(BinaryUtils.convert(fd.scale, 2)); // Height + baos.write(new byte[] {0x00, 0x00}); // Width + + baos.write(new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00}); + + baos.write(0x60); + + // Outline Font (triplet '5D') + baos.write(0x04); + baos.write(0x5D); + baos.write(BinaryUtils.convert(fd.scale, 2)); + } + } + + byte[] data = baos.toByteArray(); + + // Set the total record length + byte[] rl1 = BinaryUtils.convert(data.length - 1, 2); + data[1] = rl1[0]; + data[2] = rl1[1]; + + os.write(data); + } + + /** + * Add a font definition on the the map coded font object. + * + * @param fontReference + * the font number used as the resource identifier + * @param font + * the font + * @param size + * the size of the font + * @param orientation + * the orientation of the font + * @throws MaximumSizeExceededException if the maximum number of fonts have been exceeded + */ + public void addFont(int fontReference, AFPFont font, int size, int orientation) + throws MaximumSizeExceededException { + + FontDefinition fd = new FontDefinition(); + + fd.fontReferenceKey = BinaryUtils.convert(fontReference)[0]; + + switch (orientation) { + case 90: + fd.orientation = 0x2D; + break; + case 180: + fd.orientation = 0x5A; + break; + case 270: + fd.orientation = (byte) 0x87; + break; + default: + fd.orientation = 0x00; + break; + } + + try { + if (font instanceof RasterFont) { + RasterFont raster = (RasterFont) font; + CharacterSet cs = raster.getCharacterSet(size); + if (cs == null) { + String msg = "Character set not found for font " + + font.getFontName() + " with point size " + size; + log.error(msg); + throw new FontRuntimeException(msg); + } + + fd.characterSet = cs.getNameBytes(); + + if (fd.characterSet.length != 8) { + throw new IllegalArgumentException("The character set " + + new String(fd.characterSet, + AFPConstants.EBCIDIC_ENCODING) + + " must have a fixed length of 8 characters."); + } + + fd.codePage = cs.getCodePage().getBytes( + AFPConstants.EBCIDIC_ENCODING); + + if (fd.codePage.length != 8) { + throw new IllegalArgumentException("The code page " + + new String(fd.codePage, + AFPConstants.EBCIDIC_ENCODING) + + " must have a fixed length of 8 characters."); + } + + } else if (font instanceof OutlineFont) { + OutlineFont outline = (OutlineFont) font; + CharacterSet cs = outline.getCharacterSet(); + fd.characterSet = cs.getNameBytes(); + + // There are approximately 72 points to 1 inch or 20 1440ths per point. + + fd.scale = ((size / 1000) * 20); + + fd.codePage = cs.getCodePage().getBytes( + AFPConstants.EBCIDIC_ENCODING); + + if (fd.codePage.length != 8) { + throw new IllegalArgumentException("The code page " + + new String(fd.codePage, + AFPConstants.EBCIDIC_ENCODING) + + " must have a fixed length of 8 characters."); + } + } else { + String msg = "Font of type " + font.getClass().getName() + + " not recognized."; + log.error(msg); + throw new FontRuntimeException(msg); + } + + if (fontList.size() > 253) { + // Throw an exception if the size is exceeded + throw new MaximumSizeExceededException(); + } else { + fontList.add(fd); + } + + } catch (UnsupportedEncodingException ex) { + throw new FontRuntimeException("Failed to create font " + + " due to a UnsupportedEncodingException", ex); + } + } + + + /** + * Private utility class used as a container for font attributes + */ + private class FontDefinition { + + /** + * The code page of the font + */ + private byte[] codePage; + + /** + * The character set of the font + */ + private byte[] characterSet; + + /** + * The font reference key + */ + private byte fontReferenceKey; + + /** + * The orientation of the font + */ + private byte orientation; + + /** + * The scale (only specified for outline fonts) + */ + private int scale = 0; + } + +} diff --git a/src/java/org/apache/fop/afp/modca/MapContainerData.java b/src/java/org/apache/fop/afp/modca/MapContainerData.java new file mode 100644 index 000000000..dba7616a8 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/MapContainerData.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.modca; + +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.fop.afp.modca.triplets.MappingOptionTriplet; +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 { + + /** + * Main constructor + * + * @param optionValue the mapping option value + */ + public MapContainerData(byte optionValue) { + super.addTriplet(new MappingOptionTriplet(optionValue)); + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + 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); + } +} diff --git a/src/java/org/apache/fop/afp/modca/MapDataResource.java b/src/java/org/apache/fop/afp/modca/MapDataResource.java new file mode 100644 index 000000000..7bebc4c07 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/MapDataResource.java @@ -0,0 +1,58 @@ +/* + * 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 org.apache.fop.afp.util.BinaryUtils; + +/** + * The Map Data Resource structured field specifies resources that are + * required for presentation. + */ +public class MapDataResource extends AbstractStructuredAFPObject { + + /** + * Main constructor + */ + public MapDataResource() { + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + super.writeStart(os); + byte[] data = new byte[11]; + copySF(data, Type.MAP, Category.DATA_RESOURCE); + + int tripletDataLen = getTripletDataLength(); + + byte[] len = BinaryUtils.convert(10 + tripletDataLen, 2); + data[1] = len[0]; + data[2] = len[1]; + + len = BinaryUtils.convert(2 + tripletDataLen, 2); + data[9] = len[0]; + data[10] = len[1]; + + os.write(data); + os.write(tripletData); + } +} diff --git a/src/java/org/apache/fop/afp/modca/MapPageOverlay.java b/src/java/org/apache/fop/afp/modca/MapPageOverlay.java new file mode 100644 index 000000000..9fd3c7059 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/MapPageOverlay.java @@ -0,0 +1,141 @@ +/* + * 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.io.UnsupportedEncodingException; +import java.util.List; + +import org.apache.fop.afp.AFPConstants; +import org.apache.fop.afp.util.BinaryUtils; + +/** + * The Map Page Overlay structured field maps a Resource Local ID to the name of + * a Begin Overlay structured field. A Map Page Overlay structured field may + * contain from one to 254 repeating groups. + */ +public class MapPageOverlay extends AbstractAFPObject { + + private static final int MAX_SIZE = 253; + + /** + * The collection of overlays (maximum of 254 stored as byte[]) + */ + private List overLays = null; + + /** + * Constructor for the Map Page Overlay + */ + public MapPageOverlay() { + } + + private List getOverlays() { + if (overLays == null) { + this.overLays = new java.util.ArrayList(); + } + return this.overLays; + } + + /** + * Add an overlay to to the map page overlay object. + * + * @param name + * The name of the overlay. + * @throws MaximumSizeExceededException if the maximum size is reached + */ + public void addOverlay(String name) throws MaximumSizeExceededException { + if (getOverlays().size() > MAX_SIZE) { + throw new MaximumSizeExceededException(); + } + if (name.length() != 8) { + throw new IllegalArgumentException("The name of overlay " + name + + " must be 8 characters"); + } + if (log.isDebugEnabled()) { + log.debug("addOverlay():: adding overlay " + name); + } + try { + byte[] data = name.getBytes(AFPConstants.EBCIDIC_ENCODING); + getOverlays().add(data); + } catch (UnsupportedEncodingException usee) { + log.error("addOverlay():: UnsupportedEncodingException translating the name " + + name); + } + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + int oLayCount = getOverlays().size(); + int recordlength = oLayCount * 18; + + byte[] data = new byte[recordlength + 9]; + + data[0] = 0x5A; + + // Set the total record length + byte[] rl1 = BinaryUtils.convert(recordlength + 8, 2); //Ignore the + // first byte in + // the length + data[1] = rl1[0]; + data[2] = rl1[1]; + + // Structured field ID for a MPO + data[3] = (byte) 0xD3; + data[4] = (byte) Type.MAP; + data[5] = (byte) Category.PAGE_OVERLAY; + + data[6] = 0x00; // Reserved + data[7] = 0x00; // Reserved + data[8] = 0x00; // Reserved + + int pos = 8; + + //For each overlay + byte olayref = 0x00; + + for (int i = 0; i < oLayCount; i++) { + olayref = (byte) (olayref + 1); + + data[++pos] = 0x00; + data[++pos] = 0x12; //the length of repeating group + + data[++pos] = 0x0C; //Fully Qualified Name + data[++pos] = 0x02; + data[++pos] = (byte) 0x84; + data[++pos] = 0x00; + + //now add the name + byte[] name = (byte[]) overLays.get(i); + + for (int j = 0; j < name.length; j++) { + data[++pos] = name[j]; + } + + data[++pos] = 0x04; //Resource Local Identifier (RLI) + data[++pos] = 0x24; + data[++pos] = 0x02; + + //now add the unique id to the RLI + data[++pos] = olayref; + } + os.write(data); + } +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/modca/MaximumSizeExceededException.java b/src/java/org/apache/fop/afp/modca/MaximumSizeExceededException.java new file mode 100644 index 000000000..6d1c74156 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/MaximumSizeExceededException.java @@ -0,0 +1,37 @@ +/* + * 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 exception to handle maximum sizes being exceeded. + * + */ +public class MaximumSizeExceededException extends Exception { + + private static final long serialVersionUID = 7823120005542216446L; + + /** + * Default constructor + */ + public MaximumSizeExceededException() { + super(); + } + +} diff --git a/src/java/org/apache/fop/afp/modca/NoOperation.java b/src/java/org/apache/fop/afp/modca/NoOperation.java new file mode 100644 index 000000000..cb5841346 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/NoOperation.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.afp.modca; + +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.fop.afp.AFPConstants; +import org.apache.fop.afp.util.BinaryUtils; + +/** + * The No Operation structured field may be used to carry comments + * or any other type of unarchitected data. Although not recommended, + * it may also be used to carry semantic data in private or exchange data + * streams. However, because receivers of interchange data streams should + * ignore the content of No Operation structured fields and because + * receiver-generator products are not required to propagate + * No Operation structured fields, no semantics should be attached to + * the data carried by the No Operation structured field in interchange + */ +public class NoOperation extends AbstractAFPObject { + + /** Up to 32759 bytes of data with no architectural definition */ + private static final int MAX_DATA_LEN = 32759; + + /** + * Byte representation of the comment + */ + private String content; + + /** + * Construct a tag logical element with the name and value specified. + * + * @param content the content to record + */ + public NoOperation(String content) { + this.content = content; + } + + /** + * Accessor method to obtain the byte array AFP datastream for the + * NoOperation. + * + * @param os The outputsteam stream + * @throws java.io.IOException if an I/O exception occurs during processing + */ + public void writeToStream(OutputStream os) throws IOException { + byte[] contentData = content.getBytes(AFPConstants.EBCIDIC_ENCODING); + int contentLen = contentData.length; + + // packet maximum of 32759 bytes + if (contentLen > MAX_DATA_LEN) { + contentLen = MAX_DATA_LEN; + } + + byte[] data = new byte[9 + contentLen]; + + data[0] = 0x5A; + + // Set the total record length + byte[] rl1 = BinaryUtils.convert(8 + contentLen, 2); + + //Ignore first byte + data[1] = rl1[0]; + data[2] = rl1[1]; + + // Structured field ID for a TLE + data[3] = (byte) 0xD3; + data[4] = (byte) 0xEE; + data[5] = (byte) 0xEE; + + data[6] = 0x00; // Reserved + data[7] = 0x00; // Reserved + data[8] = 0x00; // Reserved + + int pos = 9; + for (int i = 0; i < contentLen; i++) { + data[pos++] = contentData[i]; + } + os.write(data); + } + +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/modca/ObjectAreaDescriptor.java b/src/java/org/apache/fop/afp/modca/ObjectAreaDescriptor.java new file mode 100644 index 000000000..21c21e39f --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/ObjectAreaDescriptor.java @@ -0,0 +1,87 @@ +/* + * 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 org.apache.commons.io.output.ByteArrayOutputStream; +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; + +/** + * The Object Area Descriptor structured field specifies the size and attributes + * of an object area presentation space. + */ +public class ObjectAreaDescriptor extends AbstractDescriptor { + + /** + * Construct an object area descriptor for the specified object width + * and object height. + * + * @param width the object width. + * @param height the object height. + * @param widthRes the object width resolution. + * @param heightRes the object height resolution. + */ + public ObjectAreaDescriptor(int width, int height, int widthRes, int heightRes) { + 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; + } + + /** {@inheritDoc} */ + public void writeStart(OutputStream os) throws IOException { + super.writeStart(os); + byte[] data = new byte[9]; + copySF(data, Type.DESCRIPTOR, Category.OBJECT_AREA); + byte[] len = BinaryUtils.convert(data.length + tripletData.length - 1, 2); + data[1] = len[0]; // Length + data[2] = len[1]; + os.write(data); + } + +} diff --git a/src/java/org/apache/fop/afp/modca/ObjectAreaPosition.java b/src/java/org/apache/fop/afp/modca/ObjectAreaPosition.java new file mode 100644 index 000000000..3929c1196 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/ObjectAreaPosition.java @@ -0,0 +1,112 @@ +/* + * 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 org.apache.fop.afp.util.BinaryUtils; + +/** + * The Object Area Position structured field specifies the origin and + * orientation of the object area, and the origin and orientation of the + * object content within the object area. + */ +public class ObjectAreaPosition extends AbstractAFPObject { + + private final int x; + private final int y; + private final int rotation; + private int xOffset; + private int yOffset; + + /** + * Construct an object area position for the specified object y, y position. + * + * @param x The x coordinate. + * @param y The y coordinate. + * @param rotation The coordinate system rotation (must be 0, 90, 180, 270). + */ + public ObjectAreaPosition(int x, int y, int rotation) { + this.x = x; + this.y = y; + this.rotation = rotation; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = new byte[33]; + copySF(data, Type.POSITION, Category.OBJECT_AREA); + + byte[] len = BinaryUtils.convert(32, 2); + data[1] = len[0]; // Length + data[2] = len[1]; + + data[9] = 0x01; // OAPosID = 1 + data[10] = 0x17; // RGLength = 23 + + byte[] xcoord = BinaryUtils.convert(x, 3); + data[11] = xcoord[0]; // XoaOSet + data[12] = xcoord[1]; + data[13] = xcoord[2]; + + byte[] ycoord = BinaryUtils.convert(y, 3); + data[14] = ycoord[0]; // YoaOSet + data[15] = ycoord[1]; + data[16] = ycoord[2]; + + byte xorient = (byte)(rotation / 2); + data[17] = xorient; // XoaOrent + + byte yorient = (byte)(rotation / 2 + 45); + data[19] = yorient; // YoaOrent + + byte[] xoffset = BinaryUtils.convert(xOffset, 3); + data[22] = xoffset[0]; // XocaOSet + data[23] = xoffset[1]; + data[24] = xoffset[2]; + + byte[] yoffset = BinaryUtils.convert(yOffset, 3); + data[25] = yoffset[0]; // YocaOSet + data[26] = yoffset[1]; + data[27] = yoffset[2]; + + data[28] = 0x00; // XocaOrent + data[29] = 0x00; + + data[30] = 0x2D; // YocaOrent + data[31] = 0x00; + + data[32] = 0x01; // RefCSys + + os.write(data); + } + + /** {@inheritDoc} */ + public String toString() { + return "ObjectAreaPosition{" + + "x=" + x + + ", y=" + y + + ", rotation=" + rotation + + ", rotation=" + rotation + + ", xOffset=" + xOffset + + ", yOffset=" + yOffset; + } +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/modca/ObjectContainer.java b/src/java/org/apache/fop/afp/modca/ObjectContainer.java new file mode 100644 index 000000000..791f4da1b --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/ObjectContainer.java @@ -0,0 +1,124 @@ +/* + * 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 org.apache.commons.io.IOUtils; +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.Factory; +import org.apache.fop.afp.modca.triplets.MappingOptionTriplet; +import org.apache.fop.afp.util.BinaryUtils; + +/** + * Object containers are MO:DCA objects that envelop and carry object data. + */ +public class ObjectContainer extends AbstractDataObject { + + /** the object container data maximum length */ + private static final int MAX_DATA_LEN = 32759; + + private InputStream inputStream; + + /** + * Main constructor + * + * @param factory the object factory + * @param name the name of this object container + */ + public ObjectContainer(Factory factory, String name) { + super(factory, name); + } + + /** {@inheritDoc} */ + protected void writeStart(OutputStream os) throws IOException { + byte[] headerData = new byte[17]; + copySF(headerData, Type.BEGIN, Category.OBJECT_CONTAINER); + + // Set the total record length + int containerLen = headerData.length + getTripletDataLength() - 1; + byte[] len = BinaryUtils.convert(containerLen, 2); + headerData[1] = len[0]; // Length byte 1 + headerData[2] = len[1]; // Length byte 2 + + os.write(headerData); + } + + /** {@inheritDoc} */ + protected void writeContent(OutputStream os) throws IOException { + super.writeContent(os); // write triplets and OEG + + // write OCDs + byte[] dataHeader = new byte[9]; + copySF(dataHeader, SF_CLASS, Type.DATA, Category.OBJECT_CONTAINER); + final int lengthOffset = 1; + + copyChunks(dataHeader, lengthOffset, MAX_DATA_LEN, inputStream, os); + IOUtils.closeQuietly(inputStream); + } + + /** {@inheritDoc} */ + protected void writeEnd(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.END, Category.OBJECT_CONTAINER); + os.write(data); + } + + /** {@inheritDoc} */ + public void setViewport(AFPDataObjectInfo dataObjectInfo) { + AFPResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); + AFPResourceLevel resourceLevel = resourceInfo.getLevel(); + + // only need to set MCD and CDD when OC when is inlined (pre-2000 apps) + if (resourceLevel.isInline()) { + super.setViewport(dataObjectInfo); + + MapContainerData mapContainerData + = factory.createMapContainerData(MappingOptionTriplet.SCALE_TO_FIT); + getObjectEnvironmentGroup().setMapContainerData(mapContainerData); + + int dataWidth = dataObjectInfo.getDataWidth(); + int dataHeight = dataObjectInfo.getDataHeight(); + + AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo(); + int widthRes = objectAreaInfo.getWidthRes(); + int heightRes = objectAreaInfo.getHeightRes(); + + ContainerDataDescriptor containerDataDescriptor + = factory.createContainerDataDescriptor( + dataWidth, dataHeight, widthRes, heightRes); + getObjectEnvironmentGroup().setDataDescriptor(containerDataDescriptor); + } + } + + /** + * Sets the inputstream for the the object container data + * + * @param inputStream the inputstream for the object container data + */ + public void setInputStream(InputStream inputStream) { + this.inputStream = inputStream; + } +} diff --git a/src/java/org/apache/fop/afp/modca/ObjectEnvironmentGroup.java b/src/java/org/apache/fop/afp/modca/ObjectEnvironmentGroup.java new file mode 100644 index 000000000..8cb610d9e --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/ObjectEnvironmentGroup.java @@ -0,0 +1,173 @@ +/* + * 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 org.apache.fop.afp.util.BinaryUtils; + +/** + * An Object Environment Group (OEG) may be associated with an object and is contained + * within the object's begin-end envelope. + * The object environment group defines the object's origin and orientation on the page, + * and can contain font and color attribute table information. The scope of an object + * environment group is the scope of its containing object. + * + * An application that creates a data-stream document may omit some of the parameters + * normally contained in the object environment group, or it may specify that one or + * more default values are to be used. + */ +public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { + + /** the PresentationEnvironmentControl for the object environment group */ + private PresentationEnvironmentControl presentationEnvironmentControl = null; + + /** the ObjectAreaDescriptor for the object environment group */ + private ObjectAreaDescriptor objectAreaDescriptor = null; + + /** the ObjectAreaPosition for the object environment group */ + private ObjectAreaPosition objectAreaPosition = null; + + /** the DataDescriptor for the object environment group */ + private AbstractDescriptor dataDescriptor; + + /** the MapDataResource for the object environment group */ + private MapDataResource mapDataResource; + + /** the MapContainerData for the object environment group */ + private MapContainerData mapContainerData; + + /** + * Constructor for the ObjectEnvironmentGroup, this takes a + * name parameter which must be 8 characters long. + * + * @param name the object environment group name + */ + public ObjectEnvironmentGroup(String name) { + super(name); + } + + /** + * Sets the Object Area Descriptor + * + * @param objectAreaDescriptor the object area descriptor + */ + public void setObjectAreaDescriptor(ObjectAreaDescriptor objectAreaDescriptor) { + this.objectAreaDescriptor = objectAreaDescriptor; + } + + /** + * Sets the Object Area Position + * + * @param objectAreaPosition the object area position + */ + public void setObjectAreaPosition(ObjectAreaPosition objectAreaPosition) { + this.objectAreaPosition = objectAreaPosition; + } + + /** {@inheritDoc} */ + protected void writeStart(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.BEGIN, Category.OBJECT_ENVIRONMENT_GROUP); + + int tripletDataLength = getTripletDataLength(); + int sfLen = data.length + tripletDataLength - 1; + byte[] len = BinaryUtils.convert(sfLen, 2); + data[1] = len[0]; + data[2] = len[1]; + + os.write(data); + } + + /** {@inheritDoc} */ + protected void writeContent(OutputStream os) throws IOException { + super.writeContent(os); + + if (presentationEnvironmentControl != null) { + presentationEnvironmentControl.writeToStream(os); + } + + if (objectAreaDescriptor != null) { + objectAreaDescriptor.writeToStream(os); + } + + if (objectAreaPosition != null) { + objectAreaPosition.writeToStream(os); + } + + if (mapContainerData != null) { + mapContainerData.writeToStream(os); + } + + if (mapDataResource != null) { + mapDataResource.writeToStream(os); + } + + if (dataDescriptor != null) { + dataDescriptor.writeToStream(os); + } + } + + /** {@inheritDoc} */ + protected void writeEnd(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.END, Category.OBJECT_ENVIRONMENT_GROUP); + os.write(data); + } + + /** + * Sets the presentation environment control + * + * @param presentationEnvironmentControl the presentation environment control + */ + public void setPresentationEnvironmentControl( + PresentationEnvironmentControl presentationEnvironmentControl) { + this.presentationEnvironmentControl = presentationEnvironmentControl; + } + + /** + * Sets the data descriptor + * + * @param dataDescriptor the data descriptor + */ + public void setDataDescriptor(AbstractDescriptor dataDescriptor) { + this.dataDescriptor = dataDescriptor; + } + + /** + * Sets the map data resource + * + * @param mapDataResource the map data resource + */ + public void setMapDataResource(MapDataResource mapDataResource) { + this.mapDataResource = mapDataResource; + } + + /** + * Sets the map container data + * + * @param mapContainerData the map container data + */ + public void setMapContainerData(MapContainerData mapContainerData) { + this.mapContainerData = mapContainerData; + } + +} diff --git a/src/java/org/apache/fop/afp/modca/Overlay.java b/src/java/org/apache/fop/afp/modca/Overlay.java new file mode 100644 index 000000000..ea9619b20 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/Overlay.java @@ -0,0 +1,87 @@ +/* + * 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 org.apache.fop.afp.Factory; + + +/** + * An overlay is a MO:DCA-P resource object. + * + * It may be stored in an external resource library or it may be + * carried in a resource group. An overlay is similar to a page in + * that it defines its own environment and carries the same data objects. + */ +public class Overlay extends PageObject { + + /** + * Construct a new overlay object for the specified name argument, the overlay + * name should be an 8 character identifier. + * + * @param factory + * the resource manager of the page. + * @param name + * the name of the page. + * @param width + * the width of the page. + * @param height + * the height of the page. + * @param rotation + * the rotation of the page. + * @param widthResolution + * the width resolution of the page. + * @param heightResolution + * the height resolution of the page. + */ + public Overlay(Factory factory, + String name, int width, int height, int rotation, + int widthResolution, int heightResolution) { + super(factory, name, width, height, rotation, widthResolution, heightResolution); + } + + /** {@inheritDoc} */ + protected void writeStart(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.BEGIN, Category.OVERLAY); + os.write(data); + } + + /** {@inheritDoc} */ + protected void writeContent(OutputStream os) throws IOException { + super.writeContent(os); + + getActiveEnvironmentGroup().writeToStream(os); + + writeObjects(includePageSegments, os); + writeObjects(tagLogicalElements, os); + writeObjects(objects, os); + } + + + /** {@inheritDoc} */ + protected void writeEnd(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.END, Category.OVERLAY); + os.write(data); + } +} diff --git a/src/java/org/apache/fop/afp/modca/PageDescriptor.java b/src/java/org/apache/fop/afp/modca/PageDescriptor.java new file mode 100644 index 000000000..502123def --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/PageDescriptor.java @@ -0,0 +1,88 @@ +/* + * 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 org.apache.fop.afp.util.BinaryUtils; + +/** + * The Page Descriptor structured field specifies the size and attributes of + * a page or overlay presentation space. + * + */ +public class PageDescriptor extends AbstractDescriptor { + + /** + * Construct a page descriptor for the specified page width + * and page height. + * + * @param width The page width. + * @param height The page height. + * @param widthRes The page width resolution + * @param heightRes The page height resolution + */ + public PageDescriptor(int width, int height, int widthRes, int heightRes) { + super(width, height, widthRes, heightRes); + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = new byte[24]; + copySF(data, Type.DESCRIPTOR, Category.PAGE); + data[2] = 0x17; + + // XpgBase + data[9] = 0x00; // XpgBase = 10 inches + + // YpgBase + data[10] = 0x00; // YpgBase = 10 inches + + // XpgUnits + byte[] xdpi = BinaryUtils.convert(widthRes * 10, 2); + data[11] = xdpi[0]; + data[12] = xdpi[1]; + + // YpgUnits + byte[] ydpi = BinaryUtils.convert(heightRes * 10, 2); + data[13] = ydpi[0]; + data[14] = ydpi[1]; + + // XpgSize + byte[] x = BinaryUtils.convert(width, 3); + data[15] = x[0]; + data[16] = x[1]; + data[17] = x[2]; + + // YpgSize + byte[] y = BinaryUtils.convert(height, 3); + data[18] = y[0]; + data[19] = y[1]; + data[20] = y[2]; + + data[21] = 0x00; // Reserved + data[22] = 0x00; // Reserved + data[23] = 0x00; // Reserved + + os.write(data); + } + +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/modca/PageGroup.java b/src/java/org/apache/fop/afp/modca/PageGroup.java new file mode 100644 index 000000000..47e378d72 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/PageGroup.java @@ -0,0 +1,105 @@ +/* + * 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.List; + +import org.apache.fop.afp.Factory; + +/** + * A page group is used in the data stream to define a named, logical grouping + * of sequential pages. Page groups are delimited by begin-end structured fields + * that carry the name of the page group. Page groups are defined so that the + * pages that comprise the group can be referenced or processed as a single + * entity. Page groups are often processed in stand-alone fashion; that is, they + * are indexed, retrieved, and presented outside the context of the containing + * document. + */ +public class PageGroup extends AbstractResourceEnvironmentGroupContainer { + + /** The tag logical elements contained within this group */ + private List tagLogicalElements = null; + + /** + * Constructor for the PageGroup. + * + * @param factory the resource manager + * @param name the name of the page group + */ + public PageGroup(Factory factory, String name) { + super(factory, name); + } + + private List getTagLogicalElements() { + if (tagLogicalElements == null) { + this.tagLogicalElements = new java.util.ArrayList(); + } + return this.tagLogicalElements; + } + + /** + * Creates a TagLogicalElement on the page. + * + * @param name + * the name of the tag + * @param value + * the value of the tag + */ + public void createTagLogicalElement(String name, String value) { + TagLogicalElement tle = factory.createTagLogicalElement(name, value); + if (!getTagLogicalElements().contains(tle)) { + getTagLogicalElements().add(tle); + } + } + + /** + * Method to mark the end of the page group. + */ + protected void endPageGroup() { + complete = true; + } + + /** {@inheritDoc} */ + protected void writeContent(OutputStream os) throws IOException { + writeObjects(tagLogicalElements, os); + super.writeContent(os); + } + + /** {@inheritDoc} */ + protected void writeStart(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.BEGIN, Category.PAGE_GROUP); + os.write(data); + } + + /** {@inheritDoc} */ + protected void writeEnd(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.END, Category.PAGE_GROUP); + os.write(data); + } + + /** {@inheritDoc} */ + public String toString() { + return this.getName(); + } +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/modca/PageObject.java b/src/java/org/apache/fop/afp/modca/PageObject.java new file mode 100644 index 000000000..33852d90b --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/PageObject.java @@ -0,0 +1,219 @@ +/* + * 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 org.apache.fop.afp.Factory; +import org.apache.fop.afp.ioca.ImageCellPosition; +import org.apache.fop.afp.ioca.ImageInputDescriptor; +import org.apache.fop.afp.ioca.ImageOutputControl; +import org.apache.fop.afp.ioca.ImageRasterData; +import org.apache.fop.afp.ioca.ImageRasterPattern; + +/** + * Pages contain the data objects that comprise a presentation document. Each + * page has a set of data objects associated with it. Each page within a + * document is independent from any other page, and each must establish its own + * environment parameters. + * + * The page is the level in the document component hierarchy that is used for + * printing or displaying a document's content. The data objects contained in + * the page envelope in the data stream are presented when the page is + * presented. Each data object has layout information associated with it that + * directs the placement and orientation of the data on the page. In addition, + * each page contains layout information that specifies the measurement units, + * page width, and page depth. + * + * A page is initiated by a begin page structured field and terminated by an end + * page structured field. Structured fields that define objects and active + * environment groups or that specify attributes of the page may be encountered + * in page state. + * + */ +public class PageObject extends AbstractResourceGroupContainer { + + /** + * Construct a new page object for the specified name argument, the page + * name should be an 8 character identifier. + * + * @param factory the resource manager + * + * @param name + * the name of the page. + * @param width + * the width of the page. + * @param height + * the height of the page. + * @param rotation + * the rotation of the page. + * @param widthRes + * the width resolution of the page. + * @param heightRes + * the height resolution of the page. + */ + public PageObject(Factory factory, + String name, int width, int height, int rotation, + int widthRes, int heightRes) { + super(factory, name, width, height, rotation, widthRes, heightRes); + } + + /** + * Creates an IncludePageOverlay on the page. + * + * @param name + * the name of the overlay + * @param x + * the x position of the overlay + * @param y + * the y position of the overlay + * @param orientation + * the orientation required for the overlay + */ + public void createIncludePageOverlay(String name, int x, int y, int orientation) { + getActiveEnvironmentGroup().createOverlay(name); + IncludePageOverlay ipo = new IncludePageOverlay(name, x, y, orientation); + addObject(ipo); + } + + /** + * 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 grayscale). + * + * @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 red + * the red value + * @param green + * the green value + * @param blue + * the blue value + */ + public void createShading(int x, int y, int w, int h, int red, int green, int blue) { + int xCoord = 0; + int yCoord = 0; + int areaWidth = 0; + int areaHeight = 0; + switch (rotation) { + case 90: + xCoord = areaWidth - y - h; + yCoord = x; + areaWidth = h; + areaHeight = w; + break; + case 180: + xCoord = areaWidth - x - w; + yCoord = areaHeight - y - h; + areaWidth = w; + areaHeight = h; + break; + case 270: + xCoord = y; + yCoord = areaHeight - x - w; + areaWidth = h; + areaHeight = w; + break; + default: + xCoord = x; + yCoord = y; + areaWidth = w; + areaHeight = h; + break; + } + + // Convert the color to grey scale + float shade = (float) ((red * 0.3) + (green * 0.59) + (blue * 0.11)); + + int grayscale = Math.round((shade / 255) * 16); + + IMImageObject imImageObject = factory.createIMImageObject(); + + ImageOutputControl imageOutputControl = new ImageOutputControl(0, 0); + ImageInputDescriptor imageInputDescriptor = new ImageInputDescriptor(); + ImageCellPosition imageCellPosition = new ImageCellPosition(xCoord, yCoord); + imageCellPosition.setXFillSize(areaWidth); + imageCellPosition.setYFillSize(areaHeight); + imageCellPosition.setXSize(64); + imageCellPosition.setYSize(8); + + //defining this as a resource + byte[] rasterData = ImageRasterPattern.getRasterData(grayscale); + ImageRasterData imageRasterData = factory.createImageRasterData(rasterData); + + imImageObject.setImageOutputControl(imageOutputControl); + imImageObject.setImageInputDescriptor(imageInputDescriptor); + imImageObject.setImageCellPosition(imageCellPosition); + imImageObject.setImageRasterData(imageRasterData); + addObject(imImageObject); + } + + /** {@inheritDoc} */ + protected void writeStart(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.BEGIN, Category.PAGE); + os.write(data); + } + + /** {@inheritDoc} */ + protected void writeContent(OutputStream os) throws IOException { + writeTriplets(os); + + getActiveEnvironmentGroup().writeToStream(os); + + writeObjects(includePageSegments, os); + writeObjects(tagLogicalElements, os); + writeObjects(objects, os); + } + + /** {@inheritDoc} */ + protected void writeEnd(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.END, Category.PAGE); + os.write(data); + } + + /** + * Adds an AFP object reference to this page + * + * @param obj an AFP object + */ + public void addObject(Object obj) { + endPresentationObject(); + super.addObject(obj); + } + + /** {@inheritDoc} */ + public String toString() { + return this.getName(); + } + + /** {@inheritDoc} */ + protected boolean canWrite(AbstractAFPObject ao) { + return true; + } +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/modca/PageSegment.java b/src/java/org/apache/fop/afp/modca/PageSegment.java new file mode 100644 index 000000000..ab1388efb --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/PageSegment.java @@ -0,0 +1,90 @@ +/* + * 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.List; + +/** + * A page segment is a MO:DCA-P resource object. It may be stored in an + * external resource library or it may be carried in a resource group. + * Page segments contain any combination of IOCA image objects and + * GOCA graphics objects. + */ +public class PageSegment extends AbstractNamedAFPObject { + + private List/**/ objects = null; + + /** + * Main constructor + * + * @param name the name of this object + */ + public PageSegment(String name) { + super(name); + } + + /** + * Returns a list of objects contained withing this page segment + * + * @return a list of objects contained within this page segment + */ + public List/**/ getObjects() { + if (objects == null) { + objects = new java.util.ArrayList(); + } + return objects; + } + + /** + * Adds a resource object (image/graphic) to this page segment + * + * @param object the resource objec to add to this page segment + */ + public void addObject(AbstractAFPObject object) { + getObjects().add(object); + } + + /** {@inheritDoc} */ + protected void writeStart(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.BEGIN, Category.PAGE_SEGMENT); + os.write(data); + } + + /** {@inheritDoc} */ + protected void writeContent(OutputStream os) throws IOException { + super.writeContent(os); + writeObjects(objects, os); + } + + /** {@inheritDoc} */ + protected void writeEnd(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.END, Category.PAGE_SEGMENT); + os.write(data); + } + + /** {@inheritDoc} */ + public String toString() { + return this.name; + } +} diff --git a/src/java/org/apache/fop/afp/modca/PreparedAFPObject.java b/src/java/org/apache/fop/afp/modca/PreparedAFPObject.java new file mode 100644 index 000000000..2771515bf --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/PreparedAFPObject.java @@ -0,0 +1,34 @@ +/* + * 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 new file mode 100644 index 000000000..b1f95e236 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/PreprocessPresentationObject.java @@ -0,0 +1,145 @@ +/* + * 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 org.apache.fop.afp.modca.triplets.FullyQualifiedNameTriplet; +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. + */ +public class PreprocessPresentationObject extends AbstractStructuredAFPObject { + 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 + */ + public PreprocessPresentationObject(AbstractStructuredAFPObject prePresObj) { + if (prePresObj instanceof ImageObject || prePresObj instanceof Overlay) { + if (prePresObj instanceof ImageObject) { + this.objType = TYPE_IMAGE; + } else { + this.objType = TYPE_OVERLAY; + } + setFullyQualifiedName( + 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; + } + + /** + * 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; + } + + /** + * Sets the Y axis origin for object content + * + * @param yOffset the Y axis origin for object content + */ + public void setYOffset(int yOffset) { + this.objYOffset = yOffset; + } + + /** {@inheritDoc} */ + public void writeStart(OutputStream os) throws IOException { + super.writeStart(os); + + byte[] data = new byte[9]; + copySF(data, Type.PROCESS, Category.DATA_RESOURCE); + + byte[] l = BinaryUtils.convert(19 + getTripletDataLength(), 2); + data[1] = l[0]; // Length byte 1 + data[2] = l[1]; // Length byte 1 + + os.write(data); + } + + /** {@inheritDoc} */ + public void writeContent(OutputStream os) throws IOException { + byte[] data = new byte[12]; + byte[] l = BinaryUtils.convert(12 + getTripletDataLength(), 2); + data[0] = l[0]; // RGLength + data[1] = l[1]; // RGLength + data[2] = objType; // ObjType + data[3] = 0x00; // Reserved + data[4] = 0x00; // Reserved + data[5] = objOrent; // ObjOrent + if (objXOffset > 0) { + byte[] xOff = BinaryUtils.convert(objYOffset, 3); + data[6] = xOff[0]; // XocaOset (not specified) + data[7] = xOff[1]; // XocaOset + data[8] = xOff[2]; // XocaOset + } else { + data[6] = (byte)0xFF; // XocaOset (not specified) + data[7] = (byte)0xFF; // XocaOset + data[8] = (byte)0xFF; // XocaOset + } + if (objYOffset > 0) { + byte[] yOff = BinaryUtils.convert(objYOffset, 3); + data[9] = yOff[0]; // YocaOset (not specified) + data[10] = yOff[1]; // YocaOset + data[11] = yOff[2]; // YocaOset + } else { + data[9] = (byte)0xFF; // YocaOset (not specified) + data[10] = (byte)0xFF; // YocaOset + 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 new file mode 100644 index 000000000..49b33c0ef --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/PresentationEnvironmentControl.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +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; + +/** + * The Presentation Environment Control structured field specifies parameters that + * affect the rendering of presentation data and the appearance that is to be assumed + * by the presentation device. + */ +public class PresentationEnvironmentControl extends AbstractStructuredAFPObject { + + /** + * Main constructor + */ + 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]; + copySF(data, Type.CONTROL, Category.DOCUMENT); + int tripletDataLen = getTripletDataLength(); + byte[] len = BinaryUtils.convert(10 + tripletDataLen); + data[1] = len[0]; + data[2] = len[1]; + data[9] = 0x00; // Reserved; must be zero + data[10] = 0x00; // Reserved; must be zero + + os.write(data); + os.write(tripletData); + } + + // TODO + private class DeviceAppearanceTriplet extends Triplet { + public DeviceAppearanceTriplet() { + super(Triplet.DEVICE_APPEARANCE); + } + } + + // TODO + private class RenderingIntentTriplet extends Triplet { + public RenderingIntentTriplet() { + super(Triplet.RENDERING_INTENT); + } + } + + // TODO + private class ObjectOffsetTriplet extends Triplet { + public ObjectOffsetTriplet() { + super(Triplet.OBJECT_OFFSET); + } + } +} diff --git a/src/java/org/apache/fop/afp/modca/PresentationTextData.java b/src/java/org/apache/fop/afp/modca/PresentationTextData.java new file mode 100644 index 000000000..4bc2b914e --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/PresentationTextData.java @@ -0,0 +1,569 @@ +/* + * 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.io.IOException; +import java.io.OutputStream; + +import org.apache.commons.io.output.ByteArrayOutputStream; +import org.apache.fop.afp.AFPLineDataInfo; +import org.apache.fop.afp.AFPTextDataInfo; +import org.apache.fop.afp.util.BinaryUtils; + +/** + * Presentation text data contains the graphic characters and the control + * sequences necessary to position the characters within the object space. The + * data consists of: - graphic characters to be presented - control sequences + * that position them - modal control sequences that adjust the positions by + * small amounts - other functions causing text to be presented with differences + * in appearance. + * + * The graphic characters are expected to conform to a coded font representation + * so that they can be translated from the code point in the object data to the + * character in the coded font. The units of measure for linear displacements + * are derived from the PresentationTextDescriptor or from the hierarchical + * defaults. + * + * In addition to graphic character code points, Presentation Text data can + * contain embedded control sequences. These are strings of two or more bytes + * which signal an alternate mode of processing for the content of the current + * Presentation Text data. + * + */ +public class PresentationTextData extends AbstractAFPObject { + + /** + * The maximum size of the presentation text data. + */ + private static final int MAX_SIZE = 8192; + + /** + * The afp data relating to this presentation text data. + */ + private final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + /** + * The current x coordinate. + */ + private int currentX = -1; + + /** + * The current y cooridnate + */ + private int currentY = -1; + + /** + * The current font + */ + private String currentFont = ""; + + /** + * The current orientation + */ + private int currentOrientation = 0; + + /** + * The current color + */ + private Color currentColor = new Color(0, 0, 0); + + /** + * The current variable space increment + */ + private int currentVariableSpaceCharacterIncrement = 0; + + /** + * The current inter character adjustment + */ + private int currentInterCharacterAdjustment = 0; + + /** + * Default constructor for the PresentationTextData. + */ + public PresentationTextData() { + this(false); + } + + /** + * Constructor for the PresentationTextData, the boolean flag indicate + * whether the control sequence prefix should be set to indicate the start + * of a new control sequence. + * + * @param controlInd + * The control sequence indicator. + */ + public PresentationTextData(boolean controlInd) { + final byte[] data = { + 0x5A, // Structured field identifier + 0x00, // Record length byte 1 + 0x00, // Record length byte 2 + (byte) 0xD3, // PresentationTextData identifier byte 1 + (byte) 0xEE, // PresentationTextData identifier byte 2 + (byte) 0x9B, // PresentationTextData identifier byte 3 + 0x00, // Flag + 0x00, // Reserved + 0x00, // Reserved + }; + baos.write(data, 0, 9); + + if (controlInd) { + baos.write(new byte[] {0x2B, (byte) 0xD3}, 0, 2); + } + } + + /** + * The Set Coded Font Local control sequence activates a coded font and + * specifies the character attributes to be used. This is a modal control + * sequence. + * + * @param font + * The font local identifier. + * @param afpdata + * The output stream to which data should be written. + */ + private void setCodedFont(byte font, ByteArrayOutputStream afpdata) { + // Avoid unnecessary specification of the font + if (String.valueOf(font).equals(currentFont)) { + return; + } else { + currentFont = String.valueOf(font); + } + + afpdata.write(new byte[] {0x03, (byte) 0xF1, font}, 0, 3); + } + + /** + * Establishes the current presentation position on the baseline at a new + * I-axis coordinate, which is a specified number of measurement units from + * the B-axis. There is no change to the current B-axis coordinate. + * + * @param coordinate + * The coordinate for the inline move. + * @param afpdata + * The output stream to which data should be written. + */ + private void absoluteMoveInline(int coordinate, + ByteArrayOutputStream afpdata) { + byte[] b = BinaryUtils.convert(coordinate, 2); + afpdata.write(new byte[] {0x04, (byte) 0xC7, b[0], b[1]}, 0, 4); + currentX = coordinate; + } + + /** + * Establishes the baseline and the current presentation position at a new + * B-axis coordinate, which is a specified number of measurement units from + * the I-axis. There is no change to the current I-axis coordinate. + * + * @param coordinate + * The coordinate for the baseline move. + * @param afpdata + * The output stream to which data should be written. + */ + private void absoluteMoveBaseline(int coordinate, + ByteArrayOutputStream afpdata) { + byte[] b = BinaryUtils.convert(coordinate, 2); + afpdata.write(new byte[] {0x04, (byte) 0xD3, b[0], b[1]}, 0, 4); + currentY = coordinate; + } + + private static final int TRANSPARENT_MAX_SIZE = 253; + + /** + * The Transparent Data control sequence contains a sequence of code points + * that are presented without a scan for embedded control sequences. + * + * @param data + * The text data to add. + * @param afpdata + * The output stream to which data should be written. + */ + private void addTransparentData(byte[] data, ByteArrayOutputStream afpdata) { + // Calculate the length + int l = data.length + 2; + if (l > 255) { + // Check that we are not exceeding the maximum length + throw new IllegalArgumentException( + "Transparent data is longer than " + TRANSPARENT_MAX_SIZE + " bytes: " + data); + } + afpdata.write(new byte[] {BinaryUtils.convert(l)[0], (byte) 0xDB}, + 0, 2); + afpdata.write(data, 0, data.length); + } + + /** + * Draws a line of specified length and specified width in the B-direction + * from the current presentation position. The location of the current + * presentation position is unchanged. + * + * @param length + * The length of the rule. + * @param width + * The width of the rule. + * @param afpdata + * The output stream to which data should be written. + */ + private void drawBaxisRule(int length, int width, + ByteArrayOutputStream afpdata) { + afpdata.write(new byte[] { + 0x07, // Length + (byte) 0xE7, // Type + }, 0, 2); + // Rule length + byte[] data1 = BinaryUtils.shortToByteArray((short) length); + afpdata.write(data1, 0, data1.length); + // Rule width + byte[] data2 = BinaryUtils.shortToByteArray((short) width); + afpdata.write(data2, 0, data2.length); + // Rule width fraction + afpdata.write(0x00); + } + + /** + * Draws a line of specified length and specified width in the I-direction + * from the current presentation position. The location of the current + * presentation position is unchanged. + * + * @param length + * The length of the rule. + * @param width + * The width of the rule. + * @param afpdata + * The output stream to which data should be written. + */ + private void drawIaxisRule(int length, int width, + ByteArrayOutputStream afpdata) { + afpdata.write(new byte[] { + 0x07, // Length + (byte) 0xE5, // Type + }, 0, 2); + // Rule length + byte[] data1 = BinaryUtils.shortToByteArray((short) length); + afpdata.write(data1, 0, data1.length); + // Rule width + byte[] data2 = BinaryUtils.shortToByteArray((short) width); + afpdata.write(data2, 0, data2.length); + // Rule width fraction + afpdata.write(0x00); + } + + /** + * Create the presentation text data for the byte array of data. + * + * @param textDataInfo + * the afp text data + * @throws MaximumSizeExceededException + * thrown if the maximum number of text data is exceeded + */ + public void createTextData(AFPTextDataInfo textDataInfo) + throws MaximumSizeExceededException { + + ByteArrayOutputStream afpdata = new ByteArrayOutputStream(); + + int rotation = textDataInfo.getRotation(); + if (currentOrientation != rotation) { + setTextOrientation(rotation, afpdata); + currentOrientation = rotation; + currentX = -1; + currentY = -1; + } + + // Avoid unnecessary specification of the Y coordinate + int y = textDataInfo.getY(); + if (currentY != y) { + absoluteMoveBaseline(y, afpdata); + currentX = -1; + } + + // Avoid unnecessary specification of the X coordinate + int x = textDataInfo.getX(); + if (currentX != x) { + absoluteMoveInline(x, afpdata); + } + + // Avoid unnecessary specification of the variable space increment + if (textDataInfo.getVariableSpaceCharacterIncrement() + != currentVariableSpaceCharacterIncrement) { + setVariableSpaceCharacterIncrement(textDataInfo + .getVariableSpaceCharacterIncrement(), afpdata); + currentVariableSpaceCharacterIncrement = textDataInfo + .getVariableSpaceCharacterIncrement(); + } + + // Avoid unnecessary specification of the inter character adjustment + if (textDataInfo.getInterCharacterAdjustment() != currentInterCharacterAdjustment) { + setInterCharacterAdjustment(textDataInfo.getInterCharacterAdjustment(), + afpdata); + currentInterCharacterAdjustment = textDataInfo + .getInterCharacterAdjustment(); + } + + // Avoid unnecessary specification of the text color + if (!textDataInfo.getColor().equals(currentColor)) { + setExtendedTextColor(textDataInfo.getColor(), afpdata); + currentColor = textDataInfo.getColor(); + } + + setCodedFont(BinaryUtils.convert(textDataInfo.getFontReference())[0], + afpdata); + + // Add transparent data + byte[] data = textDataInfo.getData(); + if (data.length <= TRANSPARENT_MAX_SIZE) { + addTransparentData(data, afpdata); + } else { + // data size greater than TRANSPARENT_MAX_SIZE so slice + int numTransData = data.length / TRANSPARENT_MAX_SIZE; + byte[] buff = new byte[TRANSPARENT_MAX_SIZE]; + int currIndex = 0; + for (int transDataCnt = 0; transDataCnt < numTransData; transDataCnt++) { + currIndex = transDataCnt * TRANSPARENT_MAX_SIZE; + System.arraycopy(data, currIndex, buff, 0, TRANSPARENT_MAX_SIZE); + addTransparentData(buff, afpdata); + } + int remainingTransData = data.length / TRANSPARENT_MAX_SIZE; + buff = new byte[remainingTransData]; + System.arraycopy(data, currIndex, buff, 0, remainingTransData); + addTransparentData(buff, afpdata); + } + currentX = -1; + + int dataSize = afpdata.size(); + + if (baos.size() + dataSize > MAX_SIZE) { + currentX = -1; + currentY = -1; + throw new MaximumSizeExceededException(); + } + + byte[] outputdata = afpdata.toByteArray(); + baos.write(outputdata, 0, outputdata.length); + } + + private int ensurePositive(int value) { + if (value < 0) { + return 0; + } + return value; + } + + /** + * Drawing of lines using the starting and ending coordinates, thickness and + * colour arguments. + * + * @param lineDataInfo the line data information. + * @throws MaximumSizeExceededException + * thrown if the maximum number of line data has been exceeded + */ + public void createLineData(AFPLineDataInfo lineDataInfo) throws MaximumSizeExceededException { + + ByteArrayOutputStream afpdata = new ByteArrayOutputStream(); + + int orientation = lineDataInfo.getRotation(); + if (currentOrientation != orientation) { + setTextOrientation(orientation, afpdata); + currentOrientation = orientation; + } + + // Avoid unnecessary specification of the Y coordinate + int y1 = ensurePositive(lineDataInfo.getY1()); + if (y1 != currentY) { + absoluteMoveBaseline(y1, afpdata); + } + + // Avoid unnecessary specification of the X coordinate + int x1 = ensurePositive(lineDataInfo.getX1()); + if (x1 != currentX) { + absoluteMoveInline(x1, afpdata); + } + + Color color = lineDataInfo.getColor(); + if (!color.equals(currentColor)) { + setExtendedTextColor(color, afpdata); + currentColor = color; + } + + int x2 = ensurePositive(lineDataInfo.getX2()); + int y2 = ensurePositive(lineDataInfo.getY2()); + int thickness = lineDataInfo.getThickness(); + if (y1 == y2) { + drawIaxisRule(x2 - x1, thickness, afpdata); + } else if (x1 == x2) { + drawBaxisRule(y2 - y1, thickness, afpdata); + } else { + log.error("Invalid axis rule unable to draw line"); + return; + } + + int dataSize = afpdata.size(); + + if (baos.size() + dataSize > MAX_SIZE) { + currentX = -1; + currentY = -1; + throw new MaximumSizeExceededException(); + } + + byte[] outputdata = afpdata.toByteArray(); + baos.write(outputdata, 0, outputdata.length); + } + + /** + * The Set Text Orientation control sequence establishes the I-direction and + * B-direction for the subsequent text. This is a modal control sequence. + * + * Semantics: This control sequence specifies the I-axis and B-axis + * orientations with respect to the Xp-axis for the current Presentation + * Text object. The orientations are rotational values expressed in degrees + * and minutes. + * + * @param orientation + * The text orientation (0, 90, 180, 270). + * @param os + * The output stream to which data should be written. + */ + private void setTextOrientation(int orientation, + ByteArrayOutputStream os) { + os.write(new byte[] {0x06, (byte) 0xF7, }, 0, 2); + switch (orientation) { + case 90: + os.write(0x2D); + os.write(0x00); + os.write(0x5A); + os.write(0x00); + break; + case 180: + os.write(0x5A); + os.write(0x00); + os.write(0x87); + os.write(0x00); + break; + case 270: + os.write(0x87); + os.write(0x00); + os.write(0x00); + os.write(0x00); + break; + default: + os.write(0x00); + os.write(0x00); + os.write(0x2D); + os.write(0x00); + break; + } + } + + /** + * The Set Extended Text Color control sequence specifies a color value and + * defines the color space and encoding for that value. The specified color + * value is applied to foreground areas of the text presentation space. This + * is a modal control sequence. + * + * @param col + * The color to be set. + * @param os + * The output stream to which data should be written. + */ + private void setExtendedTextColor(Color col, ByteArrayOutputStream os) { + byte[] colorData = new byte[] { + 15, // Control sequence length + (byte) 0x81, // Control sequence function type + 0x00, // Reserved; must be zero + 0x01, // Color space - 0x01 = RGB + 0x00, // Reserved; must be zero + 0x00, // Reserved; must be zero + 0x00, // Reserved; must be zero + 0x00, // Reserved; must be zero + 8, // Number of bits in component 1 + 8, // Number of bits in component 2 + 8, // Number of bits in component 3 + 0, // Number of bits in component 4 + (byte) (col.getRed()), // Red intensity + (byte) (col.getGreen()), // Green intensity + (byte) (col.getBlue()), // Blue intensity + }; + + os.write(colorData, 0, colorData.length); + } + + /** + * //TODO This is a modal control sequence. + * + * @param incr + * The increment to be set. + * @param os + * The output stream to which data should be written. + */ + private void setVariableSpaceCharacterIncrement(int incr, + ByteArrayOutputStream os) { + byte[] b = BinaryUtils.convert(incr, 2); + + os.write(new byte[] { + 4, // Control sequence length + (byte) 0xC5, // Control sequence function type + b[0], b[1] }, + 0, 4); + } + + /** + * //TODO This is a modal control sequence. + * + * @param incr + * The increment to be set. + * @param os + * The output stream to which data should be written. + */ + private void setInterCharacterAdjustment(int incr, ByteArrayOutputStream os) { + byte[] b = BinaryUtils.convert(Math.abs(incr), 2); + os.write(new byte[] { + 5, // Control sequence length + (byte) 0xC3, // Control sequence function type + b[0], b[1], (byte) (incr >= 0 ? 0 : 1) // Direction + }, 0, 5); + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = baos.toByteArray(); + byte[] size = BinaryUtils.convert(data.length - 1, 2); + data[1] = size[0]; + data[2] = size[1]; + os.write(data); + } + + /** + * A control sequence is a sequence of bytes that specifies a control + * function. A control sequence consists of a control sequence introducer + * and zero or more parameters. The control sequence can extend multiple + * presentation text data objects, but must eventually be terminated. This + * method terminates the control sequence. + * + * @throws MaximumSizeExceededException + * thrown in the event that maximum size has been exceeded + */ + public void endControlSequence() throws MaximumSizeExceededException { + byte[] data = new byte[2]; + data[0] = 0x02; + data[1] = (byte) 0xF8; + if (data.length + baos.size() > MAX_SIZE) { + throw new MaximumSizeExceededException(); + } + baos.write(data, 0, data.length); + } +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/modca/PresentationTextDescriptor.java b/src/java/org/apache/fop/afp/modca/PresentationTextDescriptor.java new file mode 100644 index 000000000..ef2696da8 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/PresentationTextDescriptor.java @@ -0,0 +1,101 @@ +/* + * 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 org.apache.fop.afp.util.BinaryUtils; + +/** + * The Presentation Text Descriptor specifies the units of measure for the + * Presentation Text object space, the size of the Presentation Text object + * space, and the initial values for modal parameters, called initial text + * conditions. Initial values not provided are defaulted by the controlling + * environment or the receiving device. + * + * The Presentation Text Descriptor provides the following initial values: + * - Unit base + * - Xp-units per unit base + * - Yp-units per unit base + * - Xp-extent of the presentation space + * - Yp-extent of the presentation space + * - Initial text conditions. + * + * The initial text conditions are values provided by the Presentation Text + * Descriptor to initialize the modal parameters of the control sequences. + * Modal control sequences typically are characterized by the word set in + * the name of the control sequence. Modal parameters are identified as such + * in their semantic descriptions. + * + */ +public class PresentationTextDescriptor extends AbstractDescriptor { + + /** + * Constructor a PresentationTextDescriptor for the specified + * width and height. + * + * @param width The width of the page. + * @param height The height of the page. + * @param widthRes The width resolution of the page. + * @param heightRes The height resolution of the page. + */ + public PresentationTextDescriptor(int width, int height, + int widthRes, int heightRes) { + super(width, height, widthRes, heightRes); + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + byte[] data = new byte[23]; + + copySF(data, Type.MIGRATION, Category.PRESENTATION_TEXT); + + data[1] = 0x00; // length + data[2] = 0x16; + + data[9] = 0x00; + data[10] = 0x00; + + byte[] xdpi = BinaryUtils.convert(widthRes * 10, 2); + data[11] = xdpi[0]; // xdpi + data[12] = xdpi[1]; + + byte[] ydpi = BinaryUtils.convert(heightRes * 10, 2); + data[13] = ydpi[0]; // ydpi + data[14] = ydpi[1]; + + byte[] x = BinaryUtils.convert(width, 3); + data[15] = x[0]; + data[16] = x[1]; + data[17] = x[2]; + + byte[] y = BinaryUtils.convert(height, 3); + data[18] = y[0]; + data[19] = y[1]; + data[20] = y[2]; + + data[21] = 0x00; + data[22] = 0x00; + + os.write(data); + } + +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/modca/PresentationTextObject.java b/src/java/org/apache/fop/afp/modca/PresentationTextObject.java new file mode 100644 index 000000000..070a33a84 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/PresentationTextObject.java @@ -0,0 +1,169 @@ +/* + * 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.List; + +import org.apache.fop.afp.AFPLineDataInfo; +import org.apache.fop.afp.AFPTextDataInfo; + +/** + * The Presentation Text object is the data object used in document processing + * environments for representing text which has been prepared for presentation. + * Text, as used here, means an ordered string of characters, such as graphic + * symbols, numbers, and letters, that are suitable for the specific purpose of + * representing coherent information. Text which has been prepared for + * presentation has been reduced to a primitive form through explicit + * specification of the characters and their placement in the presentation + * space. Control sequences which designate specific control functions may be + * embedded within the text. These functions extend the primitive form by + * applying specific characteristics to the text when it is presented. The + * collection of the graphic characters and control codes is called Presentation + * Text, and the object that contains the Presentation Text is called the + * PresentationText object. + */ +public class PresentationTextObject extends AbstractNamedAFPObject { + + /** + * The current presentation text data + */ + private PresentationTextData currentPresentationTextData = null; + + /** + * The presentation text data list + */ + private List/**/ presentationTextDataList = null; + + /** + * Construct a new PresentationTextObject for the specified name argument, + * the name should be an 8 character identifier. + * + * @param name the name of this presentation object + */ + public PresentationTextObject(String name) { + super(name); + } + + /** + * Create the presentation text data for the byte array of data. + * + * @param textDataInfo + * The afp text data + */ + public void createTextData(AFPTextDataInfo textDataInfo) { + if (currentPresentationTextData == null) { + startPresentationTextData(); + } + try { + currentPresentationTextData.createTextData(textDataInfo); + } catch (MaximumSizeExceededException msee) { + endPresentationTextData(); + createTextData(textDataInfo); + } + } + + /** + * Drawing of lines using the starting and ending coordinates, thickness and + * orientation arguments. + * + * @param lineDataInfo the line data information. + */ + public void createLineData(AFPLineDataInfo lineDataInfo) { + if (currentPresentationTextData == null) { + startPresentationTextData(); + } + try { + currentPresentationTextData.createLineData(lineDataInfo); + } catch (MaximumSizeExceededException msee) { + endPresentationTextData(); + createLineData(lineDataInfo); + } + } + + /** + * Helper method to mark the start of the presentation text data + */ + private void startPresentationTextData() { + if (presentationTextDataList == null) { + presentationTextDataList = new java.util.ArrayList/**/(); + } + if (presentationTextDataList.size() == 0) { + currentPresentationTextData = new PresentationTextData(true); + } else { + currentPresentationTextData = new PresentationTextData(); + } + presentationTextDataList.add(currentPresentationTextData); + } + + /** + * Helper method to mark the end of the presentation text data + */ + private void endPresentationTextData() { + this.currentPresentationTextData = null; + } + + /** {@inheritDoc} */ + protected void writeStart(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.BEGIN, Category.PRESENTATION_TEXT); + os.write(data); + } + + /** {@inheritDoc} */ + protected void writeContent(OutputStream os) throws IOException { + writeObjects(this.presentationTextDataList, os); + } + + /** {@inheritDoc} */ + protected void writeEnd(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.END, Category.PRESENTATION_TEXT); + os.write(data); + } + + /** + * A control sequence is a sequence of bytes that specifies a control + * function. A control sequence consists of a control sequence introducer + * and zero or more parameters. The control sequence can extend multiple + * presentation text data objects, but must eventually be terminated. This + * method terminates the control sequence. + */ + public void endControlSequence() { + if (currentPresentationTextData == null) { + startPresentationTextData(); + } + try { + currentPresentationTextData.endControlSequence(); + } catch (MaximumSizeExceededException msee) { + endPresentationTextData(); + endControlSequence(); + } + } + + /** {@inheritDoc} */ + public String toString() { + if (presentationTextDataList != null) { + return presentationTextDataList.toString(); + } + return null; + } +} diff --git a/src/java/org/apache/fop/afp/modca/Registry.java b/src/java/org/apache/fop/afp/modca/Registry.java new file mode 100644 index 000000000..23c72cd39 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/Registry.java @@ -0,0 +1,254 @@ +/* + * 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.util.Collections; + +import org.apache.xmlgraphics.util.MimeConstants; + +/** + * MOD:CA Registry of object types + */ +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_FS45 = 12; + private static final byte COMPID_EPS = 13; + private static final byte COMPID_TIFF = 14; + private static final byte COMPID_GIF = 22; + private static final byte COMPID_JFIF = 23; // jpeg file interchange format + private static final byte COMPID_PDF_SINGLE_PAGE = 25; + private static final byte COMPID_PCL_PAGE_OBJECT = 34; + + /** mime type entry mapping */ + private final java.util.Map/**/ mimeObjectTypeMap + = Collections.synchronizedMap( + new java.util.HashMap/**/()); + + /** singleton instance */ + private static Registry instance = null; + + /** + * Returns a single instance of a MO:DCA Registry + * + * @return a single instance of an MO:DCA Registry + */ + public static Registry getInstance() { + synchronized (Registry.class) { + if (instance == null) { + instance = new Registry(); + } + } + return instance; + } + + /** + * private constructor + */ + private Registry() { + init(); + } + + /** + * Initializes the mimetype map + */ + private void init() { + mimeObjectTypeMap.put( + MimeConstants.MIME_AFP_IOCA_FS10, + new ObjectType( + COMPID_IOCA_FS10, + new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x05}, + "IOCA FS10", + true, + MimeConstants.MIME_AFP_IOCA_FS10 + ) + ); + mimeObjectTypeMap.put( + MimeConstants.MIME_AFP_IOCA_FS11, + new ObjectType( + COMPID_IOCA_FS11, + new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x11}, + "IOCA FS11", + true, + MimeConstants.MIME_AFP_IOCA_FS11 + ) + ); + mimeObjectTypeMap.put( + MimeConstants.MIME_AFP_IOCA_FS45, + new ObjectType( + COMPID_IOCA_FS45, + new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x12}, + "IOCA FS45", + true, + MimeConstants.MIME_AFP_IOCA_FS45 + ) + ); + mimeObjectTypeMap.put( + MimeConstants.MIME_EPS, + new ObjectType( + COMPID_EPS, + new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x0D}, + "Encapsulated Postscript", + true, + MimeConstants.MIME_EPS + ) + ); + mimeObjectTypeMap.put( + MimeConstants.MIME_TIFF, + new ObjectType( + COMPID_TIFF, + new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x0E}, + "TIFF", + true, + MimeConstants.MIME_TIFF + ) + ); + mimeObjectTypeMap.put( + MimeConstants.MIME_GIF, + new ObjectType( + COMPID_GIF, + new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x16}, + "GIF", + true, + MimeConstants.MIME_GIF + ) + ); + mimeObjectTypeMap.put( + MimeConstants.MIME_JPEG, + new ObjectType( + COMPID_JFIF, + new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x17}, + "JFIF", + true, + MimeConstants.MIME_JPEG + ) + ); + mimeObjectTypeMap.put(MimeConstants.MIME_PDF, + new ObjectType( + COMPID_PDF_SINGLE_PAGE, + new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x19}, + "PDF Single-page Object", + true, + MimeConstants.MIME_PDF + ) + ); + mimeObjectTypeMap.put( + MimeConstants.MIME_PCL, + new ObjectType( + COMPID_PCL_PAGE_OBJECT, + new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x22}, + "PCL Page Object", + true, + MimeConstants.MIME_PCL + ) + ); + } + + /** + * Returns the MOD:CA object type given a mimetype + * + * @param mimeType the object mimetype + * @return the MOD:CA object type + */ + public ObjectType getObjectType(String mimeType) { + return (ObjectType)mimeObjectTypeMap.get(mimeType); + } + + /** + * Encapsulates a MOD:CA Registry Object Type entry + */ + public class ObjectType { + private final byte componentId; + private final byte[] oid; + private final String name; + private final boolean includable; + private final String mimeType; + + /** + * Main constructor + * + * @param componentId the component id of this object type + * @param oid the object id of this object type + * @param name the object type name + * @param includable true if this object can be included with an IOB structured field + * @param mimeType the mime type associated with this object type + */ + public ObjectType(byte componentId, byte[] oid, String name, + boolean includable, String mimeType) { + this.name = name; + this.includable = includable; + this.mimeType = mimeType; + this.componentId = componentId; + this.oid = oid; + } + + /** + * Returns a MOD:CA object type OID from a given a componentId + * + * @return the corresponding object type id for a given component id + * or null if the component id is unknown and the object type OID was not found. + */ + public byte[] getOID() { + return this.oid; + } + + /** + * Returns the object type name for the given componentId + * + * @return the object type name for the given componentId + */ + public String getName() { + return this.name; + } + + /** + * Returns the compontentId for this entry + * + * @return the compontentId for this entry + */ + public byte getComponentId() { + return this.componentId; + } + + /** + * Returns true if this component can be included with an IOB structured field + * + * @return true if this component can be included with an IOB structured field + */ + public boolean isIncludable() { + return this.includable; + } + + /** + * Returns the mime type associated with this object type + * + * @return the mime type associated with this object type + */ + public String getMimeType() { + return this.mimeType; + } + + /** {@inheritDoc} */ + public String toString() { + return this.getName(); + } + } +} diff --git a/src/java/org/apache/fop/afp/modca/ResourceEnvironmentGroup.java b/src/java/org/apache/fop/afp/modca/ResourceEnvironmentGroup.java new file mode 100644 index 000000000..cb0653ddd --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/ResourceEnvironmentGroup.java @@ -0,0 +1,134 @@ +/* + * 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.List; + +/** + * 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 + */ + private static final String DEFAULT_NAME = "REG00001"; + + /** + * The maps data resources contained in this resource environment group + */ + private List/**/ mapDataResources = null; + + /** + * 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 + */ + private List/**/ preProcessPresentationObjects = null; + + /** + * The resource environment group state + */ + private boolean complete = false; + + /** + * Default constructor + */ + public ResourceEnvironmentGroup() { + this(DEFAULT_NAME); + } + + private List/**/ getMapDataResources() { + if (mapDataResources == null) { + this.mapDataResources = new java.util.ArrayList/**/(); + } + return this.mapDataResources; + } + + private List getMapPageOverlays() { + if (mapPageOverlays == null) { + this.mapPageOverlays = new java.util.ArrayList(); + } + return this.mapPageOverlays; + } + + private List/**/ getPreprocessPresentationObjects() { + if (preProcessPresentationObjects == null) { + this.preProcessPresentationObjects + = new java.util.ArrayList/**/(); + } + return this.preProcessPresentationObjects; + } + + /** + * Constructor for the ResourceEnvironmentGroup, this takes a + * name parameter which must be 8 characters long. + * @param name the resource environment group name + */ + public ResourceEnvironmentGroup(String name) { + super(name); + } + +// /** +// * Adds an AFP object mapping reference to this resource environment group +// * @param obj the object to add +// */ +// public void addObject(AbstractStructuredAFPObject obj) { +// getMapDataResources().add(new MapDataResource(obj)); +// 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]; + copySF(data, Type.BEGIN, Category.RESOURCE_ENVIROMENT_GROUP); + os.write(data); + } + + /** {@inheritDoc} */ + protected void writeEnd(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.END, Category.RESOURCE_ENVIROMENT_GROUP); + os.write(data); + } + + /** {@inheritDoc} */ + protected void writeContent(OutputStream os) throws IOException { + writeObjects(mapDataResources, os); + writeObjects(mapPageOverlays, os); + writeObjects(preProcessPresentationObjects, os); + } + +} diff --git a/src/java/org/apache/fop/afp/modca/ResourceGroup.java b/src/java/org/apache/fop/afp/modca/ResourceGroup.java new file mode 100644 index 000000000..2218998a0 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/ResourceGroup.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.afp.modca; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.Iterator; +import java.util.Set; + +import org.apache.fop.afp.Streamable; + +/** + * A Resource Group contains a set of overlays. + */ +public class ResourceGroup extends AbstractNamedAFPObject { + + /** Set of resource uri */ + private final Set/**/ resourceSet = new java.util.HashSet/**/(); + + /** + * Constructor for the ResourceGroup, this takes a + * name parameter which must be 8 characters long. + * + * @param name the resource group name + */ + public ResourceGroup(String name) { + super(name); + } + + /** + * Add this named object to this resource group + * + * @param namedObject a named object + * @throws IOException thrown if an I/O exception of some sort has occurred. + */ + public void addObject(AbstractNamedAFPObject namedObject) throws IOException { + resourceSet.add(namedObject); + } + + /** + * Returns the number of resources contained in this resource group + * + * @return the number of resources contained in this resource group + */ + public int getResourceCount() { + return resourceSet.size(); + } + + /** + * Returns true if the resource exists within this resource group, + * false otherwise. + * + * @param uri the uri of the resource + * @return true if the resource exists within this resource group + */ + public boolean resourceExists(String uri) { + return resourceSet.contains(uri); + } + + /** {@inheritDoc} */ + public void writeStart(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.BEGIN, Category.RESOURCE_GROUP); + os.write(data); + } + + /** {@inheritDoc} */ + public void writeContent(OutputStream os) throws IOException { + Iterator it = resourceSet.iterator(); + while (it.hasNext()) { + Object object = it.next(); + if (object instanceof Streamable) { + Streamable streamableObject = (Streamable)object; + streamableObject.writeToStream(os); + } + } + } + + /** {@inheritDoc} */ + public void writeEnd(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.END, Category.RESOURCE_GROUP); + os.write(data); + } + + /** {@inheritDoc} */ + public String toString() { + return this.name + " " + resourceSet/*getResourceMap()*/; + } +} diff --git a/src/java/org/apache/fop/afp/modca/ResourceObject.java b/src/java/org/apache/fop/afp/modca/ResourceObject.java new file mode 100644 index 000000000..a5b551e07 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/ResourceObject.java @@ -0,0 +1,168 @@ +/* + * 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 org.apache.fop.afp.modca.triplets.Triplet; +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 { + + private AbstractNamedAFPObject namedObject; + + /** + * Default constructor + * + * @param name the name of this resource (reference id) + */ + public ResourceObject(String name) { + super(name); + } + + /** + * Sets the data object referenced by this resource object + * + * @param obj the named data object + */ + public void setDataObject(AbstractNamedAFPObject obj) { + this.namedObject = obj; + } + + /** + * Returns the data object referenced by this resource object + * + * @return the data object referenced by this resource object + */ + public AbstractNamedAFPObject getDataObject() { + return namedObject; + } + + /** {@inheritDoc} */ + protected void writeStart(OutputStream os) throws IOException { + super.writeStart(os); + + byte[] data = new byte[19]; + copySF(data, Type.BEGIN, Category.NAME_RESOURCE); + + // Set the total record length + int tripletDataLength = getTripletDataLength(); + byte[] len = BinaryUtils.convert(18 + tripletDataLength, 2); + data[1] = len[0]; // Length byte 1 + data[2] = len[1]; // Length byte 2 + + // Set reserved bits + data[17] = 0x00; // Reserved + data[18] = 0x00; // Reserved + + os.write(data); + } + + /** {@inheritDoc} */ + protected void writeContent(OutputStream os) throws IOException { + super.writeContent(os); // write triplets + if (namedObject != null) { + namedObject.writeToStream(os); + } + } + + /** {@inheritDoc} */ + protected void writeEnd(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.END, Category.NAME_RESOURCE); + os.write(data); + } + + /** {@inheritDoc} */ + public String toString() { + return this.getName(); + } + + /** + * Sets Resource Object Type triplet + * + * @param type the resource object type + */ + public void setType(byte type) { + getTriplets().add(new ResourceObjectTypeTriplet(type)); + } + + /** 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/StreamedResourceGroup.java b/src/java/org/apache/fop/afp/modca/StreamedResourceGroup.java new file mode 100644 index 000000000..d6ab741b6 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/StreamedResourceGroup.java @@ -0,0 +1,92 @@ +/* + * 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 print-file resource group + */ +public class StreamedResourceGroup extends ResourceGroup { + /** the outputstream to write to */ + private final OutputStream os; + + private boolean started = false; + + private boolean complete = false; + + /** + * Main constructor + * + * @param name the resource group name + * @param os the outputstream + */ + public StreamedResourceGroup(String name, OutputStream os) { + super(name); + this.os = os; + } + + /** + * Adds a resource to the external resource group + * + * @param namedObject a named object + * @throws IOException thrown if an I/O exception of some sort has occurred. + */ + public void addObject(AbstractNamedAFPObject namedObject) throws IOException { + if (!started) { + writeStart(os); + started = true; + } + try { + namedObject.writeToStream(os); + } finally { + os.flush(); + } + } + + /** + * Closes this external resource group file + * + * @throws IOException thrown if an I/O exception of some sort has occurred. + */ + public void close() throws IOException { + writeEnd(os); + 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 + * + * @return the outputstream + */ + public OutputStream getOutputStream() { + return this.os; + } +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/modca/TagLogicalElement.java b/src/java/org/apache/fop/afp/modca/TagLogicalElement.java new file mode 100644 index 000000000..2e1fa5e07 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/TagLogicalElement.java @@ -0,0 +1,130 @@ +/* + * 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.io.UnsupportedEncodingException; + +import org.apache.fop.afp.AFPConstants; +import org.apache.fop.afp.util.BinaryUtils; + +/** + * A Tag Logical Element structured field assigns an attribute name and an + * attribute value to a page or page group. The Tag Logical Element structured + * field may be embedded directly in the page or page group, or it may reference + * the page or page group from a document index. When a Tag Logical Element + * structured field references a page or is embedded in a page following the + * active environment group, it is associated with the page. When a Tag Logical + * Element structured field references a page group or is embedded in a page + * group following the Begin Named Page Group structured field, it is associated + * with the page group. When a Tag Logical Element structured field is associated + * with a page group, the parameters of the Tag Logical Element structured field + * are inherited by all pages in the page group and by all other page groups + * that are nested in the page group. The scope of a Tag Logical Element is + * determined by its position with respect to other TLEs that reference, or are + * embedded in, the same page or page group. The Tag Logical Element structured + * field does not provide any presentation specifications and therefore has no + * effect on the appearance of a document when it is presented. + *

+ */ +public class TagLogicalElement extends AbstractAFPObject { + + /** + * Name of the key, used within the TLE + */ + private String name = null; + + /** + * Value returned by the key + */ + private String value = null; + + /** + * Construct a tag logical element with the name and value specified. + * + * @param name the name of the tag logical element + * @param value the value of the tag logical element + */ + public TagLogicalElement(String name, String value) { + this.name = name; + this.value = value; + } + + /** {@inheritDoc} */ + public void writeToStream(OutputStream os) throws IOException { + + byte[] data = new byte[17 + name.length() + value.length()]; + + data[0] = 0x5A; + // Set the total record length + byte[] rl1 + = BinaryUtils.convert(16 + name.length() + value.length(), 2); + //Ignore first byte + data[1] = rl1[0]; + data[2] = rl1[1]; + + // Structured field ID for a TLE + data[3] = (byte) 0xD3; + data[4] = (byte) Type.ATTRIBUTE; + data[5] = (byte) Category.PROCESS_ELEMENT; + + data[6] = 0x00; // Reserved + data[7] = 0x00; // Reserved + data[8] = 0x00; // Reserved + + //Use 2 triplets, attrubute name and value (the key for indexing) + + byte[] rl2 = BinaryUtils.convert(name.length() + 4, 1); + data[9] = rl2[0]; // length of the triplet, including this field + data[10] = 0x02; //Identifies it as a FQN triplet + data[11] = 0x0B; // GID format + data[12] = 0x00; + + byte[] tleByteName = null; + byte[] tleByteValue = null; + try { + tleByteName = name.getBytes(AFPConstants.EBCIDIC_ENCODING); + tleByteValue = value.getBytes(AFPConstants.EBCIDIC_ENCODING); + } catch (UnsupportedEncodingException usee) { + tleByteName = name.getBytes(); + tleByteValue = value.getBytes(); + log.warn( + "Constructor:: UnsupportedEncodingException translating the name " + + name); + } + + int pos = 13; + for (int i = 0; i < tleByteName.length; i++) { + data[pos++] = tleByteName[i]; + } + + byte[] rl3 = BinaryUtils.convert(tleByteValue.length + 4, 1); + data[pos++] = rl3[0]; // length of the triplet, including this field + data[pos++] = 0x36; //Identifies the triplet, attribute value + data[pos++] = 0x00; // Reserved + data[pos++] = 0x00; // Reserved + + for (int i = 0; i < tleByteValue.length; i++) { + data[pos++] = tleByteValue[i]; + } + os.write(data); + } +} diff --git a/src/java/org/apache/fop/afp/modca/TagLogicalElementBean.java b/src/java/org/apache/fop/afp/modca/TagLogicalElementBean.java new file mode 100644 index 000000000..5d4523777 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/TagLogicalElementBean.java @@ -0,0 +1,64 @@ +/* + * 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; + +/** + * The TagLogicalElementBean provides a bean for holding the attributes of + * a tag logical element as key value pairs. + *

+ */ +public class TagLogicalElementBean { + + /** The key attribute */ + private String key; + + /** The value attribute */ + private String value; + + /** + * Constructor for the TagLogicalElementBean. + * + * @param key the key attribute + * @param value the value attribute + */ + public TagLogicalElementBean(String key, String value) { + this.key = key; + this.value = value; + } + + /** + * Getter for the key attribute. + * + * @return the key + */ + public String getKey() { + return key; + } + + /** + * Getter for the value attribute. + * + * @return the value + */ + public String getValue() { + return value; + } + +} diff --git a/src/java/org/apache/fop/afp/modca/triplets/ExtendedResourceLocalIdentifierTriplet.java b/src/java/org/apache/fop/afp/modca/triplets/ExtendedResourceLocalIdentifierTriplet.java new file mode 100644 index 000000000..a6059d3ec --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/triplets/ExtendedResourceLocalIdentifierTriplet.java @@ -0,0 +1,55 @@ +/* + * 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.util.BinaryUtils; + +/** + * The Extended Resource Local Identifier triplet specifies a resource type and a + * four byte local identifier or LID. The LID usually is associated with a specific + * 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 { + + /** the image resource type */ + public static final byte TYPE_IMAGE_RESOURCE = 0x10; + + /** the retired value type */ + public static final byte TYPE_RETIRED_VALUE = 0x30; + + /** the retired value type */ + public static final byte TYPE_MEDIA_RESOURCE = 0x40; + + /** + * Main constructor + * + * @param type the resource type + * @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); + } +} diff --git a/src/java/org/apache/fop/afp/modca/triplets/FullyQualifiedNameTriplet.java b/src/java/org/apache/fop/afp/modca/triplets/FullyQualifiedNameTriplet.java new file mode 100644 index 000000000..a949124c8 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/triplets/FullyQualifiedNameTriplet.java @@ -0,0 +1,191 @@ +/* + * 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.UnsupportedEncodingException; + +import org.apache.fop.afp.AFPConstants; + +/** + * A Fully Qualified Name triplet enable the identification and referencing of + * objects using Gloabl Identifiers (GIDs). + */ +public class FullyQualifiedNameTriplet extends Triplet { + + // 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. */ + 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; + + /** 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 + * resource and is used to located the resource object in the resource hierarchy. + * The data object that uses the resource may or may not be defined by an + * IBM presentation architecture. + */ + 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; + } + + /** + * 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.fqName = fqName; + + byte[] fqNameBytes; + String encoding = AFPConstants.EBCIDIC_ENCODING; + if (format == FORMAT_URL) { + encoding = AFPConstants.US_ASCII_ENCODING; + } + try { + fqNameBytes = fqName.getBytes(encoding); + } catch (UnsupportedEncodingException e) { + throw new IllegalArgumentException( + encoding + " encoding failed"); + } + + 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; + } +} \ 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 new file mode 100644 index 000000000..9fe6dad79 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/triplets/MappingOptionTriplet.java @@ -0,0 +1,68 @@ +/* + * 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; + +/** + * Specifies the mapping of data object presentation space to object area + */ +public class MappingOptionTriplet extends Triplet { + /** + * the data object is placed in the upper left corner, all data must be presented + * within the object area extents + */ + public static final byte POSITION = 0x00; + + /** + * the data object is placed in the upper left corner, 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 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; + + /** + * Main constructor + * + * @param mapValue the mapping option to use + */ + public MappingOptionTriplet(byte mapValue) { + super(Triplet.MAPPING_OPTION, mapValue); + } +} diff --git a/src/java/org/apache/fop/afp/modca/triplets/MeasurementUnitsTriplet.java b/src/java/org/apache/fop/afp/modca/triplets/MeasurementUnitsTriplet.java new file mode 100644 index 000000000..d39dc5f96 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/triplets/MeasurementUnitsTriplet.java @@ -0,0 +1,54 @@ +/* + * 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.util.BinaryUtils; + +/** + * The Measurement Units triplet is used to specify the units of measure + * for a presentation space + */ +public class MeasurementUnitsTriplet extends Triplet { + + private static final byte TEN_INCHES = 0x00; + private static final byte TEN_CM = 0x01; + + /** + * 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? + byte[] xUnits = BinaryUtils.convert(xRes * 10, 2); + 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); + } +} diff --git a/src/java/org/apache/fop/afp/modca/triplets/ObjectAreaSizeTriplet.java b/src/java/org/apache/fop/afp/modca/triplets/ObjectAreaSizeTriplet.java new file mode 100644 index 000000000..64fba23c9 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/triplets/ObjectAreaSizeTriplet.java @@ -0,0 +1,62 @@ +/* + * 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.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 { + + /** + * 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); + } + + /** + * 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); + } +} diff --git a/src/java/org/apache/fop/afp/modca/triplets/ObjectByteExtentTriplet.java b/src/java/org/apache/fop/afp/modca/triplets/ObjectByteExtentTriplet.java new file mode 100644 index 000000000..355fe8288 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/triplets/ObjectByteExtentTriplet.java @@ -0,0 +1,39 @@ +/* + * 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.util.BinaryUtils; + +/** + * The Object Byte Extent triplet is used to specify the number of bytes contained in an object + */ +public class ObjectByteExtentTriplet extends Triplet { + + /** + * Main constructor + * + * @param byteExt the number of bytes contained in the object + */ + public ObjectByteExtentTriplet(int byteExt) { + super(OBJECT_BYTE_EXTENT); + byte[] data = BinaryUtils.convert(byteExt, 4); + super.setData(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 new file mode 100644 index 000000000..1692339ac --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/triplets/ObjectClassificationTriplet.java @@ -0,0 +1,188 @@ +/* + * 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.UnsupportedEncodingException; + +import org.apache.fop.afp.AFPConstants; +import org.apache.fop.afp.modca.Registry.ObjectType; +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 { + + /** + * The scope of this object is the including page or overlay + */ + public static final byte CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT = 0x01; + + /** + * The scope of this object is not defined + */ + public static final byte CLASS_TIME_VARIANT_PRESENTATION_OBJECT = 0x10; + + /** + * This is not a presentation object, the scope of this object is not defined + */ + public static final byte CLASS_EXECUTABLE_PROGRAM = 0x20; + + /** + * Setup information file, document level. This is not a presentation object, + */ + public static final byte CLASS_SETUP_FILE = 0x30; + + /** + * This is a resource used by a presentation object that may itself be a resource. + * The scope of the resource is the object that uses the resource. + */ + public static final byte CLASS_SECONDARY_RESOURCE = 0x40; + + /** + * Data object font. This is a non-FOCA font resource used to present + * text in a data object. The scope of the resource is the object that + * uses the resource. + */ + public static final byte CLASS_DATA_OBJECT_FONT = 0x41; + + /** + * Main constructor + * + * @param objectClass the object class type + * @param objectType the object type registry entry + * @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 ObjectClassificationTriplet(byte objectClass, ObjectType objectType, + boolean dataInContainer, boolean containerHasOEG, boolean dataInOCD) { + // no object level or company name specified + 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 + * + * @param objectClass the object class type + * @param objectType the object type registry entry + * @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 + * @param objLev the release level or version number of the object type + * @param compName the name of the company or organization that owns the object definition + */ + public ObjectClassificationTriplet(byte objectClass, ObjectType objectType, + boolean dataInContainer, boolean containerHasOEG, boolean dataInOCD, + String objLev, String compName) { + super(OBJECT_CLASSIFICATION); + + 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); + } + + /** + * Returns the structured field flags + * + * @param dataInContainer true if the object data in carried in the object container + * @param containerHasOEG true if the object container has an object environment group + * @param dataInOCD true if the object container data carries the object data + * + * @return the byte value of this structure + */ + public byte[] getStrucFlgs(boolean dataInContainer, boolean containerHasOEG, + boolean dataInOCD) { + byte[] strucFlgs = new byte[2]; + // Object Container (BOC/EOC) + if (dataInContainer) { + strucFlgs[0] |= 3 << 6; + } else { + strucFlgs[0] |= 1 << 6; + } + // Object Environment Group (OEG) + if (containerHasOEG) { + strucFlgs[0] |= 3 << 4; + } else { + strucFlgs[0] |= 1 << 4; + } + // Object Container Data (OCD) structured fields + if (dataInOCD) { + strucFlgs[0] |= 3 << 2; + } else { + strucFlgs[0] |= 1 << 2; + } + strucFlgs[1] = 0x00; + return strucFlgs; + } +} \ 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 new file mode 100644 index 000000000..0f087e4fd --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/triplets/PresentationSpaceMixingRulesTriplet.java @@ -0,0 +1,62 @@ +/* + * 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; + +/** + * 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 { + + /** background on background mixing rule */ + public static final byte RULE_BACK_ON_BACK = 0x70; + + /** background on foreground mixing rule */ + public static final byte RULE_BACK_ON_FORE = 0x71; + + /** foreground on background mixing rule */ + public static final byte RULE_FORE_ON_BACK = 0x72; + + /** 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; + + /** blend */ + public static final byte BLEND = (byte)0x03; + + /** MO:DCA default mixing */ + public static final byte DEFAULT = (byte)0xFF; + + + /** + * Main constructor + * + * @param rules the mixing rules + */ + public PresentationSpaceMixingRulesTriplet(byte[] rules) { + super(PRESENTATION_SPACE_MIXING_RULE, rules); + } +} diff --git a/src/java/org/apache/fop/afp/modca/triplets/PresentationSpaceResetMixingTriplet.java b/src/java/org/apache/fop/afp/modca/triplets/PresentationSpaceResetMixingTriplet.java new file mode 100644 index 000000000..38041f140 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/triplets/PresentationSpaceResetMixingTriplet.java @@ -0,0 +1,48 @@ +/* + * 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; + +/** + * 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 { + + /** + * 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; + + /** + * Main constructor + * + * @param backgroundMixFlag the background mixing flag + */ + public PresentationSpaceResetMixingTriplet(byte backgroundMixFlag) { + super(PRESENTATION_SPACE_RESET_MIXING, backgroundMixFlag); + } +} diff --git a/src/java/org/apache/fop/afp/modca/triplets/ResourceObjectTypeTriplet.java b/src/java/org/apache/fop/afp/modca/triplets/ResourceObjectTypeTriplet.java new file mode 100644 index 000000000..784975c43 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/triplets/ResourceObjectTypeTriplet.java @@ -0,0 +1,21 @@ +/* + * 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; + diff --git a/src/java/org/apache/fop/afp/modca/triplets/Triplet.java b/src/java/org/apache/fop/afp/modca/triplets/Triplet.java new file mode 100644 index 000000000..b7f51466b --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/triplets/Triplet.java @@ -0,0 +1,162 @@ +/* + * 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/util/BinaryUtils.java b/src/java/org/apache/fop/afp/util/BinaryUtils.java new file mode 100644 index 000000000..2b2649415 --- /dev/null +++ b/src/java/org/apache/fop/afp/util/BinaryUtils.java @@ -0,0 +1,135 @@ +/* + * 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.util; + +import java.io.ByteArrayOutputStream; + +/** + * Library of utility useful conversion methods. + * + */ +public final class BinaryUtils { + + /** + * Convert an int into the corresponding byte array by encoding each + * two hexadecimal digits as a char. This will return a byte array + * to the length specified by bufsize. + * @param integer The int representation. + * @param bufsize The required byte array size. + * @return the hexadecimal digits as a byte array + */ + public static byte[] convert(int integer, int bufsize) { + StringBuffer buf = new StringBuffer(Integer.toHexString(integer)); + //Convert to an even number of digits + if (buf.length() % 2 != 0) { + buf.insert(0, "0"); + } + int size = buf.length() / 2; + if (size > bufsize) { + buf.delete(0, buf.length() - (bufsize * 2)); + } else { + while (size < bufsize) { + buf.insert(0, "00"); + size++; + } + } + return convert(buf.toString()); + } + + /** + * Convert an int into the corresponding byte array by encoding each + * two hexadecimal digits as a char. + * @param integer The int representation + * @return the hexadecimal digits as a byte array + */ + public static byte[] convert(int integer) { + return convert(Integer.toHexString(integer)); + } + + /** + * Convert a String of hexadecimal digits into the corresponding + * byte array by encoding each two hexadecimal digits as a byte. + * @param digits The hexadecimal digits representation. + * @return the hexadecimal digits as a byte array + */ + public static byte[] convert(String digits) { + + if (digits.length() % 2 == 0) { + // Even number of digits, so ignore + } else { + // Convert to an even number of digits + digits = "0" + digits; + } + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + for (int i = 0; i < digits.length(); i += 2) { + char c1 = digits.charAt(i); + char c2 = digits.charAt(i + 1); + byte b = 0; + if ((c1 >= '0') && (c1 <= '9')) { + b += ((c1 - '0') * 16); + } else if ((c1 >= 'a') && (c1 <= 'f')) { + b += ((c1 - 'a' + 10) * 16); + } else if ((c1 >= 'A') && (c1 <= 'F')) { + b += ((c1 - 'A' + 10) * 16); + } else { + throw new IllegalArgumentException("Bad hexadecimal digit"); + } + + if ((c2 >= '0') && (c2 <= '9')) { + b += (c2 - '0'); + } else if ((c2 >= 'a') && (c2 <= 'f')) { + b += (c2 - 'a' + 10); + } else if ((c2 >= 'A') && (c2 <= 'F')) { + b += (c2 - 'A' + 10); + } else { + throw new IllegalArgumentException("Bad hexadecimal digit"); + } + baos.write(b); + } + return (baos.toByteArray()); + } + + /** + * Convert the specified short into a byte array. + * @param value The value to be converted. + * @param array The array to receive the data. + * @param offset The offset into the byte array for the start of the value. + */ + public static void shortToByteArray( + short value, + byte[] array, + int offset) { + array[offset] = (byte) (value >>> 8); + array[offset + 1] = (byte) value; + } + + /** + * Convert the specified short into a byte array. + * @param value The value to be converted. + * @return The byte array + */ + public static byte[] shortToByteArray(short value) { + byte[] serverValue = new byte[2]; + shortToByteArray(value, serverValue, 0); + return serverValue; + } + +} diff --git a/src/java/org/apache/fop/afp/util/DTDEntityResolver.java b/src/java/org/apache/fop/afp/util/DTDEntityResolver.java new file mode 100644 index 000000000..dcf5ad7d9 --- /dev/null +++ b/src/java/org/apache/fop/afp/util/DTDEntityResolver.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.util; + +import java.io.IOException; +import java.net.URL; + +import org.apache.fop.afp.fonts.FontRuntimeException; +import org.xml.sax.EntityResolver; +import org.xml.sax.InputSource; + +/** + * An entity resolver for both DOM and SAX models of the SAX document. + *

+ * The entity resolver only handles queries for the DTD. It will find any URI + * with a recognised public id and return an {@link org.xml.sax.InputSource}. + *

+ * @author Joe Schmetzer + */ +public class DTDEntityResolver implements EntityResolver { + + /** Public ID for the AFP fonts 1.0 DTD. */ + public static final String AFP_DTD_1_0_ID + = "-//APACHE/DTD AFP Installed Font Definition DTD 1.0//EN"; + + /** Resource location for the AFP fonts 1.0 DTD. */ + public static final String AFP_DTD_1_0_RESOURCE + = "afp-fonts-1.0.dtd"; + + /** Public ID for the AFP fonts 1.1 DTD. */ + public static final String AFP_DTD_1_1_ID + = "-//APACHE/DTD AFP Installed Font Definition DTD 1.1//EN"; + + /** Resource location for the AFP fonts 1.1 DTD. */ + public static final String AFP_DTD_1_1_RESOURCE + = "afp-fonts-1.1.dtd"; + + /** Public ID for the AFP fonts 1.2 DTD. */ + public static final String AFP_DTD_1_2_ID + = "-//APACHE/DTD AFP Installed Font Definition DTD 1.2//EN"; + + /** Resource location for the AFP fonts 1.2 DTD. */ + public static final String AFP_DTD_1_2_RESOURCE + = "afp-fonts-1.2.dtd"; + + /** + * Resolve the combination of system and public identifiers. + * If this resolver recognises the publicId, it will handle the resolution + * from the classpath, otherwise it will return null and allow the default + * resolution to occur. + * + * @param publicId the public identifier to use + * @param systemId the system identifier to resolve + * @return An input source to the entity or null if not handled + * @throws IOException an error reading the stream + */ + public InputSource resolveEntity(String publicId, String systemId) + throws IOException { + + URL resource = null; + if ( AFP_DTD_1_2_ID.equals(publicId) ) { + resource = getResource( AFP_DTD_1_2_RESOURCE ); + } else if ( AFP_DTD_1_1_ID.equals(publicId) ) { + resource = getResource( AFP_DTD_1_1_RESOURCE ); + } else if ( AFP_DTD_1_0_ID.equals(publicId) ) { + throw new FontRuntimeException( + "The AFP Installed Font Definition 1.0 DTD is not longer supported" ); + } else if (systemId != null && systemId.indexOf("afp-fonts.dtd") >= 0 ) { + throw new FontRuntimeException( + "The AFP Installed Font Definition DTD must be specified using the public id" ); + } else { + return null; + } + + InputSource inputSource = new InputSource( resource.openStream() ); + inputSource.setPublicId( publicId ); + inputSource.setSystemId( systemId ); + + return inputSource; + } + + /** + * Returns the URL of a resource on the classpath + * @param resourceName the path to the resource relative to the root of the + * classpath. + * @return the URL of the required resource + * @throws FontRuntimeException if the resource could not be found. + */ + private URL getResource(String resourcePath) { + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + if (cl == null) { + cl = ClassLoader.getSystemClassLoader(); + } + + URL resource = cl.getResource( resourcePath ); + if (resource == null) { + throw new FontRuntimeException( "Resource " + resourcePath + + "could not be found on the classpath" ); + } + + return resource; + } +} diff --git a/src/java/org/apache/fop/afp/util/StringUtils.java b/src/java/org/apache/fop/afp/util/StringUtils.java new file mode 100644 index 000000000..ce68d27be --- /dev/null +++ b/src/java/org/apache/fop/afp/util/StringUtils.java @@ -0,0 +1,81 @@ +/* + * 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.util; + +/** + * Library of utility methods useful in dealing with strings. + * + */ +public class StringUtils { + + /** + * Padds the string to the left with the given character for + * the specified length. + * @param input The input string. + * @param padding The char used for padding. + * @param length The length of the new string. + * @return The padded string. + */ + public static String lpad(String input, char padding, int length) { + + if (input == null) { + input = new String(); + } + + if (input.length() >= length) { + return input; + } else { + StringBuffer result = new StringBuffer(); + int numChars = length - input.length(); + for (int i = 0; i < numChars; i++) { + result.append(padding); + } + result.append(input); + return result.toString(); + } + } + + /** + * Padds the string to the right with the given character for + * the specified length. + * @param input The input string. + * @param padding The char used for padding. + * @param length The length of the new string. + * @return The padded string. + */ + public static String rpad(String input, char padding, int length) { + + if (input == null) { + input = new String(); + } + + if (input.length() >= length) { + return input; + } else { + StringBuffer result = new StringBuffer(input); + int numChars = length - input.length(); + for (int i = 0; i < numChars; i++) { + result.append(padding); + } + return result.toString(); + } + } + +} \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/util/StructuredFieldReader.java b/src/java/org/apache/fop/afp/util/StructuredFieldReader.java new file mode 100644 index 000000000..34add3bbe --- /dev/null +++ b/src/java/org/apache/fop/afp/util/StructuredFieldReader.java @@ -0,0 +1,133 @@ +/* + * 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.util; + +import java.io.IOException; +import java.io.InputStream; + +/** + * A helper class to read structured fields from a MO:DCA document. Each + * component of a mixed object document is explicitly defined and delimited + * in the data. This is accomplished through the use of MO:DCA data structures, + * called structured fields. Structured fields are used to envelop document + * components and to provide commands and information to applications using + * the data. Structured fields may contain one or more parameters. Each + * parameter provides one value from a set of values defined by the architecture. + *

+ * MO:DCA structured fields consist of two parts: an introducer that identifies + * the length and type of the structured field, and data that provides the + * structured field's effect. The data is contained in a set of parameters, + * which can consist of other data structures and data elements. The maximum + * length of a structured field is 32767 bytes. + *

+ */ +public class StructuredFieldReader { + + /** + * The input stream to read + */ + private InputStream inputStream = null; + + /** + * The constructor for the StructuredFieldReader + * @param inputStream the input stream to process + */ + public StructuredFieldReader(InputStream inputStream) { + this.inputStream = inputStream; + } + + /** + * Get the next structured field as identified by the identifer + * parameter (this must be a valid MO:DCA structured field. + * @param identifier the three byte identifier + * @throws IOException if an I/O exception occurred + * @return the next structured field or null when there are no more + */ + public byte[] getNext(byte[] identifier) throws IOException { + + int bufferPointer = 0; + byte[] bufferData = new byte[identifier.length + 2]; + for (int x = 0; x < identifier.length; x++) { + bufferData[x] = 0x00; + } + + int c; + while ((c = inputStream.read()) > -1) { + + bufferData[bufferPointer] = (byte) c; + + // Check the last characters in the buffer + int index = 0; + boolean found = true; + + for (int i = identifier.length - 1; i > -1; i--) { + + int p = bufferPointer - index; + if (p < 0) { + p = bufferData.length + p; + } + + index++; + + if (identifier[i] != bufferData[p]) { + found = false; + break; + } + + } + + if (found) { + + byte[] length = new byte[2]; + + int a = bufferPointer - identifier.length; + if (a < 0) { + a = bufferData.length + a; + } + + int b = bufferPointer - identifier.length - 1; + if (b < 0) { + b = bufferData.length + b; + } + + length[0] = bufferData[b]; + length[1] = bufferData[a]; + + int reclength = ((length[0] & 0xFF) << 8) + + (length[1] & 0xFF) - identifier.length - 2; + + byte[] retval = new byte[reclength]; + + inputStream.read(retval, 0, reclength); + + return retval; + + } + + bufferPointer++; + if (bufferPointer >= bufferData.length) { + bufferPointer = 0; + } + + } + + return null; + } +} diff --git a/src/java/org/apache/fop/fonts/Base14Font.java b/src/java/org/apache/fop/fonts/Base14Font.java index 04349a148..9b2e95bc7 100644 --- a/src/java/org/apache/fop/fonts/Base14Font.java +++ b/src/java/org/apache/fop/fonts/Base14Font.java @@ -19,6 +19,7 @@ package org.apache.fop.fonts; + /** * Base class for all Base 14 fonts. */ diff --git a/src/java/org/apache/fop/fonts/CustomFont.java b/src/java/org/apache/fop/fonts/CustomFont.java index 0b40dfecc..4cf24ae16 100644 --- a/src/java/org/apache/fop/fonts/CustomFont.java +++ b/src/java/org/apache/fop/fonts/CustomFont.java @@ -26,6 +26,7 @@ import java.util.Set; import javax.xml.transform.Source; + /** * Abstract base class for custom fonts loaded from files, for example. */ diff --git a/src/java/org/apache/fop/fonts/Font.java b/src/java/org/apache/fop/fonts/Font.java index ebd45457d..e9740c00c 100644 --- a/src/java/org/apache/fop/fonts/Font.java +++ b/src/java/org/apache/fop/fonts/Font.java @@ -23,6 +23,7 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.fop.fonts.CodePointMapping; /** * This class holds font state information and provides access to the font diff --git a/src/java/org/apache/fop/fonts/FontCollection.java b/src/java/org/apache/fop/fonts/FontCollection.java index 3c9bba7f4..d481ae2f9 100644 --- a/src/java/org/apache/fop/fonts/FontCollection.java +++ b/src/java/org/apache/fop/fonts/FontCollection.java @@ -24,6 +24,7 @@ package org.apache.fop.fonts; * Sets up a set of fonts */ public interface FontCollection { + /** * Sets up fonts in a font info object. * diff --git a/src/java/org/apache/fop/fonts/FontDescriptor.java b/src/java/org/apache/fop/fonts/FontDescriptor.java index fadc73834..e7c81c9f3 100644 --- a/src/java/org/apache/fop/fonts/FontDescriptor.java +++ b/src/java/org/apache/fop/fonts/FontDescriptor.java @@ -19,6 +19,7 @@ package org.apache.fop.fonts; + /** * This interface enhances the font metrics interface with access methods to * value needed to register fonts in various target formats like PDF or diff --git a/src/java/org/apache/fop/fonts/FontEventListener.java b/src/java/org/apache/fop/fonts/FontEventListener.java index b508d7053..740a05fdc 100644 --- a/src/java/org/apache/fop/fonts/FontEventListener.java +++ b/src/java/org/apache/fop/fonts/FontEventListener.java @@ -19,7 +19,6 @@ package org.apache.fop.fonts; - /** * Event listener interface for font-related events. */ diff --git a/src/java/org/apache/fop/fonts/FontMetrics.java b/src/java/org/apache/fop/fonts/FontMetrics.java index 7d5588690..29ade1ef3 100644 --- a/src/java/org/apache/fop/fonts/FontMetrics.java +++ b/src/java/org/apache/fop/fonts/FontMetrics.java @@ -23,6 +23,7 @@ import java.util.Map; import java.util.Set; + /** * Main interface for access to font metrics. */ diff --git a/src/java/org/apache/fop/fonts/FontTriplet.java b/src/java/org/apache/fop/fonts/FontTriplet.java index 8e0acd8f2..f5cfe442a 100644 --- a/src/java/org/apache/fop/fonts/FontTriplet.java +++ b/src/java/org/apache/fop/fonts/FontTriplet.java @@ -21,6 +21,7 @@ package org.apache.fop.fonts; import java.io.Serializable; + /** * FontTriplet contains information on name, style and weight of one font */ diff --git a/src/java/org/apache/fop/fonts/FontType.java b/src/java/org/apache/fop/fonts/FontType.java index 0abe06a10..95b594ca4 100644 --- a/src/java/org/apache/fop/fonts/FontType.java +++ b/src/java/org/apache/fop/fonts/FontType.java @@ -19,12 +19,10 @@ package org.apache.fop.fonts; -import org.apache.avalon.framework.ValuedEnum; - /** * This class enumerates all supported font types. */ -public class FontType extends ValuedEnum { +public class FontType { /** * Collective identifier for "other" font types @@ -51,12 +49,16 @@ public class FontType extends ValuedEnum { */ public static final FontType TRUETYPE = new FontType("TrueType", 5); + private final String name; + private final int value; + /** * @see org.apache.avalon.framework.Enum#Enum(String) */ protected FontType(String name, int value) { - super(name, value); + this.name = name; + this.value = value; } @@ -107,4 +109,22 @@ public class FontType extends ValuedEnum { } } + /** + * Returns the name + * + * @return the name + */ + public String getName() { + return name; + } + + /** + * Returns the value + * + * @return the value + */ + public int getValue() { + return value; + } + } diff --git a/src/java/org/apache/fop/fonts/FontUtil.java b/src/java/org/apache/fop/fonts/FontUtil.java index 6ec89631f..49f23c12f 100644 --- a/src/java/org/apache/fop/fonts/FontUtil.java +++ b/src/java/org/apache/fop/fonts/FontUtil.java @@ -19,6 +19,7 @@ package org.apache.fop.fonts; + /** * Font utilities. */ diff --git a/src/java/org/apache/fop/fonts/MultiByteFont.java b/src/java/org/apache/fop/fonts/MultiByteFont.java index f25ca4e7e..b22b92e2f 100644 --- a/src/java/org/apache/fop/fonts/MultiByteFont.java +++ b/src/java/org/apache/fop/fonts/MultiByteFont.java @@ -23,6 +23,7 @@ package org.apache.fop.fonts; import java.text.DecimalFormat; import java.util.Map; + /** * Generic MultiByte (CID) font */ diff --git a/src/java/org/apache/fop/fonts/MutableFont.java b/src/java/org/apache/fop/fonts/MutableFont.java index 5939bfed4..a5acf51b3 100644 --- a/src/java/org/apache/fop/fonts/MutableFont.java +++ b/src/java/org/apache/fop/fonts/MutableFont.java @@ -23,6 +23,7 @@ import java.util.Map; import java.util.Set; + /** * This interface is used to set the values of a font during configuration time. */ diff --git a/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java index 6b0e88cbb..dc8a020ae 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java @@ -20,12 +20,12 @@ package org.apache.fop.layoutmgr.inline; import org.apache.fop.fo.flow.PageNumber; -import org.apache.fop.area.inline.InlineArea; -import org.apache.fop.area.inline.TextArea; -import org.apache.fop.area.Trait; import org.apache.fop.fonts.Font; import org.apache.fop.fonts.FontInfo; import org.apache.fop.fonts.FontTriplet; +import org.apache.fop.area.inline.InlineArea; +import org.apache.fop.area.inline.TextArea; +import org.apache.fop.area.Trait; import org.apache.fop.layoutmgr.LayoutContext; import org.apache.fop.layoutmgr.TraitSetter; import org.apache.fop.traits.MinOptMax; diff --git a/src/java/org/apache/fop/pdf/PDFState.java b/src/java/org/apache/fop/pdf/PDFState.java index 0f3e06070..138458552 100644 --- a/src/java/org/apache/fop/pdf/PDFState.java +++ b/src/java/org/apache/fop/pdf/PDFState.java @@ -25,7 +25,7 @@ import java.awt.Shape; import java.awt.geom.Area; import java.awt.geom.GeneralPath; -import org.apache.fop.render.AbstractState; +import org.apache.fop.AbstractState; /** * This keeps information about the current state when writing to pdf. @@ -44,7 +44,7 @@ import org.apache.fop.render.AbstractState; * It is impossible to optimise the result without analysing the all * the possible combinations after completing. */ -public class PDFState extends org.apache.fop.render.AbstractState { +public class PDFState extends org.apache.fop.AbstractState { private static final long serialVersionUID = 5384726143906371279L; @@ -165,7 +165,7 @@ public class PDFState extends org.apache.fop.render.AbstractState { return new PDFState(); } - private class PDFData extends org.apache.fop.render.AbstractState.AbstractData { + private class PDFData extends org.apache.fop.AbstractState.AbstractData { private static final long serialVersionUID = 3527950647293177764L; diff --git a/src/java/org/apache/fop/render/AbstractState.java b/src/java/org/apache/fop/render/AbstractState.java deleted file mode 100644 index 04409390f..000000000 --- a/src/java/org/apache/fop/render/AbstractState.java +++ /dev/null @@ -1,433 +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.render; - -import java.awt.Color; -import java.awt.geom.AffineTransform; -import java.io.Serializable; -import java.util.Arrays; -import java.util.Iterator; -import java.util.Stack; - -/** - * A base class which holds information about the current rendering state. - */ -public abstract class AbstractState implements Cloneable, Serializable { - - /** current state data */ - private AbstractData currentData = null; - - /** the state stack */ - private StateStack stateStack = null; - - /** - * Instantiates a new state data object - * - * @return a new state data object - */ - protected abstract AbstractData instantiateData(); - - /** - * Instantiates a new state object - * - * @return a new state object - */ - protected abstract AbstractState instantiateState(); - - /** - * Returns the currently valid state - * - * @return the currently valid state - */ - public AbstractData getData() { - if (currentData == null) { - currentData = instantiateData(); - } - return currentData; - } - - /** - * Set the current color. - * Check if the new color is a change and then set the current color. - * - * @param col the color to set - * @return true if the color has changed - */ - public boolean setColor(Color col) { - if (!col.equals(getData().color)) { - getData().color = col; - return true; - } - return false; - } - - /** - * Get the color. - * - * @return the color - */ - public Color getColor() { - if (getData().color == null) { - getData().color = Color.black; - } - return getData().color; - } - - /** - * Get the background color. - * - * @return the background color - */ - public Color getBackColor() { - if (getData().backColor == null) { - getData().backColor = Color.white; - } - return getData().backColor; - } - - /** - * Set the current background color. - * Check if the new background color is a change and then set the current background color. - * - * @param col the background color to set - * @return true if the color has changed - */ - public boolean setBackColor(Color col) { - if (!col.equals(getData().backColor)) { - getData().backColor = col; - return true; - } - return false; - } - - /** - * Set the current font name - * - * @param internalFontName the internal font name - * @return true if the font name has changed - */ - public boolean setFontName(String internalFontName) { - if (!internalFontName.equals(getData().fontName)) { - getData().fontName = internalFontName; - return true; - } - return false; - } - - /** - * Gets the current font name - * - * @return the current font name - */ - public String getFontName() { - return getData().fontName; - } - - /** - * Gets the current font size - * - * @return the current font size - */ - public int getFontSize() { - return getData().fontSize; - } - - /** - * Set the current font size. - * Check if the font size is a change and then set the current font size. - * - * @param size the font size to set - * @return true if the font size has changed - */ - public boolean setFontSize(int size) { - if (size != getData().fontSize) { - getData().fontSize = size; - return true; - } - return false; - } - - /** - * Set the current line width. - * - * @param width the line width in points - * @return true if the line width has changed - */ - public boolean setLineWidth(float width) { - if (getData().lineWidth != width) { - getData().lineWidth = width; - return true; - } - return false; - } - - /** - * Returns the current line width - * - * @return the current line width - */ - public float getLineWidth() { - return getData().lineWidth; - } - - /** - * Sets the dash array (line type) for the current basic stroke - * - * @param dash the line dash array - * @return true if the dash array has changed - */ - public boolean setDashArray(float[] dash) { - if (!Arrays.equals(dash, getData().dashArray)) { - getData().dashArray = dash; - return true; - } - return false; - } - - /** - * Get the current transform. - * This gets the combination of all transforms in the - * current state. - * - * @return the calculate combined transform for the current state - */ - public AffineTransform getTransform() { - AffineTransform at = new AffineTransform(); - for (Iterator iter = getStateStack().iterator(); iter.hasNext();) { - AbstractData data = (AbstractData)iter.next(); - AffineTransform stackTrans = data.getTransform(); - at.concatenate(stackTrans); - } - AffineTransform currentTrans = getData().getTransform(); - at.concatenate(currentTrans); - return at; - } - - /** - * Check the current transform. - * The transform for the current state is the combination of all - * transforms in the current state. The parameter is compared - * against this current transform. - * - * @param tf the transform the check against - * @return true if the new transform is different then the current transform - */ - public boolean checkTransform(AffineTransform tf) { - return !tf.equals(getData().getTransform()); - } - - /** - * Get a copy of the base transform for the page. Used to translate - * IPP/BPP values into X,Y positions when positioning is "fixed". - * - * @return the base transform, or null if the state stack is empty - */ - public AffineTransform getBaseTransform() { - if (getStateStack().isEmpty()) { - return null; - } else { - AbstractData baseData = (AbstractData)getStateStack().get(0); - return (AffineTransform) baseData.getTransform().clone(); - } - } - - /** - * Concatenates the given AffineTransform to the current one. - * - * @param at the transform to concatenate to the current level transform - */ - public void concatenate(AffineTransform at) { - getData().concatenate(at); - } - - /** - * Resets the current AffineTransform. - */ - public void resetTransform() { - getData().resetTransform(); - } - - /** - * Push the current 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() { - AbstractData copy = (AbstractData)getData().clone(); - getStateStack().push(copy); - } - - /** - * Pop the 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. - * - * @return the restored state, null if the stack is empty - */ - public AbstractData pop() { - if (!getStateStack().isEmpty()) { - this.currentData = (AbstractData)getStateStack().pop(); - return this.currentData; - } else { - return null; - } - } - - /** - * Clears the state stack - */ - public void clear() { - getStateStack().clear(); - currentData = null; - } - - /** - * Return the state stack - * - * @return the state stack - */ - protected Stack/**/ getStateStack() { - if (stateStack == null) { - stateStack = new StateStack(); - } - return stateStack; - } - - /** {@inheritDoc} */ - public Object clone() { - AbstractState state = instantiateState(); - state.stateStack = new StateStack(this.stateStack); - state.currentData = (AbstractData)this.currentData.clone(); - return state; - } - - /** {@inheritDoc} */ - public String toString() { - return ", stateStack=" + stateStack - + ", currentData=" + currentData; - } - - /** - * A base state data holding object - */ - public abstract class AbstractData implements Cloneable, Serializable { - - /** The current color */ - private Color color = null; - - /** The current background color */ - private Color backColor = null; - - /** The current font name */ - private String fontName = null; - - /** The current font size */ - private int fontSize = 0; - - /** The current line width */ - private float lineWidth = 0; - - /** The dash array for the current basic stroke (line type) */ - private float[] dashArray = null; - - /** The current transform */ - private AffineTransform transform = null; - - /** - * Concatenate the given AffineTransform with the current thus creating - * a new viewport. Note that all concatenation operations are logged - * so they can be replayed if necessary (ex. for block-containers with - * "fixed" positioning. - * - * @param at Transformation to perform - */ - public void concatenate(AffineTransform at) { - getTransform().concatenate(at); - } - - /** - * Get the current AffineTransform. - * - * @return the current transform - */ - public AffineTransform getTransform() { - if (transform == null) { - transform = new AffineTransform(); - } - return transform; - } - - /** - * Resets the current AffineTransform. - */ - public void resetTransform() { - transform = getBaseTransform(); -// transform = new AffineTransform(); - } - - /** - * Returns the derived rotation from the current transform - * - * @return the derived rotation from the current transform - */ - public int getDerivedRotation() { - AffineTransform at = getTransform(); - double sx = at.getScaleX(); - double sy = at.getScaleY(); - double shx = at.getShearX(); - double shy = at.getShearY(); - int rotation = 0; - if (sx == 0 && sy == 0 && shx > 0 && shy < 0) { - rotation = 270; - } else if (sx < 0 && sy < 0 && shx == 0 && shy == 0) { - rotation = 180; - } else if (sx == 0 && sy == 0 && shx < 0 && shy > 0) { - rotation = 90; - } else { - rotation = 0; - } - return rotation; - } - - /** {@inheritDoc} */ - public Object clone() { - AbstractData data = instantiateData(); - data.color = this.color; - data.backColor = this.backColor; - data.fontName = this.fontName; - data.fontSize = this.fontSize; - data.lineWidth = this.lineWidth; - data.dashArray = this.dashArray; - data.transform = new AffineTransform(this.transform); - return data; - } - - /** {@inheritDoc} */ - public String toString() { - return "color=" + color - + ", backColor=" + backColor - + ", fontName=" + fontName - + ", fontSize=" + fontSize - + ", lineWidth=" + lineWidth - + ", dashArray=" + dashArray - + ", transform=" + transform; - } - } -} diff --git a/src/java/org/apache/fop/render/StateStack.java b/src/java/org/apache/fop/render/StateStack.java deleted file mode 100644 index ab68a3968..000000000 --- a/src/java/org/apache/fop/render/StateStack.java +++ /dev/null @@ -1,50 +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.render; - -import java.util.Collection; - -/** - * No copy constructor for java.util.Stack so extended and implemented one. - */ -public class StateStack extends java.util.Stack { - - private static final long serialVersionUID = 4897178211223823041L; - - /** - * Default constructor - */ - public StateStack() { - super(); - } - - /** - * Copy constructor - * - * @param c initial contents of stack - */ - public StateStack(Collection c) { - elementCount = c.size(); - // 10% for growth - elementData = new Object[ - (int)Math.min((elementCount * 110L) / 100, Integer.MAX_VALUE)]; - c.toArray(elementData); - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/AFPAbstractGraphicsObjectPainter.java b/src/java/org/apache/fop/render/afp/AFPAbstractGraphicsObjectPainter.java deleted file mode 100644 index 101d28b61..000000000 --- a/src/java/org/apache/fop/render/afp/AFPAbstractGraphicsObjectPainter.java +++ /dev/null @@ -1,62 +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.render.afp; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.fop.render.afp.modca.GraphicsObject; -import org.apache.xmlgraphics.java2d.Graphics2DImagePainter; - -/** - * A simple AFP Graphics 2D painter - */ -public abstract class AFPAbstractGraphicsObjectPainter implements Graphics2DImagePainter { - /** Static logging instance */ - protected static Log log = LogFactory.getLog(AFPAbstractGraphicsObjectPainter.class); - - private final AFPGraphics2D graphics2D; - - /** - * Default constructor - */ - public AFPAbstractGraphicsObjectPainter() { - final boolean textAsShapes = false; - this.graphics2D = new AFPGraphics2D(textAsShapes); - } - - /** - * Constructor - * - * @param graphics the afp graphics 2d implementation - */ - public AFPAbstractGraphicsObjectPainter(AFPGraphics2D graphics) { - this.graphics2D = graphics; - } - - /** - * Sets the GOCA Graphics Object - * - * @param graphicsObject the GOCA Graphics Object - */ - public void setGraphicsObject(GraphicsObject graphicsObject) { - this.graphics2D.setGraphicsObject(graphicsObject); - } - -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/AFPAbstractImageFactory.java b/src/java/org/apache/fop/render/afp/AFPAbstractImageFactory.java index 565732b06..0c32204e2 100644 --- a/src/java/org/apache/fop/render/afp/AFPAbstractImageFactory.java +++ b/src/java/org/apache/fop/render/afp/AFPAbstractImageFactory.java @@ -21,6 +21,14 @@ package org.apache.fop.render.afp; import java.io.IOException; +import org.apache.fop.afp.AFPDataObjectInfo; +import org.apache.fop.afp.AFPForeignAttributeReader; +import org.apache.fop.afp.AFPObjectAreaInfo; +import org.apache.fop.afp.AFPResourceInfo; +import org.apache.fop.afp.AFPState; +import org.apache.fop.afp.AFPUnitConverter; + + /** * Abstract image configurator */ @@ -51,7 +59,7 @@ public abstract class AFPAbstractImageFactory { * @return the data object info * @throws IOException thrown if an I/O exception of some sort has occurred. */ - public AFPDataObjectInfo create(AFPImageInfo afpImageInfo) throws IOException { + public AFPDataObjectInfo create(AFPRendererImageInfo afpImageInfo) throws IOException { AFPDataObjectInfo dataObjectInfo = createDataObjectInfo(); // set resource information diff --git a/src/java/org/apache/fop/render/afp/AFPBatikGraphicsObjectPainter.java b/src/java/org/apache/fop/render/afp/AFPBatikGraphicsObjectPainter.java index 94da16d71..0aa77d61b 100644 --- a/src/java/org/apache/fop/render/afp/AFPBatikGraphicsObjectPainter.java +++ b/src/java/org/apache/fop/render/afp/AFPBatikGraphicsObjectPainter.java @@ -24,6 +24,8 @@ import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import org.apache.batik.gvt.GraphicsNode; +import org.apache.fop.afp.AFPAbstractGraphicsObjectPainter; +import org.apache.fop.afp.AFPGraphics2D; /** * Paints SVG as a GOCA Graphics Object using Batik diff --git a/src/java/org/apache/fop/render/afp/AFPBorderPainter.java b/src/java/org/apache/fop/render/afp/AFPBorderPainter.java deleted file mode 100644 index 5fbb91abc..000000000 --- a/src/java/org/apache/fop/render/afp/AFPBorderPainter.java +++ /dev/null @@ -1,195 +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.render.afp; - -import java.awt.geom.AffineTransform; - -import org.apache.fop.fo.Constants; -import org.apache.fop.render.afp.modca.DataStream; -import org.apache.fop.util.ColorUtil; - -/** - * Handles the drawing of borders/lines in AFP - */ -public class AFPBorderPainter extends AbstractAFPPainter { - - /** - * Main constructor - * - * @param state the unit converter - * @param dataStream the afp datastream - */ - public AFPBorderPainter(AFPState state, DataStream dataStream) { - super(state, dataStream); - } - - /** {@inheritDoc} */ - public void paint(PaintInfo paintInfo) { - BorderPaintInfo borderPaintInfo = (BorderPaintInfo)paintInfo; - float w = borderPaintInfo.getX2() - borderPaintInfo.getX1(); - float h = borderPaintInfo.getY2() - borderPaintInfo.getY1(); - if ((w < 0) || (h < 0)) { - log.error("Negative extent received. Border won't be painted."); - return; - } - - int pageWidth = dataStream.getCurrentPage().getWidth(); - int pageHeight = dataStream.getCurrentPage().getHeight(); - AFPUnitConverter unitConv = state.getUnitConverter(); - AffineTransform at = state.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()) { - case 0: - x1 += at.getTranslateX(); - y1 += at.getTranslateY(); - x2 += at.getTranslateX(); - y2 += at.getTranslateY(); - break; - case 90: - x1 += at.getTranslateY(); - y1 += (float) (pageWidth - at.getTranslateX()); - x2 += at.getTranslateY(); - y2 += (float) (pageWidth - at.getTranslateX()); - break; - case 180: - x1 += (float) (pageWidth - at.getTranslateX()); - y1 += (float) (pageHeight - at.getTranslateY()); - x2 += (float) (pageWidth - at.getTranslateX()); - y2 += (float) (pageHeight - at.getTranslateY()); - break; - case 270: - x1 = (float) (pageHeight - at.getTranslateY()); - y1 += (float) at.getTranslateX(); - x2 += x1; - y2 += (float) at.getTranslateX(); - break; - } - - AFPLineDataInfo lineDataInfo = new AFPLineDataInfo(); - lineDataInfo.setColor(borderPaintInfo.getColor()); - lineDataInfo.setRotation(state.getRotation()); - lineDataInfo.x1 = Math.round(x1); - lineDataInfo.y1 = Math.round(y1); - if (borderPaintInfo.isHorizontal()) { - lineDataInfo.setThickness(Math.round(y2 - y1)); - } else { - lineDataInfo.setThickness(Math.round(x2 - x1)); - } - - // handle border-*-style - switch (borderPaintInfo.getStyle()) { - case Constants.EN_DOUBLE: - if (borderPaintInfo.isHorizontal()) { - lineDataInfo.x2 = Math.round(x2); - lineDataInfo.y2 = lineDataInfo.y1; - dataStream.createLine(lineDataInfo); - lineDataInfo.y1 += Math.round((lineDataInfo.thickness / 3) * 2); - dataStream.createLine(lineDataInfo); - } else { - lineDataInfo.x2 = lineDataInfo.x1; - lineDataInfo.y2 = Math.round(y2); - dataStream.createLine(lineDataInfo); - lineDataInfo.x1 += Math.round((lineDataInfo.thickness / 3) * 2); - dataStream.createLine(lineDataInfo); - } - break; - case Constants.EN_DASHED: - int thick = lineDataInfo.thickness * 3; - if (borderPaintInfo.isHorizontal()) { - lineDataInfo.x2 = lineDataInfo.x1 + thick; - lineDataInfo.y2 = lineDataInfo.y1; - int ex2 = Math.round(x2); - while (lineDataInfo.x1 + thick < ex2) { - dataStream.createLine(lineDataInfo); - lineDataInfo.x1 += 2 * thick; - lineDataInfo.x2 = lineDataInfo.x1 + thick; - } - } else { - lineDataInfo.x2 = lineDataInfo.x1; - lineDataInfo.y2 = lineDataInfo.y1 + thick; - int ey2 = Math.round(y2); - while (lineDataInfo.y1 + thick < ey2) { - dataStream.createLine(lineDataInfo); - lineDataInfo.y1 += 2 * thick; - lineDataInfo.y2 = lineDataInfo.y1 + thick; - } - } - break; - case Constants.EN_DOTTED: - if (borderPaintInfo.isHorizontal()) { - lineDataInfo.x2 = lineDataInfo.x1 + lineDataInfo.thickness; - lineDataInfo.y2 = lineDataInfo.y1; - int ex2 = Math.round(x2); - while (lineDataInfo.x1 + lineDataInfo.thickness < ex2) { - dataStream.createLine(lineDataInfo); - lineDataInfo.x1 += 3 * lineDataInfo.thickness; - lineDataInfo.x2 = lineDataInfo.x1 + lineDataInfo.thickness; - } - } else { - lineDataInfo.x2 = lineDataInfo.x1; - lineDataInfo.y2 = lineDataInfo.y1 + lineDataInfo.thickness; - int ey2 = Math.round(y2); - while (lineDataInfo.y1 + lineDataInfo.thickness < ey2) { - dataStream.createLine(lineDataInfo); - lineDataInfo.y1 += 3 * lineDataInfo.thickness; - lineDataInfo.y2 = lineDataInfo.y1 + lineDataInfo.thickness; - } - } - break; - case Constants.EN_GROOVE: - case Constants.EN_RIDGE: - //TODO - lineDataInfo.x2 = Math.round(x2); - float colFactor = (borderPaintInfo.getStyle() == Constants.EN_GROOVE ? 0.4f : -0.4f); - float h3 = (y2 - y1) / 3; - lineDataInfo.color = ColorUtil.lightenColor(borderPaintInfo.getColor(), -colFactor); - lineDataInfo.thickness = Math.round(h3); - lineDataInfo.y1 = lineDataInfo.y2 = Math.round(y1); - dataStream.createLine(lineDataInfo); - lineDataInfo.color = borderPaintInfo.getColor(); - lineDataInfo.y1 = lineDataInfo.y2 = Math.round(y1 + h3); - dataStream.createLine(lineDataInfo); - lineDataInfo.color = ColorUtil.lightenColor(borderPaintInfo.getColor(), colFactor); - lineDataInfo.y1 = lineDataInfo.y2 = Math.round(y1 + h3 + h3); - dataStream.createLine(lineDataInfo); - break; - case Constants.EN_HIDDEN: - break; - case Constants.EN_INSET: - case Constants.EN_OUTSET: - case Constants.EN_SOLID: - default: - if (borderPaintInfo.isHorizontal()) { - lineDataInfo.x2 = Math.round(x2); - lineDataInfo.y2 = lineDataInfo.y1; - } else { - lineDataInfo.x2 = lineDataInfo.x1; - lineDataInfo.y2 = Math.round(y2); - } - dataStream.createLine(lineDataInfo); - } - } - -} diff --git a/src/java/org/apache/fop/render/afp/AFPConstants.java b/src/java/org/apache/fop/render/afp/AFPConstants.java deleted file mode 100644 index b9ab2de78..000000000 --- a/src/java/org/apache/fop/render/afp/AFPConstants.java +++ /dev/null @@ -1,53 +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.render.afp; - -/** - * Constants used by the AFP renderer. - * - */ -public interface AFPConstants { - - /** - * The encoding to use to convert to EBCIDIC - */ - String EBCIDIC_ENCODING = "Cp1146"; - - /** - * The encoding to use to convert to ASCII - */ - String ASCII_ENCODING = "Cp1252"; - - /** - * The encoding to use to convert to US ASCII (7 bit) - */ - String US_ASCII_ENCODING = "US-ASCII"; - - /** - * The scaling of the default transform is set to - * approximately 72 user space coordinates per square inch - */ - int DPI_72 = 72; - - /** - * 72dpi in millipoints - */ - int DPI_72_MPTS = DPI_72 * 1000; -} diff --git a/src/java/org/apache/fop/render/afp/AFPDataObjectFactory.java b/src/java/org/apache/fop/render/afp/AFPDataObjectFactory.java deleted file mode 100644 index f8e3c1518..000000000 --- a/src/java/org/apache/fop/render/afp/AFPDataObjectFactory.java +++ /dev/null @@ -1,256 +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.render.afp; - -import java.awt.geom.Rectangle2D; - -import org.apache.fop.render.afp.ioca.ImageContent; -import org.apache.fop.render.afp.modca.AbstractDataObject; -import org.apache.fop.render.afp.modca.AbstractNamedAFPObject; -import org.apache.fop.render.afp.modca.Document; -import org.apache.fop.render.afp.modca.Factory; -import org.apache.fop.render.afp.modca.GraphicsObject; -import org.apache.fop.render.afp.modca.ImageObject; -import org.apache.fop.render.afp.modca.IncludeObject; -import org.apache.fop.render.afp.modca.ObjectContainer; -import org.apache.fop.render.afp.modca.Overlay; -import org.apache.fop.render.afp.modca.PageSegment; -import org.apache.fop.render.afp.modca.Registry; -import org.apache.fop.render.afp.modca.ResourceObject; -import org.apache.fop.render.afp.modca.triplets.MappingOptionTriplet; -import org.apache.fop.render.afp.modca.triplets.ObjectClassificationTriplet; -import org.apache.xmlgraphics.image.codec.tiff.TIFFImage; -import org.apache.xmlgraphics.java2d.Graphics2DImagePainter; - -/** - * Factory for high level data objects (Image/Graphics etc) - */ -public class AFPDataObjectFactory { - - private final Factory factory; - - /** - * Main constructor - * - * @param factory an object factory - */ - public AFPDataObjectFactory(Factory factory) { - this.factory = factory; - } - - /** - * Creates and configures an ObjectContainer. - * - * @param dataObjectInfo the object container info - * @return a newly created Object Container - */ - public ObjectContainer createObjectContainer(AFPDataObjectInfo dataObjectInfo) { - ObjectContainer objectContainer = factory.createObjectContainer(); - - // set object classification - Registry.ObjectType objectType = dataObjectInfo.getObjectType(); - AFPResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); - AFPResourceLevel resourceLevel = resourceInfo.getLevel(); - final boolean dataInContainer = true; - final boolean containerHasOEG = resourceLevel.isInline(); - final boolean dataInOCD = true; - objectContainer.setObjectClassification( - ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT, - objectType, dataInContainer, containerHasOEG, dataInOCD); - - objectContainer.setInputStream(dataObjectInfo.getInputStream()); - return objectContainer; - } - - /** - * Creates and configures an IOCA Image Object. - * - * @param imageObjectInfo the image object info - * @return a newly created IOCA Image Object - */ - public ImageObject createImage(AFPImageObjectInfo imageObjectInfo) { - // IOCA bitmap image - ImageObject imageObj = factory.createImageObject(); - if (imageObjectInfo.hasCompression()) { - int compression = imageObjectInfo.getCompression(); - switch (compression) { - case TIFFImage.COMP_FAX_G3_1D: - imageObj.setEncoding(ImageContent.COMPID_G3_MH); - break; - case TIFFImage.COMP_FAX_G3_2D: - imageObj.setEncoding(ImageContent.COMPID_G3_MR); - break; - case TIFFImage.COMP_FAX_G4_2D: - imageObj.setEncoding(ImageContent.COMPID_G3_MMR); - break; - default: - throw new IllegalStateException( - "Invalid compression scheme: " + compression); - } - } - - if (imageObjectInfo.isColor()) { - imageObj.setIDESize((byte) 24); - } else { - imageObj.setIDESize((byte) imageObjectInfo.getBitsPerPixel()); - } - imageObj.setData(imageObjectInfo.getData()); - - return imageObj; - } - - /** - * Creates and returns a new graphics object. - * - * @param graphicsObjectInfo the graphics object info - * @return a new graphics object - */ - public GraphicsObject createGraphic(AFPGraphicsObjectInfo graphicsObjectInfo) { - // set newly created graphics object in g2d - GraphicsObject graphicsObj = factory.createGraphicsObject(); - AFPGraphics2D g2d = graphicsObjectInfo.getGraphics2D(); - g2d.setGraphicsObject(graphicsObj); - - // paint to graphics object - Graphics2DImagePainter painter = graphicsObjectInfo.getPainter(); - Rectangle2D area = graphicsObjectInfo.getArea(); - painter.paint(g2d, area); - - // return painted graphics object - return graphicsObj; - } - - /** - * Creates and returns a new include object. - * - * @param includeName the include name - * @param dataObjectInfo a data object info - * - * @return a new include object - */ - public IncludeObject createInclude(String includeName, AFPDataObjectInfo dataObjectInfo) { - IncludeObject includeObj = factory.createInclude(includeName); - - if (dataObjectInfo instanceof AFPImageObjectInfo) { - // IOCA image object - includeObj.setObjectType(IncludeObject.TYPE_IMAGE); - } else if (dataObjectInfo instanceof AFPGraphicsObjectInfo) { - // graphics object - includeObj.setObjectType(IncludeObject.TYPE_GRAPHIC); - } else { - // object container - includeObj.setObjectType(IncludeObject.TYPE_OTHER); - - // set mandatory object classification (type other) - Registry.ObjectType objectType = dataObjectInfo.getObjectType(); - if (objectType != null) { - // set object classification - final boolean dataInContainer = true; - final boolean containerHasOEG = false; // environment parameters set in include - final boolean dataInOCD = true; - includeObj.setObjectClassification( - // object scope not defined - ObjectClassificationTriplet.CLASS_TIME_VARIANT_PRESENTATION_OBJECT, - objectType, dataInContainer, containerHasOEG, dataInOCD); - } else { - throw new IllegalStateException( - "Failed to set Object Classification Triplet on Object Container."); - } - } - - AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo(); - - int xOffset = objectAreaInfo.getX(); - int yOffset = objectAreaInfo.getY(); - includeObj.setObjectAreaOffset(xOffset, yOffset); - - int width = objectAreaInfo.getWidth(); - int height = objectAreaInfo.getHeight(); - includeObj.setObjectAreaSize(width, height); - - int rotation = objectAreaInfo.getRotation(); - includeObj.setObjectAreaOrientation(rotation); - - int widthRes = objectAreaInfo.getWidthRes(); - int heightRes = objectAreaInfo.getHeightRes(); - includeObj.setMeasurementUnits(widthRes, heightRes); - - includeObj.setMappingOption(MappingOptionTriplet.SCALE_TO_FIT); - - return includeObj; - } - - /** - * Creates a resource object wrapper for named includable data objects - * - * @param namedObj an named object - * @param resourceInfo resource information - * @param objectType the object type - * @return a new resource object wrapper - */ - public ResourceObject createResource(AbstractNamedAFPObject namedObj, - AFPResourceInfo resourceInfo, Registry.ObjectType objectType) { - ResourceObject resourceObj = null; - String resourceName = resourceInfo.getName(); - if (resourceName != null) { - resourceObj = factory.createResource(resourceName); - } else { - resourceObj = factory.createResource(); - } - - if (namedObj instanceof Document) { - resourceObj.setType(ResourceObject.TYPE_DOCUMENT); - } else if (namedObj instanceof PageSegment) { - resourceObj.setType(ResourceObject.TYPE_PAGE_SEGMENT); - } else if (namedObj instanceof Overlay) { - resourceObj.setType(ResourceObject.TYPE_OVERLAY_OBJECT); - } else if (namedObj instanceof AbstractDataObject) { - AbstractDataObject dataObj = (AbstractDataObject)namedObj; - if (namedObj instanceof ObjectContainer) { - resourceObj.setType(ResourceObject.TYPE_OBJECT_CONTAINER); - - // set object classification - final boolean dataInContainer = true; - final boolean containerHasOEG = false; // must be included - final boolean dataInOCD = true; - // mandatory triplet for object container - resourceObj.setObjectClassification( - ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT, - objectType, dataInContainer, containerHasOEG, dataInOCD); - } else if (namedObj instanceof ImageObject) { - // ioca image type - resourceObj.setType(ResourceObject.TYPE_IMAGE); - } else if (namedObj instanceof GraphicsObject) { - resourceObj.setType(ResourceObject.TYPE_GRAPHIC); - } else { - throw new UnsupportedOperationException( - "Unsupported resource object for data object type " + dataObj); - } - } else { - throw new UnsupportedOperationException( - "Unsupported resource object type " + namedObj); - } - - // set the resource information/classification on the data object - resourceObj.setDataObject(namedObj); - return resourceObj; - } - -} diff --git a/src/java/org/apache/fop/render/afp/AFPDataObjectInfo.java b/src/java/org/apache/fop/render/afp/AFPDataObjectInfo.java deleted file mode 100644 index cdd4b4d37..000000000 --- a/src/java/org/apache/fop/render/afp/AFPDataObjectInfo.java +++ /dev/null @@ -1,206 +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.render.afp; - -import java.io.InputStream; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.fop.render.afp.modca.Registry; - -/** - * A list of parameters associated with an AFP data objects - */ -public class AFPDataObjectInfo { - private static final Log log = LogFactory.getLog("org.apache.fop.afp"); - - /** the object area info */ - private AFPObjectAreaInfo objectAreaInfo; - - /** resource info */ - private AFPResourceInfo resourceInfo; - - /** the data object width */ - private int dataWidth; - - /** the data object height */ - private int dataHeight; - - /** the object data in an inputstream */ - private InputStream inputStream; - - /** the object registry mimetype */ - private String mimeType; - - /** - * Default constructor - */ - public AFPDataObjectInfo() { - } - - /** - * Sets the image mime type - * - * @param mimeType the image mime type - */ - public void setMimeType(String mimeType) { - this.mimeType = mimeType; - } - - /** - * Returns the mime type of this data object - * - * @return the mime type of this data object - */ - public String getMimeType() { - return mimeType; - } - - /** - * Convenience method to return the object type - * - * @return the object type - */ - public Registry.ObjectType getObjectType() { - return Registry.getInstance().getObjectType(getMimeType()); - } - - /** - * Returns the resource level at which this data object should reside - * - * @return the resource level at which this data object should reside - */ - public AFPResourceInfo getResourceInfo() { - if (resourceInfo == null) { - this.resourceInfo = new AFPResourceInfo(); - } - return resourceInfo; - } - - /** - * Sets the resource level at which this object should reside - * - * @param resourceInfo the resource level at which this data object should reside - */ - public void setResourceInfo(AFPResourceInfo resourceInfo) { - this.resourceInfo = resourceInfo; - } - - /** - * Sets the object area info - * - * @param objectAreaInfo the object area info - */ - public void setObjectAreaInfo(AFPObjectAreaInfo objectAreaInfo) { - this.objectAreaInfo = objectAreaInfo; - } - - /** - * Returns the object area info - * - * @return the object area info - */ - public AFPObjectAreaInfo getObjectAreaInfo() { - return this.objectAreaInfo; - } - - /** {@inheritDoc} */ - public String toString() { - return "AFPDataObjectInfo{" - + "mimeType=" + mimeType - + ", dataWidth=" + dataWidth - + ", dataHeight=" + dataHeight - + (objectAreaInfo != null ? ", objectAreaInfo=" + objectAreaInfo : "") - + (resourceInfo != null ? ", resourceInfo=" + resourceInfo : ""); - } - - /** - * Returns the uri of this data object - * - * @return the uri of this data object - */ - public String getUri() { - return getResourceInfo().getUri(); - } - - /** - * Sets the data object uri - * - * @param uri the data object uri - */ - public void setUri(String uri) { - getResourceInfo().setUri(uri); - } - - /** - * Returns the image data width - * - * @return the image data width - */ - public int getDataWidth() { - return dataWidth; - } - - /** - * Sets the image data width - * - * @param imageDataWidth the image data width - */ - public void setDataWidth(int imageDataWidth) { - this.dataWidth = imageDataWidth; - } - - /** - * Returns the image data height - * - * @return the image data height - */ - public int getDataHeight() { - return dataHeight; - } - - /** - * Sets the image data height - * - * @param imageDataHeight the image data height - */ - public void setDataHeight(int imageDataHeight) { - this.dataHeight = imageDataHeight; - } - - /** - * Sets the object data inputstream - * - * @param inputStream the object data inputstream - */ - public void setInputStream(InputStream inputStream) { - this.inputStream = inputStream; - } - - /** - * Returns the object data inputstream - * - * @return the object data inputstream - */ - public InputStream getInputStream() { - return this.inputStream; - } - -} diff --git a/src/java/org/apache/fop/render/afp/AFPDataObjectInfoFactory.java b/src/java/org/apache/fop/render/afp/AFPDataObjectInfoFactory.java index a4979eb89..dcf074262 100644 --- a/src/java/org/apache/fop/render/afp/AFPDataObjectInfoFactory.java +++ b/src/java/org/apache/fop/render/afp/AFPDataObjectInfoFactory.java @@ -19,8 +19,18 @@ package org.apache.fop.render.afp; +import java.awt.Point; +import java.awt.geom.Rectangle2D; import java.io.IOException; +import org.apache.fop.afp.AFPDataObjectInfo; +import org.apache.fop.afp.AFPForeignAttributeReader; +import org.apache.fop.afp.AFPObjectAreaInfo; +import org.apache.fop.afp.AFPResourceInfo; +import org.apache.fop.afp.AFPState; +import org.apache.fop.afp.AFPUnitConverter; + + /** * Abstract image configurator */ @@ -47,33 +57,35 @@ public abstract class AFPDataObjectInfoFactory { /** * Configures the data object info * - * @param afpImageInfo the afp image info + * @param rendererImageInfo the afp image info * @return the data object info * @throws IOException thrown if an I/O exception of some sort has occurred. */ - public AFPDataObjectInfo create(AFPImageInfo afpImageInfo) throws IOException { + public AFPDataObjectInfo create(AFPRendererImageInfo rendererImageInfo) throws IOException { AFPDataObjectInfo dataObjectInfo = createDataObjectInfo(); // set resource information AFPResourceInfo resourceInfo - = foreignAttributeReader.getResourceInfo(afpImageInfo.foreignAttributes); - resourceInfo.setUri(afpImageInfo.uri); + = foreignAttributeReader.getResourceInfo(rendererImageInfo.getForeignAttributes()); + resourceInfo.setUri(rendererImageInfo.getURI()); dataObjectInfo.setResourceInfo(resourceInfo); // set object area AFPObjectAreaInfo objectAreaInfo = new AFPObjectAreaInfo(); - float srcX = afpImageInfo.origin.x + (float)afpImageInfo.pos.getX(); - float srcY = afpImageInfo.origin.y + (float)afpImageInfo.pos.getY(); + Point origin = rendererImageInfo.getOrigin(); + Rectangle2D position = rendererImageInfo.getPosition(); + float srcX = origin.x + (float)position.getX(); + float srcY = origin.y + (float)position.getY(); AFPUnitConverter unitConv = state.getUnitConverter(); int[] coords = unitConv.mpts2units(new float[] {srcX, srcY}); objectAreaInfo.setX(coords[X]); objectAreaInfo.setY(coords[Y]); - int width = Math.round(unitConv.mpt2units((float)afpImageInfo.pos.getWidth())); + int width = Math.round(unitConv.mpt2units((float)position.getWidth())); objectAreaInfo.setWidth(width); - int height = Math.round(unitConv.mpt2units((float)afpImageInfo.pos.getHeight())); + int height = Math.round(unitConv.mpt2units((float)position.getHeight())); objectAreaInfo.setHeight(height); int resolution = state.getResolution(); diff --git a/src/java/org/apache/fop/render/afp/AFPDataObjectInfoProvider.java b/src/java/org/apache/fop/render/afp/AFPDataObjectInfoProvider.java index b54479e53..4211fe360 100644 --- a/src/java/org/apache/fop/render/afp/AFPDataObjectInfoProvider.java +++ b/src/java/org/apache/fop/render/afp/AFPDataObjectInfoProvider.java @@ -22,6 +22,7 @@ package org.apache.fop.render.afp; import java.util.Iterator; import java.util.Map; +import org.apache.fop.afp.AFPState; import org.apache.xmlgraphics.image.loader.Image; import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D; import org.apache.xmlgraphics.image.loader.impl.ImageRawCCITTFax; diff --git a/src/java/org/apache/fop/render/afp/AFPFontAttributes.java b/src/java/org/apache/fop/render/afp/AFPFontAttributes.java deleted file mode 100644 index ffbc85046..000000000 --- a/src/java/org/apache/fop/render/afp/AFPFontAttributes.java +++ /dev/null @@ -1,107 +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.render.afp; - -import org.apache.fop.render.afp.fonts.AFPFont; - -/** - * This class encapsulates the font attributes that need to be included - * in the AFP data stream. This class does not assist in converting the - * font attributes to AFP code pages and character set values. - * - */ -public class AFPFontAttributes { - - /** - * The font reference - */ - private int fontReference; - - /** - * The font key - */ - private String fontKey; - - /** - * The font - */ - private AFPFont font; - - /** - * The point size - */ - private int pointSize; - - /** - * Constructor for the AFPFontAttributes - * @param fontKey the font key - * @param font the font - * @param pointSize the point size - */ - public AFPFontAttributes(String fontKey, AFPFont font, int pointSize) { - this.fontKey = fontKey; - this.font = font; - this.pointSize = pointSize; - } - - /** - * @return the font - */ - public AFPFont getFont() { - return font; - } - - /** - * @return the FontKey attribute - */ - public String getFontKey() { - return fontKey + pointSize; - } - - /** - * @return the point size attribute - */ - public int getPointSize() { - return pointSize; - } - - /** - * @return the FontReference attribute - */ - public int getFontReference() { - return fontReference; - } - - /** - * Sets the FontReference attribute - * @param fontReference the FontReference to set - */ - public void setFontReference(int fontReference) { - this.fontReference = fontReference; - } - - /** {@inheritDoc} */ - public String toString() { - return "fontReference=" + fontReference - + ", fontKey=" + fontKey - + ", font=" + font - + ", pointSize=" + pointSize; - } -} diff --git a/src/java/org/apache/fop/render/afp/AFPForeignAttributeReader.java b/src/java/org/apache/fop/render/afp/AFPForeignAttributeReader.java deleted file mode 100644 index 4d5d4c1db..000000000 --- a/src/java/org/apache/fop/render/afp/AFPForeignAttributeReader.java +++ /dev/null @@ -1,126 +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.render.afp; - -import java.io.File; -import java.util.Map; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.fop.render.afp.extensions.AFPElementMapping; -import org.apache.xmlgraphics.util.QName; - -/** - * Parses any AFP foreign attributes - */ -public class AFPForeignAttributeReader { - private static final Log log = LogFactory.getLog("org.apache.fop.afp"); - - /** the resource-name attribute */ - public static final String RESOURCE_NAME = "afp:resource-name"; - - /** the resource-level attribute */ - public static final String RESOURCE_LEVEL = "afp:resource-level"; - - /** the resource-group-file attribute */ - public static final String RESOURCE_GROUP_FILE = "afp:resource-group-file"; - - /** - * Main constructor - */ - public AFPForeignAttributeReader() { - } - - /** - * Returns the resource information - * - * @param foreignAttributes the foreign attributes - * @return the resource information - */ - public AFPResourceInfo getResourceInfo(Map/**/ foreignAttributes) { - AFPResourceInfo resourceInfo = new AFPResourceInfo(); - if (foreignAttributes != null && !foreignAttributes.isEmpty()) { - QName resourceNameKey = new QName(AFPElementMapping.NAMESPACE, RESOURCE_NAME); - String resourceName = (String)foreignAttributes.get(resourceNameKey); - if (resourceName != null) { - resourceInfo.setName(resourceName); - } - AFPResourceLevel level = getResourceLevel(foreignAttributes); - if (level != null) { - resourceInfo.setLevel(level); - } - } - return resourceInfo; - } - - /** - * Returns the resource level - * - * @param foreignAttributes the foreign attributes - * @return the resource level - */ - public AFPResourceLevel getResourceLevel(Map/**/ foreignAttributes) { - AFPResourceLevel resourceLevel = null; - if (foreignAttributes != null && !foreignAttributes.isEmpty()) { - QName resourceLevelKey = new QName(AFPElementMapping.NAMESPACE, RESOURCE_LEVEL); - if (foreignAttributes.containsKey(resourceLevelKey)) { - String levelString = (String)foreignAttributes.get(resourceLevelKey); - resourceLevel = AFPResourceLevel.valueOf(levelString); - // if external get resource group file attributes - if (resourceLevel != null && resourceLevel.isExternal()) { - QName resourceGroupFileKey = new QName(AFPElementMapping.NAMESPACE, - RESOURCE_GROUP_FILE); - String resourceGroupFile - = (String)foreignAttributes.get(resourceGroupFileKey); - if (resourceGroupFile == null) { - String msg = RESOURCE_GROUP_FILE + " not specified"; - log.error(msg); - throw new UnsupportedOperationException(msg); - } - File resourceExternalGroupFile = new File(resourceGroupFile); - SecurityManager security = System.getSecurityManager(); - try { - if (security != null) { - security.checkWrite(resourceExternalGroupFile.getPath()); - } - } catch (SecurityException ex) { - String msg = "unable to gain write access to external resource file: " - + resourceGroupFile; - log.error(msg); - } - - try { - boolean exists = resourceExternalGroupFile.exists(); - if (exists) { - log.warn("overwriting external resource file: " - + resourceGroupFile); - } - resourceLevel.setExternalFilePath(resourceGroupFile); - } catch (SecurityException ex) { - String msg = "unable to gain read access to external resource file: " - + resourceGroupFile; - log.error(msg); - } - } - } - } - return resourceLevel; - } -} diff --git a/src/java/org/apache/fop/render/afp/AFPGraphics2D.java b/src/java/org/apache/fop/render/afp/AFPGraphics2D.java deleted file mode 100644 index 9acf76873..000000000 --- a/src/java/org/apache/fop/render/afp/AFPGraphics2D.java +++ /dev/null @@ -1,582 +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.render.afp; - -import java.awt.AlphaComposite; -import java.awt.BasicStroke; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Graphics; -import java.awt.GraphicsConfiguration; -import java.awt.Image; -import java.awt.Rectangle; -import java.awt.Shape; -import java.awt.Stroke; -import java.awt.geom.AffineTransform; -import java.awt.geom.Ellipse2D; -import java.awt.geom.Line2D; -import java.awt.geom.PathIterator; -import java.awt.geom.Rectangle2D; -import java.awt.image.BufferedImage; -import java.awt.image.ImageObserver; -import java.awt.image.RenderedImage; -import java.awt.image.renderable.RenderableImage; -import java.io.IOException; - -import org.apache.commons.io.output.ByteArrayOutputStream; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.apache.xmlgraphics.image.loader.ImageInfo; -import org.apache.xmlgraphics.image.loader.ImageSize; -import org.apache.xmlgraphics.image.loader.impl.ImageRendered; -import org.apache.xmlgraphics.java2d.AbstractGraphics2D; -import org.apache.xmlgraphics.java2d.GraphicContext; -import org.apache.xmlgraphics.java2d.StrokingTextHandler; -import org.apache.xmlgraphics.java2d.TextHandler; -import org.apache.xmlgraphics.ps.ImageEncodingHelper; - -import org.apache.fop.apps.MimeConstants; -import org.apache.fop.render.afp.goca.GraphicsSetLineType; -import org.apache.fop.render.afp.modca.GraphicsObject; - -/** - * This is a concrete implementation of AbstractGraphics2D (and - * therefore of Graphics2D) which is able to generate GOCA byte - * codes. - * - * @see org.apache.xmlgraphics.java2d.AbstractGraphics2D - */ -public class AFPGraphics2D extends AbstractGraphics2D { - - private static final Log log = LogFactory.getLog(AFPGraphics2D.class); - - private static final int X = 0; - - private static final int Y = 1; - - private static final int X1 = 0; - - private static final int Y1 = 1; - - private static final int X2 = 2; - - private static final int Y2 = 3; - - - /** graphics object */ - private GraphicsObject graphicsObj = null; - - /** Fallback text handler */ - protected TextHandler fallbackTextHandler = new StrokingTextHandler(this); - - /** Custom text handler */ - protected TextHandler customTextHandler = null; - - /** AFP info */ - private AFPInfo info = null; - - /** Current AFP state */ - private AFPState state = null; - - /** - * Main constructor - * - * @param textAsShapes - * if true, all text is turned into shapes in the convertion. No - * text is output. - * - */ - public AFPGraphics2D(boolean textAsShapes) { - super(textAsShapes); - } - - /** - * Copy Constructor - * - * @param g2d - * a AFPGraphics2D whose properties should be copied - */ - public AFPGraphics2D(AFPGraphics2D g2d) { - super(g2d); - this.graphicsObj = g2d.graphicsObj; - this.fallbackTextHandler = g2d.fallbackTextHandler; - this.customTextHandler = g2d.customTextHandler; - this.info = g2d.info; - this.state = g2d.state; - } - - /** - * Sets the AFPInfo - * - * @param afpInfo the AFP Info to use - */ - public void setAFPInfo(AFPInfo afpInfo) { - this.info = afpInfo; - this.state = info.getState(); - } - - /** - * Gets the AFPInfo - * - * @return the AFPInfo - */ - public AFPInfo getAFPInfo() { - return this.info; - } - - /** - * Sets the GraphicContext - * - * @param gc - * GraphicContext to use - */ - public void setGraphicContext(GraphicContext gc) { - this.gc = gc; - } - - /** - * Apply the stroke to the AFP graphics object. - * This takes the java stroke and outputs the appropriate settings - * to the AFP graphics object so that the stroke attributes are handled. - * - * @param stroke the java stroke - */ - protected void applyStroke(Stroke stroke) { - if (stroke instanceof BasicStroke) { - BasicStroke basicStroke = (BasicStroke) stroke; - float lineWidth = basicStroke.getLineWidth(); - if (state.setLineWidth(lineWidth)) { - getGraphicsObject().setLineWidth(Math.round(lineWidth * 2)); - } - // note: this is an approximation at best! - float[] dashArray = basicStroke.getDashArray(); - if (state.setDashArray(dashArray)) { - byte type = GraphicsSetLineType.DEFAULT; // normally SOLID - if (dashArray != null) { - type = GraphicsSetLineType.DOTTED; // default to plain DOTTED if dashed line - // float offset = basicStroke.getDashPhase(); - if (dashArray.length == 2) { - if (dashArray[0] < dashArray[1]) { - type = GraphicsSetLineType.SHORT_DASHED; - } else if (dashArray[0] > dashArray[1]) { - type = GraphicsSetLineType.LONG_DASHED; - } - } else if (dashArray.length == 4) { - if (dashArray[0] > dashArray[1] - && dashArray[2] < dashArray[3]) { - type = GraphicsSetLineType.DASH_DOT; - } else if (dashArray[0] < dashArray[1] - && dashArray[2] < dashArray[3]) { - type = GraphicsSetLineType.DOUBLE_DOTTED; - } - } else if (dashArray.length == 6) { - if (dashArray[0] > dashArray[1] - && dashArray[2] < dashArray[3] - && dashArray[4] < dashArray[5]) { - type = GraphicsSetLineType.DASH_DOUBLE_DOTTED; - } - } - } - getGraphicsObject().setLineType(type); - } - } else { - log.warn("Unsupported Stroke: " + stroke.getClass().getName()); - } - } - - /** - * Handle the Batik drawing event - * - * @param shape - * the shape to draw - * @param fill - * true if the shape is to be drawn filled - */ - private void doDrawing(Shape shape, boolean fill) { - getGraphicsObject(); - if (!fill) { - graphicsObj.newSegment(); - } - - Color color = getColor(); - if (state.setColor(color)) { - graphicsObj.setColor(color); - } - - Stroke stroke = getStroke(); - applyStroke(stroke); - - if (fill) { - graphicsObj.beginArea(); - } - AffineTransform trans = super.getTransform(); - - PathIterator iter = shape.getPathIterator(trans); - double[] dstPts = new double[6]; - int[] coords = null; - if (shape instanceof Line2D) { - iter.currentSegment(dstPts); - coords = new int[4]; - coords[X1] = (int) Math.round(dstPts[X]); - coords[Y1] = (int) Math.round(dstPts[Y]); - iter.next(); - iter.currentSegment(dstPts); - coords[X2] = (int) Math.round(dstPts[X]); - coords[Y2] = (int) Math.round(dstPts[Y]); - graphicsObj.addLine(coords); - } else if (shape instanceof Rectangle2D) { - iter.currentSegment(dstPts); - coords = new int[4]; - coords[X2] = (int) Math.round(dstPts[X]); - coords[Y2] = (int) Math.round(dstPts[Y]); - iter.next(); - iter.next(); - iter.currentSegment(dstPts); - coords[X1] = (int) Math.round(dstPts[X]); - coords[Y1] = (int) Math.round(dstPts[Y]); - graphicsObj.addBox(coords); - } else if (shape instanceof Ellipse2D) { - Ellipse2D elip = (Ellipse2D) shape; - double scale = trans.getScaleX(); - double radiusWidth = elip.getWidth() / 2; - double radiusHeight = elip.getHeight() / 2; - graphicsObj.setArcParams( - (int)Math.round(radiusWidth * scale), - (int)Math.round(radiusHeight * scale), - 0, - 0 - ); - double[] srcPts = new double[] {elip.getCenterX(), elip.getCenterY()}; - trans.transform(srcPts, 0, dstPts, 0, 1); - final int mh = 1; - final int mhr = 0; - graphicsObj.addFullArc( - (int)Math.round(dstPts[X]), - (int)Math.round(dstPts[Y]), - mh, - mhr - ); - } else { - // graphics segment opening coordinates (x,y) - // current position coordinates (x,y) - for (int[] openingCoords = new int[2], currCoords = new int[2]; - !iter.isDone(); iter.next()) { - // round the coordinate values and combine with current position - // coordinates - 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]); - } 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; - } else { - // close of the graphics segment - if (type == PathIterator.SEG_CLOSE) { - coords = new int[] { - coords[coords.length - 2], //prev X - coords[coords.length - 1], //prev Y - openingCoords[X], - openingCoords[Y] - }; - graphicsObj.addLine(coords); - } else { - log.debug("Unrecognised path iterator type: " - + type); - } - continue; - } - // combine current position coordinates with new graphics - // segment coordinates - coords = new int[numCoords + 2]; - coords[X] = currCoords[X]; - coords[Y] = currCoords[Y]; - for (int i = 0; i < numCoords; i++) { - coords[i + 2] = (int) Math.round(dstPts[i]); - } - if (type == PathIterator.SEG_LINETO) { - graphicsObj.addLine(coords); - } else if (type == PathIterator.SEG_QUADTO - || type == PathIterator.SEG_CUBICTO) { - graphicsObj.addFillet(coords); - } - // update current position coordinates - currCoords[X] = coords[coords.length - 2]; - currCoords[Y] = coords[coords.length - 1]; - } - } - } - if (fill) { - graphicsObj.endArea(); - } - } - - /** {@inheritDoc} */ - public void draw(Shape shape) { -// log.debug("draw() shape=" + shape); - doDrawing(shape, false); - } - - /** {@inheritDoc} */ - public void fill(Shape shape) { -// log.debug("fill() shape=" + shape); - doDrawing(shape, true); - } - - /** - * Central handler for IOExceptions for this class. - * - * @param ioe - * IOException to handle - */ - public void handleIOException(IOException ioe) { - // TODO Surely, there's a better way to do this. - log.error(ioe.getMessage()); - ioe.printStackTrace(); - } - - /** {@inheritDoc} */ - public void drawString(String str, float x, float y) { - try { - if (customTextHandler != null && !textAsShapes) { - customTextHandler.drawString(str, x, y); - } else { - fallbackTextHandler.drawString(str, x, y); - } - } catch (IOException ioe) { - handleIOException(ioe); - } - } - - /** {@inheritDoc} */ - public GraphicsConfiguration getDeviceConfiguration() { - return new AFPGraphicsConfiguration(); - } - - /** {@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); - } - - /** {@inheritDoc} */ - public void dispose() { - this.graphicsObj = null; - } - - /** {@inheritDoc} */ - public boolean drawImage(Image img, int x, int y, ImageObserver observer) { - return drawImage(img, x, y, img.getWidth(observer), img.getHeight(observer), observer); - } - - private BufferedImage buildBufferedImage(Dimension size) { - return new BufferedImage(size.width, size.height, - BufferedImage.TYPE_INT_ARGB); - } - - private AFPImageObjectInfo getImageObjectInfo( - RenderedImage img, int x, int y, int width, int height) throws IOException { - ImageInfo imageInfo = new ImageInfo(null, "image/unknown"); - ImageSize size = new ImageSize(img.getWidth(), img.getHeight(), 72); - imageInfo.setSize(size); - - ImageRendered imageRendered = new ImageRendered(imageInfo, img, null); - RenderedImage renderedImage = imageRendered.getRenderedImage(); - - // create image object info - AFPImageObjectInfo imageObjectInfo = new AFPImageObjectInfo(); - - imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS45); - - imageObjectInfo.setBitsPerPixel(state.getBitsPerPixel()); - - imageObjectInfo.setResourceInfo(info.getResourceInfo()); - - int dataHeight = renderedImage.getHeight(); - imageObjectInfo.setDataHeight(dataHeight); - - int dataWidth = renderedImage.getWidth(); - imageObjectInfo.setDataWidth(dataWidth); - - boolean colorImages = state.isColorImages(); - imageObjectInfo.setColor(colorImages); - - ByteArrayOutputStream boas = new ByteArrayOutputStream(); - ImageEncodingHelper.encodeRenderedImageAsRGB(renderedImage, boas); - byte[] imageData = boas.toByteArray(); - - // convert to grayscale - if (!colorImages) { - boas.reset(); - int bitsPerPixel = state.getBitsPerPixel(); - imageObjectInfo.setBitsPerPixel(bitsPerPixel); - ImageEncodingHelper.encodeRGBAsGrayScale( - imageData, dataWidth, dataHeight, bitsPerPixel, boas); - imageData = boas.toByteArray(); - } - imageObjectInfo.setData(imageData); - - if (imageInfo != null) { - imageObjectInfo.setUri(imageInfo.getOriginalURI()); - } - - // create object area info - AFPObjectAreaInfo objectAreaInfo = new AFPObjectAreaInfo(); - - AffineTransform at = gc.getTransform(); - float[] srcPts = new float[] {x, y}; - float[] dstPts = new float[srcPts.length]; - at.transform(srcPts, 0, dstPts, 0, 1); - objectAreaInfo.setX(Math.round(dstPts[X])); - objectAreaInfo.setY(Math.round(dstPts[Y])); - - AFPUnitConverter unitConv = state.getUnitConverter(); - - int w = Math.round(unitConv.pt2units(width)); - objectAreaInfo.setWidth(w); - - int h = Math.round(unitConv.pt2units(height)); - objectAreaInfo.setHeight(h); - - int resolution = state.getResolution(); - objectAreaInfo.setWidthRes(resolution); - objectAreaInfo.setHeightRes(resolution); - - imageObjectInfo.setObjectAreaInfo(objectAreaInfo); - - return imageObjectInfo; - } - - /** {@inheritDoc} */ - public boolean drawImage(Image img, int x, int y, int width, int height, - ImageObserver observer) { - - // draw with AWT Graphics2D - Dimension size = new Dimension(width, height); - BufferedImage bufferedImage = buildBufferedImage(size); - - java.awt.Graphics2D g2d = bufferedImage.createGraphics(); - g2d.setComposite(AlphaComposite.SrcOver); - - Color color = new Color(1, 1, 1, 0); - g2d.setBackground(color); - g2d.setPaint(color); - - g2d.fillRect(0, 0, width, height); - - int bufferedWidth = bufferedImage.getWidth(); - int bufferedHeight = bufferedImage.getHeight(); - Rectangle clipRect = new Rectangle(0, 0, bufferedWidth, bufferedHeight); - g2d.clip(clipRect); - - g2d.setComposite(gc.getComposite()); - - boolean drawn = g2d.drawImage(img, 0, 0, bufferedWidth, bufferedHeight, observer); - g2d.dispose(); - - if (drawn) { - try { - // get image object info - AFPImageObjectInfo imageObjectInfo = getImageObjectInfo(bufferedImage, x, y, width, height); - - // create image resource - AFPResourceManager resourceManager = info.getResourceManager(); - resourceManager.createObject(imageObjectInfo); - return true; - } catch (IOException ioe) { - handleIOException(ioe); - } - } - return false; - } - - /** {@inheritDoc} */ - public void drawRenderableImage(RenderableImage img, AffineTransform xform) { - log.debug("drawRenderableImage() NYI: img=" + img + ", xform=" + xform); - } - - /** {@inheritDoc} */ - public void drawRenderedImage(RenderedImage img, AffineTransform xform) { - log.debug("drawRenderedImage() NYI: img=" + img + ", xform=" + xform); - } - - /** {@inheritDoc} */ - public FontMetrics getFontMetrics(Font f) { - log.debug("getFontMetrics() NYI: f=" + f); - return null; - } - - /** {@inheritDoc} */ - public void setXORMode(Color col) { - log.debug("setXORMode() NYI: col=" + col); - } - - /** - * Sets a custom TextHandler implementation that is responsible for painting - * text. The default TextHandler paints all text as shapes. A custom - * implementation can implement text painting using text painting operators. - * - * @param handler - * the custom TextHandler implementation - */ - public void setCustomTextHandler(TextHandler handler) { - this.customTextHandler = handler; - } - - /** - * Returns the GOCA graphics object - * - * @return the GOCA graphics object - */ - protected GraphicsObject getGraphicsObject() { - return this.graphicsObj; - } - - /** - * Sets the GOCA graphics object - * - * @param obj the GOCA graphics object - */ - public void setGraphicsObject(GraphicsObject obj) { - this.graphicsObj = obj; - } - - /** - * Sets the AFP state - * - * @param state the AFP state - */ - protected void setState(AFPState state) { - this.state = state; - } - -} diff --git a/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java b/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java index 6561902d9..453e16429 100644 --- a/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java +++ b/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java @@ -25,6 +25,10 @@ import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.io.IOException; +import org.apache.fop.afp.AFPGraphics2D; +import org.apache.fop.afp.AFPGraphicsObjectInfo; +import org.apache.fop.afp.AFPResourceManager; +import org.apache.fop.afp.AFPState; import org.apache.fop.render.AbstractGraphics2DAdapter; import org.apache.fop.render.RendererContext; import org.apache.fop.render.RendererContext.RendererContextWrapper; @@ -56,7 +60,7 @@ public class AFPGraphics2DAdapter extends AbstractGraphics2DAdapter { * * @return the AFP graphics 2D implementation */ - protected AFPGraphics2D getGraphics2D() { + public AFPGraphics2D getGraphics2D() { return g2d; } @@ -70,11 +74,12 @@ public class AFPGraphics2DAdapter extends AbstractGraphics2DAdapter { AFPInfo afpInfo = AFPSVGHandler.getAFPInfo(context); - g2d.setAFPInfo(afpInfo); + g2d.setResourceManager(afpInfo.getResourceManager()); + g2d.setResourceInfo(afpInfo.getResourceInfo()); + g2d.setState(afpInfo.getState()); g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext()); // // scale/convert to afp units - AFPState state = afpInfo.getState(); // AFPUnitConverter unitConv = state.getUnitConverter(); // float scale = unitConv.mpt2units(1); @@ -96,6 +101,7 @@ public class AFPGraphics2DAdapter extends AbstractGraphics2DAdapter { RendererContextWrapper ctx = RendererContext.wrapRendererContext(context); BufferedImage bi = paintToBufferedImage(painter, ctx, resolution, false, false); + AFPState state = afpInfo.getState(); AffineTransform trans = state.getData().getTransform(); float scale = AFPRenderer.NORMAL_AFP_RESOLUTION / context.getUserAgent().getTargetResolution(); diff --git a/src/java/org/apache/fop/render/afp/AFPGraphicsConfiguration.java b/src/java/org/apache/fop/render/afp/AFPGraphicsConfiguration.java deleted file mode 100644 index 1f40b7cfd..000000000 --- a/src/java/org/apache/fop/render/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.render.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/render/afp/AFPGraphicsDevice.java b/src/java/org/apache/fop/render/afp/AFPGraphicsDevice.java deleted file mode 100644 index d4c756a5a..000000000 --- a/src/java/org/apache/fop/render/afp/AFPGraphicsDevice.java +++ /dev/null @@ -1,80 +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.render.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/render/afp/AFPGraphicsObjectInfo.java b/src/java/org/apache/fop/render/afp/AFPGraphicsObjectInfo.java deleted file mode 100644 index b4c651574..000000000 --- a/src/java/org/apache/fop/render/afp/AFPGraphicsObjectInfo.java +++ /dev/null @@ -1,105 +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.render.afp; - -import java.awt.geom.Rectangle2D; - -import org.apache.xmlgraphics.java2d.Graphics2DImagePainter; -import org.apache.xmlgraphics.util.MimeConstants; - -/** - * A graphics object info which contains necessary painting objects - */ -public class AFPGraphicsObjectInfo extends AFPDataObjectInfo { - - /** the graphics object painter implementation */ - private Graphics2DImagePainter painter; - - /** the graphics object area */ - private Rectangle2D area; - - /** the AFP graphics 2d implementation */ - private AFPGraphics2D g2d; - - /** - * Returns the graphics painter - * - * @return the graphics painter - */ - public Graphics2DImagePainter getPainter() { - return this.painter; - } - - /** - * Sets the graphics painter - * - * @param graphicsPainter the graphics painter - */ - public void setPainter(Graphics2DImagePainter graphicsPainter) { - this.painter = graphicsPainter; - } - - /** - * Returns the graphics area - * - * @return the graphics area - */ - public Rectangle2D getArea() { - return this.area; - } - - /** - * Sets the graphics area area - * - * @param area the graphics object area - */ - public void setArea(Rectangle2D area) { - this.area = area; - } - - /** - * Sets the AFP graphics 2D implementation - * - * @param g2d the AFP graphics 2D implementation - */ - public void setGraphics2D(AFPGraphics2D g2d) { - this.g2d = g2d; - } - - /** - * Returns the AFP graphics 2D implementation - * - * @return the AFP graphics 2D implementation - */ - public AFPGraphics2D getGraphics2D() { - return this.g2d; - } - - /** {@inheritDoc} */ - public String toString() { - return "GraphicsObjectInfo{" + super.toString() + "}"; - } - - /** {@inheritDoc} */ - public String getMimeType() { - return MimeConstants.MIME_SVG; - } - -} diff --git a/src/java/org/apache/fop/render/afp/AFPImageGraphics2DFactory.java b/src/java/org/apache/fop/render/afp/AFPImageGraphics2DFactory.java index ab9cf7ef7..d76e26d57 100644 --- a/src/java/org/apache/fop/render/afp/AFPImageGraphics2DFactory.java +++ b/src/java/org/apache/fop/render/afp/AFPImageGraphics2DFactory.java @@ -26,7 +26,16 @@ import java.awt.geom.Rectangle2D; import java.io.IOException; import org.apache.batik.bridge.BridgeContext; +import org.apache.fop.afp.AFPDataObjectInfo; +import org.apache.fop.afp.AFPGraphics2D; +import org.apache.fop.afp.AFPGraphicsObjectInfo; +import org.apache.fop.afp.AFPObjectAreaInfo; +import org.apache.fop.afp.AFPResourceInfo; +import org.apache.fop.afp.AFPResourceLevel; +import org.apache.fop.afp.AFPState; +import org.apache.fop.afp.AFPTextHandler; import org.apache.fop.image.loader.batik.GenericGraphics2DImagePainter; +import org.apache.fop.render.RendererContext; import org.apache.fop.svg.SVGUserAgent; import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D; import org.apache.xmlgraphics.util.MimeConstants; @@ -54,9 +63,9 @@ public class AFPImageGraphics2DFactory extends AFPDataObjectInfoFactory { private static final AFPResourceLevel inlineResourceLevel = new AFPResourceLevel(AFPResourceLevel.INLINE); /** {@inheritDoc} */ - public AFPDataObjectInfo create(AFPImageInfo afpImageInfo) throws IOException { + public AFPDataObjectInfo create(AFPRendererImageInfo rendererImageInfo) throws IOException { AFPGraphicsObjectInfo graphicsObjectInfo - = (AFPGraphicsObjectInfo)super.create(afpImageInfo); + = (AFPGraphicsObjectInfo)super.create(rendererImageInfo); AFPResourceInfo resourceInfo = graphicsObjectInfo.getResourceInfo(); // level not explicitly set/changed so default to inline for GOCA graphic objects @@ -69,13 +78,17 @@ public class AFPImageGraphics2DFactory extends AFPDataObjectInfoFactory { graphicsObjectInfo.setMimeType(MimeConstants.MIME_AFP_GOCA); // set graphics 2d - AFPGraphics2DAdapter g2dAdapter = afpImageInfo.g2dAdapter; + AFPGraphics2DAdapter g2dAdapter = rendererImageInfo.getGraphics2DAdapter(); AFPGraphics2D g2d = g2dAdapter.getGraphics2D(); graphicsObjectInfo.setGraphics2D(g2d); - // set afp info - AFPInfo afpInfo = AFPSVGHandler.getAFPInfo(afpImageInfo.rendererContext); - g2d.setAFPInfo(afpInfo); + // set resource, state and font info + RendererContext rendererContext = rendererImageInfo.getRendererContext(); + AFPInfo afpInfo = AFPSVGHandler.getAFPInfo(rendererContext); + g2d.setResourceManager(afpInfo.getResourceManager()); + g2d.setResourceInfo(afpInfo.getResourceInfo()); + g2d.setState(afpInfo.getState()); + g2d.setFontInfo(afpInfo.getFontInfo()); // set to default graphic context g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext()); @@ -89,7 +102,7 @@ public class AFPImageGraphics2DFactory extends AFPDataObjectInfoFactory { // controls whether text painted by Batik is generated using text or path operations SVGUserAgent svgUserAgent - = new SVGUserAgent(afpImageInfo.rendererContext.getUserAgent(), new AffineTransform()); + = new SVGUserAgent(rendererContext.getUserAgent(), new AffineTransform()); BridgeContext ctx = new BridgeContext(svgUserAgent); if (!afpInfo.strokeText()) { AFPTextHandler textHandler = new AFPTextHandler(g2d); @@ -101,7 +114,7 @@ public class AFPImageGraphics2DFactory extends AFPDataObjectInfoFactory { } // set painter - ImageGraphics2D imageG2D = (ImageGraphics2D)afpImageInfo.img; + ImageGraphics2D imageG2D = (ImageGraphics2D)rendererImageInfo.getImage(); GenericGraphics2DImagePainter painter = (GenericGraphics2DImagePainter)imageG2D.getGraphics2DImagePainter(); painter = new AFPGraphics2DImagePainter(painter); diff --git a/src/java/org/apache/fop/render/afp/AFPImageInfo.java b/src/java/org/apache/fop/render/afp/AFPImageInfo.java deleted file mode 100644 index 9acc87b3f..000000000 --- a/src/java/org/apache/fop/render/afp/AFPImageInfo.java +++ /dev/null @@ -1,97 +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.render.afp; - -import java.awt.Point; -import java.awt.geom.Rectangle2D; -import java.util.Map; - -import org.apache.fop.render.RendererContext; -import org.apache.xmlgraphics.image.loader.Image; -import org.apache.xmlgraphics.image.loader.ImageInfo; - -/** - * The AFP image information - */ -public class AFPImageInfo { - - /** the image uri */ - protected final String uri; - - /** the current pos */ - protected final Rectangle2D pos; - - /** the origin */ - protected final Point origin; - - /** the foreign attributes */ - protected final Map foreignAttributes; - - /** the image info */ - protected final ImageInfo info; - - /** the image */ - protected final Image img; - - /** the AFP graphics 2d adapter */ - protected AFPGraphics2DAdapter g2dAdapter; - - /** the renderer context */ - protected RendererContext rendererContext; - - /** - * Main constructor - * - * @param uri the image uri - * @param pos the image content area - * @param origin the current position - * @param info the image info - * @param img the image - * @param foreignAttributes the foreign attributes - */ - public AFPImageInfo(String uri, Rectangle2D pos, Point origin, - ImageInfo info, Image img, Map foreignAttributes) { - this.uri = uri; - this.pos = pos; - this.origin = origin; - this.info = info; - this.img = img; - this.foreignAttributes = foreignAttributes; - } - - /** - * Sets the renderer context - * - * @param rendererContext the renderer context - */ - public void setRendererContext(RendererContext rendererContext) { - this.rendererContext = rendererContext; - } - - /** - * Sets the graphics 2d adapter - * - * @param adapter the graphics 2d adapter - */ - public void setGraphics2DAdapter(AFPGraphics2DAdapter adapter) { - this.g2dAdapter = adapter; - } - -} diff --git a/src/java/org/apache/fop/render/afp/AFPImageObjectInfo.java b/src/java/org/apache/fop/render/afp/AFPImageObjectInfo.java deleted file mode 100644 index 711e135d0..000000000 --- a/src/java/org/apache/fop/render/afp/AFPImageObjectInfo.java +++ /dev/null @@ -1,137 +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.render.afp; - - - -/** - * A list of parameters associated with an image - */ -public class AFPImageObjectInfo extends AFPDataObjectInfo { - /** number of bits per pixel used */ - private int bitsPerPixel; - - /** is this a color image? */ - private boolean color; - - /** compression type if any */ - private int compression = -1; - - /** the object data in a byte array */ - private byte[] data; - - /** - * Default constructor - */ - public AFPImageObjectInfo() { - super(); - } - - /** - * Sets the number of bits per pixel - * - * @param bitsPerPixel the number of bits per pixel - */ - public void setBitsPerPixel(int bitsPerPixel) { - this.bitsPerPixel = bitsPerPixel; - } - - /** - * Sets if this image is color - * - * @param color true if this is a color image - */ - public void setColor(boolean color) { - this.color = color; - } - - /** - * Returns the number of bits used per pixel - * - * @return the number of bits used per pixel - */ - public int getBitsPerPixel() { - return bitsPerPixel; - } - - /** - * Returns true if this is a color image - * - * @return true if this is a color image - */ - public boolean isColor() { - return color; - } - - /** - * Returns true if this image uses compression - * - * @return true if this image uses compression - */ - public boolean hasCompression() { - return compression > -1; - } - - /** - * Returns the compression type - * - * @return the compression type - */ - public int getCompression() { - return compression; - } - - /** - * Sets the compression used with this image - * - * @param compression the type of compression used with this image - */ - public void setCompression(int compression) { - this.compression = compression; - } - - /** - * Sets the object data - * - * @param data the object data - */ - public void setData(byte[] data) { - this.data = data; - } - - /** - * Returns the object data - * - * @return the object data - */ - public byte[] getData() { - return this.data; - } - - /** {@inheritDoc} */ - public String toString() { - return "AFPImageObjectInfo{" + super.toString() - + ", compression=" + compression - + ", color=" + color - + ", bitsPerPixel=" + bitsPerPixel - + "}"; - } - -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/AFPImageRawStreamFactory.java b/src/java/org/apache/fop/render/afp/AFPImageRawStreamFactory.java index 172b67038..19504f6c9 100644 --- a/src/java/org/apache/fop/render/afp/AFPImageRawStreamFactory.java +++ b/src/java/org/apache/fop/render/afp/AFPImageRawStreamFactory.java @@ -22,6 +22,10 @@ package org.apache.fop.render.afp; import java.io.IOException; import java.io.InputStream; +import org.apache.fop.afp.AFPDataObjectInfo; +import org.apache.fop.afp.AFPObjectAreaInfo; +import org.apache.fop.afp.AFPState; +import org.apache.xmlgraphics.image.loader.ImageInfo; import org.apache.xmlgraphics.image.loader.impl.ImageRawStream; /** @@ -39,13 +43,14 @@ public class AFPImageRawStreamFactory extends AFPDataObjectInfoFactory { } /** {@inheritDoc} */ - public AFPDataObjectInfo create(AFPImageInfo afpImageInfo) throws IOException { - AFPDataObjectInfo dataObjectInfo = super.create(afpImageInfo); - String mimeType = afpImageInfo.info.getMimeType(); + public AFPDataObjectInfo create(AFPRendererImageInfo rendererImageInfo) throws IOException { + AFPDataObjectInfo dataObjectInfo = super.create(rendererImageInfo); + ImageInfo imageInfo = rendererImageInfo.getImageInfo(); + String mimeType = imageInfo.getMimeType(); if (mimeType != null) { dataObjectInfo.setMimeType(mimeType); } - ImageRawStream rawStream = (ImageRawStream) afpImageInfo.img; + ImageRawStream rawStream = (ImageRawStream) rendererImageInfo.getImage(); int resolution = state.getResolution(); AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo(); diff --git a/src/java/org/apache/fop/render/afp/AFPImageRenderedFactory.java b/src/java/org/apache/fop/render/afp/AFPImageRenderedFactory.java index b3ffe31db..9c59e8b83 100644 --- a/src/java/org/apache/fop/render/afp/AFPImageRenderedFactory.java +++ b/src/java/org/apache/fop/render/afp/AFPImageRenderedFactory.java @@ -23,9 +23,13 @@ import java.awt.image.RenderedImage; import java.io.IOException; import org.apache.commons.io.output.ByteArrayOutputStream; -import org.apache.fop.apps.MimeConstants; +import org.apache.fop.afp.AFPDataObjectInfo; +import org.apache.fop.afp.AFPImageObjectInfo; +import org.apache.fop.afp.AFPObjectAreaInfo; +import org.apache.fop.afp.AFPState; import org.apache.xmlgraphics.image.loader.impl.ImageRendered; import org.apache.xmlgraphics.ps.ImageEncodingHelper; +import org.apache.xmlgraphics.util.MimeConstants; /** * A buffered image data object info factory @@ -42,9 +46,9 @@ public class AFPImageRenderedFactory extends AFPDataObjectInfoFactory { } /** {@inheritDoc} */ - public AFPDataObjectInfo create(AFPImageInfo afpImageInfo) throws IOException { + public AFPDataObjectInfo create(AFPRendererImageInfo rendererImageInfo) throws IOException { AFPImageObjectInfo imageObjectInfo - = (AFPImageObjectInfo)super.create(afpImageInfo); + = (AFPImageObjectInfo)super.create(rendererImageInfo); imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS45); @@ -53,7 +57,7 @@ public class AFPImageRenderedFactory extends AFPDataObjectInfoFactory { objectAreaInfo.setWidthRes(resolution); objectAreaInfo.setHeightRes(resolution); - ImageRendered imageRendered = (ImageRendered) afpImageInfo.img; + ImageRendered imageRendered = (ImageRendered) rendererImageInfo.img; RenderedImage renderedImage = imageRendered.getRenderedImage(); int dataHeight = renderedImage.getHeight(); diff --git a/src/java/org/apache/fop/render/afp/AFPInfo.java b/src/java/org/apache/fop/render/afp/AFPInfo.java index 73bbb24a3..5fd59c2aa 100644 --- a/src/java/org/apache/fop/render/afp/AFPInfo.java +++ b/src/java/org/apache/fop/render/afp/AFPInfo.java @@ -20,6 +20,9 @@ package org.apache.fop.render.afp; import org.apache.avalon.framework.configuration.Configuration; +import org.apache.fop.afp.AFPResourceInfo; +import org.apache.fop.afp.AFPResourceManager; +import org.apache.fop.afp.AFPState; import org.apache.fop.fonts.FontInfo; /** diff --git a/src/java/org/apache/fop/render/afp/AFPLineDataInfo.java b/src/java/org/apache/fop/render/afp/AFPLineDataInfo.java deleted file mode 100644 index 618cf21ae..000000000 --- a/src/java/org/apache/fop/render/afp/AFPLineDataInfo.java +++ /dev/null @@ -1,192 +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.render.afp; - -import java.awt.Color; - -/** Line data information */ -public class AFPLineDataInfo { - - /** the x1 coordinate */ - int x1; - - /** the y1 coordinate */ - int y1; - - /** the x2 coordinate */ - int x2; - - /** the y2 coordinate */ - int y2; - - /** the thickness */ - int thickness; - - /** the painting color */ - Color color; - - /** the rotation */ - int rotation = 0; - - /** - * Default constructor - */ - public AFPLineDataInfo() { - } - - /** - * Returns the X1 coordinate - * - * @return the X1 coordinate - */ - public int getX1() { - return x1; - } - - /** - * Sets the X1 coordinate - * - * @param x1 the X1 coordinate - */ - public void setX1(int x1) { - this.x1 = x1; - } - - /** - * Returns the Y1 coordinate - * - * @return the Y1 coordinate - */ - public int getY1() { - return y1; - } - - /** - * Sets the Y1 coordinate - * - * @param y1 the Y1 coordinate - */ - public void setY1(int y1) { - this.y1 = y1; - } - - /** - * Returns the X2 coordinate - * - * @return the X2 coordinate - */ - public int getX2() { - return x2; - } - - /** - * Sets the X2 coordinate - * - * @param x2 the X2 coordinate - */ - public void setX2(int x2) { - this.x2 = x2; - } - - /** - * Returns the Y2 coordinate - * - * @return the Y2 coordinate - */ - public int getY2() { - return y2; - } - - /** - * Sets the Y2 coordinate - * - * @param y2 the Y2 coordinate - */ - public void setY2(int y2) { - this.y2 = y2; - } - - /** - * Returns the line thickness - * - * @return the line thickness - */ - public int getThickness() { - return thickness; - } - - /** - * Sets the line thickness - * - * @param thickness the line thickness - */ - public void setThickness(int thickness) { - this.thickness = thickness; - } - - /** - * Returns line color - * - * @return the line color - */ - public Color getColor() { - return color; - } - - /** - * Sets the line color - * - * @param color the line color - */ - public void setColor(Color color) { - this.color = color; - } - - /** - * Returns line rotation - * - * @return the line rotation - */ - public int getRotation() { - return rotation; - } - - /** - * Sets the line rotation - * - * @param rotation the line rotation - */ - public void setRotation(int rotation) { - this.rotation = rotation; - } - - /** {@inheritDoc} */ - public String toString() { - return "AFPLineDataInfo{x1=" + x1 - + ", y1=" + y1 - + ", x2=" + x2 - + ", y2=" + y2 - + ", thickness=" + thickness - + ", color=" + color - + ", rotation=" + rotation - + "}"; - } - -} diff --git a/src/java/org/apache/fop/render/afp/AFPObjectAreaInfo.java b/src/java/org/apache/fop/render/afp/AFPObjectAreaInfo.java deleted file mode 100644 index 0a3cdef87..000000000 --- a/src/java/org/apache/fop/render/afp/AFPObjectAreaInfo.java +++ /dev/null @@ -1,172 +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.render.afp; - -/** - * A common class used to convey locations, - * dimensions and resolutions of data objects. - */ -public class AFPObjectAreaInfo { - private int x; - private int y; - private int width; - private int height; - private int widthRes; - private int heightRes; - private int rotation = 0; - - /** - * Sets the x position of the data object - * - * @param x the x position of the data object - */ - public void setX(int x) { - this.x = x; - } - - /** - * Sets the y position of the data object - * - * @param y the y position of the data object - */ - public void setY(int y) { - this.y = y; - } - - /** - * Sets the data object width - * - * @param width the width of the data object - */ - public void setWidth(int width) { - this.width = width; - } - - /** - * Sets the data object height - * - * @param height the height of the data object - */ - public void setHeight(int height) { - this.height = height; - } - - /** - * Sets the width resolution - * - * @param widthRes the width resolution - */ - public void setWidthRes(int widthRes) { - this.widthRes = widthRes; - } - - /** - * Sets the height resolution - * - * @param heightRes the height resolution - */ - public void setHeightRes(int heightRes) { - this.heightRes = heightRes; - } - - /** - * Returns the x coordinate of this data object - * - * @return the x coordinate of this data object - */ - public int getX() { - return x; - } - - /** - * Returns the y coordinate of this data object - * - * @return the y coordinate of this data object - */ - public int getY() { - return y; - } - - /** - * Returns the width of this data object - * - * @return the width of this data object - */ - public int getWidth() { - return width; - } - - /** - * Returns the height of this data object - * - * @return the height of this data object - */ - public int getHeight() { - return height; - } - - /** - * Returns the width resolution of this data object - * - * @return the width resolution of this data object - */ - public int getWidthRes() { - return widthRes; - } - - /** - * Returns the height resolution of this data object - * - * @return the height resolution of this data object - */ - public int getHeightRes() { - return heightRes; - } - - /** - * Returns the rotation of this data object - * - * @return the rotation of this data object - */ - public int getRotation() { - return rotation; - } - - /** - * Sets the data object rotation - * - * @param rotation the data object rotation - */ - public void setRotation(int rotation) { - this.rotation = rotation; - } - - /** {@inheritDoc} */ - public String toString() { - return "x=" + x - + ", y=" + y - + ", width=" + width - + ", height=" + height - + ", widthRes=" + widthRes - + ", heightRes=" + heightRes - + ", rotation=" + rotation; - } - -} diff --git a/src/java/org/apache/fop/render/afp/AFPPageFonts.java b/src/java/org/apache/fop/render/afp/AFPPageFonts.java deleted file mode 100644 index 1bcbbb51d..000000000 --- a/src/java/org/apache/fop/render/afp/AFPPageFonts.java +++ /dev/null @@ -1,65 +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.render.afp; - -import org.apache.fop.render.afp.fonts.AFPFont; - -/** - * Holds the current page fonts - */ -public class AFPPageFonts extends java.util.HashMap { - private static final long serialVersionUID = -4991896259427109041L; - - /** - * Default constructor - */ - public AFPPageFonts() { - super(); - } - - /** - * Parameterized constructor - * - * @param fonts an existing set of afp page fonts - */ - public AFPPageFonts(AFPPageFonts fonts) { - super(fonts); - } - - /** - * Registers a font on the current page and returns font attributes - * - * @param fontName the internal font name - * @param font the AFPFont - * @param fontSize the font point size - * @return newly registered AFPFontAttributes - */ - public AFPFontAttributes registerFont(String fontName, AFPFont font, int fontSize) { - String pageFontKey = fontName + "_" + fontSize; - AFPFontAttributes afpFontAttributes = (AFPFontAttributes)super.get(pageFontKey); - // Add to page font mapping if not already present - if (afpFontAttributes == null) { - afpFontAttributes = new AFPFontAttributes(fontName, font, fontSize); - super.put(pageFontKey, afpFontAttributes); - afpFontAttributes.setFontReference(super.size()); - } - return afpFontAttributes; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/AFPRawCCITTFaxFactory.java b/src/java/org/apache/fop/render/afp/AFPRawCCITTFaxFactory.java index 2f090b0ba..17aff9fc0 100644 --- a/src/java/org/apache/fop/render/afp/AFPRawCCITTFaxFactory.java +++ b/src/java/org/apache/fop/render/afp/AFPRawCCITTFaxFactory.java @@ -21,6 +21,10 @@ package org.apache.fop.render.afp; import java.io.IOException; +import org.apache.fop.afp.AFPDataObjectInfo; +import org.apache.fop.afp.AFPImageObjectInfo; +import org.apache.fop.afp.AFPObjectAreaInfo; +import org.apache.fop.afp.AFPState; import org.apache.xmlgraphics.image.loader.impl.ImageRawCCITTFax; /** @@ -38,10 +42,10 @@ public class AFPRawCCITTFaxFactory extends AFPDataObjectInfoFactory { } /** {@inheritDoc} */ - public AFPDataObjectInfo create(AFPImageInfo afpImageInfo) throws IOException { - AFPImageObjectInfo imageObjectInfo = (AFPImageObjectInfo)super.create(afpImageInfo); + public AFPDataObjectInfo create(AFPRendererImageInfo rendererImageInfo) throws IOException { + AFPImageObjectInfo imageObjectInfo = (AFPImageObjectInfo)super.create(rendererImageInfo); - ImageRawCCITTFax ccitt = (ImageRawCCITTFax) afpImageInfo.img; + ImageRawCCITTFax ccitt = (ImageRawCCITTFax) rendererImageInfo.img; imageObjectInfo.setCompression(ccitt.getCompression()); AFPObjectAreaInfo objectAreaInfo = imageObjectInfo.getObjectAreaInfo(); diff --git a/src/java/org/apache/fop/render/afp/AFPRectanglePainter.java b/src/java/org/apache/fop/render/afp/AFPRectanglePainter.java deleted file mode 100644 index 18f275459..000000000 --- a/src/java/org/apache/fop/render/afp/AFPRectanglePainter.java +++ /dev/null @@ -1,82 +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.render.afp; - -import java.awt.geom.AffineTransform; - -import org.apache.fop.render.afp.modca.DataStream; - -public class AFPRectanglePainter extends AbstractAFPPainter { - - /** - * Main constructor - * - * @param state the afp state - * @param dataStream the afp datastream - */ - public AFPRectanglePainter(AFPState state, DataStream dataStream) { - super(state, dataStream); - } - - /** {@inheritDoc} */ - public void paint(PaintInfo paintInfo) { - RectanglePaintInfo rectanglePaintInfo = (RectanglePaintInfo)paintInfo; - int pageWidth = dataStream.getCurrentPage().getWidth(); - int pageHeight = dataStream.getCurrentPage().getHeight(); - - AFPUnitConverter unitConv = state.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(); - - AFPLineDataInfo lineDataInfo = new AFPLineDataInfo(); - lineDataInfo.color = state.getColor(); - lineDataInfo.rotation = state.getRotation(); - lineDataInfo.thickness = Math.round(height); - - switch (lineDataInfo.rotation) { - case 0: - lineDataInfo.x1 = Math.round((float)at.getTranslateX() + x); - lineDataInfo.y1 = lineDataInfo.y2 = Math.round((float)at.getTranslateY() + y); - lineDataInfo.x2 = Math.round((float)at.getTranslateX() + x + width); - break; - case 90: - lineDataInfo.x1 = Math.round((float)at.getTranslateY() + x); - lineDataInfo.y1 = lineDataInfo.y2 - = pageWidth - Math.round((float)at.getTranslateX()) + Math.round(y); - lineDataInfo.x2 = Math.round(width + (float)at.getTranslateY() + x); - break; - case 180: - lineDataInfo.x1 = pageWidth - Math.round((float)at.getTranslateX() - x); - lineDataInfo.y1 = lineDataInfo.y2 = pageHeight - Math.round((float)at.getTranslateY() - y); - lineDataInfo.x2 = pageWidth - Math.round((float)at.getTranslateX() - x - width); - break; - case 270: - lineDataInfo.x1 = pageHeight - Math.round((float)at.getTranslateY() - x); - lineDataInfo.y1 = lineDataInfo.y2 = Math.round((float)at.getTranslateX() + y); - lineDataInfo.x2 = lineDataInfo.x1 + Math.round(width - x); - break; - } - dataStream.createLine(lineDataInfo); - } -} diff --git a/src/java/org/apache/fop/render/afp/AFPRenderer.java b/src/java/org/apache/fop/render/afp/AFPRenderer.java index 89ec9ad63..d0737ed70 100644 --- a/src/java/org/apache/fop/render/afp/AFPRenderer.java +++ b/src/java/org/apache/fop/render/afp/AFPRenderer.java @@ -33,6 +33,23 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import org.apache.fop.AbstractState; +import org.apache.fop.afp.AFPBorderPainter; +import org.apache.fop.afp.AFPConstants; +import org.apache.fop.afp.AFPDataObjectInfo; +import org.apache.fop.afp.AFPPageFonts; +import org.apache.fop.afp.AFPRectanglePainter; +import org.apache.fop.afp.AFPResourceManager; +import org.apache.fop.afp.AFPState; +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.fonts.AFPFont; +import org.apache.fop.afp.fonts.AFPFontAttributes; +import org.apache.fop.afp.fonts.AFPFontCollection; +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; import org.apache.fop.apps.MimeConstants; @@ -51,15 +68,10 @@ import org.apache.fop.fonts.FontCollection; import org.apache.fop.fonts.FontInfo; import org.apache.fop.fonts.FontManager; import org.apache.fop.render.AbstractPathOrientedRenderer; -import org.apache.fop.render.AbstractState; import org.apache.fop.render.Graphics2DAdapter; import org.apache.fop.render.RendererContext; import org.apache.fop.render.afp.extensions.AFPElementMapping; import org.apache.fop.render.afp.extensions.AFPPageSetup; -import org.apache.fop.render.afp.fonts.AFPFont; -import org.apache.fop.render.afp.fonts.AFPFontCollection; -import org.apache.fop.render.afp.modca.DataStream; -import org.apache.fop.render.afp.modca.PageObject; import org.apache.xmlgraphics.image.loader.ImageException; import org.apache.xmlgraphics.image.loader.ImageFlavor; import org.apache.xmlgraphics.image.loader.ImageInfo; @@ -423,8 +435,8 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { Point origin = new Point(currentIPPosition, currentBPPosition); AFPDataObjectInfoFactory factory = dataObjectInfoProvider.getFactory(img); if (factory != null) { - AFPImageInfo afpImageInfo - = new AFPImageInfo(uri, pos, origin, info, img, foreignAttributes); + AFPRendererImageInfo afpImageInfo + = new AFPRendererImageInfo(uri, pos, origin, info, img, foreignAttributes); if (factory instanceof AFPImageGraphics2DFactory) { RendererContext rendererContext = createRendererContext( x, y, posInt.width, posInt.height, foreignAttributes); diff --git a/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java b/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java index aba38af2f..6a59d27e3 100644 --- a/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java +++ b/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java @@ -24,6 +24,11 @@ import java.util.List; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; +import org.apache.fop.afp.fonts.AFPFontInfo; +import org.apache.fop.afp.fonts.CharacterSet; +import org.apache.fop.afp.fonts.FopCharacterSet; +import org.apache.fop.afp.fonts.OutlineFont; +import org.apache.fop.afp.fonts.RasterFont; import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.fonts.FontTriplet; @@ -31,11 +36,6 @@ import org.apache.fop.fonts.FontUtil; import org.apache.fop.fonts.Typeface; import org.apache.fop.render.PrintRendererConfigurator; import org.apache.fop.render.Renderer; -import org.apache.fop.render.afp.fonts.AFPFontInfo; -import org.apache.fop.render.afp.fonts.CharacterSet; -import org.apache.fop.render.afp.fonts.FopCharacterSet; -import org.apache.fop.render.afp.fonts.OutlineFont; -import org.apache.fop.render.afp.fonts.RasterFont; import org.apache.fop.util.LogUtil; /** diff --git a/src/java/org/apache/fop/render/afp/AFPRendererImageInfo.java b/src/java/org/apache/fop/render/afp/AFPRendererImageInfo.java new file mode 100644 index 000000000..d4a14d3c2 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/AFPRendererImageInfo.java @@ -0,0 +1,168 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.render.afp; + +import java.awt.Point; +import java.awt.geom.Rectangle2D; +import java.util.Map; + +import org.apache.fop.render.RendererContext; +import org.apache.xmlgraphics.image.loader.Image; +import org.apache.xmlgraphics.image.loader.ImageInfo; + +/** + * The AFP image information + */ +public class AFPRendererImageInfo { + + /** the image uri */ + protected final String uri; + + /** the current pos */ + protected final Rectangle2D pos; + + /** the origin */ + protected final Point origin; + + /** the foreign attributes */ + protected final Map foreignAttributes; + + /** the image info */ + protected final ImageInfo info; + + /** the image */ + protected final Image img; + + /** the AFP graphics 2d adapter */ + protected AFPGraphics2DAdapter g2dAdapter; + + /** the renderer context */ + protected RendererContext rendererContext; + + /** + * Main constructor + * + * @param uri the image uri + * @param pos the image content area + * @param origin the current position + * @param info the image info + * @param img the image + * @param foreignAttributes the foreign attributes + */ + public AFPRendererImageInfo(String uri, Rectangle2D pos, Point origin, + ImageInfo info, Image img, Map foreignAttributes) { + this.uri = uri; + this.pos = pos; + this.origin = origin; + this.info = info; + this.img = img; + this.foreignAttributes = foreignAttributes; + } + + /** + * Sets the renderer context + * + * @param rendererContext the renderer context + */ + public void setRendererContext(RendererContext rendererContext) { + this.rendererContext = rendererContext; + } + + /** + * Sets the graphics 2d adapter + * + * @param adapter the graphics 2d adapter + */ + public void setGraphics2DAdapter(AFPGraphics2DAdapter adapter) { + this.g2dAdapter = adapter; + } + + /** + * Returns the image info + * + * @return the image info + */ + public ImageInfo getImageInfo() { + return this.info; + } + + /** + * Returns the image + * + * @return the image + */ + public Image getImage() { + return this.img; + } + + /** + * Returns the graphics 2D adapter + * + * @return the graphics 2D adapter + */ + public AFPGraphics2DAdapter getGraphics2DAdapter() { + return this.g2dAdapter; + } + + /** + * Returns the renderer context + * + * @return the renderer context + */ + public RendererContext getRendererContext() { + return this.rendererContext; + } + + /** + * Return the foreign attributes + * @return the foreign attributes + */ + public Map getForeignAttributes() { + return this.foreignAttributes; + } + + /** + * Return the uri + * + * @return the uri + */ + public String getURI() { + return this.uri; + } + + /** + * Return the origin + * + * @return the origin + */ + public Point getOrigin() { + return this.origin; + } + + /** + * Return the position + * + * @return the position + */ + public Rectangle2D getPosition() { + return this.pos; + } + +} diff --git a/src/java/org/apache/fop/render/afp/AFPResourceInfo.java b/src/java/org/apache/fop/render/afp/AFPResourceInfo.java deleted file mode 100644 index f52a3cd0b..000000000 --- a/src/java/org/apache/fop/render/afp/AFPResourceInfo.java +++ /dev/null @@ -1,140 +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.render.afp; - -/** - * The level at which a resource is to reside in the AFP output - */ -public class AFPResourceInfo { - private static final AFPResourceLevel DEFAULT_LEVEL - = new AFPResourceLevel(AFPResourceLevel.PRINT_FILE); - - /** the uri of this resource */ - private String uri = null; - - /** the reference name of this resource */ - private String name = null; - - /** the resource level of this resource */ - private AFPResourceLevel level = DEFAULT_LEVEL; - - /** true when the resource level was changed */ - private boolean levelChanged = false; - - /** - * Sets the data object uri - * - * @param uri the data object uri - */ - public void setUri(String uri) { - this.uri = uri; - } - - /** - * Returns the uri of this data object - * - * @return the uri of this data object - */ - public String getUri() { - return uri; - } - - /** - * Sets the resource reference name - * - * @param resourceName the resource reference name - */ - public void setName(String resourceName) { - this.name = resourceName; - } - - /** - * Returns the resource reference name - * - * @return the resource reference name - */ - public String getName() { - return this.name; - } - - /** - * Returns the resource level - * - * @return the resource level - */ - public AFPResourceLevel getLevel() { - if (level == null) { - return DEFAULT_LEVEL; - } - return this.level; - } - - /** - * Sets the resource level - * - * @param resourceLevel the resource level - */ - public void setLevel(AFPResourceLevel resourceLevel) { - this.level = resourceLevel; - levelChanged = true; - } - - /** - * Returns true when the resource level was set - * - * @return true when the resource level was set - */ - public boolean levelChanged() { - return levelChanged; - } - - /** {@inheritDoc} */ - public String toString() { - return "AFPResourceInfo{uri=" + uri - + (name != null ? ", name=" + name : "") - + (level != null ? ", level=" + level : "") - + "}"; - - } - - /** {@inheritDoc} */ - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if ((obj == null) || !(obj instanceof AFPResourceInfo)) { - return false; - } - - AFPResourceInfo ri = (AFPResourceInfo)obj; - return (uri == ri.uri || uri != null && uri.equals(ri.uri)) - && (name == ri.name || name != null && name.equals(ri.name)) - && (level == ri.level || level != null && level.equals(ri.level)); - } - - /** {@inheritDoc} */ - public int hashCode() { - int hash = 7; - hash = 31 * hash + (null == uri ? 0 : uri.hashCode()); - hash = 31 * hash + (null == name ? 0 : name.hashCode()); - hash = 31 * hash + (null == level ? 0 : level.hashCode()); - return hash; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/AFPResourceLevel.java b/src/java/org/apache/fop/render/afp/AFPResourceLevel.java deleted file mode 100644 index 8dc1c2077..000000000 --- a/src/java/org/apache/fop/render/afp/AFPResourceLevel.java +++ /dev/null @@ -1,201 +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.render.afp; - -/** - * A resource level - */ -public class AFPResourceLevel { - - /** directly in page **/ - public static final int INLINE = 0; - - /** page level **/ - public static final int PAGE = 1; - - /** page group level **/ - public static final int PAGE_GROUP = 2; - - /** document level **/ - public static final int DOCUMENT = 3; - - /** print file level **/ - public static final int PRINT_FILE = 4; - - /** external level **/ - public static final int EXTERNAL = 5; - - private static final String NAME_INLINE = "inline"; - private static final String NAME_PAGE = "page"; - private static final String NAME_PAGE_GROUP = "page-group"; - private static final String NAME_DOCUMENT = "document"; - private static final String NAME_PRINT_FILE = "print-file"; - private static final String NAME_EXTERNAL = "external"; - - private static final String[] NAMES = new String[] { - NAME_INLINE, NAME_PAGE, NAME_PAGE_GROUP, NAME_DOCUMENT, NAME_PRINT_FILE, NAME_EXTERNAL - }; - - - /** where the resource will reside in the AFP output */ - private int level = PRINT_FILE; // default is print-file level - - /** the external resource group file path */ - private String extFilePath = null; - - /** - * Sets the resource placement level within the AFP output - * - * @param levelString the resource level (page, page-group, document, print-file or external) - * @return true if the resource level was successfully set - */ - public static AFPResourceLevel valueOf(String levelString) { - if (levelString != null) { - levelString = levelString.toLowerCase(); - AFPResourceLevel resourceLevel = null; - for (int i = 0; i < NAMES.length; i++) { - if (NAMES[i].equals(levelString)) { - resourceLevel = new AFPResourceLevel(i); - break; - } - } - return resourceLevel; - } - return null; - } - - /** - * Main constructor - * - * @param level the resource level - */ - public AFPResourceLevel(int level) { - setLevel(level); - } - - /** - * Sets the resource level - * - * @param level the resource level - */ - public void setLevel(int level) { - this.level = level; - } - - /** - * Returns true if this is at page level - * - * @return true if this is at page level - */ - public boolean isPage() { - return level == PAGE; - } - - /** - * Returns true if this is at page group level - * - * @return true if this is at page group level - */ - public boolean isPageGroup() { - return level == PAGE_GROUP; - } - - /** - * Returns true if this is at document level - * - * @return true if this is at document level - */ - public boolean isDocument() { - return level == DOCUMENT; - } - - /** - * Returns true if this is at external level - * - * @return true if this is at external level - */ - public boolean isExternal() { - return level == EXTERNAL; - } - - /** - * Returns true if this is at print-file level - * - * @return true if this is at print-file level - */ - public boolean isPrintFile() { - return level == PRINT_FILE; - } - - /** - * Returns true if this resource level is inline - * - * @return true if this resource level is inline - */ - public boolean isInline() { - return level == INLINE; - } - - /** - * Returns the destination file path of the external resource group file - * - * @return the destination file path of the external resource group file - */ - public String getExternalFilePath() { - return this.extFilePath; - } - - /** - * Sets the external destination of the resource - * - * @param filePath the external resource group file - */ - public void setExternalFilePath(String filePath) { - this.extFilePath = filePath; - } - - /** {@inheritDoc} */ - public String toString() { - return NAMES[level] + (isExternal() ? ", file=" + extFilePath : ""); - } - - /** {@inheritDoc} */ - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if ((obj == null) || !(obj instanceof AFPResourceLevel)) { - return false; - } - - AFPResourceLevel rl = (AFPResourceLevel)obj; - return (level == level) - && (extFilePath == rl.extFilePath - || extFilePath != null && extFilePath.equals(rl.extFilePath)); - } - - /** {@inheritDoc} */ - public int hashCode() { - int hash = 7; - hash = 31 * hash + level; - hash = 31 * hash + (null == extFilePath ? 0 : extFilePath.hashCode()); - return hash; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/AFPResourceManager.java b/src/java/org/apache/fop/render/afp/AFPResourceManager.java deleted file mode 100644 index 6acc2419c..000000000 --- a/src/java/org/apache/fop/render/afp/AFPResourceManager.java +++ /dev/null @@ -1,189 +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.render.afp; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.Map; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.fop.render.afp.modca.AbstractDataObject; -import org.apache.fop.render.afp.modca.AbstractNamedAFPObject; -import org.apache.fop.render.afp.modca.DataStream; -import org.apache.fop.render.afp.modca.Factory; -import org.apache.fop.render.afp.modca.IncludeObject; -import org.apache.fop.render.afp.modca.Registry; -import org.apache.fop.render.afp.modca.ResourceGroup; - -/** - * Manages the creation and storage of document resources - */ -public class AFPResourceManager { - /** Static logging instance */ - private static final Log log = LogFactory.getLog(AFPResourceManager.class); - - /** The AFP datastream (document tree) */ - private DataStream dataStream; - - /** Resource creation factory */ - private final Factory factory; - - private final AFPStreamer streamer; - - private final AFPDataObjectFactory dataObjectFactory; - - /** Maintain a reference count of instream objects for referencing purposes */ - private int instreamObjectCount = 0; - - /** a mapping of resourceInfo --> include name */ - private final Map/**/ includeNameMap - = new java.util.HashMap()/**/; - - /** - * Main constructor - */ - public AFPResourceManager() { - this.factory = new Factory(); - this.streamer = new AFPStreamer(factory); - this.dataObjectFactory = new AFPDataObjectFactory(factory); - } - - /** - * Sets the outputstream - * - * @param state the afp state - * @param outputStream the outputstream - */ - public void createDataStream(AFPState state, OutputStream outputStream) { - this.dataStream = streamer.createDataStream(state); - streamer.setOutputStream(outputStream); - } - - /** - * Returns the AFP DataStream - * - * @return the AFP DataStream - */ - public DataStream getDataStream() { - return this.dataStream; - } - - /** - * Tells the streamer to write - * - * @throws IOException thrown if an I/O exception of some sort has occurred. - */ - public void writeToStream() throws IOException { - streamer.close(); - } - - /** - * Sets the default resource group file path - * - * @param filePath the default resource group file path - */ - - public void setDefaultResourceGroupFilePath(String filePath) { - streamer.setDefaultResourceGroupFilePath(filePath); - } - - /** - * Creates a new data object in the AFP datastream - * - * @param dataObjectInfo the data object info - * - * @throws IOException thrown if an I/O exception of some sort has occurred. - */ - public void createObject(AFPDataObjectInfo dataObjectInfo) throws IOException { - AbstractNamedAFPObject namedObj = null; - - AFPResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); - String uri = resourceInfo.getUri(); - if (uri == null) { - uri = "/"; - } - // if this is an instream data object adjust the uri to ensure that its unique - if (uri.endsWith("/")) { - uri += "#" + (++instreamObjectCount); - resourceInfo.setUri(uri); - } - - String objectName = (String)includeNameMap.get(resourceInfo); - if (objectName == null) { - boolean useInclude = true; - Registry.ObjectType objectType = null; - - // new resource so create - if (dataObjectInfo instanceof AFPImageObjectInfo) { - AFPImageObjectInfo imageObjectInfo = (AFPImageObjectInfo)dataObjectInfo; - namedObj = dataObjectFactory.createImage(imageObjectInfo); - } else if (dataObjectInfo instanceof AFPGraphicsObjectInfo) { - AFPGraphicsObjectInfo graphicsObjectInfo = (AFPGraphicsObjectInfo)dataObjectInfo; - namedObj = dataObjectFactory.createGraphic(graphicsObjectInfo); - } else { - // natively embedded object - namedObj = dataObjectFactory.createObjectContainer(dataObjectInfo); - objectType = dataObjectInfo.getObjectType(); - useInclude = objectType != null && objectType.isIncludable(); - } - - // set data object viewport (i.e. position, rotation, dimension, resolution) - if (namedObj instanceof AbstractDataObject) { - AbstractDataObject dataObj = (AbstractDataObject)namedObj; - dataObj.setViewport(dataObjectInfo); - } - - AFPResourceLevel resourceLevel = resourceInfo.getLevel(); - ResourceGroup resourceGroup = streamer.getResourceGroup(resourceLevel); - useInclude &= resourceGroup != null; - if (useInclude) { - // if it is to reside within a resource group at print-file or external level - if (resourceLevel.isPrintFile() || resourceLevel.isExternal()) { - // wrap newly created data object in a resource object - namedObj = dataObjectFactory.createResource(namedObj, resourceInfo, objectType); - } - - // add data object into its resource group destination - resourceGroup.addObject(namedObj); - - // create the include object - objectName = namedObj.getName(); - IncludeObject includeObject - = dataObjectFactory.createInclude(objectName, dataObjectInfo); - - // add an include to the current page - dataStream.getCurrentPage().addObject(includeObject); - - // record mapping of resource info to data object resource name - includeNameMap.put(resourceInfo, objectName); - } else { - // not to be included so inline data object directly into the current page - dataStream.getCurrentPage().addObject(namedObj); - } - } else { - // an existing data resource so reference it by adding an include to the current page - IncludeObject includeObject - = dataObjectFactory.createInclude(objectName, dataObjectInfo); - dataStream.getCurrentPage().addObject(includeObject); - } - } - -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/AFPSVGHandler.java b/src/java/org/apache/fop/render/afp/AFPSVGHandler.java index b3632b70f..57837fb4f 100644 --- a/src/java/org/apache/fop/render/afp/AFPSVGHandler.java +++ b/src/java/org/apache/fop/render/afp/AFPSVGHandler.java @@ -32,6 +32,15 @@ import org.apache.batik.bridge.GVTBuilder; import org.apache.batik.dom.AbstractDocument; import org.apache.batik.dom.svg.SVGDOMImplementation; import org.apache.batik.gvt.GraphicsNode; +import org.apache.fop.afp.AFPForeignAttributeReader; +import org.apache.fop.afp.AFPGraphics2D; +import org.apache.fop.afp.AFPGraphicsObjectInfo; +import org.apache.fop.afp.AFPObjectAreaInfo; +import org.apache.fop.afp.AFPResourceInfo; +import org.apache.fop.afp.AFPResourceManager; +import org.apache.fop.afp.AFPState; +import org.apache.fop.afp.AFPTextHandler; +import org.apache.fop.afp.AFPUnitConverter; import org.apache.fop.fo.extensions.ExtensionElementMapping; import org.apache.fop.render.AbstractGenericSVGHandler; import org.apache.fop.render.Renderer; @@ -109,7 +118,6 @@ public class AFPSVGHandler extends AbstractGenericSVGHandler { protected void renderSVGDocument(final RendererContext context, final Document doc) throws IOException { - AFPRenderer renderer = (AFPRenderer)context.getRenderer(); AFPInfo afpInfo = getAFPInfo(context); // fallback paint as bitmap @@ -125,7 +133,7 @@ public class AFPSVGHandler extends AbstractGenericSVGHandler { } String uri = ((AbstractDocument)doc).getDocumentURI(); - AFPState state = (AFPState)renderer.getState(); + AFPState state = afpInfo.getState(); state.setImageUri(uri); // set the data object parameters @@ -160,8 +168,12 @@ public class AFPSVGHandler extends AbstractGenericSVGHandler { // Configure Graphics2D implementation final boolean textAsShapes = false; AFPGraphics2D g2d = new AFPGraphics2D(textAsShapes); + + g2d.setResourceManager(afpInfo.getResourceManager()); + g2d.setResourceInfo(afpInfo.getResourceInfo()); + g2d.setState(afpInfo.getState()); g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext()); - g2d.setAFPInfo(afpInfo); + g2d.setFontInfo(afpInfo.getFontInfo()); // Configure GraphicsObjectPainter with the Graphics2D implementation AFPBatikGraphicsObjectPainter painter = new AFPBatikGraphicsObjectPainter(g2d); @@ -172,9 +184,9 @@ public class AFPSVGHandler extends AbstractGenericSVGHandler { = new SVGUserAgent(context.getUserAgent(), new AffineTransform()); BridgeContext ctx = new BridgeContext(svgUserAgent); if (!afpInfo.strokeText()) { - AFPTextHandler afpTextHandler = new AFPTextHandler(g2d); - g2d.setCustomTextHandler(afpTextHandler); - AFPTextPainter textPainter = new AFPTextPainter(afpTextHandler); + AFPTextHandler textHandler = new AFPTextHandler(g2d); + g2d.setCustomTextHandler(textHandler); + AFPTextPainter textPainter = new AFPTextPainter(textHandler); ctx.setTextPainter(textPainter); AFPTextElementBridge tBridge = new AFPTextElementBridge(textPainter); ctx.putBridge(tBridge); diff --git a/src/java/org/apache/fop/render/afp/AFPState.java b/src/java/org/apache/fop/render/afp/AFPState.java deleted file mode 100644 index 8209f3153..000000000 --- a/src/java/org/apache/fop/render/afp/AFPState.java +++ /dev/null @@ -1,511 +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.render.afp; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.fop.render.AbstractState; - -/** - * This keeps information about the current state when writing to an AFP datastream. - */ -public class AFPState extends org.apache.fop.render.AbstractState implements Cloneable { - - private static final long serialVersionUID = 8206711712452344473L; - - private static Log log = LogFactory.getLog("org.apache.fop.render.afp.AFPState"); - - /** the portrait rotation */ - private int portraitRotation = 0; - - /** the landscape rotation */ - private int landscapeRotation = 270; - - /** color image support */ - private boolean colorImages = false; - - /** images are supported in this AFP environment */ - private boolean nativeImages = false; - - /** default value for image depth */ - private int bitsPerPixel = 8; - - /** the output resolution */ - private int resolution = 240; // 240 dpi - - /** the current page */ - private AFPPageState pageState = new AFPPageState(); - -// /** reference orientation */ -// private int orientation = 0; - - /** a unit converter */ - private final transient AFPUnitConverter unitConv = new AFPUnitConverter(this); - - /** - * Sets the rotation to be used for portrait pages, valid values are 0 - * (default), 90, 180, 270. - * - * @param rotation - * The rotation in degrees. - */ - protected void setPortraitRotation(int rotation) { - if (rotation == 0 || rotation == 90 || rotation == 180 - || rotation == 270) { - portraitRotation = rotation; - } else { - throw new IllegalArgumentException( - "The portrait rotation must be one" - + " of the values 0, 90, 180, 270"); - - } - } - - /** - * Returns the rotation to be used for portrait pages - * - * @return the rotation to be used for portrait pages - */ - protected int getPortraitRotation() { - return this.portraitRotation; - } - - /** - * Sets the rotation to be used for landscape pages, valid values are 0, 90, - * 180, 270 (default). - * - * @param rotation - * The rotation in degrees. - */ - protected void setLandscapeRotation(int rotation) { - if (rotation == 0 || rotation == 90 || rotation == 180 - || rotation == 270) { - landscapeRotation = rotation; - } else { - throw new IllegalArgumentException( - "The landscape rotation must be one" - + " of the values 0, 90, 180, 270"); - } - } - - /** - * Returns the landscape rotation - * - * @return the landscape rotation - */ - protected int getLandscapeRotation() { - return this.landscapeRotation; - } - - /** - * Sets the number of bits used per pixel - * - * @param bitsPerPixel - * number of bits per pixel - */ - public void setBitsPerPixel(int bitsPerPixel) { - switch (bitsPerPixel) { - case 1: - case 4: - case 8: - this.bitsPerPixel = bitsPerPixel; - break; - default: - log.warn("Invalid bits_per_pixel value, must be 1, 4 or 8."); - this.bitsPerPixel = 8; - break; - } - } - - /** - * Returns the number of bits per pixel - * - * @return the number of bits per pixel - */ - public int getBitsPerPixel() { - return this.bitsPerPixel; - } - - /** - * Sets whether images are color or not - * - * @param colorImages - * color image output - */ - public void setColorImages(boolean colorImages) { - this.colorImages = colorImages; - } - - /** - * Returns true if color images are to be used - * - * @return true if color images are to be used - */ - protected boolean isColorImages() { - return this.colorImages; - } - - /** - * Sets whether images are natively supported or not in the AFP environment - * - * @param nativeImages true if images are natively supported in this AFP environment - */ - public void setNativeImages(boolean nativeImages) { - this.nativeImages = nativeImages; - } - - /** - * Returns true if images are supported natively in this AFP environment - * - * @return true if images are supported natively in this AFP environment - */ - protected boolean isNativeImages() { - return this.nativeImages; - } - - /** - * Sets the output/device resolution - * - * @param resolution - * the output resolution (dpi) - */ - public void setResolution(int resolution) { - if (log.isDebugEnabled()) { - log.debug("renderer-resolution set to: " + resolution + "dpi"); - } - this.resolution = resolution; - } - - /** - * Returns the output/device resolution. - * - * @return the resolution in dpi - */ - protected int getResolution() { - return this.resolution; - } - - /** {@inheritDoc} */ - protected AbstractData instantiateData() { - return new AFPData(); - } - - /** {@inheritDoc} */ - protected AbstractState instantiateState() { - return new AFPState(); - } - - /** - * Returns the state of the current page - * - * @return the state of the current page - */ - protected AFPPageState getPageState() { - return this.pageState; - } - - /** - * Sets if the current painted shape is to be filled - * - * @param fill true if the current painted shape is to be filled - * @return true if the fill value has changed - */ - protected boolean setFill(boolean fill) { - if (fill != ((AFPData)getData()).filled) { - ((AFPData)getData()).filled = fill; - return true; - } - return false; - } - - /** - * Gets the current page fonts - * - * @return the current page fonts - */ - protected AFPPageFonts getPageFonts() { - return pageState.getFonts(); - } - - /** - * Increments and returns the page font count - * - * @return the page font count - */ - public int incrementPageFontCount() { - return pageState.incrementFontCount(); - } - - /** - * Sets the page width - * - * @param pageWidth the page width - */ - public void setPageWidth(int pageWidth) { - pageState.setWidth(pageWidth); - } - - /** - * Returns the page width - * - * @return the page width - */ - public int getPageWidth() { - return pageState.getWidth(); - } - - /** - * Sets the page height - * - * @param pageHeight the page height - */ - public void setPageHeight(int pageHeight) { - pageState.setHeight(pageHeight); - } - - /** - * Returns the page height - * - * @return the page height - */ - public int getPageHeight() { - return pageState.getHeight(); - } - - /** - * Returns the page rotation - * - * @return the page rotation - */ - public int getPageRotation() { - return pageState.getOrientation(); - } - - /** - * Sets the uri of the current image - * - * @param uri the uri of the current image - */ - protected void setImageUri(String uri) { - ((AFPData)getData()).imageUri = uri; - } - - /** - * Gets the uri of the current image - * - * @return the uri of the current image - */ - public String getImageUri() { - return ((AFPData)getData()).imageUri; - } - - /** - * Returns the currently derived rotation - * - * @return the currently derived rotation - */ - public int getRotation() { - return getData().getDerivedRotation(); - } - - /** - * Returns the unit converter - * - * @return the unit converter - */ - public AFPUnitConverter getUnitConverter() { - return this.unitConv; - } - - /** {@inheritDoc} */ - public Object clone() { - AFPState state = (AFPState)super.clone(); - state.pageState = (AFPPageState)this.pageState.clone(); - state.portraitRotation = this.portraitRotation; - state.landscapeRotation = this.landscapeRotation; - state.bitsPerPixel = this.bitsPerPixel; - state.colorImages = this.colorImages; - state.resolution = this.resolution; - return state; - } - - /** {@inheritDoc} */ - public String toString() { - return "AFPState{" + "portraitRotation=" + portraitRotation - + ", landscapeRotation=" + landscapeRotation - + ", colorImages=" + colorImages - + ", bitsPerPixel=" + bitsPerPixel - + ", resolution=" + resolution - + ", pageState=" + pageState - + super.toString() - + "}"; - } - - /** - * Page level state data - */ - private class AFPPageState implements Cloneable { - /** page width */ - private int width = 0; - - /** page height */ - private int height = 0; - - /** page fonts */ - private AFPPageFonts fonts = new AFPPageFonts(); - - /** page font count */ - private int fontCount = 0; - - /** page orientation */ - private int orientation = 0; - - /** - * Returns the page width - * - * @return the page width - */ - protected int getWidth() { - return width; - } - - /** - * Sets the page width - * - * @param width the page width - */ - protected void setWidth(int width) { - this.width = width; - } - - /** - * Returns the page height - * - * @return the page height - */ - protected int getHeight() { - return height; - } - - /** - * Sets the page height - * - * @param height the page height - */ - protected void setHeight(int height) { - this.height = height; - } - - /** - * Returns the page fonts - * - * @return the page fonts - */ - protected AFPPageFonts getFonts() { - return fonts; - } - - /** - * Sets the current page fonts - * - * @param fonts the current page fonts - */ - protected void setFonts(AFPPageFonts fonts) { - this.fonts = fonts; - } - - /** - * Increments and returns the current page font count - * - * @return increment and return the current page font count - */ - protected int incrementFontCount() { - return ++fontCount; - } - - /** - * Returns the current page orientation - * - * @return the current page orientation - */ - protected int getOrientation() { - return orientation; - } - - /** - * Sets the current page orientation - * - * @param orientation the current page orientation - */ - protected void setOrientation(int orientation) { - this.orientation = orientation; - } - - /** {@inheritDoc} */ - public Object clone() { - AFPPageState state = new AFPPageState(); - state.width = this.width; - state.height = this.height; - state.orientation = this.orientation; - state.fonts = new AFPPageFonts(this.fonts); - state.fontCount = this.fontCount; - return state; - } - - /** {@inheritDoc} */ - public String toString() { - return "AFPPageState{width=" + width - + ", height=" + height - + ", orientation=" + orientation - + ", fonts=" + fonts - + ", fontCount=" + fontCount - + "}"; - } - } - - /** - * Block level state data - */ - private class AFPData extends org.apache.fop.render.AbstractState.AbstractData { - private static final long serialVersionUID = -1789481244175275686L; - - /** The current fill status */ - private boolean filled = false; - - private String imageUri = null; - - /** {@inheritDoc} */ - public Object clone() { - AFPData obj = (AFPData)super.clone(); - obj.filled = this.filled; - obj.imageUri = this.imageUri; - return obj; - } - - /** {@inheritDoc} */ - public String toString() { - return "AFPData{" + super.toString() - + ", filled=" + filled - + ", imageUri=" + imageUri - + "}"; - } - } - -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/AFPStreamer.java b/src/java/org/apache/fop/render/afp/AFPStreamer.java deleted file mode 100644 index be68caab2..000000000 --- a/src/java/org/apache/fop/render/afp/AFPStreamer.java +++ /dev/null @@ -1,217 +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.render.afp; - -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.RandomAccessFile; -import java.util.Iterator; -import java.util.Map; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.fop.render.afp.modca.DataStream; -import org.apache.fop.render.afp.modca.Factory; -import org.apache.fop.render.afp.modca.ResourceGroup; -import org.apache.fop.render.afp.modca.StreamedResourceGroup; - -/** - * Manages the streaming of the AFP output - */ -public class AFPStreamer implements Streamable { - /** Static logging instance */ - private static final Log log = LogFactory.getLog(AFPStreamer.class); - - private static final String AFPDATASTREAM_TEMP_FILE_PREFIX = "AFPDataStream_"; - - private static final int BUFFER_SIZE = 4096; - - private static final String DEFAULT_EXTERNAL_RESOURCE_FILENAME = "resources.afp"; - - - private final Factory factory; - - /** A mapping of external resource destinations to resource groups */ - private final Map/**/pathResourceGroupMap - = new java.util.HashMap/**/(); - - private StreamedResourceGroup printFileResourceGroup; - - /** Sets the default resource group file path */ - private String defaultResourceGroupFilePath = DEFAULT_EXTERNAL_RESOURCE_FILENAME; - - private File tempFile; - - /** temporary document outputstream */ - private OutputStream documentOutputStream; - - /** the final outputstream */ - private OutputStream outputStream; - - private RandomAccessFile documentFile; - - private DataStream dataStream; - - /** - * Main constructor - * - * @param factory a factory - */ - public AFPStreamer(Factory factory) { - this.factory = factory; - } - - /** - * Creates a new DataStream - * @param state the afp state - * - * @return a new {@link DataStream} - */ - public DataStream createDataStream(AFPState state) { - try { - this.tempFile = File.createTempFile(AFPDATASTREAM_TEMP_FILE_PREFIX, null); - this.documentFile = new RandomAccessFile(tempFile, "rw"); - this.documentOutputStream = new BufferedOutputStream( - new FileOutputStream(documentFile.getFD())); - this.dataStream = factory.createDataStream(state, documentOutputStream); - } catch (IOException e) { - log.error(e.getMessage()); - } - return dataStream; - } - - /** - * Sets the default resource group file path - * - * @param filePath the default resource group file path - */ - public void setDefaultResourceGroupFilePath(String filePath) { - this.defaultResourceGroupFilePath = filePath; - } - - /** - * 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.isInline()) { // no resource group for inline level - return null; - } - if (level.isExternal()) { - String filePath = level.getExternalFilePath(); - if (filePath == null) { - log.warn("No file path provided for external resource, using default."); - filePath = defaultResourceGroupFilePath; - } - resourceGroup = (ResourceGroup)pathResourceGroupMap.get(filePath); - if (resourceGroup == null) { - OutputStream os = null; - try { - os = new BufferedOutputStream(new FileOutputStream(filePath)); - } catch (FileNotFoundException fnfe) { - log.error("Failed to create/open external resource group file '" - + filePath + "'"); - } finally { - if (os != null) { - resourceGroup = factory.createStreamedResourceGroup(os); - pathResourceGroupMap.put(filePath, resourceGroup); - } - } - } - } else if (level.isPrintFile()) { - if (printFileResourceGroup == null) { - // use final outputstream for print-file resource group - printFileResourceGroup = factory.createStreamedResourceGroup(outputStream); - } - resourceGroup = printFileResourceGroup; - } else { - // resource group in afp document datastream - resourceGroup = dataStream.getResourceGroup(level); - } - return resourceGroup; - } - - /** - * Closes off the AFP stream writing the document stream - * - * @throws IOException if an an I/O exception of some sort has occurred - */ - public void close() throws IOException { - // write out any external resource groups - Iterator it = pathResourceGroupMap.entrySet().iterator(); - while (it.hasNext()) { - StreamedResourceGroup resourceGroup = (StreamedResourceGroup)it.next(); - resourceGroup.close(); - } - - // close any open print-file resource group - if (printFileResourceGroup != null) { - printFileResourceGroup.close(); - } - - // write out document - writeToStream(outputStream); - - outputStream.close(); - - // delete temporary file - tempFile.delete(); - } - - /** - * Sets the final outputstream - * - * @param outputStream an outputstream - */ - public void setOutputStream(OutputStream outputStream) { - this.outputStream = outputStream; - } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - int len = (int)documentFile.length(); - int numChunks = len / BUFFER_SIZE; - int remainingChunkSize = len % BUFFER_SIZE; - byte[] buffer; - - documentFile.seek(0); - if (numChunks > 0) { - buffer = new byte[BUFFER_SIZE]; - for (int i = 0; i < numChunks; i++) { - documentFile.read(buffer, 0, BUFFER_SIZE); - os.write(buffer, 0, BUFFER_SIZE); - } - } else { - buffer = new byte[remainingChunkSize]; - } - if (remainingChunkSize > 0) { - documentFile.read(buffer, 0, remainingChunkSize); - os.write(buffer, 0, remainingChunkSize); - } - os.flush(); - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/AFPTextDataInfo.java b/src/java/org/apache/fop/render/afp/AFPTextDataInfo.java deleted file mode 100644 index 7cc90c589..000000000 --- a/src/java/org/apache/fop/render/afp/AFPTextDataInfo.java +++ /dev/null @@ -1,202 +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.render.afp; - -import java.awt.Color; - -/** - * Text data information - */ -public class AFPTextDataInfo { - - private int fontReference; - - private int x; - - private int y; - - private Color color; - - private int variableSpaceCharacterIncrement; - - private int interCharacterAdjustment; - - private byte[] data; - - private int rotation; - - /** - * Returns the font reference - * - * @return the font reference - */ - public int getFontReference() { - return fontReference; - } - - /** - * Sets the font reference - * - * @param fontReference the font reference - */ - protected void setFontReference(int fontReference) { - this.fontReference = fontReference; - } - - /** - * Returns the x coordinate - * - * @return the x coordinate - */ - public int getX() { - return x; - } - - /** - * Sets the X coordinate - * - * @param x the X coordinate - */ - public void setX(int x) { - this.x = x; - } - - /** - * Returns the y coordinate - * - * @return the y coordinate - */ - public int getY() { - return y; - } - - /** - * Sets the Y coordinate - * - * @param y the Y coordinate - */ - public void setY(int y) { - this.y = y; - } - - /** - * Returns the color - * - * @return the color - */ - public Color getColor() { - return color; - } - - /** - * Sets the color - * - * @param color the color - */ - protected void setColor(Color color) { - this.color = color; - } - - /** - * Return the variable space character increment - * - * @return the variable space character increment - */ - public int getVariableSpaceCharacterIncrement() { - return variableSpaceCharacterIncrement; - } - - /** - * Sets the variable space character increment - * - * @param variableSpaceCharacterIncrement the variable space character increment - */ - protected void setVariableSpaceCharacterIncrement( - int variableSpaceCharacterIncrement) { - this.variableSpaceCharacterIncrement = variableSpaceCharacterIncrement; - } - - /** - * Return the inter character adjustment - * - * @return the inter character adjustment - */ - public int getInterCharacterAdjustment() { - return interCharacterAdjustment; - } - - /** - * Sets the inter character adjustment - * - * @param interCharacterAdjustment the inter character adjustment - */ - protected void setInterCharacterAdjustment(int interCharacterAdjustment) { - this.interCharacterAdjustment = interCharacterAdjustment; - } - - /** - * Return the text data - * - * @return the text data - */ - public byte[] getData() { - return data; - } - - /** - * Sets the text data - * - * @param data the text orientation - */ - protected void setData(byte[] data) { - this.data = data; - } - - /** - * Sets the text orientation - * - * @param rotation the text rotation - */ - public void setRotation(int rotation) { - this.rotation = rotation; - } - - /** - * Returns the text rotation - * - * @return the text rotation - */ - public int getRotation() { - return this.rotation; - } - - /** {@inheritDoc} */ - public String toString() { - return "TextDataInfo{fontReference=" + fontReference - + ", x=" + x - + ", y=" + y - + ", color=" + color - + ", vsci=" + variableSpaceCharacterIncrement - + ", ica=" + interCharacterAdjustment - + ", orientation=" + rotation - + ", data=" + data - + "}"; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/AFPTextHandler.java b/src/java/org/apache/fop/render/afp/AFPTextHandler.java deleted file mode 100644 index 0bd36b3e6..000000000 --- a/src/java/org/apache/fop/render/afp/AFPTextHandler.java +++ /dev/null @@ -1,105 +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.render.afp; - -import java.awt.Color; -import java.io.IOException; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.fop.fonts.Font; -import org.apache.fop.fonts.FontInfo; -import org.apache.fop.render.afp.fonts.AFPFont; -import org.apache.fop.render.afp.modca.GraphicsObject; -import org.apache.xmlgraphics.java2d.TextHandler; - -/** - * Specialized TextHandler implementation that the AFPGraphics2D class delegates to to paint text - * using AFP GOCA text operations. - */ -public class AFPTextHandler implements TextHandler { - - /** logging instance */ - private static Log log = LogFactory.getLog(AFPTextHandler.class); - - private AFPGraphics2D g2d = null; - - /** Overriding FontState */ - protected Font overrideFont = null; - - /** current state */ - private AFPState state = null; - - /** - * Main constructor. - * @param g2d the PSGraphics2D instance this instances is used by - */ - public AFPTextHandler(AFPGraphics2D g2d) { - this.g2d = g2d; - this.state = g2d.getAFPInfo().getState(); - } - - /** - * Return the font information associated with this object - * @return the FontInfo object - */ - public FontInfo getFontInfo() { - return g2d.getAFPInfo().getFontInfo(); - } - - /** - * Add a text string to the current data object of the AFP datastream. - * The text is painted using text operations. - * {@inheritDoc} - */ - public void drawString(String str, float x, float y) throws IOException { - log.debug("drawString() str=" + str + ", x=" + x + ", y=" + y); - GraphicsObject graphicsObj = g2d.getGraphicsObject(); - Color col = g2d.getColor(); - if (state.setColor(col)) { - graphicsObj.setColor(col); - } - if (overrideFont != null) { - FontInfo fontInfo = getFontInfo(); - AFPPageFonts pageFonts = state.getPageFonts(); - String internalFontName = overrideFont.getFontName(); - int fontSize = overrideFont.getFontSize(); - if (state.setFontName(internalFontName) || state.setFontSize(fontSize)) { - AFPFont font = (AFPFont)fontInfo.getFonts().get(internalFontName); - AFPFontAttributes afpFontAttributes = pageFonts.registerFont( - internalFontName, - font, - fontSize - ); - int fontReference = afpFontAttributes.getFontReference(); - graphicsObj.setCharacterSet(fontReference); - } - } - graphicsObj.addString(str, Math.round(x), Math.round(y)); - } - - /** - * Sets the overriding font. - * @param overrideFont Overriding Font to set - */ - public void setOverrideFont(Font overrideFont) { - this.overrideFont = overrideFont; - } -} diff --git a/src/java/org/apache/fop/render/afp/AFPTextPainter.java b/src/java/org/apache/fop/render/afp/AFPTextPainter.java index 3e908792d..7cc96d0cc 100644 --- a/src/java/org/apache/fop/render/afp/AFPTextPainter.java +++ b/src/java/org/apache/fop/render/afp/AFPTextPainter.java @@ -34,6 +34,11 @@ import java.util.Iterator; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.fop.afp.AFPGraphics2D; +import org.apache.fop.afp.AFPTextHandler; +import org.apache.fop.fonts.Font; +import org.apache.fop.fonts.FontInfo; +import org.apache.fop.fonts.FontTriplet; import org.apache.batik.dom.svg.SVGOMTextElement; import org.apache.batik.gvt.text.Mark; @@ -44,9 +49,6 @@ import org.apache.batik.gvt.text.TextPaintInfo; import org.apache.batik.gvt.font.GVTFontFamily; import org.apache.batik.gvt.renderer.StrokingTextPainter; -import org.apache.fop.fonts.Font; -import org.apache.fop.fonts.FontInfo; -import org.apache.fop.fonts.FontTriplet; /** * Renders the attributed character iterator of a TextNode. diff --git a/src/java/org/apache/fop/render/afp/AFPUnitConverter.java b/src/java/org/apache/fop/render/afp/AFPUnitConverter.java deleted file mode 100644 index 8a25bb604..000000000 --- a/src/java/org/apache/fop/render/afp/AFPUnitConverter.java +++ /dev/null @@ -1,120 +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.render.afp; - -import java.awt.geom.AffineTransform; - - -/** - * AFP Unit converter - */ -public class AFPUnitConverter { - - /** the AFP state */ - private final AFPState state; - - /** - * Unit converter - * - * @param state the AFP state - */ - public AFPUnitConverter(AFPState state) { - this.state = state; - } - - /** - * Converts millipoints to units - * - * @param srcPts source points - * @param dstPts destination points - * @return transformed points - */ - public int[] mpts2units(float[] srcPts, float[] dstPts) { - return transformPoints(srcPts, dstPts, true); - } - - /** - * Converts points to units - * - * @param srcPts source points - * @param dstPts destination points - * @return transformed points - */ - public int[] pts2units(float[] srcPts, float[] dstPts) { - return transformPoints(srcPts, dstPts, false); - } - - /** - * Converts millipoints to units - * - * @param srcPts source points - * @return transformed points - */ - public int[] mpts2units(float[] srcPts) { - return transformPoints(srcPts, null, true); - } - - /** - * Converts points to units - * - * @param srcPts source points - * @return transformed points - */ - public int[] pts2units(float[] srcPts) { - return transformPoints(srcPts, null, false); - } - - /** - * Converts point to unit - * - * @param pt point - * @return transformed point - */ - public float pt2units(float pt) { - return pt / ((float)AFPConstants.DPI_72 / state.getResolution()); - } - - /** - * Converts millipoint to unit - * - * @param mpt millipoint - * @return transformed point - */ - public float mpt2units(float mpt) { - return mpt / ((float)AFPConstants.DPI_72_MPTS / state.getResolution()); - } - - private int[] transformPoints(float[] srcPts, float[] dstPts, boolean milli) { - if (dstPts == null) { - dstPts = new float[srcPts.length]; - } - AffineTransform at = state.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++) { - if (!milli) { - dstPts[i] *= 1000; - } - coords[i] = Math.round(dstPts[i]); - } - return coords; - } - -} diff --git a/src/java/org/apache/fop/render/afp/AbstractAFPPainter.java b/src/java/org/apache/fop/render/afp/AbstractAFPPainter.java deleted file mode 100644 index ec148e5a4..000000000 --- a/src/java/org/apache/fop/render/afp/AbstractAFPPainter.java +++ /dev/null @@ -1,51 +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.render.afp; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.fop.render.afp.modca.DataStream; - -public abstract class AbstractAFPPainter { - - /** Static logging instance */ - protected static Log log = LogFactory.getLog("org.apache.fop.render.afp"); - - protected final DataStream dataStream; - protected final AFPState state; - - /** - * Main constructor - * - * @param state the afp state - * @param dataStream the afp datastream - */ - public AbstractAFPPainter(AFPState state, DataStream dataStream) { - this.state = state; - this.dataStream = dataStream; - } - - /** - * Paints the painting item - * - * @param paintInfo the painting information - */ - public abstract void paint(PaintInfo paintInfo); -} diff --git a/src/java/org/apache/fop/render/afp/BorderPaintInfo.java b/src/java/org/apache/fop/render/afp/BorderPaintInfo.java deleted file mode 100644 index 9ba7f29cf..000000000 --- a/src/java/org/apache/fop/render/afp/BorderPaintInfo.java +++ /dev/null @@ -1,120 +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.render.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/render/afp/PaintInfo.java b/src/java/org/apache/fop/render/afp/PaintInfo.java deleted file mode 100644 index 3225ef61d..000000000 --- a/src/java/org/apache/fop/render/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.render.afp; - -/** - * Generic painting information interface - */ -public interface PaintInfo { - -} diff --git a/src/java/org/apache/fop/render/afp/RectanglePaintInfo.java b/src/java/org/apache/fop/render/afp/RectanglePaintInfo.java deleted file mode 100644 index 9e4b3f2e7..000000000 --- a/src/java/org/apache/fop/render/afp/RectanglePaintInfo.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.render.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/render/afp/Streamable.java b/src/java/org/apache/fop/render/afp/Streamable.java deleted file mode 100644 index cb2cd1bda..000000000 --- a/src/java/org/apache/fop/render/afp/Streamable.java +++ /dev/null @@ -1,38 +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.render.afp; - -import java.io.IOException; -import java.io.OutputStream; - -/** - * Implementing object is able to write to an OutputStream - */ -public interface Streamable { - - /** - * DataStream objects must implement the writeToStream() - * method to write its data to the given OutputStream - * - * @param os the outputsteam stream - * @throws java.io.IOException an I/O exception of some sort has occurred. - */ - void writeToStream(OutputStream os) throws IOException; -} diff --git a/src/java/org/apache/fop/render/afp/exceptions/FontRuntimeException.java b/src/java/org/apache/fop/render/afp/exceptions/FontRuntimeException.java deleted file mode 100644 index a54e4ad67..000000000 --- a/src/java/org/apache/fop/render/afp/exceptions/FontRuntimeException.java +++ /dev/null @@ -1,46 +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.render.afp.exceptions; - -/** - * A runtime exception for handling fatal errors in processing fonts. - *

- */ -public class FontRuntimeException extends NestedRuntimeException { - - /** - * Constructs a FontRuntimeException with the specified message. - * @param msg the exception mesaage - */ - public FontRuntimeException(String msg) { - super(msg); - } - - /** - * Constructs a FontRuntimeException with the specified message - * wrapping the underlying exception. - * @param msg the exception mesaage - * @param t the underlying exception - */ - public FontRuntimeException(String msg, Throwable t) { - super(msg, t); - } - -} diff --git a/src/java/org/apache/fop/render/afp/fonts/AFPBase12FontCollection.java b/src/java/org/apache/fop/render/afp/fonts/AFPBase12FontCollection.java deleted file mode 100644 index 9157b9083..000000000 --- a/src/java/org/apache/fop/render/afp/fonts/AFPBase12FontCollection.java +++ /dev/null @@ -1,157 +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.render.afp.fonts; - -import org.apache.fop.fonts.Base14Font; -import org.apache.fop.fonts.Font; -import org.apache.fop.fonts.FontCollection; -import org.apache.fop.fonts.FontInfo; -import org.apache.fop.fonts.base14.Courier; -import org.apache.fop.fonts.base14.CourierBold; -import org.apache.fop.fonts.base14.CourierBoldOblique; -import org.apache.fop.fonts.base14.CourierOblique; -import org.apache.fop.fonts.base14.Helvetica; -import org.apache.fop.fonts.base14.HelveticaBold; -import org.apache.fop.fonts.base14.HelveticaOblique; -import org.apache.fop.fonts.base14.TimesBold; -import org.apache.fop.fonts.base14.TimesBoldItalic; -import org.apache.fop.fonts.base14.TimesItalic; -import org.apache.fop.fonts.base14.TimesRoman; - -/** - * Sets up a typical Base 12 font configuration for AFP - */ -public class AFPBase12FontCollection implements FontCollection { - - /** standard raster font sizes */ - private static final int[] RASTER_SIZES = {6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 24, 30, 36}; - - /** standard raster font charset references */ - private static final String[] CHARSET_REF = { - "60", "70", "80", "90", "00", "A0", "B0", "D0", "F0", "H0", "J0", "N0", "T0", "Z0"}; - - private void addCharacterSet(RasterFont font, String charsetName, Base14Font base14) { - for (int i = 0; i < RASTER_SIZES.length; i++) { - int size = RASTER_SIZES[i]; - FopCharacterSet characterSet = new FopCharacterSet( - CharacterSet.DEFAULT_CODEPAGE, CharacterSet.DEFAULT_ENCODING, - charsetName + CHARSET_REF[i], size, base14); - font.addCharacterSet(size, characterSet); - } - } - - private int addFontProperties(FontInfo fontInfo, AFPFont font, - String[] names, String style, int weight, int num) { - String internalFontKey = "F" + num; - fontInfo.addMetrics(internalFontKey, font); - fontInfo.addFontProperties(internalFontKey, names, style, weight); - num++; - return num; - } - - /** {@inheritDoc} */ - public int setup(int start, FontInfo fontInfo) { - - /** - * Add the base 12 fonts (Helvetica, Times and Courier) - * - * Note: this default font configuration may not be available - * on your AFP environment. - */ - int num = start; - RasterFont font = null; - - /** standard font family reference names for Helvetica font */ - final String[] helveticaNames = {"Helvetica", "Arial", "sans-serif"}; - font = new RasterFont("Helvetica"); - addCharacterSet(font, "C0H200", new Helvetica()); - num = addFontProperties(fontInfo, font, helveticaNames, - Font.STYLE_NORMAL, Font.WEIGHT_NORMAL, num); - - font = new RasterFont("Helvetica Italic"); - addCharacterSet(font, "C0H300", new HelveticaOblique()); - num = addFontProperties(fontInfo, font, helveticaNames, - Font.STYLE_ITALIC, Font.WEIGHT_NORMAL, num); - - font = new RasterFont("Helvetica (Semi) Bold"); - addCharacterSet(font, "C0H400", new HelveticaBold()); - num = addFontProperties(fontInfo, font, helveticaNames, - Font.STYLE_NORMAL, Font.WEIGHT_BOLD, num); - - font = new RasterFont("Helvetica Italic (Semi) Bold"); - addCharacterSet(font, "C0H500", new HelveticaOblique()); - num = addFontProperties(fontInfo, font, helveticaNames, - Font.STYLE_ITALIC, Font.WEIGHT_BOLD, num); - - - /** standard font family reference names for Times font */ - - /** any is treated as serif */ - final String[] timesNames = {"Times", "TimesRoman", "Times Roman", "Times-Roman", - "Times New Roman", "TimesNewRoman", "serif", "any"}; - - font = new RasterFont("Times Roman"); - addCharacterSet(font, "CON200", new TimesRoman()); - num = addFontProperties(fontInfo, font, timesNames, - Font.STYLE_NORMAL, Font.WEIGHT_NORMAL, num); - - font = new RasterFont("Times Roman Italic"); - addCharacterSet(font, "CON300", new TimesItalic()); - num = addFontProperties(fontInfo, font, timesNames, - Font.STYLE_ITALIC, Font.WEIGHT_NORMAL, num); - - font = new RasterFont("Times Roman Bold"); - addCharacterSet(font, "CON400", new TimesBold()); - num = addFontProperties(fontInfo, font, timesNames, - Font.STYLE_NORMAL, Font.WEIGHT_BOLD, num); - - font = new RasterFont("Times Roman Italic Bold"); - addCharacterSet(font, "CON500", new TimesBoldItalic()); - num = addFontProperties(fontInfo, font, timesNames, - Font.STYLE_ITALIC, Font.WEIGHT_BOLD, num); - - - /** standard font family reference names for Courier font */ - final String[] courierNames = {"Courier", "monospace"}; - - font = new RasterFont("Courier"); - addCharacterSet(font, "C04200", new Courier()); - num = addFontProperties(fontInfo, font, courierNames, - Font.STYLE_NORMAL, Font.WEIGHT_NORMAL, num); - - font = new RasterFont("Courier Italic"); - addCharacterSet(font, "C04300", new CourierOblique()); - num = addFontProperties(fontInfo, font, courierNames, - Font.STYLE_ITALIC, Font.WEIGHT_NORMAL, num); - - font = new RasterFont("Courier Bold"); - addCharacterSet(font, "C04400", new CourierBold()); - num = addFontProperties(fontInfo, font, courierNames, - Font.STYLE_NORMAL, Font.WEIGHT_BOLD, num); - - font = new RasterFont("Courier Italic Bold"); - addCharacterSet(font, "C04500", new CourierBoldOblique()); - num = addFontProperties(fontInfo, font, courierNames, - Font.STYLE_ITALIC, Font.WEIGHT_BOLD, num); - - return num; - } - -} diff --git a/src/java/org/apache/fop/render/afp/fonts/AFPFont.java b/src/java/org/apache/fop/render/afp/fonts/AFPFont.java deleted file mode 100644 index e87675e63..000000000 --- a/src/java/org/apache/fop/render/afp/fonts/AFPFont.java +++ /dev/null @@ -1,112 +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.render.afp.fonts; -import java.util.Map; -import java.util.Set; - -import org.apache.fop.fonts.FontType; -import org.apache.fop.fonts.Typeface; - - -/** - * All implementations of AFP fonts should extend this base class, - * the object implements the FontMetrics information. - *

- */ -public abstract class AFPFont extends Typeface { - - /** The font name */ - protected String name; - - /** - * Constructor for the base font requires the name. - * @param name the name of the font - */ - public AFPFont(String name) { - this.name = name; - } - - /** {@inheritDoc} */ - public String getFontName() { - return this.name; - } - - /** {@inheritDoc} */ - public String getEmbedFontName() { - return this.name; - } - - /** {@inheritDoc} */ - public String getFullName() { - return getFontName(); - } - - /** {@inheritDoc} */ - public Set getFamilyNames() { - Set s = new java.util.HashSet(); - s.add(this.name); - return s; - } - - /** - * Returns the type of the font. - * @return the font type - */ - public FontType getFontType() { - return FontType.OTHER; - } - - /** - * Indicates if the font has kerning information. - * @return True, if kerning is available. - */ - public boolean hasKerningInfo() { - return false; - } - - /** - * Returns the kerning map for the font. - * @return the kerning map - */ - public Map getKerningInfo() { - return null; - } - - /** - * Returns the character set for a given size - * @param size the font size - * @return the character set object - */ - public abstract CharacterSet getCharacterSet(int size); - - /** - * Determines whether this font contains a particular character/glyph. - * @param c character to check - * @return True if the character is supported, False otherwise - */ - public boolean hasChar(char c) { - return true; - } - - /** {@inheritDoc} */ - public String toString() { - return "name=" + name; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/fonts/AFPFontCollection.java b/src/java/org/apache/fop/render/afp/fonts/AFPFontCollection.java deleted file mode 100644 index 540ee3b49..000000000 --- a/src/java/org/apache/fop/render/afp/fonts/AFPFontCollection.java +++ /dev/null @@ -1,92 +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.render.afp.fonts; - -import java.util.Iterator; -import java.util.List; - -import org.apache.fop.events.EventBroadcaster; -import org.apache.fop.fonts.Font; -import org.apache.fop.fonts.FontCollection; -import org.apache.fop.fonts.FontInfo; -import org.apache.fop.fonts.FontTriplet; -import org.apache.fop.render.afp.AFPEventProducer; - -/** - * A base collection of AFP fonts - */ -public class AFPFontCollection implements FontCollection { - - private final EventBroadcaster eventBroadcaster; - - private final List/**/ fontInfoList; - - /** - * Main constructor - * - * @param eventBroadcaster the event broadcaster - * @param fontInfoList the font info list - */ - public AFPFontCollection(EventBroadcaster eventBroadcaster, - List/**/ fontInfoList) { - this.eventBroadcaster = eventBroadcaster; - this.fontInfoList = fontInfoList; - } - - /** {@inheritDoc} */ - public int setup(int start, FontInfo fontInfo) { - int num = 1; - AFPEventProducer eventProducer = AFPEventProducer.Provider.get(eventBroadcaster); - if (fontInfoList != null && fontInfoList.size() > 0) { - for (Iterator it = fontInfoList.iterator(); it.hasNext();) { - AFPFontInfo afpFontInfo = (AFPFontInfo)it.next(); - AFPFont afpFont = afpFontInfo.getAFPFont(); - List/**/ tripletList = afpFontInfo.getFontTriplets(); - for (Iterator it2 = tripletList.iterator(); it2.hasNext();) { - FontTriplet triplet = (FontTriplet)it2.next(); - fontInfo.addFontProperties("F" + num, - triplet.getName(), triplet.getStyle(), triplet.getWeight()); - fontInfo.addMetrics("F" + num, afpFont); - num++; - } - } - if (fontInfo.fontLookup("any", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL) == null) { - eventProducer.warnMissingDefaultFont(this, Font.STYLE_NORMAL, Font.WEIGHT_NORMAL); - } - if (fontInfo.fontLookup("any", Font.STYLE_ITALIC, Font.WEIGHT_NORMAL) == null) { - eventProducer.warnMissingDefaultFont(this, Font.STYLE_ITALIC, Font.WEIGHT_NORMAL); - } - if (fontInfo.fontLookup("any", Font.STYLE_NORMAL, Font.WEIGHT_BOLD) == null) { - eventProducer.warnMissingDefaultFont(this, Font.STYLE_ITALIC, Font.WEIGHT_BOLD); - } - if (fontInfo.fontLookup("any", Font.STYLE_ITALIC, Font.WEIGHT_BOLD) == null) { - eventProducer.warnMissingDefaultFont(this, Font.STYLE_ITALIC, Font.WEIGHT_BOLD); - } - } else { - eventProducer.warnDefaultFontSetup(this); - - // Go with a default base 12 configuration for AFP environments - FontCollection base12FontCollection = new AFPBase12FontCollection(); - num = base12FontCollection.setup(num, fontInfo); - } - return num; - } - -} diff --git a/src/java/org/apache/fop/render/afp/fonts/AFPFontInfo.java b/src/java/org/apache/fop/render/afp/fonts/AFPFontInfo.java deleted file mode 100644 index a70dce4b9..000000000 --- a/src/java/org/apache/fop/render/afp/fonts/AFPFontInfo.java +++ /dev/null @@ -1,62 +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.render.afp.fonts; - -import java.util.List; - -/** - * FontInfo contains meta information on fonts - */ -public class AFPFontInfo { - - private AFPFont font; - private List/**/ tripletList; - - /** - * Main constructor - * - * @param afpFont The AFP Font - * @param tripletList List of font triplets to associate with this font - */ - public AFPFontInfo(AFPFont afpFont, List/**/ tripletList) { - this.font = afpFont; - this.tripletList = tripletList; - } - - /** - * Returns the afp font - * - * @return the afp font - */ - public AFPFont getAFPFont() { - return font; - } - - /** - * Returns the list of font triplets associated with this font. - * - * @return List of font triplets - */ - public List/**/ getFontTriplets() { - return tripletList; - } - -} - diff --git a/src/java/org/apache/fop/render/afp/fonts/AFPFontReader.java b/src/java/org/apache/fop/render/afp/fonts/AFPFontReader.java deleted file mode 100644 index f72d23d47..000000000 --- a/src/java/org/apache/fop/render/afp/fonts/AFPFontReader.java +++ /dev/null @@ -1,591 +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.render.afp.fonts; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FilenameFilter; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.List; -import java.util.Map; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.fop.render.afp.tools.StructuredFieldReader; - -/** - * The AFPFontReader is responsible for reading the font attributes from binary - * code page files and the character set metric files. In IBM font structure, a - * code page maps each character of text to the characters in a character set. - * Each character is translated into a code point. When the character is - * printed, each code point is matched to a character ID on the code page - * specified. The character ID is then matched to the image (raster pattern or - * outline pattern) of the character in the character set specified. The image - * in the character set is the image that is printed in the document. To be a - * valid code page for a particular character set, all character IDs in the code - * page must be included in that character set.

This class will read the - * font information from the binary code page files and character set metric - * files in order to determine the correct metrics to use when rendering the - * formatted object.

- * - * @author Pete Townsend - */ -public final class AFPFontReader { - - /** - * Static logging instance - */ - protected static final Log log = LogFactory.getLog("org.apache.fop.render.afp.fonts"); - - /** - * Template used to convert lists to arrays. - */ - private static final CharacterSetOrientation[] EMPTY_CSO_ARRAY = new CharacterSetOrientation[0]; - - /** Codepage MO:DCA structured field. */ - private static final byte[] CODEPAGE_SF = new byte[] { - (byte) 0xD3, (byte) 0xA8, (byte) 0x87}; - - /** Character table MO:DCA structured field. */ - private static final byte[] CHARACTER_TABLE_SF = new byte[] { - (byte) 0xD3, (byte) 0x8C, (byte) 0x87}; - - /** Font control MO:DCA structured field. */ - private static final byte[] FONT_CONTROL_SF = new byte[] { - (byte) 0xD3, (byte) 0xA7, (byte) 0x89 }; - - /** Font orientation MO:DCA structured field. */ - private static final byte[] FONT_ORIENTATION_SF = new byte[] { - (byte) 0xD3, (byte) 0xAE, (byte) 0x89 }; - - /** Font position MO:DCA structured field. */ - private static final byte[] FONT_POSITION_SF = new byte[] { - (byte) 0xD3, (byte) 0xAC, (byte) 0x89 }; - - /** Font index MO:DCA structured field. */ - private static final byte[] FONT_INDEX_SF = new byte[] { - (byte) 0xD3, (byte) 0x8C, (byte) 0x89 }; - - /** - * The conversion factor to millipoints for 240 dpi - */ - private static final int FOP_100_DPI_FACTOR = 1; - - /** - * The conversion factor to millipoints for 240 dpi - */ - private static final int FOP_240_DPI_FACTOR = 300000; - - /** - * The conversion factor to millipoints for 300 dpi - */ - private static final int FOP_300_DPI_FACTOR = 240000; - - /** - * The encoding to use to convert from EBCIDIC to ASCII - */ - private static final String ASCII_ENCODING = "UTF8"; - - /** - * The collection of code pages - */ - private final Map/*>*/ codePages - = new java.util.HashMap/*>*/(); - - /** - * Returns an InputStream to a given file path and filename - * - * @param path the file path - * @param filename the file name - * @return an inputStream - * - * @throws IOException in the event that an I/O exception of some sort has occurred - */ - private InputStream openInputStream(String path, String filename) throws IOException { - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - if (classLoader == null) { - classLoader = AFPFontReader.class.getClassLoader(); - } - - URL url = classLoader.getResource(path); - - if (url == null) { - try { - File file = new File(path); - url = file.toURI().toURL(); - if (url == null) { - String msg = "file not found " + filename + " in classpath: " + path; - log.error(msg); - throw new FileNotFoundException(msg); - } - } catch (MalformedURLException ex) { - String msg = "file not found " + filename + " in classpath: " + path; - log.error(msg); - throw new FileNotFoundException(msg); - } - } - - File directory = new File(url.getPath()); - if (!directory.canRead()) { - String msg = "Failed to read directory " + url.getPath(); - log.error(msg); - throw new FileNotFoundException(msg); - } - - final String filterpattern = filename.trim(); - FilenameFilter filter = new FilenameFilter() { - public boolean accept(File dir, String name) { - return name.startsWith(filterpattern); - } - }; - - File[] files = directory.listFiles(filter); - - if (files.length < 1) { - String msg = "file search for " + filename + " located " - + files.length + " files"; - log.error(msg); - throw new FileNotFoundException(msg); - } else if (files.length > 1) { - String msg = "file search for " + filename + " located " - + files.length + " files"; - log.warn(msg); - } - - InputStream inputStream = files[0].toURI().toURL().openStream(); - - if (inputStream == null) { - String msg = "AFPFontReader:: getInputStream():: file not found for " + filename; - log.error(msg); - throw new FileNotFoundException(msg); - } - - return inputStream; - } - - /** - * Closes the inputstream - * - * @param inputStream the inputstream to close - */ - private void closeInputStream(InputStream inputStream) { - try { - if (inputStream != null) { - inputStream.close(); - } - } catch (Exception ex) { - // Lets log at least! - log.error(ex.getMessage()); - } - } - - /** - * Load the font details and metrics into the CharacterSetMetric object, - * this will use the actual afp code page and character set files to load - * the object with the necessary metrics. - * - * @param characterSet the CharacterSetMetric object to populate - * @throws IOException if an I/O exception of some sort has occurred. - */ - public void loadCharacterSetMetric(CharacterSet characterSet) throws IOException { - - InputStream inputStream = null; - - try { - - /** - * Get the code page which contains the character mapping - * information to map the unicode character id to the graphic - * chracter global identifier. - */ - String codePageId = new String(characterSet.getCodePage()); - String path = characterSet.getPath(); - - Map/**/ codePage = (Map/**/)codePages.get(codePageId); - - if (codePage == null) { - codePage = loadCodePage(codePageId, characterSet.getEncoding(), path); - codePages.put(codePageId, codePage); - } - - /** - * Load the character set metric information, no need to cache this - * information as it should be cached by the objects that wish to - * load character set metric information. - */ - final String characterSetName = characterSet.getName(); - - inputStream = openInputStream(path, characterSetName); - - StructuredFieldReader structuredFieldReader = new StructuredFieldReader(inputStream); - - // Process D3A789 Font Control - FontControl fontControl = processFontControl(structuredFieldReader); - - if (fontControl != null) { - //process D3AE89 Font Orientation - CharacterSetOrientation[] characterSetOrientations - = processFontOrientation(structuredFieldReader); - - int dpi = fontControl.getDpi(); - - //process D3AC89 Font Position - processFontPosition(structuredFieldReader, characterSetOrientations, dpi); - - //process D38C89 Font Index (per orientation) - for (int i = 0; i < characterSetOrientations.length; i++) { - processFontIndex(structuredFieldReader, - characterSetOrientations[i], codePage, dpi); - characterSet.addCharacterSetOrientation(characterSetOrientations[i]); - } - } else { - throw new IOException( - "Failed to read font control structured field in character set " - + characterSetName); - } - - } finally { - closeInputStream(inputStream); - } - - } - - /** - * Load the code page information from the appropriate file. The file name - * to load is determined by the code page name and the file extension 'CDP'. - * - * @param codePage - * the code page identifier - * @param encoding - * the encoding to use for the character decoding - * @returns a code page mapping - */ - private Map/**/ loadCodePage(String codePage, String encoding, - String path) throws IOException { - - // Create the HashMap to store code page information - Map/**/ codePages = new java.util.HashMap/**/(); - - InputStream inputStream = null; - try { - inputStream = openInputStream(path, codePage.trim()); - - StructuredFieldReader structuredFieldReader = new StructuredFieldReader(inputStream); - byte[] data = structuredFieldReader.getNext(CHARACTER_TABLE_SF); - - int position = 0; - byte[] gcgiBytes = new byte[8]; - byte[] charBytes = new byte[1]; - - // Read data, ignoring bytes 0 - 2 - for (int index = 3; index < data.length; index++) { - if (position < 8) { - // Build the graphic character global identifier key - gcgiBytes[position] = data[index]; - position++; - } else if (position == 9) { - position = 0; - // Set the character - charBytes[0] = data[index]; - String gcgiString = new String(gcgiBytes, - AFPConstants.EBCIDIC_ENCODING); - String charString = new String(charBytes, encoding); -// int value = charString.charAt(0); - codePages.put(gcgiString, charString); - } else { - position++; - } - } - } finally { - closeInputStream(inputStream); - } - - return codePages; - } - - /** - * Process the font control details using the structured field reader. - * - * @param structuredFieldReader - * the structured field reader - */ - private FontControl processFontControl(StructuredFieldReader structuredFieldReader) - throws IOException { - - byte[] fncData = structuredFieldReader.getNext(FONT_CONTROL_SF); - -// int position = 0; - FontControl fontControl = null; - if (fncData != null) { - fontControl = new FontControl(); - - if (fncData[7] == (byte) 0x02) { - fontControl.setRelative(true); - } - - int dpi = (((fncData[9] & 0xFF) << 8) + (fncData[10] & 0xFF)) / 10; - - fontControl.setDpi(dpi); - } - return fontControl; - } - - /** - * Process the font orientation details from using the structured field - * reader. - * - * @param structuredFieldReader - * the structured field reader - */ - private CharacterSetOrientation[] processFontOrientation( - StructuredFieldReader structuredFieldReader) throws IOException { - - byte[] data = structuredFieldReader.getNext(FONT_ORIENTATION_SF); - - int position = 0; - byte[] fnoData = new byte[26]; - - List orientations = new java.util.ArrayList(); - - // Read data, ignoring bytes 0 - 2 - for (int index = 3; index < data.length; index++) { - // Build the font orientation record - fnoData[position] = data[index]; - position++; - - if (position == 26) { - - position = 0; - - int orientation = 0; - - switch (fnoData[2]) { - case 0x00: - orientation = 0; - break; - case 0x2D: - orientation = 90; - break; - case 0x5A: - orientation = 180; - break; - case (byte) 0x87: - orientation = 270; - break; - default: - System.out.println("ERROR: Oriantation"); - } - - CharacterSetOrientation cso = new CharacterSetOrientation( - orientation); - orientations.add(cso); - - } - } - - return (CharacterSetOrientation[]) orientations - .toArray(EMPTY_CSO_ARRAY); - } - - /** - * Populate the CharacterSetOrientation object in the suplied array with the - * font position details using the supplied structured field reader. - * - * @param structuredFieldReader - * the structured field reader - * @param characterSetOrientations - * the array of CharacterSetOrientation objects - */ - private void processFontPosition(StructuredFieldReader structuredFieldReader, - CharacterSetOrientation[] characterSetOrientations, int dpi) throws IOException { - - byte[] data = structuredFieldReader.getNext(FONT_POSITION_SF); - - int position = 0; - byte[] fpData = new byte[26]; - - int characterSetOrientationIndex = 0; - int fopFactor = 0; - - switch (dpi) { - case 100: - fopFactor = FOP_100_DPI_FACTOR; - break; - case 240: - fopFactor = FOP_240_DPI_FACTOR; - break; - case 300: - fopFactor = FOP_300_DPI_FACTOR; - break; - default: - String msg = "Unsupported font resolution of " + dpi + " dpi."; - log.error(msg); - throw new IOException(msg); - } - - // Read data, ignoring bytes 0 - 2 - for (int index = 3; index < data.length; index++) { - if (position < 22) { - // Build the font orientation record - fpData[position] = data[index]; - } else if (position == 22) { - - position = 0; - - CharacterSetOrientation characterSetOrientation - = characterSetOrientations[characterSetOrientationIndex]; - - int xHeight = ((fpData[2] & 0xFF) << 8) + (fpData[3] & 0xFF); - int capHeight = ((fpData[4] & 0xFF) << 8) + (fpData[5] & 0xFF); - int ascHeight = ((fpData[6] & 0xFF) << 8) + (fpData[7] & 0xFF); - int dscHeight = ((fpData[8] & 0xFF) << 8) + (fpData[9] & 0xFF); - - dscHeight = dscHeight * -1; - - characterSetOrientation.setXHeight(xHeight * fopFactor); - characterSetOrientation.setCapHeight(capHeight * fopFactor); - characterSetOrientation.setAscender(ascHeight * fopFactor); - characterSetOrientation.setDescender(dscHeight * fopFactor); - - characterSetOrientationIndex++; - - fpData[position] = data[index]; - - } - - position++; - } - - } - - /** - * Process the font index details for the character set orientation. - * - * @param structuredFieldReader - * the structured field reader - * @param cso - * the CharacterSetOrientation object to populate - * @param codepage - * the map of code pages - */ - private void processFontIndex(StructuredFieldReader structuredFieldReader, - CharacterSetOrientation cso, Map/**/ codepage, int dpi) - throws IOException { - - byte[] data = structuredFieldReader.getNext(FONT_INDEX_SF); - - int fopFactor = 0; - - switch (dpi) { - case 100: - fopFactor = FOP_100_DPI_FACTOR; - break; - case 240: - fopFactor = FOP_240_DPI_FACTOR; - break; - case 300: - fopFactor = FOP_300_DPI_FACTOR; - break; - default: - String msg = "Unsupported font resolution of " + dpi + " dpi."; - log.error(msg); - throw new IOException(msg); - } - - int position = 0; - - byte[] gcgid = new byte[8]; - byte[] fiData = new byte[20]; - - int lowest = 255; - int highest = 0; - - // Read data, ignoring bytes 0 - 2 - for (int index = 3; index < data.length; index++) { - if (position < 8) { - gcgid[position] = data[index]; - position++; - } else if (position < 27) { - fiData[position - 8] = data[index]; - position++; - } else if (position == 27) { - - fiData[position - 8] = data[index]; - - position = 0; - - String gcgiString = new String(gcgid, AFPConstants.EBCIDIC_ENCODING); - - String idx = (String) codepage.get(gcgiString); - - if (idx != null) { - - int cidx = idx.charAt(0); - int width = ((fiData[0] & 0xFF) << 8) + (fiData[1] & 0xFF); - - if (cidx < lowest) { - lowest = cidx; - } - - if (cidx > highest) { - highest = cidx; - } - - int a = (width * fopFactor); - - cso.setWidth(cidx, a); - - } - - } - } - - cso.setFirstChar(lowest); - cso.setLastChar(highest); - - } - - private class FontControl { - - private int dpi; - - private boolean isRelative = false; - - public int getDpi() { - return dpi; - } - - public void setDpi(int i) { - dpi = i; - } - - public boolean isRelative() { - return isRelative; - } - - public void setRelative(boolean b) { - isRelative = b; - } - } - -} diff --git a/src/java/org/apache/fop/render/afp/fonts/CharacterSet.java b/src/java/org/apache/fop/render/afp/fonts/CharacterSet.java deleted file mode 100644 index fc0ab8b16..000000000 --- a/src/java/org/apache/fop/render/afp/fonts/CharacterSet.java +++ /dev/null @@ -1,318 +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.render.afp.fonts; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.util.Map; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.fop.render.afp.AFPConstants; -import org.apache.fop.render.afp.tools.StringUtils; - -/** - * The IBM Font Object Content Architecture (FOCA) supports presentation - * of character shapes by defining their characteristics, which include - * font description information for identifying the characters, font metric - * information for positioning the characters, and character shape information - * for presenting the character images. - *

- * Presenting a graphic character on a presentation surface requires - * information on the rotation and position of character on the physical - * or logical page. - *

- * This class proivdes font metric information for a particular font - * as identified by the character set name. This information is obtained - * directly from the AFP font files which must be installed in the path - * specified in the afp-fonts xml definition file. - *

- */ -public class CharacterSet { - - /** Static logging instance */ - protected static final Log log = LogFactory.getLog(CharacterSet.class.getName()); - - /** default codepage */ - protected static final String DEFAULT_CODEPAGE = "T1V10500"; - - /** default encoding */ - protected static final String DEFAULT_ENCODING = "Cp500"; - - private static final int MAX_NAME_LEN = 8; - - - /** The code page to which the character set relates */ - protected String codePage; - - /** The encoding used for the code page */ - protected String encoding; - - /** The character set relating to the font */ - protected String name; - - /** The path to the installed fonts */ - protected String path; - - /** Indicator as to whether to metrics have been loaded */ - private boolean isMetricsLoaded = false; - - /** The current orientation (currently only 0 is supported by FOP) */ - private final String currentOrientation = "0"; - - /** The collection of objects for each orientation */ - private Map characterSetOrientations = null; - - /** - * Constructor for the CharacterSetMetric object, the character set is used - * to load the font information from the actual AFP font. - * - * @param codePage the code page identifier - * @param encoding the encoding of the font - * @param name the character set name - * @param path the path to the installed afp fonts - */ - public CharacterSet(String codePage, String encoding, String name, String path) { - if (name.length() > MAX_NAME_LEN) { - String msg = "Character set name '" + name + "' must be a maximum of " - + MAX_NAME_LEN + " characters"; - log.error("Constructor:: " + msg); - throw new IllegalArgumentException(msg); - } - - if (name.length() < MAX_NAME_LEN) { - this.name = StringUtils.rpad(name, ' ', MAX_NAME_LEN); - } else { - this.name = name; - } - this.codePage = codePage; - this.encoding = encoding; - this.path = path; - - this.characterSetOrientations = new java.util.HashMap(4); - } - - /** - * Add character set metric information for the different orientations - * - * @param cso the metrics for the orientation - */ - public void addCharacterSetOrientation(CharacterSetOrientation cso) { - characterSetOrientations.put( - String.valueOf(cso.getOrientation()), - cso); - } - - /** - * Ascender height is the distance from the character baseline to the - * top of the character box. A negative ascender height signifies that - * all of the graphic character is below the character baseline. For - * a character rotation other than 0, ascender height loses its - * meaning when the character is lying on its side or is upside down - * with respect to normal viewing orientation. For the general case, - * Ascender Height is the characters most positive y-axis value. - * For bounded character boxes, for a given character having an - * ascender, ascender height and baseline offset are equal. - * - * @return the ascender value in millipoints - */ - public int getAscender() { - load(); - return getCharacterSetOrientation().getAscender(); - } - - /** - * Cap height is the average height of the uppercase characters in - * a font. This value is specified by the designer of a font and is - * usually the height of the uppercase M. - * - * @return the cap height value in millipoints - */ - public int getCapHeight() { - load(); - return getCharacterSetOrientation().getCapHeight(); - } - - /** - * Descender depth is the distance from the character baseline to - * the bottom of a character box. A negative descender depth signifies - * that all of the graphic character is above the character baseline. - * - * @return the descender value in millipoints - */ - public int getDescender() { - load(); - return getCharacterSetOrientation().getDescender(); - } - - /** - * Returns the first character in the character set - * - * @return the first character in the character set - */ - public int getFirstChar() { - load(); - return getCharacterSetOrientation().getFirstChar(); - } - - /** - * Returns the last character in the character set - * - * @return the last character in the character set - */ - public int getLastChar() { - load(); - return getCharacterSetOrientation().getLastChar(); - } - - /** - * Returns the path where the font resources are installed - * - * @return the path where the font resources are installed - */ - public String getPath() { - return path; - } - - /** - * Get the width (in 1/1000ths of a point size) of all characters - * - * @return the widths of all characters - */ - public int[] getWidths() { - load(); - return getCharacterSetOrientation().getWidths(); - } - - /** - * XHeight refers to the height of the lower case letters above the baseline. - * - * @return the typical height of characters - */ - public int getXHeight() { - load(); - return getCharacterSetOrientation().getXHeight(); - } - - /** - * Get the width (in 1/1000ths of a point size) of the character - * identified by the parameter passed. - * - * @param character the character from which the width will be calculated - * @return the width of the character - */ - public int getWidth(int character) { - load(); - return getCharacterSetOrientation().getWidth(character); - } - - /** - * Lazy creation of the character metrics, the afp font file will only - * be processed on a method call requiring the metric information. - */ - private void load() { - if (!isMetricsLoaded) { - AFPFontReader afpFontReader = new AFPFontReader(); - try { - afpFontReader.loadCharacterSetMetric(this); - isMetricsLoaded = true; - } catch (IOException e) { - String msg = "Failed to load the character set metrics for code page " + codePage; - log.error(msg); - throw new RuntimeException(e.getMessage()); - } - } - } - - /** - * Returns the AFP character set identifier - * - * @return the AFP character set identifier - */ - public String getName() { - return name; - } - - /** - * Returns the AFP character set identifier as a byte array - * - * @return the AFP character set identifier as a byte array - */ - public byte[] getNameBytes() { - byte[] nameBytes = null; - try { - nameBytes = name.getBytes(AFPConstants.EBCIDIC_ENCODING); - } catch (UnsupportedEncodingException usee) { - nameBytes = name.getBytes(); - log.warn( - "UnsupportedEncodingException translating the name " + name); - } - return nameBytes; - } - - /** - * Returns the AFP code page identifier - * - * @return the AFP code page identifier - */ - public String getCodePage() { - return codePage; - } - - /** - * Returns the AFP code page encoding - * - * @return the AFP code page encoding - */ - public String getEncoding() { - return encoding; - } - - /** - * Helper method to return the current CharacterSetOrientation, note - * that FOP does not yet implement the "reference-orientation" - * attribute therefore we always use the orientation zero degrees, - * Other orientation information is captured for use by a future - * implementation (whenever FOP implement the mechanism). This is also - * the case for landscape prints which use an orientation of 270 degrees, - * in 99.9% of cases the font metrics will be the same as the 0 degrees - * therefore the implementation currently will always use 0 degrees. - * - * @return characterSetOrentation The current orientation metrics. - */ - private CharacterSetOrientation getCharacterSetOrientation() { - CharacterSetOrientation c - = (CharacterSetOrientation) characterSetOrientations.get(currentOrientation); - return c; - } - - /** - * Map a Unicode character to a code point in the font. - * The code tables are already converted to Unicode therefore - * we can use the identity mapping. - * - * @param c character to map - * @return the mapped character - */ - public char mapChar(char c) { - return c; - } - -} diff --git a/src/java/org/apache/fop/render/afp/fonts/CharacterSetOrientation.java b/src/java/org/apache/fop/render/afp/fonts/CharacterSetOrientation.java deleted file mode 100644 index e13029717..000000000 --- a/src/java/org/apache/fop/render/afp/fonts/CharacterSetOrientation.java +++ /dev/null @@ -1,275 +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.render.afp.fonts; - -/** - * The IBM Font Object Content Architecture (FOCA) supports presentation - * of character shapes by defining their characteristics, which include - * Font-Description information for identifying the characters, Font-Metric - * information for positioning the characters, and Character-Shape - * information for presenting the character images. - * - * Presenting a graphic character on a presentation surface requires - * that you communicate this information clearly to rotate and position - * characters correctly on the physical or logical page. - * - * This class provides font metric information for a particular font - * as by the orientation. - * - * This information is obtained directly from the AFP font files which must - * be installed in the classpath under in the location specified by the path - * attribute in the afp-font.xml file. - *

- */ -public class CharacterSetOrientation { - - /** - * The code page to which the character set relates - */ - private String codePage; - - /** - * The encoding used for the code page - */ - private String encoding; - - /** - * The ascender height for the character set - */ - private int ascender; - - /** - * The descender depth for the character set - */ - private int descender; - - /** - * The height of capital letters - */ - private int capHeight; - - /** - * The characters in the charcater set - */ - private int[] chars = new int[256]; - - /** - * The height of lowercase letters - */ - private int xHeight; - - /** - * The first character - */ - private int firstChar; - - /** - * The last character - */ - private int lastChar; - - - /** - * The character set orientation - */ - private int orientation = 0; - - /** - * Constructor for the CharacterSetOrientation, the orientation is - * expressed as the degrees rotation (i.e 0, 90, 180, 270) - * @param orientation the character set orientation - */ - public CharacterSetOrientation(int orientation) { - this.orientation = orientation; - } - - /** - * Ascender height is the distance from the character baseline to the - * top of the character box. A negative ascender height signifies that - * all of the graphic character is below the character baseline. For - * a character rotation other than 0, ascender height loses its - * meaning when the character is lying on its side or is upside down - * with respect to normal viewing orientation. For the general case, - * Ascender Height is the character�s most positive y-axis value. - * For bounded character boxes, for a given character having an - * ascender, ascender height and baseline offset are equal. - * @return the ascender value in millipoints - */ - public int getAscender() { - return ascender; - } - - /** - * Cap height is the average height of the uppercase characters in - * a font. This value is specified by the designer of a font and is - * usually the height of the uppercase M. - * @return the cap height value in millipoints - */ - public int getCapHeight() { - return capHeight; - } - - /** - * Descender depth is the distance from the character baseline to - * the bottom of a character box. A negative descender depth signifies - * that all of the graphic character is above the character baseline. - * @return the descender value in millipoints - */ - public int getDescender() { - return descender; - } - - /** - * The first character in the character set - * @return the first character - */ - public int getFirstChar() { - return firstChar; - } - - /** - * The last character in the character set - * @return the last character - */ - public int getLastChar() { - return lastChar; - } - - /** - * The orientation for these metrics in the character set - * @return the orientation - */ - public int getOrientation() { - return orientation; - } - - /** - * Get the width (in 1/1000ths of a point size) of all characters - * in this character set. - * @return the widths of all characters - */ - public int[] getWidths() { - int arr[] = new int[(getLastChar() - getFirstChar()) + 1]; - System.arraycopy(chars, getFirstChar(), arr, 0, (getLastChar() - getFirstChar()) + 1); - return arr; - } - - /** - * XHeight refers to the height of the lower case letters above - * the baseline. - * @return heightX the typical height of characters - */ - public int getXHeight() { - return xHeight; - } - - /** - * Get the width (in 1/1000ths of a point size) of the character - * identified by the parameter passed. - * @param characterIndex the character to evaluate - * @return the widths of the character - */ - public int getWidth(int characterIndex) { - if (characterIndex >= chars.length) { - throw new IllegalArgumentException("Invalid character index: " - + characterIndex + ", maximum is " + (chars.length - 1)); - } - return chars[characterIndex]; - } - - /** - * Ascender height is the distance from the character baseline to the - * top of the character box. A negative ascender height signifies that - * all of the graphic character is below the character baseline. For - * a character rotation other than 0, ascender height loses its - * meaning when the character is lying on its side or is upside down - * with respect to normal viewing orientation. For the general case, - * Ascender Height is the character�s most positive y-axis value. - * For bounded character boxes, for a given character having an - * ascender, ascender height and baseline offset are equal. - * @param ascender the ascender to set - */ - public void setAscender(int ascender) { - this.ascender = ascender; - } - - /** - * Cap height is the average height of the uppercase characters in - * a font. This value is specified by the designer of a font and is - * usually the height of the uppercase M. - * @param capHeight the cap height to set - */ - public void setCapHeight(int capHeight) { - this.capHeight = capHeight; - } - - /** - * Descender depth is the distance from the character baseline to - * the bottom of a character box. A negative descender depth signifies - * that all of the graphic character is above the character baseline. - * @param descender the descender value in millipoints - */ - public void setDescender(int descender) { - this.descender = descender; - } - - /** - * The first character in the character set - * @param firstChar the first character - */ - public void setFirstChar(int firstChar) { - this.firstChar = firstChar; - } - - /** - * The last character in the character set - * @param lastChar the last character - */ - public void setLastChar(int lastChar) { - this.lastChar = lastChar; - } - - /** - * Set the width (in 1/1000ths of a point size) of the character - * identified by the parameter passed. - * @param character the character for which the width is being set - * @param width the widths of the character - */ - public void setWidth(int character, int width) { - - if (character >= chars.length) { - // Increase the size of the array if necessary - int arr[] = new int[(character - firstChar) + 1]; - System.arraycopy(chars, 0, arr, 0, chars.length); - chars = arr; - } - chars[character] = width; - - } - - /** - * XHeight refers to the height of the lower case letters above - * the baseline. - * @param xHeight the typical height of characters - */ - public void setXHeight(int xHeight) { - this.xHeight = xHeight; - } -} diff --git a/src/java/org/apache/fop/render/afp/fonts/FopCharacterSet.java b/src/java/org/apache/fop/render/afp/fonts/FopCharacterSet.java deleted file mode 100644 index d5beb5a33..000000000 --- a/src/java/org/apache/fop/render/afp/fonts/FopCharacterSet.java +++ /dev/null @@ -1,141 +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.render.afp.fonts; - -import org.apache.fop.fonts.Typeface; - -/** - * A Character set for a normal FOP font

- */ -public class FopCharacterSet extends CharacterSet { - - /** The character set for this font */ - private Typeface charSet = null; - private int size = 0; - - /** - * Constructor for the CharacterSetMetric object, the character set is used - * to load the font information from the actual AFP font. - * @param codePage the code page identifier - * @param encoding the encoding of the font - * @param name the character set name - * @param size the font size - * @param charSet the fop character set - */ - public FopCharacterSet( - String codePage, - String encoding, - String name, - int size, - Typeface charSet) { - - super(codePage, encoding, name, null); - this.charSet = charSet; - this.size = size * 1000; - } - - /** - * Ascender height is the distance from the character baseline to the - * top of the character box. A negative ascender height signifies that - * all of the graphic character is below the character baseline. For - * a character rotation other than 0, ascender height loses its - * meaning when the character is lying on its side or is upside down - * with respect to normal viewing orientation. For the general case, - * Ascender Height is the character�s most positive y-axis value. - * For bounded character boxes, for a given character having an - * ascender, ascender height and baseline offset are equal. - * @return the ascender value in millipoints - */ - public int getAscender() { - return charSet.getAscender(size); - } - - /** - * Cap height is the average height of the uppercase characters in - * a font. This value is specified by the designer of a font and is - * usually the height of the uppercase M. - * @return the cap height value in millipoints - */ - public int getCapHeight() { - return charSet.getCapHeight(size); - } - - /** - * Descender depth is the distance from the character baseline to - * the bottom of a character box. A negative descender depth signifies - * that all of the graphic character is above the character baseline. - * @return the descender value in millipoints - */ - public int getDescender() { - return charSet.getDescender(size); - } - - /** - * The first character in the character set - * @return the first character - */ - public int getFirstChar() { - return 0; - } - - /** - * The last character in the character set - * @return the last character - */ - public int getLastChar() { - return 0; - } - - /** - * Get the width (in 1/1000ths of a point size) of all characters - * @return the widths of all characters - */ - public int[] getWidths() { - return charSet.getWidths(); - } - - /** - * XHeight refers to the height of the lower case letters above the baseline. - * @return the typical height of characters - */ - public int getXHeight() { - return charSet.getXHeight(size); - } - - /** - * Get the width (in 1/1000ths of a point size) of the character - * identified by the parameter passed. - * @param character the character from which the width will be calculated - * @return the width of the character - */ - public int getWidth(int character) { - return charSet.getWidth(character, size); - } - - /** - * Map a Unicode character to a code point in the font. - * @param c character to map - * @return the mapped character - */ - public char mapChar(char c) { - return charSet.mapChar(c); - } - -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/fonts/OutlineFont.java b/src/java/org/apache/fop/render/afp/fonts/OutlineFont.java deleted file mode 100644 index 71c5dfb6f..000000000 --- a/src/java/org/apache/fop/render/afp/fonts/OutlineFont.java +++ /dev/null @@ -1,181 +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.render.afp.fonts; - -/** - * A font defined as a set of lines and curves as opposed to a bitmap font. An - * outline font can be scaled to any size and otherwise transformed more easily - * than a bitmap font, and with more attractive results.

- * - */ -public class OutlineFont extends AFPFont { - - /** The character set for this font */ - private CharacterSet charSet = null; - - /** - * Constructor for an outline font. - * - * @param name - * the name of the font - * @param charSet - * the chracter set - */ - public OutlineFont(String name, CharacterSet charSet) { - super(name); - this.charSet = charSet; - } - - /** - * Get the character set metrics. - * - * @return the character set - */ - public CharacterSet getCharacterSet() { - - return charSet; - - } - - /** - * Get the character set metrics. - * @param size ignored - * @return the character set - */ - public CharacterSet getCharacterSet(int size) { - - return charSet; - - } - - /** - * Get the first character in this font. - * @return the first character in this font - */ - public int getFirstChar() { - return charSet.getFirstChar(); - } - - /** - * Get the last character in this font. - * @return the last character in this font - */ - public int getLastChar() { - return charSet.getLastChar(); - } - - /** - * The ascender is the part of a lowercase letter that extends above the - * "x-height" (the height of the letter "x"), such as "d", "t", or "h". Also - * used to denote the part of the letter extending above the x-height. - * - * @param size - * the point size - * @return the ascender for the given size - */ - public int getAscender(int size) { - return charSet.getAscender() / 1000 * size; - } - - /** - * Obtains the height of capital letters for the specified point size. - * - * @param size - * the point size - * @return the cap height for the given size - */ - public int getCapHeight(int size) { - return charSet.getCapHeight() / 1000 * size; - } - - /** - * The descender is the part of a lowercase letter that extends below the - * base line, such as "g", "j", or "p". Also used to denote the part of the - * letter extending below the base line. - * - * @param size - * the point size - * @return the descender for the given size - */ - public int getDescender(int size) { - return charSet.getDescender() / 1000 * size; - } - - /** - * The "x-height" (the height of the letter "x"). - * - * @param size - * the point size - * @return the x height for the given size - */ - public int getXHeight(int size) { - return charSet.getXHeight() / 1000 * size; - } - - /** - * Obtain the width of the character for the specified point size. - * @param character the character - * @param size point size - * @return the width of the character for the specified point size - */ - public int getWidth(int character, int size) { - return charSet.getWidth(character) / 1000 * size; - } - - /** - * Get the getWidth (in 1/1000ths of a point size) of all characters in this - * character set. - * - * @param size - * the point size - * @return the widths of all characters - */ - public int[] getWidths(int size) { - int[] widths = charSet.getWidths(); - for (int i = 0; i < widths.length; i++) { - widths[i] = widths[i] / 1000 * size; - } - return widths; - } - - /** - * Get the getWidth (in 1/1000ths of a point size) of all characters in this - * character set. - * - * @return the widths of all characters - */ - public int[] getWidths() { - return getWidths(1000); - } - - /** - * Map a Unicode character to a code point in the font. - * @param c character to map - * @return the mapped character - */ - public char mapChar(char c) { - return charSet.mapChar(c); - } - - /** {@inheritDoc} */ - public String getEncodingName() { - return charSet.getEncoding(); - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/fonts/RasterFont.java b/src/java/org/apache/fop/render/afp/fonts/RasterFont.java deleted file mode 100644 index ee4bfba6c..000000000 --- a/src/java/org/apache/fop/render/afp/fonts/RasterFont.java +++ /dev/null @@ -1,237 +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.render.afp.fonts; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.fop.fo.properties.FixedLength; -import org.apache.fop.render.afp.exceptions.FontRuntimeException; - -/** - * A font where each character is stored as an array of pixels (a bitmap). Such - * fonts are not easily scalable, in contrast to vectored fonts. With this type - * of font, the font metrics information is held in character set files (one for - * each size and style).

- * - */ -public class RasterFont extends AFPFont { - - /** Static logging instance */ - protected static final Log log = LogFactory.getLog("org.apache.fop.render.afp.fonts"); - - private Map charSets = new HashMap(); - - private CharacterSet charSet = null; - - /** - * Constructor for the raster font requires the name, weight and style - * attribute to be available as this forms the key to the font. - * - * @param name - * the name of the font - */ - public RasterFont(String name) { - super(name); - } - - /** - * Adds the character set for the given point size - * @param size point size - * @param characterSet character set - */ - public void addCharacterSet(int size, CharacterSet characterSet) { - this.charSets.put(String.valueOf(size), characterSet); - this.charSet = characterSet; - } - - /** - * Get the character set metrics for the specified point size. - * - * @param size the point size - * @return the character set metrics - */ - public CharacterSet getCharacterSet(int size) { - - String pointsize = String.valueOf(size / 1000); - CharacterSet csm = (CharacterSet) charSets.get(pointsize); - if (csm == null) { - csm = (CharacterSet) charSets.get(size + FixedLength.MPT); - } - if (csm == null) { - // Get char set with nearest font size - int distance = Integer.MAX_VALUE; - for (Iterator it = charSets.entrySet().iterator(); it.hasNext();) { - Map.Entry me = (Map.Entry)it.next(); - String key = (String)me.getKey(); - if (!key.endsWith(FixedLength.MPT)) { - int mpt = Integer.parseInt(key) * 1000; - if (Math.abs(size - mpt) < distance) { - distance = Math.abs(size - mpt); - pointsize = (String)me.getKey(); - csm = (CharacterSet)me.getValue(); - } - } - } - if (csm != null) { - charSets.put(size + FixedLength.MPT, csm); - String msg = "No " + (size / 1000) + "pt font " + getFontName() - + " found, substituted with " + pointsize + "pt font"; - log.warn(msg); - } - } - if (csm == null) { - String msg = "No font found for font " + getFontName() - + " with point size " + pointsize; - log.error(msg); - throw new FontRuntimeException(msg); - } - return csm; - - } - - /** - * Get the first character in this font. - * @return the first character in this font. - */ - public int getFirstChar() { - Iterator it = charSets.values().iterator(); - if (it.hasNext()) { - CharacterSet csm = (CharacterSet) it.next(); - return csm.getFirstChar(); - } else { - String msg = "getFirstChar() - No character set found for font:" + getFontName(); - log.error(msg); - throw new FontRuntimeException(msg); - } - } - - /** - * Get the last character in this font. - * @return the last character in this font. - */ - public int getLastChar() { - - Iterator it = charSets.values().iterator(); - if (it.hasNext()) { - CharacterSet csm = (CharacterSet) it.next(); - return csm.getLastChar(); - } else { - String msg = "getLastChar() - No character set found for font:" + getFontName(); - log.error(msg); - throw new FontRuntimeException(msg); - } - - } - - /** - * The ascender is the part of a lowercase letter that extends above the - * "x-height" (the height of the letter "x"), such as "d", "t", or "h". Also - * used to denote the part of the letter extending above the x-height. - * - * @param size the point size - * @return the ascender for the given point size - */ - public int getAscender(int size) { - return getCharacterSet(size).getAscender(); - } - - /** - * Obtains the height of capital letters for the specified point size. - * - * @param size the point size - * @return the cap height for the specified point size - */ - public int getCapHeight(int size) { - return getCharacterSet(size).getCapHeight(); - } - - /** - * The descender is the part of a lowercase letter that extends below the - * base line, such as "g", "j", or "p". Also used to denote the part of the - * letter extending below the base line. - * - * @param size the point size - * @return the descender for the specified point size - */ - public int getDescender(int size) { - return getCharacterSet(size).getDescender(); - } - - /** - * The "x-height" (the height of the letter "x"). - * - * @param size the point size - * @return the x height for the given point size - */ - public int getXHeight(int size) { - return getCharacterSet(size).getXHeight(); - } - - /** - * Obtain the width of the character for the specified point size. - * @param character the character - * @param size the point size - * @return the width for the given point size - */ - public int getWidth(int character, int size) { - return getCharacterSet(size).getWidth(character); - } - - /** - * Get the getWidth (in 1/1000ths of a point size) of all characters in this - * character set. - * - * @param size - * the point size - * @return the widths of all characters - */ - public int[] getWidths(int size) { - return getCharacterSet(size).getWidths(); - } - - /** - * Get the getWidth (in 1/1000ths of a point size) of all characters in this - * character set. - * - * @return the widths of all characters - */ - public int[] getWidths() { - return getWidths(1000); - } - - /** - * Map a Unicode character to a code point in the font. - * @param c character to map - * @return the mapped character - */ - public char mapChar(char c) { - return charSet.mapChar(c); - } - - /** {@inheritDoc} */ - public String getEncodingName() { - return charSet.getEncoding(); - } - -} diff --git a/src/java/org/apache/fop/render/afp/goca/AbstractGraphicsCoord.java b/src/java/org/apache/fop/render/afp/goca/AbstractGraphicsCoord.java deleted file mode 100644 index dbb7469fe..000000000 --- a/src/java/org/apache/fop/render/afp/goca/AbstractGraphicsCoord.java +++ /dev/null @@ -1,137 +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.render.afp.goca; - -import org.apache.fop.render.afp.modca.AbstractPreparedAFPObject; -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * A base class encapsulating the structure of coordinate based GOCA objects - */ -public abstract class AbstractGraphicsCoord extends AbstractPreparedAFPObject { - - /** array of x/y coordinates */ - protected int[] coords = null; - - /** - * Constructor - * - * @param coords the x/y coordinates for this object - */ - public AbstractGraphicsCoord(int[] coords) { - this.coords = coords; - prepareData(); - } - - /** - * Constructor - * - * @param x the x coordinate for this object - * @param y the y coordinate for this object - */ - public AbstractGraphicsCoord(int x, int y) { - this(new int[] {x, y}); - } - - /** - * Constructor - * - * @param x1 the x1 coordinate for this object - * @param y1 the y1 coordinate for this object - * @param x2 the x2 coordinate for this object - * @param y2 the y2 coordinate for this object - */ - public AbstractGraphicsCoord(int x1, int y1, int x2, int y2) { - this(new int[] {x1, y1, x2, y2}); - } - - /** - * Returns the order code to use - * - * @return the order code to use - */ - protected abstract byte getOrderCode(); - - /** - * Returns the length of this order code (typically this is the same as the coordinate length) - * - * @return the length of this order code - * - */ - protected int getLength() { - return this.coords.length * 2; - } - - /** - * Creates a newly created and initialized byte data - * - * @return a newly created and initialized byte data - */ - protected byte[] createData() { - int len = getLength(); - byte[] data = new byte[len + 2]; - data[0] = getOrderCode(); // ORDER CODE - data[1] = (byte)len; // LENGTH - return data; - } - - /** {@inheritDoc} */ - protected void prepareData() { - super.data = createData(); - int fromIndex = data.length - getLength(); - addCoords(data, fromIndex); - } - - /** - * Adds the coordinates to the structured field data - * - * @param data the structured field data - * @param fromIndex the start index - */ - protected void addCoords(byte[] data, int fromIndex) { - // X/Y POS - for (int i = 0; i < coords.length; i++, fromIndex += 2) { - byte[] coord = BinaryUtils.convert(coords[i], 2); - data[fromIndex] = coord[0]; - data[fromIndex + 1] = coord[1]; - } - } - - /** - * 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 = ""; - for (int i = 0; i < coords.length; i++) { - coordsStr += (i % 2 == 0) ? "x" : "y"; - coordsStr += (i / 2) + "=" + coords[i] + ","; - } - coordsStr = coordsStr.substring(0, coordsStr.length() - 1); - return getName() + "{" + coordsStr + "}"; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsArea.java b/src/java/org/apache/fop/render/afp/goca/GraphicsArea.java deleted file mode 100644 index 7ad6ede27..000000000 --- a/src/java/org/apache/fop/render/afp/goca/GraphicsArea.java +++ /dev/null @@ -1,76 +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.render.afp.goca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.modca.AbstractPreparedObjectContainer; - -/** - * A GOCA graphics area (container for filled shapes/objects) - */ -public final class GraphicsArea extends AbstractPreparedObjectContainer { - - 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() { - // start len + end len + data len - 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[] endData = new byte[] { - (byte)0x60, // GEAR order code - 0x00, // LENGTH - }; - os.write(endData); - } - - /** {@inheritDoc} */ - public String toString() { - return "GraphicsArea{drawBoundary=" + drawBoundary + "}"; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsBox.java b/src/java/org/apache/fop/render/afp/goca/GraphicsBox.java deleted file mode 100644 index 3daa437f2..000000000 --- a/src/java/org/apache/fop/render/afp/goca/GraphicsBox.java +++ /dev/null @@ -1,61 +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.render.afp.goca; - -/** - * A GOCA graphics rectangular box - */ -public final class GraphicsBox extends AbstractGraphicsCoord { - - /** - * Constructor - * - * @param coords the x/y coordinates for this object - */ - public GraphicsBox(int[] coords) { - super(coords); - } - - /** {@inheritDoc} */ - protected byte getOrderCode() { - return (byte)0xC0; - } - - /** {@inheritDoc} */ - protected int getLength() { - return 10; - } - - /** {@inheritDoc} */ - protected void prepareData() { - super.data = createData(); - final int fromIndex = 4; - addCoords(data, fromIndex); - } - - /** {@inheritDoc} */ - protected byte[] createData() { - byte[] data = super.createData(); - data[2] = (byte)0x20; // CONTROL draw control flags - data[3] = 0x00; // reserved - return data; - } - -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsChainedSegment.java b/src/java/org/apache/fop/render/afp/goca/GraphicsChainedSegment.java deleted file mode 100644 index ba4ccea86..000000000 --- a/src/java/org/apache/fop/render/afp/goca/GraphicsChainedSegment.java +++ /dev/null @@ -1,148 +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.render.afp.goca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.modca.AbstractPreparedObjectContainer; -import org.apache.fop.render.afp.modca.PreparedAFPObject; -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * A GOCA graphics segment - */ -public final class GraphicsChainedSegment extends AbstractPreparedObjectContainer { - - /** 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; - - /** - * Main constructor - * - * @param name - * the name of this graphics segment - */ - public GraphicsChainedSegment(String name) { - super(name); - } - - /** - * Constructor - * - * @param name - * the name of this graphics segment - * @param previous - * the previous graphics segment in this chain - */ - public GraphicsChainedSegment(String name, GraphicsChainedSegment previous) { - super(name); - previous.next = this; - this.previous = previous; - } - - /** {@inheritDoc} */ - public int getDataLength() { - return 14 + super.getDataLength(); - } - - private static final byte APPEND_NEW_SEGMENT = 0; -// private static final byte PROLOG = 4; -// private static final byte APPEND_TO_EXISING = 48; - - private static final int NAME_LENGTH = 4; - - /** {@inheritDoc} */ - protected int getNameLength() { - return NAME_LENGTH; - } - - /** {@inheritDoc} */ - protected void writeStart(OutputStream os) throws IOException { - super.writeStart(os); - - byte[] data = new byte[14]; - data[0] = 0x70; // BEGIN_SEGMENT - data[1] = 0x0C; // Length of following parameters - - // segment name - byte[] nameBytes = getNameBytes(); - System.arraycopy(nameBytes, 0, data, 2, NAME_LENGTH); - - data[6] = 0x00; // FLAG1 (ignored) - data[7] = APPEND_NEW_SEGMENT; - - int dataLength = super.getDataLength(); - byte[] len = BinaryUtils.convert(dataLength, 2); - data[8] = len[0]; // SEGL - data[9] = len[1]; - - // P/S NAME (predecessor name) - if (previous != null) { - nameBytes = previous.getNameBytes(); - System.arraycopy(nameBytes, 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(PreparedAFPObject drawingOrder) { - if (currentArea != null) { - currentArea.addObject(drawingOrder); - } else { - super.addObject(drawingOrder); - } - } - - /** {@inheritDoc} */ - public String toString() { - return "GraphicsChainedSegment(name=" + super.getName() + ")"; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsData.java b/src/java/org/apache/fop/render/afp/goca/GraphicsData.java deleted file mode 100644 index 538933a03..000000000 --- a/src/java/org/apache/fop/render/afp/goca/GraphicsData.java +++ /dev/null @@ -1,128 +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.render.afp.goca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.modca.AbstractPreparedObjectContainer; -import org.apache.fop.render.afp.modca.PreparedAFPObject; -import org.apache.fop.render.afp.tools.BinaryUtils; -import org.apache.fop.render.afp.tools.StringUtils; - -/** - * A GOCA graphics data - */ -public final class GraphicsData extends AbstractPreparedObjectContainer { - - /** The maximum graphics data length */ - public static final int MAX_DATA_LEN = 32767; - - /** The graphics segment */ - private GraphicsChainedSegment currentSegment = null; - - /** {@inheritDoc} */ - public int getDataLength() { - return 8 + super.getDataLength(); - } - - /** - * Begins a graphics area (start of fill) - */ - public void beginArea() { - getSegment().beginArea(); - } - - /** - * Ends a graphics area (end of fill) - */ - public void endArea() { - getSegment().endArea(); - } - - /** - * Returns a new segment name - * - * @return a new segment name - */ - private 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 (currentSegment == null) { - newSegment(); - } - return this.currentSegment; - } - - /** - * Creates a new graphics segment - * - * @return a newly created graphics segment - */ - public GraphicsChainedSegment newSegment() { - String name = createSegmentName(); - if (currentSegment == null) { - this.currentSegment = new GraphicsChainedSegment(name); - } else { - this.currentSegment = new GraphicsChainedSegment(name, currentSegment); - } - super.addObject(currentSegment); - return currentSegment; - } - - /** {@inheritDoc} */ - public void addObject(PreparedAFPObject drawingOrder) { - if (currentSegment == null - || (currentSegment.getDataLength() + drawingOrder.getDataLength()) - >= GraphicsChainedSegment.MAX_DATA_LEN) { - newSegment(); - } - currentSegment.addObject(drawingOrder); - } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - byte[] data = new byte[9]; - copySF(data, SF_CLASS, Type.DATA, Category.GRAPHICS); - int dataLength = getDataLength(); - byte[] len = BinaryUtils.convert(dataLength, 2); - data[1] = len[0]; // Length byte 1 - 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); - } - - /** {@inheritDoc} */ - public String toString() { - return "GraphicsData"; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsFillet.java b/src/java/org/apache/fop/render/afp/goca/GraphicsFillet.java deleted file mode 100644 index cc1cedf2a..000000000 --- a/src/java/org/apache/fop/render/afp/goca/GraphicsFillet.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.render.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 GraphicsFillet extends AbstractGraphicsCoord { - - /** - * Constructor - * - * @param coords the x/y coordinates for this object - */ - public GraphicsFillet(int[] coords) { - super(coords); - } - - /** {@inheritDoc} */ - protected byte getOrderCode() { - return (byte)0xC5; - } - -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsFullArc.java b/src/java/org/apache/fop/render/afp/goca/GraphicsFullArc.java deleted file mode 100644 index 41347280e..000000000 --- a/src/java/org/apache/fop/render/afp/goca/GraphicsFullArc.java +++ /dev/null @@ -1,78 +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.render.afp.goca; - -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * A GOCA graphics arc (circle/ellipse) - */ -public class GraphicsFullArc extends AbstractGraphicsCoord { - /** the integer portion of the multiplier */ - private final int mh; - - /** the fractional portion of the multiplier */ - private final int mhr; - - /** - * Constructor - * - * @param x the x coordinate of the center of the circle/ellipse - * @param y the y coordinate of the center of the circle/ellipse - * @param mh the integer portion of the multiplier - * @param mhr the fractional portion of the multiplier - */ - public GraphicsFullArc(int x, int y, int mh, int mhr) { - 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; - } - - /** {@inheritDoc} */ - protected int getLength() { - return super.getLength() + 2; - } - - /** {@inheritDoc} */ - protected void prepareData() { - super.data = super.createData(); - final int fromIndex = 2; - super.addCoords(data, fromIndex); - } - - /** {@inheritDoc} */ - public String toString() { - return "GraphicsFullArc{" - + ", centerx=" + coords[0] - + ", centery=" + coords[1] - + ", mh=" + mh - + ", mhr=" + mhr - + "}"; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsImage.java b/src/java/org/apache/fop/render/afp/goca/GraphicsImage.java deleted file mode 100644 index ed8c1b386..000000000 --- a/src/java/org/apache/fop/render/afp/goca/GraphicsImage.java +++ /dev/null @@ -1,117 +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.render.afp.goca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.modca.AbstractStructuredAFPObject; -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * A GOCA Image - */ -public class GraphicsImage extends AbstractStructuredAFPObject { - - /** x coordinate */ - private final int x; - - /** y coordinate */ - private final int y; - - /** width */ - private final int width; - - /** height */ - private final int height; - - /** image data */ - private final byte[] imageData; - - /** - * Main constructor - * - * @param x the x coordinate of the image - * @param y the y coordinate of the image - * @param width the image width - * @param height the image height - * @param imageData the image data - */ - public GraphicsImage(int x, int y, int width, int height, byte[] imageData) { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - this.imageData = imageData; - } - - /** {@inheritDoc} */ - protected void writeStart(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) 0x0A, // LENGTH - xcoord[0], - xcoord[1], - ycoord[0], - ycoord[1], - 0x00, // FORMAT - 0x00, // RES - w[0], // WIDTH - w[1], // - h[0], // HEIGHT - h[1] // - }; - os.write(data); - } - - /** the maximum image data length */ - public static final short MAX_DATA_LEN = 255; - - /** {@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) 0x93, // GEIMG order code - 0x00 // LENGTH - }; - os.write(data); - } - - /** {@inheritDoc} */ - public String toString() { - return "GraphicsImage{x=" + x - + ", y=" + y - + ", width=" + width - + ", height=" + height - + "}"; - } -} diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsLine.java b/src/java/org/apache/fop/render/afp/goca/GraphicsLine.java deleted file mode 100644 index f09d24d98..000000000 --- a/src/java/org/apache/fop/render/afp/goca/GraphicsLine.java +++ /dev/null @@ -1,43 +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.render.afp.goca; - - -/** - * A GOCA graphics straight line drawn from the - * given position or current position. - */ -public class GraphicsLine extends AbstractGraphicsCoord { - - /** - * Constructor - * - * @param coords the x/y coordinates for this object - */ - public GraphicsLine(int[] coords) { - super(coords); - } - - /** {@inheritDoc} */ - protected byte getOrderCode() { - return (byte)0xC1; - } - -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsSetArcParameters.java b/src/java/org/apache/fop/render/afp/goca/GraphicsSetArcParameters.java deleted file mode 100644 index 26735ed30..000000000 --- a/src/java/org/apache/fop/render/afp/goca/GraphicsSetArcParameters.java +++ /dev/null @@ -1,51 +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.render.afp.goca; - -/** - * Sets the arc parameters for a GOCA graphics arc (circle/ellipse) - */ -public class GraphicsSetArcParameters extends AbstractGraphicsCoord { - - /** - * Constructor - * - * @param xmaj x coordinate of the major axis point - * @param ymin y coordinate of the minor axis point - * @param xmin x coordinate of the minor axis point - * @param ymaj y coordinate of the major axis point - */ - public GraphicsSetArcParameters(int xmaj, int ymin, int xmin, int ymaj) { - super(xmaj, ymin, xmin, ymaj); - } - - /** {@inheritDoc} */ - protected byte getOrderCode() { - return 0x22; - } - - /** {@inheritDoc} */ - public String toString() { - return getName() + "{xmaj=" + coords[0] - + ",ymin=" + coords[1] - + ",xmin=" + coords[2] - + ",ymaj=" + coords[3] + "}"; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsSetCharacterSet.java b/src/java/org/apache/fop/render/afp/goca/GraphicsSetCharacterSet.java deleted file mode 100644 index f3d8b186b..000000000 --- a/src/java/org/apache/fop/render/afp/goca/GraphicsSetCharacterSet.java +++ /dev/null @@ -1,53 +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.render.afp.goca; - -import org.apache.fop.render.afp.modca.AbstractPreparedAFPObject; -import org.apache.fop.render.afp.tools.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 diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsSetCurrentPosition.java b/src/java/org/apache/fop/render/afp/goca/GraphicsSetCurrentPosition.java deleted file mode 100644 index 7b68d0f17..000000000 --- a/src/java/org/apache/fop/render/afp/goca/GraphicsSetCurrentPosition.java +++ /dev/null @@ -1,41 +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.render.afp.goca; - - -/** - * Sets the current painting position of the graphics object - */ -public class GraphicsSetCurrentPosition extends AbstractGraphicsCoord { - - /** - * Constructor - * - * @param coords the x/y coordinates for this object - */ - public GraphicsSetCurrentPosition(int[] coords) { - super(coords); - } - - /** {@inheritDoc} */ - protected byte getOrderCode() { - return (byte)0x21; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsSetLineType.java b/src/java/org/apache/fop/render/afp/goca/GraphicsSetLineType.java deleted file mode 100644 index febf2dfb2..000000000 --- a/src/java/org/apache/fop/render/afp/goca/GraphicsSetLineType.java +++ /dev/null @@ -1,86 +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.render.afp.goca; - -import org.apache.fop.render.afp.modca.AbstractPreparedAFPObject; - -/** - * Sets the value of the current line type attribute when stroking GOCA shapes (structured fields) - */ -public class GraphicsSetLineType extends AbstractPreparedAFPObject { - - /** the default line type */ - public static final byte DEFAULT = 0x00; // normally SOLID - - /** the default line type */ - public static final byte DOTTED = 0x01; - - /** short dashed line type */ - public static final byte SHORT_DASHED = 0x02; - - /** dashed dotted line type */ - public static final byte DASH_DOT = 0x03; - - /** double dotted line type */ - public static final byte DOUBLE_DOTTED = 0x04; - - /** long dashed line type */ - public static final byte LONG_DASHED = 0x05; - - /** dash double dotted line type */ - public static final byte DASH_DOUBLE_DOTTED = 0x06; - - /** solid line type */ - public static final byte SOLID = 0x07; - - /** invisible line type */ - public static final byte INVISIBLE = 0x08; - - /** line type */ - private byte type = DEFAULT; - - /** - * Main constructor - * - * @param type line type - */ - public GraphicsSetLineType(byte type) { - this.type = type; - prepareData(); - } - - /** {@inheritDoc} */ - protected void prepareData() { - super.data = new byte[] { - 0x18, // GSLW order code - type // line type - }; - } - - private static final String[] TYPES = { - "default (solid)", "dotted", "short dashed", "dash dotted", "double dotted", - "long dashed", "dash double dotted", "solid", "invisible" - }; - - /** {@inheritDoc} */ - public String toString() { - return "GraphicsSetLineType{type=" + TYPES[type] + "}"; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsSetLineWidth.java b/src/java/org/apache/fop/render/afp/goca/GraphicsSetLineWidth.java deleted file mode 100644 index 82163d29e..000000000 --- a/src/java/org/apache/fop/render/afp/goca/GraphicsSetLineWidth.java +++ /dev/null @@ -1,53 +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.render.afp.goca; - -import org.apache.fop.render.afp.modca.AbstractPreparedAFPObject; - -/** - * Sets the line width to use when stroking GOCA shapes (structured fields) - */ -public class GraphicsSetLineWidth extends AbstractPreparedAFPObject { - /** line width multiplier */ - private int multiplier = 1; - - /** - * Main constructor - * - * @param multiplier the line width multiplier - */ - public GraphicsSetLineWidth(int multiplier) { - this.multiplier = multiplier; - prepareData(); - } - - /** {@inheritDoc} */ - protected void prepareData() { - super.data = new byte[] { - 0x19, // GSLW order code - (byte)multiplier // MH (line-width) - }; - } - - /** {@inheritDoc} */ - public String toString() { - return "GraphicsSetLineWidth{multiplier=" + multiplier + "}"; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsSetMix.java b/src/java/org/apache/fop/render/afp/goca/GraphicsSetMix.java deleted file mode 100644 index 99a04d3ee..000000000 --- a/src/java/org/apache/fop/render/afp/goca/GraphicsSetMix.java +++ /dev/null @@ -1,55 +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.render.afp.goca; - -import org.apache.fop.render.afp.modca.AbstractPreparedAFPObject; - -public class GraphicsSetMix extends AbstractPreparedAFPObject { - - public static final byte MODE_DEFAULT = 0x00; - public static final byte MODE_OVERPAINT = 0x02; - - /** the mix mode value */ - private final byte mode; - - /** - * Main constructor - * - * @param mode the mix mode value - */ - public GraphicsSetMix(byte mode) { - this.mode = mode; - prepareData(); - } - - /** {@inheritDoc} */ - protected void prepareData() { - super.data = new byte[] { - 0x0C, // GSMX order code - mode // MODE (mix mode value) - }; - } - - /** {@inheritDoc} */ - public String toString() { - return "GraphicsSetMix{mode=" + mode + "}"; - } - -} diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsSetPatternSymbol.java b/src/java/org/apache/fop/render/afp/goca/GraphicsSetPatternSymbol.java deleted file mode 100644 index bdc7b1233..000000000 --- a/src/java/org/apache/fop/render/afp/goca/GraphicsSetPatternSymbol.java +++ /dev/null @@ -1,105 +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.render.afp.goca; - -import org.apache.fop.render.afp.modca.AbstractPreparedAFPObject; - -/** - * Sets the pattern symbol to use when filling following GOCA structured fields - */ -public class GraphicsSetPatternSymbol extends AbstractPreparedAFPObject { - /** dotted density 1 */ - public static final byte DOTTED_DENSITY_1 = 0x01; - - /** dotted density 2 */ - public static final byte DOTTED_DENSITY_2 = 0x02; - - /** dotted density 3 */ - public static final byte DOTTED_DENSITY_3 = 0x03; - - /** dotted density 4 */ - public static final byte DOTTED_DENSITY_4 = 0x04; - - /** dotted density 5 */ - public static final byte DOTTED_DENSITY_5 = 0x05; - - /** dotted density 6 */ - public static final byte DOTTED_DENSITY_6 = 0x06; - - /** dotted density 7 */ - public static final byte DOTTED_DENSITY_7 = 0x07; - - /** dotted density 8 */ - public static final byte DOTTED_DENSITY_8 = 0x08; - - /** dotted density 9 */ - public static final byte VERTICAL_LINES = 0x09; - - /** horizontal lines */ - public static final byte HORIZONTAL_LINES = 0x0A; - - /** diagonal lines, bottom left to top right 1 */ - public static final byte DIAGONAL_LINES_BLTR_1 = 0x0B; - - /** diagonal lines, bottom left to top right 2 */ - public static final byte DIAGONAL_LINES_BLTR_2 = 0x0C; - - /** diagonal lines, top left to bottom right 1 */ - public static final byte DIAGONAL_LINES_TLBR_1 = 0x0D; - - /** diagonal lines, top left to bottom right 2 */ - public static final byte DIAGONAL_LINES_TLBR_2 = 0x0E; - - /** no fill */ - public static final byte NO_FILL = 0x0F; - - /** solid fill */ - public static final byte SOLID_FILL = 0x10; - - /** blank (same as no fill) */ - public static final byte BLANK = 0x40; // processed same as NO_FILL - - /** the graphics pattern symbol to use */ - private final byte symbol; - - /** - * Main constructor - * - * @param symb the pattern symbol to use - */ - public GraphicsSetPatternSymbol(byte symb) { - this.symbol = symb; - prepareData(); - } - - /** {@inheritDoc} */ - protected void prepareData() { - super.data = new byte[] { - 0x28, // GSPT order code - symbol - }; - } - - /** {@inheritDoc} */ - public String toString() { - return "GraphicsSetPatternSymbol(fill=" - + (symbol == SOLID_FILL ? true : false) + ")"; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsSetProcessColor.java b/src/java/org/apache/fop/render/afp/goca/GraphicsSetProcessColor.java deleted file mode 100644 index aa98b95c2..000000000 --- a/src/java/org/apache/fop/render/afp/goca/GraphicsSetProcessColor.java +++ /dev/null @@ -1,89 +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.render.afp.goca; - -import java.awt.Color; -import java.awt.color.ColorSpace; - -import org.apache.fop.render.afp.modca.AbstractPreparedAFPObject; - -/** - * Sets the current processing color for the following GOCA structured fields - */ -public class GraphicsSetProcessColor extends AbstractPreparedAFPObject { - /** the color to set */ - private final Color color; - - /** - * Main constructor - * - * @param color the color to set - */ - public GraphicsSetProcessColor(Color color) { - this.color = color; - prepareData(); - } - - /** {@inheritDoc} */ - protected void prepareData() { - // COLSPCE - byte colspace; - int colSpaceType = color.getColorSpace().getType(); - if (colSpaceType == ColorSpace.TYPE_CMYK) { - colspace = 0x04; - } else if (colSpaceType == ColorSpace.TYPE_RGB) { - colspace = 0x01; - } else { - log.error("unsupported colorspace " + colSpaceType); - colspace = 0x01; - } - - // COLSIZE(S) - float[] colcomp = color.getColorComponents(null); - byte[] colsizes = new byte[] {0x00, 0x00, 0x00, 0x00}; - for (int i = 0; i < colcomp.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 - data[2] = 0x00; // reserved; must be zero - data[3] = colspace; // COLSPCE - data[4] = 0x00; // reserved; must be zero - data[5] = 0x00; // reserved; must be zero - data[6] = 0x00; // reserved; must be zero - data[7] = 0x00; // reserved; must be zero - data[8] = colsizes[0]; // COLSIZE(S) - 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); - } - } - - /** {@inheritDoc} */ - public String toString() { - return "GraphicsSetProcessColor(col=" + color + ")"; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsString.java b/src/java/org/apache/fop/render/afp/goca/GraphicsString.java deleted file mode 100644 index a67774b6d..000000000 --- a/src/java/org/apache/fop/render/afp/goca/GraphicsString.java +++ /dev/null @@ -1,115 +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.render.afp.goca; - -import java.io.UnsupportedEncodingException; - -import org.apache.fop.render.afp.AFPConstants; -import org.apache.fop.render.afp.modca.AbstractPreparedAFPObject; -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * 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(); - } - - /** - * Constructor - * - * @param str the character string - * @param x the x coordinate - * @param y the y coordinate - */ - public GraphicsString(String str, int x, int y) { - this.str = str; - this.x = x; - this.y = y; - prepareData(); - } - - /** {@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); - } - } - - /** {@inheritDoc} */ - public String toString() { - String string = "GraphicsString{str='" + str + "'"; - if (!fromCurrentPosition) { - string += ",x=" + x + ",y=" + y; - } - string += "}"; - return string; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/ioca/ImageCellPosition.java b/src/java/org/apache/fop/render/afp/ioca/ImageCellPosition.java deleted file mode 100644 index 4faac0c6e..000000000 --- a/src/java/org/apache/fop/render/afp/ioca/ImageCellPosition.java +++ /dev/null @@ -1,174 +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.render.afp.ioca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.modca.AbstractAFPObject; -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * The IM Image Cell Position structured field specifies the placement, - * size, and replication of IM image cells. - */ -public class ImageCellPosition extends AbstractAFPObject { - - /** - * Offset of image cell in X direction - */ - private int xOffset = 0; - - /** - * Offset of image cell in Y direction - */ - private int yOffset = 0; - - /** - * Size of image cell in X direction - */ - private final byte[] xSize = new byte[] {(byte)0xFF, (byte)0xFF}; - - /** - * Size of image cell in Y direction - */ - private final byte[] ySize = new byte[] {(byte)0xFF, (byte)0xFF}; - - /** - * Size of fill rectangle in X direction - */ - private final byte[] xFillSize = new byte[] {(byte)0xFF, (byte)0xFF}; - - /** - * Size of fill rectangle in Y direction - */ - private final byte[] yFillSize = new byte[] {(byte)0xFF, (byte)0xFF}; - - /** - * Constructor for the ImageCellPosition - * @param x The offset of image cell in X direction - * @param y The offset of image cell in Y direction - */ - public ImageCellPosition(int x, int y) { - xOffset = x; - yOffset = y; - } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - byte[] data = new byte[21]; - copySF(data, Type.POSITION, Category.IM_IMAGE); - - data[1] = 0x00; // length - data[2] = 0x14; - - /** - * Specifies the offset along the Xp direction, in image points, - * of this image cell from the IM image object area origin. - */ - byte[] x1 = BinaryUtils.convert(xOffset, 2); - data[9] = x1[0]; - data[10] = x1[1]; - - /** - * Specifies the offset along the Yp direction, in image points, - * of this image cell from the IM image object area origin. - */ - byte[] x2 = BinaryUtils.convert(yOffset, 2); - data[11] = x2[0]; - data[12] = x2[1]; - - data[13] = xSize[0]; - data[14] = xSize[1]; - - data[15] = ySize[0]; - data[16] = ySize[1]; - - data[17] = xFillSize[0]; - data[18] = xFillSize[1]; - - data[19] = yFillSize[0]; - data[20] = yFillSize[1]; - - os.write(data); - } - - /** - * Specifies the extent in the X direction, in image points, - * of this image cell. A value of X'FFFF' indicates that the - * default extent specified in bytes 28 and 29 of the Image - * Input Descriptor (IID) is to be used. - * - * @param xcSize The size to set. - */ - public void setXSize(int xcSize) { - byte[] x = BinaryUtils.convert(xcSize, 2); - xSize[0] = x[0]; - xSize[1] = x[1]; - } - - /** - * Specifies the extent of the fill rectangle in the X direction, - * in image points. This value can be smaller than, equal to, or - * larger than the image cell extent in the X direction (XCSize). - * A value of X'FFFF' indicates that the image cell X-extent should - * be used as the fill rectangle X-extent. The fill rectangle is - * filled in the X direction by repeating the image cell in the - * X direction. The image cell can be truncated to fit the rectangle. - * - * @param size The size to set. - */ - public void setXFillSize(int size) { - byte[] x = BinaryUtils.convert(size, 2); - this.xFillSize[0] = x[0]; - this.xFillSize[1] = x[1]; - } - - /** - * Specifies the extent in the Y direction, in image points, - * of this image cell. A value of X'FFFF' indicates that the - * default extent specified in bytes 30 and 31 of the Image - * Input Descriptor (IID) is to be used. - * - * @param size The size to set. - */ - public void setYSize(int size) { - byte[] x = BinaryUtils.convert(size, 2); - this.ySize[0] = x[0]; - this.ySize[1] = x[1]; - } - - /** - * Specifies the extent of the fill rectangle in the Y direction, - * in image points. This value can be smaller than, equal to, or - * larger than the image cell extent in the Y direction (YCSize). - * A value of X'FFFF' indicates that the image cell Y-extent should - * be used as the fill rectangle Y-extent. The fill rectangle is - * filled in the Y direction by repeating the image cell in the - * Y direction. The image cell can be truncated to fit the rectangle. - * - * @param size The size to set. - */ - public void setYFillSize(int size) { - byte[] x = BinaryUtils.convert(size, 2); - this.yFillSize[0] = x[0]; - this.yFillSize[1] = x[1]; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/ioca/ImageContent.java b/src/java/org/apache/fop/render/afp/ioca/ImageContent.java deleted file mode 100644 index 7143b986c..000000000 --- a/src/java/org/apache/fop/render/afp/ioca/ImageContent.java +++ /dev/null @@ -1,277 +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.render.afp.ioca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.modca.AbstractStructuredAFPObject; - -/** - */ -public class ImageContent extends AbstractStructuredAFPObject { - - /** - * The CCITT T.4 Group 3 Coding Standard (G3 MH-Modified Huffman) is a - * compression method standardized by the International Telegraph and - * Telephone Consultative Committee (CCITT) for facsimile. It enables - * one-dimensional compression. - */ - public static final byte COMPID_G3_MH = (byte)0x80; - - /** - * The CCITT T.4 Group 3 Coding Option (G3 MR-Modified READ) is a - * compression method standardized by the International Telegraph and - * Telephone Consultative Committee (CCITT) for facsimile. It enables - * two-dimensional compression. - */ - public static final byte COMPID_G3_MR = (byte)0x81; - - /** - * The CCITT T.6 Group 4 Coding Standard (G4 MMR-Modified Modified READ) is a - * compression method standardized by the International Telegraph and - * Telephone Consultative Committee (CCITT) for facsimile. It enables - * two-dimensional compression. - */ - public static final byte COMPID_G3_MMR = (byte)0x82; - - /** - * The image size parameter - */ - private ImageSizeParameter imageSizeParameter = null; - - /** - * The image encoding - */ - private byte encoding = (byte)0x03; - - /** - * The image ide size - */ - private byte size = 1; - - /** - * The image compression - */ - private byte compression = (byte)0xC0; - - /** - * The image color model - */ - private byte colorModel = (byte)0x01; - - /** - * The image data - */ - private byte[] data; - - /** - * Constructor for the image content - */ - public ImageContent() { - } - - /** - * Sets the image size parameter - * - * @param imageSizeParameter the image size parameter. - */ - public void setImageSizeParameter(ImageSizeParameter imageSizeParameter) { - this.imageSizeParameter = imageSizeParameter; - } - - /** - * Sets the image encoding. - * - * @param enc The image encoding. - */ - public void setImageEncoding(byte enc) { - this.encoding = enc; - } - - /** - * Sets the image compression. - * - * @param comp The image compression. - */ - public void setImageCompression(byte comp) { - this.compression = comp; - } - - /** - * Sets the image IDE size. - * - * @param s The IDE size. - */ - public void setImageIDESize(byte s) { - this.size = s; - } - - /** - * Sets the image IDE color model. - * - * @param color the IDE color model. - */ - public void setImageIDEColorModel(byte color) { - this.colorModel = color; - } - - /** - * Set the data image store information. - * - * @param imageData the image data - */ - public void setImageData(byte[] imageData) { - this.data = imageData; - } - - private static final int MAX_DATA_LEN = 65535; - - /** {@inheritDoc} */ - protected void writeContent(OutputStream os) throws IOException { - if (imageSizeParameter != null) { - imageSizeParameter.writeToStream(os); - } - - // TODO convert to triplet/parameter class - os.write(getImageEncodingParameter()); - - os.write(getImageIDESizeParameter()); - - os.write(getIDEStructureParameter()); - - os.write(getExternalAlgorithmParameter()); - - // Image Data - if (data != null) { - final byte[] dataHeader = new byte[] { - (byte)0xFE, // ID - (byte)0x92, // ID - 0x00, // length - 0x00 // length - }; - final int lengthOffset = 2; - writeChunksToStream(this.data, dataHeader, lengthOffset, MAX_DATA_LEN, os); - } - } - - /** {@inheritDoc} */ - protected void writeStart(OutputStream os) throws IOException { - final byte[] startData = new byte[] { - (byte)0x91, // ID - 0x01, // Length - (byte)0xff, // Object Type = IOCA Image Object - }; - os.write(startData); - } - - /** {@inheritDoc} */ - protected void writeEnd(OutputStream os) throws IOException { - final byte[] endData = new byte[] { - (byte)0x93, // ID - 0x00, // Length - }; - os.write(endData); - } - - /** - * Helper method to return the image encoding parameter. - * - * @return byte[] The data stream. - */ - private byte[] getImageEncodingParameter() { - final byte[] encodingData = new byte[] { - (byte)0x95, // ID - 0x02, // Length - encoding, - 0x01, // RECID - }; - return encodingData; - } - - /** - * Helper method to return the external algorithm parameter. - * - * @return byte[] The data stream. - */ - private byte[] getExternalAlgorithmParameter() { - if (encoding == (byte)0x83 && compression != 0) { - final byte[] extAlgData = new byte[] { - (byte)0x95, // ID - 0x00, // Length - 0x10, // ALGTYPE = Compression Algorithm - 0x00, // Reserved - (byte)0x83, // COMPRID = JPEG - 0x00, // Reserved - 0x00, // Reserved - 0x00, // Reserved - compression, // MARKER - 0x00, // Reserved - 0x00, // Reserved - 0x00, // Reserved - }; - extAlgData[1] = (byte)(extAlgData.length - 2); - return extAlgData; - } - return new byte[0]; - } - - /** - * Helper method to return the image encoding parameter. - * - * @return byte[] The data stream. - */ - private byte[] getImageIDESizeParameter() { - final byte[] ideSizeData = new byte[] { - (byte)0x96, // ID - 0x01, // Length - size, - }; - return ideSizeData; - } - - /** - * Helper method to return the external algorithm parameter. - * - * @return byte[] The data stream. - */ - private byte[] getIDEStructureParameter() { - if (colorModel != 0 && size == 24) { - final byte bits = (byte)(size / 3); - final byte[] ideStructData = new byte[] { - (byte)0x9B, // ID - 0x00, // Length - 0x00, // FLAGS - 0x00, // Reserved - colorModel, // COLOR MODEL - 0x00, // Reserved - 0x00, // Reserved - 0x00, // Reserved - bits, - bits, - bits, - }; - ideStructData[1] = (byte)(ideStructData.length - 2); - return ideStructData; - } - return new byte[0]; - } - -} diff --git a/src/java/org/apache/fop/render/afp/ioca/ImageInputDescriptor.java b/src/java/org/apache/fop/render/afp/ioca/ImageInputDescriptor.java deleted file mode 100644 index cb6595eaf..000000000 --- a/src/java/org/apache/fop/render/afp/ioca/ImageInputDescriptor.java +++ /dev/null @@ -1,138 +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.render.afp.ioca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.modca.AbstractAFPObject; -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * The IM Image Input Descriptor structured field contains the - * descriptor data for an IM image data object. This data specifies - * the resolution, size, and color of the IM image. - */ -public class ImageInputDescriptor extends AbstractAFPObject { - - /** - * The resolution of the raster image (default 240) - */ - private int resolution = 240; - - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - - byte[] data = new byte[45]; - copySF(data, Type.DESCRIPTOR, Category.IM_IMAGE); - - data[1] = 0x00; // length - data[2] = 0x2C; - - // Constant data. - data[9] = 0x00; - data[10] = 0x00; - data[11] = 0x09; - data[12] = 0x60; - data[13] = 0x09; - data[14] = 0x60; - data[15] = 0x00; - data[16] = 0x00; - data[17] = 0x00; - data[18] = 0x00; - data[19] = 0x00; - data[20] = 0x00; - - // X Base (Fixed x00) - data[21] = 0x00; - // Y Base (Fixed x00) - data[22] = 0x00; - - byte[] imagepoints = BinaryUtils.convert(resolution * 10, 2); - - /** - * Specifies the number of image points per unit base for the X axis - * of the image. This value is ten times the resolution of the image - * in the X direction. - */ - data[23] = imagepoints[0]; - data[24] = imagepoints[1]; - - /** - * Specifies the number of image points per unit base for the Y axis - * of the image. This value is ten times the resolution of the image - * in the Y direction. - */ - data[25] = imagepoints[0]; - data[26] = imagepoints[1]; - - /** - * Specifies the extent in the X direction, in image points, of an - * non-celled (simple) image. - */ - data[27] = 0x00; - data[28] = 0x01; - - /** - * Specifies the extent in the Y direction, in image points, of an - * non-celled (simple) image. - */ - data[29] = 0x00; - data[30] = 0x01; - - // Constant Data - data[31] = 0x00; - data[32] = 0x00; - data[33] = 0x00; - data[34] = 0x00; - data[35] = 0x2D; - data[36] = 0x00; - - // Default size of image cell in X direction - data[37] = 0x00; - data[38] = 0x01; - - // Default size of image cell in Y direction - data[39] = 0x00; - data[40] = 0x01; - - // Constant Data - data[41] = 0x00; - data[42] = 0x01; - - // Image Color - data[43] = (byte)0xFF; - data[44] = (byte)0xFF; - - os.write(data); - } - - /** - * Sets the resolution information for the raster image - * the default value is a resolution of 240 dpi. - * - * @param resolution The resolution value - */ - public void setResolution(int resolution) { - this.resolution = resolution; - } - -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/ioca/ImageOutputControl.java b/src/java/org/apache/fop/render/afp/ioca/ImageOutputControl.java deleted file mode 100644 index 1758f4a16..000000000 --- a/src/java/org/apache/fop/render/afp/ioca/ImageOutputControl.java +++ /dev/null @@ -1,200 +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.render.afp.ioca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.modca.AbstractAFPObject; -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * The IM Image Output Control structured field specifies the position and - * orientation of the IM image object area and the mapping of the image points - * to presentation device pels. - * - */ -public class ImageOutputControl extends AbstractAFPObject { - - /** - * The orientation of the image - */ - private int orientation = 0; - - /** - * Specifies the offset, along the X-axis, of the IM image object area - * origin to the origin of the including page - */ - private int xCoord = 0; - - /** - * Specifies the offset, along the Y-axis, of the IM image object area - * origin to the origin of the including page - */ - private int yCoord = 0; - - /** - * Map an image point to a single presentation device - */ - private boolean singlePoint = true; - - /** - * Constructor for the ImageOutputControl The x parameter specifies the - * offset, along the X-axis, of the IM image object area origin to the - * origin of the including page and the y parameter specifies the offset - * along the Y-axis. The offset is specified in image points and is resolved - * using the units of measure specified for the image in the IID structured - * field. - * - * @param x - * The X-axis offset. - * @param y - * The Y-axis offset. - */ - public ImageOutputControl(int x, int y) { - xCoord = x; - yCoord = y; - } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - - byte[] data = new byte[33]; - - data[0] = 0x5A; - data[1] = 0x00; - data[2] = 0x20; - data[3] = (byte) 0xD3; - data[4] = (byte) 0xA7; - data[5] = (byte) 0x7B; - data[6] = 0x00; - data[7] = 0x00; - data[8] = 0x00; - - // XoaOset - byte[] x1 = BinaryUtils.convert(xCoord, 3); - data[9] = x1[0]; - data[10] = x1[1]; - data[11] = x1[2]; - - // YoaOset - byte[] x2 = BinaryUtils.convert(yCoord, 3); - data[12] = x2[0]; - data[13] = x2[1]; - data[14] = x2[2]; - - switch (orientation) { - case 0: - // 0 and 90 degrees respectively - data[15] = 0x00; - data[16] = 0x00; - data[17] = 0x2D; - data[18] = 0x00; - break; - case 90: - // 90 and 180 degrees respectively - data[15] = 0x2D; - data[16] = 0x00; - data[17] = 0x5A; - data[18] = 0x00; - break; - case 180: - // 180 and 270 degrees respectively - data[15] = 0x5A; - data[16] = 0x00; - data[17] = (byte) 0x87; - data[18] = 0x00; - break; - case 270: - // 270 and 0 degrees respectively - data[15] = (byte) 0x87; - data[16] = 0x00; - data[17] = 0x00; - data[18] = 0x00; - break; - default: - // 0 and 90 degrees respectively - data[15] = 0x00; - data[16] = 0x00; - data[17] = 0x2D; - data[18] = 0x00; - break; - - } - - // Constant Data - data[19] = 0x00; - data[20] = 0x00; - data[21] = 0x00; - data[22] = 0x00; - data[23] = 0x00; - data[24] = 0x00; - data[25] = 0x00; - data[26] = 0x00; - - if (singlePoint) { - data[27] = 0x03; - data[28] = (byte) 0xE8; - data[29] = 0x03; - data[30] = (byte) 0xE8; - } else { - data[27] = 0x07; - data[28] = (byte) 0xD0; - data[29] = 0x07; - data[30] = (byte) 0xD0; - } - - // Constant Data - data[31] = (byte) 0xFF; - data[32] = (byte) 0xFF; - - os.write(data); - } - - /** - * Sets the orientation which specifies the amount of clockwise rotation of - * the IM image object area. - * - * @param orientation - * The orientation to set. - */ - public void setOrientation(int orientation) { - - if (orientation == 0 || orientation == 90 || orientation == 180 - || orientation == 270) { - this.orientation = orientation; - } else { - throw new IllegalArgumentException( - "The orientation must be one of the values 0, 90, 180, 270"); - } - } - - /** - * Sets the singlepoint, if true map an image point to a single presentation - * device pel in the IM image object area. If false map an image point to - * two presentation device pels in the IM image object area (double-dot) - * - * @param singlepoint - * Use the singlepoint basis when true. - */ - public void setSinglepoint(boolean singlepoint) { - singlePoint = singlepoint; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/ioca/ImageRasterData.java b/src/java/org/apache/fop/render/afp/ioca/ImageRasterData.java deleted file mode 100644 index 0c863e1e7..000000000 --- a/src/java/org/apache/fop/render/afp/ioca/ImageRasterData.java +++ /dev/null @@ -1,77 +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.render.afp.ioca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.modca.AbstractAFPObject; -import org.apache.fop.render.afp.modca.AbstractAFPObject.Category; -import org.apache.fop.render.afp.modca.AbstractAFPObject.Type; -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * Contains the image points that define the IM image raster pattern. - * - * A raster pattern is the array of presentation device pels that forms - * the image. The image data is uncompressed. Bits are grouped into - * bytes and are ordered from left to right within each byte. Each bit - * in the image data represents an image point and is mapped to - * presentation device pels as specified in the IOC structured field. - * A bit with value B'1' indicates a significant image point; a bit - * with value B'0' indicates an insignificant image point. - * Image points are recorded from left to right in rows that represents - * scan lines (X direction), and rows representing scan lines are - * recorded from top to bottom (Y direction). When the image is - * presented, all image points in a row are presented before any - * image points in the next sequential row are presented, and all rows - * have the same number of image points. If the total number of image - * points is not a multiple of 8, the last byte of the image data is - * padded to a byte boundary. The padding bits do not represent image - * points and are ignored by presentation devices. - */ -public class ImageRasterData extends AbstractAFPObject { - - /** - * 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) { - this.rasterData = data; - } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - byte[] data = new byte[9]; - copySF(data, Type.DATA, Category.IM_IMAGE); - // The size of the structured field - byte[] len = BinaryUtils.convert(rasterData.length + 8, 2); - data[1] = len[0]; - data[2] = len[1]; - os.write(data); - - os.write(rasterData); - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/ioca/ImageRasterPattern.java b/src/java/org/apache/fop/render/afp/ioca/ImageRasterPattern.java deleted file mode 100644 index 9619c40ff..000000000 --- a/src/java/org/apache/fop/render/afp/ioca/ImageRasterPattern.java +++ /dev/null @@ -1,759 +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.render.afp.ioca; - -/** - * Raster data is a grid of cells covering an area of interest. - * Each pixel, the smallest unit of information in the grid, displays - * a unique attribute. This static class generates raster data for different - * shades of grey (betweeen 0 and 16) the lower the number being the - * darker the shade. The image data dimensions are 64 x 8. - */ -public class ImageRasterPattern { - - /** - * The Raster Pattern for Greyscale 16 - */ - private static final byte[] GREYSCALE16 = new byte[] { - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - }; - - /** - * The Raster Pattern for Greyscale 15 - */ - private static final byte[] GREYSCALE15 = new byte[] { - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - }; - - /** - * The Raster Pattern for Greyscale 14 - */ - private static final byte[] GREYSCALE14 = new byte[] { - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x44, - 0x44, - 0x44, - 0x44, - 0x44, - 0x44, - 0x44, - 0x44, - }; - - - /** - * The Raster Pattern for Greyscale 13 - */ - private static final byte[] GREYSCALE13 = new byte[] { - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - }; - - /** - * The Raster Pattern for Greyscale 12 - */ - private static final byte[] GREYSCALE12 = new byte[] { - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - }; - - /** - * The Raster Pattern for Greyscale 11 - */ - private static final byte[] GREYSCALE11 = new byte[] { - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - 0x44, - 0x44, - 0x44, - 0x44, - 0x44, - 0x44, - 0x44, - 0x44, - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - }; - - /** - * The Raster Pattern for Greyscale 10 - */ - private static final byte[] GREYSCALE10 = new byte[] { - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - 0x44, - 0x44, - 0x44, - 0x44, - 0x44, - 0x44, - 0x44, - 0x44, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - }; - - /** - * The Raster Pattern for Greyscale 9 - */ - private static final byte[] GREYSCALE09 = new byte[] { - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - 0x11, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - }; - - /** - * The Raster Pattern for Greyscale 8 - */ - private static final byte[] GREYSCALE08 = new byte[] { - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - }; - - - /** - * The Raster Pattern for Greyscale 7 - */ - private static final byte[] GREYSCALE07 = new byte[] { - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - }; - - - /** - * The Raster Pattern for Greyscale 6 - */ - private static final byte[] GREYSCALE06 = new byte[] { - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - (byte)0xEE, - (byte)0xEE, - (byte)0xEE, - (byte)0xEE, - (byte)0xEE, - (byte)0xEE, - (byte)0xEE, - (byte)0xEE, - }; - - /** - * The Raster Pattern for Greyscale 5 - */ - private static final byte[] GREYSCALE05 = new byte[] { - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xEE, - (byte)0xEE, - (byte)0xEE, - (byte)0xEE, - (byte)0xEE, - (byte)0xEE, - (byte)0xEE, - (byte)0xEE, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - }; - - - /** - * The Raster Pattern for Greyscale 4 - */ - private static final byte[] GREYSCALE04 = new byte[] { - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xAA, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - }; - - /** - * The Raster Pattern for Greyscale 3 - */ - private static final byte[] GREYSCALE03 = new byte[] { - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - 0x55, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xBB, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - }; - - /** - * The Raster Pattern for Greyscale 2 - */ - private static final byte[] GREYSCALE02 = new byte[] { - 0x77, - 0x77, - 0x77, - 0x77, - 0x77, - 0x77, - 0x77, - 0x77, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xDD, - (byte)0xDD, - (byte)0xDD, - (byte)0xDD, - (byte)0xDD, - (byte)0xDD, - (byte)0xDD, - (byte)0xDD, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - }; - - - /** - * The Raster Pattern for Greyscale 1 - */ - private static final byte[] GREYSCALE01 = new byte[] { - 0x77, - 0x77, - 0x77, - 0x77, - 0x77, - 0x77, - 0x77, - 0x77, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - }; - - - /** - * The Raster Pattern for Greyscale 00 - */ - private static final byte[] GREYSCALE00 = new byte[] { - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - (byte)0xFF, - }; - - /** - * Static method to return the raster image data for the - * grey scale specified. The scale should be between 0 (darkest) - * and 16 (lightest). - * @param greyscale The grey scale value (0 - 16) - * @return the raster data byte array for the given greyscale value - */ - public static byte[] getRasterData(int greyscale) { - - int repeat = 16; - - byte[] greypattern = new byte[32]; - byte[] rasterdata = new byte[32 * repeat]; - - switch (greyscale) { - case 0: - System.arraycopy(GREYSCALE00, 0, greypattern, 0, 32); - break; - case 1: - System.arraycopy(GREYSCALE01, 0, greypattern, 0, 32); - break; - case 2: - System.arraycopy(GREYSCALE02, 0, greypattern, 0, 32); - break; - case 3: - System.arraycopy(GREYSCALE03, 0, greypattern, 0, 32); - break; - case 4: - System.arraycopy(GREYSCALE04, 0, greypattern, 0, 32); - break; - case 5: - System.arraycopy(GREYSCALE05, 0, greypattern, 0, 32); - break; - case 6: - System.arraycopy(GREYSCALE06, 0, greypattern, 0, 32); - break; - case 7: - System.arraycopy(GREYSCALE07, 0, greypattern, 0, 32); - break; - case 8: - System.arraycopy(GREYSCALE08, 0, greypattern, 0, 32); - break; - case 9: - System.arraycopy(GREYSCALE09, 0, greypattern, 0, 32); - break; - case 10: - System.arraycopy(GREYSCALE10, 0, greypattern, 0, 32); - break; - case 11: - System.arraycopy(GREYSCALE11, 0, greypattern, 0, 32); - break; - case 12: - System.arraycopy(GREYSCALE12, 0, greypattern, 0, 32); - break; - case 13: - System.arraycopy(GREYSCALE13, 0, greypattern, 0, 32); - break; - case 14: - System.arraycopy(GREYSCALE14, 0, greypattern, 0, 32); - break; - case 15: - System.arraycopy(GREYSCALE15, 0, greypattern, 0, 32); - break; - case 16: - System.arraycopy(GREYSCALE16, 0, greypattern, 0, 32); - break; - default : - System.arraycopy(GREYSCALE00, 0, greypattern, 0, 32); - break; - } - - for (int i = 0; i < repeat; i++) { - System.arraycopy(greypattern, 0, rasterdata, i * 32, 32); - } - return rasterdata; - } -} diff --git a/src/java/org/apache/fop/render/afp/ioca/ImageSegment.java b/src/java/org/apache/fop/render/afp/ioca/ImageSegment.java deleted file mode 100644 index 8f6e6a59c..000000000 --- a/src/java/org/apache/fop/render/afp/ioca/ImageSegment.java +++ /dev/null @@ -1,161 +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.render.afp.ioca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.modca.AbstractNamedAFPObject; -import org.apache.fop.render.afp.modca.Factory; - -/** - * An Image Segment is represented by a set of self-defining fields, fields - * that describe their own contents. It starts with a Begin Segment, and - * ends with an End Segment. - * - * Between the Begin Segment and End Segment is the image information to - * be processed, called the Image Content. - * - * Only one Image Content can exist within a single IOCA Image Segment. - */ -public class ImageSegment extends AbstractNamedAFPObject { - - /** - * The ImageContent for the image segment - */ - private ImageContent imageContent = null; - - private final Factory factory; - - /** - * Constructor for the image segment with the specified name, - * the name must be a fixed length of eight characters. - * @param factory the object factory - * - * @param name the name of the image. - */ - public ImageSegment(Factory factory, String name) { - super(name); - this.factory = factory; - } - - private ImageContent getImageContent() { - if (imageContent == null) { - this.imageContent = factory.createImageContent(); - } - return imageContent; - } - - /** - * Sets the image size parameters resolution, hsize and vsize. - * - * @param hsize The horizontal size of the image. - * @param vsize The vertical size of the image. - * @param hresol The horizontal resolution of the image. - * @param vresol The vertical resolution of the image. - */ - public void setImageSize(int hsize, int vsize, int hresol, int vresol) { - ImageSizeParameter imageSizeParameter - = factory.createImageSizeParameter(hsize, vsize, hresol, vresol); - getImageContent().setImageSizeParameter(imageSizeParameter); - } - - /** - * Sets the image encoding. - * - * @param encoding The image encoding. - */ - public void setEncoding(byte encoding) { - getImageContent().setImageEncoding(encoding); - } - - /** - * Sets the image compression. - * - * @param compression The image compression. - */ - public void setCompression(byte compression) { - getImageContent().setImageCompression(compression); - } - - /** - * Sets the image IDE size. - * - * @param size The IDE size. - */ - public void setIDESize(byte size) { - getImageContent().setImageIDESize(size); - } - - /** - * Sets the image IDE color model. - * - * @param colorModel the IDE color model. - */ - public void setIDEColorModel(byte colorModel) { - getImageContent().setImageIDEColorModel(colorModel); - } - - /** - * Set the data image data. - * - * @param data the image data - */ - public void setData(byte[] data) { - getImageContent().setImageData(data); - } - - /** {@inheritDoc} */ - public void writeContent(OutputStream os) throws IOException { - if (imageContent != null) { - imageContent.writeToStream(os); - } - } - - private static final int NAME_LENGTH = 4; - - /** {@inheritDoc} */ - protected int getNameLength() { - return NAME_LENGTH; - } - - /** {@inheritDoc} */ - protected void writeStart(OutputStream os) throws IOException { - byte[] nameBytes = getNameBytes(); - byte[] data = new byte[] { - 0x70, // ID - 0x04, // Length - nameBytes[0], // Name byte 1 - nameBytes[1], // Name byte 2 - nameBytes[2], // Name byte 3 - nameBytes[3], // Name byte 4 - }; - os.write(data); - } - - /** {@inheritDoc} */ - protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[] { - 0x71, // ID - 0x00, // Length - }; - os.write(data); - } -} diff --git a/src/java/org/apache/fop/render/afp/ioca/ImageSizeParameter.java b/src/java/org/apache/fop/render/afp/ioca/ImageSizeParameter.java deleted file mode 100644 index e2c408200..000000000 --- a/src/java/org/apache/fop/render/afp/ioca/ImageSizeParameter.java +++ /dev/null @@ -1,88 +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.render.afp.ioca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.modca.AbstractAFPObject; -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * Describes the measurement characteristics of the image when it is created. - */ -public class ImageSizeParameter extends AbstractAFPObject { - - private int hSize = 0; - private int vSize = 0; - private int hRes = 0; - private int vRes = 0; - - /** - * Constructor for a ImageSizeParameter for the specified - * resolution, hsize and vsize. - * - * @param hsize The horizontal size of the image. - * @param vsize The vertical size of the image. - * @param hresol The horizontal resolution of the image. - * @param vresol The vertical resolution of the image. - */ - public ImageSizeParameter(int hsize, int vsize, int hresol, int vresol) { - this.hSize = hsize; - this.vSize = vsize; - this.hRes = hresol; - this.vRes = vresol; - } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - byte[] data = new byte[] { - (byte)0x94, // ID = Image Size Parameter - 0x09, // Length - 0x00, // Unit base - 10 Inches - 0x00, // HRESOL - 0x00, // - 0x00, // VRESOL - 0x00, // - 0x00, // HSIZE - 0x00, // - 0x00, // VSIZE - 0x00, // - }; - - byte[] x = BinaryUtils.convert(hRes, 2); - data[3] = x[0]; - data[4] = x[1]; - - byte[] y = BinaryUtils.convert(vRes, 2); - data[5] = y[0]; - data[6] = y[1]; - - byte[] w = BinaryUtils.convert(hSize, 2); - data[7] = w[0]; - data[8] = w[1]; - - byte[] h = BinaryUtils.convert(vSize, 2); - data[9] = h[0]; - data[10] = h[1]; - - os.write(data); - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java deleted file mode 100644 index 87ae21cda..000000000 --- a/src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java +++ /dev/null @@ -1,244 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.Collection; -import java.util.Iterator; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.fop.render.afp.Streamable; - -/** - * This is the base class for all data stream objects. Page objects are - * responsible for building and generating the binary datastream in an - * AFP format. - */ -public abstract class AbstractAFPObject implements Streamable { - - /** Static logging instance */ - protected static final Log log = LogFactory.getLog("org.apache.fop.render.afp.modca"); - - /** the structured field class id */ - protected static final byte SF_CLASS = (byte)0xD3; - - private static final byte[] SF_HEADER = new byte[] { - 0x5A, // Structured field identifier - 0x00, // Length byte 1 - 0x10, // Length byte 2 - SF_CLASS, // Structured field id byte 1 - (byte) 0x00, // Structured field id byte 2 - (byte) 0x00, // Structured field id byte 3 - 0x00, // Flags - 0x00, // Reserved - 0x00, // Reserved - }; - - /** - * Copies the template structured field data array to the given byte array - * - * @param data the structured field data byte array - * @param type the type code - * @param category the category code - */ - protected void copySF(byte[] data, byte type, byte category) { - copySF(data, SF_CLASS, type, category); - } - - /** - * Copies the template structured field data array to the given byte array - * - * @param data the structured field data byte array - * @param clazz the class code - * @param type the type code - * @param category the category code - */ - protected static void copySF(byte[] data, byte clazz, byte type, byte category) { - System.arraycopy(SF_HEADER, 0, data, 0, SF_HEADER.length); - data[3] = clazz; - data[4] = type; - data[5] = category; - } - - /** - * Help method to write a set of AFPObjects to the AFP datastream. - * - * @param objects a list of AFPObjects - * @param os The stream to write to - * @throws java.io.IOException an I/O exception of some sort has occurred. - */ - protected void writeObjects(Collection/**/ objects, OutputStream os) - throws IOException { - if (objects != null && objects.size() > 0) { - Iterator it = objects.iterator(); - while (it.hasNext()) { - Object object = it.next(); - if (object instanceof Streamable) { - ((Streamable)object).writeToStream(os); - it.remove(); // once written, immediately remove the object - } - } - } - } - - /** structured field type codes */ - public interface Type { - - /** Attribute */ - byte ATTRIBUTE = (byte)0x0A; - - /** Copy Count */ - byte COPY_COUNT = (byte)0xA2; - - /** Descriptor */ - byte DESCRIPTOR = (byte)0xA6; - - /** Control */ - byte CONTROL = (byte)0xA7; - - /** Begin */ - byte BEGIN = (byte)0xA8; - - /** End */ - byte END = (byte)0xA9; - - /** Map */ - byte MAP = (byte)0xAB; - - /** Position */ - byte POSITION = (byte)0xAC; - - /** Process */ - byte PROCESS = (byte)0xAD; - - /** Include */ - byte INCLUDE = (byte)0xAF; - - /** Table */ - byte TABLE = (byte)0xB0; - - /** Migration */ - byte MIGRATION = (byte)0xB1; - - /** Variable */ - byte VARIABLE = (byte)0xB2; - - /** Link */ - byte LINK = (byte)0xB4; - - /** Data */ - byte DATA = (byte)0xEE; - } - - /** structured field category codes */ - public interface Category { - - /** Page Segment */ - byte PAGE_SEGMENT = (byte)0x5F; - - /** Object Area */ - byte OBJECT_AREA = (byte)0x6B; - - /** Color Attribute Table */ - byte COLOR_ATTRIBUTE_TABLE = (byte)0x77; - - /** IM Image */ - byte IM_IMAGE = (byte)0x7B; - - /** Medium */ - byte MEDIUM = (byte)0x88; - - /** Coded Font */ - byte CODED_FONT = (byte)0x8A; - - /** Process Element */ - byte PROCESS_ELEMENT = (byte)0x90; - - /** Object Container */ - byte OBJECT_CONTAINER = (byte)0x92; - - /** Presentation Text */ - byte PRESENTATION_TEXT = (byte)0x9B; - - /** Index */ - byte INDEX = (byte)0xA7; - - /** Document */ - byte DOCUMENT = (byte)0xA8; - - /** Page Group */ - byte PAGE_GROUP = (byte)0xAD; - - /** Page */ - byte PAGE = (byte)0xAF; - - /** Graphics */ - byte GRAPHICS = (byte)0xBB; - - /** Data Resource */ - byte DATA_RESOURCE = (byte)0xC3; - - /** Document Environment Group (DEG) */ - byte DOCUMENT_ENVIRONMENT_GROUP = (byte)0xC4; - - /** Resource Group */ - byte RESOURCE_GROUP = (byte)0xC6; - - /** Object Environment Group (OEG) */ - byte OBJECT_ENVIRONMENT_GROUP = (byte)0xC7; - - /** Active Environment Group (AEG) */ - byte ACTIVE_ENVIRONMENT_GROUP = (byte)0xC9; - - /** Medium Map */ - byte MEDIUM_MAP = (byte)0xCC; - - /** Form Map */ - byte FORM_MAP = (byte)0xCD; - - /** Name Resource */ - byte NAME_RESOURCE = (byte)0xCE; - - /** Page Overlay */ - byte PAGE_OVERLAY = (byte)0xD8; - - /** Resource Environment Group (REG) */ - byte RESOURCE_ENVIROMENT_GROUP = (byte)0xD9; - - /** Overlay */ - byte OVERLAY = (byte)0xDF; - - /** Data Suppression */ - byte DATA_SUPRESSION = (byte)0xEA; - - /** Bar Code */ - byte BARCODE = (byte)0xEB; - - /** No Operation */ - byte NO_OPERATION = (byte)0xEE; - - /** Image */ - byte IMAGE = (byte)0xFB; - } - -} - diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java deleted file mode 100644 index b59af4157..000000000 --- a/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java +++ /dev/null @@ -1,107 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.AFPDataObjectInfo; -import org.apache.fop.render.afp.AFPObjectAreaInfo; -import org.apache.fop.render.afp.AFPResourceInfo; -import org.apache.fop.render.afp.AFPResourceLevel; - -/** - * Abstract base class used by the ImageObject and GraphicsObject which both - * have define an ObjectEnvironmentGroup - */ -public abstract class AbstractDataObject extends AbstractNamedAFPObject { - - /** the object environment group */ - protected ObjectEnvironmentGroup objectEnvironmentGroup = null; - - /** the object factory */ - protected final Factory factory; - - /** - * Named constructor - * - * @param factory the object factory - * @param name data object name - */ - public AbstractDataObject(Factory factory, String name) { - super(name); - this.factory = factory; - } - - /** - * Sets the object view port (area position and size). - * - * @param dataObjectInfo - * the object area info - */ - public void setViewport(AFPDataObjectInfo dataObjectInfo) { - AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo(); - - // object area descriptor - int width = objectAreaInfo.getWidth(); - int height = objectAreaInfo.getHeight(); - int widthRes = objectAreaInfo.getWidthRes(); - int heightRes = objectAreaInfo.getHeightRes(); - ObjectAreaDescriptor objectAreaDescriptor - = factory.createObjectAreaDescriptor(width, height, widthRes, heightRes); - getObjectEnvironmentGroup().setObjectAreaDescriptor(objectAreaDescriptor); - - // object area position - AFPResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); - AFPResourceLevel resourceLevel = resourceInfo.getLevel(); - ObjectAreaPosition objectAreaPosition = null; - if (resourceLevel.isInline()) { - int x = objectAreaInfo.getX(); - int y = objectAreaInfo.getY(); - int rotation = objectAreaInfo.getRotation(); - objectAreaPosition = factory.createObjectAreaPosition(x, y, rotation); - } else { - // positional values are specified in the oaOffset of the include object - objectAreaPosition = factory.createObjectAreaPosition(0, 0, 0); - } - getObjectEnvironmentGroup().setObjectAreaPosition(objectAreaPosition); - } - - /** - * Gets the ObjectEnvironmentGroup - * - * @return the object environment group - */ - public ObjectEnvironmentGroup getObjectEnvironmentGroup() { - if (objectEnvironmentGroup == null) { - this.objectEnvironmentGroup = factory.createObjectEnvironmentGroup(); - } - return objectEnvironmentGroup; - } - - /** {@inheritDoc} */ - protected void writeContent(OutputStream os) throws IOException { - super.writeContent(os); // write triplets - if (objectEnvironmentGroup != null) { - objectEnvironmentGroup.writeToStream(os); - } - } - -} diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractDescriptor.java b/src/java/org/apache/fop/render/afp/modca/AbstractDescriptor.java deleted file mode 100644 index 2ec5feac2..000000000 --- a/src/java/org/apache/fop/render/afp/modca/AbstractDescriptor.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.render.afp.modca; - -/** - * Base class for AFP descriptor objects - */ -public abstract class AbstractDescriptor extends AbstractStructuredAFPObject { - /** width of this descriptor */ - protected int width = 0; - /** height of this descriptor */ - protected int height = 0; - /** width resolution of this descriptor */ - protected int widthRes = 0; - /** height resolution of this descriptor */ - protected int heightRes = 0; - - /** - * Default constructor - */ - public AbstractDescriptor() { - } - - /** - * Constructor a PresentationTextDescriptor for the specified - * width and height. - * - * @param width The width of the page. - * @param height The height of the page. - * @param widthRes The width resolution of the page. - * @param heightRes The height resolution of the page. - */ - public AbstractDescriptor(int width, int height, int widthRes, int heightRes) { - this.width = width; - this.height = height; - this.widthRes = widthRes; - this.heightRes = heightRes; - } - - /** {@inheritDoc} */ - public String toString() { - return "width=" + width - + ", height=" + height - + ", widthRes=" + widthRes - + ", heightRes=" + heightRes; - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractEnvironmentGroup.java b/src/java/org/apache/fop/render/afp/modca/AbstractEnvironmentGroup.java deleted file mode 100644 index 7e81e4934..000000000 --- a/src/java/org/apache/fop/render/afp/modca/AbstractEnvironmentGroup.java +++ /dev/null @@ -1,101 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.List; - -/** - * A base class that encapsulates common features of - * ActiveEnvironmentGroup and ResourceEnvironmentGroup - */ -public abstract class AbstractEnvironmentGroup extends AbstractNamedAFPObject { - - /** - * The collection of MapPageOverlay objects - */ - protected List mapPageOverlays = null; - - /** - * Main constructor - * - * @param name the object name - */ - public AbstractEnvironmentGroup(String name) { - super(name); - } - - private List getMapPageOverlays() { - if (mapPageOverlays == null) { - mapPageOverlays = new java.util.ArrayList(); - } - return mapPageOverlays; - } - - /** - * Actually creates the MPO object. - * Also creates the supporting object (an IPO) - * - * @param name the name of the overlay to be used - */ - public void createOverlay(String name) { - MapPageOverlay mpo = getCurrentMapPageOverlay(); - if (mpo == null) { - mpo = new MapPageOverlay(); - getMapPageOverlays().add(mpo); - } - - try { - mpo.addOverlay(name); - } catch (MaximumSizeExceededException msee) { - mpo = new MapPageOverlay(); - getMapPageOverlays().add(mpo); - try { - mpo.addOverlay(name); - } catch (MaximumSizeExceededException ex) { - // Should never happen (but log just in case) - log.error("createOverlay():: resulted in a MaximumSizeExceededException"); - } - } - } - - /** - * Getter method for the most recent MapPageOverlay added to the - * Active Environment Group (returns null if no MapPageOverlay exist) - * - * @return the most recent Map Coded Font - */ - private MapPageOverlay getCurrentMapPageOverlay() { - if (mapPageOverlays != null && mapPageOverlays.size() > 0) { - return (MapPageOverlay) mapPageOverlays.get(mapPageOverlays.size() - 1); - } else { - return null; - } - } - - /** {@inheritDoc} */ - protected void writeContent(OutputStream os) throws IOException { - super.writeContent(os); - if (mapPageOverlays != null) { - writeObjects(mapPageOverlays, os); - } - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractNamedAFPObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractNamedAFPObject.java deleted file mode 100644 index 31a4b8430..000000000 --- a/src/java/org/apache/fop/render/afp/modca/AbstractNamedAFPObject.java +++ /dev/null @@ -1,111 +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.render.afp.modca; - -import java.io.UnsupportedEncodingException; - -import org.apache.fop.render.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 { - - private static final int DEFAULT_NAME_LENGTH = 8; - - /** - * The actual name of the object - */ - protected String name = null; - - /** - * Default constructor - */ - protected AbstractNamedAFPObject() { - } - - /** - * Constructor for the ActiveEnvironmentGroup, this takes a - * name parameter which should be 8 characters long. - * - * @param name the object name - */ - protected AbstractNamedAFPObject(String name) { - this.name = name; - } - - /** - * Returns the name length - * - * @return the name length - */ - protected int getNameLength() { - return DEFAULT_NAME_LENGTH; - } - - /** - * Returns the name as a byte array in EBCIDIC encoding - * - * @return the name as a byte array in EBCIDIC encoding - */ - protected byte[] getNameBytes() { - int nameLen = getNameLength(); - if (name.length() < nameLen) { - name = (name + " ").substring(0, nameLen); - } else if (name.length() > nameLen) { - String truncatedName = name.substring(0, nameLen); - log.warn("Constructor:: name '" + name + "'" - + " truncated to " + nameLen + " chars" - + " ('" + truncatedName + "')"); - } - byte[] nameBytes = null; - try { - nameBytes = name.getBytes(AFPConstants.EBCIDIC_ENCODING); - } catch (UnsupportedEncodingException usee) { - nameBytes = name.getBytes(); - log.warn( - "Constructor:: UnsupportedEncodingException translating the name " - + name); - } - return nameBytes; - } - - /** {@inheritDoc} */ - protected void copySF(byte[] data, byte type, byte category) { - super.copySF(data, type, category); - byte[] nameData = getNameBytes(); - System.arraycopy(nameData, 0, data, 9, nameData.length); - } - - /** - * Returns the name of this object - * - * @return the name of this object - */ - public String getName() { - return name; - } - - /** {@inheritDoc} */ - public String toString() { - return getName(); - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java deleted file mode 100644 index 6b03adee0..000000000 --- a/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java +++ /dev/null @@ -1,345 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.List; - -import org.apache.fop.render.afp.AFPLineDataInfo; -import org.apache.fop.render.afp.AFPTextDataInfo; -import org.apache.fop.render.afp.fonts.AFPFont; - -/** - * Pages contain the data objects that comprise a presentation document. Each - * page has a set of data objects associated with it. Each page within a - * document is independent from any other page, and each must establish its own - * environment parameters. - * - * The page is the level in the document component hierarchy that is used for - * printing or displaying a document's content. The data objects contained in - * the page envelope in the data stream are presented when the page is - * presented. Each data object has layout information associated with it that - * directs the placement and orientation of the data on the page. In addition, - * each page contains layout information that specifies the measurement units, - * page width, and page depth. - * - * A page is initiated by a begin page structured field and terminated by an end - * page structured field. Structured fields that define objects and active - * environment groups or that specify attributes of the page may be encountered - * in page state. - * - */ -public abstract class AbstractPageObject extends AbstractNamedAFPObject { - - /** The active environment group for the page */ - protected ActiveEnvironmentGroup activeEnvironmentGroup = null; - - /** The current presentation text object */ - private PresentationTextObject currentPresentationTextObject = null; - - /** The list of tag logical elements */ - protected List/**/ tagLogicalElements = null; - - /** The list of the include page segments */ - protected List/**/ includePageSegments = null; - - /** The list of objects within this resource container */ - protected List/**/ objects = new java.util.ArrayList(); - - /** The page width */ - private int width; - - /** The page height */ - private int height; - - /** The page rotation */ - protected int rotation = 0; - - /** The page state */ - protected boolean complete = false; - - /** The width resolution */ - private int widthRes; - - /** The height resolution */ - private int heightRes; - - /** the object factory */ - protected final Factory factory; - - /** - * Default constructor - * - * @param factory the object factory - */ - public AbstractPageObject(Factory factory) { - this.factory = factory; - } - - /** - * Main constructor - * - * @param factory the object factory - * @param name the name of this page object - */ - public AbstractPageObject(Factory factory, String name) { - super(name); - this.factory = factory; - } - - /** - * Construct a new page object for the specified name argument, the page - * name should be an 8 character identifier. - * - * @param factory - * the object factory. - * @param name - * the name of the page. - * @param width - * the width of the page. - * @param height - * the height of the page. - * @param rotation - * the rotation of the page. - * @param widthRes - * the width resolution of the page. - * @param heightRes - * the height resolution of the page. - */ - public AbstractPageObject(Factory factory, - String name, int width, int height, int rotation, - int widthRes, int heightRes) { - super(name); - - this.factory = factory; - this.width = width; - this.height = height; - this.rotation = rotation; - this.widthRes = widthRes; - this.heightRes = heightRes; - } - - /** - * 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 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) { - getActiveEnvironmentGroup().createFont(fontReference, font, size, 0); - } - - /** - * Helper method to create a line on the current page, this method delegates - * to the presentation text object in order to construct the line. - * - * @param lineDataInfo the line data information. - */ - public void createLine(AFPLineDataInfo lineDataInfo) { - getPresentationTextObject().createLineData(lineDataInfo); - } - - /** - * Helper method to create text on the current page, this method delegates - * to the presentation text object in order to construct the text. - * - * @param textDataInfo - * the afp text data - */ - public void createText(AFPTextDataInfo textDataInfo) { - getPresentationTextObject().createTextData(textDataInfo); - } - - /** - * Helper method to mark the end of the page. This should end the control - * sequence on the current presentation text object. - */ - public void endPage() { - if (currentPresentationTextObject != null) { - currentPresentationTextObject.endControlSequence(); - } - complete = true; - } - - /** - * Ends the presentation text object - */ - protected void endPresentationObject() { - if (currentPresentationTextObject != null) { - currentPresentationTextObject.endControlSequence(); - currentPresentationTextObject = null; - } - } - - /** - * Helper method to create a presentation text object - * on the current page and to return the object. - * - * @return the presentation text object - */ - private PresentationTextObject getPresentationTextObject() { - if (currentPresentationTextObject == null) { - PresentationTextObject presentationTextObject - = factory.createPresentationTextObject(); - addObject(presentationTextObject); - this.currentPresentationTextObject = presentationTextObject; - } - return currentPresentationTextObject; - } - - /** - * Creates a TagLogicalElement on the page. - * - * @param name - * the name of the tag - * @param value - * the value of the tag - */ - public void createTagLogicalElement(String name, String value) { - TagLogicalElement tle = new TagLogicalElement(name, value); - if (tagLogicalElements == null) { - tagLogicalElements = new java.util.ArrayList/**/(); - } - tagLogicalElements.add(tle); - } - - /** - * Creates a NoOperation on the page. - * - * @param content the byte data - */ - public void createNoOperation(String content) { - addObject(new NoOperation(content)); - } - - /** - * Creates an IncludePageSegment on the current page. - * - * @param name - * the name of the page segment - * @param x - * the x coordinate of the page segment. - * @param y - * the y coordinate of the page segment. - */ - public void createIncludePageSegment(String name, int x, int y) { - IncludePageSegment ips = factory.createIncludePageSegment(name, x, y); - getIncludePageSegments().add(ips); - } - - /** - * Returns the include page segments list - * - * @return the include page segments list - */ - private List getIncludePageSegments() { - if (this.includePageSegments == null) { - this.includePageSegments = new java.util.ArrayList/**/(); - } - return this.includePageSegments; - } - - /** - * Returns the ActiveEnvironmentGroup associated with this page. - * - * @return the ActiveEnvironmentGroup object - */ - public ActiveEnvironmentGroup getActiveEnvironmentGroup() { - if (activeEnvironmentGroup == null) { - // every page object must have an ActiveEnvironmentGroup - this.activeEnvironmentGroup - = factory.createActiveEnvironmentGroup(width, height, widthRes, heightRes); - - if (rotation != 0) { - switch (rotation) { - case 90: - activeEnvironmentGroup.setObjectAreaPosition(width, 0, rotation); - break; - case 180: - activeEnvironmentGroup.setObjectAreaPosition(width, height, rotation); - break; - case 270: - activeEnvironmentGroup.setObjectAreaPosition(0, height, rotation); - break; - default: - } - } - } - 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 - * - * @return the height of the page - */ - public int getHeight() { - return height; - } - - /** - * Returns the width of the page - * - * @return the width of the page - */ - public int getWidth() { - return width; - } - - /** - * Returns the rotation of the page - * - * @return the rotation of the page - */ - public int getRotation() { - return rotation; - } - - /** {@inheritDoc} */ - protected void writeContent(OutputStream os) throws IOException { - super.writeContent(os); - writeObjects(this.objects, os); - } - - /** - * Adds an AFP object reference to this page - * - * @param obj an AFP object - */ - public void addObject(Object obj) { - objects.add(obj); - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractPreparedAFPObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractPreparedAFPObject.java deleted file mode 100644 index 42b729cf0..000000000 --- a/src/java/org/apache/fop/render/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.render.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/render/afp/modca/AbstractPreparedObjectContainer.java b/src/java/org/apache/fop/render/afp/modca/AbstractPreparedObjectContainer.java deleted file mode 100644 index 5d32a6b9b..000000000 --- a/src/java/org/apache/fop/render/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.render.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/render/afp/modca/AbstractResourceEnvironmentGroupContainer.java b/src/java/org/apache/fop/render/afp/modca/AbstractResourceEnvironmentGroupContainer.java deleted file mode 100644 index 1a5cc86d6..000000000 --- a/src/java/org/apache/fop/render/afp/modca/AbstractResourceEnvironmentGroupContainer.java +++ /dev/null @@ -1,97 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; - - -/** - * An abstract class which encapsulates the common features of - * Document and PageGroup resource containers - */ -public abstract class AbstractResourceEnvironmentGroupContainer - extends AbstractResourceGroupContainer { - - /** - * The resource environment group used to store complex resources - */ - protected ResourceEnvironmentGroup resourceEnvironmentGroup = null; - - /** - * Main constructor - * - * @param factory the object factory - * @param name the name of this resource container - */ - public AbstractResourceEnvironmentGroupContainer( - Factory factory, String name) { - super(factory, name); - } - - /** - * Adds a page to the resource container. - * - * @param page - the Page object - */ - public void addPage(PageObject page) { - addObject(page); - } - - /** - * Adds a PageGroup to the resource container. - * - * @param pageGroup the PageGroup object - */ - public void addPageGroup(PageGroup pageGroup) { - addObject(pageGroup); - } - - /** - * Creates an InvokeMediaMap on the page. - * - * @param name - * the name of the media map - */ - public void createInvokeMediumMap(String name) { - InvokeMediumMap invokeMediumMap = factory.createInvokeMediumMap(name); - addObject(invokeMediumMap); - } - - /** {@inheritDoc} */ - protected void writeContent(OutputStream os) throws IOException { - super.writeContent(os); - if (resourceEnvironmentGroup != null) { - resourceEnvironmentGroup.writeToStream(os); - } - } - - /** - * Returns the resource environment group - * - * @return the resource environment group - */ - protected ResourceEnvironmentGroup getResourceEnvironmentGroup() { - if (resourceEnvironmentGroup == null) { - this.resourceEnvironmentGroup = factory.createResourceEnvironmentGroup(); - } - return this.resourceEnvironmentGroup; - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractResourceGroupContainer.java b/src/java/org/apache/fop/render/afp/modca/AbstractResourceGroupContainer.java deleted file mode 100644 index 9a29f7486..000000000 --- a/src/java/org/apache/fop/render/afp/modca/AbstractResourceGroupContainer.java +++ /dev/null @@ -1,166 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.Collection; -import java.util.Iterator; - -import org.apache.fop.render.afp.Streamable; - - -/** - * An abstract container of resource objects - */ -public abstract class AbstractResourceGroupContainer extends AbstractPageObject -implements Streamable { - - /** The container started state */ - protected boolean started = false; - - /** the resource group object */ - protected ResourceGroup resourceGroup = null; - - /** - * Default constructor - * - * @param factory the object factory - */ - public AbstractResourceGroupContainer(Factory factory) { - super(factory); - } - - /** - * Named constructor - * - * @param factory the object factory - * @param name the name of this resource container - */ - public AbstractResourceGroupContainer(Factory factory, String name) { - super(factory, name); - } - - /** - * Construct a new page object for the specified name argument, the page - * name should be an 8 character identifier. - * - * @param factory - * the object factory - * @param name - * the name of the page. - * @param width - * the width of the page. - * @param height - * the height of the page. - * @param rotation - * the rotation of the page. - * @param widthRes - * the width resolution of the page. - * @param heightRes - * the height resolution of the page. - */ - public AbstractResourceGroupContainer(Factory factory, - String name, int width, int height, int rotation, int widthRes, int heightRes) { - super(factory, name, width, height, rotation, widthRes, heightRes); - } - - /** - * Return the number of resources in this container - * - * @return the number of resources in this container - */ - protected int getResourceCount() { - if (resourceGroup != null) { - return resourceGroup.getResourceCount(); - } - return 0; - } - - /** - * Returns true if this resource group container contains resources - * - * @return true if this resource group container contains resources - */ - protected boolean hasResources() { - return resourceGroup != null && resourceGroup.getResourceCount() > 0; - } - - /** - * Returns the resource group in this resource group container - * - * @return the resource group in this resource group container - */ - protected ResourceGroup getResourceGroup() { - if (resourceGroup == null) { - resourceGroup = factory.createResourceGroup(); - } - return resourceGroup; - } - -// /** {@inheritDoc} */ -// protected void writeContent(OutputStream os) throws IOException { -// if (resourceGroup != null) { -// resourceGroup.writeToStream(os); -// } -// super.writeContent(os); -// } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - if (!started) { - writeStart(os); - started = true; - } - - writeContent(os); - - if (complete) { - writeEnd(os); - } - } - - /** {@inheritDoc} */ - protected void writeObjects(Collection/**/ objects, OutputStream os) - throws IOException { - if (objects != null && objects.size() > 0) { - Iterator it = objects.iterator(); - while (it.hasNext()) { - AbstractAFPObject ao = (AbstractAFPObject)it.next(); - if (canWrite(ao)) { - ao.writeToStream(os); - it.remove(); - } else { - break; - } - } - } - } - - /** - * Returns true if this object can be written - * - * @param obj an AFP object - * @return true if this object can be written - */ - protected boolean canWrite(AbstractAFPObject obj) { - return obj instanceof AbstractPageObject && ((AbstractPageObject)obj).isComplete(); - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java deleted file mode 100644 index 89b7f8cdb..000000000 --- a/src/java/org/apache/fop/render/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.render.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.render.afp.modca.Registry.ObjectType; -import org.apache.fop.render.afp.modca.triplets.FullyQualifiedNameTriplet; -import org.apache.fop.render.afp.modca.triplets.ObjectClassificationTriplet; -import org.apache.fop.render.afp.modca.triplets.Triplet; -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * 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/render/afp/modca/ActiveEnvironmentGroup.java b/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java deleted file mode 100644 index da418aca6..000000000 --- a/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java +++ /dev/null @@ -1,220 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.List; - -import org.apache.fop.render.afp.fonts.AFPFont; - -/** - * An Active Environment Group (AEG) is associated with each page, - * and is contained in the page's begin-end envelope in the data stream. - * The active environment group contains layout and formatting information - * that defines the measurement units and size of the page, and may contain - * resource information. - * - * Any objects that are required for page presentation and that are to be - * treated as resource objects must be mapped with a map structured field - * in the AEG. The scope of an active environment group is the scope of its - * containing page or overlay. - * - */ -public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { - - /** The collection of MapCodedFont objects */ - private final List/**/ mapCodedFonts - = new java.util.ArrayList/**/(); - - /** the collection of MapDataResource objects */ - private final List mapDataResources = null; - - /** the Object Area Descriptor for the active environment group */ - private ObjectAreaDescriptor objectAreaDescriptor = null; - - /** the Object Area Position for the active environment group */ - private ObjectAreaPosition objectAreaPosition = null; - - /** the PresentationTextDescriptor for the active environment group */ - private PresentationTextDescriptor presentationTextDataDescriptor = null; - - /** the PageDescriptor for the active environment group */ - private PageDescriptor pageDescriptor = null; - - /** the resource manager */ - private final Factory factory; - - /** - * Constructor for the ActiveEnvironmentGroup, this takes a - * name parameter which must be 8 characters long. - * - * @param factory the object factory - * @param name the active environment group name - * @param width the page width - * @param height the page height - * @param widthRes the page width resolution - * @param heightRes the page height resolution - */ - public ActiveEnvironmentGroup(Factory factory, - String name, int width, int height, int widthRes, int heightRes) { - super(name); - - this.factory = factory; - - // Create PageDescriptor - this.pageDescriptor - = factory.createPageDescriptor(width, height, widthRes, heightRes); - - // Create ObjectAreaDescriptor - this.objectAreaDescriptor - = factory.createObjectAreaDescriptor(width, height, widthRes, heightRes); - - // Create PresentationTextDataDescriptor - this.presentationTextDataDescriptor - = factory.createPresentationTextDataDescriptor(width, height, - widthRes, heightRes); - } - - /** - * Set the position of the object area - * - * @param x the x offset - * @param y the y offset - * @param rotation the rotation - */ - public void setObjectAreaPosition(int x, int y, int rotation) { - this.objectAreaPosition = factory.createObjectAreaPosition(x, y, rotation); - } - - /** - * Accessor method to obtain the PageDescriptor object of the - * active environment group. - * - * @return the page descriptor object - */ - public PageDescriptor getPageDescriptor() { - return pageDescriptor; - } - - /** - * Accessor method to obtain the PresentationTextDataDescriptor object of - * the active environment group. - * - * @return the presentation text descriptor - */ - public PresentationTextDescriptor getPresentationTextDataDescriptor() { - return presentationTextDataDescriptor; - } - - /** {@inheritDoc} */ - public void writeContent(OutputStream os) throws IOException { - super.writeTriplets(os); - - writeObjects(mapCodedFonts, os); - writeObjects(mapDataResources, os); - writeObjects(mapPageOverlays, os); - - if (pageDescriptor != null) { - pageDescriptor.writeToStream(os); - } - if (objectAreaDescriptor != null && objectAreaPosition != null) { - objectAreaDescriptor.writeToStream(os); - objectAreaPosition.writeToStream(os); - } - if (presentationTextDataDescriptor != null) { - presentationTextDataDescriptor.writeToStream(os); - } - } - - /** {@inheritDoc} */ - protected void writeStart(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.BEGIN, Category.ACTIVE_ENVIRONMENT_GROUP); - os.write(data); - } - - /** {@inheritDoc} */ - protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.END, Category.ACTIVE_ENVIRONMENT_GROUP); - os.write(data); - } - - /** - * Method to create a map coded font object - * - * @param fontRef the font number used as the resource identifier - * @param font the font - * @param size the point size of the font - * @param orientation the orientation of the font (e.g. 0, 90, 180, 270) - */ - public void createFont(int fontRef, AFPFont font, int size, int orientation) { - MapCodedFont mapCodedFont = getCurrentMapCodedFont(); - if (mapCodedFont == null) { - mapCodedFont = factory.createMapCodedFont(); - mapCodedFonts.add(mapCodedFont); - } - - try { - mapCodedFont.addFont(fontRef, font, size, orientation); - } catch (MaximumSizeExceededException msee) { - mapCodedFont = factory.createMapCodedFont(); - mapCodedFonts.add(mapCodedFont); - - try { - mapCodedFont.addFont(fontRef, font, size, orientation); - } catch (MaximumSizeExceededException ex) { - // Should never happen (but log just in case) - log.error("createFont():: resulted in a MaximumSizeExceededException"); - } - } - } - - /** - * Getter method for the most recent MapCodedFont added to the - * Active Environment Group (returns null if no MapCodedFonts exist) - * - * @return the most recent Map Coded Font. - */ - private MapCodedFont getCurrentMapCodedFont() { - int size = mapCodedFonts.size(); - if (size > 0) { - return (MapCodedFont)mapCodedFonts.get(size - 1); - } else { - return null; - } - } - -// private List getMapDataResources() { -// if (mapDataResources == null) { -// mapDataResources = new java.util.ArrayList(); -// } -// return mapDataResources; -//} - -// /** -// * Method to create a map data resource object -// * @param dataObjectAccessor a data object accessor -// */ -// protected void createMapDataResource(DataObjectAccessor dataObjectAccessor) { -// getMapDataResources().add(new MapDataResource(dataObjectAccessor)); -// } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/ContainerDataDescriptor.java b/src/java/org/apache/fop/render/afp/modca/ContainerDataDescriptor.java deleted file mode 100644 index 224b25112..000000000 --- a/src/java/org/apache/fop/render/afp/modca/ContainerDataDescriptor.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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * Container data descriptor (to maintain compatibility with pre-year 2000 applications) - */ -public class ContainerDataDescriptor extends AbstractDescriptor { - - /** - * Main constructor - * - * @param width the container data width - * @param height the container data height - * @param widthRes the container width resolution - * @param heightRes the container height resolution - */ - public ContainerDataDescriptor(int width, int height, int widthRes, - int heightRes) { - super(width, height, widthRes, heightRes); - } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - byte[] data = new byte[21]; - copySF(data, Type.DESCRIPTOR, Category.OBJECT_CONTAINER); - - // SF length - byte[] len = BinaryUtils.convert(data.length - 1, 2); - data[1] = len[0]; - data[2] = len[1]; - - // XocBase = 10 inches - data[9] = 0x00; - - // YocBase = 10 inches - data[10] = 0x00; - - // XocUnits - byte[] xdpi = BinaryUtils.convert(widthRes * 10, 2); - data[11] = xdpi[0]; - data[12] = xdpi[1]; - - // YocUnits - byte[] ydpi = BinaryUtils.convert(heightRes * 10, 2); - data[13] = ydpi[0]; - data[14] = ydpi[1]; - - // XocSize - byte[] xsize = BinaryUtils.convert(width, 3); - data[15] = xsize[0]; - data[16] = xsize[1]; - data[17] = xsize[2]; - - // YocSize - byte[] ysize = BinaryUtils.convert(height, 3); - data[18] = ysize[0]; - data[19] = ysize[1]; - data[20] = ysize[2]; - } - -} diff --git a/src/java/org/apache/fop/render/afp/modca/DataStream.java b/src/java/org/apache/fop/render/afp/modca/DataStream.java deleted file mode 100644 index 2f5336f20..000000000 --- a/src/java/org/apache/fop/render/afp/modca/DataStream.java +++ /dev/null @@ -1,636 +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.render.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.render.afp.AFPFontAttributes; -import org.apache.fop.render.afp.AFPLineDataInfo; -import org.apache.fop.render.afp.AFPResourceLevel; -import org.apache.fop.render.afp.AFPState; -import org.apache.fop.render.afp.AFPTextDataInfo; -import org.apache.fop.render.afp.fonts.AFPFont; -import org.apache.fop.render.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 Log log = LogFactory.getLog("org.apache.fop.render.afp.modca"); - - /** Boolean completion indicator */ - private boolean complete = false; - - /** The application producing the AFP document */ - // not used - // private String producer = null; - - /** 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 portrait rotation */ -// private int portraitRotation = 0; -// -// /** The landscape rotation */ -// private int landscapeRotation = 270; - - /** 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 state */ - private final AFPState state; - - /** - * Default constructor for the AFPDocumentStream. - * - * @param factory the resource factory - * @param state the afp state - * @param outputStream the outputstream to write to - */ - public DataStream(Factory factory, AFPState 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; - } - - /** - * Sets the rotation to be used for portrait pages, valid values are 0 - * (default), 90, 180, 270. - * - * @param pageRotation the rotation in degrees. - * @deprecated not used - */ - public void setPortraitRotation(int pageRotation) { - } - - /** - * Sets the rotation to be used for landscape pages, valid values are 0, 90, - * 180, 270 (default). - * - * @param pageRotation the rotation in degrees. - * @deprecated not used - */ - public void setLandscapeRotation(int pageRotation) { - } - - /** - * Sets the offsets to be used for element positioning - * - * @param xOff - * the offset in the x direction - * @param yOff - * the offset in the y direction - * @param orientation - * the orientation - * @deprecated not used - */ - public void setOffsets(int xOff, int yOff, int orientation) { - } - -} diff --git a/src/java/org/apache/fop/render/afp/modca/Document.java b/src/java/org/apache/fop/render/afp/modca/Document.java deleted file mode 100644 index 30fa8e557..000000000 --- a/src/java/org/apache/fop/render/afp/modca/Document.java +++ /dev/null @@ -1,98 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; - -/** - * The document is the highest level of the MO:DCA data-stream document - * component hierarchy. Documents can be made up of pages, and the pages, which - * are at the intermediate level, can be made up of objects. Objects are at the - * lowest level, and can be bar codes, graphics, images, and presentation text. - * - * At each level of the hierarchy certain sets of MO:DCA data structures, called - * structured fields, are permissible. The document, pages and objects are - * bounded by structured fields that define their beginnings and their ends. - * These structured fields, called begin-end pairs, provide an envelope for the - * data-stream components. This feature enables a processor of the data stream - * that is not fully compliant with the architecture to bypass those objects - * that are beyond its scope, and to process the data stream to the best of its - * abilities. - * - * A presentation document is one that has been formatted and is intended for - * presentation, usually on a printer or display device. A data stream - * containing a presentation document should produce the same document content - * in the same format on different printers or display devices dependent, - * however, on the capabilities of each of the printers or display devices. A - * presentation document can reference resources that are to be included as part - * of the document to be presented. - * - */ -public final class Document extends AbstractResourceEnvironmentGroupContainer { - - /** - * Constructor for the document object. - * - * @param factory - * the object factory - * @param name - * the name of the document - */ - public Document(Factory factory, String name) { - super(factory, name); - } - - /** - * Method to mark the end of the page group. - */ - public void endDocument() { - complete = true; - } - - /** - * Returns an indication if the page group is complete - * - * @return whether or not this page group is complete - */ - public boolean isComplete() { - return complete; - } - - /** {@inheritDoc} */ - protected void writeStart(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.BEGIN, Category.DOCUMENT); - os.write(data); - } - - /** {@inheritDoc} */ - protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.END, Category.DOCUMENT); - os.write(data); - } - - /** {@inheritDoc} */ - public String toString() { - return this.name; - } - -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/Factory.java b/src/java/org/apache/fop/render/afp/modca/Factory.java deleted file mode 100644 index 468912b50..000000000 --- a/src/java/org/apache/fop/render/afp/modca/Factory.java +++ /dev/null @@ -1,606 +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.render.afp.modca; - -import java.io.OutputStream; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.fop.render.afp.AFPState; -import org.apache.fop.render.afp.goca.GraphicsData; -import org.apache.fop.render.afp.ioca.ImageContent; -import org.apache.fop.render.afp.ioca.ImageRasterData; -import org.apache.fop.render.afp.ioca.ImageSegment; -import org.apache.fop.render.afp.ioca.ImageSizeParameter; -import org.apache.fop.render.afp.tools.StringUtils; - -/** - * Creator of MO:DCA data objects (mostly) - */ -public class Factory { - - /** Static logging instance */ - private static final Log log = LogFactory.getLog(Factory.class); - - private static final String OBJECT_ENVIRONMENT_GROUP_NAME_PREFIX = "OEG"; - - private static final String ACTIVE_ENVIRONMENT_GROUP_NAME_PREFIX = "AEG"; - - private static final String IMAGE_NAME_PREFIX = "IMG"; - - private static final String GRAPHIC_NAME_PREFIX = "GRA"; - - private static final String BARCODE_NAME_PREFIX = "BAR"; - -// private static final String OTHER_NAME_PREFIX = "OTH"; - - private static final String OBJECT_CONTAINER_NAME_PREFIX = "OC"; - - private static final String RESOURCE_NAME_PREFIX = "RES"; - - private static final String RESOURCE_GROUP_NAME_PREFIX = "RG"; - - private static final String PAGE_GROUP_NAME_PREFIX = "PGP"; - - private static final String PAGE_NAME_PREFIX = "PGN"; - - private static final String OVERLAY_NAME_PREFIX = "OVL"; - - private static final String PRESENTATION_TEXT_NAME_PREFIX = "PT"; - - private static final String DOCUMENT_NAME_PREFIX = "DOC"; - - private static final String IM_IMAGE_NAME_PREFIX = "IMIMG"; - - private static final String IMAGE_SEGMENT_NAME_PREFIX = "IS"; - - - /** the page group count */ - private int pageGroupCount = 0; - - /** the page count */ - private int pageCount = 0; - - /** the image count */ - private int imageCount = 0; - - /** the im image count */ - private int imImageCount = 0; - - /** the image segment count */ - private int imageSegmentCount = 0; - - /** the graphic count */ - private int graphicCount = 0; - - /** the object container count */ - private int objectContainerCount = 0; - - /** the resource count */ - private int resourceCount = 0; - - /** the resource group count */ - private int resourceGroupCount = 0; - - /** the overlay count */ - private int overlayCount = 0; - - /** the presentation text object count */ - private int textObjectCount = 0; - - /** the active environment group count */ - private int activeEnvironmentGroupCount = 0; - - /** the document count */ - private int documentCount = 0; - - /** the object environment group count */ - private int objectEnvironmentGroupCount = 0; - - /** - * Main constructor - */ - public Factory() { - } - - /** - * Creates a new IOCA {@link ImageObject} - * - * @return a new {@link ImageObject} - */ - public ImageObject createImageObject() { - String name = IMAGE_NAME_PREFIX - + StringUtils.lpad(String.valueOf(++imageCount), '0', 5); - ImageObject imageObject = new ImageObject(this, name); - return imageObject; - } - - /** - * Creates an IOCA {@link IMImageObject} - * - * @return a new {@link IMImageObject} - */ - public IMImageObject createIMImageObject() { - String name = IM_IMAGE_NAME_PREFIX - + StringUtils.lpad(String.valueOf(++imImageCount), '0', 3); - IMImageObject imImageObject = new IMImageObject(name); - return imImageObject; - } - - /** - * Creates a new GOCA {@link GraphicsObject} - * - * @return a new {@link GraphicsObject} - */ - public GraphicsObject createGraphicsObject() { - String name = GRAPHIC_NAME_PREFIX - + StringUtils.lpad(String.valueOf(++graphicCount), '0', 5); - GraphicsObject graphicsObj = new GraphicsObject(this, name); - return graphicsObj; - } - - /** - * Creates a new MO:DCA {@link ObjectContainer} - * - * @return a new {@link ObjectContainer} - */ - public ObjectContainer createObjectContainer() { - String name = OBJECT_CONTAINER_NAME_PREFIX - + StringUtils.lpad(String.valueOf(++objectContainerCount), '0', 6); - return new ObjectContainer(this, name); - } - - /** - * Creates a new MO:DCA {@link ResourceObject} - * - * @param resourceName the resource object name - * @return a new {@link ResourceObject} - */ - public ResourceObject createResource(String resourceName) { - return new ResourceObject(resourceName); - } - - /** - * Creates a new MO:DCA {@link ResourceObject} - * - * @return a new {@link ResourceObject} - */ - public ResourceObject createResource() { - String name = RESOURCE_NAME_PREFIX - + StringUtils.lpad(String.valueOf(++resourceCount), '0', 5); - return createResource(name); - } - - /** - * Creates a new MO:DCA {@link PageGroup} - * - * @return a new {@link PageGroup} - */ - public PageGroup createPageGroup() { - String name = PAGE_GROUP_NAME_PREFIX - + StringUtils.lpad(String.valueOf(++pageGroupCount), '0', 5); - return new PageGroup(this, name); - } - - /** - * Creates a new MO:DCA {@link ActiveEnvironmentGroup} - * - * @param width the page width - * @param height the page height - * @param widthRes the page width resolution - * @param heightRes the page height resolution - * @return a new {@link ActiveEnvironmentGroup} - */ - public ActiveEnvironmentGroup createActiveEnvironmentGroup( - int width, int height, int widthRes, int heightRes) { - String name = ACTIVE_ENVIRONMENT_GROUP_NAME_PREFIX - + StringUtils.lpad(String.valueOf(++activeEnvironmentGroupCount ), '0', 5); - return new ActiveEnvironmentGroup(this, name, width, height, widthRes, heightRes); - } - - /** - * Creates a new MO:DCA {@link ResourceGroup} - * - * @return a new {@link ResourceGroup} - */ - public ResourceGroup createResourceGroup() { - String name = RESOURCE_GROUP_NAME_PREFIX - + StringUtils.lpad(String.valueOf(++resourceGroupCount), '0', 6); - return new ResourceGroup(name); - } - - /** - * Creates a new MO:DCA {@link StreamedResourceGroup} - * - * @param os the outputstream of the streamed resource group - * @return a new {@link StreamedResourceGroup} - */ - public StreamedResourceGroup createStreamedResourceGroup(OutputStream os) { - String name = RESOURCE_GROUP_NAME_PREFIX - + StringUtils.lpad(String.valueOf(++resourceGroupCount), '0', 6); - return new StreamedResourceGroup(name, os); - } - - /** - * Creates a new MO:DCA {@link PageObject}. - * - * @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 - * - * @return a new {@link PageObject} - */ - public PageObject createPage(int pageWidth, int pageHeight, int pageRotation, - int pageWidthRes, int pageHeightRes) { - String pageName = PAGE_NAME_PREFIX - + StringUtils.lpad(String.valueOf(++pageCount), '0', 5); - return new PageObject(this, pageName, pageWidth, pageHeight, - pageRotation, pageWidthRes, pageHeightRes); - } - - - /** - * Creates a new MO:DCA {@link PresentationTextObject}. - * - * @return a new {@link PresentationTextObject} - */ - public PresentationTextObject createPresentationTextObject() { - String textObjectName = PRESENTATION_TEXT_NAME_PREFIX - + StringUtils.lpad(String.valueOf(++textObjectCount), '0', 6); - return new PresentationTextObject(textObjectName); - } - - - /** - * Creates a new MO:DCA {@link Overlay}. - * - * @param width - * the width of the overlay - * @param height - * the height of the overlay - * @param widthRes - * the width resolution of the overlay - * @param heightRes - * the height resolution of the overlay - * @param overlayRotation - * the rotation of the overlay - * - * @return a new {@link Overlay}. - */ - public Overlay createOverlay(int width, int height, - int widthRes, int heightRes, int overlayRotation) { - String overlayName = OVERLAY_NAME_PREFIX - + StringUtils.lpad(String.valueOf(++overlayCount), '0', 5); - Overlay overlay = new Overlay(this, overlayName, width, height, - overlayRotation, widthRes, heightRes); - return overlay; - } - - /** - * Creates a MO:DCA {@link Document} - * - * @return a new {@link Document} - */ - public Document createDocument() { - String documentName = DOCUMENT_NAME_PREFIX - + StringUtils.lpad(String.valueOf(++documentCount), '0', 5); - Document document = new Document(this, documentName); - return document; - } - - /** - * Creates a MO:DCA {@link MapCodedFont} - * - * @return a new {@link MapCodedFont} - */ - public MapCodedFont createMapCodedFont() { - MapCodedFont mapCodedFont = new MapCodedFont(); - return mapCodedFont; - } - - /** - * Creates a MO:DCA {@link IncludePageSegment} - * - * @param name the page segment name - * @param x the x coordinate - * @param y the y coordinate - * - * @return a new {@link IncludePageSegment} - */ - public IncludePageSegment createIncludePageSegment(String name, int x, int y) { - IncludePageSegment includePageSegment = new IncludePageSegment(name, x, y); - return includePageSegment; - } - - /** - * Creates a MO:DCA {@link IncludeObject} - * - * @param name the name of this include object - * @return a new {@link IncludeObject} - */ - public IncludeObject createInclude(String name) { - IncludeObject includeObject = new IncludeObject(name); - return includeObject; - } - - /** - * Creates a MO:DCA {@link TagLogicalElement} - * - * @param name name of the element - * @param value value of the element - * @return a new {@link TagLogicalElement} - */ - public TagLogicalElement createTagLogicalElement(String name, String value) { - TagLogicalElement tle = new TagLogicalElement(name, value); - return tle; - } - - /** - * Creates a new {@link DataStream} - * - * @param state the afp state - * @param outputStream an outputstream to write to - * @return a new {@link DataStream} - */ - public DataStream createDataStream(AFPState state, OutputStream outputStream) { - DataStream dataStream = new DataStream(this, state, outputStream); - return dataStream; - } - - /** - * Creates a new MO:DCA {@link PageDescriptor} - * - * @param width the page width. - * @param height the page height. - * @param widthRes the page width resolution. - * @param heightRes the page height resolution. - * @return a new {@link PageDescriptor} - */ - public PageDescriptor createPageDescriptor(int width, int height, int widthRes, int heightRes) { - PageDescriptor pageDescriptor = new PageDescriptor(width, height, widthRes, heightRes); - return pageDescriptor; - } - - /** - * Returns a new MO:DCA {@link ObjectEnvironmentGroup} - * - * @return a new {@link ObjectEnvironmentGroup} - */ - public ObjectEnvironmentGroup createObjectEnvironmentGroup() { - String oegName = OBJECT_ENVIRONMENT_GROUP_NAME_PREFIX - + StringUtils.lpad(String.valueOf(++objectEnvironmentGroupCount), '0', 5); - ObjectEnvironmentGroup objectEnvironmentGroup = new ObjectEnvironmentGroup(oegName); - return objectEnvironmentGroup; - } - - /** - * Creates a new GOCA {@link GraphicsData} - * - * @return a new {@link GraphicsData} - */ - public GraphicsData createGraphicsData() { - GraphicsData graphicsData = new GraphicsData(); - return graphicsData; - } - - /** - * Creates a new {@link ObjectAreaDescriptor} - * - * @param width the object width. - * @param height the object height. - * @param widthRes the object width resolution. - * @param heightRes the object height resolution. - * @return a new {@link ObjectAreaDescriptor} - */ - public ObjectAreaDescriptor createObjectAreaDescriptor( - int width, int height, int widthRes, int heightRes) { - ObjectAreaDescriptor objectAreaDescriptor - = new ObjectAreaDescriptor(width, height, widthRes, heightRes); - return objectAreaDescriptor; - } - - /** - * Creates a new {@link ObjectAreaPosition} - * - * @param x the x coordinate. - * @param y the y coordinate. - * @param rotation the coordinate system rotation (must be 0, 90, 180, 270). - * @return a new {@link ObjectAreaPosition} - */ - public ObjectAreaPosition createObjectAreaPosition(int x, int y, - int rotation) { - ObjectAreaPosition objectAreaPosition = new ObjectAreaPosition( - x, y, rotation); - return objectAreaPosition; - } - - /** - * Creates a new {@link ImageDataDescriptor} - * - * @param width the image width - * @param height the image height - * @param widthRes the x resolution of the image - * @param heightRes the y resolution of the image - * @return a new {@link ImageDataDescriptor} - */ - public ImageDataDescriptor createImageDataDescriptor( - int width, int height, int widthRes, int heightRes) { - ImageDataDescriptor imageDataDescriptor = new ImageDataDescriptor( - width, height, widthRes, heightRes); - return imageDataDescriptor; - } - - /** - * Creates a new GOCA {@link GraphicsDataDescriptor} - * - * @param xlwind the left edge of the graphics window - * @param xrwind the right edge of the graphics window - * @param ybwind the top edge of the graphics window - * @param ytwind the bottom edge of the graphics window - * @param widthRes the x resolution of the graphics window - * @param heightRes the y resolution of the graphics window - * @return a new {@link GraphicsDataDescriptor} - */ - public GraphicsDataDescriptor createGraphicsDataDescriptor( - int xlwind, int xrwind, int ybwind, int ytwind, int widthRes, int heightRes) { - GraphicsDataDescriptor graphicsDataDescriptor = new GraphicsDataDescriptor( - xlwind, xrwind, ybwind, ytwind, widthRes, heightRes); - return graphicsDataDescriptor; - } - - /** - * Creates a new MO:DCA {@link ContainerDataDescriptor} - * - * @param dataWidth the container data width - * @param dataHeight the container data height - * @param widthRes the container data width resolution - * @param heightRes the container data height resolution - * @return a new {@link ContainerDataDescriptor} - */ - public ContainerDataDescriptor createContainerDataDescriptor( - int dataWidth, int dataHeight, int widthRes, int heightRes) { - ContainerDataDescriptor containerDataDescriptor - = new ContainerDataDescriptor(dataWidth, dataHeight, widthRes, heightRes); - return containerDataDescriptor; - } - - /** - * Creates a new MO:DCA {@link MapContainerData} - * - * @param optionValue the option value - * @return a new {@link MapContainerData} - */ - public MapContainerData createMapContainerData(byte optionValue) { - MapContainerData mapContainerData = new MapContainerData(optionValue); - return mapContainerData; - } - - /** - * Creates a new MO:DCA {@link MapDataResource} - * - * @return a new {@link MapDataResource} - */ - public MapDataResource createMapDataResource() { - MapDataResource mapDataResource = new MapDataResource(); - return mapDataResource; - } - - /** - * Creates a new PTOCA {@link PresentationTextDescriptor} - * - * @return a new {@link PresentationTextDescriptor} - */ - public PresentationTextDescriptor createPresentationTextDataDescriptor( - int width, int height, int widthRes, int heightRes) { - PresentationTextDescriptor presentationTextDescriptor - = new PresentationTextDescriptor(width, height, - widthRes, heightRes); - return presentationTextDescriptor; - } - - /** - * Creates a new MO:DCA {@link PresentationEnvironmentControl} - * - * @return a new {@link PresentationEnvironmentControl} - */ - public PresentationEnvironmentControl createPresentationEnvironmentControl() { - PresentationEnvironmentControl presentationEnvironmentControl - = new PresentationEnvironmentControl(); - return presentationEnvironmentControl; - } - - /** - * Creates a new MO:DCA {@link InvokeMediumMap} - * - * @param name the object name - * @return a new {@link InvokeMediumMap} - */ - public InvokeMediumMap createInvokeMediumMap(String name) { - InvokeMediumMap invokeMediumMap = new InvokeMediumMap(name); - return invokeMediumMap; - } - - /** - * Creates a new MO:DCA {@link ResourceEnvironmentGroup} - * - * @return a new {@link ResourceEnvironmentGroup} - */ - public ResourceEnvironmentGroup createResourceEnvironmentGroup() { - ResourceEnvironmentGroup resourceEnvironmentGroup = new ResourceEnvironmentGroup(); - return resourceEnvironmentGroup; - } - - /** - * Creates a new IOCA {@link ImageSegment} - * - * @return a new {@link ImageSegment} - */ - public ImageSegment createImageSegment() { - String name = IMAGE_SEGMENT_NAME_PREFIX - + StringUtils.lpad(String.valueOf(++imageSegmentCount), '0', 2); - ImageSegment imageSegment = new ImageSegment(this, name); - return imageSegment; - } - - /** - * Creates an new IOCA {@link ImageContent} - * - * @return an {@link ImageContent} - */ - public ImageContent createImageContent() { - ImageContent imageContent = new ImageContent(); - return imageContent; - } - - /** - * Creates a new IOCA {@link ImageRasterData} - * - * @param rasterData raster data - * @return a new {@link ImageRasterData} - */ - public ImageRasterData createImageRasterData(byte[] rasterData) { - ImageRasterData imageRasterData = new ImageRasterData(rasterData); - return imageRasterData; - } - - /** - * Creates an new IOCA {@link ImageSizeParameter}. - * - * @param hsize The horizontal size of the image. - * @param vsize The vertical size of the image. - * @param hresol The horizontal resolution of the image. - * @param vresol The vertical resolution of the image. - * @return a new {@link ImageSizeParameter} - */ - public ImageSizeParameter createImageSizeParameter(int hsize, int vsize, - int hresol, int vresol) { - ImageSizeParameter imageSizeParameter - = new ImageSizeParameter(hsize, vsize, hresol, vresol); - return imageSizeParameter; - } - -} diff --git a/src/java/org/apache/fop/render/afp/modca/GraphicsDataDescriptor.java b/src/java/org/apache/fop/render/afp/modca/GraphicsDataDescriptor.java deleted file mode 100644 index 7ee0e07f5..000000000 --- a/src/java/org/apache/fop/render/afp/modca/GraphicsDataDescriptor.java +++ /dev/null @@ -1,152 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * GOCA Graphics Data Descriptor - */ -public class GraphicsDataDescriptor extends AbstractDescriptor { - - private final int xlwind; - - private final int xrwind; - - private final int ybwind; - - private final int ytwind; - - /** - * Main constructor - * - * @param xlwind - * the left edge of the graphics window - * @param xrwind - * the right edge of the graphics window - * @param ybwind - * the top edge of the graphics window - * @param ytwind - * the bottom edge of the graphics window - * @param widthRes - * the width resolution of the graphics window - * @param heightRes - * the height resolution of the graphics window - */ - protected GraphicsDataDescriptor(int xlwind, int xrwind, int ybwind, - int ytwind, int widthRes, int heightRes) { - this.xlwind = xlwind; - this.xrwind = xrwind; - this.ybwind = ybwind; - this.ytwind = ytwind; - super.widthRes = widthRes; - super.heightRes = heightRes; - } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - byte[] headerData = new byte[9]; - copySF(headerData, Type.DESCRIPTOR, Category.GRAPHICS); - - byte[] drawingOrderSubsetData = getDrawingOrderSubset(); - - byte[] windowSpecificationData = getWindowSpecification(); - - byte[] len = BinaryUtils.convert(headerData.length - + drawingOrderSubsetData.length - + windowSpecificationData.length - 1, 2); - headerData[1] = len[0]; - headerData[2] = len[1]; - - os.write(headerData); - os.write(drawingOrderSubsetData); - os.write(windowSpecificationData); - } - - /** - * Returns the drawing order subset data - * - * @return the drawing order subset data - */ - private byte[] getDrawingOrderSubset() { - final byte[] data = new byte[] { - // Drawing order subset - (byte) 0xF7, - 7, // LENGTH - (byte) 0xB0, // drawing order subset - 0x00, // reserved (must be zero) - 0x00, // reserved (must be zero) - 0x02, // SUBLEV - 0x00, // VERSION 0 - 0x01, // LENGTH (of following field) - 0x00 // GEOM - }; - return data; - } - - private static final int ABS = 2; - private static final int IMGRES = 8; - - /** - * Returns the window specification data - * - * @return the window specification data - */ - private byte[] getWindowSpecification() { - byte[] xlcoord = BinaryUtils.convert(xlwind, 2); - byte[] xrcoord = BinaryUtils.convert(xrwind, 2); - byte[] xbcoord = BinaryUtils.convert(ybwind, 2); - byte[] ytcoord = BinaryUtils.convert(ytwind, 2); - byte[] xResol = BinaryUtils.convert(widthRes * 10, 2); - byte[] yResol = BinaryUtils.convert(heightRes * 10, 2); - byte[] imxyres = xResol; - - // Window specification - final byte[] data = new byte[] { - (byte) 0xF6, - 18, // LENGTH - (ABS + IMGRES), // FLAGS (ABS) - 0x00, // reserved (must be zero) - 0x00, // CFORMAT (coordinate format - 16bit high byte first signed) - 0x00, // UBASE (unit base - ten inches) - - xResol[0], // XRESOL - xResol[1], - yResol[0], // YRESOL - yResol[1], - - imxyres[0], // IMXYRES (Number of image points per ten inches - imxyres[1], // in X and Y directions) - - xlcoord[0], // XLWIND - xlcoord[1], - xrcoord[0], // XRWIND - xrcoord[1], - xbcoord[0], // YBWIND - xbcoord[1], - ytcoord[0], // YTWIND - ytcoord[1] - }; - return data; - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/GraphicsObject.java b/src/java/org/apache/fop/render/afp/modca/GraphicsObject.java deleted file mode 100644 index 4d33b28de..000000000 --- a/src/java/org/apache/fop/render/afp/modca/GraphicsObject.java +++ /dev/null @@ -1,302 +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.render.afp.modca; - -import java.awt.Color; -import java.io.IOException; -import java.io.OutputStream; -import java.util.List; - -import org.apache.fop.render.afp.AFPDataObjectInfo; -import org.apache.fop.render.afp.AFPObjectAreaInfo; -import org.apache.fop.render.afp.goca.GraphicsBox; -import org.apache.fop.render.afp.goca.GraphicsData; -import org.apache.fop.render.afp.goca.GraphicsFillet; -import org.apache.fop.render.afp.goca.GraphicsFullArc; -import org.apache.fop.render.afp.goca.GraphicsLine; -import org.apache.fop.render.afp.goca.GraphicsSetArcParameters; -import org.apache.fop.render.afp.goca.GraphicsSetCharacterSet; -import org.apache.fop.render.afp.goca.GraphicsSetCurrentPosition; -import org.apache.fop.render.afp.goca.GraphicsSetLineType; -import org.apache.fop.render.afp.goca.GraphicsSetLineWidth; -import org.apache.fop.render.afp.goca.GraphicsSetPatternSymbol; -import org.apache.fop.render.afp.goca.GraphicsSetProcessColor; -import org.apache.fop.render.afp.goca.GraphicsString; - -/** - * Top-level GOCA graphics object. - * - * Acts as container and factory of all other graphic objects - */ -public class GraphicsObject extends AbstractDataObject { - - /** The graphics data */ - private GraphicsData currentGraphicsData = null; - - /** list of objects contained within this container */ - protected List/**/ objects - = new java.util.ArrayList/**/(); - - /** - * Default constructor - * - * @param factory the object factory - * @param name the name of graphics object - */ - public GraphicsObject(Factory factory, String name) { - super(factory, name); - } - - /** {@inheritDoc} */ - public void setViewport(AFPDataObjectInfo dataObjectInfo) { - super.setViewport(dataObjectInfo); - - AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo(); - int width = objectAreaInfo.getWidth(); - int height = objectAreaInfo.getHeight(); - int widthRes = objectAreaInfo.getWidthRes(); - int heightRes = objectAreaInfo.getHeightRes(); - final int leftEdge = 0; - final int topEdge = 0; - GraphicsDataDescriptor graphicsDataDescriptor = factory.createGraphicsDataDescriptor( - leftEdge, width, topEdge, height, widthRes, heightRes); - - getObjectEnvironmentGroup().setDataDescriptor(graphicsDataDescriptor); - } - - /** {@inheritDoc} */ - public void addObject(PreparedAFPObject drawingOrder) { - if (currentGraphicsData == null - || (currentGraphicsData.getDataLength() + drawingOrder.getDataLength()) - >= GraphicsData.MAX_DATA_LEN) { - newData(); - } - currentGraphicsData.addObject(drawingOrder); - } - - /** - * Gets the current graphics data, creating a new one if necessary - * - * @return the current graphics data - */ - private GraphicsData getData() { - if (this.currentGraphicsData == null) { - return newData(); - } - return this.currentGraphicsData; - } - - /** - * Creates a new graphics data - * - * @return a newly created graphics data - */ - private GraphicsData newData() { - this.currentGraphicsData = factory.createGraphicsData(); - objects.add(currentGraphicsData); - return currentGraphicsData; - } - - /** - * Sets the current color - * - * @param color the active color to use - */ - public void setColor(Color color) { - addObject(new GraphicsSetProcessColor(color)); - } - - /** - * Sets the current position - * - * @param coords the x and y coordinates of the current position - */ - public void setCurrentPosition(int[] coords) { - addObject(new GraphicsSetCurrentPosition(coords)); - } - - /** - * Sets the line width - * - * @param multiplier the line width multiplier - */ - public void setLineWidth(int multiplier) { - GraphicsSetLineWidth graphicsSetLineWidth = new GraphicsSetLineWidth(multiplier); - addObject(graphicsSetLineWidth); - } - - /** - * Sets the line type - * - * @param type the line type - */ - public void setLineType(byte type) { - GraphicsSetLineType graphicsSetLineType = new GraphicsSetLineType(type); - addObject(graphicsSetLineType); - } - - /** - * Sets whether to fill the next shape - * - * @param fill whether to fill the next shape - */ - public void setFill(boolean fill) { - GraphicsSetPatternSymbol graphicsSetPattern = new GraphicsSetPatternSymbol( - fill ? GraphicsSetPatternSymbol.SOLID_FILL - : GraphicsSetPatternSymbol.NO_FILL - ); - addObject(graphicsSetPattern); - } - - /** - * Sets the character set to use - * - * @param fontReference the character set (font) reference - */ - public void setCharacterSet(int fontReference) { - addObject(new GraphicsSetCharacterSet(fontReference)); - } - - /** - * Adds a line at the given x/y coordinates - * - * @param coords the x/y coordinates (can be a series) - */ - public void addLine(int[] coords) { - addObject(new GraphicsLine(coords)); - } - - /** - * Adds a box at the given coordinates - * - * @param coords the x/y coordinates - */ - public void addBox(int[] coords) { - addObject(new GraphicsBox(coords)); - } - - /** - * Adds a fillet (curve) at the given coordinates - * - * @param coords the x/y coordinates - */ - public void addFillet(int[] coords) { - addObject(new GraphicsFillet(coords)); - } - - /** - * Sets the arc parameters - * - * @param xmaj the maximum value of the x coordinate - * @param ymin the minimum value of the y coordinate - * @param xmin the minimum value of the x coordinate - * @param ymaj the maximum value of the y coordinate - */ - public void setArcParams(int xmaj, int ymin, int xmin, int ymaj) { - addObject(new GraphicsSetArcParameters(xmaj, ymin, xmin, ymaj)); - } - - /** - * Adds an arc - * - * @param x the x coordinate - * @param y the y coordinate - * @param mh the integer portion of the multiplier - * @param mhr the fractional portion of the multiplier - */ - public void addFullArc(int x, int y, int mh, int mhr) { - 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 a string - * - * @param str the string - * @param x the x coordinate - * @param y the y coordinate - */ - public void addString(String str, int x, int y) { - addObject(new GraphicsString(str, x, y)); - } - - /** - * Begins a graphics area (start of fill) - */ - public void beginArea() { - if (currentGraphicsData == null) { - newData(); - } - currentGraphicsData.beginArea(); - } - - /** - * Ends a graphics area (end of fill) - */ - public void endArea() { - if (currentGraphicsData != null) { - currentGraphicsData.endArea(); - } - } - - /** {@inheritDoc} */ - public String toString() { - return "GraphicsObject: " + getName(); - } - - /** - * Creates a new graphics segment - */ - public void newSegment() { - getData().newSegment(); - } - - /** {@inheritDoc} */ - protected void writeStart(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.BEGIN, Category.GRAPHICS); - os.write(data); - } - - /** {@inheritDoc} */ - protected void writeContent(OutputStream os) throws IOException { - super.writeContent(os); - super.writeObjects(objects, os); - } - - /** {@inheritDoc} */ - protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.END, Category.GRAPHICS); - os.write(data); - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/IMImageObject.java b/src/java/org/apache/fop/render/afp/modca/IMImageObject.java deleted file mode 100644 index 63fff8cdc..000000000 --- a/src/java/org/apache/fop/render/afp/modca/IMImageObject.java +++ /dev/null @@ -1,141 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.ioca.ImageCellPosition; -import org.apache.fop.render.afp.ioca.ImageInputDescriptor; -import org.apache.fop.render.afp.ioca.ImageOutputControl; -import org.apache.fop.render.afp.ioca.ImageRasterData; - -/** - * An IM image data object specifies the contents of a raster image and - * its placement on a page, overlay, or page segment. An IM image can be - * either simple or complex. A simple image is composed of one or more Image - * Raster Data (IRD) structured fields that define the raster pattern for the - * entire image. A complex image is divided into regions called image cells. - * Each image cell is composed of one or more IRD structured fields that define - * the raster pattern for the image cell, and one Image Cell Position (ICP) - * structured field that defines the position of the image cell relative to - * the origin of the entire image. Each ICP also specifies the size of the - * image cell and a fill rectangle into which the cell is replicated. - *

- */ -public class IMImageObject extends AbstractNamedAFPObject { - - /** - * The image output control - */ - private ImageOutputControl imageOutputControl = null; - - /** - * The image input descriptor - */ - private ImageInputDescriptor imageInputDescriptor = null; - - /** - * The image cell position - */ - private ImageCellPosition imageCellPosition = null; - - /** - * The image rastor data - */ - private ImageRasterData imageRasterData = null; - - /** - * Constructor for the image object with the specified name, - * the name must be a fixed length of eight characters. - * - * @param name The name of the image. - */ - public IMImageObject(String name) { - super(name); - } - - /** - * Sets the ImageOutputControl. - * - * @param imageOutputControl The imageOutputControl to set - */ - public void setImageOutputControl(ImageOutputControl imageOutputControl) { - this.imageOutputControl = imageOutputControl; - } - - /** - * Sets the ImageCellPosition. - * - * @param imageCellPosition The imageCellPosition to set - */ - public void setImageCellPosition(ImageCellPosition imageCellPosition) { - this.imageCellPosition = imageCellPosition; - } - - /** - * Sets the ImageInputDescriptor. - * - * @param imageInputDescriptor The imageInputDescriptor to set - */ - public void setImageInputDescriptor(ImageInputDescriptor imageInputDescriptor) { - this.imageInputDescriptor = imageInputDescriptor; - } - - /** - * Sets the ImageRastorData. - * - * @param imageRasterData The imageRasterData to set - */ - public void setImageRasterData(ImageRasterData imageRasterData) { - this.imageRasterData = imageRasterData; - } - - /** {@inheritDoc} */ - protected void writeContent(OutputStream os) throws IOException { - super.writeContent(os); - if (imageOutputControl != null) { - imageOutputControl.writeToStream(os); - } - if (imageInputDescriptor != null) { - imageInputDescriptor.writeToStream(os); - } - if (imageCellPosition != null) { - imageCellPosition.writeToStream(os); - } - if (imageRasterData != null) { - imageRasterData.writeToStream(os); - } - } - - /** {@inheritDoc} */ - protected void writeStart(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.BEGIN, Category.IM_IMAGE); - os.write(data); - } - - /** {@inheritDoc} */ - protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.END, Category.IM_IMAGE); - os.write(data); - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/ImageDataDescriptor.java b/src/java/org/apache/fop/render/afp/modca/ImageDataDescriptor.java deleted file mode 100644 index 430f6590c..000000000 --- a/src/java/org/apache/fop/render/afp/modca/ImageDataDescriptor.java +++ /dev/null @@ -1,77 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * ImageDataDescriptor - */ -public class ImageDataDescriptor extends AbstractDescriptor { - - /** - * Constructor for a ImageDataDescriptor for the specified - * resolution, width and height. - * - * @param width The width of the image. - * @param height The height of the height. - * @param widthRes The horizontal resolution of the image. - * @param heightRes The vertical resolution of the image. - */ - public ImageDataDescriptor(int width, int height, int widthRes, int heightRes) { - super(width, height, widthRes, heightRes); - } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - byte[] data = new byte[22]; - copySF(data, Type.DESCRIPTOR, Category.IMAGE); - - // SF length - byte[] len = BinaryUtils.convert(data.length - 1, 2); - data[1] = len[0]; - data[2] = len[1]; - - byte[] x = BinaryUtils.convert(widthRes, 2); - data[10] = x[0]; - data[11] = x[1]; - - byte[] y = BinaryUtils.convert(heightRes, 2); - data[12] = y[0]; - data[13] = y[1]; - - byte[] w = BinaryUtils.convert(width, 2); - data[14] = w[0]; - data[15] = w[1]; - - byte[] h = BinaryUtils.convert(height, 2); - data[16] = h[0]; - data[17] = h[1]; - - data[18] = (byte)0xF7; // ID = Set IOCA Function Set - data[19] = 0x02; // Length - data[20] = 0x01; // Category = Function set identifier - data[21] = 0x0B; // FCNSET = IOCA FS 11 - - os.write(data); - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/ImageObject.java b/src/java/org/apache/fop/render/afp/modca/ImageObject.java deleted file mode 100644 index 005bae176..000000000 --- a/src/java/org/apache/fop/render/afp/modca/ImageObject.java +++ /dev/null @@ -1,153 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.commons.io.output.ByteArrayOutputStream; -import org.apache.fop.render.afp.AFPDataObjectInfo; -import org.apache.fop.render.afp.AFPImageObjectInfo; -import org.apache.fop.render.afp.AFPObjectAreaInfo; -import org.apache.fop.render.afp.ioca.ImageSegment; - -/** - * An IOCA Image Data Object - */ -public class ImageObject extends AbstractDataObject { - - private static final int MAX_DATA_LEN = 32759; - - /** the image segment */ - private ImageSegment imageSegment = null; - - /** - * Constructor for the image object with the specified name, - * the name must be a fixed length of eight characters. - * - * @param name The name of the image. - * @param factory the resource manager - */ - public ImageObject(Factory factory, String name) { - super(factory, name); - } - - private ImageSegment getImageSegment() { - if (imageSegment == null) { - this.imageSegment = factory.createImageSegment(); - } - return imageSegment; - } - - /** {@inheritDoc} */ - public void setViewport(AFPDataObjectInfo dataObjectInfo) { - super.setViewport(dataObjectInfo); - - AFPImageObjectInfo imageObjectInfo = (AFPImageObjectInfo)dataObjectInfo; - int dataWidth = imageObjectInfo.getDataWidth(); - int dataHeight = imageObjectInfo.getDataHeight(); - - AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo(); - int widthRes = objectAreaInfo.getWidthRes(); - int heightRes = objectAreaInfo.getHeightRes(); - - ImageDataDescriptor imageDataDescriptor - = factory.createImageDataDescriptor(dataWidth, dataHeight, widthRes, heightRes); - getObjectEnvironmentGroup().setDataDescriptor(imageDataDescriptor); - - getImageSegment().setImageSize(dataWidth, dataHeight, widthRes, heightRes); - } - - /** - * Sets the image encoding. - * - * @param encoding The image encoding. - */ - public void setEncoding(byte encoding) { - getImageSegment().setEncoding(encoding); - } - - /** - * Sets the image compression. - * - * @param compression The image compression. - */ - public void setCompression(byte compression) { - getImageSegment().setCompression(compression); - } - - /** - * Sets the image IDE size. - * - * @param size The IDE size. - */ - public void setIDESize(byte size) { - getImageSegment().setIDESize(size); - } - - /** - * Sets the image IDE color model. - * - * @param colorModel the IDE color model. - */ - public void setIDEColorModel(byte colorModel) { - getImageSegment().setIDEColorModel(colorModel); - } - - /** - * Set the data of the image. - * - * @param data the image data - */ - public void setData(byte[] data) { - getImageSegment().setData(data); - } - - /** {@inheritDoc} */ - protected void writeStart(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.BEGIN, Category.IMAGE); - os.write(data); - } - - /** {@inheritDoc} */ - protected void writeContent(OutputStream os) throws IOException { - super.writeContent(os); - - if (imageSegment != null) { - final byte[] dataHeader = new byte[9]; - copySF(dataHeader, SF_CLASS, Type.DATA, Category.IMAGE); - final int lengthOffset = 1; - - // TODO save memory! - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - imageSegment.writeToStream(baos); - byte[] data = baos.toByteArray(); - writeChunksToStream(data, dataHeader, lengthOffset, MAX_DATA_LEN, os); - } - } - - /** {@inheritDoc} */ - protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.END, Category.IMAGE); - os.write(data); - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/IncludeObject.java b/src/java/org/apache/fop/render/afp/modca/IncludeObject.java deleted file mode 100644 index 9e5216f6f..000000000 --- a/src/java/org/apache/fop/render/afp/modca/IncludeObject.java +++ /dev/null @@ -1,303 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.modca.triplets.MappingOptionTriplet; -import org.apache.fop.render.afp.modca.triplets.MeasurementUnitsTriplet; -import org.apache.fop.render.afp.modca.triplets.ObjectAreaSizeTriplet; -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * An Include Object structured field references an object on a page or overlay. - * It optionally contains parameters that identify the object and that specify - * presentation parameters such as object position, size, orientation, mapping, - * and default color. - *

- * Where the presentation parameters conflict with parameters specified in the - * object's environment group (OEG), the parameters in the Include Object - * structured field override. If the referenced object is a page segment, the - * IOB parameters override the corresponding environment group parameters on all - * data objects in the page segment. - *

- */ -public class IncludeObject extends AbstractNamedAFPObject { - - /** the object referenced is of type page segment */ - public static final byte TYPE_PAGE_SEGMENT = (byte)0x5F; - - /** the object referenced is of type other */ - public static final byte TYPE_OTHER = (byte)0x92; - - /** the object referenced is of type graphic */ - public static final byte TYPE_GRAPHIC = (byte)0xBB; - - /** the object referenced is of type barcode */ - public static final byte TYPE_BARCODE = (byte)0xEB; - - /** the object referenced is of type image */ - public static final byte TYPE_IMAGE = (byte)0xFB; - - - /** the object type referenced (default is other) */ - private byte objectType = TYPE_OTHER; - - /** the X-axis origin of the object area */ - private int xoaOset = 0; - - /** the Y-axis origin of the object area */ - private int yoaOset = 0; - - /** the orientation of the referenced object */ - private int oaOrent = 0; - - /** the X-axis origin defined in the object */ - private int xocaOset = -1; - - /** the Y-axis origin defined in the object */ - private int yocaOset = -1; - - /** - * Constructor for the include object with the specified name, the name must - * be a fixed length of eight characters and is the name of the referenced - * object. - * - * @param name the name of this include object - */ - public IncludeObject(String name) { - super(name); - } - - /** - * Sets the orientation to use for the Include Object. - * - * @param orientation - * The orientation (0,90, 180, 270) - */ - public void setObjectAreaOrientation(int orientation) { - if (orientation == 0 || orientation == 90 || orientation == 180 - || orientation == 270) { - this.oaOrent = orientation; - } else { - throw new IllegalArgumentException( - "The orientation must be one of the values 0, 90, 180, 270"); - } - } - - /** - * Sets the x and y offset to the origin in the object area - * - * @param x the X-axis origin of the object area - * @param y the Y-axis origin of the object area - */ - public void setObjectAreaOffset(int x, int y) { - this.xoaOset = x; - this.yoaOset = y; - } - - /** - * Sets the x and y offset of the content area to the object area - * used in conjunction with the {@link MappingOptionTriplet.POSITION} and - * {@link MappingOptionTriplet.POSITION_AND_TRIM}. - * - * @param x the X-axis origin defined in the object - * @param y the Y-axis origin defined in the object - */ - public void setContentAreaOffset(int x, int y) { - this.xocaOset = x; - this.yocaOset = y; - } - - /** - * Sets the data object type - * - * @param type the data object type - */ - public void setObjectType(byte type) { - this.objectType = type; - } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - byte[] data = new byte[36]; - super.copySF(data, Type.INCLUDE, Category.DATA_RESOURCE); - - // Set the total record length - int tripletDataLength = getTripletDataLength(); - byte[] len = BinaryUtils.convert(35 + tripletDataLength, 2); //Ignore first byte - data[1] = len[0]; - data[2] = len[1]; - - data[17] = 0x00; // reserved - data[18] = objectType; - - //XoaOset (object area) - if (xoaOset > -1) { - byte[] x = BinaryUtils.convert(xoaOset, 3); - data[19] = x[0]; - data[20] = x[1]; - data[21] = x[2]; - } else { - data[19] = (byte)0xFF; - data[20] = (byte)0xFF; - data[21] = (byte)0xFF; - } - - // YoaOset (object area) - if (yoaOset > -1) { - byte[] y = BinaryUtils.convert(yoaOset, 3); - data[22] = y[0]; - data[23] = y[1]; - data[24] = y[2]; - } else { - data[22] = (byte)0xFF; - data[23] = (byte)0xFF; - data[24] = (byte)0xFF; - } - - // XoaOrent/YoaOrent - switch (oaOrent) { - case -1: // use x/y axis orientation defined in object - data[25] = (byte)0xFF; // x axis rotation - data[26] = (byte)0xFF; // - data[27] = (byte)0xFF; // y axis rotation - data[28] = (byte)0xFF; - break; - case 90: - data[25] = 0x2D; - data[26] = 0x00; - data[27] = 0x5A; - data[28] = 0x00; - break; - case 180: - data[25] = 0x5A; - data[25] = 0x00; - data[27] = (byte)0x87; - data[28] = 0x00; - break; - case 270: - data[25] = (byte)0x87; - data[26] = 0x00; - data[27] = 0x00; - data[28] = 0x00; - break; - default: // 0 degrees - data[25] = 0x00; - data[26] = 0x00; - data[27] = 0x2D; - data[28] = 0x00; - break; - } - - // XocaOset (object content) - if (xocaOset > -1) { - byte[] x = BinaryUtils.convert(xocaOset, 3); - data[29] = x[0]; - data[30] = x[1]; - data[31] = x[2]; - } else { - data[29] = (byte)0xFF; - data[30] = (byte)0xFF; - data[31] = (byte)0xFF; - } - - // YocaOset (object content) - if (yocaOset > -1) { - byte[] y = BinaryUtils.convert(yocaOset, 3); - data[32] = y[0]; - data[33] = y[1]; - data[34] = y[2]; - } else { - data[32] = (byte)0xFF; - data[33] = (byte)0xFF; - data[34] = (byte)0xFF; - } - // RefCSys (Reference coordinate system) - data[35] = 0x01; // Page or overlay coordinate system - - // Write structured field data - os.write(data); - - // Write triplet for FQN internal/external object reference - if (tripletData != null) { - os.write(tripletData); - } - } - - private String getObjectTypeName() { - String objectTypeName = null; - if (objectType == TYPE_PAGE_SEGMENT) { - objectTypeName = "page segment"; - } else if (objectType == TYPE_OTHER) { - objectTypeName = "other"; - } else if (objectType == TYPE_GRAPHIC) { - objectTypeName = "graphic"; - } else if (objectType == TYPE_BARCODE) { - objectTypeName = "barcode"; - } else if (objectType == TYPE_IMAGE) { - objectTypeName = "image"; - } - return objectTypeName; - } - - /** {@inheritDoc} */ - public String toString() { - return "IncludeObject{name=" + this.getName() - + ", objectType=" + getObjectTypeName() - + ", xoaOset=" + xoaOset - + ", yoaOset=" + yoaOset - + ", oaOrent" + oaOrent - + ", xocaOset=" + xocaOset - + ", yocaOset=" + yocaOset - + "}"; - } - - /** - * Sets the mapping option - * - * @param optionValue the mapping option value - */ - public void setMappingOption(byte optionValue) { - addTriplet(new MappingOptionTriplet(optionValue)); - } - - /** - * Sets the extent of an object area in the X and Y directions - * - * @param x the x direction extent - * @param y the y direction extent - */ - public void setObjectAreaSize(int x, int y) { - addTriplet(new ObjectAreaSizeTriplet(x, y)); - } - - /** - * Sets the measurement units used to specify the units of measure - * - * @param xRes units per base on the x-axis - * @param yRes units per base on the y-axis - */ - public void setMeasurementUnits(int xRes, int yRes) { - addTriplet(new MeasurementUnitsTriplet(xRes, xRes)); - } - -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/IncludePageOverlay.java b/src/java/org/apache/fop/render/afp/modca/IncludePageOverlay.java deleted file mode 100644 index be1ef870f..000000000 --- a/src/java/org/apache/fop/render/afp/modca/IncludePageOverlay.java +++ /dev/null @@ -1,129 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * - * The Include Page Overlay structured field references an overlay resource - * definition that is to be positioned on the page. A page overlay can be - * referenced at any time during the page state, but not during an object state. - * The overlay contains its own active environment group definition. - * - * Note: There is no need for the triplets, so I have ignored them. - * - * A real example of where this will be used is for static overlays, such as an - * address on the page. - * - */ -public class IncludePageOverlay extends AbstractNamedAFPObject { - - /** - * The x coordinate - */ - private int x = 0; - - /** - * The y coordinate - */ - private int y = 0; - - /** - * The orientation - */ - private int orientation = 0; - - /** - * Constructor for the Include Page Overlay - * - * @param overlayName Name of the page segment - * @param x The x position - * @param y The y position - * @param orientation The orientation - */ - public IncludePageOverlay(String overlayName, int x, int y, int orientation) { - super(overlayName); - - this.x = x; - this.y = y; - setOrientation(orientation); - } - - /** - * Sets the orientation to use for the overlay. - * - * @param orientation - * The orientation (0,90, 180, 270) - */ - public void setOrientation(int orientation) { - if (orientation == 0 || orientation == 90 || orientation == 180 - || orientation == 270) { - this.orientation = orientation; - } else { - throw new IllegalArgumentException( - "The orientation must be one of the values 0, 90, 180, 270"); - } - } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - byte[] data = new byte[25]; //(9 +16) - copySF(data, Type.INCLUDE, Category.PAGE_OVERLAY); - - // Set the total record length - byte[] len = BinaryUtils.convert(24, 2); //Ignore first byte - data[1] = len[0]; - data[2] = len[1]; - - byte[] xPos = BinaryUtils.convert(x, 3); - data[17] = xPos[0]; // x coordinate - data[18] = xPos[1]; - data[19] = xPos[2]; - - byte[] yPos = BinaryUtils.convert(y, 3); - data[20] = yPos[0]; // y coordinate - data[21] = yPos[1]; - data[22] = yPos[2]; - - switch (orientation) { - case 90: - data[23] = 0x2D; - data[24] = 0x00; - break; - case 180: - data[23] = 0x5A; - data[24] = 0x00; - break; - case 270: - data[23] = (byte) 0x87; - data[24] = 0x00; - break; - default: - data[23] = 0x00; - data[24] = 0x00; - break; - } - os.write(data); - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/IncludePageSegment.java b/src/java/org/apache/fop/render/afp/modca/IncludePageSegment.java deleted file mode 100644 index a9d247553..000000000 --- a/src/java/org/apache/fop/render/afp/modca/IncludePageSegment.java +++ /dev/null @@ -1,91 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * The Include Page Segment structured field references a page segment resource - * object that is to be presented on the page or overlay presentation space. The IPS - * specifies a reference point on the including page or overlay coordinate system that - * may be used to position objects contained in the page segment. A page segment - * can be referenced at any time during page or overlay state, but not during an - * object state. The page segment inherits the active environment group definition of - * the including page or overlay. - * - * Note : No use for Triplets. - * - * A 'real' example for where this will be used is for - * the dynamic placing of overlay objects, such as signatures - * that may have to be placed at different positions on a document. - * - */ -public class IncludePageSegment extends AbstractNamedAFPObject { - - /** - * The x position where we need to put this object on the page - */ - private int x; - - /** - * The y position where we need to put this object on the page - */ - private int y; - - /** - * Constructor for the Include Page Segment - * - * @param name Name of the page segment - * @param x The x position - * @param y The y position - */ - public IncludePageSegment(String name, int x, int y) { - super(name); - - this.x = x; - this.y = y; - } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - byte[] data = new byte[23]; //(9 +14) - copySF(data, Type.INCLUDE, Category.PAGE_SEGMENT); - - // Set the total record length - byte[] len = BinaryUtils.convert(22, 2); //Ignore first byte - data[1] = len[0]; - data[2] = len[1]; - - byte[] xPos = BinaryUtils.convert(x, 3); - data[17] = xPos[0]; // x coordinate - data[18] = xPos[1]; - data[19] = xPos[2]; - - byte[] yPos = BinaryUtils.convert(y, 3); - data[20] = yPos[0]; // y coordinate - data[21] = yPos[1]; - data[22] = yPos[2]; - - os.write(data); - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/InterchangeSet.java b/src/java/org/apache/fop/render/afp/modca/InterchangeSet.java deleted file mode 100644 index 4d52df3d3..000000000 --- a/src/java/org/apache/fop/render/afp/modca/InterchangeSet.java +++ /dev/null @@ -1,115 +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.render.afp.modca; - -/** - * MO:DCA Interchange Set - */ -public class InterchangeSet { - /** interchange set 1 string value */ - public static final String MODCA_PRESENTATION_INTERCHANGE_SET_1 = "MO:DCA-P IS/1"; - - /** interchange set 2 string value */ - public static final String MODCA_PRESENTATION_INTERCHANGE_SET_2 = "MO:DCA-P IS/2"; - - /** resource interchange set string value */ - public static final String MODCA_RESOURCE_INTERCHANGE_SET = "MO:DCA-L"; - - private static final String[] NAMES = { - MODCA_PRESENTATION_INTERCHANGE_SET_1, - MODCA_PRESENTATION_INTERCHANGE_SET_2, - MODCA_RESOURCE_INTERCHANGE_SET - }; - - private static final int SET_1 = 0; - private static final int SET_2 = 1; - private static final int RESOURCE_SET = 2; - - /** the actual interchange set in use */ - private int value; - - /** - * Returns the interchange set value of a given string - * - * @param str an interchange set value - * @return an interchange set - */ - public static InterchangeSet valueOf(String str) { - if (MODCA_PRESENTATION_INTERCHANGE_SET_1.equals(str)) { - return new InterchangeSet(SET_1); - } else if (MODCA_PRESENTATION_INTERCHANGE_SET_2.equals(str)) { - return new InterchangeSet(SET_2); - } else if (MODCA_RESOURCE_INTERCHANGE_SET.equals(str)) { - return new InterchangeSet(RESOURCE_SET); - } else { - throw new IllegalArgumentException("Invalid MO:DCA interchange set :" + str); - } - } - - /** - * Main constructor - * - * @param value the interchange set value - */ - public InterchangeSet(int value) { - this.value = value; - } - - /** - * Returns true if complies with MOD:CA interchange set 1 - * - * @return true if complies with MOD:CA interchange set 1 - */ - protected boolean is1() { - return value == SET_1; - } - - /** - * Returns true if complies with MOD:CA interchange set 2 - * - * @return true if complies with MOD:CA interchange set 2 - */ - public boolean is2() { - return value == SET_2; - } - - /** - * Returns true if complies with MOD:CA resource set - * - * @return true if complies with MOD:CA resource set - */ - public boolean isResource() { - return value == RESOURCE_SET; - } - - /** {@inheritDoc} */ - public String toString() { - return NAMES[value]; - } - - /** - * Returns true if MOD:CA interchange set 2 (resource groups) is supported - * - * @return true if MOD:CA interchange set 2 (resource groups) is supported - */ - public boolean supportsLevel2() { - return is2() || isResource(); - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/InvokeMediumMap.java b/src/java/org/apache/fop/render/afp/modca/InvokeMediumMap.java deleted file mode 100644 index cee7711e6..000000000 --- a/src/java/org/apache/fop/render/afp/modca/InvokeMediumMap.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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * The Invoke Medium Map structured field identifies the Medium Map that is to - * become active for the document. An Invoke Medium Map structured field affects - * the document's current environment. The Medium Map's effect on current environment - * parameter values lasts until a new Medium Map is invoked. - */ -public class InvokeMediumMap extends AbstractNamedAFPObject { - - /** - * Constructor for the Invoke Medium Map - * - * @param name the name of the medium map - */ - public InvokeMediumMap(String name) { - super(name); - } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - - byte[] data = new byte[17]; - copySF(data, Type.MAP, Category.MEDIUM_MAP); - - // Set the total record length - byte[] len = BinaryUtils.convert(16, 2); //Ignore first byte - data[1] = len[0]; - data[2] = len[1]; - - os.write(data); - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/MapCodedFont.java b/src/java/org/apache/fop/render/afp/modca/MapCodedFont.java deleted file mode 100644 index f305630bc..000000000 --- a/src/java/org/apache/fop/render/afp/modca/MapCodedFont.java +++ /dev/null @@ -1,275 +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.render.afp.modca; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; -import java.util.Iterator; -import java.util.List; - -import org.apache.fop.render.afp.AFPConstants; -import org.apache.fop.render.afp.exceptions.FontRuntimeException; -import org.apache.fop.render.afp.fonts.AFPFont; -import org.apache.fop.render.afp.fonts.CharacterSet; -import org.apache.fop.render.afp.fonts.OutlineFont; -import org.apache.fop.render.afp.fonts.RasterFont; -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * The Map Coded Font structured field maps a unique coded font resource local - * ID, which may be embedded one or more times within an object's data and - * descriptor, to the identifier of a coded font resource object. Additionally, - * the Map Coded Font structured field specifies a set of resource attributes - * for the coded font. - * - * @author Pete Townsend - */ -public class MapCodedFont extends AbstractStructuredAFPObject { - - /** - * The collection of map coded fonts (maximum of 254) - */ - private List/**/ fontList = new java.util.ArrayList(); - - /** - * Constructor for the MapCodedFont - */ - public MapCodedFont() { - } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - byte[] startData = new byte[9]; - copySF(startData, Type.MAP, Category.CODED_FONT); - baos.write(startData); - - Iterator iter = fontList.iterator(); - while (iter.hasNext()) { - FontDefinition fd = (FontDefinition) iter.next(); - - // Start of repeating groups (occurs 1 to 254) - baos.write(0x00); - - if (fd.scale == 0) { - // Raster Font - baos.write(0x22); // Length of 34 - } else { - // Outline Font - baos.write(0x3A); // Length of 58 - } - - // Font Character Set Name Reference - baos.write(0x0C); - baos.write(0x02); - baos.write((byte) 0x86); - baos.write(0x00); - baos.write(fd.characterSet); - - // Font Code Page Name Reference - baos.write(0x0C); - baos.write(0x02); - baos.write((byte) 0x85); - baos.write(0x00); - baos.write(fd.codePage); - - // Character Rotation - baos.write(0x04); - baos.write(0x26); - baos.write(fd.orientation); - baos.write(0x00); - - // Resource Local Identifier - baos.write(0x04); - baos.write(0x24); - baos.write(0x05); - baos.write(fd.fontReferenceKey); - - if (fd.scale != 0) { - // Outline Font (triplet '1F') - baos.write(0x14); - baos.write(0x1F); - baos.write(0x00); - baos.write(0x00); - - baos.write(BinaryUtils.convert(fd.scale, 2)); // Height - baos.write(new byte[] {0x00, 0x00}); // Width - - baos.write(new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00}); - - baos.write(0x60); - - // Outline Font (triplet '5D') - baos.write(0x04); - baos.write(0x5D); - baos.write(BinaryUtils.convert(fd.scale, 2)); - } - } - - byte[] data = baos.toByteArray(); - - // Set the total record length - byte[] rl1 = BinaryUtils.convert(data.length - 1, 2); - data[1] = rl1[0]; - data[2] = rl1[1]; - - os.write(data); - } - - /** - * Add a font definition on the the map coded font object. - * - * @param fontReference - * the font number used as the resource identifier - * @param font - * the font - * @param size - * the size of the font - * @param orientation - * the orientation of the font - * @throws MaximumSizeExceededException if the maximum number of fonts have been exceeded - */ - public void addFont(int fontReference, AFPFont font, int size, int orientation) - throws MaximumSizeExceededException { - - FontDefinition fd = new FontDefinition(); - - fd.fontReferenceKey = BinaryUtils.convert(fontReference)[0]; - - switch (orientation) { - case 90: - fd.orientation = 0x2D; - break; - case 180: - fd.orientation = 0x5A; - break; - case 270: - fd.orientation = (byte) 0x87; - break; - default: - fd.orientation = 0x00; - break; - } - - try { - if (font instanceof RasterFont) { - RasterFont raster = (RasterFont) font; - CharacterSet cs = raster.getCharacterSet(size); - if (cs == null) { - String msg = "Character set not found for font " - + font.getFontName() + " with point size " + size; - log.error(msg); - throw new FontRuntimeException(msg); - } - - fd.characterSet = cs.getNameBytes(); - - if (fd.characterSet.length != 8) { - throw new IllegalArgumentException("The character set " - + new String(fd.characterSet, - AFPConstants.EBCIDIC_ENCODING) - + " must have a fixed length of 8 characters."); - } - - fd.codePage = cs.getCodePage().getBytes( - AFPConstants.EBCIDIC_ENCODING); - - if (fd.codePage.length != 8) { - throw new IllegalArgumentException("The code page " - + new String(fd.codePage, - AFPConstants.EBCIDIC_ENCODING) - + " must have a fixed length of 8 characters."); - } - - } else if (font instanceof OutlineFont) { - OutlineFont outline = (OutlineFont) font; - CharacterSet cs = outline.getCharacterSet(); - fd.characterSet = cs.getNameBytes(); - - // There are approximately 72 points to 1 inch or 20 1440ths per point. - - fd.scale = ((size / 1000) * 20); - - fd.codePage = cs.getCodePage().getBytes( - AFPConstants.EBCIDIC_ENCODING); - - if (fd.codePage.length != 8) { - throw new IllegalArgumentException("The code page " - + new String(fd.codePage, - AFPConstants.EBCIDIC_ENCODING) - + " must have a fixed length of 8 characters."); - } - } else { - String msg = "Font of type " + font.getClass().getName() - + " not recognized."; - log.error(msg); - throw new FontRuntimeException(msg); - } - - if (fontList.size() > 253) { - // Throw an exception if the size is exceeded - throw new MaximumSizeExceededException(); - } else { - fontList.add(fd); - } - - } catch (UnsupportedEncodingException ex) { - throw new FontRuntimeException("Failed to create font " - + " due to a UnsupportedEncodingException", ex); - } - } - - - /** - * Private utility class used as a container for font attributes - */ - private class FontDefinition { - - /** - * The code page of the font - */ - private byte[] codePage; - - /** - * The character set of the font - */ - private byte[] characterSet; - - /** - * The font reference key - */ - private byte fontReferenceKey; - - /** - * The orientation of the font - */ - private byte orientation; - - /** - * The scale (only specified for outline fonts) - */ - private int scale = 0; - } - -} diff --git a/src/java/org/apache/fop/render/afp/modca/MapContainerData.java b/src/java/org/apache/fop/render/afp/modca/MapContainerData.java deleted file mode 100644 index 9ec157ee8..000000000 --- a/src/java/org/apache/fop/render/afp/modca/MapContainerData.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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.modca.triplets.MappingOptionTriplet; -import org.apache.fop.render.afp.tools.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 { - - /** - * Main constructor - * - * @param optionValue the mapping option value - */ - public MapContainerData(byte optionValue) { - super.addTriplet(new MappingOptionTriplet(optionValue)); - } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - 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); - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/MapDataResource.java b/src/java/org/apache/fop/render/afp/modca/MapDataResource.java deleted file mode 100644 index 09b18b9a7..000000000 --- a/src/java/org/apache/fop/render/afp/modca/MapDataResource.java +++ /dev/null @@ -1,58 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * The Map Data Resource structured field specifies resources that are - * required for presentation. - */ -public class MapDataResource extends AbstractStructuredAFPObject { - - /** - * Main constructor - */ - public MapDataResource() { - } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - super.writeStart(os); - byte[] data = new byte[11]; - copySF(data, Type.MAP, Category.DATA_RESOURCE); - - int tripletDataLen = getTripletDataLength(); - - byte[] len = BinaryUtils.convert(10 + tripletDataLen, 2); - data[1] = len[0]; - data[2] = len[1]; - - len = BinaryUtils.convert(2 + tripletDataLen, 2); - data[9] = len[0]; - data[10] = len[1]; - - os.write(data); - os.write(tripletData); - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/MapPageOverlay.java b/src/java/org/apache/fop/render/afp/modca/MapPageOverlay.java deleted file mode 100644 index 3143e80a0..000000000 --- a/src/java/org/apache/fop/render/afp/modca/MapPageOverlay.java +++ /dev/null @@ -1,141 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; -import java.util.List; - -import org.apache.fop.render.afp.AFPConstants; -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * The Map Page Overlay structured field maps a Resource Local ID to the name of - * a Begin Overlay structured field. A Map Page Overlay structured field may - * contain from one to 254 repeating groups. - */ -public class MapPageOverlay extends AbstractAFPObject { - - private static final int MAX_SIZE = 253; - - /** - * The collection of overlays (maximum of 254 stored as byte[]) - */ - private List overLays = null; - - /** - * Constructor for the Map Page Overlay - */ - public MapPageOverlay() { - } - - private List getOverlays() { - if (overLays == null) { - this.overLays = new java.util.ArrayList(); - } - return this.overLays; - } - - /** - * Add an overlay to to the map page overlay object. - * - * @param name - * The name of the overlay. - * @throws MaximumSizeExceededException if the maximum size is reached - */ - public void addOverlay(String name) throws MaximumSizeExceededException { - if (getOverlays().size() > MAX_SIZE) { - throw new MaximumSizeExceededException(); - } - if (name.length() != 8) { - throw new IllegalArgumentException("The name of overlay " + name - + " must be 8 characters"); - } - if (log.isDebugEnabled()) { - log.debug("addOverlay():: adding overlay " + name); - } - try { - byte[] data = name.getBytes(AFPConstants.EBCIDIC_ENCODING); - getOverlays().add(data); - } catch (UnsupportedEncodingException usee) { - log.error("addOverlay():: UnsupportedEncodingException translating the name " - + name); - } - } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - int oLayCount = getOverlays().size(); - int recordlength = oLayCount * 18; - - byte[] data = new byte[recordlength + 9]; - - data[0] = 0x5A; - - // Set the total record length - byte[] rl1 = BinaryUtils.convert(recordlength + 8, 2); //Ignore the - // first byte in - // the length - data[1] = rl1[0]; - data[2] = rl1[1]; - - // Structured field ID for a MPO - data[3] = (byte) 0xD3; - data[4] = (byte) Type.MAP; - data[5] = (byte) Category.PAGE_OVERLAY; - - data[6] = 0x00; // Reserved - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - - int pos = 8; - - //For each overlay - byte olayref = 0x00; - - for (int i = 0; i < oLayCount; i++) { - olayref = (byte) (olayref + 1); - - data[++pos] = 0x00; - data[++pos] = 0x12; //the length of repeating group - - data[++pos] = 0x0C; //Fully Qualified Name - data[++pos] = 0x02; - data[++pos] = (byte) 0x84; - data[++pos] = 0x00; - - //now add the name - byte[] name = (byte[]) overLays.get(i); - - for (int j = 0; j < name.length; j++) { - data[++pos] = name[j]; - } - - data[++pos] = 0x04; //Resource Local Identifier (RLI) - data[++pos] = 0x24; - data[++pos] = 0x02; - - //now add the unique id to the RLI - data[++pos] = olayref; - } - os.write(data); - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/MaximumSizeExceededException.java b/src/java/org/apache/fop/render/afp/modca/MaximumSizeExceededException.java deleted file mode 100644 index a66fa9b30..000000000 --- a/src/java/org/apache/fop/render/afp/modca/MaximumSizeExceededException.java +++ /dev/null @@ -1,37 +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.render.afp.modca; - -/** - * An exception to handle maximum sizes being exceeded. - * - */ -public class MaximumSizeExceededException extends Exception { - - private static final long serialVersionUID = 7823120005542216446L; - - /** - * Default constructor - */ - public MaximumSizeExceededException() { - super(); - } - -} diff --git a/src/java/org/apache/fop/render/afp/modca/NoOperation.java b/src/java/org/apache/fop/render/afp/modca/NoOperation.java deleted file mode 100644 index 258fcf47d..000000000 --- a/src/java/org/apache/fop/render/afp/modca/NoOperation.java +++ /dev/null @@ -1,100 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.AFPConstants; -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * The No Operation structured field may be used to carry comments - * or any other type of unarchitected data. Although not recommended, - * it may also be used to carry semantic data in private or exchange data - * streams. However, because receivers of interchange data streams should - * ignore the content of No Operation structured fields and because - * receiver-generator products are not required to propagate - * No Operation structured fields, no semantics should be attached to - * the data carried by the No Operation structured field in interchange - */ -public class NoOperation extends AbstractAFPObject { - - /** Up to 32759 bytes of data with no architectural definition */ - private static final int MAX_DATA_LEN = 32759; - - /** - * Byte representation of the comment - */ - private String content; - - /** - * Construct a tag logical element with the name and value specified. - * - * @param content the content to record - */ - public NoOperation(String content) { - this.content = content; - } - - /** - * Accessor method to obtain the byte array AFP datastream for the - * NoOperation. - * - * @param os The outputsteam stream - * @throws java.io.IOException if an I/O exception occurs during processing - */ - public void writeToStream(OutputStream os) throws IOException { - byte[] contentData = content.getBytes(AFPConstants.EBCIDIC_ENCODING); - int contentLen = contentData.length; - - // packet maximum of 32759 bytes - if (contentLen > MAX_DATA_LEN) { - contentLen = MAX_DATA_LEN; - } - - byte[] data = new byte[9 + contentLen]; - - data[0] = 0x5A; - - // Set the total record length - byte[] rl1 = BinaryUtils.convert(8 + contentLen, 2); - - //Ignore first byte - data[1] = rl1[0]; - data[2] = rl1[1]; - - // Structured field ID for a TLE - data[3] = (byte) 0xD3; - data[4] = (byte) 0xEE; - data[5] = (byte) 0xEE; - - data[6] = 0x00; // Reserved - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - - int pos = 9; - for (int i = 0; i < contentLen; i++) { - data[pos++] = contentData[i]; - } - os.write(data); - } - -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/ObjectAreaDescriptor.java b/src/java/org/apache/fop/render/afp/modca/ObjectAreaDescriptor.java deleted file mode 100644 index 3bd271d5b..000000000 --- a/src/java/org/apache/fop/render/afp/modca/ObjectAreaDescriptor.java +++ /dev/null @@ -1,87 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.commons.io.output.ByteArrayOutputStream; -import org.apache.fop.render.afp.modca.triplets.MeasurementUnitsTriplet; -import org.apache.fop.render.afp.modca.triplets.ObjectAreaSizeTriplet; -import org.apache.fop.render.afp.modca.triplets.PresentationSpaceResetMixingTriplet; -import org.apache.fop.render.afp.modca.triplets.Triplet; -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * The Object Area Descriptor structured field specifies the size and attributes - * of an object area presentation space. - */ -public class ObjectAreaDescriptor extends AbstractDescriptor { - - /** - * Construct an object area descriptor for the specified object width - * and object height. - * - * @param width the object width. - * @param height the object height. - * @param widthRes the object width resolution. - * @param heightRes the object height resolution. - */ - public ObjectAreaDescriptor(int width, int height, int widthRes, int heightRes) { - 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; - } - - /** {@inheritDoc} */ - public void writeStart(OutputStream os) throws IOException { - super.writeStart(os); - byte[] data = new byte[9]; - copySF(data, Type.DESCRIPTOR, Category.OBJECT_AREA); - byte[] len = BinaryUtils.convert(data.length + tripletData.length - 1, 2); - data[1] = len[0]; // Length - data[2] = len[1]; - os.write(data); - } - -} diff --git a/src/java/org/apache/fop/render/afp/modca/ObjectAreaPosition.java b/src/java/org/apache/fop/render/afp/modca/ObjectAreaPosition.java deleted file mode 100644 index fbe8c7089..000000000 --- a/src/java/org/apache/fop/render/afp/modca/ObjectAreaPosition.java +++ /dev/null @@ -1,111 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * The Object Area Position structured field specifies the origin and - * orientation of the object area, and the origin and orientation of the - * object content within the object area. - */ -public class ObjectAreaPosition extends AbstractAFPObject { - - private final int x; - private final int y; - private final int rotation; - private int xOffset; - private int yOffset; - - /** - * Construct an object area position for the specified object y, y position. - * - * @param x The x coordinate. - * @param y The y coordinate. - * @param rotation The coordinate system rotation (must be 0, 90, 180, 270). - */ - public ObjectAreaPosition(int x, int y, int rotation) { - this.x = x; - this.y = y; - this.rotation = rotation; - } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - byte[] data = new byte[33]; - copySF(data, Type.POSITION, Category.OBJECT_AREA); - - byte[] len = BinaryUtils.convert(32, 2); - data[1] = len[0]; // Length - data[2] = len[1]; - - data[9] = 0x01; // OAPosID = 1 - data[10] = 0x17; // RGLength = 23 - - byte[] xcoord = BinaryUtils.convert(x, 3); - data[11] = xcoord[0]; // XoaOSet - data[12] = xcoord[1]; - data[13] = xcoord[2]; - - byte[] ycoord = BinaryUtils.convert(y, 3); - data[14] = ycoord[0]; // YoaOSet - data[15] = ycoord[1]; - data[16] = ycoord[2]; - - byte xorient = (byte)(rotation / 2); - data[17] = xorient; // XoaOrent - - byte yorient = (byte)(rotation / 2 + 45); - data[19] = yorient; // YoaOrent - - byte[] xoffset = BinaryUtils.convert(xOffset, 3); - data[22] = xoffset[0]; // XocaOSet - data[23] = xoffset[1]; - data[24] = xoffset[2]; - - byte[] yoffset = BinaryUtils.convert(yOffset, 3); - data[25] = yoffset[0]; // YocaOSet - data[26] = yoffset[1]; - data[27] = yoffset[2]; - - data[28] = 0x00; // XocaOrent - data[29] = 0x00; - - data[30] = 0x2D; // YocaOrent - data[31] = 0x00; - - data[32] = 0x01; // RefCSys - - os.write(data); - } - - /** {@inheritDoc} */ - public String toString() { - return "ObjectAreaPosition{" - + "x=" + x - + ", y=" + y - + ", rotation=" + rotation - + ", rotation=" + rotation - + ", xOffset=" + xOffset - + ", yOffset=" + yOffset; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/ObjectContainer.java b/src/java/org/apache/fop/render/afp/modca/ObjectContainer.java deleted file mode 100644 index d9a7c2895..000000000 --- a/src/java/org/apache/fop/render/afp/modca/ObjectContainer.java +++ /dev/null @@ -1,123 +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.render.afp.modca; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import org.apache.commons.io.IOUtils; -import org.apache.fop.render.afp.AFPDataObjectInfo; -import org.apache.fop.render.afp.AFPObjectAreaInfo; -import org.apache.fop.render.afp.AFPResourceInfo; -import org.apache.fop.render.afp.AFPResourceLevel; -import org.apache.fop.render.afp.modca.triplets.MappingOptionTriplet; -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * Object containers are MO:DCA objects that envelop and carry object data. - */ -public class ObjectContainer extends AbstractDataObject { - - /** the object container data maximum length */ - private static final int MAX_DATA_LEN = 32759; - - private InputStream inputStream; - - /** - * Main constructor - * - * @param factory the object factory - * @param name the name of this object container - */ - public ObjectContainer(Factory factory, String name) { - super(factory, name); - } - - /** {@inheritDoc} */ - protected void writeStart(OutputStream os) throws IOException { - byte[] headerData = new byte[17]; - copySF(headerData, Type.BEGIN, Category.OBJECT_CONTAINER); - - // Set the total record length - int containerLen = headerData.length + getTripletDataLength() - 1; - byte[] len = BinaryUtils.convert(containerLen, 2); - headerData[1] = len[0]; // Length byte 1 - headerData[2] = len[1]; // Length byte 2 - - os.write(headerData); - } - - /** {@inheritDoc} */ - protected void writeContent(OutputStream os) throws IOException { - super.writeContent(os); // write triplets and OEG - - // write OCDs - byte[] dataHeader = new byte[9]; - copySF(dataHeader, SF_CLASS, Type.DATA, Category.OBJECT_CONTAINER); - final int lengthOffset = 1; - - copyChunks(dataHeader, lengthOffset, MAX_DATA_LEN, inputStream, os); - IOUtils.closeQuietly(inputStream); - } - - /** {@inheritDoc} */ - protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.END, Category.OBJECT_CONTAINER); - os.write(data); - } - - /** {@inheritDoc} */ - public void setViewport(AFPDataObjectInfo dataObjectInfo) { - AFPResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); - AFPResourceLevel resourceLevel = resourceInfo.getLevel(); - - // only need to set MCD and CDD when OC when is inlined (pre-2000 apps) - if (resourceLevel.isInline()) { - super.setViewport(dataObjectInfo); - - MapContainerData mapContainerData - = factory.createMapContainerData(MappingOptionTriplet.SCALE_TO_FIT); - getObjectEnvironmentGroup().setMapContainerData(mapContainerData); - - int dataWidth = dataObjectInfo.getDataWidth(); - int dataHeight = dataObjectInfo.getDataHeight(); - - AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo(); - int widthRes = objectAreaInfo.getWidthRes(); - int heightRes = objectAreaInfo.getHeightRes(); - - ContainerDataDescriptor containerDataDescriptor - = factory.createContainerDataDescriptor( - dataWidth, dataHeight, widthRes, heightRes); - getObjectEnvironmentGroup().setDataDescriptor(containerDataDescriptor); - } - } - - /** - * Sets the inputstream for the the object container data - * - * @param inputStream the inputstream for the object container data - */ - public void setInputStream(InputStream inputStream) { - this.inputStream = inputStream; - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/ObjectEnvironmentGroup.java b/src/java/org/apache/fop/render/afp/modca/ObjectEnvironmentGroup.java deleted file mode 100644 index 7c44701bf..000000000 --- a/src/java/org/apache/fop/render/afp/modca/ObjectEnvironmentGroup.java +++ /dev/null @@ -1,173 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * An Object Environment Group (OEG) may be associated with an object and is contained - * within the object's begin-end envelope. - * The object environment group defines the object's origin and orientation on the page, - * and can contain font and color attribute table information. The scope of an object - * environment group is the scope of its containing object. - * - * An application that creates a data-stream document may omit some of the parameters - * normally contained in the object environment group, or it may specify that one or - * more default values are to be used. - */ -public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { - - /** the PresentationEnvironmentControl for the object environment group */ - private PresentationEnvironmentControl presentationEnvironmentControl = null; - - /** the ObjectAreaDescriptor for the object environment group */ - private ObjectAreaDescriptor objectAreaDescriptor = null; - - /** the ObjectAreaPosition for the object environment group */ - private ObjectAreaPosition objectAreaPosition = null; - - /** the DataDescriptor for the object environment group */ - private AbstractDescriptor dataDescriptor; - - /** the MapDataResource for the object environment group */ - private MapDataResource mapDataResource; - - /** the MapContainerData for the object environment group */ - private MapContainerData mapContainerData; - - /** - * Constructor for the ObjectEnvironmentGroup, this takes a - * name parameter which must be 8 characters long. - * - * @param name the object environment group name - */ - public ObjectEnvironmentGroup(String name) { - super(name); - } - - /** - * Sets the Object Area Descriptor - * - * @param objectAreaDescriptor the object area descriptor - */ - public void setObjectAreaDescriptor(ObjectAreaDescriptor objectAreaDescriptor) { - this.objectAreaDescriptor = objectAreaDescriptor; - } - - /** - * Sets the Object Area Position - * - * @param objectAreaPosition the object area position - */ - public void setObjectAreaPosition(ObjectAreaPosition objectAreaPosition) { - this.objectAreaPosition = objectAreaPosition; - } - - /** {@inheritDoc} */ - protected void writeStart(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.BEGIN, Category.OBJECT_ENVIRONMENT_GROUP); - - int tripletDataLength = getTripletDataLength(); - int sfLen = data.length + tripletDataLength - 1; - byte[] len = BinaryUtils.convert(sfLen, 2); - data[1] = len[0]; - data[2] = len[1]; - - os.write(data); - } - - /** {@inheritDoc} */ - protected void writeContent(OutputStream os) throws IOException { - super.writeContent(os); - - if (presentationEnvironmentControl != null) { - presentationEnvironmentControl.writeToStream(os); - } - - if (objectAreaDescriptor != null) { - objectAreaDescriptor.writeToStream(os); - } - - if (objectAreaPosition != null) { - objectAreaPosition.writeToStream(os); - } - - if (mapContainerData != null) { - mapContainerData.writeToStream(os); - } - - if (mapDataResource != null) { - mapDataResource.writeToStream(os); - } - - if (dataDescriptor != null) { - dataDescriptor.writeToStream(os); - } - } - - /** {@inheritDoc} */ - protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.END, Category.OBJECT_ENVIRONMENT_GROUP); - os.write(data); - } - - /** - * Sets the presentation environment control - * - * @param presentationEnvironmentControl the presentation environment control - */ - public void setPresentationEnvironmentControl( - PresentationEnvironmentControl presentationEnvironmentControl) { - this.presentationEnvironmentControl = presentationEnvironmentControl; - } - - /** - * Sets the data descriptor - * - * @param dataDescriptor the data descriptor - */ - public void setDataDescriptor(AbstractDescriptor dataDescriptor) { - this.dataDescriptor = dataDescriptor; - } - - /** - * Sets the map data resource - * - * @param mapDataResource the map data resource - */ - public void setMapDataResource(MapDataResource mapDataResource) { - this.mapDataResource = mapDataResource; - } - - /** - * Sets the map container data - * - * @param mapContainerData the map container data - */ - public void setMapContainerData(MapContainerData mapContainerData) { - this.mapContainerData = mapContainerData; - } - -} diff --git a/src/java/org/apache/fop/render/afp/modca/Overlay.java b/src/java/org/apache/fop/render/afp/modca/Overlay.java deleted file mode 100644 index 2791d3a15..000000000 --- a/src/java/org/apache/fop/render/afp/modca/Overlay.java +++ /dev/null @@ -1,85 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; - - -/** - * An overlay is a MO:DCA-P resource object. - * - * It may be stored in an external resource library or it may be - * carried in a resource group. An overlay is similar to a page in - * that it defines its own environment and carries the same data objects. - */ -public class Overlay extends PageObject { - - /** - * Construct a new overlay object for the specified name argument, the overlay - * name should be an 8 character identifier. - * - * @param factory - * the resource manager of the page. - * @param name - * the name of the page. - * @param width - * the width of the page. - * @param height - * the height of the page. - * @param rotation - * the rotation of the page. - * @param widthResolution - * the width resolution of the page. - * @param heightResolution - * the height resolution of the page. - */ - public Overlay(Factory factory, - String name, int width, int height, int rotation, - int widthResolution, int heightResolution) { - super(factory, name, width, height, rotation, widthResolution, heightResolution); - } - - /** {@inheritDoc} */ - protected void writeStart(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.BEGIN, Category.OVERLAY); - os.write(data); - } - - /** {@inheritDoc} */ - protected void writeContent(OutputStream os) throws IOException { - super.writeContent(os); - - getActiveEnvironmentGroup().writeToStream(os); - - writeObjects(includePageSegments, os); - writeObjects(tagLogicalElements, os); - writeObjects(objects, os); - } - - - /** {@inheritDoc} */ - protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.END, Category.OVERLAY); - os.write(data); - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/PageDescriptor.java b/src/java/org/apache/fop/render/afp/modca/PageDescriptor.java deleted file mode 100644 index 8f0d0dfae..000000000 --- a/src/java/org/apache/fop/render/afp/modca/PageDescriptor.java +++ /dev/null @@ -1,87 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * The Page Descriptor structured field specifies the size and attributes of - * a page or overlay presentation space. - * - */ -public class PageDescriptor extends AbstractDescriptor { - - /** - * Construct a page descriptor for the specified page width - * and page height. - * - * @param width The page width. - * @param height The page height. - * @param widthRes The page width resolution - * @param heightRes The page height resolution - */ - public PageDescriptor(int width, int height, int widthRes, int heightRes) { - super(width, height, widthRes, heightRes); - } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - byte[] data = new byte[24]; - copySF(data, Type.DESCRIPTOR, Category.PAGE); - data[2] = 0x17; - - // XpgBase - data[9] = 0x00; // XpgBase = 10 inches - - // YpgBase - data[10] = 0x00; // YpgBase = 10 inches - - // XpgUnits - byte[] xdpi = BinaryUtils.convert(widthRes * 10, 2); - data[11] = xdpi[0]; - data[12] = xdpi[1]; - - // YpgUnits - byte[] ydpi = BinaryUtils.convert(heightRes * 10, 2); - data[13] = ydpi[0]; - data[14] = ydpi[1]; - - // XpgSize - byte[] x = BinaryUtils.convert(width, 3); - data[15] = x[0]; - data[16] = x[1]; - data[17] = x[2]; - - // YpgSize - byte[] y = BinaryUtils.convert(height, 3); - data[18] = y[0]; - data[19] = y[1]; - data[20] = y[2]; - - data[21] = 0x00; // Reserved - data[22] = 0x00; // Reserved - data[23] = 0x00; // Reserved - - os.write(data); - } - -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/PageGroup.java b/src/java/org/apache/fop/render/afp/modca/PageGroup.java deleted file mode 100644 index f56e945e3..000000000 --- a/src/java/org/apache/fop/render/afp/modca/PageGroup.java +++ /dev/null @@ -1,103 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.List; - -/** - * A page group is used in the data stream to define a named, logical grouping - * of sequential pages. Page groups are delimited by begin-end structured fields - * that carry the name of the page group. Page groups are defined so that the - * pages that comprise the group can be referenced or processed as a single - * entity. Page groups are often processed in stand-alone fashion; that is, they - * are indexed, retrieved, and presented outside the context of the containing - * document. - */ -public class PageGroup extends AbstractResourceEnvironmentGroupContainer { - - /** The tag logical elements contained within this group */ - private List tagLogicalElements = null; - - /** - * Constructor for the PageGroup. - * - * @param factory the resource manager - * @param name the name of the page group - */ - public PageGroup(Factory factory, String name) { - super(factory, name); - } - - private List getTagLogicalElements() { - if (tagLogicalElements == null) { - this.tagLogicalElements = new java.util.ArrayList(); - } - return this.tagLogicalElements; - } - - /** - * Creates a TagLogicalElement on the page. - * - * @param name - * the name of the tag - * @param value - * the value of the tag - */ - public void createTagLogicalElement(String name, String value) { - TagLogicalElement tle = factory.createTagLogicalElement(name, value); - if (!getTagLogicalElements().contains(tle)) { - getTagLogicalElements().add(tle); - } - } - - /** - * Method to mark the end of the page group. - */ - protected void endPageGroup() { - complete = true; - } - - /** {@inheritDoc} */ - protected void writeContent(OutputStream os) throws IOException { - writeObjects(tagLogicalElements, os); - super.writeContent(os); - } - - /** {@inheritDoc} */ - protected void writeStart(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.BEGIN, Category.PAGE_GROUP); - os.write(data); - } - - /** {@inheritDoc} */ - protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.END, Category.PAGE_GROUP); - os.write(data); - } - - /** {@inheritDoc} */ - public String toString() { - return this.getName(); - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/PageObject.java b/src/java/org/apache/fop/render/afp/modca/PageObject.java deleted file mode 100644 index fae4a6252..000000000 --- a/src/java/org/apache/fop/render/afp/modca/PageObject.java +++ /dev/null @@ -1,218 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.ioca.ImageCellPosition; -import org.apache.fop.render.afp.ioca.ImageInputDescriptor; -import org.apache.fop.render.afp.ioca.ImageOutputControl; -import org.apache.fop.render.afp.ioca.ImageRasterData; -import org.apache.fop.render.afp.ioca.ImageRasterPattern; - -/** - * Pages contain the data objects that comprise a presentation document. Each - * page has a set of data objects associated with it. Each page within a - * document is independent from any other page, and each must establish its own - * environment parameters. - * - * The page is the level in the document component hierarchy that is used for - * printing or displaying a document's content. The data objects contained in - * the page envelope in the data stream are presented when the page is - * presented. Each data object has layout information associated with it that - * directs the placement and orientation of the data on the page. In addition, - * each page contains layout information that specifies the measurement units, - * page width, and page depth. - * - * A page is initiated by a begin page structured field and terminated by an end - * page structured field. Structured fields that define objects and active - * environment groups or that specify attributes of the page may be encountered - * in page state. - * - */ -public class PageObject extends AbstractResourceGroupContainer { - - /** - * Construct a new page object for the specified name argument, the page - * name should be an 8 character identifier. - * - * @param factory the resource manager - * - * @param name - * the name of the page. - * @param width - * the width of the page. - * @param height - * the height of the page. - * @param rotation - * the rotation of the page. - * @param widthRes - * the width resolution of the page. - * @param heightRes - * the height resolution of the page. - */ - public PageObject(Factory factory, - String name, int width, int height, int rotation, - int widthRes, int heightRes) { - super(factory, name, width, height, rotation, widthRes, heightRes); - } - - /** - * Creates an IncludePageOverlay on the page. - * - * @param name - * the name of the overlay - * @param x - * the x position of the overlay - * @param y - * the y position of the overlay - * @param orientation - * the orientation required for the overlay - */ - public void createIncludePageOverlay(String name, int x, int y, int orientation) { - getActiveEnvironmentGroup().createOverlay(name); - IncludePageOverlay ipo = new IncludePageOverlay(name, x, y, orientation); - addObject(ipo); - } - - /** - * 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 grayscale). - * - * @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 red - * the red value - * @param green - * the green value - * @param blue - * the blue value - */ - public void createShading(int x, int y, int w, int h, int red, int green, int blue) { - int xCoord = 0; - int yCoord = 0; - int areaWidth = 0; - int areaHeight = 0; - switch (rotation) { - case 90: - xCoord = areaWidth - y - h; - yCoord = x; - areaWidth = h; - areaHeight = w; - break; - case 180: - xCoord = areaWidth - x - w; - yCoord = areaHeight - y - h; - areaWidth = w; - areaHeight = h; - break; - case 270: - xCoord = y; - yCoord = areaHeight - x - w; - areaWidth = h; - areaHeight = w; - break; - default: - xCoord = x; - yCoord = y; - areaWidth = w; - areaHeight = h; - break; - } - - // Convert the color to grey scale - float shade = (float) ((red * 0.3) + (green * 0.59) + (blue * 0.11)); - - int grayscale = Math.round((shade / 255) * 16); - - IMImageObject imImageObject = factory.createIMImageObject(); - - ImageOutputControl imageOutputControl = new ImageOutputControl(0, 0); - ImageInputDescriptor imageInputDescriptor = new ImageInputDescriptor(); - ImageCellPosition imageCellPosition = new ImageCellPosition(xCoord, yCoord); - imageCellPosition.setXFillSize(areaWidth); - imageCellPosition.setYFillSize(areaHeight); - imageCellPosition.setXSize(64); - imageCellPosition.setYSize(8); - - //defining this as a resource - byte[] rasterData = ImageRasterPattern.getRasterData(grayscale); - ImageRasterData imageRasterData = factory.createImageRasterData(rasterData); - - imImageObject.setImageOutputControl(imageOutputControl); - imImageObject.setImageInputDescriptor(imageInputDescriptor); - imImageObject.setImageCellPosition(imageCellPosition); - imImageObject.setImageRasterData(imageRasterData); - addObject(imImageObject); - } - - /** {@inheritDoc} */ - protected void writeStart(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.BEGIN, Category.PAGE); - os.write(data); - } - - /** {@inheritDoc} */ - protected void writeContent(OutputStream os) throws IOException { - writeTriplets(os); - - getActiveEnvironmentGroup().writeToStream(os); - - writeObjects(includePageSegments, os); - writeObjects(tagLogicalElements, os); - writeObjects(objects, os); - } - - /** {@inheritDoc} */ - protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.END, Category.PAGE); - os.write(data); - } - - /** - * Adds an AFP object reference to this page - * - * @param obj an AFP object - */ - public void addObject(Object obj) { - endPresentationObject(); - super.addObject(obj); - } - - /** {@inheritDoc} */ - public String toString() { - return this.getName(); - } - - /** {@inheritDoc} */ - protected boolean canWrite(AbstractAFPObject ao) { - return true; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/PageSegment.java b/src/java/org/apache/fop/render/afp/modca/PageSegment.java deleted file mode 100644 index 292deb1b1..000000000 --- a/src/java/org/apache/fop/render/afp/modca/PageSegment.java +++ /dev/null @@ -1,90 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.List; - -/** - * A page segment is a MO:DCA-P resource object. It may be stored in an - * external resource library or it may be carried in a resource group. - * Page segments contain any combination of IOCA image objects and - * GOCA graphics objects. - */ -public class PageSegment extends AbstractNamedAFPObject { - - private List/**/ objects = null; - - /** - * Main constructor - * - * @param name the name of this object - */ - public PageSegment(String name) { - super(name); - } - - /** - * Returns a list of objects contained withing this page segment - * - * @return a list of objects contained within this page segment - */ - public List/**/ getObjects() { - if (objects == null) { - objects = new java.util.ArrayList(); - } - return objects; - } - - /** - * Adds a resource object (image/graphic) to this page segment - * - * @param object the resource objec to add to this page segment - */ - public void addObject(AbstractAFPObject object) { - getObjects().add(object); - } - - /** {@inheritDoc} */ - protected void writeStart(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.BEGIN, Category.PAGE_SEGMENT); - os.write(data); - } - - /** {@inheritDoc} */ - protected void writeContent(OutputStream os) throws IOException { - super.writeContent(os); - writeObjects(objects, os); - } - - /** {@inheritDoc} */ - protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.END, Category.PAGE_SEGMENT); - os.write(data); - } - - /** {@inheritDoc} */ - public String toString() { - return this.name; - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/PreparedAFPObject.java b/src/java/org/apache/fop/render/afp/modca/PreparedAFPObject.java deleted file mode 100644 index 6856d3287..000000000 --- a/src/java/org/apache/fop/render/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.render.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/render/afp/modca/PreprocessPresentationObject.java b/src/java/org/apache/fop/render/afp/modca/PreprocessPresentationObject.java deleted file mode 100644 index 000988a3d..000000000 --- a/src/java/org/apache/fop/render/afp/modca/PreprocessPresentationObject.java +++ /dev/null @@ -1,145 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.modca.triplets.FullyQualifiedNameTriplet; -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * The Preprocess Presentation Object structured field specifies presentation - * parameters for a data object that has been mapped as a resource. - */ -public class PreprocessPresentationObject extends AbstractStructuredAFPObject { - 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 - */ - public PreprocessPresentationObject(AbstractStructuredAFPObject prePresObj) { - if (prePresObj instanceof ImageObject || prePresObj instanceof Overlay) { - if (prePresObj instanceof ImageObject) { - this.objType = TYPE_IMAGE; - } else { - this.objType = TYPE_OVERLAY; - } - setFullyQualifiedName( - 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; - } - - /** - * 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; - } - - /** - * Sets the Y axis origin for object content - * - * @param yOffset the Y axis origin for object content - */ - public void setYOffset(int yOffset) { - this.objYOffset = yOffset; - } - - /** {@inheritDoc} */ - public void writeStart(OutputStream os) throws IOException { - super.writeStart(os); - - byte[] data = new byte[9]; - copySF(data, Type.PROCESS, Category.DATA_RESOURCE); - - byte[] l = BinaryUtils.convert(19 + getTripletDataLength(), 2); - data[1] = l[0]; // Length byte 1 - data[2] = l[1]; // Length byte 1 - - os.write(data); - } - - /** {@inheritDoc} */ - public void writeContent(OutputStream os) throws IOException { - byte[] data = new byte[12]; - byte[] l = BinaryUtils.convert(12 + getTripletDataLength(), 2); - data[0] = l[0]; // RGLength - data[1] = l[1]; // RGLength - data[2] = objType; // ObjType - data[3] = 0x00; // Reserved - data[4] = 0x00; // Reserved - data[5] = objOrent; // ObjOrent - if (objXOffset > 0) { - byte[] xOff = BinaryUtils.convert(objYOffset, 3); - data[6] = xOff[0]; // XocaOset (not specified) - data[7] = xOff[1]; // XocaOset - data[8] = xOff[2]; // XocaOset - } else { - data[6] = (byte)0xFF; // XocaOset (not specified) - data[7] = (byte)0xFF; // XocaOset - data[8] = (byte)0xFF; // XocaOset - } - if (objYOffset > 0) { - byte[] yOff = BinaryUtils.convert(objYOffset, 3); - data[9] = yOff[0]; // YocaOset (not specified) - data[10] = yOff[1]; // YocaOset - data[11] = yOff[2]; // YocaOset - } else { - data[9] = (byte)0xFF; // YocaOset (not specified) - data[10] = (byte)0xFF; // YocaOset - data[11] = (byte)0xFF; // YocaOset - } - os.write(data); - - // Triplets - super.writeContent(os); - } - -} diff --git a/src/java/org/apache/fop/render/afp/modca/PresentationEnvironmentControl.java b/src/java/org/apache/fop/render/afp/modca/PresentationEnvironmentControl.java deleted file mode 100644 index f186f930c..000000000 --- a/src/java/org/apache/fop/render/afp/modca/PresentationEnvironmentControl.java +++ /dev/null @@ -1,97 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.modca.triplets.Triplet; -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * The Presentation Environment Control structured field specifies parameters that - * affect the rendering of presentation data and the appearance that is to be assumed - * by the presentation device. - */ -public class PresentationEnvironmentControl extends AbstractStructuredAFPObject { - - /** - * Main constructor - */ - 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]; - copySF(data, Type.CONTROL, Category.DOCUMENT); - int tripletDataLen = getTripletDataLength(); - byte[] len = BinaryUtils.convert(10 + tripletDataLen); - data[1] = len[0]; - data[2] = len[1]; - data[9] = 0x00; // Reserved; must be zero - data[10] = 0x00; // Reserved; must be zero - - os.write(data); - os.write(tripletData); - } - - // TODO - private class DeviceAppearanceTriplet extends Triplet { - public DeviceAppearanceTriplet() { - super(Triplet.DEVICE_APPEARANCE); - } - } - - // TODO - private class RenderingIntentTriplet extends Triplet { - public RenderingIntentTriplet() { - super(Triplet.RENDERING_INTENT); - } - } - - // TODO - private class ObjectOffsetTriplet extends Triplet { - public ObjectOffsetTriplet() { - super(Triplet.OBJECT_OFFSET); - } - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/PresentationTextData.java b/src/java/org/apache/fop/render/afp/modca/PresentationTextData.java deleted file mode 100644 index dc0512b6d..000000000 --- a/src/java/org/apache/fop/render/afp/modca/PresentationTextData.java +++ /dev/null @@ -1,569 +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.render.afp.modca; - -import java.awt.Color; -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.commons.io.output.ByteArrayOutputStream; -import org.apache.fop.render.afp.AFPLineDataInfo; -import org.apache.fop.render.afp.AFPTextDataInfo; -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * Presentation text data contains the graphic characters and the control - * sequences necessary to position the characters within the object space. The - * data consists of: - graphic characters to be presented - control sequences - * that position them - modal control sequences that adjust the positions by - * small amounts - other functions causing text to be presented with differences - * in appearance. - * - * The graphic characters are expected to conform to a coded font representation - * so that they can be translated from the code point in the object data to the - * character in the coded font. The units of measure for linear displacements - * are derived from the PresentationTextDescriptor or from the hierarchical - * defaults. - * - * In addition to graphic character code points, Presentation Text data can - * contain embedded control sequences. These are strings of two or more bytes - * which signal an alternate mode of processing for the content of the current - * Presentation Text data. - * - */ -public class PresentationTextData extends AbstractAFPObject { - - /** - * The maximum size of the presentation text data. - */ - private static final int MAX_SIZE = 8192; - - /** - * The afp data relating to this presentation text data. - */ - private final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - /** - * The current x coordinate. - */ - private int currentX = -1; - - /** - * The current y cooridnate - */ - private int currentY = -1; - - /** - * The current font - */ - private String currentFont = ""; - - /** - * The current orientation - */ - private int currentOrientation = 0; - - /** - * The current color - */ - private Color currentColor = new Color(0, 0, 0); - - /** - * The current variable space increment - */ - private int currentVariableSpaceCharacterIncrement = 0; - - /** - * The current inter character adjustment - */ - private int currentInterCharacterAdjustment = 0; - - /** - * Default constructor for the PresentationTextData. - */ - public PresentationTextData() { - this(false); - } - - /** - * Constructor for the PresentationTextData, the boolean flag indicate - * whether the control sequence prefix should be set to indicate the start - * of a new control sequence. - * - * @param controlInd - * The control sequence indicator. - */ - public PresentationTextData(boolean controlInd) { - final byte[] data = { - 0x5A, // Structured field identifier - 0x00, // Record length byte 1 - 0x00, // Record length byte 2 - (byte) 0xD3, // PresentationTextData identifier byte 1 - (byte) 0xEE, // PresentationTextData identifier byte 2 - (byte) 0x9B, // PresentationTextData identifier byte 3 - 0x00, // Flag - 0x00, // Reserved - 0x00, // Reserved - }; - baos.write(data, 0, 9); - - if (controlInd) { - baos.write(new byte[] {0x2B, (byte) 0xD3}, 0, 2); - } - } - - /** - * The Set Coded Font Local control sequence activates a coded font and - * specifies the character attributes to be used. This is a modal control - * sequence. - * - * @param font - * The font local identifier. - * @param afpdata - * The output stream to which data should be written. - */ - private void setCodedFont(byte font, ByteArrayOutputStream afpdata) { - // Avoid unnecessary specification of the font - if (String.valueOf(font).equals(currentFont)) { - return; - } else { - currentFont = String.valueOf(font); - } - - afpdata.write(new byte[] {0x03, (byte) 0xF1, font}, 0, 3); - } - - /** - * Establishes the current presentation position on the baseline at a new - * I-axis coordinate, which is a specified number of measurement units from - * the B-axis. There is no change to the current B-axis coordinate. - * - * @param coordinate - * The coordinate for the inline move. - * @param afpdata - * The output stream to which data should be written. - */ - private void absoluteMoveInline(int coordinate, - ByteArrayOutputStream afpdata) { - byte[] b = BinaryUtils.convert(coordinate, 2); - afpdata.write(new byte[] {0x04, (byte) 0xC7, b[0], b[1]}, 0, 4); - currentX = coordinate; - } - - /** - * Establishes the baseline and the current presentation position at a new - * B-axis coordinate, which is a specified number of measurement units from - * the I-axis. There is no change to the current I-axis coordinate. - * - * @param coordinate - * The coordinate for the baseline move. - * @param afpdata - * The output stream to which data should be written. - */ - private void absoluteMoveBaseline(int coordinate, - ByteArrayOutputStream afpdata) { - byte[] b = BinaryUtils.convert(coordinate, 2); - afpdata.write(new byte[] {0x04, (byte) 0xD3, b[0], b[1]}, 0, 4); - currentY = coordinate; - } - - private static final int TRANSPARENT_MAX_SIZE = 253; - - /** - * The Transparent Data control sequence contains a sequence of code points - * that are presented without a scan for embedded control sequences. - * - * @param data - * The text data to add. - * @param afpdata - * The output stream to which data should be written. - */ - private void addTransparentData(byte[] data, ByteArrayOutputStream afpdata) { - // Calculate the length - int l = data.length + 2; - if (l > 255) { - // Check that we are not exceeding the maximum length - throw new IllegalArgumentException( - "Transparent data is longer than " + TRANSPARENT_MAX_SIZE + " bytes: " + data); - } - afpdata.write(new byte[] {BinaryUtils.convert(l)[0], (byte) 0xDB}, - 0, 2); - afpdata.write(data, 0, data.length); - } - - /** - * Draws a line of specified length and specified width in the B-direction - * from the current presentation position. The location of the current - * presentation position is unchanged. - * - * @param length - * The length of the rule. - * @param width - * The width of the rule. - * @param afpdata - * The output stream to which data should be written. - */ - private void drawBaxisRule(int length, int width, - ByteArrayOutputStream afpdata) { - afpdata.write(new byte[] { - 0x07, // Length - (byte) 0xE7, // Type - }, 0, 2); - // Rule length - byte[] data1 = BinaryUtils.shortToByteArray((short) length); - afpdata.write(data1, 0, data1.length); - // Rule width - byte[] data2 = BinaryUtils.shortToByteArray((short) width); - afpdata.write(data2, 0, data2.length); - // Rule width fraction - afpdata.write(0x00); - } - - /** - * Draws a line of specified length and specified width in the I-direction - * from the current presentation position. The location of the current - * presentation position is unchanged. - * - * @param length - * The length of the rule. - * @param width - * The width of the rule. - * @param afpdata - * The output stream to which data should be written. - */ - private void drawIaxisRule(int length, int width, - ByteArrayOutputStream afpdata) { - afpdata.write(new byte[] { - 0x07, // Length - (byte) 0xE5, // Type - }, 0, 2); - // Rule length - byte[] data1 = BinaryUtils.shortToByteArray((short) length); - afpdata.write(data1, 0, data1.length); - // Rule width - byte[] data2 = BinaryUtils.shortToByteArray((short) width); - afpdata.write(data2, 0, data2.length); - // Rule width fraction - afpdata.write(0x00); - } - - /** - * Create the presentation text data for the byte array of data. - * - * @param textDataInfo - * the afp text data - * @throws MaximumSizeExceededException - * thrown if the maximum number of text data is exceeded - */ - public void createTextData(AFPTextDataInfo textDataInfo) - throws MaximumSizeExceededException { - - ByteArrayOutputStream afpdata = new ByteArrayOutputStream(); - - int rotation = textDataInfo.getRotation(); - if (currentOrientation != rotation) { - setTextOrientation(rotation, afpdata); - currentOrientation = rotation; - currentX = -1; - currentY = -1; - } - - // Avoid unnecessary specification of the Y coordinate - int y = textDataInfo.getY(); - if (currentY != y) { - absoluteMoveBaseline(y, afpdata); - currentX = -1; - } - - // Avoid unnecessary specification of the X coordinate - int x = textDataInfo.getX(); - if (currentX != x) { - absoluteMoveInline(x, afpdata); - } - - // Avoid unnecessary specification of the variable space increment - if (textDataInfo.getVariableSpaceCharacterIncrement() - != currentVariableSpaceCharacterIncrement) { - setVariableSpaceCharacterIncrement(textDataInfo - .getVariableSpaceCharacterIncrement(), afpdata); - currentVariableSpaceCharacterIncrement = textDataInfo - .getVariableSpaceCharacterIncrement(); - } - - // Avoid unnecessary specification of the inter character adjustment - if (textDataInfo.getInterCharacterAdjustment() != currentInterCharacterAdjustment) { - setInterCharacterAdjustment(textDataInfo.getInterCharacterAdjustment(), - afpdata); - currentInterCharacterAdjustment = textDataInfo - .getInterCharacterAdjustment(); - } - - // Avoid unnecessary specification of the text color - if (!textDataInfo.getColor().equals(currentColor)) { - setExtendedTextColor(textDataInfo.getColor(), afpdata); - currentColor = textDataInfo.getColor(); - } - - setCodedFont(BinaryUtils.convert(textDataInfo.getFontReference())[0], - afpdata); - - // Add transparent data - byte[] data = textDataInfo.getData(); - if (data.length <= TRANSPARENT_MAX_SIZE) { - addTransparentData(data, afpdata); - } else { - // data size greater than TRANSPARENT_MAX_SIZE so slice - int numTransData = data.length / TRANSPARENT_MAX_SIZE; - byte[] buff = new byte[TRANSPARENT_MAX_SIZE]; - int currIndex = 0; - for (int transDataCnt = 0; transDataCnt < numTransData; transDataCnt++) { - currIndex = transDataCnt * TRANSPARENT_MAX_SIZE; - System.arraycopy(data, currIndex, buff, 0, TRANSPARENT_MAX_SIZE); - addTransparentData(buff, afpdata); - } - int remainingTransData = data.length / TRANSPARENT_MAX_SIZE; - buff = new byte[remainingTransData]; - System.arraycopy(data, currIndex, buff, 0, remainingTransData); - addTransparentData(buff, afpdata); - } - currentX = -1; - - int dataSize = afpdata.size(); - - if (baos.size() + dataSize > MAX_SIZE) { - currentX = -1; - currentY = -1; - throw new MaximumSizeExceededException(); - } - - byte[] outputdata = afpdata.toByteArray(); - baos.write(outputdata, 0, outputdata.length); - } - - private int ensurePositive(int value) { - if (value < 0) { - return 0; - } - return value; - } - - /** - * Drawing of lines using the starting and ending coordinates, thickness and - * colour arguments. - * - * @param lineDataInfo the line data information. - * @throws MaximumSizeExceededException - * thrown if the maximum number of line data has been exceeded - */ - public void createLineData(AFPLineDataInfo lineDataInfo) throws MaximumSizeExceededException { - - ByteArrayOutputStream afpdata = new ByteArrayOutputStream(); - - int orientation = lineDataInfo.getRotation(); - if (currentOrientation != orientation) { - setTextOrientation(orientation, afpdata); - currentOrientation = orientation; - } - - // Avoid unnecessary specification of the Y coordinate - int y1 = ensurePositive(lineDataInfo.getY1()); - if (y1 != currentY) { - absoluteMoveBaseline(y1, afpdata); - } - - // Avoid unnecessary specification of the X coordinate - int x1 = ensurePositive(lineDataInfo.getX1()); - if (x1 != currentX) { - absoluteMoveInline(x1, afpdata); - } - - Color color = lineDataInfo.getColor(); - if (!color.equals(currentColor)) { - setExtendedTextColor(color, afpdata); - currentColor = color; - } - - int x2 = ensurePositive(lineDataInfo.getX2()); - int y2 = ensurePositive(lineDataInfo.getY2()); - int thickness = lineDataInfo.getThickness(); - if (y1 == y2) { - drawIaxisRule(x2 - x1, thickness, afpdata); - } else if (x1 == x2) { - drawBaxisRule(y2 - y1, thickness, afpdata); - } else { - log.error("Invalid axis rule unable to draw line"); - return; - } - - int dataSize = afpdata.size(); - - if (baos.size() + dataSize > MAX_SIZE) { - currentX = -1; - currentY = -1; - throw new MaximumSizeExceededException(); - } - - byte[] outputdata = afpdata.toByteArray(); - baos.write(outputdata, 0, outputdata.length); - } - - /** - * The Set Text Orientation control sequence establishes the I-direction and - * B-direction for the subsequent text. This is a modal control sequence. - * - * Semantics: This control sequence specifies the I-axis and B-axis - * orientations with respect to the Xp-axis for the current Presentation - * Text object. The orientations are rotational values expressed in degrees - * and minutes. - * - * @param orientation - * The text orientation (0, 90, 180, 270). - * @param os - * The output stream to which data should be written. - */ - private void setTextOrientation(int orientation, - ByteArrayOutputStream os) { - os.write(new byte[] {0x06, (byte) 0xF7, }, 0, 2); - switch (orientation) { - case 90: - os.write(0x2D); - os.write(0x00); - os.write(0x5A); - os.write(0x00); - break; - case 180: - os.write(0x5A); - os.write(0x00); - os.write(0x87); - os.write(0x00); - break; - case 270: - os.write(0x87); - os.write(0x00); - os.write(0x00); - os.write(0x00); - break; - default: - os.write(0x00); - os.write(0x00); - os.write(0x2D); - os.write(0x00); - break; - } - } - - /** - * The Set Extended Text Color control sequence specifies a color value and - * defines the color space and encoding for that value. The specified color - * value is applied to foreground areas of the text presentation space. This - * is a modal control sequence. - * - * @param col - * The color to be set. - * @param os - * The output stream to which data should be written. - */ - private void setExtendedTextColor(Color col, ByteArrayOutputStream os) { - byte[] colorData = new byte[] { - 15, // Control sequence length - (byte) 0x81, // Control sequence function type - 0x00, // Reserved; must be zero - 0x01, // Color space - 0x01 = RGB - 0x00, // Reserved; must be zero - 0x00, // Reserved; must be zero - 0x00, // Reserved; must be zero - 0x00, // Reserved; must be zero - 8, // Number of bits in component 1 - 8, // Number of bits in component 2 - 8, // Number of bits in component 3 - 0, // Number of bits in component 4 - (byte) (col.getRed()), // Red intensity - (byte) (col.getGreen()), // Green intensity - (byte) (col.getBlue()), // Blue intensity - }; - - os.write(colorData, 0, colorData.length); - } - - /** - * //TODO This is a modal control sequence. - * - * @param incr - * The increment to be set. - * @param os - * The output stream to which data should be written. - */ - private void setVariableSpaceCharacterIncrement(int incr, - ByteArrayOutputStream os) { - byte[] b = BinaryUtils.convert(incr, 2); - - os.write(new byte[] { - 4, // Control sequence length - (byte) 0xC5, // Control sequence function type - b[0], b[1] }, - 0, 4); - } - - /** - * //TODO This is a modal control sequence. - * - * @param incr - * The increment to be set. - * @param os - * The output stream to which data should be written. - */ - private void setInterCharacterAdjustment(int incr, ByteArrayOutputStream os) { - byte[] b = BinaryUtils.convert(Math.abs(incr), 2); - os.write(new byte[] { - 5, // Control sequence length - (byte) 0xC3, // Control sequence function type - b[0], b[1], (byte) (incr >= 0 ? 0 : 1) // Direction - }, 0, 5); - } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - byte[] data = baos.toByteArray(); - byte[] size = BinaryUtils.convert(data.length - 1, 2); - data[1] = size[0]; - data[2] = size[1]; - os.write(data); - } - - /** - * A control sequence is a sequence of bytes that specifies a control - * function. A control sequence consists of a control sequence introducer - * and zero or more parameters. The control sequence can extend multiple - * presentation text data objects, but must eventually be terminated. This - * method terminates the control sequence. - * - * @throws MaximumSizeExceededException - * thrown in the event that maximum size has been exceeded - */ - public void endControlSequence() throws MaximumSizeExceededException { - byte[] data = new byte[2]; - data[0] = 0x02; - data[1] = (byte) 0xF8; - if (data.length + baos.size() > MAX_SIZE) { - throw new MaximumSizeExceededException(); - } - baos.write(data, 0, data.length); - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/PresentationTextDescriptor.java b/src/java/org/apache/fop/render/afp/modca/PresentationTextDescriptor.java deleted file mode 100644 index 807aba4d7..000000000 --- a/src/java/org/apache/fop/render/afp/modca/PresentationTextDescriptor.java +++ /dev/null @@ -1,100 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * The Presentation Text Descriptor specifies the units of measure for the - * Presentation Text object space, the size of the Presentation Text object - * space, and the initial values for modal parameters, called initial text - * conditions. Initial values not provided are defaulted by the controlling - * environment or the receiving device. - * - * The Presentation Text Descriptor provides the following initial values: - * - Unit base - * - Xp-units per unit base - * - Yp-units per unit base - * - Xp-extent of the presentation space - * - Yp-extent of the presentation space - * - Initial text conditions. - * - * The initial text conditions are values provided by the Presentation Text - * Descriptor to initialize the modal parameters of the control sequences. - * Modal control sequences typically are characterized by the word set in - * the name of the control sequence. Modal parameters are identified as such - * in their semantic descriptions. - * - */ -public class PresentationTextDescriptor extends AbstractDescriptor { - - /** - * Constructor a PresentationTextDescriptor for the specified - * width and height. - * - * @param width The width of the page. - * @param height The height of the page. - * @param widthRes The width resolution of the page. - * @param heightRes The height resolution of the page. - */ - public PresentationTextDescriptor(int width, int height, - int widthRes, int heightRes) { - super(width, height, widthRes, heightRes); - } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - byte[] data = new byte[23]; - - copySF(data, Type.MIGRATION, Category.PRESENTATION_TEXT); - - data[1] = 0x00; // length - data[2] = 0x16; - - data[9] = 0x00; - data[10] = 0x00; - - byte[] xdpi = BinaryUtils.convert(widthRes * 10, 2); - data[11] = xdpi[0]; // xdpi - data[12] = xdpi[1]; - - byte[] ydpi = BinaryUtils.convert(heightRes * 10, 2); - data[13] = ydpi[0]; // ydpi - data[14] = ydpi[1]; - - byte[] x = BinaryUtils.convert(width, 3); - data[15] = x[0]; - data[16] = x[1]; - data[17] = x[2]; - - byte[] y = BinaryUtils.convert(height, 3); - data[18] = y[0]; - data[19] = y[1]; - data[20] = y[2]; - - data[21] = 0x00; - data[22] = 0x00; - - os.write(data); - } - -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/PresentationTextObject.java b/src/java/org/apache/fop/render/afp/modca/PresentationTextObject.java deleted file mode 100644 index 4071ebb9d..000000000 --- a/src/java/org/apache/fop/render/afp/modca/PresentationTextObject.java +++ /dev/null @@ -1,169 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.List; - -import org.apache.fop.render.afp.AFPLineDataInfo; -import org.apache.fop.render.afp.AFPTextDataInfo; - -/** - * The Presentation Text object is the data object used in document processing - * environments for representing text which has been prepared for presentation. - * Text, as used here, means an ordered string of characters, such as graphic - * symbols, numbers, and letters, that are suitable for the specific purpose of - * representing coherent information. Text which has been prepared for - * presentation has been reduced to a primitive form through explicit - * specification of the characters and their placement in the presentation - * space. Control sequences which designate specific control functions may be - * embedded within the text. These functions extend the primitive form by - * applying specific characteristics to the text when it is presented. The - * collection of the graphic characters and control codes is called Presentation - * Text, and the object that contains the Presentation Text is called the - * PresentationText object. - */ -public class PresentationTextObject extends AbstractNamedAFPObject { - - /** - * The current presentation text data - */ - private PresentationTextData currentPresentationTextData = null; - - /** - * The presentation text data list - */ - private List/**/ presentationTextDataList = null; - - /** - * Construct a new PresentationTextObject for the specified name argument, - * the name should be an 8 character identifier. - * - * @param name the name of this presentation object - */ - public PresentationTextObject(String name) { - super(name); - } - - /** - * Create the presentation text data for the byte array of data. - * - * @param textDataInfo - * The afp text data - */ - public void createTextData(AFPTextDataInfo textDataInfo) { - if (currentPresentationTextData == null) { - startPresentationTextData(); - } - try { - currentPresentationTextData.createTextData(textDataInfo); - } catch (MaximumSizeExceededException msee) { - endPresentationTextData(); - createTextData(textDataInfo); - } - } - - /** - * Drawing of lines using the starting and ending coordinates, thickness and - * orientation arguments. - * - * @param lineDataInfo the line data information. - */ - public void createLineData(AFPLineDataInfo lineDataInfo) { - if (currentPresentationTextData == null) { - startPresentationTextData(); - } - try { - currentPresentationTextData.createLineData(lineDataInfo); - } catch (MaximumSizeExceededException msee) { - endPresentationTextData(); - createLineData(lineDataInfo); - } - } - - /** - * Helper method to mark the start of the presentation text data - */ - private void startPresentationTextData() { - if (presentationTextDataList == null) { - presentationTextDataList = new java.util.ArrayList/**/(); - } - if (presentationTextDataList.size() == 0) { - currentPresentationTextData = new PresentationTextData(true); - } else { - currentPresentationTextData = new PresentationTextData(); - } - presentationTextDataList.add(currentPresentationTextData); - } - - /** - * Helper method to mark the end of the presentation text data - */ - private void endPresentationTextData() { - this.currentPresentationTextData = null; - } - - /** {@inheritDoc} */ - protected void writeStart(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.BEGIN, Category.PRESENTATION_TEXT); - os.write(data); - } - - /** {@inheritDoc} */ - protected void writeContent(OutputStream os) throws IOException { - writeObjects(this.presentationTextDataList, os); - } - - /** {@inheritDoc} */ - protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.END, Category.PRESENTATION_TEXT); - os.write(data); - } - - /** - * A control sequence is a sequence of bytes that specifies a control - * function. A control sequence consists of a control sequence introducer - * and zero or more parameters. The control sequence can extend multiple - * presentation text data objects, but must eventually be terminated. This - * method terminates the control sequence. - */ - public void endControlSequence() { - if (currentPresentationTextData == null) { - startPresentationTextData(); - } - try { - currentPresentationTextData.endControlSequence(); - } catch (MaximumSizeExceededException msee) { - endPresentationTextData(); - endControlSequence(); - } - } - - /** {@inheritDoc} */ - public String toString() { - if (presentationTextDataList != null) { - return presentationTextDataList.toString(); - } - return null; - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/Registry.java b/src/java/org/apache/fop/render/afp/modca/Registry.java deleted file mode 100644 index 3311817eb..000000000 --- a/src/java/org/apache/fop/render/afp/modca/Registry.java +++ /dev/null @@ -1,254 +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.render.afp.modca; - -import java.util.Collections; - -import org.apache.xmlgraphics.util.MimeConstants; - -/** - * MOD:CA Registry of object types - */ -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_FS45 = 12; - private static final byte COMPID_EPS = 13; - private static final byte COMPID_TIFF = 14; - private static final byte COMPID_GIF = 22; - private static final byte COMPID_JFIF = 23; // jpeg file interchange format - private static final byte COMPID_PDF_SINGLE_PAGE = 25; - private static final byte COMPID_PCL_PAGE_OBJECT = 34; - - /** mime type entry mapping */ - private final java.util.Map/**/ mimeObjectTypeMap - = Collections.synchronizedMap( - new java.util.HashMap/**/()); - - /** singleton instance */ - private static Registry instance = null; - - /** - * Returns a single instance of a MO:DCA Registry - * - * @return a single instance of an MO:DCA Registry - */ - public static Registry getInstance() { - synchronized (Registry.class) { - if (instance == null) { - instance = new Registry(); - } - } - return instance; - } - - /** - * private constructor - */ - private Registry() { - init(); - } - - /** - * Initializes the mimetype map - */ - private void init() { - mimeObjectTypeMap.put( - MimeConstants.MIME_AFP_IOCA_FS10, - new ObjectType( - COMPID_IOCA_FS10, - new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x05}, - "IOCA FS10", - true, - MimeConstants.MIME_AFP_IOCA_FS10 - ) - ); - mimeObjectTypeMap.put( - MimeConstants.MIME_AFP_IOCA_FS11, - new ObjectType( - COMPID_IOCA_FS11, - new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x11}, - "IOCA FS11", - true, - MimeConstants.MIME_AFP_IOCA_FS11 - ) - ); - mimeObjectTypeMap.put( - MimeConstants.MIME_AFP_IOCA_FS45, - new ObjectType( - COMPID_IOCA_FS45, - new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x12}, - "IOCA FS45", - true, - MimeConstants.MIME_AFP_IOCA_FS45 - ) - ); - mimeObjectTypeMap.put( - MimeConstants.MIME_EPS, - new ObjectType( - COMPID_EPS, - new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x0D}, - "Encapsulated Postscript", - true, - MimeConstants.MIME_EPS - ) - ); - mimeObjectTypeMap.put( - MimeConstants.MIME_TIFF, - new ObjectType( - COMPID_TIFF, - new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x0E}, - "TIFF", - true, - MimeConstants.MIME_TIFF - ) - ); - mimeObjectTypeMap.put( - MimeConstants.MIME_GIF, - new ObjectType( - COMPID_GIF, - new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x16}, - "GIF", - true, - MimeConstants.MIME_GIF - ) - ); - mimeObjectTypeMap.put( - MimeConstants.MIME_JPEG, - new ObjectType( - COMPID_JFIF, - new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x17}, - "JFIF", - true, - MimeConstants.MIME_JPEG - ) - ); - mimeObjectTypeMap.put(MimeConstants.MIME_PDF, - new ObjectType( - COMPID_PDF_SINGLE_PAGE, - new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x19}, - "PDF Single-page Object", - true, - MimeConstants.MIME_PDF - ) - ); - mimeObjectTypeMap.put( - MimeConstants.MIME_PCL, - new ObjectType( - COMPID_PCL_PAGE_OBJECT, - new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x22}, - "PCL Page Object", - true, - MimeConstants.MIME_PCL - ) - ); - } - - /** - * Returns the MOD:CA object type given a mimetype - * - * @param mimeType the object mimetype - * @return the MOD:CA object type - */ - public ObjectType getObjectType(String mimeType) { - return (ObjectType)mimeObjectTypeMap.get(mimeType); - } - - /** - * Encapsulates a MOD:CA Registry Object Type entry - */ - public class ObjectType { - private final byte componentId; - private final byte[] oid; - private final String name; - private final boolean includable; - private final String mimeType; - - /** - * Main constructor - * - * @param componentId the component id of this object type - * @param oid the object id of this object type - * @param name the object type name - * @param includable true if this object can be included with an IOB structured field - * @param mimeType the mime type associated with this object type - */ - public ObjectType(byte componentId, byte[] oid, String name, - boolean includable, String mimeType) { - this.name = name; - this.includable = includable; - this.mimeType = mimeType; - this.componentId = componentId; - this.oid = oid; - } - - /** - * Returns a MOD:CA object type OID from a given a componentId - * - * @return the corresponding object type id for a given component id - * or null if the component id is unknown and the object type OID was not found. - */ - public byte[] getOID() { - return this.oid; - } - - /** - * Returns the object type name for the given componentId - * - * @return the object type name for the given componentId - */ - public String getName() { - return this.name; - } - - /** - * Returns the compontentId for this entry - * - * @return the compontentId for this entry - */ - public byte getComponentId() { - return this.componentId; - } - - /** - * Returns true if this component can be included with an IOB structured field - * - * @return true if this component can be included with an IOB structured field - */ - public boolean isIncludable() { - return this.includable; - } - - /** - * Returns the mime type associated with this object type - * - * @return the mime type associated with this object type - */ - public String getMimeType() { - return this.mimeType; - } - - /** {@inheritDoc} */ - public String toString() { - return this.getName(); - } - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/ResourceEnvironmentGroup.java b/src/java/org/apache/fop/render/afp/modca/ResourceEnvironmentGroup.java deleted file mode 100644 index 1d66f560f..000000000 --- a/src/java/org/apache/fop/render/afp/modca/ResourceEnvironmentGroup.java +++ /dev/null @@ -1,134 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.List; - -/** - * 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 - */ - private static final String DEFAULT_NAME = "REG00001"; - - /** - * The maps data resources contained in this resource environment group - */ - private List/**/ mapDataResources = null; - - /** - * 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 - */ - private List/**/ preProcessPresentationObjects = null; - - /** - * The resource environment group state - */ - private boolean complete = false; - - /** - * Default constructor - */ - public ResourceEnvironmentGroup() { - this(DEFAULT_NAME); - } - - private List/**/ getMapDataResources() { - if (mapDataResources == null) { - this.mapDataResources = new java.util.ArrayList/**/(); - } - return this.mapDataResources; - } - - private List getMapPageOverlays() { - if (mapPageOverlays == null) { - this.mapPageOverlays = new java.util.ArrayList(); - } - return this.mapPageOverlays; - } - - private List/**/ getPreprocessPresentationObjects() { - if (preProcessPresentationObjects == null) { - this.preProcessPresentationObjects - = new java.util.ArrayList/**/(); - } - return this.preProcessPresentationObjects; - } - - /** - * Constructor for the ResourceEnvironmentGroup, this takes a - * name parameter which must be 8 characters long. - * @param name the resource environment group name - */ - public ResourceEnvironmentGroup(String name) { - super(name); - } - -// /** -// * Adds an AFP object mapping reference to this resource environment group -// * @param obj the object to add -// */ -// public void addObject(AbstractStructuredAFPObject obj) { -// getMapDataResources().add(new MapDataResource(obj)); -// 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]; - copySF(data, Type.BEGIN, Category.RESOURCE_ENVIROMENT_GROUP); - os.write(data); - } - - /** {@inheritDoc} */ - protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.END, Category.RESOURCE_ENVIROMENT_GROUP); - os.write(data); - } - - /** {@inheritDoc} */ - protected void writeContent(OutputStream os) throws IOException { - writeObjects(mapDataResources, os); - writeObjects(mapPageOverlays, os); - writeObjects(preProcessPresentationObjects, os); - } - -} diff --git a/src/java/org/apache/fop/render/afp/modca/ResourceGroup.java b/src/java/org/apache/fop/render/afp/modca/ResourceGroup.java deleted file mode 100644 index c412f85f7..000000000 --- a/src/java/org/apache/fop/render/afp/modca/ResourceGroup.java +++ /dev/null @@ -1,107 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.Iterator; -import java.util.Set; - -import org.apache.fop.render.afp.Streamable; - -/** - * A Resource Group contains a set of overlays. - */ -public class ResourceGroup extends AbstractNamedAFPObject { - - /** Set of resource uri */ - private final Set/**/ resourceSet = new java.util.HashSet/**/(); - - /** - * Constructor for the ResourceGroup, this takes a - * name parameter which must be 8 characters long. - * - * @param name the resource group name - */ - public ResourceGroup(String name) { - super(name); - } - - /** - * Add this named object to this resource group - * - * @param namedObject a named object - * @throws IOException thrown if an I/O exception of some sort has occurred. - */ - public void addObject(AbstractNamedAFPObject namedObject) throws IOException { - resourceSet.add(namedObject); - } - - /** - * Returns the number of resources contained in this resource group - * - * @return the number of resources contained in this resource group - */ - public int getResourceCount() { - return resourceSet.size(); - } - - /** - * Returns true if the resource exists within this resource group, - * false otherwise. - * - * @param uri the uri of the resource - * @return true if the resource exists within this resource group - */ - public boolean resourceExists(String uri) { - return resourceSet.contains(uri); - } - - /** {@inheritDoc} */ - public void writeStart(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.BEGIN, Category.RESOURCE_GROUP); - os.write(data); - } - - /** {@inheritDoc} */ - public void writeContent(OutputStream os) throws IOException { - Iterator it = resourceSet.iterator(); - while (it.hasNext()) { - Object object = it.next(); - if (object instanceof Streamable) { - Streamable streamableObject = (Streamable)object; - streamableObject.writeToStream(os); - } - } - } - - /** {@inheritDoc} */ - public void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.END, Category.RESOURCE_GROUP); - os.write(data); - } - - /** {@inheritDoc} */ - public String toString() { - return this.name + " " + resourceSet/*getResourceMap()*/; - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/ResourceObject.java b/src/java/org/apache/fop/render/afp/modca/ResourceObject.java deleted file mode 100644 index edbe30226..000000000 --- a/src/java/org/apache/fop/render/afp/modca/ResourceObject.java +++ /dev/null @@ -1,168 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.fop.render.afp.modca.triplets.Triplet; -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * This resource structured field begins an envelope that is used to carry - * resource objects in print-file-level (external) resource groups. - */ -public class ResourceObject extends AbstractPreparedAFPObject { - - private AbstractNamedAFPObject namedObject; - - /** - * Default constructor - * - * @param name the name of this resource (reference id) - */ - public ResourceObject(String name) { - super(name); - } - - /** - * Sets the data object referenced by this resource object - * - * @param obj the named data object - */ - public void setDataObject(AbstractNamedAFPObject obj) { - this.namedObject = obj; - } - - /** - * Returns the data object referenced by this resource object - * - * @return the data object referenced by this resource object - */ - public AbstractNamedAFPObject getDataObject() { - return namedObject; - } - - /** {@inheritDoc} */ - protected void writeStart(OutputStream os) throws IOException { - super.writeStart(os); - - byte[] data = new byte[19]; - copySF(data, Type.BEGIN, Category.NAME_RESOURCE); - - // Set the total record length - int tripletDataLength = getTripletDataLength(); - byte[] len = BinaryUtils.convert(18 + tripletDataLength, 2); - data[1] = len[0]; // Length byte 1 - data[2] = len[1]; // Length byte 2 - - // Set reserved bits - data[17] = 0x00; // Reserved - data[18] = 0x00; // Reserved - - os.write(data); - } - - /** {@inheritDoc} */ - protected void writeContent(OutputStream os) throws IOException { - super.writeContent(os); // write triplets - if (namedObject != null) { - namedObject.writeToStream(os); - } - } - - /** {@inheritDoc} */ - protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[17]; - copySF(data, Type.END, Category.NAME_RESOURCE); - os.write(data); - } - - /** {@inheritDoc} */ - public String toString() { - return this.getName(); - } - - /** - * Sets Resource Object Type triplet - * - * @param type the resource object type - */ - public void setType(byte type) { - getTriplets().add(new ResourceObjectTypeTriplet(type)); - } - - /** 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/render/afp/modca/StreamedResourceGroup.java b/src/java/org/apache/fop/render/afp/modca/StreamedResourceGroup.java deleted file mode 100644 index abe2e1547..000000000 --- a/src/java/org/apache/fop/render/afp/modca/StreamedResourceGroup.java +++ /dev/null @@ -1,92 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; - -/** - * A print-file resource group - */ -public class StreamedResourceGroup extends ResourceGroup { - /** the outputstream to write to */ - private final OutputStream os; - - private boolean started = false; - - private boolean complete = false; - - /** - * Main constructor - * - * @param name the resource group name - * @param os the outputstream - */ - public StreamedResourceGroup(String name, OutputStream os) { - super(name); - this.os = os; - } - - /** - * Adds a resource to the external resource group - * - * @param namedObject a named object - * @throws IOException thrown if an I/O exception of some sort has occurred. - */ - public void addObject(AbstractNamedAFPObject namedObject) throws IOException { - if (!started) { - writeStart(os); - started = true; - } - try { - namedObject.writeToStream(os); - } finally { - os.flush(); - } - } - - /** - * Closes this external resource group file - * - * @throws IOException thrown if an I/O exception of some sort has occurred. - */ - public void close() throws IOException { - writeEnd(os); - 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 - * - * @return the outputstream - */ - public OutputStream getOutputStream() { - return this.os; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/TagLogicalElement.java b/src/java/org/apache/fop/render/afp/modca/TagLogicalElement.java deleted file mode 100644 index 64160c087..000000000 --- a/src/java/org/apache/fop/render/afp/modca/TagLogicalElement.java +++ /dev/null @@ -1,130 +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.render.afp.modca; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; - -import org.apache.fop.render.afp.AFPConstants; -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * A Tag Logical Element structured field assigns an attribute name and an - * attribute value to a page or page group. The Tag Logical Element structured - * field may be embedded directly in the page or page group, or it may reference - * the page or page group from a document index. When a Tag Logical Element - * structured field references a page or is embedded in a page following the - * active environment group, it is associated with the page. When a Tag Logical - * Element structured field references a page group or is embedded in a page - * group following the Begin Named Page Group structured field, it is associated - * with the page group. When a Tag Logical Element structured field is associated - * with a page group, the parameters of the Tag Logical Element structured field - * are inherited by all pages in the page group and by all other page groups - * that are nested in the page group. The scope of a Tag Logical Element is - * determined by its position with respect to other TLEs that reference, or are - * embedded in, the same page or page group. The Tag Logical Element structured - * field does not provide any presentation specifications and therefore has no - * effect on the appearance of a document when it is presented. - *

- */ -public class TagLogicalElement extends AbstractAFPObject { - - /** - * Name of the key, used within the TLE - */ - private String name = null; - - /** - * Value returned by the key - */ - private String value = null; - - /** - * Construct a tag logical element with the name and value specified. - * - * @param name the name of the tag logical element - * @param value the value of the tag logical element - */ - public TagLogicalElement(String name, String value) { - this.name = name; - this.value = value; - } - - /** {@inheritDoc} */ - public void writeToStream(OutputStream os) throws IOException { - - byte[] data = new byte[17 + name.length() + value.length()]; - - data[0] = 0x5A; - // Set the total record length - byte[] rl1 - = BinaryUtils.convert(16 + name.length() + value.length(), 2); - //Ignore first byte - data[1] = rl1[0]; - data[2] = rl1[1]; - - // Structured field ID for a TLE - data[3] = (byte) 0xD3; - data[4] = (byte) Type.ATTRIBUTE; - data[5] = (byte) Category.PROCESS_ELEMENT; - - data[6] = 0x00; // Reserved - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - - //Use 2 triplets, attrubute name and value (the key for indexing) - - byte[] rl2 = BinaryUtils.convert(name.length() + 4, 1); - data[9] = rl2[0]; // length of the triplet, including this field - data[10] = 0x02; //Identifies it as a FQN triplet - data[11] = 0x0B; // GID format - data[12] = 0x00; - - byte[] tleByteName = null; - byte[] tleByteValue = null; - try { - tleByteName = name.getBytes(AFPConstants.EBCIDIC_ENCODING); - tleByteValue = value.getBytes(AFPConstants.EBCIDIC_ENCODING); - } catch (UnsupportedEncodingException usee) { - tleByteName = name.getBytes(); - tleByteValue = value.getBytes(); - log.warn( - "Constructor:: UnsupportedEncodingException translating the name " - + name); - } - - int pos = 13; - for (int i = 0; i < tleByteName.length; i++) { - data[pos++] = tleByteName[i]; - } - - byte[] rl3 = BinaryUtils.convert(tleByteValue.length + 4, 1); - data[pos++] = rl3[0]; // length of the triplet, including this field - data[pos++] = 0x36; //Identifies the triplet, attribute value - data[pos++] = 0x00; // Reserved - data[pos++] = 0x00; // Reserved - - for (int i = 0; i < tleByteValue.length; i++) { - data[pos++] = tleByteValue[i]; - } - os.write(data); - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/TagLogicalElementBean.java b/src/java/org/apache/fop/render/afp/modca/TagLogicalElementBean.java deleted file mode 100644 index c47abe9b2..000000000 --- a/src/java/org/apache/fop/render/afp/modca/TagLogicalElementBean.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.render.afp.modca; - -/** - * The TagLogicalElementBean provides a bean for holding the attributes of - * a tag logical element as key value pairs. - *

- */ -public class TagLogicalElementBean { - - /** The key attribute */ - private String key; - - /** The value attribute */ - private String value; - - /** - * Constructor for the TagLogicalElementBean. - * - * @param key the key attribute - * @param value the value attribute - */ - public TagLogicalElementBean(String key, String value) { - this.key = key; - this.value = value; - } - - /** - * Getter for the key attribute. - * - * @return the key - */ - public String getKey() { - return key; - } - - /** - * Getter for the value attribute. - * - * @return the value - */ - public String getValue() { - return value; - } - -} diff --git a/src/java/org/apache/fop/render/afp/modca/triplets/ExtendedResourceLocalIdentifierTriplet.java b/src/java/org/apache/fop/render/afp/modca/triplets/ExtendedResourceLocalIdentifierTriplet.java deleted file mode 100644 index a2d42feb9..000000000 --- a/src/java/org/apache/fop/render/afp/modca/triplets/ExtendedResourceLocalIdentifierTriplet.java +++ /dev/null @@ -1,55 +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.render.afp.modca.triplets; - -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * The Extended Resource Local Identifier triplet specifies a resource type and a - * four byte local identifier or LID. The LID usually is associated with a specific - * 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 { - - /** the image resource type */ - public static final byte TYPE_IMAGE_RESOURCE = 0x10; - - /** the retired value type */ - public static final byte TYPE_RETIRED_VALUE = 0x30; - - /** the retired value type */ - public static final byte TYPE_MEDIA_RESOURCE = 0x40; - - /** - * Main constructor - * - * @param type the resource type - * @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); - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/triplets/FullyQualifiedNameTriplet.java b/src/java/org/apache/fop/render/afp/modca/triplets/FullyQualifiedNameTriplet.java deleted file mode 100644 index 68bef3e56..000000000 --- a/src/java/org/apache/fop/render/afp/modca/triplets/FullyQualifiedNameTriplet.java +++ /dev/null @@ -1,191 +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.render.afp.modca.triplets; - -import java.io.UnsupportedEncodingException; - -import org.apache.fop.render.afp.AFPConstants; - -/** - * A Fully Qualified Name triplet enable the identification and referencing of - * objects using Gloabl Identifiers (GIDs). - */ -public class FullyQualifiedNameTriplet extends Triplet { - - // 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. */ - 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; - - /** 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 - * resource and is used to located the resource object in the resource hierarchy. - * The data object that uses the resource may or may not be defined by an - * IBM presentation architecture. - */ - 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; - } - - /** - * 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.fqName = fqName; - - byte[] fqNameBytes; - String encoding = AFPConstants.EBCIDIC_ENCODING; - if (format == FORMAT_URL) { - encoding = AFPConstants.US_ASCII_ENCODING; - } - try { - fqNameBytes = fqName.getBytes(encoding); - } catch (UnsupportedEncodingException e) { - throw new IllegalArgumentException( - encoding + " encoding failed"); - } - - 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; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/triplets/MappingOptionTriplet.java b/src/java/org/apache/fop/render/afp/modca/triplets/MappingOptionTriplet.java deleted file mode 100644 index daebb6183..000000000 --- a/src/java/org/apache/fop/render/afp/modca/triplets/MappingOptionTriplet.java +++ /dev/null @@ -1,68 +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.render.afp.modca.triplets; - -/** - * Specifies the mapping of data object presentation space to object area - */ -public class MappingOptionTriplet extends Triplet { - /** - * the data object is placed in the upper left corner, all data must be presented - * within the object area extents - */ - public static final byte POSITION = 0x00; - - /** - * the data object is placed in the upper left corner, 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 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; - - /** - * Main constructor - * - * @param mapValue the mapping option to use - */ - public MappingOptionTriplet(byte mapValue) { - super(Triplet.MAPPING_OPTION, mapValue); - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/triplets/MeasurementUnitsTriplet.java b/src/java/org/apache/fop/render/afp/modca/triplets/MeasurementUnitsTriplet.java deleted file mode 100644 index 71da6e059..000000000 --- a/src/java/org/apache/fop/render/afp/modca/triplets/MeasurementUnitsTriplet.java +++ /dev/null @@ -1,54 +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.render.afp.modca.triplets; - -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * The Measurement Units triplet is used to specify the units of measure - * for a presentation space - */ -public class MeasurementUnitsTriplet extends Triplet { - - private static final byte TEN_INCHES = 0x00; - private static final byte TEN_CM = 0x01; - - /** - * 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? - byte[] xUnits = BinaryUtils.convert(xRes * 10, 2); - 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); - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/triplets/ObjectAreaSizeTriplet.java b/src/java/org/apache/fop/render/afp/modca/triplets/ObjectAreaSizeTriplet.java deleted file mode 100644 index 6b9e25a69..000000000 --- a/src/java/org/apache/fop/render/afp/modca/triplets/ObjectAreaSizeTriplet.java +++ /dev/null @@ -1,62 +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.render.afp.modca.triplets; - -import org.apache.fop.render.afp.tools.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 { - - /** - * 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); - } - - /** - * 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); - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/triplets/ObjectByteExtentTriplet.java b/src/java/org/apache/fop/render/afp/modca/triplets/ObjectByteExtentTriplet.java deleted file mode 100644 index b98a46a72..000000000 --- a/src/java/org/apache/fop/render/afp/modca/triplets/ObjectByteExtentTriplet.java +++ /dev/null @@ -1,39 +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.render.afp.modca.triplets; - -import org.apache.fop.render.afp.tools.BinaryUtils; - -/** - * The Object Byte Extent triplet is used to specify the number of bytes contained in an object - */ -public class ObjectByteExtentTriplet extends Triplet { - - /** - * Main constructor - * - * @param byteExt the number of bytes contained in the object - */ - public ObjectByteExtentTriplet(int byteExt) { - super(OBJECT_BYTE_EXTENT); - byte[] data = BinaryUtils.convert(byteExt, 4); - super.setData(data); - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/triplets/ObjectClassificationTriplet.java b/src/java/org/apache/fop/render/afp/modca/triplets/ObjectClassificationTriplet.java deleted file mode 100644 index 8ba97b61d..000000000 --- a/src/java/org/apache/fop/render/afp/modca/triplets/ObjectClassificationTriplet.java +++ /dev/null @@ -1,188 +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.render.afp.modca.triplets; - -import java.io.UnsupportedEncodingException; - -import org.apache.fop.render.afp.AFPConstants; -import org.apache.fop.render.afp.modca.Registry.ObjectType; -import org.apache.fop.render.afp.tools.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 { - - /** - * The scope of this object is the including page or overlay - */ - public static final byte CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT = 0x01; - - /** - * The scope of this object is not defined - */ - public static final byte CLASS_TIME_VARIANT_PRESENTATION_OBJECT = 0x10; - - /** - * This is not a presentation object, the scope of this object is not defined - */ - public static final byte CLASS_EXECUTABLE_PROGRAM = 0x20; - - /** - * Setup information file, document level. This is not a presentation object, - */ - public static final byte CLASS_SETUP_FILE = 0x30; - - /** - * This is a resource used by a presentation object that may itself be a resource. - * The scope of the resource is the object that uses the resource. - */ - public static final byte CLASS_SECONDARY_RESOURCE = 0x40; - - /** - * Data object font. This is a non-FOCA font resource used to present - * text in a data object. The scope of the resource is the object that - * uses the resource. - */ - public static final byte CLASS_DATA_OBJECT_FONT = 0x41; - - /** - * Main constructor - * - * @param objectClass the object class type - * @param objectType the object type registry entry - * @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 ObjectClassificationTriplet(byte objectClass, ObjectType objectType, - boolean dataInContainer, boolean containerHasOEG, boolean dataInOCD) { - // no object level or company name specified - 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 - * - * @param objectClass the object class type - * @param objectType the object type registry entry - * @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 - * @param objLev the release level or version number of the object type - * @param compName the name of the company or organization that owns the object definition - */ - public ObjectClassificationTriplet(byte objectClass, ObjectType objectType, - boolean dataInContainer, boolean containerHasOEG, boolean dataInOCD, - String objLev, String compName) { - super(OBJECT_CLASSIFICATION); - - 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); - } - - /** - * Returns the structured field flags - * - * @param dataInContainer true if the object data in carried in the object container - * @param containerHasOEG true if the object container has an object environment group - * @param dataInOCD true if the object container data carries the object data - * - * @return the byte value of this structure - */ - public byte[] getStrucFlgs(boolean dataInContainer, boolean containerHasOEG, - boolean dataInOCD) { - byte[] strucFlgs = new byte[2]; - // Object Container (BOC/EOC) - if (dataInContainer) { - strucFlgs[0] |= 3 << 6; - } else { - strucFlgs[0] |= 1 << 6; - } - // Object Environment Group (OEG) - if (containerHasOEG) { - strucFlgs[0] |= 3 << 4; - } else { - strucFlgs[0] |= 1 << 4; - } - // Object Container Data (OCD) structured fields - if (dataInOCD) { - strucFlgs[0] |= 3 << 2; - } else { - strucFlgs[0] |= 1 << 2; - } - strucFlgs[1] = 0x00; - return strucFlgs; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/triplets/PresentationSpaceMixingRulesTriplet.java b/src/java/org/apache/fop/render/afp/modca/triplets/PresentationSpaceMixingRulesTriplet.java deleted file mode 100644 index 0f2def9bf..000000000 --- a/src/java/org/apache/fop/render/afp/modca/triplets/PresentationSpaceMixingRulesTriplet.java +++ /dev/null @@ -1,62 +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.render.afp.modca.triplets; - -/** - * 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 { - - /** background on background mixing rule */ - public static final byte RULE_BACK_ON_BACK = 0x70; - - /** background on foreground mixing rule */ - public static final byte RULE_BACK_ON_FORE = 0x71; - - /** foreground on background mixing rule */ - public static final byte RULE_FORE_ON_BACK = 0x72; - - /** 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; - - /** blend */ - public static final byte BLEND = (byte)0x03; - - /** MO:DCA default mixing */ - public static final byte DEFAULT = (byte)0xFF; - - - /** - * Main constructor - * - * @param rules the mixing rules - */ - public PresentationSpaceMixingRulesTriplet(byte[] rules) { - super(PRESENTATION_SPACE_MIXING_RULE, rules); - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/triplets/PresentationSpaceResetMixingTriplet.java b/src/java/org/apache/fop/render/afp/modca/triplets/PresentationSpaceResetMixingTriplet.java deleted file mode 100644 index ebba65df5..000000000 --- a/src/java/org/apache/fop/render/afp/modca/triplets/PresentationSpaceResetMixingTriplet.java +++ /dev/null @@ -1,48 +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.render.afp.modca.triplets; - -/** - * 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 { - - /** - * 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; - - /** - * Main constructor - * - * @param backgroundMixFlag the background mixing flag - */ - public PresentationSpaceResetMixingTriplet(byte backgroundMixFlag) { - super(PRESENTATION_SPACE_RESET_MIXING, backgroundMixFlag); - } -} diff --git a/src/java/org/apache/fop/render/afp/modca/triplets/ResourceObjectTypeTriplet.java b/src/java/org/apache/fop/render/afp/modca/triplets/ResourceObjectTypeTriplet.java deleted file mode 100644 index c157659d6..000000000 --- a/src/java/org/apache/fop/render/afp/modca/triplets/ResourceObjectTypeTriplet.java +++ /dev/null @@ -1,21 +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.render.afp.modca.triplets; - diff --git a/src/java/org/apache/fop/render/afp/modca/triplets/Triplet.java b/src/java/org/apache/fop/render/afp/modca/triplets/Triplet.java deleted file mode 100644 index 9c88f6862..000000000 --- a/src/java/org/apache/fop/render/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.render.afp.modca.triplets; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; - -import org.apache.fop.render.afp.AFPConstants; -import org.apache.fop.render.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/render/afp/tools/BinaryUtils.java b/src/java/org/apache/fop/render/afp/tools/BinaryUtils.java deleted file mode 100644 index 31ba45bcf..000000000 --- a/src/java/org/apache/fop/render/afp/tools/BinaryUtils.java +++ /dev/null @@ -1,135 +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.render.afp.tools; - -import java.io.ByteArrayOutputStream; - -/** - * Library of utility useful conversion methods. - * - */ -public final class BinaryUtils { - - /** - * Convert an int into the corresponding byte array by encoding each - * two hexadecimal digits as a char. This will return a byte array - * to the length specified by bufsize. - * @param integer The int representation. - * @param bufsize The required byte array size. - * @return the hexadecimal digits as a byte array - */ - public static byte[] convert(int integer, int bufsize) { - StringBuffer buf = new StringBuffer(Integer.toHexString(integer)); - //Convert to an even number of digits - if (buf.length() % 2 != 0) { - buf.insert(0, "0"); - } - int size = buf.length() / 2; - if (size > bufsize) { - buf.delete(0, buf.length() - (bufsize * 2)); - } else { - while (size < bufsize) { - buf.insert(0, "00"); - size++; - } - } - return convert(buf.toString()); - } - - /** - * Convert an int into the corresponding byte array by encoding each - * two hexadecimal digits as a char. - * @param integer The int representation - * @return the hexadecimal digits as a byte array - */ - public static byte[] convert(int integer) { - return convert(Integer.toHexString(integer)); - } - - /** - * Convert a String of hexadecimal digits into the corresponding - * byte array by encoding each two hexadecimal digits as a byte. - * @param digits The hexadecimal digits representation. - * @return the hexadecimal digits as a byte array - */ - public static byte[] convert(String digits) { - - if (digits.length() % 2 == 0) { - // Even number of digits, so ignore - } else { - // Convert to an even number of digits - digits = "0" + digits; - } - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - for (int i = 0; i < digits.length(); i += 2) { - char c1 = digits.charAt(i); - char c2 = digits.charAt(i + 1); - byte b = 0; - if ((c1 >= '0') && (c1 <= '9')) { - b += ((c1 - '0') * 16); - } else if ((c1 >= 'a') && (c1 <= 'f')) { - b += ((c1 - 'a' + 10) * 16); - } else if ((c1 >= 'A') && (c1 <= 'F')) { - b += ((c1 - 'A' + 10) * 16); - } else { - throw new IllegalArgumentException("Bad hexadecimal digit"); - } - - if ((c2 >= '0') && (c2 <= '9')) { - b += (c2 - '0'); - } else if ((c2 >= 'a') && (c2 <= 'f')) { - b += (c2 - 'a' + 10); - } else if ((c2 >= 'A') && (c2 <= 'F')) { - b += (c2 - 'A' + 10); - } else { - throw new IllegalArgumentException("Bad hexadecimal digit"); - } - baos.write(b); - } - return (baos.toByteArray()); - } - - /** - * Convert the specified short into a byte array. - * @param value The value to be converted. - * @param array The array to receive the data. - * @param offset The offset into the byte array for the start of the value. - */ - public static void shortToByteArray( - short value, - byte[] array, - int offset) { - array[offset] = (byte) (value >>> 8); - array[offset + 1] = (byte) value; - } - - /** - * Convert the specified short into a byte array. - * @param value The value to be converted. - * @return The byte array - */ - public static byte[] shortToByteArray(short value) { - byte[] serverValue = new byte[2]; - shortToByteArray(value, serverValue, 0); - return serverValue; - } - -} diff --git a/src/java/org/apache/fop/render/afp/tools/DTDEntityResolver.java b/src/java/org/apache/fop/render/afp/tools/DTDEntityResolver.java deleted file mode 100644 index e9554ecea..000000000 --- a/src/java/org/apache/fop/render/afp/tools/DTDEntityResolver.java +++ /dev/null @@ -1,120 +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.render.afp.tools; - -import java.io.IOException; -import java.net.URL; - -import org.apache.fop.render.afp.exceptions.FontRuntimeException; -import org.xml.sax.EntityResolver; -import org.xml.sax.InputSource; - -/** - * An entity resolver for both DOM and SAX models of the SAX document. - *

- * The entity resolver only handles queries for the DTD. It will find any URI - * with a recognised public id and return an {@link org.xml.sax.InputSource}. - *

- * @author Joe Schmetzer - */ -public class DTDEntityResolver implements EntityResolver { - - /** Public ID for the AFP fonts 1.0 DTD. */ - public static final String AFP_DTD_1_0_ID - = "-//APACHE/DTD AFP Installed Font Definition DTD 1.0//EN"; - - /** Resource location for the AFP fonts 1.0 DTD. */ - public static final String AFP_DTD_1_0_RESOURCE - = "afp-fonts-1.0.dtd"; - - /** Public ID for the AFP fonts 1.1 DTD. */ - public static final String AFP_DTD_1_1_ID - = "-//APACHE/DTD AFP Installed Font Definition DTD 1.1//EN"; - - /** Resource location for the AFP fonts 1.1 DTD. */ - public static final String AFP_DTD_1_1_RESOURCE - = "afp-fonts-1.1.dtd"; - - /** Public ID for the AFP fonts 1.2 DTD. */ - public static final String AFP_DTD_1_2_ID - = "-//APACHE/DTD AFP Installed Font Definition DTD 1.2//EN"; - - /** Resource location for the AFP fonts 1.2 DTD. */ - public static final String AFP_DTD_1_2_RESOURCE - = "afp-fonts-1.2.dtd"; - - /** - * Resolve the combination of system and public identifiers. - * If this resolver recognises the publicId, it will handle the resolution - * from the classpath, otherwise it will return null and allow the default - * resolution to occur. - * - * @param publicId the public identifier to use - * @param systemId the system identifier to resolve - * @return An input source to the entity or null if not handled - * @throws IOException an error reading the stream - */ - public InputSource resolveEntity(String publicId, String systemId) - throws IOException { - - URL resource = null; - if ( AFP_DTD_1_2_ID.equals(publicId) ) { - resource = getResource( AFP_DTD_1_2_RESOURCE ); - } else if ( AFP_DTD_1_1_ID.equals(publicId) ) { - resource = getResource( AFP_DTD_1_1_RESOURCE ); - } else if ( AFP_DTD_1_0_ID.equals(publicId) ) { - throw new FontRuntimeException( - "The AFP Installed Font Definition 1.0 DTD is not longer supported" ); - } else if (systemId != null && systemId.indexOf("afp-fonts.dtd") >= 0 ) { - throw new FontRuntimeException( - "The AFP Installed Font Definition DTD must be specified using the public id" ); - } else { - return null; - } - - InputSource inputSource = new InputSource( resource.openStream() ); - inputSource.setPublicId( publicId ); - inputSource.setSystemId( systemId ); - - return inputSource; - } - - /** - * Returns the URL of a resource on the classpath - * @param resourceName the path to the resource relative to the root of the - * classpath. - * @return the URL of the required resource - * @throws FontRuntimeException if the resource could not be found. - */ - private URL getResource(String resourcePath) { - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - if (cl == null) { - cl = ClassLoader.getSystemClassLoader(); - } - - URL resource = cl.getResource( resourcePath ); - if (resource == null) { - throw new FontRuntimeException( "Resource " + resourcePath - + "could not be found on the classpath" ); - } - - return resource; - } -} diff --git a/src/java/org/apache/fop/render/afp/tools/StringUtils.java b/src/java/org/apache/fop/render/afp/tools/StringUtils.java deleted file mode 100644 index c49509aa0..000000000 --- a/src/java/org/apache/fop/render/afp/tools/StringUtils.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.render.afp.tools; - -/** - * Library of utility methods useful in dealing with strings. - * - */ -public class StringUtils { - - /** - * Padds the string to the left with the given character for - * the specified length. - * @param input The input string. - * @param padding The char used for padding. - * @param length The length of the new string. - * @return The padded string. - */ - public static String lpad(String input, char padding, int length) { - - if (input == null) { - input = new String(); - } - - if (input.length() >= length) { - return input; - } else { - StringBuffer result = new StringBuffer(); - int numChars = length - input.length(); - for (int i = 0; i < numChars; i++) { - result.append(padding); - } - result.append(input); - return result.toString(); - } - } - - /** - * Padds the string to the right with the given character for - * the specified length. - * @param input The input string. - * @param padding The char used for padding. - * @param length The length of the new string. - * @return The padded string. - */ - public static String rpad(String input, char padding, int length) { - - if (input == null) { - input = new String(); - } - - if (input.length() >= length) { - return input; - } else { - StringBuffer result = new StringBuffer(input); - int numChars = length - input.length(); - for (int i = 0; i < numChars; i++) { - result.append(padding); - } - return result.toString(); - } - } - -} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/tools/StructuredFieldReader.java b/src/java/org/apache/fop/render/afp/tools/StructuredFieldReader.java deleted file mode 100644 index 48beff023..000000000 --- a/src/java/org/apache/fop/render/afp/tools/StructuredFieldReader.java +++ /dev/null @@ -1,133 +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.render.afp.tools; - -import java.io.IOException; -import java.io.InputStream; - -/** - * A helper class to read structured fields from a MO:DCA document. Each - * component of a mixed object document is explicitly defined and delimited - * in the data. This is accomplished through the use of MO:DCA data structures, - * called structured fields. Structured fields are used to envelop document - * components and to provide commands and information to applications using - * the data. Structured fields may contain one or more parameters. Each - * parameter provides one value from a set of values defined by the architecture. - *

- * MO:DCA structured fields consist of two parts: an introducer that identifies - * the length and type of the structured field, and data that provides the - * structured field's effect. The data is contained in a set of parameters, - * which can consist of other data structures and data elements. The maximum - * length of a structured field is 32767 bytes. - *

- */ -public class StructuredFieldReader { - - /** - * The input stream to read - */ - private InputStream inputStream = null; - - /** - * The constructor for the StructuredFieldReader - * @param inputStream the input stream to process - */ - public StructuredFieldReader(InputStream inputStream) { - this.inputStream = inputStream; - } - - /** - * Get the next structured field as identified by the identifer - * parameter (this must be a valid MO:DCA structured field. - * @param identifier the three byte identifier - * @throws IOException if an I/O exception occurred - * @return the next structured field or null when there are no more - */ - public byte[] getNext(byte[] identifier) throws IOException { - - int bufferPointer = 0; - byte[] bufferData = new byte[identifier.length + 2]; - for (int x = 0; x < identifier.length; x++) { - bufferData[x] = 0x00; - } - - int c; - while ((c = inputStream.read()) > -1) { - - bufferData[bufferPointer] = (byte) c; - - // Check the last characters in the buffer - int index = 0; - boolean found = true; - - for (int i = identifier.length - 1; i > -1; i--) { - - int p = bufferPointer - index; - if (p < 0) { - p = bufferData.length + p; - } - - index++; - - if (identifier[i] != bufferData[p]) { - found = false; - break; - } - - } - - if (found) { - - byte[] length = new byte[2]; - - int a = bufferPointer - identifier.length; - if (a < 0) { - a = bufferData.length + a; - } - - int b = bufferPointer - identifier.length - 1; - if (b < 0) { - b = bufferData.length + b; - } - - length[0] = bufferData[b]; - length[1] = bufferData[a]; - - int reclength = ((length[0] & 0xFF) << 8) - + (length[1] & 0xFF) - identifier.length - 2; - - byte[] retval = new byte[reclength]; - - inputStream.read(retval, 0, reclength); - - return retval; - - } - - bufferPointer++; - if (bufferPointer >= bufferData.length) { - bufferPointer = 0; - } - - } - - return null; - } -} diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderer.java b/src/java/org/apache/fop/render/pdf/PDFRenderer.java index 61ed1ff07..cc1caea03 100644 --- a/src/java/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/java/org/apache/fop/render/pdf/PDFRenderer.java @@ -50,6 +50,7 @@ import org.apache.xmlgraphics.xmp.Metadata; import org.apache.xmlgraphics.xmp.schemas.XMPBasicAdapter; import org.apache.xmlgraphics.xmp.schemas.XMPBasicSchema; +import org.apache.fop.AbstractState; import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.MimeConstants; @@ -112,7 +113,6 @@ import org.apache.fop.pdf.PDFTextUtil; import org.apache.fop.pdf.PDFXMode; import org.apache.fop.pdf.PDFXObject; import org.apache.fop.render.AbstractPathOrientedRenderer; -import org.apache.fop.render.AbstractState; import org.apache.fop.render.Graphics2DAdapter; import org.apache.fop.render.RendererContext; import org.apache.fop.util.CharUtilities; diff --git a/src/java/org/apache/fop/render/ps/PSTextPainter.java b/src/java/org/apache/fop/render/ps/PSTextPainter.java index 31cb4b605..7c525dbf7 100644 --- a/src/java/org/apache/fop/render/ps/PSTextPainter.java +++ b/src/java/org/apache/fop/render/ps/PSTextPainter.java @@ -38,6 +38,9 @@ import java.util.Iterator; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.fop.fonts.Font; +import org.apache.fop.fonts.FontInfo; +import org.apache.fop.fonts.FontTriplet; import org.apache.xmlgraphics.java2d.ps.PSGraphics2D; import org.apache.xmlgraphics.java2d.TextHandler; @@ -51,9 +54,6 @@ import org.apache.batik.gvt.text.TextPaintInfo; import org.apache.batik.gvt.font.GVTFontFamily; import org.apache.batik.gvt.renderer.StrokingTextPainter; -import org.apache.fop.fonts.Font; -import org.apache.fop.fonts.FontInfo; -import org.apache.fop.fonts.FontTriplet; /** * Renders the attributed character iterator of a TextNode. diff --git a/src/java/org/apache/fop/store/FileStore.java b/src/java/org/apache/fop/store/FileStore.java deleted file mode 100644 index 131daf32b..000000000 --- a/src/java/org/apache/fop/store/FileStore.java +++ /dev/null @@ -1,166 +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.store; - -import java.io.File; -import java.io.FileDescriptor; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.RandomAccessFile; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.xmlgraphics.image.loader.ImageManager; - -/** - * A useful class which is able to easily store and retrieve large resources (such as images) - */ -public class FileStore { - - /** logger */ - protected static Log log = LogFactory.getLog(ImageManager.class); - - /** Internal temporary storage buffer size */ - private static final int BUFFER_SIZE = 4096; - - /** Used for storage of data objects */ - protected RandomAccessFile raFile; - - /** The temporary cache file */ - private File tempFile; - - /** The file outputstream */ - protected FileOutputStream fos; - - /** - * Default constructor - * - * @param prefix file store prefix - */ - public FileStore(String prefix) { - try { - this.tempFile = File.createTempFile(prefix, null); - this.raFile = new RandomAccessFile(tempFile, "rw"); - FileDescriptor fd = raFile.getFD(); - this.fos = new FileOutputStream(fd); - } catch (IOException e) { - // TODO - log.error(e.getMessage()); - } - } - - /** - * Clears the resource store. - * - * @throws IOException if an error occurs while clearing the store - */ - public void clear() throws IOException { - if (tempFile != null) { - raFile.close(); - raFile = null; - fos = null; - if (tempFile.exists() && !tempFile.delete()) { - throw new IOException("Could not delete temporary file: " + tempFile); - } - tempFile = null; - } - } - - /** {@inheritDoc} */ - public void finalize() throws Throwable { - try { - clear(); - } finally { - super.finalize(); - } - } - - /** - * Returns the storer of a given object - * - * @param object an object to be stored - * @return a storer of the object - */ - protected Storer getStorer(Object object) { - Storer storer; - if (object instanceof Writable) { - storer = new WritableStorer(this, (Writable)object); - } else if (object instanceof InputStream) { - storer = new InputStreamStorer(this, (InputStream)object); - } else { - throw new IllegalArgumentException("Unsupported object " + object); - } - return storer; - } - - /** - * Stores an object in the cache - * - * @param object the object to store - * @return a new save information record - * - * @throws java.io.IOException an I/O exception of some sort has occurred. - */ - public StoreRecord write(Object object) throws IOException { - return getStorer(object).store(); - } - - /** - * Reads all the data from a given store information record - * and returns it in a byte array. - * This is potentially a memory hungry operation so use with care. - * - * @param storeInfo a store information record - * @return the stored data in a byte array. - * @throws java.io.IOException an I/O exception of some sort has occurred. - */ - public byte[] read(StoreRecord storeInfo) throws IOException { - raFile.seek(storeInfo.position); - byte[] buff = new byte[storeInfo.size]; - raFile.read(buff); - return buff; - } - - /** - * Writes out the resource in full using the store information to the given outputstream. - * - * @param storeInfo the save information - * @param os the outputstream to write to - * - * @throws java.io.IOException an I/O exception of some sort has occurred. - */ - public void writeToStream(StoreRecord storeInfo, OutputStream os) throws IOException { - if (storeInfo == null) { - throw new IllegalArgumentException("save is null"); - } - double chunkCount = storeInfo.size / BUFFER_SIZE; - byte[] buffer = new byte[BUFFER_SIZE]; - raFile.seek(storeInfo.position); - for (int cnt = 0; cnt < chunkCount; cnt++) { - raFile.read(buffer, 0, BUFFER_SIZE); - os.write(buffer, 0, BUFFER_SIZE); - } - int lastChunkLength = storeInfo.size % BUFFER_SIZE; - raFile.read(buffer, 0, lastChunkLength); - os.write(buffer, 0, lastChunkLength); - } -} diff --git a/src/java/org/apache/fop/store/InputStreamStorer.java b/src/java/org/apache/fop/store/InputStreamStorer.java deleted file mode 100644 index 5d72c932f..000000000 --- a/src/java/org/apache/fop/store/InputStreamStorer.java +++ /dev/null @@ -1,50 +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.store; - -import java.io.IOException; -import java.io.InputStream; - -import org.apache.commons.io.IOUtils; - -/** - * Storer of InputStreams - */ -public final class InputStreamStorer extends Storer { - - /** an inputstream */ - private final InputStream in; - - /** - * Constructor - * - * @param store our resource store - * @param in an inputstream - */ - protected InputStreamStorer(FileStore store, InputStream in) { - super(store); - this.in = in; - } - - /** {@inheritDoc} */ - protected void doStore() throws IOException { - IOUtils.copy(in, store.fos); - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/store/StoreRecord.java b/src/java/org/apache/fop/store/StoreRecord.java deleted file mode 100644 index f4dd8ff49..000000000 --- a/src/java/org/apache/fop/store/StoreRecord.java +++ /dev/null @@ -1,90 +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.store; - -import java.io.IOException; -import java.io.OutputStream; - -/** - * Store save information - */ -public class StoreRecord { - - /** the resource store associated with this store information */ - private final FileStore store; - - /** data position */ - protected long position; - - /** data chunk size */ - protected int size; - - /** - * Main constructor - * - * @param store our resource store - */ - public StoreRecord(FileStore store) { - this.store = store; - } - - /** - * Returns the storage position - * - * @return the storage position - */ - public long getPosition() { - return this.position; - } - - /** - * Returns the storage size - * - * @return the storage size - */ - public int getLength() { - return this.size; - } - - /** - * Returns the resource store associated with this store record - * - * @return the resource store associated with this store record - */ - public FileStore getStore() { - return this.store; - } - - /** - * Convenience method used to writes the data referenced - * by this storage record to an outputstream - * - * @param os the outputstream to write to - * @throws java.io.IOException an I/O exception of some sort has occurred. - */ - public void writeToStream(OutputStream os) throws IOException { - store.writeToStream(this, os); - } - - /** {@inheritDoc} */ - public String toString() { - return "pos=" + position + ", size=" + size; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/store/Storer.java b/src/java/org/apache/fop/store/Storer.java deleted file mode 100644 index d8dbab191..000000000 --- a/src/java/org/apache/fop/store/Storer.java +++ /dev/null @@ -1,87 +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.store; - -import java.io.IOException; - -/** - * Base storer class - */ -public class Storer { - - /** write session */ - protected final WriteSession session; - - /** file store */ - protected final FileStore store; - - /** - * Constructor - * - * @param store our resource store - */ - public Storer(FileStore store) { - this.store = store; - this.session = new WriteSession(this); - } - - /** - * Instantiates the store information record - * - * @return a new store information record - */ - protected StoreRecord createRecord() { - return new StoreRecord(store); - } - - /** - * Stores the object - * - * @return a store information record - * @throws IOException thrown if an I/O exception of some sort has occurred. - */ - public StoreRecord store() throws IOException { - StoreRecord record = null; - session.begin(); - try { - doStore(); - } finally { - record = session.end(); - } - return record; - } - - /** - * Actually performs the store operation - * - * @throws IOException thrown if an I/O exception of some sort has occurred. - */ - protected void doStore() throws IOException { - } - - /** - * Returns the file store associated with this storer - * - * @return the file store associated with this storer - */ - protected FileStore getStore() { - return store; - } -} diff --git a/src/java/org/apache/fop/store/Writable.java b/src/java/org/apache/fop/store/Writable.java deleted file mode 100644 index 8f6052261..000000000 --- a/src/java/org/apache/fop/store/Writable.java +++ /dev/null @@ -1,38 +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.store; - -import java.io.IOException; -import java.io.OutputStream; - -/** - * Implementing object is able to write to an OutputStream - */ -public interface Writable { - - /** - * DataStream objects must implement the writeToStream() - * method to write its data to the given OutputStream - * - * @param outputStream The outputsteam stream - * @throws java.io.IOException an I/O exception of some sort has occurred. - */ - void writeToStream(OutputStream outputStream) throws IOException; -} diff --git a/src/java/org/apache/fop/store/WritableStorer.java b/src/java/org/apache/fop/store/WritableStorer.java deleted file mode 100644 index bba11287e..000000000 --- a/src/java/org/apache/fop/store/WritableStorer.java +++ /dev/null @@ -1,47 +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.store; - -import java.io.IOException; - -/** - * Storer of objects that implement the Writable interface - */ -public class WritableStorer extends Storer { - - /** a Writable object */ - protected final Writable writable; - - /** - * Constructor - * - * @param store our resource store - * @param writable an object implementing the Writable interface - */ - public WritableStorer(FileStore store, Writable writable) { - super(store); - this.writable = writable; - } - - /** {@inheritDoc} */ - protected void doStore() throws IOException { - writable.writeToStream(store.fos); - } -} diff --git a/src/java/org/apache/fop/store/WriteSession.java b/src/java/org/apache/fop/store/WriteSession.java deleted file mode 100644 index 034357355..000000000 --- a/src/java/org/apache/fop/store/WriteSession.java +++ /dev/null @@ -1,109 +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.store; - -import java.io.IOException; -import java.io.OutputStream; - -/** - * A Write session - */ -public class WriteSession { - /** true if the session output was flushed */ - protected boolean flushed = false; - - /** the session storer */ - private final Storer storer; - - /** the storer's file store */ - private final FileStore store; - - /** the store information record */ - protected StoreRecord record; - - /** - * Constructor - * - * @param store our store - */ - public WriteSession(FileStore store) { - this.storer = new Storer(store); - this.store = store; - } - - /** - * Constructor - * - * @param storer our storer - */ - public WriteSession(Storer storer) { - this.storer = storer; - this.store = storer.getStore(); - } - - /** - * Begins the session - * - * @throws IOException thrown if an I/O exception of some sort has occurred. - */ - public void begin() throws IOException { - // always write to the end of the store - long length = store.raFile.length(); - if (store.raFile.getFilePointer() < length) { - store.raFile.seek(length); - } - - this.record = storer.createRecord(); - record.position = store.raFile.getFilePointer(); - } - - /** - * Ends the session - * - * @return a new store information record - * @throws IOException thrown if an I/O exception of some sort has occurred. - */ - public StoreRecord end() throws IOException { - if (!flushed) { - store.fos.flush(); - flushed = true; - } - record.size = (int)(store.raFile.getFilePointer() - record.position); - return record; - } - - /** - * Returns the outputstream of this store - * - * @return the outputstream of this store - */ - public OutputStream getOutputStream() { - return store.fos; - } - - /** - * Returns the store record - * - * @return the store record - */ - public StoreRecord getRecord() { - return record; - } -} \ No newline at end of file diff --git a/src/java/org/apache/fop/svg/GraphicsConfiguration.java b/src/java/org/apache/fop/svg/GraphicsConfiguration.java index ca3b3363c..881096b9a 100644 --- a/src/java/org/apache/fop/svg/GraphicsConfiguration.java +++ b/src/java/org/apache/fop/svg/GraphicsConfiguration.java @@ -17,7 +17,6 @@ /* $Id$ */ - package org.apache.fop.svg; import java.awt.image.VolatileImage; diff --git a/src/java/org/apache/fop/svg/PDFBridgeContext.java b/src/java/org/apache/fop/svg/PDFBridgeContext.java index fdf83784f..6aa29cfa1 100644 --- a/src/java/org/apache/fop/svg/PDFBridgeContext.java +++ b/src/java/org/apache/fop/svg/PDFBridgeContext.java @@ -26,11 +26,11 @@ import org.apache.batik.bridge.Bridge; import org.apache.batik.bridge.BridgeContext; import org.apache.batik.bridge.DocumentLoader; import org.apache.batik.bridge.UserAgent; +import org.apache.fop.fonts.FontInfo; import org.apache.xmlgraphics.image.loader.ImageManager; import org.apache.xmlgraphics.image.loader.ImageSessionContext; -import org.apache.fop.fonts.FontInfo; /** * BridgeContext which registers the custom bridges for PDF output. diff --git a/src/java/org/apache/fop/svg/PDFGraphicsConfiguration.java b/src/java/org/apache/fop/svg/PDFGraphicsConfiguration.java index 83a431d5e..0204a2756 100644 --- a/src/java/org/apache/fop/svg/PDFGraphicsConfiguration.java +++ b/src/java/org/apache/fop/svg/PDFGraphicsConfiguration.java @@ -26,6 +26,7 @@ import java.awt.image.ColorModel; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; + /** * Our implementation of the class that returns information about * roughly what we can handle and want to see (alpha for example).