Skip to content

Commit a54303c

Browse files
committed
[css-inline-3] Rip apart and rewrite inline height calculation section.
1 parent 6219a6b commit a54303c

1 file changed

Lines changed: 93 additions & 70 deletions

File tree

css-inline-3/Overview.bs

Lines changed: 93 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -197,21 +197,22 @@ Layout Within Line Boxes</h3>
197197
user agents flow [=inline-level boxes=] into a stack of [=line boxes=].
198198
Layout within the [=line box=] is performed as follows:
199199

200-
1. The [=logical height=] of each [=inline-level box=] in the [=line box=]
201-
is calculated.
200+
1. The [=layout bounds=] of each [=inline-level box=] in the [=line box=]
201+
are calculated.
202202

203203
<ul class=switch>
204204
<li>
205205
For [=atomic inlines=] such as [=replaced elements=] and [=inline blocks=]:
206-
this is their [=outer size=].
206+
this is their [=margin box=].
207207
<li>
208208
For the [=root inline box=]
209209
and for [=inline boxes=] with ''line-sizing: legacy'':
210-
this is their used 'line-height'.
210+
this derived from their used 'line-height',
211+
see [[#inline-height]].
211212

212213
<li>
213214
For other (non-root) [=inline boxes=] with ''line-sizing: normal'':
214-
this is their [=outer size=].
215+
this is their [=margin box=].
215216

216217
Issue(5178): Handle negative half-leading?
217218
</ul>
@@ -221,8 +222,9 @@ Layout Within Line Boxes</h3>
221222
Those with [=line-relative alignment values=]
222223
are aligned so as to minimize the line box height.
223224

224-
3. The [=line box=]’s [=logical height=] is calculated as the distance between
225-
the uppermost box top and the lowermost box bottom.
225+
3. The [=line box=]’s [=logical height=] is calculated
226+
to exactly include the aligned [=layout bounds=]
227+
of all its [=inline-level boxes=].
226228

227229
4. The [=root inline box=]’s [=aligned subtree=]
228230
and boxes with line-box&ndash;relative 'vertical-align' values
@@ -354,6 +356,34 @@ Baseline Types and Metrics</h3>
354356
they must be synthesized,
355357
see [[#baseline-tables]] and [[#baseline-synthesis]].
356358

359+
<h4 id="ascent-descent">
360+
Ascent and Descent Metrics</h4>
361+
362+
CSS assumes that every font has font metrics
363+
that specify a characteristic height above the baseline--
364+
called the <dfn>ascent metric</dfn>--
365+
and a characteristic depth below it--
366+
called the <dfn>descent metric</dfn>--
367+
which CSS uses for laying out text and boxes
368+
in an [=inline formatting context=].
369+
Note that these are metrics of the font as a whole
370+
and need not correspond to the ascender and descender of any individual glyph.
371+
372+
Note: It is recommended that implementations that use OpenType or TrueType fonts
373+
use the metrics <code>sTypoAscender</code> and <code>sTypoDescender</code>
374+
from the font's OS/2 table
375+
(after scaling to the current element's font size)
376+
to find the [=ascent metric=] and [=descent metric=] for CSS layout.
377+
In the absence of these metrics,
378+
the "Ascent" and "Descent" metrics from the HHEA table should be used.
379+
380+
User Agents may use different sets of font metrics
381+
when determining the [=ascent metric=] and [=descent metric=]
382+
depending on whether the 'line-height' property is
383+
''line-height/normal'' or some other value,
384+
for instance taking external leading metrics into account
385+
only in the ''line-height/normal'' case.
386+
357387
<h3 id="baseline-tables">
358388
Baselines of Glyphs and Boxes</h3>
359389

@@ -736,7 +766,7 @@ Line Spacing: the 'line-height' property</h3>
736766
<dd>
737767
Determine the [=preferred line height=]
738768
automatically based on font metrics.
739-
See [[#leading]].
769+
See [[#inline-height]].
740770

741771
<dt><dfn><<length>></dfn>
742772
<dd>
@@ -758,6 +788,10 @@ Line Spacing: the 'line-height' property</h3>
758788
Negative values are illegal.
759789
</dl>
760790

791+
Note: Glyphs from fonts other than the [=first available font=]
792+
do not impact the [=layout bounds=] or [=baseline=] position
793+
of an [=inline box=] with a non-''line-height/normal'' 'line-height'.
794+
761795
<div class="example">
762796
The three rules in the example below have the same resultant line height:
763797

@@ -782,75 +816,64 @@ Line Spacing: the 'line-height' property</h3>
782816
See also <a href="https://github.com/w3c/csswg-drafts/issues/3118">Issue 3118</a>
783817
and <a href="https://github.com/w3c/csswg-drafts/issues/2165">Issue 2165</a>.
784818

785-
<h4 id="leading">Leading and half-leading</h4>
786-
787-
CSS assumes that every font has font metrics
788-
that specify a characteristic height above the baseline and a depth below it.
789-
In this section we use <var>A</var> to mean that height
790-
(for a given font at a given size)
791-
and <var>D</var> the depth.
792-
We also define <var>AD</var> = <var>A</var> + <var>D</var>,
793-
the distance from the top to the bottom.
794-
(See the note below for <a href="#sTypoAscender">how to find <var>A</var> and <var>D</var> for TrueType and OpenType fonts.</a>)
795-
Note that these are metrics of the font as a whole
796-
and need not correspond to the ascender and descender of any individual glyph.
797-
798-
The User Agent must align the glyphs in a non-replaced [=inline box=]
819+
<h3 id="inline-height">
820+
Logical Height Contributions of Inline Boxes</h3>
821+
822+
The contribution of an [=inline box=] to the [=logical height=] of its [=line box=],
823+
here referred to as its <dfn>layout bounds</dfn>,
824+
is always calculated with respect to its text metrics,
825+
as described below.
826+
The sizes and positions of child boxes do not influence
827+
its [=layout bounds=]
828+
(or its own [=logical height=], for that matter,
829+
see 'inline-sizing').
830+
831+
Note: The [=layout bounds=] need not correspond
832+
to the box’s visible edges (see 'line-sizing').
833+
834+
These calculations use the metrics <var>A</var> and <var>D</var>,
835+
where <var>A</var> refers to the [=ascent metric=]
836+
(for the given font at its given size)
837+
and <var>D</var> to the [=descent metric=],
838+
each adjusted to account for the [=dominant baseline=]’s offset from zero.
839+
840+
To find the [=layout bounds=] of an [=inline box=],
841+
the UA must first align
842+
all the glyphs <em>directly</em> contained in the [=inline box=]
799843
to each other by their [=dominant baselines=].
800-
Then, for each glyph,
801-
determine the <var>A</var> and <var>D</var>.
802-
(Note that glyphs in a single element
803-
can come from different fonts
804-
and thus need not all have the same <var>A</var> and <var>D</var>.)
805-
If the inline box contains no glyphs at all,
844+
(See [[#baseline-tables]].)
845+
If the [=inline box=] contains no glyphs at all,
806846
or if it contains only glyphs from fallback fonts,
807847
it is considered to contain a “strut” (an invisible glyph of zero width)
808848
with the <var>A</var> and <var>D</var> of the box's [=first available font=].
809849

810-
<p id="inline-box-height">When the value of the 'line-height' property
811-
is something other than ''line-height/normal'',
812-
determine the leading <var>L</var> to add,
813-
where <var>L</var> = 'line-height' - <var>AD</var> of the first available font.
814-
Half the leading is added above <var>A</var> of the first available font,
850+
When its computed 'line-height' is ''line-height/normal'',
851+
the [=layout bounds=] of an inline box encloses all its glyphs,
852+
going from the highest <var>A</var> to the deepest <var>D</var>.
853+
(Note that glyphs in a single box
854+
can come from different fonts
855+
and thus might not all have the same <var>A</var> and <var>D</var>.)
856+
857+
When its computed 'line-height' is not ''line-height/normal'',
858+
its [=layout bounds=] are derived solely from
859+
metrics of its [=first available font=]
860+
(ignoring glyphs from other fonts),
861+
and <dfn>leading</dfn> is used
862+
to adjust the effective <var>A</var> and <var>D</var>
863+
to add up to the used 'line-height'.
864+
Calculate the [=leading=] <var>L</var>
865+
as <var>L</var> = 'line-height' - (<var>A</var> + <var>D</var>).
866+
Half the [=leading=] is added above <var>A</var> of the first available font,
815867
and the other half below <var>D</var> of the first available font,
816-
giving a total height above the baseline of
868+
giving an effective ascent above the baseline of
817869
<var>A′</var> = <var>A</var> + <var>L</var>/2,
818-
and a total depth of <var>D′</var> = <var>D</var> + <var>L</var>/2.
819-
Glyphs from fonts other than the first available font
820-
do not impact the height or baseline of the inline box
821-
for 'line-height' values other than ''line-height/normal''.
870+
and an effective descent of <var>D′</var> = <var>D</var> + <var>L</var>/2.
871+
The [=layout bounds=] exactly encloses
872+
this effective <var>A′</var> and <var>D′</var>.
822873

823874
Note: <var>L</var> may be negative.
824875

825-
Boxes of child elements do not influence this height.
826-
827-
When the value of the 'line-height' property is ''line-height/normal'',
828-
the height of the inline box encloses all glyphs,
829-
going from the highest <var>A</var> to the deepest <var>D</var>.
830-
831-
User Agents may use different sets of font metrics
832-
when determining <var>A</var> and <var>D</var>
833-
depending on whether the 'line-height' property is
834-
''line-height/normal'' or some other value,
835-
for instance taking external leading metrics into account
836-
only in the ''line-height/normal'' case.
837-
838-
839-
Note: CSS&nbsp;2 does not define what the content area of an inline box is
840-
(see [[#line-fill]])
841-
and thus different UAs may draw the backgrounds and borders in different places.
842-
843-
<p class=note id=sTypoAscender>Note: It is recommended that
844-
implementations that use OpenType or TrueType fonts
845-
use the metrics <code>sTypoAscender</code> and <code>sTypoDescender</code>
846-
from the font's OS/2 table
847-
(after scaling to the current element's font size)
848-
to find <var>A</var> and <var>D</var>.
849-
In the absence of these metrics,
850-
the "Ascent" and "Descent" metrics from the HHEA table should be used.
851-
852-
Note: The ascent and descent metrics in the font data might need to be adjusted
853-
to account for the [=dominant baseline=]’s offset from zero.
876+
ISSUE: Integrate effects of ''line-sizing: normal'' and 'leading-trim'.
854877

855878
<h3 id="line-sizing-property">
856879
Line Sizing Containment: the 'line-sizing' property</h3>
@@ -880,7 +903,7 @@ Line Sizing Containment: the 'line-sizing' property</h3>
880903
The inline box contributes to the sizing of its line box
881904
based on its 'line-height',
882905
rather than based on its box edges,
883-
as defined in [[!CSS2]].
906+
as defined in [[#inline-height]].
884907
In Quirks Mode [[!QUIRKS]],
885908
any <a>inline box</a> <a lt="box fragment">fragment</a>
886909
that has zero borders and padding and
@@ -1185,8 +1208,8 @@ Inline Box Heights: the 'inline-sizing' property</h3>
11851208
<dt><dfn>normal</dfn>
11861209
<dd>
11871210
The <a>content area</a> of the <a>inline box</a>
1188-
is sized and position to fit its (possibly hypothetical) text,
1189-
see below.
1211+
is sized and position to fit (possibly hypothetical) text
1212+
from its [=first available font=].
11901213

11911214
<dt><dfn>stretch</dfn>
11921215
<dd>

0 commit comments

Comments
 (0)