pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msahy...@apache.org
Subject svn commit: r1745288 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation: PDAppearanceContentStream.java handlers/PDAppearanceHandler.java handlers/PDSquareAppearanceHandler.java
Date Mon, 23 May 2016 22:38:16 GMT
Author: msahyoun
Date: Mon May 23 22:38:16 2016
New Revision: 1745288

URL: http://svn.apache.org/viewvc?rev=1745288&view=rev
Log:
PDFBOX-3353: support dashed lines; improve path closing for 0 line width

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceContentStream.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDAppearanceHandler.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSquareAppearanceHandler.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceContentStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceContentStream.java?rev=1745288&r1=1745287&r2=1745288&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceContentStream.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceContentStream.java
Mon May 23 22:38:16 2016
@@ -23,6 +23,7 @@ import java.text.NumberFormat;
 import java.util.Locale;
 
 import org.apache.pdfbox.contentstream.PDAbstractContentStream;
+import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream;
 
@@ -106,7 +107,8 @@ public final class PDAppearanceContentSt
     /**
      * Set the stroking color.
      * 
-     * <p>The command is only emitted if the color is not null and the number of 
+     * <p>
+     * The command is only emitted if the color is not null and the number of
      * components is gt 0.
      * 
      * @see PDAbstractContentStream#setStrokingColor(PDColor)
@@ -158,7 +160,8 @@ public final class PDAppearanceContentSt
     /**
      * Set the non stroking color.
      * 
-     * <p>The command is only emitted if the color is not null and the number of 
+     * <p>
+     * The command is only emitted if the color is not null and the number of
      * components is gt 0.
      * 
      * @see PDAbstractContentStream#setNonStrokingColor(PDColor)
@@ -207,6 +210,20 @@ public final class PDAppearanceContentSt
         }
     }
 
+    public void setBorderLine(float lineWidth, PDBorderStyleDictionary bs) throws IOException
+    {
+        // Important:
+        // can't use PDBorderStyleDictionary.getDashStyle() as
+        // this will return a default dash style if non is existing
+        if (bs != null && (bs.getCOSObject().containsKey(COSName.D)))
+        {
+            setLineDashPattern(bs.getDashStyle().getDashArray(), 0);
+        } else
+        {
+            setLineWidthOnDemand(lineWidth);
+        }
+    }
+
     /**
      * Sets the line width. The command is only emitted if the lineWidth is
      * different to 1.
@@ -223,4 +240,31 @@ public final class PDAppearanceContentSt
             setLineWidth(lineWidth);
         }
     }
+    
+    /**
+     * Close a path.
+     * 
+     * <p>Dependent on the lineWidth and whether or not there is a background
+     * to be generated there are different commands to be used for closing a path.
+     * 
+     * @param lineWidth the line width of the path.
+     * @param hasBackground shall there be a background color.
+     * @throws IOException if an IO error occurs while writing to the stream.
+     */
+    public void closePath(float lineWidth, boolean hasBackground) throws IOException
+    {
+        if (lineWidth < 1e-6) {
+            writeOperator("n");
+        }
+        else
+        {
+            if (!hasBackground)
+            {
+                stroke();
+            } else
+            {
+                fillAndStroke();
+            }
+        }
+    }
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDAppearanceHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDAppearanceHandler.java?rev=1745288&r1=1745287&r2=1745288&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDAppearanceHandler.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDAppearanceHandler.java
Mon May 23 22:38:16 2016
@@ -21,6 +21,7 @@ import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationSquareCircle;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceDictionary;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceEntry;
 
@@ -178,6 +179,18 @@ public abstract class PDAppearanceHandle
 
         return appearanceEntry;
     }
+    
+    /**
+     * Set the differences rectangle.
+     */
+    void setRectDifference(float lineWidth)
+    {
+        if (annotation instanceof PDAnnotationSquareCircle && lineWidth > 0)
+        {
+            PDRectangle differences = new PDRectangle(lineWidth/2, lineWidth/2,0,0);
+            ((PDAnnotationSquareCircle) annotation).setRectDifference(differences);
+        }
+    }
 
     /**
      * Get a padded rectangle.

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSquareAppearanceHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSquareAppearanceHandler.java?rev=1745288&r1=1745287&r2=1745288&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSquareAppearanceHandler.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSquareAppearanceHandler.java
Mon May 23 22:38:16 2016
@@ -59,21 +59,20 @@ public class PDSquareAppearanceHandler e
             boolean hasBackground = contentStream
                     .setNonStrokingColorOnDemand(((PDAnnotationSquareCircle) getAnnotation()).getInteriorColor());
 
-            contentStream.setLineWidthOnDemand(lineWidth);
+            contentStream.setBorderLine(lineWidth, ((PDAnnotationSquareCircle) getAnnotation()).getBorderStyle());
+            
+            // the differences rectangle
+            // TODO: this only works for border effect solid. Cloudy needs a different approach.
+            setRectDifference(lineWidth);
             
             // Acrobat applies a padding to each side of the bbox so the line is completely
within
             // the bbox.
-            PDRectangle borderEdge = getPaddedRectangle(bbox,lineWidth);
+            PDRectangle borderEdge = getPaddedRectangle(bbox,lineWidth/2);
             contentStream.addRect(borderEdge.getLowerLeftX() , borderEdge.getLowerLeftY(),
                     borderEdge.getWidth(), borderEdge.getHeight());
 
-            if (!hasBackground)
-            {
-                contentStream.stroke();
-            } else
-            {
-                contentStream.fillAndStroke();
-            }
+            contentStream.closePath(lineWidth, hasBackground);
+
             contentStream.close();
         } catch (IOException e)
         {
@@ -108,7 +107,7 @@ public class PDSquareAppearanceHandler e
     // so we will leave that to be implemented by individual handlers.
     // If at the end all annotations support the BS entry this can be handled
     // here and removed from the individual handlers.
-    public float getLineWidth()
+    float getLineWidth()
     {
         PDAnnotationSquareCircle annotation = (PDAnnotationSquareCircle) getAnnotation();
 



Mime
View raw message