Try to align glyphs on their baselines after stem darkening

This commit is contained in:
Patrick Walton 2017-11-10 08:16:27 -08:00
parent f2d5ced933
commit a73fb9ab8d
1 changed files with 8 additions and 2 deletions

View File

@ -240,6 +240,12 @@ export abstract class TextRenderer extends Renderer {
const atlasGlyphs = this.renderContext.atlasGlyphs;
const pixelsPerUnit = this.displayPixelsPerUnit;
// FIXME(pcwalton): This is a hack that tries to align glyphs on their baselines after
// stem darkening. It's better than nothing, but we should really do better.
const stemDarkeningOffset = glmatrix.vec2.clone(this.stemDarkeningAmount);
glmatrix.vec2.scale(stemDarkeningOffset, stemDarkeningOffset, pixelsPerUnit);
glmatrix.vec2.scale(stemDarkeningOffset, stemDarkeningOffset, 1.0 / Math.sqrt(2.0));
const transforms = new Float32Array((pathCount + 1) * 4);
for (const glyph of atlasGlyphs) {
@ -248,8 +254,8 @@ export abstract class TextRenderer extends Renderer {
transforms[pathID * 4 + 0] = pixelsPerUnit;
transforms[pathID * 4 + 1] = pixelsPerUnit;
transforms[pathID * 4 + 2] = atlasOrigin[0];
transforms[pathID * 4 + 3] = atlasOrigin[1];
transforms[pathID * 4 + 2] = atlasOrigin[0] + stemDarkeningOffset[0];
transforms[pathID * 4 + 3] = atlasOrigin[1] + stemDarkeningOffset[1];
}
return transforms;