forked from mrego/csswg-drafts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Overview.bs
1285 lines (1029 loc) · 45.1 KB
/
Overview.bs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<h1>CSS Inline Layout Module Level 3</h1>
<style media="print" type="text/css">
img#edge { width: 80%; height: 70%;}
dt.label { display: run-in; }
</style>
<pre class='metadata'>
Shortname: css-inline
Level: 3
Status: ED
Work Status: Revising
Group: csswg
TR: https://www.w3.org/TR/css-inline/
ED: https://drafts.csswg.org/css-inline/
Previous version: https://www.w3.org/TR/2016/WD-css-inline-3-20160524/
Previous version: https://www.w3.org/TR/2015/WD-css-inline-3-20150917/
Previous version: https://www.w3.org/TR/2014/WD-css-inline-3-20141218/
Previous version: https://www.w3.org/TR/2002/WD-css3-linebox-20020515/
!Issues list: <a href="https://www.w3.org/Bugs/Public/buglist.cgi?query_format=advanced&product=CSS&component=Linebox&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED">CSS3 Line Layout issues in Bugzilla</a>
Editor: Dave Cramer, Hachette Livre, [email protected]
Editor: Elika J. Etemad / fantasai, Invited Expert, http://fantasai.inkedblade.net/contact
Editor: Steve Zilles, Adobe, [email protected]
Abstract: The CSS formatting model provides for a flow of elements and text inside of a container to be wrapped into lines. The formatting of elements and text within a line, its positioning in the inline progression direction, and the breaking of lines are described in [[CSS3TEXT]]. This module describes the positioning in the block progression direction both of elements and text within lines and of the lines themselves. This positioning is often relative to a baseline. It also describes special features for formatting of first lines and drop caps. It extends on the model in [[CSS2]].
Ignored Terms: line-height-shift-adjustment, text-script, after, before, alignment subtree
Link Defaults: css-fonts-3 (property) font-family, css-color-3 (property) color
At Risk: the 'initial-letter-wrap' property
</pre>
<h2 id="intro">
Introduction</h2>
This module defines the CSS Inline Layout model,
replacing and extending the model as defined in CSS2.1.
It is very much a work-in-progress, and implementers should reference CSS2.1 for now.
The <dfn export>root inline box</dfn> is an anonymous inline box
which is automatically generated to hold
all of the <a>inline-level</a> contents of a <a>block container</a>
(if it has any).
It inherits from its parent <a>block container</a>,
but is otherwise unstyleable.
<h2 id="line-height">
Line Heights and Baseline Alignment</h2>
<p class="issue">This section is being rewritten. Refer to <a href="https://www.w3.org/TR/CSS2/visudet.html#line-height">section 10.8</a> of [[CSS2]] for the normative CSS definition or the <a href="https://www.w3.org/TR/2002/WD-css3-linebox-20020515/">2002 Working Draft</a> if you want pretty pictures. (But ignore the old text, half of it's wrong. We're not specifying which half, that's to be determined.)
<strong>The CSS2 specification should be used as the guideline for implementation.</strong></p>
Issue: The CSSWG would like to know which baseline values are necessary: if any can be dropped, or any need to be added.
<h3 id="dominant-baseline-property">
Dominant Baselines: the 'dominant-baseline' property</h3>
<pre class="propdef">
Name: dominant-baseline
Value: auto | text-bottom | alphabetic | ideographic | middle | central | mathematical | hanging | text-top
Initial: normal
Applies to: block containers and inline boxes
Inherited: yes
Percentages: N/A
Media: visual
Computed value: as specified
</pre>
This property specifies the <dfn>dominant baseline</dfn>,
which is the baseline used to align the box's text and inline-level contents.
Values have the following meanings:
<dl dfn-for=dominant-baseline dfn-type=value>
<dt><dfn>auto</dfn>
<dd>
Equivalent to ''dominant-baseline/alphabetic'' in <a>horizontal writing modes</a>
and in <a>vertical writing modes</a>
when 'text-orientation' is ''sideways'', ''sideways-right'', or ''sideways-left''.
Equivalent to ''dominant-baseline/central'' in <a>vertical writing modes</a>
when 'text-orientation' is ''mixed'' or ''upright''.
However, in SVG text, the origin point of glyphs
(used for coordinate-based glyph positioning)
is always handled as for ''dominant-baseline/central''
in <a>vertical writing modes</a>.
<dt><dfn>text-bottom</dfn>
<dd>
Use the bottom of the em box as the baseline.
<dt><dfn>alphabetic</dfn>
<dd>
Use the alphabetic baseline.
<dt><dfn>ideographic</dfn>
<dd>
Match the box's ideographic character face under-side baseline to that of its parent.
<dt><dfn>middle</dfn>
<dd>
Use the “middle” baseline: halfway between the alphabetic baseline and the ex-height.
<dt><dfn>central</dfn>
<dd>
Use the central baseline
(halfway between the ascent and descent).
<dt><dfn>mathematical</dfn>
<dd>
Use the mathematical baseline.
<dt><dfn>hanging</dfn>
<dd>
Use the hanging baseline.
<dt><dfn>text-top</dfn>
<dd>
Use the top of the em box as the baseline.
</dl>
See [[CSS3-WRITING-MODES]] for an introduction to dominant baselines.
Issue: Should be text-over and text-under instead of text-top and text-bottom,
but maybe it's better not to use those terms for consistency with legacy 'vertical-align'.
Issue: Add <css>first</css> and <css>last</css> values.
Note, in this property, these are combinatorial,
whereas in the <css>align/justify-self/content</css> properties, it's singular.
Do we want to align the syntaxes wrt hyphens vs. spaces or what?
<h3 id="transverse-alignment">
Transverse Box Alignment: the 'vertical-align' property</h3>
<pre class="propdef">
Name: vertical-align
Value: <<'baseline-shift'>> || <<'alignment-baseline'>>
Initial: baseline
Applies to: inline-level boxes
Inherited: no
Percentages: N/A
Media: visual
Computed value: as specified
</pre>
<p>This shorthand property specifies how an inline-level box is aligned within the line.
Values are the same as for its longhand properties, see below.
<p class="advisement">
Authors should use this property ('vertical-align') instead of its longhands.
<h4 id="alignment-baseline-property">
Alignment Point: 'alignment-baseline' longhand</h4>
<pre class="propdef">
Name: alignment-baseline
Value: baseline | text-bottom | alphabetic | ideographic | middle | central | mathematical | text-top | bottom | center | top
Initial: baseline
Applies to: inline-level boxes
Inherited: no
Percentages: N/A
Media: visual
Computed value: as specified
</pre>
<p>Specifies what point of an inline-level box is aligned to what point in the parent.
Values are defined below:
For the following definitions,
the margin box is used for atomic inlines,
the leading box for non-replaced inlines,
and the baselines of the box are <a lt="synthesized baseline">synthesized</a> if missing in the line-box's inline axis:
<dl dfn-for=alignment-baseline dfn-type=value>
<dt><dfn>baseline</dfn>
<dd>
Use the <a>dominant baseline</a> choice of the parent.
Match the box's corresponding baseline to that of its parent.
<dt><dfn>text-bottom</dfn>
<dd>
Match the bottom of the box to the bottom of the parent's content area.
<dt><dfn>alphabetic</dfn>
<dd>
Match the box's alphabetic baseline to that of its parent.
<dt><dfn>ideographic</dfn>
<dd>
Match the box's ideographic character face under-side baseline to that of its parent.
<dt><dfn>middle</dfn>
<dd>
Align the vertical midpoint of the box with
the baseline of the parent box plus half the x-height of the parent.
<dt><dfn>central</dfn>
<dd>
Match the box's central baseline to the central baseline of its parent.
<dt><dfn>mathematical</dfn>
<dd>
Match the box's mathematical baseline to that of its parent.
<dt><dfn>text-top</dfn>
<dd>
Match the top of the box to the top of the parent's content area.
</dl>
For the following definitions, the <a>alignment subtree</a>
is as defined in [[!CSS2]].
<dl dfn-for=alignment-baseline dfn-type=value>
<dt><dfn>top</dfn>
<dd>
Align the top of the aligned subtree with the top of the line box.
<dt><dfn>center</dfn>
<dd>
Align the center of the aligned subtree with the center of the line box.
<dt><dfn>bottom</dfn>
<dd>
Align the bottom of the aligned subtree with the bottom of the line box.
</dl>
SVG implementations <em>may</em> support the following aliases
in order to support legacy content:
<pre dfn-for=alignment-baseline dfn-type=value>
<dfn>text-before-edge</dfn> = ''alignment-baseline/text-top''
<dfn>text-after-edge</dfn> = ''alignment-baseline/text-bottom''
</pre>
These values are not allowed in the 'vertical-align' shorthand.
<h4 id="baseline-shift-property">
Alignment Shift: 'baseline-shift' longhand</h4>
<pre class="propdef">
Name: baseline-shift
Value: <<length>> | <<percentage>> | sub | super
Initial: 0
Applies to: inline-level boxes
Inherited: no
Percentages: refer to the used value of 'line-height'
Media: visual
Computed value: absolute length, percentage, or keyword specified
</pre>
<p>This property specifies by how much the box is shifted up
from its alignment point.
It does not apply when 'alignment-baseline' is ''alignment-baseline/top'' or ''alignment-baseline/bottom''.
<p class="advisement">
Authors should use the 'vertical-align' shorthand instead of this property.
Values have the following meanings:
<dl dfn-for="baseline-shift" dfn-type=value>
<dt><dfn><<length>></dfn>
<dd>Raise (positive value) or lower (negative value) by the specified length.
<dt><dfn><<percentage>></dfn>
<dd>Raise (positive value) or lower (negative value) by the specified percentage of the 'line-height'.
<dt><dfn>sub</dfn>
<dd>Lower by the offset appropriate for subscripts of the parent’s box.
(The UA should use the parent’s font data to find this offset whenever possible.)
<dt><dfn>super</dfn>
<dd>Raise by the offset appropriate for superscripts of the parent’s box.
(The UA should use the parent’s font data to find this offset whenever possible.)
</dl>
<p>User agents <em>may</em> additionally support the keyword <dfn for=baseline-shift>baseline</dfn>
as computing to ''0''
if is necessary for them to support legacy SVG content.
Issue: We would prefer to remove this, and are looking for feedback from SVG user agents as to whether it's necessary.
<h2 id="initial-letter-styling">
<!--<a name="Initial"></a>-->
Initial Letters</h2>
<p class="issue">The editors would appreciate any examples of drop initials in non-western scripts, especially Arabic and Indic scripts.</p>
<h3 id="initial-letter-intro">
<!--<a name="DropInitial"></a>-->
An Introduction to Initial Letters</h3>
Large, decorative letters have been used to start new sections of text since before the invention of printing.
In fact, their use predates lowercase letters entirely.
<h4 id="drop-initial">
Drop Initial</h4>
A <dfn>dropped initial</dfn> (or “drop cap”)
is a larger-than-usual letter at the start of a paragraph,
with a baseline at least one line lower than the first baseline of the paragraph.
The size of the drop initial is usually indicated by how many lines it occupies.
Two- and three-line drop initials are very common.
<figure>
<img src="images/Dropcap-E-acute-3line.png" width="480"
alt="3-line drop cap with E Acute" >
<figcaption>
Three-line drop initial with E acute.
Since the cap-height of the drop initial aligns with the cap-height of the main text,
the accent extends above the paragraph.
</figcaption>
</figure>
The exact size and position of a <a>dropped initial</a>
depends on the alignment of its glyph.
Reference points on the drop cap must align precisely
with reference points in the text.
In Western scripts, the top reference points are
the cap height of the initial letter and of the first line of text.
The bottom reference points are
the alphabetic baseline of the initial letter
and the baseline of the Nth line of text.
<a href="#f2">Figure 2</a> shows a simple two-line drop cap, with the relevant reference lines marked.
<figure id="f2">
<img src="images/Dropcap-lines.png" width="600"
alt="drop cap showing alignment">
<figcaption>Two-line drop cap showing baselines (green lines), cap-height (red line), and ascender (cyan line).</figcaption>
</figure>
The alignment constraints for drop initials depend on the writing system.
In ideographic scripts, the initial letter extends
from the <a>block-start</a> edge of the first line
to the <a>block-end</a> edge of the Nth line.
<figure>
<img src="images/Initial-2line-JapaneseVertical六.png" width="480"
alt="Japanese Vertical Initial">
<figcaption>Two-line drop initial in vertical writing mode</figcaption>
</figure>
In some Indic scripts, the top alignment point
is the hanging baseline,
and the bottom alignment point is the text-after-edge.
<figure>
<img src="images/Devangari-Initial.png" width="480"
alt="Devangari initial letter">
<figcaption>Devangari <a>initial letter</a> aligned with hanging baseline. Alignment points shown in red.</figcaption>
</figure>
<h4 id="sunk-initial">
Sunken Initial Letters</h4>
Some styles of drop initials do not align with the first line of text.
A <dfn>sunken initial</dfn> (or “sunken cap”)
both sinks below the first baseline,
and extends above the first line of text.
<figure>
<img src="images/SunkenCapA.png" width="480"
alt="sunken drop initial">
<figcaption>Sunken cap. The letter drops two lines, but is the size of a three-line initial letter.</figcaption>
</figure>
<h4 id="raise-initial">
Raised Initial Letters</h4>
A <dfn>raised initial</dfn> (often called a “raised cap” or “stick-up cap”) “sinks” to the first text baseline.
Note: A proper raised initial has several advantages over
simply increasing the font size of a first letter.
The line spacing in the rest of the paragraph will not be altered,
but text will still be excluded around large descenders.
And if the size of raised initial is defined to be an integral number of lines,
implicit baseline grids can be maintained.
<figure>
<img src="images/RaisedCap.png" width="480"
alt="raised cap">
<figcaption>Raised cap. The initial letter is the size of a 3-line initial, but does not drop.</figcaption>
</figure>
<h3 id="selecting-drop-initials">Selecting Initial Letters</h3>
Initial letters are typically a single letter, although
they may include punctuation or a sequence of characters which
are perceived by the user to be a single typographic unit.
The <code>::first-letter</code> pseudo-element, as defined in [[SELECT]],
can be used to select an <a>initial letter</a>.
Authors who need more control over which characters are included in an initial letter,
or who want to apply initial-letter formatting to replaced elements or multiple words
an also apply the 'initial-letter' property to the first inline-level child of a block container.
<div class="example">
<pre>
<p>This paragraph has a dropped “T”.
<p><img alt="H" src="illuminated-h.svg">ere we have an illuminated “H”.
<p><span>Words may also</span> be given initial letter styling at the beginning of a paragraph.
</pre>
<pre>
::first-letter, /* style first paragraph's T */
img, /* style illuminated H */
span /* style phrase inside span */
{ initial-letter: 2; }
</pre>
</div>
<h4 id="initial-letter-punctuation">Initial Letter Punctuation</h4>
Since <code>::first-letter</code> selects punctuation before or after the first letter, these characters are included in the initial-letter.
<figure>
<img src="images/initial-letter-punctuation-quote.png" width="604"
alt="Paragraph showing both opening quote and first letter set as three-line drop cap">
<figcaption>The <code>::first-letter</code> pseudo-element selects the quotation mark as well as the “M.”</figcaption>
</figure>
Issue: Should there be a way to opt out of this behavior? See <a href="https://github.com/w3c/csswg-drafts/issues/310">Github Issue 310</a>.
<h3 id="sizing-drop-initials">
Creating Initial Letters: the 'initial-letter' property</h3>
<pre class="propdef">
Name: <dfn id="propdef-initial-letter">initial-letter</dfn>
Value: normal | [<<number>> <<integer>>?]
Initial: normal
Applies to: <code>::first-letter</code> pseudo-elements and inline-level first child of a block container
Inherited: no
Percentages: N/A
Media: visual
Computed value: as specified
</pre>
This property specifies styling for dropped, raised, and sunken initial letters.
It takes the following values:
<dl dfn-for=initial-letter dfn-type=value>
<dt><dfn>normal</dfn>
<dd>
No special initial-letter effect. Text behaves as normal.
<dt><dfn><<number>></dfn>
<dd>
This first argument defines the size of the initial letter
in terms of how many lines it occupies.
Values less than one are invalid.
<dt><dfn><<integer>></dfn>
<dd>
This optional second argument argument
defines the number of lines the initial letter should sink.
Values less than one are invalid.
If omitted, it duplicates the first argument,
floored to the nearest positive whole number.
</dl>
Issue: Should this be <css>initial-letters</css> (plural) as originally discussed?
Since it can apply to multiple letters.
An <dfn lt="initial letter | initial letter box">initial letter</dfn> is
a box to which 'initial-letter' applies and is not ''initial-letter/normal'':
this triggers the special layout considerations described below.
<div class="example">
Here are some examples of 'initial-letter' usage:
<dl>
<dt>''initial-letter: 3''
<dt>(''initial-letter: 3 3'')
<dd>
Represents a <a>dropped initial</a> 3 lines high, 3 lines deep.
<img src="images/InitialLetter33.png" width="360"
alt="3 lines high, 3 lines deep">
<dt>''initial-letter: 3 2''
<dd>
Represents a <a>sunken initial</a> 3 lines high, 2 lines deep.
<img src="images/InitialLetter32.png" width="360"
alt="3 lines high, 2 lines deep">
<dt>''initial-letter: 3 1''
<dd>
Represents a <a>raised initial</a> 3 lines high, 1 line deep.
<img src="images/InitialLetter31.png" width="360"
alt="3 lines high, 1 line deep">
<dt>''initial-letter: 2.51 3''
<dd>
The size of the initial letter does not have to be an integral number of lines.
In this case only the bottom aligns.
<img src="images/non-integer-initial.png" width="360"
alt="Non-integral initial letter that only aligns at base">
</dl>
</div>
<div class="example">
The following code will create a 2-line dropped initial letter at the beginning of each paragraph:
<pre>p::first-letter { initial-letter: 2; }</pre>
</div>
Issue: Define interaction with <a>ruby</a>. Easiest is to make it not apply to/within <a>ruby</a>.
The 'initial-letter' property does not apply to boxes
that are not positioned at the start of the line due to bidi reordering.
<h4 id="initial-letter-properties">
Properties</h4>
The following properties apply to an <a>initial letter</a>:
<ul>
<li>all font properties (see [[CSS3-FONTS]])
<li>the 'color' and 'opacity' properties (see [[CSS3COLOR]])
<li>all background properties (see [[CSS3BG]])
<li>any typesetting properties that apply to inline elements (see [[CSS3TEXT]])
<li>all text decoration properties (see [[CSS3-TEXT-DECOR]])
<li>all margin, border and padding properties (see [[CSS2]] and [[CSS3BG]])
</ul>
Note: Which properties apply to <a>initial letter</a>
depend on whether it is an inline box or an <a>initial letter</a> box,
as <a>initial letter</a> is a display type.
Issue: Add 'width'/'height' as requested by Tantek... need to integrate with model.
<h4 id="initial-letter-model">
Layout Model</h4>
An <a>initial letter</a> is laid out following the steps outlined below:
<ol>
<li>
Find the used font size based on its 'initial-letter' size,
'initial-letter-align' alignment points,
and font metrics.
Note that no layout is required in this step.
The font size used for sizing the <a>initial letter</a> contents
<em>does not</em> affect its computed 'font-size' property
(and therefore has no effect on the computation of ''em'' length values, etc.).
<li>
Size the <a>initial letter</a>’s content box.
The content box of a non-atomic inline initial letter
is the smallest rectangle required to include the entirety of its glyphs
as well as the margin boxes of any atomic inlines it contains.
<li>
The initial letter's margin box is placed at the edge of the line.
If it has no padding or borders, it is negatively offset
by the distance from the start edge of its content box
to the point in the content that would have been placed
at the start edge of the containing block
if it had ''initial-letter: none''.
<li>
Exclude content within the inline letter's margin box
according to 'initial-letter-wrap'.
</ol>
<h4 id="initial-letter-box">
Content-box Size, Margins, Borders, and Padding</h4>
Initial letters can be styled with margins, padding, and borders
just like any other box.
Unless 'initial-letter-align' is ''initial-letter-align/border-box'',
its vertical alignment and sizing are not affected;
however the effective exclusion area is
(and corresponds to the margin area).
When padding and borders are zero,
the initial letter may be kerned;
see below.
<h3 id="aligning-initial-letter">
Alignment of Initial Letters: the 'initial-letter-align' property</h3>
As mentioned earlier, the alignment of initial letters
depends on the script used.
The 'initial-letter-align' property can be used to specify the proper alignment.
<pre class="propdef" id="initial-letter-align">
Name: <dfn id="propdef-initial-letter-align">initial-letter-align</dfn>
Value: border-box? [ alphabetic | ideographic | hebrew | hanging ] | border-box
Initial: alphabetic
Applies to: <code>::first-letter</code> pseudo elements and inline level first child of a block container
Inherited: yes
Percentages: N/A
Media: visual
Computed value: specified value
</pre>
This property specifies the alignment points
used to size and position an <a>initial letter</a>.
Two sets of alignment points are necessary:
the <a>over</a> and <a>under</a> alignment points of the <a>initial letter</a>
are matched to corresponding <a>over</a> and <a>under</a> points of the surrounding text.
Values have the following meanings:
<dl dfn-type="value" dfn-for="initial-letter-align">
<dt><dfn>alphabetic</dfn>
<dd>
Use the alphabetic and cap-height baselines of the surrounding text
to align the <a>initial letter</a>.
<dt><dfn>ideographic</dfn>
<dd>
Use the ideographic character face bottom and top edge baselines of the surrounding text
to align the <a>initial letter</a>.
<dt><dfn>hebrew</dfn>
<dd>
Use the alphabetic and (as yet theoretical) hebrew hanging baseline of the surrounding text
to align the <a>initial letter</a>.
<dt><dfn>hanging</dfn>
<dd>
Use the alphabetic and hanging baselines of the surrounding text
to align the <a>initial letter</a>.
<dt><dfn>border-box</dfn>
<dd>
Use the <a>initial letter box</a>’s <a>line-over</a> and <a>line-under</a> border edges
as the <a>over</a> and <a>under</a> alignment points, respectively.
</dl>
Issue: Is there proper a typographic term for the hebrew “hanging” baseline?
<div class="example">
The vertical writing mode example from <a href="#f2">Figure 2</a> could be coded as:
<pre>
span.initial {
initial-letter: 2;
initial-letter-align: ideographic;
}
</pre>
</div>
<div class="example">
Initial letter in Hebrew
<pre>
span.initial {
initial-letter: 2;
initial-letter-align: hebrew;
}
</pre>
<img src="images/hebrew-initial-letter.png" width="480"
alt="optical kerning in the presence or absence of a space after the initial letter">
</div>
Except when ''border-box'' is specified,
the alignment points of the <a>initial letter</a>
are automatically determined from its contents:
<ol>
<li>If the <a>initial letter</a>
is an atomic inline,
use its <a>over</a> and <a>under</a> content-box edges.
<li>Else if the <a>initial letter</a>
contains any character from the Han, Hangul, Kana, or Yi <a>Unicode scripts</a>,
use the ideographic character face bottom and top edge baselines.
<li>Else if the <a>initial letter</a>
contains any character from the Devanagari, Bengali, and Gurmukhi <a>Unicode scripts</a>,
use the hanging and alphabetic baselines.
<li>Else if the <a>initial letter</a>
contains any character from the Hebrew <a>Unicode scripts</a>,
use the ideographic character face bottom and top edge baselines.
<li>Else use the alphabetic and cap-height baselines.
</ol>
Issue: What is the proper alignment for South Asian scripts
that do not have the explicit hanging baseline, such as Tamil or Telugu?
Note: The ordering of keywords in this property is fixed in case ''border-box''
is expanded to ''[ border-box | alphabetic | ideographic | hebrew | hanging ]''
to allow explicitly specifying the <a>initial letter</a>’s alignment points.
<h4 id="initial-letter-align-defaults">
UA Default Stylesheet for 'initial-letter-align'</h4>
In order to provide the better behavior by default,
UAs must include in their default UA style sheet the following rules:
<pre>
[lang=zh], [lang=ja], [lang=ko], [lang=ii] {
initial-letter-align: ideographic;
}
[lang|=iw], [lang|=yi], [lang|=lad], [lang|=jrb] {
initial-letter-align: hebrew;
}
[lang|=hi], [lang|=mr], [lang|=ne], , [lang|=pi], [lang|=kok], [lang|=brx], [lang|=mai], [lang|=sd], [lang|=sa] {
initial-letter-align: hanging;
}
</pre>
Issue: We don't have a way to do subtag selection with attr selectors.
(It's a feature of '':lang()'' in Selectors 4,
but we don't want to use that because we want to hit the language root,
not all of the descendant elements.)
These selectors should also include the relevant script subtags.
<h3 id="sizing-initial-letters">
Sizing Initial Letters</h3>
The size of a drop initial is determined
by the need to satisfy the required alignment.
For an <var>N</var>-line drop initial in a Western script,
the cap-height of the letter needs to be (<var>N</var> – 1) times the line-height,
plus the cap-height of the surrounding text.
Note this height is <em>not</em> the font size of the drop initial.
Actually calculating this font size is tricky.
For an <var>N</var>-line drop initial,
we find the drop initial font size to be:
<figure>
<img src="images/InitialCapEquation.png" width="604"
alt="Font size of drop cap = ((N-1) * line-height + [cap-height of para] * [font size of paragraph])/[cap-height ratio of drop initial font]">
</figure>
<!--
<div>
<math display="block"><mrow><mi>Font size of drop initial</mi><mo>=</mo></mrow><mfrac><mrow><mo>(</mo><mi>N</mi><mo>-</mo><mn>1</mn><mo>)</mo><mo>×</mo><mi>line-height</mi><mo>+</mo><mo>(</mo><mi>cap-height ratio of para font</mi><mo>×</mo><mi>font size of para</mi><mo>)</mo></mrow><mrow><mi>cap-height ratio of drop initial font</mi></mrow></mfrac></math>
</div>
-->
<div class="example">
A three-line drop initial in Adobe Minion Pro
would have a font size of 61.2pt given
12pt text, 16pt line-height, and a cap-height of 651/1000 (from the font’s OS/2 table).
</div>
The line height used in this calculation
is the 'line-height' of the containing block
(or, in the case where a baseline grid is in use,
the baseline-to-baseline spacing required by the baseline grid [[CSS3-LINE-GRID]]).
The contents of the lines spanned,
and therefore any variation in their heights and positions,
is not accounted for.
<h4 id="initial-letter-shaping">
Shaping and Glyph Selection</h4>
When 'initial-letter' is not ''normal'',
shaping does not occur across the box's boundaries,
as if the zero-width non-joiner (U+200C) were inserted
before/after the <a>initial letter</a>.
For example, if the first letter of the Farsi word “پس”
were styled with ''initial-letter: 2 1'',
both letters would be styled in their isolated forms,
with “پ” as the initial letter, followed by the normally-styled “س”.
Issue: Are there other things we need to consider here?
<h3 id="initial-letter-exclusions">
Space Around Initial Letters</h3>
The glyph(s) of an initial letter do not always fit within the specified sink.
For example, if an initial letter has a descender,
it could crash into the (n+1)th line of text.
This is not desirable.
<figure>
<img src="images/Dropcap-J-3line-crash.png" width="480"
alt="3-line drop cap with J, with descender crashing into fourth line of text">
<figcaption>Incorrect: three-line initial letter with descender</figcaption>
</figure>
Text is therefore excluded around the glyph bounding boxes of the initial letters.
Specifically, for non-atomic initial letters,
the content box of the element is sized to fit:
<ul>
<li>The specified amount of sink
(i.e the distance from the top alignment point to the bottom alignment point).
<li>The actual ascent and descent and side bearings of all the glyphs it contains
that are part of its inline formatting context,
even if they leak outside their em boxes.
<li>The margin boxes of all the atomic inlines it contains
that are part of its inline formatting context,
even if they leak outside its own line-height.
</ul>
The margin box of the initial letter is then made an exclusion area for subsequent text.
<figure>
<img src="images/Dropcap-J-3line-exclude.png" width="480"
alt="3-line drop cap with J, but four-line exclusion">
<figcaption>Correct: text excluded around glyph bounding box</figcaption>
</figure>
<h3 id="initial-letter-position">
Positioning and Kerning Initial Letters</h3>
In the <a>block axis</a>, the <a>initial letter</a> is positioned
to satisfy its alignment requirements. (See 'initial-letter-align'.)
In the <a>inline axis</a>, the position of the inline letter
is given by aligning its start margin edge to the start edge of the containing block.
However, if the <a>initial letter</a> is a non-atomic inline with zero padding and borders,
the UA must apply an additional negative offset on the start side,
of the amount necessary to optically align the first glyph
to the containing block edge as it would be in normal text.
<h3 id="initial-letter-wrapping">
Initial Letter Wrapping: the 'initial-letter-wrap' property</h3>
Note: 'initial-letter-wrap' is at risk.
<pre class="propdef">
Name: <dfn id="propdef-initial-letter-wrap">initial-letter-wrap</dfn>
Value: none | first | all | grid | <<length>> | <<percentage>>
Initial: none
Applies to: <code>::first-letter</code> pseudo-elements and inline-level first child of a block container
Inherited: yes
Percentages: relative to <a>logical width</a> of (last fragment of) initial letter
Media: visual
Computed value: as specified
</pre>
This property specifies whether lines impacted by an <a>initial letter</a>
are shortened to fit the rectangular shape of the <a>initial letter</a> box
or follow the contour of its end-edge glyph outline.
<dl dfn-for=initial-letter-wrap dfn-type=value>
<dt><dfn>none</dfn>
<dd>
No contour-fitting is performed:
each impacted line is aligned flush to the end margin edge of the <a>initial letter</a>.
<dt><dfn>first</dfn>
<dd>
Behaves as ''none''
if the first <a>typographic character unit</a> after the <a>initial letter</a>
belongs to Unicode General Category Zs.
Otherwise behaves as for ''all''
on the first line of the block containing the initial letter
and as ''none'' on the rest.
<div class="example">
This example shows why contour-fitting the first line is necessary,
and why it is dropped when the <a>initial letter</a> is followed by a space:
<figure>
<img src="images/OpticalKerning.png" width="200"
alt="optical kerning in the presence or absence of a space after the initial letter">
<figcaption>
In the top paragraph, the initial letter "A" has a word space after it:
the gap between the top of the "A" and the next letter
provides the necessary word separation.
In the next paragraph, the initial letter "A"
is part of the first word,
and leaving a gap between the top of the "A" and the next letter
would create a jarring visual break within the word.
In this case, the first line of text
should be kerned into the initial letter's area,
as shown in the bottom paragraph.
</figcaption>
</figure>
</div>
Issue: Do we need an unconditional ''first''?
(I.e. Should we rename this value to ''auto'' and add a ''first'' value that does not check for spaces?)
<dt><dfn>all</dfn></dt>
<dd>
For each line of text impacted by the initial letter,
the line box adjacent to the intial letter starts
at the start-most point that touches the ink of the initial letter,
plus the amount of the <a>initial letter</a>’s end-side border+padding+margin.</dd>
Note: This value is at-risk.
<dt><dfn>grid</dfn>
<dd>
This value is the same as ''none'',
except that the exclusion area of the impacted lines
is increased as necessary for its end-edge to land on the character grid.
The 'justify-self' property can then be used to align
the initial letter box within the exclusion area.
The heuristic for matching the character grid is
1em × <var>n</var> + 'letter-spacing' × (<var>n</var> - 1),
where <var>n</var> is the size of the initial letter
as specified by the 'initial-letter' property,
and 1em represents the typical character advance width for ideographic characters
(and may be replaced by a more accurate value if known).
<figure>
<img src="images/CJK-Initial.001.png" width="480"
alt="Diagram of Japanese initial letter in vertical writing mode">
<figcaption>Diagram of Japanese initial letter in vertical writing mode</figcaption>
</figure>
Note: In this example, the exclusion area for the drop initial
is larger than its glyph in order to preserve inline-axis alignment.
Note: This value is also at-risk.
<dt><dfn><<length>></dfn>
<dt><dfn><<percentage>></dfn>
<dd>
This value behaves the same as ''first''
except that the adjustment to the first line is given explicitly
instead of being inferred from the glyph shape.
Issue: This really needs font-relative lengths to be relative to the used size.
Note: This value exists because it is easier to implement.
Authors are encouraged to use the ''first'' value
and to set margins to control spacing,
and to use this as a fallback for glyph detection if necessary.
<div class="example">
In the following example, UAs that support ''first'' will use the glyph outline
plus the specified margin in order to place the first line,
whereas UAs that only support <<length>> or <<percentage>> values
will pull in the first line by 40% of the initial letter's width
(and then add the margin to that point).
<pre>
h1 + p:first-letter {
initial-letter: 3; /* 3-line drop-cap */
initial-letter-wrap: first;
margin-right: 0.1em;
}
@supports (not (initial-letter-wrap: first)) {
/* Classes auto-generated on paragraphs to match first letter. */
p.A:first-letter {
initial-letter-wrap: -40%; /* Start of glyph outline, assuming correct font. */
}
}
</pre>
</div>
Issue: These values and related annoyance is likely unnecessary if someone submits a patch to Blink to support ''first''.
</dl>
Issue: Edit figure to show how auto behaves in varying contexts
<div class="example">
<pre>
p::first-letter {
initial-letter: 3;
initial-letter-wrap: none;
}
</pre>
<figure>
<img src="images/A-wraparound-none.png" width="600"
alt="regular dropcap A">
<figcaption>Ordinary initial letter with no wrapping.</figcaption>
</figure>
</div>
<div class="example">
<pre>
p::first-letter {
initial-letter: 3;
initial-letter-wrap: all;
}
</pre>
<img src="images/A-wraparound.png" width="600"
alt="text wrapping around dropcap A" >
Text follows shape of initial letter.
Each line box should just touch the ink of the letter,
with some offset (represented by the shaded box).
</div>
<div class="example">
<pre>
p::first-letter {
initial-letter: 3;
initial-letter-wrap: first;
}
</pre>
<img src="images/A-wraparound-first.png" width="600"
alt="text wrapping around dropcap A but only on first line">
Only the first line is moved up against the ink of the initial letter.
</div>
<div class="example">
<img src="images/V-wraparound.png" width="600"
alt="text wrapping around dropcap V">