Skip to content

Commit 7711a1f

Browse files
fserbdomenic
authored andcommitted
Add advances to TextMetrics and change baselines API
This changes the canvas TextMetrics interface mixin in two ways: * It adds an advances attribute, for the advances of each character. * It changes the baselines-retrieval API from separate attributes to a dictionary returned by a getBaselines() method.
1 parent d6feb05 commit 7711a1f

File tree

1 file changed

+39
-26
lines changed

1 file changed

+39
-26
lines changed

source

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60014,10 +60014,18 @@ interface <dfn>CanvasPattern</dfn> {
6001460014
void <span data-x="dom-canvaspattern-setTransform">setTransform</span>(optional <span>DOMMatrix2DInit</span> transform);
6001560015
};
6001660016

60017+
[Exposed=(Window,Worker)]
60018+
dictionary <dfn>Baselines</dfn> {
60019+
double <span data-x="dom-Baselines-alphabetic">alphabetic</span>;
60020+
double <span data-x="dom-Baselines-hanging">hanging</span>;
60021+
double <span data-x="dom-Baselines-ideographic">ideographic</span>;
60022+
};
60023+
6001760024
[Exposed=(Window,Worker)]
6001860025
interface <dfn>TextMetrics</dfn> {
6001960026
// x-direction
6002060027
readonly attribute double <span data-x="dom-textmetrics-width">width</span>; // advance width
60028+
readonly attribute FrozenArray&lt;double> <span data-x="dom-textmetrics-advances">advances</span>;
6002160029
readonly attribute double <span data-x="dom-textmetrics-actualBoundingBoxLeft">actualBoundingBoxLeft</span>;
6002260030
readonly attribute double <span data-x="dom-textmetrics-actualBoundingBoxRight">actualBoundingBoxRight</span>;
6002360031

@@ -60028,9 +60036,7 @@ interface <dfn>TextMetrics</dfn> {
6002860036
readonly attribute double <span data-x="dom-textmetrics-actualBoundingBoxDescent">actualBoundingBoxDescent</span>;
6002960037
readonly attribute double <span data-x="dom-textmetrics-emHeightAscent">emHeightAscent</span>;
6003060038
readonly attribute double <span data-x="dom-textmetrics-emHeightDescent">emHeightDescent</span>;
60031-
readonly attribute double <span data-x="dom-textmetrics-hangingBaseline">hangingBaseline</span>;
60032-
readonly attribute double <span data-x="dom-textmetrics-alphabeticBaseline">alphabeticBaseline</span>;
60033-
readonly attribute double <span data-x="dom-textmetrics-ideographicBaseline">ideographicBaseline</span>;
60039+
<span>Baselines</span> <span data-x="dom-textmetrics-getBaselines">getBaselines</span>();
6003460040
};
6003560041

6003660042
[<span data-x="dom-imagedata">Constructor</span>(unsigned long sw, unsigned long sh),
@@ -62953,6 +62959,7 @@ try {
6295362959
</dd>
6295462960

6295562961
<dt><var>metrics</var> . <code subdfn data-x="dom-textmetrics-width">width</code></dt>
62962+
<dt><var>metrics</var> . <code subdfn data-x="dom-textmetrics-advances">advances</code></dt>
6295662963
<dt><var>metrics</var> . <code subdfn data-x="dom-textmetrics-actualBoundingBoxLeft">actualBoundingBoxLeft</code></dt>
6295762964
<dt><var>metrics</var> . <code subdfn data-x="dom-textmetrics-actualBoundingBoxRight">actualBoundingBoxRight</code></dt>
6295862965
<dt><var>metrics</var> . <code subdfn data-x="dom-textmetrics-fontBoundingBoxAscent">fontBoundingBoxAscent</code></dt>
@@ -62961,9 +62968,7 @@ try {
6296162968
<dt><var>metrics</var> . <code subdfn data-x="dom-textmetrics-actualBoundingBoxDescent">actualBoundingBoxDescent</code></dt>
6296262969
<dt><var>metrics</var> . <code subdfn data-x="dom-textmetrics-emHeightAscent">emHeightAscent</code></dt>
6296362970
<dt><var>metrics</var> . <code subdfn data-x="dom-textmetrics-emHeightDescent">emHeightDescent</code></dt>
62964-
<dt><var>metrics</var> . <code subdfn data-x="dom-textmetrics-hangingBaseline">hangingBaseline</code></dt>
62965-
<dt><var>metrics</var> . <code subdfn data-x="dom-textmetrics-alphabeticBaseline">alphabeticBaseline</code></dt>
62966-
<dt><var>metrics</var> . <code subdfn data-x="dom-textmetrics-ideographicBaseline">ideographicBaseline</code></dt>
62971+
<dt><var>metrics</var> . <code subdfn data-x="dom-textmetrics-getBaselines">getBaselines</code>()</dt>
6296762972

6296862973
<dd>
6296962974

@@ -63150,7 +63155,7 @@ v6DVT (also check for '- -' bits in the part above) -->
6315063155
argument, <var>text</var>. When the method is invoked, the user agent must run the
6315163156
<span>text preparation algorithm</span>, passing it <var>text</var> and the object implementing
6315263157
the <code>CanvasText</code> interface, and then using the returned <span>inline box</span> must
63153-
create a new <code>TextMetrics</code> object with its attributes set as described in the following
63158+
create a new <code>TextMetrics</code> object with members behaving as described in the following
6315463159
list.
6315563160
<!--ADD-TOPIC:Security-->
6315663161
If doing these measurements requires using a font that has an <span>origin</span> that is not the
@@ -63173,6 +63178,13 @@ v6DVT (also check for '- -' bits in the part above) -->
6317363178
<dd><p>The width of that <span>inline box</span>, in <span data-x="'px'">CSS pixels</span>. (The
6317463179
text's advance width.)</p></dd>
6317563180

63181+
<dt><dfn><code data-x="dom-textmetrics-advances">advances</code></dfn> attribute</dt>
63182+
63183+
<dd><p>Returns a frozen array containing advances for each character in the measured text. Each
63184+
advance is measured as the distance from the beginning of the string (starting at 0) up to the
63185+
left side of the character. The same frozen array object must be returned every time this
63186+
attribute's getter is invoked.</p></dd>
63187+
6317663188
<dt><dfn><code data-x="dom-textmetrics-actualBoundingBoxLeft">actualBoundingBoxLeft</code></dfn> attribute</dt>
6317763189

6317863190
<dd>
@@ -63270,30 +63282,31 @@ v6DVT (also check for '- -' bits in the part above) -->
6327063282
indicating that the given baseline is below the bottom of that em square (so this value will
6327163283
usually be negative). (Zero if the given baseline is the bottom of that em square.)</p></dd>
6327263284

63273-
<dt><dfn><code data-x="dom-textmetrics-hangingBaseline">hangingBaseline</code></dfn> attribute</dt>
63274-
63275-
<dd><p>The distance from the horizontal line indicated by the <code
63276-
data-x="dom-context-2d-textBaseline">textBaseline</code> attribute to the hanging baseline of the
63277-
<span>line box</span>, in <span data-x="'px'">CSS pixels</span>; positive numbers indicating that
63278-
the given baseline is below the hanging baseline. (Zero if the given baseline is the hanging
63279-
baseline.)</p></dd>
63285+
<dt><dfn><code data-x="dom-textmetrics-getBaselines">getBaselines()</code></dfn> method</dt>
6328063286

63281-
<dt><dfn><code data-x="dom-textmetrics-alphabeticBaseline">alphabeticBaseline</code></dfn> attribute</dt>
63287+
<dd>
63288+
<p>Returns a <code>Baselines</code> dictionary containing available baselines:
6328263289

63283-
<dd><p>The distance from the horizontal line indicated by the <code
63284-
data-x="dom-context-2d-textBaseline">textBaseline</code> attribute to the alphabetic baseline of
63285-
the <span>line box</span>, in <span data-x="'px'">CSS pixels</span>; positive numbers indicating
63286-
that the given baseline is below the alphabetic baseline. (Zero if the given baseline is the
63287-
alphabetic baseline.)</p></dd>
63290+
<ul>
63291+
<li><p>If the alphabetic baseline is available for this text, the <dfn><code
63292+
data-x="dom-Baselines-alphabetic">alphabetic</code></dfn> dictionary member must be set to that
63293+
baseline value.</p></li>
6328863294

63289-
<dt><dfn><code data-x="dom-textmetrics-ideographicBaseline">ideographicBaseline</code></dfn> attribute</dt>
63295+
<li><p>If the hanging baseline is available for this text, the <dfn><code
63296+
data-x="dom-Baselines-hanging">hanging</code></dfn> dictionary member must be set to that
63297+
baseline value.</p></li>
6329063298

63291-
<dd><p>The distance from the horizontal line indicated by the <code
63292-
data-x="dom-context-2d-textBaseline">textBaseline</code> attribute to the ideographic baseline of
63293-
the <span>line box</span>, in <span data-x="'px'">CSS pixels</span>; positive numbers indicating
63294-
that the given baseline is below the ideographic baseline. (Zero if the given baseline is the
63295-
ideographic baseline.)</p></dd>
63299+
<li><p>If the ideographic baseline is available for this text, the <dfn><code
63300+
data-x="dom-Baselines-ideographic">ideographic</code></dfn> dictionary member must be set to
63301+
that baseline value.</p></li>
63302+
</ul>
6329663303

63304+
<p>In all cases, the baslines values are represented as distance from the horizontal line
63305+
indicated by the <code data-x="dom-context-2d-textBaseline">textBaseline</code> attribute to
63306+
their respective baseline of the <span>line box</span>, in <span
63307+
data-x="'px'">CSS pixels</span>, with positive numbers indicating that the given baseline is
63308+
below the current <code data-x="dom-context-2d-textBaseline">textBaseline</code>.</p>
63309+
</dd>
6329763310
</dl>
6329863311

6329963312
<p class="note">Glyphs rendered using <code data-x="dom-context-2d-fillText">fillText()</code> and

0 commit comments

Comments
 (0)