CSS Font Loading Module Level 3

要約

この~CSS~moduleは、~font資源を動的に~loadするために利用される~event, および~interfaceについて述べる。 ◎ This CSS module describes events and interfaces used for dynamically loading font resources.

~CSSisaLANG

この文書の位置付け

これは編集者草案の公開の複製です… 【以下,この節の他の内容は CSS 日本語訳 共通ページに委譲。】

1. 序論

~CSSでは、作者は `font-face$at 規則を介して,~custom~fontを~webから~loadする( “読み込む” )ことが許容される。 これの利用は,~stylesheetを著作するときは容易であるが、~scriptを介して動的に利用するときはずっと困難になる。 ◎ CSS allows authors to load custom fonts from the web via the @font-face rule. While this is easy to use when authoring a stylesheet, it’s much more difficult to use dynamically via scripting.

更には、~CSSでは,~UAが ~fontを実際にいつ~loadするか選べるようにされているので、ある~font~face( “書体” )が頁~上のどこからも現在利用されていない場合、ほとんどの~UAは,それに結付けられている~fileを~downloadしない。 このことは、当の~font~faceを後で利用する場合,遅延を被ることを意味する — ~UAは,それが結局は利用されると気付いたとき初めて、~font~fileを~download/構文解析し始めるので。 ◎ Further, CSS allows the user agent to choose when to actually load a font; if a font face isn’t currently 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.

この仕様は、~CSS内の~font~faceに対する~interfaceを定義して,~font~faceを~scriptから容易に作成する/~loadすることを可能にする。 それはまた、頁に利用されている[ 個々の~font/ すべての~font ]の~loading状態s( “status” )を追跡するための~methodも供する。 ◎ 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.

この仕様を成す一部のものの挙動は、通常の ECMAScript ~objを利用して定義されている — 種々のものは`~promise$を内部的に利用しており†、 `FontFaceSet$I は `Set^I を内部的に利用している。 編集者は、これらの~obj(およびそれらの~prototype-chain)が本来のそれであり,いかなる作者~codeからも影響されていないものと~~見なして記している††。 この記し方でよいのか? そうであれば,そのことを仕様~内にどう指示すべきか? ◎ Several things in this spec use normal ES objects to define behavior, such as various things using Promises internally, and FontFaceSet using a Set internally. I believe the intention here is that these objects (and their prototype chains) are pristine, unaffected by anything the author has done. Is this a good intention? If so, how should I indicate this in the spec?

【† この訳では、~promiseに関する用語については, Writing Promise-Using 仕様 に定義される用語にリンク(和訳)をあてがっている。 また、原文の用語 “fulfill((~promiseを)~~充足する)” は、実際には, Promise-Using 仕様の “resolve (`解決する$)” を意味するので、この訳では,それに倣って対訳を違えている。 】【†† Promise-Using 仕様では、このことを表す用語として,(当の~objの ECMAScript ~propの) 初期~値( initial value ) が定義されている。 】

【この訳に固有の表記規約】

この訳の,~algoや定義の記述に利用されている各種記号( ~LET, 此れ, ~IF, ~THROW, 等々)の意味や定義の詳細は,~SYMBOL_DEF_REFを~~参照されたし。

語 `~promise@ は、 `Promise$I ~obj(次~節)の略記である。

“~obj %O に対する %O . `someSlot^sl という表記は、 “%O の `someSlot^sl 内部~slot” の略記である。

原文に利用されている HTML 用語は W3C 版 HTML を参照しているが、ここでは WHATWG HTML を参照するように置換している。

1.1. 値

この仕様は、 ECMAScript 6 に定義される `Promise$I を利用する。 HTML5Rocks にて,格好の `Promise^I の入門的な紹介日本語訳 )を読める。 ◎ This specification uses Promises, which are defined in ECMAScript 6. HTML5Rocks has some good tutorial material introducing Promises.

1.2. ~task源

この仕様において,`~taskを~queueする$ときに利用する`~task源$は、 "font loading" ~task源である。 ◎ Whenever this specification queues a task, it queues it onto the "font loading" task source.

2. `FontFace^I ~interface

`FontFace$I ~interfaceは、利用できる単独の~font~faceを表現する。 `FontFace^I ~objは、~CSS `font-face$at 規則により,暗黙的に定義され、また ~urlや~binary~dataから手動で構築することもできる。 ◎ The FontFace interface represents a single usable font face. CSS @font-face rules implicitly define FontFace objects, or they can be constructed manually from a url or binary data.

typedef (`ArrayBuffer$I or `ArrayBufferView$I) `BinaryData@I;

dictionary `FontFaceDescriptors@I {
  `CSSOMString$ `style@dm = "normal";
  `CSSOMString$ `weight@dm = "normal";
  `CSSOMString$ `stretch@dm = "normal";
  `CSSOMString$ `unicodeRange@dm = "U+0-10FFFF";
  `CSSOMString$ `variant@dm = "normal";
  `CSSOMString$ `featureSettings@dm = "normal";
  `CSSOMString$ `variationSettings@dm = "normal";
  `CSSOMString$ `display@dm = "auto";
};

enum `FontFaceLoadStatus@I {
    `unloaded@l, `loading@l, `loaded@l, `error@l
};

[
  `FontFace$mC(
      `CSSOMString$ %family,
      (`CSSOMString$ or `BinaryData$I) %source,
      optional `FontFaceDescriptors$I %descriptors
  ),
  `Exposed$=(Window,Worker)
]
interface `FontFace@I {
  attribute `CSSOMString$ `family$m;
  attribute `CSSOMString$ `style$m;
  attribute `CSSOMString$ `weight$m;
  attribute `CSSOMString$ `stretch$m;
  attribute `CSSOMString$ `unicodeRange$m;
  attribute `CSSOMString$ `variant$m;
  attribute `CSSOMString$ `featureSettings$m;
  attribute `CSSOMString$ `variationSettings$m;
  attribute `CSSOMString$ `display$m;

  readonly attribute `FontFaceLoadStatus$I `status$m;

  Promise<`FontFace$I> `load$m();
  readonly attribute Promise<`FontFace$I> `loaded$m;
};

すべての語 “文書” について、どの文書が参照されているか明らかになるよう明確化する — ~objは文書~間を移動し得るので。 ◎ Clarify all mentions of "the document" to be clear about which document is being referenced, since objects can move between documents.

`family@m
`style@m
`weight@m
`stretch@m
`unicodeRange@m
これらの属性はいずれも、[ 此れが表現する~font~face ]の,[ `font-face$at 規則にて定義される,対応する名前の記述子 ]により定義されるある側面を表現する。 これらは、その対応する記述子と同じに構文解析される。 これらは、`~font照合$~algoにより利用されるが,それ以外の効果はない。 ◎ family, of type CSSOMString ◎ style, of type CSSOMString ◎ weight, of type CSSOMString ◎ stretch, of type CSSOMString ◎ unicodeRange, of type CSSOMString ◎ These attributes all represent the corresponding aspects of a font face, as defined by the descriptors defined in the CSS @font-face rule. They are parsed the same as the corresponding @font-face descriptors. They are used by the font matching algorithm, but otherwise have no effect.
例えば,[ `style$m が `italic^l にされた `FontFace$I ]は、~italic~font~faceを 表現する — 当の~font~faceを~italicにするものではない。 ◎ For example, a FontFace with a style of "italic" represents an italic font face; it does not make the font face italic.
取得子は、属性に結付けられている文字列を返す。 ◎ On getting, return the string associated with this attribute.
設定子は、まず,所与の文字列を対応する `font-face$at 記述子の`文法に則って構文解析する$。 文法に合致しない場合は `SyntaxError^E を投出し、他の場合は[[ 構文解析した結果の値 ]を直列化した結果 ]に設定する。 ◎ On setting, parse the string according to the grammar for the corresponding @font-face descriptor. If it does not match the grammar, throw a SyntaxError; otherwise, set the attribute to the serialization of the parsed value.
`variant@m
`featureSettings@m
`variationSettings@m
`display@m
これらの属性はいずれも、各種[ `font-face$at 規則にて定義される,対応する名前の記述子 ]と同じ意味を持ち,同じように構文解析される。 ◎ variant, of type CSSOMString ◎ featureSettings, of type CSSOMString ◎ variationSettings, of type CSSOMString ◎ display, of type CSSOMString ◎ These attributes have the same meaning, and are parsed the same as, the corresponding descriptors in the CSS @font-face rules.
これらは、~fontが~supportする特定の特色機能を 可能化-/不能化- する。 前述の属性と違って、これらの属性は,実際に,此れが表現する~font~faceに影響する。 それ以外の点では、取得子/設定子の挙動は,前述の属性( `family$m 他)と同じである。 ◎ They turn on or off specific features in fonts that support them. Unlike the previous attributes, these attributes actually affect the font face. ◎ On getting, return the string associated with this attribute. ◎ On setting, parse the string according to the grammar for the corresponding @font-face descriptor. If it does not match the grammar, throw a SyntaxError; otherwise, set the attribute to the serialization of the parsed value.
`FontFaceLoadStatus$I `status@m
この属性は、此れが表現する~font~faceの現在の状態sを反映する。 `FontFace$I が新たに作成された時点では `unloaded^l にされ~MUST。 ◎ status, of type FontFaceLoadStatus, readonly ◎ This attribute reflects the current status of the font face. It must be "unloaded" for a newly-created FontFace.

次のいずれかの場合に変化し得る:

  • 作者は、 `FontFace$I 上の `load()$m ~methodを通して,当の~font~faceを~loadするよう要請することに因り,明示的に変更できる。
  • ~UAにおいて,~screen上に何らかの~textを描くため 当の~font~faceが必要になることが検出されることに因り、暗黙的に変更され得る。
◎ It can change due to an author explicitly requesting a font face to load, such as through the load() method on FontFace, or implicitly by the user agent, due to it detecting that the font face is needed to draw some text on the screen.
Promise<`FontFace$I> `loaded@m
この属性は、此れが表現する~font~faceの `FontStatusPromise$sl を反映する。 ◎ loaded, of type Promise<FontFace>, readonly ◎ This attribute reflects the [[FontStatusPromise]] of the font face.

各 `FontFace$I ~objは、次に挙げる内部~slotを包含する: ◎ ↓

`FontStatusPromise@sl
この~slotは、~fontの状態sを追跡するためにある。 状態sは、 解決待ちの状態から開始され,[ ~fontが成功裡に~loadされ構文解析されたか / ~errorに~~遭遇した ]ときに,それに応じて[ `解決され$る/`却下され$る ]。 ◎ All FontFace objects contain an internal [[FontStatusPromise]] slot, 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.
`Urls@sl
`Data@sl
いずれか片方は ~NULL, もう片方は 非 ~NULL になる(非 ~NULL の方は、渡されたか~dataに基づいて,構築子により設定される)。 ◎ All FontFace objects also contain internal [[Urls]] and [[Data]] slots, of which one is null and the other is not null (the non-null one is set by the constructor, based on which data is passed in).

2.1. 構築子

`FontFace$I は、次のいずれかから構築できる:

  • ~font~face~fileを指している URL
  • ~font~faceの~binary表現を包含している `ArrayBuffer$I (または `ArrayBufferView$I )
◎ A FontFace 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.

`FontFace(family, source, descriptors )@m ~methodの被~call時には、次の手続きを実行する: ◎ When the FontFace(family, source, descriptors) method is called, execute these steps:

  1. %~font~face ~LET 新たな `FontFace$I ~obj
  2. %~font~face の `status$m 属性 ~SET `unloaded^l
  3. %状態s~promise ~LET `新たな~promise$
  4. %~font~face . `FontStatusPromise$sl ~SET %状態s~promise ◎ Let font face be a fresh FontFace object. Set font face’s status attribute to "unloaded", Set its internal [[FontStatusPromise]] slot to a fresh pending Promise object.
  5. 各~引数を`文法に則って構文解析する$:

      • %family を構文解析する
      • %descriptors の各 `FontFaceDescriptors$I ~memberは, `font-face$at 規則の対応する記述子の文法に則って構文解析する。
      • %source 引数は,それが `CSSOMString$I ならば, `font-face$at 規則の `src^d 記述子の文法に則って構文解析する。
      ◎ Parse the family argument, and the members of the descriptors argument, according to the grammars of the corresponding descriptors of the CSS @font-face rule. If the source argument is a CSSOMString, parse it according to the grammar of the CSS src descriptor of the @font-face rule.\
    1. ~IF[ 前~段のいずれかの構文解析-に失敗した ]:

      1. `SyntaxError^E 例外で %状態s~promise を`却下する$
      2. %~font~face の対応している各種~属性 ~SET 空~文字列
      3. %~font~face の `status$m 属性 ~SET `error^l
      ◎ If any of them fail to parse correctly, reject font face’s [[FontStatusPromise]] with a DOMException named "SyntaxError", set font face’s corresponding attributes to the empty string, and set font face’s status attribute to "error".\
    2. ~ELSE ⇒ %~font~face の対応する各種~属性 ~SET 構文解析された結果の各~値を直列化した結果 ◎ Otherwise, set font face’s corresponding attributes to the serialization of the parsed values.

    注記: %source 引数に `http://example.com/myFont.woff^l の様な裸の~urlを渡しても働かないことになる — 少なくとも, `url(http://example.com/myFont.woff)^l の様に `url()$css 関数で包装する必要がある。 この不便さの引き換えに,次が可能になる:

    • 複数の~fallback~fontを指定する。
    • 各~fallback~fontに対し,その型を指定する。
    • 局所~fontを容易に参照する。
    ◎ Note: Note that this means that passing a naked url as the source argument, like "http://example.com/myFont.woff", won’t work - it needs to be at least wrapped in a url() function, like "url(http://example.com/myFont.woff)". 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.

    基底~urlを定義して、相対~urlを解決できるようにする必要がある。 文書の~urlにするべきか? ~workerについてもそうするのが正しいのか? あるいは~worker~urlを利用すべきか? それは常に定義されているのか? ◎ Need to define the base url, so relative urls can resolve. Should it be the url of the document? Is that correct for workers too, or should they use their worker url? Is that always defined?

  6. ~RET %~font~face — ただし,以降の手続きも並列的に続行する: ◎ Return font face.\
  7. ~IF[ %~font~face の `status$m ~EQ `error^l ] ⇒ ~RET ◎ If font face’s status is "error", terminate this algorithm; otherwise, complete the rest of these steps asynchronously.
  8. ~IF[ %source は `CSSOMString$I である ] ⇒ %~font~face . `Urls$sl ~SET %source ◎ If the source argument was a CSSOMString, set font face’s internal [[Urls]] slot to the string.
  9. ~ELSE( %source は `BinaryData$I である) ⇒ %~font~face . `Data$sl ~SET %source ◎ If the source argument was a BinaryData, set font face’s internal [[Data]] slot to the passed argument.
  10. %~data ~LET %~font~face . `Data$sl ◎ ↓
  11. ~IF[ %~data ~EQ ~NULL ] ⇒ ~RET ◎ If font face’s [[Data]] slot is not null,\
  12. 次を走らす`~taskを~queueする$: ◎ queue a task to run the following steps synchronously:

    1. %~font~face の `status$m 属性 ~SET `loading^l ◎ Set font face’s status attribute to "loading".
    2. %~font~face を`含む$ような ~EACH ( `FontFaceSet$I ~obj %~face~set ) に対し: ◎ For each FontFaceSet font face is in:

      1. ~IF[ %~face~set . `LoadingFonts$sl は空である ] ⇒ `~loadingに切替える$( %~face~set ) ◎ If the FontFaceSet’s [[LoadingFonts]] list is empty, switch the FontFaceSet to loading.
      2. %~face~set . `LoadingFonts$sl に %~font~face を付加する ◎ Append font face to the FontFaceSet’s [[LoadingFonts]] list.
  13. %~data を~fontとして構文解析するよう試みる — 完了した時点で,次を走らす`~taskを~queueする$: ◎ Asynchronously, attempt to parse the data in it as a font. When this is completed, successfully or not, queue a task to run the following steps synchronously:

    1. ~IF[ 構文解析に成功した( %~font~face は今や構文解析された~fontを表現する ) ]: ◎ If the load was successful, font face now represents the parsed font;\

      1. %~font~face で %状態s~promise を`解決する$ 【この段は次の段より後にするべき?(下の “却下-” も同様)】 ◎ fulfill font face’s [[FontStatusPromise]] with font face,\
      2. %~font~face の `status$m 属性 ~SET `loaded^l ◎ and set its status attribute to "loaded".
      3. %~font~face を`含む$ような ~EACH ( `FontFaceSet$I ~obj %~face~set ) に対し: ◎ For each FontFaceSet font face is in:

        1. %~face~set . `LoadedFonts$sl に %~font~face を追加する ◎ Add font face to the FontFaceSet’s [[LoadedFonts]] list.
        2. %~face~set . `LoadingFonts$sl から %~font~face を除去する ◎ Remove font face from the FontFaceSet’s [[LoadingFonts]] list.\
        3. ~IF[ %~face~set . `LoadingFonts$sl は空である ] ⇒ `~load済みに切替える$( %~face~set ) ◎ If font was the last item in that list (and so the list is now empty), switch the FontFaceSet to loaded.
    2. ~ELSE(構文解析に失敗した): ◎ Otherwise,\

      1. `SyntaxError^E 例外で %状態s~promise を`却下する$ ◎ reject font face’s [[FontStatusPromise]] with a DOMException named "SyntaxError" and\
      2. %~font~face の `status$m 属性 ~SET `error^l ◎ set font face’s status attribute to "error".
      3. %~font~face を`含む$ような ~EACH ( `FontFaceSet$I ~obj %~face~set ) に対し: ◎ For each FontFaceSet font face is in:

        1. %~face~set . `FailedFonts$sl に %~font~face を追加する ◎ Add font face to the FontFaceSet’s [[FailedFonts]] list.
        2. %~face~set . `LoadingFonts$sl から %~font~face を除去する ◎ Remove font face from the FontFaceSet’s [[LoadingFonts]] list.\
        3. ~IF[ %~face~set . `LoadingFonts$sl は空である ] ⇒ `~load済みに切替える$( %~face~set ) ◎ If font was the last item in that list (and so the list is now empty), switch the FontFaceSet to loaded.

注記: 新たに構築された `FontFace^I ~objは、当の[ 文書 / ~worker~thread ]に対する文脈に結付けられている `FontFaceSet^I 【`~font~source$】 に自動的に追加されることはない。 このことは、新たに構築された~fontは~preloadされ得るが、それを実際に利用できるのは, `FontFaceSet^I に明示的に追加された後になることを意味する。 `FontFaceSet^I についてのより完全な記述は、以降の節を見よ。 ◎ Note: Newly constructed FontFace objects are not automatically added to the FontFaceSet associated with a document or a context for a worker thread. This means that while newly constructed fonts can be preloaded, they cannot actually be used until they are explicitly added to a FontFaceSet. See the following section for a more complete description of FontFaceSet.

2.2. `load()^m ~method

`FontFace$I の `load()$m ~methodは、~urlに基づく~font~faceに対し,その~font~dataを要請して~loadするよう強制する。 ~binary~dataから構築された~fontや[ ~load中にある/~load済みの ]~fontに対しては何もしない。 ◎ The load() method of FontFace 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.

`load()@m ~methodの被~call時には、次の手続きを実行する: ◎ When the load() method is called, execute these steps:

  1. %状態s~promise ~LET 此れ . `FontStatusPromise$sl ◎ ↓
  2. ~IF[ 此れ . `Urls$sl ~EQ ~NULL ]~OR[ 此れの `status$m 属性 ~NEQ `unloaded^l ] ⇒ ~RET %状態s~promise ◎ Let font face be the FontFace object on which this method was called. ◎ If font face’s [[Urls]] slot is null, or its status attribute is anything other than "unloaded", return font face’s [[FontStatusPromise]] and abort these steps.
  3. 此れの `status$m 属性 ~SET `loading^l ◎ Otherwise, set font face’s status attribute to "loading",\
  4. ~RET %状態s~promise — ただし,以降の手続きも並列的に続行する: ◎ return font face’s [[FontStatusPromise]], and continue executing the rest of this algorithm asynchronously.
  5. 此れの `Urls$sl ~slotの値を利用して、[ それが `font-face$at 規則の `src$d 記述子の値であった ]かのように,[ `CSS-FONTS-3$r による定義に従って~fontを~loadする ]ことを試みる ◎ Using the value of font face’s [[Urls]] slot, attempt to load a font as defined in [CSS-FONTS-3], as if it was the value of a @font-face rule’s src descriptor.
  6. ~load演算の完了-時には、次を走らす`~taskを~queueする$: ◎ When the load operation completes, successfully or not, queue a task to run the following steps synchronously:

    1. ~IF[ ~loadする試みは失敗した ]: ◎ If the attempt to load fails,\

      1. `NetworkError^E 例外で %状態s~promise を`却下する$ 【この段は次の段より後にするべき?(下の “解決-” も同様)】 ◎ reject font face’s [[FontStatusPromise]] with a DOMException whose name is "NetworkError" and\
      2. 此れの `status$m 属性 ~SET `error^l ◎ set font face’s status attribute to "error".
      3. 此れを`含む$ような ~EACH ( `FontFaceSet$I ~obj %~face~set ) に対し: ◎ For each FontFaceSet font face is in:

        1. %~face~set . `FailedFonts$sl に此れを追加する ◎ Add font face to the FontFaceSet’s [[FailedFonts]] list.
        2. %~face~set . `LoadingFonts$sl から此れを除去する ◎ Remove font face from the FontFaceSet’s [[LoadingFonts]] list.\
        3. ~IF[ %~face~set . `LoadingFonts$sl は空である ] ⇒ `~load済みに切替える$( %~face~set ) ◎ If font was the last item in that list (and so the list is now empty), switch the FontFaceSet to loaded.
    2. ~ELSE(~loadは成功した — 此れは今や~load済みの~fontを表現する): ◎ Otherwise, font face now represents the loaded font;\

      1. 此れで %状態s~promise を`解決する$ ◎ fulfill font face’s [[FontStatusPromise]] with font face and\
      2. 此れの `status$m 属性 ~SET `loaded^l ◎ set font face’s status attribute to "loaded".
      3. 此れを`含む$ような ~EACH ( `FontFaceSet$I ~obj %~face~set ) に対し: ◎ For each FontFaceSet font face is in:

        1. %~face~set . `LoadedFonts$sl に此れを追加する ◎ Add font face to the FontFaceSet’s [[LoadedFonts]] list.
        2. %~face~set . `LoadingFonts$sl から此れを除去する ◎ Remove font face from the FontFaceSet’s [[LoadingFonts]] list.\
        3. ~IF[ %~face~set . `LoadingFonts$sl は空である ] ⇒ `~load済みに切替える$( %~face~set ) ◎ If font was the last item in that list (and so the list is now empty), switch the FontFaceSet to loaded.

~UAは、所与の~font~faceが 頁~上の何かを描画するために必要とされることを決定したときに自前で~font~loadを起動できる。 これが起きたときは、ここに述べた対応する `FontFace$I の `load()$m ~methodが~callされたかのように動作し~MUST。 ◎ 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 FontFace’s load() method described here.

注記: ~UAには、同じ生成元に属する頁~上にて,同じ~fontを重ねて~downloadするのを避けるため、 “~font~cache” を活用するものもある。 複数の `FontFace$I ~objが、その~font~cache内の同じ~entryに対応付けられ得る。 このことは、 `FontFace$I ~objを~loadし始める時機は,それが `FontFaceSet$I 内にない場合でも予期できないことを意味する — 同じ~font~dataを指している他の `FontFace$I ~objが,(おそらく,別の頁~上で)すでに~load済みかもしれないので。 ◎ Note: Some UAs utilize a "font cache" which avoids having to download the same font multiple times on a page or on multiple pages within the same origin. Multiple FontFace objects can be mapped to the same entry in the font cache, which means that a FontFace object might start loading unexpectedly, even if it’s not in a FontFaceSet, because some other FontFace object pointing to the same font data (perhaps on a different page entirely!) has been loaded.

2.3. `font-face^at 規則との相互作用

`font-face$at 規則は、対応する `FontFace$I ~objを自動的に定義する — それは、その規則が構文解析されたとき,自動的に,文書の`~font~source$内に置かれる。 そのような `FontFace$I ~objは `~CSSに接続されて@ いるといい、その規則を指して,~objの`接続-先$という。 ◎ A CSS @font-face rule automatically defines a corresponding FontFace object, which is automatically placed in the document’s font source when the rule is parsed. This FontFace object is CSS-connected.

`~CSSに接続されて$いる `FontFace$I ~objの[ `family$m, `style$m, `weight$m, `stretch$m, `unicodeRange$m, `variant$m, `featureSettings$m ]属性は、その`接続-先$規則~内の対応する記述子と同じ値に設定される。 この[ `font-face$at 規則, `FontFace$I ~obj ]の間には二方向の接続がある: 規則~内の各種~記述子に対する どのような変更も,~objの対応する属性に即時に反映され、その逆も同様になる。 ◎ The FontFace object corresponding to a @font-face rule has its family, style, weight, stretch, unicodeRange, variant, and featureSettings attributes set to the same value as the corresponding descriptors in the @font-face rule. There is a two-way connection between the two: any change made to a @font-face descriptor is immediately reflected in the corresponding FontFace attribute, and vice versa.

`FontFace^I ~objが 文書~間で転送されたときには、`~CSSに接続され$なくなる。 ◎ When a FontFace is transferred between documents, it’s no longer CSS-connected.

`FontFace$I ~objの `Urls$sl 内部~slotは、 `font-face$at 規則の `src$d 記述子の値に設定され, `src$d 記述子に加えられる変更を反映する。 ◎ The internal [[Urls]] slot of the FontFace object is set to the value of the @font-face rule’s src descriptor, and reflects any changes made to the src descriptor.

他の場合、 `font-face$at 規則により作成される `FontFace$I ~objは、手動で作成されたものと一致する。 【 “他の場合”とは? この文は何を意味する?】 ◎ Otherwise, a FontFace object created by a CSS @font-face rule is identical to one created manually.

`~CSSに接続されて$いる `FontFace$I ~objは、次が生じたときには,その`接続-先$ %規則 への接続を絶って`~CSSに接続され$なくされ~MUST: ◎ ↓

  • %規則 が文書から除去されたとき。 この接続は、どのような手段をもってしても~~回復できない(同じ `font-face$at 規則を再度~stylesheetに追加した場合、それを`接続-先$とする新たな `FontFace$I ~objが作成されることになる)。 ◎ If a @font-face rule is removed from the document, its corresponding FontFace object is no longer CSS-connected. The connection is not restorable by any means (but adding the @font-face back to the stylesheet will create a brand new FontFace object which is CSS-connected).
  • %規則 の `src^d 記述子が新たな値に変更されたとき。 この場合、新たな `src^d を反映するような 新たな `FontFace$I ~objを作成した上で,その`接続-先$を %規則 にし~MUST。(また、`~font~source$においても,古い~objは除去して,新たな `FontFace$I ~objを追加することになる)。 ◎ If a @font-face rule has its src descriptor changed to a new value, the original connected FontFace object must stop being CSS-connected. A new FontFace reflecting its new src must be created and CSS-connected to the @font-face. (This will also remove the old and add the new FontFace objects from any font sources they appear in.)

3. `FontFaceSet^I ~interface

dictionary `FontFaceSetLoadEventInit@I : `EventInit$I {
  sequence<`FontFace$I> `fontfaces@dm = [];
};

[`FontFaceSetLoadEvent@mC(
    `CSSOMString$ %type,
    optional `FontFaceSetLoadEventInit$I %eventInitDict
 ),
 `Exposed$=(Window,Worker)]
interface `FontFaceSetLoadEvent@I : `Event$I {
  [`SameObject$] readonly attribute FrozenArray<`FontFace$I> `fontfaces@m;
};

enum `FontFaceSetLoadStatus@I { `~loading1@l, `~loaded1@l };

callback `ForEachCallback@I = void (
    `FontFace$I %font,
    long %index,
    `FontFaceSet$I %self
);

[`Exposed$=(Window,Worker),
 `FontFaceSet$mC(sequence<`FontFace$I> %initialFaces)
]
interface `FontFaceSet@I : `EventTarget$I {
  /* 
`FontFaceSet^I は`~set-like$x。
◎
FontFaceSet is Set-like!
 */
  setlike<`FontFace$I>;
  `FontFaceSet$I `add$m(`FontFace$I %font);
  boolean `delete$m(`FontFace$I %font);
  void `clear$m();

  /* 
~loading状態の変化に対する各種~event
◎
events for when loading state changes
 */
  attribute `EventHandler$I `onloading@m;
  attribute `EventHandler$I `onloadingdone@m;
  attribute `EventHandler$I `onloadingerror@m;

  /* 
適切になるなら,各~loadを検査し始め、すべての~loadが完了した時点で,~promiseを解決する。
◎
check and start loads if appropriate and fulfill promise when all loads complete
 */
  Promise<sequence<`FontFace$I>> `~load1$m(`CSSOMString$ %font, optional `CSSOMString$ %text = " ");

  /* 
~font~list内のすべての~fontが~loadされたかどうかを返す(可用でないものに対しては,~loadは起動されない)
◎
return whether all fonts in the fontlist are loaded (does not initiate load if not available)
 */
  boolean `check$m(`CSSOMString$ %font, optional `CSSOMString$ %text = " ");

  /* 
~fontの~loadingと~layout演算を終えたときの非同期~通知
◎
async notification that font loading and layout operations are done
 */
  readonly attribute Promise<`FontFaceSet$I> `ready$m;

  /* 
~loading状態
— いずれかの~fontを~load中の間は `loading^l /
~ELSE_ `loaded^l
◎
loading state, "loading" while one or more fonts loading, "loaded" otherwise
 */
  readonly attribute `FontFaceSetLoadStatus$I `~status1@m;
};
`ready@m
この属性は `FontFaceSet$I . `ReadyPromise$sl を反映する。 ◎ This attribute reflects the FontFaceSet's [[ReadyPromise]] slot.
この`~promise$とその利用についての更なる詳細は `ready^m 属性 節 を見よ。 ◎ See §3.4 The ready attribute for more details on this Promise and its use.
`FontFaceSet(initialFaces)@m
この構築子の被~call時には、 %initialFaces 引数を反復して得られる各~値を,構築される `FontFaceSet$I ~obj の`~set~entries$に追加し~MUST。 ◎ The FontFaceSet constructor, when called, must iterate its initialFaces argument and add each value to its set entries.

`~set~entries$の `反復~順序@ は、次に従わ~MUST: ◎ iteration order

  1. `~CSSに接続されて$いる `FontFace$I ~objたち — `font-face$at 規則の文書~順序で。
  2. `~CSSに接続されて$いない `FontFace$I ~objたち — 挿入~順序で。
◎ When iterated over, all CSS-connected FontFace objects must come first, in document order of their connected @font-face rules, followed by the non-CSS-connected FontFace objects, in insertion order.

`~set~entries@ ( `~set~entries$x `WebIDL-1$r )は、次のように初期化される: ◎ set entries

  • この `FontFaceSet$I ~objが`~font~source$である場合、 `font-face^at 規則との相互作用 節 に指定されるように初期化される。 ◎ If a FontFaceSet is a font source, its set entries are initialized as specified in §4.2 Interaction with CSS’s @font-face Rule.
  • 他の場合、空になる。 ◎ Otherwise, its set entries are initially empty.
`add(font)@m

被~call時には、次の手続きを実行する: ◎ When the add() method is called, execute the following steps:

  1. ~IF[ %~font ~IN 此れの`~set~entries$ ] ⇒ ~RET 此れ ◎ If font is already in the FontFaceSet’s set entries, skip to the last step of this algorithm immediately.
  2. ~IF[ %~font は`~CSSに接続されて$いる ] ⇒ ~THROW `InvalidModificationError$E ◎ If font is CSS-connected, throw an InvalidModificationError exception and exit this algorithm immediately.
  3. 此れの`~set~entries$に %~font を追加する ◎ Add the font argument to the FontFaceSet’s set entries.
  4. ~IF[ %~font の `status$m 属性 ~EQ `loading^l ]: ◎ If font’s status attribute is "loading":

    1. ~IF[ 此れ . `LoadingFonts$sl は空である ] ⇒ `~loadingに切替える$( 此れ ) ◎ If the FontFaceSet’s [[LoadingFonts]] list is empty, switch the FontFaceSet to loading.
    2. 此れ . `LoadingFonts$sl に %~font を付加する ◎ Append font to the FontFaceSet’s [[LoadingFonts]] list.
  5. ~RET 此れ ◎ Return the FontFaceSet.
`delete(font)@m

被~call時には、次の手続きを実行する: ◎ When the delete() method is called, execute the following steps:

  1. ~IF[ %~font は`~CSSに接続されて$いる ] ⇒ ~RET ~F ◎ If font is CSS-connected, return false and exit this algorithm immediately.
  2. `削除?^V ~LET 此れの`~set~entries$から %~font を除去した結果†

    【† おそらく、次を意味する: 】

    1. `削除?^V ~LET ~F
    2. ~IF[ %~font ~IN 此れの`~set~entries$ ]:

      1. `削除?^V ~SET ~T
      2. 此れの`~set~entries$から %~font を除去する
    ◎ Let deleted be the result of removing font from the FontFaceSet’s set entries.
  3. 次の各~listから %~font を(含まれていれば)除去する ⇒ 此れ . `LoadedFonts$sl, 此れ . `FailedFonts$sl, 此れ . `LoadingFonts$sl ◎ If font is present in the FontFaceSet’s [[LoadedFonts]], or [[FailedFonts]] lists, remove it. ◎ ↓
  4. ~IF[ 此れ . `LoadingFonts$sl は空である ] ⇒ `~load済みに切替える$( 此れ ) ◎ If font is present in the FontFaceSet’s [[LoadingFonts]] list, remove it. If font was the last item in that list (and so the list is now empty), switch the FontFaceSet to loaded.
  5. ~RET `削除?^V ◎ Return deleted.
`clear()@m

被~call時には、次を実行する: ◎ When the clear() method is called, execute the following steps:

  1. 此れの`~set~entries$を空にする
  2. 此れ . `LoadedFonts$sl を空にする
  3. 此れ . `FailedFonts$sl を空にする ◎ Remove all items from the FontFaceSet’s set entries, its [[LoadedFonts]] list, and its [[FailedFonts]] list.
  4. ~IF[ 此れの `LoadingFonts$sl ~listは空でない ]:

    1. 此れ . `FailedFonts$sl ~listを空にする
    2. `~load済みに切替える$( 此れ )
    ◎ If the FontFaceSet’s [[LoadingFonts]] list is non-empty, remove all items from it, then switch the FontFaceSet to loaded.

`FontFaceSet$I ~objはまた、次の内部~slotを有する:

`LoadingFonts@sl
`LoadedFonts@sl
`FailedFonts@sl
これらは、空~listに初期化される。
`ReadyPromise@sl
`新たな~promise$に初期化される。
◎ FontFaceSet objects also have internal [[LoadingFonts]], [[LoadedFonts]], and [[FailedFonts]] slots, all of which are initialized to empty lists, and a [[ReadyPromise]] slot, which is initialized to a fresh pending Promise.

~font~familyは,利用されるときにのみ~loadされるので、作者は,内容に対する~fontの~loadingがいつ生じるか解する必要もときどきある。 ここに定義される各種~event/~methodを利用すれば、特定の~fontの可用性に依存する動作を,もっと制御できるようになる。 ◎ 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.

`FontFaceSet$I ~objは、次のいずれかが満たされるならば `環境待ち@ にあるとされる: ◎ A FontFaceSet is pending on the environment if any of the following are true:

  • 文書は依然として~load中にある。 ◎ the document is still loading
  • 文書による~stylesheet要請は、応答待ちにある。 ◎ the document has pending stylesheet requests
  • 文書の~layout演算は、完了待ちにある — それは、~UAに~fontを要請させることもあれば, ~fontが近過去に~loadされたかどうかに依存することもある。 ◎ the document has pending layout operations which might cause the user agent to request a font, or which depend on recently-loaded fonts

注記: その趣旨は、 `FontFaceSet$I が`環境待ち$でなくなった時点から — 文書に更に変更が加えられない限り — 作者は,計測される~sizeや位置が “正しい” ことに依存できるようにすることである。 上の条件が,この保証を全部的に捉えていない場合、そうなるように改正される必要がある。 ◎ Note: The idea is that once a FontFaceSet stops being pending on the environment, as long as nothing further changes the document, an author can depend on sizes/positions of things being "correct" when measured. If the above conditions do not fully capture this guarantee, they need to be amended to do so.

3.1. 各種~event

~font~load~eventにより、文書~全体の~font~loadingの挙動に容易に応答でき, 各~fontを個別に~listenし続けずに済むようになる:

  • `loading@et ~eventは、文書が~fontを~loadし始めたときに発火される。
  • `loadingdone@et ~eventは、文書は~fontを~loadし終えた, かつ どれも成功裡に~loadされたときに発火される。
  • `loadingerror@et ~eventは、文書は~fontを~loadし終えたが,~loadに失敗した~fontがあるときに発火される。
◎ 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 loading event fires when the document begins loading fonts, while the loadingdone and loadingerror events fire when the document is done loading fonts, containing the fonts that successfully loaded or failed to load, respectively.

`FontFaceSet^I ~objは、次に挙げる~event~handlerを(および,対応する~event~handler~event型も),~IDL属性として~supportし~MUST: ◎ The following are the event handlers (and their corresponding event handler event types) that must be supported by FontFaceSet objects as IDL attributes:

`~event~handler~IDL属性$ `~event~handler~event型$
`onloading$m `loading$et
`onloadingdone$m `loadingdone$et
`onloadingerror$m `loadingerror$et

`~font~load~eventを発火する@ ときは、所与の ( `FontFaceSet$I %~target, 名前 %e, %~font~faces (省略時は ε ) ) に対し,次を走らす:

  1. %~face集合 ~LET %~target に含まれる `FontFace$I ~objすべてからなる集合
  2. ~IF[ %~font~faces ~NEQ ε ] ⇒ %~face集合 から[ %~font~faces に含まれないもの ]をすべて除去する
  3. %~target に向けて,名前 %e の`~eventを発火する$ — `FontFaceSetLoadEvent$I を利用し,次のように初期化して ⇒ `fontfaces$m 属性 ~SET %~face集合†

【 原文には, %~font~faces が省略された場合に %~face集合 が何になるか明確に述べられていないが、単に最初の段で与えられるものになると思われる。 】

◎ To fire a font load event named e at a FontFaceSet target with optional font faces means to fire a simple event named e using the FontFaceSetLoadEvent interface that also meets these conditions: • The fontfaces attribute is initialized to the result of filtering font faces to only contain FontFace objects contained in target.

`~loadingに切替える@ ときは、所与の ( `FontFaceSet$I ~obj %~face~set ) に対し,次の手続きを走らせ~MUST: ◎ When asked to switch the FontFaceSet to loading for a given FontFaceSet, the user agent must run the following steps:

  1. %~face~set の `~status1$m 属性 ~SET `loading^l ◎ Let font face set be the given FontFaceSet. ◎ Set the status attribute of font face set to "loading".
  2. ~IF[ %~face~set . `ReadyPromise$sl が保持している~promiseはすでに`解決され$ている ] ⇒ %~face~set . `ReadyPromise$sl ~SET `新たな~promise$ ◎ If font face set’s [[ReadyPromise]] slot currently holds a fulfilled promise, replace it with a fresh pending promise.
  3. 次を走らす`~taskを~queueする$ ⇒ `~font~load~eventを発火する$( %~face~set, `loading$et ) ◎ Queue a task to fire a font load event named loading at font face set.

以下に与える手続きの目的においては、各 `FontFaceSet$I ~objには, `環境渋滞中~flag@ (初期時は ~OFF )が結付けられているとする。 ◎ ↓↓

`~load済みに切替える@ ときは、所与の ( `FontFaceSet$I ~obj %~face~set ) に対し,次の手続きを走らせ~MUST: ◎ When asked to switch the FontFaceSet to loaded for a given FontFaceSet, the user agent must run the following steps:

  1. ~IF[ %~face~set は`環境待ち$にある ]:

    1. %~face~set の`環境渋滞中~flag$ ~SET ~ON
    2. ~RET
    ◎ Let font face set be the given FontFaceSet. ◎ If font face set is pending on the environment, mark it as stuck on the environment, and exit this algorithm.
  2. %~face~set の `~status1$m 属性 ~SET `loaded^l ◎ Set font face set’s status attribute to "loaded".
  3. %~face~set で[ %~face~set . `ReadyPromise$sl ]を`解決する$ ◎ Fulfill font face set’s [[ReadyPromise]] attribute’s value with font face set.
  4. 次を走らす`~taskを~queueする$: ◎ Queue a task to perform the following steps synchronously:

    1. `~load済みの~fontたち^V ~LET %~face~set . `LoadedFonts$sl (空の場合もある) ◎ Let loaded fonts be the (possibly empty) contents of font face set’s [[LoadedFonts]] slot.
    2. `失敗した~fontたち^V ~LET %~face~set . `FailedFonts$sl (空の場合もある) ◎ Let failed fonts be the (possibly empty) contents of font face set’s [[FailedFonts]] slot.
    3. `LoadedFonts$sl ~slot ~SET 空~list ◎ ↓
    4. `FailedFonts$sl ~slot ~SET 空~list ◎ Reset the [[LoadedFonts]] and [[FailedFonts]] slots to empty lists.
    5. `~font~load~eventを発火する$( %~face~set, `loadingdone$et, `~load済みの~fontたち^V ) ◎ Fire a font load event named loadingdone at font face set with loaded fonts.
    6. ~IF[ `失敗した~fontたち^V は空でない ] ⇒ `~font~load~eventを発火する$( %~face~set, `loadingerror$et, `失敗した~fontたち^V ) ◎ If font face set’s failed fonts is non-empty, fire a font load event named loadingerror at font face set with failed fonts.

~UAは,[ `環境待ち$にあった `FontFaceSet$I ~obj %~face~set ]が`環境待ち$でなくなったときは、次の手続きを走らせ~MUST: ◎ Whenever a FontFaceSet goes from pending on the environment to not pending on the environment, the user agent must run the following steps:

  1. ~IF[ %~face~set の`環境渋滞中~flag$ ~EQ ~ON ]~AND[ %~face~set . `LoadingFonts$sl は空である ] ⇒ `~load済みに切替える$( %~face~set ) ◎ If the FontFaceSet is stuck on the environment and its [[LoadingFonts]] list is empty, switch the FontFaceSet to loaded.
  2. %~face~set の`環境渋滞中~flag$ ~SET ~OFF ◎ If the FontFaceSet is stuck on the environment, unmark it as such.

`FontFaceSet^I ~obj %~source から `合致する~font~faces@ を見出すときは、所与の:

  • %~font (~font文字列)
  • %~text (見本~text,省略時は 1 個の U+0020 SPACE からなる文字列)
  • %~system~font許容~flag(省略時は ~OFF)

に対し、次の手続きを走らす:

◎ If asked to find the matching font faces from a FontFaceSet source, for a given font string font optionally some sample text text, and optionally an allow system fonts flag, run the following steps:
  1. %解析結果 ~LET `font$p ~propの~CSS値~構文を利用して %~font を構文解析した結果 ◎ Parse font using the CSS value syntax of the font property.\
  2. ~IF[ 前段で構文~errorが生じた ] ⇒ ~RET ( 構文~error, … ) ◎ If a syntax error occurs, return a syntax error.
  3. ~IF[ %解析結果 は `~CSS全域~keyword$である ] ⇒ ~RET ( 構文~error, … ) ◎ If the parsed value is a CSS-wide keyword, return a syntax error.
  4. %解析結果 内のすべての相対~長さを,対応する~propの初期~値を基準に絶対化する(例えば `bolder^v の様な相対~font~weightは、初期~値 `normal^v を基準に評価される。) ◎ Absolutize all relative lengths against the initial values of the corresponding properties. (For example, a relative font weight like bolder is evaluated against the initial value normal.) ◎ If text was not explicitly provided, let it be a string containing a single space character (U+0020 SPACE).
  5. %~font~family~list ~LET %解析結果 内の~font~familyの~list ◎ Let font family list be the list of font families parsed from font,\
  6. %~font~style ~LET %解析結果 内の他の~font~style属性 ◎ and font style be the other font style attributes parsed from font.
  7. `可用な~font~faces^V ~LET %~source 内の~font~faceたち ◎ Let available font faces be the font faces within source.\
  8. ~IF[ %~system~font許容~flag ~EQ ~ON ] ⇒ `可用な~font~faces^V にすべての~system~fontを追加する ◎ If the allow system fonts flag is specified, add all system fonts to available font faces.
  9. `合致した~font~faces^V ~LET 空~list ◎ Let matched font faces initially be an empty list.
  10. %~font~family~list 内の ~EACH ( %~family ) に対し ⇒ `合致した~font~faces^V に次を追加する ⇒ `~font照合$規則を利用して、 `可用な~font~faces^V 内の~font~faceのうち,次を満たすものを選定した結果 ⇒ [ %~family に属する ]~AND[ %~font~style に合致する ]

    ( `unicodeRange$m 属性の利用は,複数の~font~faceが選定され得ることを意味する。)

    ◎ For each family in font family list, use the font matching rules to select the font faces from available font faces that match the font style, and add them to matched font faces. The use of the unicodeRange attribute means that this may be more than just a single font face.
  11. `見出された~faceあり^V ~SET[ `合致した~font~faces^V は空ならば ~F / ~ELSE_ ~T ] ◎ If matched font faces is empty, set the found faces flag to false. Otherwise, set it to true.
  12. `合致した~font~faces^V 内の ~EACH ( %~font~face ) に対し ⇒ ~IF[ %~text 内のどの文字の符号位置も %~font~face に定義されている `unicode-range$d に含まれていない† ] ⇒ `合致した~font~faces^V から %~font~face を除去する

    【† この条件の `unicode-range$d は、`有効~文字~map$とされるべきであろう。 】

    ◎ For each font face in matched font faces, if its defined unicode-range does not include the codepoint of at least one character in text, remove it from the list.
  13. ~RET ( `合致した~font~faces^V, `見出された~faceあり^V ) ◎ Return matched font faces and the found faces flag.

3.2. `load()^m ~method

`FontFaceSet$I の `~load1()$m ~methodは、所与の~font~list内のすべての~fontが,~loadされ可用になったかどうかを決定する。 ~font~list内に まだ~loadされていない~download可能な~fontがある場合、~UAは それらの各~fontに対し,~loadを起動することになる。 この~methodは、`~promise$を返す。 それは、 すべての~fontが~loadされ,利用される準備ができたときに`解決され$、 いずれかの~fontを適正に~loadするのに失敗したときは,`却下され$る。 ◎ The load() method of FontFaceSet 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.

`~load1(font, text)@m ~methodの被~call時には、次の手続きを実行する: ◎ When the load( font, text ) method is called, execute these steps:

  1. %~promise ~LET 新たに作成された~promise~obj。 ◎ Let font face set be the FontFaceSet object this method was called on. Let promise be a newly-created promise object.
  2. ~RET %~promise — ただし、以下の手続きは並列的に走らす。 ◎ Return promise. Complete the rest of these steps asynchronously.
  3. ( %~font~face~list, … ) ~LET 次を与える下で,此れから`合致する~font~faces$を見出した結果 ⇒ ( %font, %text, ~OFF ) ◎ Find the matching font faces from font face set using the font and text arguments passed to the function, and let font face list be the return value (ignoring the found faces flag).
  4. ~IF[ %~font~face~list ~EQ 構文~error ]:

    1. `SyntaxError^E 例外で %~promise を`却下する$
    2. ~RET
    ◎ If a syntax error was returned, reject promise with a SyntaxError exception and terminate these steps.
  5. 次を走らす`~taskを~queueする$: ◎ Queue a task to run the following steps synchronously:

    1. %~promise~list ~LET 空~list ◎ ↓
    2. %~font~face~list 内の ~EACH ( %~font~face ) に対し:

      1. %~font~face の `load()$m ~methodを~callする
      2. %~promise~list に %~font~face の `FontStatusPromise$sl を付加する
      ◎ For all of the font faces in the font face list, call their load() method.
    3. [ %~promise~list を`すべてを待機-$した結果 ]で %~promise を`解決する$ ◎ Resolve promise with the result of waiting for all of the [[FontStatusPromise]]s of each font face in the font face list, in order.

3.3. `check()^m ~method

`FontFaceSet$I 上の `check()$m ~methodは、[ 供された~textを,特定0の~font~listで “安全に” 描画できる(後で “~fontが入替わる” ことはない)かどうか ]を決定する。 この~methodは、 ( ~text, ~font ) の組み合わせが与えられた下で,[ ~textを描画する際に[ ~unloadされた / 現在~load中にある ]~fontを利用しようと試みられることはない ]ならば ~T を返し、他の場合は ~F を返す。 ◎ The check() method of FontFaceSet will determine whether you can "safely" render some provided text with a particular font list, such that it won’t cause a "font swap" later. If the given text/font combo will render without attempting to use any unloaded or currently-loading fonts, this method will return true; otherwise, it returns false.

注記: この~methodの挙動においては,二つの 自明でない特殊な事例に注意されたし: ◎ Two special cases in this method’s behavior should be noted, as they are non-obvious:

  • 指定された~fontは存在するが、その `unicode-range$d が供された~textを成すある文字を含んでいないことに因り,可能なすべての~faceがはじかれる場合、 ~T を返す — 当の~textは,~UAによる~fallback~fontで描画され、~font~loadを誘発しなくなるので。 ◎ If the specified fonts exist, but all possible faces are ruled out due to their unicode-range not covering the provided text, the method returns true, as the text will be rendered in the UA’s fallback font instead, and won’t trigger any font loads.
  • 指定されたどの~fontも存在しない場合、前項の事例と技術的には似るが,例外が投出される(その~font~listで描画される~textに対しては,単に~UAによる~fallback~fontが利用されることになる)。 そのような状況は,およそ、誤記であるか,あるいは ~download可能な~fontの名前が変更されたにもかかわらず,利用している古い名前を更新し忘れた結果によるものなので、無為に ~T を返すより ~errorにする方が有用になるので。 ◎ If none of the specified fonts exist, even though this is technically similar to the previous case (in that text rendered with that font list would just use the UA fallback font), the method instead throws an error. This is because such a situation is almost certainly either a typo, or the result of changing the name of a downloadable font and forgetting to update all places the old name was used, and an error is more useful than a vacuous true.

`check(font, text)@m ~methodの被~call時には、次を実行する: ◎ When the check( font, text) method is called, execute these steps:

  1. ( %~font~face~list, `見出された~faceあり^V ) ~LET 次を与える下で,此れから`合致する~font~faces$を見出した結果 ⇒ ( %font, %text, ~ON ) ◎ Let font face set be the FontFaceSet object this method was called on. ◎ Find the matching font faces from font face set using the font and text arguments passed to the function, and including system fonts, and let font face list be the returned list of font faces, and found faces be the returned found faces flag.\
  2. ~IF[ %~font~face~list ~EQ 構文~error ] ⇒ ~THROW `SyntaxError^E ◎ If a syntax error was returned, throw a SyntaxError exception and terminate these steps.
  3. ~IF[ `見出された~faceあり^V ~EQ ~F ] ⇒ ~THROW `XXX error^E 【正式な~error名は未策定の模様】 ◎ If found faces is false, throw an XXX error and abort this algorithm.
  4. ~IF[ %~font~face~list 内に ~system~fontでない, かつ[ `status$m 属性 ~NEQ `loaded^l ]なる~fontがある ] ⇒ ~RET ~F ◎ If font face list is empty, or all fonts in the font face list either have a status attribute of "loaded" or are system fonts, return true. Otherwise, return false.
  5. ~RET ~T ◎ ↑

3.4. `ready^m 属性

~loadされる~fontの個数は,所与の~text片に利用されている~fontの個数に依存するので、~fontを~loadする必要があるかどうかは 既知でない事例もある。 `ready$m 属性は、[ 文書が~fontを~loadし終えたときに解決される`~promise$ ]を返す。 これにより,作者は、~load中の~fontに影響され得る内容を精査するに先立って,どの~fontが~loadされたか追跡し続けなくとも済むようになる。 ◎ 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 ready attribute contains 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.

注記: `ready$m 属性から返される`~promise$ %P においては: ◎ ↓

  • %P が`解決され$るのは一度限りであるが、作者は,解決された後にも更に~fontが~loadされ得ることに留意するべきである。 これは、 `loadingdone$et ~eventが発火されるのを~listenするのと似るが、 %P に渡される~callbackは,当の~fontはすでに~load済みのため,~font~loadは生じなかったときでも,常に~callされるからである。 それは、どの~fontが必要で,精確にいつ~loadされるか追跡し続けることなく,~codeを~font~loadに同期させる単純かつ容易な仕方を与える。 ◎ Note: Authors should note that a given ready promise is only fulfilled once, but further fonts may be loaded after it fulfills. This is similar to listening for a loadingdone event to fire, but the callbacks passed to the ready promise will always 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.
  • ~UAは、 %P を`解決する$前に,~font~loadを複数回 反復する必要が生じ得る。 これは、~font~list内のある~fontは~loadされたが,それが必要な~glyphを包含しておらず,~list内の他の~fontを~loadする必要がある状況(~font~fallback状況)にて生じ得る。 %P が`解決され$るのは、~layout演算が完了して,それ以上~font~loadが必要とされなくなった後に限られる。 ◎ Note: Note that the user agent may need to iterate over multiple font loads before the ready promise 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 ready promise is only fulfilled after layout operations complete and no additional font loads are necessary.
  • `FontFace$I `load()$m ~methodから返される`~promise$と違って、 %P は,`解決され$るのみであり, `却下され$ることは決してない。 ◎ Note: Note that the Promise returned by this ready attribute is only ever fulfilled, never rejected, unlike the Promise returned by the FontFace load() method.

3.5. ~CSS ~font~loading/照合との相互作用

~UAは、[ `~font照合$~algo `CSS-FONTS-3$r を自動的に走らせた結果の,合致する~font~faces ]と[[ 文書に対する`~font~source$内の~font, および局所~font~face ]からなる集合 ]とを、精確に一致させ~MUST。 ◎ When the font matching algorithm in [CSS-FONTS-3] is run automatically by the user-agent, the set of font faces it matches over must be precisely the set of fonts in the font source for the document, plus any local font faces.

~UAは、~font~faceを~loadする必要が生じたときは、対応している `FontFace$I ~objの `load()$m ~methodを~callして,そうし~MUST。 ◎ When a user-agent needs to load a font face, it must do so by calling the load() method of the corresponding FontFace object.

(これは、 【その~methodに定義されている】 同じ~algoを走らせ~MUSTことを意味する — 当の~objの `load^m ~prop内に現在~格納されている値そのものを~callするのでなく) ◎ (This means it must run the same algorithm, not literally call the value currently stored in the load property of the object.)

~fontは、 `FontFaceSet$I に追加された時点から可用になる。 ~stylesheetに新たな `font-face$at 規則を追加することは、 `Document$I ~objの `FontFaceSet$I に新たな `FontFace$I を追加することを~~意味する。 ◎ Fonts are available when they are added to a FontFaceSet. Adding a new @font-face rule to a stylesheet also adds a new FontFace to the FontFaceSet of the Document object.

新たな `font-face$at 規則を追加する例: ◎ Adding a new @font-face rule:

document.styleSheets[0].insertRule(
  "@font-face { font-family: newfont; src: url(newfont.woff); }", 0);
document.body.style.fontFamily = "newfont, serif";

新たな `FontFace$I ~objを構築して `document.fonts^c に追加する例: ◎ Constructing a new FontFace object and adding it to document.fonts:

var %f = new FontFace("newfont", "url(newfont.woff)");
document.fonts.add(%f);
document.body.style.fontFamily = "newfont, serif";

いずれの事例に対しても、~layout~engineは,~font資源 `newfont.woff^l の~loadingを起動することになる — `font-face$at 規則により~fontが~loadされるのと同じように。 ◎ In both cases, the loading of the font resource “newfont.woff” will be initiated by the layout engine, just as other @font-face rule fonts are loaded.

`document.fonts^c への追加を省略した場合、~fontは決して~loadされず,~textは既定の~serif~fontで表示されることになる: ◎ Omitting the addition to document.fonts means the font would never be loaded and text would be displayed in the default serif font:

var f = new FontFace("newfont", "url(newtest.woff)", {});

/* 
新たな {{FontFace}} は {{FontFaceSet}} には追加されないので、
`font-family^p ~propは、それを見れない
— 代わりに `serif^v が利用されることになる。
◎
new {{FontFace}} not added to {{FontFaceSet}}, so the 'font-family' property can’t see it, and serif will be used instead
 */
document.body.style.fontFamily = "newfont, serif";

~fontを,利用する前に明示的に~preloadするときは、作者は `FontFaceSet$I への新たな `FontFace$I の追加を,その~loadが完了するまで先送りできる: ◎ To explicitly preload a font before using it, authors can defer the addition of a new FontFace to a FontFaceSet until the load has completed:

var %f = new FontFace("newfont", "url(newfont.woff)", {});
%f.load().then(function (%loadedFace) {
  document.fonts.add(%loadedFace);
  document.body.style.fontFamily = "newfont, serif";
});

この事例では、~font資源 `newfont.woff^l は,先ず~downloadされる。 完了したなら、文書の `FontFaceSet$I に~fontが追加され, `body^e の~fontは変更され、~layout~engineは,その新たな~font資源を利用するようになる。 ◎ In this case, the font resource “newfont.woff” is first downloaded. Once the download completes, the font is added to the document’s FontFaceSet, the body font is changed, and the layout engine uses the new font resource.

4. `FontFaceSource^I ~interface

[`Exposed$=(Window,Worker),
 `NoInterfaceObject$]
interface `FontFaceSource@I {
  readonly attribute `FontFaceSet$I `fonts@m;
};

`Document$I implements `FontFaceSource$I;
`WorkerGlobalScope$I implements `FontFaceSource$I;

どの[ 文書, ~worker, その他,何らかの方式で~fontを利用する ]ような文脈も、 `FontFaceSource$I ~interfaceを実装し~MUST。 文脈の `fonts$m 属性の値を、その `~font~source@ という — それは、他が定義されない限り,~fontに関係する演算にて利用される,すべての~fontを供する。 “~font~source” を参照している演算は、[ その演算が占めている,関連する文脈の`~font~source$ ]を参照しているものと解釈され~MUST。 ◎ Any document, workers, or other context which can use fonts in some manner must implement the FontFaceSource interface. The value of the context’s fonts attribute is its font source, 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 font source of the relevant context in which the operation is taking place.

[ これらの文脈いずれかを占めている,~fontに関係する演算 ]に `可用な~font~face@ は、当の文脈の`~font~source$の中の `FontFace$I ~objで与えられる。 ◎ For any font-related operation that takes place within one of these contexts, the FontFace objects within the font source are its available font faces.

4.1. ~workerにおける `FontFaceSources^I

~worker文書における`~font~source$は、初期~時は空とする。 ◎ Within a Worker document, the font source is initially empty.

注記: `FontFace$I ~objは、通常通り構築したり追加でき,~workerの中での~CSS`~font照合$に影響する(例えば `OffscreenCanvas$I の中で~textを描くときなど)。 ◎ Note: FontFace objects can be constructed and added to it as normal, which affects CSS font-matching within the worker (such as, for example, drawing text into a OffscreenCanvas).

4.2. `font-face^at 規則との相互作用

文書の`~font~source$の`~set~entries$は、初期~時には,[ 文書の~stylesheet内のある `font-face$at 規則を`接続-先$とする `FontFace$I ~obj ]たちで拡充され~MUST — それらの規則の文書~順序で。 `font-face$at 規則が~stylesheet[ に追加-/から除去- ]されるに伴い,あるいは [ `font-face$at 規則を包含している~stylesheet ]が文書[ に追加-/から除去- ]されるに伴い、それを`接続-先$とする どの `FontFace$I ~objも,この順序を保守するように,文書の`~font~source$[ に追加-/から除去- ]され~MUST。 ◎ The set entries for a document’s font source must be initially populated with all the CSS-connected FontFace objects from all of the CSS @font-face rules in the document’s stylesheets, in document order. As @font-face rules are added or removed from a stylesheet, or stylesheets containing @font-face rules are added or removed, the corresponding CSS-connected FontFace objects must be added or removed from the document’s font source, and maintain this ordering.

手動で追加された `FontFace$I ~objの順序は、`~CSSに接続されて$いるそれらの後で~MUST。 【`反復~順序$を見よ。】 ◎ Any manually-added FontFace objects must be ordered after the CSS-connected ones.

`FontFaceSet$I ~objの `add()$m ~methodの被~call時には、渡された `FontFace$I ~objが`~CSSに接続されて$いて,すでに~set内にある場合、演算は何もしては~MUST_NOT。 他の場合、 `InvalidModificationError$E を投出し~MUST。 ◎ When a FontFaceSet object’s add() method is called with a CSS-connected FontFace object, if the object is already in the set, the operation must be a no-op; otherwise, the operation must do nothing, and throw an InvalidModificationError.

`FontFaceSet$I ~objの `delete()$m ~methodの被~call時には、渡された `FontFace$I ~objが`~CSSに接続されて$いる場合は,何もせず ~F を返さ~MUST。 ◎ When a FontFaceSet object’s delete() method is called with a CSS-connected FontFace object, the operation must be a no-op, and return false.

注記: 作者は、除去された `FontFace$I ~objへの参照を — それが`~font~source$から自動的に除去されたものであっても — 依然として保守できる。 `font-face^at 規則との相互作用 節 に指定されるように、当の~objは除去された時点で`~CSSに接続され$なくなるが。 ◎ Note: Authors can still maintain references to a removed FontFace, even if it’s been automatically removed from a font source. As specified in §2.3 Interaction with CSS’s @font-face Rule, though, the FontFace is no longer CSS-connected at that point.

注記: この仕様の将来~versionでは、局所~fontに対しても[ 相互作用する/照会する ]仕方を定義することが期待されている。 ◎ Note: It is expected that a future version of this specification will define ways of interacting with and querying local fonts as well.

5. API 例

すべての~fontに対する~loadが完了してから,内容を示す例: ◎ To show content only after all font loads complete:

document.fonts.ready.then(function() {
  var %content = document.getElementById("content");
  %content.style.visibility = "visible";
});

~download可能な~fontに対する~downloadを明示的に起動して、完了~時に,それらの~fontで~canvas内に~textを描く例: ◎ Drawing text in a canvas with a downloadable font, explicitly initiating the font download and drawing upon completion:

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);

~rich-text編集~appは、編集が行われたとき,対象の~text要素を計測し直す必要があり得る。 ~textの~styleが変更された場合、追加の~font~downloadを要するかもしれないし,当の~fontは すでに~downloadされているかもしれない — いずれにせよ、その計測は,~font~loadが完了した後に行う必要がある: ◎ 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:

function measureTextElements() {
  /* 
この中では、~download可能な~fontの計量を利用して,内容を計測できる
◎
contents can now be measured using the metrics of the downloadable font(s)
 */
}

function doEditing() {
  /* 
内容や~layoutに対する,追加の~font~loadを生じさせ得るような演算
◎
content/layout operations that may cause additional font loads
 */
  document.fonts.ready.then(measureTextElements);
}

`loadingdone$et ~eventが発火されるのは、~fontに関係するすべての~loadが完了して,なおかつ ~textは 追加の~font~loadを生じさせることなく~lay-outされた後に限られる: ◎ The loadingdone event only fires after all font related loads have completed and text has been laid out without causing additional font loads:

<style>
@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");
}
@font-face {
  font-family: unused;
  src: url(unused.woff);
}

body { font-family: latin-serif, jpn-mincho; }
</style>
<p>納豆はいかがでしょうか

この状況では、~UAは先ず latinserif.woff ~fontを~downloadしてから、それを利用して日本語~textを描こうと試行する。 その~font内には日本語~glyphがないので、~fallbackが生じ, mincho.woff ~fontが~downloadされる。 `loadingdone$et ~eventが発火されるのは、この 2 番目の~fontが~downloadされ,日本語~textが~lay-outされた後になる。 ◎ 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 loadingdone event fire.

unused ~fontは~loadされない — それは、~textからも利用されないので、~UAはそれを~loadしようと試行すらしない。 その結果、 `loadingdone$et ~eventにも干渉しない。 ◎ The "unused" font isn’t loaded, but no text is using it, so the UA isn’t even trying to load it. It doesn’t interfere with the loadingdone event.

変更点

May 2014 CSS Font Loading Last Call Working Draft からの変更点: ◎ Changes from the May 2014 CSS Font Loading Last Call Working Draft:

  • 副作用の時機をきちんと定義するため、非同期~algoにて,用語 “`~taskを~queueする$” を利用するように正した。 ◎ Corrected the async algorithms to use "queue a task" language, to ensure that side-effect timing is well-defined.
  • ~IDLの実施を適正にするため、 `fontfaces$m 属性の型を `FrozenArray^I に切り替えた。 ◎ Switched fontfaces to be a FrozenArray, to match with proper IDL practice.
  • `font-face$at に揃えるため、 `variationSettings$m, `display$m を追加した。 ◎ Added variationSettings and display, to sync with @font-face.

謝辞

Several members of the Google Fonts team provided helpful feedback on font load events, as did Boris Zbarsky, Jonas Sicking and ms2ger.

~privacyと~security上の考慮点

`FontFaceSet$I ~objは、利用者が~installしている~font情報を漏洩するが、既存の `font-face$at 規則と正確に同じ仕方でそうするので,新たな情報を漏洩したり, それを容易にすることはない。 ◎ The FontFaceSet object leaks information about the user’s installed fonts, but in the exact same way as the existing @font-face rule; no new information is leaked, or in any appreciable easier manner.

この仕様はまた、新たな~security上の考慮点を導入するものではない。 ◎ This specification introduces no new security considerations.