pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1604279 - /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java
Date Fri, 20 Jun 2014 21:23:19 GMT
Author: tilman
Date: Fri Jun 20 21:23:19 2014
New Revision: 1604279

URL: http://svn.apache.org/r1604279
Log:
PDFBOX-1940: New stroke width calcluation, as done by John Hewson in rev 1571803 in the trunk

Modified:
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java?rev=1604279&r1=1604278&r2=1604279&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java Fri
Jun 20 21:23:19 2014
@@ -389,12 +389,7 @@ public class PageDrawer extends PDFStrea
      */
     private BasicStroke calculateStroke()
     {
-        float lineWidth = (float)getGraphicsState().getLineWidth();
-        Matrix ctm = getGraphicsState().getCurrentTransformationMatrix();
-        if (ctm != null && ctm.getXScale() > 0)
-        {
-            lineWidth = lineWidth * ctm.getXScale();
-        }
+        float lineWidth = transformWidth((float) getGraphicsState().getLineWidth());
         if (lineWidth < 0.25)
         {
             lineWidth = 0.25f;
@@ -410,14 +405,18 @@ public class PageDrawer extends PDFStrea
             float[] dashArray = stroke.getDashArray();
             if (dashArray != null)
             {
-                if (ctm != null && ctm.getXScale() > 0)
+                // apply the CTM
+                for (int i = 0; i < dashArray.length; ++i)
                 {
-                    for (int i = 0; i < dashArray.length; ++i)
-                    {
-                        dashArray[i] *= ctm.getXScale();
-                    }
+                    dashArray[i] = transformWidth(dashArray[i]);
+                }
+                phaseStart = (int)transformWidth(phaseStart);
+
+                // empty dash array is illegal
+                if (dashArray.length == 0)
+                {
+                    dashArray = null;
                 }
-                phaseStart *= ctm.getXScale();
             }
             currentStroke = new BasicStroke(lineWidth, stroke.getEndCap(), stroke.getLineJoin(),
                     stroke.getMiterLimit(), dashArray, phaseStart);
@@ -471,7 +470,7 @@ public class PageDrawer extends PDFStrea
      * @param y y-coordinate of the point to be transform
      * @return the transformed coordinates as Point2D.Double
      */
-    public java.awt.geom.Point2D.Double transformedPoint(double x, double y)
+    public Point2D.Double transformedPoint(double x, double y)
     {
         double[] position = {x,y}; 
         getGraphicsState().getCurrentTransformationMatrix().createAffineTransform().transform(
@@ -513,7 +512,7 @@ public class PageDrawer extends PDFStrea
         if (clippingWindingRule > -1)
         {
             PDGraphicsState graphicsState = getGraphicsState();
-            GeneralPath clippingPath = (GeneralPath)getLinePath().clone();
+            GeneralPath clippingPath = (GeneralPath)getLinePath().clone(); // TODO do we
really need to clone this? isn't the line path reset anyway?
             clippingPath.setWindingRule(clippingWindingRule);
             // If there is already set a clipping path, we have to intersect the new with
the existing one
             if (graphicsState.getCurrentClippingPath() != null) 
@@ -697,4 +696,19 @@ public class PageDrawer extends PDFStrea
     {
         throw new IOException("Not Implemented");
     }
+
+    private float transformWidth(float width)
+    {
+        Matrix ctm = getGraphicsState().getCurrentTransformationMatrix();
+
+        if (ctm == null)
+        {
+            // TODO does the CTM really need to use null?
+            return width;
+        }
+
+        float x = ctm.getValue(0, 0) + ctm.getValue(1, 0);
+        float y = ctm.getValue(0, 1) + ctm.getValue(1, 1);
+        return width * (float) Math.sqrt((x * x + y * y) * 0.5);
+    }
 }



Mime
View raw message