Skip to content

Proposal for a more extensible text rendering pipeline #5378

@henrik-wolf

Description

@henrik-wolf

Following up on the discussion over on discourse regarding my proof of concept Typst backend for rendering strings in Makie, I have been digging through the text code, to see how we could provide an official way of extending the text rendering pipeline to more complex strings. Doing so would allow for a cleaner implementation of the currently supported

  • Latex strings (currently hard coded in the text rendering pipeline, adds a linesegments plot to the otherwise atomic text plot, which results in a few places where Text has to get special treatment)
  • "normal" strings
  • Rich text

more stable integrations in the future with

  • Typst strings
  • TikZ Images currently provided by MakieTeX

and potentially other interesting applications in which "rendering text" does not necessarily mean producing glyphs at certain locations, such as PlantUML or Mermaid diagrams.

As this would be a fairly large piece of work, I want to put out proposal to discuss the approach that I would take, before I start implementing it.

Fundamentally, this proposal follows the suggestion of @asinghvi17, that we add an AbstractStringLayouter type, that users can subtype and then use their subtypes as an attribute in all text! calls to dispatch on custom text rendering behaviour.

To do this, I believe that we need to do the following:

  • lift Text out of the atomic plots, and replace it with a new atomic called something like Glyphs
  • Glyphs now takes as arguments everything that Text produced up until this point, something like this: outputs of text rendering
  • The default theme gets a new attribute string_layouter=SimpleStringLayouter()
  • as well as Text getting something like string_layouter=@inherit string_layouter
  • Text now gets its own plot!(text::Text) method, in which we resolve the appropriate string layouter for each given string, and then dispatch to something like _layout_with_layouter(plot::Text, layouter<:AbstractStringLayouter, current_string), which the user can overwrite to plot! arbitrary things into the text-plot. Rendering LaTeX strings would then for example contain a call to glyphs!, as well as to linesegments!

Please let me know what you think!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementFeature requests and enhancements

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions