class TCPDF_FONTS (View source)

Properties

static protected $cache_uniord

Static cache used for speed up uniord performances

Methods

static string|false
addTTFfont(string $fontfile, string $fonttype = '', string $enc = '', int $flags = 32, string $outpath = '', int $platid = 3, int $encid = 1, bool $addcbbox = false, bool $link = false)

Convert and add the selected TrueType or Type1 font to the fonts folder (that must be writeable).

static int
_getTTFtableChecksum(string $table, int $length)

Returs the checksum of a TTF table.

static string
_getTrueTypeFontSubset(string $font, array $subsetchars)

Returns a subset of the TrueType font data without the unused glyphs.

static string
_putfontwidths(array $font, int $cidoffset = 0)

Outputs font widths

static string
updateCIDtoGIDmap(string $map, int $cid, int $gid)

Update the CIDToGIDMap string with a new value.

static string
_getfontpath()

Return fonts path

static string
getFontFullPath(string $file, string $fontdir = false)

Return font full path

static float
getFontRefSize(string $size, float $refsize = 12)

Get a reference font size.

static string
unichr(int $c, bool $unicode = true)

Returns the unicode caracter specified by the value

static string
unichrUnicode(int $c)

Returns the unicode caracter specified by UTF-8 value

static string
unichrASCII(int $c)

Returns the unicode caracter specified by ASCII value

static string
arrUTF8ToUTF16BE(array $unicode, bool $setbom = false)

Converts array of UTF-8 characters to UTF16-BE string.
Based on: http://www.faqs.org/rfcs/rfc2781.html

  Encoding UTF-16:

static array
UTF8ArrayToUniArray(array $ta, bool $isunicode = true)

Convert an array of UTF8 values to array of unicode characters

static string
UTF8ArrSubString(string[] $strarr, int $start = '', int $end = '', bool $unicode = true)

Extract a slice of the $strarr array and return it as string.

static string
UniArrSubString(string[] $uniarr, int $start = '', int $end = '')

Extract a slice of the $uniarr array and return it as string.

static array
UTF8ArrToLatin1Arr(array $unicode)

Converts UTF-8 characters array to array of Latin1 characters array

static string
UTF8ArrToLatin1(array $unicode)

Converts UTF-8 characters array to Latin1 string

static int
uniord(string $uch)

Converts UTF-8 character to integer value.
Uses the getUniord() method if the value is not cached.

static int
getUniord(string $uch)

Converts UTF-8 character to integer value.
Invalid byte sequences will be replaced with 0xFFFD (replacement character)
Based on: http://www.faqs.org/rfcs/rfc3629.html

   Char. number range  |        UTF-8 octet sequence
      (hexadecimal)    |              (binary)
   --------------------+-----------------------------------------------
   0000 0000-0000 007F | 0xxxxxxx
   0000 0080-0000 07FF | 110xxxxx 10xxxxxx
   0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
   0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
   ---------------------------------------------------------------------

static array
UTF8StringToArray(string $str, bool $isunicode, array $currentfont)

Converts UTF-8 strings to codepoints array.
Invalid byte sequences will be replaced with 0xFFFD (replacement character)

static string
UTF8ToLatin1(string $str, bool $isunicode, array $currentfont)

Converts UTF-8 strings to Latin1 when using the standard 14 core fonts.

static string
UTF8ToUTF16BE(string $str, bool $setbom, bool $isunicode, array $currentfont)

Converts UTF-8 strings to UTF16-BE.

static string
utf8StrRev(string $str, bool $setbom, bool $forcertl, bool $isunicode, array $currentfont)

Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).

static string
utf8StrArrRev(array $arr, string $str, bool $setbom, bool $forcertl, bool $isunicode, array $currentfont)

Reverse the RLT substrings array using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).

static array
utf8Bidi(array $ta, string $str, bool $forcertl, bool $isunicode, array $currentfont)

Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).

Details

static string|false addTTFfont(string $fontfile, string $fonttype = '', string $enc = '', int $flags = 32, string $outpath = '', int $platid = 3, int $encid = 1, bool $addcbbox = false, bool $link = false)

Since: 5.9.123 (2010-09-30)

Convert and add the selected TrueType or Type1 font to the fonts folder (that must be writeable).

Parameters

string $fontfile

Font file (full path).

string $fonttype

Font type. Leave empty for autodetect mode. Valid values are: TrueTypeUnicode, TrueType, Type1, CID0JP = CID-0 Japanese, CID0KR = CID-0 Korean, CID0CS = CID-0 Chinese Simplified, CID0CT = CID-0 Chinese Traditional.

string $enc

Name of the encoding table to use. Leave empty for default mode. Omit this parameter for TrueType Unicode and symbolic fonts like Symbol or ZapfDingBats.

int $flags

Unsigned 32-bit integer containing flags specifying various characteristics of the font (PDF32000:2008 - 9.8.2 Font Descriptor Flags): +1 for fixed font; +4 for symbol or +32 for non-symbol; +64 for italic. Fixed and Italic mode are generally autodetected so you have to set it to 32 = non-symbolic font (default) or 4 = symbolic font.

string $outpath

Output path for generated font files (must be writeable by the web server). Leave empty for default font folder.

int $platid

Platform ID for CMAP table to extract (when building a Unicode font for Windows this value should be 3, for Macintosh should be 1).

int $encid

Encoding ID for CMAP table to extract (when building a Unicode font for Windows this value should be 1, for Macintosh should be 0). When Platform ID is 3, legal values for Encoding ID are: 0=Symbol, 1=Unicode, 2=ShiftJIS, 3=PRC, 4=Big5, 5=Wansung, 6=Johab, 7=Reserved, 8=Reserved, 9=Reserved, 10=UCS-4.

bool $addcbbox

If true includes the character bounding box information on the php font file.

bool $link

If true link to system font instead of copying the font data (not transportable) - Note: do not work with Type1 fonts.

Return Value

string|false

TCPDF font name or boolean false in case of error.

static int _getTTFtableChecksum(string $table, int $length)

Since: 5.2.000 (2010-06-02)

Returs the checksum of a TTF table.

Parameters

string $table

table to check

int $length

length of table in bytes

Return Value

int checksum

static string _getTrueTypeFontSubset(string $font, array $subsetchars)

Since: 5.2.000 (2010-06-02)

Returns a subset of the TrueType font data without the unused glyphs.

Parameters

string $font

TrueType font data.

array $subsetchars

Array of used characters (the glyphs to keep).

Return Value

string

A subset of TrueType font data without the unused glyphs.

static string _putfontwidths(array $font, int $cidoffset = 0)

Since: 4.4.000 (2008-12-07)

Outputs font widths

Parameters

array $font

font data

int $cidoffset

offset for CID values

Return Value

string

PDF command string for font widths

static string updateCIDtoGIDmap(string $map, int $cid, int $gid)

Since: 5.9.123 (2011-09-29)

Update the CIDToGIDMap string with a new value.

Parameters

string $map CIDToGIDMap.
int $cid

CID value.

int $gid

GID value.

Return Value

string CIDToGIDMap.

static string _getfontpath()

Return fonts path

Return Value

string

static string getFontFullPath(string $file, string $fontdir = false)

Since: 6.0.025

Return font full path

Parameters

string $file

Font file name.

string $fontdir

Font directory (set to false fto search on default directories)

Return Value

string

Font full path or empty string

static float getFontRefSize(string $size, float $refsize = 12)

Get a reference font size.

Parameters

string $size

String containing font size value.

float $refsize

Reference font size in points.

Return Value

float

value in points

static string unichr(int $c, bool $unicode = true)

Since: 2.3.000 (2008-03-05)

Returns the unicode caracter specified by the value

Parameters

int $c

UTF-8 value

bool $unicode

True if we are in unicode mode, false otherwise.

Return Value

string

Returns the specified character.

static string unichrUnicode(int $c)

Returns the unicode caracter specified by UTF-8 value

Parameters

int $c

UTF-8 value

Return Value

string

Returns the specified character.

static string unichrASCII(int $c)

Returns the unicode caracter specified by ASCII value

Parameters

int $c

UTF-8 value

Return Value

string

Returns the specified character.

static protected string arrUTF8ToUTF16BE(array $unicode, bool $setbom = false)

Since: 2.1.000 (2008-01-08)

Converts array of UTF-8 characters to UTF16-BE string.
Based on: http://www.faqs.org/rfcs/rfc2781.html

  Encoding UTF-16:

Encoding of a single character from an ISO 10646 character value to UTF-16 proceeds as follows. Let U be the character number, no greater than 0x10FFFF.

1) If U < 0x10000, encode U as a 16-bit unsigned integer and terminate.

2) Let U' = U - 0x10000. Because U is less than or equal to 0x10FFFF, U' must be less than or equal to 0xFFFFF. That is, U' can be represented in 20 bits.

3) Initialize two 16-bit unsigned integers, W1 and W2, to 0xD800 and 0xDC00, respectively. These integers each have 10 bits free to encode the character value, for a total of 20 bits.

4) Assign the 10 high-order bits of the 20-bit U' to the 10 low-order bits of W1 and the 10 low-order bits of U' to the 10 low-order bits of W2. Terminate.

Graphically, steps 2 through 4 look like: U' = yyyyyyyyyyxxxxxxxxxx W1 = 110110yyyyyyyyyy W2 = 110111xxxxxxxxxx

Parameters

array $unicode

array containing UTF-8 unicode values

bool $setbom

if true set the Byte Order Mark (BOM = 0xFEFF)

Return Value

string

static array UTF8ArrayToUniArray(array $ta, bool $isunicode = true)

Since: 4.5.037 (2009-04-07)

Convert an array of UTF8 values to array of unicode characters

Parameters

array $ta

The input array of UTF8 values.

bool $isunicode

True for Unicode mode, false otherwise.

Return Value

array

Return array of unicode characters

static string UTF8ArrSubString(string[] $strarr, int $start = '', int $end = '', bool $unicode = true)

Extract a slice of the $strarr array and return it as string.

Parameters

string[] $strarr

The input array of characters.

int $start

the starting element of $strarr.

int $end

first element that will not be returned.

bool $unicode

True if we are in unicode mode, false otherwise.

Return Value

string

Return part of a string

static string UniArrSubString(string[] $uniarr, int $start = '', int $end = '')

Since: 4.5.037 (2009-04-07)

Extract a slice of the $uniarr array and return it as string.

Parameters

string[] $uniarr

The input array of characters.

int $start

the starting element of $strarr.

int $end

first element that will not be returned.

Return Value

string

Return part of a string

static array UTF8ArrToLatin1Arr(array $unicode)

Since: 4.8.023 (2010-01-15)

Converts UTF-8 characters array to array of Latin1 characters array

Parameters

array $unicode

array containing UTF-8 unicode values

Return Value

array

static string UTF8ArrToLatin1(array $unicode)

Since: 4.8.023 (2010-01-15)

Converts UTF-8 characters array to Latin1 string

Parameters

array $unicode

array containing UTF-8 unicode values

Return Value

string

static int uniord(string $uch)

Converts UTF-8 character to integer value.
Uses the getUniord() method if the value is not cached.

Parameters

string $uch

character string to process.

Return Value

int

Unicode value

static int getUniord(string $uch)

Converts UTF-8 character to integer value.
Invalid byte sequences will be replaced with 0xFFFD (replacement character)
Based on: http://www.faqs.org/rfcs/rfc3629.html

   Char. number range  |        UTF-8 octet sequence
      (hexadecimal)    |              (binary)
   --------------------+-----------------------------------------------
   0000 0000-0000 007F | 0xxxxxxx
   0000 0080-0000 07FF | 110xxxxx 10xxxxxx
   0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
   0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
   ---------------------------------------------------------------------

ABFN notation:

UTF8-octets = *( UTF8-char ) UTF8-char = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4 UTF8-1 = %x00-7F UTF8-2 = %xC2-DF UTF8-tail

UTF8-3 = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) / %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail ) UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) / %xF4 %x80-8F 2( UTF8-tail ) UTF8-tail = %x80-BF

Parameters

string $uch

character string to process.

Return Value

int

Unicode value

static array UTF8StringToArray(string $str, bool $isunicode, array $currentfont)

Converts UTF-8 strings to codepoints array.
Invalid byte sequences will be replaced with 0xFFFD (replacement character)

Parameters

string $str

string to process.

bool $isunicode

True when the documetn is in Unicode mode, false otherwise.

array $currentfont

Reference to current font array.

Return Value

array

containing codepoints (UTF-8 characters values)

static string UTF8ToLatin1(string $str, bool $isunicode, array $currentfont)

Since: 3.2.000 (2008-06-23)

Converts UTF-8 strings to Latin1 when using the standard 14 core fonts.

Parameters

string $str

string to process.

bool $isunicode

True when the documetn is in Unicode mode, false otherwise.

array $currentfont

Reference to current font array.

Return Value

string

static string UTF8ToUTF16BE(string $str, bool $setbom, bool $isunicode, array $currentfont)

Since: 1.53.0.TC005 (2005-01-05)

Converts UTF-8 strings to UTF16-BE.

Parameters

string $str

string to process.

bool $setbom

if true set the Byte Order Mark (BOM = 0xFEFF)

bool $isunicode

True when the documetn is in Unicode mode, false otherwise.

array $currentfont

Reference to current font array.

Return Value

string

static string utf8StrRev(string $str, bool $setbom, bool $forcertl, bool $isunicode, array $currentfont)

Since: 2.1.000 (2008-01-08)

Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).

Parameters

string $str

string to manipulate.

bool $setbom

if true set the Byte Order Mark (BOM = 0xFEFF)

bool $forcertl

if true forces RTL text direction

bool $isunicode

True if the document is in Unicode mode, false otherwise.

array $currentfont

Reference to current font array.

Return Value

string

static string utf8StrArrRev(array $arr, string $str, bool $setbom, bool $forcertl, bool $isunicode, array $currentfont)

Since: 4.9.000 (2010-03-27)

Reverse the RLT substrings array using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).

Parameters

array $arr

array of unicode values.

string $str

string to manipulate (or empty value).

bool $setbom

if true set the Byte Order Mark (BOM = 0xFEFF)

bool $forcertl

if true forces RTL text direction

bool $isunicode

True if the document is in Unicode mode, false otherwise.

array $currentfont

Reference to current font array.

Return Value

string

static array utf8Bidi(array $ta, string $str, bool $forcertl, bool $isunicode, array $currentfont)

Since: 2.4.000 (2008-03-06)

Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).

Parameters

array $ta

array of characters composing the string.

string $str

string to process

bool $forcertl

if 'R' forces RTL, if 'L' forces LTR

bool $isunicode

True if the document is in Unicode mode, false otherwise.

array $currentfont

Reference to current font array.

Return Value

array

of unicode chars