Skip to content

_brand.yml: google returning different font names confuses us #11947

Open

Description

@cscheid

This works:

typography: 
  fonts:
    - source: google
      family: 'Source Sans Pro'
  base: 
    family: 'Source Sans Pro'

This doesn't:

typography: 
  fonts:
    - source: google
      family: 'Source Sans 3'
  base: 
    family: 'Source Sans 3'

Even though "Source Sans 3" is the name of the font on Google Fonts. The issue appears to be that the CSS query returns Source Sans Pro as the name of the font, but we try to use Source Sans 3, and faceplant.

Activity

  1. added
    bug
    on Jan 24, 2025
  2. self-assigned this
    on Jan 24, 2025
  3. added
    brand
    on Jan 24, 2025
  4. added this to the v1.7 milestone on Jan 24, 2025
  5. gordonwoodhull commented on Jan 25, 2025

    @gordonwoodhull
    Member

    Related to #11278 on the Typst side, which I stopgapped with some documentation because it seemed pretty rare.

    But if the CSS query returns the actual font name, that's much better!

  6. modified the milestones: v1.7, v1.8 on Apr 9, 2025
  7. gordonwoodhull commented on May 15, 2025

    @gordonwoodhull
    Member

    I did random testing of font names from a couple of lists of google fonts published in 2023, and wasn't able to find any instances where the CSS query response does not match the request.

    Source Sans 3 now returns a working font file containing the family name Source Sans 3 - the above example works in Typst now.

    The example in #11278, Sono, still returns a font file containing the family name Sono Extralight Monospace and still fails. But the CSS query response also says Sono so there would be no shortcut. We would need to read the font file to find the correct font family name.

  8. cscheid commented on May 15, 2025

    @cscheid
    MemberAuthor

    We could do the following (very ugly):

    write a script that goes over all fonts in google fonts and bunny, and performs this consistency check. Then we write a translation function that fixes bad names. In practice this won't solve every problems, but will probably solve all of our problems...

  9. gordonwoodhull commented on May 19, 2025

    @gordonwoodhull
    Member

    Across 1837 Google fonts, 72 have a different name after loading the font in Typst, and 6 had errors in processing.

    Of the different names, 42 are false positives

    • font family names are not case sensitive
    • if the Typst-accepted font family name is a prefix of the Google Fonts font family name, you could just request the prefix and it will work

    Here are the 30 remaining differences, with Google Fonts family name first and Typst font family name second:

    Ballet,Ballet 16pt
    Bodoni Moda,Bodoni Moda 11pt
    Bricolage Grotesque,Bricolage Grotesque 96pt
    DM Sans,DM Sans 9pt
    Geologica,Geologica Thin Roman
    Headland One,HeadlandOne
    Imbue,Imbue Thin 10pt
    M PLUS Rounded 1c,Rounded Mplus 1c
    Merriweather,Merriweather Light 18pt
    Montagu Slab,Montagu Slab 144pt
    Nanum Gothic,NanumGothic
    Nanum Gothic Coding,NanumGothicCoding
    Nanum Myeongjo,NanumMyeongjo
    Newsreader,Newsreader 16pt 16pt
    Noto Sans Phags Pa,Noto Sans PhagsPa
    Nova Mono,NovaMono
    Nunito Sans,Nunito Sans 12pt ExtraLight 12pt
    Pathway Extreme,Pathway Extreme 8pt Thin 12pt
    Playfair,Playfair 5pt
    Recursive,Recursive Sans Linear
    Roboto Serif,Roboto Serif 20pt
    Sirin Stencil,SirinStencil
    Sono,Sono ExtraLight Monospace
    Texturina,Texturina Medium 12pt
    Wavefont,Wavefont Thin Rounded
    Agu Display,Agu Display Uzo
    Bodoni Moda SC,Bodoni Moda SC 11pt
    Hedvig Letters Serif,Hedvig Letters Serif 24pt 24pt
    Poetsen One,PoetsenOne
    

    It's unclear what's going on, but it looks like a bug somewhere in the Typst font stack. It does not seem to be related to variable fonts, i.e. some of these are variable and some are not.

    The point sizes as part of the name are particularly wacky, and I have no explanation for that. AFAIK TrueType fonts were always variable on font size? Obviously these work at other point sizes.

    So yeah, it's possible to provide a mapping for Typst, and it is perhaps more ugly than expected.

    It would be nice to do the same analysis for HTML, but I don't know how to generate the mapping and also would need to learn how to better troubleshoot fonts in the browser. It's clear that it's interpreting names differently from Typst, since Source Sans 3 is not on this list.

    Google Fonts also has some opaque mapping, since Source Sans Pro does not bring up anything on fonts.google.com, nor is it in the list generated from their API, but it works via CSS query.

    My sed/bash script for this analysis is here:
    https://github.com/gordonwoodhull/font-name-mismatch-testing

  10. cscheid commented on May 19, 2025

    @cscheid
    MemberAuthor

    This is a very interesting analysis and result; we should consider sharing it with the Typst folks.

  11. gordonwoodhull commented on May 19, 2025

    @gordonwoodhull
    Member

    fc-scan also returns the same names most, but not all of the time. E.g. it returns Source Sans 3 ExtraLight, which also doesn't work for HTML.

    There is fuzziness about font family name suffixes that I don't really understand, see e.g. typst/typst#4773

  12. modified the milestones: v1.8, Future on Jul 17, 2025
  13. gordonwoodhull commented on Oct 14, 2025

    @gordonwoodhull
    Member

    Important clarification in

    Even where the Typst-recognized font family name is a prefix of the Google font family name, you can get in trouble because it's impossible to distinguish between multiple variants of the font family which get mapped to the same Typst font family name.

    I've updated the script to also detect these "ambiguous" font family names due to the prefix being another valid font family name.

    Here are the additional fonts affected:

    Archivo,Archivo Black
    Asap,Asap Condensed
    Barlow,Barlow Condensed,Barlow Semi Condensed
    BioRhyme,BioRhyme Expanded
    Bungee,Bungee Hairline
    Cabin,Cabin Condensed
    Encode Sans,Encode Sans Condensed,Encode Sans Expanded,Encode Sans Semi Condensed,Encode Sans Semi Expanded
    Fira Sans,Fira Sans Condensed,Fira Sans Extra Condensed
    IBM Plex Sans,IBM Plex Sans Condensed
    PT Sans,PT Sans Narrow
    Reddit Sans,Reddit Sans Condensed
    Roboto,Roboto Condensed
    Saira,Saira Condensed,Saira Extra Condensed,Saira Semi Condensed
    Sofia Sans,Sofia Sans Condensed,Sofia Sans Extra Condensed,Sofia Sans Semi Condensed
    Ubuntu,Ubuntu Condensed
    Stint Ultra Condensed,Stint Ultra Expanded
    

    These ones have errors: Buda,Coda Caption,Molle,Roboto Flex,Sunflower,UnifrakturCook

    I don't think I captured the errors from the first run, but I think these must be disjoint, so 12 in total have errors in processing.

  14. cderv commented on Oct 15, 2025

    @cderv
    Member

    As we know about them thanks to your work, would it make sense while we find a fix or wait for a fix in Typst, to warn the users if one of these fonts is used?

    This would be cool user experience to know in advance why an errors (or silent non working) would happen

  15. gordonwoodhull commented on Oct 15, 2025

    @gordonwoodhull
    Member

    Good idea... let me think about what we could say here.

    I'd want the warning to be accurate and precise, but this is not trivial to explain...

  16. gordonwoodhull commented on Oct 17, 2025

    @gordonwoodhull
    Member

    I did further testing, and consulted DeepWiki to help understand Typst's font resolution code. (Note: it does hallucinate some of the training data and even suffixes like Semicondensed, but I think the analysis is mostly correct?)

    I learned:

    1. The "ambiguous fonts" are not a bug - Typst is treating these variants as variants, and if the font metadata is correct, you can load all the variants (as separate fonts resources in brand.yml) and then select them using style, weight, andstretch.
    2. The quality of font metadata varies between font family, but where it is correct, it works. I've added printing of Typst's font variant data to the mismatch.sh script in the repo. For example we can see that Archivo Black is not properly distinguished in Weight from Archivo, but Fira Sans, Fira Sans Condensed, and Fira Sans Extra Condensed are properly distinguished by Stretch. It would be possible to automate this further and classify each "ambiguous font" by whether it has working font metadata, but I'll leave that for another time.
    3. The point sizes that are shown in most of the name mismatches in the first run are "optical sizes", which is another way that font variants worked before variable fonts. They can be used at any size, but the optical size is the optimal size. Typst does not try to trim these suffixes, so you have to use the full name.

    Here is Claude's classification of the actual discrepancies, with the Google font family on the left and the Typst font family name on the right.

     │ 1. Font names with optical size suffix:                                           │
     │ ----------------------------------------                                          │
     │ Ballet                    -> Ballet 16pt                                          │
     │ Bodoni Moda               -> Bodoni Moda 11pt                                     │
     │ Bricolage Grotesque       -> Bricolage Grotesque 96pt                             │
     │ DM Sans                   -> DM Sans 9pt                                          │
     │ Imbue                     -> Imbue Thin 10pt                                      │
     │ Merriweather              -> Merriweather Light 18pt                              │
     │ Montagu Slab              -> Montagu Slab 144pt                                   │
     │ Newsreader                -> Newsreader 16pt 16pt                                 │
     │ Nunito Sans               -> Nunito Sans 12pt ExtraLight 12pt                     │
     │ Pathway Extreme           -> Pathway Extreme 8pt Thin 12pt                        │
     │ Playfair                  -> Playfair 5pt                                         │
     │ Roboto Serif              -> Roboto Serif 20pt                                    │
     │ Texturina                 -> Texturina Medium 12pt                                │
     │ Bodoni Moda SC            -> Bodoni Moda SC 11pt                                  │
     │ Hedvig Letters Serif      -> Hedvig Letters Serif 24pt 24pt                       │
     │                                                                                   │
     │ 2. Font names with unknown suffixes:                                              │
     │ ----------------------------------------                                          │
     │ Geologica                 -> Geologica Thin Roman                                 │
     │ Recursive                 -> Recursive Sans Linear                                │
     │ Sono                      -> Sono ExtraLight Monospace                            │
     │ Wavefont                  -> Wavefont Thin Rounded                                │
     │ Agu Display               -> Agu Display Uzo                                      │
     │                                                                                   │
     │ 3. Font names with spacing issues only:                                           │
     │ ----------------------------------------                                          │
     │ Headland One              -> HeadlandOne                                          │
     │ Nanum Gothic              -> NanumGothic                                          │
     │ Nanum Gothic Coding       -> NanumGothicCoding                                    │
     │ Nanum Myeongjo           -> NanumMyeongjo                                         │
     │ Noto Sans Phags Pa        -> Noto Sans PhagsPa                                    │
     │ Nova Mono                 -> NovaMono                                             │
     │ Sirin Stencil             -> SirinStencil                                         │
     │ Poetsen One               -> PoetsenOne                                           │
     │                                                                                   │
     │ 4. Other font name discrepancies:                                                 │
     │ ----------------------------------------                                          │
     │ M PLUS Rounded 1c         -> Rounded Mplus 1c                                     │
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

brandbug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions