Skip to content

Commit 60a4980

Browse files
authored
Add support for character-level and glyph-level mirroring of RTL operators (#277)
* Clarify layout of large operators algorithm * Add support for RTL mirroring of operators
1 parent 6409aff commit 60a4980

File tree

1 file changed

+129
-33
lines changed

1 file changed

+129
-33
lines changed

spec.html

Lines changed: 129 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,13 +1738,23 @@ <h4>Layout of operators</h4>
17381738
<a data-xref-type="css-property">color</a>
17391739
of the <code>&lt;mo&gt;</code> element.
17401740
</p>
1741+
<p>
1742+
Let <code>dir</code> be the element's computed
1743+
<a data-xref-type="css-property">direction</a>.
1744+
</p>
17411745
<p>Operators are laid out as follows:</p>
17421746
<ol class="algorithm">
17431747
<li>
17441748
If the content of the <code>&lt;mo&gt;</code> element is not
17451749
made
17461750
of a single character <code>c</code> then fall back to the
17471751
layout algorithm of <a href="#layout-of-mtext"></a>.
1752+
If it is not possible to <a>get a glyph</a> corresponding to
1753+
<code>c</code> given directionality <code>dir</code>, then
1754+
fall back to the layout algorithm of <a href="#layout-of-mtext"></a>.
1755+
Otherwise, let <code>g</code> be the result of running
1756+
<a>get a glyph</a> corresponding to <code>c</code>
1757+
given directionality <code>dir</code>.
17481758
</li>
17491759
<li>
17501760
If the operator has the [=embellished operator/stretchy=] property:
@@ -1754,10 +1764,8 @@ <h4>Layout of operators</h4>
17541764
<ol>
17551765
<li>
17561766
If it is not possible to <a>shape a stretchy glyph</a>
1757-
corresponding to <code>c</code> in the inline direction
1758-
with the
1759-
<a>first available font</a>
1760-
then fall back to the
1767+
<code>g</code> in the inline direction with the
1768+
<a>first available font</a> then fall back to the
17611769
layout algorithm of <a href="#layout-of-mtext"></a>.
17621770
</li>
17631771
<li>
@@ -1777,13 +1785,13 @@ <h4>Layout of operators</h4>
17771785
<li>
17781786
The <a>inline size</a> and (ink) block metrics of the math content
17791787
are given by algorithm to
1780-
<a>shape a stretchy glyph</a> to <a>inline dimension</a>
1781-
<code>T<sub>inline</sub></code>.
1788+
<a>shape a stretchy glyph</a> <code>g</code> to
1789+
<a>inline dimension</a> <code>T<sub>inline</sub></code>.
17821790
</li>
17831791
<li>
17841792
The painting of the operator is performed by the
17851793
algorithm
1786-
to <a>shape a stretchy glyph</a>
1794+
to <a>shape a stretchy glyph</a> <code>g</code>
17871795
stretched to <a>inline dimension</a>
17881796
<code>T<sub>inline</sub></code> and
17891797
at position determined by the previous box metrics.
@@ -1796,10 +1804,8 @@ <h4>Layout of operators</h4>
17961804
<ol>
17971805
<li>
17981806
If it is not possible to <a>shape a stretchy glyph</a>
1799-
corresponding to <code>c</code> in the block direction
1800-
with the
1801-
<a>first available font</a>
1802-
then fall back to the
1807+
<code>g</code> in the block direction with the
1808+
<a>first available font</a> then fall back to the
18031809
layout algorithm of <a href="#layout-of-mtext"></a>.
18041810
</li>
18051811
<li>
@@ -1862,7 +1868,7 @@ <h4>Layout of operators</h4>
18621868
Let <code>minsize</code> and <code>maxsize</code>
18631869
be the [=embellished operator/minsize=] and [=embellished operator/maxsize=] properties on the
18641870
operator. Percentage values are interpreted relative
1865-
to the height of the glyph for <code>c</code>.
1871+
to the height of <code>g</code>.
18661872
Let <code>T</code> =
18671873
<code>T<sub>ascent</sub></code> +
18681874
<code>T<sub>descent</sub></code> be the target size.
@@ -1920,7 +1926,7 @@ <h4>Layout of operators</h4>
19201926
<a>line-descent</a>
19211927
of the math content
19221928
are obtained by the algorithm to
1923-
<a>shape a stretchy glyph</a>
1929+
<a>shape a stretchy glyph</a> <code>g</code>
19241930
to <a>block dimension</a>
19251931
<code>T<sub>ascent</sub></code> +
19261932
<code>T<sub>descent</sub></code>.
@@ -1937,7 +1943,7 @@ <h4>Layout of operators</h4>
19371943
</li>
19381944
<li>
19391945
The painting of the operator is performed by the
1940-
algorithm to <a>shape a stretchy glyph</a>
1946+
algorithm to <a>shape a stretchy glyph</a> <code>g</code>
19411947
stretched to <a>block dimension</a>
19421948
<code>T<sub>ascent</sub></code> +
19431949
<code>T<sub>descent</sub></code>
@@ -1961,25 +1967,63 @@ <h4>Layout of operators</h4>
19611967
then:
19621968
<ol>
19631969
<li>
1964-
<p>
1965-
Use the
1966-
<code>MathVariants</code>
1967-
table to try and find a glyph of height at least
1968-
<a>DisplayOperatorMinHeight</a>.
1969-
If none is found, fall back to the
1970-
largest non-base glyph. If none is found, fall back to
1971-
the layout algorithm of <a href="#layout-of-mtext"></a>.
1972-
</p>
1970+
If it is not possible to <a>shape a stretchy glyph</a>
1971+
<code>g</code> in the block direction with the
1972+
<a>first available font</a> then fall back to the
1973+
layout algorithm of <a href="#layout-of-mtext"></a>.
1974+
<div class="note">
1975+
Here we treat a non-[=embellished operator/stretchy=] [=embellished operator/largeop=]
1976+
glyph as stretchy with target dimension <a>DisplayOperatorMinHeight</a>.
1977+
</div>
19731978
</li>
19741979
<li>
1975-
The <a>min-content inline size</a>,
1976-
<a>max-content inline size</a>,
1977-
<a>inline size</a> and block metrics of the math content
1978-
are given by the
1979-
glyph found.
1980+
The <a>min-content inline size</a> and
1981+
<a>max-content inline size</a> of the math content
1982+
are set to the <a>preferred inline size of a glyph
1983+
stretched along the block axis</a>.
1984+
</li>
1985+
<li>
1986+
The <a>inline size</a>,
1987+
<a>ink line-ascent</a>,
1988+
<a>ink line-descent</a>,
1989+
<a>line-ascent</a> and
1990+
<a>line-descent</a>
1991+
of the math content
1992+
are obtained by the algorithm to
1993+
<a>shape a stretchy glyph</a> <code>g</code>
1994+
to <a>block dimension</a>
1995+
<a>DisplayOperatorMinHeight</a>.
1996+
The <a>inline size</a> of the math content is the width of
1997+
the stretchy glyph. The stretchy glyph is shifted
1998+
towards the <a>line-under</a> by a value Δ so that its
1999+
center aligns with the center of the target when
2000+
[=embellished operator/symmetric=]:
2001+
the ink ascent of the math content is
2002+
the ascent of the stretchy glyph − Δ
2003+
and the ink descent of the math content is
2004+
the descent of the stretchy glyph + Δ.
2005+
<ul>
2006+
<li>
2007+
If the operator has the [=embellished operator/symmetric=] property,
2008+
then
2009+
Δ = [(ascent of stretchy glyph − descent of stretchy glyph) − 2 * <a>AxisHeight</a>] / 2.
2010+
</li>
2011+
<li>
2012+
Otherwise,
2013+
Δ = 0.
2014+
</li>
2015+
</ul>
2016+
<div class="note">
2017+
The point of Δ here is simply to vertically align the operator when [=embellished operator/symmetric=].
2018+
</div>
19802019
</li>
19812020
<li>
1982-
Paint the glyph.
2021+
The painting of the operator is performed by the
2022+
algorithm to <a>shape a stretchy glyph</a> <code>g</code>
2023+
stretched to <a>block dimension</a>
2024+
<a>DisplayOperatorMinHeight</a>
2025+
and at position determined by the previous box metrics
2026+
shifted by Δ towards the <a>line-over</a>.
19832027
</li>
19842028
</ol>
19852029
<figure id="figure-sum-base-and-displastyle-sizes">
@@ -2838,8 +2882,11 @@ <h5>Radical symbol</h5>
28382882
of that element.
28392883
</p>
28402884
<p>
2841-
The <dfn>radical glyph</dfn> is the glyph obtained for the
2842-
character U+221A SQUARE ROOT.
2885+
Let <code>dir</code> be the computed <a data-xref-type="css-property">direction</a>
2886+
of the <code>&lt;msqrt&gt;</code> or <code>&lt;mroot&gt;</code> element.
2887+
The <dfn>radical glyph</dfn> is the glyph obtained as a result of running
2888+
<a>get a glyph</a> corresponding to the U+221A SQUARE ROOT character
2889+
given <code>dir</code>.
28432890
</p>
28442891
<p>
28452892
The <dfn>radical gap</dfn> is given by
@@ -2856,8 +2903,8 @@ <h5>Radical symbol</h5>
28562903
<p>
28572904
The <dfn>box metrics of the radical glyph</dfn>
28582905
and <dfn>painting of the surd</dfn> are given by the algorithm to
2859-
<a>shape a stretchy glyph</a> to <a>block dimension</a> the
2860-
target size for the radical glyph.
2906+
<a>shape a stretchy glyph</a> to the
2907+
target size for the radical glyph in the <a>block dimension</a>.
28612908
</p>
28622909
</section>
28632910
<section>
@@ -5639,6 +5686,55 @@ <h4>Algorithms for glyph stretching</h4>
56395686
such as
56405687
the one suggested in <a href="#unicode-based-glyph-assemblies"></a>.
56415688
</div>
5689+
<p>
5690+
The algorithm to <dfn>get a glyph</dfn> corresponding to a character <code>c</code> given a directionality <code>dir</code>
5691+
is the following:
5692+
</p>
5693+
<ul class="algorithm">
5694+
<li>
5695+
Let <code>g</code> be the glyph corresponding to <code>c</code>
5696+
in the <a>first available font</a>.
5697+
If it is not possible to find such a glyph, then exit with failure.
5698+
</li>
5699+
<li>
5700+
If <code>dir</code> is <code>rtl</code>:
5701+
<ul>
5702+
<li>
5703+
If there exists an OpenType rtlm variant of
5704+
<code>g</code> in the <a>first available font</a>,
5705+
then return it and exit with success. [[OPEN-FONT-FORMAT]]
5706+
</li>
5707+
<li>
5708+
Otherwise, if <code>c</code> has the Bidi_Mirrored property [[BIDI]]:
5709+
<ul>
5710+
<li>
5711+
If <code>c</code> has a corresponding mirrored codepoint,
5712+
<code>c'</code>, then return the glyph corresponding
5713+
to <code>c'</code> and exit with success.
5714+
If it is not possible to find such a glyph, then exit with failure.
5715+
</li>
5716+
<li>
5717+
Otherwise, exit with failure.
5718+
</li>
5719+
</ul>
5720+
<div class="note">
5721+
These failure cases are for when a character should be mirrored
5722+
according to its Bidi_Mirrored property, but no corresponding codepoint
5723+
or glyph exists.
5724+
</div>
5725+
</li>
5726+
<li>
5727+
Otherwise, return <code>g</code> and exit with success.
5728+
</li>
5729+
</ul>
5730+
</li>
5731+
<li class="assert">
5732+
Assert: <code>dir</code> is <code>ltr</code>.
5733+
</li>
5734+
<li>
5735+
Return <code>g</code> and exit with success.
5736+
</li>
5737+
</ul>
56425738
</section>
56435739
</section>
56445740
</section>

0 commit comments

Comments
 (0)