Skip to content

Cross-platform font selection engine #4901

Closed

Description

@kmcallister

See discussion on #1908.

@cybergeek94:

Sounds like a new library project: cross-platform font querying using native APIs.

@nattokirai:

Yeah, the level of support for various things related to fonts needed by a modern web browser varies across platforms. In general, you'll need to maintain some sort of font lookup interface and fill in what's needed on a per-platform basis. OSX and DirectWrite are fairly easy, fontconfig and Android are relatively painful. Gecko uses platform API's to maintain a list of font families available and fills in data for a given family when it's actually used. Font style matching really needs to be done by servo code and not punted to platform-level API's which have their own rules for style matching.

Key features of a font system interface:

  • lookup a font family name
  • enumerate styles within a single family
  • select a given face within a family based on CSS font properties (i.e. weight/width/slant)
  • activate a font from data (with required sanitation such as OTS)
  • lookup individual font faces via a fullname or Postscript name

For browsers you'll also need:

  • system font fallback, the ability to find a font for a given character
  • mappings of generics based on language/script (e.g. sans-serif for Arabic and Japanese are not the same font)
  • ability to read (and cache) font metrics and font table data

See also #3369, #3030, #1677, #249, #190, #186, and many others.

cc @Manishearth, @jdm

Activity

  1. added
    E-very-complex
    B-feature-tracking
    on Feb 12, 2015
  2. Yoric commented on Oct 4, 2015

    @Yoric
    Contributor

    @kmcallister, is this still useful? If so, I might try and look at it, at least for some platforms.

    Also, is there any kind of consensus for an API?

  3. Manishearth commented on Oct 4, 2015

    @Manishearth
    Member
  4. Yoric commented on Oct 4, 2015

    @Yoric
    Contributor

    If fontconfig-rs has an acceptable API, I can work on making it cross-platform.

  5. nattokirai commented on Oct 5, 2015

    @nattokirai

    Fontconfig is not an API that you want to base anything on. It is basically a "pick a font" API that doesn't, by intention, cover all the font services needed by a browser engine. A cross-platform API needs to integrate appropriately with underlying system font services, which means doing more work for older platforms (e.g. XP, Linux) and less for more modern ones (DirectWrite, CoreText).

  6. Yoric commented on Oct 5, 2015

    @Yoric
    Contributor

    As I have little-to-no knowledge in (cross-platform) font management, any suggestion of a nice API would be very useful. Should I try to ape CoreText (actually, did you mean CoreText or Apple Type Services?) or DirectWrite, for instance?

  7. abonander commented on Oct 5, 2015

    @abonander

    cc @retep998 for status on DirectWrite bindings in winapi, I can't seem to find them. The DirectWrite API is C++/COM so it might be a little more involved to call into.

    Servo actually already has CoreText bindings. I don't know how useful they are though.

    Edit: looks like the DirectWrite bindings have yet to be filled out: https://crates.io/crates/dwrite-sys

  8. vvuk commented on Oct 5, 2015

    @vvuk
    Contributor

    DWrite is COM; as far as I can tell, the winapi bindings are complete for it (despite the docs saying otherwise). The only public entry point is via the DWriteCreateFactory factory getter, everything else is done through interface structs. e.g. https://github.com/retep998/winapi-rs/blob/master/src/dwrite.rs

    For an API for this, I would suggest looking at what Gecko does -- gfxPlatformFontList/gfxFont and friends. It's been fairly recently designed and is pretty clean, though is support for lots of things that servo may not want to deal with right away. It would also give you an idea of how it maps to the various platforms.

  9. Yoric commented on Oct 5, 2015

    @Yoric
    Contributor

    Would it be best to implement this as a separate lib?

  10. abonander commented on Oct 5, 2015

    @abonander

    Definitely. Cross-platform font selection isn't just a problem for browser engines. It would be really beneficial if it were reusable for other projects.

  11. Yoric commented on Oct 5, 2015

    @Yoric
    Contributor

    The initial description of the issue didn't mention actual rendering. Is that still true?

  12. nattokirai commented on Oct 6, 2015

    @nattokirai

    Font management, shaping and rendering are really three separate pieces that are pretty distinct, especially the rendering part. I would keep rendering separate.

    Note that you really need more than just "font selection", you need a way of managing font resources efficiently.

  13. retep998 commented on Oct 6, 2015

    @retep998

    Do note that on Windows, DirectWrite handles all aspects of dealing with fonts including management shaping and rendering.

    I'm currently polishing up the dwrite bindings so I can bump them on crates.io soon.

  14. nattokirai commented on Oct 6, 2015

    @nattokirai

    Gecko uses harfbuzz for shaping on all platforms with the exception of Apple-flavored TrueType fonts which require CoreText shaping. Using DirectWrite to do shaping will work just fine but you may not end up with consistent results across platforms and you increase your per-platform testing requirements.

  15. Yoric commented on Oct 13, 2015

    @Yoric
    Contributor

    I'm currently working on #7029, so I may not have time to get started on this before a few weeks.

  16. flacerdk commented on Oct 2, 2016

    @flacerdk
    Contributor

    @Yoric: Are you currently working on this? Or is anyone else? I've been looking into how to improve font selection on Linux (see e.g. #12944), but I figured an ideal solution would likely involve something like this. I'd volunteer myself, but testing on Windows and OS X would be very time-consuming for me. I'd be willing to look into handling Fontconfig, though.

  17. Yoric commented on Oct 2, 2016

    @Yoric
    Contributor

    Sorry about that, I've been asked to work on other stuff and I forgot to mention it. So, anyone, feel free to pick this up.

  18. added 2 commits that reference this issue on Feb 22, 2018
  19. atouchet commented on May 8, 2020

    @atouchet
    Contributor

    Does font-kit take care of this?

  20. jdm commented on May 8, 2020

    @jdm
    Member

    It takes care of some of it. I don't see a good reason for this issue to remain open, though, since we have many of the requirements implemented in Servo.

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

    A-platform/fontsB-feature-trackingE-very-complex

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions