Skip to content

Commit 7bec5bd

Browse files
committed
fix: improve fonts path configuration and documentation
1 parent f5a3926 commit 7bec5bd

5 files changed

Lines changed: 68 additions & 8 deletions

File tree

‎README.md‎

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,38 @@ How to migrate custom font usage:
9999
3. Keep using `SetFont()`/`AddFont()` from TCPDF, but validate that each custom family resolves from tc-lib assets or from your explicit font path.
100100
4. Update deployment packaging so `vendor/` font assets are shipped in production.
101101

102-
Font generation procedure (Makefile):
102+
Font generation procedure:
103+
104+
Font assets are generated at install time and are not shipped in the package. Composer runs the scripts declared by the root project only, so a project that requires TCPDF as a dependency must run the generation itself.
105+
106+
In a project that requires TCPDF, add the step to its own `composer.json`:
107+
108+
```json
109+
{
110+
"scripts": {
111+
"tc-lib-pdf-fonts": [
112+
"[ -d vendor/tecnickcom/tc-lib-pdf-font ] && make -C vendor/tecnickcom/tc-lib-pdf-font deps fonts || true"
113+
],
114+
"post-install-cmd": [
115+
"@tc-lib-pdf-fonts"
116+
],
117+
"post-update-cmd": [
118+
"@tc-lib-pdf-fonts"
119+
],
120+
"post-autoload-dump": [
121+
"@tc-lib-pdf-fonts"
122+
]
123+
}
124+
}
125+
```
126+
127+
This covers `composer install`, `composer update`, `composer require` and `composer dump-autoload`. To generate them once instead, run the build from the project root:
128+
129+
```bash
130+
make -C vendor/tecnickcom/tc-lib-pdf-font deps fonts
131+
```
132+
133+
In a checkout of this repository, use the Makefile targets:
103134

104135
1. Run `make deps` to install Composer dependencies and initialize tc-lib font assets.
105136
2. Run `make fonts` to initialize fonts only when missing.
@@ -109,6 +140,8 @@ Expected generated asset sentinel:
109140

110141
- `vendor/tecnickcom/tc-lib-pdf-font/target/fonts/core/helvetica.json`
111142

143+
A missing asset directory is reported as `unable to read file: helvetica.json` on the first page. The full font documentation is at [tcpdf.org/docs/fonts](https://tcpdf.org/docs/fonts/).
144+
112145
Compatibility notes:
113146

114147
- TCPDF checks configured font paths and tc-lib font assets.
@@ -122,8 +155,9 @@ Example:
122155
```php
123156
require __DIR__.'/vendor/autoload.php';
124157

125-
// Optional: override only if you need a non-default path.
126-
define('K_PATH_FONTS', __DIR__.'/vendor/tecnickcom/tc-lib-pdf-font/target/fonts/');
158+
// Optional: TCPDF resolves the installed tc-lib-pdf-font package on its own.
159+
// Define the constant only to use font assets from another directory.
160+
define('K_PATH_FONTS', '/opt/app/fonts/');
127161

128162
$pdf->SetFont('helvetica', '', 11);
129163
```

‎VERSION‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.0.8
1+
7.0.9

‎composer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"require": {
3030
"php": ">=8.2",
3131
"ext-curl": "*",
32-
"tecnickcom/tc-lib-pdf": "^8.73.5"
32+
"tecnickcom/tc-lib-pdf": "^8.73.6"
3333
},
3434
"require-dev": {
3535
"carthage-software/mago": "1.47.6",

‎tcpdf.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
//============================================================+
44
// File name : tcpdf.php
5-
// Version : 7.0.8
5+
// Version : 7.0.9
66
// Author : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - info@tecnick.com
77
// License : GNU-LGPL v3 (https://www.gnu.org/copyleft/lesser.html)
88
// Copyright (C): 2002-2026 Nicola Asuni - Tecnick.com LTD
@@ -15,7 +15,7 @@
1515
* See: https://tcpdf.org
1616
* @package com.tecnick.tcpdf
1717
* @author Nicola Asuni
18-
* @version 7.0.8
18+
* @version 7.0.9
1919
*/
2020

2121
// TCPDF configuration

‎tcpdf_autoconfig.php‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,33 @@
7171
}
7272

7373
if (!defined('K_PATH_FONTS')) {
74-
define('K_PATH_FONTS', K_PATH_MAIN . 'vendor/tecnickcom/tc-lib-pdf-font/target/fonts/');
74+
$tcpdf_fonts_dirs = [];
75+
if (class_exists('Composer\InstalledVersions', false)) {
76+
try {
77+
$tcpdf_fonts_pkg = Composer\InstalledVersions::getInstallPath('tecnickcom/tc-lib-pdf-font');
78+
if (is_string($tcpdf_fonts_pkg) && $tcpdf_fonts_pkg !== '') {
79+
$tcpdf_fonts_dirs[] = rtrim($tcpdf_fonts_pkg, '/\\') . '/target/fonts/';
80+
}
81+
} catch (Throwable) {
82+
// tc-lib-pdf-font is not installed through Composer
83+
}
84+
}
85+
86+
// TCPDF as the root project: the package is under its own vendor directory.
87+
$tcpdf_fonts_dirs[] = K_PATH_MAIN . 'vendor/tecnickcom/tc-lib-pdf-font/target/fonts/';
88+
// TCPDF as a dependency: the package is a sibling in the same vendor directory.
89+
$tcpdf_fonts_dirs[] = dirname(K_PATH_MAIN) . '/tc-lib-pdf-font/target/fonts/';
90+
91+
$tcpdf_fonts_path = $tcpdf_fonts_dirs[0];
92+
foreach ($tcpdf_fonts_dirs as $tcpdf_fonts_dir) {
93+
if (!@is_dir($tcpdf_fonts_dir)) {
94+
continue;
95+
}
96+
97+
$tcpdf_fonts_path = $tcpdf_fonts_dir;
98+
break;
99+
}
100+
define('K_PATH_FONTS', $tcpdf_fonts_path);
75101
}
76102

77103
if (!defined('K_PATH_URL')) {

0 commit comments

Comments
 (0)