You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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).
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?
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.
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.
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.
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.
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.
@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.
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.
Activity
Yoric commentedon Oct 4, 2015
@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?
Manishearth commentedon Oct 4, 2015
cc @vvuk
Yoric commentedon Oct 4, 2015
If fontconfig-rs has an acceptable API, I can work on making it cross-platform.
nattokirai commentedon Oct 5, 2015
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).
Yoric commentedon Oct 5, 2015
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?
abonander commentedon Oct 5, 2015
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
vvuk commentedon Oct 5, 2015
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.
Yoric commentedon Oct 5, 2015
Would it be best to implement this as a separate lib?
abonander commentedon Oct 5, 2015
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.
Yoric commentedon Oct 5, 2015
The initial description of the issue didn't mention actual rendering. Is that still true?
nattokirai commentedon Oct 6, 2015
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.
retep998 commentedon Oct 6, 2015
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.
nattokirai commentedon Oct 6, 2015
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.
Yoric commentedon Oct 13, 2015
I'm currently working on #7029, so I may not have time to get started on this before a few weeks.
flacerdk commentedon Oct 2, 2016
@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.
Yoric commentedon Oct 2, 2016
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.
Auto merge of #20021 - jonleighton:lazy-font-group, r=mbrubeck,glennw
Auto merge of #20021 - jonleighton:lazy-font-group, r=mbrubeck,glennw
atouchet commentedon May 8, 2020
Does font-kit take care of this?
jdm commentedon May 8, 2020
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.