setasign\SetaPDF2\Core\Text

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

File: /SetaPDF v2/Core/Text/TextBlock.php
Old class name (alias): \SetaPDF_Core_Text_Block

Class hierarchy

Summary

Properties

$_align

protected string TextBlock::$_align = 'left'

The text alignment

$_backgroundColor

$_borderColor

$_borderWidth

protected int|float TextBlock::$_borderWidth = 0

The border width

$_charSpacing

protected int|float TextBlock::$_charSpacing = 0

The character spacing value

$_dataCache

protected array TextBlock::$_dataCache = array()

An array for caching calculation results

$_dataCacheClearCallback

protected callback TextBlock::$_dataCacheClearCallback

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

$_encoding

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

The encoding of the text

$_font

$_fontSize

protected float|int TextBlock::$_fontSize = 12

The font size

$_internalText

protected string TextBlock::$_internalText = ''

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

$_lineHeight

protected null|int|float TextBlock::$_lineHeight

The line height

$_outlineColor

The color of the text outline

$_outlineWidth

protected int|float TextBlock::$_outlineWidth = 1.0

The outline width

$_paddingBottom

protected int|float TextBlock::$_paddingBottom = 0

Padding bottom value

$_paddingLeft

protected int|float TextBlock::$_paddingLeft = 0

Padding left value

$_paddingRight

protected int|float TextBlock::$_paddingRight = 0

Padding right value

$_paddingTop

protected int|float TextBlock::$_paddingTop = 0

Padding top value

$_renderingMode

protected int TextBlock::$_renderingMode = 0

The rendering mode

$_text

protected string TextBlock::$_text

The text in user defined encoding

$_textColor

$_underline

protected bool TextBlock::$_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 int|float TextBlock::$_width

A specific width of this text stamp

$_wordSpacing

protected int|float TextBlock::$_wordSpacing = 0

Word spacing value


Methods

__construct()

public TextBlock::__construct (
\SetaPDF_Core_Font_FontInterface $font,
int|float $fontSize = null
)

The constructor.

Parameters
$font : \SetaPDF_Core_Font_FontInterface
 
$fontSize : int|float
 

_clearDataCache()

protected TextBlock::_clearDataCache (
void
): void

Clears the internal data cache.

_drawBorderAndBackground()

protected TextBlock::_drawBorderAndBackground (
\SetaPDF_Core_Canvas $canvas,
int|float $x,
int|float $y
): void

Draws the border and background onto the canvas.

Parameters
$canvas : \SetaPDF_Core_Canvas
 
$x : int|float

The lower left x-value of the text block

$y : int|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 TextBlock::_drawText (
\SetaPDF_Core_Canvas $canvas,
int|float $x,
int|float $y
): void

Draws the text onto the canvas.

Parameters
$canvas : \SetaPDF_Core_Canvas
 
$x : int|float

The lower left x-value of the text block

$y : int|float

The lower left y-value of the text block

Exceptions

Throws \setasign\SetaPDF2\Core\Exception

Throws \setasign\SetaPDF2\Core\Font\Exception

Throws \setasign\SetaPDF2\Core\Type\Exception

Throws \setasign\SetaPDF2\Core\Type\IndirectReference\Exception

Throws \setasign\SetaPDF2\NotImplementedException

_fixX()

protected TextBlock::_fixX (
int|float $x
): int|float

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

Parameters
$x : int|float
 

_fixY()

protected TextBlock::_fixY (
int|float $y
): int|float

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

Parameters
$y : int|float
 

_getLines()

protected TextBlock::_getLines (
void
): array

Get the text as lines and caches the result.

_getManualLineBreaks()

protected TextBlock::_getManualLineBreaks (
void
): mixed

Get line numbers which use a manual line break.

_getTextWidth()

private TextBlock::_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 TextBlock::cleanUp (
void
): void

Release resources / cycled references.

draw()

public TextBlock::draw (
\SetaPDF_Core_Canvas $canvas,
int|float $x,
int|float $y
): void

Draws the text block onto a canvas.

Parameters
$canvas : \SetaPDF_Core_Canvas
 
$x : int|float

The lower left x-value of the text block

$y : int|float

The lower left y-value of the text block

Exceptions

Throws \setasign\SetaPDF2\Core\Exception

Throws \setasign\SetaPDF2\Core\Font\Exception

Throws \setasign\SetaPDF2\Core\Type\Exception

Throws \setasign\SetaPDF2\Core\Type\IndirectReference\Exception

Throws \setasign\SetaPDF2\NotImplementedException

getAlign()

public TextBlock::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 TextBlock::getBorderWidth (
void
): int|float

Get the border width.

getCharSpacing()

public TextBlock::getCharSpacing (
void
): int|float

Get the character spacing value.

getFont()

Get the font object.

getFontSize()

public TextBlock::getFontSize (
void
): int|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 TextBlock::getHeight (
void
): int|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()

public TextBlock::getLineCount (
void
): int

Get the line count of the text block.

getLineHeight()

public TextBlock::getLineHeight (
void
): int|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()

public TextBlock::getOutlineWidth (
void
): float

Get the outline width.

The outline width is only used at specific rendering modes.

getPaddingBottom()

public TextBlock::getPaddingBottom (
void
): int|float

Get the bottom padding.

getPaddingLeft()

public TextBlock::getPaddingLeft (
void
): int|float

Get the left padding.

getPaddingRight()

public TextBlock::getPaddingRight (
void
): int|float

Get the right padding.

getPaddingTop()

public TextBlock::getPaddingTop (
void
): int|float

Get the top padding.

getRenderingMode()

public TextBlock::getRenderingMode (
void
): int

Get the defined rendering mode.

See

getText()

public TextBlock::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 TextBlock::getTextHeight (
void
): float|int

Get the height of the text.

getTextWidth()

public TextBlock::getTextWidth (
void
): int|float

Get the width of the longest text line.

getUnderline()

public TextBlock::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 TextBlock::getWidth (
void
): int|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 TextBlock::getWordSpacing (
void
): int|float

Get the word spacing value.

setAlign()

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

Set the text alignment.

Parameters
$align : string
 
See

setBackgroundColor()

setBorderColor()

setBorderWidth()

public TextBlock::setBorderWidth (
int|float $borderWidth
): void

Set the border width.

Parameters
$borderWidth : int|float
 

setCharSpacing()

public TextBlock::setCharSpacing (
int|float $charSpacing
): void

Set the character spacing value.

Parameters
$charSpacing : int|float
 

setDataCacheClearCallback()

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

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

Parameters
$callback : callback
 

setFont()

public TextBlock::setFont (
\SetaPDF_Core_Font_FontInterface $font,
int|float $fontSize = null
): void

Set the font object and size.

Parameters
$font : \SetaPDF_Core_Font_FontInterface
 
$fontSize : int|float
 

setFontSize()

public TextBlock::setFontSize (
int|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 : int|float
 

setLineHeight()

public TextBlock::setLineHeight (
float|int|null $lineHeight
): void

Set the line height / leading.

Parameters
$lineHeight : float|int|null
 

setOutlineWidth()

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

Set the outline width.

The outline width is only used at specific rendering modes.

Parameters
$outlineWidth : float
 

setPadding()

public TextBlock::setPadding (
int|float $padding
): void

Set the padding.

Parameters
$padding : int|float
 

setPaddingBottom()

public TextBlock::setPaddingBottom (
int|float $paddingBottom
): void

Set the bottom padding.

Parameters
$paddingBottom : int|float
 

setPaddingLeft()

public TextBlock::setPaddingLeft (
int|float $paddingLeft
): void

Set the left padding.

Parameters
$paddingLeft : int|float
 

setPaddingRight()

public TextBlock::setPaddingRight (
int|float $paddingRight
): void

Set the right padding.

Parameters
$paddingRight : int|float
 

setPaddingTop()

public TextBlock::setPaddingTop (
int|float $paddingTop
): void

Set the top padding.

Parameters
$paddingTop : int|float
 

setRenderingMode()

public TextBlock::setRenderingMode (
int $renderingMode = 0
): void

Set the rendering mode.

Parameters
$renderingMode : int
 
See

setText()

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

Set the text.

Parameters
$text : string
 
$encoding : string

The encoding of $text

setTextWidth()

public TextBlock::setTextWidth (
int|float $width
): void

Set the width of the text.

Parameters
$width : int|float
 

setUnderline()

public TextBlock::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()

WARNING: This method is marked as deprecated!

Use setTextWidth() instead.

public TextBlock::setWidth (
int|float $width
): void
Parameters
$width : int|float
 
See

setWordSpacing()

public TextBlock::setWordSpacing (
int|float $wordSpacing
): void

Set the word spacing value.

Parameters
$wordSpacing : int|float