Skip to content

Commit 2da3f9c

Browse files
committed
[css-fonts-4] Merge font-variant-position from CSS Fonts 4 w3c#1653
1 parent c1900b8 commit 2da3f9c

3 files changed

Lines changed: 203 additions & 0 deletions

File tree

css-fonts-4/Overview.bs

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3640,6 +3640,209 @@ including <span title="none!!font-variant-ligatures">'none'</span>
36403640
<h3 id="font-variant-position-prop">
36413641
Subscript and superscript forms: the 'font-variant-position' property</h3>
36423642

3643+
3644+
<pre class="propdef">
3645+
Name: font-variant-position
3646+
3647+
Value: normal | sub | super
3648+
Initial: normal
3649+
Applies to: all elements
3650+
Inherited: yes
3651+
Percentages: n/a
3652+
Computed value: as specified
3653+
Animation type: discrete
3654+
</pre>
3655+
3656+
<p>This property is used
3657+
to enable typographic subscript and superscript glyphs.
3658+
These are alternate glyphs
3659+
designed within the same em-box as default glyphs
3660+
and are intended to be laid out
3661+
on the same baseline
3662+
as the default glyphs,
3663+
with no resizing or repositioning of the baseline.
3664+
They are explicitly designed
3665+
to match the surrounding text
3666+
and to be more readable
3667+
without affecting the line height.</p>
3668+
3669+
<div class="figure"><img alt="comparison between real subscript glyphs and synthesized ones" src="images/realsubscripts.png" /><p class="caption">Subscript glyphs (top) vs. typical synthesized subscripts (bottom)</p></div>
3670+
3671+
<p>Individual values have the following meanings:</p>
3672+
3673+
<dl dfn-for="font-variant-position" dfn-type="value">
3674+
<dt><dfn id="font-variant-position-normal-value" title="normal!!font-variant-position">normal</dfn></dt>
3675+
<dd>None of the features listed below are enabled.</dd>
3676+
<dt><dfn>sub</dfn></dt>
3677+
<dd>Enables display of subscript variants
3678+
(OpenType feature: <span class="tag">subs</span>).</dd>
3679+
<dt><dfn>super</dfn></dt>
3680+
<dd>Enables display of superscript variants
3681+
(OpenType feature: <span class="tag">sups</span>).</dd>
3682+
</dl>
3683+
3684+
<p>Because of the semantic nature of subscripts and superscripts,
3685+
when the value is either 'sub' or 'super'
3686+
for a given contiguous run of text,
3687+
if a variant glyph is not available for all the characters in the run,
3688+
simulated glyphs <!-- must --> should be synthesized
3689+
for all characters
3690+
using reduced forms of the glyphs
3691+
that would be used
3692+
without this feature applied.
3693+
This is done per run
3694+
to avoid a mixture of variant glyphs and synthesized ones
3695+
that would not align correctly.
3696+
In the case of OpenType fonts
3697+
that lack subscript or superscript glyphs
3698+
for a given character,
3699+
user agents <em>must</em> synthesize
3700+
appropriate subscript and superscript glyphs.</p>
3701+
3702+
<div class="figure"><img alt="alternate superscripts vs. glyphs synthesized using superscript metrics" src="images/superscript-alt-synth.png" /><p class="caption">Superscript alternate glyph (left), synthesized superscript glyphs (middle), and incorrect mixture of the two (right)</p></div>
3703+
3704+
<!--
3705+
at-risk must downgraded to should
3706+
see https://github.com/w3c/csswg-drafts/issues/2796#issuecomment-398565265
3707+
-->
3708+
<p>In situations where text decorations
3709+
are only applied to runs of text
3710+
containing superscript or subscript glyphs,
3711+
the synthesized glyphs may be used,
3712+
to avoid problems with the placement of decorations.</p>
3713+
3714+
<p>In the past,
3715+
user agents have used font-size
3716+
and vertical-align
3717+
to simulate subscripts and superscripts
3718+
for the
3719+
<code title="HTML sub element">sub</code>
3720+
and <code title="HTML sup element">sup</code> elements.
3721+
To allow a backwards compatible way
3722+
of defining subscripts and superscripts,
3723+
it is recommended
3724+
that authors use conditional rules [[CSS3-CONDITIONAL]]
3725+
so that older user agents will still render
3726+
subscripts and superscripts via
3727+
the older mechanism.</p>
3728+
3729+
<p>Because <code>font-size: smaller</code>
3730+
is often used for these elements,
3731+
the effective scaling factor
3732+
applied to subscript and superscript text
3733+
varies depending upon the size.
3734+
For larger text,
3735+
the font size is often reduced by a third
3736+
but for smaller text sizes,
3737+
the reduction can be much less.
3738+
This allows subscripts and superscripts
3739+
to remain readable
3740+
even within elements using small text sizes.
3741+
User agents should consider this
3742+
when deciding how to synthesize
3743+
subscript and superscript glyphs.</p>
3744+
3745+
<p class="note">The OpenType font format
3746+
defines subscript and superscript metrics
3747+
in the
3748+
<a href="https://docs.microsoft.com/en-us/typography/opentype/spec/os2">OS/2 table</a>
3749+
[[!OPENTYPE]]
3750+
but these are not always accurate in practice
3751+
and so cannot be relied upon
3752+
when synthesizing subscript and superscript glyphs.</p>
3753+
3754+
<p>Authors should note
3755+
that fonts typically only provide
3756+
subscript and superscript glyphs
3757+
for a subset of all characters
3758+
supported by the font.
3759+
For example,
3760+
while subscript and superscript glyphs
3761+
are often available for Latin numbers,
3762+
glyphs for punctuation and letter characters
3763+
are less frequently provided.
3764+
The synthetic fallback rules
3765+
defined for this property
3766+
try to ensure that subscripts and superscripts
3767+
will always appear
3768+
but the appearance may not match author expectations
3769+
if the font used does not provide
3770+
the appropriate alternate glyph
3771+
for all characters contained in a
3772+
subscript or superscript.</p>
3773+
3774+
<p>This property is not cumulative.
3775+
Applying it to elements
3776+
within a subscript or superscript
3777+
won't nest the placement
3778+
of a subscript or superscript glyph.
3779+
Images contained within text runs
3780+
where the value of this property
3781+
is 'sub' or 'super' will be drawn
3782+
just as they would
3783+
if the value was <span title="normal!!font-variant-position">'normal'</span>.</p>
3784+
3785+
<!-- due to lack of consensus, couldn't resolve on exact positioning of text decorations:
3786+
http://www.w3.org/2013/06/06-css-minutes.html#item03 -->
3787+
3788+
<p>Because of these limitations,
3789+
'font-variant-position'
3790+
is not recommended for use in user agent stylesheets.
3791+
Authors should use it
3792+
in cases where subscripts or superscripts
3793+
will only contain the narrow range of characters
3794+
supported by the fonts specified.</p>
3795+
3796+
<p class="note">The variant glyphs
3797+
use the same baseline
3798+
as the default glyphs would use.
3799+
There is no shift in the placement along the baseline,
3800+
so the use of variant glyphs doesn't affect
3801+
the height of the inline box
3802+
or alter the height of the linebox.
3803+
This makes superscript and subscript variants
3804+
ideal for situations where it's important
3805+
that leading remain constant,
3806+
such as in multi-column layout.</p>
3807+
3808+
<div class="example">
3809+
<p>A typical user agent default style for the <span class="tag">sub</span> element:</p>
3810+
3811+
<pre>sub {
3812+
vertical-align: sub;
3813+
font-size: smaller;
3814+
line-height: normal;
3815+
}
3816+
</pre>
3817+
3818+
<p>Using 'font-variant-position'
3819+
to specify typographic subscripts
3820+
in a way that will still show subscripts
3821+
in older user agents:</p>
3822+
3823+
<pre>@supports ( font-variant-position: sub ) {
3824+
3825+
sub {
3826+
vertical-align: baseline;
3827+
font-size: 100%;
3828+
line-height: inherit;
3829+
font-variant-position: sub;
3830+
}
3831+
3832+
}
3833+
</pre>
3834+
3835+
<p>User agents that support the 'font-variant-position' property
3836+
will select a subscript variant glyph
3837+
and render this
3838+
without adjusting the baseline or font-size.
3839+
Older user agents will ignore
3840+
the 'font-variant-position' property definition
3841+
and use the standard defaults for subscripts.
3842+
</p>
3843+
</div>
3844+
3845+
36433846
<h3 id="font-variant-caps-prop">
36443847
Capitalization: the 'font-variant-caps' property</h3>
36453848

15.7 KB
Loading
7.18 KB
Loading

0 commit comments

Comments
 (0)