From 4555c4ee9625c4d77f3d7e8c904e25cb6f34d615 Mon Sep 17 00:00:00 2001 From: Raman Gupta Date: Mon, 24 Aug 2015 18:37:22 -0400 Subject: [PATCH] Fallback to canvas measurement when font glyph not available If characters are inserted for which the configured font has no glyph, the code assigns a default width of 0 to the character. This causes the line wrapping and cursor positioning logic to be incorrect. Instead of assigning a default width of 0, fallback to a canvas-based measurement to determine the width the browser will use when rendering the character. Fixes #11. --- src/core/TextFontMetrics.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/TextFontMetrics.js b/src/core/TextFontMetrics.js index 7216fe4..425c5f6 100644 --- a/src/core/TextFontMetrics.js +++ b/src/core/TextFontMetrics.js @@ -49,7 +49,8 @@ function calcCharAdvanceOpenType(char, fontSize, font, unitsPerEm) { let glyph = font.charToGlyph(char) return glyph.unicode ? glyph.advanceWidth * calcFontScale(fontSize, unitsPerEm) : - 0 + // font doesn't contain a glyph for this char, fallback to canvas measurement + calcTextAdvanceCanvas(char, fontSize, font) } let canvas = _.memoize(function() {