SetaPDF_Core_Canvas A class representing a Canvas

File: /SetaPDF/Core/Canvas.php

Class hierarchy

Implements

Summary

Constants

GS_SYNC_COLOR

GS_SYNC_CURRENT_TRANSFORMATION_MATRIX

GS_SYNC_TEXT


Properties

$_cache

protected string SetaPDF_Core_Canvas::$_cache = ''

Cached written content

$_cacheOutput

protected boolean SetaPDF_Core_Canvas::$_cacheOutput = false

Should the output be cached or not

$_canvasContainer

$_draw

Draw helper instance

$_graphicState

$_graphicStateSync

Sync level

$_markedContent

A helper instance for marked content

$_path

Path helper instance

$_text

Text helper instance


Methods

__construct()

public SetaPDF_Core_Canvas::__construct ( SetaPDF_Core_Canvas_ContainerInterface $canvasContainer )

The constructor.

Parameters
$canvasContainer : SetaPDF_Core_Canvas_ContainerInterface

The canvas container

addCurrentTransformationMatrix()

public SetaPDF_Core_Canvas SetaPDF_Core_Canvas::addCurrentTransformationMatrix ( int|float $a, int|float $b, int|float $c, int|float $d, int|float $e, int|float $f )

Add a transformation matrix to the matrix stack of the current graphic state.

Parameters
$a : int|float

A

$b : int|float

B

$c : int|float

C

$d : int|float

D

$e : int|float

E

$f : int|float

F

See
  • PDF-Reference PDF 32000-1:2008 8.3.4 Transformation Matrices

addResource()

public string SetaPDF_Core_Canvas::addResource ( string|SetaPDF_Core_Resource $type [, SetaPDF_Core_Resource|SetaPDF_Core_Type_IndirectObjectInterface $object = null [, SetaPDF_Core_Document $document = null ]] )

Add a resource to the pages/xobjects resources dictionary.

Parameters
$type : string|SetaPDF_Core_Resource

The resource type (Font, XObject, ExtGState,...) or an implementation of SetaPDF_Core_Resource

$object : SetaPDF_Core_Resource|SetaPDF_Core_Type_IndirectObjectInterface

The resource to add

$document : SetaPDF_Core_Document

The document instance

Return Values

The name of the added resource.

Exceptions

Throws InvalidArgumentException

cleanUp()

public void SetaPDF_Core_Canvas::cleanUp ( void )

Release objects to free memory and cycled references.

After calling this method the instance of this object is unusable!

clear()

public void SetaPDF_Core_Canvas::clear ( void )

Clears the complete canvas content.

draw()

public SetaPDF_Core_Canvas_Draw SetaPDF_Core_Canvas::draw ( void )

Get the draw helper.

drawXObject()

public SetaPDF_Core_Canvas SetaPDF_Core_Canvas::drawXObject ( string $name )

Draw an external object.

If a form XObject instance is passed, it will be added to the resources automatically.

Parameters
$name : string

The name or a form XObject instance.

Exceptions

Throws InvalidArgumentException

getCache()

public string SetaPDF_Core_Canvas::getCache ( void )

Returns the cache.

getContainer()

public SetaPDF_Core_Canvas_ContainerInterface SetaPDF_Core_Canvas_Simple::getContainer ( void )

Get the container of the canvas (origin object).

getGraphicStateSync()

public int SetaPDF_Core_Canvas::getGraphicStateSync ( void )

Get the bitmask that defines which values should be synced with the graphic state object.

See

getHeight()

public float SetaPDF_Core_Canvas::getHeight ( void )

Get the height of the canvas.

getResources()

public bool|SetaPDF_Core_Type_AbstractType SetaPDF_Core_Canvas_Simple::getResources ( [ boolean $inherited = true [, boolean $create = false [, string $entryKey = null ]]] )

Returns the resources dictionary or an entry of it.

If no resource dictionary exists it is possible to automatically create it and/or the desired entry.

Parameters
$inherited : boolean

Check for a resources dictionary in parent nodes

$create : boolean

Create dictionary/ies if they do not exists

$entryKey : string

The entries key (Font, XObject,...)

Return Values

Returns the resources object or dictionary or false if none was found.

getStream()

public string SetaPDF_Core_Canvas::getStream ( void )

Get the whole byte stream of the canvas.

See

getStreamProxy()

public SetaPDF_Core_Canvas_StreamProxyInterface SetaPDF_Core_Canvas::getStreamProxy ( void )

Get the stream proxy.

getUserSpaceXY()

public array SetaPDF_Core_Canvas::getUserSpaceXY ( int $x, int $y )

Returns the user space coordinates of the transformation matrix.

Parameters
$x : int

x-coordinate

$y : int

y-coordinate

Return Values

('x' => $x, 'y' => $y)

See

getWidth()

public float SetaPDF_Core_Canvas::getWidth ( void )

Get the width of the canvas.

graphicState()

public SetaPDF_Core_Canvas_GraphicState SetaPDF_Core_Canvas::graphicState ( void )

Return the graphic state object if no graphic state is defined an new instance will be initialized.

markedContent()

public SetaPDF_Core_Canvas_MarkedContent SetaPDF_Core_Canvas::markedContent ( void )

Get the marked content helper.

normalizeRotation()

public bool SetaPDF_Core_Canvas::normalizeRotation ( number $rotation, SetaPDF_Core_DataStructure_Rectangle $box )

Normalize the graphic state in view to an outer rotation (e.g. page rotation).

Parameters
$rotation : number
 
$box : SetaPDF_Core_DataStructure_Rectangle
 

path()

public SetaPDF_Core_Canvas_Path SetaPDF_Core_Canvas::path ( void )

Get the path helper.

restoreGraphicState()

public SetaPDF_Core_Canvas SetaPDF_Core_Canvas::restoreGraphicState ( void )

Restore the last graphic state and pop all matrices of the current graphic state out of the matrix stack.

rotate()

public SetaPDF_Core_Canvas SetaPDF_Core_Canvas::rotate ( int|float $x, int|float $y, float $angle )

Rotate the transformation matrix by $angle degrees at the origin defined by $x and $y.

Parameters
$x : int|float

X-coordinate of rotation point

$y : int|float

Y-coordinate of rotation point

$angle : float

Angle to rotate in degrees

saveGraphicState()

public SetaPDF_Core_Canvas SetaPDF_Core_Canvas::saveGraphicState ( void )

Open a new graphic state and copy the entire graphic state onto the stack of the new graphic state.

scale()

public SetaPDF_Core_Canvas SetaPDF_Core_Canvas::scale ( int|float $scaleX, int|float $scaleY )

Scale the transformation matrix by the factor $scaleX and $scaleY.

Parameters
$scaleX : int|float

Scale factor on X

$scaleY : int|float

Scale factor on Y

setColor()

public SetaPDF_Core_Canvas SetaPDF_Core_Canvas::setColor ( SetaPDF_Core_DataStructure_Color|array|int|string $color [, boolean $stroking = true ] )

Set the color.

Parameters
$color : SetaPDF_Core_DataStructure_Color|array|int|string

The color

$stroking : boolean

Do stroking?

setColorSpace()

public SetaPDF_Core_Canvas SetaPDF_Core_Canvas::setColorSpace ( SetaPDF_Core_ColorSpace|SetaPDF_Core_Type_Name|string $colorSpace [, bool $stroking = true ] )

Set the current color space.

Parameters
$colorSpace : SetaPDF_Core_ColorSpace|SetaPDF_Core_Type_Name|string

The color space

$stroking : bool

Do stroking?

setGraphicState()

public SetaPDF_Core_Canvas SetaPDF_Core_Canvas::setGraphicState ( SetaPDF_Core_Resource_ExtGState $graphicState [, SetaPDF_Core_Document $document = null ] )

Set a named graphic state.

Parameters
$graphicState : SetaPDF_Core_Resource_ExtGState

The graphic state

$document : SetaPDF_Core_Document
 
Exceptions

Throws InvalidArgumentException

setGraphicStateSync()

public void SetaPDF_Core_Canvas::setGraphicStateSync ( integer $graphicStateSync )

Set the bitmask defining, which values should be synced with the graphic state object.

Parameters
$graphicStateSync : integer
 

setNonStrokingColor()

public SetaPDF_Core_Canvas SetaPDF_Core_Canvas::setNonStrokingColor ( SetaPDF_Core_DataStructure_Color|array|int|string $color )

Set the non-stroking color.

Parameters
$color : SetaPDF_Core_DataStructure_Color|array|int|string

The non-stroking color

setNonStrokingColorSpace()

public SetaPDF_Core_Canvas SetaPDF_Core_Canvas::setNonStrokingColorSpace ( SetaPDF_Core_ColorSpace|SetaPDF_Core_Type_Name|string $colorSpace )

Set the non-stroking color space.

Parameters
$colorSpace : SetaPDF_Core_ColorSpace|SetaPDF_Core_Type_Name|string

The color space

setResource()

public string SetaPDF_Core_Canvas::setResource ( string $type, string $name, SetaPDF_Core_Resource|SetaPDF_Core_Type_IndirectObjectInterface $object [, SetaPDF_Core_Document $document = null ] )

Set a resource for the canvas.

Parameters
$type : string

The resource type (Font, XObject, ExtGState,...) or an implementation of SetaPDF_Core_Resource

$name : string

The name of the resource

$object : SetaPDF_Core_Resource|SetaPDF_Core_Type_IndirectObjectInterface
 
$document : SetaPDF_Core_Document
 
Exceptions

Throws InvalidArgumentException

setStrokingColor()

public SetaPDF_Core_Canvas SetaPDF_Core_Canvas::setStrokingColor ( SetaPDF_Core_DataStructure_Color|array|int|string $color )

Set the stroking color.

Parameters
$color : SetaPDF_Core_DataStructure_Color|array|int|string

The stroking color

setStrokingColorSpace()

public SetaPDF_Core_Canvas SetaPDF_Core_Canvas::setStrokingColorSpace ( SetaPDF_Core_ColorSpace|SetaPDF_Core_Type_Name|string $colorSpace )

Set the stroking color space.

Parameters
$colorSpace : SetaPDF_Core_ColorSpace|SetaPDF_Core_Type_Name|string

The color space

skew()

public SetaPDF_Core_Canvas SetaPDF_Core_Canvas::skew ( float $angleX, float $angleY [, int $x = 0 [, int $y = 0 ]] )

Skew the transformation matrix.

Parameters
$angleX : float

Angle to x-axis in degrees

$angleY : float

Angle to y-axis in degrees

$x : int

Points to stretch on x-axis

$y : int

Point to stretch on y-axis

startCache()

public void SetaPDF_Core_Canvas::startCache ( void )

Start caching.

The output of write() will be cached.

This will also clear the cache.

stopCache()

public void SetaPDF_Core_Canvas::stopCache ( void )

Stop caching the output of write().

This will also clear the cache.

text()

public SetaPDF_Core_Canvas_Text SetaPDF_Core_Canvas::text ( void )

Get the text helper.

toUserSpace()

public SetaPDF_Core_Geometry_Vector SetaPDF_Core_Canvas::toUserSpace ( SetaPDF_Core_Geometry_Vector $vector )

Returns the user space coordinates vector.

Parameters
$vector : SetaPDF_Core_Geometry_Vector
 

translate()

public SetaPDF_Core_Canvas SetaPDF_Core_Canvas::translate ( int|float $shiftX, int|float $shiftY )

Move the transformation matrix by $shiftX and $shiftY on x-axis and y-axis.

Parameters
$shiftX : int|float

Points to move on x-axis

$shiftY : int|float

Points to move on y-axis

write()

public void SetaPDF_Core_Canvas::write ( string $bytes )

Writes bytes to the canvas content stream.

Parameters
$bytes : string

The bytes to write

See