Author: tilman
Date: Thu Feb  6 19:08:58 2025
New Revision: 1923620

URL: http://svn.apache.org/viewvc?rev=1923620&view=rev
Log:
PDFBOX-5660: DRY refactoring

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

Modified: 
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDTextAppearanceHandler.java
URL: 
http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDTextAppearanceHandler.java?rev=1923620&r1=1923619&r2=1923620&view=diff
==============================================================================
--- 
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDTextAppearanceHandler.java
 (original)
+++ 
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDTextAppearanceHandler.java
 Thu Feb  6 19:08:58 2025
@@ -138,11 +138,11 @@ public class PDTextAppearanceHandler ext
             }
             else if (PDAnnotationText.NAME_STAR.equals(annotationTypeName))
             {
-                drawStar(annotation, contentStream);
+                drawZapf(annotation, contentStream, 19, 0, "a35"); // 0x2605
             }
             else if (PDAnnotationText.NAME_CHECK.equals(annotationTypeName))
             {
-                drawCheck(annotation, contentStream);
+                drawZapf(annotation, contentStream, 19, 50, "a20"); // 0x2714
             }
             else if 
(PDAnnotationText.NAME_RIGHT_ARROW.equals(annotationTypeName))
             {
@@ -150,7 +150,7 @@ public class PDTextAppearanceHandler ext
             }
             else if 
(PDAnnotationText.NAME_RIGHT_POINTER.equals(annotationTypeName))
             {
-                drawRightPointer(annotation, contentStream);
+                drawZapf(annotation, contentStream, 17, 50, "a174"); // 0x27A4
             }
             else if 
(PDAnnotationText.NAME_CROSS_HAIRS.equals(annotationTypeName))
             {
@@ -324,7 +324,6 @@ public class PDTextAppearanceHandler ext
         contentStream.closeAndFillAndStroke();
         
         // alternatively, this could also be drawn with Zapf Dingbats "a21"
-        // see DrawStar()
     }
 
     private void drawHelp(PDAnnotationText annotation, final 
PDAppearanceContentStream contentStream)
@@ -437,84 +436,6 @@ public class PDTextAppearanceHandler ext
         contentStream.fill();
     }
 
-    private void drawStar(PDAnnotationText annotation, final 
PDAppearanceContentStream contentStream)
-            throws IOException
-    {
-        PDRectangle bbox = adjustRectAndBBox(annotation, 20, 19);
-
-        float min = Math.min(bbox.getWidth(), bbox.getHeight());
-
-        contentStream.setMiterLimit(4);
-        contentStream.setLineJoinStyle(1);
-        contentStream.setLineCapStyle(0);
-        contentStream.setLineWidth(0.59f); // value from Adobe
-
-        List<Number> fontMatrix = 
PDType1Font.ZAPF_DINGBATS.getFontBoxFont().getFontMatrix();
-        float xScale = (Float) fontMatrix.get(0);
-        float yScale = (Float) fontMatrix.get(3);
-        contentStream.transform(Matrix.getScaleInstance(xScale * min / 0.8f, 
yScale * min / 0.8f));
-
-        // we get the shape of a Zapf Dingbats star (0x2605) and use that one.
-        // Adobe uses a different font (which one?), or created the shape from 
scratch.
-        GeneralPath path = PDType1Font.ZAPF_DINGBATS.getPath("a35");
-        addPath(contentStream, path);
-        contentStream.fillAndStroke();
-    }
-
-    //TODO this is mostly identical to drawStar, except for scale, translation 
and symbol
-    // maybe use a table with all values and draw from there
-    // this could also optionally use outer circle
-    private void drawCheck(PDAnnotationText annotation, final 
PDAppearanceContentStream contentStream)
-            throws IOException
-    {
-        PDRectangle bbox = adjustRectAndBBox(annotation, 20, 19);
-
-        float min = Math.min(bbox.getWidth(), bbox.getHeight());
-
-        contentStream.setMiterLimit(4);
-        contentStream.setLineJoinStyle(1);
-        contentStream.setLineCapStyle(0);
-        contentStream.setLineWidth(0.59f); // value from Adobe
-
-        List<Number> fontMatrix = 
PDType1Font.ZAPF_DINGBATS.getFontBoxFont().getFontMatrix();
-        float xScale = (Float) fontMatrix.get(0);
-        float yScale = (Float) fontMatrix.get(3);
-        contentStream.transform(Matrix.getScaleInstance(xScale * min / 0.8f, 
yScale * min / 0.8f));
-        contentStream.transform(Matrix.getTranslateInstance(0, 50));
-
-        // we get the shape of a Zapf Dingbats check (0x2714) and use that one.
-        // Adobe uses a different font (which one?), or created the shape from 
scratch.
-        GeneralPath path = PDType1Font.ZAPF_DINGBATS.getPath("a20");
-        addPath(contentStream, path);
-        contentStream.fillAndStroke();
-    }
-
-    //TODO this is mostly identical to drawStar, except for scale, translation 
and symbol
-    private void drawRightPointer(PDAnnotationText annotation, final 
PDAppearanceContentStream contentStream)
-            throws IOException
-    {
-        PDRectangle bbox = adjustRectAndBBox(annotation, 20, 17);
-
-        float min = Math.min(bbox.getWidth(), bbox.getHeight());
-
-        contentStream.setMiterLimit(4);
-        contentStream.setLineJoinStyle(1);
-        contentStream.setLineCapStyle(0);
-        contentStream.setLineWidth(0.59f); // value from Adobe
-
-        List<Number> fontMatrix = 
PDType1Font.ZAPF_DINGBATS.getFontBoxFont().getFontMatrix();
-        float xScale = (Float) fontMatrix.get(0);
-        float yScale = (Float) fontMatrix.get(3);
-        contentStream.transform(Matrix.getScaleInstance(xScale * min / 0.8f, 
yScale * min / 0.8f));
-        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.ZAPF_DINGBATS.getPath("a174");
-        addPath(contentStream, path);
-        contentStream.fillAndStroke();
-    }
-
     private void drawCrossHairs(PDAnnotationText annotation, final 
PDAppearanceContentStream contentStream)
             throws IOException
     {
@@ -712,7 +633,32 @@ public class PDTextAppearanceHandler ext
         contentStream.curveTo(3441, 4847, 3253, 4658, 3253, 4425);
         contentStream.fillAndStroke();
     }
-    
+
+    private void drawZapf(PDAnnotationText annotation, final 
PDAppearanceContentStream contentStream,
+            int by, int ty, String glyphName) throws IOException
+    {
+        PDRectangle bbox = adjustRectAndBBox(annotation, 20, by);
+
+        float min = Math.min(bbox.getWidth(), bbox.getHeight());
+
+        contentStream.setMiterLimit(4);
+        contentStream.setLineJoinStyle(1);
+        contentStream.setLineCapStyle(0);
+        contentStream.setLineWidth(0.59f); // value from Adobe
+
+        List<Number> fontMatrix = 
PDType1Font.ZAPF_DINGBATS.getFontBoxFont().getFontMatrix();
+        float xScale = (Float) fontMatrix.get(0);
+        float yScale = (Float) fontMatrix.get(3);
+        contentStream.transform(Matrix.getScaleInstance(xScale * min / 0.8f, 
yScale * min / 0.8f));
+        contentStream.transform(Matrix.getTranslateInstance(0, ty));
+
+        // we get the shape of a Zapf Dingbats glyph and use that one.
+        // Adobe uses a different font (which one?), or created the shape from 
scratch.
+        GeneralPath path = PDType1Font.ZAPF_DINGBATS.getPath(glyphName);
+        addPath(contentStream, path);
+        contentStream.fillAndStroke();
+    }
+
     private void addPath(final PDAppearanceContentStream contentStream, 
GeneralPath path) throws IOException
     {
         double curX = 0;


Reply via email to