Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy load fonts in a FontGroup #20021

Merged
merged 2 commits into from Feb 22, 2018
Merged

Commits on Feb 22, 2018

  1. Lazy load fonts in a FontGroup

    This is a step towards fixing #17267. To fix that, we need to be able to
    try various different fallback fonts in turn, which would become
    unweildy with the prior eager-loading strategy.
    
    Prior to this change, FontGroup loaded up all Font instances, including
    the fallback font, before any of them were checked for the presence of
    the glyphs we're trying to render.
    
    So for the following CSS:
    
        font-family: Helvetica, Arial;
    
    The FontGroup would contain a Font instance for Helvetica, and a Font
    instance for Arial, and a Font instance for the fallback font.
    
    It may be that Helvetica contains glyphs for every character in the
    document, and therefore Arial and the fallback font are not needed at
    all.
    
    This change makes the strategy lazy, so that we'll only create a Font
    for Arial if we cannot find a glyph within Helvetica. I've also
    substantially refactored the existing code in the process and added
    some documentation along the way.
    jonleighton committed Feb 22, 2018
  2. Add test for FontContext/FontGroup functionality

    Unfortunately, this required quite a bit of changes to the non-test
    code. That's because FontContext depends on a FontCacheThread, which in
    turn depends on a CoreResourceThread and therefore lots of other data
    structures.
    
    It seemed like it would be very difficult to instantiate a FontContext
    as it was, and even if we could it seems like overkill to have all these
    data structures present for a relatively focused test.
    
    Therefore, I created a FontSource trait which represents the interface
    which FontContext uses to talk to FontCacheThread. FontCacheThread then
    implements FontSource. Then, in the test, we can create a dummy
    implementation of FontSource rather than using FontCacheThread.
    
    This actually has the advantage that we can make our dummy
    implementation behave in certain specific way which are useful for
    testing, for example it can count the number of times
    find_font_template() is called, which helps us verify that
    caching/lazy-loading is working as intended.
    jonleighton committed Feb 22, 2018
You can’t perform that action at this time.