php-font-lib icon indicating copy to clipboard operation
php-font-lib copied to clipboard

Chrome & Firefox errors when loading generated subset TTF fonts, for all fonts

Open oxygen opened this issue 8 years ago • 8 comments

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();

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/30616454-chrome-firefox-errors-when-loading-generated-subset-ttf-fonts-for-all-fonts?utm_campaign=plugin&utm_content=tracker%2F317728&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F317728&utm_medium=issues&utm_source=github).

oxygen avatar Feb 07 '16 02:02 oxygen

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.

oxygen avatar Feb 07 '16 02:02 oxygen

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);
    }

oxygen avatar Feb 07 '16 02:02 oxygen

Hi sir oxygen.did you have a solution?I have the same problem. @oxygen

jepsonwu avatar Nov 22 '17 03:11 jepsonwu

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 avatar Nov 23 '17 13:11 oxygen

@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.

roberthenniger avatar Apr 14 '20 22:04 roberthenniger

@oxygen @jepsonwu @roberthenniger I had the same problem image

wilbur-yu avatar Apr 15 '20 09:04 wilbur-yu

@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.

roberthenniger avatar Apr 16 '20 10:04 roberthenniger

@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 :)

oluwasayo avatar Apr 22 '21 14:04 oluwasayo

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.

bsweeney avatar Oct 14 '23 17:10 bsweeney

Thank you!!!

oxygen avatar Jan 06 '24 15:01 oxygen