Skip to content

Commit

Permalink
Fallback to canvas measurement when font glyph not available
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rocketraman committed Aug 24, 2015
1 parent 5b604e3 commit 4555c4e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/core/TextFontMetrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 4555c4e

Please sign in to comment.