Mpdf: Custom fonts not working when starting with capital letter

Created on 9 May 2019  路  4Comments  路  Source: mpdf/mpdf

I found this bug

$fontData += [
  'forum' => [
    'R' => 'Forum-Regular.ttf',
  ]
]

-> this is OK, works with font-family: forum; OR font-family: Forum;

$fontData += [
  'Forum' => [
    'R' => 'Forum-Regular.ttf',
  ]
]

-> this is FAILS to work with font-family: forum; or font-family: Forum; or being used as default font.

This is mPDF and PHP version and environment (server/fpm/cli etc) I am using

mPDF 8.0
PHP 7.1

This is a PHP code snippet I use

<?php
        $defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults();
        $fontDirs = $defaultConfig['fontDir'];
        $defaultFontConfig = (new \Mpdf\Config\FontVariables())->getDefaults();
        $fontData = $defaultFontConfig['fontdata'];
        $fontData += [
            'Forum' => [
                'R' => 'Forum-Regular.ttf',
            ]
        ];

        $mpdf = new Mpdf([
            'tempDir' => dirname(dirname(__DIR__)).'/tmp',
            'fontDir' => array_merge($fontDirs, [
                dirname(dirname(__DIR__)).'/assets/fonts/',
            ]),
            'fontdata' => $fontData,
            'mode' => 'utf-8', 
            'format' => 'A4',
            'margin_top' => 10,     
            'margin_bottom' => 10,     
            'margin_right' => 15,     
            'margin_left' => 15,     
            'orientation' => 'P'
        ]);

This is a HTML/CSS code snippet I use

    .event .eventInfo {
        font-family: Forum;
    }
    .data {
        font-family: forum;
    }
bufix fonts research needed

All 4 comments

Can confirm. Also, thanks @vitexikora that issue saved my day. Have been looking for a mistake in my code for hours.

Its a trap for developers. I costed me 2-3 hours of debugging, and I doubt that just me. When I told this to my colleagues on our company slack, one just admitted he had the same troubles some time ago, and that he had finally given up and had to switch to a different library, definitely more than 3 hrs. Is it that complicated to call strtolower in the backend?

It is not complicated to call strtolower in the backend. But as always, this is most likely not just calling strtolower in the backend.

But feel free to prepare a pull request.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gauravparmar picture gauravparmar  路  4Comments

danielbarenkamp picture danielbarenkamp  路  4Comments

applibs picture applibs  路  4Comments

huglester picture huglester  路  5Comments

blacksheep-dev picture blacksheep-dev  路  4Comments