aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/afp/AFPGraphics2D.java
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2009-01-11 11:15:34 +0000
committerJeremias Maerki <jeremias@apache.org>2009-01-11 11:15:34 +0000
commitf6fafddeff005039538d90c825f723ba69f73564 (patch)
tree1e0131fbe0e0cca382747b76cc2409ede0d4b65e /src/java/org/apache/fop/afp/AFPGraphics2D.java
parentf6768c2460e3bd6f99b60fa296e0f1a4919e2ce5 (diff)
downloadxmlgraphics-fop-f6fafddeff005039538d90c825f723ba69f73564.tar.gz
xmlgraphics-fop-f6fafddeff005039538d90c825f723ba69f73564.zip
GOCA improvements:
Improved font size and line width calculation. Removed superfluous AFPGraphics2D.setFontInfo() method. Avoid ClassCastException inside SVG filter operations when not an AFPGraphics2D is passed in. Fixed line width state handling (it appears as if after a new segment the line width is reset. Found that out empirically. Didn't find the corresponding reference in the spec). git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign@733450 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/afp/AFPGraphics2D.java')
-rw-r--r--src/java/org/apache/fop/afp/AFPGraphics2D.java62
1 files changed, 46 insertions, 16 deletions
diff --git a/src/java/org/apache/fop/afp/AFPGraphics2D.java b/src/java/org/apache/fop/afp/AFPGraphics2D.java
index ee160feca..6f552ae5b 100644
--- a/src/java/org/apache/fop/afp/AFPGraphics2D.java
+++ b/src/java/org/apache/fop/afp/AFPGraphics2D.java
@@ -47,11 +47,7 @@ import java.io.IOException;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.fop.afp.goca.GraphicsSetLineType;
-import org.apache.fop.afp.modca.GraphicsObject;
-import org.apache.fop.afp.svg.AFPGraphicsConfiguration;
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.svg.NativeImageHandler;
+
import org.apache.xmlgraphics.image.loader.ImageInfo;
import org.apache.xmlgraphics.image.loader.ImageSize;
import org.apache.xmlgraphics.image.loader.impl.ImageRendered;
@@ -61,6 +57,13 @@ import org.apache.xmlgraphics.java2d.StrokingTextHandler;
import org.apache.xmlgraphics.java2d.TextHandler;
import org.apache.xmlgraphics.ps.ImageEncodingHelper;
import org.apache.xmlgraphics.util.MimeConstants;
+import org.apache.xmlgraphics.util.UnitConv;
+
+import org.apache.fop.afp.goca.GraphicsSetLineType;
+import org.apache.fop.afp.modca.GraphicsObject;
+import org.apache.fop.afp.svg.AFPGraphicsConfiguration;
+import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.svg.NativeImageHandler;
/**
* This is a concrete implementation of <tt>AbstractGraphics2D</tt> (and
@@ -180,6 +183,32 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand
this.gc = gc;
}
+ private int getResolution() {
+ return this.paintingState.getResolution();
+ }
+
+ /**
+ * Converts a length value to an absolute value.
+ * Please note that this only uses the "ScaleY" factor, so this will result
+ * in a bad value should "ScaleX" and "ScaleY" be different.
+ * @param length the length
+ * @return the absolute length
+ */
+ public double convertToAbsoluteLength(double length) {
+ AffineTransform current = getTransform();
+ double mult = getResolution() / (double)UnitConv.IN2PT;
+ double factor = -current.getScaleY() / mult;
+ return length * factor;
+ }
+
+ /** IBM's AFP Workbench paints lines that are wider than expected. We correct manually. */
+ private static final double GUESSED_WIDTH_CORRECTION = 1.7;
+
+ private static final double SPEC_NORMAL_LINE_WIDTH = UnitConv.in2pt(0.01); //"approx" 0.01 inch
+ private static final double NORMAL_LINE_WIDTH
+ = SPEC_NORMAL_LINE_WIDTH * GUESSED_WIDTH_CORRECTION;
+
+
/**
* Apply the stroke to the AFP graphics object.
* This takes the java stroke and outputs the appropriate settings
@@ -193,7 +222,17 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand
// set line width
float lineWidth = basicStroke.getLineWidth();
- graphicsObj.setLineWidth(Math.round(lineWidth / 2));
+ if (false) {
+ //Old approach. Retained until verified problems with 1440 resolution
+ graphicsObj.setLineWidth(Math.round(lineWidth / 2));
+ } else {
+ double absoluteLineWidth = lineWidth * Math.abs(getTransform().getScaleY());
+ double multiplier = absoluteLineWidth / NORMAL_LINE_WIDTH;
+ graphicsObj.setLineWidth((int)Math.round(multiplier));
+ //TODO Use GSFLW instead of GSLW for higher accuracy?
+ }
+
+ //No line join, miter limit and end cap support in GOCA. :-(
// set line type/style (note: this is an approximation at best!)
float[] dashArray = basicStroke.getDashArray();
@@ -651,15 +690,6 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand
}
/**
- * Sets the FontInfo
- *
- * @param the FontInfo
- */
- public void setFontInfo(FontInfo fontInfo) {
- this.fontInfo = fontInfo;
- }
-
- /**
* Returns the FontInfo
*
* @return the FontInfo
@@ -687,7 +717,7 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand
/** {@inheritDoc} */
public void addNativeImage(org.apache.xmlgraphics.image.loader.Image image,
float x, float y, float width, float height) {
- log.debug("NYI: addNativeImage() "+ "image=" + image
+ log.debug("NYI: addNativeImage() " + "image=" + image
+ ",x=" + x + ",y=" + y + ",width=" + width + ",height=" + height);
}