Skip to content

Commit 688cc1a

Browse files
author
litherum
committed
[css-fonts-4] Port over more @font-face descriptors from level 3
1 parent 11f3c41 commit 688cc1a

File tree

1 file changed

+345
-1
lines changed

1 file changed

+345
-1
lines changed

css-fonts-4/Overview.bs

Lines changed: 345 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ Using CSS font matching rules,
12611261
a user agent can selectively download
12621262
only those faces that are needed for a given piece of text.
12631263

1264-
It's syntax is:
1264+
Its syntax is:
12651265

12661266
<pre class=prod>
12671267
@font-face {
@@ -1707,6 +1707,350 @@ as well as the values supported by the font file itself.
17071707
to select a particular face within a font family.
17081708
</div>
17091709

1710+
<h3 id="unicode-range-desc">
1711+
Character range: the 'unicode-range' descriptor</h3>
1712+
1713+
<pre class='descdef'>
1714+
Name: unicode-range
1715+
Value: <<urange>> #
1716+
Initial: U+0-10FFFF
1717+
For: @font-face
1718+
</pre>
1719+
1720+
This descriptor defines the set of Unicode codepoints that may be
1721+
supported by the font face for which it is declared. The descriptor
1722+
value is a comma-delimited list of Unicode range (<<urange>>)
1723+
values. The union of these ranges defines the set of codepoints that
1724+
serves as a hint for user agents when deciding whether or not to
1725+
download a font resource for a given text run.
1726+
1727+
Each <<urange>> value is a
1728+
<a href="https://www.w3.org/TR/CSS21/syndata.html#tokenization"><code title="UNICODE-RANGE token">UNICODE-RANGE</code></a>
1729+
token made up of a "U+" or "u+" prefix
1730+
followed by a codepoint range in one of the three forms listed below.
1731+
Ranges that do not fit one of the these forms are invalid
1732+
and cause the declaration to be ignored.
1733+
1734+
<dl>
1735+
<dt>single codepoint (e.g. U+416)</dt>
1736+
<dd>a Unicode codepoint, represented as one to six hexadecimal digits</dd>
1737+
<dt>interval range (e.g. U+400-4ff)</dt>
1738+
<dd>represented as two hyphen-separated Unicode codepoints
1739+
indicating the inclusive start and end codepoints of a range</dd>
1740+
<dt>wildcard range (e.g. U+4??)</dt>
1741+
<dd>defined by the set of codepoints implied when
1742+
trailing '?' characters signify any hexadeximal digit</dd>
1743+
</dl>
1744+
1745+
Individual codepoints are written using hexadecimal values that correspond to
1746+
<a href="https://www.unicode.org/charts/">Unicode character codepoints</a>.
1747+
Unicode codepoint values must be between 0 and 10FFFF inclusive. Digit
1748+
values of codepoints are ASCII case-insensitive. For interval ranges,
1749+
the start and end codepoints must be within the range noted above and
1750+
the end codepoint must be greater than or equal to the start
1751+
codepoint.
1752+
1753+
Wildcard ranges specified with ‘?’ that lack an
1754+
initial digit (e.g. "U+???") are valid and equivalent
1755+
to a wildcard range with an initial zero digit (e.g. "U+0???" = "U+0000-0FFF").
1756+
Wildcard ranges that extend beyond the range of
1757+
Unicode codepoints are invalid. Because of this, the maximum
1758+
number of trailing '?' wildcard characters is five, even though the
1759+
<a href="https://www.w3.org/TR/CSS21/syndata.html#tokenization"><code title="UNICODE-RANGE token">UNICODE-RANGE</code></a>
1760+
token accepts six.
1761+
1762+
Within the comma-delimited list of Unicode ranges in a
1763+
'unicode-range' descriptor declaration, ranges may overlap. The union
1764+
of these ranges defines the set of codepoints for which the
1765+
corresponding font may be used. User agents must not download or use
1766+
the font for codepoints outside this set. User agents may normalize
1767+
the list of ranges into a list that is different but represents the
1768+
same set of codepoints.
1769+
1770+
The associated font might not contain glyphs for the entire set of
1771+
codepoints defined by the 'unicode-range' descriptor. When the font
1772+
is used, the <dfn>effective character map</dfn> is the intersection of the
1773+
codepoints defined by 'unicode-range' with the font's <em>character map</em>.
1774+
This allows authors to define supported ranges in terms of broad
1775+
ranges without worrying about the precise codepoint ranges supported
1776+
by the underlying font.
1777+
1778+
<h4 id="composite-fonts">Using character ranges to define composite fonts</h4>
1779+
1780+
Multiple <code>@font-face</code> rules with different unicode ranges for the same
1781+
family and style descriptor values can be used to create composite fonts
1782+
that mix the glyphs from different fonts for different scripts. This
1783+
can be used to combine fonts that only contain glyphs for a single
1784+
script (e.g. Latin, Greek, Cyrillic) or it can be used by authors as a
1785+
way of segmenting a font into fonts for commonly used characters and
1786+
less frequently used characters. Since the user agent will only pull
1787+
down the fonts it needs this helps reduce page bandwidth.
1788+
1789+
If the unicode ranges overlap for a set of <code>@font-face</code> rules with the
1790+
same family and style descriptor values, the rules are ordered in the
1791+
reverse order they were defined; the last rule defined is the first to
1792+
be checked for a given character.
1793+
1794+
Example ranges for specific languages or characters:
1795+
1796+
<dl>
1797+
<dt>unicode-range: U+A5;</dt>
1798+
<dd>a single code point, the yen/yuan symbol</dd>
1799+
1800+
<dt>unicode-range: U+0-7F;</dt>
1801+
<dd>code range for basic ASCII characters</dd>
1802+
1803+
<dt>unicode-range: U+590-5ff;</dt>
1804+
<dd>code range for Hebrew characters</dd>
1805+
1806+
<dt>unicode-range: U+A5, U+4E00-9FFF, U+30??, U+FF00-FF9F;</dt>
1807+
<dd>code range for Japanese kanji, hiragana and katakana characters plus yen/yuan symbol</dd>
1808+
</dl>
1809+
1810+
<div class="example">
1811+
The BBC provides news services in a wide variety of languages, many
1812+
that are not well supported across all platforms. Using an <code>@font-face</code>
1813+
rule, the BBC could provide a font for any of these languages, as it
1814+
already does via a manual font download.</p>
1815+
<pre>
1816+
@font-face {
1817+
font-family: BBCBengali;
1818+
src: url(fonts/BBCBengali.woff) format("woff");
1819+
unicode-range: U+00-FF, U+980-9FF;
1820+
}
1821+
</pre>
1822+
</div>
1823+
1824+
<div class="example">
1825+
Technical documents often require a wide range of symbols. The STIX
1826+
Fonts project is one project aimed at providing fonts to support a wide
1827+
range of technical typesetting in a standardized way. The example below
1828+
shows the use of a font that provides glyphs for many of the
1829+
mathematical and technical symbol ranges within Unicode:
1830+
<pre>
1831+
@font-face {
1832+
font-family: STIXGeneral;
1833+
src: local(STIXGeneral), url(/stixfonts/STIXGeneral.otf);
1834+
unicode-range: U+000-49F, U+2000-27FF, U+2900-2BFF, U+1D400-1D7FF;
1835+
}
1836+
</pre>
1837+
</div>
1838+
1839+
<div class="example">
1840+
This example shows how an author can override the glyphs used for
1841+
Latin characters in a Japanese font with glyphs from a different font.
1842+
The first rule specifies no range so it defaults to the entire range.
1843+
The range specified in the second rule overlaps but takes precedence
1844+
because it is defined later.
1845+
1846+
<pre>
1847+
@font-face {
1848+
font-family: JapaneseWithGentium;
1849+
src: local(MSMincho);
1850+
/* no range specified, defaults to entire range */
1851+
}
1852+
1853+
@font-face {
1854+
font-family: JapaneseWithGentium;
1855+
src: url(../fonts/Gentium.woff);
1856+
unicode-range: U+0-2FF;
1857+
}
1858+
</pre>
1859+
</div>
1860+
1861+
<div class="example">
1862+
Consider a family constructed to optimize bandwidth by separating out
1863+
Latin, Japanese and other characters into different font files:
1864+
1865+
<pre>
1866+
/* fallback font - size: 4.5MB */
1867+
@font-face {
1868+
font-family: DroidSans;
1869+
src: url(DroidSansFallback.woff);
1870+
/* no range specified, defaults to entire range */
1871+
}
1872+
1873+
/* Japanese glyphs - size: 1.2MB */
1874+
@font-face {
1875+
font-family: DroidSans;
1876+
src: url(DroidSansJapanese.woff);
1877+
unicode-range: U+3000-9FFF, U+ff??;
1878+
}
1879+
1880+
/* Latin, Greek, Cyrillic along with some
1881+
punctuation and symbols - size: 190KB */
1882+
@font-face {
1883+
font-family: DroidSans;
1884+
src: url(DroidSans.woff);
1885+
unicode-range: U+000-5FF, U+1e00-1fff, U+2000-2300;
1886+
}
1887+
</pre>
1888+
1889+
For simple Latin text, only the font for Latin characters is downloaded:
1890+
1891+
<pre>
1892+
body { font-family: DroidSans; }
1893+
1894+
&lt;p>This is that&lt;/p>
1895+
</pre>
1896+
1897+
In this case the user agent first checks the unicode-range for the
1898+
font containing Latin characters (DroidSans.woff). Since all the
1899+
characters above are in the range U+0-5FF, the user agent downloads the
1900+
font and renders the text with that font.
1901+
1902+
Next, consider text that makes use of an arrow character (&#x21e8;):
1903+
1904+
<pre>
1905+
&lt;p>This &amp;#x21e8; that&lt;p>
1906+
</pre>
1907+
1908+
The user agent again first checks the unicode-range of the font
1909+
containing Latin characters. Since U+2000-2300 includes the arrow
1910+
code point (U+21E8), the user agent downloads the font. For this
1911+
character however the Latin font does not have a matching glyph, so the
1912+
effective unicode-range used for font matching excludes this code point.
1913+
Next, the user agent evaluates the Japanese font. The unicode-range for
1914+
the Japanese font, U+3000-9FFF and U+ff??, does not include U+21E8, so
1915+
the user agent does not download the Japanese font.
1916+
Next the fallback font is considered. The <code>@font-face</code> rule for the
1917+
fallback font does not define unicode-range so its value defaults to
1918+
the range of all Unicode code points. The fallback font is downloaded and
1919+
used to render the arrow character.
1920+
1921+
</div>
1922+
1923+
<h3 id="font-rend-desc">
1924+
Font features: the 'font-variant' and 'font-feature-settings' descriptors</h3>
1925+
1926+
<pre class='descdef'>
1927+
Name: font-variant
1928+
Value: normal | none | [ <<common-lig-values>> || <<discretionary-lig-values>> || <<historical-lig-values>> ||
1929+
<<contextual-alt-values>> || <var title="stylistic">stylistic(<<feature-value-name>>)</var> || <var>historical-forms</var> ||
1930+
<var>styleset(<<feature-value-name>> #)</var> ||
1931+
<var>character-variant(<<feature-value-name>> #)</var> ||
1932+
<var>swash(<<feature-value-name>>)</var> || <var>ornaments(<<feature-value-name>>)</var> ||
1933+
<var>annotation(<<feature-value-name>>)</var> ||
1934+
[ <i>small-caps</i> | <i>all-small-caps</i> | <i>petite-caps</i> | <i>all-petite-caps</i> | <i>unicase</i> | <i>titling-caps</i> ] ||
1935+
<<numeric-figure-values>> || <<numeric-spacing-values>> || <<numeric-fraction-values>> || <i>ordinal</i> || <i>slashed-zero</i> ||
1936+
<<east-asian-variant-values>> || <<east-asian-width-values>> || <i>ruby</i> ||
1937+
[ <i>sub</i> | <i>super</i> ] ]
1938+
Initial: normal
1939+
For: @font-face
1940+
</pre>
1941+
1942+
<pre class='descdef'>
1943+
Name: font-feature-settings
1944+
Value: normal | <<feature-tag-value>> #
1945+
Initial: normal
1946+
For: @font-face
1947+
</pre>
1948+
1949+
These descriptors define initial settings that apply when the font defined by
1950+
an <code>@font-face</code> rule is rendered. They do not affect font selection.
1951+
Values are identical to those defined for the corresponding
1952+
'font-variant' and 'font-feature-settings' properties defined below
1953+
except that the value 'inherit' is omitted. When multiple font
1954+
feature descriptors or properties are used, the cumulative effect on
1955+
text rendering is detailed in the section
1956+
<a href="#font-feature-resolution">Font Feature Resolution</a> below.
1957+
In cases where specific values define synthesized fallback for certain
1958+
'font-variant' subproperties, the same synthesized fallback
1959+
applies when used within those values are used with the
1960+
'font-variant' descriptor.
1961+
1962+
<h4 id="font-face-loading">Font loading guidelines</h4>
1963+
1964+
The <code>@font-face</code> rule is designed to allow lazy loading
1965+
of font resources that are only downloaded when used within a
1966+
document. A stylesheet can include <code>@font-face</code> rules for
1967+
a library of fonts of which only a select set are used; user agents
1968+
must only download those fonts that are referred to within the style
1969+
rules applicable to a given page. User agents that download all fonts
1970+
defined in <code>@font-face</code> rules without considering whether
1971+
those fonts are in fact used within a page are considered
1972+
non-conformant. In cases where a font might be downloaded in character
1973+
fallback cases, user agents may download a font if it's contained within
1974+
the computed value of <span title="font-family!!property">'font-family'</span>
1975+
for a given text run.
1976+
1977+
<pre>
1978+
@font-face {
1979+
font-family: GeometricModern;
1980+
src: url(font.woff);
1981+
}
1982+
1983+
p {
1984+
/* font will be downloaded for pages with p elements */
1985+
font-family: GeometricModern, sans-serif;
1986+
}
1987+
1988+
h2 {
1989+
/* font may be downloaded for pages with h2 elements, even if Futura is available locally */
1990+
font-family: Futura, GeometricModern, sans-serif;
1991+
}
1992+
</pre>
1993+
1994+
In cases where textual content is loaded before downloadable fonts
1995+
are available, user agents may render text as it would be rendered if
1996+
downloadable font resources are not available or they may render text
1997+
transparently with fallback fonts to avoid a flash of text using a
1998+
fallback font. In cases where the font download fails user agents must
1999+
display text, simply leaving transparent text is considered
2000+
non-conformant behavior. Authors are advised to use fallback fonts in
2001+
their font lists that closely match the metrics of the
2002+
downloadable fonts to avoid large page reflows where possible.
2003+
2004+
<a id="same-origin-restriction">
2005+
<a id="allowing-cross-origin-font-loading">
2006+
<h4 id="font-fetching-requirements">Font fetching requirements</h4>
2007+
2008+
For font loads, user agents must use the
2009+
<a href="https://www.w3.org/TR/html5/infrastructure.html#cors-enabled-fetch">potentially CORS-enabled fetch</a>
2010+
method defined by the [[!HTML5]] specification for URL's defined
2011+
within @font-face rules. When fetching, user agents must use
2012+
"Anonymous" mode, set the referrer source to the stylesheet's URL and
2013+
set the origin to the URL of the containing document.
2014+
2015+
Note: The implications of this for authors are that fonts
2016+
will typically not be loaded cross-origin unless authors specifically
2017+
takes steps to permit cross-origin loads. Sites can explicitly allow
2018+
cross-site loading of font data using the <code>Access-Control-Allow-Origin</code>
2019+
HTTP header. For other schemes, no explicit mechanism to allow
2020+
cross-origin loading, beyond what is permitted by the
2021+
<a href="https://www.w3.org/TR/html5/infrastructure.html#cors-enabled-fetch">potentially CORS-enabled fetch</a>
2022+
method, is defined or required.
2023+
2024+
<div class="example">
2025+
For the examples given below, assume that a document is located at
2026+
<code>https://example.com/page.html</code> and all URL's link to valid
2027+
font resources supported by the user agent.
2028+
2029+
Fonts defined with the 'src' descriptor values below will be loaded:
2030+
2031+
<pre>/* same origin (i.e. domain, scheme, port match document) */
2032+
src: url(fonts/simple.woff);
2033+
2034+
/* data url's with no redirects are treated as same origin */
2035+
src: url("data:application/font-woff;base64,...");
2036+
2037+
/* cross origin, different domain */
2038+
/* Access-Control-Allow-Origin response header set to '*' */
2039+
src: url(http://another.example.com/fonts/simple.woff);
2040+
</pre>
2041+
2042+
Fonts defined with the 'src' descriptor values below will fail to load:
2043+
2044+
<pre>/* cross origin, different scheme */
2045+
/* no Access-Control-xxx headers in response */
2046+
src: url(https://example.com/fonts/simple.woff);
2047+
2048+
/* cross origin, different domain */
2049+
/* no Access-Control-xxx headers in response */
2050+
src: url(http://another.example.com/fonts/simple.woff);
2051+
</pre>
2052+
</div>
2053+
17102054
<h3 id="font-display-desc">
17112055
Controlling Font Display Per Font-Face: the 'font-display' descriptor</h3>
17122056

0 commit comments

Comments
 (0)