Skip to content

Support variable fonts - #8425

Merged
laurmaedje merged 8 commits into
mainfrom
variable-fonts
Jun 5, 2026
Merged

laurmaedje merged 8 commits into
mainfrom
variable-fonts

Conversation

@laurmaedje

@laurmaedje laurmaedje commented Jun 4, 2026 •

Copy link
Copy Markdown
Member

This PR adds support for variable fonts to Typst. It is based on prior work in #8240 and #6771, but in the end I made some deeper structural changes, so I've opened a new PR.

User-facing changes

  • Typst now correctly recognizes variable fonts and considers their variant coverage for the purposes of font selection.

  • For a selected font, it automatically configures the ital, slnt, wght, wdth, and opsz axes based on text.style, text.weight, text.stretch, and text.size.

  • Font variations can be explicitly configured via text.variations. When one of the well-known axes is specified, it takes precedence over the automatically selected value.

  • Usage of variable fonts in SVG is likewise supported, including optical sizing.

  • Variable font and axis information is now visible in font summaries for IDE tooling, e.g. in autocomplete and tooltips. For example, the summary for Fraunces could read "Variable. Weight 100–900. Has italics. Supports optical sizing. SOFT 0–100. WONK 0–1."

  • typst fonts likewise lists variable font information. Its output is generally revamped for improved readability.

    Example output of typst fonts
    Cantarell
    └ /fonts/Cantarell-VF.otf (Variable)
        Style: Normal
        Stretch: 100%
        Weight: 100-800 (Default: 400)
    
    Crimson Pro
    ├ /fonts/CrimsonPro[wght].ttf (Variable)
    │   Style: Normal
    │   Stretch: 100%
    │   Weight: 200-900 (Default: 400)
    └ /fonts/CrimsonPro-Italic[wght].ttf (Variable)
        Style: Italic
        Stretch: 100%
        Weight: 200-900 (Default: 400)
    
    DejaVu Sans Mono
    ├ (Embedded)
    │   Style: Normal, Weight: 700, Stretch: 100%
    ├ (Embedded)
    │   Style: Italic, Weight: 700, Stretch: 100%
    ├ (Embedded)
    │   Style: Italic, Weight: 400, Stretch: 100%
    └ (Embedded)
        Style: Normal, Weight: 400, Stretch: 100%
    
    Fraunces
    ├ /fonts/Fraunces[SOFT,WONK,opsz,wght].ttf (Variable)
    │   Style: Normal
    │   Stretch: 100%
    │   Weight: 100-900 (Default: 900)
    │   Optical Size: 9pt-144pt (Default: 9pt)
    │   SOFT: 0-100 (Default: 0)
    │   WONK: 0-1 (Default: 1)
    └ /fonts/Fraunces-Italic[SOFT,WONK,opsz,wght].ttf (Variable)
        Style: Italic
        Stretch: 100%
        Weight: 100-900 (Default: 900)
        Optical Size: 9pt-144pt (Default: 9pt)
        SOFT: 0-100 (Default: 0)
        WONK: 0-1 (Default: 1)
    
    Google Sans Flex
    └ /fonts/GoogleSansFlex-VariableFont_GRAD,ROND,opsz,slnt,wdth,wght.ttf (Variable)
        Slant: -10-0 (Default: 0)
        Weight: 100-900 (Default: 400)
        Stretch: 50%-151% (Default: 100%)
        Optical Size: 6pt-144pt (Default: 18pt)
        GRAD: 0-100 (Default: 0)
        ROND: 0-100 (Default: 0)
    
    Libertinus Serif
    ├ (Embedded)
    │   Style: Normal, Weight: 400, Stretch: 100%
    ├ (Embedded)
    │   Style: Normal, Weight: 700, Stretch: 100%
    ├ (Embedded)
    │   Style: Italic, Weight: 400, Stretch: 100%
    ├ (Embedded)
    │   Style: Italic, Weight: 700, Stretch: 100%
    ├ (Embedded)
    │   Style: Normal, Weight: 600, Stretch: 100%
    └ (Embedded)
        Style: Italic, Weight: 600, Stretch: 100%
    
    Mona Sans VF
    └ /fonts/MonaSansVF[wdth,wght,opsz,ital].ttf (Variable)
        Italic: 0-1 (Default: 0)
        Weight: 200-900 (Default: 200)
        Stretch: 75%-125% (Default: 100%)
        Optical Size: 0pt-100pt (Default: 0pt)
    
    New Computer Modern
    ├ (Embedded)
    │   Style: Normal, Weight: 400, Stretch: 100%
    ├ (Embedded)
    │   Style: Normal, Weight: 700, Stretch: 100%
    ├ (Embedded)
    │   Style: Italic, Weight: 400, Stretch: 100%
    └ (Embedded)
        Style: Italic, Weight: 700, Stretch: 100%
    
    New Computer Modern Math
    ├ (Embedded)
    │   Style: Normal, Weight: 700, Stretch: 100%
    ├ (Embedded)
    │   Style: Normal, Weight: 450, Stretch: 100%
    └ (Embedded)
        Style: Normal, Weight: 400, Stretch: 100%
    
    Noto Serif CJK HK
    └ /fonts/NotoSerifCJKhk-VF.ttf (Variable)
        Style: Normal
        Stretch: 100%
        Weight: 200-900 (Default: 200)
    
    Noto Serif CJK JP
    └ /fonts/NotoSerifCJKjp-VF.ttf (Variable)
        Style: Normal
        Stretch: 100%
        Weight: 200-900 (Default: 200)
    
    Noto Serif CJK KR
    └ /fonts/NotoSerifCJKkr-VF.ttf (Variable)
        Style: Normal
        Stretch: 100%
        Weight: 200-900 (Default: 200)
    
    Noto Serif CJK SC
    └ /fonts/NotoSerifCJKsc-VF.ttf (Variable)
        Style: Normal
        Stretch: 100%
        Weight: 200-900 (Default: 200)
    
    Noto Serif CJK TC
    └ /fonts/NotoSerifCJKtc-VF.ttf (Variable)
        Style: Normal
        Stretch: 100%
        Weight: 200-900 (Default: 200)
    
    Recursive Sans Linear
    └ /fonts/Recursive_VF_1.085.ttf (Variable)
        Stretch: 100%
        Slant: -15-0 (Default: 0)
        Weight: 300-900 (Default: 300)
        MONO: 0-1 (Default: 0)
        CASL: 0-1 (Default: 0)
        CRSV: 0-1 (Default: 0.5)
    
    Roboto Flex
    └ /fonts/RobotoFlex-VariableFont_GRAD,XOPQ,XTRA,YOPQ,YTAS,YTDE,YTFI,YTLC,YTUC,opsz,slnt,wdth,wght.ttf (Variable)
        Slant: -10-0 (Default: 0)
        Weight: 100-900 (Default: 400)
        Stretch: 50%-151% (Default: 100%)
        Optical Size: 8pt-144pt (Default: 14pt)
        GRAD: -200-150 (Default: 0)
        XOPQ: 27-175 (Default: 96)
        YOPQ: 25-135 (Default: 79)
        XTRA: 323-603 (Default: 468)
        YTUC: 528-760 (Default: 712)
        YTLC: 416-570 (Default: 514)
        YTAS: 649-854 (Default: 750)
        YTDE: -305--98 (Default: -203)
        YTFI: 560-788 (Default: 738)
    

Implementation considerations

  • The Font type was split into Font and FontInstance. The former represents a (potentially variable) font without variation coordinates while the latter represents a font with known variation values. Only the latter provides access to any kind of metrics that depend on variations, ensuring that a font is always instantiated before we try to read metrics.

  • Font selection takes into account variation axes, but is still only based on style, weight, and stretch, not on point size or custom variations. Technically, it could be expanded, but I don't think this is practically very relevant for variable fonts (e.g. having two different font files with different optical size coverage). For static fonts, optical-size based selection would be nice, but out of scope for this PR. In Add variable font support #8240, the same amount of information was taken into account, but book.select's signature was changed because selection and instantiation happened in one step. Due to the Font/FontInstance split, book.select's signature remains unchanged in this PR.

  • The FontInfo struct now contains metadata about all variation axes in a font. This design is a bit more generic than the one in Add variable font support #8240 and Add initial support for variable fonts #6771 and allows us to (a) potentially expand font selection to include more axis information and (b) is useful metadata for things like IDE tooling.

  • I've fixed a few bugs / missing features with variable fonts in dependencies:

    The krilla change has not yet landed, so this PR is blocked on that.

  • The SVG hashes have all changed because FontInstance hashes differently than the old Font. In Add variable font support #8240, this was resolved by avoiding hashing empty variations, but I think this could technically lead to hash collisions on types like &[FontInstance], so I've avoided this and just accepted the ref changes.

@laurmaedje laurmaedje added the text Related to the text category, which is all about text handling, shaping, etc. label Jun 4, 2026

@isuffix isuffix left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought I would peruse this just a bit and check with my clippy lint branch. I don't really know enough to judge the structure, but I did find some small syntax fixes.

Comment thread crates/typst-cli/src/fonts.rs Resolved
Comment thread crates/typst-ide/src/utils.rs Resolved
Comment thread crates/typst-ide/src/utils.rs Resolved
Comment on lines +230 to +233
/// _Note:_ If you want to strongly emphasize your text, you should do so
/// using the @strong[strong] function instead. This makes it easy to adapt
/// the style later if you change your mind about how to signify the strong
/// emphasis.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should open an issue for Note/Info/Warning callouts?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure yet how visually notable I want those notes to be, but a component wouldn't hurt either way.

@laurmaedje
laurmaedje force-pushed the font-handling-refactors branch from 9ca38f9 to 38d9f43 Compare June 5, 2026 08:32
Base automatically changed from font-handling-refactors to main June 5, 2026 08:38
@laurmaedje
laurmaedje merged commit ace3225 into main Jun 5, 2026
18 checks passed
@laurmaedje
laurmaedje deleted the variable-fonts branch June 5, 2026 09:07
ParaN3xus added a commit to ParaN3xus/typst.ts that referenced this pull request Jun 9, 2026
ParaN3xus added a commit to ParaN3xus/tinymist that referenced this pull request Jun 9, 2026
ParaN3xus added a commit to ParaN3xus/tinymist that referenced this pull request Jun 9, 2026
ParaN3xus added a commit to ParaN3xus/tinymist that referenced this pull request Jun 9, 2026
ParaN3xus added a commit to ParaN3xus/tinymist that referenced this pull request Jun 9, 2026
ParaN3xus added a commit to ParaN3xus/tinymist that referenced this pull request Jun 9, 2026
ParaN3xus added a commit to ParaN3xus/tinymist that referenced this pull request Jun 9, 2026
ParaN3xus added a commit to ParaN3xus/tinymist that referenced this pull request Jun 10, 2026
ParaN3xus added a commit to ParaN3xus/tinymist that referenced this pull request Jun 10, 2026
ParaN3xus added a commit to ParaN3xus/tinymist that referenced this pull request Jun 10, 2026
ParaN3xus added a commit to ParaN3xus/typst.ts that referenced this pull request Jun 10, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Myriad-Dreamin added a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 15, 2026
Part of the Typst 0.15 cleanup stack. This slice covers text accessor,
font metadata, color presentation, and viewer color-space API changes.

## Upstream Typst Changes

- [`typst/typst#8393`](typst/typst#8393) changes
syntax/source text access. Tinymist updates semantic tokens, analysis
matchers, lint/debug instrumentation, query helpers, and AST utilities
to use the new accessor style.
- [`typst/typst#8425`](typst/typst#8425) adds
font axis metadata. Tinymist initializes font axes and forwards them
through document metrics and symbol glyph handling.
- [`typst/typst#7629`](typst/typst#7629) changes
color presentation behavior. Tinymist updates color presentation
conversion and renderer color-space handling for the Typst 0.15 color
APIs.

## Tinymist Changes

- Updates text access in `tinymist-query`, `tinymist-analysis`,
`tinymist-debug`, `tinymist-lint`, and AST-facing helpers.
- Updates `tinymist-world` font metadata construction for the new axes
field.
- Updates document metrics and symbol glyph collection to preserve font
axis information.
- Updates `tinymist-query` color presentations for the revised Typst
color API.
- Updates viewer rendering color-space conversion so Typst 0.15 colors
are mapped correctly before rendering.

---------

Co-authored-by: paran3xus <[email protected]>
Myriad-Dreamin pushed a commit to Myriad-Dreamin/typst.ts that referenced this pull request Jun 15, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/typst.ts that referenced this pull request Jun 15, 2026
Myriad-Dreamin added a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 15, 2026
Part of the Typst 0.15 cleanup stack. This slice covers text accessor,
font metadata, color presentation, and viewer color-space API changes.

## Upstream Typst Changes

- [`typst/typst#8393`](typst/typst#8393) changes
syntax/source text access. Tinymist updates semantic tokens, analysis
matchers, lint/debug instrumentation, query helpers, and AST utilities
to use the new accessor style.
- [`typst/typst#8425`](typst/typst#8425) adds
font axis metadata. Tinymist initializes font axes and forwards them
through document metrics and symbol glyph handling.
- [`typst/typst#7629`](typst/typst#7629) changes
color presentation behavior. Tinymist updates color presentation
conversion and renderer color-space handling for the Typst 0.15 color
APIs.

## Tinymist Changes

- Updates text access in `tinymist-query`, `tinymist-analysis`,
`tinymist-debug`, `tinymist-lint`, and AST-facing helpers.
- Updates `tinymist-world` font metadata construction for the new axes
field.
- Updates document metrics and symbol glyph collection to preserve font
axis information.
- Updates `tinymist-query` color presentations for the revised Typst
color API.
- Updates viewer rendering color-space conversion so Typst 0.15 colors
are mapped correctly before rendering.

---------

Co-authored-by: paran3xus <[email protected]>
Myriad-Dreamin added a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 15, 2026
Part of the Typst 0.15 cleanup stack. This slice covers text accessor,
font metadata, color presentation, and viewer color-space API changes.

## Upstream Typst Changes

- [`typst/typst#8393`](typst/typst#8393) changes
syntax/source text access. Tinymist updates semantic tokens, analysis
matchers, lint/debug instrumentation, query helpers, and AST utilities
to use the new accessor style.
- [`typst/typst#8425`](typst/typst#8425) adds
font axis metadata. Tinymist initializes font axes and forwards them
through document metrics and symbol glyph handling.
- [`typst/typst#7629`](typst/typst#7629) changes
color presentation behavior. Tinymist updates color presentation
conversion and renderer color-space handling for the Typst 0.15 color
APIs.

## Tinymist Changes

- Updates text access in `tinymist-query`, `tinymist-analysis`,
`tinymist-debug`, `tinymist-lint`, and AST-facing helpers.
- Updates `tinymist-world` font metadata construction for the new axes
field.
- Updates document metrics and symbol glyph collection to preserve font
axis information.
- Updates `tinymist-query` color presentations for the revised Typst
color API.
- Updates viewer rendering color-space conversion so Typst 0.15 colors
are mapped correctly before rendering.

---------

Co-authored-by: paran3xus <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

text Related to the text category, which is all about text handling, shaping, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Variable font in SVG changes from thin weight to tofu (possible regression?) Support variable fonts

2 participants