W3C home > Mailing lists > Public > whatwg@whatwg.org > August 2011

[whatwg] Requesting TextMetrics baseline property

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Tue, 30 Aug 2011 16:33:01 -0700
Message-ID: <CAAWBYDAgk40mEwLuPS-XfGom5rrRPnmhcAEsfe2L9pEiP4_u7g@mail.gmail.com>
On Tue, Aug 30, 2011 at 3:56 PM, Charles Pritchard <chuck at jumis.com> wrote:
> On Aug 30, 2011, at 3:26 PM, "Tab Atkins Jr." <jackalmage at gmail.com> wrote:
>> On Tue, Aug 30, 2011 at 3:19 PM, Charles Pritchard <chuck at jumis.com> wrote:
>>>
>>> I'd like to see a new property added to the TextMetrics object from Canvas
>>> 2d.
>>>
>>> var t = ctx.measureText('text span');
>>> t == { width: int, baseline: int };
>>>
>>> The baseline corresponds to the vertical offset of the anchor point.
>>> A tiny number. It's not the same as height, but it has a similar use.
>>>
>>> It allows allows the author to manage style markers on spans of text
>>> presenting different baselines.
>>>
>>> The following textBaseline image can not be generated in canvas:
>>> https://developer.mozilla.org/en/drawing_text_using_a_canvas
>>> http://www.whatwg.org/specs/web-apps/current-work/images/baselines.png
>>>
>>> It can, but we have to do css hacks/edge detection, as measureText is
>>> insufficient.
>>> By exposing the baseline offset in the TextMetrics method, we would be able
>>> to generate
>>> the lines in that image, and appropriately position the text captions.
>>>
>>> It seems appropriate that the illustration for textBaseline be something
>>> that can be easily generated from within canvas. The same standard is held
>>> for SVG documentation.
>>
>> Agreed, though there are multiple baselines that could be requested.
>> The diagram you link to points out three of them. ?The alphabetic
>> baseline is what you want most of the time, but all of them can be
>> useful depending on the type of text you're formatting.
>
> The author would have to set ctx.textBaseline, and re-run TextMetrics for each baseline they are incorporating.
>
> The enumeration of supported baselines is already in the canvas spec.

Okay, that's reasonable.

~TJ
Received on Tuesday, 30 August 2011 16:33:01 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 30 January 2013 18:48:05 GMT