Skip to content

Commit 6f9692a

Browse files
committed
Replace MathtextBackend mechanism.
The MathtextBackend ("MB") mechanism was previously used to let actual backends customize how they received mathtext results -- either as lists of glyphs and rectangles (for vector backends: MathtextBackendPath), or a bitmap (for raster backends: MathtextBackendAgg); in both cases, metrics are also provided. MBs also controlled font hinting. Note that the MB mechanism was not publically user-extendable (this would require touching the private MathTextParser._backend_mapping dict), so third parties could not meaningfully provide their own backends. MBs were attached to _mathtext.Fonts objects, which were central to the "shipping" stage of the parse (ship(), which converts the nested parse tree created by pyparsing into flat calls to render_glyph and render_rect_filled). This led to a slightly curious API, where the old MathtextBackendAgg.get_results() (for example) calls `_mathtext.ship(0, 0, box)` and this somehow magically mutates self -- this is because self is indirectly attached to sub-elements of box. This PR changes the implementation to instead detach output logic from Fonts (which become restricted to providing glyph metrics and related info), and makes ship() instead return a simple Output object (lists of glyphs and rects) which is itself able either to convert to a VectorResult or a RasterResult -- namedtuples that are backcompatible with the tuples previously returned by MathTextParser.parse(). (While technically these are "new" classes in the API, they are simply there to (slightly) better document the return value of MathtextBackend.parse().) In summary, this patch - removes the non-extensible MB system, - detaches output logic from Fonts objects, thus avoiding "action at distance" where `ship(0, 0, box)` would mutate the calling MB, - (weakly) documents the return value of MathtextBackend.parse().
1 parent 53c5f88 commit 6f9692a

File tree

3 files changed

+171
-68
lines changed

3 files changed

+171
-68
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``MathtextBackend``, ``MathtextBackendAgg``, ``MathtextBackendPath``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... are deprecated with no replacement.

0 commit comments

Comments
 (0)