Skip to content

Unable to load newer fonts in Zend_Pdf #439

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

Closed
dretsa opened this issue Sep 20, 2024 · 3 comments
Closed

Unable to load newer fonts in Zend_Pdf #439

dretsa opened this issue Sep 20, 2024 · 3 comments
Labels
to be released PR exists or in master, but not released yet
Milestone

Comments

@dretsa
Copy link

dretsa commented Sep 20, 2024

If you try to load a newer font using Zend_Pdf, you get an error Unable to read version 4 table. The check is done at:

/library/Zend/Pdf/FileParser/Font/OpenType.php:555

This is because newer fonts use OS/2 table version 4, which is similar to 3. There are no structural differences between OS/2 v3 and OS/2 v4. Changing the value on the if statement will make fonts work most of the time. There are some specification differences, although and I can't find any information on how they differ.

I am trying to use the font Inter in my PDFs.

I've searched for a way to convert from v4 to v3 but can't find any easy way to do so. Would it be hard to implement this change?

@wex
Copy link

wex commented Apr 17, 2025

I just took deeper look about this issue and managed to reproduce the issue and dug little bit deeper: "Version 4 was defined in OpenType 1.5. Version 4 has two fewer fields than version 5, and the same fields as in version 3. Although new fields were not added beyond those in version 3, the specification of certain fields was revised." (https://learn.microsoft.com/en-us/typography/opentype/spec/os2#version-4-table-format)

I'm gonna take a closer look on those revised fields, report back and possible create a PR if it's trivial change.

@wex
Copy link

wex commented Apr 17, 2025

Had some spare time, so here's some results.

Changed OS/2 fields between v3 and v4:

Impacts on code:

  • ulUnicodeRange:
    /**
    * @todo Font is recognized as Adobe Latin subset font if it only contains
    * Basic Latin characters (only bit 0 of Unicode range bits is set).
    * Actually, other Unicode subranges like General Punctuation (bit 31) also
    * fall into Adobe Latin characters. So this code has to be modified.
    */
    $this->isAdobeLatinSubset = (($unicodeRange1 == 1) && ($unicodeRange2 == 0) &&
    ($unicodeRange3 == 0) && ($unicodeRange4 == 0));
    $this->_debugLog(($this->isAdobeLatinSubset ? 'Is' : 'Is not') . ' a subset of Adobe Latin');
    • current code is not implementing correct behavior and has todo from release 1.12 (June 2012) -> no impact
  • fsSelection:
    /* Skip the font style bits. We use the values found in the 'head' table.
    * Also skip the first Unicode and last Unicode character indicies. Our
    * cmap implementation does not need these values.
    */
    $this->skipBytes(6);
    • fsSelection is skipped (with usFirstCharIndex and usLastCharIndex) -> no impact

Created a pull request to add support for v4 OS/2 tables - will open a bug about ulUnicodeRange -support!

@develart-projects develart-projects added the to be released PR exists or in master, but not released yet label May 7, 2025
@develart-projects develart-projects added this to the 1.24.4 milestone May 7, 2025
@develart-projects
Copy link
Collaborator

THank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to be released PR exists or in master, but not released yet
Projects
None yet
Development

No branches or pull requests

3 participants