pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1821940 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolygonAppearanceHandler.java
Date Mon, 22 Jan 2018 20:17:05 GMT
Author: tilman
Date: Mon Jan 22 20:17:05 2018
New Revision: 1821940

URL: http://svn.apache.org/viewvc?rev=1821940&view=rev
Log:
PDFBOX-3353: adjust rectangle

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

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolygonAppearanceHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolygonAppearanceHandler.java?rev=1821940&r1=1821939&r2=1821940&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolygonAppearanceHandler.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolygonAppearanceHandler.java
Mon Jan 22 20:17:05 2018
@@ -25,6 +25,7 @@ import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSNumber;
+import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationPolygon;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceContentStream;
@@ -54,10 +55,40 @@ public class PDPolygonAppearanceHandler
     @Override
     public void generateNormalAppearance()
     {
+        PDAnnotationPolygon annotation = (PDAnnotationPolygon) getAnnotation();
         float lineWidth = getLineWidth();
+        PDRectangle rect = annotation.getRectangle();
+
+        // Adjust rectangle even if not empty
+        // CTAN-example-Annotations.pdf p2
+        //TODO in a class structure this should be overridable
+        float minX = Float.MAX_VALUE;
+        float minY = Float.MAX_VALUE;
+        float maxX = Float.MIN_VALUE;
+        float maxY = Float.MIN_VALUE;
+        float[] pathsArray = annotation.getVertices();
+        if (pathsArray != null)
+        {
+            //TODO this adjustment is only for PDF 1.*. 
+            //     Similar code should be done for PDF 2.0 (see "Path")
+            for (int i = 0; i < pathsArray.length / 2; ++i)
+            {
+                float x = pathsArray[i * 2];
+                float y = pathsArray[i * 2 + 1];
+                minX = Math.min(minX, x);
+                minY = Math.min(minY, y);
+                maxX = Math.max(maxX, x);
+                maxY = Math.max(maxY, y);
+            }
+            rect.setLowerLeftX(Math.min(minX - lineWidth / 2, rect.getLowerLeftX()));
+            rect.setLowerLeftY(Math.min(minY - lineWidth / 2, rect.getLowerLeftY()));
+            rect.setUpperRightX(Math.max(maxX + lineWidth, rect.getUpperRightX()));
+            rect.setUpperRightY(Math.max(maxY + lineWidth, rect.getUpperRightY()));
+            annotation.setRectangle(rect);
+        }
+
         try
         {
-            PDAnnotationPolygon annotation = (PDAnnotationPolygon) getAnnotation();
             try (PDAppearanceContentStream contentStream = getNormalAppearanceAsContentStream())
             {
                 boolean hasStroke = contentStream.setStrokingColorOnDemand(getColor());



Mime
View raw message