Skip to content

Commit 8eed341

Browse files
committed
[css-inline-3] Tighten up initial letter layout. Dedup, reorganize, fix minor glitches, etc.
1 parent d802767 commit 8eed341

File tree

1 file changed

+193
-142
lines changed

1 file changed

+193
-142
lines changed

css-inline-3/Overview.bs

+193-142
Original file line numberDiff line numberDiff line change
@@ -794,120 +794,6 @@ Applicability</h4>
794794
whose 'float' is not ''float/none'' or 'position' is not ''static'',
795795
because these values cause its 'display' to compute to ''display/block''.
796796

797-
<h4 id="initial-letter-properties">
798-
Properties</h4>
799-
800-
All properties that apply to an <a>inline box</a>
801-
also apply to an <a>initial letter</a>
802-
(unless it is an <a>atomic inline</a>,
803-
in which case the set of properties that apply to an <a>atomic inline</a> apply)
804-
except for 'vertical-align' and its <a>sub-properties</a>,
805-
'font-size', and 'line-height'.
806-
<!-- Basically, any properties defined in css-inline
807-
except those specific to initial letters,
808-
so keep this list updated as we add things to this spec. -->
809-
Additionally, all of the <a>sizing properties</a>
810-
and 'box-sizing' also apply to <a>initial letters</a>.
811-
812-
<h4 id="initial-letter-model">
813-
Layout Model</h4>
814-
815-
An <a>initial letter</a> is laid out following the steps outlined below:
816-
817-
<ol>
818-
<li>
819-
Find the used font size based on its 'initial-letters' size,
820-
'initial-letters-align' alignment points,
821-
and font metrics.
822-
Note that no layout is required in this step.
823-
The font size used for sizing the <a>initial letter</a> contents
824-
<em>does not</em> affect its computed 'font-size' property
825-
(and therefore has no effect on the computation of ''em'' length values, etc.).
826-
827-
<li>
828-
Size the <a>initial letter</a>’s content box.
829-
830-
If its <a>width</a>/<a>height</a> is definite,
831-
use that value
832-
(clamped as required by the <a>min size</a> and <a>max size</a> properties,
833-
and handling 'box-sizing' as required)
834-
for that dimension of the box.
835-
In the case of a definite <a>inline size</a>,
836-
'text-align' is honored
837-
for aligning the contents of the <a>initial letter</a> within its box
838-
in the <a>inline axis</a>
839-
(using its <a>inline-axis</a> bearings as usual,
840-
not the bounding box of its glyph outlines).
841-
In the case of a definite <a>block size</a>,
842-
'align-content' is honored
843-
for aligning its contents in the <a>block axis</a>
844-
(using its <a>block-axis</a> bearings,
845-
synthesizing them if needed).
846-
847-
Otherwise
848-
it is considered to have an <a>automatic size</a> in that dimension
849-
and is sized and positioned to coincide with
850-
the smallest rectangle that would include
851-
the bounding boxes of all its glyphs--
852-
excluding any that <a spec="css-text-3">hang</a>
853-
(see 'hanging-punctuation')--
854-
as well as the margin boxes of any atomic inlines it contains.
855-
856-
ISSUE: Should the hanging punctuation be included in the box instead
857-
(so that the box is drawn around the punctuation when it is made visible through borders/background),
858-
but rather only excluded when positioning the box
859-
(so that the initial letter remains flush,
860-
with the hanging punctuation properly hanging)?
861-
See <a href="https://github.com/w3c/csswg-drafts/issues/310">discussion</a>.
862-
863-
<li>
864-
In the <a>inline axis</a>,
865-
the initial letter's margin box is placed at the start edge of the line.
866-
If it is a non-atomic inline
867-
with an <a lt="automatic size">automatic</a> <a>inline size</a>
868-
and has no padding or borders,
869-
it is negatively offset
870-
by the distance from the start edge of its content box
871-
to the point in the content that would have been placed
872-
at the start edge of the containing block
873-
if it had ''initial-letters: none''.
874-
875-
In the <a>block axis</a>,
876-
the initial letter is anchored to the dominant baseline
877-
of the <a>first formatted line</a>,
878-
positioned with respect to that baseline
879-
such that it would sink the number of lines
880-
specified by 'initial-letters'’s second argument
881-
if its containing block held only
882-
the <a>initial letter</a> itself
883-
followed by an infinite sequence of plain text
884-
as the direct contents of its <a>root inline box</a>.
885-
886-
<figure>
887-
<img src="images/infinite-text.png" width="300"
888-
alt="text underlay shows how initial letter alignment is not affected
889-
by the content of the spanned lines">
890-
</figure>
891-
892-
<li>
893-
Exclude content within the inline letter's margin box
894-
according to 'initial-letters-wrap'.
895-
</ol>
896-
897-
<h4 id="initial-letter-box">
898-
Content-box Size, Margins, Borders, and Padding</h4>
899-
900-
Initial letters can be styled with margins, padding, and borders
901-
just like any other box.
902-
Unless 'initial-letters-align' is ''initial-letters-align/border-box'',
903-
its vertical alignment and sizing are not affected;
904-
however the effective exclusion area is
905-
(and corresponds to the margin area).
906-
907-
When padding and borders are zero,
908-
the initial letter may be kerned;
909-
see below.
910-
911797
<h3 id="aligning-initial-letter">
912798
Alignment of Initial Letters: the 'initial-letters-align' property</h3>
913799

@@ -1048,11 +934,96 @@ UA Default Stylesheet for 'initial-letters-align'</h4>
1048934
Issue: This only covers the most common cross-linguistic transcription systems.
1049935
Should we include any other / all script tags in the UA style sheet?
1050936

937+
<h3 id="initial-letter-layout">
938+
Initial Letter Layout</h3>
939+
940+
There are two types of <a>initial letter boxes</a>:
941+
those that arise from non-replaced <a>inline boxes</a>
942+
and those that arise from <a>atomic inlines</a>.
943+
944+
For the non-atomic <dfn lt="inline initial letter | inline initial letter box">inline initial letter</dfn>,
945+
the box and its contents
946+
participate in the same <a>inline formatting context</a>
947+
as the line on which it occurs,
948+
and a lot of special rules apply
949+
to give the expected sizing and alignment.
950+
951+
For an <dfn lt="atomic initial letter | atomic initial letter box">atomic initial letter</dfn>,
952+
however,
953+
which is either a <a>replaced element</a>
954+
or which establishes an <a>independent formatting context</a> for its contents,
955+
the sizing of the box
956+
and layout of the contents within the box
957+
follows the usual rules:
958+
it is primarily the positioning of the box
959+
which is special.
960+
961+
<h4 id="initial-letter-properties">
962+
Properties Applying to Initial Letters</h4>
963+
964+
All properties that apply to an <a>inline box</a>
965+
also apply to an <a>inline initial letter</a>
966+
except for 'vertical-align' and its <a>sub-properties</a>,
967+
'font-size', 'line-height', 'line-sizing', and 'inline-sizing'.
968+
<!-- Basically, any properties defined in css-inline
969+
except those specific to initial letters,
970+
so keep this list updated as we add things to this spec. -->
971+
Additionally, all of the <a>sizing properties</a>
972+
and 'box-sizing' also apply to <a>initial letters</a>,
973+
(see [[!css-sizing-3]]).
974+
975+
All properties that apply to an <a>atomic inline</a>
976+
also apply to the <a>atomic inline</a> when styled as an <a>initial letter</a>,
977+
except for 'vertical-align' and its <a>sub-properties</a>.
978+
979+
<h4 id="initial-letter-box">
980+
Margins, Borders, and Padding</h4>
981+
982+
Initial letters can be styled with margins, padding, and borders
983+
just like any other box.
984+
Unless 'initial-letters-align' is ''initial-letters-align/border-box'',
985+
its vertical alignment and sizing are not affected;
986+
however the effective exclusion area is
987+
(and corresponds to the margin area).
988+
989+
ISSUE: Reword that to handle 'box-sizing' correctly.
990+
991+
When padding and borders are zero,
992+
the initial letter may be kerned;
993+
see below.
994+
1051995
<h3 id="sizing-initial-letters">
1052-
Sizing Initial Letters</h3>
996+
Font Sizing of Initial Letters</h3>
997+
998+
For an <a>inline initial letter</a>,
999+
the font size used for sizing the <a>initial letter</a> contents
1000+
is calculated to fulfill its specified <a>size</a> (see 'initial-letters')
1001+
as anchored by its specified alignment points (see 'initial-letters-align').
1002+
Note that no layout is required in this calculation:
1003+
it is based only on computed values and font metrics.
1004+
These <a lt="used value">used</a> font size calculations
1005+
<em>do not</em> affect the <a lt="computed value">computed</a> 'font-size',
1006+
and therefore have no effect on the computation of ''em'' length values, etc.
1007+
1008+
ISSUE: What about inheritance to descendants?
1009+
1010+
For an <a>atomic initial letter</a>,
1011+
the used font size is the computed font size as usual.
1012+
1013+
The line height used in these calculations
1014+
is the 'line-height' of the containing block
1015+
(or, in the case where a baseline grid is in use,
1016+
the baseline-to-baseline spacing required by the baseline grid [[CSS-LINE-GRID-1]]).
1017+
The contents of the lines spanned,
1018+
and therefore any variation in their heights and positions,
1019+
is not accounted for.
1020+
1021+
<figure>
1022+
<img src="images/infinite-text.png" width="300"
1023+
alt="text underlay shows how initial letter alignment is not affected
1024+
by the content of the spanned lines">
1025+
</figure>
10531026

1054-
The size of a drop initial is determined
1055-
by the need to satisfy the required alignment.
10561027
For an <var>N</var>-line drop initial in a Western script,
10571028
the cap-height of the letter needs to be (<var>N</var> – 1) times the line-height,
10581029
plus the cap-height of the surrounding text.
@@ -1073,26 +1044,21 @@ Sizing Initial Letters</h3>
10731044
</div>
10741045
-->
10751046

1047+
ISSUE: Update this calculation to be a) generic across writing systems / alignment points and b) handle non-integer sizes.
1048+
10761049
<div class="example">
10771050
A three-line drop initial in Adobe Minion Pro
10781051
would have a font size of 61.2pt given
10791052
12pt text, 16pt line-height, and a cap-height of 651/1000 (from the font’s OS/2 table).
10801053
</div>
10811054

1082-
The line height used in this calculation
1083-
is the 'line-height' of the containing block
1084-
(or, in the case where a baseline grid is in use,
1085-
the baseline-to-baseline spacing required by the baseline grid [[CSS-LINE-GRID-1]]).
1086-
The contents of the lines spanned,
1087-
and therefore any variation in their heights and positions,
1088-
is not accounted for.
1089-
10901055
<h4 id="initial-letter-shaping">
10911056
Shaping and Glyph Selection</h4>
10921057

10931058
When 'initial-letters' is not ''initial-letters/normal'',
1094-
shaping <em>should</em> still occur across the box's boundaries,
1095-
see [[css-text-3#boundary-shaping]].
1059+
shaping <em>should</em> still occur across
1060+
an <a>inline initial letter box</a>'s boundaries.
1061+
(See [[css-text-3#boundary-shaping]].)
10961062
For example, if the first letter of the Farsi word “پس”
10971063
were styled with ''initial-letters: 2 1'',
10981064
both letters would be styled in their joined forms,
@@ -1102,9 +1068,64 @@ Shaping and Glyph Selection</h4>
11021068
even when shaped in their joining forms.
11031069

11041070
Issue: Are there other things we need to consider here?
1105-
1106-
<h3 id="initial-letter-exclusions">
1107-
Space Around Initial Letters</h3>
1071+
1072+
<h3 id="initial-letter-box-size">
1073+
Sizing the Initial Letter Box</h3>
1074+
1075+
If the <a>initial letter</a>’s <a>specified width</a>/<a>specified height</a>
1076+
is <a>definite</a>,
1077+
use that value
1078+
(clamped as required by the <a>min size</a> and <a>max size</a> properties,
1079+
and handling 'box-sizing' as required)
1080+
for that dimension of the box.
1081+
1082+
Otherwise
1083+
it is considered to have an <a>automatic size</a> in that dimension
1084+
and is sized and positioned to coincide with
1085+
the smallest rectangle that would include
1086+
the bounding boxes of all its glyphs--
1087+
excluding any that <a spec="css-text-3">hang</a>
1088+
(see 'hanging-punctuation')--
1089+
as well as the margin boxes of any atomic inlines it contains.
1090+
1091+
ISSUE: Should the hanging punctuation be included in the box instead
1092+
(so that the box is drawn around the punctuation when it is made visible through borders/background),
1093+
but rather only excluded when positioning the box
1094+
(so that the initial letter remains flush,
1095+
with the hanging punctuation properly hanging)?
1096+
See <a href="https://github.com/w3c/csswg-drafts/issues/310">discussion</a>.
1097+
1098+
<h4 id="initial-letter-content-align">
1099+
Alignment Within an Initial Letter Box</h4>
1100+
1101+
By default (i.e. under <a>automatic sizing</a>),
1102+
the content box of an <a>inline initial letter</a>
1103+
is fitted exactly to its content,
1104+
and alignment properties like 'text-align' or 'align-content' do not apply.
1105+
However, if the box is <em>not</em> sized automatically:
1106+
1107+
<ul>
1108+
<li>
1109+
If the <a>inline size</a> is <a>definite</a>,
1110+
'text-align' is honored
1111+
for aligning the contents of the <a>initial letter</a>
1112+
within its box in the <a>inline axis</a>
1113+
(using its <a>inline-axis</a> bearings as usual,
1114+
not the bounding box of its glyph outlines).
1115+
1116+
<li>
1117+
If the <a>block size</a> is <a>definite</a>,
1118+
'align-content' is honored
1119+
for aligning its contents in the <a>block axis</a>
1120+
(using its <a>block-axis</a> bearings,
1121+
synthesizing them if needed).
1122+
</ul>
1123+
1124+
<h3 id="initial-letter-position">
1125+
Initial Letter Positioning and Spacing</h3>
1126+
1127+
<h4 id="initial-letter-exclusions">
1128+
Space Below Initial Letters</h4>
11081129

11091130
The glyph(s) of an initial letter do not always fit within the specified sink.
11101131
For example, if an initial letter has a descender,
@@ -1118,8 +1139,9 @@ Space Around Initial Letters</h3>
11181139
In this font, the capital “J” extends well below the baseline (shown in red).</figcaption>
11191140
</figure>
11201141

1121-
Text is therefore excluded around the glyph bounding boxes of the initial letters.
1122-
1142+
Therefore all line boxes impacted by the glyph bounding boxes
1143+
of an <a>initial letter</a> are excluded,
1144+
not just those within range of the <a>initial letter sink</a>.
11231145
Specifically, for non-atomic initial letters,
11241146
the content box of the element is sized to fit:
11251147

@@ -1136,27 +1158,56 @@ Space Around Initial Letters</h3>
11361158
even if they leak outside its own line-height.
11371159
</ul>
11381160

1139-
The margin box of the initial letter is then made an exclusion area for subsequent text.
1161+
The initial letter is then made an exclusion area,
1162+
the same as if it were a float.
1163+
See 'initial-letter-wrap' for details.
11401164

11411165
<figure>
11421166
<img src="images/Dropcap-J-3line-exclude.png" width="480"
11431167
alt="3-line drop cap with J, but four-line exclusion">
11441168
<figcaption>Correct: text excluded around glyph bounding box</figcaption>
11451169
</figure>
11461170

1147-
<h3 id="initial-letter-position">
1148-
Positioning and Kerning Initial Letters</h3>
1171+
<h4 id="initial-letter-block-position">
1172+
Block-axis Positioning</h4>
11491173

11501174
In the <a>block axis</a>, the <a>initial letter</a> is positioned
1151-
to satisfy its alignment requirements. (See 'initial-letters-align'.)
1175+
as required to satisfy its <a>under</a> alignment point ('initial-letters-align')
1176+
at its specified [=initial letter sink|sink=] ('initial-letters'),
1177+
i.e. it is positioned
1178+
such that it would sink the number of lines
1179+
specified by 'initial-letters'’s second argument
1180+
and align to the requisite <a>under</a> alignment point
1181+
if it was assumed that its containing block held only
1182+
the <a>initial letter</a> itself
1183+
followed by an infinite sequence of plain text
1184+
as the direct contents of its <a>root inline box</a>.
1185+
1186+
<figure>
1187+
<img src="images/infinite-text.png" width="300"
1188+
alt="Constant-sized text underlay shows how initial letter alignment
1189+
is not affected by the content of the spanned lines.">
1190+
</figure>
11521191

1153-
In the <a>inline axis</a>, the position of the inline letter
1154-
is given by aligning its start margin edge to the start edge of the containing block.
1192+
Its position is anchored with respect to the line on which it occurs.
1193+
1194+
<h4 id="initial-letter-inline-position">
1195+
Inline Positioning and Kerning</h4>
11551196

1156-
However, if the <a>initial letter</a> is a non-atomic inline with zero padding and borders,
1157-
the UA must apply an additional negative offset on the start side,
1158-
of the amount necessary to optically align the first glyph
1159-
to the containing block edge as it would be in normal text.
1197+
In the <a>inline axis</a>, the position of the inline letter
1198+
is given by matching its <a>inline-start</a> <a>margin edge</a>
1199+
with the <a>inline-start</a> edge of the line box.
1200+
1201+
However, if the <a>initial letter</a> is a non-atomic inline
1202+
with an [=automatic size|automatic=] [=inline size=] and
1203+
zero padding and borders,
1204+
it is negatively offset
1205+
by the distance from the start edge of its content box
1206+
to the point in the content that would have been placed
1207+
at the start edge of the containing block
1208+
if it were not an <a>initial letter</a>
1209+
(i.e. the distance between its glyph bounding box
1210+
and its start side bearing).
11601211

11611212
<h3 id="initial-letter-wrapping">
11621213
Initial Letter Wrapping: the 'initial-letters-wrap' property</h3>

0 commit comments

Comments
 (0)