-
Notifications
You must be signed in to change notification settings - Fork 791
Expand file tree
/
Copy pathFontLoadEvents.html
More file actions
1003 lines (786 loc) · 38.4 KB
/
FontLoadEvents.html
File metadata and controls
1003 lines (786 loc) · 38.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang=en>
<head><meta content="text/html;charset=utf-8" http-equiv=Content-Type>
<title>CSS Font Load Events Module Level 3</title>
<!--
FIXME when publishing: copy the current default.css and link to
"default.css" rather than "../default.css"
-->
<link href="../default.css" rel=stylesheet type="text/css">
<link href="../csslogo.ico" rel="shortcut icon" type="image/x-icon">
<!-- I'm just experimenting here, don't get your bee in a bonnet -->
<script src="http://use.typekit.com/xon2bky.js"
type="text/javascript"></script>
<script type="text/javascript">try{Typekit.load();}catch(e){}</script>
<style type="text/css">
body, th, td, h1, h2, h3, h4, h5, h6 {
font-family: "myriad-pro", sans-serif !important;
}
body {
padding: 2em 70px 2em 70px;
}
p + p, p.mtb {
margin-top: 0.8em;
text-indent: 0px;
}
#bolderlighter {
width: 40%;
}
#bolderlighter th {
text-align: center;
}
#fontformats td, #eventhandlers td, #fontformats th, #eventhandlers th {
padding-right: 2em;
text-align: left;
}
dd {
margin-bottom: 1em;
}
#authors dd {
margin-bottom: 0;
}
#fontstylematchingalg {
list-style-type: lower-alpha;
}
#fontmatchingalg ul, #fontmatchingalg ol {
margin-top: 0.8em;
}
#fontmatchingalg li + li {
margin-top: 0.8em;
}
div.example {
padding: 1em;
margin-top: 1em;
}
div.example + div.example {
margin-top: 2em;
}
div.figure {
page-break-inside: avoid;
}
pre.prod { white-space: pre-wrap; margin: 1em 0 1em 2em }
div.featex {
width: 700px;
}
div.featex img {
margin: auto;
display: block;
}
span.tag {
font-family: monospace;
font-size: 120%;
}
ol ol {
list-style-type: lower-alpha;
}
.idl-code {
font-weight: bold;
color: #c50;
}
</style>
<link href="http://www.w3.org/StyleSheets/TR/W3C-ED.css" rel=stylesheet
type="text/css">
<body>
<div class=head> <!--begin-logo-->
<p><a href="http://www.w3.org/"><img alt=W3C height=48
src="http://www.w3.org/Icons/w3c_home" width=72></a> <!--end-logo-->
<h1>CSS Font Load Events Module Level 3</h1>
<h2 class="no-num no-toc" id=editors-draft-22-february-2013>Editor's Draft
22 February 2013</h2>
<dl id=authors>
<dt>This version:
<dd><a
href="http://dev.w3.org/csswg/css-font-load-events-3/">http://dev.w3.org/csswg/css-font-load-events-3/</a>
<!-- <dd><a href="http://www.w3.org/TR/2013/ED-css-font-load-events-3-20130222/">http://www.w3.org/TR/2013/ED-css-font-load-events-3-20130222/</a> -->
<dt>Latest version:
<dd><a
href="http://www.w3.org/TR/css-font-load-events-3/">http://www.w3.org/TR/css-font-load-events-3/</a>
<dt>Latest editor's draft:
<dd><a
href="http://dev.w3.org/csswg/css-font-load-events-3/">http://dev.w3.org/csswg/css-font-load-events-3/</a>
(<a
href="https://dvcs.w3.org/hg/csswg/log/tip/css-font-load-events-3/FontLoadEvents.html">change
log</a>)</dd>
<!-- <dt>Previous version:</dt>
<dd><a href="http://www.w3.org/TR/2013/WD-css3-fonts-20130212/">http://www.w3.org/TR/2013/WD-css3-fonts-20130212/</a></dd> -->
<dt>Issues List:</dt>
<!-- <dd><a href="http://www.w3.org/Style/CSS/Tracker/products/18">CSS3 Fonts issues in Tracker</a>
<dd><a href="https://www.w3.org/Bugs/Public/buglist.cgi?query_format=advanced&product=CSS&component=Fonts&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED">CSS3 Fonts issues in Bugzilla</a> -->
<dt>Feedback:</dt>
<dd><a href="mailto:www-style@w3.org?subject=%5B[css-fond-load-events]%5D%20feedback"
>www-style@w3.org</a>
with subject line “<kbd>[css-font-load-events]
<var>… message topic …</var></kbd>”
(<a rel="discussion" href="http://lists.w3.org/Archives/Public/www-style/"
>archives</a>)
<dt>Editor:
<dd><a href="mailto:jdaggett@mozilla.com">John Daggett (Mozilla)</a>
</dl>
<
A364
div>
<!--begin-copyright-->
<p class=copyright><a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=license>Copyright</a> © 2013 <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>
<!--end-copyright-->
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc" id=abstract>Abstract</h2>
<p>This CSS module describes events and interfaces used for dynamically
loading font resources. The contents of this specification were previously
contained in the <a
href="http://www.w3.org/TR/2013/WD-css3-fonts-20130212/">CSS3 Fonts</a>
module.
<h2 class="no-num no-toc" id=status>Status of this document</h2>
<!--begin-status-->
<p>This is a public copy of the editors' draft. It is provided for
discussion only and may change at any moment. Its publication here does
not imply endorsement of its contents by W3C. Don't cite this document
other than as 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?Subject=%5Bcss-font-load-events-3%5D%20PUT%20SUBJECT%20HERE">
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-load-events-3” in the subject, preferably like this:
“[<!---->css-font-load-events-3<!---->] <em>…summary of
comment…</em>”
<p>This document was produced by the <a href="/Style/CSS/members">CSS
Working Group</a> (part of the <a href="/Style/">Style Activity</a>).
<p>This document was produced by a group operating under the <a
href="/Consortium/Patent-Policy-20040205/">5 February 2004 W3C Patent
Policy</a>. W3C maintains a <a href="/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="/Consortium/Patent-Policy-20040205/#def-essential">Essential
Claim(s)</a> must disclose the information in accordance with <a
href="/Consortium/Patent-Policy-20040205/#sec-Disclosure">section 6 of the
W3C Patent Policy</a>.</p>
<!--end-status-->
<!--
<h3 class="no-num no-toc" id="atrisk">Features at risk</h3>
<p>The following features are at risk and may be removed when exiting CR:</p>
<ul>
</ul>
-->
<h2 class="no-num no-toc" id=contents>Table of contents</h2>
<!--begin-toc-->
<ul class=toc>
<li><a href="#introduction"><span class=secno>1 </span>Introduction</a>
<li><a href="#font-load-events"><span class=secno>2 </span>Font Load
Events</a>
<ul class=toc>
<li><a href="#document-fontloader"><span class=secno>2.1
</span>Extension to the <code>document</code> interface</a>
<li><a href="#fontloader-interface"><span class=secno>2.2 </span>The
<code>FontLoader</code> Interface</a>
<ul class=toc>
<li><a href="#events"><span class=secno>2.2.1 </span>Events</a>
<li><a href="#methods"><span class=secno>2.2.2 </span>Methods</a>
</ul>
<li><a href="#font-load-event-examples"><span class=secno>2.3
</span>Font load event examples</a>
</ul>
<li class=no-num><a href="#ch-ch-ch-changes">Changes</a>
<ul class=toc>
<li class=no-num><a href="#recent-changes"> Changes from the February
2013 CSS3 Fonts Working Draft</a>
</ul>
<li class=no-num><a href="#acknowledgments">Acknowledgments</a>
<li class=no-num><a href="#conformance"> Conformance</a>
<ul class=toc>
<li class=no-num><a href="#conventions"> Document Conventions</a>
<li class=no-num><a href="#conformance-classes"> Conformance Classes</a>
<li class=no-num><a href="#partial"> Partial Implementations</a>
<li class=no-num><a href="#experimental"> Experimental
Implementations</a>
<li class=no-num><a href="#testing"> Non-Experimental
Implementations</a>
</ul>
<li class=no-num><a href="#references">References</a>
<ul class=toc>
<li class=no-num><a href="#normative-references">Normative
References</a>
</ul>
<li class=no-num><a href="#index">Index</a>
</ul>
<!--end-toc-->
<h2 id=introduction><span class=secno>1 </span>Introduction</h2>
<p>Wait until last call...
<h2 id=font-load-events><span class=secno>2 </span>Font Load Events</h2>
<p>Since fonts defined via <code>@font-face</code> rules are loaded on
demand, pages may need to know precisely when fonts have completed
downloading before measuring text elements on the page or to show some
form of interim user interface state.
<h3 id=document-fontloader><span class=secno>2.1 </span>Extension to the
<code>document</code> interface</h3>
<p>To allow font loading to be tracked explicitly within content the
following event target is added to the <code>document</code> of the page:
<pre class=idl>partial interface Document {
readonly attribute FontLoader fontloader;
};
</pre>
<h3 id=fontloader-interface><span class=secno>2.2 </span>The
<code>FontLoader</code> Interface</h3>
<pre class=idl>dictionary CSSFontFaceLoadEventInit : EventInit {
CSSFontFaceRule fontface = null;
DOMError error = null;
};
dictionary LoadFontParameters {
DOMString font;
DOMString text = " ";
FontsReadyCallback success;
FontsReadyCallback error;
};
[Constructor(DOMString type, optional CSSFontFaceLoadEventInit eventInitDict)]
interface CSSFontFaceLoadEvent : Event {
readonly attribute CSSFontFaceRule fontface;
readonly attribute DOMError? error = null;
}
callback FontsReadyCallback = void ();
interface FontLoader : EventTarget {
// -- events for when loading state changes
attribute EventHandler <a href="#fontloader-loading">onloading</a>;
attribute EventHandler <a href="#fontloader-loadingdone">onloadingdone</a>;
// -- events for each individual font load
attribute EventHandler <a href="#fontloader-loadstart">onloadstart</a>;
attribute EventHandler <a href="#fontloader-load">onload</a>;
attribute EventHandler <a href="#fontloader-error">onerror</a>;
// check and start load if appropriate
// and fire callback when all loads complete
void <a href="#fontloader-loadfont">loadFont</a>(LoadFontParameters params);
// return whether all fonts in the fontlist are loaded
// (does not initiate load if not available)
boolean <a href="#fontloader-checkfont">checkFont</a>(DOMString font, optional DOMString text = " ");
// async notify upon completion, pending layout changes
void <a href="#fontloader-notifywhenfontsready">notifyWhenFontsReady</a>(FontsReadyCallback fontsReadyCallback);
// loading state, true while one or more fonts loading, false otherwise
readonly attribute boolean loading;
};</pre>
<p>Because font families defined with <code>@font-face</code> rules 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 id=font-load>font load</dfn> is used below to indicate
when the loading of content for a given <code>@font-face</code> rule
completes. An <code>@font-face</code> rule may list multiple alternate
resources within the ‘<code class=property>src</code>’ descriptor,
including references to local fonts, but the term font load only refers to
the loading of the finally selected resource for a given rule, not to the
loading of each individual resource.
<p class=issue>Given that the FontLoader object is defined to be attached
to the document, how will canvas worker threads load fonts?
<p class=issue>Some FontLoader methods, in particular loadFont, seem like a
good fit for <a
href="https://github.com/slightlyoff/DOMFuture/">DOMFuture</a>, a spec
that hopefully will be ready within the next month or so. Should
FontLoader be based on that or at least some parts of that? Do we need to
decide this now?
<h4 id=events><span class=secno>2.2.1 </span>Events</h4>
<p>Font load events are grouped into two general categories, events
associated with a group of fonts loading (<code
class=idl-code>loading</code>, <code class=idl-code>loading</code>) or
finer-grained events associated with each individual font loaded (<code
class=idl-code>loadstart</code>, <code class=idl-code>load</code>, <code
class=idl-code>error</code>).
<p>The following are the event handlers (and their corresponding event
handler event types) that must be supported by <code>FontLoader</code>
objects as IDL attributes:
<table class=data id=eventhandlers>
<thead>
<tr>
<th>Event handler
<th>Event handler event type
<tbody>
<tr>
<th><code class=idl-code>onloading</code>
<td><code class=idl-code>loading</code>
<tr>
<th><code class=idl-code>onloadingdone</code>
<td><code class=idl-code>loadingdone</code>
<tr>
<th><code class=idl-code>onloadstart</code>
<td><code class=idl-code>loadstart</code>
<tr>
<th><code class=idl-code>onload</code>
<td><code class=idl-code>load</code>
<tr>
<th><code class=idl-code>onerror</code>
<td><code class=idl-code>error</code>
</table>
<p>To <dfn id=fire-a-font-load-event>fire a font load event</dfn> named
<var>e</var> at a <code>FontLoader</code> target 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
<code>CSSFontFaceLoadEvent</code> interface that also meets these
conditions:
<ol>
<li>The <code class=idl-code>fontface</code> attribute is initialized to
the given <var>font face rule</var>.
<li>The <code class=idl-code>error</code> attribute is initialized to the
given <var>error</var>, if one occurred during the font load.
</ol>
<p>When the user agent determines that one or more fonts defined via
<code>@font-face</code> rules in a document <var>doc</var> need to be
loaded, it must run the following steps:
<ol>
<li>Let <var>font loader</var> be the value of the <code
class=idl-code>fontloader</code> attribute of <var>doc</var>.
<li>Set the <code class=idl-code>loading</code> attribute of <var>font
loader</var> to true.
<li><a href="#fire-a-font-load-event">Fire a font load event</a> named <a
id=fontloader-loading><code class=idl-code>"loading"</code></a> at
<var>font loader</var> with <code class=idl-code>fontface</code> set to
the first <code>@font-face</code> rule.
<li>When the user agent begins loading the first resource for a given
<code>@font-face</code> rule, it must <a
href="#fire-a-font-load-event">fire a font load event</a> named <a
id=fontloader-loadstart><code class=idl-code>"loadstart"</code></a> at
<var>font loader</var> with <code class=idl-code>fontface</code> set to
the given <code>@font-face</code> rule.
</ol>
<p>These steps imply that if fonts are loaded concurrently, the <code
class=idl-code>loading</code> event will fire just once, while the <code
class=idl-code>loadstart</code> event will be fired once for each
<code>@font-face</code> rule whose load is initiated. User agents must
only set the <code class=idl-code>error</code> attribute of a font load
event to a non-null value in the cases noted in this section.
<p>The term “font load” covers any of the resources listed in the
‘src’ descriptor, including local fonts. When multiple resources are
listed, the “font load” is the first resource in the list to
successfully load or the error that occurs on the last resource for which
a load is attempted.
<p>When the user agent completes each font load for a document
<var>doc</var>, it must run the following steps:
<ol>
<li>Let <var>font loader</var> be the value of the <code
class=idl-code>fontloader</code> attribute of <var>doc</var>.
<li>If a font data was successfully loaded and activated, <a
href="#fire-a-font-load-event">fire a font load event</a> named <a
id=fontloader-load><code class=idl-code>"load"</code></a> at <var>font
loader</var> with <code class=idl-code>fontface</code> set to the
<code>@font-face</code> rule for which the font data was loaded.
<li>Otherwise, <a href="#fire-a-font-load-event">fire a font load
event</a> named <a id=fontloader-error><code
class=idl-code>"error"</code></a> at <var>font loader</var> with <code
class=idl-code>fontface</code> set to the <code>@font-face</code> rule
for which the error occurred. If the font data can't be loaded <code
class=idl-code>error</code> is set to one of the standard
<code>DOMError</code> types (e.g. <code>NotFoundError</code>,
<code>NetworkError</code>). If the font data was downloaded but invalid,
then <code class=idl-code>error</code> is set to
<code>"InvalidFontDataError"</code>. If several resources are listed in
the <code>src</code> descriptor, the error that caused the last font
resource in the list to fail must be used.
</ol>
<p>When the user agent completes the final font load for document
<var>doc</var>, after all pending layout operations that might affect font
selection have completed and no font loads are pending, it must run the
following steps:
<ol>
<li>Let <var>font loader</var> be the value of the <code
class=idl-code>fontloader</code> attribute of <var>doc</var>.
<li>Set the <code class=idl-code>loading</code> attribute of <var>font
loader</var> to false.
<li><a href="#fire-a-font-load-event">Fire a font load event</a> named <a
id=fontloader-error><code class=idl-code>"loadingdone"</code></a> at
<var>font loader</var> with <code class=idl-code>fontface</code> set to
the <code>@font-face</code> rule of the last font loaded.
</ol>
<p>For example, if three fonts are loaded at the same time, a <code
class=idl-code>"loading"</code> event followed by three <code
class=idl-code>"loadstart"</code> events and three <code
class=idl-code>"load"</code> or <code class=idl-code>
22CE
"error"</code>
events, followed by a <code class=idl-code>"loadingdone"</code> event will
occur.
<p class=issue>Errors will go "unreported" when using the general category
of font load events (i.e. <code class=idl-code>"loading"</code> and <code
class=idl-code>"loadingdone"</code>). This seems fine but need to confirm
this.
<h4 id=methods><span class=secno>2.2.2 </span>Methods</h4>
<p>The methods <code class=idl-code>loadFont</code> and <code
class=idl-code>checkFont</code> must determine whether all fonts in the
given font list have been loaded and are available. If all fonts are
available, <code class=idl-code>checkFont</code> must return true, false
if one or more fonts are not available. In the case of <code
class=idl-code>loadFont</code>, if any fonts are downloadable fonts and
have not already been loaded, the user agent must initiate the load of
each of these fonts.
<p>The <a id=fontloader-loadfont><code
class=idl-code>loadFont(params)</code></a> method must use these steps:
<ol>
<li>Parse the value of the <code class=idl-code>font</code> member of
<code class=idl-code>params</code>, using the CSS value syntax of the
‘<code class=property>font</code>’ property.
<li>If a syntax error occurs, return.
<li>Otherwise, let <var>font family list</var> be the set of families and
<var>font style</var> be the other font style attributes.
<li>For each family in <var>font family list</var>, use the font matching
rules to select the font faces that match the <var>font style</var>. In
the case where these are font faces defined via <code>@font-face</code>
rules, the use of ‘<code class=property>unicode-range</code>’ means
that this may be more than just a single font face.
<li>Remove from the set of font faces all faces that have defined ‘<code
class=property>unicode-range</code>’ values that don't intersect the
range of character values in the <code class=idl-code>text</code> member
of <code class=idl-code>params</code> and set this to be the <var>font
load list</var>.
<li>For all of the font faces in the <var>font load list</var>, initiate
the load of any font that has not already been loaded and return.
<li>When all fonts in the <var>font load list</var> have been loaded, fire
the appropriate callback handler. If all fonts loaded successfully, call
the callback specified by the <code class=idl-code>success</code> member
of <code class=idl-code>params</code>. If an error occurred with any one
of the fonts in the <var>font load list</var> or if the list is empty,
call the callback specified by the <code class=idl-code>error</code>
member of <code class=idl-code>params</code>.
</ol>
<p>Callbacks for <code class=idl-code>loadFont</code> fire in addition to
the callbacks that fire due to font event handlers.
<p>The <a id=fontloader-checkfont><code class=idl-code>checkFont(font,
text)</code></a> method must use these steps:
<ol>
<li>Parse the value of the <code class=idl-code>font</code> parameter,
using the CSS value syntax of the ‘<code class=property>font</code>’
property.
<li>If a syntax error occurs, return <code class=idl-code>false</code>.
<li>Otherwise, let <var>font family list</var> be the set of families and
<var>font style</var> be the other font style attributes.
<li>For each family in <var>font family list</var>, use the font matching
rules to select the font faces that match the <var>font style</var>. In
the case where these are font faces defined via <code>@font-face</code>
rules, the use of ‘<code class=property>unicode-range</code>’ means
that this may be more than just a single font face.
<li>Remove from the set of font faces all faces that have defined ‘<code
class=property>unicode-range</code>’ values that don't intersect the
range of character values in the <code class=idl-code>text</code>
parameter and set this to be the <var>font load list</var>.
<li>If the <var>font load list</var> contains no font faces, return <code
class=idl-code>false</code>.
<li>If all fonts in the <var>font load list</var> have already
successfully been loaded, return <code class=idl-code>true</code>.
Otherwise, return <code class=idl-code>false</code>.
</ol>
<p>The <code class=idl-code>font</code> parameter of <code
class=idl-code>checkFont</code> and the <code class=idl-code>font</code>
member of <code class=idl-code>params</code> parameter of <code
class=idl-code>loadFont</code> both specify the list of fonts to load.
These values must be parsed using the same syntax as values for the CSS
‘<code class=property>font</code>’ property, the same way the <code
class=idl-code>font</code> attribute of the
<code>CanvasRenderingContext2D</code> is interpreted. <a href="#HTML5"
rel=biblioentry>[HTML5]<!--{{!HTML5}}--></a> This yields a list of font
families along with font style attributes.
<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
id=fontloader-notifywhenfontsready><code
class=idl-code>notifyWhenFontsReady</code></a> method provides a way for
authors to avoid having to keep track of which fonts have or haven't been
loaded before examining content affected by which font is used.
<p>The <code class=idl-code>notifyWhenFontsReady(fontsReadyCallback)</code>
method must use these steps:
<ol>
<li>Let <var>font loader</var> be the value of the <code
class=idl-code>fontloader</code> attribute of <var>doc</var>.
<li>Add the value of the <code class=idl-code>fontsReadyCallback</code>
parameter to the <var>notify</var> callback list of the <var>font
loader</var> and return.
<li>Once all pending layout operations have completed, determine whether
font resources need to be loaded.
<li>If no loads are in progress, copy the contents of the
<var>notify</var> callback list to the <var>notify pending</var> list of
the <var>font loader</var> and clear out the <var>notify</var> list.
After the <code class=idl-code>"loadingdone"</code> event fires, call
each of the callbacks in the <var>notify pending</var> list and clear out
the <var>notify pending</var> list.
<li>Otherwise, after all font loads complete and subsequent layout
operations finish, again check whether loads are in progress. If no loads
are in progress, execute the previous step. If fonts are still loading,
continue waiting until those loads complete and repeat this step.
</ol>
<p>Authors should note here that the callback only fires once, the method
needs to be called again when further font loads might occur. This method
is similar to the callback function of the <code
class=idl-code>"loadingdone"</code> event handler, except that in this
case the callback 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 sync code to font loads without the need to keep track
of what fonts are needed and precisely when they load.
<p>Note that the user agent may need to iterate over multiple font loads
before the notify callback is called. 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
notify callback only fires after layout operations complete and no
additional font loads are necessary.
<h3 id=font-load-event-examples><span class=secno>2.3 </span>Font load
event examples</h3>
<div class=example>
<p>To show content only after all font loads complete:</p>
<pre> document.fontloader.onloadingdone = function() {
var content = document.getElementById("content");
content.style.visibility = "visible";
}
</pre>
</div>
<div class=example>
<p>Drawing text in a canvas with a downloadable font, explicitly
initiating the font download and drawing upon completion:</p>
<pre> function drawStuff() {
var ctx = document.getElementById("c").getContext("2d");
ctx.fillStyle = "red";
ctx.font = "50px MyDownloadableFont";
ctx.fillText("Hello!", 100, 100);
}
document.fontloader.loadFont({font: "50px MyDownloadableFont",
success: drawStuff,
error: handleError});</pre>
</div>
<div class=example>
<p>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:</p>
<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.fontloader.notifyWhenFontsReady(measureTextElements);
}
</pre>
</div>
<div class=example>
<p>Unlike the per-font load events, the <code
class=idl-code>"loadingdone"</code> event only fires after all font
related loads have completed <strong>and</strong> text has been laid out
without causing additional font loads:</p>
<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; }
<p><a href="https://twitter.com/maji_kichi_/status/292546415685693440/photo/1" style="text-decoration: none;">納豆はいかがでしょうか</a></p>
</pre>
<p>In this situation, the user agent first downloads ‘<code
class=css>latinserif.woff</code>’ 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 ‘<code
class=css>mincho.woff</code>’ is downloaded. Only after the second font
is downloaded and the Japanese text laid out does the <code
class=idl-code>"loadingdone"</code> event fire.</p>
</div>
<h2 class=no-num id=ch-ch-ch-changes>Changes</h2>
<h3 class=no-num id=recent-changes> Changes from the <a
href="http://www.w3.org/TR/2013/WD-css3-fonts-20130212/">February 2013
CSS3 Fonts Working Draft</a></h3>
<p>Major changes include:
<ul>
<li>Add details of font load errors
</ul>
<h2 class=no-num id=acknowledgments>Acknowledgments</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-num id=conformance> Conformance</h2>
<h3 class=no-num id=conventions> Document Conventions</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
href="#RFC2119" rel=biblioentry>[RFC2119]<!--{{!RFC2119}}--></a>
<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.
</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.
<h3 class=no-num id=conformance-classes> Conformance Classes</h3>
<p>Conformance to CSS Font Load Events Level 3 Module is defined for three
conformance classes:
<dl>
<dt><dfn id=style-sheet title="style sheet!!as conformance class">style
sheet</dfn>
<dd>A <a href="http://www.w3.org/TR/CSS21/conform.html#style-sheet">CSS
style sheet</a>.
<dt><dfn id=renderer>renderer</dfn>
<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><dfn id=authoring-tool>authoring tool</dfn>
<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 CSS Font Load Events Level 3 Module if
all of its declarations that use properties defined in this module have
values that are valid according to the generic CSS grammar and the
individual grammars of each property as given in this module.
<p>A renderer is conformant to CSS Font Load Events Level 3 Module if, in
addition to interpreting the style sheet as defined by the appropriate
specifications, it supports all the features defined by CSS Font Load
Events Level 3 Module 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 CSS Font Load Events Level 3 Module
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-num id=partial> Partial Implementations</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.
<h3 class=no-num id=experimental> Experimental Implementations</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.
<p>Prior to a specification reaching the Candidate Recommendation stage in
the W3C process, all implementations of a CSS feature are considered
experimental. The CSS Working Group recommends that implementations use a
vendor-prefixed syntax for such features, including those in W3C Working
Drafts. This avoids incompatibilities with future changes in the draft.
<h3 class=no-num id=testing> Non-Experimental Implementations</h3>
<p>Once a specification reaches the Candidate Recommendation stage,
non-experimental implementations are possible, and implementors should
release an unprefixed implementation of any CR-level feature they can
demonstrate to be correctly implemented according to spec.
<p>To establish and maintain the interoperability of CSS across
implementations, the CSS Working Group requests that non-experimental CSS
renderers submit an implementation report (and, if necessary, the
testcases used for that implementation report) to the W3C before releasing
an unprefixed implementation of any CSS features. Testcases submitted to
W3C are subject to review and correction by the CSS Working Group.
<p>Further information on submitting testcases and implementation reports
can be found from on the CSS Working Group's website at <a
href="http://www.w3.org/Style/CSS/Test/">http://www.w3.org/Style/CSS/Test/</a>.
Questions should be directed to the <a
href="http://lists.w3.org/Archives/Public/public-css-testsuite">public-css-testsuite@w3.org</a>
mailing list.
<h2 class=no-num id=references>References</h2>
<h3 class=no-num id=normative-references>Normative References</h3>
<!--begin-normative-->
<!-- Sorted by label -->
<dl class=bibliography>
<dt style="display: none"><!-- keeps the doc valid if the DL is empty -->
<!---->
<dt id=CSS3-FONTS>[CSS3-FONTS]
<dd>John Daggett. <a
href="http://www.w3.org/TR/2012/WD-css3-fonts-20121211/"><cite>CSS Fonts
Module Level 3.</cite></a> 11 December 2012. W3C Working Draft. (Work in
progress.) URL: <a
href="http://www.w3.org/TR/2012/WD-css3-fonts-20121211/">http://www.w3.org/TR/2012/WD-css3-fonts-20121211/</a>
</dd>
<!---->
<dt id=DOM>[DOM]
<dd>Anne van Kesteren; et al. <a
href="http://www.w3.org/TR/2012/WD-dom-20121206/"><cite>DOM4.</cite></a>
6 December 2012. W3C Working Draft. (Work in progress.) URL: <a
href="http://www.w3.org/TR/2012/WD-dom-20121206/">http://www.w3.org/TR/2012/WD-dom-20121206/</a>
</dd>
<!---->
<dt id=HTML5>[HTML5]
<dd>Ian Hickson. <a
href="http://www.w3.org/TR/2012/CR-html5-20121217/"><cite>HTML5.</cite></a>
17 December 2012. W3C Candidate Recommendation. (Work in progress.) URL:
<a
href="http://www.w3.org/TR/2012/CR-html5-20121217/">http://www.w3.org/TR/2012/CR-html5-20121217/</a>
</dd>
<!---->
<dt id=RFC2119>[RFC2119]
<dd>S. Bradner. <a href="http://www.ietf.org/rfc/rfc2119.txt"><cite>Key
words for use in RFCs to Indicate Requirement Levels.</cite></a> Internet
RFC 2119. URL: <a
href="http://www.ietf.org/rfc/rfc2119.txt">http://www.ietf.org/rfc/rfc2119.txt</a>
</dd>
<!---->
</dl>
<!--end-normative-->
<!--{{!CSS3-FONTS}}-->
<!--{{!DOM}}-->
<!-- <h3 class="no-num" id="other-references">Other References</h3> -->
<!--begin-informative-->
<!-- Sorted by label -->
<dl class=bibliography>
<dt style="display: none"><!-- keeps the doc valid if the DL is empty -->
<!---->
</dl>
<!--end-informative-->
<h2 class=no-num id=index>Index</h2>
<!--begin-index-->
<ul class=indexlist>
<li>authoring tool, <a href="#authoring-tool" title="authoring
tool"><strong>#</strong></a>
<li>fire a font load event, <a href="#fire-a-font-load-event" title="fire
a font load event"><strong>2.2.1</strong></a>
<li>font load, <a href="#font-load" title="font
load"><strong>2.2</strong></a>
<li>renderer, <a href="#renderer" title=renderer><strong>#</strong></a>
<li>style sheet
<ul>
<li>as conformance class, <a href="#style-sheet" title="style sheet, as
conformance class"><strong>#</strong></a>
</ul>
</ul>
<!--end-index-->
</html>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-declaration:"~/SGML/HTML4.decl"
sgml-default-doctype-name:"html"
sgml-minimize-attributes:t
sgml-nofill-elements:("pre" "style" "br")
sgml-live-element-indicator:t
sgml-omittag:nil
sgml-shorttag:nil
sgml-namecase-general:t
sgml-general-insert-case:lower
sgml-always-quote-attributes:t
sgml-indent-step:nil
sgml-indent-data:t
sgml-parent-document:nil
sgml-exposed-tags:nil
sgml-local-catalogs:nil