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/06/22 18:40:02 UTC

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

Author: tilman
Date: Fri Jun 22 18:40:01 2018
New Revision: 1834152

URL: http://svn.apache.org/viewvc?rev=1834152&view=rev
Log:
PDFBOX-3353: support /CrossHairs

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

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDTextAppearanceHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDTextAppearanceHandler.java?rev=1834152&r1=1834151&r2=1834152&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDTextAppearanceHandler.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDTextAppearanceHandler.java Fri Jun 22 18:40:01 2018
@@ -57,6 +57,7 @@ public class PDTextAppearanceHandler ext
         SUPPORTED_NAMES.add(PDAnnotationText.NAME_STAR);
         SUPPORTED_NAMES.add(PDAnnotationText.NAME_RIGHT_ARROW);
         SUPPORTED_NAMES.add(PDAnnotationText.NAME_RIGHT_POINTER);
+        SUPPORTED_NAMES.add(PDAnnotationText.NAME_CROSS_HAIRS);
     }
 
     public PDTextAppearanceHandler(PDAnnotation annotation)
@@ -136,6 +137,9 @@ public class PDTextAppearanceHandler ext
                 case PDAnnotationText.NAME_RIGHT_POINTER:
                     drawRightPointer(annotation, contentStream);
                     break;
+                case PDAnnotationText.NAME_CROSS_HAIRS:
+                    drawCrossHairs(annotation, contentStream);
+                    break;
                 default:
                     break;
             }
@@ -281,6 +285,9 @@ public class PDTextAppearanceHandler ext
         contentStream.lineTo(small, min - large);
         contentStream.lineTo(min / 2 - small, min / 2);
         contentStream.closeAndFillAndStroke();
+        
+        // alternatively, this could also be drawn with Zapf Dingbats "a21"
+        // see DrawStar()
     }
 
     private void drawHelp(PDAnnotationText annotation, final PDAppearanceContentStream contentStream)
@@ -460,6 +467,28 @@ public class PDTextAppearanceHandler ext
         addPath(contentStream, path);
         contentStream.fillAndStroke();
     }
+
+    private void drawCrossHairs(PDAnnotationText annotation, final PDAppearanceContentStream contentStream)
+            throws IOException
+    {
+        PDRectangle bbox = adjustRectAndBBox(annotation, 20, 20);
+
+        float min = Math.min(bbox.getWidth(), bbox.getHeight());
+
+        contentStream.setMiterLimit(4);
+        contentStream.setLineJoinStyle(0);
+        contentStream.setLineCapStyle(0);
+        contentStream.setLineWidth(0.61f); // value from Adobe
+
+        contentStream.transform(Matrix.getScaleInstance(0.001f * min / 1.5f, 0.001f * min / 1.5f));
+        contentStream.transform(Matrix.getTranslateInstance(0, 50));
+
+        // we get the shape of a Zapf Dingbats right pointer (0x27A4) and use that one.
+        // Adobe uses a different font (which one?), or created the shape from scratch.
+        GeneralPath path = PDType1Font.SYMBOL.getPath("circleplus");
+        addPath(contentStream, path);
+        contentStream.fillAndStroke();
+    }
 
     private void drawRightArrow(PDAnnotationText annotation, final PDAppearanceContentStream contentStream)
             throws IOException