dompdf / php-font-lib

A library to read, parse, export and make subsets of different types of font files.
GNU Lesser General Public License v2.1
1.73k stars 256 forks source link

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

Closed oxygen closed 6 months ago

oxygen commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 6 years ago

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

oxygen commented 6 years ago

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 commented 4 years ago

@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 commented 4 years ago

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

roberthenniger commented 4 years ago

@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 commented 3 years ago

@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 commented 9 months ago

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 commented 6 months ago

Thank you!!!