Repository navigation
Conversation
andylizi
force-pushed
the
selectable-text-2
branch
from
November 1, 2026 18:40
5665b7d to
1a1971f
Compare
andylizi
marked this pull request as ready for review
November 1, 2026 18:40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a new parameter
set text(selectable: false)that partially addresses #2249.With the parameter set, the glyphs of a text run are drawn as outlined paths, making them unselectable in viewers. For accessibility, the text of the run is attached as
/ActualTextto aSpanstructure element that wraps the run's marked content in the tag tree.This only covers page-level text. Text in SVGs is rendered by krilla-svg, which draws glyphs individually and cannot nest its own marked content for the text runs within Typst's marked content for the image. So there is currently nothing to attach the replacement text to. Supporting this would require changes in krilla, probably an API for krilla-svg to report its text runs back to the caller (or accept a callback that lets the caller tag each run), and I'd like to leave that as follow-up work.
The user-facing design was proposed in #5938 (comment). The implementation approach was discussed in #7295 (comment) with one major difference: it is done fully in Typst.
In the original proposal:
Unfortunately, doing this automatically in krilla turns out to be impractical. The tag tree is built entirely by the caller, and krilla only serializes the finished tree. For krilla to attach the replacement text itself, it would have to modify that tree after the fact, and it would have to infer where to insert the text from the marked content that was active when the glyphs were drawn, which krilla does not even track today. And there are more complications, such as what to do when several outlined runs share one marked content sequence, or when the caller already wraps its runs in
Spanelements for language and script attributes. So while it is technically possible, I don't think it is worth the complexity. It also would not help with the SVG case described above. CC @LaurenzV in case I'm missing something here!We went down the more difficult path of placing
/ActualTexton structure elements due to broader viewer support, but there is mozilla/pdf.js#12237 for pdf.js to also support/ActualTextin marked content properties. If and when that support becomes widespread, we can revisit this and move the/ActualTextinto the content stream, where krilla can write it during text rendering. That will be a lot cleaner to implement. The pdf.js issue also mentions that PDFium has added support for the marked content properties form as well, but I have not tested that myself.Closes #2249 (we could open a follow-up issue for SVG images if needed).