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

MSDF rendered glyphs have incorrect vertical and horizontal registration #1

Open
michaeljclark opened this issue Jun 15, 2021 · 0 comments

Comments

@michaeljclark
Copy link
Owner

There appears to be a rounding bug in msdfgen which causes glyphs to have incorrect vertical and horizontal registration. Look at the position of the u relative to the m in the attached image. FreeType on the left versus MSDF on the right.

image

MSDF has been disabled by default in glfont da5d920 primarily to log the issue in the commit history. MSDF is currently enabled in most of the examples. The metrics used to calculate the glyph bounds are the same. It is likely that msdfgen has a slightly different scaling of the contours than FreeType so the fix possibly requires making changes to msdfgen.

The FreeType metrics:

glyb/src/glyph.cc

Lines 575 to 580 in da5d920

/* font dimensions */
ox = (int)floorf((float)ftglyph->metrics.horiBearingX / 64.0f) - 1;
oy = (int)floorf((float)(ftglyph->metrics.horiBearingY -
ftglyph->metrics.height) / 64.0f) - 1;
w = (int)ceilf(ftglyph->metrics.width / 64.0f) + 2;
h = (int)ceilf(ftglyph->metrics.height / 64.0f) + 2;

The MSDF metrics:

glyb/src/msdf.cc

Lines 147 to 153 in da5d920

/* font dimensions */
ftglyph = face->ftface->glyph;
int ox = (int)floorf((float)ftglyph->metrics.horiBearingX / 64.0f) - 1;
int oy = (int)floorf((float)(ftglyph->metrics.horiBearingY -
ftglyph->metrics.height) / 64.0f) - 1;
int w = (int)ceilf(ftglyph->metrics.width / 64.0f) + 2;
int h = (int)ceilf(ftglyph->metrics.height / 64.0f) + 2;

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

No branches or pull requests

1 participant