Skip to content

Two fixes for placement of sbix glyphs - #2174

Open
LaurenzV wants to merge 2 commits into
googlefonts:mainfrom
LaurenzV:fix-lsb
Open

LaurenzV wants to merge 2 commits into
googlefonts:mainfrom
LaurenzV:fix-lsb

Conversation

@LaurenzV

Copy link
Copy Markdown
Contributor

Ok so, I've been going into a bit of a rabbit hole prompted by some issues we encountered with the placement of sbix glyphs in Vello. As part of this, i had AI generate a test case that is checks different combination of metrics in a sbix glyph to see how it behaves.

Consider the following two SVGs, which contain the fonts embedded (once with CFF and once with glyf outlines)

sbix_grid_embedded_cff sbix_grid_embedded_glyf

If I open these SVGs in Safari, all letters are centered in each cell correctly:
image

If I open these SVGs in Chrome on Windows, the glyf one looks like this:
image
the CFF one like this:
image

(on Chrome on MacOS, the CFF one is actually completetly broken, interestingly enough).

Anyway, current Vello fails the glyf test case in the same way. For the CFF one it's even more broken as there also is a vertical shift:
image

I believe the differences stem from two issues in skrifa, both of which this PR fixes.

Vertical placement of CFF glyphs

The spec says

When placing the graphic within the line of text, the placement depends upon whether there are contours in the 'glyf' table for the current glyph ID:

  • If there is no glyph contour, the glyph design space origin for the graphic is placed at the starting drawing position for this glyph. The lsb value for the current glyph ID from the 'hmtx' table has no effect.
  • If there is a glyph contour, the glyph design space origin for the graphic is placed at the lower left corner of the glyph bounding box (xMin, yMin).

I guess the spec must literally mean only for glyf tables, i.e. for CFF tables we should not apply yMin, even if there is a CFF outline. Because if I do this (applied in the first commit), Vello now exactly matches Chrome rendering, and compared to CoreText there are only horizontal shifts now. I guess Chrome must be getting those metrics differently somehow, hence why it's not affected by this specific bug.

LSB placement

As quoted above, the spec also says The lsb value for the current glyph ID from the 'hmtx' table has no effect.. So for CFF fonts or for TTF fonts where the glyph has no outline, the lsb value should not be used at all. If I apply this patch (in the second commit), Vello now renders all glyphs (except for the two that don't work because skrifa doesn't support dupe glyphs yet) correctly!

I hope I didn't miss anything and that these changes are correct.

@dfrg dfrg left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One suggested simplification but otherwise looks good to me.

I don't think we anticipated sbix+CFF fonts (what strangeness is this?) or sbix glyphs paired with empty outlines. Nice catch!

Comment thread skrifa/src/metrics.rs
}

impl GlyphMetrics<'_> {
pub(crate) fn has_glyf_contours(&self, glyph_id: GlyphId) -> Option<bool> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should probably be fn glyf_y_min(...) -> Option<i16> gated by number of contours being non-zero? That gives us the answer we actually want and avoids a second load of the glyph.

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 this pull request may close these issues.

2 participants