Closed Bug 1086207 Opened 10 years ago Closed 10 years ago

font load events and promise resolution do not occur in correct order

Categories

(Core :: CSS Parsing and Computation, defect, P3)

defect

Tracking

()

RESOLVED FIXED

People

(Reporter: jtd, Assigned: heycam)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

The Font Loading API allows for fonts to be created and added to the set of fonts used by a document:

  var f = new FontFace(name, fontURL);
  document.fonts.add(f);

Fonts can be explicitly loaded:

  f.load();
  assert(f.status != "unloaded");

This works but when the load happens via layout lazily loading the font, the status of the face is never updated correctly.

  document.ready.then(function() {
    assert(f.status != "unloaded");
  });

This second assertion fails with current code.
Note: layout.css.font-loading-api.enabled must be set to true to run the testcase.
Blocks: 1028497
It does seem to be set to loaded, if I inspect its status in the Web Console, so maybe it is happening later than it should, or document.fonts.ready is resolving earlier than it should.
(In reply to Cameron McCormack (:heycam) (away October 6 - November 5) from comment #2)
> It does seem to be set to loaded, if I inspect its status in the Web
> Console, so maybe it is happening later than it should, or
> document.fonts.ready is resolving earlier than it should.

Checking the load status on a timeout does show it as loaded. But I think the underlying problem here is the weird mStatus flag in FontFace. I think that probably should *not* exist. 

Part of this may be a spec problem. Looking over the spec now, I'm not sure the relationship of 'loading' on both the FontFace and FontFaceSet to pending font loads makes sense. Effectively this requires a sync reflow whenever FontFace.status or FontFaceSet.status is checked. I think it's trying to keep the 'status' state in sync with the ready promise. I don't think this is needed.

There's no clear detail about whether reflows need to be done before FontFace.status is returned but it does say that pending loads need to be cleared before FontFaceSet.status is returned. And since the defn of FontFaceSet.status == "loaded" is "no FontFace.status is loading", that seems to require what the code says it requires.

However, either way I think FontFace.status should *always* return the state of the underlying gfxUserFontEntry.
While not entirely clear, the spec indicates that status changes to FontFace objects should take place as a condition for the ready() promise being fulfilled. Also, looking over the spec indicates that there's no need to wait for pending layout operations to complete in the case of FontFace.status (but there is for FontFaceSet.status).
Wrote an extended testcase, looks like we have some serious problems to deal with here. Very little is correct... :(

Testcase: creates a font face object with a data URL, adds it to the font set, then set up handlers to log font and font set status on both events and when promises are resolved.

Note: the ready promise on FontFaceSet in Chrome is a *function* that returns a promise rather than a promise attribute.

Chrome output (as expected):
add new font - font unloaded, set loaded
onloading event - font loading, set loading
after layout - font loading, set loading
font loaded - font loaded, set loading
onloadingdone event - font loaded, set loaded
document.fonts ready - font loaded, set loaded

Gecko trunk output (*sigh*):
onloadingdone event - font unloaded, set loaded (195x !!!)
after layout - font unloaded, set loaded
<< too much recursion >>
document.fonts ready - font unloaded, set loaded
onloading event - font loaded, set loaded
onloadingdone event - font loaded, set loaded
font loaded - font loaded, set loaded
Priority: -- → P3
Summary: font load status not set correctly when load occurs via layout → font load events and promise resolution does not occur in correct order
Summary: font load events and promise resolution does not occur in correct order → font load events and promise resolution do not occur in correct order
Do we need to fix this before shipping the font loading API?

Also, was there some other question you wanted my feedback on?
Flags: needinfo?(jdaggett)
(In reply to David Baron [:dbaron] (UTC-4) (needinfo? for questions) (away/busy Oct. 24-31) from comment #6)
> Do we need to fix this before shipping the font loading API?

Yes, we need to fix this before enabling the pref. There are synchronization issues here and that will affect display if not fixed (e.g. if an loadingdone event fires before the font is actually loaded, use of a font within canvas will not display in the desired way).

> Also, was there some other question you wanted my feedback on?

I originally cc'ed you because I thought there was a spec issue (comment 3) but after reading through it a little more, I think the algorithms in the spec are correct but some of the definitions are confusing and not quite correct. They probably could be explained better but they are sufficient at this point I think.
Flags: needinfo?(jdaggett)
(In reply to John Daggett (:jtd) from comment #7)
> Yes, we need to fix this before enabling the pref. There are synchronization
> issues here and that will affect display if not fixed (e.g. if an
> loadingdone event fires before the font is actually loaded, use of a font
> within canvas will not display in the desired way).

OK, I filed bug 1088437 to track enabling the API, and made this bug block it.

> I originally cc'ed you because I thought there was a spec issue (comment 3)
> but after reading through it a little more, I think the algorithms in the
> spec are correct but some of the definitions are confusing and not quite
> correct. They probably could be explained better but they are sufficient at
> this point I think.

Probably best for you to send feedback directly to www-style rather than through me, and then let me know if there are issues there that you need me bug people in the WG about if you don't get an adequate response.
(In reply to David Baron [:dbaron] (UTC-4) (needinfo? for questions) (away/busy Oct. 24-31) from comment #8)
> Probably best for you to send feedback directly to www-style rather than
> through me, and then let me know if there are issues there that you need me
> bug people in the WG about if you don't get an adequate response.

Yup, that's what I did. I think the definition of FontFaceSet.status should be revised to be more in line with what the actual algorithm says about when 'status' changes occur:

http://lists.w3.org/Archives/Public/www-style/2014Oct/0373.html
Blocks: 1094571
Blocks: 1094576
Assignee: jdaggett → cam
There are a few different issues here so I'm going to break them off into separate bugs.
Depends on: 1144450
Fixed by the work in dependent bugs.
Status: NEW → RESOLVED
Closed: 10 years ago
Depends on: 1145506
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: