You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ja...@apache.org on 2014/09/26 23:21:19 UTC
svn commit: r1627890 - in
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox:
contentstream/operator/state/ pdmodel/graphics/state/
Author: jahewson
Date: Fri Sep 26 21:21:18 2014
New Revision: 1627890
URL: http://svn.apache.org/r1627890
Log:
PDFBOX-2391: Use an enum for rendering intent
Added:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/RenderingIntent.java
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/state/SetRenderingIntent.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExternalGraphicsState.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDGraphicsState.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/state/SetRenderingIntent.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/state/SetRenderingIntent.java?rev=1627890&r1=1627889&r2=1627890&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/state/SetRenderingIntent.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/state/SetRenderingIntent.java Fri Sep 26 21:21:18 2014
@@ -23,6 +23,7 @@ import org.apache.pdfbox.cos.COSBase;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.contentstream.operator.Operator;
import org.apache.pdfbox.contentstream.operator.OperatorProcessor;
+import org.apache.pdfbox.pdmodel.graphics.state.RenderingIntent;
/**
* ri: Set the rendering intent.
@@ -35,7 +36,7 @@ public class SetRenderingIntent extends
public void process(Operator operator, List<COSBase> operands) throws IOException
{
COSName value = (COSName)operands.get(0);
- context.getGraphicsState().setRenderingIntent(value.getName());
+ context.getGraphicsState().setRenderingIntent(RenderingIntent.valueOf(value.getName()));
}
@Override
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExternalGraphicsState.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExternalGraphicsState.java?rev=1627890&r1=1627889&r2=1627890&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExternalGraphicsState.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExternalGraphicsState.java Fri Sep 26 21:21:18 2014
@@ -36,33 +36,15 @@ import org.apache.pdfbox.pdmodel.graphic
*/
public class PDExternalGraphicsState implements COSObjectable
{
- /**
- * Rendering intent constants, see PDF Reference 1.5 Section 4.5.4 Rendering Intents.
- */
- public static final String RENDERING_INTENT_ABSOLUTE_COLORIMETRIC = "AbsoluteColorimetric";
- /**
- * Rendering intent constants, see PDF Reference 1.5 Section 4.5.4 Rendering Intents.
- */
- public static final String RENDERING_INTENT_RELATIVE_COLORIMETRIC = "RelativeColorimetric";
- /**
- * Rendering intent constants, see PDF Reference 1.5 Section 4.5.4 Rendering Intents.
- */
- public static final String RENDERING_INTENT_SATURATION = "Saturation";
- /**
- * Rendering intent constants, see PDF Reference 1.5 Section 4.5.4 Rendering Intents.
- */
- public static final String RENDERING_INTENT_PERCEPTUAL = "Perceptual";
-
-
- private COSDictionary graphicsState;
+ private final COSDictionary dict;
/**
* Default constructor, creates blank graphics state.
*/
public PDExternalGraphicsState()
{
- graphicsState = new COSDictionary();
- graphicsState.setItem( COSName.TYPE, COSName.EXT_G_STATE );
+ dict = new COSDictionary();
+ dict.setItem(COSName.TYPE, COSName.EXT_G_STATE);
}
/**
@@ -72,7 +54,7 @@ public class PDExternalGraphicsState imp
*/
public PDExternalGraphicsState(COSDictionary dictionary)
{
- graphicsState = dictionary;
+ dict = dictionary;
}
/**
@@ -84,7 +66,7 @@ public class PDExternalGraphicsState imp
*/
public void copyIntoGraphicsState( PDGraphicsState gs ) throws IOException
{
- for( COSName key : graphicsState.keySet() )
+ for( COSName key : dict.keySet() )
{
if( key.equals( COSName.LW ) )
{
@@ -169,7 +151,7 @@ public class PDExternalGraphicsState imp
*/
public COSDictionary getCOSDictionary()
{
- return graphicsState;
+ return dict;
}
/**
@@ -179,7 +161,7 @@ public class PDExternalGraphicsState imp
*/
public COSBase getCOSObject()
{
- return graphicsState;
+ return dict;
}
/**
@@ -209,7 +191,7 @@ public class PDExternalGraphicsState imp
*/
public int getLineCapStyle()
{
- return graphicsState.getInt( COSName.LC );
+ return dict.getInt( COSName.LC );
}
/**
@@ -219,7 +201,7 @@ public class PDExternalGraphicsState imp
*/
public void setLineCapStyle( int style )
{
- graphicsState.setInt( COSName.LC, style );
+ dict.setInt(COSName.LC, style);
}
/**
@@ -229,7 +211,7 @@ public class PDExternalGraphicsState imp
*/
public int getLineJoinStyle()
{
- return graphicsState.getInt( COSName.LJ );
+ return dict.getInt( COSName.LJ );
}
/**
@@ -239,7 +221,7 @@ public class PDExternalGraphicsState imp
*/
public void setLineJoinStyle( int style )
{
- graphicsState.setInt( COSName.LJ, style );
+ dict.setInt(COSName.LJ, style);
}
@@ -271,7 +253,7 @@ public class PDExternalGraphicsState imp
public PDLineDashPattern getLineDashPattern()
{
PDLineDashPattern retval = null;
- COSArray dp = (COSArray)graphicsState.getDictionaryObject( COSName.D );
+ COSArray dp = (COSArray) dict.getDictionaryObject( COSName.D );
if( dp != null )
{
COSArray array = new COSArray();
@@ -291,7 +273,7 @@ public class PDExternalGraphicsState imp
*/
public void setLineDashPattern( PDLineDashPattern dashPattern )
{
- graphicsState.setItem(COSName.D, dashPattern.getCOSObject());
+ dict.setItem(COSName.D, dashPattern.getCOSObject());
}
/**
@@ -299,9 +281,17 @@ public class PDExternalGraphicsState imp
*
* @return null or the RI value in the dictionary.
*/
- public String getRenderingIntent()
+ public RenderingIntent getRenderingIntent()
{
- return graphicsState.getNameAsString( "RI" );
+ String ri = dict.getNameAsString( "RI" );
+ if (ri != null)
+ {
+ return RenderingIntent.valueOf(ri);
+ }
+ else
+ {
+ return null;
+ }
}
/**
@@ -311,7 +301,7 @@ public class PDExternalGraphicsState imp
*/
public void setRenderingIntent( String ri )
{
- graphicsState.setName("RI", ri);
+ dict.setName("RI", ri);
}
/**
@@ -321,7 +311,7 @@ public class PDExternalGraphicsState imp
*/
public boolean getStrokingOverprintControl()
{
- return graphicsState.getBoolean(COSName.OP, false);
+ return dict.getBoolean(COSName.OP, false);
}
/**
@@ -331,7 +321,7 @@ public class PDExternalGraphicsState imp
*/
public void setStrokingOverprintControl( boolean op )
{
- graphicsState.setBoolean(COSName.OP, op);
+ dict.setBoolean(COSName.OP, op);
}
/**
@@ -342,7 +332,7 @@ public class PDExternalGraphicsState imp
*/
public boolean getNonStrokingOverprintControl()
{
- return graphicsState.getBoolean( COSName.OP_NS, getStrokingOverprintControl() );
+ return dict.getBoolean( COSName.OP_NS, getStrokingOverprintControl() );
}
/**
@@ -352,7 +342,7 @@ public class PDExternalGraphicsState imp
*/
public void setNonStrokingOverprintControl( boolean op )
{
- graphicsState.setBoolean( COSName.OP_NS, op );
+ dict.setBoolean(COSName.OP_NS, op);
}
/**
@@ -383,7 +373,7 @@ public class PDExternalGraphicsState imp
public PDFontSetting getFontSetting()
{
PDFontSetting setting = null;
- COSBase base = graphicsState.getDictionaryObject( COSName.FONT );
+ COSBase base = dict.getDictionaryObject( COSName.FONT );
if (base instanceof COSArray)
{
COSArray font = (COSArray)base;
@@ -402,7 +392,7 @@ public class PDExternalGraphicsState imp
*/
public void setFontSetting( PDFontSetting fs )
{
- graphicsState.setItem(COSName.FONT, fs);
+ dict.setItem(COSName.FONT, fs);
}
/**
@@ -452,7 +442,7 @@ public class PDExternalGraphicsState imp
*/
public boolean getAutomaticStrokeAdjustment()
{
- return graphicsState.getBoolean(COSName.SA, false);
+ return dict.getBoolean(COSName.SA, false);
}
/**
@@ -462,7 +452,7 @@ public class PDExternalGraphicsState imp
*/
public void setAutomaticStrokeAdjustment( boolean sa )
{
- graphicsState.setBoolean(COSName.SA, sa);
+ dict.setBoolean(COSName.SA, sa);
}
/**
@@ -512,7 +502,7 @@ public class PDExternalGraphicsState imp
*/
public boolean getAlphaSourceFlag()
{
- return graphicsState.getBoolean(COSName.AIS, false);
+ return dict.getBoolean(COSName.AIS, false);
}
/**
@@ -522,7 +512,7 @@ public class PDExternalGraphicsState imp
*/
public void setAlphaSourceFlag( boolean alpha )
{
- graphicsState.setBoolean(COSName.AIS, alpha);
+ dict.setBoolean(COSName.AIS, alpha);
}
/**
@@ -531,7 +521,7 @@ public class PDExternalGraphicsState imp
* @return the blending mode
*/
public BlendMode getBlendMode() {
- return BlendMode.getInstance(graphicsState.getDictionaryObject(COSName.BM));
+ return BlendMode.getInstance(dict.getDictionaryObject(COSName.BM));
}
/**
@@ -540,7 +530,7 @@ public class PDExternalGraphicsState imp
* @return the soft mask
*/
public PDSoftMask getSoftMask() {
- return PDSoftMask.create(graphicsState.getDictionaryObject(COSName.SMASK));
+ return PDSoftMask.create(dict.getDictionaryObject(COSName.SMASK));
}
/**
@@ -552,7 +542,7 @@ public class PDExternalGraphicsState imp
*/
public boolean getTextKnockoutFlag()
{
- return graphicsState.getBoolean( COSName.TK,true );
+ return dict.getBoolean( COSName.TK,true );
}
/**
@@ -562,7 +552,7 @@ public class PDExternalGraphicsState imp
*/
public void setTextKnockoutFlag( boolean tk )
{
- graphicsState.setBoolean( COSName.TK, tk );
+ dict.setBoolean(COSName.TK, tk);
}
/**
@@ -575,7 +565,7 @@ public class PDExternalGraphicsState imp
private Float getFloatItem( COSName key )
{
Float retval = null;
- COSNumber value = (COSNumber)graphicsState.getDictionaryObject( key );
+ COSNumber value = (COSNumber) dict.getDictionaryObject( key );
if( value != null )
{
retval = value.floatValue();
@@ -593,11 +583,11 @@ public class PDExternalGraphicsState imp
{
if( value == null )
{
- graphicsState.removeItem( key );
+ dict.removeItem(key);
}
else
{
- graphicsState.setItem( key, new COSFloat( value) );
+ dict.setItem(key, new COSFloat(value));
}
}
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDGraphicsState.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDGraphicsState.java?rev=1627890&r1=1627889&r2=1627890&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDGraphicsState.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDGraphicsState.java Fri Sep 26 21:21:18 2014
@@ -51,7 +51,7 @@ public class PDGraphicsState implements
private int lineJoin = BasicStroke.JOIN_MITER;
private float miterLimit = 10;
private PDLineDashPattern lineDashPattern = new PDLineDashPattern();
- private String renderingIntent;
+ private RenderingIntent renderingIntent;
private boolean strokeAdjustment = false;
private BlendMode blendMode = BlendMode.COMPATIBLE;
private PDSoftMask softMask;
@@ -434,7 +434,7 @@ public class PDGraphicsState implements
*
* @return The rendering intent
*/
- public String getRenderingIntent()
+ public RenderingIntent getRenderingIntent()
{
return renderingIntent;
}
@@ -444,7 +444,7 @@ public class PDGraphicsState implements
*
* @param value The new rendering intent.
*/
- public void setRenderingIntent(String value)
+ public void setRenderingIntent(RenderingIntent value)
{
renderingIntent = value;
}
Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/RenderingIntent.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/RenderingIntent.java?rev=1627890&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/RenderingIntent.java (added)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/RenderingIntent.java Fri Sep 26 21:21:18 2014
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.pdmodel.graphics.state;
+
+/**
+ * Rendering intent.
+ *
+ * @author John Hewson
+ */
+public enum RenderingIntent
+{
+ /**
+ * Absolute Colorimetric.
+ */
+ ABSOLUTE_COLORIMETRIC("AbsoluteColorimetric"),
+
+ /**
+ * Relative Colorimetric.
+ */
+ RELATIVE_COLORIMETRIC("RelativeColorimetric"),
+
+ /**
+ * Saturation.
+ */
+ SATURATION("Saturation"),
+
+ /**
+ * Neither fill nor stroke text (invisible)
+ */
+ PERCEPTUAL("Perceptual");
+
+ public static RenderingIntent fromString(String value)
+ {
+ return RenderingIntent.valueOf(value);
+ }
+
+ private final String value;
+
+ RenderingIntent(String value)
+ {
+ this.value = value;
+ }
+
+ /**
+ * Returns the string value, as used in a PDF file.
+ */
+ public String stringValue()
+ {
+ return value;
+ }
+}