php-font-lib
php-font-lib copied to clipboard
Chrome & Firefox errors when loading generated subset TTF fonts, for all fonts
I have generated a subset font for each font with only the letters from the font's file name. I was going to use these subset TTF files for a preview of the font.
Using these fonts: https://github.com/google/fonts All 1736 fonts fails with one of these errors:
(index):1 OTS parsing error: incorrect entrySelector for table directory (index):1 OTS parsing error: hhea: misaligned table
This is the code I am using to generate the subset files:
$tmp=tempnam(sys_get_temp_dir(), $strFontFamily);
$fontFile=\FontLib\Font::load($arrFont["path"]);
$fontFile->parse();
$fontFile->setSubset($strFontFamily);
$fontFile->reduce();
$fontFile->open($tmp, FontLib\BinaryStream::modeWrite);
$fontFile->encode(array("OS/2"));
$fontFile->close();
The original fonts work as a preview without any errors in Chrome and Firefox. The subset fonts fail in Chrome and Firefox.
The subset fonts work just fine in the Windows font preview tool and in Internet Explorer.
This may be useful:
"incorrect entrySelector for table directory" is thrown here: https://searchcode.com/codesearch/view/26727670/ Line 242
// entry_selector is Log2(maximum power of 2 <= numTables)
if (header->entry_selector != max_pow2) {
return OTS_FAILURE_MSG_HDR("incorrect entrySelector for table directory");
}
I have hardcoded incremental values for $entrySelector
, to no avail. The number of misaligned table
errors per font seem to increase though.
Porting the above code into PHP yields the exact same value in the same spot, so the problem is earlier/elsewhere.
"misaligned table" is thrown here: https://searchcode.com/codesearch/view/26727670/ Line 460
// tables must be 4-byte aligned
if (tables[i].offset & 3) {
return OTS_FAILURE_MSG_TAG("misaligned table", &tables[i].tag);
}
Hi sir oxygen.did you have a solution?I have the same problem. @oxygen
No, and I vaguely remember reporting it to Google, but most likely I didn't.
This needs to be reported to Chrome and Firefox and see if its their fault.
I mean I don't know enough about fonts to tell where the fault lies.
@oxygen, @jepsonwu have the same issue and was wondering on how you solved your subset problem? We also need font previews and they do not work when created over php-font-lib.
@oxygen @jepsonwu @roberthenniger I had the same problem
@PhenX is there a solution to this problem? How could we solve this issue since it would be awesome to create subsets without installing a big tech stack as npm-fontkit or something similar.
@PhenX is there a solution to this problem? How could we solve this issue since it would be awesome to create subsets without installing a big tech stack as npm-fontkit or something similar.
FWIW, I arrived at this issue from using fontkit :)
After looking into this a bit more it appears that generated TrueType font files may not fully conform to the spec. I've tested a number of fonts and identified the spec compliance issues that will prevent a font from loading in the browsers. I'm tracking the full list of non-compliance issues in #123.
The next release will address the bare minimum of issues identified so that web browsers will load a generated font.
Thank you!!!