Skip to content
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

Fix PHP Notice Processing Font GPOS OTL Data #1967

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

jakejackson1
Copy link
Contributor

This notice occurred when loading mPDF with the commercially-licensed Myriad Pro TTF font file. Because it isn't an open-source font, and I don't have another font that exhibits this behaviour, I haven't written a unit test for it.

If you have access to the font, the following snippet will generate the PHP notice when the font cache is being created (delete the font cache afterward to replicate consecutively):

<?php

use Mpdf\Mpdf;

require_once __DIR__ . '/vendor/autoload.php';

error_reporting(E_ALL);

$mpdf = new Mpdf([
	'fontDir' => [
		__DIR__ . '/ttfonts',
		__DIR__ . '/test-fonts',
	],
	'fontdata' => [
		'myriadpro' => [
			'R' => 'MyriadPro-Regular.ttf',
			'useOTL' => 0x80,

		]
	],
	'default_font' => 'myriadpro',
]);

$mpdf->WriteHTML( 'Test' );
$mpdf->Close();

The underlying issue was when reading the font's GPOS FeatureList table. In the case of Myriad Pro, it includes the "Size" feature, but has no data associated with it. mPDF expects all features to have associated data in the form of a LookUpListIndex, even though a features LookUpCount can be zero.

I gather this font supported "Size" in the past, but it was replaced by the STAT table and the feature key was never fully removed.

This notice occurred when loading mPDF with the commercially-licensed Myriad Pro TTF font file. Because it isn't an open-source font, and I don't know another font that exhibits this behaviour, I haven't written a unit test for it.

If you have access to the font, the following snippet will generate the PHP notice when the font cache is being created (delete the font cache afterward to replicate):

```
<?php

use Mpdf\Mpdf;

require_once __DIR__ . '/vendor/autoload.php';

error_reporting(E_ALL);

$mpdf = new Mpdf([
	'fontDir' => [
		__DIR__ . '/ttfonts',
		__DIR__ . '/test-fonts',
	],
	'fontdata' => [
		'myriadpro' => [
			'R' => 'MyriadPro-Regular.ttf',
			'useOTL' => 0x80,

		]
	],
	'default_font' => 'myriadpro',
]);

$mpdf->WriteHTML( 'Test' );
$mpdf->Close();
```

The underlying issue was when reading the font's GPOS FeatureList table. In the case of Myriad Pro, it includes the "Size" feature, but has no data associated with it. mPDF expects all features to have associated data in the form of a LookUpListIndex (https://github.com/mpdf/mpdf/blob/development/src/TTFontFile.php#L3377), even though a features LookUpCount can be zero (https://github.com/mpdf/mpdf/blob/development/src/TTFontFile.php#L3355-L3357).

I gather this font supported "Size" in the past, but it was replaced by the STAT table and the feature key was never fully removed (https://learn.microsoft.com/en-us/typography/opentype/spec/features_pt#size).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant