pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1832878 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolylineAppearanceHandler.java
Date Mon, 04 Jun 2018 18:42:09 GMT
Author: tilman
Date: Mon Jun  4 18:42:09 2018
New Revision: 1832878

URL: http://svn.apache.org/viewvc?rev=1832878&view=rev
Log:
PDFBOX-3353: don't rotate non angled styles

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolylineAppearanceHandler.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolylineAppearanceHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolylineAppearanceHandler.java?rev=1832878&r1=1832877&r2=1832878&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolylineAppearanceHandler.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolylineAppearanceHandler.java
Mon Jun  4 18:42:09 2018
@@ -160,8 +160,15 @@ public class PDPolylineAppearanceHandler
                 float x1 = pathsArray[0];
                 float y1 = pathsArray[1];
                 cs.saveGraphicsState();
-                double angle = Math.atan2(y2 - y1, x2 - x1);
-                cs.transform(Matrix.getRotateInstance(angle, x1, y1));
+                if (ANGLED_STYLES.contains(annotation.getStartPointEndingStyle()))
+                {
+                    double angle = Math.atan2(y2 - y1, x2 - x1);
+                    cs.transform(Matrix.getRotateInstance(angle, x1, y1));
+                }
+                else
+                {
+                    cs.transform(Matrix.getTranslateInstance(x1, y1));
+                }
                 drawStyle(annotation.getStartPointEndingStyle(), cs, 0, 0, ab.width, hasStroke,
hasBackground);
                 cs.restoreGraphicsState();
             }
@@ -174,10 +181,24 @@ public class PDPolylineAppearanceHandler
                 float x2 = pathsArray[pathsArray.length - 2];
                 float y2 = pathsArray[pathsArray.length - 1];
                 // save / restore not needed because it's the last one
-                double angle = Math.atan2(y2 - y1, x2 - x1);
-                cs.transform(Matrix.getRotateInstance(angle, x1, y1));
-                float lineLength = (float) Math.sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1)
* (y2 - y1)));
-                drawStyle(annotation.getEndPointEndingStyle(), cs, lineLength, 0, ab.width,
hasStroke, hasBackground);
+                if (ANGLED_STYLES.contains(annotation.getEndPointEndingStyle()))
+                {
+                    // we're transforming to (x1,y1) instead of to (x2,y2) position
+                    // because drawStyle needs to be aware
+                    // by the non zero x parameter that this is "right ending" side
+                    // of a line. This is important for arrows styles.
+                    //TODO this is not really good and should be improved,
+                    // maybe by an additional parameter for drawStyle?
+                    double angle = Math.atan2(y2 - y1, x2 - x1);
+                    cs.transform(Matrix.getRotateInstance(angle, x1, y1));
+                    float lineLength = (float) Math.sqrt(((x2 - x1) * (x2 - x1)) + ((y2 -
y1) * (y2 - y1)));
+                    drawStyle(annotation.getEndPointEndingStyle(), cs, lineLength, 0, ab.width,
hasStroke, hasBackground);
+                }
+                else
+                {
+                    cs.transform(Matrix.getTranslateInstance(x2, y2));
+                    drawStyle(annotation.getEndPointEndingStyle(), cs, 0, 0, ab.width, hasStroke,
hasBackground);
+                }
             }
         }
         catch (IOException ex)



Mime
View raw message