-
Notifications
You must be signed in to change notification settings - Fork 707
/
Copy pathOverview.bs
1567 lines (1351 loc) · 68.6 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
<pre class='metadata'>
Title: CSS Ruby Layout Module Level 1
Shortname: css-ruby
Level: 1
Status: ED
Work Status: Exploring
Group: csswg
ED: https://drafts.csswg.org/css-ruby-1/
TR: https://www.w3.org/TR/css-ruby-1/
Previous Version: https://www.w3.org/TR/2014/WD-css-ruby-1-20140805/
Previous Version: https://www.w3.org/TR/2013/WD-css3-ruby-20130919/
Editor: Elika J. Etemad / fantasai, Invited Expert, http://fantasai.inkedblade.net/contact, w3cid 35400
Editor: Koji Ishii, Google, kojiishi@gmail.com, w3cid 45369
Editor: Xidorn Quan, Mozilla https://www.mozilla.org/, https://www.upsuper.org/, w3cid 73936
Abstract: “Ruby”, a form of interlinear annotation, are short runs of text alongside the base text.
Abstract: They are typically used in East Asian documents to indicate pronunciation or to provide a short annotation.
Abstract: This module describes the rendering model and formatting controls related to displaying ruby annotations in CSS.
Ignored terms: internal table elements
Ignored vars: any
</pre>
<!--
Issues:
box layout/sizing
clean up inter-character vs. parallel layout requirements
Redo all examples with consistent font. (M+ 2p?)
-->
<h2 id="intro">
Introduction</h2>
<p><em>This section is not normative.</em>
<h3 id="placement">
Module interactions</h3>
<p>This module extends the inline box model of CSS Level 2 [[!CSS2]]
to support ruby.
<p>None of the properties in this module apply to the <code>::first-line</code> or
<code>::first-letter</code> pseudo-elements.
<h3 id="values">
Values</h3>
This specification follows the <a href="https://www.w3.org/TR/CSS2/about.html#property-defs">CSS property definition conventions</a> from [[!CSS2]].
Value types not defined in this specification are defined in CSS Values & Units [[!CSS-VALUES-3]].
Other CSS modules may expand the definitions of these value types.
In addition to the property-specific values listed in their definitions,
all properties defined in this specification
also accept the <a>CSS-wide keywords</a> keywords as their property value.
For readability they have not been repeated explicitly.
<h3 id="diagram-conventions">
Diagram conventions</h3>
<p>Many typographical conventions in East Asian typography depend
on whether the character rendered is wide (CJK) or narrow (non-CJK).
There are a number of illustrations in this document
for which the following legend is used:
<dl>
<dt><img alt="Symbolic wide-cell glyph representation" width="39" height="39" src="images/fullwidth.gif">
<dd>Wide-cell glyph (e.g. Han) that is the <var>n</var>th character in the text run.
They are typically sized to 50% when used as annotations.
<dt><img alt="Symbolic narrow-cell glyph representation" width="19" height="39" src="images/halfwidth.gif">
<dd>Narrow-cell glyph (e.g. Roman) which is the <var>n</var>th glyph in the text run.
</dl>
<p>The orientation which the above symbols assume in the diagrams
corresponds to the orientation that the glyphs they represent
are intended to assume when rendered by the user agent.
Spacing between these characters in the diagrams is incidental,
unless intentionally changed to make a point.
<h3 id="ruby-def">
What is ruby?</h3>
<p><dfn export>Ruby</dfn> is the commonly-used name for a run of text
that appears alongside another run of text (referred to as the “base”)
and serves as an annotation or a pronunciation guide associated with that run of text.
<p>The following figures show two examples of Ruby,
a simple case and one with more complicated structure.
<div class="example">
<p>In this first example, a single annotation is used to annotate the base text.
<div class="figure">
<p><img src="images/licence.png"
alt="Example of ruby applied on top of a Japanese expression">
<p class="caption">Example of ruby used in Japanese (simple case)
</div>
<p>In Japanese typography, this case is sometimes called
<span lang="ja">taigo</span> ruby or group-ruby (per-word ruby),
because the annotation as a whole is associated
with multi-character word (as a whole).
</div>
<div class="example">
<p>In this second example,
two levels of annotations are attached to a base sequence:
the hiragana characters on top refer to the pronunciation of each of the base kanji characters,
while the words “Keio” and “University” on the bottom are annotations describing the English translation.
<div class="figure">
<p><img src="images/ruby-univ.gif"
alt="Example showing complex ruby with annotation text over and under the base characters">
<p class="caption">Complex ruby with annotation text over and under the base characters
</div>
<p>
<p>Notice that to allow correct association between the hiragana characters and
their corresponding Kanji base characters,
the spacing between these Kanji characters is adjusted.
(This happens around the fourth Kanji character in the figure above.)
To avoid variable spacing between the Kanji characters in the example above
the hiragana annotations can be styled as a <i>collapsed annotation</i>,
which will look more like the group-ruby example earlier.
However because the base-annotation pairings are recorded in the ruby structure,
if the text breaks across lines, the annotation characters will stay
correctly paired with their respective base characters.
</div>
<p><i>Ruby</i> formatting as used in Japanese is described in JIS X-4051 [[JIS4051]] (in Japanese)
and in Requirements for Japanese Text Layout [[JLREQ]] (in English and Japanese)].
In HTML, ruby structure and markup to represent it is described
in the Ruby Markup Extension specification.
This module describes the CSS rendering model
and formatting controls relevant to ruby layout of such markup.
<h2 id="ruby-model">
Ruby Box Model</h2>
<p>The CSS ruby model is based on
the <a href="https://www.w3.org/TR/html5/text-level-semantics.html#the-ruby-element">W3C HTML5 Ruby Markup</a> model
and the <a href="https://www.w3.org/TR/ruby/">XHTML Ruby Annotation Recommendation</a> [[RUBY]].
In this model, a ruby structure consists of
one or more <i>ruby base</i> elements representing the base (annotated) text,
associated with one or more levels of <i>ruby annotation</i> elements representing the annotations.
The structure of ruby is similar to that of a table:
there are “rows” (the <i lt="base level">base text level</i>, each <i>annotation level</i>)
and “columns” (each <i>ruby base</i> and its corresponding <i>ruby annotations</i>).
<p>Consecutive bases and annotations are grouped together into <i>ruby segments</i>.
Within a <i>ruby segment</i>, a <i>ruby annotation</i> may span multiple <i>ruby bases</i>.
<p class="note">In HTML, a single <code><ruby></code> element may contain multiple <i>ruby segments</i>.
(In the XHTML Ruby model, a single <code><ruby></code> element can only contain one <i>ruby segment</i>.)
<h3 id="ruby-display">
Ruby-specific 'display' Values</h3>
<p>For document languages (such as XML applications) that do not have pre-defined ruby elements,
authors must map document language elements to ruby elements;
this is done with the 'display' property.
<pre class=propdef partial>
Name: display
New values: ruby | ruby-base | ruby-text | ruby-base-container | ruby-text-container
</pre>
<p>The following new 'display' values assign ruby layout roles to an arbitrary element:
<dl dfn-type=value export dfn-for=display>
<dt><dfn>ruby</dfn>
<dd>Specifies that an element generates a <dfn dfn for lt="ruby container | ruby container box">ruby container box</dfn>.
(Corresponds to HTML/XHTML <code><ruby></code> elements.)
<dt><dfn>ruby-base</dfn>
<dd>Specifies that an element generates a <dfn dfn for lt="ruby base box | ruby base">ruby base box</dfn>.
(Corresponds to HTML/XHTML <code><rb></code> elements.)
<dt><dfn>ruby-text</dfn>
<dd>Specifies that an element generates a <dfn dfn for lt="ruby annotation box | ruby annotation | annotation">ruby annotation box</dfn>.
(Corresponds to HTML/XHTML <code><rt></code> elements.)
<dt><dfn>ruby-base-container</dfn>
<dd>Specifies that an element generates a <dfn dfn for lt="ruby base container box | ruby base container">ruby base container box</dfn>.
(Corresponds to XHTML <code><rbc></code> elements; generated as an anonymous box in HTML.)
<dt><dfn>ruby-text-container</dfn>
<dd>Specifies that an element generates a <dfn dfn for lt="ruby annotation container box | ruby annotation container">ruby annotation container box</dfn>.
(Corresponds to HTML/XHTML <code><rtc></code> elements.)
</dl>
<p class="advisement">Authors using a language (such as HTML)
that supports dedicated ruby markup
should use that markup rather than
styling arbitrary elements (like <code><span></code>)
with ruby 'display' values.
Using the correct markup ensures that screen readers
and non-CSS renderers can interpret the ruby structures.
<h4 id="formatting-context">
The Ruby Formatting Context</h4>
<p><i>Ruby containers</i> are non-atomic inline-level boxes.
Like inline boxes, they break across lines,
and their containing block is the nearest block container ancestor.
And just as the contents of an inline box
participate in the same inline formatting context that contains the inline box itself,
a <i>ruby container</i> and its base-level contents
participate in the same inline formatting context that contains the <i>ruby container</i> itself.
<p>However <i>ruby containers</i> also establish a <dfn export>ruby formatting context</dfn>
that builds further structure around their segment of the inline formatting context.
<i>Ruby bases</i>, <i>ruby annotations</i>, <i>ruby base containers</i>, and <i>ruby annotation containers</i>
are <dfn export lt="internal ruby boxes|internal ruby display types">internal ruby boxes</dfn>:
like <i>internal table elements</i>,
they have specific roles in ruby layout,
and participate in their <i>ruby container</i>’s <i>ruby formatting context</i>.
<p>As with the contents of inline boxes,
the containing block for the contents of a <i>ruby container</i> (and all its <i>internal ruby boxes</i>)
is the containing block of the <i>ruby container</i>.
So floats, for example, are trapped by the <i>ruby container</i>’s containing block,
not any of the ruby box types.
<p class="issue">Are internal ruby boxes inline-level?
<h4 id="block-ruby">
Non-Inline Ruby</h4>
<p>If an element has an <i>inner display type</i> of ''ruby''
and an <i>outer display type</i> other than ''display/inline'',
then it generates two boxes:
a principal box of the required <i>outer display type</i> type,
and an inline-level <i>ruby container</i>.
All properties specified on the element apply to the principal box
(and if inheritable, inherit to the <i>ruby container box</i>).
This allows styling the element as a block,
while correctly maintaining the internal ruby structure.
<p class="note">
Note that absolute positioning or floating an element causes its 'display' value
to compute to a block-level equivalent. (See [[!CSS-DISPLAY-3]] or [[!CSS2]] section 9.7.)
For the <i>internal ruby display types</i>,
this causes their 'display' value to compute to ''display/block''.
<h3 id="box-fixup">
Anonymous Ruby Box Generation</h3>
<p>The CSS model does not require that the document language
include elements that correspond to each of these components.
Missing parts of the structure are implied through the anonymous box generation rules
<a href="https://www.w3.org/TR/CSS2/tables.html#anonymous-boxes">similar to those used to normalize tables</a>. [[!CSS2]]
<ol>
<li id="anon-gen-inlinize"><strong><a>Inlinify</a> block-level boxes:</strong>
Any in-flow boxes directly contained by a
<i>ruby container</i>,
<i>ruby base container</i>,
<i>ruby annotation container</i>,
<i>ruby base box</i>,
or <i>ruby annotation box</i>
are “<a>inlinified</a>” per [[!CSS-DISPLAY-3]]),
and their 'display' value computed accordingly,
so that they contain only inline-level content.
For example,
the 'display' property of an in-flow element with ''display: block''
parented by an element with ''display: ruby-text''
computes to ''inline-block''.
<li id="anon-gen-anon-ruby"><strong>Generate anonymous ruby containers</strong>:
Any <a href="https://www.w3.org/TR/CSS2/tables.html#anonymous-boxes">consecutive</a> sequence of
improperly-contained
<i>ruby base containers</i>,
<i>ruby annotation containers</i>,
<i>ruby bases</i>,
and/or
<i>ruby annotations</i>
(and any intervening <i>white space</i>)
is wrapped in an anonymous <i>ruby container</i>.
For the purpose of this step:
<ul>
<li>an improperly-contained <i>ruby base</i> is one not parented by a <i>ruby base container</i> or <i>ruby container</i>
<li>an improperly-contained <i>ruby annotation</i> is one not parented by a <i>ruby annotation container</i> or <i>ruby container</i>
<li>an improperly-contained <i>ruby base container</i> or <i>ruby annotation container</i>
is one not parented by a <i>ruby container</i>
</ul>
<li id="anon-gen-bare-inlines"><strong>Wrap misparented inline-level content:</strong>
Any consecutive sequence of text and inline-level boxes
directly parented by a <i>ruby container</i> or <i>ruby base container</i>
is wrapped in an anonymous <i>ruby base</i>.
Similarly, any consecutive sequence of text and inline-level boxes
directly parented by a <i>ruby annotation container</i>
is wrapped in an anonymous <i>ruby annotation</i>.
(For this purpose, misparented <i>internal table elements</i>
are treated as <a>inline-level content</a>
since, being parented by ruby boxes,
they will be ultimately wrapped by an <a>inline table</a>.)
However, if an anonymous box so constructed contains only <i>white space</i>,
it is considered <dfn>intra-ruby white space</dfn>
and is either discarded
or preserved
as described below.
<li id="anony-gen-trim-space"><strong>Trim leading/trailing white space:</strong>
Any <i>intra-ruby white space</i>
that is not the sole child of its parent
and occurs at the beginning or end of
a <i>ruby container</i>, <i>ruby annotation container</i>, or <i>ruby base container</i>
is removed, as if it had ''display: none''
<li id="anon-gen-discard-space"><strong>Remove inter-level white space:</strong>
Any <i>intra-ruby white space</i>
whose immediately adjacent siblings match one of the patterns below
is <dfn>inter-level white space</dfn>
and is removed, as if it had ''display: none''.
<table class="data">
<thead>
<tr><th>Previous box
<th>Next box
<tbody>
<tr><td><var>any</var>
<td><i>ruby annotation container</i>
<tr><td>not <i>ruby annotation</i>
<td><i>ruby annotation</i>
<!--
<tr><td><i>ruby base</i> or <i>ruby base container</i>
<td><i>ruby annotation</i> or <i>ruby annotation container</i>
<tr><td><i>ruby annotation container</i>
<td><i>ruby annotation container</i>
<tr><td><i>ruby annotation</i>
<td><i>ruby annotation container</i>
<tr><td><i>ruby annotation container</i>
<td><i>ruby annotation</i>
-->
</table>
<li id="anon-gen-interpret-space"><strong>Interpret intra-level white space:</strong>
Any <i>intra-ruby white space</i> box
whose immediately adjacent siblings match one of the patterns below
is assigned the box type and subtype defined in the table below:
<table class="data">
<colgroup span=2></colgroup>
<colgroup span=2></colgroup>
<thead>
<tr><th>Previous box
<th>Next box
<th>Box type
<th>Subtype
<tbody>
<tr><td><i>ruby base</i>
<td><i>ruby base</i>
<td><i>ruby base</i>
<td><dfn>inter-base white space</dfn>
<tr><td><i>ruby annotation</i>
<td><i>ruby annotation</i>
<td><i>ruby annotation</i>
<td><dfn>inter-annotation white space</dfn>
<tr><td><i>ruby annotation</i> or <i>ruby annotation container</i>
<td><i>ruby base</i> or <i>ruby base container</i>
<td rowspan=3><i>ruby base</i>
<td rowspan=3><dfn>inter-segment white space</dfn>
<tr><td><i>ruby base</i> or <i>ruby base container</i>
<td><i>ruby base container</i>
<tr><td><i>ruby base container</i>
<td><i>ruby base</i> or <i>ruby base container</i>
</table>
The <dfn>intra-level white space</dfn> boxes defined above are
treated specially for pairing and layout. See below.
<li id="anon-gen-unbreak"><strong>Suppress line breaks:</strong>
Convert all forced line breaks inside <i>ruby annotations</i> (regardless of 'white-space' value)
as defined for <i>collapsible</i> segment breaks in <a href="https://www.w3.org/TR/css-text-3/#line-break-transform">CSS Text Level 3 § 4.1.2</a>.
<p class="issue">The goal of this is to simplify the layout model by suppressing any line breaks within ruby annotations.
Alternatively we could try to define some kind of acceptable behavior for them.
<li id="anon-gen-anon-containers"><strong>Generate anonymous level containers:</strong>
Any consecutive sequence of <i>ruby bases</i> and <i>inter-base white space</i>
(and not <i>inter-segment white space</i>)
not parented by a <i>ruby base container</i>
is wrapped in an anonymous <i>ruby base container</i>.
Similarly, any consecutive sequence of <i>ruby annotations</i> and <i>inter-annotation white space</i>
not parented by a <i>ruby annotation container</i>
is wrapped in an anonymous <i>ruby annotation container</i>.
</ol>
<p class="issue">Make <a href="http://lists.w3.org/Archives/Public/www-archive/2014Jun/att-0027/PastedGraphic-1.png">this diagram</a> into an example.
<p>Once all ruby layout structures are properly parented,
the UA can start to associate bases with their annotations.
<p class="note">
Note that the UA is not required to create any of these anonymous boxes
(or the anonymous empty <i>intra-level white space</i> boxes in the pairing section)
in its internal structures,
as long as pairing and layout behaves as if they existed.
<h3 id="ruby-pairing">
Annotation Pairing</h3>
<p>Annotation <dfn>pairing</dfn> is the process of associating
<i>ruby annotations</i> with <i>ruby bases</i>.
Each <i>ruby annotation</i> is associated with one or more <i>ruby bases</i>,
and is said to <dfn>span</dfn> those bases.
(A <i>ruby annotation</i> that <i>spans</i> multiple bases is called
a <dfn>spanning annotation</dfn>.)
A <i>ruby base</i> is can be associated with
only one <i>ruby annotation</i> per <i>annotation level</i>.
However, if there are multiple <i>annotation levels</i>,
it can be associated with multiple <i>ruby annotations</i>.
Once pairing is complete, ruby “column” units are defined,
each represented by a single <i>ruby base</i>
and one <i>ruby annotation</i> (possibly an empty, anonymous one)
from each <i>annotation level</i> in its <i>ruby segment</i>.
<h4 id="segment-pairing">
Segment Pairing and Annotation Levels</h4>
<p>A ruby structure is divided into <dfn>ruby segments</dfn>,
each consisting of a single <i>ruby base container</i>
followed by one or more <i>ruby annotation containers</i>.
Each <i>ruby annotation container</i> in a <i>ruby segment</i>
represents one <dfn lt="annotation level | level">level</dfn> of annotation for the base text:
the first one represents the first level of annotation,
the second one represents the second level of annotation,
and so on.
The <i>ruby base container</i> represents the <dfn>base level</dfn>.
The <i>ruby base container</i> in each segment is thus paired
with each of the <i>ruby annotation containers</i> in that segment.
<p>In order to handle degenerate cases, some empty anonymous containers are assumed:
<ul>
<li>If the first child of a <i>ruby container</i> is a <i>ruby annotation container</i>,
an anonymous, empty <i>ruby base container</i> is assumed to exist before it.
<li>Similarly, if the <i>ruby container</i> contains consecutive <i>ruby base containers</i>,
anonymous, empty <i>ruby annotation containers</i> are assumed to exist between them.
</ul>
<p><i>Inter-segment white space</i> is effectively a <i>ruby segment</i> of its own.
<h4 id="base-annotation-pairing">
Unit Pairing and Spanning Annotations</h4>
<p>Within a <i>ruby segment</i>,
each <i>ruby base</i> in the <i>ruby base container</i>
is paired with one <i>ruby annotation</i>
from each <i>ruby annotation container</i> in its <i>ruby segment</i>.
<p>If a <i>ruby annotation container</i> contains only
a single, anonymous <i>ruby annotation</i>,
then that <i>ruby annotation</i> is paired with (i.e. <i>spans</i> across)
all of the <i>ruby bases</i> in its <i>ruby segment</i>.
<p>Otherwise, each <i>ruby annotation</i> is paired,
in order, with the corresponding <i>ruby base</i> in that segment</i>.
If there are not enough <i>ruby annotations</i> in a <i>ruby annotation container</i>,
the remaining <i>ruby bases</i> are paired with anonymous empty annotations
inserted at the end of the <i>ruby annotation container</i>.
If there are not enough <i>ruby bases</i>,
any remaining <i>ruby annotations</i> pair with empty, anonymous bases
inserted at the end of the <i>ruby base container</i>.
<p>If an implementation supports ruby markup with explicit spanning
(e.g. XHTML Complex Ruby Annotations),
it must adjust the pairing rules to pair <i>spanning annotations</i>
to their bases appropriately.
<p><i>Intra-level white space</i> does not participate in standard annotation <i>pairing</i>.
However, if the immediately-adjacent <i>ruby bases</i> or <i>ruby annotations</i>
are paired
<ul>
<li>with two <i>ruby bases</i> or <i lt="ruby annotations">annotations</i>
that surround corresponding <i>intra-level white space</i> in another level,
then the so-corresponding <i>intra-level white space</i> boxes are also paired.
<li>with a single spanning <i>ruby annotation</i>,
then the <i>intra-level white space</i> is also paired to that <i>ruby annotation</i>
<li>with two <i>ruby bases</i> or <i lt="ruby annotations">annotations</i>
with no intervening <i>intra-level white space</i>,
then the <i>intra-level white space</i> box pairs with
an anonymous empty <i>intra-level white space</i> box assumed to exist between them.
</ul>
<p class="issue">Insert diagram</p>
<h4 id="nested-pairing">
Complex Spanning with Nested Ruby</h4>
<p>When <i>ruby containers</i> are <dfn lt="nested ruby">nested</dfn>,
pairing begins with the deepest <i>ruby container</i>,
then expands out.
From the pairing perspective of the outer <i>ruby container</i>,
each <i>ruby container</i> nested within another <i>ruby container</i>
counts as representing a single <i>ruby base</i>/<i>annotation</i> per level.
The outer <i>ruby container</i>’s <i>ruby annotations</i> paired to the <i>nested ruby</i>
are therefore paired with (and <i>span</i>) all of the nested <i>ruby container</i>’s <i>ruby bases</i>.
Each <i>ruby annotation container</i> in the nested <i>ruby container</i>
occupies the same <i>annotation level</i> in the outer <i>ruby container</i>
as it does in the inner one
and participates in its layout as if it were directly contained in the outer <i>ruby container</i>.
<p>This process is recursive.
Thus, using nested <i>ruby containers</i> allows the representation
of complex spanning relationships.
<p class="issue">It's not clear whether this falls out of layout handling of ruby containers inside ruby bases
or needs to be handled specially.
Waiting until layout is better-defined to find out...
<h3 id="autohide">
Autohiding Base-identical Annotations</h3>
<p>If a <i>ruby annotation</i> has the exact same text content as its base,
it is <dfn lt="hidden ruby annotation | hidden annotation">hidden</dfn>.
Hiding a <i>ruby annotation</i> does not affect annotation pairing
or the block-axis positioning of boxes in other <i>levels</i>.
However the <i>hidden annotation</i> is not visible,
and it has no impact on layout
other than to separate adjacent sequences of <i>ruby annotation boxes</i> within its level,
as if they belonged to separate segments
and the <i>hidden annotation</i>’s base were not a <i>ruby base</i> but an intervening inline.
<div class="example">
<p>This is to allow correct inlined display of annotations
for Japanese words that are a mix of kanji and hiragana.
For example, the word <span lang=ja>振り仮名</span> should be inlined as
<p class="figure">振り仮名(ふりがな)
<p>and therefore marked up as
<pre>
<!-- --><ruby>
<!-- --> <rb>振</rb><rb>り</rb><rb>仮</rb><rb>名</rb>
<!-- --> <rp>(</rp><rt>ふ</rt><rt>り</rt><rt>が</rt><rt>な</rt><rp>)</rp>
<!-- --></ruby></pre>
<p>However, when displayed as ruby, the “り” should be hidden
<div class="figure">
<p><img src="images/furigana-separate.png"
alt="Hiragana annotations for 振り仮名 appear, each pronunciation above its kanji base character.">
<p class="caption">Hiragana ruby for 振り仮名. Notice there is no hiragana annotation above り, since it is already in hiragana.
</div>
</div>
<p>When the computed value of 'ruby-merge' is ''collapse'',
the autohiding is disabled.
When the computed value of 'ruby-merge' is ''auto'',
the user agent may decide whether to autohide or not,
but it is recommended to autohide if the algorithm the user agent chose
produces the results similar to ''separate'' would produce.
<p>The content comparison for this auto-hiding behavior
takes place prior to white space collapsing ('white-space') and text transformation ('text-transform')
and ignores elements (considers only the <code>textContent</code> of the boxes).
<p class="note">
Future levels of CSS Ruby may add controls for auto-hiding,
but in this level it is always forced.
<h3 id="white-space">
White Space Collapsing</h3>
<p>White space within a ruby structure is <a href="#anon-gen-discard-space">discarded</a>
<ul>
<li>at the beginning and end of a <i>ruby container</i>, <i>ruby annotation container</i>, or <i>ruby base container</i>,
<li>between a <i>ruby base container</i> and its following <i>ruby annotation container</i>,
<li>between <i>ruby annotation containers</i>.
</ul>
<div class="example">
For example, the following markup will display without any spaces:
<pre>
<!-- --><ruby>
<!-- --> <rb>東</rb><rb>京</rb>
<!-- --> <rt>とう</rt><rt>きょう</rt>
<!-- --> <rt>Tō</rt><rt>kyō</rt>
<!-- --></ruby></pre>
</div>
<p>Between <i>ruby segments</i>, between <i>ruby bases</i>, and between <i>ruby annotations</i>, however,
white space is not discarded,
and is maintained for rendering
as <i lt="inter-base white space">inter-base</i>,
<i lt="inter-annotation white space">inter-annotation</i>,
or <i>inter-segment white space</i>.
(See <a href="#box-fixup">Anonymous Ruby Box Generation</a>, above.)
<div class="example">
<p>The rules preserving white space allow ruby to be used with space-separated scripts such as Latin.
For example,
<pre>
<!-- --><ruby>
<!-- --> <rb>W</rb><rb>W</rb><rb>W</rb>
<!-- --> <rt>World</rt> <rt>Wide</rt> <rt>Web</rt>
<!-- --></ruby></pre>
<p>They also ensure that annotated white space is preserved. For example,
<pre>
<!-- --><ruby>
<!-- --> <rb>Aerith</rb><rb> </rb><rb>Gainsboro</rb>
<!-- --> <rt>エアリス</rt><rt>・</rt><rt>ゲインズブール</rt>
<!-- --></ruby></pre>
</div>
<p>Where undiscarded white space is <i>collapsible</i>, it will collapse
following the standard <a href="https://www.w3.org/TR/css3-text/#white-space-rules">white space processing rules</a>. [[!CSS3TEXT]]
For <i>collapsible white space</i> between <i>ruby segments</i> (<i>inter-segment white space</i>), however,
the contextual text for determining collapsing behavior is given by the <i>ruby bases</i> on either side,
not the text on either side of the white space in source document order.
<div class="note">
<p>Note that the white space processing rules
cause a white space sequence containing a <i>segment break</i> (such as a line feed)
to <a href="https://www.w3.org/TR/css3-text/#line-break-transform">collapse to nothing</a> between Han and Kana characters.
This means that Chinese and Japanese ruby can safely use white space for indentation of ruby markup.
For example, the following markup will display without any spaces:
<pre>
<!-- --><ruby>
<!-- --> 屋<rt>おく</rt>内<rt>ない</rt>
<!-- --> 禁<rt>きん</rt>煙<rt>えん</rt>
<!-- --></ruby></pre>
<p>However, white space that does not contain a <i>segment break</i> does not collapse completely away,
so this markup will display with a space between the first and second ruby pairs:
<pre>
<!-- --><ruby>
<!-- --> 屋<rt>おく</rt> 内<rt>ない</rt>
<!-- --> 禁<rt>きん</rt> 煙<rt>えん</rt>
<!-- --></ruby></pre>
</div>
<h2 id="ruby-layout">
Ruby Layout</h2>
<p>When a ruby structure is laid out,
its <i>base level</i> is laid out on the line,
aligned according to its 'vertical-align' property
exactly as if its <i>ruby bases</i> were a regular sequence of inline boxes.
Each <i>ruby base container</i> is sized and positioned
to contain exactly all of its <i>ruby bases</i>’ margin boxes.
<p><i>Ruby annotations</i> associated with the <i>base level</i>
are then positioned with respect to their <i>ruby base boxes</i>
according to the applicable 'ruby-position' values.
<i>Ruby annotations</i> within a level (within a single <i>ruby container</i>)
are aligned to each other as if they were inline boxes
participating in the same inline formatting context.
Each <i>ruby annotation container</i> is sized and positioned
to contain exactly all of its <i>ruby annotations</i>’ margin boxes.
<p><i>Ruby annotation containers</i> are stacked outward
over or under their corresponding <i>ruby base container</i>,
without any intervening space.
<p class="issue">Should block-axis margins collapse?
This makes layout more robust,
but is inconsistent with how inlines behave along the inline-axis.
<p>A ruby container (or fragment thereof)
measures as wide as the content of its widest level.
Similarly, <i>ruby base boxes</i> and <i>ruby annotation boxes</i>
within a ruby “column” have the measure of the widest content in that “column”.
In the case of <i>spanning annotations</i>
(whether actually spanning or pretending to span per 'ruby-merge'),
the measures of the <i>ruby annotation box</i> and
the sum of its associated <i>ruby base boxes</i> must match.
<p>How the extra space is distributed
when ruby content is narrower than the measure of its box
is specified by the 'ruby-align' property.
<p class="issue">Should the ruby bases and annotations size to the column,
or size to the content?
<h3 id="inter-character-layout">
Inter-character Ruby Layout</h3>
<p>Inter-character annotations have special layout.
When 'ruby-position' indicates ''inter-character'' annotations,
the affected <i>ruby annotation boxes</i>
are spliced into and measured as part of the layout of the <i>base level</i>.
The <i>ruby base container</i> must be sized to include both the <i>ruby base boxes</i>
as well as the ''inter-character'' <i>ruby annotation boxes</i>.
The affected <i>ruby annotation container</i> is similarly sized
so that its content box coincides with that of the <i>ruby base container</i>.
<p>For the purpose of laying out other levels of annotations,
an ''inter-character'' annotation effectively becomes part of its base.
<span class="issue">Or should it become a quasi-base between two bases?</span>
A spanning ''inter-character'' annotation is placed after
all the bases that it spans.
<h3 id="box-style">
Styling Ruby Boxes</h3>
<p>In most respects, ruby boxes can be styled similar to inline boxes.
However, the UA is not required to support
any of the box properties (borders, margins, padding),
any of the background properties or outline properties,
or any other property that illustrates the bounds of the box
on <i>ruby base container boxes</i>, <i>ruby annotation container boxes</i>,
or <a href="#nested-pairing">ruby-internal ruby container boxes</a>.
The UA may implement these boxes simply as abstractions for inheritance
and control over the layout of their contents.
<h3 id="line-breaks">
Breaking Across Lines</h3>
<p>When there is not enough space for an entire <i>ruby container</i> to fit on the line,
the ruby may be broken wherever all levels simultaneously allow a break.
Ruby most often breaks between base-annotation sets,
but if the line-breaking rules allow it, can also break within a <i>ruby base</i>
(and, in parallel, its associated <i>ruby annotation boxes</i>).
<p>Whenever ruby breaks across lines, <i>ruby annotations</i> must stay
with their respective <i>ruby bases</i>.
The line <em>must not</em> break between a <i>ruby base</i> and its <i>annotations</i>,
even in the case of ''inter-character'' <i>annotations</i>.
<div class="figure">
<img src="images/r-break-b.gif"
alt='Diagram showing the line breaking opportunity in a "Bopomofo" ruby'>
<p class="caption">''inter-character'' ruby line breaking opportunity
</div>
<h4 id="break-between">
Breaking Between Bases</h4>
<p>In typical cases, <i>ruby base boxes</i> and <i>ruby annotation boxes</i>
are styled to forbid internal line wrapping and do not contain forced breaks.
(See <a href="#default-stylesheet">Appendix A</a>.)
In such cases the <i>ruby container</i> can only break between adjacent <i>ruby bases</i>,
and only if no <i>ruby annotations</i> span those <i>ruby bases</i>.
<div class="figure">
<p><img src="images/r-break-a.gif"
alt="Diagram showing the line breaking opportunity in a complex ruby">
<p class="caption">Ruby line breaking opportunity
</div>
<p>Whether ruby can break between two adjacent <i>ruby bases</i>
is controlled by normal line-breaking rules for the base text,
exactly as if the <i>ruby bases</i> were adjacent inline boxes.
(The annotations are ignored when determining soft wrap opportunities for the <i>base level</i>.)
<div class="example">
<p>For example, if two adjacent ruby bases are “蝴” and “蝶”,
the line may break between them,
because lines are normally allowed to break between two Han characters.
However, if 'word-break' is ''keep-all'', that line break is forbidden.
<pre><ruby>蝴<rt>hú</rt>蝶<rt>dié</rt></pre>
</div>
<p>Inter-base white space is significant for evaluating line break opportunities between <i>ruby bases</i>.
As with white space between inlines, it collapses when the line breaks there.
Similarly, annotation white space is also trimmed at a line break.
<div class="example">
<p>For example, given the following markup:
<pre><ruby><rb>one</rb> <rb>two</rb> <rt>1</rt> <rt>2</rt></ruby></pre>
<p>Due to the space, the line may break between “one” and “two“.
If the line breaks there, that space—and the space between “1” and “2”—disappears,
in accordance with standard CSS white space processing rules. [[CSS3TEXT]]
</div>
<h4 id="break-within">
Breaking Within Bases</h4>
<p>For longer base texts, it is sometimes appropriate to allow breaking within a base-annotation pair.
For example, if an English sentence is annotated with its Japanese translation,
allowing the text to wrap allows for reasonable line breaking behavior in the paragraph.
<p class="issue">
Insert scanned example so people don't think this is just the ramblings of an insane spec-writer.
<p>Line-breaking within a <i>ruby base</i> is only allowed if the 'white-space' property
of the <i>ruby base</i> and all its parallel <i>annotations</i> allow it,
and there exists a <i>soft wrap opportunity</i> <em>within</em> (i.e. not at the start or end)
the content of each base/annotation box.
Since there is no structural correspondence between fragments of content
within <i>ruby bases</i> and <i>annotations</i>,
the UA may break at any set of opportunities;
but it is recommended that the UA attempt to proportionally balance
the amount of content inside each fragment.
<p>There are no line breaking opportunities within ''inter-character'' <i>annotations</i>.
<p>Ruby alignment takes place within each fragment, after line-breaking.
<h3 id="bidi">
Bidi Reordering</h3>
<p>The Unicode bidirectional algorithm reorders logically-stored text for visual presentation
when characters from scripts of opposing directionalities are mixed
within a single paragraph.
<p>To preserve the correspondance of <i>ruby annotations</i>
to their respective <i>ruby bases</i>,
a few restrictions must be imposed:
<ul>
<li>The contents of a <i>ruby base</i> or <i>ruby annotation</i> must remain contiguous.
<li><i>Ruby annotations</i> must be reordered together with their <i>ruby bases</i>.
<li>All <i>ruby bases</i> spanned by a single <i>ruby annotation</i> must remain contiguous.
</ul>
<p>To this end,
<ul>
<li>
Bidi isolation is forced on all <i>internal ruby boxes</i> and the <i>ruby container</i>:
the ''unicode-bidi/normal'' and ''embed'' values of 'unicode-bidi' compute to ''isolate'',
and ''bidi-override'' computes to ''isolate-override''.
<p class="note">
Note this means that implicit bidi reordering does not work across ruby bases,
so authors will need to ensure that the <i>ruby container</i>’s declared directionality
does indeed match its contents.
<li>
During layout, <i>ruby segments</i> are ordered within the <i>ruby container</i>
by the 'direction' property of their <i>ruby container</i>.
<li>
Within a segment, <i>ruby bases</i> and <i>ruby annotations</i>
are ordered within their respective containers
by the 'direction' property of the segment’s <i>ruby base container</i>.
<span class="note">
Note this means the 'direction' property on <i>ruby annotation containers</i>
is ignored for the purpose of layout.
However, it can still inherit into the container's children
and thereby affect the <i>inline base direction</i>
of any <i>ruby annotations</i> it contains.
</span>
</ul>
<p>As with other inline-level content,
the bidi reordering of <i>internal ruby boxes</i> happens after line-breaking
so that content is divided across lines according to its logical order.
<p>See [[CSS3-WRITING-MODES]] for a more in-depth discussion of bidirectional text in CSS.
<!-- Some alternate proposals exist in the 2013 draft's comments section. -->
<h3 id="line-height">
Line Spacing</h3>
<p>The 'line-height' property controls spacing between lines in CSS.
When inline content on line is shorter than the 'line-height',
half-leading is added on either side of the content,
as specified in <a href="https://www.w3.org/TR/CSS2/visudet.html#line-height">CSS2.1§10.8</a>. [[!CSS2]]
<p>In order to ensure consistent spacing of lines,
documents with ruby typically ensure that the 'line-height' is large enough
to accommodate ruby between lines of text.
Therefore, ordinarily, <i>ruby annotation containers</i> and <i>ruby annotation boxes</i>
do not contribute to the measured height of a line's inline contents;
any alignment (see 'vertical-align') and line-height calculations
are performed using only the <i>ruby base container</i>,
exactly as if it were a normal inline.
<p>However, if the 'line-height' specified on the <i>ruby container</i>
is less than the distance between
the top of the top <i>ruby annotation container</i>
and the bottom of the bottom <i>ruby annotation container</i>,
then additional leading is added
on the appropriate side of the <i>ruby base container</i>
such that if a block consisted of three lines
each containing ruby identical to this,
none of the <i>ruby containers</i> would overlap.
<p class="note">Note that this does not ensure that the <i>ruby annotations</i> remain within the line box.
It merely ensures that <em>if all lines had equal spacing</em>
and equivalent amounts and positioning of <i>ruby annotations</i>,
there would be enough room to avoid overlap.
<p>Authors should ensure appropriate 'line-height' and 'padding' to accommodate ruby,
and be particularly careful at the beginning or end of a block
and when a line contains inline-level content
(such as images, inline blocks, or elements shifted with 'vertical-align')
taller than the paragraph's default font size.
<div class="figure">
<p><img src="images/rlh-a.gif"
alt="The content of each line sits in the middle of its line height;
the additional space on each side is called half-leading.
Ruby fits between lines if it is smaller than twice the half-leading,
but this means that it occupies space belonging to the half-leading of the previous line.">
<p class="caption">Ruby annotations will often overflow the line;
authors should ensure content over/under a ruby-annotated line
is adequately spaced to leave room for the ruby.
</div>
<p class="note">More control over how ruby affects alignment and line layout
will be part of the CSS Line Layout Module Level 3.
Note, it is currently in the process of being rewritten;
the current drafts should not be relied upon.
<h2 id="ruby-props">
Ruby Formatting Properties</h2>
<p>The following properties are introduced to control ruby
<a href="#rubypos">positioning</a>,
<a href="#collapsed-ruby">text distribution</a>,
and <a href="#rubyalign">alignment</a>.
<h3 id="rubypos">
Ruby Positioning: the 'ruby-position' property</h3>
<pre class="propdef">
Name: ruby-position
Value: over | under | inter-character
Initial: over
Applies to: ruby annotation containers
Inherited: yes
Computed value: specified keyword
Animation type: discrete
</pre>
<p>This property controls position of the ruby text with respect to its base.
Values have the following meanings:
<p class="issue"><span class="issuehead">Issue-107: </span> Roland Steiner has requested the addition of an auto value as default. See <a href="http://www.w3.org/Search/Mail/Public/advanced_search?keywords=&hdr-1-name=subject&hdr-1-query=ruby-position%3A+undesirable+default+value+%27before%27+for+complex+ruby&hdr-2-name=from&hdr-2-query=&hdr-3-name=message-id&hdr-3-query=&period_month=&period_year=&index-grp=Public__FULL&index-type=t&type-index=www-style&resultsperpage=20&sortby=date">this thread</a> and <a href="http://www.w3.org/Search/Mail/Public/advanced_search?keywords=&hdr-1-name=subject&hdr-1-query=Styling+of+complex+Ruby&hdr-2-name=from&hdr-2-query=&hdr-3-name=message-id&hdr-3-query=&period_month=&period_year=&index-grp=Public__FULL&index-type=t&type-index=public-i18n-core&resultsperpage=20&sortby=date">this one</a>. Current proposal is to add an optional ''alternate?'' keyword.</p>
<dl dfn-for=ruby-position dfn-type=value>
<dt><dfn>over</dfn>
<dd>The ruby text appears <a>line-over</a> the base.
<div class="figure">
<p><img src="images/shinkansen-top.gif"
alt="Diagram of ruby glyph layout in horizontal mode with ruby text appearing above the base">
<p class="caption">Ruby over Japanese base text in horizontal layout
</div>
<div class="figure">
<p><img src="images/shinkansen-right.gif" width="33"
alt="Diagram of ruby glyph layout in vertical mode with ruby text appearing vertically on the right of the base">
<p class="caption">Ruby to the right of Japanese base text in vertical layout
</div>
</dd>
<dt><dfn>under</dfn>
<dd>The ruby text appears <a>line-under</a> the base.
This is a relatively rare setting used in ideographic East Asian writing systems,
most easily found in educational text.
<div class="figure">
<p><img src="images/shinkansen-bottom.gif"
alt="Diagram of ruby glyph layout in horizontal mode with ruby text appearing below the base">
<p class="caption">Ruby under Japanese base text in horizontal layout
</div>
<div class="figure">
<p><img src="images/shinkansen-left.gif"
alt="Diagram of ruby glyph layout in vertical mode with ruby text appearing vertically on the left of the base">
<p class="caption">Ruby to the left of Japanese base text in vertical layout
</div>
</dd>
<dt><dfn>inter-character</dfn></dt>
<dd>
<p>The ruby text appears on the right of the base in horizontal text.
This value forces the computed value of 'writing-mode' of the <i>ruby annotation container</i> to be ''vertical-rl''.
<p>This value is provided for the special case of traditional Chinese
as used especially in Taiwan:
ruby (made of <a href="#g-bopomofo">bopomofo</a> glyphs) in that context
appears vertically along the right side of the base glyph,
even when the layout of the base characters is horizontal:
<div class="figure">
<p><img src="images/bopomofo.gif"
alt="Example of Taiwanese-style ruby">
<p class="caption">“Bopomofo” ruby in traditional Chinese
(ruby text shown in blue for clarity) in horizontal layout
</div>
</dd>
</dl>
<p>If multiple <i>ruby annotation containers</i> have the same 'ruby-position',
they stack along the block axis,
with lower levels of annotation closer to the base text.
<h3 id="collapsed-ruby">
Sharing Annotation Space: the 'ruby-merge' property</h3>
<pre class="propdef">
Name: ruby-merge
Value: separate | collapse | auto
Initial: separate
Applies to: ruby annotation containers
Inherited: yes
Computed value: specified keyword
Animation type: by computed value type
</pre>
<p>
This property controls how ruby annotation boxes should be rendered
when there are more than one in a ruby container box:
whether each pair should be kept separate,
the annotations should be <dfn lt="collapsed annotation">collapsed</dfn> and rendered as a group,
or the separation should be determined based on the space available.
<p>Possible values:</p>
<dl dfn-for=ruby-merge dfn-type=value>
<dt><dfn>separate</dfn>
<dd>
<p>
Each ruby annotation box is rendered in the same column(s) as its corresponding base box(es).
This style is called “mono ruby” in [[JLREQ]].
<div class="example">
<p>For example, the following two markups render the same:
<pre><ruby>無<rt>む</ruby><ruby>常<rt>じょう</ruby></pre>
<p>and:
<pre><ruby style="ruby-merge:separate"><rb>無<rb>常<rt>む<rt>じょう</ruby></pre>
</div>