Index: conf/fop.xconf
===================================================================
--- conf/fop.xconf	(revision 1339120)
+++ conf/fop.xconf	(working copy)
@@ -94,6 +94,7 @@
       -->
       <images mode="b+w" bits-per-pixel="8"/>
       <renderer-resolution>240</renderer-resolution>
+      <line-width-correction>2.5</line-width-correction>
       <resource-group-file>resources.afp</resource-group-file>
 
       <fonts>
Index: src/documentation/content/xdocs/trunk/output.xml
===================================================================
--- src/documentation/content/xdocs/trunk/output.xml	(revision 1339120)
+++ src/documentation/content/xdocs/trunk/output.xml	(working copy)
@@ -757,6 +757,14 @@
       <source><![CDATA[
       <renderer-resolution>240</renderer-resolution>]]></source>
       </section>
+      <section id="afp-line-width-correction-config">
+        <title>Line Width Correction</title>
+        <p>The default line width in AFP is device dependent. This means that a line width specified in, say,
+          a SVG source file may not render the way it was intended. The output AFP line with can be corrected
+          by the &lt;line-width-correction/&gt; configuration element. Example:</p>
+      <source><![CDATA[
+      <line-width-correction>2.5</line-width-correction>]]></source>
+      </section>
       <section id="afp-image-config">
         <title>Images</title>
         <p>By default the AFP Renderer converts all images to 8 bit grey level.
Index: src/documentation/content/xdocs/trunk/configuration.xml
===================================================================
--- src/documentation/content/xdocs/trunk/configuration.xml	(revision 1339120)
+++ src/documentation/content/xdocs/trunk/configuration.xml	(working copy)
@@ -471,6 +471,7 @@
 <source><![CDATA[<renderer mime="application/x-afp">
   <images mode="b+w" bits-per-pixel="8" native="true"/>
   <renderer-resolution>240</renderer-resolution>
+  <line-width-correction>2.5</line-width-correction>
   
   <!-- a default external resource group file -->
   <resource-group-file>resources.afp</resource-group-file>
@@ -482,6 +483,9 @@
       <p>
         The default value for the "renderer-resolution" is 240 dpi. 
       </p>
+      <p>
+        The default line width is device dependent and may need to be fine tuned so that the output matches the expected result. The default correction value is 2.5.
+      </p>
  <!--
       <p>
         The default value for the MO:DCA "interchange-set" is "MO:DCA-L". Other compliance settings include presentation interchange sets "MO:DCA-P IS/1" and "MO:DCA-P IS/2" (Resource Groups). 
Index: src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java
===================================================================
--- src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java	(revision 1339120)
+++ src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java	(working copy)
@@ -29,6 +29,7 @@
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 
+import org.apache.fop.afp.AFPConstants;
 import org.apache.fop.afp.AFPEventProducer;
 import org.apache.fop.afp.AFPResourceLevel;
 import org.apache.fop.afp.AFPResourceLevelDefaults;
@@ -446,6 +447,13 @@
             customizable.setResolution(rendererResolutionCfg.getValueAsInteger(240));
         }
 
+        // renderer resolution
+        Configuration lineWidthCorrectionCfg = cfg.getChild("line-width-correction", false);
+        if (lineWidthCorrectionCfg != null) {
+            customizable.setLineWidthCorrection(lineWidthCorrectionCfg
+                    .getValueAsFloat(AFPConstants.LINE_WIDTH_CORRECTION));
+        }
+
         // a default external resource group file setting
         Configuration resourceGroupFileCfg
         = cfg.getChild("resource-group-file", false);
Index: src/java/org/apache/fop/render/afp/AFPDocumentHandler.java
===================================================================
--- src/java/org/apache/fop/render/afp/AFPDocumentHandler.java	(revision 1339120)
+++ src/java/org/apache/fop/render/afp/AFPDocumentHandler.java	(working copy)
@@ -443,6 +443,11 @@
     }
 
     /** {@inheritDoc} */
+    public void setLineWidthCorrection(float correction) {
+        paintingState.setLineWidthCorrection(correction);
+    }
+
+    /** {@inheritDoc} */
     public int getResolution() {
         return paintingState.getResolution();
     }
Index: src/java/org/apache/fop/render/afp/AFPCustomizable.java
===================================================================
--- src/java/org/apache/fop/render/afp/AFPCustomizable.java	(revision 1339120)
+++ src/java/org/apache/fop/render/afp/AFPCustomizable.java	(working copy)
@@ -90,6 +90,13 @@
     void setResolution(int resolution);
 
     /**
+     * Sets the line width correction
+     *
+     * @param correction the line width multiplying factor correction
+     */
+    void setLineWidthCorrection(float correction);
+
+    /**
      * Sets whether FS11 and FS45 non-inline images should be wrapped in a page segment
      * @param pSeg true iff images should be wrapped
      */
Index: src/java/org/apache/fop/afp/AFPConstants.java
===================================================================
--- src/java/org/apache/fop/afp/AFPConstants.java	(revision 1339120)
+++ src/java/org/apache/fop/afp/AFPConstants.java	(working copy)
@@ -50,4 +50,15 @@
      * 72dpi in millipoints
      */
     int DPI_72_MPTS = DPI_72 * 1000;
+
+    /**
+     * The line width is set as a multiplier of a default line with; the width of the default
+     * line width is implementation defined, which probably means different devices use different
+     * actual widths; this means that the source line width (as specified in, say, a SVG line
+     * element) needs to be corrected by a fudge factor that depends on the output device so that
+     * the final output (print to paper, screen viewer) looks as intended.
+     */
+    float LINE_WIDTH_CORRECTION = 2.5f;
+
 }
+
Index: src/java/org/apache/fop/afp/AFPPaintingState.java
===================================================================
--- src/java/org/apache/fop/afp/AFPPaintingState.java	(revision 1339120)
+++ src/java/org/apache/fop/afp/AFPPaintingState.java	(working copy)
@@ -79,6 +79,12 @@
     /** the output resolution */
     private int resolution = 240; // 240 dpi
 
+    /**
+     * A configurable value to correct the line width so that the output matches the expected. Different
+     * devices may need different values.
+     */
+    private float lineWidthCorrection = AFPConstants.LINE_WIDTH_CORRECTION;
+
     /** determines whether GOCA is enabled or disabled  */
     private boolean gocaEnabled = true;
     /** determines whether to stroke text in GOCA mode or to use text operators where possible */
@@ -323,6 +329,18 @@
     }
 
     /**
+     * Sets the line width correction
+     *
+     * @param correction the line width multiplying factor correction
+     */
+    public void setLineWidthCorrection(float correction) {
+        if (log.isDebugEnabled()) {
+            log.debug("line width correction set to: " + correction);
+        }
+        this.lineWidthCorrection = correction;
+    }
+
+    /**
      * Returns the output/device resolution.
      *
      * @return the resolution in dpi
@@ -332,6 +350,14 @@
     }
 
     /**
+     * Returns the line width correction.
+     * @return the correction
+     */
+    public float getLineWidthCorrection() {
+        return this.lineWidthCorrection;
+    }
+
+    /**
      * Controls whether GOCA is enabled or disabled.
      * @param enabled true if GOCA is enabled, false if it is disabled
      */
Index: src/java/org/apache/fop/afp/modca/GraphicsObject.java
===================================================================
--- src/java/org/apache/fop/afp/modca/GraphicsObject.java	(revision 1339120)
+++ src/java/org/apache/fop/afp/modca/GraphicsObject.java	(working copy)
@@ -48,6 +48,7 @@
 import org.apache.fop.afp.goca.GraphicsSetArcParameters;
 import org.apache.fop.afp.goca.GraphicsSetCharacterSet;
 import org.apache.fop.afp.goca.GraphicsSetCurrentPosition;
+import org.apache.fop.afp.goca.GraphicsSetFractionalLineWidth;
 import org.apache.fop.afp.goca.GraphicsSetLineType;
 import org.apache.fop.afp.goca.GraphicsSetLineWidth;
 import org.apache.fop.afp.goca.GraphicsSetPatternSymbol;
@@ -182,8 +183,20 @@
      * @param lineWidth the line width multiplier
      */
     public void setLineWidth(int lineWidth) {
-        if (lineWidth != graphicsState.lineWidth) {
+        if ((float) lineWidth != graphicsState.lineWidth) {
             addObject(new GraphicsSetLineWidth(lineWidth));
+            graphicsState.lineWidth = (float) lineWidth;
+        }
+    }
+
+    /**
+     * Sets the line width
+     *
+     * @param lineWidth the line width multiplier
+     */
+    public void setLineWidth(float lineWidth) {
+        if (lineWidth != graphicsState.lineWidth) {
+            addObject(new GraphicsSetFractionalLineWidth(lineWidth));
             graphicsState.lineWidth = lineWidth;
         }
     }
@@ -414,7 +427,7 @@
         private byte lineType;
 
         /** the current line width */
-        private int lineWidth;
+        private float lineWidth;
 
         /** the current fill pattern */
         private byte patternSymbol;
Index: src/java/org/apache/fop/afp/AFPGraphics2D.java
===================================================================
--- src/java/org/apache/fop/afp/AFPGraphics2D.java	(revision 1339120)
+++ src/java/org/apache/fop/afp/AFPGraphics2D.java	(working copy)
@@ -263,14 +263,6 @@
         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
@@ -282,17 +274,11 @@
         if (stroke instanceof BasicStroke) {
             BasicStroke basicStroke = (BasicStroke) stroke;
 
-            // set line width
+            // set line width and correct it; NOTE: apparently we need to correct the width so that the
+            // output looks OK since the default with depends on the output device
             float lineWidth = basicStroke.getLineWidth();
-            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?
-            }
+            float correction = paintingState.getLineWidthCorrection();
+            graphicsObj.setLineWidth(lineWidth * correction);
 
             //No line join, miter limit and end cap support in GOCA. :-(
 
Index: src/java/org/apache/fop/afp/goca/GraphicsSetFractionalLineWidth.java
===================================================================
--- src/java/org/apache/fop/afp/goca/GraphicsSetFractionalLineWidth.java	(revision 0)
+++ src/java/org/apache/fop/afp/goca/GraphicsSetFractionalLineWidth.java	(revision 0)
@@ -0,0 +1,69 @@
+/*
+ * 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;
+
+/**
+ * Sets the line width to use when stroking GOCA shapes (structured fields)
+ */
+public class GraphicsSetFractionalLineWidth extends AbstractGraphicsDrawingOrder {
+
+    /** line width multiplier */
+    private final float multiplier;
+
+    /**
+     * Main constructor
+     *
+     * @param multiplier the line width multiplier
+     */
+    public GraphicsSetFractionalLineWidth(float multiplier) {
+        this.multiplier = multiplier;
+    }
+
+    /** {@inheritDoc} */
+    public int getDataLength() {
+        return 4;
+    }
+
+    /** {@inheritDoc} */
+    public void writeToStream(OutputStream os) throws IOException {
+        int integral = (int) multiplier;
+        int fractional = (int) ((multiplier - (float) integral) * 256);
+        byte[] data = new byte[] {
+                getOrderCode(), // GSLW order code
+                0x02, // two bytes next
+                (byte) integral, // integral line with
+                (byte) fractional // and fractional
+        };
+        os.write(data);
+    }
+
+    /** {@inheritDoc} */
+    public String toString() {
+        return "GraphicsSetFractionalLineWidth{multiplier=" + multiplier + "}";
+    }
+
+    /** {@inheritDoc} */
+    byte getOrderCode() {
+        return 0x11;
+    }
+}
Index: src/java/org/apache/fop/afp/goca/GraphicsSetLineWidth.java
===================================================================
--- src/java/org/apache/fop/afp/goca/GraphicsSetLineWidth.java	(revision 1339120)
+++ src/java/org/apache/fop/afp/goca/GraphicsSetLineWidth.java	(working copy)
@@ -28,7 +28,7 @@
 public class GraphicsSetLineWidth extends AbstractGraphicsDrawingOrder {
 
     /** line width multiplier */
-    private int multiplier = 1;
+    private final int multiplier;
 
     /**
      * Main constructor
@@ -48,7 +48,7 @@
     public void writeToStream(OutputStream os) throws IOException {
         byte[] data = new byte[] {
            getOrderCode(), // GSLW order code
-           (byte)multiplier // MH (line-width)
+           (byte) multiplier // MH (line-width)
         };
         os.write(data);
     }
Index: test/java/org/apache/fop/afp/AFPGraphics2DTestCase.java
===================================================================
--- test/java/org/apache/fop/afp/AFPGraphics2DTestCase.java	(revision 0)
+++ test/java/org/apache/fop/afp/AFPGraphics2DTestCase.java	(revision 0)
@@ -0,0 +1,57 @@
+/*
+ * 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;
+
+import java.awt.BasicStroke;
+
+import org.junit.Test;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.apache.fop.afp.modca.GraphicsObject;
+import org.apache.fop.fonts.FontInfo;
+
+public class AFPGraphics2DTestCase {
+
+    private final float lineWidth = 1.0f;
+    private final float correction = 2.5f;
+    private final BasicStroke stroke = mock(BasicStroke.class);
+    private final GraphicsObject gObject = mock(GraphicsObject.class);
+    private final AFPPaintingState paintingState = mock(AFPPaintingState.class);
+    private final AFPResourceManager resourceManager = mock(AFPResourceManager.class);
+    private final AFPResourceInfo resourceInfo = mock(AFPResourceInfo.class);
+    private final FontInfo fontInfo = mock(FontInfo.class);
+    private AFPGraphics2D graphics2D = new AFPGraphics2D(false, paintingState, resourceManager, resourceInfo,
+            fontInfo);
+
+    @Test
+    public void testApplyStroke() {
+        // note: this only tests the setLineWidth in the GraphicsObject
+        float correctedLineWidth = lineWidth * correction;
+        when(stroke.getLineWidth()).thenReturn(lineWidth);
+        when(paintingState.getLineWidthCorrection()).thenReturn(correction);
+        graphics2D.setGraphicsObject(gObject);
+        graphics2D.applyStroke(stroke);
+        verify(gObject).setLineWidth(correctedLineWidth);
+    }
+
+}
Index: test/java/org/apache/fop/afp/goca/GraphicsSetFractionalLineWidthTestCase.java
===================================================================
--- test/java/org/apache/fop/afp/goca/GraphicsSetFractionalLineWidthTestCase.java	(revision 0)
+++ test/java/org/apache/fop/afp/goca/GraphicsSetFractionalLineWidthTestCase.java	(revision 0)
@@ -0,0 +1,59 @@
+/*
+ * 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.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class GraphicsSetFractionalLineWidthTestCase {
+
+    private final float multiplier = 5.25f;
+    private final GraphicsSetFractionalLineWidth gsflw = new GraphicsSetFractionalLineWidth(multiplier);
+
+    @Test
+    public void testGetDataLength() {
+        assertEquals(4, gsflw.getDataLength());
+    }
+
+    @Test
+    public void testWriteToStream() throws IOException {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        gsflw.writeToStream(baos);
+        baos.close();
+        // note: 0.25 = 64/256 and 64 = 4*16, so 0x40
+        // expected: 0x11 (order code), 0x02 (2 bytes next), 0x05 (integral multiplier), 0x40 (fractional
+        // multiplier)
+        byte[] expected = new byte[] {0x11, 0x02, 0x05, 0x40};
+        assertTrue(Arrays.equals(expected, baos.toByteArray()));
+    }
+
+    @Test
+    public void testToString() {
+        // lets make sure we keep good coverage...
+        assertEquals("GraphicsSetFractionalLineWidth{multiplier=" + multiplier + "}", gsflw.toString());
+    }
+
+}
Index: test/java/org/apache/fop/afp/goca/GraphicsSetLineWidthTestCase.java
===================================================================
--- test/java/org/apache/fop/afp/goca/GraphicsSetLineWidthTestCase.java	(revision 0)
+++ test/java/org/apache/fop/afp/goca/GraphicsSetLineWidthTestCase.java	(revision 0)
@@ -0,0 +1,57 @@
+/*
+ * 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.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class GraphicsSetLineWidthTestCase {
+
+    private final int multiplier = 5;
+    private final GraphicsSetLineWidth gslw = new GraphicsSetLineWidth(multiplier);
+
+    @Test
+    public void testGetDataLength() {
+        assertEquals(2, gslw.getDataLength());
+    }
+
+    @Test
+    public void testWriteToStream() throws IOException {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        gslw.writeToStream(baos);
+        baos.close();
+        // expected: 0x19 (order code), 0x05 (integral multiplier)
+        byte[] expected = new byte[] {0x19, 0x05};
+        assertTrue(Arrays.equals(expected, baos.toByteArray()));
+    }
+
+    @Test
+    public void testToString() {
+        // lets make sure we keep good coverage...
+        assertEquals("GraphicsSetLineWidth{multiplier=" + multiplier + "}", gslw.toString());
+    }
+
+}
