Com\Tecnick\Pdf\Font\Stack
Tags
Table of Contents
- DEFAULT_SIZE = 10
- Default font size in points
- $encdiff : array<string|int, mixed>
- Array containing encoding differences
- $file : array<string|int, mixed>
- Array containing font definitions grouped by file
- $font : array<string|int, mixed>
- Array containing all fonts data
- $index : int
- Current font index
- $kunit : float
- Unit of measure conversion ratio
- $metric : array<string|int, mixed>
- Array containing font metrics for each fontkey-size combination.
- $numdiffs : int
- Index for Encoding differences
- $numfonts : int
- Font counter
- $pdfa : bool
- True if we are in PDF/A mode.
- $stack : array<string|int, mixed>
- Array (stack) containing fonts in order of insertion.
- $subset : bool
- Default subset mode
- $unicode : bool
- True if we are in Unicode mode, False otherwhise.
- __construct() : string
- Initialize fonts buffer
- add() : string
- Add a new font to the fonts buffer
- addSubsetChar() : mixed
- Add a character to the subset list
- getCharBBox() : array<string|int, mixed>
- Returns the glyph bounding box of the specified character in the current font in user units.
- getCharWidth() : int
- Returns true if the specified unicode value is defined in the current font
- getCurrentFont() : array<string|int, mixed>
- Returns the current font data array
- getEncDiffs() : array<string|int, mixed>
- Returns the fonts buffer
- getFont() : array<string|int, mixed>|bool
- Get font by key
- getFonts() : array<string|int, mixed>
- Returns the fonts buffer
- getOrdArrWidth() : float
- Returns the lenght of the string specified using an array of codepoints.
- insert() : array<string|int, mixed>
- Insert a font into the stack
- isCharDefined() : bool
- Returns true if the specified unicode value is defined in the current font
- isSubsetMode() : bool
- Get the default subset mode
- isValidKey() : bool
- Returns true if the specified font key exist on buffer
- popLastFont() : array<string|int, mixed>
- Remove and return the last inserted font
- replaceChar() : int
- Replace a char if it is defined on the current font.
- replaceMissingChars() : array<string|int, mixed>
- Replace missing characters with selected substitutions
- setFontSubKey() : mixed
- Set font sub-key value
- getFontMetric() : array<string|int, mixed>
- Returns the font metrics associated to the input key.
- getInputSize() : mixed
- Normalize the input size
- getInputSpacing() : mixed
- Normalize the input spacing
- getInputStretching() : mixed
- Normalize the input stretching
- getNormalizedFontKeys() : array<string|int, mixed>
- Return normalized font keys
- setFontDiff() : mixed
- Set font diff
- setFontFile() : mixed
- Set font file and subset
Constants
DEFAULT_SIZE
Default font size in points
public mixed DEFAULT_SIZE = 10
Properties
$encdiff
Array containing encoding differences
protected array<string|int,
mixed> $encdiff = array()
$file
Array containing font definitions grouped by file
protected array<string|int,
mixed> $file = array()
$font
Array containing all fonts data
protected array<string|int,
mixed> $font = array()
$index
Current font index
protected int $index = -1
$kunit
Unit of measure conversion ratio
protected float $kunit = 1.0
$metric
Array containing font metrics for each fontkey-size combination.
protected array<string|int,
mixed> $metric = array()
$numdiffs
Index for Encoding differences
protected int $numdiffs = 0
$numfonts
Font counter
protected int $numfonts = 0
$pdfa
True if we are in PDF/A mode.
protected bool $pdfa = false
$stack
Array (stack) containing fonts in order of insertion.
protected array<string|int,
mixed> $stack = array()
The last item is the current font.
$subset
Default subset mode
protected bool $subset = false
$unicode
True if we are in Unicode mode, False otherwhise.
protected bool $unicode = true
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
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 $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
-
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
Return values
string —Font key
addSubsetChar()
Add a character to the subset list
public addSubsetChar(int $key,
int $char)
: mixed
Parameters
- $key : int
-
The font key
- $char : int
-
The Unicode character value to add
Return values
mixed —getCharBBox()
Returns the glyph bounding box of the specified character in the current font in user units.
public getCharBBox(int $ord)
: array<string|int,
mixed>
Parameters
- $ord : int
-
Unicode character value.
Return values
array<string|int, mixed> —(xMin, yMin, xMax, yMax)
getCharWidth()
Returns true if the specified unicode value is defined in the current font
public getCharWidth(int $ord)
: int
Parameters
- $ord : int
-
Unicode character value.
Return values
int —getCurrentFont()
Returns the current font data array
public getCurrentFont()
: array<string|int,
mixed>
Return values
array<string|int, mixed> —getEncDiffs()
Returns the fonts buffer
public getEncDiffs()
: array<string|int,
mixed>
Return values
array<string|int, mixed> —getFont()
Get font by key
public getFont(string $key)
: array<string|int,
mixed>|bool
Parameters
- $key : string
-
Font key
Tags
Return values
array<string|int, mixed>|bool —Returns the fonts array or false in case of missing font.
getFonts()
Returns the fonts buffer
public getFonts()
: array<string|int,
mixed>
Return values
array<string|int, mixed> —getOrdArrWidth()
Returns the lenght of the string specified using an array of codepoints.
public getOrdArrWidth(array<string|int,
mixed> $uniarr)
: float
Parameters
- $uniarr : array<string|int, mixed>
-
Array of character codepoints.
Return values
float —insert()
Insert a font into the stack
public insert(int &$objnum,
string $font[,
string $style
= ''
][,
int $size
= null
][,
float $spacing
= null
][,
float $stretching
= null
][,
string $ifile
= ''
][,
bool $subset
= null
]) : array<string|int,
mixed>
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
-
Font size in points (set to null to inherit the last font size).
- $spacing : float = null
-
Extra spacing between characters.
- $stretching : float = 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
-
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
Return values
array<string|int, mixed> —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 —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()
: array<string|int,
mixed>
Return values
array<string|int, mixed> —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<string|int,
mixed> $uniarr[,
array<string|int,
mixed> $subs
= array()
]) : array<string|int,
mixed>
Parameters
- $uniarr : array<string|int, mixed>
-
Array of character codepoints.
- $subs : array<string|int, mixed> = array()
-
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<string|int, mixed> —setFontSubKey()
Set font sub-key value
public setFontSubKey(int $key,
int $subkey,
mixed $data)
: mixed
Parameters
- $key : int
-
The font key
- $subkey : int
-
Font sub-key
- $data : mixed
-
The data to set
Return values
mixed —getFontMetric()
Returns the font metrics associated to the input key.
protected getFontMetric(array<string|int,
mixed> $font)
: array<string|int,
mixed>
Parameters
- $font : array<string|int, mixed>
-
Stack item
Return values
array<string|int, mixed> —getInputSize()
Normalize the input size
protected getInputSize([mixed $size
= null
]) : mixed
return float
Parameters
- $size : mixed = null
Return values
mixed —getInputSpacing()
Normalize the input spacing
protected getInputSpacing([float $spacing
= null
]) : mixed
Parameters
- $spacing : float = null
-
Extra spacing between characters.
return float
Return values
mixed —getInputStretching()
Normalize the input stretching
protected getInputStretching([float $stretching
= null
]) : mixed
Parameters
- $stretching : float = null
-
Horizontal character stretching ratio.
return float
Return values
mixed —getNormalizedFontKeys()
Return normalized font keys
protected getNormalizedFontKeys(string $fontfamily)
: array<string|int,
mixed>
Parameters
- $fontfamily : string
-
Property string containing comma-separated font family names
Return values
array<string|int, mixed> —setFontDiff()
Set font diff
protected setFontDiff(string $key)
: mixed
Parameters
- $key : string
-
Font key
Return values
mixed —setFontFile()
Set font file and subset
protected setFontFile(string $key)
: mixed
Parameters
- $key : string
-
Font key