classes-Com-Tecnick-Pdf-Font-Stack

It appears that you are using AdBlocking software. The cost of running this website is covered by advertisements. If you like it please feel free to a small amount of money to secure the future of this website.

Stack extends Buffer

in package

Com\Tecnick\Pdf\Font\Stack

Tags
since
2011-05-23
category

Library

author

Nicola Asuni info@tecnick.com

copyright

2011-2024 Nicola Asuni - Tecnick.com LTD

license

http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)

link
https://github.com/tecnickcom/tc-lib-pdf-font
phpstan-import-type

TFontData from Load

phpstan-type

TTextSplit array{ 'pos': int, 'ord': int, 'spaces': int, 'septype': string, 'wordwidth': float, 'totwidth': float, 'totspacewidth': float, }

phpstan-type

TTextDims array{ 'chars': int, 'spaces': int, 'words': int, 'totwidth': float, 'totspacewidth': float, 'split': array<int, TTextSplit>, }

phpstan-type

TBBox array{float, float, float, float}

phpstan-type

TStackItem array{ 'key': string, 'style': string, 'size': float, 'spacing': float, 'stretching': float, }

phpstan-type

TFontMetric array{ 'ascent': float, 'avgwidth': float, 'capheight': float, 'cbbox': array<int, TBBox>, 'cratio': float, 'cw': array<int, float>, 'descent': float, 'dw': float, 'fbbox': array<int, float>, 'height': float, 'key': string, 'maxwidth': float, 'midpoint': float, 'missingwidth': float, 'out': string, 'outraw': string, 'size': float, 'spacing': float, 'stretching': float, 'type': string, 'up': float, 'usize': float, 'ut': float, 'xheight': float, }

SuppressWarnings

(PHPMD.ExcessiveClassComplexity)

Table of Contents

Constants

DEFAULT_SIZE  = 10
Default font size in points

Methods

__construct()  : string
Initialize fonts buffer
add()  : string
Add a new font to the fonts buffer
addSubsetChar()  : void
Add a character to the subset list
getCharBBox()  : TBBox
Returns the glyph bounding box of the specified character in the current font in user units.
getCharWidth()  : float
Returns the width of the specified character
getCurrentFont()  : TFontMetric
Returns the current font data array
getCurrentFontType()  : string
Returns the current font type (i.e.: Core, TrueType, TrueTypeUnicode, Type1).
getEncDiffs()  : array<int, string>
Returns the fonts buffer
getFont()  : TFontData
Get font by key
getFonts()  : array<string, TFontData>
Returns the fonts buffer
getOrdArrDims()  : TTextDims
Returns various dimensions of the string specified using an array of codepoints.
getOrdArrWidth()  : float
Returns the lenght of the string specified using an array of codepoints.
getOutCurrentFont()  : string
Returns the PDF code to use the current font.
insert()  : TFontMetric
Insert a font into the stack
isCharDefined()  : bool
Returns true if the specified unicode value is defined in the current font
isCurrentByteFont()  : bool
Returns true if the current font type is Core, TrueType or Type1.
isCurrentUnicodeFont()  : bool
Returns true if the current font type is TrueTypeUnicode or cidfont0.
isSubsetMode()  : bool
Get the default subset mode
isValidKey()  : bool
Returns true if the specified font key exist on buffer
popLastFont()  : TFontMetric
Remove and return the last inserted font
replaceChar()  : int
Replace a char if it is defined on the current font.
replaceMissingChars()  : array<int, int>
Replace missing characters with selected substitutions

Constants

DEFAULT_SIZE

Default font size in points

public mixed DEFAULT_SIZE = 10

Methods

__construct()

Initialize fonts buffer

public __construct(float $kunit[, bool $subset = false ][, bool $unicode = true ][, bool $pdfa = false ]) : string
Parameters
$kunit : float

Unit of measure conversion ratio.

$subset : bool = false

If true embedd only a subset of the fonts (stores only the information related to the used characters); If false embedd full font; This option is valid only for TrueTypeUnicode fonts and it is disabled for PDF/A. If you want to enable users to modify the document, set this parameter to false. If you subset the font, the person who receives your PDF would need to have your same font in order to make changes to your PDF. The file size of the PDF would also be smaller because you are embedding only a subset. NOTE: This option is computational and memory intensive.

$unicode : bool = true

True if we are in Unicode mode, False otherwhise.

$pdfa : bool = false

True if we are in PDF/A mode.

Tags
throws
Exception

in case of error

Return values
string

Font key

add()

Add a new font to the fonts buffer

public add(int &$objnum, string $font[, string $style = '' ][, string $ifile = '' ][, bool|null $subset = null ]) : string

The definition file (and the font file itself when embedding) must be present either in the current directory or in the one indicated by K_PATH_FONTS if the constant is defined.

Parameters
$objnum : int

Current PDF object number

$font : string

Font family. If it is a standard family name, it will override the corresponding font.

$style : string = ''

Font style. Possible values are (case insensitive): regular (default) B: bold I: italic U: underline D: strikeout (linethrough) O: overline

$ifile : string = ''

The font definition file (or empty for autodetect). By default, the name is built from the family and style, in lower case with no spaces.

$subset : bool|null = null

If true embed only a subset of the font (stores only the information related to the used characters); If false embed full font; This option is valid only for TrueTypeUnicode fonts and it is disabled for PDF/A. If you want to enable users to modify the document, set this parameter to false. If you subset the font, the person who receives your PDF would need to have your same font in order to make changes to your PDF. The file size of the PDF would also be smaller because you are embedding only a subset. Set this to null to use the default value. NOTE: This option is computational and memory intensive.

Tags
throws
Exception

in case of error

Return values
string

Font key

addSubsetChar()

Add a character to the subset list

public addSubsetChar(string $key, int $char) : void
Parameters
$key : string

The font key

$char : int

The Unicode character value to add

getCharBBox()

Returns the glyph bounding box of the specified character in the current font in user units.

public getCharBBox(int $ord) : TBBox
Parameters
$ord : int

Unicode character value.

Return values
TBBox

(xMin, yMin, xMax, yMax)

getCharWidth()

Returns the width of the specified character

public getCharWidth(int $ord) : float
Parameters
$ord : int

Unicode character value.

Return values
float

getCurrentFont()

Returns the current font data array

public getCurrentFont() : TFontMetric
Return values
TFontMetric

getCurrentFontType()

Returns the current font type (i.e.: Core, TrueType, TrueTypeUnicode, Type1).

public getCurrentFontType() : string
Return values
string

getEncDiffs()

Returns the fonts buffer

public getEncDiffs() : array<int, string>
Return values
array<int, string>

getFont()

Get font by key

public getFont(string $key) : TFontData
Parameters
$key : string

Font key

Tags
throws
Exception

in case of error

Return values
TFontData

Returns the fonts array.

getFonts()

Returns the fonts buffer

public getFonts() : array<string, TFontData>
Return values
array<string, TFontData>

getOrdArrDims()

Returns various dimensions of the string specified using an array of codepoints.

public getOrdArrDims(array<int, int> $uniarr) : TTextDims
Parameters
$uniarr : array<int, int>

Array of character codepoints.

Return values
TTextDims

getOrdArrWidth()

Returns the lenght of the string specified using an array of codepoints.

public getOrdArrWidth(array<int, int> $uniarr) : float
Parameters
$uniarr : array<int, int>

Array of character codepoints.

Return values
float

getOutCurrentFont()

Returns the PDF code to use the current font.

public getOutCurrentFont() : string
Return values
string

insert()

Insert a font into the stack

public insert(int &$objnum, string $font[, string $style = '' ][, int|null $size = null ][, float|null $spacing = null ][, float|null $stretching = null ][, string $ifile = '' ][, bool|null $subset = null ]) : TFontMetric

The definition file (and the font file itself when embedding) must be present either in the current directory or in the one indicated by K_PATH_FONTS if the constant is defined.

Parameters
$objnum : int

Current PDF object number

$font : string

Font family, or comma separated list of font families If it is a standard family name, it will override the corresponding font.

$style : string = ''

Font style. Possible values are (case insensitive): regular (default) B: bold I: italic U: underline D: strikeout (linethrough) O: overline

$size : int|null = null

Font size in points (set to null to inherit the last font size).

$spacing : float|null = null

Extra spacing between characters.

$stretching : float|null = null

Horizontal character stretching ratio.

$ifile : string = ''

The font definition file (or empty for autodetect). By default, the name is built from the family and style, in lower case with no spaces.

$subset : bool|null = null

If true embedd only a subset of the font (stores only the information related to the used characters); If false embedd full font; This option is valid only for TrueTypeUnicode fonts and it is disabled for PDF/A. If you want to enable users to modify the document, set this parameter to false. If you subset the font, the person who receives your PDF would need to have your same font in order to make changes to your PDF. The file size of the PDF would also be smaller because you are embedding only a subset. Set this to null to use the default value. NOTE: This option is computational and memory intensive.

Tags
throws
Exception

in case of error

Return values
TFontMetric

Font data

isCharDefined()

Returns true if the specified unicode value is defined in the current font

public isCharDefined(int $ord) : bool
Parameters
$ord : int

Unicode character value to convert

Return values
bool

isCurrentByteFont()

Returns true if the current font type is Core, TrueType or Type1.

public isCurrentByteFont() : bool
Return values
bool

isCurrentUnicodeFont()

Returns true if the current font type is TrueTypeUnicode or cidfont0.

public isCurrentUnicodeFont() : bool
Return values
bool

isSubsetMode()

Get the default subset mode

public isSubsetMode() : bool
Return values
bool

isValidKey()

Returns true if the specified font key exist on buffer

public isValidKey(string $key) : bool
Parameters
$key : string

Font key

Return values
bool

popLastFont()

Remove and return the last inserted font

public popLastFont() : TFontMetric
Return values
TFontMetric

replaceChar()

Replace a char if it is defined on the current font.

public replaceChar(int $oldchar, int $newchar) : int
Parameters
$oldchar : int

Integer code (unicode) of the character to replace.

$newchar : int

Integer code (unicode) of the new character.

Return values
int

the replaced char or the old char in case the new char i not defined

replaceMissingChars()

Replace missing characters with selected substitutions

public replaceMissingChars(array<int, int> $uniarr[, array<int, array<string|int, int>> $subs = [] ]) : array<int, int>
Parameters
$uniarr : array<int, int>

Array of character codepoints.

$subs : array<int, array<string|int, int>> = []

Array of possible character substitutions. The key is the character to check (integer value), the value is an array of possible substitutes.

Return values
array<int, int>

Array of character codepoints.

On this page
 

© 2004-2024 – Nicola Asuni - Tecnick.com - All rights reserved.
about - disclaimer - privacy