que-etc / resize-observer-polyfill

A polyfill for the Resize Observer API
MIT License
1.75k stars 132 forks source link

Trigger refresh on font load #54

Open ellan11 opened 5 years ago

ellan11 commented 5 years ago

It appears that in current implementation refresh won’t be triggered when a font is loaded, and elements’ resize caused by the font load won’t be detected. Is this assumption correct, and if so do you plan to add a support for it?

HolgerJeromin commented 5 years ago

FYI: I needed that event in another project. We need browser support for that, which is not polyfillable. Here with typescript annotations:

// register event for loading new font files
const fontFaceSet: EventTarget = (document as any).fonts;
if (fontFaceSet && fontFaceSet.addEventListener) {
    fontFaceSet.addEventListener('loadingdone', () => {
        // layout / glyphs could have been changed
    });
} else {
    // no fallback is possible without this API as a font files download can be triggered
    // at any time when a new glyph is rendered on screen
}
ellan11 commented 5 years ago

Cool, thanks. I'll use that approach to trigger refresh when fontFaceSet is supported, and will try to upstream.