You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2018/01/27 14:21:01 UTC

svn commit: r1822410 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLineAppearanceHandler.java

Author: tilman
Date: Sat Jan 27 14:21:01 2018
New Revision: 1822410

URL: http://svn.apache.org/viewvc?rev=1822410&view=rev
Log:
PDFBOX-3353: support ClosedArrow line style

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

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLineAppearanceHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLineAppearanceHandler.java?rev=1822410&r1=1822409&r2=1822410&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLineAppearanceHandler.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLineAppearanceHandler.java Sat Jan 27 14:21:01 2018
@@ -93,16 +93,15 @@ public class PDLineAppearanceHandler ext
 
         // add/substract with, font height, and arrows
         //TODO also consider other stuff at line ends
-        // arrow length is 10 * width at about 30° => 5 * width should be enough
+        // arrow length is 10 * width at about 30° => 6 * width seems to be enough
         // but need to consider ll, lle and llo too
-        rect.setLowerLeftX(Math.min(minX - Math.max(ab.width * 5, Math.abs(llo+ll+lle)), rect.getLowerLeftX()));
-        rect.setLowerLeftY(Math.min(minY - Math.max(ab.width * 5, Math.abs(llo+ll+lle)), rect.getLowerLeftY()));
-        rect.setUpperRightX(Math.max(maxX + Math.max(ab.width * 5, Math.abs(llo+ll+lle)), rect.getUpperRightX()));
-        rect.setUpperRightY(Math.max(maxY + Math.max(ab.width * 5, Math.abs(llo+ll+lle)), rect.getUpperRightY()));
+        rect.setLowerLeftX(Math.min(minX - Math.max(ab.width * 6, Math.abs(llo+ll+lle)), rect.getLowerLeftX()));
+        rect.setLowerLeftY(Math.min(minY - Math.max(ab.width * 6, Math.abs(llo+ll+lle)), rect.getLowerLeftY()));
+        rect.setUpperRightX(Math.max(maxX + Math.max(ab.width * 6, Math.abs(llo+ll+lle)), rect.getUpperRightX()));
+        rect.setUpperRightY(Math.max(maxY + Math.max(ab.width * 6, Math.abs(llo+ll+lle)), rect.getUpperRightY()));
 
         annotation.setRectangle(rect);
 
-
         try
         {
             try (PDAppearanceContentStream cs = getNormalAppearanceAsContentStream())
@@ -173,7 +172,8 @@ public class PDLineAppearanceHandler ext
 
                     // draw the line horizontally, using the rotation CTM to get to correct final position
                     // that's the easiest way to calculate the positions for the line before and after inline caption
-                    if (PDAnnotationLine.LE_OPEN_ARROW.equals(annotation.getStartPointEndingStyle()))
+                    if (PDAnnotationLine.LE_OPEN_ARROW.equals(annotation.getStartPointEndingStyle()) ||
+                        PDAnnotationLine.LE_CLOSED_ARROW.equals(annotation.getStartPointEndingStyle()))
                     {
                         cs.moveTo(ab.width, y);
                     }
@@ -195,7 +195,8 @@ public class PDLineAppearanceHandler ext
                         cs.lineTo(xOffset - ab.width, y);
                         cs.moveTo(lineLength - xOffset + ab.width, y);
                     }
-                    if (PDAnnotationLine.LE_OPEN_ARROW.equals(annotation.getEndPointEndingStyle()))
+                    if (PDAnnotationLine.LE_OPEN_ARROW.equals(annotation.getEndPointEndingStyle()) ||
+                        PDAnnotationLine.LE_CLOSED_ARROW.equals(annotation.getEndPointEndingStyle()))
                     {
                         cs.lineTo(lineLength - ab.width, y);
                     }
@@ -219,7 +220,8 @@ public class PDLineAppearanceHandler ext
                 }
                 else
                 {
-                    if (PDAnnotationLine.LE_OPEN_ARROW.equals(annotation.getStartPointEndingStyle()))
+                    if (PDAnnotationLine.LE_OPEN_ARROW.equals(annotation.getStartPointEndingStyle()) ||
+                        PDAnnotationLine.LE_CLOSED_ARROW.equals(annotation.getStartPointEndingStyle()))
                     {
                         cs.moveTo(ab.width, y);
                     }
@@ -227,7 +229,8 @@ public class PDLineAppearanceHandler ext
                     {
                         cs.moveTo(0, y);
                     }
-                    if (PDAnnotationLine.LE_OPEN_ARROW.equals(annotation.getEndPointEndingStyle()))
+                    if (PDAnnotationLine.LE_OPEN_ARROW.equals(annotation.getEndPointEndingStyle()) ||
+                        PDAnnotationLine.LE_CLOSED_ARROW.equals(annotation.getEndPointEndingStyle()))
                     {
                         cs.lineTo(lineLength - ab.width, y);
                     }
@@ -238,24 +241,47 @@ public class PDLineAppearanceHandler ext
                     cs.drawShape(ab.width, hasStroke, false);
                 }
 
+                // do this here and not before showing the text, or the text would appear in the
+                // interior color
+                boolean hasBackground = cs.setNonStrokingColorOnDemand(annotation.getInteriorColor());
+
                 // there can be many, many more styles...
                 //TODO numbers for arrow size are arbitrary and likely wrong
                 // current strategy: angle 30°, arrow arm length = 10 * line width
                 // cos(angle) = x position
                 // sin(angle) = y position
-                if (PDAnnotationLine.LE_OPEN_ARROW.equals(annotation.getStartPointEndingStyle()))
+                if (PDAnnotationLine.LE_OPEN_ARROW.equals(annotation.getStartPointEndingStyle()) ||
+                    PDAnnotationLine.LE_CLOSED_ARROW.equals(annotation.getStartPointEndingStyle()))
                 {
                     cs.moveTo((float) (Math.cos(ARROW_ANGLE) * ab.width * 10), y + (float) (Math.sin(ARROW_ANGLE) * ab.width * 10));
                     cs.lineTo(ab.width, y);
                     cs.lineTo((float) (Math.cos(ARROW_ANGLE) * ab.width * 10), y - (float) (Math.sin(ARROW_ANGLE) * ab.width * 10));
-                    cs.drawShape(ab.width, hasStroke, false);
+                    if (PDAnnotationLine.LE_CLOSED_ARROW.equals(annotation.getEndPointEndingStyle()))
+                    {
+                        cs.closePath();
+                        cs.drawShape(ab.width, hasStroke, hasBackground);
+                    }
+                    else
+                    {
+                        // need to do this separately, because sometimes /IC is set anyway
+                        cs.drawShape(ab.width, hasStroke, false);
+                    }
                 }
-                if (PDAnnotationLine.LE_OPEN_ARROW.equals(annotation.getEndPointEndingStyle()))
+                if (PDAnnotationLine.LE_OPEN_ARROW.equals(annotation.getEndPointEndingStyle())
+                        || PDAnnotationLine.LE_CLOSED_ARROW.equals(annotation.getEndPointEndingStyle()))
                 {
                     cs.moveTo((float) (lineLength - Math.cos(ARROW_ANGLE) * ab.width * 10), y + (float) (Math.sin(ARROW_ANGLE) * ab.width * 10));
                     cs.lineTo(lineLength - ab.width, y);
                     cs.lineTo((float) (lineLength - Math.cos(ARROW_ANGLE) * ab.width * 10), y - (float) (Math.sin(ARROW_ANGLE) * ab.width * 10));
-                    cs.drawShape(ab.width, hasStroke, false);
+                    if (PDAnnotationLine.LE_CLOSED_ARROW.equals(annotation.getEndPointEndingStyle()))
+                    {
+                        cs.closePath();
+                        cs.drawShape(ab.width, hasStroke, hasBackground);
+                    }
+                    else
+                    {
+                        cs.drawShape(ab.width, hasStroke, false);
+                    }
                 }
             }
         }