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

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

Closed
oxygen opened this issue Feb 7, 2016 · 10 comments · Fixed by #124
Closed

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

oxygen opened this issue Feb 7, 2016 · 10 comments · Fixed by #124
Milestone

Comments

@oxygen
Copy link

oxygen commented Feb 7, 2016

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
Copy link
Author

oxygen commented Feb 7, 2016

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 oxygen changed the title Chrome errors when loading generated subset TTF fonts, for all fonts Chrome & Firefox errors when loading generated subset TTF fonts, for all fonts Feb 7, 2016
@oxygen
Copy link
Author

oxygen commented Feb 7, 2016

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

@jepsonwu
Copy link

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

@oxygen
Copy link
Author

oxygen commented Nov 23, 2017

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.

@roberthenniger
Copy link

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

@wilbur-yu
Copy link

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

@roberthenniger
Copy link

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

@oluwasayo
Copy link

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

@bsweeney bsweeney added this to the 0.5.4 milestone Dec 12, 2021
@bsweeney
Copy link
Member

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.

@oxygen
Copy link
Author

oxygen commented Jan 6, 2024

Thank you!!!

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 a pull request may close this issue.

6 participants