From 07a94ceab3ebd4d330198f11e06ff72867ea2fa9 Mon Sep 17 00:00:00 2001 From: Boris Ulyanov Date: Fri, 7 Jan 2022 08:27:19 +0300 Subject: [PATCH] Fix glyph clipping at the bottom/2 #42 --- index.js | 4 ++-- test/fixtures/1-out.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 5e512c9..f72b8bb 100644 --- a/index.js +++ b/index.js @@ -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 @@ -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 diff --git a/test/fixtures/1-out.json b/test/fixtures/1-out.json index c2fcc48..97c1b3b 100644 --- a/test/fixtures/1-out.json +++ b/test/fixtures/1-out.json @@ -3,7 +3,7 @@ "height": 51, "glyphWidth": 48, "glyphHeight": 45, - "glyphTop": 39, + "glyphTop": 40, "glyphLeft": 0, "glyphAdvance": 48 } \ No newline at end of file