From f6fa22263eb843527a1525d960565934c1f01130 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Wed, 20 Apr 2011 14:07:36 +0000 Subject: [PATCH] Bugfix for AFP GOCA segments: they were not properly marked as appended which could lead to graphics state changes in some implementations. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1095418 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/afp/goca/GraphicsChainedSegment.java | 23 ++++++++++++++----- .../org/apache/fop/afp/goca/GraphicsData.java | 22 ++++++++++++++---- status.xml | 4 ++++ 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/java/org/apache/fop/afp/goca/GraphicsChainedSegment.java b/src/java/org/apache/fop/afp/goca/GraphicsChainedSegment.java index 8d94bf9fc..9e7016874 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsChainedSegment.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsChainedSegment.java @@ -33,6 +33,7 @@ public final class GraphicsChainedSegment extends AbstractGraphicsDrawingOrderCo protected static final int MAX_DATA_LEN = 8192; private byte[] predecessorNameBytes; + private boolean appended; /** * Main constructor @@ -41,7 +42,7 @@ public final class GraphicsChainedSegment extends AbstractGraphicsDrawingOrderCo * the name of this graphics segment */ public GraphicsChainedSegment(String name) { - super(name); + this(name, null, false); } /** @@ -51,24 +52,32 @@ public final class GraphicsChainedSegment extends AbstractGraphicsDrawingOrderCo * the name of this graphics segment * @param predecessorNameBytes * the name of the predecessor in this chain + * @param appended true if this segment is appended to the previous one */ - public GraphicsChainedSegment(String name, byte[] predecessorNameBytes) { + public GraphicsChainedSegment(String name, byte[] predecessorNameBytes, boolean appended) { super(name); - this.predecessorNameBytes = predecessorNameBytes; + if (predecessorNameBytes != null) { + this.predecessorNameBytes = new byte[predecessorNameBytes.length]; + System.arraycopy(predecessorNameBytes, 0, + this.predecessorNameBytes, 0, predecessorNameBytes.length); + } + this.appended = appended; } /** {@inheritDoc} */ + @Override 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 byte APPEND_TO_EXISING = 6; private static final int NAME_LENGTH = 4; /** {@inheritDoc} */ + @Override protected int getNameLength() { return NAME_LENGTH; } @@ -78,6 +87,7 @@ public final class GraphicsChainedSegment extends AbstractGraphicsDrawingOrderCo } /** {@inheritDoc} */ + @Override public void writeToStream(OutputStream os) throws IOException { byte[] data = new byte[14]; data[0] = getOrderCode(); // BEGIN_SEGMENT @@ -88,7 +98,7 @@ public final class GraphicsChainedSegment extends AbstractGraphicsDrawingOrderCo System.arraycopy(nameBytes, 0, data, 2, NAME_LENGTH); data[6] = 0x00; // FLAG1 (ignored) - data[7] = APPEND_NEW_SEGMENT; + data[7] = this.appended ? APPEND_TO_EXISING : APPEND_NEW_SEGMENT; //FLAG2 int dataLength = super.getDataLength(); byte[] len = BinaryUtils.convert(dataLength, 2); @@ -105,7 +115,8 @@ public final class GraphicsChainedSegment extends AbstractGraphicsDrawingOrderCo } /** {@inheritDoc} */ + @Override public String toString() { - return "GraphicsChainedSegment(name=" + super.getName() + ")"; + return "GraphicsChainedSegment(name=" + super.getName() + ", len: " + getDataLength() + ")"; } } \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/goca/GraphicsData.java b/src/java/org/apache/fop/afp/goca/GraphicsData.java index 1ba757e4b..752d09b48 100644 --- a/src/java/org/apache/fop/afp/goca/GraphicsData.java +++ b/src/java/org/apache/fop/afp/goca/GraphicsData.java @@ -44,6 +44,7 @@ public final class GraphicsData extends AbstractGraphicsDrawingOrderContainer { } /** {@inheritDoc} */ + @Override public int getDataLength() { return 8 + super.getDataLength(); } @@ -60,28 +61,39 @@ public final class GraphicsData extends AbstractGraphicsDrawingOrderContainer { } /** - * Creates a new graphics segment + * Creates a new graphics segment. * * @return a newly created graphics segment */ public GraphicsChainedSegment newSegment() { + return newSegment(false); + } + + /** + * Creates a new graphics segment. + * @param appended true if this segment is appended to the previous one + * @return a newly created graphics segment + */ + public GraphicsChainedSegment newSegment(boolean appended) { String segmentName = createSegmentName(); if (currentSegment == null) { currentSegment = new GraphicsChainedSegment(segmentName); } else { currentSegment.setComplete(true); - currentSegment = new GraphicsChainedSegment(segmentName, currentSegment.getNameBytes()); + currentSegment = new GraphicsChainedSegment(segmentName, + currentSegment.getNameBytes(), appended); } super.addObject(currentSegment); return currentSegment; } /** {@inheritDoc} */ + @Override public void addObject(StructuredData object) { if (currentSegment == null || (currentSegment.getDataLength() + object.getDataLength()) >= GraphicsChainedSegment.MAX_DATA_LEN) { - newSegment(); + newSegment(true); } currentSegment.addObject(object); } @@ -97,6 +109,7 @@ public final class GraphicsData extends AbstractGraphicsDrawingOrderContainer { } /** {@inheritDoc} */ + @Override public void writeToStream(OutputStream os) throws IOException { byte[] data = new byte[9]; copySF(data, SF_CLASS, Type.DATA, Category.GRAPHICS); @@ -110,8 +123,9 @@ public final class GraphicsData extends AbstractGraphicsDrawingOrderContainer { } /** {@inheritDoc} */ + @Override public String toString() { - return "GraphicsData"; + return "GraphicsData(len: " + getDataLength() + ")"; } /** diff --git a/status.xml b/status.xml index 23dedd018..808fc5d66 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. --> + + Bugfix for AFP GOCA segments: they were not properly marked as appended which could + lead to graphics state changes in some implementations. + Bugzilla 51010: Bookmarks create useless lines in RTF -- 2.39.5