SetaPDF_Core_Canvas A class representing a Canvas

File: /SetaPDF v2/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()

The constructor.

Parameters
$canvasContainer : SetaPDF_Core_Canvas_ContainerInterface

The canvas container

addCurrentTransformationMatrix()

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

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()

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 SetaPDF_Core_Canvas::cleanUp (
void
): void

Release objects to free memory and cycled references.

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

clear()

public SetaPDF_Core_Canvas::clear (
void
): void

Clears the complete canvas content.

draw()

Get the draw helper.

drawXObject()

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 SetaPDF_Core_Canvas::getCache (
void
): string

Returns the cache.

getContainer()

Get the container of the canvas (origin object).

getGraphicStateSync()

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

See

getHeight()

public SetaPDF_Core_Canvas::getHeight (
void
): float

Get the height of the canvas.

getResources()

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

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 dictionary, a dictionary by an entry key or false if none was found.

Exceptions

Throws SetaPDF_Core_Type_Exception

getStream()

public SetaPDF_Core_Canvas::getStream (
[ bool $ignoreFaultyStreams = false ]
): string

Get the whole byte stream of the canvas.

Parameters
$ignoreFaultyStreams : bool
 
See

getStreamProxy()

getUserSpaceXY()

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

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 SetaPDF_Core_Canvas::getWidth (
void
): float

Get the width of the canvas.

graphicState()

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

markedContent()

Get the marked content helper.

normalizeRotation()

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

Parameters
$rotation : number
 
$box : SetaPDF_Core_DataStructure_Rectangle
 

normalizeRotationAndOrigin()

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

Parameters
$rotation : number
 
$box : SetaPDF_Core_DataStructure_Rectangle
 

path()

Get the path helper.

restoreGraphicState()

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

rotate()

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

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()

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

scale()

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

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::setColor (
SetaPDF_Core_DataStructure_Color|int[]|int|string $color [, boolean $stroking = true ]
): SetaPDF_Core_Canvas

Set the color.

Parameters
$color : SetaPDF_Core_DataStructure_Color|int[]|int|string

The color

$stroking : boolean

Do stroking?

setColorSpace()

Set the current color space.

Parameters
$colorSpace : SetaPDF_Core_ColorSpace|SetaPDF_Core_Type_Name|string

The color space

$stroking : bool

Do stroking?

setGraphicState()

Set a named graphic state.

Parameters
$graphicState : SetaPDF_Core_Resource_ExtGState

The graphic state

$document : SetaPDF_Core_Document
 
Exceptions

Throws InvalidArgumentException

setGraphicStateSync()

public SetaPDF_Core_Canvas::setGraphicStateSync (
integer $graphicStateSync
): void

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

Parameters
$graphicStateSync : integer
 

setNonStrokingColor()

Set the non-stroking color.

Parameters
$color : SetaPDF_Core_DataStructure_Color|int[]|int|string

The non-stroking color

setNonStrokingColorSpace()

Set the non-stroking color space.

Parameters
$colorSpace : SetaPDF_Core_ColorSpace|SetaPDF_Core_Type_Name|string

The color space

setResource()

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

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()

Set the stroking color.

Parameters
$color : SetaPDF_Core_DataStructure_Color|int[]|int|string

The stroking color

setStrokingColorSpace()

Set the stroking color space.

Parameters
$colorSpace : SetaPDF_Core_ColorSpace|SetaPDF_Core_Type_Name|string

The color space

skew()

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

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 SetaPDF_Core_Canvas::startCache (
void
): void

Start caching.

The output of write() will be cached.

This will also clear the cache.

stopCache()

public SetaPDF_Core_Canvas::stopCache (
void
): void

Stop caching the output of write().

This will also clear the cache.

text()

Get the text helper.

toUserSpace()

Returns the user space coordinates vector.

Parameters
$vector : SetaPDF_Core_Geometry_Vector
 

translate()

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

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 SetaPDF_Core_Canvas::write (
string $bytes
): void

Writes bytes to the canvas content stream.

Parameters
$bytes : string

The bytes to write

See