From 6a1c75ff782f5cd334d96456eb2db7981dfffaf2 Mon Sep 17 00:00:00 2001 From: Adrian Cumiskey Date: Fri, 21 Nov 2008 14:29:17 +0000 Subject: [PATCH] y-axis positioning fix in AFPGraphics2D. GraphicsState inner class created in GraphicsObject. Unused methods setFill() and incrementPageFontCount() removed. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@719587 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/fop/afp/AFPDataObjectFactory.java | 11 ++++ .../org/apache/fop/afp/AFPGraphics2D.java | 10 +++- .../org/apache/fop/afp/AFPPaintingState.java | 23 -------- .../apache/fop/afp/AFPResourceManager.java | 9 +-- .../fop/afp/modca/AbstractDescriptor.java | 20 +++++++ .../apache/fop/afp/modca/GraphicsObject.java | 55 ++++++++++--------- .../fop/afp/modca/ObjectEnvironmentGroup.java | 9 +++ .../apache/fop/render/afp/AFPRenderer.java | 3 +- 8 files changed, 80 insertions(+), 60 deletions(-) diff --git a/src/java/org/apache/fop/afp/AFPDataObjectFactory.java b/src/java/org/apache/fop/afp/AFPDataObjectFactory.java index 5463a336b..aba181358 100644 --- a/src/java/org/apache/fop/afp/AFPDataObjectFactory.java +++ b/src/java/org/apache/fop/afp/AFPDataObjectFactory.java @@ -63,6 +63,9 @@ public class AFPDataObjectFactory { public ObjectContainer createObjectContainer(AFPDataObjectInfo dataObjectInfo) { ObjectContainer objectContainer = factory.createObjectContainer(); + // set data object viewport (i.e. position, rotation, dimension, resolution) + objectContainer.setViewport(dataObjectInfo); + // set object classification Registry.ObjectType objectType = dataObjectInfo.getObjectType(); AFPResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); @@ -87,6 +90,10 @@ public class AFPDataObjectFactory { public ImageObject createImage(AFPImageObjectInfo imageObjectInfo) { // IOCA bitmap image ImageObject imageObj = factory.createImageObject(); + + // set data object viewport (i.e. position, rotation, dimension, resolution) + imageObj.setViewport(imageObjectInfo); + if (imageObjectInfo.hasCompression()) { int compression = imageObjectInfo.getCompression(); switch (compression) { @@ -124,6 +131,10 @@ public class AFPDataObjectFactory { public GraphicsObject createGraphic(AFPGraphicsObjectInfo graphicsObjectInfo) { // set newly created graphics object in g2d GraphicsObject graphicsObj = factory.createGraphicsObject(); + + // set data object viewport (i.e. position, rotation, dimension, resolution) + graphicsObj.setViewport(graphicsObjectInfo); + AFPGraphics2D g2d = graphicsObjectInfo.getGraphics2D(); g2d.setGraphicsObject(graphicsObj); diff --git a/src/java/org/apache/fop/afp/AFPGraphics2D.java b/src/java/org/apache/fop/afp/AFPGraphics2D.java index e8eebce43..ee160feca 100644 --- a/src/java/org/apache/fop/afp/AFPGraphics2D.java +++ b/src/java/org/apache/fop/afp/AFPGraphics2D.java @@ -580,13 +580,17 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand /** {@inheritDoc} */ public void drawRenderedImage(RenderedImage img, AffineTransform xform) { - int width = img.getWidth(); - int height = img.getHeight(); + int imgWidth = img.getWidth(); + int imgHeight = img.getHeight(); AffineTransform at = paintingState.getData().getTransform(); AffineTransform gat = gc.getTransform(); + int graphicsObjectHeight + = graphicsObj.getObjectEnvironmentGroup().getObjectAreaDescriptor().getHeight(); int x = (int)Math.round(at.getTranslateX() + gat.getTranslateX()); - int y = (int)Math.round(at.getTranslateY()); + int y = (int)Math.round(at.getTranslateY() - (gat.getTranslateY() - graphicsObjectHeight)); + int width = (int)Math.round(imgWidth * gat.getScaleX()); + int height = (int)Math.round(imgHeight * -gat.getScaleY()); try { // get image object info AFPImageObjectInfo imageObjectInfo diff --git a/src/java/org/apache/fop/afp/AFPPaintingState.java b/src/java/org/apache/fop/afp/AFPPaintingState.java index bf710b18d..95a310bcb 100644 --- a/src/java/org/apache/fop/afp/AFPPaintingState.java +++ b/src/java/org/apache/fop/afp/AFPPaintingState.java @@ -223,20 +223,6 @@ implements Cloneable { return this.pagePaintingState; } - /** - * Sets if the current painted shape is to be filled - * - * @param fill true if the current painted shape is to be filled - * @return true if the fill value has changed - */ - protected boolean setFill(boolean fill) { - if (fill != ((AFPData)getData()).filled) { - ((AFPData)getData()).filled = fill; - return true; - } - return false; - } - /** * Gets the current page fonts * @@ -246,15 +232,6 @@ implements Cloneable { return pagePaintingState.getFonts(); } - /** - * Increments and returns the page font count - * - * @return the page font count - */ - public int incrementPageFontCount() { - return pagePaintingState.incrementFontCount(); - } - /** * Sets the page width * diff --git a/src/java/org/apache/fop/afp/AFPResourceManager.java b/src/java/org/apache/fop/afp/AFPResourceManager.java index 9a521dbe7..164ebfd2d 100644 --- a/src/java/org/apache/fop/afp/AFPResourceManager.java +++ b/src/java/org/apache/fop/afp/AFPResourceManager.java @@ -23,7 +23,6 @@ import java.io.IOException; import java.io.OutputStream; import java.util.Map; -import org.apache.fop.afp.modca.AbstractDataObject; import org.apache.fop.afp.modca.AbstractNamedAFPObject; import org.apache.fop.afp.modca.IncludeObject; import org.apache.fop.afp.modca.Registry; @@ -136,18 +135,12 @@ public class AFPResourceManager { AFPGraphicsObjectInfo graphicsObjectInfo = (AFPGraphicsObjectInfo)dataObjectInfo; namedObj = dataObjectFactory.createGraphic(graphicsObjectInfo); } else { - // natively embedded object + // natively embedded data object namedObj = dataObjectFactory.createObjectContainer(dataObjectInfo); objectType = dataObjectInfo.getObjectType(); useInclude = objectType != null && objectType.isIncludable(); } - // set data object viewport (i.e. position, rotation, dimension, resolution) - if (namedObj instanceof AbstractDataObject) { - AbstractDataObject dataObj = (AbstractDataObject)namedObj; - dataObj.setViewport(dataObjectInfo); - } - AFPResourceLevel resourceLevel = resourceInfo.getLevel(); ResourceGroup resourceGroup = streamer.getResourceGroup(resourceLevel); useInclude &= resourceGroup != null; diff --git a/src/java/org/apache/fop/afp/modca/AbstractDescriptor.java b/src/java/org/apache/fop/afp/modca/AbstractDescriptor.java index c471794e9..8344bf0d1 100644 --- a/src/java/org/apache/fop/afp/modca/AbstractDescriptor.java +++ b/src/java/org/apache/fop/afp/modca/AbstractDescriptor.java @@ -23,6 +23,7 @@ package org.apache.fop.afp.modca; * Base class for AFP descriptor objects */ public abstract class AbstractDescriptor extends AbstractTripletStructuredObject { + /** width of this descriptor */ protected int width = 0; /** height of this descriptor */ @@ -61,4 +62,23 @@ public abstract class AbstractDescriptor extends AbstractTripletStructuredObject + ", widthRes=" + widthRes + ", heightRes=" + heightRes; } + + /** + * Returns the width + * + * @return the width + */ + public int getWidth() { + return this.width; + } + + /** + * Returns the height + * + * @return the height + */ + public int getHeight() { + return this.height; + } + } diff --git a/src/java/org/apache/fop/afp/modca/GraphicsObject.java b/src/java/org/apache/fop/afp/modca/GraphicsObject.java index 710e7364b..7602f7dd5 100644 --- a/src/java/org/apache/fop/afp/modca/GraphicsObject.java +++ b/src/java/org/apache/fop/afp/modca/GraphicsObject.java @@ -55,27 +55,15 @@ import org.apache.fop.afp.goca.GraphicsSetProcessColor; */ public class GraphicsObject extends AbstractDataObject { - /** The graphics data */ + /** the graphics data */ private GraphicsData currentData = null; /** list of objects contained within this container */ protected List/**/ objects = new java.util.ArrayList/**/(); - /** 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; + /** the graphics state */ + private final GraphicsState graphicsState = new GraphicsState(); /** * Default constructor @@ -151,9 +139,9 @@ public class GraphicsObject extends AbstractDataObject { * @param color the active color to use */ public void setColor(Color color) { - if (!color.equals(currentColor)) { - this.currentColor = color; + if (!color.equals(graphicsState.color)) { addObject(new GraphicsSetProcessColor(color)); + graphicsState.color = color; } } @@ -172,9 +160,9 @@ public class GraphicsObject extends AbstractDataObject { * @param lineWidth the line width multiplier */ public void setLineWidth(int lineWidth) { - if (lineWidth != currentLineWidth) { - currentLineWidth = lineWidth; + if (lineWidth != graphicsState.lineWidth) { addObject(new GraphicsSetLineWidth(lineWidth)); + graphicsState.lineWidth = lineWidth; } } @@ -184,9 +172,9 @@ public class GraphicsObject extends AbstractDataObject { * @param lineType the line type */ public void setLineType(byte lineType) { - if (lineType != currentLineType) { - currentLineType = lineType; + if (lineType != graphicsState.lineType) { addObject(new GraphicsSetLineType(lineType)); + graphicsState.lineType = lineType; } } @@ -207,9 +195,9 @@ public class GraphicsObject extends AbstractDataObject { * @param the fill pattern of the next shape */ public void setPatternSymbol(byte patternSymbol) { - if (currentPatternSymbol != patternSymbol) { - currentPatternSymbol = patternSymbol; + if (patternSymbol != graphicsState.patternSymbol) { addObject(new GraphicsSetPatternSymbol(patternSymbol)); + graphicsState.patternSymbol = patternSymbol; } } @@ -219,9 +207,9 @@ public class GraphicsObject extends AbstractDataObject { * @param characterSet the character set (font) reference */ public void setCharacterSet(int characterSet) { - if (currentCharacterSet != characterSet) { - currentCharacterSet = characterSet; + if (characterSet != graphicsState.characterSet) { addObject(new GraphicsSetCharacterSet(characterSet)); + graphicsState.characterSet = characterSet; } } @@ -377,4 +365,21 @@ public class GraphicsObject extends AbstractDataObject { os.write(data); } + /** the internal graphics state */ + private class GraphicsState { + /** the current color */ + private Color color; + + /** the current line type */ + private byte lineType; + + /** the current line width */ + private int lineWidth; + + /** the current fill pattern */ + private byte patternSymbol; + + /** the current character set */ + private int characterSet; + } } \ No newline at end of file diff --git a/src/java/org/apache/fop/afp/modca/ObjectEnvironmentGroup.java b/src/java/org/apache/fop/afp/modca/ObjectEnvironmentGroup.java index 883a5446d..bc0cc5a63 100644 --- a/src/java/org/apache/fop/afp/modca/ObjectEnvironmentGroup.java +++ b/src/java/org/apache/fop/afp/modca/ObjectEnvironmentGroup.java @@ -172,4 +172,13 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { this.mapContainerData = mapContainerData; } + /** + * Returns the object area descriptor + * + * @return the object area descriptor + */ + public ObjectAreaDescriptor getObjectAreaDescriptor() { + return this.objectAreaDescriptor; + } + } diff --git a/src/java/org/apache/fop/render/afp/AFPRenderer.java b/src/java/org/apache/fop/render/afp/AFPRenderer.java index edc8f7662..903099610 100644 --- a/src/java/org/apache/fop/render/afp/AFPRenderer.java +++ b/src/java/org/apache/fop/render/afp/AFPRenderer.java @@ -517,7 +517,8 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { // register font as necessary String internalFontName = getInternalFontNameForArea(text); - AFPFont font = (AFPFont)fontInfo.getFonts().get(internalFontName); + Map/**/ fontMetricMap = fontInfo.getFonts(); + AFPFont font = (AFPFont)fontMetricMap.get(internalFontName); AFPPageFonts pageFonts = paintingState.getPageFonts(); AFPFontAttributes fontAttributes = pageFonts.registerFont(internalFontName, font, fontSize); -- 2.39.5