Skip to content

Looking up CSS generic families #100

Open

Description

@SimonSapin

In CSS, the serif, sans-serif, cursive, fantasy, and monospace keywords when used without quotes have a different meaning than other keywords (which are space-joined into a single string) or quoted strings. They are "generic" font families.

Currently Source::select_family_by_generic_name allows looking up concrete font families from those keywords, but it is #[doc(hidden)] with a FIXME comment about returning multiple families.

In the specification:

https://drafts.csswg.org/css-fonts/#generic-font-families

All five generic font families must always result in at least one matched font face, for all CSS implementations. However, the generics may be composite faces (with different typefaces based on such things as the Unicode range of the character, the language of the containing element, user preferences and system settings, among others). They are also not guaranteed to always be different from each other.

https://drafts.csswg.org/css-fonts/#font-style-matching

User agents may choose the generic font family to use based on the language of the containing element or the Unicode range of the character.

Based on other uses, the spec appears to misuse "character" to mean Unicode code point. But then “When text contains characters such as combining marks” there’s specific handling based on grouping by grapheme cluster.

So perhaps Source::select_family_by_generic_name should be unhidden, but after some API change. Would an input "character" (perhaps a char code point, or a &str grapheme cluster?) be useful to any of the backends? What about an optional language tag?

Activity

  1. pcwalton commented on Sep 13, 2019

    @pcwalton
    Contributor

    My gut tells me that having a "hint" structure could be useful as a parameter to the font selection methods. This hint structure could optionally include an &str EGC and a language tag. I like the name "hint" because it strongly implies that we can modify the algorithm over time, since the specs are clearly imprecise right now. It will be fine if Servo relies on the details of the matching algorithm of this "hint", but calling it a "hint" suggests to other users of font-kit that they should not rely on these details, because they're subject to change as the CSS and/or Unicode specifications evolve.

    How does that sound?

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions