diff --git a/assets/ckeditor/html_label.js b/assets/ckeditor/html_label.js index b5ca5c3e..9040f3c7 100644 --- a/assets/ckeditor/html_label.js +++ b/assets/ckeditor/html_label.js @@ -181,7 +181,8 @@ Editor.defaultConfig = { 'DejaVu Serif, serif', 'Helvetica, Arial, sans-serif', 'Times New Roman, Times, serif', - 'Courier New, Courier, monospace' + 'Courier New, Courier, monospace', + 'Unifont, monospace', ], supportAllValues: true }, diff --git a/assets/fonts/dompdf/.gitignore b/assets/fonts/dompdf/.gitignore new file mode 100644 index 00000000..085ad9f3 --- /dev/null +++ b/assets/fonts/dompdf/.gitignore @@ -0,0 +1,3 @@ +# Ignore font files +*.otf +*.ttf \ No newline at end of file diff --git a/assets/fonts/dompdf/README.md b/assets/fonts/dompdf/README.md new file mode 100644 index 00000000..d80c64f4 --- /dev/null +++ b/assets/fonts/dompdf/README.md @@ -0,0 +1 @@ +Put your font ttf files in this folder to make them available to the label generator. \ No newline at end of file diff --git a/composer.json b/composer.json index 44e7d21d..65c371bb 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,7 @@ "florianv/swap-bundle": "dev-master", "gregwar/captcha-bundle": "^2.1.0", "jbtronics/2fa-webauthn": "^v2.0.0", + "jbtronics/dompdf-font-loader-bundle": "^1.0.0", "jfcherng/php-diff": "^6.14", "league/csv": "^9.8.0", "league/html-to-markdown": "^5.0.1", @@ -35,6 +36,7 @@ "nyholm/psr7": "^1.1", "ocramius/proxy-manager": "2.2.*", "omines/datatables-bundle": "^0.7.2", + "part-db/label-fonts": "^1.0", "php-translation/symfony-bundle": "^0.13.0", "phpdocumentor/reflection-docblock": "^5.2", "s9e/text-formatter": "^2.1", diff --git a/composer.lock b/composer.lock index 0ddb8941..802b29d1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "28e49fed0a1eb5f33d7ca39a19ba2fff", + "content-hash": "ac083d3e7e6f9bfde54fb37e99edf662", "packages": [ { "name": "beberlei/assert", @@ -2511,6 +2511,61 @@ }, "time": "2023-06-11T11:09:45+00:00" }, + { + "name": "jbtronics/dompdf-font-loader-bundle", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/jbtronics/dompdf-font-loader-bundle.git", + "reference": "8323aa3d4c3e70536b958a44f159208a6a0f7fa2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jbtronics/dompdf-font-loader-bundle/zipball/8323aa3d4c3e70536b958a44f159208a6a0f7fa2", + "reference": "8323aa3d4c3e70536b958a44f159208a6a0f7fa2", + "shasum": "" + }, + "require": { + "dompdf/dompdf": "v1.0.0|v2.0.3", + "ext-json": "*", + "php": "^8.1", + "symfony/finder": "^6.0", + "symfony/framework-bundle": "^6.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.5", + "roave/security-advisories": "dev-latest", + "symfony/phpunit-bridge": "^6.0" + }, + "type": "symfony-bundle", + "autoload": { + "psr-4": { + "Jbtronics\\DompdfFontLoaderBundle\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jan Böhmer", + "email": "mail@jan-boehmer.de" + } + ], + "description": "A symfony bundle to easily load custom fonts for dompdf (on cache warming)", + "keywords": [ + "dompdf", + "fonts", + "symfony", + "symfony-bundle" + ], + "support": { + "issues": "https://github.com/jbtronics/dompdf-font-loader-bundle/issues", + "source": "https://github.com/jbtronics/dompdf-font-loader-bundle/tree/v1.0.0" + }, + "time": "2023-07-02T00:21:14+00:00" + }, { "name": "jfcherng/php-color-output", "version": "3.0.0", @@ -4139,6 +4194,44 @@ }, "time": "2022-06-14T06:56:20+00:00" }, + { + "name": "part-db/label-fonts", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/Part-DB/label-fonts.git", + "reference": "65f4a47d877f45e39804cd86a4fc65789b49ee2f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Part-DB/label-fonts/zipball/65f4a47d877f45e39804cd86a4fc65789b49ee2f", + "reference": "65f4a47d877f45e39804cd86a4fc65789b49ee2f", + "shasum": "" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "proprietary" + ], + "authors": [ + { + "name": "The Part-DB Team", + "homepage": "https://github.com/Part-DB/Part-DB-server" + } + ], + "description": "This library bundles the fonts used in Part-DB for label generators. Fonts are work of others.", + "homepage": "https://github.com/Part-DB/Part-DB-server", + "keywords": [ + "font", + "fonts", + "part-db" + ], + "support": { + "issues": "https://github.com/Part-DB/label-fonts/issues", + "source": "https://github.com/Part-DB/label-fonts/tree/v1.0.0" + }, + "time": "2023-07-02T01:01:20+00:00" + }, { "name": "phenx/php-font-lib", "version": "0.5.4", @@ -14370,16 +14463,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.21", + "version": "1.10.22", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "b2a30186be2e4d97dce754ae4e65eb0ec2f04eb5" + "reference": "97d694dfd4ceb57bcce4e3b38548f13ea62e4287" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/b2a30186be2e4d97dce754ae4e65eb0ec2f04eb5", - "reference": "b2a30186be2e4d97dce754ae4e65eb0ec2f04eb5", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/97d694dfd4ceb57bcce4e3b38548f13ea62e4287", + "reference": "97d694dfd4ceb57bcce4e3b38548f13ea62e4287", "shasum": "" }, "require": { @@ -14428,7 +14521,7 @@ "type": "tidelift" } ], - "time": "2023-06-21T20:07:58+00:00" + "time": "2023-06-30T20:04:11+00:00" }, { "name": "phpstan/phpstan-doctrine", @@ -14752,12 +14845,12 @@ "source": { "type": "git", "url": "https://github.com/Roave/SecurityAdvisories.git", - "reference": "9920192eab87b9ae105696b0b86326c8fac91677" + "reference": "885786b30f50e83a88941df2062d68de623599fd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/9920192eab87b9ae105696b0b86326c8fac91677", - "reference": "9920192eab87b9ae105696b0b86326c8fac91677", + "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/885786b30f50e83a88941df2062d68de623599fd", + "reference": "885786b30f50e83a88941df2062d68de623599fd", "shasum": "" }, "conflict": { @@ -15011,7 +15104,7 @@ "marcwillmann/turn": "<0.3.3", "matyhtf/framework": "<3.0.6", "mautic/core": "<4.3|= 2.13.1", - "mediawiki/core": ">=1.27,<1.27.6|>=1.29,<1.29.3|>=1.30,<1.30.2|>=1.31,<1.31.9|>=1.32,<1.32.6|>=1.32.99,<1.33.3|>=1.33.99,<1.34.3|>=1.34.99,<1.35", + "mediawiki/core": "<=1.39.3", "mediawiki/matomo": "<2.4.3", "melisplatform/melis-asset-manager": "<5.0.1", "melisplatform/melis-cms": "<5.0.1", @@ -15229,7 +15322,7 @@ "thelia/thelia": ">=2.1-beta.1,<2.1.3", "theonedemon/phpwhois": "<=4.2.5", "thinkcmf/thinkcmf": "<=5.1.7", - "thorsten/phpmyfaq": "<3.2-beta", + "thorsten/phpmyfaq": "<3.2-beta.2", "tinymce/tinymce": "<5.10.7|>=6,<6.3.1", "tinymighty/wiki-seo": "<1.2.2", "titon/framework": ">=0,<9.9.99", @@ -15275,7 +15368,7 @@ "wintercms/winter": "<1.0.475|>=1.1,<1.1.10|>=1.2,<1.2.1", "woocommerce/woocommerce": "<6.6", "wp-cli/wp-cli": "<2.5", - "wp-graphql/wp-graphql": "<0.3.5", + "wp-graphql/wp-graphql": "<=1.14.5", "wpanel/wpanel4-cms": "<=4.3.1", "wpcloud/wp-stateless": "<3.2", "wwbn/avideo": "<=12.4", @@ -15360,7 +15453,7 @@ "type": "tidelift" } ], - "time": "2023-06-28T23:04:41+00:00" + "time": "2023-06-30T21:04:19+00:00" }, { "name": "sebastian/diff", diff --git a/config/bundles.php b/config/bundles.php index 3e6c7dfe..89a63165 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -29,4 +29,5 @@ return [ Nbgrp\OneloginSamlBundle\NbgrpOneloginSamlBundle::class => ['all' => true], Symfony\UX\StimulusBundle\StimulusBundle::class => ['all' => true], Symfony\UX\Translator\UxTranslatorBundle::class => ['all' => true], + Jbtronics\DompdfFontLoaderBundle\DompdfFontLoaderBundle::class => ['all' => true], ]; diff --git a/config/packages/dompdf_font_loader.yaml b/config/packages/dompdf_font_loader.yaml new file mode 100644 index 00000000..8e35c37b --- /dev/null +++ b/config/packages/dompdf_font_loader.yaml @@ -0,0 +1,11 @@ +dompdf_font_loader: + auto_install: true + + fonts: + unifont: + normal: "%kernel.project_dir%/vendor/part-db/label-fonts/fonts/unifont.ttf" + + # Enable autodiscovery of fonts, so that font installation is much easier + autodiscovery: + paths: + - "%kernel.project_dir%/assets/fonts/dompdf" \ No newline at end of file diff --git a/docs/usage/labels.md b/docs/usage/labels.md index 0d885f12..35c6d317 100644 --- a/docs/usage/labels.md +++ b/docs/usage/labels.md @@ -92,4 +92,27 @@ The following variables are in injected into Twig and can be accessed using `{% | `{% raw %}{{ element }}{% endraw %}` | The target element, selected in label dialog | | `{% raw %}{{ user }}{% endraw %}` | The current logged in user. Null if you are not logged in | | `{% raw %}{{ install_title }}{% endraw %}` | The name of the current Part-DB instance (similar to [[INSTALL_NAME]] placeholder). | -| `{% raw %}{{ page }}{% endraw %}` | The page number (the nth-element for which the label is generated | \ No newline at end of file +| `{% raw %}{{ page }}{% endraw %}` | The page number (the nth-element for which the label is generated | + + +## Use custom fonts for PDF labels +You can use your own fonts for label generation. To do this, put the TTF files of the fonts you want to use into the `assets/fonts/dompdf` folder. +The filename will be used as name for the font family and you can use a `_bold` (or `_b`), `_italic` (or `_i`) or `_bold_italic` (or `_bi`) suffix to define +different styles of the font. So for example, if you copy the file `myfont.ttf` and `myfont_bold.ttf` into the `assets/fonts/dompdf` folder, you can use the font family `myfont` with regular and bold style. +Afterwards regenerate cache with `php bin/console cache:clear`, so the new fonts will be available for label generation. + +The fonts will not be availble from the UI directly, you have to use it in the HTML directly either by defining a `style="font-family: 'myfont';"` attribute on the HTML element or by using a CSS class. +You can define the font globally for the label, by adding following statement to the "Additional styles (CSS)" option in the label generator settings: +```css +* { + font-family: 'myfont'; +} +``` + +## Non-latin characters in PDF labels +The default used font (DejaVu) does not support all characters. Especially characters from non-latin languages like Chinese, Japanese, Korean, Arabic, Hebrew, Cyrillic, etc. are not supported. +For this we use [Unifont](http://unifoundry.com/unifont.html) as fallback font. This font supports all (or most) unicode characters, but is not as beautiful as DejaVu. + +If you want to use a different (more beautiful) font, you can use the [custom fonts](#use-custom-fonts-for-pdf-labels) feature. +There is the [Noto](https://www.google.com/get/noto/) font family from Google, which supports a lot of languages and is available in different styles (regular, bold, italic, bold-italic). +For example you can use [Noto CJK](https://github.com/notofonts/noto-cjk) for more beautful Chinese, Japanese and Korean characters. \ No newline at end of file diff --git a/symfony.lock b/symfony.lock index 7572566b..ed92f4e1 100644 --- a/symfony.lock +++ b/symfony.lock @@ -177,6 +177,9 @@ "jbtronics/2fa-webauthn": { "version": "dev-master" }, + "jbtronics/dompdf-font-loader-bundle": { + "version": "dev-main" + }, "laminas/laminas-code": { "version": "3.4.1" }, diff --git a/templates/label_system/labels/label_style.css.twig b/templates/label_system/labels/label_style.css.twig index c2434a77..edbf9522 100644 --- a/templates/label_system/labels/label_style.css.twig +++ b/templates/label_system/labels/label_style.css.twig @@ -22,7 +22,7 @@ } body { - font-family: "DejaVu Sans Mono"; + font-family: "DejaVu Sans Mono", "unifont", monospace; font-size: 12px; line-height: 1.0; }