diff --git a/index.js b/index.js index 9d3ea19..33f66c3 100644 --- a/index.js +++ b/index.js @@ -55,7 +55,7 @@ export default class TinySDF { // If the glyph overflows the canvas size, it will be clipped at the bottom/right const glyphWidth = Math.min(this.size - this.buffer, Math.ceil(actualBoundingBoxRight - actualBoundingBoxLeft)); - const glyphHeight = Math.min(this.size - this.buffer, Math.ceil(actualBoundingBoxAscent + actualBoundingBoxDescent)); + const glyphHeight = Math.min(this.size - this.buffer, Math.ceil(actualBoundingBoxAscent) + Math.ceil(actualBoundingBoxDescent)); const width = glyphWidth + 2 * this.buffer; const height = glyphHeight + 2 * this.buffer; @@ -80,14 +80,12 @@ export default class TinySDF { gridOuter.fill(INF, 0, len); gridInner.fill(0, 0, len); - const offset = (width - glyphWidth) >> 1; - for (let y = 0; y < glyphHeight; y++) { for (let x = 0; x < glyphWidth; x++) { const a = imgData.data[4 * (y * glyphWidth + x) + 3] / 255; // alpha value if (a === 0) continue; // empty pixels - const j = (y + offset) * width + x + offset; + const j = (y + buffer) * width + x + buffer; if (a === 1) { // fully drawn pixels gridOuter[j] = 0; diff --git a/test/fixtures/1-out.json b/test/fixtures/1-out.json index 2a73176..c2fcc48 100644 --- a/test/fixtures/1-out.json +++ b/test/fixtures/1-out.json @@ -1,8 +1,8 @@ { "width": 54, - "height": 50, + "height": 51, "glyphWidth": 48, - "glyphHeight": 44, + "glyphHeight": 45, "glyphTop": 39, "glyphLeft": 0, "glyphAdvance": 48 diff --git a/test/fixtures/1-sdf.png b/test/fixtures/1-sdf.png index 079a9bd..3b50280 100644 Binary files a/test/fixtures/1-sdf.png and b/test/fixtures/1-sdf.png differ