Skip to content

Commit c434f64

Browse files
FOP-3287: Set line end to flat for AFP
1 parent d1fe1f1 commit c434f64

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed

fop-core/src/main/java/org/apache/fop/afp/AFPGraphics2D.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import org.apache.xmlgraphics.java2d.TextHandler;
6060
import org.apache.xmlgraphics.util.UnitConv;
6161

62+
import org.apache.fop.afp.goca.GraphicsSetLineEnd;
6263
import org.apache.fop.afp.goca.GraphicsSetLineType;
6364
import org.apache.fop.afp.modca.GraphicsObject;
6465
import org.apache.fop.afp.modca.ResourceObject;
@@ -316,6 +317,7 @@ protected void applyStroke(Stroke stroke) {
316317
}
317318
graphicsObj.setLineType(type);
318319
}
320+
graphicsObj.setLineEnd(GraphicsSetLineEnd.FLAT);
319321
} else {
320322
LOG.warn("Unsupported Stroke: " + stroke.getClass().getName());
321323
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/* $Id$ */
19+
20+
package org.apache.fop.afp.goca;
21+
22+
import java.io.IOException;
23+
import java.io.OutputStream;
24+
25+
/**
26+
* Sets the line end to use when stroking GOCA shapes (structured fields)
27+
*/
28+
public class GraphicsSetLineEnd extends AbstractGraphicsDrawingOrder {
29+
public static final byte FLAT = 1;
30+
private byte lineEnd;
31+
32+
public GraphicsSetLineEnd(byte lineEnd) {
33+
this.lineEnd = lineEnd;
34+
}
35+
36+
/** {@inheritDoc} */
37+
public int getDataLength() {
38+
return 2;
39+
}
40+
41+
/** {@inheritDoc} */
42+
public void writeToStream(OutputStream os) throws IOException {
43+
byte[] data = new byte[] {
44+
getOrderCode(), // GSLW order code
45+
lineEnd
46+
};
47+
os.write(data);
48+
}
49+
50+
/** {@inheritDoc} */
51+
byte getOrderCode() {
52+
return 0x1A;
53+
}
54+
}

fop-core/src/main/java/org/apache/fop/afp/modca/GraphicsObject.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.apache.fop.afp.goca.GraphicsSetCharacterSet;
4848
import org.apache.fop.afp.goca.GraphicsSetCurrentPosition;
4949
import org.apache.fop.afp.goca.GraphicsSetFractionalLineWidth;
50+
import org.apache.fop.afp.goca.GraphicsSetLineEnd;
5051
import org.apache.fop.afp.goca.GraphicsSetLineType;
5152
import org.apache.fop.afp.goca.GraphicsSetLineWidth;
5253
import org.apache.fop.afp.goca.GraphicsSetPatternSymbol;
@@ -212,6 +213,10 @@ public void setLineType(byte lineType) {
212213
}
213214
}
214215

216+
public void setLineEnd(byte lineEnd) {
217+
addObject(new GraphicsSetLineEnd(lineEnd));
218+
}
219+
215220
/**
216221
* Sets whether the following shape is to be filled.
217222
*

fop-core/src/test/java/org/apache/fop/afp/AFPGraphics2DTestCase.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public void testDrawGraphicsFillet() throws IOException {
134134
ByteArrayOutputStream bos = new ByteArrayOutputStream();
135135
go.writeToStream(bos);
136136
ByteArrayInputStream is = new ByteArrayInputStream(bos.toByteArray());
137-
is.skip(17 + 9 + 14 + 6);
137+
is.skip(17 + 9 + 14 + 8);
138138
int graphicsFilletMarker = 0x85;
139139
Assert.assertEquals(is.read(), graphicsFilletMarker);
140140
int sizeOfGraphicsFillet = 128;
@@ -153,4 +153,20 @@ public void testDrawGraphicsFilletClipped() throws IOException {
153153
go.writeToStream(bos);
154154
Assert.assertEquals(bos.size(), 17 + 17);
155155
}
156+
157+
@Test
158+
public void testDrawGraphicsLineEnd() throws IOException {
159+
GraphicContext gc = new GraphicContext();
160+
gc.setClip(new Rectangle(0, 0, 100, 100));
161+
graphics2D.setGraphicContext(gc);
162+
GraphicsObject go = new GraphicsObject(new Factory(), "test");
163+
graphics2D.setGraphicsObject(go);
164+
graphics2D.draw(new Area(new Ellipse2D.Double(0, 0, 100, 100)));
165+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
166+
go.writeToStream(bos);
167+
ByteArrayInputStream is = new ByteArrayInputStream(bos.toByteArray());
168+
is.skip(40);
169+
Assert.assertEquals(is.read(), 0x1A);
170+
Assert.assertEquals(is.read(), 1);
171+
}
156172
}

0 commit comments

Comments
 (0)