Support colorization of text via TeX directives#31234
Support colorization of text via TeX directives#31234MaddieM4 wants to merge 2 commits intomatplotlib:text-overhaulfrom
Conversation
|
Thank you for opening your first PR into Matplotlib! If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. You can also join us on gitter for real-time discussion. For details on testing, writing docs, and our review process, please see the developer guide. We strive to be a welcoming and open project. Please follow our Code of Conduct. |
|
The current failing tests all seem to be the image comparison test I mentioned in the main body of the PR. There's also a stub test failure, which I take to be because I've added a new (temporary) alternative implementation of The final CI error I see is a bit opaque to me, in the middle of one of the Windows builds. It seems to not be related to the PR itself. |
|
Thanks for working on this. Note that in #30039 I introduced a new way of rendering TeX in Agg (by actually parsing the dvi file and rendering the glyphs one at a time, similarly to what is already done for all the vector backends) which I hope to make the default in the future (if only because that will be necessary to support xetex/luatex); this PR will need to be adapted to handle that approach. (I believe that this amounts to parsing and using the xcolor specials that get inserted in the dvi file.) The codecov CI error can be ignored. I would suggest adding the typestub for now even if needs to be changed later, to make reviewing easier. |
| { | ||
| int x, y; | ||
|
|
||
| if (auto value = std::get_if<double>(&vx)) { |
There was a problem hiding this comment.
Go straight for the newer API here, no need to introduce the old one.
|
@anntzer Ooh, rendering glyphs "in-house" with AGG like that makes it way easier to preserve existing APIs by treating external colors as defaults. I'll spend some time this week updating my PR accordingly. Should this PR be targeting merge into the |
|
You should target text-overhaul for now. Note that running the test suite on that branch is a bit tricky because the baseline images are out of sync and on another temporary branch for now (to make a long story short, that branch exists because we need to update a huge number of baseline images, but don't want to repeatedly do so at each commit because that would really bloat the repo size; so we will just make a single update of all baseline images when the branch is complete -- hopefully soon). So it's expected that CI will fail. Fortunately, your feature will all be self-contained into separate tests (for text colorization) so that hopefully shouldn't be too big of a problem for your PR. |
|
Alright. My branch is in a messy state for now, and will need some big changes to work with the new pipeline. But after some reverse-engineering, I can tell that |
|
I guess it depends on what you mean by "not smart enough to expose specials". Specials are just strings after an xxx1/2/3/4 opcode, and these are right now just logged by the Dvi class because it doesn't know how to interpret them; what's missing is indeed actually recording and interpreting these strings, and keeping track of the glyph on which color specials apply. |
|
That's exactly what I meant, but my phrasing could have been better. One of the catches here is that, without recognizing a specific type of special, you can't know if it covers a range of glyphs, or if it's something more like "insert an image here." So if we had an interface to iterate all the DVI ops, that could easily cover specials "generically" (since it doesn't need to understand them, just report them). Since we only have a higher-level API that applies ops as state mutations, I don't see a good generic way to expose specials that So the question is how to expose the supported "spanny" specials (covering a range of glyphs) as an API to the |
|
It's kinda rough, trying to catch breakage on the Hypothetically, if I were to make the DVI reader changes as a separate PR against |
It's probably reasonable to split the Dvi class implementation into a reader part that just yields a list of opcodes, and a second "virtual machine" part that applies them, if that helps.
The reason I made them properties of the font object (and intend to deprecate them as properties of the glyph objects) is that this directly maps to their definition in the dvi files, especially in the xetex (_define_native_font) and luatex (DviFont.from_luatex) cases, so it felt artificial to "lift" that info to the Text objects. OTOH, the extra "color" field suggested here naturally applies to Text objects. I think deprecating the use of Text as a namedtuple and turning it into a dataclass with an extra "color" field is reasonable. (Side point, though it absolutely doesn't have to be done here: probably we can write a decorator to help that transition, by providing deprecation warnings and temporary backcompat if someone tries to call (indirectly, e.g. via iteration)
The updated figures are actually available at #30161. @QuLogic can you remind us of your workflow? (Personally, I only run the relevant tests (as few as possible) and ignore the errors directly related to outdated images when working on that branch.) |
PR summary
This is my work in progress to fix #6724, allowing TeX-formatted tech fields to respect color directives. I'm making this PR as a draft, because I'd like some advice on a few things, before bringing it to a more finished state. Here's some example code, and the resulting images with my patch - note that the text in the examples is partially colorized, demonstrating that it works by inline TeX directives.
So, what are the remaining issues?
RendererAgg::draw_text_image, so that code would need to be rethought, and would likely run into the problems from Point 1 (expecting external colorization support).AI Disclosure
I don't use it, I don't need it.
PR checklist