Skip to content

typst uses other font that specified despite using fallback: false  #2917

Closed as not planned

Description

@JeyRunner

Description

When specifying the font Roboto with the option fallback: false while having both fonts Roboto and Roboto Condensed installed on the system the wrong font Roboto Condensed is selected.

Code to reproduce:

#text(
  font: "Roboto",
  fallback: false
)[
  This is Roboto!
]

The embedded font in the pdf is SUIXSO+RobotoCondensed-Regular.

When Roboto Condensed is removed from the system typst uses the correct font Roboto (embedded font in the pdf is SUIXSO+Roboto-Regular).

When both are installed on the system the output of fc-list : | grep Roboto is:

/usr/share/fonts/truetype/roboto/unhinted/RobotoTTF/Roboto-Thin.ttf: Roboto,Roboto Thin:style=Thin,Regular
/usr/share/fonts/truetype/roboto/unhinted/RobotoTTF/Roboto-MediumItalic.ttf: Roboto,Roboto Medium:style=Medium Italic,Italic
/usr/share/fonts/truetype/roboto/unhinted/RobotoCondensed-Italic.ttf: Roboto Condensed:style=Italic
/usr/share/fonts/truetype/roboto/unhinted/RobotoCondensed-Bold.ttf: Roboto Condensed:style=Bold
/usr/share/fonts/truetype/roboto/unhinted/RobotoCondensed-Medium.ttf: Roboto Condensed,Roboto Condensed Medium:style=Medium,Regular
/usr/share/fonts/truetype/roboto/unhinted/RobotoTTF/Roboto-ThinItalic.ttf: Roboto,Roboto Thin:style=Thin Italic,Italic
/usr/share/fonts/truetype/roboto/unhinted/RobotoTTF/Roboto-LightItalic.ttf: Roboto,Roboto Light:style=Light Italic,Italic
/usr/share/fonts/truetype/roboto/unhinted/RobotoCondensed-BoldItalic.ttf: Roboto Condensed:style=Bold Italic
/usr/share/fonts/truetype/roboto/unhinted/RobotoCondensed-LightItalic.ttf: Roboto Condensed,Roboto Condensed Light:style=Light Italic,Italic
/usr/share/fonts/truetype/roboto/unhinted/RobotoTTF/Roboto-Italic.ttf: Roboto:style=Italic
/usr/share/fonts/truetype/roboto/unhinted/RobotoTTF/Roboto-BlackItalic.ttf: Roboto,Roboto Black:style=Black Italic,Italic
/usr/share/fonts/truetype/roboto/unhinted/RobotoCondensed-Light.ttf: Roboto Condensed,Roboto Condensed Light:style=Light,Regular
/usr/share/fonts/truetype/roboto/unhinted/RobotoCondensed-MediumItalic.ttf: Roboto Condensed,Roboto Condensed Medium:style=Medium Italic,Italic
/usr/share/fonts/truetype/roboto/unhinted/RobotoTTF/Roboto-Medium.ttf: Roboto,Roboto Medium:style=Medium,Regular
/usr/share/fonts/truetype/roboto/unhinted/RobotoTTF/Roboto-Bold.ttf: Roboto:style=Bold
/usr/share/fonts/truetype/roboto/unhinted/RobotoTTF/Roboto-Black.ttf: Roboto,Roboto Black:style=Black,Regular
/usr/share/fonts/truetype/roboto/unhinted/RobotoTTF/Roboto-Light.ttf: Roboto,Roboto Light:style=Light,Regular
/usr/share/fonts/truetype/roboto/unhinted/RobotoTTF/Roboto-Regular.ttf: Roboto:style=Regular
/usr/share/fonts/truetype/roboto/unhinted/RobotoTTF/Roboto-BoldItalic.ttf: Roboto:style=Bold Italic
/usr/share/fonts/truetype/roboto/unhinted/RobotoCondensed-Regular.ttf: Roboto Condensed:style=Regular

At the same time, typst does not seem to differentiate between the two fonts:

typst fonts | grep Roboto    # when both fonts are installed
> Roboto

Also forcing typst to first look at the specific folder of one of the fonts does not change the list of discovered fonts.
Both seem to be interpreted as Roboto:

# folder with RobotoCondensed
typst fonts --font-path /usr/share/fonts/truetype/roboto/unhinted/ | grep Roboto
> Roboto

# folder with Roboto
typst fonts --font-path /usr/share/fonts/truetype/roboto/unhinted/RobotoTTF | grep Roboto
> Roboto

Used system: linux (22.04.1-Ubuntu)

Reproduction URL

No response

Operating system

Linux

Typst version

  • I am using the latest version of Typst

Activity

  1. added
    bug
    on Dec 11, 2023
  2. Leedehai commented on Dec 12, 2023

    @Leedehai
    Contributor

    I did some digging and it turns out the font selection is based on font family and font variant. Both Roboto and Roboto Condensed's family name is recognized as "Roboto" by Typst. In fact, both fonts are registered in Typst's internal font book as

    FontInfo { family: "Roboto", variant: Normal-400-FontStretch(1000), flags: FontFlags(0x0), coverage: Coverage(..) }
    

    So Typst has no way to differentiate the two.

    Update: with fc-scan --format="%{family}\n" [path] [1] I can verify the family names are different. One is Roboto Condensed and the other is simply Roboto. I can confirm Typst did pick up the correct family names from the fonts, but typographic_family() strips away the suffix "condensed" afterwards before registering the fonts.

    Though it appears to be a WAI, in fact we probably need to change this behavior..

    Update 2:
    With fc-scan --format="%{family} %{width}\n" [path] I can verify the "width" of both fonts are 100, despite [1] says "width" represents "Condensed, normal or expanded".

    [1] For a full list of possible properties ("names" in their jargon), see http://www.freedesktop.org/software/fontconfig/fontconfig-user.html#AEN21

  3. laurmaedje commented on Dec 12, 2023

    @laurmaedje
    Member

    So Typst has no way to differentiate the two.

    Typst differentiates between the two via #set text(stretch: 75%) (condensed) and #set text(stretch: 100%) (normal). Apparently, the metadata of Roboto Condensed is wrong if it also has FontStretch(1000), which is 100%.

  4. laurmaedje commented on Dec 12, 2023

    @laurmaedje
    Member

    While I want to retain this capability, I do agree that the current font grouping results in problems in some cases, because fonts are just such as mess. Also see: #2098

  5. Enivex commented on Dec 12, 2023

    @Enivex
    Collaborator

    This is a duplicate of #576 I think?

  6. JeyRunner commented on Dec 12, 2023

    @JeyRunner
    Author

    Thank you both for looking into this :)

    Yes #2098 would solve the issue. Maybe it would be nice to have a separate field in text for the full family name, like font-full-name.

    Meanwhile, this could be fixed by just adding a separate case for the Roboto font in typographic_family (note that I am new to the code base and not a rust expert...):

    fn typographic_family(mut family: &str) -> &str {
        // ...
         // Trim style suffixes repeatedly.
        while trimmed.len() < len {
            len = trimmed.len();
    
            // Find style suffix.
            let mut t = trimmed;
            let mut shortened = false;
            while let Some(s) = SUFFIXES.iter().chain(extra).find_map(|s| {
                    // dont't remove condensed from font 'Roboto Condensed'
                    if t.contains("roboto") && s.contains("condensed") {
                        return None;
                    }
                    t.strip_suffix(s)
                }) {
                shortened = true;
                t = s;
            }
       // ...

    But obviously, this is very hacky...

  7. laurmaedje commented on Dec 12, 2023

    @laurmaedje
    Member

    Closing in favor of #576

  8. added
    duplicate
    on Dec 12, 2023
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

    bugduplicate

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions