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/08/29 06:52:06 UTC

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

Author: tilman
Date: Wed Aug 29 06:52:06 2018
New Revision: 1839546

URL: http://svn.apache.org/viewvc?rev=1839546&view=rev
Log:
PDFBOX-3353: create /RD entry and modify rect, bbox and matrix like Adobe

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

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCaretAppearanceHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCaretAppearanceHandler.java?rev=1839546&r1=1839545&r2=1839546&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCaretAppearanceHandler.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCaretAppearanceHandler.java Wed Aug 29 06:52:06 2018
@@ -18,10 +18,12 @@ package org.apache.pdfbox.pdmodel.intera
 import java.io.IOException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationCaret;
 import org.apache.pdfbox.pdmodel.PDAppearanceContentStream;
+import org.apache.pdfbox.util.Matrix;
 
 /**
  * Handler to generate the caret annotations appearance.
@@ -48,13 +50,6 @@ public class PDCaretAppearanceHandler ex
     @Override
     public void generateNormalAppearance()
     {
-        //TODO Adobe creates the /RD entry with a number that is decided by dividing the height by 10,
-        // with a maximum result of 5. That number is then substracted from the /BBox
-        // values and used in the translation values in the matrix and also for the line width
-        // (not used here because it has no effect).
-        // Currently, the rendering difference between our content stream and the one from Adobe
-        // is minimal, about one pixel line at the bottom.
-
         PDAnnotationCaret annotation = (PDAnnotationCaret) getAnnotation();
         try (PDAppearanceContentStream contentStream = getNormalAppearanceAsContentStream())
         {
@@ -65,6 +60,24 @@ public class PDCaretAppearanceHandler ex
 
             PDRectangle rect = getRectangle();
             PDRectangle bbox = new PDRectangle(rect.getWidth(), rect.getHeight());
+            if (!annotation.getCOSObject().containsKey(COSName.RD))
+            {
+                // Adobe creates the /RD entry with a number that is decided
+                // by dividing the height by 10, with a maximum result of 5.
+                // That number is then used to enlarge the bbox and the rectangle and added to the
+                // translation values in the matrix and also used for the line width
+                // (not here because it has no effect, see comment near fill() ).
+                // The curves are based on the original rectangle.
+                float rd = Math.min(rect.getHeight() / 10, 5);
+                annotation.setRectDifferences(rd);
+                bbox = new PDRectangle(-rd, -rd, rect.getWidth() + 2 * rd, rect.getHeight() + 2 * rd);
+                Matrix matrix = annotation.getNormalAppearanceStream().getMatrix();
+                matrix.transformPoint(rd, rd);
+                annotation.getNormalAppearanceStream().setMatrix(matrix.createAffineTransform());
+                PDRectangle rect2 = new PDRectangle(rect.getLowerLeftX() - rd, rect.getLowerLeftY() - rd,
+                                                    rect.getWidth() + 2 * rd, rect.getHeight() + 2 * rd);
+                annotation.setRectangle(rect2);
+            }
             annotation.getNormalAppearanceStream().setBBox(bbox);
 
             float halfX = rect.getWidth() / 2;