Skip to content

Server-Side Font Face CSS Generation and Printing: Ongoing Roadmap (formerly the Fonts API) #41479

Closed

Description

@hellofromtonya

This is an epic ticket to share the ongoing roadmap including:

Updates:

Changed to Font Face: to server-side generate and print fonts' @font-face styles

With the introduction of the new Fonts Library, the role of the Fonts API has significantly changed as noted in #41479 (comment).

Previously, its roles were:

  • Role 1: Generate and print the @font-face styles for all “enqueued” fonts.
  • Role 2: Provide a means for plugins to present fonts to users, who can then decide whether to use these fonts (i.e. through the Site Editor).

Its new role is:

  • Generate and print the @font-face styles for all theme defined and user activated fonts.

Fonts will be presented to users via the Fonts Library, rather than through the Fonts API.

Plugins will no longer interact with the Fonts API. Instead, they will integrate directly into the Font Library (once that capability exists).

Font Face "gets" the fonts to print from Theme JSON merged data layer. Fonts are no longer registered or enqueued directly with it.

A full API is no longer needed. Thus, Font Face replaces the Fonts API.

Vision

As part of fonts management and Fonts Library,

This API's job is to provide the backend capabilities to support the "font library" to include font management and dynamic building of the @font-face styles.

The "font library" feature will continue to be built, refined, stabilized, and tuned over multiple WordPress releases.

Font Library

See #50927.

The idea is to have the concept of a font library on a site to

  • manage and catalogue fonts
  • and then provide users an interface for them to select which fonts to use in the live site.

The fonts in the library can come from:

  • a theme bundling them
  • a user uploading fonts they purchased
  • a plugin

The fonts to be used in the site are saved and available via Theme JSON merged data layer, i.e. WP_Theme_JSON_Resolver_Gutenberg::get_merged_data()->get_settings().

FAQ

What about classic sites?

Yes, supported ✅

Classic themes and plugins can have their @font-face styles generated and printed. How?

Classic themes have 2 options:

Plugins supporting classic sites can use Option 1.

Ongoing work

Architecture

⭐ Required for Core introduction:

Performance

⭐ Required for Core introduction:
None

Feature needs

⭐ Required for Core introduction:
None

Future enhancements

  • Add font management UI to Customizer for classic themes

Bugs

None

Documentation

Backports

Future.

Tracking key

✅ Done
⚪ WIP: work in progress
🟡 Experiment WIP
🍏 in testing or code review
🔴 Danger > immediate action needed
🚫 Blocked

⭐ Needed for WP Core introduction

Activity

  1. added
    [Type] OverviewComprehensive, high level view of an area of focus often with multiple tracking issues
    on Jun 1, 2022
  2. added
    [Type] Tracking IssueTactical breakdown of efforts across the codebase and/or tied to Overview issues.
    on Jun 20, 2022
  3. hellofromtonya commented on Jun 23, 2022

    @hellofromtonya
    ContributorAuthor

    The vision for the font management through a formal Webfonts API is now available in the description of this roadmap (ie in the Vision section).

    The first priority is to solidify the architecture as all other tasks will be affected by these architectural changes:

    Once these 2 tasks are done, then the remaining tasks can be prioritized along with impacts to update each of them to fit within the architectural changes. I removed the priority labels from each of these other tasks.

  4. azaozz commented on Jun 24, 2022

    @azaozz
    Contributor

    This sounds great! A clear and well defined vision makes the tasks ahead much easier to understand.

    Trying to get into a bit more details, perhaps "brainstorm" a little more. One of the hard performance related questions would be: What happens when somebody decides to register the whole collection from https://fontsource.org/ (more than 1600 fonts)? It's pretty pointless (will need a dedicated UI and still the users will have a pretty hard time selecting fonts from such a huge list) but that doesn't mean it's not going to happen.

    That led to couple of questions:

    1. What is the purpose of registering the webfonts outside of the Global Styles UI. Would registering be needed even there, or a "list of the names of available fonts" (perhaps with preview images for the UI) would be sufficient.
    2. How is that UI going to work with possibly hundreds of fonts?

    For the first question, in most cases it seems registering can be done together with the enqueueing only for the fonts that are in use. That will speed things up and perhaps reduce complexity a little. Thinking a bit further implementation-wise: should registering a font be needed for enqueueing it? Seems not. A "prior art" is how scripts can be enqueued without a need to be registered.

    The second question is harder. Are we talking about building UI similar to the Google's webfonts picker? Seems anything less may not be enough, perhaps. Not sure what a UI for picking one out of a hundred fonts may be, but thinking it would be best to have an idea about it before deciding on the back-end code, so the requirements of that (and future) UI are met.

  5. adamsilverstein commented on Jul 11, 2022

    @adamsilverstein
    Member

    Great to see this overview issue @hellofromtonya - this is super helpful as I've been struggling to keep up with the Fonts API proposals & progress.

    I noticed several features I see in other font APIs that aren't mentioned here and wanted to know if these are on your roadmap at all or would be something to propose for a future iteration:

    • Adding DNS prefetch/preconnect/preload tags to font enqueues
    • Supporting for downloading fonts (to avoid external requests), ideally built in/automatic
    • Font display attribute (to control what happens during loading)
    • subset support (to load part of a font)
    • encode fonts to base64/directly inject into global styles (avoids an extra server request)
  6. desrosj commented on Jul 14, 2022

    @desrosj
    Member

    One thing that's been bugging me is that I feel like "Webfonts" is wrong when I read it. I did some searching around, and my findings seem to point towards "Web fonts" as the preferred way to refer to this. I know this is a nit, but I think it's important to get it right and be consistent. here are some authoritative pages I found pointing to Web Fonts:

    Other pages for Webfonts

  7. azaozz commented on Jul 27, 2022

    @azaozz
    Contributor

    Supporting for downloading fonts (to avoid external requests), ideally built in/automatic

    @adamsilverstein Yeah, support for preloading is needed, but not sure what "downloading" has to do here? Thought is was decided that this API is for local fonts only. This has numerous advantages as discussed before. Downloading what, and from where? :)

    I'd also think that if a plugin wants to use external fonts from a CDN, like Google fonts, it would still consider downloading the open source fonts as available at places like https://github.com/fontsource/fontsource and not trying to capture the CDN's output (which may also have some compatibility or licensing issues as it is closed source).

  8. hellofromtonya commented on Jul 28, 2022

    @hellofromtonya
    ContributorAuthor

    @mtias and I discussed this roadmap for both block and classic themes. From that discussion, I've updated the description of this ongoing roadmap including the "font library" vision, technical details, and a new FAQ section.

    The changes include publicly exposing enqueue and remove functionality.

  9. hellofromtonya commented on Jul 28, 2022

    @hellofromtonya
    ContributorAuthor

    Thought is was decided that this API is for local fonts only. ~ @azaozz

    Bundled in the API is a local fonts provider. It does not include remote font foundry handling. It does provide the means for plugin authors to create custom providers, such as to handle (a) an alternative local fonts approach or (b) remotely hosted fonts.

    IMO I don't think Core should force only local fonts.

    cc @adamsilverstein @azaozz

  10. adamsilverstein commented on Jul 29, 2022

    @adamsilverstein
    Member

    Thanks for clarifying @hellofromtonya and @azaozz

    was decided that this API is for local fonts only

    It does provide the means for plugin authors to create custom providers, such as to handle (a) an alternative local fonts approach or (b) remotely hosted fonts.

    🎉 Great!

  11. hellofromtonya commented on Aug 1, 2022

    @hellofromtonya
    ContributorAuthor

    I opened a separate issue for renaming consideration per @desrosj suggestion. Let's move the naming discussion to here #42868

  12. hellofromtonya commented on Aug 17, 2022

    @hellofromtonya
    ContributorAuthor

    Tracking the block level typography consistency effort #43242

  13. hellofromtonya commented on Dec 19, 2022

    @hellofromtonya
    ContributorAuthor

    ⭐ Status Update:

    Status: Blocked by architectural work.

    DONE: ✅ The major architectural redesign (See #41481) is now merged. The new architecture is a code rewrite which has breaking changes. Some high level details:

    • Changes data structures and publicly exposed functions/methods.
    • Includes a temporary backwards-compatible (BC) layer that throws deprecation notices to alert developers of where they need to modify their code to use the API. This BC layer will not be backported to Core.

    NEXT: ⚪ There are 2 more architectural tasks that need to be completed to unblock the remaining bugs, performance, and feature work can continue.

    👉 Where can you help?

  14. hellofromtonya commented on Jan 18, 2023

    @hellofromtonya
    ContributorAuthor

    ⭐ Status Update ⭐
    18 Jan 2023

    Status:

    • Architecture is now unblocked 🎉
    • Work on remaining issues is underway

    Big Picture

    👉 It's a NEW API
    The API has been completely redesigned with a new architecture and renamed including all publicly available functions, classes, and methods.

    👉 BC Layer
    A backwards-compatibility (BC) layer (with deprecations) was added to ensure sites using this API in production keep running while giving developers time to upgrade to the new API. This BC Layer will NOT be backported to Core.

    Who's impacted?

    • Any external code (outside of Gutenberg) that is directly interfacing with the API.
      While the BC Layer will keep sites running, extenders will need to upgrade their code to use the new API, especially once the API is backported to WP Core.

    • Theme's using theme.json are NOT impacted.
      Why? This file is automatically ingested, processed, and defined fonts registered and enqueued within the API.

    • All open PRs (see below)

    ⭐ 👉 Next steps

    • Identify must-haves for WP 6.2 as these will be the highest priorities.

    These 2 issues are must-haves:

    All open PRs are impacted. This means each open issue and any of its PRs must be evaluated one-by-one and if still relevant, rebased and rebuilt to apply changes to the new API.

    TODO:

    1. Evaluate each PR to determine:
      • Is it still needed?
      • If yes, how should the changes be introduced into the new API?
      • If yes, what priority level should it be for WP 6.2?
    2. Rebase and rebuild PRs:
      Each PR will need to be rebased on top of trunk to bring the new API into its scope. In most cases (if not all), the PR will need to rebuilt.
  15. 17 remaining items

  16. hellofromtonya commented on Jun 21, 2023

    @hellofromtonya
    ContributorAuthor

    Sorry for the delay in responding to you @webd-uk.

    How can we find out more about this because it will need to be used to add fonts that a plugin previously added via other methods. Specifically ... if a user has already selected to use a font via an existing plugin, will there be a way for the plugin to seamlessly pre-select the font via this new Font Library registration method for the user so that the user doesn't have to select the font again?

    If the user has already selected a plugin defined font, then that font should be saved in the database when saving those selections in the Site Editor. Those fonts then should be within the theme.json merged data, i.e. WP_Theme_JSON_Resolver_Gutenberg::get_merged_data()->get_settings() within ['typography']['fontFamilies'].

    Then when it's time to "print" @font-face styles, the new Fonts API (or whatever name it becomes) pulls from WP_Theme_JSON_Resolver_Gutenberg::get_merged_data()->get_settings() to extract the fonts to print.

    As for what gets "activated" in the Font Library, I think it's also using that same data.

    What isn't there yet is the means for a plugin to "register" its defined fonts with the Font Library.

    I'd suggest asking the question and contributing in the main issue #45271 or in the Font Library's WIP PR #50927.

  17. webd-uk commented on Jun 22, 2023

    @webd-uk

    I'd suggest asking the question and contributing in the main issue #45271 or in the Font Library's WIP PR #50927.

    Thank you, @hellofromtonya! I will definitely be doing that but need to read up on everything first. Thanks again, Wordpress has needed this built-in feature for soooooooo long!

  18. hellofromtonya commented on Jun 22, 2023

    @hellofromtonya
    ContributorAuthor

    Update 22 Jun 2023

    New Learnings

    New Learnings since my 19th Jun update:

    What currently works with the Fonts Library?

    WordPress Core ✅
    Fonts API ❌

    The stopgap code in WordPress Core since 6.0.0 works with the Fonts Library _wp_theme_json_webfonts_handler() and supports classic themes adding a theme.json file with only fonts defined. ✅

    However, the Fonts API in Gutenberg does not work with the Fonts Library and must be changed before the Fonts Library is merged. ❌

    Should the Fonts API's architecture change?

    Yes! ✅

    It needs a near complete redesign.

    Issue #51769 is for the redesign, transforming the Fonts API into only a Font Face styles generator and printer.

    WIP PR #51770 is what I envision as the redesign.

    What about classic sites?

    Yes, supported ✅

    Classic themes and plugins can have their @font-face styles generated without requiring register or enqueue. How?

    Classic themes have 2 options:

    1. Option 1: Add a callback function hooked in 'wp_head' and 'admin_print_styles' and within that callback function, invoke a new print method and pass their fonts to it.
    2. Option 2: Add a theme.json file that only defines the fonts. See issue [Fonts API] Proposal: classic themes define fonts in a theme.json file #51714 for more information.

    Plugins supporting classic sites can use Option 1.

    What about font-face property validation?

    Yes, still required ✅

    To support classic sites and potentially other needed customizations, the new Font Face design exposes a print( $fonts ) method that accepts an array of fonts. Those are the fonts that will be processed to generate and print the @font-face styles.

    As any source could invoke that print( $fonts ) method, the passed in font-face properties still require validation. Why? To (a) protect the code from missing properties or invalid data types and (b) provide extenders guidance of where problems are in the array of fonts.

    What about "providers"?

    Fonts Library only supports serving @font-face src from local assets. It has Google Fonts built into it, but downloads the font files to wp-content/fonts/ for local access.

    To keep parity with the Fonts Library, the Fonts API support of custom providers will be removed. The new design will only support local font files. This change will ensure fonts work the same on all types of sites.

    If enough of need is discovered, then a future enhancement could be to add custom provider support.

    What about sites currently using the Fonts API?

    The API is experimental. However, the API has taken the approach of supporting backward compatibility through the BC Layer to avoid sites breaking.

    The new Font Face generation is a big big change. Care is needed to consider how to safeguard sites currently using the Fonts API while guiding developers towards where and what needs to change.

  19. changed the title [-]Fonts API: Ongoing Roadmap (formerly the Webfonts API)[/-] [+]Server-Side Font Face CSS Generation and Printing: Ongoing Roadmap (formerly the Fonts API)[/+] on Jul 18, 2023
  20. hellofromtonya commented on Jul 18, 2023

    @hellofromtonya
    ContributorAuthor

    The description of this roadmap is now updated for "Font Face", i.e. to define its new role in font management and its scope of work.

  21. hellofromtonya commented on Aug 21, 2023

    @hellofromtonya
    ContributorAuthor

    Update

    Font Face is ready to be introduced into WordPress Core. It is a direct replacement for _wp_theme_json_webfonts_handler() in that it processes block themes with the same @font-face styles while providing the means for classic themes and plugins to also print their font's @font-face styles.

    TODO:

  22. hellofromtonya commented on Aug 22, 2023

    @hellofromtonya
    ContributorAuthor

    Here's the Core Trac ticket for merging Font Face into Core https://core.trac.wordpress.org/ticket/59165.

  23. annezazu commented on Mar 21, 2024

    @annezazu
    Contributor

    Closing this out as https://core.trac.wordpress.org/ticket/59165 shipped. Let me know if that's incorrect and I can reopen. Thanks for all the hard work here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] Font Library[Feature] TypographyFont and typography-related issues and PRs[Type] OverviewComprehensive, high level view of an area of focus often with multiple tracking issues[Type] Tracking IssueTactical breakdown of efforts across the codebase and/or tied to Overview issues.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions