-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TrueType Font file not found error on Mac with bold/italic font and AUTOSIZE_METHOD_EXACT #3190
Comments
I think I see a way we might be able to implement this in a reasonable and testable manner. It would help if you can give me a list of what the file names for each of the entries in |
Thanks for looking into it !
Here you go <?php
include("vendor/autoload.php");
use PhpOffice\PhpSpreadsheet\Shared\Font;
chdir("/System/Library/Fonts/Supplemental/");
foreach(array_keys(Font::FONT_FILE_NAMES) as $f) {
echo "### $f*\n";
foreach(glob($f . "*") as $n)
echo "- $n\n";
} Arial*
Calibri*Comic Sans MS*
Courier New*
Georgia*
Impact*
Liberation Sans*Lucida Console*Lucida Sans Unicode*Microsoft Sans Serif*
Palatino Linotype*Symbol*Tahoma*
Times New Roman*
Trebuchet MS*
Verdana*
|
Thank you. No surprises there, except for the additional Arial fonts (I plan to support "user-defined" fonts in my PR, so I may or may not add them to the "known" list). Also, some are missing from the Mac directory (which won't be any worse a situation than they're in now). I will push my PR tonight, or at least sometime over the weekend, |
Awesome, thanks !
…On Sat, 28 Jan 2023 at 00:30, 'oleibman' via Damien Regad < ***@***.***> wrote:
Thank you. No surprises there, except for the additional Arial fonts (I
plan to support "user-defined" fonts in my PR, so I may or may not add them
to the "known" list). Also, some are missing from the Mac directory (which
won't be any worse a situation than they're in now). I will push my PR
tonight, or at least sometime over the weekend,
—
Reply to this email directly, view it on GitHub
<#3190 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADN2Y2EJAEGGWKFPF6GEQTWURLBHANCNFSM6AAAAAASFMBV5I>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Fix PHPOffice#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', ], ]); ```
My tests are fairly artificial. Can you test against PR #3326 and verify that it meets your needs? |
* 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.
@oleibman Apologies, I had a busy week and did not find the time to test the PR in time. Many thanks for the fix ! |
This is:
What is the expected behavior?
Spreadsheet generated with text formatted as defined in default style, with autosized column
What is the current behavior?
Exception: TrueType Font file not found in PhpSpreadsheet/Shared/Font.php on line 557
But the font file is there... it's just named differently. On my Mac, fonts are in
/System/Library/Fonts/Supplemental
, Arial files are as follows (naming and behaviour is identical with other fonts):instead of the expected
which are generated by PhpOffice\PhpSpreadsheet\Shared\Font::getTrueTypeFontFileFromFont().
As a workaround, I aliased the font files, but that's a pain...
Another workaround is to not use AUTOSIZE_METHOD_EXACT, but in this case I actually need it.
It would be nice, considering that this naming is standard on Mac if PhpSpreadsheet were able to automatically use the
Bold/Italic/Bold Italic
suffix variants in addition to the existingbd/i/bi
.What are the steps to reproduce?
What features do you think are causing the issue
Does an issue affect all spreadsheet file formats? If not, which formats are affected?
Probably yes, but tested only with Xlsx.
Which versions of PhpSpreadsheet and PHP are affected?
Tested with 1.24.1 and 1.25.2 on PHP 8.1.11.
The text was updated successfully, but these errors were encountered: