8000 csswg-drafts/css-font-loading/Overview.html at 0c757c77f66775c9afeffb2478de44130f9b0d7f · w3c/csswg-drafts · GitHub
Skip to content

Latest commit

 

History

History
1106 lines (890 loc) · 91.3 KB

File metadata and controls

1106 lines (890 loc) · 91.3 KB
<!DOCTYPE html><html lang=en><head>
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
<title>CSS Font Loading Module Level 3</title>
<link href=../default.css rel=stylesheet type=text/css>
<link href=../csslogo.ico rel="shortcut icon" type=image/x-icon>
<link href=https://www.w3.org/StyleSheets/TR/W3C-FPWD rel=stylesheet type=text/css>
</head>
<body class=h-entry>
<div class=head>
<p data-fill-with=logo><a class=logo href=http://www.w3.org/>
<img alt=W3C height=48 src=http://www.w3.org/Icons/w3c_home width=72>
</a>
</p>
<h1 class="p-name no-ref" id=title>CSS Font Loading Module Level 3</h1>
<h2 class="no-num no-toc no-ref heading settled heading" id=subtitle><span class=content>W3C First Public Working Draft,
<span class=dt-updated><span class=value-title title=20140214>14 February 2014</span></span></span></h2>
<div data-fill-with=spec-metadata><dl><dt>This version:<dd><a class=u-url href=http://www.w3.org/TR/2014/FPWD-css-font-loading-3-20140214/>http://www.w3.org/TR/2014/FPWD-css-font-loading-3-20140214/</a><dt>Latest version:<dd><a href=http://w3.org/TR/css-font-loading/>http://w3.org/TR/css-font-loading/</a><dt>Editor’s Draft:<dd><a href=http://dev.w3.org/csswg/css-font-loading/>http://dev.w3.org/csswg/css-font-loading/</a>
<dt>Feedback:</dt>
<dd><a href="mailto:www-style@w3.org?subject=%5Bcss-font-loading%5D%20feedback">www-style@w3.org</a>
with subject line
“<kbd>[css-font-loading] <var>… message topic …</var></kbd>”(<a href=http://lists.w3.org/Archives/Public/www-style/ rel=discussion>archives</a>)<dt>Test Suite:<dd>None Yet<dt>Editors:
<dd class="p-author h-card vcard"><a class="p-name fn u-url url" href=http://xanthir.com/contact/>Tab Atkins Jr.</a> (<span class="p-org org">Google</span>)<dt>Former Editors:
<dd class="p-author h-card vcard"><a class="p-name fn u-email email" href=mailto:jdaggett@mozilla.com>John Daggett</a> (<span class="p-org org">Mozilla</span>)</dl></div>
<div data-fill-with=warning></div>
<p class=copyright data-fill-with=copyright><a href=http://www.w3.org/Consortium/Legal/ipr-notice#Copyright>Copyright</a> © 2014 <a href=http://www.w3.org/><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a href=http://www.csail.mit.edu/><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>, <a href=http://www.ercim.eu/><abbr title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>, <a href=http://www.keio.ac.jp/>Keio</a>, <a href=http://ev.buaa.edu.cn/>Beihang</a>), All Rights Reserved. W3C <a href=http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer>liability</a>, <a href=http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks>trademark</a> and <a href=http://www.w3.org/Consortium/Legal/copyright-documents>document use</a> rules apply.
</p>
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc no-ref heading settled heading" id=abstract><span class=content>Abstract</span></h2>
<p class=p-summary data-fill-with=abs 7292 tract>This CSS module describes events and interfaces used for dynamically loading font resources.
<a href=http://www.w3.org/TR/CSS/>CSS</a> is a language for describing the rendering of structured documents
(such as HTML and XML)
on screen, on paper, in speech, etc.</p>
<h2 class="no-num no-toc no-ref heading settled heading" id=status><span class=content>Status of this document</span></h2>
<div data-fill-with=status><p><em>This section describes the status of this document at the time of
its publication. Other documents may supersede this document. A list of
current W3C publications and the latest revision of this technical report
can be found in the <a href=http://www.w3.org/TR/>W3C technical reports
index at http://www.w3.org/TR/.</a></em>
<p>This document is a <b>First Public Working Draft</b>.
<p>Publication as a First Public Working Draft does not imply endorsement by the W3C
Membership. This is a draft document and may be updated, replaced or
obsoleted by other documents at any time. It is inappropriate to cite this
document as other than work in progress.
<p>The (<a href=http://lists.w3.org/Archives/Public/www-style/>archived</a>) public
mailing list <a href=mailto:www-style@w3.org>www-style@w3.org</a> (see
<a href=http://www.w3.org/Mail/Request>instructions</a>) is preferred
for discussion of this specification. When sending e-mail, please put the
text “css-font-loading” in the subject, preferably like this:
“[css-font-loading] <em>…summary of comment…</em>”
<p>This document was produced by the <a href=http://www.w3.org/Style/CSS/members>CSS Working Group</a> (part of
the <a href=http://www.w3.org/Style/>Style Activity</a>).
<p>This document was produced by a group operating under the <a href=http://www.w3.org/Consortium/Patent-Policy-20040205/>5 February
2004 W3C Patent Policy</a>. W3C maintains a <a href=http://www.w3.org/2004/01/pp-impl/32061/status rel=disclosure>public list of any patent disclosures</a> made in
connection with the deliverables of the group; that page also includes
instructions for disclosing a patent. An individual who has actual
knowledge of a patent which the individual believes contains <a href=http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential>Essential
Claim(s)</a> must disclose the information in accordance with <a href=http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure>section
6 of the W3C Patent Policy</a>.</p>
</div>
<div data-fill-with=at-risk></div>
<h2 class="no-num no-toc no-ref heading settled heading" id=contents><span class=content>Table of Contents</span></h2>
<div data-fill-with=table-of-contents><ul class=toc><li><a href=#introduction><span class=secno>1</span>
Introduction</a><li><a href=#fontface-interface><span class=secno>2</span>
The <code>FontFace</code> Interface</a><ul class=toc><li><a href=#font-face-constructor><span class=secno>2.1</span>
The Constructor</a><li><a href=#font-face-load><span class=secno>2.2</span>
The <code>load()</code> method</a><li><a href=#font-face-ready><span class=secno>2.3</span>
The <code>ready()</code> method</a><li><a href=#font-face-css-connection><span class=secno>2.4</span>
Interaction with CSS’s <span class=css data-link-type=maybe title=@font-face>@font-face</span> Rule</a></ul><li><a href=#FontFaceSet-interface><span class=secno>3</span>
The <code>FontFaceSet</code> Interface</a><ul class=toc><li><a href=#set-modifications><span class=secno>3.1</span>
Modifications of normal Set methods</a><li><a href=#FontFaceSet-events><span class=secno>3.2</span>
Events</a><li><a href=#font-face-set-load><span class=secno>3.3</span>
The <code>load()</code> method</a><li><a href=#font-face-set-check><span class=secno>3.4</span>
The <code>check()</code> method</a><li><a href=#font-face-set-ready><span class=secno>3.5</span>
The <code>ready()</code> method</a><li><a href=#font-face-set-css><span class=secno>3.6</span>
Interaction with CSS Font Loading and Matching</a></ul><li><a href=#font-face-source><span class=secno>4</span>
The <code>FontFaceSource</code> interface</a><ul class=toc><li><a href=#document-font-face-set><span class=secno>4.1</span>
Interaction with CSS’s <span class=css data-link-type=maybe title=@font-face>@font-face</span> Rule</a></ul><li><a href=#font-load-event-examples><span class=secno>5</span>
API Examples</a><li><a href=#changes><span class=secno></span>Changes</a><ul class=toc><li><a href=#changes-since-20130212><span class=secno></span>
Changes from the <span>February 2013 CSS3 Fonts Working Draft</span></a></ul><li><a href=#acknowledgments><span class=secno></span>
Acknowledgments</a><li><a href=#conformance><span class=secno></span>
Conformance</a><ul class=toc><li><a href=#conventions><span class=secno></span>
Document conventions</a><li><a href=#conformance-classes><span class=secno></span>
Conformance classes</a><li><a href=#partial><span class=secno></span>
Partial implementations</a><li><a href=#experimental><span class=secno></span>
Experimental implementations</a><li><a href=#testing><span class=secno></span>
Non-experimental implementations</a></ul><li><a href=#references><span class=secno></span>
References</a><ul class=toc><li><a href=#normative><span class=secno></span>
Normative References</a><li><a href=#informative><span class=secno></span>
Informative References</a></ul><li><a href=#index><span class=secno></span>
Index</a><li><a href=#property-index><span class=secno></span>
Property index</a><li><a href=#issues-index><span class=secno></span>Issues Index</a></ul></div>
<h2 class="heading settled heading" data-level=1 id=introduction><span class=secno>1 </span><span class=content>
Introduction</span><a class=self-link href=#introduction></a></h2>
<p> CSS allows authors to load custom fonts from the web via the <a class=css data-link-type=maybe href=http://www.w3.org/TR/css-fonts-3/#at-font-face-rule title=@font-face>@font-face</a> rule.
While this is easy to use when authoring a stylesheet,
it’s much more difficult to use dynamically via scripting.
<p> Further, CSS allows the user agent to choose when to actually load a font;
if a font face isn’t <em>currently</em> used by anything on a page,
most user agents will not download its associated file.
This means that later use of the font face will incur a delay
as the user agent finally notices a usage and begins downloading and parsing the font file.
<p> This specification defines a scripting interface to font faces in CSS,
allowing font faces to be easily created and loaded from script.
It also provides methods to track the loading status of an individual font,
or of all the fonts on an entire page.
<h2 class="heading settled heading" data-level=2 id=fontface-interface><span class=secno>2 </span><span class=content>
The <code>FontFace</code> Interface</span><a class=self-link href=#fontface-interface></a></h2>
<p> The <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> interface represents a single usable font face.
CSS <a class=css data-link-type=maybe href=http://www.w3.org/TR/css-fonts-3/#at-font-face-rule title=@font-face>@font-face</a> rules implicitly define FontFace objects,
or they can be constructed manually from a url or binary data.
<pre class=idl>typedef (<a data-link-type=idl href=http://www.khronos.org/registry/typedarray/specs/latest/#ArrayBuffer title=arraybuffer>ArrayBuffer</a> or <a data-link-type=idl href=http://www.khronos.org/registry/typedarray/specs/latest/#ArrayBufferView title=arraybufferview>ArrayBufferView</a>) <a class=idl-code data-global-name="" data-link-type=typedef href=http://dev.w3.org/csswg/css-font-load-events-3/#typedefdef-binarydata title=binarydata>BinaryData</a>;
dictionary <a class=idl-code data-global-name="" data-link-type=dictionary href=http://dev.w3.org/csswg/css-font-load-events-3/#dictdef-fontfacedescriptors title=fontfacedescriptors>FontFaceDescriptors</a> {
DOMString <a class=idl-code data-global-name="FontFaceDescriptors<dictionary>/style<dict-member>" data-link-for=FontFaceDescriptors data-link-type=dict-member href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfacedescriptors-style title=style>style</a> = "normal";
DOMString <a class=idl-code data-global-name="FontFaceDescriptors<dictionary>/weight<dict-member>" data-link-for=FontFaceDescriptors data-link-type=dict-member href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfacedescriptors-weight title=weight>weight</a> = "normal";
DOMString <a class=idl-code data-global-name="FontFaceDescriptors<dictionary>/stretch<dict-member>" data-link-for=FontFaceDescriptors data-link-type=dict-member href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfacedescriptors-stretch title=stretch>stretch</a> = "normal";
DOMString <a class=idl-code data-global-name="FontFaceDescriptors<dictionary>/unicoderange<dict-member>" data-link-for=FontFaceDescriptors data-link-type=dict-member href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfacedescriptors-unicoderange title=unicoderange>unicodeRange</a> = "U+0-10FFFF";
DOMString <a class=idl-code data-global-name="FontFaceDescriptors<dictionary>/variant<dict-member>" data-link-for=FontFaceDescriptors data-link-type=dict-member href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfacedescriptors-variant title=variant>variant</a> = "normal";
DOMString <a class=idl-code data-global-name="FontFaceDescriptors<dictionary>/featuresettings<dict-member>" data-link-for=FontFaceDescriptors data-link-type=dict-member href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfacedescriptors-featuresettings title=featuresettings>featureSettings</a> = "normal";
};
enum <a class=idl-code data-global-name="" data-link-type=enum href=http://dev.w3.org/csswg/css-font-load-events-3/#enumdef-fontfaceloadstatus title=fontfaceloadstatus>FontFaceLoadStatus</a> { "unloaded", "loading", "loaded", "error" };
[Constructor(DOMString <a class=idl-code data-global-name="FontFace<interface>/FontFace()<method>/family<argument>" data-link-for=FontFace/FontFace() data-link-type=argument href=#dom-fontfacefontface-family title=family>family</a>, (DOMString or <a data-link-type=idl href=http://dev.w3.org/csswg/css-font-load-events-3/#typedefdef-binarydata title=binarydata>BinaryData</a>) <a class=idl-code data-global-name="FontFace<interface>/FontFace()<method>/source<argument>" data-link-for=FontFace/FontFace() data-link-type=argument href=#dom-fontfacefontface-source title=source>source</a>,
<a data-link-type=idl href=http://dev.w3.org/csswg/css-font-load-events-3/#dictdef-fontfacedescriptors title=fontfacedescriptors>FontFaceDescriptors</a> <a class=idl-code data-global-name="FontFace<interface>/FontFace()<method>/descriptors<argument>" data-link-for=FontFace/FontFace() data-link-type=argument href=#dom-fontfacefontface-descriptors title=descriptors>descriptors</a>)]
interface <a class=idl-code data-global-name="" data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> {
attribute DOMString <a class=idl-code data-global-name="FontFace<interface>/family<attribute>" data-link-for=FontFace data-link-type=attribute href=#dom-fontface-family title=family>family</a>;
attribute DOMString <a class=idl-code data-global-name="FontFace<interface>/style<attribute>" data-link-for=FontFace data-link-type=attribute href=#dom-fontface-style title=style>style</a>;
attribute DOMString <a class=idl-code data-global-name="FontFace<interface>/weight<attribute>" data-link-for=FontFace data-link-type=attribute href=#dom-fontface-weight title=weight>weight</a>;
attribute DOMString <a class=idl-code data-global-name="FontFace<interface>/stretch<attribute>" data-link-for=FontFace data-link-type=attribute href=#dom-fontface-stretch title=stretch>stretch</a>;
attribute DOMString <a class=idl-code data-global-name="FontFace<interface>/unicoderange<attribute>" data-link-for=FontFace data-link-type=attribute href=#dom-fontface-unicoderange title=unicoderange>unicodeRange</a>;
attribute DOMString <a class=idl-code data-global-name="FontFace<interface>/variant<attribute>" data-link-for=FontFace data-link-type=attribute href=#dom-fontface-variant title=variant>variant</a>;
attribute DOMString <a class=idl-code data-global-name="FontFace<interface>/featuresettings<attribute>" data-link-for=FontFace data-link-type=attribute href=#dom-fontface-featuresettings title=featuresettings>featureSettings</a>;
readonly attribute <a data-link-type=idl href=http://dev.w3.org/csswg/css-font-load-events-3/#enumdef-fontfaceloadstatus title=fontfaceloadstatus>FontFaceLoadStatus</a> <a class=idl-code data-global-name="FontFace<interface>/status<attribute>" data-link-for=FontFace data-link-type=attribute href=#dom-fontface-status title=status>status</a>;
// If the font face’s source is url-based and its status isn’t
// "loading" or "loaded", this kicks off the load.
void <a class=idl-code data-global-name="FontFace<interface>/load()<method>" data-link-for=FontFace data-link-type=method href=#dom-fontface-load title=load()>load</a>();
// Returns a promise that fulfills or rejects when the font face
// reached "loaded" or "error" status.
<a data-link-type=idl title=promise>Promise</a> <a class=idl-code data-global-name="FontFace<interface>/ready()<method>" data-link-for=FontFace data-link-type=method href=#dom-fontface-ready title=ready()>ready</a>();
};
</pre>
<dl data-dfn-for=FontFace data-dfn-type=attribute>
<dt><dfn class=idl-code data-dfn-for=FontFace data-dfn-type=attribute data-export="" id=dom-fontface-family>family<a class=self-link href=#dom-fontface-family></a></dfn>, of type <a class=idl-code data-link-type=interface title=domstring>DOMString</a>
<dt><dfn class=idl-code data-dfn-for=FontFace data-dfn-type=attribute data-export="" id=dom-fontface-style>style<a class=self-link href=#dom-fontface-style></a></dfn>, of type <a class=idl-code data-link-type=interface title=domstring>DOMString</a>
<dt><dfn class=idl-code data-dfn-for=FontFace data-dfn-type=attribute data-export="" id=dom-fontface-weight>weight<a class=self-link href=#dom-fontface-weight></a></dfn>, of type <a class=idl-code data-link-type=interface title=domstring>DOMString</a>
<dt><dfn class=idl-code data-dfn-for=FontFace data-dfn-type=attribute data-export="" id=dom-fontface-stretch>stretch<a class=self-link href=#dom-fontface-stretch></a></dfn>, of type <a class=idl-code data-link-type=interface title=domstring>DOMString</a>
<dt><dfn class=idl-code data-dfn-for=FontFace data-dfn-type=attribute data-export="" id=dom-fontface-unicoderange>unicodeRange<a class=self-link href=#dom-fontface-unicoderange></a></dfn>, of type <a class=idl-code data-link-type=interface title=domstring>DOMString</a>
<dd>
These attributes all represent the corresponding aspects of a font face,
as defined by the descriptors defined in the CSS <a class=css data-link-type=maybe href=http://www.w3.org/TR/css-fonts-3/#at-font-face-rule title=@font-face>@font-face</a> rule.
They are parsed the same as the corresponding <a class=css data-link-type=maybe href=http://www.w3.org/TR/css-fonts-3/#at-font-face-rule title=@font-face>@font-face</a> descriptors.
They are used by the font matching algorithm,
but otherwise have no effect.
<p> For example, a <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> with a <a class=idl-code data-link-type=attribute href=#dom-fontface-style title=style>style</a> of <code>"italic"</code>
<em>represents</em> an italic font face;
it does not <strong>make</strong> the font face italic.
<dt><dfn class=idl-code data-dfn-for=FontFace data-dfn-type=attribute data-export="" id=dom-fontface-variant>variant<a class=self-link href=#dom-fontface-variant></a></dfn>, of type <a class=idl-code data-link-type=interface title=domstring>DOMString</a>
<dt><dfn class=idl-code data-dfn-for=FontFace data-dfn-type=attribute data-export="" id=dom-fontface-featuresettings>featureSettings<a class=self-link href=#dom-fontface-featuresettings></a></dfn>, of type <a class=idl-code data-link-type=interface title=domstring>DOMString</a>
<dd>
These attributes have the same meaning,
and are parsed the same as,
the corresponding descriptors in the CSS <a class=css data-link-type=maybe href=http://www.w3.org/TR/css-fonts-3/#at-font-face-rule title=@font-face>@font-face</a> rules.
<p> They turn on or off specific features in fonts that support them.
Unlike the previous attributes,
these attributes actually affect the font face.
<dt><dfn class=idl-code data-dfn-for=FontFace data-dfn-type=attribute data-export="" id=dom-fontface-status>status<a class=self-link href=#dom-fontface-status></a></dfn>, of type <a class=idl-code data-link-type=enum href=http://dev.w3.org/csswg/css-font-load-events-3/#enumdef-fontfaceloadstatus title=fontfaceloadstatus>FontFaceLoadStatus</a>
<dd>
This attribute reflects the current status of the font face.
It must be "unloaded" for a newly-created <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a>.
<p> It can change due to an author explicitly requesting a font face to load,
such as through the <a class=idl-code data-link-for=FontFace data-link-type=method href=#dom-fontface-load title=load()>load()</a> method on <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a>,
or implicitly by the user agent,
due to it detecting that the font face is needed to draw some text on the screen.
</dl>
<p> All <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> objects contain an internal <dfn class=idl-code data-dfn-for=FontFace data-dfn-type=attribute data-export="" id=dom-fontface-fontstatuspromise>[FontStatusPromise]<a class=self-link href=#dom-fontface-fontstatuspromise></a></dfn> attribute,
which tracks the status of the font.
It starts out pending,
and fulfills or rejects when the font is successfully loaded and parsed, or hits an error.
<p> All <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> objects also contain
internal <dfn class=idl-code data-dfn-for=FontFace data-dfn-type=attribute data-export="" id=dom-fontface-urls>[Urls]<a class=self-link href=#dom-fontface-urls></a></dfn> and <dfn class=idl-code data-dfn-for=FontFace data-dfn-type=attribute data-export="" id=dom-fontface-data>[Data]<a class=self-link href=#dom-fontface-data></a></dfn> attributes,
of which one is not <code>null</code> and the rest are <code>null</code>.
<h3 class="heading settled heading" data-level=2.1 id=font-face-constructor><span class=secno>2.1 </span><span class=content>
The Constructor</span><a class=self-link href=#font-face-constructor></a></h3>
<p> A <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> can be constructed either
from a URL pointing to a font face file,
or from an ArrayBuffer (or ArrayBufferView) containing the binary representation of a font face.
<p> When the <dfn class=idl-code data-dfn-for=FontFace data-dfn-type=method data-export="" id=dom-fontface-fontface title=FontFace()>FontFace<a class=self-link href=#dom-fontface-fontface></a></dfn>(DOMString <dfn class=idl-code data-dfn-for=FontFace/FontFace() data-dfn-type=argument data-export="" id=dom-fontfacefontface-family>family<a class=self-link href=#dom-fontfacefontface-family></a></dfn>, (DOMString or <a data-link-type=idl href=http://dev.w3.org/csswg/css-font-load-events-3/#typedefdef-binarydata title=binarydata>BinaryData</a>) <dfn class=idl-code data-dfn-for=FontFace/FontFace() data-dfn-type=argument data-export="" id=dom-fontfacefontface-source>source<a class=self-link href=#dom-fontfacefontface-source></a></dfn>, <a data-link-type=idl href=http://dev.w3.org/csswg/css-font-load-events-3/#dictdef-fontfacedescriptors title=fontfacedescriptors>FontFaceDescriptors</a> <dfn class=idl-code data-dfn-for=FontFace/FontFace() data-dfn-type=argument data-export="" id=dom-fontfacefontface-descriptors>descriptors<a class=self-link href=#dom-fontfacefontface-descriptors></a></dfn>) method is called,
execute these steps:
<ol data-link-type=idl>
<li>
Let <var>font face</var> be a fresh <a data-link-type=idl href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> object.
Set <var>font face’s</var> <a data-link-for=FontFace data-link-type=idl href=#dom-fontface-status title=status>status</a> argument to <code>"unloaded"</code>.
Set its internal <a data-link-type=idl href=#dom-fontface-fontstatuspromise title=[fontstatuspromise]>[FontStatusPromise]</a> attribute to a newly-created promise object.
Return <var>font face</var>,
and complete the rest of these steps asynchronously.
<li>
Parse the <a class=idl-code data-link-type=argument href=#dom-fontfacefontface-family title=family>family</a> argument,
and the members of the <a class=idl-code data-link-for=FontFace() data-link-type=argument href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfacefontface-fontface-descriptors title=descriptors>descriptors</a> argument,
according to the grammars of the corresponding descriptors of the CSS <a class=css data-link-type=maybe href=http://www.w3.org/TR/css-fonts-3/#at-font-face-rule title=@font-face>@font-face</a> rule.
If any of them fail to parse correctly,
reject <var>font face’s</var> <a data-link-type=idl href=#dom-fontface-fontstatuspromise title=[fontstatuspromise]>[FontStatusPromise]</a> with a SyntaxError exception and abort these steps.
Otherwise, set <var>font face’s</var> corresponding attributes to the serialization of the parsed values.
<li>
If the <a data-link-type=idl href=#dom-fontfacefontface-source title=source>source</a> argument was a <a data-link-type=idl title=domstring>DOMString</a>,
parse it according to the grammar of the <a class=property data-link-type=propdesc href=http://www.w3.org/TR/css-fonts-3/#descdef-src title=src>src</a> descriptor of the CSS <a class=css data-link-type=maybe href=http://www.w3.org/TR/css-fonts-3/#at-font-face-rule title=@font-face>@font-face</a> rule.
If it fails to parse correctly,
reject <var>font face’s</var> <a data-link-type=idl href=#dom-fontface-fontstatuspromise title=[fontstatuspromise]>[FontStatusPromise]</a> with a SyntaxError exception and abort these steps;
otherwise, set <var>font face’s</var> internal <a data-link-type=idl href=#dom-fontface-urls title=[urls]>[Urls]</a> attribute to the string.
<p class=note> Note: Note that this means that passing a naked url as the source argument,
like <code>"http://example.com/myFont.woff"</code>,
won’t work - it needs to be at least wrapped in a <span class=css data-link-type=maybe title=url()>url()</span> function,
like <code>"url(http://example.com/myFont.woff)"</code>.
In return for this inconvenience,
you get to specify multiple fallbacks,
specify the type of font each fallback is,
and refer to local fonts easily.
<p> If the <a data-link-type=idl href=#dom-fontfacefontface-source title=source>source</a> argument was a <a data-link-type=idl href=http://dev.w3.org/csswg/css-font-load-events-3/#typedefdef-binarydata title=binarydata>BinaryData</a>,
set <var>font face’s</var> internal <a data-link-type=idl href=#dom-fontface-data title=[data]>[Data]</a> attribute to the passed argument.
<li>
If <var>font face’s</var> <a data-link-type=idl href=#dom-fontface-data title=[data]>[Data]</a> attribute is not <code>null</code>,
set <var>font face’s</var> <a data-link-for=FontFace data-link-type=idl href=#dom-fontface-status title=status>status</a> attribute to "loading",
and attempt to parse the data in it as a font.
If this is successful,
<var>font face</var> now represents the parsed font;
fulfill <var>font face’s</var> <a data-link-type=idl href=#dom-fontface-fontstatuspromise title=[fontstatuspromise]>[FontStatusPromise]</a> with <var>font face</var>,
and set its <a data-link-for=FontFace data-link-type=idl href=#dom-fontface-status title=status>status</a> attribute to "loaded".
If it is unsuccessful,
reject <var>font face’s</var> <a data-link-type=idl href=#dom-fontface-fontstatuspromise title=[fontstatuspromise]>[FontStatusPromise]</a> with a SyntaxError
and set <var>font face’s</var> <a data-link-for=FontFace data-link-type=idl href=#dom-fontface-status title=status>status</a> attribute to "error".
</ol>
<h3 class="heading settled heading" data-level=2.2 id=font-face-load><span class=secno>2.2 </span><span class=content>
The <code>load()</code> method</span><a class=self-link href=#font-face-load></a></h3>
<p> The <a class=idl-code data-link-for=FontFace data-link-type=method href=#dom-fontface-load title=load()>load()</a> method of <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a>
forces a url-based font face to request its font data and load.
For fonts constructed from binary data,
or fonts that are already loading or loaded,
it does nothing.
<p> When the <dfn class=idl-code data-dfn-for=FontFace data-dfn-type=method data-export="" id=dom-fontface-load>load()<a class=self-link href=#dom-fontface-load></a></dfn> method is called,
execute these steps:
<ol data-link-type=idl>
<li>
Let <var>font face</var> be the <a data-link-type=idl href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> object on which this method was called.
<li>
If <var>font face’s</var> <a data-link-type=idl href=#dom-fontface-urls title=[urls]>[Urls]</a> attribute is <code>null</code>,
or its <a data-link-for=FontFace data-link-type=idl href=#dom-fontface-status title=status>status</a> attribute is anything other than <code>"unloaded"</code>,
abort this algorithm immediately.
<li>
Otherwise,
set <var>font face’s</var> <a data-link-for=FontFace data-link-type=idl href=#dom-fontface-status title=status>status</a> attribute to "loading",
return immediately,
and follow these steps asynchronously:
<li>
Using the value of <var>font face’s <a data-link-type=idl href=#dom-fontface-urls title=[urls]>[Urls]</a> attribute,
attempt to load a font as defined in <a data-biblio-type=normative data-link-type=biblio href=#css3-fonts title=css3-fonts>[CSS3-FONTS]</a>,
as if it was the value of a <a class=css data-link-type=maybe href=http://www.w3.org/TR/css-fonts-3/#at-font-face-rule title=@font-face>@font-face</a> rule’s <a class=property data-link-type=propdesc href=http://www.w3.org/TR/css-fonts-3/#descdef-src title=src>src</a> descriptor.
</var><li>
If the attempt to load fails,
reject <var>font face’s</var> <a data-link-type=idl href=#dom-fontface-fontstatuspromise title=[fontstatuspromise]>[FontStatusPromise]</a> with a NetworkError
and set <var>font face’s</var> <a data-link-for=FontFace data-link-type=idl href=#dom-fontface-status title=status>status</a> attribute to "error".
<li>
Otherwise,
<var>font face</var> now represents the loaded font;
fulfill <var>font face’s</var> <a data-link-type=idl href=#dom-fontface-fontstatuspromise title=[fontstatuspromise]>[FontStatusPromise]</a> with <var>font face</var>
and set <var>font face’s</var> <a data-link-for=FontFace data-link-type=idl href=#dom-fontface-status title=status>status</a> attribute to "loaded".
</ol>
<p> User agents can initiate font loads on their own,
whenever they determine that a given font face is necessary to render something on the page.
When this happens,
they must act as if they had called the corresponding <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a>’s <a class=idl-code data-link-for=FontFace data-link-type=method href=#dom-fontface-load title=load()>load()</a> method described here.
<h3 class="heading settled heading" data-level=2.3 id=font-face-ready><span class=secno>2.3 </span><span class=content>
The <code>ready()</code> method</span><a class=self-link href=#font-face-ready></a></h3>
<p> The <a class=idl-code data-link-for=FontFace data-link-type=method href=#dom-fontface-ready title=ready()>ready()</a> method of <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a>
returns a Promise
which is fulfilled when the font face is successfully loaded,
or rejected when the font face fails to load or parse successfully.
<p> When the <dfn class=idl-code data-dfn-for=FontFace data-dfn-type=method data-export="" id=dom-fontface-ready>ready()<a class=self-link href=#dom-fontface-ready></a></dfn> method is called,
execute these steps:
<ol data-link-type=idl>
<li>
Let <var>font face</var> be the <a data-link-type=idl href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> object on which this method was called.
<li>
Let <var>ready promise</var> be a newly-created promise object.
<li>
Resolve <var>ready promise</var> with <var>font face’s</var> <a class=idl-code data-link-type=attribute href=#dom-fontface-fontstatuspromise title=[fontstatuspromise]>[FontStatusPromise]</a>.
<li>
Return <var>ready promise</var>.
</ol>
<h3 class="heading settled heading" data-level=2.4 id=font-face-css-connection><span class=secno>2.4 </span><span class=content>
Interaction with CSS’s <a class=css data-link-type=maybe href=http://www.w3.org/TR/css-fonts-3/#at-font-face-rule title=@font-face>@font-face</a> Rule</span><a class=self-link href=#font-face-css-connection></a></h3>
<p> A CSS <a class=css data-link-type=maybe href=http://www.w3.org/TR/css-fonts-3/#at-font-face-rule title=@font-face>@font-face</a> rule automatically defines a corresponding <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> object,
which is automatically placed in the document’s <a data-link-type=dfn href=#font-source title="font source">font source</a>.
This <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> object is <dfn data-dfn-type=dfn data-noexport="" id=css-connected>CSS-connected<a class=self-link href=#css-connected></a></dfn>.
<p> The <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> object corresponding to a <a class=css data-link-type=maybe href=http://www.w3.org/TR/css-fonts-3/#at-font-face-rule title=@font-face>@font-face</a> rule
has its <a class=idl-code data-link-type=attribute href=#dom-fontface-family title=family>family</a>, <a class=idl-code data-link-type=attribute href=#dom-fontface-style title=style>style</a>, <a class=idl-code data-link-type=attribute href=#dom-fontface-weight title=weight>weight</a>, <a class=idl-code data-link-type=attribute href=#dom-fontface-stretch title=stretch>stretch</a>, <a class=idl-code data-link-type=attribute href=#dom-fontface-unicoderange title=unicoderange>unicodeRange</a>, <a class=idl-code data-link-type=attribute href=#dom-fontface-variant title=variant>variant</a>, and <a class=idl-code data-link-type=attribute href=#dom-fontface-featuresettings title=featuresettings>featureSettings</a> attributes
set to the same value as the corresponding descriptors in the <a class=css data-link-type=maybe href=http://www.w3.org/TR/css-fonts-3/#at-font-face-rule title=@font-face>@font-face</a> rule.
There is a two-way connection between the two:
any change made to a <a class=css data-link-type=maybe href=http://www.w3.org/TR/css-fonts-3/#at-font-face-rule title=@font-face>@font-face</a> descriptor is immediately reflected in the corresponding <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> attribute,
and vice versa.
<p> The internal <a class=idl-code data-link-type=attribute href=#dom-fontface-urls title=[urls]>[Urls]</a> attribute of the <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> object is set to the value of the <a class=css data-link-type=maybe href=http://www.w3.org/TR/css-fonts-3/#at-font-face-rule title=@font-face>@font-face</a> rule’s <a class=property data-link-type=propdesc href=http://www.w3.org/TR/css-fonts-3/#descdef-src title=src>src</a> descriptor,
and reflects any changes made to the <a class=property data-link-type=propdesc href=http://www.w3.org/TR/css-fonts-3/#descdef-src title=src>src</a> descriptor.
<p> Otherwise, a <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> object created by a CSS <a class=css data-link-type=maybe href=http://www.w3.org/TR/css-fonts-3/#at-font-face-rule title=@font-face>@font-face</a> rule is identical to one created manually.
<p> If a <a class=css data-link-type=maybe href=http://www.w3.org/TR/css-fonts-3/#at-font-face-rule title=@font-face>@font-face</a> rule is removed from the document, its corresponding <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> object is no longer <a data-link-type=dfn href=#css-connected title=css-connected>CSS-connected</a>.
The connection is not restorable by any means
(but adding the <a class=css data-link-type=maybe href=http://www.w3.org/TR/css-fonts-3/#at-font-face-rule title=@font-face>@font-face</a> back to the stylesheet will create a brand new <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> object which <em>is</em> <a data-link-type=dfn href=#css-connected title=css-connected>CSS-connected</a>).
<h2 class="heading settled heading" data-level=3 id=FontFaceSet-interface><span class=secno>3 </span><span class=content>
The <code>FontFaceSet</code> Interface</span><a class=self-link href=#FontFaceSet-interface></a></h2>
<pre class=idl>dictionary <a class=idl-code data-global-name="" data-link-type=dictionary href=http://dev.w3.org/csswg/css-font-load-events-3/#dictdef-cssfontfaceloadeventinit title=cssfontfaceloadeventinit>CSSFontFaceLoadEventInit</a> : <a data-link-type=idl title=eventinit>EventInit</a> {
sequence&lt;<a data-link-type=idl title=cssfontfacerule>CSSFontFaceRule</a>&gt; <a class=idl-code data-global-name="CSSFontFaceLoadEventInit<dictionary>/fontfaces<dict-member>" data-link-for=CSSFontFaceLoadEventInit data-link-type=dict-member href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-cssfontfaceloadeventinit-fontfaces title=fontfaces>fontfaces</a> = null;
};
[Constructor(DOMString <a class=idl-code data-global-name="CSSFontFaceLoadEvent<interface>/CSSFontFaceLoadEvent()<method>/type<argument>" data-link-for=CSSFontFaceLoadEvent/CSSFontFaceLoadEvent() data-link-type=argument href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-cssfontfaceloadeventcssfontfaceloadevent-type title=type>type</a>, optional <a data-link-type=idl href=http://dev.w3.org/csswg/css-font-load-events-3/#dictdef-cssfontfaceloadeventinit title=cssfontfaceloadeventinit>CSSFontFaceLoadEventInit</a> <a class=idl-code data-global-name="CSSFontFaceLoadEvent<interface>/CSSFontFaceLoadEvent()<method>/eventinitdict<argument>" data-link-for=CSSFontFaceLoadEvent/CSSFontFaceLoadEvent() data-link-type=argument href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-cssfontfaceloadeventcssfontfaceloadevent-eventinitdict title=eventinitdict>eventInitDict</a>)]
interface <a class=idl-code data-global-name="" data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-cssfontfaceloadevent title=cssfontfaceloadevent>CSSFontFaceLoadEvent</a> : <a data-link-type=idl href=http://www.w3.org/TR/html5/obsolete.html#dom-script-event title=event>Event</a> {
readonly attribute sequence&lt;<a data-link-type=idl title=cssfontfacerule>CSSFontFaceRule</a>&gt; <a class=idl-code data-global-name="CSSFontFaceLoadEvent<interface>/fontfaces<attribute>" data-link-for=CSSFontFaceLoadEvent data-link-type=attribute href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-cssfontfaceloadevent-fontfaces title=fontfaces>fontfaces</a>;
};
enum <a class=idl-code data-global-name="" data-link-type=enum href=http://dev.w3.org/csswg/css-font-load-events-3/#enumdef-fontfacesetloadstatus title=fontfacesetloadstatus>FontFaceSetLoadStatus</a> { "loading", "loaded" };
[SetClass(FontFace)]
interface <a class=idl-code data-global-name="" data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfaceset title=fontfaceset>FontFaceSet</a> {
// -- events for when loading state changes
attribute <a data-link-type=idl href=http://www.w3.org/TR/html5/webappapis.html#eventhandler title=eventhandler>EventHandler</a> <a class=idl-code data-global-name="FontFaceSet<interface>/onloading<attribute>" data-link-for=FontFaceSet data-link-type=attribute href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfaceset-onloading title=onloading>onloading</a>;
attribute <a data-link-type=idl href=http://www.w3.org/TR/html5/webappapis.html#eventhandler title=eventhandler>EventHandler</a> <a class=idl-code data-global-name="FontFaceSet<interface>/onloadingdone<attribute>" data-link-for=FontFaceSet data-link-type=attribute href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfaceset-onloadingdone title=onloadingdone>onloadingdone</a>;
attribute <a data-link-type=idl href=http://www.w3.org/TR/html5/webappapis.html#eventhandler title=eventhandler>EventHandler</a> <a class=idl-code data-global-name="FontFaceSet<interface>/onloadingerror<attribute>" data-link-for=FontFaceSet data-link-type=attribute href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfaceset-onloadingerror title=onloadingerror>onloadingerror</a>;
// check and start loads if appropriate
// and fulfill promise when all loads complete
<a data-link-type=idl title=promise>Promise</a> <a class=idl-code data-global-name="FontFaceSet<interface>/load()<method>" data-link-for=FontFaceSet data-link-type=method href=#dom-fontfaceset-load title=load()>load</a>(DOMString <a class=idl-code data-global-name="FontFaceSet<interface>/load()<method>/font<argument>" data-link-for=FontFaceSet/load() data-link-type=argument href=#dom-fontfacesetload-font title=font>font</a>, optional DOMString <a class=idl-code data-global-name="FontFaceSet<interface>/load()<method>/text<argument>" data-link-for=FontFaceSet/load() data-link-type=argument href=#dom-fontfacesetload-text title=text>text</a> = " ");
// return whether all fonts in the fontlist are loaded
// (does not initiate load if not available)
boolean <a class=idl-code data-global-name="FontFaceSet<interface>/check()<method>" data-link-for=FontFaceSet data-link-type=method href=#dom-fontfaceset-check title=check()>check</a>(DOMString <a class=idl-code data-global-name="FontFaceSet<interface>/check()<method>/font<argument>" data-link-for=FontFaceSet/check() data-link-type=argument href=#dom-fontfacesetcheck-font title=font>font</a>, optional DOMString <a class=idl-code data-global-name="FontFaceSet<interface>/check()<method>/text<argument>" data-link-for=FontFaceSet/check() data-link-type=argument href=#dom-fontfacesetcheck-text title=text>text</a> = " ");
// async notification that font loading and layout operations are done
<a data-link-type=idl title=promise>Promise</a> <a class=idl-code data-global-name="FontFaceSet<interface>/ready()<method>" data-link-for=FontFaceSet data-link-type=method href=#dom-fontfaceset-ready title=ready()>ready</a>();
// loading state, "loading" while one or more fonts loading, "loaded" otherwise
readonly attribute <a data-link-type=idl href=http://dev.w3.org/csswg/css-font-load-events-3/#enumdef-fontfaceloadstatus title=fontfaceloadstatus>FontFaceLoadStatus</a> <a class=idl-code data-global-name="FontFaceSet<interface>/status<attribute>" data-link-for=FontFaceSet data-link-type=attribute href=#dom-fontfaceset-status title=status>status</a>;
};
<a data-link-type=idl href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfaceset title=fontfaceset>FontFaceSet</a> implements <a data-link-type=idl title=eventtarget>EventTarget</a>;
</pre>
<p> The set entries for a <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfaceset title=fontfaceset>FontFaceSet</a> is initially an empty list.
A <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfaceset title=fontfaceset>FontFaceSet</a> attached to a document may have some initial <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> objects prefilled in it;
see the section on <a href=#document-font-face-set>Interactions with CSS’s @font-face Rule</a> for details.
<p> Because font families are loaded only when they are used,
content sometimes needs to understand when the loading of fonts occurs.
Authors can use the events and methods defined here to allow greater control over actions
that are dependent upon the availability of specific fonts.
<p> The term <dfn data-dfn-type=dfn data-noexport="" id=font-load>font load<a class=self-link href=#font-load></a></dfn> indicates when the
loading of content for a given <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> object completes.
A <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> object may list multiple alternate resources
within its <a class=idl-code data-link-type=attribute href=#dom-fontface-urls title=[urls]>[Urls]</a> attribute,
including references to local fonts,
but the term font load only refers to the loading of the finally selected resource for a given <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a>,
not to the loading of each individual resource.
<p> There are <dfn data-dfn-type=dfn data-noexport="" id=no-pending-font-loads>no pending font loads<a class=self-link href=#no-pending-font-loads></a></dfn> whenever all of the following are true:
<p> <ul>
<li>
The document has finished loading.
<li>
There are no pending stylesheet requests.
<li>
There are no <a data-link-type=dfn href=#available-font-faces title="available font faces">available font faces</a>
with a <a class=idl-code data-link-for=FontFace data-link-type=attribute href=#dom-fontface-status title=status>status</a> of "loading".
<li>
There are no pending layout operations which might cause the user agent to request a font.
</ul>
<p> If any of the above conditions are false,
there are <dfn data-dfn-type=dfn data-noexport="" id=possibly-pending-font-loads>possibly pending font loads<a class=self-link href=#possibly-pending-font-loads></a></dfn>.
<dl>
<dt><dfn class=idl-code data-dfn-for=FontFaceSet data-dfn-type=attribute data-export="" id=dom-fontfaceset-status>status<a class=self-link href=#dom-fontfaceset-status></a></dfn>, of type <a class=idl-code data-link-type=interface title=domstring>DOMString</a>
<dd>
If there are <a data-link-type=dfn href=#possibly-pending-font-loads title="possibly pending font loads">possibly pending font loads</a>,
the <a class=idl-code data-link-for=FontFaceSet data-link-type=attribute href=#dom-fontfaceset-status title=status>status</a> attribute must have the value <code class=idl-code>"loading"</code>.
Otherwise, it must have the value <code class=idl-code>"loaded"</code>.
</dl>
<p> <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfaceset title=fontfaceset>FontFaceSet</a> objects also have internal
<dfn class=idl-code data-dfn-for=FontFaceSet data-dfn-type=attribute data-export="" id=dom-fontfaceset-loadingfonts>[LoadingFonts]<a class=self-link href=#dom-fontfaceset-loadingfonts></a></dfn>,
<dfn class=idl-code data-dfn-for=FontFaceSet data-dfn-type=attribute data-export="" id=dom-fontfaceset-loadedfonts>[LoadedFonts]<a class=self-link href=#dom-fontfaceset-loadedfonts></a></dfn>,
<dfn class=idl-code data-dfn-for=FontFaceSet data-dfn-type=attribute data-export="" id=dom-fontfaceset-failedfonts>[FailedFonts]<a class=self-link href=#dom-fontfaceset-failedfonts></a></dfn>,
and <dfn class=idl-code data-dfn-for=FontFaceSet data-dfn-type=attribute data-export="" id=dom-fontfaceset-pendingreadypromises>[PendingReadyPromises]<a class=self-link href=#dom-fontfaceset-pendingreadypromises></a></dfn> attributes,
all of which are initialized to the empty list.
<p class=issue id=issue-094f6719><a class=self-link href=#issue-094f6719></a>
Document the FontFaceSet behavior for Workers.
(They start out empty, but can construct fonts or be sent them via postMessage.)
<h3 class="heading settled heading" data-level=3.1 id=set-modifications><span class=secno>3.1 </span><span class=content>
Modifications of normal Set methods</span><a class=self-link href=#set-modifications></a></h3>
<p> The <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfaceset title=fontfaceset>FontFaceSet</a> methods <code>add()</code> and <code>delete()</code>
must throw an InvalidModificationError exception
if their argument is a <a data-link-type=dfn href=#css-connected title=css-connected>CSS-connected</a> <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> object.
<p> The <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfaceset title=fontfaceset>FontFaceSet</a> method <code>clear()</code>
must only remove the manually-added <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> objects;
the <a data-link-type=dfn href=#css-connected title=css-connected>CSS-connected</a> <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> objects are unaffected.
<h3 class="heading settled heading" data-level=3.2 id=FontFaceSet-events><span class=secno>3.2 </span><span class=content>
Events</span><a class=self-link href=#FontFaceSet-events></a></h3>
<p> Font load events make it easy to respond to the font-loading behavior of the entire document,
rather than having to listen to each font specifically.
The <dfn class=idl-code data-dfn-for=FontFaceSet data-dfn-type=event data-export="" id=dom-fontfaceset-loading>loading<a class=self-link href=#dom-fontfaceset-loading></a></dfn> event
fires when the document begins loading fonts,
while the <dfn class=idl-code data-dfn-for=FontFaceSet data-dfn-type=event data-export="" id=dom-fontfaceset-loadingdone>loadingdone<a class=self-link href=#dom-fontfaceset-loadingdone></a></dfn>
and <dfn class=idl-code data-dfn-for=FontFaceSet data-dfn-type=event data-export="" id=dom-fontfaceset-loadingerror>loadingerror<a class=self-link href=#dom-fontfaceset-loadingerror></a></dfn> events
fire when the document is done loading fonts,
containing the fonts that successfully loaded
or failed to load,
respectively.
<p> The following are the event handlers (and their corresponding event handler event types)
that must be supported by <code>FontFaceSet</code> objects as IDL attributes:
<table class=data id=eventhandlers>
<thead>
<tr>
<th>Event handler
<th>Event handler event type
<tbody>
<tr>
<th><a class=idl-code data-link-type=attribute href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfaceset-onloading title=onloading>onloading</a>
<td><a class=idl-code data-link-type=event href=#dom-fontfaceset-loading title=loading>loading</a>
<tr>
<th><a class=idl-code data-link-type=attribute href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfaceset-onloadingdone title=onloadingdone>onloadingdone</a>
<td><a class=idl-code data-link-type=event href=#dom-fontfaceset-loadingdone title=loadingdone>loadingdone</a>
<tr>
<th><a class=idl-code data-link-type=attribute href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfaceset-onloadingerror title=onloadingerror>onloadingerror</a>
<td><a class=idl-code data-link-type=event href=#dom-fontfaceset-loadingerror title=loadingerror>loadingerror</a>
</table>
<p> To <dfn data-dfn-type=dfn data-noexport="" id=fire-a-font-load-event>fire a font load event<a class=self-link href=#fire-a-font-load-event></a></dfn> named <var>e</var>
at a <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfaceset title=fontfaceset>FontFaceSet</a> <var>target</var>
with optional <var>font faces</var>
means to
<a href=http://www.w3.org/TR/html5/webappapis.html#event-firing>fire a simple event</a> named <var>e</var>
using the <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-cssfontfaceloadevent title=cssfontfaceloadevent>CSSFontFaceLoadEvent</a> interface that also meets these conditions:
<ol>
<li>
The <a class=idl-code data-link-type=attribute href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-cssfontfaceloadevent-fontfaces title=fontfaces>fontfaces</a> attribute is initialized to the given list of <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> objects.
</ol>
<p> Whenever a <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> in a given <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfaceset title=fontfaceset>FontFaceSet</a> <var>font face set</var>
changes its <a class=idl-code data-link-for=FontFace data-link-type=attribute href=#dom-fontface-status title=status>status</a> attribute to
<p> Whenever one or more <a data-link-type=dfn href=#available-font-faces title="available font faces">available font faces</a> for a given <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfaceset title=fontfaceset>FontFaceSet</a>
change their <a class=idl-code data-link-for=FontFace data-link-type=attribute href=#dom-fontface-status title=status>status</a> attribute to "loading",
the user agent must run the following steps:
<ol>
<li>
Let <var>font face set</var> be the given <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfaceset title=fontfaceset>FontFaceSet</a>,
and <var>loading fonts</var> be the <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> objects
that have newly switched to "loading" status,
in the same order as they appear in <var>font face set</var>.
<li>
Set the <a class=idl-code data-link-for=FontFaceSet data-link-type=attribute href=#dom-fontfaceset-status title=status>status</a> attribute of <var>font face set</var> to "loading".
<li>
If <var>font face set’s</var> <a class=idl-code data-link-type=attribute href=#dom-fontfaceset-loadingfonts title=[loadingfonts]>[LoadingFonts]</a> attribute is currently empty,
<a data-link-type=dfn href=#fire-a-font-load-event title="fire a font load event">fire a font load event</a> named <a class=idl-code data-link-type=event href=#dom-fontfaceset-loading title=loading>loading</a> at <var>font face set</var>.
<li>
Append the <var>loading fonts</var> to <var>font face set’s</var> <a class=idl-code data-link-type=attribute href=#dom-fontfaceset-loadingfonts title=[loadingfonts]>[LoadingFonts]</a> attribute.
</ol>
<p> Whenever one or more <a data-link-type=dfn href=#available-font-faces title="available font faces">available font faces</a> for a given <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfaceset title=fontfaceset>FontFaceSet</a>
change their <a class=idl-code data-link-for=FontFace data-link-type=attribute href=#dom-fontface-status title=status>status</a> attribute to "loaded" or "error",
the user agent must run the following steps:
<ol>
<li>
Let <var>font face set</var> be the given <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfaceset title=fontfaceset>FontFaceSet</a>,
and <var>loaded fonts</var> be the <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> objects
that have newly switched to "loaded" or "error" status,
in the same order as they appear in <var>font face set</var>.
<li>
For each font in the <var>loaded fonts</var>,
if their <a class=idl-code data-link-for=FontFace data-link-type=attribute href=#dom-fontface-status title=status>status</a> attribute is "loaded",
append them to <var>font face set’s</var> <a class=idl-code data-link-type=attribute href=#dom-fontfaceset-loadedfonts title=[loadedfonts]>[LoadedFonts]</a> attribute;
if it’s "error",
append them to <var>font face set’s</var> <a class=idl-code data-link-type=attribute href=#dom-fontfaceset-failedfonts title=[failedfonts]>[FailedFonts]</a> attribute.
</ol>
<p> If there are ever <a data-link-type=dfn href=#no-pending-font-loads title="no pending font loads">no pending font loads</a>
and either of <var>font face set’s</var> <a class=idl-code data-link-type=attribute href=#dom-fontfaceset-loadedfonts title=[loadedfonts]>[LoadedFonts]</a> or <a class=idl-code data-link-type=attribute href=#dom-fontfaceset-failedfonts title=[failedfonts]>[FailedFonts]</a> attributes are not empty,
user agents must run these steps:
<ol>
<li>
Set <var>font face set’s</var> <a class=idl-code data-link-for=FontFaceSet data-link-type=attribute href=#dom-fontfaceset-status title=status>status</a> attribute to "loaded".
<li>
<a data-link-type=dfn href=#fire-a-font-load-event title="fire a font load event">Fire a font load event</a> named <a class=idl-code data-link-type=event href=#dom-fontfaceset-loadingdone title=loadingdone>loadingdone</a> at <var>font face set</var>
with the contents of <var>font face set’s</var> <a class=idl-code data-link-type=attribute href=#dom-fontfaceset-loadedfonts title=[loadedfonts]>[LoadedFonts]</a> attribute, if any.
<li>
If <var>font face set’s</var> <a class=idl-code data-link-type=attribute href=#dom-fontfaceset-failedfonts title=[failedfonts]>[FailedFonts]</a> attribute is non-empty,
<a data-link-type=dfn href=#fire-a-font-load-event title="fire a font load event">fire a font load event</a> named <a class=idl-code data-link-type=event href=#dom-fontfaceset-loadingerror title=loadingerror>loadingerror</a> at <var>font face set</var>
with the contents of <var>font face set’s</var> <a class=idl-code data-link-type=attribute href=#dom-fontfaceset-failedfonts title=[failedfonts]>[FailedFonts]</a> attribute.
<li>
If <var>font face set’s</var> <a class=idl-code data-link-type=attribute href=#dom-fontfaceset-pendingreadypromises title=[pendingreadypromises]>[PendingReadyPromises]</a> attribute is non-empty,
fulfill each promise in the attribute’s value with <var>font face set</var>.
<li>
Empty <var>font face set’s</var> <a class=idl-code data-link-type=attribute href=#dom-fontfaceset-loadingfonts title=[loadingfonts]>[LoadingFonts]</a>, <a class=idl-code data-link-type=attribute href=#dom-fontfaceset-loadedfonts title=[loadedfonts]>[LoadedFonts]</a>, <a class=idl-code data-link-type=attribute href=#dom-fontfaceset-failedfonts title=[failedfonts]>[FailedFonts]</a>, and <a class=idl-code data-link-type=attribute href=#dom-fontfaceset-pendingreadypromises title=[pendingreadypromises]>[PendingReadyPromises]</a> attributes.
</ol>
<p> If asked to <dfn data-dfn-type=dfn data-export="" id=find-the-matching-font-faces>find the matching font faces<a class=self-link href=#find-the-matching-font-faces></a></dfn>
from a FontFaceSet <var>source</var>,
for a given font string <var>font</var>
and optionally some sample text <var>text</var>,
run the following steps:
<ol>
<li>
Parse <var>font</var>
using the CSS value syntax of the <a class=property data-link-type=propdesc href=http://www.w3.org/TR/css-fonts-3/#propdef-font title=font>font</a> property.
If a syntax error occurs,
return a syntax error.
<li>
If <var>text</var> was not explicitly provided,
let it be a string containing a single space character (U+0020 SPACE).
<li>
Let <var>font family list</var> be the list of font families parsed from <var>font</var>,
and <var>font style</var> be the other font style attributes parsed from <var>font</var>.
<li>
Let <var>available font faces</var> be the font faces within <var>source</var>.
<li>
Let <var>matched font faces</var> initially be an empty list.
<li>
For each family in <var>font family list</var>,
use the font matching rules to select the font faces from <var>available font faces</var>
that match the <var>font style</var>,
and add them to <var>matched font faces</var>.
The use of the <a class=idl-code data-link-type=attribute href=#dom-fontface-unicoderange title=unicoderange>unicodeRange</a> attribute means that this may be more than just a single font face.
<li>
For each font face in <var>matched font faces</var>,
if its defined <a class=property data-link-type=propdesc href=http://www.w3.org/TR/css-fonts-3/#descdef-unicode-range title=unicode-range>unicode-range</a> does not include the codepoint of at least one character in <var>text</var>,
remove it from the list.
<li>
Return <var>matched font faces</var>.
</ol>
<h3 class="heading settled heading" data-level=3.3 id=font-face-set-load><span class=secno>3.3 </span><span class=content>
The <code>load()</code> method</span><a class=self-link href=#font-face-set-load></a></h3>
<p> The <a data-link-for=FontFaceSet data-link-type=functionish href=#dom-fontfaceset-load title=load()>load()</a> method of <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfaceset title=fontfaceset>FontFaceSet</a> will determine whether all fonts in the given font list
have been loaded and are available.
If any fonts are downloadable fonts and have not already been loaded,
the user agent will initiate the load of each of these fonts.
It returns a Promise,
which is fulfilled when all of the fonts are loaded and ready to be used,
or rejected if any font failed to load properly.
<p> When the <dfn class=idl-code data-dfn-for=FontFaceSet data-dfn-type=method data-export="" id=dom-fontfaceset-load title=load()>load<a class=self-link href=#dom-fontfaceset-load></a></dfn>(<dfn class=idl-code data-dfn-for=FontFaceSet/load() data-dfn-type=argument data-export="" id=dom-fontfacesetload-font>font<a class=self-link href=#dom-fontfacesetload-font></a></dfn>, <dfn class=idl-code data-dfn-for=FontFaceSet/load() data-dfn-type=argument data-export="" id=dom-fontfacesetload-text>text<a class=self-link href=#dom-fontfacesetload-text></a></dfn>) method is called,
execute these steps:
<ol>
<li>
Let <var>font face set</var> be the <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfaceset title=fontfaceset>FontFaceSet</a> object this method was called on.
Let <var>promise</var> be a newly-created promise object.
<li>
Return <var>promise</var>.
Complete the rest of these steps asynchronously.
<li>
<a data-link-type=dfn href=#find-the-matching-font-faces title="find the matching font faces">Find the matching font faces</a> from <var>font face set</var>
using the <a class=idl-code data-link-for=FontFaceSet/load() data-link-type=argument href=#dom-fontfacesetload-font title=font>font</a> and <a class=idl-code data-link-for=FontFaceSet/load() data-link-type=argument href=#dom-fontfacesetload-text title=text>text</a> arguments passed to the function,
and let <var>font face list</var> be the return value.
If a syntax error was returned,
reject <var>promise</var> with a SyntaxError exception
and terminate these steps.
<li>
For all of the font faces in the <var>font face list</var>,
call their <a class=idl-code data-link-for=FontFace data-link-type=method href=#dom-fontface-load title=load()>load()</a> method.
<li>
Resolve <var>promise</var> with the result of
waiting for all of the <a class=idl-code data-link-type=attribute href=#dom-fontface-fontstatuspromise title=[fontstatuspromise]>[FontStatusPromise]</a>s of each font face in the <var>font face list</var>, in order.
</ol>
<h3 class="heading settled heading" data-level=3.4 id=font-face-set-check><span class=secno>3.4 </span><span class=content>
The <code>check()</code> method</span><a class=self-link href=#font-face-set-check></a></h3>
<p> The <a data-link-type=functionish href=#dom-fontfaceset-check title=check()>check()</a> method of <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfaceset title=fontfaceset>FontFaceSet</a> will determine whether all fonts in the given font list
have been loaded and are available.
If all fonts are available,
it returns true;
otherwise, it returns false.
<p> When the <dfn class=idl-code data-dfn-for=FontFaceSet data-dfn-type=method data-export="" id=dom-fontfaceset-check title=check()>check<a class=self-link href=#dom-fontfaceset-check></a></dfn>(<dfn class=idl-code data-dfn-for=FontFaceSet/check() data-dfn-type=argument data-export="" id=dom-fontfacesetcheck-font>font<a class=self-link href=#dom-fontfacesetcheck-font></a></dfn>, <dfn class=idl-code data-dfn-for=FontFaceSet/check() data-dfn-type=argument data-export="" id=dom-fontfacesetcheck-text>text<a class=self-link href=#dom-fontfacesetcheck-text></a></dfn>) method is called,
execute these steps:
<ol>
<li>
Let <var>font face set</var> be the <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfaceset title=fontfaceset>FontFaceSet</a> object this method was called on.
<li>
<a data-link-type=dfn href=#find-the-matching-font-faces title="find the matching font faces">Find the matching font faces</a> from <var>font face set</var>
using the <a class=idl-code data-link-for=FontFaceSet/check() data-link-type=argument href=#dom-fontfacesetcheck-font title=font>font</a> and <a class=idl-code data-link-for=FontFaceSet/check() data-link-type=argument href=#dom-fontfacesetcheck-text title=text>text</a> arguments passed to the function,
and let <var>font face list</var> be the return value.
If a syntax error was returned,
reject <var>promise</var> with a SyntaxError exception
and terminate these steps.
<li>
If the <var>font face list</var> contains no font faces,
return <code class=idl-code>true</code>.
<li>
If all fonts in the <var>font face list</var> have a <a class=idl-code data-link-for=FontFace data-link-type=attribute href=#dom-fontface-status title=status>status</a> attribute of "loaded",
return <code>true</code>.
Otherwise, return <code>false</code>.
</ol>
<h3 class="heading settled heading" data-level=3.5 id=font-face-set-ready><span class=secno>3.5 </span><span class=content>
The <code>ready()</code> method</span><a class=self-link href=#font-face-set-ready></a></h3>
<p> Because the number of fonts loaded depends on the how many fonts are used for a given piece of text,
in some cases whether fonts need to be loaded or not may not be known.
The <a data-link-for=FontFaceSet data-link-type=functionish href=#dom-fontfaceset-ready title=ready()>ready()</a> method returns a Promise which is resolved when the document is done loading fonts,
which provides a way for authors to avoid having to keep track of which fonts have or haven’t been loaded
before examining content which may be affected by loading fonts.
<p> When the <dfn class=idl-code data-dfn-for=FontFaceSet data-dfn-type=method data-export="" id=dom-fontfaceset-ready>ready()<a class=self-link href=#dom-fontfaceset-ready></a></dfn> method is called,
execute these steps:
<ol>
<li>
Let <var>font face set</var> be the <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfaceset title=fontfaceset>FontFaceSet</a> object this method was called on.
Let <var>ready promise</var> be a fresh Promise which is initially pending.
<li>
If <var>font face set’s</var> <a class=idl-code data-link-for=FontFaceSet data-link-type=attribute href=#dom-fontfaceset-status title=status>status</a> attribute is "loaded",
fulfill <var>ready promise</var> with <var>font face set</var>.
Otherwise, append <var>ready promise</var>
to <var>font face set’s</var> <a class=idl-code data-link-type=attribute href=#dom-fontfaceset-pendingreadypromises title=[pendingreadypromises]>[PendingReadyPromises]</a> attribute.
<li>
Return <var>ready promise</var>.
</ol>
<p class=note> Note: Authors should note that a given <var>ready promise</var> is only fulfilled once,
but further fonts may be loaded after it fulfills.
This is similar to listening for a <a class=idl-code data-link-type=event href=#dom-fontfaceset-loadingdone title=loadingdone>loadingdone</a> event to fire,
but the callbacks passed to the <a class=idl-code data-link-for=FontFaceSet data-link-type=method href=#dom-fontfaceset-ready title=ready()>ready()</a> promise will <strong>always</strong> get called,
even when no font loads occur because the fonts in question are already loaded.
It’s a simple, easy way to synchronize code to font loads
without the need to keep track of what fonts are needed and precisely when they load.
<p class=note> Note: Note that the user agent may need to iterate over multiple font loads before the <var>ready promise</var> is fulfilled.
This can occur with font fallback situations,
where one font in the fontlist is loaded
but doesn’t contain a particular glyph
and other fonts in the fontlist need to be loaded.
The <var>ready promise</var> is only fulfilled after layout operations complete
and no additional font loads are necessary.
<p class=note> Note: Note that the Promise returned by this <a class=idl-code data-link-for=FontFaceSet data-link-type=method href=#dom-fontfaceset-ready title=ready()>ready()</a> method is only ever fulfilled,
never rejected,
unlike the Promise returned by the <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> <a class=idl-code data-link-for=FontFace data-link-type=method href=#dom-fontface-ready title=ready()>ready()</a> method.
<h3 class="heading settled heading" data-level=3.6 id=font-face-set-css><span class=secno>3.6 </span><span class=content>
Interaction with CSS Font Loading and Matching</span><a class=self-link href=#font-face-set-css></a></h3>
<p> When the font matching algorithm in <a data-biblio-type=informative data-link-type=biblio href=#css3-fonts title=css3-fonts>[CSS3-FONTS]</a> is run automatically by the user-agent,
the set of font faces it matches over must be precisely the set of fonts in the <a data-link-type=dfn href=#font-source title="font source">font source</a> for the document,
plus any local font faces.
<p> When a user-agent needs to load a font face,
it must do so by calling the <a class=idl-code data-link-for=FontFace data-link-type=method href=#dom-fontface-load title=load()>load()</a> method
of the corresponding <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> object.
<p> (This means it must run the same algorithm,
not literally call the value currently stored in the <code>load</code> property of the object.)
<h2 class="heading settled heading" data-level=4 id=font-face-source><span class=secno>4 </span><span class=content>
The <code>FontFaceSource</code> interface</span><a class=self-link href=#font-face-source></a></h2>
<pre class=idl>interface <a class=idl-code data-global-name="" data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfacesource title=fontfacesource>FontFaceSource</a> {
readonly attribute <a data-link-type=idl href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfaceset title=fontfaceset>FontFaceSet</a> <a class=idl-code data-global-name="FontFaceSource<interface>/fonts<attribute>" data-link-for=FontFaceSource data-link-type=attribute href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfacesource-fonts title=fonts>fonts</a>;
};
<a data-link-type=idl href=http://www.w3.org/TR/html5/infrastructure.html#dom-document title=document>Document</a> implements <a data-link-type=idl href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfacesource title=fontfacesource>FontFaceSource</a>;
<a data-link-type=idl title=workerglobalscope>WorkerGlobalScope</a> implements <a data-link-type=idl href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfacesource title=fontfacesource>FontFaceSource</a>;
</pre>
<p> Any document, workers, or other context which can use fonts in some manner must implement the <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfacesource title=fontfacesource>FontFaceSource</a> interface.
The value of the context’s <a class=idl-code data-link-type=attribute href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontfacesource-fonts title=fonts>fonts</a> attribute is its <dfn data-dfn-type=dfn data-noexport="" id=font-source>font source<a class=self-link href=#font-source></a></dfn>,
which provides all of the fonts used in font-related operations,
unless defined otherwise.
Operations referring to “the font source” must be interpreted as referring to the <a data-link-type=dfn href=#font-source title="font source">font source</a> of the relevant context in which the operation is taking place.
<p> For any font-related operation that takes place within one of these contexts,
the <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> objects within the <a data-link-type=dfn href=#font-source title="font source">font source</a> are its <dfn data-dfn-type=dfn data-noexport="" id=available-font-faces>available font faces<a class=self-link href=#available-font-faces></a></dfn>.
<h3 class="heading settled heading" data-level=4.1 id=document-font-face-set><span class=secno>4.1 </span><span class=content>
Interaction with CSS’s <a class=css data-link-type=maybe href=http://www.w3.org/TR/css-fonts-3/#at-font-face-rule title=@font-face>@font-face</a> Rule</span><a class=self-link href=#document-font-face-set></a></h3>
<p> The set entries for a document’s <a data-link-type=dfn href=#font-source title="font source">font source</a>
must be initially populated with all the <a data-link-type=dfn href=#css-connected title=css-connected>CSS-connected</a> <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> objects
from all of the CSS <a class=css data-link-type=maybe href=http://www.w3.org/TR/css-fonts-3/#at-font-face-rule title=@font-face>@font-face</a> rules in the document’s stylesheets,
in document order.
As <a class=css data-link-type=maybe href=http://www.w3.org/TR/css-fonts-3/#at-font-face-rule title=@font-face>@font-face</a> rules are added or removed from a stylesheet,
or stylesheets containing <a class=css data-link-type=maybe href=http://www.w3.org/TR/css-fonts-3/#at-font-face-rule title=@font-face>@font-face</a> rules are added or removed,
the corresponding <a data-link-type=dfn href=#css-connected title=css-connected>CSS-connected</a> <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> objects
must be added or removed from the document’s <a data-link-type=dfn href=#font-source title="font source">font source</a>,
and maintain this ordering.
<p> All non-<a data-link-type=dfn href=#css-connected title=css-connected>CSS-connected</a> <a class=idl-code data-link-type=interface href=http://dev.w3.org/csswg/css-font-load-events-3/#dom-fontface title=fontface>FontFace</a> objects must be sorted after the <a data-link-type=dfn href=#css-connected title=css-connected>CSS-connected</a> ones,
in insertion order.
<p class=issue id=issue-d3a24efa><a class=self-link href=#issue-d3a24efa></a>
Can/should we include the local system fonts,
or is that a fingerprinting problem?
I think the set of local fonts is trivially discoverable anyway.
Alternately, define a specialized variant of FontFace which represents all the local fonts collectively,
and perhaps can be queried against?
This would make FontFaceSet fully explain the current behavior of fonts.
<h2 class="heading settled heading" data-level=5 id=font-load-event-examples><span class=secno>5 </span><span class=content>
API Examples</span><a class=self-link href=#font-load-event-examples></a></h2>
<div class=example>
To show content only after all font loads complete:
<pre> document.FontFaceSet.ready().then(function() {
var content = document.getElementById("content");
content.style.visibility = "visible";
});
</pre> </div>
<div class=example>
Drawing text in a canvas with a downloadable font, explicitly
initiating the font download and drawing upon completion:
<pre> function drawStuff() {
var ctx = document.getElementById("c").getContext("2d");
ctx.fillStyle = "red";
ctx.font = "50px MyDownloadableFont";
ctx.fillText("Hello!", 100, 100);
}
document.fonts.load("50px MyDownloadableFont")
.then(drawStuff, handleError);
</pre> </div>
<div class=example>
A rich text editing application may need to measure text elements
after editing operations have taken place. Since style changes may
or may not require additional fonts to be downloaded, or the fonts
may already have been downloaded, the measurement procedures need to
occur after those font loads complete:
<pre> function measureTextElements() {
// contents can now be measured using the metrics of
// the downloadable font(s)
}
function doEditing() {
// content/layout operations that may cause additional font loads
document.fonts.ready().then(measureTextElements);
}
</pre> </div>
<div class=example>
The <a class=idl-code data-link-type=event href=#dom-fontfaceset-loadingdone title=loadingdone>loadingdone</a> event only fires after all font related loads have completed
<strong>and</strong> text has been laid out without causing additional font loads:
<pre> @font-face {
font-family: latin-serif;
src: url(latinserif.woff) format("woff"); /* contains no kanji/kana */
}
@font-face {
font-family: jpn-mincho;
src: url(mincho.woff) format("woff");
}
body { font-family: latin-serif, jpn-mincho; }
&lt;p&gt;納豆はいかがでしょうか
</pre>
<p> In this situation, the user agent first downloads “latinserif.woff”
and then tries to use this to draw the Japanese text. But because no
Japanese glyphs are present in that font, fallback occurs and the font
“mincho.woff” is downloaded. Only after the second font is downloaded
and the Japanese text laid out does the <a class=idl-code data-link-type=event href=#dom-fontfaceset-loadingdone title=loadingdone>loadingdone</a>
event fire.
</div>
<h2 class="no-num heading settled heading" id=changes><span class=content>Changes</span><a class=self-link href=#changes></a></h2>
<h3 class="no-num heading settled heading" id=changes-since-20130212><span class=content>
Changes from the <a href=http://www.w3.org/TR/2013/WD-css3-fonts-20130212/>February 2013 CSS3 Fonts Working Draft</a></span><a class=self-link href=#changes-since-20130212></a></h3>
<p> Major changes include:
<p> <ul>
<li>Add details of font load errors.
<li>Switched to a promise-based design for load() and ready().
<li>Renamed notifyWhenFontsReady() to ready().
<li>Added a FontFace interface, to directly represent the individual font faces, and allow manual construction of font faces without having to indirect through a @font-face rule.
<li>Dropped the per-font events, in favor of promise-based methods on FontFace.
</ul>
<h2 class="no-num heading settled heading" id=acknowledgments><span class=content>
Acknowledgments</span><a class=self-link href=#acknowledgments></a></h2>
<p> Several members of the Google Fonts team provided helpful feedback on font load events,
as did Boris Zbarsky, Jonas Sicking and ms2ger.
<h2 class="no-ref no-num heading settled heading" id=conformance><span class=content>
Conformance</span><a class=self-link href=#conformance></a></h2>
<h3 class="no-ref heading settled heading" id=conventions><span class=content>
Document conventions</span><a class=self-link href=#conventions></a></h3>
<p>Conformance requirements are expressed with a combination of
descriptive assertions and RFC 2119 terminology. The key words "MUST",
"MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT",
"RECOMMENDED", "MAY", and "OPTIONAL" in the normative parts of this
document are to be interpreted as described in RFC 2119.
However, for readability, these words do not appear in all uppercase
letters in this specification.
<p>All of the text of this specification is normative except sections
explicitly marked as non-normative, examples, and notes. <a data-biblio-type=normative data-link-type=biblio href=#rfc2119 title=rfc2119>[RFC2119]</a></p>
<p>Examples in this specification are introduced with the words "for example"
or are set apart from the normative text with <code>class="example"</code>,
like this:
<div class=example>
<p>This is an example of an informative example.</p>
</div>
<p>Informative notes begin with the word "Note" and are set apart from the
normative text with <code>class="note"</code>, like this:
<p class=note>Note, this is an informative note.</p>
<h3 class="no-ref heading settled heading" id=conformance-classes><span class=content>
Conformance classes</span><a class=self-link href=#conformance-classes></a></h3>
<p>Conformance to this specification
is defined for three conformance classes:
<dl>
<dt>style sheet
<dd>A <a href=http://www.w3.org/TR/CSS21/conform.html#style-sheet>CSS
style sheet</a>.
<dt>renderer
<dd>A <a href=http://www.w3.org/TR/CSS21/conform.html#user-agent>UA</a>
that interprets the semantics of a style sheet and renders
documents that use them.
<dt>authoring tool
<dd>A <a href=http://www.w3.org/TR/CSS21/conform.html#user-agent>UA</a>
that writes a style sheet.
</dl>
<p>A style sheet is conformant to this specification
if all of its statements that use syntax defined in this module are valid
according to the generic CSS grammar and the individual grammars of each
feature defined in this module.
<p>A renderer is conformant to this specification
if, in addition to interpreting the style sheet as defined by the
appropriate specifications, it supports all the features defined
by this specification by parsing them correctly
and rendering the document accordingly. However, the inability of a
UA to correctly render a document due to limitations of the device
does not make the UA non-conformant. (For example, a UA is not
required to render color on a monochrome monitor.)
<p>An authoring tool is conformant to this specification
if it writes style sheets that are syntactically correct according to the
generic CSS grammar and the individual grammars of each feature in
this module, and meet all other conformance requirements of style sheets
as described in this module.
<h3 class="no-ref heading settled heading" id=partial><span class=content>
Partial implementations</span><a class=self-link href=#partial></a></h3>
<p>So that authors can exploit the forward-compatible parsing rules to
assign fallback values, CSS renderers <strong>must</strong>
treat as invalid (and <a href=http://www.w3.org/TR/CSS21/conform.html#ignore>ignore
as appropriate</a>) any at-rules, properties, property values, keywords,
and other syntactic constructs for which they have no usable level of
support. In particular, user agents <strong>must not</strong> selectively
ignore unsupported component values and honor supported values in a single
multi-value property declaration: if any value is considered invalid
(as unsupported values must be), CSS requires that the entire declaration
be ignored.</p>
<h3 class="no-ref heading settled heading" id=experimental><span class=content>
Experimental implementations</span><a class=self-link href=#experimental></a></h3>
<p>To avoid clashes with future CSS features, the CSS2.1 specification
reserves a <a href=http://www.w3.org/TR/CSS21/syndata.html#vendor-keywords>prefixed
syntax</a> for proprietary and experimental extensions to CSS.