From: Jeremias Maerki Date: Thu, 21 Apr 2011 14:59:09 +0000 (+0000) Subject: AFP GOCA: Work-around for InfoPrint's AFP implementation (AFP Viewer 3.5.4.1, AFP... X-Git-Tag: fop-1_1rc1old~233 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a5eb05ea8d940ccaa4f9d30b094b673b1e6246b9;p=xmlgraphics-fop.git AFP GOCA: Work-around for InfoPrint's AFP implementation (AFP Viewer 3.5.4.1, AFP Workbench 2.5.4.1) which seems to lose the character set state over Graphics Data (GAD) boundaries. Setting the SegFlag on the SFI header did not help. Instead, the character set is re-set before each Character String order. As part of the fix, some additional flags were implemented, but now not used. They might be useful in the future. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1095739 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/afp/goca/GraphicsChainedSegment.java b/src/java/org/apache/fop/afp/goca/GraphicsChainedSegment.java index 9e7016874..2ce7e3442 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsChainedSegment.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsChainedSegment.java @@ -34,6 +34,7 @@ public final class GraphicsChainedSegment extends AbstractGraphicsDrawingOrderCo private byte[] predecessorNameBytes; private boolean appended; + private boolean prologPresent; /** * Main constructor @@ -42,7 +43,7 @@ public final class GraphicsChainedSegment extends AbstractGraphicsDrawingOrderCo * the name of this graphics segment */ public GraphicsChainedSegment(String name) { - this(name, null, false); + this(name, null, false, false); } /** @@ -53,8 +54,10 @@ public final class GraphicsChainedSegment extends AbstractGraphicsDrawingOrderCo * @param predecessorNameBytes * the name of the predecessor in this chain * @param appended true if this segment is appended to the previous one + * @param prologPresent true if this segment starts with a prolog */ - public GraphicsChainedSegment(String name, byte[] predecessorNameBytes, boolean appended) { + public GraphicsChainedSegment(String name, byte[] predecessorNameBytes, + boolean appended, boolean prologPresent) { super(name); if (predecessorNameBytes != null) { this.predecessorNameBytes = new byte[predecessorNameBytes.length]; @@ -62,6 +65,7 @@ public final class GraphicsChainedSegment extends AbstractGraphicsDrawingOrderCo this.predecessorNameBytes, 0, predecessorNameBytes.length); } this.appended = appended; + this.prologPresent = prologPresent; } /** {@inheritDoc} */ @@ -71,8 +75,8 @@ public final class GraphicsChainedSegment extends AbstractGraphicsDrawingOrderCo } private static final byte APPEND_NEW_SEGMENT = 0; -// private static final byte PROLOG = 4; private static final byte APPEND_TO_EXISING = 6; + private static final byte PROLOG = 0x10; private static final int NAME_LENGTH = 4; @@ -98,7 +102,12 @@ public final class GraphicsChainedSegment extends AbstractGraphicsDrawingOrderCo System.arraycopy(nameBytes, 0, data, 2, NAME_LENGTH); data[6] = 0x00; // FLAG1 (ignored) - data[7] = this.appended ? APPEND_TO_EXISING : APPEND_NEW_SEGMENT; //FLAG2 + + //FLAG2 + data[7] |= this.appended ? APPEND_TO_EXISING : APPEND_NEW_SEGMENT; + if (this.prologPresent) { + data[7] |= PROLOG; + } int dataLength = super.getDataLength(); byte[] len = BinaryUtils.convert(dataLength, 2); diff --git a/src/java/org/apache/fop/afp/goca/GraphicsData.java b/src/java/org/apache/fop/afp/goca/GraphicsData.java index 752d09b48..de10d3fbb 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsData.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsData.java @@ -32,11 +32,14 @@ import org.apache.fop.afp.util.StringUtils; public final class GraphicsData extends AbstractGraphicsDrawingOrderContainer { /** the maximum graphics data length */ - public static final int MAX_DATA_LEN = 8192; + public static final int MAX_DATA_LEN = GraphicsChainedSegment.MAX_DATA_LEN + 16; + //+16 to avoid unnecessary, practically empty GraphicsData instances. /** the graphics segment */ private GraphicsChainedSegment currentSegment = null; + private boolean segmentedData; + /** * Main constructor */ @@ -49,6 +52,15 @@ public final class GraphicsData extends AbstractGraphicsDrawingOrderContainer { return 8 + super.getDataLength(); } + /** + * Sets the indicator that this instance is a part of a series of segmented data chunks. + * This indirectly sets the SegFlag on the SFI header. + * @param segmented true if this data object is not the last of the series + */ + public void setSegmentedData(boolean segmented) { + this.segmentedData = segmented; + } + /** * Returns a new segment name * @@ -66,22 +78,23 @@ public final class GraphicsData extends AbstractGraphicsDrawingOrderContainer { * @return a newly created graphics segment */ public GraphicsChainedSegment newSegment() { - return newSegment(false); + return newSegment(false, false); } /** * Creates a new graphics segment. * @param appended true if this segment is appended to the previous one + * @param prologPresent true if started with a prolog * @return a newly created graphics segment */ - public GraphicsChainedSegment newSegment(boolean appended) { + public GraphicsChainedSegment newSegment(boolean appended, boolean prologPresent) { String segmentName = createSegmentName(); if (currentSegment == null) { currentSegment = new GraphicsChainedSegment(segmentName); } else { currentSegment.setComplete(true); currentSegment = new GraphicsChainedSegment(segmentName, - currentSegment.getNameBytes(), appended); + currentSegment.getNameBytes(), appended, prologPresent); } super.addObject(currentSegment); return currentSegment; @@ -93,7 +106,7 @@ public final class GraphicsData extends AbstractGraphicsDrawingOrderContainer { if (currentSegment == null || (currentSegment.getDataLength() + object.getDataLength()) >= GraphicsChainedSegment.MAX_DATA_LEN) { - newSegment(true); + newSegment(true, false); } currentSegment.addObject(object); } @@ -117,6 +130,9 @@ public final class GraphicsData extends AbstractGraphicsDrawingOrderContainer { byte[] len = BinaryUtils.convert(dataLength, 2); data[1] = len[0]; // Length byte 1 data[2] = len[1]; // Length byte 2 + if (this.segmentedData) { + data[6] |= 32; //Data is segmented + } os.write(data); writeObjects(objects, os); diff --git a/src/java/org/apache/fop/afp/modca/GraphicsObject.java b/src/java/org/apache/fop/afp/modca/GraphicsObject.java index c94ad5ffc..cf732c77a 100644 --- a/src/java/org/apache/fop/afp/modca/GraphicsObject.java +++ b/src/java/org/apache/fop/afp/modca/GraphicsObject.java @@ -39,6 +39,7 @@ import org.apache.fop.afp.goca.GraphicsBox; import org.apache.fop.afp.goca.GraphicsChainedSegment; import org.apache.fop.afp.goca.GraphicsCharacterString; import org.apache.fop.afp.goca.GraphicsData; +import org.apache.fop.afp.goca.GraphicsEndProlog; import org.apache.fop.afp.goca.GraphicsFillet; import org.apache.fop.afp.goca.GraphicsFullArc; import org.apache.fop.afp.goca.GraphicsImage; @@ -62,8 +63,8 @@ public class GraphicsObject extends AbstractDataObject { private GraphicsData currentData = null; /** list of objects contained within this container */ - protected List/**/ objects - = new java.util.ArrayList/**/(); + protected List objects + = new java.util.ArrayList(); /** the graphics state */ private final GraphicsState graphicsState = new GraphicsState(); @@ -325,6 +326,10 @@ public class GraphicsObject extends AbstractDataObject { * @param y the y coordinate */ public void addString(String str, int x, int y) { + //Work-around for InfoPrint's AFP which loses character set state over Graphics Data + //boundaries. + addObject(new GraphicsSetCharacterSet(graphicsState.characterSet)); + addObject(new GraphicsCharacterString(str, x, y)); } @@ -342,6 +347,13 @@ public class GraphicsObject extends AbstractDataObject { addObject(new GraphicsAreaEnd()); } + /** + * Ends the prolog. + */ + public void endProlog() { + addObject(new GraphicsEndProlog()); + } + /** {@inheritDoc} */ @Override public String toString() { @@ -359,9 +371,9 @@ public class GraphicsObject extends AbstractDataObject { /** {@inheritDoc} */ @Override public void setComplete(boolean complete) { - Iterator it = objects.iterator(); + Iterator it = objects.iterator(); while (it.hasNext()) { - Completable completedObject = (Completable)it.next(); + Completable completedObject = it.next(); completedObject.setComplete(true); } super.setComplete(complete); diff --git a/status.xml b/status.xml index 808fc5d66..20f71aba0 100644 --- a/status.xml +++ b/status.xml @@ -59,6 +59,10 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + AFP GOCA: Work-around for InfoPrint's AFP implementation which seems to lose + the character set state over Graphics Data (GAD) boundaries. + Bugfix for AFP GOCA segments: they were not properly marked as appended which could lead to graphics state changes in some implementations.