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/28 11:02:25 UTC

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

Author: tilman
Date: Sun Jan 28 11:02:24 2018
New Revision: 1822453

URL: http://svn.apache.org/viewvc?rev=1822453&view=rev
Log:
PDFBOX-3353: support line annotation caption offset /CO

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=1822453&r1=1822452&r2=1822453&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 Sun Jan 28 11:02:24 2018
@@ -141,6 +141,7 @@ public class PDLineAppearanceHandler ext
                 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)));
+                //TODO rename getCaption() to isCaption() or hasCaption()
                 if (annotation.getCaption() && !contents.isEmpty())
                 {
                     PDType1Font font = PDType1Font.HELVETICA;
@@ -206,6 +207,10 @@ public class PDLineAppearanceHandler ext
                     }
                     cs.drawShape(ab.width, hasStroke, false);
 
+                    // /CO entry (caption offset)
+                    float captionHorizontalOffset = annotation.getCaptionHorizontalOffset();
+                    float captionVerticalOffset = annotation.getCaptionVerticalOffset();
+
                     // check contentLength so we don't show if there was trouble before
                     if (contentLength > 0)
                     {
@@ -213,10 +218,19 @@ public class PDLineAppearanceHandler ext
 
                         cs.beginText();
                         cs.setFont(font, FONT_SIZE);
-                        cs.setTextMatrix(Matrix.getTranslateInstance(xOffset, y + yOffset));
+                        cs.setTextMatrix(Matrix.getTranslateInstance(
+                                xOffset + captionHorizontalOffset, 
+                                y + yOffset + captionVerticalOffset));
                         cs.showText(annotation.getContents());
                         cs.endText();
                     }
+
+                    if (captionVerticalOffset != 0)
+                    {
+                        // Adobe paints vertical bar to the caption
+                        cs.moveTo(0 + lineLength / 2, y);
+                        cs.lineTo(0 + lineLength / 2, y + captionVerticalOffset);
+                    }
                 }
                 else
                 {
@@ -238,8 +252,8 @@ public class PDLineAppearanceHandler ext
                     {
                         cs.lineTo(lineLength, y);
                     }
-                    cs.drawShape(ab.width, hasStroke, false);
                 }
+                cs.drawShape(ab.width, hasStroke, false);
 
                 // do this here and not before showing the text, or the text would appear in the
                 // interior color
@@ -247,7 +261,7 @@ public class PDLineAppearanceHandler ext
 
                 // 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
+                // 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()) ||