org.apache.fop.pdf

Class PDFState


public class PDFState
extends java.lang.Object

This keeps information about the current state when writing to pdf. It allows for creating new graphics states with the q operator. This class is only used to store the information about the state the caller needs to handle the actual pdf operators. When setting the state for pdf there are three possible ways of handling the situation. The values can be set to override previous or default values. A new state can be added and then the values set. The current state can be popped and values will return to a previous state then the necessary values can be overridden. The current transform behaves differently to other values as the matrix is combined with the current resolved value. It is impossible to optimise the result without analysing the all the possible combinations after completing.

Nested Class Summary

class
PDFState.Data

Constructor Summary

PDFState()
PDF State for storing graphics state.

Method Summary

boolean
checkClip(Shape cl)
Check if the clip will change the current state.
boolean
checkTransform(AffineTransform tf)
Check the current transform.
void
concatenate(AffineTransform tf)
Concatenates the given AffineTransform to the current one.
AffineTransform
getBaseTransform()
Get a copy of the base transform for the page.
PDFState.Data
getData()
PDFGState
getGState()
Get the graphics state.
int
getStackLevel()
Get the current stack level.
AffineTransform
getTransform()
Get the current transform.
PDFState.Data
pop()
Pop the state from the stack and set current values to popped state.
void
push()
Push the current state onto the stack.
boolean
setBackColor(Color col)
Set the current background color.
void
setClip(Shape cl)
Set the current clip.
boolean
setColor(Color col)
Set the current color.
boolean
setLineWidth(float width)
Set the current line width.
boolean
setPaint(Paint p)
Set the current paint.
void
setTransform(AffineTransform tf)
Deprecated. This method name is misleading.

Constructor Details

PDFState

public PDFState()
PDF State for storing graphics state.

Method Details

checkClip

public boolean checkClip(Shape cl)
Check if the clip will change the current state. A clip is assumed to be used in a situation where it will add to any clip in the current or parent states. A clip cannot be cleared, this can only be achieved by going to a parent level with the correct clip. If the clip is different then it may start a new state so that it can return to the previous clip.
Parameters:
cl - the clip shape to check
Returns:
true if the clip will change the current clip.

checkTransform

public boolean checkTransform(AffineTransform tf)
Check the current transform. The transform for the current state is the combination of all transforms in the current state. The parameter is compared against this current transform.
Parameters:
tf - the transform the check against
Returns:
true if the new transform is different then the current transform

concatenate

public void concatenate(AffineTransform tf)
Concatenates the given AffineTransform to the current one.
Parameters:
tf - the transform to concatenate to the current level transform

getBaseTransform

public AffineTransform getBaseTransform()
Get a copy of the base transform for the page. Used to translate IPP/BPP values into X,Y positions when positioning is "fixed".
Returns:
the base transform, or null if the state stack is empty

getData

public PDFState.Data getData()
Returns:
the currently valid state

getGState

public PDFGState getGState()
Get the graphics state. This gets the combination of all graphic states for the current context. This is the graphic state set with the gs operator not the other graphic state changes.
Returns:
the calculated ExtGState in the current context

getStackLevel

public int getStackLevel()
Get the current stack level.
Returns:
the current stack level

getTransform

public AffineTransform getTransform()
Get the current transform. This gets the combination of all transforms in the current state.
Returns:
the calculate combined transform for the current state

pop

public PDFState.Data pop()
Pop the state from the stack and set current values to popped state. This should be called when a Q operator is used so the state is restored to the correct values.
Returns:
the restored state, null if the stack is empty

push

public void push()
Push the current state onto the stack. This call should be used when the q operator is used so that the state is known when popped.

setBackColor

public boolean setBackColor(Color col)
Set the current background color. Check if the background color will change and then set the new color.
Parameters:
col - the new background color
Returns:
true if the background color has changed

setClip

public void setClip(Shape cl)
Set the current clip. This either sets a new clip or sets the clip to the intersect of the old clip and the new clip.
Parameters:
cl - the new clip in the current state

setColor

public boolean setColor(Color col)
Set the current color. Check if the new color is a change and then set the current color.
Parameters:
col - the color to set
Returns:
true if the color has changed

setLineWidth

public boolean setLineWidth(float width)
Set the current line width.
Parameters:
width - the line width in points
Returns:
true if the line width has changed

setPaint

public boolean setPaint(Paint p)
Set the current paint. This checks if the paint will change and then sets the current paint.
Parameters:
p - the new paint
Returns:
true if the new paint changes the current paint

setTransform

public void setTransform(AffineTransform tf)

Deprecated. This method name is misleading. Use concatenate(AffineTransform) instead!

Set a new transform. This transform is appended to the transform of the current graphic state.
Parameters:
tf - the transform to concatonate to the current level transform

Copyright 1999-2007 The Apache Software Foundation. All Rights Reserved.