Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[css-fonts] Add font-size: math, math-depth and math-style #5536

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 148 additions & 2 deletions css-fonts-4/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ Font size: the 'font-size' property</h3>

<pre class="propdef">
Name: font-size
Value: <<absolute-size>> | <<relative-size>> | <<length-percentage>>
Value: <<absolute-size>> | <<relative-size>> | <<length-percentage>> | math
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is a mistake, it must be reverted

Initial: medium
Applies to: all elements
Inherited: yes
Expand Down Expand Up @@ -879,7 +879,12 @@ Font size: the 'font-size' property</h3>
relative to the computed 'font-size' of the parent element
and possibly the table of font sizes. Possible values are:

<pre class=prod>[ larger | smaller ]</pre>
<pre class=prod>[ larger | smaller | math ]</pre>

The ''math'' keyword is treated specially: it computes to the
product of the computed 'font-size' of the parent element and a
scale factor calculated from the 'math-depth' property.
See [[#math-depth-prop]].

If the parent element has a keyword font size in the absolute size keyword mapping table,
''larger'' may compute the font size to the next entry in the table,
Expand Down Expand Up @@ -1008,6 +1013,147 @@ Font size: the 'font-size' property</h3>
should nevertheless avoid creating font sizes
of less than 9 device pixels per EM unit.

<h4 id="math-depth-prop">
Controlling 'font-size' in math formulas: the 'math-depth' property</h4>

<pre class="propdef">
Name: math-depth
Value: auto-add | add(<<integer>>) | <<integer>>
Initial: 0
Applies to: all elements
Inherited: yes
Percentages: n/a
Computed value: an integer, see below
Animation type: not animatable
</pre>

The 'math-depth' property describes how deep an element should be considered
with respect to the top-level container of a mathematical formula. This
affects the 'font-size' of mathematical formulas. For example, scripted
elements typically increments the math depth and nested scripts are
rendered with smaller and smaller 'font-size'.

Values have the following meanings:

<dl dfn-for="math-depth" dfn-type="value">
<dt><dfn id="math-depth-auto-add-value">auto-add</dfn>
<dd>An ''auto-add'' keyword
specifies an increment conditioned by the 'math-style'
property. If the computed 'math-style' is 'compact' then
the computed 'math-depth' value is the computed 'math-depth' of the
parent plus one. If the computed 'math-style' is 'normal' then
the computed 'math-depth' is the computed 'math-depth' of the parent.
<dt><dfn id="math-depth-add-integer-value">add(<<integer>>)</dfn>
<dd>An 'add(<<integer>>)'
function specifies a relative change of 'math-depth'. The
computed 'math-depth' is the computed 'math-depth' of the parent plus
the integer argument.
<dt><dfn id="math-depth-integer-value"><<integer>></dfn>
<dd>An <<integer>> specifies an absolute 'math-depth'.
</dl>

<div class="example">
The following example shows a mathematical formula with normal
'math-style' rendered with the Latin Modern Math font. When entering
subexpressions like scripts or fractions, the font-size is automatically
scaled down according to the values of the 'MATH' table contained in that
font. Note that 'font-size' is scaled down when entering the superscripts
but even faster when entering a root's prescript. Also it is scaled down
when entering the inner fraction but not when entering the outer one, due
to automatic change of 'math-style' in fractions.
<figure>
<img alt="Automatic 'font-size' in a mathematical formula" src="images/example-font-size-scriptlevel.png" >
<figcaption>Automatic 'font-size' in a mathematical formula</figcaption>
</figure>
</div>

If the specified value 'font-size' is ''math'' then the computed value of
'font-size' is obtained by multiplying the inherited value of 'font-size'
by a nonzero scale factor. This scale factor is calculated by the following
procedure:
<ol>
<li>Let A be the computed 'math-depth' value of the parent,
B the computed 'math-depth' value,
C be 0.71 and S be 1.0</li>
<li>
<ul>
<li>If A = B then return S.</li>
<li>If B &lt; A, swap A and B and set 'InvertScaleFactor' to true.</li>
<li>Otherwise B &gt; A and set 'InvertScaleFactor' to false.</li>
</ul>
</li>
<li>Let E be B - A &gt; 0.</li>
<li>If the inherited font has a 'MATH' table [[OPEN-FONT-FORMAT]]:
<ul>
<li>Read the 'scriptPercentScaleDown' and
'scriptScriptPercentScaleDown' values
from the ''MathConstants'' subtable.</li>
<li>If A ≤ 0 and B ≥ 2 then multiply S by 'scriptScriptPercentScaleDown' and
decrement E by 2.</li>
<li>Otherwise if A = 1 then multiply S by
'scriptScriptPercentScaleDown' / 'scriptPercentScaleDown' and
decrement E by 1.</li>
<li>Otherwise if B = 1 then multiply S by 'scriptPercentScaleDown'</a>
and decrement E by 1.</li>
</ul>
</li>
<li>Multiply S by C<sup>E</sup></li>
<li>Return S if 'InvertScaleFactor' is false and 1/S otherwise.</li>
</ol>

<h4 id="math-style-prop">
Compactness of math formulas: the 'math-style' property</h4>

<pre class="propdef">
Name: math-style
Value: normal | compact
Initial: normal
Applies to: all elements
Inherited: yes
Percentages: n/a
Computed value: specified keyword
Animation type: not animatable
</pre>

Values have the following meanings:

<dl dfn-for="math-style" dfn-type="value">
<dt><dfn id="math-style-normal-value">normal</dfn></dt>
<dd>Math layout is performed without trying to minimize the
[=logical height=].
<dt><dfn>compact</dfn></dt>
<dd>When the specified 'math-depth' is ''auto-add'' then
the computed value of 'math-depth' is its inherited value plus one.
If in addition the specified 'font-size' is ''math'' then the computed
value of 'font-size' is its inherited value times the factor described
in [[#math-depth-prop]].

Math layout algorithms may also apply additional changes to reduce the
[=logical height=]. In particular, [[MathML-Core]] follows these extra
rules:
<ul>
<li>Large operators (e.g. integrals) use a small size variant.
<li>Underscripts and overscripts scripts attached to operators with
movable limits (e.g. big sums or products) are placed as subscripts and
superscripts.
<li>Smaller vertical gaps and shifts from the 'MATH' table of
[[OPEN-FONT-FORMAT]] are used for fractions and radicals.
</ul>
</dl>
<div class="example">
These two mathematical formulas are rendered with a 'math-style'
set to ''compact'' (left) and ''normal'' (right).
In the former case, the 'font-size' is automatically scaled down
within the fractions and the summation limits are rendered as
subscript and superscript of the ∑. In the latter case, the ∑ is
drawn bigger than normal text and vertical gaps within fractions (even
relative to current 'font-size') is larger.
<figure>
<img alt="Math formulas with specified 'math-style' value 'compact' and 'normal'" src="images/example-math-style.png" >
<figcaption>Math formulas with specified 'math-style' value 'compact' and 'normal'</figcaption>
</figure>
</div>

<!-- font-min size and font-max-size removed by CSSWG resolution
https://github.com/w3c/csswg-drafts/issues/3739
-->
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added css-fonts-4/images/example-math-style.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.