Browse Source

SetCurrentPosition fix for line drawing.

AbstractPaintingState push(), pushAll(), pop(), popAll() renamed to save(), saveAll() and restore(), restoreAll().
Some Javadoc improvements/updates.
Added Completable, Startable object writing interfaces.
StructuredDataObject interface renamed to StructuredData.
High level DataStream class moved from afp.modca to afp package.
Graphics*Relative objects removed and feature provided by absolute implementation.
GraphicsArea broken into GraphicsAreaBegin and GraphicsAreaEnd since areas are able to span more than one segment.
Improvement in SetLineWidth thickness precision.


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@719274 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-1_0
Adrian Cumiskey 15 years ago
parent
commit
8a08b69ee6
71 changed files with 1055 additions and 791 deletions
  1. 9
    10
      src/java/org/apache/fop/afp/AFPBorderPainter.java
  2. 3
    0
      src/java/org/apache/fop/afp/AFPDataObjectFactory.java
  3. 102
    54
      src/java/org/apache/fop/afp/AFPGraphics2D.java
  4. 10
    9
      src/java/org/apache/fop/afp/AFPPaintingState.java
  5. 13
    11
      src/java/org/apache/fop/afp/AFPRectanglePainter.java
  6. 0
    1
      src/java/org/apache/fop/afp/AFPResourceManager.java
  7. 0
    1
      src/java/org/apache/fop/afp/AFPStreamer.java
  8. 7
    7
      src/java/org/apache/fop/afp/AFPUnitConverter.java
  9. 9
    7
      src/java/org/apache/fop/afp/AbstractAFPPainter.java
  10. 3
    3
      src/java/org/apache/fop/afp/BorderPaintingInfo.java
  11. 13
    15
      src/java/org/apache/fop/afp/Completable.java
  12. 23
    16
      src/java/org/apache/fop/afp/DataStream.java
  13. 4
    5
      src/java/org/apache/fop/afp/Factory.java
  14. 1
    1
      src/java/org/apache/fop/afp/PaintingInfo.java
  15. 2
    2
      src/java/org/apache/fop/afp/RectanglePaintingInfo.java
  16. 13
    15
      src/java/org/apache/fop/afp/Startable.java
  17. 3
    3
      src/java/org/apache/fop/afp/StructuredData.java
  18. 30
    29
      src/java/org/apache/fop/afp/goca/AbstractGraphicsCoord.java
  19. 60
    0
      src/java/org/apache/fop/afp/goca/AbstractGraphicsDrawingOrder.java
  20. 158
    0
      src/java/org/apache/fop/afp/goca/AbstractGraphicsDrawingOrderContainer.java
  21. 0
    83
      src/java/org/apache/fop/afp/goca/AbstractGraphicsObjectContainer.java
  22. 14
    19
      src/java/org/apache/fop/afp/goca/GraphicsAreaBegin.java
  23. 16
    20
      src/java/org/apache/fop/afp/goca/GraphicsAreaEnd.java
  24. 10
    50
      src/java/org/apache/fop/afp/goca/GraphicsChainedSegment.java
  25. 59
    19
      src/java/org/apache/fop/afp/goca/GraphicsCharacterString.java
  26. 44
    45
      src/java/org/apache/fop/afp/goca/GraphicsData.java
  27. 8
    3
      src/java/org/apache/fop/afp/goca/GraphicsFillet.java
  28. 20
    17
      src/java/org/apache/fop/afp/goca/GraphicsImage.java
  29. 17
    3
      src/java/org/apache/fop/afp/goca/GraphicsLine.java
  30. 7
    5
      src/java/org/apache/fop/afp/goca/GraphicsSetCharacterSet.java
  31. 7
    6
      src/java/org/apache/fop/afp/goca/GraphicsSetLineType.java
  32. 7
    5
      src/java/org/apache/fop/afp/goca/GraphicsSetLineWidth.java
  33. 14
    3
      src/java/org/apache/fop/afp/goca/GraphicsSetMix.java
  34. 12
    11
      src/java/org/apache/fop/afp/goca/GraphicsSetPatternSymbol.java
  35. 1
    5
      src/java/org/apache/fop/afp/goca/GraphicsSetProcessColor.java
  36. 0
    64
      src/java/org/apache/fop/afp/goca/GraphicsString.java
  37. 8
    19
      src/java/org/apache/fop/afp/ioca/ImageCellPosition.java
  38. 8
    20
      src/java/org/apache/fop/afp/ioca/ImageContent.java
  39. 1
    4
      src/java/org/apache/fop/afp/ioca/ImageInputDescriptor.java
  40. 2
    6
      src/java/org/apache/fop/afp/ioca/ImageOutputControl.java
  41. 2
    5
      src/java/org/apache/fop/afp/ioca/ImageRasterData.java
  42. 6
    6
      src/java/org/apache/fop/afp/modca/AbstractAFPObject.java
  43. 33
    2
      src/java/org/apache/fop/afp/modca/AbstractDataObject.java
  44. 11
    2
      src/java/org/apache/fop/afp/modca/AbstractNamedAFPObject.java
  45. 13
    11
      src/java/org/apache/fop/afp/modca/AbstractPageObject.java
  46. 3
    2
      src/java/org/apache/fop/afp/modca/AbstractResourceGroupContainer.java
  47. 3
    0
      src/java/org/apache/fop/afp/modca/AbstractTripletStructuredObject.java
  48. 1
    5
      src/java/org/apache/fop/afp/modca/Document.java
  49. 112
    66
      src/java/org/apache/fop/afp/modca/GraphicsObject.java
  50. 2
    4
      src/java/org/apache/fop/afp/modca/MapCodedFont.java
  51. 5
    3
      src/java/org/apache/fop/afp/modca/ObjectEnvironmentGroup.java
  52. 1
    1
      src/java/org/apache/fop/afp/modca/PageGroup.java
  53. 24
    30
      src/java/org/apache/fop/afp/modca/ResourceEnvironmentGroup.java
  54. 14
    10
      src/java/org/apache/fop/afp/modca/StreamedResourceGroup.java
  55. 2
    2
      src/java/org/apache/fop/afp/modca/triplets/AbstractTriplet.java
  56. 3
    0
      src/java/org/apache/fop/afp/modca/triplets/DescriptorPositionTriplet.java
  57. 1
    1
      src/java/org/apache/fop/afp/modca/triplets/ResourceObjectTypeTriplet.java
  58. 3
    0
      src/java/org/apache/fop/afp/svg/AFPBridgeContext.java
  59. 3
    0
      src/java/org/apache/fop/afp/svg/AFPImageElementBridge.java
  60. 23
    0
      src/java/org/apache/fop/afp/svg/package.html
  61. 23
    0
      src/java/org/apache/fop/afp/util/package.html
  62. 1
    1
      src/java/org/apache/fop/pdf/PDFPaintingState.java
  63. 2
    2
      src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java
  64. 3
    3
      src/java/org/apache/fop/render/afp/AFPInfo.java
  65. 10
    10
      src/java/org/apache/fop/render/afp/AFPRenderer.java
  66. 2
    2
      src/java/org/apache/fop/render/afp/AFPSVGHandler.java
  67. 5
    5
      src/java/org/apache/fop/render/pdf/PDFRenderer.java
  68. 2
    2
      src/java/org/apache/fop/render/pdf/PDFSVGHandler.java
  69. 3
    0
      src/java/org/apache/fop/svg/AbstractFOPBridgeContext.java
  70. 6
    6
      src/java/org/apache/fop/svg/PDFGraphics2D.java
  71. 15
    14
      src/java/org/apache/fop/util/AbstractPaintingState.java

+ 9
- 10
src/java/org/apache/fop/afp/AFPBorderPainter.java View File

@@ -21,7 +21,6 @@ package org.apache.fop.afp;

import java.awt.geom.AffineTransform;

import org.apache.fop.afp.modca.DataStream;
import org.apache.fop.fo.Constants;
import org.apache.fop.util.ColorUtil;

@@ -33,16 +32,16 @@ public class AFPBorderPainter extends AbstractAFPPainter {
/**
* Main constructor
*
* @param state the AFP painting state converter
* @param paintingState the AFP painting state converter
* @param dataStream the AFP datastream
*/
public AFPBorderPainter(AFPPaintingState state, DataStream dataStream) {
super(state, dataStream);
public AFPBorderPainter(AFPPaintingState paintingState, DataStream dataStream) {
super(paintingState, dataStream);
}

/** {@inheritDoc} */
public void paint(PaintInfo paintInfo) {
BorderPaintInfo borderPaintInfo = (BorderPaintInfo)paintInfo;
public void paint(PaintingInfo paintInfo) {
BorderPaintingInfo borderPaintInfo = (BorderPaintingInfo)paintInfo;
float w = borderPaintInfo.getX2() - borderPaintInfo.getX1();
float h = borderPaintInfo.getY2() - borderPaintInfo.getY1();
if ((w < 0) || (h < 0)) {
@@ -52,15 +51,15 @@ public class AFPBorderPainter extends AbstractAFPPainter {

int pageWidth = dataStream.getCurrentPage().getWidth();
int pageHeight = dataStream.getCurrentPage().getHeight();
AFPUnitConverter unitConv = state.getUnitConverter();
AffineTransform at = state.getData().getTransform();
AFPUnitConverter unitConv = paintingState.getUnitConverter();
AffineTransform at = paintingState.getData().getTransform();

float x1 = unitConv.pt2units(borderPaintInfo.getX1());
float y1 = unitConv.pt2units(borderPaintInfo.getY1());
float x2 = unitConv.pt2units(borderPaintInfo.getX2());
float y2 = unitConv.pt2units(borderPaintInfo.getY2());

switch (state.getRotation()) {
switch (paintingState.getRotation()) {
case 0:
x1 += at.getTranslateX();
y1 += at.getTranslateY();
@@ -89,7 +88,7 @@ public class AFPBorderPainter extends AbstractAFPPainter {

AFPLineDataInfo lineDataInfo = new AFPLineDataInfo();
lineDataInfo.setColor(borderPaintInfo.getColor());
lineDataInfo.setRotation(state.getRotation());
lineDataInfo.setRotation(paintingState.getRotation());
lineDataInfo.x1 = Math.round(x1);
lineDataInfo.y1 = Math.round(y1);
if (borderPaintInfo.isHorizontal()) {

+ 3
- 0
src/java/org/apache/fop/afp/AFPDataObjectFactory.java View File

@@ -132,8 +132,11 @@ public class AFPDataObjectFactory {
Rectangle2D area = graphicsObjectInfo.getArea();
g2d.scale(1, -1);
g2d.translate(0, -area.getHeight());

painter.paint(g2d, area);

graphicsObj.setComplete(true);

// return painted graphics object
return graphicsObj;
}

+ 102
- 54
src/java/org/apache/fop/afp/AFPGraphics2D.java View File

@@ -28,9 +28,11 @@ import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.Image;
import java.awt.Paint;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.TexturePaint;
import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
@@ -83,6 +85,9 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand

private static final int Y2 = 3;

private static final int X3 = 4;

private static final int Y3 = 5;

/** graphics object */
private GraphicsObject graphicsObj = null;
@@ -188,7 +193,7 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand

// set line width
float lineWidth = basicStroke.getLineWidth();
getGraphicsObject().setLineWidth(Math.round(lineWidth * 2));
graphicsObj.setLineWidth(Math.round(lineWidth / 2));

// set line type/style (note: this is an approximation at best!)
float[] dashArray = basicStroke.getDashArray();
@@ -219,13 +224,40 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand
}
}
}
getGraphicsObject().setLineType(type);
graphicsObj.setLineType(type);
}
} else {
log.warn("Unsupported Stroke: " + stroke.getClass().getName());
}
}

/**
* Apply the java paint to the AFP.
* This takes the java paint sets up the appropriate AFP commands
* for the drawing with that paint.
* Currently this supports the gradients and patterns from batik.
*
* @param paint the paint to convert to AFP
* @param fill true if the paint should be set for filling
* @return true if the paint is handled natively, false if the paint should be rasterized
*/
private boolean applyPaint(Paint paint, boolean fill) {
if (paint instanceof Color) {
return true;
}
log.debug("NYI: applyPaint() " + paint + " fill=" + fill);
if (paint instanceof TexturePaint) {
// TexturePaint texturePaint = (TexturePaint)paint;
// BufferedImage bufferedImage = texturePaint.getImage();
// AffineTransform at = paintingState.getTransform();
// int x = (int)Math.round(at.getTranslateX());
// int y = (int)Math.round(at.getTranslateY());
// drawImage(bufferedImage, x, y, null);
}
return false;
}


/**
* Handle the Batik drawing event
*
@@ -239,25 +271,22 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand
graphicsObj.newSegment();
}

Color color = getColor();
if (paintingState.setColor(color)) {
graphicsObj.setColor(color);
}
graphicsObj.setColor(gc.getColor());

Stroke stroke = getStroke();
applyStroke(stroke);
applyPaint(gc.getPaint(), fill);

if (fill) {
graphicsObj.beginArea();
} else {
applyStroke(gc.getStroke());
}

AffineTransform trans = gc.getTransform();
PathIterator iter = shape.getPathIterator(trans);
double[] dstPts = new double[6];
int[] coords = null;
if (shape instanceof Line2D) {
double[] dstPts = new double[6];
iter.currentSegment(dstPts);
coords = new int[4];
int[] coords = new int[4];
coords[X1] = (int) Math.round(dstPts[X]);
coords[Y1] = (int) Math.round(dstPts[Y]);
iter.next();
@@ -266,8 +295,9 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand
coords[Y2] = (int) Math.round(dstPts[Y]);
graphicsObj.addLine(coords);
} else if (shape instanceof Rectangle2D) {
double[] dstPts = new double[6];
iter.currentSegment(dstPts);
coords = new int[4];
int[] coords = new int[4];
coords[X2] = (int) Math.round(dstPts[X]);
coords[Y2] = (int) Math.round(dstPts[Y]);
iter.next();
@@ -277,6 +307,7 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand
coords[Y1] = (int) Math.round(dstPts[Y]);
graphicsObj.addBox(coords);
} else if (shape instanceof Ellipse2D) {
double[] dstPts = new double[6];
Ellipse2D elip = (Ellipse2D) shape;
double scale = trans.getScaleX();
double radiusWidth = elip.getWidth() / 2;
@@ -298,56 +329,73 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand
mhr
);
} else {
for (int[] openingCoords = new int[2]; !iter.isDone(); iter.next()) {
int type = iter.currentSegment(dstPts);
int numCoords;
if (type == PathIterator.SEG_MOVETO || type == PathIterator.SEG_LINETO) {
numCoords = 2;
} else if (type == PathIterator.SEG_QUADTO) {
numCoords = 4;
} else if (type == PathIterator.SEG_CUBICTO) {
numCoords = 6;
} else {
// close of the graphics segment
if (type == PathIterator.SEG_CLOSE) {
// close segment by drawing to opening position
graphicsObj.addLine(openingCoords, true);
} else {
log.debug("Unrecognised path iterator type: "
+ type);
}
continue;
}
coords = new int[numCoords];
for (int i = 0; i < numCoords; i++) {
coords[i] = (int) Math.round(dstPts[i]);
}
if (type == PathIterator.SEG_MOVETO) {
graphicsObj.setCurrentPosition(coords);
openingCoords[X] = coords[X];
openingCoords[Y] = coords[Y];
} else if (type == PathIterator.SEG_LINETO) {
graphicsObj.addLine(coords, true);
} else if (type == PathIterator.SEG_QUADTO
|| type == PathIterator.SEG_CUBICTO) {
graphicsObj.addFillet(coords, true);
}
}
processPathIterator(iter);
}

if (fill) {
graphicsObj.endArea();
}
}

/**
* Processes a path iterator generating the necessary painting operations.
*
* @param iter PathIterator to process
*/
private void processPathIterator(PathIterator iter) {
double[] dstPts = new double[6];
for (int[] openingCoords = new int[2]; !iter.isDone(); iter.next()) {
switch (iter.currentSegment(dstPts)) {
case PathIterator.SEG_LINETO:
graphicsObj.addLine(new int[] {
(int)Math.round(dstPts[X]),
(int)Math.round(dstPts[Y])
}, true);
break;
case PathIterator.SEG_QUADTO:
graphicsObj.addFillet(new int[] {
(int)Math.round(dstPts[X1]),
(int)Math.round(dstPts[Y1]),
(int)Math.round(dstPts[X2]),
(int)Math.round(dstPts[Y2])
}, true);
break;
case PathIterator.SEG_CUBICTO:
graphicsObj.addFillet(new int[] {
(int)Math.round(dstPts[X1]),
(int)Math.round(dstPts[Y1]),
(int)Math.round(dstPts[X2]),
(int)Math.round(dstPts[Y2]),
(int)Math.round(dstPts[X3]),
(int)Math.round(dstPts[Y3])
}, true);
break;
case PathIterator.SEG_MOVETO:
openingCoords = new int[] {
(int)Math.round(dstPts[X]),
(int)Math.round(dstPts[Y])
};
graphicsObj.setCurrentPosition(openingCoords);
break;
case PathIterator.SEG_CLOSE:
graphicsObj.addLine(openingCoords, true);
break;
default:
log.debug("Unrecognised path iterator type");
break;
}
}
}

/** {@inheritDoc} */
public void draw(Shape shape) {
// log.debug("draw() shape=" + shape);
log.debug("draw() shape=" + shape);
doDrawing(shape, false);
}

/** {@inheritDoc} */
public void fill(Shape shape) {
// log.debug("fill() shape=" + shape);
log.debug("fill() shape=" + shape);
doDrawing(shape, true);
}

@@ -381,11 +429,6 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand
return graphicsConfig;
}

/** {@inheritDoc} */
public void copyArea(int x, int y, int width, int height, int dx, int dy) {
log.debug("copyArea() NYI: ");
}

/** {@inheritDoc} */
public Graphics create() {
return new AFPGraphics2D(this);
@@ -643,4 +686,9 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand
log.debug("NYI: addNativeImage() "+ "image=" + image
+ ",x=" + x + ",y=" + y + ",width=" + width + ",height=" + height);
}

/** {@inheritDoc} */
public void copyArea(int x, int y, int width, int height, int dx, int dy) {
log.debug("copyArea() NYI: ");
}
}

+ 10
- 9
src/java/org/apache/fop/afp/AFPPaintingState.java View File

@@ -27,7 +27,8 @@ import org.apache.fop.util.AbstractPaintingState;
/**
* This keeps information about the current painting state when writing to an AFP datastream.
*/
public class AFPPaintingState extends org.apache.fop.util.AbstractPaintingState implements Cloneable {
public class AFPPaintingState extends org.apache.fop.util.AbstractPaintingState
implements Cloneable {

private static final long serialVersionUID = 8206711712452344473L;

@@ -337,14 +338,14 @@ public class AFPPaintingState extends org.apache.fop.util.AbstractPaintingState

/** {@inheritDoc} */
public Object clone() {
AFPPaintingState state = (AFPPaintingState)super.clone();
state.pagePaintingState = (AFPPagePaintingState)this.pagePaintingState.clone();
state.portraitRotation = this.portraitRotation;
state.landscapeRotation = this.landscapeRotation;
state.bitsPerPixel = this.bitsPerPixel;
state.colorImages = this.colorImages;
state.resolution = this.resolution;
return state;
AFPPaintingState paintingState = (AFPPaintingState)super.clone();
paintingState.pagePaintingState = (AFPPagePaintingState)this.pagePaintingState.clone();
paintingState.portraitRotation = this.portraitRotation;
paintingState.landscapeRotation = this.landscapeRotation;
paintingState.bitsPerPixel = this.bitsPerPixel;
paintingState.colorImages = this.colorImages;
paintingState.resolution = this.resolution;
return paintingState;
}

/** {@inheritDoc} */

+ 13
- 11
src/java/org/apache/fop/afp/AFPRectanglePainter.java View File

@@ -21,37 +21,39 @@ package org.apache.fop.afp;

import java.awt.geom.AffineTransform;

import org.apache.fop.afp.modca.DataStream;

/**
* A painter of rectangles in AFP
*/
public class AFPRectanglePainter extends AbstractAFPPainter {

/**
* Main constructor
*
* @param state the AFP painting state
* @param dataStream the afp datastream
* @param paintingState the AFP painting state
* @param dataStream the AFP datastream
*/
public AFPRectanglePainter(AFPPaintingState state, DataStream dataStream) {
super(state, dataStream);
public AFPRectanglePainter(AFPPaintingState paintingState, DataStream dataStream) {
super(paintingState, dataStream);
}

/** {@inheritDoc} */
public void paint(PaintInfo paintInfo) {
RectanglePaintInfo rectanglePaintInfo = (RectanglePaintInfo)paintInfo;
public void paint(PaintingInfo paintInfo) {
RectanglePaintingInfo rectanglePaintInfo = (RectanglePaintingInfo)paintInfo;
int pageWidth = dataStream.getCurrentPage().getWidth();
int pageHeight = dataStream.getCurrentPage().getHeight();

AFPUnitConverter unitConv = state.getUnitConverter();
AFPUnitConverter unitConv = paintingState.getUnitConverter();
float width = unitConv.pt2units(rectanglePaintInfo.getWidth());
float height = unitConv.pt2units(rectanglePaintInfo.getHeight());
float x = unitConv.pt2units(rectanglePaintInfo.getX());
float y = unitConv.pt2units(rectanglePaintInfo.getY());

AffineTransform at = state.getData().getTransform();
AffineTransform at = paintingState.getData().getTransform();

AFPLineDataInfo lineDataInfo = new AFPLineDataInfo();
lineDataInfo.color = state.getColor();
lineDataInfo.rotation = state.getRotation();
lineDataInfo.color = paintingState.getColor();
lineDataInfo.rotation = paintingState.getRotation();
lineDataInfo.thickness = Math.round(height);

switch (lineDataInfo.rotation) {

+ 0
- 1
src/java/org/apache/fop/afp/AFPResourceManager.java View File

@@ -25,7 +25,6 @@ import java.util.Map;

import org.apache.fop.afp.modca.AbstractDataObject;
import org.apache.fop.afp.modca.AbstractNamedAFPObject;
import org.apache.fop.afp.modca.DataStream;
import org.apache.fop.afp.modca.IncludeObject;
import org.apache.fop.afp.modca.Registry;
import org.apache.fop.afp.modca.ResourceGroup;

+ 0
- 1
src/java/org/apache/fop/afp/AFPStreamer.java View File

@@ -31,7 +31,6 @@ import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fop.afp.modca.DataStream;
import org.apache.fop.afp.modca.ResourceGroup;
import org.apache.fop.afp.modca.StreamedResourceGroup;


+ 7
- 7
src/java/org/apache/fop/afp/AFPUnitConverter.java View File

@@ -29,15 +29,15 @@ import java.awt.geom.AffineTransform;
public class AFPUnitConverter {

/** the AFP state */
private final AFPPaintingState state;
private final AFPPaintingState paintingState;

/**
* Unit converter
*
* @param state the AFP painting state
* @param paintingState the AFP painting state
*/
public AFPUnitConverter(AFPPaintingState state) {
this.state = state;
public AFPUnitConverter(AFPPaintingState paintingState) {
this.paintingState = paintingState;
}

/**
@@ -89,7 +89,7 @@ public class AFPUnitConverter {
* @return transformed point
*/
public float pt2units(float pt) {
return pt / ((float)AFPConstants.DPI_72 / state.getResolution());
return pt / ((float)AFPConstants.DPI_72 / paintingState.getResolution());
}

/**
@@ -99,14 +99,14 @@ public class AFPUnitConverter {
* @return transformed point
*/
public float mpt2units(float mpt) {
return mpt / ((float)AFPConstants.DPI_72_MPTS / state.getResolution());
return mpt / ((float)AFPConstants.DPI_72_MPTS / paintingState.getResolution());
}

private int[] transformPoints(float[] srcPts, float[] dstPts, boolean milli) {
if (dstPts == null) {
dstPts = new float[srcPts.length];
}
AffineTransform at = state.getData().getTransform();
AffineTransform at = paintingState.getData().getTransform();
at.transform(srcPts, 0, dstPts, 0, srcPts.length / 2);
int[] coords = new int[srcPts.length];
for (int i = 0; i < srcPts.length; i++) {

+ 9
- 7
src/java/org/apache/fop/afp/AbstractAFPPainter.java View File

@@ -21,24 +21,26 @@ package org.apache.fop.afp;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fop.afp.modca.DataStream;

/**
* A base AFP painter
*/
public abstract class AbstractAFPPainter {

/** Static logging instance */
protected static Log log = LogFactory.getLog("org.apache.xmlgraphics.afp");

protected final DataStream dataStream;
protected final AFPPaintingState state;
protected final AFPPaintingState paintingState;

/**
* Main constructor
*
* @param state the afp state
* @param dataStream the afp datastream
* @param paintingState the AFP painting state
* @param dataStream the AFP Datastream
*/
public AbstractAFPPainter(AFPPaintingState state, DataStream dataStream) {
this.state = state;
public AbstractAFPPainter(AFPPaintingState paintingState, DataStream dataStream) {
this.paintingState = paintingState;
this.dataStream = dataStream;
}

@@ -47,5 +49,5 @@ public abstract class AbstractAFPPainter {
*
* @param paintInfo the painting information
*/
public abstract void paint(PaintInfo paintInfo);
public abstract void paint(PaintingInfo paintInfo);
}

src/java/org/apache/fop/afp/BorderPaintInfo.java → src/java/org/apache/fop/afp/BorderPaintingInfo.java View File

@@ -21,11 +21,11 @@ package org.apache.fop.afp;

import java.awt.Color;


/**
* Border painting information
*/
public class BorderPaintInfo implements PaintInfo {
public class BorderPaintingInfo implements PaintingInfo {

private final float x1;
private final float y1;
private final float x2;
@@ -45,7 +45,7 @@ public class BorderPaintInfo implements PaintInfo {
* @param style the border style
* @param color the border color
*/
public BorderPaintInfo(float x1, float y1, float x2, float y2,
public BorderPaintingInfo(float x1, float y1, float x2, float y2,
boolean isHorizontal, int style, Color color) {
this.x1 = x1;
this.y1 = y1;

src/java/org/apache/fop/afp/goca/GraphicsLineRelative.java → src/java/org/apache/fop/afp/Completable.java View File

@@ -17,26 +17,24 @@

/* $Id$ */

package org.apache.fop.afp.goca;
package org.apache.fop.afp;

/**
* A GOCA graphics straight line drawn from the
* relative from the current position.
* Set and expose the internal completeness of an object.
*/
public class GraphicsLineRelative extends AbstractGraphicsCoord {
public interface Completable {

/**
* Constructor
* Sets whether or not this object is complete or not
*
* @param coords the x/y coordinates for this object
* @param complete true if this object is complete
*/
public GraphicsLineRelative(int[] coords) {
super(coords);
}
void setComplete(boolean complete);

/** {@inheritDoc} */
byte getOrderCode() {
return (byte)0x81;
}

}
/**
* Returns true if this object is complete
*
* @return true if this object is complete
*/
boolean isComplete();
}

src/java/org/apache/fop/afp/modca/DataStream.java → src/java/org/apache/fop/afp/DataStream.java View File

@@ -17,7 +17,7 @@

/* $Id$ */

package org.apache.fop.afp.modca;
package org.apache.fop.afp;

import java.awt.Color;
import java.awt.Point;
@@ -28,13 +28,16 @@ import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fop.afp.AFPLineDataInfo;
import org.apache.fop.afp.AFPPaintingState;
import org.apache.fop.afp.AFPResourceLevel;
import org.apache.fop.afp.AFPTextDataInfo;
import org.apache.fop.afp.Factory;
import org.apache.fop.afp.fonts.AFPFont;
import org.apache.fop.afp.fonts.AFPFontAttributes;
import org.apache.fop.afp.modca.AbstractPageObject;
import org.apache.fop.afp.modca.Document;
import org.apache.fop.afp.modca.InterchangeSet;
import org.apache.fop.afp.modca.Overlay;
import org.apache.fop.afp.modca.PageGroup;
import org.apache.fop.afp.modca.PageObject;
import org.apache.fop.afp.modca.ResourceGroup;
import org.apache.fop.afp.modca.TagLogicalElementBean;
import org.apache.fop.afp.modca.triplets.FullyQualifiedNameTriplet;

/**
@@ -55,7 +58,7 @@ import org.apache.fop.afp.modca.triplets.FullyQualifiedNameTriplet;
public class DataStream {

/** Static logging instance */
protected static final Log log = LogFactory.getLog("org.apache.xmlgraphics.afp.modca");
protected static final Log log = LogFactory.getLog("org.apache.xmlgraphics.afp");

/** Boolean completion indicator */
private boolean complete = false;
@@ -84,17 +87,17 @@ public class DataStream {
private OutputStream outputStream;

/** the afp painting state */
private final AFPPaintingState state;
private final AFPPaintingState paintingState;

/**
* Default constructor for the AFPDocumentStream.
*
* @param factory the resource factory
* @param state the AFP painting state
* @param paintingState the AFP painting state
* @param outputStream the outputstream to write to
*/
public DataStream(Factory factory, AFPPaintingState state, OutputStream outputStream) {
this.state = state;
public DataStream(Factory factory, AFPPaintingState paintingState, OutputStream outputStream) {
this.paintingState = paintingState;
this.factory = factory;
this.outputStream = outputStream;
}
@@ -141,7 +144,11 @@ public class DataStream {
}
}

/** {@inheritDoc} */
/**
* Helper method to mark the end of the current document.
*
* @throws IOException thrown if an I/O exception of some sort has occurred
*/
public void endDocument() throws IOException {
if (complete) {
String msg = "Invalid state - document already ended.";
@@ -329,7 +336,7 @@ public class DataStream {
*/
private Point getPoint(int x, int y) {
Point p = new Point();
int rotation = state.getRotation();
int rotation = paintingState.getRotation();
switch (rotation) {
case 90:
p.x = y;
@@ -359,7 +366,7 @@ public class DataStream {
* the afp text data
*/
public void createText(AFPTextDataInfo textDataInfo) {
int rotation = state.getRotation();
int rotation = paintingState.getRotation();
if (rotation != 0) {
textDataInfo.setRotation(rotation);
Point p = getPoint(textDataInfo.getX(), textDataInfo.getY());
@@ -406,7 +413,7 @@ public class DataStream {
* the name of the static overlay
*/
public void createIncludePageOverlay(String name) {
currentPageObject.createIncludePageOverlay(name, 0, 0, state.getRotation());
currentPageObject.createIncludePageOverlay(name, 0, 0, paintingState.getRotation());
currentPageObject.getActiveEnvironmentGroup().createOverlay(name);
}

@@ -433,7 +440,7 @@ public class DataStream {
public void createIncludePageSegment(String name, int x, int y) {
int xOrigin;
int yOrigin;
int orientation = state.getRotation();
int orientation = paintingState.getRotation();
switch (orientation) {
case 90:
xOrigin = currentPage.getWidth() - y;

+ 4
- 5
src/java/org/apache/fop/afp/Factory.java View File

@@ -30,7 +30,6 @@ import org.apache.fop.afp.ioca.ImageSegment;
import org.apache.fop.afp.ioca.ImageSizeParameter;
import org.apache.fop.afp.modca.ActiveEnvironmentGroup;
import org.apache.fop.afp.modca.ContainerDataDescriptor;
import org.apache.fop.afp.modca.DataStream;
import org.apache.fop.afp.modca.Document;
import org.apache.fop.afp.modca.GraphicsDataDescriptor;
import org.apache.fop.afp.modca.GraphicsObject;
@@ -62,7 +61,7 @@ import org.apache.fop.afp.modca.TagLogicalElement;
import org.apache.fop.afp.util.StringUtils;

/**
* Creator of MO:DCA data objects (mostly)
* Creator of MO:DCA structured field objects
*/
public class Factory {

@@ -392,12 +391,12 @@ public class Factory {
/**
* Creates a new {@link DataStream}
*
* @param state the AFP painting state
* @param paintingState the AFP painting state
* @param outputStream an outputstream to write to
* @return a new {@link DataStream}
*/
public DataStream createDataStream(AFPPaintingState state, OutputStream outputStream) {
DataStream dataStream = new DataStream(this, state, outputStream);
public DataStream createDataStream(AFPPaintingState paintingState, OutputStream outputStream) {
DataStream dataStream = new DataStream(this, paintingState, outputStream);
return dataStream;
}


src/java/org/apache/fop/afp/PaintInfo.java → src/java/org/apache/fop/afp/PaintingInfo.java View File

@@ -22,6 +22,6 @@ package org.apache.fop.afp;
/**
* Generic painting information interface
*/
public interface PaintInfo {
public interface PaintingInfo {

}

src/java/org/apache/fop/afp/RectanglePaintInfo.java → src/java/org/apache/fop/afp/RectanglePaintingInfo.java View File

@@ -23,7 +23,7 @@ package org.apache.fop.afp;
/**
* Filled rectangle painting information
*/
public class RectanglePaintInfo implements PaintInfo {
public class RectanglePaintingInfo implements PaintingInfo {

private final float x;
private final float y;
@@ -38,7 +38,7 @@ public class RectanglePaintInfo implements PaintInfo {
* @param width the width
* @param height the height
*/
public RectanglePaintInfo(float x, float y, float width, float height) {
public RectanglePaintingInfo(float x, float y, float width, float height) {
this.x = x;
this.y = y;
this.width = width;

src/java/org/apache/fop/afp/goca/GraphicsFilletRelative.java → src/java/org/apache/fop/afp/Startable.java View File

@@ -17,26 +17,24 @@

/* $Id$ */

package org.apache.fop.afp.goca;

package org.apache.fop.afp;

/**
* A GOCA graphics curved tangential line to a specified set of
* straight lines drawn from the given position or current position
* Set and expose whether an object has started or not.
*/
public final class GraphicsFilletRelative extends AbstractGraphicsCoord {
public interface Startable {

/**
* Constructor
* Sets whether or not this object has started or not
*
* @param coords the x/y coordinates for this object
* @param complete true if this object has started
*/
public GraphicsFilletRelative(int[] coords) {
super(coords);
}
void setStarted(boolean started);

/** {@inheritDoc} */
byte getOrderCode() {
return (byte)0x85;
}
}
/**
* Returns true if this object has started
*
* @return true if this object has started
*/
boolean isStarted();
}

src/java/org/apache/fop/afp/modca/StructuredDataObject.java → src/java/org/apache/fop/afp/StructuredData.java View File

@@ -17,12 +17,12 @@

/* $Id$ */

package org.apache.fop.afp.modca;
package org.apache.fop.afp;

/**
* An AFP object which is able to know its own data length before writeToStream()
* An AFP object which is able to know its own data length prior to writeToStream()
*/
public interface StructuredDataObject {
public interface StructuredData {

/**
* Returns the data length of this structured field

+ 30
- 29
src/java/org/apache/fop/afp/goca/AbstractGraphicsCoord.java View File

@@ -22,26 +22,40 @@ package org.apache.fop.afp.goca;
import java.io.IOException;
import java.io.OutputStream;

import org.apache.fop.afp.modca.AbstractNamedAFPObject;
import org.apache.fop.afp.modca.StructuredDataObject;
import org.apache.fop.afp.util.BinaryUtils;

/**
* A base class encapsulating the structure of coordinate based GOCA objects
*/
public abstract class AbstractGraphicsCoord extends AbstractNamedAFPObject
implements StructuredDataObject {
public abstract class AbstractGraphicsCoord extends AbstractGraphicsDrawingOrder {

/** array of x/y coordinates */
protected int[] coords = null;

protected boolean relative = false;

/**
* Constructor
*
* @param coords the x/y coordinates for this object
*/
public AbstractGraphicsCoord(int[] coords) {
this.coords = coords;
if (coords == null) {
relative = true;
} else {
this.coords = coords;
}
}

/**
* Constructor
*
* @param coords the x/y coordinates for this object
* @param relative
*/
public AbstractGraphicsCoord(int[] coords, boolean relative) {
this(coords);
this.relative = relative;
}

/**
@@ -68,16 +82,9 @@ public abstract class AbstractGraphicsCoord extends AbstractNamedAFPObject

/** {@inheritDoc} */
public int getDataLength() {
return 2 + (coords.length * 2);
return 2 + (coords != null ? coords.length * 2 : 0);
}

/**
* Returns the order code of this structured field
*
* @return the order code of this structured field
*/
abstract byte getOrderCode();

/**
* Returns the coordinate data start index
*
@@ -93,15 +100,10 @@ public abstract class AbstractGraphicsCoord extends AbstractNamedAFPObject
* @return the coordinate data
*/
byte[] getData() {
int len = getDataLength();
byte[] data = new byte[len];
data[0] = getOrderCode();
data[1] = (byte)(len - 2);

byte[] data = super.getData();
if (coords != null) {
addCoords(data, getCoordinateDataStartIndex());
}

return data;
}

@@ -125,16 +127,6 @@ public abstract class AbstractGraphicsCoord extends AbstractNamedAFPObject
}
}

/**
* 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 = "";
@@ -145,4 +137,13 @@ public abstract class AbstractGraphicsCoord extends AbstractNamedAFPObject
coordsStr = coordsStr.substring(0, coordsStr.length() - 1);
return getName() + "{" + coordsStr + "}";
}

/**
* Returns true if this is a relative drawing order
*
* @return true if this is a relative drawing order
*/
protected boolean isRelative() {
return this.relative;
}
}

+ 60
- 0
src/java/org/apache/fop/afp/goca/AbstractGraphicsDrawingOrder.java View File

@@ -0,0 +1,60 @@
/*
* 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.StructuredData;
import org.apache.fop.afp.modca.AbstractAFPObject;

/**
* A base GOCA drawing order
*/
public abstract class AbstractGraphicsDrawingOrder extends AbstractAFPObject
implements StructuredData {

/**
* Returns the order code of this structured field
*
* @return the order code of this structured field
*/
abstract byte getOrderCode();

/**
* Returns the coordinate data
*
* @return the coordinate data
*/
byte[] getData() {
int len = getDataLength();
byte[] data = new byte[len];
data[0] = getOrderCode();
data[1] = (byte)(len - 2);
return data;
}

/**
* 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);
}
}

+ 158
- 0
src/java/org/apache/fop/afp/goca/AbstractGraphicsDrawingOrderContainer.java View File

@@ -0,0 +1,158 @@
/*
* 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 java.util.Collection;
import java.util.Iterator;
import java.util.List;

import org.apache.fop.afp.Completable;
import org.apache.fop.afp.Startable;
import org.apache.fop.afp.StructuredData;
import org.apache.fop.afp.modca.AbstractNamedAFPObject;

/**
* A base container of prepared structured AFP objects
*/
public abstract class AbstractGraphicsDrawingOrderContainer extends AbstractNamedAFPObject
implements StructuredData, Completable, Startable {

/** list of objects contained within this container */
protected List/*<StructuredDataObject>*/ objects
= new java.util.ArrayList/*<StructuredDataObject>*/();

/** object is complete */
private boolean complete = false;

/** object has started */
private boolean started = false;

/**
* Default constructor
*/
protected AbstractGraphicsDrawingOrderContainer() {
}

/**
* Named constructor
*
* @param name the name of the container
*/
protected AbstractGraphicsDrawingOrderContainer(String name) {
super(name);
}

/** {@inheritDoc} */
protected void writeStart(OutputStream os) throws IOException {
setStarted(true);
}

/** {@inheritDoc} */
protected void writeContent(OutputStream os) throws IOException {
writeObjects(objects, os);
}

/**
* Adds a given graphics object to this container
*
* @param object the structured data object
*/
public void addObject(StructuredData object) {
objects.add(object);
}

/**
* Adds all the contents of a given graphics container to this container
*
* @param graphicsContainer a graphics container
*/
public void addAll(AbstractGraphicsDrawingOrderContainer graphicsContainer) {
Collection/*<StructuredDataObject>*/ objects = graphicsContainer.getObjects();
objects.addAll(objects);
}

/**
* Returns all the objects in this container
*
* @return all the objects in this container
*/
private Collection getObjects() {
return this.objects;
}

/**
* Removes the last drawing order from this container and returns it
*
* @return the last drawing order from this container or null if empty
*/
public StructuredData removeLast() {
int lastIndex = objects.size() - 1;
StructuredData object = null;
if (lastIndex > -1) {
object = (StructuredData)objects.get(lastIndex);
objects.remove(lastIndex);
}
return object;
}

/**
* Returns the current data length
*
* @return the current data length of this container including
* all enclosed objects (and their containers)
*/
public int getDataLength() {
int dataLen = 0;
Iterator it = objects.iterator();
while (it.hasNext()) {
dataLen += ((StructuredData)it.next()).getDataLength();
}
return dataLen;
}

/** {@inheritDoc} */
public void setComplete(boolean complete) {
Iterator it = objects.iterator();
while (it.hasNext()) {
Object object = it.next();
if (object instanceof Completable) {
((Completable)object).setComplete(true);
}
}
this.complete = true;
}

/** {@inheritDoc} */
public boolean isComplete() {
return this.complete;
}

/** {@inheritDoc} */
public boolean isStarted() {
return this.started;
}

/** {@inheritDoc} */
public void setStarted(boolean started) {
this.started = started;
}
}

+ 0
- 83
src/java/org/apache/fop/afp/goca/AbstractGraphicsObjectContainer.java View File

@@ -1,83 +0,0 @@
/*
* 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 java.util.Iterator;
import java.util.List;

import org.apache.fop.afp.modca.AbstractNamedAFPObject;
import org.apache.fop.afp.modca.StructuredDataObject;

/**
* A base container of prepared structured AFP objects
*/
public abstract class AbstractGraphicsObjectContainer extends AbstractNamedAFPObject
implements StructuredDataObject {

/** list of objects contained within this container */
protected List/*<StructuredDataObject>*/ objects
= new java.util.ArrayList/*<StructuredDataObject>*/();

/**
* Default constructor
*/
protected AbstractGraphicsObjectContainer() {
}

/**
* Named constructor
*
* @param name the name of the container
*/
protected AbstractGraphicsObjectContainer(String name) {
super(name);
}

/** {@inheritDoc} */
protected void writeContent(OutputStream os) throws IOException {
writeObjects(objects, os);
}

/**
* Adds a given graphics object to this container
*
* @param drawingOrder the graphics object
*/
public void addObject(StructuredDataObject drawingOrder) {
objects.add(drawingOrder);
}

/**
* Returns the current data length
*
* @return the current data length of this container including
* all enclosed objects (and their containers)
*/
public int getDataLength() {
int dataLen = 0;
Iterator it = objects.iterator();
while (it.hasNext()) {
dataLen += ((StructuredDataObject)it.next()).getDataLength();
}
return dataLen;
}
}

src/java/org/apache/fop/afp/goca/GraphicsArea.java → src/java/org/apache/fop/afp/goca/GraphicsAreaBegin.java View File

@@ -15,18 +15,17 @@
* limitations under the License.
*/

/* $Id: $ */
/* $Id$ */

package org.apache.fop.afp.goca;

import java.io.IOException;
import java.io.OutputStream;


/**
* A GOCA graphics area (container for filled shapes/objects)
* The beginning of a filled region (graphics area).
*/
public final class GraphicsArea extends AbstractGraphicsObjectContainer {
public class GraphicsAreaBegin extends AbstractGraphicsDrawingOrder {

private static final int RES1 = 1;
private static final int BOUNDARY = 2;
@@ -45,30 +44,26 @@ public final class GraphicsArea extends AbstractGraphicsObjectContainer {
}

/** {@inheritDoc} */
public int getDataLength() {
return 4 + super.getDataLength();
}

/** {@inheritDoc} */
protected void writeStart(OutputStream os) throws IOException {
public void writeToStream(OutputStream os) throws IOException {
byte[] data = new byte[] {
(byte)0x68, // GBAR order code
getOrderCode(), // GBAR order code
(byte)(RES1 + (drawBoundary ? BOUNDARY : NO_BOUNDARY))
};
os.write(data);
}

/** {@inheritDoc} */
protected void writeEnd(OutputStream os) throws IOException {
byte[] data = new byte[] {
(byte)0x60, // GEAR order code
0x00, // LENGTH
};
os.write(data);
public int getDataLength() {
return 2;
}

/** {@inheritDoc} */
public String toString() {
return "GraphicsArea{drawBoundary=" + drawBoundary + "}";
return "GraphicsAreaBegin{drawBoundary=" + drawBoundary + "}";
}

/** {@inheritDoc} */
byte getOrderCode() {
return 0x68;
}
}
}

src/java/org/apache/fop/afp/goca/GraphicsStringRelative.java → src/java/org/apache/fop/afp/goca/GraphicsAreaEnd.java View File

@@ -23,35 +23,31 @@ import java.io.IOException;
import java.io.OutputStream;

/**
* A GOCA graphics string
* The end of a filled region (graphics area).
*/
public class GraphicsStringRelative extends AbstractGraphicsString {

/**
* Constructor
*
* @param str the character string
*/
public GraphicsStringRelative(String str) {
super(str);
}
public class GraphicsAreaEnd extends AbstractGraphicsDrawingOrder {

/** {@inheritDoc} */
byte getOrderCode() {
return (byte)0x83;
public void writeToStream(OutputStream os) throws IOException {
byte[] data = new byte[] {
getOrderCode(), // GEAR order code
0x00, // LENGTH
};
os.write(data);
}

/** {@inheritDoc} */
public void writeToStream(OutputStream os) throws IOException {
byte[] data = getData();
byte[] strData = getStringAsBytes();
System.arraycopy(strData, 0, data, 2, strData.length);
os.write(data);
public int getDataLength() {
return 2;
}

/** {@inheritDoc} */
public String toString() {
return "GraphicsStringRelative{str='" + str + "'" + "}";
return "GraphicsAreaEnd";
}

}
/** {@inheritDoc} */
byte getOrderCode() {
return 0x60;
}
}

+ 10
- 50
src/java/org/apache/fop/afp/goca/GraphicsChainedSegment.java View File

@@ -22,25 +22,17 @@ package org.apache.fop.afp.goca;
import java.io.IOException;
import java.io.OutputStream;

import org.apache.fop.afp.modca.StructuredDataObject;
import org.apache.fop.afp.util.BinaryUtils;

/**
* A GOCA graphics segment
*/
public final class GraphicsChainedSegment extends AbstractGraphicsObjectContainer {
public final class GraphicsChainedSegment extends AbstractGraphicsDrawingOrderContainer {

/** 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;
private byte[] predecessorNameBytes;

/**
* Main constructor
@@ -57,13 +49,12 @@ public final class GraphicsChainedSegment extends AbstractGraphicsObjectContaine
*
* @param name
* the name of this graphics segment
* @param previous
* the previous graphics segment in this chain
* @param predecessorNameBytes
* the name of the predecessor in this chain
*/
public GraphicsChainedSegment(String name, GraphicsChainedSegment previous) {
public GraphicsChainedSegment(String name, byte[] predecessorNameBytes) {
super(name);
previous.next = this;
this.previous = previous;
this.predecessorNameBytes = predecessorNameBytes;
}

/** {@inheritDoc} */
@@ -88,9 +79,7 @@ public final class GraphicsChainedSegment extends AbstractGraphicsObjectContaine
}

/** {@inheritDoc} */
protected void writeStart(OutputStream os) throws IOException {
super.writeStart(os);

public void writeToStream(OutputStream os) throws IOException {
byte[] data = new byte[14];
data[0] = getOrderCode(); // BEGIN_SEGMENT
data[1] = 0x0C; // Length of following parameters
@@ -108,41 +97,12 @@ public final class GraphicsChainedSegment extends AbstractGraphicsObjectContaine
data[9] = len[1];

// P/S NAME (predecessor name)
if (previous != null) {
nameBytes = previous.getNameBytes();
System.arraycopy(nameBytes, 0, data, 10, NAME_LENGTH);
if (predecessorNameBytes != null) {
System.arraycopy(predecessorNameBytes, 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(StructuredDataObject drawingOrder) {
if (currentArea != null) {
currentArea.addObject(drawingOrder);
} else {
super.addObject(drawingOrder);
}
writeObjects(objects, os);
}

/** {@inheritDoc} */

src/java/org/apache/fop/afp/goca/AbstractGraphicsString.java → src/java/org/apache/fop/afp/goca/GraphicsCharacterString.java View File

@@ -15,15 +15,20 @@
* limitations under the License.
*/

/* $Id$ */
/* $Id: $ */

package org.apache.fop.afp.goca;

import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;

import org.apache.fop.afp.AFPConstants;

public abstract class AbstractGraphicsString extends AbstractGraphicsCoord {
/**
* A GOCA graphics string
*/
public class GraphicsCharacterString extends AbstractGraphicsCoord {

/** Up to 255 bytes of character data */
protected static final int MAX_STR_LEN = 255;
@@ -32,34 +37,63 @@ public abstract class AbstractGraphicsString extends AbstractGraphicsCoord {
protected final String str;

/**
* Constructor (relative)
* Constructor (absolute positioning)
*
* @param str the text string
* @param str the character string
* @param x the x coordinate
* @param y the y coordinate
*/
public AbstractGraphicsString(String str) {
super(null);
if (str.length() > MAX_STR_LEN) {
str = str.substring(0, MAX_STR_LEN);
log.warn("truncated character string, longer than " + MAX_STR_LEN + " chars");
}
this.str = str;
public GraphicsCharacterString(String str, int x, int y) {
super(x, y);
this.str = truncate(str);
}

/**
* Constructor (absolute)
* Constructor (relative positioning)
*
* @param str the text string
* @param str the character string
* @param x the x coordinate
* @param y the y coordinate
*/
public AbstractGraphicsString(String str, int x, int y) {
super(x, y);
this.str = str;
public GraphicsCharacterString(String str) {
super(null);
this.str = truncate(str);
}

/** {@inheritDoc} */
byte getOrderCode() {
if (isRelative()) {
return (byte)0x83;
} else {
return (byte)0xC3;
}
}

/** {@inheritDoc} */
public int getDataLength() {
return 2 + str.length();
return super.getDataLength() + str.length();
}

/** {@inheritDoc} */
public void writeToStream(OutputStream os) throws IOException {
byte[] data = getData();
byte[] strData = getStringAsBytes();
System.arraycopy(strData, 0, data, 6, strData.length);
os.write(data);
}

/**
* Truncates the string as necessary
*
* @param str a character string
* @return a possibly truncated string
*/
private String truncate(String str) {
if (str.length() > MAX_STR_LEN) {
str = str.substring(0, MAX_STR_LEN);
log.warn("truncated character string, longer than " + MAX_STR_LEN + " chars");
}
return str;
}

/**
@@ -67,8 +101,14 @@ public abstract class AbstractGraphicsString extends AbstractGraphicsCoord {
*
* @return the text string as an encoded byte array
*/
protected byte[] getStringAsBytes() throws UnsupportedEncodingException {
private byte[] getStringAsBytes() throws UnsupportedEncodingException {
return str.getBytes(AFPConstants.EBCIDIC_ENCODING);
}

}
/** {@inheritDoc} */
public String toString() {
return "GraphicsCharacterString{"
+ (coords != null ? "x=" + coords[0] + ", y=" + coords[1] : "")
+ "str='" + str + "'" + "}";
}
}

+ 44
- 45
src/java/org/apache/fop/afp/goca/GraphicsData.java View File

@@ -22,38 +22,30 @@ package org.apache.fop.afp.goca;
import java.io.IOException;
import java.io.OutputStream;

import org.apache.fop.afp.modca.StructuredDataObject;
import org.apache.fop.afp.StructuredData;
import org.apache.fop.afp.util.BinaryUtils;
import org.apache.fop.afp.util.StringUtils;

/**
* A GOCA graphics data
*/
public final class GraphicsData extends AbstractGraphicsObjectContainer {
public final class GraphicsData extends AbstractGraphicsDrawingOrderContainer {

/** The maximum graphics data length */
/** the maximum graphics data length */
public static final int MAX_DATA_LEN = 32767;

/** The graphics segment */
private GraphicsChainedSegment segment = null;

/** {@inheritDoc} */
public int getDataLength() {
return 8 + super.getDataLength();
}
/** the graphics segment */
private GraphicsChainedSegment currentSegment = null;

/**
* Begins a graphics area (start of fill)
* Main constructor
*/
public void beginArea() {
getSegment().beginArea();
public GraphicsData() {
}

/**
* Ends a graphics area (end of fill)
*/
public void endArea() {
getSegment().endArea();
/** {@inheritDoc} */
public int getDataLength() {
return 8 + super.getDataLength();
}

/**
@@ -61,48 +53,47 @@ public final class GraphicsData extends AbstractGraphicsObjectContainer {
*
* @return a new segment name
*/
private String createSegmentName() {
public 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 (segment == null) {
newSegment();
}
return this.segment;
}

/**
* Creates a new graphics segment
*
* @return a newly created graphics segment
*/
public GraphicsChainedSegment newSegment() {
String name = createSegmentName();
if (segment == null) {
this.segment = new GraphicsChainedSegment(name);
String segmentName = createSegmentName();
if (currentSegment == null) {
currentSegment = new GraphicsChainedSegment(segmentName);
} else {
this.segment = new GraphicsChainedSegment(name, segment);
currentSegment.setComplete(true);
currentSegment = new GraphicsChainedSegment(segmentName, currentSegment.getNameBytes());
}
super.addObject(segment);
return segment;
super.addObject(currentSegment);
return currentSegment;
}

/** {@inheritDoc} */
public void addObject(StructuredDataObject drawingOrder) {
if (segment == null
|| (segment.getDataLength() + drawingOrder.getDataLength())
>= GraphicsChainedSegment.MAX_DATA_LEN) {
public void addObject(StructuredData object) {
if (currentSegment == null
|| (currentSegment.getDataLength() + object.getDataLength())
>= GraphicsChainedSegment.MAX_DATA_LEN) {
newSegment();
}
segment.addObject(drawingOrder);
currentSegment.addObject(object);
}

/**
* Removes the current segment from this graphics data
*
* @return the current segment from this graphics data
*/
public StructuredData removeCurrentSegment() {
this.currentSegment = null;
return super.removeLast();
}

/** {@inheritDoc} */
@@ -115,13 +106,21 @@ public final class GraphicsData extends AbstractGraphicsObjectContainer {
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);
writeObjects(objects, os);
}

/** {@inheritDoc} */
public String toString() {
return "GraphicsData";
}

/**
* Adds the given segment to this graphics data
*
* @param segment a graphics chained segment
*/
public void addSegment(GraphicsChainedSegment segment) {
currentSegment = segment;
super.addObject(currentSegment);
}
}

+ 8
- 3
src/java/org/apache/fop/afp/goca/GraphicsFillet.java View File

@@ -30,12 +30,17 @@ public final class GraphicsFillet extends AbstractGraphicsCoord {
*
* @param coords the x/y coordinates for this object
*/
public GraphicsFillet(int[] coords) {
super(coords);
public GraphicsFillet(int[] coords, boolean relative) {
super(coords, relative);
}

/** {@inheritDoc} */
byte getOrderCode() {
return (byte)0xC5;
if (isRelative()) {
return (byte)0x85;
} else {
return (byte)0xC5;
}
}

}

+ 20
- 17
src/java/org/apache/fop/afp/goca/GraphicsImage.java View File

@@ -22,13 +22,15 @@ package org.apache.fop.afp.goca;
import java.io.IOException;
import java.io.OutputStream;

import org.apache.fop.afp.modca.AbstractStructuredObject;
import org.apache.fop.afp.util.BinaryUtils;

/**
* A GOCA Image
*/
public class GraphicsImage extends AbstractStructuredObject {
public class GraphicsImage extends AbstractGraphicsDrawingOrder {

/** the maximum image data length */
public static final short MAX_DATA_LEN = 255;

/** x coordinate */
private final int x;
@@ -63,13 +65,23 @@ public class GraphicsImage extends AbstractStructuredObject {
}

/** {@inheritDoc} */
protected void writeStart(OutputStream os) throws IOException {
public int getDataLength() {
//TODO:
return 0;
}

byte getOrderCode() {
return (byte)0xD1;
}

/** {@inheritDoc} */
public void writeToStream(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[] startData = new byte[] {
getOrderCode(), // GBIMG order code
(byte) 0x0A, // LENGTH
xcoord[0],
xcoord[1],
@@ -82,28 +94,19 @@ public class GraphicsImage extends AbstractStructuredObject {
h[0], // HEIGHT
h[1] //
};
os.write(data);
}

/** the maximum image data length */
public static final short MAX_DATA_LEN = 255;
os.write(startData);

/** {@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[] endData = new byte[] {
(byte) 0x93, // GEIMG order code
0x00 // LENGTH
};
os.write(data);
os.write(endData);
}

/** {@inheritDoc} */

+ 17
- 3
src/java/org/apache/fop/afp/goca/GraphicsLine.java View File

@@ -19,6 +19,9 @@

package org.apache.fop.afp.goca;

import java.io.IOException;
import java.io.OutputStream;

/**
* A GOCA graphics straight line drawn from the
* given absolute position
@@ -29,14 +32,25 @@ public class GraphicsLine extends AbstractGraphicsCoord {
* Constructor
*
* @param coords the x/y coordinates for this object
*
* @param relative is this a relative drawing order
*/
public GraphicsLine(int[] coords) {
super(coords);
public GraphicsLine(int[] coords, boolean relative) {
super(coords, relative);
}

/** {@inheritDoc} */
byte getOrderCode() {
return (byte)0xC1;
if (isRelative()) {
return (byte)0x81;
} else {
return (byte)0xC1;
}
}

/** {@inheritDoc} */
public void writeToStream(OutputStream os) throws IOException {
byte[] data = getData();
os.write(data);
}
}

+ 7
- 5
src/java/org/apache/fop/afp/goca/GraphicsSetCharacterSet.java View File

@@ -22,15 +22,12 @@ package org.apache.fop.afp.goca;
import java.io.IOException;
import java.io.OutputStream;

import org.apache.fop.afp.modca.AbstractNamedAFPObject;
import org.apache.fop.afp.modca.StructuredDataObject;
import org.apache.fop.afp.util.BinaryUtils;

/**
* Sets the current character set (font) to be used for following graphics strings
*/
public class GraphicsSetCharacterSet extends AbstractNamedAFPObject
implements StructuredDataObject {
public class GraphicsSetCharacterSet extends AbstractGraphicsDrawingOrder {

/** font character set reference */
private final int fontReference;
@@ -45,7 +42,7 @@ public class GraphicsSetCharacterSet extends AbstractNamedAFPObject
/** {@inheritDoc} */
public void writeToStream(OutputStream os) throws IOException {
byte[] data = new byte[] {
0x38, // GSCS order code
getOrderCode(), // GSCS order code
BinaryUtils.convert(fontReference)[0]
};
os.write(data);
@@ -61,4 +58,9 @@ public class GraphicsSetCharacterSet extends AbstractNamedAFPObject
return "GraphicsSetCharacterSet(" + fontReference + ")";
}

/** {@inheritDoc} */
byte getOrderCode() {
return 0x38;
}

}

+ 7
- 6
src/java/org/apache/fop/afp/goca/GraphicsSetLineType.java View File

@@ -22,14 +22,10 @@ package org.apache.fop.afp.goca;
import java.io.IOException;
import java.io.OutputStream;

import org.apache.fop.afp.modca.AbstractNamedAFPObject;
import org.apache.fop.afp.modca.StructuredDataObject;

/**
* Sets the value of the current line type attribute when stroking GOCA shapes (structured fields)
*/
public class GraphicsSetLineType extends AbstractNamedAFPObject
implements StructuredDataObject {
public class GraphicsSetLineType extends AbstractGraphicsDrawingOrder {

/** the default line type */
public static final byte DEFAULT = 0x00; // normally SOLID
@@ -78,7 +74,7 @@ implements StructuredDataObject {
/** {@inheritDoc} */
public void writeToStream(OutputStream os) throws IOException {
byte[] data = new byte[] {
0x18, // GSLW order code
getOrderCode(), // GSLW order code
type // line type
};
os.write(data);
@@ -93,4 +89,9 @@ implements StructuredDataObject {
public String toString() {
return "GraphicsSetLineType{type=" + TYPES[type] + "}";
}

/** {@inheritDoc} */
byte getOrderCode() {
return 0x18;
}
}

+ 7
- 5
src/java/org/apache/fop/afp/goca/GraphicsSetLineWidth.java View File

@@ -22,13 +22,10 @@ package org.apache.fop.afp.goca;
import java.io.IOException;
import java.io.OutputStream;

import org.apache.fop.afp.modca.AbstractNamedAFPObject;
import org.apache.fop.afp.modca.StructuredDataObject;

/**
* Sets the line width to use when stroking GOCA shapes (structured fields)
*/
public class GraphicsSetLineWidth extends AbstractNamedAFPObject implements StructuredDataObject {
public class GraphicsSetLineWidth extends AbstractGraphicsDrawingOrder {

/** line width multiplier */
private int multiplier = 1;
@@ -50,7 +47,7 @@ public class GraphicsSetLineWidth extends AbstractNamedAFPObject implements Stru
/** {@inheritDoc} */
public void writeToStream(OutputStream os) throws IOException {
byte[] data = new byte[] {
0x19, // GSLW order code
getOrderCode(), // GSLW order code
(byte)multiplier // MH (line-width)
};
os.write(data);
@@ -60,4 +57,9 @@ public class GraphicsSetLineWidth extends AbstractNamedAFPObject implements Stru
public String toString() {
return "GraphicsSetLineWidth{multiplier=" + multiplier + "}";
}

/** {@inheritDoc} */
byte getOrderCode() {
return 0x19;
}
}

+ 14
- 3
src/java/org/apache/fop/afp/goca/GraphicsSetMix.java View File

@@ -22,9 +22,10 @@ package org.apache.fop.afp.goca;
import java.io.IOException;
import java.io.OutputStream;

import org.apache.fop.afp.modca.AbstractNamedAFPObject;

public class GraphicsSetMix extends AbstractNamedAFPObject {
/**
* Sets the foreground mix mode.
*/
public class GraphicsSetMix extends AbstractGraphicsDrawingOrder {

public static final byte MODE_DEFAULT = 0x00;
public static final byte MODE_OVERPAINT = 0x02;
@@ -55,4 +56,14 @@ public class GraphicsSetMix extends AbstractNamedAFPObject {
return "GraphicsSetMix{mode=" + mode + "}";
}

/** {@inheritDoc} */
byte getOrderCode() {
return 0x0C;
}

/** {@inheritDoc} */
public int getDataLength() {
return 2;
}

}

+ 12
- 11
src/java/org/apache/fop/afp/goca/GraphicsSetPatternSymbol.java View File

@@ -22,14 +22,10 @@ package org.apache.fop.afp.goca;
import java.io.IOException;
import java.io.OutputStream;

import org.apache.fop.afp.modca.AbstractNamedAFPObject;
import org.apache.fop.afp.modca.StructuredDataObject;

/**
* Sets the pattern symbol to use when filling following GOCA structured fields
*/
public class GraphicsSetPatternSymbol extends AbstractNamedAFPObject
implements StructuredDataObject {
public class GraphicsSetPatternSymbol extends AbstractGraphicsDrawingOrder {

/** dotted density 1 */
public static final byte DOTTED_DENSITY_1 = 0x01;
@@ -83,15 +79,15 @@ implements StructuredDataObject {
public static final byte BLANK = 0x40; // processed same as NO_FILL

/** the graphics pattern symbol to use */
private final byte symbol;
private final byte pattern;

/**
* Main constructor
*
* @param symb the pattern symbol to use
*/
public GraphicsSetPatternSymbol(byte symb) {
this.symbol = symb;
public GraphicsSetPatternSymbol(byte pattern) {
this.pattern = pattern;
}

/** {@inheritDoc} */
@@ -102,8 +98,8 @@ implements StructuredDataObject {
/** {@inheritDoc} */
public void writeToStream(OutputStream os) throws IOException {
byte[] data = new byte[] {
0x28, // GSPT order code
symbol
getOrderCode(), // GSPT order code
pattern
};
os.write(data);
}
@@ -111,6 +107,11 @@ implements StructuredDataObject {
/** {@inheritDoc} */
public String toString() {
return "GraphicsSetPatternSymbol(fill="
+ (symbol == SOLID_FILL ? true : false) + ")";
+ (pattern == SOLID_FILL ? true : false) + ")";
}

/** {@inheritDoc} */
byte getOrderCode() {
return 0x28;
}
}

+ 1
- 5
src/java/org/apache/fop/afp/goca/GraphicsSetProcessColor.java View File

@@ -24,14 +24,10 @@ import java.awt.color.ColorSpace;
import java.io.IOException;
import java.io.OutputStream;

import org.apache.fop.afp.modca.AbstractNamedAFPObject;
import org.apache.fop.afp.modca.StructuredDataObject;

/**
* Sets the current processing color for the following GOCA structured fields
*/
public class GraphicsSetProcessColor extends AbstractNamedAFPObject
implements StructuredDataObject {
public class GraphicsSetProcessColor extends AbstractGraphicsDrawingOrder {

private final Color color;


+ 0
- 64
src/java/org/apache/fop/afp/goca/GraphicsString.java View File

@@ -1,64 +0,0 @@
/*
* 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;

/**
* A GOCA graphics string
*/
public class GraphicsString extends AbstractGraphicsString {

/**
* Constructor
*
* @param str the character string
* @param x the x coordinate
* @param y the y coordinate
*/
public GraphicsString(String str, int x, int y) {
super(str, x, y);
}

/** {@inheritDoc} */
byte getOrderCode() {
return (byte)0xC3;
}

/** {@inheritDoc} */
public int getDataLength() {
return super.getDataLength() + (coords.length * 2);
}

/** {@inheritDoc} */
public void writeToStream(OutputStream os) throws IOException {
byte[] data = getData();
byte[] strData = getStringAsBytes();
System.arraycopy(strData, 0, data, 6, strData.length);

os.write(data);
}

/** {@inheritDoc} */
public String toString() {
return "GraphicsString{x=" + coords[0] + ", y=" + coords[1] + "str='" + str + "'" + "}";
}
}

+ 8
- 19
src/java/org/apache/fop/afp/ioca/ImageCellPosition.java View File

@@ -31,38 +31,27 @@ import org.apache.fop.afp.util.BinaryUtils;
*/
public class ImageCellPosition extends AbstractAFPObject {

/**
* Offset of image cell in X direction
*/
/** offset of image cell in X direction */
private int xOffset = 0;

/**
* Offset of image cell in Y direction
*/
/** offset of image cell in Y direction */
private int yOffset = 0;

/**
* Size of image cell in X direction
*/
/** size of image cell in X direction */
private final byte[] xSize = new byte[] {(byte)0xFF, (byte)0xFF};

/**
* Size of image cell in Y direction
*/
/** size of image cell in Y direction */
private final byte[] ySize = new byte[] {(byte)0xFF, (byte)0xFF};

/**
* Size of fill rectangle in X direction
*/
/** size of fill rectangle in X direction */
private final byte[] xFillSize = new byte[] {(byte)0xFF, (byte)0xFF};

/**
* Size of fill rectangle in Y direction
*/
/** size of fill rectangle in Y direction */
private final byte[] yFillSize = new byte[] {(byte)0xFF, (byte)0xFF};

/**
* Constructor for the ImageCellPosition
* Main Constructor
*
* @param x The offset of image cell in X direction
* @param y The offset of image cell in Y direction
*/

+ 8
- 20
src/java/org/apache/fop/afp/ioca/ImageContent.java View File

@@ -53,38 +53,26 @@ public class ImageContent extends AbstractStructuredObject {
*/
public static final byte COMPID_G3_MMR = (byte)0x82;

/**
* The image size parameter
*/
/** the image size parameter */
private ImageSizeParameter imageSizeParameter = null;

/**
* The image encoding
*/
/** the image encoding */
private byte encoding = (byte)0x03;

/**
* The image ide size
*/
/** the image ide size */
private byte size = 1;

/**
* The image compression
*/
/** the image compression */
private byte compression = (byte)0xC0;

/**
* The image color model
*/
/** the image color model */
private byte colorModel = (byte)0x01;

/**
* The image data
*/
/** the image data */
private byte[] data;

/**
* Constructor for the image content
* Main Constructor
*/
public ImageContent() {
}
@@ -169,7 +157,7 @@ public class ImageContent extends AbstractStructuredObject {
0x00 // length
};
final int lengthOffset = 2;
writeChunksToStream(this.data, dataHeader, lengthOffset, MAX_DATA_LEN, os);
writeChunksToStream(data, dataHeader, lengthOffset, MAX_DATA_LEN, os);
}
}


+ 1
- 4
src/java/org/apache/fop/afp/ioca/ImageInputDescriptor.java View File

@@ -32,12 +32,9 @@ import org.apache.fop.afp.util.BinaryUtils;
*/
public class ImageInputDescriptor extends AbstractAFPObject {

/**
* The resolution of the raster image (default 240)
*/
/** the resolution of the raster image (default 240) */
private int resolution = 240;


/** {@inheritDoc} */
public void writeToStream(OutputStream os) throws IOException {


+ 2
- 6
src/java/org/apache/fop/afp/ioca/ImageOutputControl.java View File

@@ -33,9 +33,7 @@ import org.apache.fop.afp.util.BinaryUtils;
*/
public class ImageOutputControl extends AbstractAFPObject {

/**
* The orientation of the image
*/
/** the orientation of the image */
private int orientation = 0;

/**
@@ -50,9 +48,7 @@ public class ImageOutputControl extends AbstractAFPObject {
*/
private int yCoord = 0;

/**
* Map an image point to a single presentation device
*/
/** map an image point to a single presentation device */
private boolean singlePoint = true;

/**

+ 2
- 5
src/java/org/apache/fop/afp/ioca/ImageRasterData.java View File

@@ -23,8 +23,6 @@ import java.io.IOException;
import java.io.OutputStream;

import org.apache.fop.afp.modca.AbstractAFPObject;
import org.apache.fop.afp.modca.AbstractAFPObject.Category;
import org.apache.fop.afp.modca.AbstractAFPObject.Type;
import org.apache.fop.afp.util.BinaryUtils;

/**
@@ -49,13 +47,12 @@ import org.apache.fop.afp.util.BinaryUtils;
*/
public class ImageRasterData extends AbstractAFPObject {

/**
* The image raster data
*/
/** the image raster data */
private final byte[] rasterData;

/**
* Constructor for the image raster data object
*
* @param data The raster image data
*/
public ImageRasterData(byte[] data) {

+ 6
- 6
src/java/org/apache/fop/afp/modca/AbstractAFPObject.java View File

@@ -82,13 +82,13 @@ public abstract class AbstractAFPObject implements Streamable {
}

/**
* Help method to write a set of AFPObjects to the AFP datastream.
* Writes a collection of Streamable to the AFP Datastream.
*
* @param objects a list of AFPObjects
* @param os The stream to write to
* @throws java.io.IOException an I/O exception of some sort has occurred.
*/
protected void writeObjects(Collection/*<AbstractAFPObject>*/ objects, OutputStream os)
protected void writeObjects(Collection/*<Streamable>*/ objects, OutputStream os)
throws IOException {
if (objects != null && objects.size() > 0) {
Iterator it = objects.iterator();
@@ -103,14 +103,14 @@ public abstract class AbstractAFPObject implements Streamable {
}

/**
* Reads data chunks from an inputstream
* and then formats them with a structured header to a given outputstream
* Reads data chunks from an InputStream
* and then formats them with a structured header to a given OutputStream
*
* @param dataHeader the header data
* @param lengthOffset offset of length field in data chunk
* @param maxChunkLength the maximum chunk length
* @param inputStream the inputstream to read from
* @param outputStream the outputstream to write to
* @param inputStream the InputStream to read from
* @param outputStream the OutputStream to write to
* @throws IOException thrown if an I/O exception of some sort has occurred.
*/
protected static void copyChunks(byte[] dataHeader, int lengthOffset,

+ 33
- 2
src/java/org/apache/fop/afp/modca/AbstractDataObject.java View File

@@ -26,13 +26,15 @@ import org.apache.fop.afp.AFPDataObjectInfo;
import org.apache.fop.afp.AFPObjectAreaInfo;
import org.apache.fop.afp.AFPResourceInfo;
import org.apache.fop.afp.AFPResourceLevel;
import org.apache.fop.afp.Completable;
import org.apache.fop.afp.Factory;
import org.apache.fop.afp.Startable;

/**
* Abstract base class used by the ImageObject and GraphicsObject which both
* have define an ObjectEnvironmentGroup
*/
public abstract class AbstractDataObject extends AbstractNamedAFPObject {
public abstract class AbstractDataObject extends AbstractNamedAFPObject implements Startable, Completable {

/** the object environment group */
protected ObjectEnvironmentGroup objectEnvironmentGroup = null;
@@ -40,6 +42,12 @@ public abstract class AbstractDataObject extends AbstractNamedAFPObject {
/** the object factory */
protected final Factory factory;

/** the completion status of this object */
private boolean complete;

/** the starting status of this object */
private boolean started;

/**
* Named constructor
*
@@ -97,12 +105,35 @@ public abstract class AbstractDataObject extends AbstractNamedAFPObject {
return objectEnvironmentGroup;
}

/** {@inheritDoc} */
protected void writeStart(OutputStream os) throws IOException {
setStarted(true);
}

/** {@inheritDoc} */
protected void writeContent(OutputStream os) throws IOException {
super.writeContent(os); // write triplets
if (objectEnvironmentGroup != null) {
objectEnvironmentGroup.writeToStream(os);
}
}

/** {@inheritDoc} */
public void setStarted(boolean started) {
this.started = started;
}

/** {@inheritDoc} */
public boolean isStarted() {
return this.started;
}

/** {@inheritDoc} */
public void setComplete(boolean complete) {
this.complete = complete;
}

/** {@inheritDoc} */
public boolean isComplete() {
return this.complete;
}
}

+ 11
- 2
src/java/org/apache/fop/afp/modca/AbstractNamedAFPObject.java View File

@@ -66,7 +66,7 @@ public abstract class AbstractNamedAFPObject extends AbstractTripletStructuredOb
*
* @return the name as a byte array in EBCIDIC encoding
*/
protected byte[] getNameBytes() {
public byte[] getNameBytes() {
int afpNameLen = getNameLength();
int nameLen = name.length();
if (nameLen < afpNameLen) {
@@ -103,7 +103,16 @@ public abstract class AbstractNamedAFPObject extends AbstractTripletStructuredOb
* @return the name of this object
*/
public String getName() {
return name;
return this.name;
}

/**
* Sets the name of this object
*
* @param name the object name
*/
public void setName(String name) {
this.name = name;
}

/** {@inheritDoc} */

+ 13
- 11
src/java/org/apache/fop/afp/modca/AbstractPageObject.java View File

@@ -25,6 +25,7 @@ import java.util.List;

import org.apache.fop.afp.AFPLineDataInfo;
import org.apache.fop.afp.AFPTextDataInfo;
import org.apache.fop.afp.Completable;
import org.apache.fop.afp.Factory;
import org.apache.fop.afp.fonts.AFPFont;

@@ -48,7 +49,7 @@ import org.apache.fop.afp.fonts.AFPFont;
* in page state.
*
*/
public abstract class AbstractPageObject extends AbstractNamedAFPObject {
public abstract class AbstractPageObject extends AbstractNamedAFPObject implements Completable {

/** The active environment group for the page */
protected ActiveEnvironmentGroup activeEnvironmentGroup = null;
@@ -183,7 +184,7 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject {
if (currentPresentationTextObject != null) {
currentPresentationTextObject.endControlSequence();
}
complete = true;
setComplete(true);
}

/**
@@ -293,15 +294,6 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject {
return activeEnvironmentGroup;
}

/**
* Returns an indication if the page is complete
*
* @return whether this page is complete
*/
public boolean isComplete() {
return complete;
}

/**
* Returns the height of the page
*
@@ -343,4 +335,14 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject {
public void addObject(Object obj) {
objects.add(obj);
}

/** {@inheritDoc} */
public void setComplete(boolean complete) {
this.complete = complete;
}

/** {@inheritDoc} */
public boolean isComplete() {
return this.complete;
}
}

+ 3
- 2
src/java/org/apache/fop/afp/modca/AbstractResourceGroupContainer.java View File

@@ -24,6 +24,7 @@ import java.io.OutputStream;
import java.util.Collection;
import java.util.Iterator;

import org.apache.fop.afp.Completable;
import org.apache.fop.afp.Factory;
import org.apache.fop.afp.Streamable;

@@ -109,7 +110,7 @@ implements Streamable {
*
* @return the resource group in this resource group container
*/
protected ResourceGroup getResourceGroup() {
public ResourceGroup getResourceGroup() {
if (resourceGroup == null) {
resourceGroup = factory.createResourceGroup();
}
@@ -162,6 +163,6 @@ implements Streamable {
* @return true if this object can be written
*/
protected boolean canWrite(AbstractAFPObject obj) {
return obj instanceof AbstractPageObject && ((AbstractPageObject)obj).isComplete();
return obj instanceof AbstractPageObject && ((Completable)obj).isComplete();
}
}

+ 3
- 0
src/java/org/apache/fop/afp/modca/AbstractTripletStructuredObject.java View File

@@ -31,6 +31,9 @@ import org.apache.fop.afp.modca.triplets.CommentTriplet;
import org.apache.fop.afp.modca.triplets.FullyQualifiedNameTriplet;
import org.apache.fop.afp.modca.triplets.ObjectClassificationTriplet;

/**
* A MODCA structured object base class providing support for Triplets
*/
public class AbstractTripletStructuredObject extends AbstractStructuredObject {

/** list of object triplets */

+ 1
- 5
src/java/org/apache/fop/afp/modca/Document.java View File

@@ -69,11 +69,7 @@ public final class Document extends AbstractResourceEnvironmentGroupContainer {
complete = true;
}

/**
* Returns an indication if the page group is complete
*
* @return whether or not this page group is complete
*/
/** {@inheritDoc} */
public boolean isComplete() {
return complete;
}

+ 112
- 66
src/java/org/apache/fop/afp/modca/GraphicsObject.java View File

@@ -22,18 +22,24 @@ package org.apache.fop.afp.modca;
import java.awt.Color;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Iterator;
import java.util.List;

import org.apache.fop.afp.AFPDataObjectInfo;
import org.apache.fop.afp.AFPObjectAreaInfo;
import org.apache.fop.afp.Completable;
import org.apache.fop.afp.Factory;
import org.apache.fop.afp.StructuredData;
import org.apache.fop.afp.goca.GraphicsAreaBegin;
import org.apache.fop.afp.goca.GraphicsAreaEnd;
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.GraphicsFillet;
import org.apache.fop.afp.goca.GraphicsFilletRelative;
import org.apache.fop.afp.goca.GraphicsFullArc;
import org.apache.fop.afp.goca.GraphicsImage;
import org.apache.fop.afp.goca.GraphicsLine;
import org.apache.fop.afp.goca.GraphicsLineRelative;
import org.apache.fop.afp.goca.GraphicsSetArcParameters;
import org.apache.fop.afp.goca.GraphicsSetCharacterSet;
import org.apache.fop.afp.goca.GraphicsSetCurrentPosition;
@@ -41,7 +47,6 @@ import org.apache.fop.afp.goca.GraphicsSetLineType;
import org.apache.fop.afp.goca.GraphicsSetLineWidth;
import org.apache.fop.afp.goca.GraphicsSetPatternSymbol;
import org.apache.fop.afp.goca.GraphicsSetProcessColor;
import org.apache.fop.afp.goca.GraphicsString;

/**
* Top-level GOCA graphics object.
@@ -51,12 +56,27 @@ import org.apache.fop.afp.goca.GraphicsString;
public class GraphicsObject extends AbstractDataObject {

/** The graphics data */
private GraphicsData data = null;
private GraphicsData currentData = null;

/** list of objects contained within this container */
protected List/*<GraphicsDrawingOrder>*/ objects
= new java.util.ArrayList/*<GraphicsDrawingOrder>*/();

/** the current color */
private Color currentColor;

/** the current line type */
private byte currentLineType;

/** the current line width */
private int currentLineWidth;

/** the current fill pattern */
private byte currentPatternSymbol;

/** the current character set */
private int currentCharacterSet;

/**
* Default constructor
*
@@ -85,13 +105,18 @@ public class GraphicsObject extends AbstractDataObject {
}

/** {@inheritDoc} */
public void addObject(StructuredDataObject drawingOrder) {
if (data == null
|| (data.getDataLength() + drawingOrder.getDataLength())
>= GraphicsData.MAX_DATA_LEN) {
public void addObject(StructuredData object) {
if (currentData == null) {
newData();
} else if (currentData.getDataLength() + object.getDataLength()
>= GraphicsData.MAX_DATA_LEN) {
// graphics data full so transfer current incomplete segment to new data
GraphicsChainedSegment currentSegment
= (GraphicsChainedSegment)currentData.removeCurrentSegment();
currentSegment.setName(newData().createSegmentName());
currentData.addSegment(currentSegment);
}
data.addObject(drawingOrder);
currentData.addObject(object);
}

/**
@@ -100,10 +125,10 @@ public class GraphicsObject extends AbstractDataObject {
* @return the current graphics data
*/
private GraphicsData getData() {
if (this.data == null) {
if (this.currentData == null) {
return newData();
}
return this.data;
return this.currentData;
}

/**
@@ -112,9 +137,12 @@ public class GraphicsObject extends AbstractDataObject {
* @return a newly created graphics data
*/
private GraphicsData newData() {
this.data = factory.createGraphicsData();
objects.add(data);
return data;
if (currentData != null) {
currentData.setComplete(true);
}
this.currentData = factory.createGraphicsData();
objects.add(currentData);
return currentData;
}

/**
@@ -123,7 +151,10 @@ public class GraphicsObject extends AbstractDataObject {
* @param color the active color to use
*/
public void setColor(Color color) {
addObject(new GraphicsSetProcessColor(color));
if (!color.equals(currentColor)) {
this.currentColor = color;
addObject(new GraphicsSetProcessColor(color));
}
}

/**
@@ -138,43 +169,60 @@ public class GraphicsObject extends AbstractDataObject {
/**
* Sets the line width
*
* @param multiplier the line width multiplier
* @param lineWidth the line width multiplier
*/
public void setLineWidth(int multiplier) {
GraphicsSetLineWidth graphicsSetLineWidth = new GraphicsSetLineWidth(multiplier);
addObject(graphicsSetLineWidth);
public void setLineWidth(int lineWidth) {
if (lineWidth != currentLineWidth) {
currentLineWidth = lineWidth;
addObject(new GraphicsSetLineWidth(lineWidth));
}
}

/**
* Sets the line type
*
* @param type the line type
* @param lineType the line type
*/
public void setLineType(byte type) {
GraphicsSetLineType graphicsSetLineType = new GraphicsSetLineType(type);
addObject(graphicsSetLineType);
public void setLineType(byte lineType) {
if (lineType != currentLineType) {
currentLineType = lineType;
addObject(new GraphicsSetLineType(lineType));
}
}

/**
* Sets whether to fill the next shape
* Sets whether the following shape is to be filled
*
* @param fill whether to fill the next shape
* @param fill true if the following shape is to be filled
*/
public void setFill(boolean fill) {
GraphicsSetPatternSymbol graphicsSetPattern = new GraphicsSetPatternSymbol(
fill ? GraphicsSetPatternSymbol.SOLID_FILL
: GraphicsSetPatternSymbol.NO_FILL
);
addObject(graphicsSetPattern);
setPatternSymbol(fill ?
GraphicsSetPatternSymbol.SOLID_FILL :
GraphicsSetPatternSymbol.NO_FILL);
}

/**
* Sets the fill pattern of the next shape
*
* @param the fill pattern of the next shape
*/
public void setPatternSymbol(byte patternSymbol) {
if (currentPatternSymbol != patternSymbol) {
currentPatternSymbol = patternSymbol;
addObject(new GraphicsSetPatternSymbol(patternSymbol));
}
}

/**
* Sets the character set to use
*
* @param fontReference the character set (font) reference
* @param characterSet the character set (font) reference
*/
public void setCharacterSet(int fontReference) {
addObject(new GraphicsSetCharacterSet(fontReference));
public void setCharacterSet(int characterSet) {
if (currentCharacterSet != characterSet) {
currentCharacterSet = characterSet;
addObject(new GraphicsSetCharacterSet(characterSet));
}
}

/**
@@ -193,11 +241,7 @@ public class GraphicsObject extends AbstractDataObject {
* @param relative relative true for a line at current position (relative to)
*/
public void addLine(int[] coords, boolean relative) {
if (relative) {
addObject(new GraphicsLineRelative(coords));
} else {
addObject(new GraphicsLine(coords));
}
addObject(new GraphicsLine(coords, relative));
}

/**
@@ -222,14 +266,10 @@ public class GraphicsObject extends AbstractDataObject {
* Adds a fillet (curve) at the given coordinates
*
* @param coords the x/y coordinates
* @param relative relative true for a fillet at current position (relative to)
* @param relative relative true for a fillet (curve) at current position (relative to)
*/
public void addFillet(int[] coords, boolean relative) {
if (relative) {
addObject(new GraphicsFilletRelative(coords));
} else {
addObject(new GraphicsFillet(coords));
}
addObject(new GraphicsFillet(coords, relative));
}

/**
@@ -245,7 +285,7 @@ public class GraphicsObject extends AbstractDataObject {
}

/**
* Adds an arc
* Adds a full arc
*
* @param x the x coordinate
* @param y the y coordinate
@@ -256,18 +296,18 @@ public class GraphicsObject extends AbstractDataObject {
addObject(new GraphicsFullArc(x, y, mh, mhr));
}

// /**
// * Adds an image
// *
// * @param x the x coordinate
// * @param y the y coordinate
// * @param width the image width
// * @param height the image height
// * @param imgData the image data
// */
// public void addImage(int x, int y, int width, int height, byte[] imgData) {
// addObject(new GraphicsImage(x, y, width, height, imgData));
// }
/**
* Adds an image
*
* @param x the x coordinate
* @param y the y coordinate
* @param width the image width
* @param height the image height
* @param imgData the image data
*/
public void addImage(int x, int y, int width, int height, byte[] imgData) {
addObject(new GraphicsImage(x, y, width, height, imgData));
}

/**
* Adds a string
@@ -277,26 +317,21 @@ public class GraphicsObject extends AbstractDataObject {
* @param y the y coordinate
*/
public void addString(String str, int x, int y) {
addObject(new GraphicsString(str, x, y));
addObject(new GraphicsCharacterString(str, x, y));
}

/**
* Begins a graphics area (start of fill)
*/
public void beginArea() {
if (data == null) {
newData();
}
data.beginArea();
addObject(new GraphicsAreaBegin());
}

/**
* Ends a graphics area (end of fill)
*/
public void endArea() {
if (data != null) {
data.endArea();
}
addObject(new GraphicsAreaEnd());
}

/** {@inheritDoc} */
@@ -311,8 +346,19 @@ public class GraphicsObject extends AbstractDataObject {
getData().newSegment();
}

/** {@inheritDoc} */
public void setComplete(boolean complete) {
Iterator it = objects.iterator();
while (it.hasNext()) {
Completable completedObject = (Completable)it.next();
completedObject.setComplete(true);
}
super.setComplete(complete);
}

/** {@inheritDoc} */
protected void writeStart(OutputStream os) throws IOException {
super.writeStart(os);
byte[] data = new byte[17];
copySF(data, Type.BEGIN, Category.GRAPHICS);
os.write(data);
@@ -321,7 +367,7 @@ public class GraphicsObject extends AbstractDataObject {
/** {@inheritDoc} */
protected void writeContent(OutputStream os) throws IOException {
super.writeContent(os);
super.writeObjects(objects, os);
writeObjects(objects, os);
}

/** {@inheritDoc} */

+ 2
- 4
src/java/org/apache/fop/afp/modca/MapCodedFont.java View File

@@ -43,14 +43,12 @@ import org.apache.fop.afp.util.BinaryUtils;
*/
public class MapCodedFont extends AbstractStructuredObject {

/**
* The collection of map coded fonts (maximum of 254)
*/
/** the collection of map coded fonts (maximum of 254) */
private final List/*<FontDefinition>*/ fontList
= new java.util.ArrayList/*<FontDefinition>*/();

/**
* Constructor for the MapCodedFont
* Main constructor
*/
public MapCodedFont() {
}

+ 5
- 3
src/java/org/apache/fop/afp/modca/ObjectEnvironmentGroup.java View File

@@ -38,13 +38,13 @@ import org.apache.fop.afp.util.BinaryUtils;
public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject {

/** the PresentationEnvironmentControl for the object environment group */
private PresentationEnvironmentControl presentationEnvironmentControl = null;
private PresentationEnvironmentControl presentationEnvironmentControl;

/** the ObjectAreaDescriptor for the object environment group */
private ObjectAreaDescriptor objectAreaDescriptor = null;
private ObjectAreaDescriptor objectAreaDescriptor;

/** the ObjectAreaPosition for the object environment group */
private ObjectAreaPosition objectAreaPosition = null;
private ObjectAreaPosition objectAreaPosition;

/** the DataDescriptor for the object environment group */
private AbstractDescriptor dataDescriptor;
@@ -95,6 +95,8 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject {
data[2] = len[1];

os.write(data);

writeTriplets(os);
}

/** {@inheritDoc} */

+ 1
- 1
src/java/org/apache/fop/afp/modca/PageGroup.java View File

@@ -74,7 +74,7 @@ public class PageGroup extends AbstractResourceEnvironmentGroupContainer {
/**
* Method to mark the end of the page group.
*/
protected void endPageGroup() {
public void endPageGroup() {
complete = true;
}


+ 24
- 30
src/java/org/apache/fop/afp/modca/ResourceEnvironmentGroup.java View File

@@ -5,9 +5,9 @@
* 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.
@@ -23,34 +23,27 @@ import java.io.IOException;
import java.io.OutputStream;
import java.util.List;

import org.apache.fop.afp.Completable;

/**
* A Resource Environment Group contains a set of resources for a document
* or for a group of pages in a document.
*/
public class ResourceEnvironmentGroup extends AbstractEnvironmentGroup {
/**
* Default name for the resource group
*/
public class ResourceEnvironmentGroup extends AbstractEnvironmentGroup implements Completable {

/** default name for the resource group */
private static final String DEFAULT_NAME = "REG00001";

/**
* The maps data resources contained in this resource environment group
*/
/** the maps data resources contained in this resource environment group */
private List/*<MapDataResource>*/ mapDataResources = null;
/**
* The maps page overlays contained in this resource environment group
*/

/** the maps page overlays contained in this resource environment group */
private List mapPageOverlays = null;
/**
* The pre-process presentation objects contained in this resource environment group
*/

/** the pre-process presentation objects contained in this resource environment group */
private List/*<PreprocessPresentationObject>*/ preProcessPresentationObjects = null;

/**
* The resource environment group state
*/
/** the resource environment group state */
private boolean complete = false;

/**
@@ -100,16 +93,7 @@ public class ResourceEnvironmentGroup extends AbstractEnvironmentGroup {
// createOverlay(obj.get);
// getPreprocessPresentationObjects().add(new PreprocessPresentationObject(obj));
// }
/**
* Returns an indication if the resource environment group is complete
*
* @return whether or not this resource environment group is complete or not
*/
public boolean isComplete() {
return complete;
}

/** {@inheritDoc} */
protected void writeStart(OutputStream os) throws IOException {
byte[] data = new byte[17];
@@ -131,4 +115,14 @@ public class ResourceEnvironmentGroup extends AbstractEnvironmentGroup {
writeObjects(preProcessPresentationObjects, os);
}

/** {@inheritDoc} */
public void setComplete(boolean complete) {
this.complete = complete;
}

/** {@inheritDoc} */
public boolean isComplete() {
return complete;
}

}

+ 14
- 10
src/java/org/apache/fop/afp/modca/StreamedResourceGroup.java View File

@@ -22,10 +22,12 @@ package org.apache.fop.afp.modca;
import java.io.IOException;
import java.io.OutputStream;

import org.apache.fop.afp.Completable;

/**
* A print-file resource group
*/
public class StreamedResourceGroup extends ResourceGroup {
public class StreamedResourceGroup extends ResourceGroup implements Completable {
/** the outputstream to write to */
private final OutputStream os;

@@ -72,15 +74,6 @@ public class StreamedResourceGroup extends ResourceGroup {
complete = true;
}

/**
* Returns true if this resource group is complete
*
* @return true if this resource group is complete
*/
public boolean isComplete() {
return this.complete;
}

/**
* Returns the outputstream
*
@@ -89,4 +82,15 @@ public class StreamedResourceGroup extends ResourceGroup {
public OutputStream getOutputStream() {
return this.os;
}

/** {@inheritDoc} */
public void setComplete(boolean complete) {
this.complete = complete;
}

/** {@inheritDoc} */
public boolean isComplete() {
return this.complete;
}

}

+ 2
- 2
src/java/org/apache/fop/afp/modca/triplets/AbstractTriplet.java View File

@@ -20,12 +20,12 @@
package org.apache.fop.afp.modca.triplets;

import org.apache.fop.afp.Streamable;
import org.apache.fop.afp.modca.StructuredDataObject;
import org.apache.fop.afp.StructuredData;

/**
* A simple implementation of a MOD:CA triplet
*/
public abstract class AbstractTriplet implements Streamable, StructuredDataObject {
public abstract class AbstractTriplet implements Streamable, StructuredData {
public static final byte CODED_GRAPHIC_CHARACTER_SET_GLOBAL_IDENTIFIER = 0x01;

/** Triplet identifiers */

+ 3
- 0
src/java/org/apache/fop/afp/modca/triplets/DescriptorPositionTriplet.java View File

@@ -22,6 +22,9 @@ package org.apache.fop.afp.modca.triplets;
import java.io.IOException;
import java.io.OutputStream;

/**
* Associates an ObjectAreaPosition with and ObjectAreaDescriptor structured field
*/
public class DescriptorPositionTriplet extends AbstractTriplet {

private final byte oapId;

+ 1
- 1
src/java/org/apache/fop/afp/modca/triplets/ResourceObjectTypeTriplet.java View File

@@ -22,7 +22,7 @@ package org.apache.fop.afp.modca.triplets;
import java.io.IOException;
import java.io.OutputStream;

/** resource object type triplet */
/** A Resource Object Type Triplet */
public class ResourceObjectTypeTriplet extends AbstractTriplet {

private static final byte RESOURCE_OBJECT = 0x21;

+ 3
- 0
src/java/org/apache/fop/afp/svg/AFPBridgeContext.java View File

@@ -31,6 +31,9 @@ import org.apache.fop.svg.AbstractFOPBridgeContext;
import org.apache.xmlgraphics.image.loader.ImageManager;
import org.apache.xmlgraphics.image.loader.ImageSessionContext;

/**
* An AFP specific implementation of a Batik BridgeContext
*/
public class AFPBridgeContext extends AbstractFOPBridgeContext {

private final AFPGraphics2D g2d;

+ 3
- 0
src/java/org/apache/fop/afp/svg/AFPImageElementBridge.java View File

@@ -22,6 +22,9 @@ package org.apache.fop.afp.svg;
import org.apache.fop.svg.AbstractFOPImageElementBridge;
import org.apache.xmlgraphics.image.loader.ImageFlavor;

/**
* An AFP specific implementation of a Batik SVGImageElementBridge
*/
public class AFPImageElementBridge extends AbstractFOPImageElementBridge {

private final ImageFlavor[] supportedFlavors = new ImageFlavor[]

+ 23
- 0
src/java/org/apache/fop/afp/svg/package.html View File

@@ -0,0 +1,23 @@
<!--
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.html 643433 2008-04-01 15:08:24Z acumiskey $ -->
<HTML>
<TITLE>org.apache.fop.afp.modca.svg Package</TITLE>
<BODY>
<P>Contains a collection of AFP specific Batik bridges.</P>
</BODY>
</HTML>

+ 23
- 0
src/java/org/apache/fop/afp/util/package.html View File

@@ -0,0 +1,23 @@
<!--
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.html 643433 2008-04-01 15:08:24Z acumiskey $ -->
<HTML>
<TITLE>org.apache.fop.afp.modca.triplets Package</TITLE>
<BODY>
<P>Contains a collection of useful AFP utility classes.</P>
</BODY>
</HTML>

+ 1
- 1
src/java/org/apache/fop/pdf/PDFPaintingState.java View File

@@ -170,7 +170,7 @@ public class PDFPaintingState extends org.apache.fop.util.AbstractPaintingState
* This call should be used when the q operator is used
* so that the state is known when popped.
*/
public void push() {
public void save() {
AbstractData data = getData();
AbstractData copy = (AbstractData)data.clone();
data.clearTransform();

+ 2
- 2
src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java View File

@@ -61,7 +61,7 @@ public class AFPGraphics2DAdapter extends AbstractGraphics2DAdapter {
final boolean textAsShapes = false;
AFPGraphics2D g2d = afpInfo.createGraphics2D(textAsShapes);

paintingState.push();
paintingState.save();

//Fallback solution: Paint to a BufferedImage
if (afpInfo.paintAsBitmap()) {
@@ -95,7 +95,7 @@ public class AFPGraphics2DAdapter extends AbstractGraphics2DAdapter {
resourceManager.createObject(graphicsObjectInfo);
}

paintingState.pop();
paintingState.restore();
}

/** {@inheritDoc} */

+ 3
- 3
src/java/org/apache/fop/render/afp/AFPInfo.java View File

@@ -215,10 +215,10 @@ public final class AFPInfo {
/**
* Sets the AFP state
*
* @param state the AFP state
* @param paintingState the AFP state
*/
public void setPaintingState(AFPPaintingState state) {
this.paintingState = state;
public void setPaintingState(AFPPaintingState paintingState) {
this.paintingState = paintingState;
}

/**

+ 10
- 10
src/java/org/apache/fop/render/afp/AFPRenderer.java View File

@@ -41,13 +41,13 @@ import org.apache.fop.afp.AFPRectanglePainter;
import org.apache.fop.afp.AFPResourceManager;
import org.apache.fop.afp.AFPTextDataInfo;
import org.apache.fop.afp.AFPUnitConverter;
import org.apache.fop.afp.BorderPaintInfo;
import org.apache.fop.afp.RectanglePaintInfo;
import org.apache.fop.afp.BorderPaintingInfo;
import org.apache.fop.afp.DataStream;
import org.apache.fop.afp.RectanglePaintingInfo;
import org.apache.fop.afp.fonts.AFPFont;
import org.apache.fop.afp.fonts.AFPFontAttributes;
import org.apache.fop.afp.fonts.AFPFontCollection;
import org.apache.fop.afp.fonts.AFPPageFonts;
import org.apache.fop.afp.modca.DataStream;
import org.apache.fop.afp.modca.PageObject;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
@@ -171,9 +171,9 @@ public class AFPRenderer extends AbstractPathOrientedRenderer {
*/
public AFPRenderer() {
super();
this.imageHandlerRegistry = new AFPImageHandlerRegistry();
this.resourceManager = new AFPResourceManager();
this.paintingState = new AFPPaintingState();
this.imageHandlerRegistry = new AFPImageHandlerRegistry();
this.unitConv = paintingState.getUnitConverter();
}

@@ -335,13 +335,13 @@ public class AFPRenderer extends AbstractPathOrientedRenderer {
/** {@inheritDoc} */
public void drawBorderLine(float x1, float y1, float x2, float y2,
boolean horz, boolean startOrBefore, int style, Color col) {
BorderPaintInfo borderPaintInfo = new BorderPaintInfo(x1, y1, x2, y2, horz, style, col);
BorderPaintingInfo borderPaintInfo = new BorderPaintingInfo(x1, y1, x2, y2, horz, style, col);
borderPainter.paint(borderPaintInfo);
}

/** {@inheritDoc} */
public void fillRect(float x, float y, float width, float height) {
RectanglePaintInfo rectanglePaintInfo = new RectanglePaintInfo(x, y, width, height);
RectanglePaintingInfo rectanglePaintInfo = new RectanglePaintingInfo(x, y, width, height);
rectanglePainter.paint(rectanglePaintInfo);
}

@@ -485,23 +485,23 @@ public class AFPRenderer extends AbstractPathOrientedRenderer {
/** {@inheritDoc} */
public void restoreStateStackAfterBreakOut(List breakOutList) {
log.debug("Block.FIXED --> restoring context after break-out");
paintingState.pushAll(breakOutList);
paintingState.saveAll(breakOutList);
}

/** {@inheritDoc} */
protected List breakOutOfStateStack() {
log.debug("Block.FIXED --> break out");
return paintingState.popAll();
return paintingState.restoreAll();
}

/** {@inheritDoc} */
public void saveGraphicsState() {
paintingState.push();
paintingState.save();
}

/** {@inheritDoc} */
public void restoreGraphicsState() {
paintingState.pop();
paintingState.restore();
}

/** {@inheritDoc} */

+ 2
- 2
src/java/org/apache/fop/render/afp/AFPSVGHandler.java View File

@@ -125,7 +125,7 @@ public class AFPSVGHandler extends AbstractGenericSVGHandler {
int height = afpInfo.getHeight();
int resolution = afpInfo.getResolution();

paintingState.push(); // save
paintingState.save(); // save

AFPObjectAreaInfo objectAreaInfo
= createObjectAreaInfo(paintingState, x, y, width, height, resolution);
@@ -140,7 +140,7 @@ public class AFPSVGHandler extends AbstractGenericSVGHandler {
AFPResourceManager resourceManager = afpInfo.getResourceManager();
resourceManager.createObject(graphicsObjectInfo);

paintingState.pop(); // resume
paintingState.restore(); // resume
}

private AFPObjectAreaInfo createObjectAreaInfo(AFPPaintingState paintingState,

+ 5
- 5
src/java/org/apache/fop/render/pdf/PDFRenderer.java View File

@@ -640,7 +640,7 @@ public class PDFRenderer extends AbstractPathOrientedRenderer {
/** {@inheritDoc} */
protected void saveGraphicsState() {
endTextObject();
paintingState.push();
paintingState.save();
currentStream.add("q\n");
}

@@ -648,7 +648,7 @@ public class PDFRenderer extends AbstractPathOrientedRenderer {
endTextObject();
currentStream.add("Q\n");
if (popState) {
paintingState.pop();
paintingState.restore();
}
}

@@ -1099,7 +1099,7 @@ public class PDFRenderer extends AbstractPathOrientedRenderer {
AbstractPaintingState.AbstractData data;
while (true) {
data = paintingState.getData();
if (paintingState.pop() == null) {
if (paintingState.restore() == null) {
break;
}
if (breakOutList.size() == 0) {
@@ -1747,7 +1747,7 @@ public class PDFRenderer extends AbstractPathOrientedRenderer {
public void renderLeader(Leader area) {
renderInlineAreaBackAndBorders(area);

paintingState.push();
paintingState.save();
saveGraphicsState();
int style = area.getRuleStyle();
float startx = (currentIPPosition + area.getBorderAndPaddingWidthStart()) / 1000f;
@@ -1805,7 +1805,7 @@ public class PDFRenderer extends AbstractPathOrientedRenderer {
}

restoreGraphicsState();
paintingState.pop();
paintingState.restore();
beginTextObject();
super.renderLeader(area);
}

+ 2
- 2
src/java/org/apache/fop/render/pdf/PDFSVGHandler.java View File

@@ -243,7 +243,7 @@ public class PDFSVGHandler extends AbstractGenericSVGHandler
pdfInfo.currentStream.add("%SVG start\n");

//Save state and update coordinate system for the SVG image
pdfInfo.pdfPaintingState.push();
pdfInfo.pdfPaintingState.save();
pdfInfo.pdfPaintingState.concatenate(imageTransform);

//Now that we have the complete transformation matrix for the image, we can update the
@@ -262,7 +262,7 @@ public class PDFSVGHandler extends AbstractGenericSVGHandler
context.getUserAgent().getEventBroadcaster());
eventProducer.svgRenderingError(this, e, getDocumentURI(doc));
}
pdfInfo.pdfPaintingState.pop();
pdfInfo.pdfPaintingState.restore();
renderer.restoreGraphicsState();
pdfInfo.currentStream.add("%SVG end\n");
}

+ 3
- 0
src/java/org/apache/fop/svg/AbstractFOPBridgeContext.java View File

@@ -30,6 +30,9 @@ import org.apache.fop.fonts.FontInfo;
import org.apache.xmlgraphics.image.loader.ImageManager;
import org.apache.xmlgraphics.image.loader.ImageSessionContext;

/**
* A FOP base implementation of a Batik BridgeContext.
*/
public abstract class AbstractFOPBridgeContext extends BridgeContext {

/** The font list. */

+ 6
- 6
src/java/org/apache/fop/svg/PDFGraphics2D.java View File

@@ -608,7 +608,7 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand

if (newClip || newTransform) {
currentStream.write("q\n");
paintingState.push();
paintingState.save();
if (newTransform) {
concatMatrix(tranvals);
}
@@ -634,7 +634,7 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand

if (newClip || newTransform) {
currentStream.write("Q\n");
paintingState.pop();
paintingState.restore();
}
return;
}
@@ -646,7 +646,7 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand
doDrawing(false, true, false);
if (newClip || newTransform) {
currentStream.write("Q\n");
paintingState.pop();
paintingState.restore();
}
}

@@ -1614,7 +1614,7 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand

if (newClip || newTransform) {
currentStream.write("q\n");
paintingState.push();
paintingState.save();
if (newTransform) {
concatMatrix(tranvals);
}
@@ -1638,7 +1638,7 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand

if (newClip || newTransform) {
currentStream.write("Q\n");
paintingState.pop();
paintingState.restore();
}
return;
}
@@ -1651,7 +1651,7 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand
iter.getWindingRule() == PathIterator.WIND_EVEN_ODD);
if (newClip || newTransform) {
currentStream.write("Q\n");
paintingState.pop();
paintingState.restore();
}
}


+ 15
- 14
src/java/org/apache/fop/util/AbstractPaintingState.java View File

@@ -28,9 +28,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.Stack;


/**
* A base class which holds information about the current rendering state.
* A base class which holds information about the current painting state.
*/
public abstract class AbstractPaintingState implements Cloneable, Serializable {

@@ -278,23 +277,23 @@ public abstract class AbstractPaintingState implements Cloneable, Serializable {


/**
* Push the current painting state onto the stack.
* Save the current painting state.
* This pushes the current painting state onto the stack.
* This call should be used when the Q operator is used
* so that the state is known when popped.
*/
public void push() {
public void save() {
AbstractData copy = (AbstractData)getData().clone();
stateStack.push(copy);
}

/**
* Pop the painting state from the stack and set current values to popped state.
* This should be called when a Q operator is used so
* the state is restored to the correct values.
* Restore the current painting state.
* This pops the painting state from the stack and sets current values to popped state.
*
* @return the restored state, null if the stack is empty
*/
public AbstractData pop() {
public AbstractData restore() {
if (!stateStack.isEmpty()) {
setData((AbstractData)stateStack.pop());
return this.data;
@@ -304,30 +303,32 @@ public abstract class AbstractPaintingState implements Cloneable, Serializable {
}

/**
* Pushes all painting state data in the given list to the stack
* Save all painting state data.
* This pushes all painting state data in the given list to the stack
*
* @param dataList a state data list
*/
public void pushAll(List/*<AbstractData>*/ dataList) {
public void saveAll(List/*<AbstractData>*/ dataList) {
Iterator it = dataList.iterator();
while (it.hasNext()) {
// save current data on stack
push();
save();
setData((AbstractData)it.next());
}
}

/**
* Pops all painting state data from the stack
* Restore all painting state data.
* This pops all painting state data from the stack
*
* @return a list of state data popped from the stack
*/
public List/*<AbstractData>*/ popAll() {
public List/*<AbstractData>*/ restoreAll() {
List/*<AbstractData>*/ dataList = new java.util.ArrayList/*<AbstractData>*/();
AbstractData data;
while (true) {
data = getData();
if (pop() == null) {
if (restore() == null) {
break;
}
// insert because of stack-popping

Loading…
Cancel
Save