Re: Text metrics with display:none

Hi Brian,

On 28/11/11 12:59 PM, Brian Birtles wrote:
> What is the expected result of the following methods called on the
> <text> element?
>
>   getNumberOfChars
>   getComputedTextLength
>   getSubStringLength
>   getStartPositionOfChar/getEndPositionOfChar/getExtentOfChar
 >
> It seems that most of the major browsers are treating the display:none
> characters as if they don't exist for the purpose of these metrics. Most
> likely such characters are not present in the rendering tree and
> calculating font metrics is tied to the rendering tree.
>
> My questions:
>
> 1) Have I understood the spec correctly--that getNumberOfChars should
> return 3?

I believe you have.

> 2) If so, should we change the spec or the browsers?

Both. :)

Here is my go at a proposed behaviour:

* The indices that these methods work on are the textContent-like indices.

* When getSubStringLength includes characters that correspond to glyphs 
that are not rendered due to display:none (or say because they've fallen 
off the end of a <textPath>), then these characters don't contribute to 
the string length.  In an extreme case, calling getSubStringLength on 
<text display="none">abc</text> returns 0.

* getStartPositionOfChar and getEndPositionOfChar return NaN when given 
a character index that corresponds to a glyph not being displayed.

* getExtentOfChar returns 0 when given a character index that 
corresponds to a glyph not being displayed.

I choose 0 for getExtentOfChar to be consistent with getSubStringLength 
just ignoring the non-displayed characters.

WDYT?

Received on Thursday, 8 December 2011 03:56:45 UTC