Skip to content

hhea.numberOfHMetrics not correct for monospace #3014

Closed as not planned
Closed as not planned

Description

@aaronbell

Microsoft makes a specific recommendation for monospace fonts to set the hhea.numberofHMetrics value to 3.

Following that guidance, Fontbakery recently implemented a check that issues a FAIL if this is not set per Microsoft's recommendation.

However, as far as I can tell, fonttools does not consider whether a font is monospaced when calculating hhea.numberOfHMetrics. In my current project, I'm noting that I'm getting a value of 1010 out rather than 3. And evaluating a variety of monospace fonts in the Google Fonts library (as well as my own Cascadia Code which is built using fonttools), none list a hhea.numberOfHMetrics of 3.

I believe a special casing needs to be added to the hhea compile / decompile to account for monospace fonts.

Activity

  1. justvanrossum commented on Mar 1, 2023

    @justvanrossum
    Collaborator

    Regardless of what fonttools will have to do, a fontbakery FAIL is rather overreaching, especially since the quoted recommendation uses the word "suggested".

  2. behdad commented on Mar 1, 2023

    @behdad
    Member

    Most monospace fonts these days are not truly "monospaced" because of zerowidth marks. That's probably why you see a large value calculated by fonttools.

  3. aaronbell commented on Mar 1, 2023

    @aaronbell
    Author

    I kind of got the sense that the 3 is to account for zerowidth marks and doublewidth CJK, (otherwise, wouldn't it just be 1?), but could be mistaken.

  4. dscorbett commented on Mar 1, 2023

    @dscorbett
    Member

    Why does Microsoft recommend this? I assume it is based on their old advice that “Glyph 1 should have no contours and zero advance width”. That is, if the font’s monospace width is n, then .notdef has width n, glyph 1 has width 0, and the rest have width n. That requires a minimum of 3 longHorMetric records in 'hmtx'. However, that is an optimization; it’s not wrong for a font to have multiple trailing longHorMetric records with the same advanceWidth, it’s just inefficient. Therefore, a FAIL seems too strong.

    Microsoft’s current advice doesn’t mention a special width for glyph 1 (.null) anymore. That means all glyphs in a monospace font could have the same width, so only 1 longHorMetric record is necessary, so hhea.numberOfHMetrics should be 1 (under a strict definition of monospace font, without zero-width marks).

  5. behdad commented on Mar 1, 2023

    @behdad
    Member

    I kind of got the sense that the 3 is to account for zerowidth marks and doublewidth CJK, (otherwise, wouldn't it just be 1?), but could be mistaken.

    Yeah it doesn't work that way. The optimization is that all the glyphs at the tail of the font that have the same advance can be removed and encoded as just one entry...

  6. anthrotype commented on Mar 1, 2023

    @anthrotype
    Member

    if fontbakery's check merely asserts that hhea.numberofHMetrics == 3 "because the spec recommends so", then it is completely bogus and should simply be ignored/removed

  7. felipesanches commented on Mar 3, 2023

    @felipesanches

    @madig suggested adding that FAIL. I have now downgraded it to a WARN and changed a bit the wording of the message, directing users to come read this conversation.

    I'm open to further improving the check by either completely removing this WARN, or by making it more informative to the users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions