Skip to content

Spot colors - #7629

Merged
laurmaedje merged 2 commits into
mainfrom
spot-color
Jun 8, 2026
Merged

laurmaedje merged 2 commits into
mainfrom
spot-color

Conversation

@reknih

@reknih reknih commented Dec 27, 2025 •

Copy link
Copy Markdown
Member

This PR adds spot colors to precisely request a given pigment in a professional print environment.

I have added the new type spot-colorant. Once constructed with a colorant name and a fallback color, the type has a single .tint(Ratio) method to construct a new spot color. spot-colorant accepts the special values "all" (all available colorants) and none (no colorants) that are specified in PDF.

For this feature, I had to break out process colors from the Color enum. I have tried my best to dispatch to small, Copyable process types early while keeping the existing API in place.

There is a behavioral change for gradients: They will now eagerly convert to the mixing space instead of doing so during export. This means that errors in conversion (which conversions to spot spaces can yield) will result in an error with a proper span when constructing the gradient instead of an unspanned error or panic during export. This means that gradient.stops will now return the spots in the mixing color space instead of their original space. The change is also a speedup since the conversion does not have to be performed for each sample.

Gradients gained the possibility to choose auto (new default) as a mixing space. auto will result in a spot color if all stops are spot colors using the same colorant and the old default of Oklab otherwise.

For the moment, all exporters will just export the fallback. I have written the necessary code for Krilla to support Separation color spaces. Once that is merged, I will integrate it here and set this to Ready to Review.

Open questions:

  • Should the colorant name and fallback color be exposed on spot-colorant
  • Should the computed fallback color be exposed on spot colors?
  • The overall size of SpotColorant makes Value larger than the 32 bytes allowed by the tests. How should this be addressed?

@reknih
reknih marked this pull request as draft December 27, 2025 12:07
@baron-de-ropp

Copy link
Copy Markdown

This is literally the last thing I need to stop using latex, and I just discovered typst yesterday. Thank you for doing the Lord's work.

@baron-de-ropp

Copy link
Copy Markdown

Hey! The CI is failing because SpotColor increases the Value enum size beyond 32 bytes.

Fix: Wrap SpotColor in Arc in the Color enum:

Spot(Arc)  // instead of Spot(SpotColor)
Then wrap all SpotColor::new(...) calls in Arc::new(...). This matches the pattern used by Gradient which also wraps its variants in Arc.

I'm shit at rust tho so double check and make sure i'm not a jagoff.

@PgBiel PgBiel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Very cool stuff! I took a look around, and wanted to leave some comments.

@laurmaedje laurmaedje added visualize Related to the visualize category, which is about drawing and illustrating interface PRs that add to or change Typst's user-facing interface as opposed to internals or docs changes. waiting-on-review This PR is waiting to be reviewed. labels Jan 5, 2026
@reknih reknih added waiting-on-author Pull request waits on author waiting-on-review This PR is waiting to be reviewed. and removed waiting-on-review This PR is waiting to be reviewed. waiting-on-author Pull request waits on author labels Jan 7, 2026
@reknih
reknih marked this pull request as ready for review January 9, 2026 09:56
@laurmaedje laurmaedje mentioned this pull request Mar 10, 2026
@urshofer

Copy link
Copy Markdown

@reknih Are there still plans to merge this PR into main ? It would be such a nice feature, we use it in a project, and it works well!

@laurmaedje

Copy link
Copy Markdown
Member

The PR will at some point be merged, yes.

@reknih
reknih force-pushed the spot-color branch 6 times, most recently from 3f890e7 to 92068ba Compare June 7, 2026 15:58
Comment thread crates/typst-pdf/src/convert.rs Resolved
Comment thread crates/typst-pdf/src/paint.rs Resolved
Comment thread crates/typst-pdf/src/paint.rs Resolved
Comment thread crates/typst-svg/src/paint.rs Resolved
Comment thread tests/suite/visualize/color.typ Resolved
@laurmaedje laurmaedje removed the waiting-on-review This PR is waiting to be reviewed. label Jun 8, 2026
Comment thread tests/suite/visualize/gradient.typ Resolved
@reknih
reknih force-pushed the spot-color branch 3 times, most recently from 2fbac9a to 1d55b4b Compare June 8, 2026 14:18
@laurmaedje
laurmaedje merged commit 3e32cb9 into main Jun 8, 2026
18 checks passed
@baron-de-ropp

Copy link
Copy Markdown

YES ITS IN MAIN!!!!! 🐔🐓🎉🎉🎉

Comment thread docs/assets/docs.css
Comment on lines +735 to +740
h3 .pill {
font-size: 20px;
border-radius: 8px;
padding: 4px 8px;
}

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.

This font-size makes the parameter name pills look plain goofy. Here's a screenshot of the str constructor:

Image

(same on firefox/chrome)

I assume there was another part of the docs that this change improved? Can we just scope it to that location?

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.

I looked more and I now see that this is being used for the spot colorant type (a nested type using a pill as the header in an h3), and it looks like not a single other pill on the color page is inside an h3, so that would explain why this wasn't noticed.

I'm opening a PR to change the targeting to exclude the normal pills in additional-info divs.

ParaN3xus added a commit to ParaN3xus/typst.ts that referenced this pull request Jun 9, 2026
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 10, 2026
@saecki
saecki deleted the spot-color branch June 10, 2026 18:10
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

interface PRs that add to or change Typst's user-facing interface as opposed to internals or docs changes. visualize Related to the visualize category, which is about drawing and illustrating

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants