org.icepdf.core.pobjects.graphics
Class GraphicsState

java.lang.Object
  extended by org.icepdf.core.pobjects.graphics.GraphicsState

public class GraphicsState
extends java.lang.Object

The PDF viewer application maintains an internal data structure called the graphics state that holds current graphics control parameters. These parameters define the global framework within which the graphics operators execute.

The graphics state is initialized at the beginning of each page, using the default values specified in Tables 4.2 and 4.3. Table 4.2 lists those graphics state parameters that are device-independent and are appropriate to specify in page descriptions. The parameters listed in Table 4.3 control details of the rendering (scan conversion) process and are device-dependent; a page description that is intended to be device-independent should not modify these parameters.

Graphics State Stack Info

A well-structured PDF document typically contains many graphical elements that are essentially independent of each other and sometimes nested to multiple levels. The graphics state stack allows these elements to make local changes to the graphics state without disturbing the graphics state of the surrounding environment. The stack is a LIFO (last in, first out) data structure in which the contents of the graphics state can be saved and later restored using the following operators:

When a graphics state is saved a new GraphicsState object is created and a pointer is set to the origional graphics state. This creates a linked list of graphics states that can be easily restored when needed (LIFO staack)

Shapes Stack

The graphics state also manipulates the Shapes stack that contains all of the rendering components dealing with graphics states. As the content parser encounters different graphic state manipulators they are added to the stack and then when the page is rendered the stack (actually a vector) is read in a FIFO to generate the drawing commands.

Device-independent graphics state parameters - (Table 4.2)

Paramater Type Value
CTM array The current transformation matrix, which maps positions from user coordinates to device coordinates. This matrix is modified by each application of the coordinate transformation operator, cm. Initial value: a matrix that transforms default user coordinates to device coordinates.
clipping path (internal) The current clipping path, which defines the boundary against which all output is to be cropped. Initial value: the boundary of the entire imageable portion of the output page.
color space name or array The current color space in which color values are to be interpreted. There are two separate color space parameters: one for stroking and one for all other painting operations. Initial value: DeviceGray.
color (various The current color to be used during painting operations. The type and interpretation of this parameter depend on the current color space; for most color spaces, a color value consists of one to four numbers. There are two separate color parameters: one for stroking and one for all other painting operations. Initial value: black.
text state (various) A set of nine graphics state parameters that pertain only to the painting of text. These include parameters that select the font, scale the glyphs to an appropriate size, and accomplish other effects. The text state parameters are described in Section 5.2, "Text State Parameters and Operators."
line width number The thickness, in user space units, of paths to be stroked.
line cap integer A code specifying the shape of the endpoints for any open path that is stroked (see "Line Cap Style" on page 186). Initial value: 0, for square butt caps.
line join integer A code specifying the shape of joints between connected segments of a stroked path. Initial value: 0, for mitered joins.
miter limit number The maximum length of mitered line joins for stroked paths. This parameter limits the length of "spikes" produced when line segments join at sharp angles. Initial value: 10.0, for a miter cutoff below approximately 11.5 degrees.
dash pattern array and number A description of the dash pattern to be used when paths are stroked. Initial value: a solid line.
rendering intent (Not supported) name The rendering intent to be used when converting CIE-based colors to device colors. Default value: RelativeColorimetric.
stroke adjustment (Not supported) boolean (PDF 1.2) A flag specifying whether to compensate for possible rasterization effects when stroking a path with a line width that is small relative to the pixel resolution of the output device.. Note that this is considered a device-independent parameter, even though the details of its effects are device-dependent. Initial value: false.
blend mode (Not supported) name or array (PDF 1.4) The current blend mode to be used in the transparent imaging model. This parameter is implicitly reset to its initial value at the beginning of execution of a transparency group XObject. Initial value: Normal.
soft mask (Not supported) dictionary or name (PDF 1.4) A soft-mask dictionary specifying the mask shape or mask opacity values to be used in the transparent imaging model, or the name None if no such mask is specified. This parameter is implicitly reset to its initial value at the beginning of execution of a transparency group XObject. Initial value: None.
alpha constant number (PDF 1.4) The constant shape or constant opacity value to be used in the transparent imaging model. There are two separate alpha constant parameters: one for stroking and one for all other painting operations. This parameter is implicitly reset to its initial value at the beginning of execution of a transparency group XObject. Initial value: 1.0.
alpha source boolean (PDF 1.4) A flag specifying whether the current soft mask and alpha constant parameters are to be interpreted as shape values (true) or opacity values (false). This flag also governs the interpretation of the SMask entry, if any, in an image dictionary. Initial value: false.

Device-Dependent graphics state parameters - (Table 4.3)

Currently Not supported

Since:
1.0

Field Summary
static Name CA_NON_STROKING_KEY
           
static Name CA_STROKING_KEY
           
 
Constructor Summary
GraphicsState(GraphicsState parentGraphicsState)
          Constructs a new GraphicsState that is a copy of the specified GraphicsState object.
GraphicsState(Shapes shapes)
          Constructs a new GraphicsState which will have default values and shapes specified by the shapes stack.
 
Method Summary
 void concatenate(ExtGState extGState)
          Concatenate the specified ExtGState to the current graphics state.
 int getAlphaRule()
           
 java.awt.geom.Area getClip()
           
 java.awt.geom.AffineTransform getCTM()
           
 float[] getDashArray()
           
 float getDashPhase()
           
 float getFillAlpha()
           
 java.awt.Color getFillColor()
           
 PColorSpace getFillColorSpace()
           
 int getLineCap()
           
 int getLineJoin()
           
 float getLineWidth()
           
 float getMiterLimit()
           
 int getOverprintMode()
           
 SoftMask getSoftMask()
           
 float getStrokeAlpha()
           
 java.awt.Color getStrokeColor()
           
 PColorSpace getStrokeColorSpace()
           
 TextState getTextState()
           
 boolean isIsolated()
           
 boolean isKnockOut()
           
 boolean isOverprintOther()
           
 boolean isOverprintStroking()
           
 boolean isTransparencyGroup()
           
 GraphicsState restore()
          Restores the previously saved graphic state.
 GraphicsState save()
          Saves the current graphics state.
 void scale(double x, double y)
          Concatenates this transform with a scaling transformation specified by the graphics state current CTM.
 void set(java.awt.geom.AffineTransform af)
          Sets the graphics state CTM to a new transform, the old CTM transform is lost.
 void setAlphaRule(int alphaRule)
           
 void setClip(java.awt.Shape newClip)
          Set the graphics state clipping area.
 void setCTM(java.awt.geom.AffineTransform ctm)
           
 void setDashArray(float[] dashArray)
           
 void setDashPhase(float dashPhase)
           
 void setFillAlpha(float alpha)
           
 void setFillColor(java.awt.Color fillColor)
           
 void setFillColorSpace(PColorSpace fillColorSpace)
           
 void setIsolated(boolean isolated)
           
 void setKnockOut(boolean knockOut)
           
 void setLineCap(int lineCap)
           
 void setLineJoin(int lineJoin)
           
 void setLineWidth(float lineWidth)
           
 void setMiterLimit(float miterLimit)
           
 void setOverprintMode(int overprintMode)
           
 void setOverprintOther(boolean overprintOther)
           
 void setOverprintStroking(boolean overprintStroking)
           
 void setShapes(Shapes shapes)
          Sets the Shapes vector.
 void setSoftMask(SoftMask softMask)
           
 void setStrokeAlpha(float alpha)
           
 void setStrokeColor(java.awt.Color strokeColor)
           
 void setStrokeColorSpace(PColorSpace strokeColorSpace)
           
 void setTextState(TextState textState)
           
 void setTransparencyGroup(boolean transparencyGroup)
           
 void translate(double x, double y)
          Concatenates this transform with a translation transformation specified by the graphics state current CTM.
 void updateClipCM(java.awt.geom.AffineTransform af)
          Updates the clip every time the tranformation matrix is updated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CA_STROKING_KEY

public static final Name CA_STROKING_KEY

CA_NON_STROKING_KEY

public static final Name CA_NON_STROKING_KEY
Constructor Detail

GraphicsState

public GraphicsState(Shapes shapes)
Constructs a new GraphicsState which will have default values and shapes specified by the shapes stack.

Parameters:
shapes - stack containing pages graphical elements.

GraphicsState

public GraphicsState(GraphicsState parentGraphicsState)
Constructs a new GraphicsState that is a copy of the specified GraphicsState object.

Parameters:
parentGraphicsState - the GraphicsState object to copy
Method Detail

setShapes

public void setShapes(Shapes shapes)
Sets the Shapes vector.

Parameters:
shapes - shapes for a given content stream.

translate

public void translate(double x,
                      double y)
Concatenates this transform with a translation transformation specified by the graphics state current CTM. An updated CTM is added to the shapes stack.

Parameters:
x - the distance by which coordinates are translated in the X axis direction
y - the distance by which coordinates are translated in the Y axis direction

scale

public void scale(double x,
                  double y)
Concatenates this transform with a scaling transformation specified by the graphics state current CTM. An update CTM is added to the shapes stack.

Parameters:
x - the factor by which coordinates are scaled along the X axis direction
y - the factor by which coordinates are scaled along the Y axis direction

set

public void set(java.awt.geom.AffineTransform af)
Sets the graphics state CTM to a new transform, the old CTM transform is lost. The new CTM value is added to the shapes stack.

Parameters:
af - the AffineTranform object to set the CTM to.

save

public GraphicsState save()
Saves the current graphics state.

Returns:
copy of the current graphics state.
See Also:
restore()

concatenate

public void concatenate(ExtGState extGState)
Concatenate the specified ExtGState to the current graphics state. Note: currently only a few of the ExtGState attributes are supported.

Parameters:
extGState - external graphics state.
See Also:
ExtGState

restore

public GraphicsState restore()
Restores the previously saved graphic state.

Returns:
the last saved graphics state.
See Also:
save()

updateClipCM

public void updateClipCM(java.awt.geom.AffineTransform af)
Updates the clip every time the tranformation matrix is updated. This is needed to insure that when a new shape is interesected with the previous clip that they are both in the same space.

Parameters:
af - transform to be applied to the clip.

setClip

public void setClip(java.awt.Shape newClip)
Set the graphics state clipping area. The new clipping area is intersected with the current current clip to generate the new clipping area which is saved to the stack.

Parameters:
newClip - new clip for graphic state.

getClip

public java.awt.geom.Area getClip()

getCTM

public java.awt.geom.AffineTransform getCTM()

setCTM

public void setCTM(java.awt.geom.AffineTransform ctm)

getLineCap

public int getLineCap()

setLineCap

public void setLineCap(int lineCap)

getLineWidth

public float getLineWidth()

setLineWidth

public void setLineWidth(float lineWidth)

getLineJoin

public int getLineJoin()

setLineJoin

public void setLineJoin(int lineJoin)

getDashArray

public float[] getDashArray()

setDashArray

public void setDashArray(float[] dashArray)

getDashPhase

public float getDashPhase()

setDashPhase

public void setDashPhase(float dashPhase)

getMiterLimit

public float getMiterLimit()

setMiterLimit

public void setMiterLimit(float miterLimit)

getFillColor

public java.awt.Color getFillColor()

setFillColor

public void setFillColor(java.awt.Color fillColor)

getStrokeColor

public java.awt.Color getStrokeColor()

setStrokeAlpha

public void setStrokeAlpha(float alpha)

getStrokeAlpha

public float getStrokeAlpha()

setFillAlpha

public void setFillAlpha(float alpha)

getFillAlpha

public float getFillAlpha()

setStrokeColor

public void setStrokeColor(java.awt.Color strokeColor)

getFillColorSpace

public PColorSpace getFillColorSpace()

setFillColorSpace

public void setFillColorSpace(PColorSpace fillColorSpace)

getStrokeColorSpace

public PColorSpace getStrokeColorSpace()

setStrokeColorSpace

public void setStrokeColorSpace(PColorSpace strokeColorSpace)

getTextState

public TextState getTextState()

setTextState

public void setTextState(TextState textState)

getOverprintMode

public int getOverprintMode()

isOverprintStroking

public boolean isOverprintStroking()

isOverprintOther

public boolean isOverprintOther()

setOverprintMode

public void setOverprintMode(int overprintMode)

setOverprintStroking

public void setOverprintStroking(boolean overprintStroking)

setOverprintOther

public void setOverprintOther(boolean overprintOther)

getAlphaRule

public int getAlphaRule()

setAlphaRule

public void setAlphaRule(int alphaRule)

isTransparencyGroup

public boolean isTransparencyGroup()

setTransparencyGroup

public void setTransparencyGroup(boolean transparencyGroup)

isIsolated

public boolean isIsolated()

setIsolated

public void setIsolated(boolean isolated)

isKnockOut

public boolean isKnockOut()

setKnockOut

public void setKnockOut(boolean knockOut)

getSoftMask

public SoftMask getSoftMask()

setSoftMask

public void setSoftMask(SoftMask softMask)