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

[whatwg] Canvas 2d Proposal - Adding float TextMetrics baseline

From: Charles Pritchard <chuck@jumis.com>
Date: Thu, 18 Aug 2011 18:29:50 -0700
Message-ID: <4E4DBC8E.5030306@jumis.com>
Following is a change proposal for the canvas 2d spec, adding an 
additional floating point attribute to TextMetrics, the object returned 
by measureText.

In my work on decorative text, we have had to get the current baseline 
through doing css measurements. By setting the baseline of a div tag, 
and measuring the changes in css values, we are able to get the values 
for all of the baselines. It's a work-around.

This is something I prepared, to try to get an additional result in 
measureText.

example:
var textMetrics = ctx.measureText('test');
Result (example numbers):
textMetrics = { width: 40, baseline: 10 }

This change proposal is part of an effort of improving the usability of 
the canvas tag.

The *measureText()* method takes one argument, /text/. When the method 
is invoked, the user agent must replace all the space characters in 
/text/ with U+0020 SPACE characters, and then must form a hypothetical 
infinitely wide CSS line box containing a single inline box containing 
the text /text/, with all the properties at their initial values except 
the 'font' property of the inline element set to the current font of the 
context, as given by the _font_ 
<file:///private/var/folders/W6/W6JvvNbZE3m-nm24bFZ2rE+++TI/-Tmp-/TemporaryItems/canvasissue131.html#dom-context-2d-font> attribute, 
and must then return a new _TextMetrics_ 
<file:///private/var/folders/W6/W6JvvNbZE3m-nm24bFZ2rE+++TI/-Tmp-/TemporaryItems/canvasissue131.html#textmetrics> object 
with its _width_ 
<file:///private/var/folders/W6/W6JvvNbZE3m-nm24bFZ2rE+++TI/-Tmp-/TemporaryItems/canvasissue131.html#dom-textmetrics-width> attribute 
set to the width of that inline box, in CSS pixels and its _baseline_ 
<file:///private/var/folders/W6/W6JvvNbZE3m-nm24bFZ2rE+++TI/-Tmp-/TemporaryItems/canvasissue131.html#dom-textmetrics-baseline> attribute 
set to the /anchor point/'s vertical position as determined by the 
current _textBaseline_ 
<file:///private/var/folders/W6/W6JvvNbZE3m-nm24bFZ2rE+++TI/-Tmp-/TemporaryItems/canvasissue131.html#dom-context-2d-textbaseline> value, 
in CSS pixels. _[CSS]_ 
<file:///private/var/folders/W6/W6JvvNbZE3m-nm24bFZ2rE+++TI/-Tmp-/TemporaryItems/canvasissue131.html#refsCSS> 


The _TextMetrics_ 
<file:///private/var/folders/W6/W6JvvNbZE3m-nm24bFZ2rE+++TI/-Tmp-/TemporaryItems/canvasissue131.html#textmetrics> interface 
is used for the objects returned from _measureText()_ 
<file:///private/var/folders/W6/W6JvvNbZE3m-nm24bFZ2rE+++TI/-Tmp-/TemporaryItems/canvasissue131.html#dom-context-2d-measuretext>. 
It has two attributes, *width* and *baseline*, which are set by the 
_measureText()_ 
<file:///private/var/folders/W6/W6JvvNbZE3m-nm24bFZ2rE+++TI/-Tmp-/TemporaryItems/canvasissue131.html#dom-context-2d-measuretext> method. 
Received on Thursday, 18 August 2011 18:29:50 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:35 UTC