8000 csswg-drafts/css-text-4/Overview.src.html at 2c40f0c4a84ebeb02f8c9d673155a836521c0400 · w3c/csswg-drafts · GitHub
Skip to content

Latest commit

 

History

History
executable file
·
4976 lines (4510 loc) · 196 KB

File metadata and controls

executable file
·
4976 lines (4510 loc) · 196 KB
</div>
<p class="issue">It's been pointed out that ''trim-inner'', ''consume-before'',
and ''consume-after'' won't work well because 'text-space-collapse' is
inherited, meaning that inserting a &lt;span> or &gt;div> would cause more
white space to be removed than otherwise.
<h3 id="tab-size">
Tab Character Size: the 'tab-size' property</h3>
<table class="propdef">
<tbody>
<tr>
<th>Name:</th>
<td><dfn>tab-size</dfn></td>
</tr>
<tr>
<th>Value:</th>
<td>&lt;integer&gt; | &lt;length&gt;</td>
</tr>
<tr>
<th>Initial:</th>
<td>8</td>
</tr>
<tr>
<th>Applies to:</th>
<td>block containers</td>
</tr>
<tr>
<th>Inherited:</th>
<td>yes</td>
</tr>
<tr>
<th>Percentages:</th>
<td>N/A</td>
</tr>
<tr>
<th>Media:</th>
<td>visual</td>
</tr>
<tr>
<th>Computed&#160;value:</th>
<td>specified value</td>
</tr>
</tbody>
</table>
<p>This property determines the measure of the tab character (U+0009)
when rendered. Integers represent the measure in space characters (U+0020).
Negative integers are not allowed.
<h3 id="white-space-rules">
The White Space Processing Rules</h3>
<p>White space processing affects only spaces (U+0020), tabs (U+0009),
and (<a href="#segment-normalization">post-normalization</a>)
line feeds (U+00A0).
<p>For each inline (including anonymous inlines) within an inline
formatting context, white space characters are handled as follows,
ignoring bidi formatting characters as if they were not there:</p>
<ul>
<li id="collapse"><p>If 'text-space-collapse'
is set to ''collapse'' or ''preserve-breaks'', white space characters
are considered <dfn>collapsible</dfn> and are processed by
performing the following steps:</p>
<ol>
<li>All spaces and tabs immediately preceding or following a line
feed character are removed.</li>
<li>If 'text-space-collapse' is not
''preserve-breaks'', line feed characters are transformed for
rendering according to the <a href="#line-break-transform">line
feed transformation rules</a>.
</li>
<li>Every tab is converted to a space (U+0020).</li>
<li>Any space immediately following another collapsible space
&mdash;even one outside the boundary of the inline&mdash;is
removed.
However, if removing this space would eliminate a line breaking
opportunity in the text, that opportunity is still considered
to exist.</li>
<li>A collapsible space immediately preceding an element with
''consume-before'' is removed. Such removed spaces do not indicate
a line breaking opportunity in the text.
<li>Any collapsible spaces after the end of an element with
''consume-after'' are removed. Such removed spaces do not indicate
a line breaking opportunity in the text.
</ol>
</li>
<li><p>If 'text-space-collapse' is set to
''preserve'', any sequence of spaces unbroken by an element
boundary is treated as a sequence of non-breaking spaces. However,
a line breaking opportunity exists at the end of the sequence.</p></li>
<li><p>If 'text-space-collapse' is set to
''discard'', the first white space character in every white space
sequence is converted to a zero width non-joiner (U+200C) and
the rest of the sequence is removed.</p>
</ul>
<p>Then, the entire block is rendered. Inlines are laid out, taking bidi
reordering into account, and wrapping as specified by the
'text-wrap' property.</p>
<p>As each line is laid out,</p>
<ol>
<li>A sequence of collapsible spaces at the beginning of a line is
removed.
<li>Each tab is rendered as a horizontal shift that lines up
the start edge of the next glyph with the next tab stop.
Tab stops occur at points that are multiples of the width of a
space (U+0020) rendered in the block's font from the block's
starting content edge. How many spaces is given by the 'tab-size'
property.</li>
<li>A sequence of collapsible spaces at the end of a line is removed.
<li>If spaces or tabs at the end of a line are non-collapsible but
have 'text-wrap' set to 'normal' or 'avoid' the UA may visually
collapse their character advance widths.
</ol>
<p>White space that was not removed during the white space processing
steps is called <dfn>preserved</dfn> white space.</p>
<div class="example">
<h4 id="egbidiwscollapse">
Example of bidirectionality with white space collapsing</h4>
<p>Consider the following markup fragment, taking special note of spaces
(with varied backgrounds and borders for emphasis and identification):
</p>
<pre><code>&lt;ltr&gt;A<span class="egbidiwsaA">&#160;</span>&lt;rtl&gt;<span class="egbidiwsbB">&#160;</span>B<span class="egbidiwsaB">&#160;</span>&lt;/rtl&gt;<span class="egbidiwsbC">&#160;</span>C&lt;/ltr&gt;</code></pre>
<p>where the <code>&lt;ltr&gt;</code> element represents a left-to-right
embedding and the <code>&lt;rtl&gt;</code> element represents a
right-to-left embedding. If the 'text-space-collapse' property is set
to ''collapse'', the above processing model would result in the
following:</p>
<ul style="line-height:1.3">
<li>The space before the B (<span class="egbidiwsbB">&#160;</span>)
would collapse with the space after the A (<span
class="egbidiwsaA">&#160;</span>).</li>
<li>The space before the C (<span class="egbidiwsbC">&#160;</span>)
would collapse with the space after the B (<span
class="egbidiwsaB">&#160;</span>).</li>
</ul>
<p>This would leave two spaces, one after the A in the left-to-right
embedding level, and one after the B in the right-to-left embedding
level. This is then ordered according to the Unicode bidirectional
algorithm, with the end result being:</p>
<pre>A<span class="egbidiwsaA">&#160;</span><span class="egbidiwsaB">&#160;</span>BC</pre>
<p>Note that there are two spaces between A and B, and none between B
and C. This is best avoided by putting spaces outside the element
instead of just inside the opening and closing tags and, where
practical, by relying on implicit bidirectionality instead of explicit
embedding levels.</p>
</div>
<h4 id="line-break-transform">
Line Feed Transformation Rules</h4>
<p>When line feeds are <a href="#collapse">collapsible</a>, they are
either transformed into a space (U+0020) or removed depending on the
context before and after the line break.</p>
<p class="note">Note that the white space processing rules have already
removed any tabs and spaces after the line feed before these checks
take place.</p>
<ul>
<li>If the character immediately before or immediately after the line
feed is the zero width space character (U+200B), then the line feed
is removed.
<li>Otherwise, if the East Asian Width property [[!UAX11]] of both
the character before and after the line feed is F, W, or H (not A),
and neither side is Hangul,
then the line feed is removed.
<li>Otherwise, the line feed is converted to a space (U+0020).
</ul>
<p class="issue">Comments on how well this would work in practice would
be very much appreciated, particularly from people who work with
Thai and similar scripts.</p>
<h4 id="white-space-summary">
Informative Summary of White Space Collapsing Effects</h4>
<ul>
<li>Consecutive white space collapses into a single space.
<li>A sequence of newlines and other white space between two
Chinese, Japanese, or Yi characters collapses into nothing.
<li>A zero width space before or after a white space sequence
containing a newline causes the entire sequence of white space
to collapse into a zero width space.
</ul>
<h3 id="white-space">
White Space and Text Wrapping Shorthand: the 'white-space' property</h3>
<table class="propdef">
<tbody>
<tr>
<th>Name:</th>
<td><dfn>white-space</dfn></td>
</tr>
<tr>
<th>Value:</th>
<td>normal | pre | nowrap | pre-wrap | pre-line</td>
</tr>
<tr>
<th>Initial:</th>
<td>not defined for shorthand properties</td>
</tr>
<tr>
<th>Applies to:</th>
<td>all elements</td>
</tr>
<tr>
<th>Inherited:</th>
<td>yes</td>
</tr>
<tr>
<th>Percentages:</th>
<td>N/A</td>
</tr>
<tr>
<th>Media:</th>
<td>visual</td>
</tr>
<tr>
<th>Computed&#160;value:</th>
<td>see individual properties</td>
</tr>
</tbody>
</table>
<p>The 'white-space' property is a shorthand for the
'text-space-collapse' and 'text-wrap' properties.
Not all combinations are represented.
Values have the following meanings:</p>
<dl>
<dt><dfn title="white-space:normal">''normal''</dfn></dt>
<dd>Sets 'text-space-collapse' to ''collapse'' and
'text-wrap' to ''normal''</dd>
<dt><dfn title="white-space:pre">''pre''</dfn></dt>
<dd>Sets 'text-space-collapse' to ''preserve'' and
'text-wrap' to ''none''</dd>
<dt><dfn title="white-space:nowrap">''nowrap''</dfn></dt>
<dd>Sets 'text-space-collapse' to ''collapse'' and
'text-wrap' to ''none''</dd>
<dt><dfn title="white-space:pre-wrap">''pre-wrap''</dfn></dt>
<dd>Sets 'text-space-collapse' to ''preserve'' and
'text-wrap' to ''normal''</dd>
<dt><dfn title="white-space:pre-line">''pre-line''</dfn></dt>
<dd>Sets 'text-space-collapse' to ''preserve-breaks'' and
'text-wrap' to ''normal''</dd>
</dl>
<p>The following informative table summarizes the behavior of various
'white-space' values:</p>
<table class="data">
<colgroup class="header"></colgroup>
<colgroup span=3></colgroup>
<thead>
<tr>
<th></th>
<th>New Lines</th>
<th>Spaces and Tabs</th>
<th>Text Wrapping</th>
</tr>
</thead>
<tbody>
<tr>
<th>normal</th>
<td>Collapse</td>
<td>Collapse</td>
<td>Wrap</td>
</tr>
<tr>
<th>pre</th>
<td>Preserve</td>
<td>Preserve</td>
<td>No wrap</td>
</tr>
<tr>
<th>nowrap</th>
<td>Collapse</td>
<td>Collapse</td>
<td>No wrap</td>
</tr>
<tr>
<th>pre-wrap</th>
<td>Preserve</td>
<td>Preserve</td>
<td>Wrap</td>
</tr>
<tr>
<th>pre-line</th>
<td>Preserve</td>
<td>Collapse</td>
<td>Wrap</td>
</tbody>
</table>
<h2 id="line-breaking">
Line Breaking and Word Boundaries</h2>
<p>In most writing systems, in the absence of hyphenation a line break occurs
only at word boundaries. Many writing systems use spaces or
punctuation to explicitly separate words, and line break opportunities
can be identified by these characters. Scripts such as Thai, Lao, and
Khmer, however, do not use spaces or punctuation to separate words.
Although the zero width space (U+200B) can be used as an explicit word
delimiter in these scripts, this practice is not common. As a result,
a lexical resource is needed to correctly identify break points in such
texts.
<p>In several other writing systems, (including Chinese, Japanese, Yi,
and sometimes also Korean) a line break opportunity is based on
character boundaries, not word boundaries. In these systems a line can break
anywhere <em>except</em> between certain character combinations.
Additionally the level of strictness in these restrictions can vary
with the typesetting style.</p>
<p>CSS does not fully define where line breaking opportunities occur,
however some controls are provided to distinguish common variations.
<p class="note">Further information on line breaking conventions can be
found in
[[JLREQ]] and [[JIS4051]] for Japanese,
[[ZHMARK]] for Chinese, and
in [[!UAX14]] for all scripts in Unicode.
<!-- The CSS Working Group notes that although UAX 14 contains a wealth of
information about line breaking conventions, a literal implementation
of its algorithm has been found to be inadequate in multiple situations. --></p>
<p class="issue">Any guidance for appropriate references here would be
much appreciated.</p>
<p class="issue">Information on line-breaking in the absence of dictionaries:
<a href="http://lists.w3.org/Archives/Public/www-style/2011Feb/0126.html">for Thai</a>
<p>Floated and absolutely-positioned elements do not introduce a line
breaking opportunity. The line breaking behavior of a replaced element
is equivalent to that of a Latin character.</p>
<p class="issue">It is not clear whether this section handles Southeast Asian
scripts well. Additionally, some guidance should be provided on how to
break or not break Southeast Asian in the absence of a dictionary.</p>
<h3 id="line-break">
Line Breaking Strictness: the 'line-break' property</h3>
<table class="propdef">
<tbody>
<tr>
<th>Name:</th>
<td><dfn>line-break</dfn></td>
</tr>
<tr>
<th>Value:</th>
<td>auto | loose | normal | strict</td>
</tr>
<tr>
<th>Initial:</th>
<td>auto</td>
</tr>
<tr>
<th>Applies to:</th>
<td>all elements</td>
</tr>
<tr>
<th>Inherited:</th>
<td>yes</td>
</tr>
<tr>
<th>Percentages:</th>
<td>N/A</td>
</tr>
<tr>
<th>Media:</th>
<td>visual</td>
</tr>
<tr>
<th>Computed&#160;value:</th>
<td>specified value</td>
</tr>
</tbody>
</table>
<p>This property specifies the strictness of line-breaking rules applied
within an element: particularly how line-breaking interacts with
punctuation. Values have the following meanings:</p>
<dl>
<dt><dfn title="line-break:auto">''auto''</dfn></dt>
<dd>The UA determines the set of line-breaking restrictions to use,
and it may vary the restrictions based on the length of the line; e.g.,
use a less restrictive set of line-break rules for short lines.</dd>
<dt><dfn title="line-break:loose">''loose''</dfn></dt>
<dd>Breaks text using the least restrictive set of line-breaking
rules. Typically used for short lines, such as in newspapers.</dd>
<dt><dfn title="line-break:normal">''normal''</dfn></dt>
<dd>Breaks text using the most common set of line-breaking rules.</dd>
<dt><dfn title="line-break:strict">''strict''</dfn></dt>
<dd>Breaks text using the most stringent set of line-breaking
rules.</dd>
</dl>
<p>CSS distinguishes between three levels of strictness in the rules for
implicit line breaking. The precise set of rules in effect for each
level is up to the UA and should follow language conventions. However,
this specification does recommend that:</p>
<ul>
<li>Following breaks be forbidden in ''strict'' line breaking and
allowed in ''normal'' and ''loose'':
<ul>
<li>breaks before Japanese <a href="#small-kana">small kana</a>
<li>breaks before the Katakana-Hiragana prolonged sound mark:
&#x30FC;&nbsp;U+30FC
</ul>
If the language is known to be Chinese or Japanese, then additionally:
<ul>
<li>breaks before before hyphens:<br>
&#x2010;&nbsp;U+2010, &#x2013;&nbsp;U+2013, &#x301C;&nbsp;U+301C,
&#x30A0;&nbsp;U+30A0
</ul>
<li>Following breaks be forbidden in ''normal'' and ''strict'' line
breaking and allowed in ''loose'':
<ul>
<li>breaks before iteration marks:<br>
&#x3005;&nbsp;U+3005, &#x303B;&nbsp;U+303B, &#x309D;&nbsp;U+309D,
&#x309E;&nbsp;U+309E, &#x30FD;&nbsp;U+30FD, &#x30FE;&nbsp;U+30FE
<li>breaks between some inseparable characters:<br>
&#x2025;&nbsp;U+2025, &#x2026;&nbsp;U+2026
</ul>
If the language is known to be Chinese or Japanese, then additionally:
<ul>
<li>breaks before certain centered punctuation marks:<br>
&#x003A;&nbsp;U+003A, &#x003B;&nbsp;U+003B, &#x30FB;&nbsp;U+30FB,
&#xFF1A;&nbsp;U+FF1A, &#xFF1B;&nbsp;U+FF1B, &#xFF65;&nbsp;U+FF65,
&#x0021;&nbsp;U+0021, &#x003F;&nbsp;U+003F, &#x203C;&nbsp;U+203C,
&#x2047;&nbsp;U+2047, &#x2048;&nbsp;U+2048, &#x2049;&nbsp;U+2049,
&#xFF01;&nbsp;U+FF01, &#xFF1F;&nbsp;U+FF1F
<li>breaks before postfixes:<br>
&#x0025;&nbsp;U+0025, &#x00A2;&nbsp;U+00A2, &#x00B0;&nbsp;U+00B0,
&#x2030;&nbsp;U+2030, &#x2032;&nbsp;U+2032, &#x2033;&nbsp;U+2033,
&#x2103;&nbsp;U+2103, &#xFF05;&nbsp;U+FF05, &#xFFE0;&nbsp;U+FFE0
<li>breaks after prefixes:<br>
&#x0024;&nbsp;U+0024, &#x00A3;&nbsp;U+00A3, &#x00A5;&nbsp;U+00A5,
&#x20AC;&nbsp;U+20AC, &#x2116;&nbsp;U+2116, &#xFF04;&nbsp;U+FF04,
&#xFFE1;&nbsp;U+FFE1, &#xFFE5;&nbsp;U+FFE5
</ul>
</ul>
<p class="note">In CSS3 no distinction is made among the levels of
strictness in non-CJK text: only CJK codepoints are affected, unless
the text is marked as Chinese or Japanese, in which case some additional
common codepoints are affected. However a future level of CSS may add
behaviors affecting non-CJK text.
<p>Support for this property is <em>optional</em>. It is recommended
for UAs that wish to support CJK typography and strongly recommended
for UAs in the Japanese market.</p>
<p class="note">The CSSWG recognizes that in a future edition of the
specification finer control over line breaking may be necessary to
satisfy high-end publishing requirements.
<h3 id="word-break">
Word Breaking Rules: the 'word-break' property</h3>
<table class="propdef">
<tbody>
<tr>
<th>Name:</th>
<td><dfn>word-break</dfn></td>
</tr>
<tr>
<th>Value:</th>
<td>normal | keep-all | break-all</td>
</tr>
<tr>
<th>Initial:</th>
<td>normal</td>
</tr>
<tr>
<th>Applies to:</th>
<td>all elements</td>
</tr>
<tr>
<th>Inherited:</th>
<td>yes</td>