SetaPDF_Core_Text_Block Class representing a text block which can be drawn onto a canvas object

File: /SetaPDF v2/Core/Text/Block.php

Class hierarchy

Summary

Properties

$_align

protected string SetaPDF_Core_Text_Block::$_align = 'left'

The text alignment

$_backgroundColor

$_borderColor

$_borderWidth

protected integer|float SetaPDF_Core_Text_Block::$_borderWidth = 0

The border width

$_charSpacing

protected integer|float SetaPDF_Core_Text_Block::$_charSpacing = 0

The character spacing value

$_dataCache

protected array SetaPDF_Core_Text_Block::$_dataCache = array()

An array for caching calculation results

$_dataCacheClearCallback

A callback which is called if the internal data cache is cleared

$_encoding

protected string SetaPDF_Core_Text_Block::$_encoding = 'UTF-8'

The encoding of the text

$_fontSize

protected float|integer SetaPDF_Core_Text_Block::$_fontSize = 12

The font size

$_internalText

The text string in UTF-16BE encoding for internal usage

$_lineHeight

protected null|integer|float SetaPDF_Core_Text_Block::$_lineHeight

The line height

$_outlineColor

The color of the text outline

$_outlineWidth

protected integer|float SetaPDF_Core_Text_Block::$_outlineWidth = 1.0

The outline width

$_paddingBottom

protected integer|float SetaPDF_Core_Text_Block::$_paddingBottom = 0

Padding bottom value

$_paddingLeft

protected integer|float SetaPDF_Core_Text_Block::$_paddingLeft = 0

Padding left value

$_paddingRight

protected integer|float SetaPDF_Core_Text_Block::$_paddingRight = 0

Padding right value

$_paddingTop

protected integer|float SetaPDF_Core_Text_Block::$_paddingTop = 0

Padding top value

$_renderingMode

The rendering mode

$_text

protected string SetaPDF_Core_Text_Block::$_text

The text in user defined encoding

$_textColor

$_underline

protected bool SetaPDF_Core_Text_Block::$_underline = false

Flag saying whether to draw the underline or not.

$_underlineColor

The color of the text underline.

If the color is defined as null, we will use the text color instead.

$_width

protected integer|float SetaPDF_Core_Text_Block::$_width

A specific width of this text stamp

$_wordSpacing

protected integer|float SetaPDF_Core_Text_Block::$_wordSpacing = 0

Word spacing value


Methods

__construct()

public SetaPDF_Core_Text_Block::__construct (
SetaPDF_Core_Font_FontInterface $font [, integer|float $fontSize = null ]
)

The constructor.

Parameters
$font : SetaPDF_Core_Font_FontInterface
 
$fontSize : integer|float
 

_clearDataCache()

protected SetaPDF_Core_Text_Block::_clearDataCache (
void
): void

Clears the internal data cache.

_drawBorderAndBackground()

protected SetaPDF_Core_Text_Block::_drawBorderAndBackground (
SetaPDF_Core_Canvas $canvas, integer|float $x, integer|float $y
): void

Draws the border and background onto the canvas.

Parameters
$canvas : SetaPDF_Core_Canvas
 
$x : integer|float

The lower left x-value of the text block

$y : integer|float

The lower left y-value of the text block

_drawRenderingMode()

Adds rendering mode specific data onto the canvas.

Parameters
$canvas : SetaPDF_Core_Canvas
 

_drawText()

protected SetaPDF_Core_Text_Block::_drawText (
SetaPDF_Core_Canvas $canvas, integer|float $x, integer|float $y
): void

Draws the text onto the canvas.

Parameters
$canvas : SetaPDF_Core_Canvas
 
$x : integer|float

The lower left x-value of the text block

$y : integer|float

The lower left y-value of the text block

Exceptions

Throws SetaPDF_Core_Exception

Throws SetaPDF_Core_Font_Exception

Throws SetaPDF_Core_Type_Exception

Throws SetaPDF_Core_Type_IndirectReference_Exception

Throws SetaPDF_Exception_NotImplemented

_fixX()

protected SetaPDF_Core_Text_Block::_fixX (
integer|float $x
): integer|float

Get the correct x-value for the text string to start writing.

Parameters
$x : integer|float
 

_fixY()

protected SetaPDF_Core_Text_Block::_fixY (
integer|float $y
): integer|float

Get the correct y-value for the text string to start writing.

Parameters
$y : integer|float
 

_getLines()

protected SetaPDF_Core_Text_Block::_getLines (
void
): array

Get the text as lines and caches the result.

_getManualLineBreaks()

Get line numbers which use a manual line break.

_getTextWidth()

private SetaPDF_Core_Text_Block::_getTextWidth (
int|float $fontSize, array $lines
): int|mixed

Get the text width by an array of text lines.

Parameters
$fontSize : int|float
 
$lines : array
 

cleanUp()

public SetaPDF_Core_Text_Block::cleanUp (
void
): void

Release resources / cycled references.

draw()

public SetaPDF_Core_Text_Block::draw (
SetaPDF_Core_Canvas $canvas, integer|float $x, integer|float $y
): void

Draws the text block onto a canvas.

Parameters
$canvas : SetaPDF_Core_Canvas
 
$x : integer|float

The lower left x-value of the text block

$y : integer|float

The lower left y-value of the text block

Exceptions

Throws SetaPDF_Core_Exception

Throws SetaPDF_Core_Font_Exception

Throws SetaPDF_Core_Type_Exception

Throws SetaPDF_Core_Type_IndirectReference_Exception

Throws SetaPDF_Exception_NotImplemented

getAlign()

public SetaPDF_Core_Text_Block::getAlign (
void
): string

Get the text alignment.

getBackgroundColor()

Get the background color object.

getBorderColor()

Get the border color object.

If no border color is defined a greyscale black color will be returned.

getBorderWidth()

public SetaPDF_Core_Text_Block::getBorderWidth (
void
): integer|float

Get the border width.

getCharSpacing()

public SetaPDF_Core_Text_Block::getCharSpacing (
void
): integer|float

Get the character spacing value.

getFont()

Get the font object.

getFontSize()

public SetaPDF_Core_Text_Block::getFontSize (
void
): integer|float

Get the font size.

If the font size was initially set to -1 this method will calculate the font size based on the available width and the text content.

getHeight()

public SetaPDF_Core_Text_Block::getHeight (
void
): integer|float

Get the height of this text block.

Calculation is done by number of lines, line-height and top and bottom padding values.

See

getLineCount()

Get the line count of the text block.

getLineHeight()

public SetaPDF_Core_Text_Block::getLineHeight (
void
): integer|float

Get the line height / leading.

If no explicit line height is defined this method will return a line height based on the lly and ury values of the font bounding box.

getOutlineColor()

Get the texts outline color object.

If no outline color is defined a greyscale black color will be returned. The outline color is only used at specific rendering modes.

See

getOutlineWidth()

Get the outline width.

The outline width is only used at specific rendering modes.

getPaddingBottom()

public SetaPDF_Core_Text_Block::getPaddingBottom (
void
): integer|float

Get the bottom padding.

getPaddingLeft()

public SetaPDF_Core_Text_Block::getPaddingLeft (
void
): integer|float

Get the left padding.

getPaddingRight()

public SetaPDF_Core_Text_Block::getPaddingRight (
void
): integer|float

Get the right padding.

getPaddingTop()

public SetaPDF_Core_Text_Block::getPaddingTop (
void
): integer|float

Get the top padding.

getRenderingMode()

public SetaPDF_Core_Text_Block::getRenderingMode (
void
): integer

Get the defined rendering mode.

See

getText()

public SetaPDF_Core_Text_Block::getText (
[ string $encoding = 'UTF-8' ]
): string

Get the text.

Parameters
$encoding : string
 

getTextColor()

Get the text color object.

If no text color is defined a greyscale black color will be returned.

getTextHeight()

public SetaPDF_Core_Text_Block::getTextHeight (
void
): float|integer

Get the height of the text.

getTextWidth()

public SetaPDF_Core_Text_Block::getTextWidth (
void
): integer|float

Get the width of the longest text line.

getUnderline()

public SetaPDF_Core_Text_Block::getUnderline (
void
): bool

Gets whether to draw an underline or not.

getUnderlineColor()

Get the underline color.

If no underline color is defined the text color is returned.

getWidth()

public SetaPDF_Core_Text_Block::getWidth (
void
): integer|float

Get the width of the stamp object.

This method returns the complete width of the text block. To get only the width of the text use the getTextWidth() method.

getWordSpacing()

public SetaPDF_Core_Text_Block::getWordSpacing (
void
): integer|float

Get the word spacing value.

setAlign()

public SetaPDF_Core_Text_Block::setAlign (
string $align
): void

Set the text alignment.

Parameters
$align : string
 
See

setBackgroundColor()

setBorderColor()

setBorderWidth()

public SetaPDF_Core_Text_Block::setBorderWidth (
integer|float $borderWidth
): void

Set the border width.

Parameters
$borderWidth : integer|float
 

setCharSpacing()

public SetaPDF_Core_Text_Block::setCharSpacing (
integer|float $charSpacing
): void

Set the character spacing value.

Parameters
$charSpacing : integer|float
 

setDataCacheClearCallback()

public SetaPDF_Core_Text_Block::setDataCacheClearCallback (
callback $callback
): void

Sets a callback function which is called if the internal cache is cleared.

Parameters
$callback : callback
 

setFont()

public SetaPDF_Core_Text_Block::setFont (
SetaPDF_Core_Font_FontInterface $font [, integer|float $fontSize = null ]
): void

Set the font object and size.

Parameters
$font : SetaPDF_Core_Font_FontInterface
 
$fontSize : integer|float
 

setFontSize()

public SetaPDF_Core_Text_Block::setFontSize (
integer|float $fontSize
): void

Set the font size.

If -1 is passed the font size is calculated based on the available width and the text content.

Parameters
$fontSize : integer|float
 

setLineHeight()

public SetaPDF_Core_Text_Block::setLineHeight (
float|integer|null $lineHeight
): void

Set the line height / leading.

Parameters
$lineHeight : float|integer|null
 

setOutlineWidth()

public SetaPDF_Core_Text_Block::setOutlineWidth (
float $outlineWidth
): void

Set the outline width.

The outline width is only used at specific rendering modes.

Parameters
$outlineWidth : float
 

setPadding()

public SetaPDF_Core_Text_Block::setPadding (
integer|float $padding
): void

Set the padding.

Parameters
$padding : integer|float
 

setPaddingBottom()

public SetaPDF_Core_Text_Block::setPaddingBottom (
integer|float $paddingBottom
): void

Set the bottom padding.

Parameters
$paddingBottom : integer|float
 

setPaddingLeft()

public SetaPDF_Core_Text_Block::setPaddingLeft (
integer|float $paddingLeft
): void

Set the left padding.

Parameters
$paddingLeft : integer|float
 

setPaddingRight()

public SetaPDF_Core_Text_Block::setPaddingRight (
integer|float $paddingRight
): void

Set the right padding.

Parameters
$paddingRight : integer|float
 

setPaddingTop()

public SetaPDF_Core_Text_Block::setPaddingTop (
integer|float $paddingTop
): void

Set the top padding.

Parameters
$paddingTop : integer|float
 

setRenderingMode()

public SetaPDF_Core_Text_Block::setRenderingMode (
[ integer $renderingMode = 0 ]
): void

Set the rendering mode.

Parameters
$renderingMode : integer
 
See

setText()

public SetaPDF_Core_Text_Block::setText (
string $text [, string $encoding = 'UTF-8' ]
): void

Set the text.

Parameters
$text : string
 
$encoding : string

The encoding of $text

setTextWidth()

public SetaPDF_Core_Text_Block::setTextWidth (
integer|float $width
): void

Set the width of the text.

Parameters
$width : integer|float
 

setUnderline()

public SetaPDF_Core_Text_Block::setUnderline (
bool $underline
): void

Set whether to draw an underline or not.

If you want an underline color that differs from the text color use setUnderlineColor().

Parameters
$underline : bool
 

setWidth()

public SetaPDF_Core_Text_Block::setWidth (
integer|float $width
): void
Parameters
$width : integer|float
 
See

setWordSpacing()

public SetaPDF_Core_Text_Block::setWordSpacing (
integer|float $wordSpacing
): void

Set the word spacing value.

Parameters
$wordSpacing : integer|float