pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1561191 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer: SetLineWidth.java StrokePath.java
Date Fri, 24 Jan 2014 21:24:16 GMT
Author: lehmi
Date: Fri Jan 24 21:24:16 2014
New Revision: 1561191

URL: http://svn.apache.org/r1561191
Log:
PDFBOX-1861: add the transformation to the dash before painting as proposed by Tilman Hausherr
and John Hewson

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/SetLineWidth.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/StrokePath.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/SetLineWidth.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/SetLineWidth.java?rev=1561191&r1=1561190&r2=1561191&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/SetLineWidth.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/SetLineWidth.java
Fri Jan 24 21:24:16 2014
@@ -23,7 +23,6 @@ import org.apache.pdfbox.pdfviewer.PageD
 import org.apache.pdfbox.util.PDFOperator;
 
 import java.awt.BasicStroke;
-import java.awt.Graphics2D;
 import java.io.IOException;
 
 /**
@@ -45,10 +44,6 @@ public class SetLineWidth extends org.ap
     {
         super.process( operator, arguments );
         float lineWidth = (float)context.getGraphicsState().getLineWidth();
-        if (lineWidth == 0) 
-        {
-            lineWidth = 1;
-        }
         PageDrawer drawer = (PageDrawer)context;
         BasicStroke stroke = (BasicStroke)drawer.getStroke();
         if (stroke == null)

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/StrokePath.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/StrokePath.java?rev=1561191&r1=1561190&r2=1561191&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/StrokePath.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/StrokePath.java
Fri Jan 24 21:24:16 2014
@@ -27,7 +27,6 @@ import org.apache.pdfbox.util.PDFOperato
 import org.apache.pdfbox.util.operator.OperatorProcessor;
 
 import java.awt.BasicStroke;
-import java.awt.Graphics2D;
 import java.io.IOException;
 
 /**
@@ -46,6 +45,7 @@ public class StrokePath extends Operator
 
     /**
      * S stroke the path.
+     *
      * @param operator The operator that is being executed.
      * @param arguments List
      *
@@ -56,24 +56,42 @@ public class StrokePath extends Operator
         ///dwilson 3/19/07 refactor
         try
         {
-            PageDrawer drawer = (PageDrawer)context;
+            PageDrawer drawer = (PageDrawer) context;
     
-            float lineWidth = (float)context.getGraphicsState().getLineWidth();
+            float lineWidth = (float) context.getGraphicsState().getLineWidth();
             Matrix ctm = context.getGraphicsState().getCurrentTransformationMatrix();
-            if ( ctm != null && ctm.getXScale() > 0) 
+            if (ctm != null && ctm.getXScale() > 0)
             {
                 lineWidth = lineWidth * ctm.getXScale();
             }
             
-            BasicStroke stroke = (BasicStroke)drawer.getStroke();
+            if (lineWidth < 0.25)
+            {
+                lineWidth = 0.25f;
+            }
+
+            BasicStroke stroke = (BasicStroke) drawer.getStroke();
             if (stroke == null)
             {
-                drawer.setStroke( new BasicStroke( lineWidth ) );
+                drawer.setStroke(new BasicStroke(lineWidth));
             }
             else
             {
-                drawer.setStroke( new BasicStroke(lineWidth, stroke.getEndCap(), stroke.getLineJoin(),

-                        stroke.getMiterLimit(), stroke.getDashArray(), stroke.getDashPhase())
);
+                float phaseStart = stroke.getDashPhase();
+                float[] dashArray = stroke.getDashArray();
+                if (dashArray != null)
+                {
+                    if (ctm != null && ctm.getXScale() > 0)
+                    {
+                        for (int i = 0; i < dashArray.length; ++i)
+                        {
+                            dashArray[i] *= ctm.getXScale();
+                        }
+                    }
+                    phaseStart *= ctm.getXScale();
+                }
+                drawer.setStroke(new BasicStroke(lineWidth, stroke.getEndCap(), stroke.getLineJoin(),
+                        stroke.getMiterLimit(), dashArray, phaseStart));
             }
             drawer.strokePath();
         }



Mime
View raw message