diff options
author | Adrian Cumiskey <acumiskey@apache.org> | 2008-10-27 11:11:31 +0000 |
---|---|---|
committer | Adrian Cumiskey <acumiskey@apache.org> | 2008-10-27 11:11:31 +0000 |
commit | 17bc8aa0870e3d6043ea2865e44fc2433dd5b36b (patch) | |
tree | 30bd6ed354f94bcf2ed696bcd450c9398378a250 /src/java/org/apache/fop/afp/goca | |
parent | 00de9a8fc1a67e93c512ba67451d1e8815d57b39 (diff) | |
download | xmlgraphics-fop-17bc8aa0870e3d6043ea2865e44fc2433dd5b36b.tar.gz xmlgraphics-fop-17bc8aa0870e3d6043ea2865e44fc2433dd5b36b.zip |
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
Diffstat (limited to 'src/java/org/apache/fop/afp/goca')
18 files changed, 1477 insertions, 0 deletions
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 |