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

The border width

$_charSpacing

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

$_font

The font to use

$_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|number SetaPDF_Core_Text_Block::$_lineHeight

The line height

$_outlineColor

The color of the text outline

$_outlineWidth

protected number SetaPDF_Core_Text_Block::$_outlineWidth = 1.0

The outline width

$_paddingBottom

Padding bottom value

$_paddingLeft

Padding left value

$_paddingRight

Padding right value

$_paddingTop

Padding top value

$_renderingMode

The rendering mode

$_text

protected string SetaPDF_Core_Text_Block::$_text

The text in user defined encoding

$_textColor

$_width

protected number SetaPDF_Core_Text_Block::$_width

A specific width of this text stamp

$_wordSpacing

Word spacing value


Methods

__construct()

public SetaPDF_Core_Text_Block::__construct (
SetaPDF_Core_Font $font [, number $fontSize = null ]
)

The constructor.

Parameters
$font : SetaPDF_Core_Font
 
$fontSize : number
 

_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, number $x, number $y
): void

Draws the border and background onto the canvas.

Parameters
$canvas : SetaPDF_Core_Canvas
 
$x : number

The lower left x-value of the text block

$y : number

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, number $x, number $y
): void

Draws the text onto the canvas.

Parameters
$canvas : SetaPDF_Core_Canvas
 
$x : number

The lower left x-value of the text block

$y : number

The lower left y-value of the text block

_fixX()

protected SetaPDF_Core_Text_Block::_fixX (
number $x
): number

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

Parameters
$x : number
 

_fixY()

protected SetaPDF_Core_Text_Block::_fixY (
number $y
): number

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

Parameters
$y : number
 

_getLines()

protected SetaPDF_Core_Text_Block::_getLines (
void
): array

Get the text as lines and caches the result.

_getTextWidth()

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

Get the text width by an array of text lines.

Parameters
$fontSize
 
$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, number $x, number $y
): void

Draws the text block onto a canvas.

Parameters
$canvas : SetaPDF_Core_Canvas
 
$x : number

The lower left x-value of the text block

$y : number

The lower left y-value of the text block

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 the a greyscale black color will be returned.

getBorderWidth()

public SetaPDF_Core_Text_Block::getBorderWidth (
void
): number

Get the border width.

getCharSpacing()

public SetaPDF_Core_Text_Block::getCharSpacing (
void
): number

Get the character spacing value.

getFont()

Get the font object.

getFontSize()

public SetaPDF_Core_Text_Block::getFontSize (
void
): number

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
): number

Get the height of this text block.

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

See

getLineCount()

public SetaPDF_Core_Text_Block::getLineCount (
void
): integer

Get the line count of the text block.

getLineHeight()

public SetaPDF_Core_Text_Block::getLineHeight (
void
): number

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 the 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
): number

Get the bottom padding.

getPaddingLeft()

public SetaPDF_Core_Text_Block::getPaddingLeft (
void
): number

Get the left padding.

getPaddingRight()

public SetaPDF_Core_Text_Block::getPaddingRight (
void
): number

Get the right padding.

getPaddingTop()

public SetaPDF_Core_Text_Block::getPaddingTop (
void
): number

Get the top padding.

getRenderingMode()

public SetaPDF_Core_Text_Block::getRenderingMode (
void
): number

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 the a greyscale black color will be returned

getTextHeight()

public SetaPDF_Core_Text_Block::getTextHeight (
void
): number

Get the height of the text.

getTextWidth()

public SetaPDF_Core_Text_Block::getTextWidth (
void
): number

Get the width of the longest text line.

getWidth()

public SetaPDF_Core_Text_Block::getWidth (
void
): number

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.

The value set in setWidth() may be differ to the one returned by this method because of padding values.

getWordSpacing()

public SetaPDF_Core_Text_Block::getWordSpacing (
void
): number

Get the word spacing value.

setAlign()

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

Set the text alignment.

Parameters
$align : string
 

setBackgroundColor()

setBorderWidth()

public SetaPDF_Core_Text_Block::setBorderWidth (
number $borderWidth
): void

Set the border width.

Parameters
$borderWidth : number
 

setCharSpacing()

public SetaPDF_Core_Text_Block::setCharSpacing (
number $charSpacing
): void

Set the character spacing value.

Parameters
$charSpacing : number
 

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 $font [, number $fontSize = null ]
): void

Set the font object and size.

Parameters
$font : SetaPDF_Core_Font
 
$fontSize : number
 

setFontSize()

public SetaPDF_Core_Text_Block::setFontSize (
number $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 : number
 

setLineHeight()

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

Set the line height / leading.

Parameters
$lineHeight : float|integer|null
 

setOutlineColor()

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 (
number $padding
): void

Set the padding.

Parameters
$padding : number
 

setPaddingBottom()

public SetaPDF_Core_Text_Block::setPaddingBottom (
number $paddingBottom
): void

Set the bottom padding.

Parameters
$paddingBottom : number
 

setPaddingLeft()

public SetaPDF_Core_Text_Block::setPaddingLeft (
number $paddingLeft
): void

Set the left padding.

Parameters
$paddingLeft : number
 

setPaddingRight()

public SetaPDF_Core_Text_Block::setPaddingRight (
number $paddingRight
): void

Set the right padding.

Parameters
$paddingRight : number
 

setPaddingTop()

public SetaPDF_Core_Text_Block::setPaddingTop (
number $paddingTop
): void

Set the top padding.

Parameters
$paddingTop : number
 

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

setWidth()

public SetaPDF_Core_Text_Block::setWidth (
number $width
): void

Set the width of the text block.

Parameters
$width : number
 

setWordSpacing()

public SetaPDF_Core_Text_Block::setWordSpacing (
number $wordSpacing
): void

Set the word spacing value.

Parameters
$wordSpacing : number