Skip to content

Commit

Permalink
Add advances to TextMetrics and change baselines API
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fserb authored and domenic committed Aug 30, 2018
1 parent d6feb05 commit 7711a1f
Showing 1 changed file with 39 additions and 26 deletions.
65 changes: 39 additions & 26 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -60014,10 +60014,18 @@ interface <dfn>CanvasPattern</dfn> {
void <span data-x="dom-canvaspattern-setTransform">setTransform</span>(optional <span>DOMMatrix2DInit</span> transform);
};

[Exposed=(Window,Worker)]
dictionary <dfn>Baselines</dfn> {
double <span data-x="dom-Baselines-alphabetic">alphabetic</span>;
double <span data-x="dom-Baselines-hanging">hanging</span>;
double <span data-x="dom-Baselines-ideographic">ideographic</span>;
};

[Exposed=(Window,Worker)]
interface <dfn>TextMetrics</dfn> {
// x-direction
readonly attribute double <span data-x="dom-textmetrics-width">width</span>; // advance width
readonly attribute FrozenArray&lt;double> <span data-x="dom-textmetrics-advances">advances</span>;
readonly attribute double <span data-x="dom-textmetrics-actualBoundingBoxLeft">actualBoundingBoxLeft</span>;
readonly attribute double <span data-x="dom-textmetrics-actualBoundingBoxRight">actualBoundingBoxRight</span>;

Expand All @@ -60028,9 +60036,7 @@ interface <dfn>TextMetrics</dfn> {
readonly attribute double <span data-x="dom-textmetrics-actualBoundingBoxDescent">actualBoundingBoxDescent</span>;
readonly attribute double <span data-x="dom-textmetrics-emHeightAscent">emHeightAscent</span>;
readonly attribute double <span data-x="dom-textmetrics-emHeightDescent">emHeightDescent</span>;
readonly attribute double <span data-x="dom-textmetrics-hangingBaseline">hangingBaseline</span>;
readonly attribute double <span data-x="dom-textmetrics-alphabeticBaseline">alphabeticBaseline</span>;
readonly attribute double <span data-x="dom-textmetrics-ideographicBaseline">ideographicBaseline</span>;
<span>Baselines</span> <span data-x="dom-textmetrics-getBaselines">getBaselines</span>();
};

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

<dt><var>metrics</var> . <code subdfn data-x="dom-textmetrics-width">width</code></dt>
<dt><var>metrics</var> . <code subdfn data-x="dom-textmetrics-advances">advances</code></dt>
<dt><var>metrics</var> . <code subdfn data-x="dom-textmetrics-actualBoundingBoxLeft">actualBoundingBoxLeft</code></dt>
<dt><var>metrics</var> . <code subdfn data-x="dom-textmetrics-actualBoundingBoxRight">actualBoundingBoxRight</code></dt>
<dt><var>metrics</var> . <code subdfn data-x="dom-textmetrics-fontBoundingBoxAscent">fontBoundingBoxAscent</code></dt>
Expand All @@ -62961,9 +62968,7 @@ try {
<dt><var>metrics</var> . <code subdfn data-x="dom-textmetrics-actualBoundingBoxDescent">actualBoundingBoxDescent</code></dt>
<dt><var>metrics</var> . <code subdfn data-x="dom-textmetrics-emHeightAscent">emHeightAscent</code></dt>
<dt><var>metrics</var> . <code subdfn data-x="dom-textmetrics-emHeightDescent">emHeightDescent</code></dt>
<dt><var>metrics</var> . <code subdfn data-x="dom-textmetrics-hangingBaseline">hangingBaseline</code></dt>
<dt><var>metrics</var> . <code subdfn data-x="dom-textmetrics-alphabeticBaseline">alphabeticBaseline</code></dt>
<dt><var>metrics</var> . <code subdfn data-x="dom-textmetrics-ideographicBaseline">ideographicBaseline</code></dt>
<dt><var>metrics</var> . <code subdfn data-x="dom-textmetrics-getBaselines">getBaselines</code>()</dt>

<dd>

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

<dt><dfn><code data-x="dom-textmetrics-advances">advances</code></dfn> attribute</dt>

<dd><p>Returns a frozen array containing advances for each character in the measured text. Each
advance is measured as the distance from the beginning of the string (starting at 0) up to the
left side of the character. The same frozen array object must be returned every time this
attribute's getter is invoked.</p></dd>

<dt><dfn><code data-x="dom-textmetrics-actualBoundingBoxLeft">actualBoundingBoxLeft</code></dfn> attribute</dt>

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

<dt><dfn><code data-x="dom-textmetrics-hangingBaseline">hangingBaseline</code></dfn> attribute</dt>

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

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

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

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

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

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

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

0 comments on commit 7711a1f

Please sign in to comment.