diff options
author | Adrian Cumiskey <acumiskey@apache.org> | 2008-03-27 16:12:00 +0000 |
---|---|---|
committer | Adrian Cumiskey <acumiskey@apache.org> | 2008-03-27 16:12:00 +0000 |
commit | 1105f2129784f6d85485ad222bdbc835473ee7ca (patch) | |
tree | c15501ca568e1339bd7b3f5ec109d7b00f18d904 /src | |
parent | 6514a1262511a543312b7ba636dc5f952a5a19e4 (diff) | |
download | xmlgraphics-fop-1105f2129784f6d85485ad222bdbc835473ee7ca.tar.gz xmlgraphics-fop-1105f2129784f6d85485ad222bdbc835473ee7ca.zip |
Moved goca package to level above modca.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@641870 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
20 files changed, 1661 insertions, 0 deletions
diff --git a/src/java/org/apache/fop/render/afp/goca/AbstractGraphicsContainer.java b/src/java/org/apache/fop/render/afp/goca/AbstractGraphicsContainer.java new file mode 100644 index 000000000..e6966d5d3 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/goca/AbstractGraphicsContainer.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY 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 java.util.Iterator; +import java.util.List; + +import org.apache.fop.render.afp.modca.AbstractNamedAFPObject; +import org.apache.fop.render.afp.modca.PreparedAFPObject; + +/** + * A base class container of GOCA structured objects + */ +public abstract class AbstractGraphicsContainer extends AbstractNamedAFPObject +implements PreparedAFPObject { + + /** + * list of objects contained within this container + */ + protected List objects = null; + + /** + * Default constructor + */ + protected AbstractGraphicsContainer() { + } + + /** + * Named constructor + * @param name the name of the container + */ + protected AbstractGraphicsContainer(String name) { + super(name); + } + + /** + * {@inheritDoc} + */ + protected void writeContent(OutputStream os) throws IOException { + if (objects != null) { + super.writeObjects(objects, os); + } + } + + /** + * Adds a given graphics drawing order to this container + * @param drawingOrder the graphics drawing order + * @return the drawingOrder if it was added, null otherwise + */ + protected PreparedAFPObject addDrawingOrder(PreparedAFPObject drawingOrder) { + log.debug(this + " adding " + drawingOrder); + if (objects == null) { + this.objects = new java.util.ArrayList(); + } + objects.add(drawingOrder); + return drawingOrder; + } + + /** + * @return the current data length of this container including + * all enclosed GOCA drawing objects (and their containers) + */ + public int getDataLength() { + int dataLen = 0; + if (objects != null) { + Iterator it = objects.iterator(); + while (it.hasNext()) { + Object obj = it.next(); + if (obj instanceof PreparedAFPObject) { + dataLen += ((PreparedAFPObject)obj).getDataLength(); + } + } + } + return dataLen; + } +} diff --git a/src/java/org/apache/fop/render/afp/goca/AbstractGraphicsCoord.java b/src/java/org/apache/fop/render/afp/goca/AbstractGraphicsCoord.java new file mode 100644 index 000000000..12d6e13a7 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/goca/AbstractGraphicsCoord.java @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY 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; + + /** + * @param coords the x/y coordinates for this object + */ + public AbstractGraphicsCoord(int[] coords) { + this.coords = coords; + prepareData(); + } + + /** + * @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}); + } + + /** + * @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}); + } + + /** + * @return the order code to use + */ + protected abstract byte getOrderCode(); + + /** + * @return the length of this order code + * (typically this is the same as the coordinate length) + */ + 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]; + } + } + + /** + * @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 new file mode 100644 index 000000000..c0d1040c8 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/goca/GraphicsArea.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.render.afp.goca; + +import java.io.IOException; +import java.io.OutputStream; + +/** + * A GOCA graphics area (container for filled shapes/objects) + */ +public final class GraphicsArea extends AbstractGraphicsContainer { + + /** 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; + } + + private static final int RES1 = 1; + private static final int BOUNDARY = 2; + private static final int NO_BOUNDARY = 0; + + /** + * {@inheritDoc} + */ + public int getDataLength() { + // start len + end len + data len + return 4 + super.getDataLength(); + } + + /** + * {@inheritDoc} + */ + protected void writeStart(OutputStream os) throws IOException { + super.writeStart(os); + 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"; + } +}
\ 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 new file mode 100644 index 000000000..8f1bc2378 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/goca/GraphicsBox.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY 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 { + + /** + * @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 new file mode 100644 index 000000000..f63aff1ea --- /dev/null +++ b/src/java/org/apache/fop/render/afp/goca/GraphicsChainedSegment.java @@ -0,0 +1,179 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY 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.PreparedAFPObject; +import org.apache.fop.render.afp.tools.BinaryUtils; + +/** + * A GOCA graphics segment + */ +public final class GraphicsChainedSegment extends AbstractGraphicsContainer { + + /** + * 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() { + int dataLen = 14 + super.getDataLength(); + if (previous == null) { + GraphicsChainedSegment current = this.next; + while (current != null) { + dataLen += current.getDataLength(); + current = current.next; + } + } + return dataLen; + } + + /** + * {@inheritDoc} + */ + protected int getNameLength() { + return 4; + } + + private static final byte APPEND_NEW_SEGMENT = 0; + + private static final byte PROLOG = 4; + + private static final byte APPEND_TO_EXISING = 48; + + /** + * {@inheritDoc} + */ + protected void writeStart(OutputStream os) throws IOException { + super.writeStart(os); + int len = super.getDataLength(); + byte[] segLen = BinaryUtils.convert(len, 2); + byte[] data = new byte[] { + 0x70, // BEGIN_SEGMENT + 0x0C, // Length of following parameters + this.nameBytes[0], + this.nameBytes[1], + this.nameBytes[2], + this.nameBytes[3], + 0x00, // FLAG1 (ignored) + APPEND_NEW_SEGMENT, + segLen[0], // SEGL + segLen[1], + 0x00, + 0x00, + 0x00, + 0x00 + }; + // P/S NAME (predecessor name) + if (previous != null) { + data[10] = previous.nameBytes[0]; + data[11] = previous.nameBytes[1]; + data[12] = previous.nameBytes[2]; + data[13] = previous.nameBytes[3]; + } + 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) { + GraphicsChainedSegment current = this.next; + while (current != null) { + current.writeDataStream(os); + current = current.next; + } + } + } + + /** + * Begins a graphics area (start of fill) + */ + protected void beginArea() { + this.currentArea = new GraphicsArea(); + super.addDrawingOrder(currentArea); + } + + /** + * Ends a graphics area (end of fill) + */ + protected void endArea() { + this.currentArea = null; + } + + /** + * {@inheritDoc} + */ + protected PreparedAFPObject addDrawingOrder(PreparedAFPObject drawingOrder) { + if (currentArea != null) { + currentArea.addDrawingOrder(drawingOrder); + } else { + super.addDrawingOrder(drawingOrder); + } + return 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 new file mode 100644 index 000000000..3c95bb245 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/goca/GraphicsData.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.render.afp.goca; + +import java.io.IOException; +import java.io.OutputStream; + +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 AbstractGraphicsContainer { + + /** + * 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(); + } + + /** + * {@inheritDoc} + */ + protected void writeStart(OutputStream os) throws IOException { + super.writeStart(os); + int l = getDataLength(); + byte[] len = BinaryUtils.convert(l, 2); + byte[] data = new byte[] { + 0x5A, // Structured field identifier + len[0], // Length byte 1 + len[1], // Length byte 2 + (byte) 0xD3, // Structured field id byte 1 + (byte) 0xEE, // Structured field id byte 2 + (byte) 0xBB, // Structured field id byte 3 + 0x00, // Flags + 0x00, // Reserved + 0x00 // Reserved + }; + os.write(data); + } + + /** + * 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.addDrawingOrder(currentSegment); + return currentSegment; + } + + /** + * {@inheritDoc} + */ + public PreparedAFPObject addDrawingOrder(PreparedAFPObject drawingOrder) { + if (currentSegment == null + || (currentSegment.getDataLength() + drawingOrder.getDataLength()) + >= GraphicsChainedSegment.MAX_DATA_LEN) { + newSegment(); + } + currentSegment.addDrawingOrder(drawingOrder); + return drawingOrder; + } + + /** + * {@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 new file mode 100644 index 000000000..122dcd04e --- /dev/null +++ b/src/java/org/apache/fop/render/afp/goca/GraphicsFillet.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY 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 { + + /** + * @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 new file mode 100644 index 000000000..92ce66d88 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/goca/GraphicsFullArc.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.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 int mh; + + /** the fractional portion of the multiplier */ + private int mhr; + + /** + * @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 super.getName() + + "(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/GraphicsImageBegin.java b/src/java/org/apache/fop/render/afp/goca/GraphicsImageBegin.java new file mode 100644 index 000000000..b55a5139d --- /dev/null +++ b/src/java/org/apache/fop/render/afp/goca/GraphicsImageBegin.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.render.afp.goca; + +import org.apache.fop.render.afp.modca.AbstractPreparedAFPObject; +import org.apache.fop.render.afp.tools.BinaryUtils; + +/** + * A GOCA graphics begin image object + */ +public final class GraphicsImageBegin extends AbstractPreparedAFPObject { + /** x coordinate */ + private int x; + + /** y coordinate */ + private int y; + + /** width */ + private int width; + + /** height */ + private int height; + + /** + * @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 + */ + public GraphicsImageBegin(int x, int y, int width, int height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + prepareData(); + } + + /** + * {@inheritDoc} + */ + protected void prepareData() { + byte[] xcoord = BinaryUtils.convert(x, 2); + byte[] ycoord = BinaryUtils.convert(y, 2); + byte[] w = BinaryUtils.convert(width, 2); + byte[] h = BinaryUtils.convert(height, 2); + super.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] // + }; + } + + /** + * {@inheritDoc} + */ + public String toString() { + return "GraphicsImageBegin(x=" + x + ",y=" + y + + ",width=" + width + ",height=" + height + ")"; + } +}
\ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsImageData.java b/src/java/org/apache/fop/render/afp/goca/GraphicsImageData.java new file mode 100644 index 000000000..b17c3d7d4 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/goca/GraphicsImageData.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.render.afp.goca; + +import org.apache.fop.render.afp.modca.AbstractPreparedAFPObject; +import org.apache.fop.render.afp.tools.BinaryUtils; + +/** + * A GOCA graphics image data + */ +public final class GraphicsImageData extends AbstractPreparedAFPObject { + + /** the maximum image data length */ + public static final short MAX_DATA_LEN = 255; + + /** + * Main constructor + * + * @param imageData the image data + * @param startIndex the start index to read the image data from + */ + public GraphicsImageData(byte[] imageData, int startIndex) { + int dataLen = MAX_DATA_LEN; + if (startIndex + MAX_DATA_LEN >= imageData.length) { + dataLen = imageData.length - startIndex - 1; + } + super.data = new byte[dataLen + 2]; + data[0] = (byte) 0x92; // GIMD + data[1] = BinaryUtils.convert(dataLen, 1)[0]; // LENGTH + System.arraycopy(imageData, startIndex, data, 2, dataLen); + } + + /** + * {@inheritDoc} + */ + public String toString() { + return "GraphicsImageData(" + + (data != null ? "" + (data.length - 2) : "null") + + ")"; + } +}
\ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsImageEnd.java b/src/java/org/apache/fop/render/afp/goca/GraphicsImageEnd.java new file mode 100644 index 000000000..24c272445 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/goca/GraphicsImageEnd.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id: $ */ + +package org.apache.fop.render.afp.goca; + +import org.apache.fop.render.afp.modca.AbstractPreparedAFPObject; + +/** + * A GOCA graphics image data + */ +public class GraphicsImageEnd extends AbstractPreparedAFPObject { + + /** + * Default constructor + */ + public GraphicsImageEnd() { + prepareData(); + } + + /** + * {@inheritDoc} + */ + protected void prepareData() { + super.data = new byte[] { + (byte) 0x93, // GEIMG order code + 0x00 // LENGTH + }; + } + + /** + * {@inheritDoc} + */ + public String toString() { + return "GraphicsImageEnd"; + } +}
\ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsLine.java b/src/java/org/apache/fop/render/afp/goca/GraphicsLine.java new file mode 100644 index 000000000..306acb448 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/goca/GraphicsLine.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.render.afp.goca; + + +/** + * A GOCA graphics straight line drawn from the + * given position or current position. + */ +public class GraphicsLine extends AbstractGraphicsCoord { + + /** + * @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 new file mode 100644 index 000000000..ce9bd1665 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/goca/GraphicsSetArcParameters.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.render.afp.goca; + +/** + * Sets the arc parameters for a GOCA graphics arc (circle/ellipse) + */ +public class GraphicsSetArcParameters extends AbstractGraphicsCoord { + + /** + * @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 new file mode 100644 index 000000000..2671908c9 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/goca/GraphicsSetCharacterSet.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY 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 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 new file mode 100644 index 000000000..866c37b38 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/goca/GraphicsSetCurrentPosition.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY 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 { + + /** + * @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 new file mode 100644 index 000000000..998304d84 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/goca/GraphicsSetLineType.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.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", "DOTTED", "SHORT_DASHED", "DASH_DOT", "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 new file mode 100644 index 000000000..b526f4385 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/goca/GraphicsSetLineWidth.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY 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/GraphicsSetPatternSymbol.java b/src/java/org/apache/fop/render/afp/goca/GraphicsSetPatternSymbol.java new file mode 100644 index 000000000..eddb531ed --- /dev/null +++ b/src/java/org/apache/fop/render/afp/goca/GraphicsSetPatternSymbol.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.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 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 new file mode 100644 index 000000000..e0dc9ed13 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/goca/GraphicsSetProcessColor.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY 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; +import org.apache.fop.render.afp.modca.GraphicsObject; + +/** + * Sets the current processing color for the following GOCA structured fields + */ +public class GraphicsSetProcessColor extends AbstractPreparedAFPObject { + /** the color to set */ + private Color col; + + /** + * Main constructor + * @param col the color to set + */ + public GraphicsSetProcessColor(Color col) { + this.col = col; + prepareData(); + } + + /** + * {@inheritDoc} + */ + protected void prepareData() { + // COLSPCE + byte colspace; + int colSpaceType = col.getColorSpace().getType(); + if (colSpaceType == ColorSpace.TYPE_CMYK) { + colspace = 0x04; + } else if (colSpaceType == ColorSpace.TYPE_RGB) { + colspace = 0x01; + } else { + GraphicsObject.log.error("unsupported colorspace " + colSpaceType); + colspace = 0x01; + } + + // COLSIZE(S) + float[] colcomp = col.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=" + col + ")"; + } +}
\ 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 new file mode 100644 index 000000000..fdeeea5bb --- /dev/null +++ b/src/java/org/apache/fop/render/afp/goca/GraphicsString.java @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY 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.modca.AFPConstants; +import org.apache.fop.render.afp.modca.AbstractPreparedAFPObject; +import org.apache.fop.render.afp.modca.GraphicsObject; +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; + + /** + * @param str the character string + */ + public GraphicsString(String str) { + this.str = str; + fromCurrentPosition = true; + prepareData(); + } + + /** + * @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) { + GraphicsObject.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 |