Re: [font-load-events] comments on new promises-based draft

Tab Atkins wrote:

> CSSFontFaceRule objects represent the @font-face syntax construct,
> nothing more.  The actual font face denoted by the @font-face rule is
> represented by the FontFace object instead.  This seems like a decent
> separation of concerns, at least to me.

Ok, I think I understand the model you want to spec - adding an
@font-face rule automatically constructs a FontFace object and adds it
to document.fonts but a newly constructed FontFace object is *not*
added to document.fonts (or whatever the worker equivalent is).

For each of the code examples below, the initial state is that of a
page containing a single stylesheet with a single @font-face rule and
no other declarations:

  // initial state for all examples below:
  @font-face { font-family: test; src: url(test.woff); }

  // 1. new @font-face rule ==> new FontFace added to document.fonts
  var s = document.styleSheets[0];
  assert(document.fonts.size == 1);
  assert(s.cssRules.length == 1);
  s.insertRule("@font-face { font-family: foo; src: url(bar.woff); }", 1);
  assert(s.cssRules.length == 2);
  assert(document.fonts.size == 2);

  // 2. new FontFace rule ==> no change to CSS OM
  var s = document.styleSheets[0];
  document.fonts.add(new FontFace("foo", "url(bar.woff)"));
  assert(documents.fonts.size == 2);
  assert(s.cssRules.length == 1);  // FontFace above *not* added

  // 3. changes to one size are reflected in the other side
  var s = document.styleSheets[0];
  var fontFaceRule = s.cssRules[0];
  var f = document.fonts[0];  // Set doesn't have this access but assume something equivalent 
  f.variant = "small-caps";
  fontFaceRule.weight = "bold";
  assert(f.variant == fontFaceRule.variant);
  assert(f.weight == fontFaceRule.weight);

  // 4. deleting a font in document.fonts does what ???
  var s = document.styleSheets[0];
  document.fonts.delete(document.fonts[0]);
  assert(s.cssRules.length == 0??? 1???);
  
  // 5. clearing out document.fonts does what ???
  var s = document.styleSheets[0];
  document.fonts.clear();
  assert(s.cssRules == ??? 0? 1?);

  // 6. modifying order of document.fonts does what?
  var s = document.styleSheets[0];
  s.insertRule("@font-face { font-family: foo; src: url(bar.woff); }", 1);
  var fontArr = [f for (f of document.fonts)];
  document.fonts.delete(fontArr[0]);
  document.fonts.add(fontArr[0]);
  assert(s.cssRules[0].fontFamily == ??? "test"? "foo"?);

I think you probably can see what I'm getting at.  Reflecting the
state of FontFaceSet and the individual rule sets that automatically
induce entries in it is complicated and needs to be spelled out.  I
think the sections of the spec that cover this need more details.

>From section 4.1:

# 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. This ordering must be maintained regardless of how the
# FontFace object is added; if a script manually removes and then
# re-adds one of them, it returns to its appropriate document-order
# position in the initial segment of the set entries. All
# non-CSS-connected FontFace objects must be sorted after the
# CSS-connected ones, in insertion order. 

I think here you need to not declare this but specify in detail how
this ordering is achieved.  I don't see how you can preserve the
ordering you're talking about since the ordering within document.fonts
is mutable by script.

Cheers,

John

Received on Wednesday, 11 September 2013 07:25:31 UTC