Text gradient in a zero-height block is invisible in PDF

Open
#9,049 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
backend

Research direction

Read crates/typst-pdf/src/paint.rs, especially convert_paint around lines 97–102 and convert_gradient around line 209; trace how the adjusted paint size and state.container_size() determine the gradient matrix. Reproduce the zero-height block and compare its PDF output with a block that has height. Done when the zero-height text gradient renders in PDF from red to blue without a singular matrix.

Written by the indexing model from the issue text.

Description

bug pdf visualize
Description

This exports a shading pattern with a singular matrix:

#block(height: 0pt, text(fill: gradient.linear(red, blue))[Gradient text])

The PDF contains /Matrix [59.488 0 0 0 70.86614 771.0236].

  • Ghostscript 10.08.0: the page is blank.
  • poppler 26.11.0 (pdftocairo): prints Syntax Warning: matrix not invertible and the page is blank.
  • PNG export: the text is solid red.

A one-line heading under #set text(top-edge: "baseline") also has zero height and gives a singular matrix.

convert_paint in crates/typst-pdf/src/paint.rs replaces a zero size with 1 pt (L97–102), but convert_gradient then uses state.container_size() for RelativeTo::Parent (L209), which still has the zero height. The code is the same on main.

Expected: the gradient shows from red to blue, as in a block with a height.

Reproduction URL

none

Operating system

macOS

Typst version
  • I am using the latest version of Typst (0.15.1)
Dominant language
Rust
Stars
57k
Forks
1.8k
Avg merge
1d 17h
Merged PRs (30d)
22

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from typst/typst

All issues in typst/typst

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.