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

Fix glyph clipping at the bottom/2 #42 #43

Merged
merged 1 commit into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class TinySDF {

// The integer/pixel part of the top alignment is encoded in metrics.glyphTop
// The remainder is implicitly encoded in the rasterization
const glyphTop = Math.floor(actualBoundingBoxAscent);
const glyphTop = Math.ceil(actualBoundingBoxAscent);
const glyphLeft = 0;

// If the glyph overflows the canvas size, it will be clipped at the bottom/right
Expand All @@ -68,7 +68,7 @@ export default class TinySDF {

const {ctx, buffer, gridInner, gridOuter} = this;
ctx.clearRect(buffer, buffer, glyphWidth, glyphHeight);
ctx.fillText(char, buffer, buffer + glyphTop + 1);
ctx.fillText(char, buffer, buffer + glyphTop);
const imgData = ctx.getImageData(buffer, buffer, glyphWidth, glyphHeight);

// Initialize grids outside the glyph range to alpha 0
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/1-out.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"height": 51,
"glyphWidth": 48,
"glyphHeight": 45,
"glyphTop": 39,
"glyphTop": 40,
"glyphLeft": 0,
"glyphAdvance": 48
}