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
Methods
- __construct()
- addCurrentTransformationMatrix()
- addResource()
- cleanUp()
- clear()
- draw()
- drawXObject()
- getCache()
- getContainer()
- getGraphicStateSync()
- getHeight()
- getResources()
- getStream()
- getStreamProxy()
- getUserSpaceXY()
- getWidth()
- graphicState()
- markedContent()
- normalizeRotation()
- normalizeRotationAndOrigin()
- path()
- restoreGraphicState()
- rotate()
- saveGraphicState()
- scale()
- setColor()
- setColorSpace()
- setGraphicState()
- setGraphicStateSync()
- setNonStrokingColor()
- setNonStrokingColorSpace()
- setResource()
- setStrokingColor()
- setStrokingColorSpace()
- skew()
- startCache()
- stopCache()
- text()
- toUserSpace()
- translate()
- write()
Constants
GS_SYNC_COLOR
GS_SYNC_CURRENT_TRANSFORMATION_MATRIX
GS_SYNC_TEXT
Properties
$_canvasContainer
The main dictionary of the canvas
$_graphicState
A graphic state instance
$_markedContent
A helper instance for marked content
$_streamProxy
The writer
Methods
__construct()
addCurrentTransformationMatrix()
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()
\setasign\SetaPDF2\Core\Resource\ResourceInterface|\setasign\SetaPDF2\Core\Type\IndirectObjectInterface $object = null,
?\setasign\SetaPDF2\Core\Document $document = null
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
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
getGraphicStateSync()
Get the bitmask that defines which values should be synced with the graphic state object.
See
getResources()
bool $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 : 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
getUserSpaceXY()
WARNING: This method is marked as deprecated!
Use toUserSpace() instead.
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
graphicState()
Return the graphic state object if no graphic state is defined an new instance will be initialized.
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
restoreGraphicState()
Restore the last graphic state and pop all matrices of the current graphic state out of the matrix stack.
rotate()
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.
setColor()
bool $stroking = true
Set the color.
Parameters
- $color : \setasign\SetaPDF2\Core\DataStructure\Color\AbstractColor|int[]|int|string
The color
- $stroking : bool
Do stroking?
setColorSpace()
bool $stroking = true
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()
?\setasign\SetaPDF2\Core\Document $document = null
Set a named graphic state.
Parameters
- $graphicState : \setasign\SetaPDF2\Core\Resource\ExtGState
The graphic state
- $document : ?\setasign\SetaPDF2\Core\Document
Exceptions
Throws \InvalidArgumentException
setGraphicStateSync()
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()
Set the non-stroking color space.
Parameters
- $colorSpace : \setasign\SetaPDF2\Core\ColorSpace\ColorSpace|\setasign\SetaPDF2\Core\Type\PdfName|string
The color space
setResource()
string $name,
\setasign\SetaPDF2\Core\Resource\ResourceInterface|\setasign\SetaPDF2\Core\Type\IndirectObjectInterface $object,
?\setasign\SetaPDF2\Core\Document $document = null
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()
Set the stroking color space.
Parameters
- $colorSpace : \setasign\SetaPDF2\Core\ColorSpace\ColorSpace|\setasign\SetaPDF2\Core\Type\PdfName|string
The color space
toUserSpace()
Returns the user space coordinates vector.
Parameters
- $vector : \setasign\SetaPDF2\Core\Geometry\Vector