Download the PHP package tecnickcom/tc-lib-pdf-font without Composer

On this page you can find all versions of the php package tecnickcom/tc-lib-pdf-font. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package tc-lib-pdf-font

tc-lib-pdf-font

Font import, metrics, and stack management utilities for PDF generation.

Latest Stable Version Build Coverage License Downloads

Sponsor on GitHub

💖 Part of the tc-lib-pdf / TCPDF ecosystem (100M+ installs). Sponsor its maintenance →


Overview

tc-lib-pdf-font provides font import and runtime font-stack services used by PDF composition engines.

It handles font metrics, encodings, and font program references, turning static font assets into the definition files and PDF objects a document needs.

Namespace \Com\Tecnick\Pdf\Font
Author Nicola Asuni [email protected]
License GNU LGPL v3 - see LICENSE
API docs https://tcpdf.org/docs/srcdoc/tc-lib-pdf-font
Packagist https://packagist.org/packages/tecnickcom/tc-lib-pdf-font

Features

Font Processing

Runtime Font Stack


Requirements


Installation


Quick Start

For larger examples, refer to test/OutputTest.php and the conversion tooling in this repository.


Character Encoding of Composite Fonts

A TrueTypeUnicode font is emitted as a composite (Type0) font with the Identity-H encoding, so every character code in a content stream is 2 bytes wide.

The character code is the glyph index of the font (CID == GID): the font dictionary declares /CIDToGIDMap /Identity, the /W array is keyed by glyph index, and a /ToUnicode CMap is generated for the glyphs used by the document so that the text stays searchable and extractable.

Encoding a string

The consumer of this library must encode composite text through the font stack, so that the glyphs used are recorded for the /W array and the /ToUnicode CMap:

The text object written to the page must also select the font the string was encoded with, otherwise the glyph indices are resolved against a different font. This does not apply to the fonts that are not GID encoded, whose character codes mean the same thing in every font.

Relevant methods:

Font definition files

The glyph index of a codepoint is read at runtime from the .ctg.z artifact of the font, which covers the whole Basic Multilingual Plane. The file must remain next to the .json definition file.

Codepoints above U+FFFF do not fit that table and are stored in the definition file under the ctgu key:

That key is only written when the font is converted with --encoding_id=10, which selects the format 12 cmap subtable.


Subset Caching

TrueType font subsetting is computational and memory intensive. When the same fonts and character sets are embedded repeatedly (for example across many generated documents), you can inject an optional cache into \Com\Tecnick\Pdf\Font\Output to reuse previously computed subset programs.

Provide any object implementing \Com\Tecnick\Pdf\Font\FontSubsetCacheInterface:

Pass it as the last constructor argument:

When no cache is supplied (the default), every subset is recomputed. The library never evicts entries: the injected backend owns expiration and size limits. The cache key accounts for the font program bytes, the cmap-selection metrics, and the requested subset characters, so distinct inputs never collide.

Using a PSR-16 cache

No PSR-16 adapter is bundled. A wrapper around any backend (PSR-16/PSR-6, Symfony Cache, Laravel, Redis, APCu) is a few lines:

The raw key of the library is human-readable and works with permissive backends, while stricter PSR-16 implementations may reject or mangle it. Hashing discards the readable namespace, so scope the underlying PSR-16 pool to this library if you share it with other consumers.


Converting Existing Fonts

Use the CLI utilities in util/ to convert existing font files into the JSON/Z format consumed by this library.

Convert One or More Fonts

Run util/convert.php and pass one or more input files with --fonts:

The command writes generated font definition files to --outpath.

Common options:

To see full usage help:

Bulk Conversion

For batch generation from the mirrored font set, run from a clone of this repository:

The script:

  1. Installs the library dependencies with composer install --no-dev when no Composer autoloader is found.
  2. Installs the util dependencies, which download the font sources from GitHub.
  3. Clears target/fonts/.
  4. Runs bulk_convert.php, which scans the mirror package and writes converted fonts under target/fonts/.

It requires PHP, Composer and network access. It does not need make or a POSIX shell, so it also runs on Windows. In a repository clone the same step is available as composer fonts and make fonts.

When the package is installed as a dependency, run the script from its location in the vendor directory, for example from the project root:

The fonts are written to vendor/tecnickcom/tc-lib-pdf-font/target/fonts/. Composer replaces the package directory on update or reinstall, which removes them, so run the script again afterwards.

Notes:


Upgrading from 3.x to 4.0

Version 4.0 changes the character codes emitted for TrueTypeUnicode fonts from Unicode codepoints to glyph indices, as described in Character Encoding of Composite Fonts.

A consumer of this library must be updated together with it:

Unchanged:


Development

make fonts runs the Bulk Conversion. The unit tests require the generated fonts.


Packaging

For system packages, bootstrap with:


Contributing

Contributions are welcome. Please review SECURITY.md.


All versions of tc-lib-pdf-font with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-hash Version *
ext-json Version *
ext-pcre Version *
ext-zlib Version *
tecnickcom/tc-lib-file Version ^3.9
tecnickcom/tc-lib-unicode-data Version ^3.1
tecnickcom/tc-lib-pdf-encrypt Version ^2.12
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package tecnickcom/tc-lib-pdf-font contains the following files

Loading the files please wait ...