setasign\SetaPDF2\Core\Canvas

Canvas A class representing a Canvas

File: /SetaPDF v2/Core/Canvas/Canvas.php
Old class name (alias): \SetaPDF_Core_Canvas

Class hierarchy

Implements

Summary

Constants

GS_SYNC_COLOR

public const Canvas::GS_SYNC_COLOR = 4

GS_SYNC_CURRENT_TRANSFORMATION_MATRIX

GS_SYNC_TEXT

public const Canvas::GS_SYNC_TEXT = 2

Properties

$_cache

protected string Canvas::$_cache = ''

Cached written content

$_cacheOutput

protected bool Canvas::$_cacheOutput = false

Should the output be cached or not

$_canvasContainer

The main dictionary of the canvas

$_draw

protected Draw Canvas::$_draw

Draw helper instance

$_graphicState

A graphic state instance

$_graphicStateSync

protected int Canvas::$_graphicStateSync = 1

Sync level

$_markedContent

A helper instance for marked content

$_path

protected Path Canvas::$_path

Path helper instance

$_streamProxy

The writer

$_text

protected Text Canvas::$_text

Text helper instance


Methods

__construct()

public Canvas::__construct (
ContainerInterface $canvasContainer
)

The constructor.

Parameters
$canvasContainer : ContainerInterface

The canvas container

addCurrentTransformationMatrix()

public Canvas::addCurrentTransformationMatrix (
int|float $a,
int|float $b,
int|float $c,
int|float $d,
int|float $e,
int|float $f
): 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|\setasign\SetaPDF2\Core\Resource\ResourceInterface

The resource type (Font, XObject, ExtGState,...) or an implementation of \setasign\SetaPDF2\Core\Resource\ResourceInterface

$object : \setasign\SetaPDF2\Core\Resource\ResourceInterface|\setasign\SetaPDF2\Core\Type\IndirectObjectInterface

The resource to add

$document : ?\setasign\SetaPDF2\Core\Document

The document instance

Return Values

The name of the added resource.

Exceptions

Throws \InvalidArgumentException

cleanUp()

public 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 Canvas::clear (
void
): void

Clears the complete canvas content.

draw()

public Canvas::draw (
void
): 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|\setasign\SetaPDF2\Core\XObject\XObject

The name or a form XObject instance.

Exceptions

Throws \setasign\SetaPDF2\Core\Type\Exception

Throws \InvalidArgumentException

getCache()

public Canvas::getCache (
void
): string

Returns the cache.

getContainer()

Get the container of the canvas (origin object).

getGraphicStateSync()

public Canvas::getGraphicStateSync (
void
): int

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

See

getHeight()

public Canvas::getHeight (
void
): float

Get the height of the canvas.

getResources()

public Simple::getResources (
bool $inherited = true,
bool $create = false,
string $entryKey = null
): false|\setasign\SetaPDF2\Core\Type\PdfDictionary|\setasign\SetaPDF2\Core\Type\PdfArray

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 : bool

Check for a resources dictionary in parent nodes

$create : bool

Create dictionary/ies if they do not exist

$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 \setasign\SetaPDF2\Core\Type\Exception

getStream()

public Canvas::getStream (
bool $ignoreFaultyStreams = false
): string

Get the whole byte stream of the canvas.

Parameters
$ignoreFaultyStreams : bool
 
See

getStreamProxy()

Get the stream proxy.

getUserSpaceXY()

WARNING: This method is marked as deprecated!

Use toUserSpace() instead.

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

Get the width of the canvas.

graphicState()

public Canvas::graphicState (
void
): 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 : \setasign\SetaPDF2\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 : \setasign\SetaPDF2\Core\DataStructure\Rectangle
 

path()

public Canvas::path (
void
): 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 Canvas::rotate (
int|float $x,
int|float $y,
float $angle
): 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()

public Canvas::saveGraphicState (
void
): Canvas

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

scale()

public Canvas::scale (
int|float $scaleX,
int|float $scaleY
): 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 Canvas::setColor (
\setasign\SetaPDF2\Core\DataStructure\Color\AbstractColor|int[]|int|string $color,
bool $stroking = true
): Canvas

Set the color.

Parameters
$color : \setasign\SetaPDF2\Core\DataStructure\Color\AbstractColor|int[]|int|string

The color

$stroking : bool

Do stroking?

setColorSpace()

Set the current color space.

Parameters
$colorSpace : \setasign\SetaPDF2\Core\ColorSpace\ColorSpace|\setasign\SetaPDF2\Core\Type\PdfName|string

The color space

$stroking : bool

Do stroking?

setGraphicState()

Set a named graphic state.

Parameters
$graphicState : \setasign\SetaPDF2\Core\Resource\ExtGState

The graphic state

$document : ?\setasign\SetaPDF2\Core\Document
 
Exceptions

Throws \InvalidArgumentException

setGraphicStateSync()

public Canvas::setGraphicStateSync (
int $graphicStateSync
): void

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

Parameters
$graphicStateSync : int
 

setNonStrokingColor()

Set the non-stroking color.

Parameters
$color : \setasign\SetaPDF2\Core\DataStructure\Color\AbstractColor|int[]|int|string

The non-stroking color

setNonStrokingColorSpace()

setResource()

Set a resource for the canvas.

Parameters
$type : string

The resource type (Font, XObject, ExtGState,...) or an implementation of \setasign\SetaPDF2\Core\Resource\ResourceInterface

$name : string

The name of the resource

$object : \setasign\SetaPDF2\Core\Resource\ResourceInterface|\setasign\SetaPDF2\Core\Type\IndirectObjectInterface
 
$document : ?\setasign\SetaPDF2\Core\Document
 
Exceptions

Throws \InvalidArgumentException

setStrokingColor()

Set the stroking color.

Parameters
$color : \setasign\SetaPDF2\Core\DataStructure\Color\AbstractColor|int[]|int|string

The stroking color

setStrokingColorSpace()

skew()

public Canvas::skew (
float $angleX,
float $angleY,
int $x = 0,
int $y = 0
): 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 Canvas::startCache (
void
): void

Start caching.

The output of write() will be cached.

This will also clear the cache.

stopCache()

public Canvas::stopCache (
void
): void

Stop caching the output of write().

This will also clear the cache.

text()

public Canvas::text (
void
): Text

Get the text helper.

toUserSpace()

translate()

public Canvas::translate (
int|float $shiftX,
int|float $shiftY
): 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 Canvas::write (
string $bytes
): void

Writes bytes to the canvas content stream.

Parameters
$bytes : string

The bytes to write

See