Commit Graph

2 Commits

Author SHA1 Message Date
oleibman 5a418ea1fb Recurse Directories Searching for Font File
Fix #2809. User felt font files should be searched recursively. The problem could be overcome merely by specifying a more precise font location. However, user has a point - the file layout on user's system is pretty common, and can be integrated into PhpSpreadsheet code easily. As a bonus, the DocBlock for setTrueTypeFontPath, which the user felt was misleading, doesn't even have to change.
2023-12-15 17:30:08 -08:00
oleibman 590e4c7af1 Allow More Fonts/Fontnames for Exact Width Calculation (#3326)
* Allow More Fonts/Fontnames for Exact Width Calculation

Fix #3190. A limited set of explicitly-named font files can be used when an exact width calculation is required. User noted that font files are named differently on Mac than on Windows (if the fonts are installed on Linux, the font names probably match Windows). Since the algorithm for generating the Mac file name from the font name seems easy, that algorithm is invoked when the Windows-named file is not found.

Moving on from there, it seems odd that only a small set of fonts are supported. It is, of course, impossible to support all possible fonts out of the box. However, it is possible to allow the user to supply additional mappings from font name to file name (or override existing mappings if neither the Windows nor Mac name matches the user's system), and doing so is permitted with this change:
```php
        \PhpOffice\PhpSpreadsheet\Shared\Font::setExtraFontArray([
            'fontname' => [ /* More than 1 can be specified */
                'x' => 'fontfilenamefornormal.ttf',
                'xb' => 'fontfilenameforbold.ttf',
                'xi' => 'fontfilenameforitalic.ttf',
                'xbi' => 'fontfilenameforbolditalic.ttf',
            ],
        ]);
```

* Unexpected Test Difference

... between Windows and Linux.
2023-02-04 07:25:31 -08:00