pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1857809 - in /pdfbox/trunk/pdfbox/src: main/java/org/apache/pdfbox/contentstream/operator/ main/java/org/apache/pdfbox/pdfparser/ main/java/org/apache/pdfbox/pdfwriter/ main/java/org/apache/pdfbox/pdmodel/ test/java/org/apache/pdfbox/pdfpa...
Date Fri, 19 Apr 2019 13:36:41 GMT
Author: lehmi
Date: Fri Apr 19 13:36:41 2019
New Revision: 1857809

URL: http://svn.apache.org/viewvc?rev=1857809&view=rev
Log:
PDFBOX-4458: use new operator name constants

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/Operator.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/OperatorName.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/ContentStreamWriter.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAppearanceContentStream.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/PDFStreamParserTest.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/Operator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/Operator.java?rev=1857809&r1=1857808&r2=1857809&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/Operator.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/Operator.java
Fri Apr 19 13:36:41 2019
@@ -60,7 +60,8 @@ public final class Operator
     public static Operator getOperator( String operator )
     {
         Operator operation;
-        if (operator.equals("ID") || OperatorName.BEGIN_INLINE_IMAGE.equals(operator))
+        if (operator.equals(OperatorName.BEGIN_INLINE_IMAGE_DATA)
+                || OperatorName.BEGIN_INLINE_IMAGE.equals(operator))
         {
             //we can't cache the ID operators.
             operation = new Operator( operator );

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/OperatorName.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/OperatorName.java?rev=1857809&r1=1857808&r2=1857809&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/OperatorName.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/OperatorName.java
Fri Apr 19 13:36:41 2019
@@ -58,6 +58,8 @@ public final class OperatorName
     // graphics
     public static final String APPEND_RECT = "re";
     public static final String BEGIN_INLINE_IMAGE = "BI";
+    public static final String BEGIN_INLINE_IMAGE_DATA = "ID";
+    public static final String END_INLINE_IMAGE = "EI";
     public static final String CLIP_EVEN_ODD = "W*";
     public static final String CLIP_NON_ZERO = "W";
     public static final String CLOSE_AND_STROKE = "s";

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java?rev=1857809&r1=1857808&r2=1857809&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java Fri
Apr 19 13:36:41 2019
@@ -25,6 +25,7 @@ import java.util.List;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.contentstream.operator.Operator;
+import org.apache.pdfbox.contentstream.operator.OperatorName;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSBoolean;
 import org.apache.pdfbox.cos.COSDictionary;
@@ -246,7 +247,7 @@ public class PDFStreamParser extends Bas
             {
                 String next = readString();
                 retval = Operator.getOperator(next);
-                if( next.equals( "BI" ) )
+                if( next.equals( OperatorName.BEGIN_INLINE_IMAGE ) )
                 {
                     Operator beginImageOP = (Operator)retval;
                     COSDictionary imageParams = new COSDictionary();
@@ -274,7 +275,7 @@ public class PDFStreamParser extends Bas
             {
                 //Special case for ID operator
                 String id = "" + (char) seqSource.read() + (char) seqSource.read();
-                if( !id.equals( "ID" ) )
+                if (!id.equals(OperatorName.BEGIN_INLINE_IMAGE_DATA))
                 {
                     throw new IOException( "Error: Expected operator 'ID' actual='" + id
+
                                            "' at stream offset " + seqSource.getPosition());
@@ -302,7 +303,7 @@ public class PDFStreamParser extends Bas
                     currentByte = seqSource.read();
                 }
                 // the EI operator isn't unread, as it won't be processed anyway
-                retval = Operator.getOperator("ID");
+                retval = Operator.getOperator(OperatorName.BEGIN_INLINE_IMAGE_DATA);
                 // save the image data to the operator, so that it can be accessed later
                 ((Operator)retval).setImageData( imageData.toByteArray() );
                 break;

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/ContentStreamWriter.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/ContentStreamWriter.java?rev=1857809&r1=1857808&r2=1857809&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/ContentStreamWriter.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/ContentStreamWriter.java
Fri Apr 19 13:36:41 2019
@@ -21,6 +21,7 @@ import java.io.OutputStream;
 import java.util.List;
 import java.util.Map;
 import org.apache.pdfbox.contentstream.operator.Operator;
+import org.apache.pdfbox.contentstream.operator.OperatorName;
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSBoolean;
@@ -169,9 +170,9 @@ public class ContentStreamWriter
         else if( o instanceof Operator)
         {
             Operator op = (Operator)o;
-            if( op.getName().equals( "BI" ) )
+            if( op.getName().equals( OperatorName.BEGIN_INLINE_IMAGE ) )
             {
-                output.write( "BI".getBytes(Charsets.ISO_8859_1) );
+                output.write( OperatorName.BEGIN_INLINE_IMAGE.getBytes(Charsets.ISO_8859_1)
);
                 COSDictionary dic = op.getImageParameters();
                 for( COSName key : dic.keySet() )
                 {
@@ -181,11 +182,11 @@ public class ContentStreamWriter
                     writeObject( value );
                     output.write( EOL );
                 }
-                output.write( "ID".getBytes(Charsets.ISO_8859_1) );
+                output.write( OperatorName.BEGIN_INLINE_IMAGE_DATA.getBytes(Charsets.ISO_8859_1)
);
                 output.write( EOL );
                 output.write( op.getImageData() );
                 output.write( EOL );
-                output.write( "EI".getBytes(Charsets.ISO_8859_1) );
+                output.write( OperatorName.END_INLINE_IMAGE.getBytes(Charsets.ISO_8859_1)
);
                 output.write( EOL );
             }
             else

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java?rev=1857809&r1=1857808&r2=1857809&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java
Fri Apr 19 13:36:41 2019
@@ -41,6 +41,7 @@ import org.apache.fontbox.ttf.gsub.Compo
 import org.apache.fontbox.ttf.gsub.GsubWorker;
 import org.apache.fontbox.ttf.gsub.GsubWorkerFactory;
 import org.apache.fontbox.ttf.model.GsubData;
+import org.apache.pdfbox.contentstream.operator.OperatorName;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSNumber;
@@ -135,7 +136,7 @@ abstract class PDAbstractContentStream i
         {
             throw new IllegalStateException("Error: Nested beginText() calls are not allowed.");
         }
-        writeOperator("BT");
+        writeOperator(OperatorName.BEGIN_TEXT);
         inTextMode = true;
     }
 
@@ -152,7 +153,7 @@ abstract class PDAbstractContentStream i
         {
             throw new IllegalStateException("Error: You must call beginText() before calling
endText.");
         }
-        writeOperator("ET");
+        writeOperator(OperatorName.END_TEXT);
         inTextMode = false;
     }
     
@@ -203,7 +204,7 @@ abstract class PDAbstractContentStream i
 
         writeOperand(resources.add(font));
         writeOperand(fontSize);
-        writeOperator("Tf");
+        writeOperator(OperatorName.SET_FONT_AND_SIZE);
     }
 
     /**
@@ -238,7 +239,7 @@ abstract class PDAbstractContentStream i
             }
         }
         write("] ");
-        writeOperator("TJ");
+        writeOperator(OperatorName.SHOW_TEXT_ADJUSTED);
     }
 
     /**
@@ -252,7 +253,7 @@ abstract class PDAbstractContentStream i
     {
         showTextInternal(text);
         write(" ");
-        writeOperator("Tj");
+        writeOperator(OperatorName.SHOW_TEXT);
     }
 
     /**
@@ -323,7 +324,7 @@ abstract class PDAbstractContentStream i
     public void setLeading(float leading) throws IOException
     {
         writeOperand(leading);
-        writeOperator("TL");
+        writeOperator(OperatorName.SET_TEXT_LEADING);
     }
 
     /**
@@ -338,7 +339,7 @@ abstract class PDAbstractContentStream i
         {
             throw new IllegalStateException("Must call beginText() before newLine()");
         }
-        writeOperator("T*");
+        writeOperator(OperatorName.NEXT_LINE);
     }
 
     /**
@@ -358,7 +359,7 @@ abstract class PDAbstractContentStream i
         }
         writeOperand(tx);
         writeOperand(ty);
-        writeOperator("Td");
+        writeOperator(OperatorName.MOVE_TEXT);
     }
 
     /**
@@ -376,7 +377,7 @@ abstract class PDAbstractContentStream i
             throw new IllegalStateException("Error: must call beginText() before setTextMatrix");
         }
         writeAffineTransform(matrix.createAffineTransform());
-        writeOperator("Tm");
+        writeOperator(OperatorName.SET_MATRIX);
     }
 
     /**
@@ -418,7 +419,7 @@ abstract class PDAbstractContentStream i
         transform(new Matrix(transform));
 
         writeOperand(resources.add(image));
-        writeOperator("Do");
+        writeOperator(OperatorName.DRAW_OBJECT);
 
         restoreGraphicsState();
     }
@@ -445,7 +446,7 @@ abstract class PDAbstractContentStream i
         transform(new Matrix(transform));
 
         writeOperand(resources.add(image));
-        writeOperator("Do");
+        writeOperator(OperatorName.DRAW_OBJECT);
 
         restoreGraphicsState();
     }
@@ -488,7 +489,7 @@ abstract class PDAbstractContentStream i
 
         // create the image dictionary
         StringBuilder sb = new StringBuilder();
-        sb.append("BI");
+        sb.append(OperatorName.BEGIN_INLINE_IMAGE);
 
         sb.append("\n /W ");
         sb.append(inlineImage.getWidth());
@@ -525,10 +526,10 @@ abstract class PDAbstractContentStream i
         writeLine();
 
         // binary data
-        writeOperator("ID");
+        writeOperator(OperatorName.BEGIN_INLINE_IMAGE_DATA);
         writeBytes(inlineImage.getData());
         writeLine();
-        writeOperator("EI");
+        writeOperator(OperatorName.END_INLINE_IMAGE);
 
         restoreGraphicsState();
     }
@@ -548,7 +549,7 @@ abstract class PDAbstractContentStream i
         }
 
         writeOperand(resources.add(form));
-        writeOperator("Do");
+        writeOperator(OperatorName.DRAW_OBJECT);
     }
 
     /**
@@ -565,7 +566,7 @@ abstract class PDAbstractContentStream i
         }
 
         writeAffineTransform(matrix.createAffineTransform());
-        writeOperator("cm");
+        writeOperator(OperatorName.CONCAT);
     }
 
     /**
@@ -591,7 +592,7 @@ abstract class PDAbstractContentStream i
         {
             nonStrokingColorSpaceStack.push(nonStrokingColorSpaceStack.peek());
         }
-        writeOperator("q");
+        writeOperator(OperatorName.SAVE);
     }
 
     /**
@@ -617,7 +618,7 @@ abstract class PDAbstractContentStream i
         {
             nonStrokingColorSpaceStack.pop();
         }
-        writeOperator("Q");
+        writeOperator(OperatorName.RESTORE);
     }
 
     protected COSName getName(PDColorSpace colorSpace)
@@ -646,7 +647,7 @@ abstract class PDAbstractContentStream i
             strokingColorSpaceStack.peek() != color.getColorSpace())
         {
             writeOperand(getName(color.getColorSpace()));
-            writeOperator("CS");
+            writeOperator(OperatorName.STROKING_COLORSPACE);
             setStrokingColorSpaceStack(color.getColorSpace());
         }
 
@@ -665,11 +666,11 @@ abstract class PDAbstractContentStream i
             color.getColorSpace() instanceof PDDeviceN ||
             color.getColorSpace() instanceof PDICCBased)
         {
-            writeOperator("SCN");
+            writeOperator(OperatorName.STROKING_COLOR_N);
         }
         else
         {
-            writeOperator("SC");
+            writeOperator(OperatorName.STROKING_COLOR);
         }
     }
 
@@ -706,7 +707,7 @@ abstract class PDAbstractContentStream i
         writeOperand(r / 255f);
         writeOperand(g / 255f);
         writeOperand(b / 255f);
-        writeOperator("RG");
+        writeOperator(OperatorName.STROKING_COLOR_RGB);
         setStrokingColorSpaceStack(PDDeviceRGB.INSTANCE);
     }
 
@@ -731,7 +732,7 @@ abstract class PDAbstractContentStream i
         writeOperand(m);
         writeOperand(y);
         writeOperand(k);
-        writeOperator("K");
+        writeOperator(OperatorName.STROKING_COLOR_CMYK);
         setStrokingColorSpaceStack(PDDeviceCMYK.INSTANCE);
     }
 
@@ -749,7 +750,7 @@ abstract class PDAbstractContentStream i
             throw new IllegalArgumentException("Parameter must be within 0..1, but is " +
g);
         }
         writeOperand(g);
-        writeOperator("G");
+        writeOperator(OperatorName.STROKING_COLOR_GRAY);
         setStrokingColorSpaceStack(PDDeviceGray.INSTANCE);
     }
 
@@ -765,7 +766,7 @@ abstract class PDAbstractContentStream i
             nonStrokingColorSpaceStack.peek() != color.getColorSpace())
         {
             writeOperand(getName(color.getColorSpace()));
-            writeOperator("cs");
+            writeOperator(OperatorName.NON_STROKING_COLORSPACE);
             setNonStrokingColorSpaceStack(color.getColorSpace());
         }
 
@@ -784,11 +785,11 @@ abstract class PDAbstractContentStream i
             color.getColorSpace() instanceof PDDeviceN ||
             color.getColorSpace() instanceof PDICCBased)
         {
-            writeOperator("scn");
+            writeOperator(OperatorName.NON_STROKING_COLOR_N);
         }
         else
         {
-            writeOperator("sc");
+            writeOperator(OperatorName.NON_STROKING_COLOR);
         }
     }
 
@@ -825,7 +826,7 @@ abstract class PDAbstractContentStream i
         writeOperand(r / 255f);
         writeOperand(g / 255f);
         writeOperand(b / 255f);
-        writeOperator("rg");
+        writeOperator(OperatorName.NON_STROKING_RGB);
         setNonStrokingColorSpaceStack(PDDeviceRGB.INSTANCE);
     }
 
@@ -869,7 +870,7 @@ abstract class PDAbstractContentStream i
         writeOperand(m);
         writeOperand(y);
         writeOperand(k);
-        writeOperator("k");
+        writeOperator(OperatorName.NON_STROKING_CMYK);
         setNonStrokingColorSpaceStack(PDDeviceCMYK.INSTANCE);
     }
 
@@ -903,7 +904,7 @@ abstract class PDAbstractContentStream i
             throw new IllegalArgumentException("Parameter must be within 0..1, but is " +
g);
         }
         writeOperand(g);
-        writeOperator("g");
+        writeOperator(OperatorName.NON_STROKING_GRAY);
         setNonStrokingColorSpaceStack(PDDeviceGray.INSTANCE);
     }
 
@@ -927,7 +928,7 @@ abstract class PDAbstractContentStream i
         writeOperand(y);
         writeOperand(width);
         writeOperand(height);
-        writeOperator("re");
+        writeOperator(OperatorName.APPEND_RECT);
     }
 
     /**
@@ -955,7 +956,7 @@ abstract class PDAbstractContentStream i
         writeOperand(y2);
         writeOperand(x3);
         writeOperand(y3);
-        writeOperator("c");
+        writeOperator(OperatorName.CURVE_TO);
     }
 
     /**
@@ -979,7 +980,7 @@ abstract class PDAbstractContentStream i
         writeOperand(y2);
         writeOperand(x3);
         writeOperand(y3);
-        writeOperator("v");
+        writeOperator(OperatorName.CURVE_TO_REPLICATE_INITIAL_POINT);
     }
 
     /**
@@ -1003,7 +1004,7 @@ abstract class PDAbstractContentStream i
         writeOperand(y1);
         writeOperand(x3);
         writeOperand(y3);
-        writeOperator("y");
+        writeOperator(OperatorName.CURVE_TO_REPLICATE_FINAL_POINT);
     }
 
     /**
@@ -1022,7 +1023,7 @@ abstract class PDAbstractContentStream i
         }
         writeOperand(x);
         writeOperand(y);
-        writeOperator("m");
+        writeOperator(OperatorName.MOVE_TO);
     }
 
     /**
@@ -1041,7 +1042,7 @@ abstract class PDAbstractContentStream i
         }
         writeOperand(x);
         writeOperand(y);
-        writeOperator("l");
+        writeOperator(OperatorName.LINE_TO);
     }
 
     /**
@@ -1056,7 +1057,7 @@ abstract class PDAbstractContentStream i
         {
             throw new IllegalStateException("Error: stroke is not allowed within a text block.");
         }
-        writeOperator("S");
+        writeOperator(OperatorName.STROKE_PATH);
     }
 
     /**
@@ -1071,7 +1072,7 @@ abstract class PDAbstractContentStream i
         {
             throw new IllegalStateException("Error: closeAndStroke is not allowed within
a text block.");
         }
-        writeOperator("s");
+        writeOperator(OperatorName.CLOSE_AND_STROKE);
     }
 
     /**
@@ -1086,7 +1087,7 @@ abstract class PDAbstractContentStream i
         {
             throw new IllegalStateException("Error: fill is not allowed within a text block.");
         }
-        writeOperator("f");
+        writeOperator(OperatorName.FILL_NON_ZERO);
     }
 
     /**
@@ -1101,7 +1102,7 @@ abstract class PDAbstractContentStream i
         {
             throw new IllegalStateException("Error: fillEvenOdd is not allowed within a text
block.");
         }
-        writeOperator("f*");
+        writeOperator(OperatorName.FILL_EVEN_ODD);
     }
 
     /**
@@ -1118,7 +1119,7 @@ abstract class PDAbstractContentStream i
         {
             throw new IllegalStateException("Error: fillAndStroke is not allowed within a
text block.");
         }
-        writeOperator("B");
+        writeOperator(OperatorName.FILL_NON_ZERO_AND_STROKE);
     }
 
     /**
@@ -1135,7 +1136,7 @@ abstract class PDAbstractContentStream i
         {
             throw new IllegalStateException("Error: fillAndStrokeEvenOdd is not allowed within
a text block.");
         }
-        writeOperator("B*");
+        writeOperator(OperatorName.FILL_EVEN_ODD_AND_STROKE);
     }
 
     /**
@@ -1152,7 +1153,7 @@ abstract class PDAbstractContentStream i
         {
             throw new IllegalStateException("Error: closeAndFillAndStroke is not allowed
within a text block.");
         }
-        writeOperator("b");
+        writeOperator(OperatorName.CLOSE_FILL_NON_ZERO_AND_STROKE);
     }
 
     /**
@@ -1169,7 +1170,7 @@ abstract class PDAbstractContentStream i
         {
             throw new IllegalStateException("Error: closeAndFillAndStrokeEvenOdd is not allowed
within a text block.");
         }
-        writeOperator("b*");
+        writeOperator(OperatorName.CLOSE_FILL_EVEN_ODD_AND_STROKE);
     }
 
     /**
@@ -1187,7 +1188,7 @@ abstract class PDAbstractContentStream i
         }
 
         writeOperand(resources.add(shading));
-        writeOperator("sh");
+        writeOperator(OperatorName.SHADING_FILL);
     }
 
     /**
@@ -1202,7 +1203,7 @@ abstract class PDAbstractContentStream i
         {
             throw new IllegalStateException("Error: closePath is not allowed within a text
block.");
         }
-        writeOperator("h");
+        writeOperator(OperatorName.CLOSE_PATH);
     }
 
     /**
@@ -1217,10 +1218,10 @@ abstract class PDAbstractContentStream i
         {
             throw new IllegalStateException("Error: clip is not allowed within a text block.");
         }
-        writeOperator("W");
+        writeOperator(OperatorName.CLIP_NON_ZERO);
         
         // end path without filling or stroking
-        writeOperator("n");
+        writeOperator(OperatorName.ENDPATH);
     }
 
     /**
@@ -1235,10 +1236,10 @@ abstract class PDAbstractContentStream i
         {
             throw new IllegalStateException("Error: clipEvenOdd is not allowed within a text
block.");
         }
-        writeOperator("W*");
+        writeOperator(OperatorName.CLIP_EVEN_ODD);
         
         // end path without filling or stroking
-        writeOperator("n");
+        writeOperator(OperatorName.ENDPATH);
     }
 
     /**
@@ -1255,7 +1256,7 @@ abstract class PDAbstractContentStream i
             throw new IllegalStateException("Error: setLineWidth is not allowed within a
text block.");
         }
         writeOperand(lineWidth);
-        writeOperator("w");
+        writeOperator(OperatorName.SET_LINE_WIDTH);
     }
 
     /**
@@ -1275,7 +1276,7 @@ abstract class PDAbstractContentStream i
         if (lineJoinStyle >= 0 && lineJoinStyle <= 2)
         {
             writeOperand(lineJoinStyle);
-            writeOperator("j");
+            writeOperator(OperatorName.SET_LINE_JOINSTYLE);
         }
         else
         {
@@ -1300,7 +1301,7 @@ abstract class PDAbstractContentStream i
         if (lineCapStyle >= 0 && lineCapStyle <= 2)
         {
             writeOperand(lineCapStyle);
-            writeOperator("J");
+            writeOperator(OperatorName.SET_LINE_CAPSTYLE);
         }
         else
         {
@@ -1329,7 +1330,7 @@ abstract class PDAbstractContentStream i
         }
         write("] ");
         writeOperand(phase);
-        writeOperator("d");
+        writeOperator(OperatorName.SET_LINE_DASHPATTERN);
     }
 
     /**
@@ -1349,7 +1350,7 @@ abstract class PDAbstractContentStream i
             throw new IllegalArgumentException("A miter limit <= 0 is invalid and will
not render in Acrobat Reader");
         }
         writeOperand(miterLimit);
-        writeOperator("M");
+        writeOperator(OperatorName.SET_LINE_MITERLIMIT);
     }
 
     /**
@@ -1361,7 +1362,7 @@ abstract class PDAbstractContentStream i
     public void beginMarkedContent(COSName tag) throws IOException
     {
         writeOperand(tag);
-        writeOperator("BMC");
+        writeOperator(OperatorName.BEGIN_MARKED_CONTENT);
     }
 
     /**
@@ -1376,7 +1377,7 @@ abstract class PDAbstractContentStream i
     {
         writeOperand(tag);
         writeOperand(resources.add(propertyList));
-        writeOperator("BDC");
+        writeOperator(OperatorName.BEGIN_MARKED_CONTENT_SEQ);
     }
 
     /**
@@ -1386,7 +1387,7 @@ abstract class PDAbstractContentStream i
      */
     public void endMarkedContent() throws IOException
     {
-        writeOperator("EMC");
+        writeOperator(OperatorName.END_MARKED_CONTENT);
     }
 
     /**
@@ -1398,7 +1399,7 @@ abstract class PDAbstractContentStream i
     public void setGraphicsStateParameters(PDExtendedGraphicsState state) throws IOException
     {
         writeOperand(resources.add(state));
-        writeOperator("gs");
+        writeOperator(OperatorName.SET_GRAPHICS_STATE_PARAMS);
     }
 
     /**
@@ -1587,7 +1588,7 @@ abstract class PDAbstractContentStream i
     public void setCharacterSpacing(float spacing) throws IOException
     {
         writeOperand(spacing);
-        writeOperator("Tc");
+        writeOperator(OperatorName.SET_CHAR_SPACING);
     }
 
     /**
@@ -1606,7 +1607,7 @@ abstract class PDAbstractContentStream i
     public void setWordSpacing(float spacing) throws IOException
     {
         writeOperand(spacing);
-        writeOperator("Tw");
+        writeOperator(OperatorName.SET_WORD_SPACING);
     }
 
     /**
@@ -1619,7 +1620,7 @@ abstract class PDAbstractContentStream i
     public void setHorizontalScaling(float scale) throws IOException
     {
         writeOperand(scale);
-        writeOperator("Tz");
+        writeOperator(OperatorName.SET_TEXT_HORIZONTAL_SCALING);
     }
 
     /**
@@ -1632,7 +1633,7 @@ abstract class PDAbstractContentStream i
     public void setRenderingMode(RenderingMode rm) throws IOException
     {
         writeOperand(rm.intValue());
-        writeOperator("Tr");
+        writeOperator(OperatorName.SET_TEXT_RENDERINGMODE);
     }
 
     /**
@@ -1646,15 +1647,13 @@ abstract class PDAbstractContentStream i
     public void setTextRise(float rise) throws IOException
     {
         writeOperand(rise);
-        writeOperator("Ts");
+        writeOperator(OperatorName.SET_TEXT_RISE);
     }
 
     private byte[] encodeForGsub(GsubWorker gsubWorker,
                                  Set<Integer> glyphIds, PDType0Font font, String text)
throws IOException
     {
-
-        String spaceRegexPattern = "\\s";
-        Pattern spaceRegex = Pattern.compile(spaceRegexPattern);
+        Pattern spaceRegex = Pattern.compile("\\s");
 
         // break the entire chunk of text into words by splitting it with space
         List<String> words = new CompoundCharacterTokenizer("\\s").tokenize(text);

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAppearanceContentStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAppearanceContentStream.java?rev=1857809&r1=1857808&r2=1857809&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAppearanceContentStream.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAppearanceContentStream.java
Fri Apr 19 13:36:41 2019
@@ -19,6 +19,8 @@ package org.apache.pdfbox.pdmodel;
 import java.io.Closeable;
 import java.io.IOException;
 import java.io.OutputStream;
+
+import org.apache.pdfbox.contentstream.operator.OperatorName;
 import org.apache.pdfbox.cos.COSArray;
 
 import org.apache.pdfbox.cos.COSName;
@@ -115,13 +117,13 @@ public final class PDAppearanceContentSt
         switch (numComponents)
         {
         case 1:
-            writeOperator("G");
+            writeOperator(OperatorName.STROKING_COLOR_GRAY);
             break;
         case 3:
-            writeOperator("RG");
+            writeOperator(OperatorName.STROKING_COLOR_RGB);
             break;
         case 4:
-            writeOperator("K");
+            writeOperator(OperatorName.STROKING_COLOR_CMYK);
             break;
         default:
             break;
@@ -174,13 +176,13 @@ public final class PDAppearanceContentSt
         switch (numComponents)
         {
         case 1:
-            writeOperator("g");
+            writeOperator(OperatorName.NON_STROKING_GRAY);
             break;
         case 3:
-            writeOperator("rg");
+            writeOperator(OperatorName.NON_STROKING_RGB);
             break;
         case 4:
-            writeOperator("k");
+            writeOperator(OperatorName.NON_STROKING_CMYK);
             break;
         default:
             break;
@@ -271,7 +273,7 @@ public final class PDAppearanceContentSt
         }
         else
         {
-            writeOperator("n");
+            writeOperator(OperatorName.ENDPATH);
         }
     }
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java?rev=1857809&r1=1857808&r2=1857809&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java Fri
Apr 19 13:36:41 2019
@@ -24,6 +24,7 @@ import java.io.OutputStream;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.pdfbox.contentstream.operator.OperatorName;
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSName;
@@ -423,7 +424,7 @@ public final class PDPageContentStream e
         transform(new Matrix(transform));
 
         writeOperand(objMapping);
-        writeOperator("Do");
+        writeOperator(OperatorName.DRAW_OBJECT);
 
         restoreGraphicsState();
     }
@@ -471,7 +472,7 @@ public final class PDPageContentStream e
     {
         setStrokingColorSpaceStack(colorSpace);
         writeOperand(getName(colorSpace));
-        writeOperator("CS");
+        writeOperator(OperatorName.STROKING_COLORSPACE);
     }
 
     /**
@@ -487,7 +488,7 @@ public final class PDPageContentStream e
     {
         setNonStrokingColorSpaceStack(colorSpace);
         writeOperand(getName(colorSpace));
-        writeOperator("cs");
+        writeOperator(OperatorName.NON_STROKING_COLORSPACE);
     }
 
     /**
@@ -516,11 +517,11 @@ public final class PDPageContentStream e
             currentStrokingColorSpace instanceof PDPattern ||
             currentStrokingColorSpace instanceof PDICCBased)
         {
-            writeOperator("SCN");
+            writeOperator(OperatorName.STROKING_COLOR_N);
         }
         else
         {
-            writeOperator("SC");
+            writeOperator(OperatorName.STROKING_COLOR);
         }
     }
 
@@ -590,11 +591,11 @@ public final class PDPageContentStream e
             currentNonStrokingColorSpace instanceof PDPattern ||
             currentNonStrokingColorSpace instanceof PDICCBased)
         {
-            writeOperator("scn");
+            writeOperator(OperatorName.NON_STROKING_COLOR_N);
         }
         else
         {
-            writeOperator("sc");
+            writeOperator(OperatorName.NON_STROKING_COLOR);
         }
     }
 
@@ -845,15 +846,15 @@ public final class PDPageContentStream e
         switch (windingRule)
         {
             case PathIterator.WIND_NON_ZERO:
-                writeOperator("W");
+            writeOperator(OperatorName.CLIP_NON_ZERO);
                 break;
             case PathIterator.WIND_EVEN_ODD:
-                writeOperator("W*");
+            writeOperator(OperatorName.CLIP_EVEN_ODD);
                 break;
             default:
                 throw new IllegalArgumentException("Error: unknown value for winding rule");
         }
-        writeOperator("n");
+        writeOperator(OperatorName.ENDPATH);
     }
 
     /**
@@ -883,7 +884,7 @@ public final class PDPageContentStream e
     {
         writeOperand(tag);
         writeOperand(propsName);
-        writeOperator("BDC");
+        writeOperator(OperatorName.BEGIN_MARKED_CONTENT_SEQ);
     }
 
     /**

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/PDFStreamParserTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/PDFStreamParserTest.java?rev=1857809&r1=1857808&r2=1857809&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/PDFStreamParserTest.java
(original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/PDFStreamParserTest.java
Fri Apr 19 13:36:41 2019
@@ -19,7 +19,7 @@ import java.io.IOException;
 import java.util.List;
 import junit.framework.TestCase;
 import org.apache.pdfbox.contentstream.operator.Operator;
-
+import org.apache.pdfbox.contentstream.operator.OperatorName;
 
 import static org.junit.Assert.assertArrayEquals;
 
@@ -94,7 +94,7 @@ public class PDFStreamParserTest extends
 
         assertEquals(2, tokens.size());
 
-        assertEquals("ID", ((Operator) tokens.get(0)).getName());
+        assertEquals(OperatorName.BEGIN_INLINE_IMAGE_DATA, ((Operator) tokens.get(0)).getName());
         assertEquals(imageDataString.length(), ((Operator) tokens.get(0)).getImageData().length);
         assertArrayEquals(imageDataString.getBytes(), ((Operator) tokens.get(0)).getImageData());
 
@@ -108,7 +108,7 @@ public class PDFStreamParserTest extends
 
         assertEquals(1, tokens.size());
 
-        assertEquals("ID", ((Operator) tokens.get(0)).getName());
+        assertEquals(OperatorName.BEGIN_INLINE_IMAGE_DATA, ((Operator) tokens.get(0)).getName());
         assertEquals(imageDataString.length(), ((Operator) tokens.get(0)).getImageData().length);
         assertArrayEquals(imageDataString.getBytes(), ((Operator) tokens.get(0)).getImageData());
     }



Mime
View raw message