Implement Makie 0.25's layout_text protocol - #34
Open
dawbarton-ai wants to merge 1 commit into
Open
Conversation
Adds `TeXLayoutHandler`, an implementation of the public `Makie.layout_text(handler, source, attributes) -> Makie.TextLayout` protocol from MakieOrg/Makie.jl#5717, so Makie 0.25 users select TeXLayout explicitly instead of relying on the type piracy the legacy adapter needs. The handler emits glyph IDs, exact FreeType faces, origins, extents, scales, block bounds, and `LineSegments` specs for horizontal and vertical rules; Makie keeps ownership of alignment, rotation, offset, validation, placement, and batching. Makie 0.24 keeps working through `MathTeXEngineExt`. Once the handler interface is present, its `generate_tex_elements(::LaTeXString)` specialisation delegates to MathTeXEngine's own implementation, so merely loading TeXLayout no longer changes Makie's default renderer. Verified against PR head 727b340b: 11/11 handler assertions plus a CairoMakie render pass covering fractions, radicals, mixed text/math, plain-string fall-through, and matrix rules. Glyph and block metrics follow Makie's contract rather than TeXLayout's ink bounds. Makie turns every `GlyphExtent` into `(0, descender)`-`(hadvance, ascender)` and expects the font's line metrics there so a block's height does not depend on which characters it holds; `MathTeXEngine.TeXChar` pads the same way, which is why the legacy path never showed this. Reporting bare ink bounds made `L"$x$"` measure 9.06 px against Makie's 20.0 px at fontsize 20, scattered baselines under `align = (:*, :center)`, and made `Axis` tick-label space depend on whether a label happened to have a descender. Extents are now padded to `max(ink_top, font_ascender)` / `min(ink_bottom, font_descender)`, and the block bbox is the union of the placed padded glyph boxes and rule bounds, which is exactly what `raw_string_boundingboxes` unions downstream. Source routing and glyph resolution move into `src/render_support.jl` so the two adapters share one implementation and one per-`FontFamily` runtime cache instead of carrying ~120 duplicated lines each. `FontFamilyKey` names the cache-key type so `_font_family_key`'s arity is stated once. Makie joins `[extras]`/`[targets]`: the handler tests were silently skipped because nothing in CI loaded `MakieExt` at all. Adding it immediately caught a shadowed-binding bug in the legacy delegation path. Also fixes inline-math delimiter stripping to use valid UTF-8 indices, so `$α$` no longer raises a `StringIndexError`, and corrects a docs example that passed `text_handler` to `Label`, which rejects it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BYXUGdHB9mLnZemWvtkZo1
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #34 +/- ##
==========================================
- Coverage 89.39% 86.09% -3.31%
==========================================
Files 21 23 +2
Lines 2915 3034 +119
==========================================
+ Hits 2606 2612 +6
- Misses 309 422 +113 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Implements the public
Makie.layout_text(handler, source, attributes) -> Makie.TextLayoutprotocol from MakieOrg/Makie.jl#5717, so Makie 0.25 users select TeXLayout explicitly instead of relying on the type piracy the legacy adapter needs.TeXLayoutHandleremits glyph IDs, exact FreeType faces, origins, extents, scales, block bounds, andLineSegmentsspecs for horizontal and vertical rules. Makie keeps ownership of alignment, rotation, offset, validation, placement, and batching, so moving or rotating a label no longer re-runs layout. The handler claims onlyLaTeXString; plain strings andrichtext fall through to Makie. A font family andLayoutOptionscan be pinned per handler or left to resolve the session defaults.Makie 0.24 keeps working through
MathTeXEngineExt. Once the handler interface is present, itsgenerate_tex_elements(::LaTeXString)specialisation delegates to MathTeXEngine's own implementation, so merely loading TeXLayout no longer changes Makie's default renderer.Glyph and block metrics
Metrics follow Makie's contract rather than TeXLayout's ink bounds. Makie turns every
GlyphExtentinto(0, descender)–(hadvance, ascender)and expects the font's line metrics there, so a block's height does not depend on which characters it holds.MathTeXEngine.TeXCharpads the same way, which is why the legacy path never showed this.Reporting bare ink bounds made
L"$x$"measure 9.06 px against Makie's 20.0 px at fontsize 20, scattered baselines underalign = (:*, :center), and madeAxistick-label space depend on whether a label happened to have a descender. Extents are now padded tomax(ink_top, font_ascender)/min(ink_bottom, font_descender), and the block bbox is the union of the placed padded glyph boxes and rule bounds — exactly whatraw_string_boundingboxesunions downstream, so align and measurement cannot disagree.Structure
Source routing and glyph resolution moved into
src/render_support.jl, so both adapters share one implementation and one per-FontFamilyruntime cache instead of carrying ~120 duplicated lines each.FontFamilyKeynames the cache-key type so_font_family_key's arity is stated once.Makiejoins[extras]/[targets]: the handler tests were silently skipped because nothing in CI loadedMakieExtat all. Until Makie 0.25 is released only the 0.24 branch runs there, so handler changes still need a manual run against a PR checkout.Also fixes inline-math delimiter stripping to use valid UTF-8 indices, so
$α$no longer raises aStringIndexError, and corrects a docs example that passedtext_handlertoLabel, which rejects it.Verification
Pkg.test(): 1571/1571 with Makie 0.24727b340b: 11/11 handler assertions, 9/9 routingStress-suite
makie_cairoreferences still need regenerating, since changing alignment is the point of the metric fix.🤖 Generated with Claude Code
https://claude.ai/code/session_01BYXUGdHB9mLnZemWvtkZo1