Join GitHub today
[font-metrics-api] Compatibility notes with Canvas TextMetrics API #832
Following up with some questions from: #828
It seems that a Houdini TextMetrics API has to figure out proper use cases to track. Meanwhile, we'd like to move forward on WHATWG over the Canvas update of the TextMetrics API. And I'd really appreciate some input from folks here about some logical issues with a Canvas TextMetrics API.
The use cases for canvas are mostly caret position and character highlight.
For Canvas, there's very little layout requirements (no vertical text, no multi-line for example). So we could think of it as a very simplified API, as long as it's not egregiously wrong from a layout perspective. Would something like this be possible?
referenced this issue
Nov 7, 2018
Careful with the terminology here... is "character" synonymous with "grapheme cluster" in that sentence?
From a JS point of view, as a user of a Canvas TextMetrics API, I would assume "character" really means "UTF-16 code unit", because that's what JS strings use (and expose). But if so, it's not necessarily possible to "draw a background on a single character", which might be only half of a surrogate pair.
So maybe you meant "Unicode codepoint"? That's more logical in terms of acting on "a single character"... but still problematic. A single Unicode character may be rendered as multiple disjoint glyphs, so that drawing a background on that single character is actually much harder than just painting a rectangle. Consider the two-character sequence <U+0D15, U+0D4A> (spelling a simple Malayalam consonant-vowel syllable). This renders as three glyphs, കൊ, where the vowel U+0D4A (ൊ) is split into two parts, one to the left of the consonant U+0D15 (ക) and one to the right of it. What "left-side position and advance" does the character U+0D4A have?
OK, so maybe you really meant "grapheme cluster" everywhere, and never some other lower-level version of "character"? Then <U+0D15, U+0D4A> is a single grapheme cluster, it has a single left-side and advance, and you could reasonably use these to paint a background for that single cluster (not character). But is that really what people want? The Malayalam syllable കൊ is made up of two characters, by any common understanding of "character", and to be unable to address those characters as separate units seems wrong.
Text is hard!