Author: tilman
Date: Sat Feb  3 05:17:29 2018
New Revision: 1823014

URL: http://svn.apache.org/viewvc?rev=1823014&view=rev
Log:
PDFBOX-4068: set up pattern content stream class; update pattern example to use 
new content stream

Added:
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPatternContentStream.java
      - copied, changed from r1823003, 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDFormContentStream.java
Modified:
    
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreatePatternsPDF.java

Modified: 
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreatePatternsPDF.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreatePatternsPDF.java?rev=1823014&r1=1823013&r2=1823014&view=diff
==============================================================================
--- 
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreatePatternsPDF.java
 (original)
+++ 
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreatePatternsPDF.java
 Sat Feb  3 05:17:29 2018
@@ -16,12 +16,13 @@
 
 package org.apache.pdfbox.examples.pdmodel;
 
+import java.awt.Color;
 import java.io.IOException;
-import java.io.OutputStream;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.PDPageContentStream;
+import org.apache.pdfbox.pdmodel.PDPatternContentStream;
 import org.apache.pdfbox.pdmodel.PDResources;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
@@ -29,7 +30,6 @@ import org.apache.pdfbox.pdmodel.graphic
 import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
 import org.apache.pdfbox.pdmodel.graphics.color.PDPattern;
 import org.apache.pdfbox.pdmodel.graphics.pattern.PDTilingPattern;
-import org.apache.pdfbox.util.Charsets;
 
 /**
  * This is an example of how to create a page that uses patterns to paint 
areas.
@@ -65,14 +65,17 @@ public final class CreatePatternsPDF
                 tilingPattern1.setYStep(10);
                 
                 COSName patternName1 = page.getResources().add(tilingPattern1);
-                //TODO
-                // there's no way to create something like a 
PDPageContentStream,
-                // so we'll do it the hard way
-
-                try (OutputStream os1 = 
tilingPattern1.getContentStream().createOutputStream())
+                try (PDPatternContentStream cs1 = new 
PDPatternContentStream(tilingPattern1))
                 {
                     // Set color, draw diagonal line + 2 more diagonals so 
that corners look good
-                    os1.write("1 0 0 RG 0 0 m 10 10 l -1 9 m 1 11 l 9 -1 m 11 
1 l s".getBytes(Charsets.US_ASCII));
+                    cs1.setStrokingColor(Color.red);
+                    cs1.moveTo(0, 0);
+                    cs1.lineTo(10, 10);
+                    cs1.moveTo(-1, 9);
+                    cs1.lineTo(1, 11);
+                    cs1.moveTo(9, -1);
+                    cs1.lineTo(11, 1);
+                    cs1.stroke();
                 }
                 
                 PDColor patternColor1 = new PDColor(patternName1, patternCS1);
@@ -90,13 +93,16 @@ public final class CreatePatternsPDF
                 tilingPattern2.setYStep(10);
                 
                 COSName patternName2 = page.getResources().add(tilingPattern2);
-                
-                try (OutputStream os2 = 
tilingPattern2.getContentStream().createOutputStream())
+                try (PDPatternContentStream cs2 = new 
PDPatternContentStream(tilingPattern2))
                 {
                     // draw a cross
-                    os2.write("0 5 m 10 5 l 5 0 m 5 10 l 
s".getBytes(Charsets.US_ASCII));
+                    cs2.moveTo(0, 5);
+                    cs2.lineTo(10, 5);
+                    cs2.moveTo(5, 0);
+                    cs2.lineTo(5, 10);
+                    cs2.stroke();
                 }
-                
+
                 // Uncolored pattern colorspace needs to know the colorspace
                 // for the color values that will be passed when painting the 
fill
                 PDColorSpace patternCS2 = new PDPattern(null, 
PDDeviceRGB.INSTANCE);

Copied: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPatternContentStream.java
 (from r1823003, 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDFormContentStream.java)
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPatternContentStream.java?p2=pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPatternContentStream.java&p1=pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDFormContentStream.java&r1=1823003&r2=1823014&rev=1823014&view=diff
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDFormContentStream.java
 (original)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPatternContentStream.java
 Sat Feb  3 05:17:29 2018
@@ -17,17 +17,17 @@ package org.apache.pdfbox.pdmodel;
 
 import java.io.IOException;
 import org.apache.pdfbox.contentstream.PDAbstractContentStream;
-import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
+import org.apache.pdfbox.pdmodel.graphics.pattern.PDTilingPattern;
 
 /**
  *
  * @author Tilman Hausherr
  */
-public class PDFormContentStream extends PDAbstractContentStream
+public class PDPatternContentStream extends PDAbstractContentStream
 {
-    public PDFormContentStream(PDFormXObject form) throws IOException
+    public PDPatternContentStream(PDTilingPattern pattern) throws IOException
     {
-        super(form.getStream().createOutputStream());
-        setResources(form.getResources());
+        super(pattern.getContentStream().createOutputStream());
+        setResources(pattern.getResources());
     }
 }


Reply via email to