Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: text is not colored correctly #13

Open
cgahr opened this issue Nov 6, 2024 · 1 comment
Open

Bug: text is not colored correctly #13

cgahr opened this issue Nov 6, 2024 · 1 comment

Comments

@cgahr
Copy link

cgahr commented Nov 6, 2024

Coloring text does not work. Consider the following code:

import matplotlib as mpl
import matplotlib.pyplot as plt
import mpl_typst.as_default  # noqa: F401

fig, ax = plt.subplots(1, 1)

colors = ["C0", "C1", "C2"]
linestyles = ["-", ":", "-."]

legend = ax.legend(
    [
        mpl.lines.Line2D([], [], ls=ls, color=color)
        for ls, color in zip(linestyles, colors, strict=True)
    ],
    ["text0", "text1", "text2"],
    loc="center",
    ncol=3,
    borderaxespad=0.5,
)

for text, color in zip(legend.get_texts(), colors, strict=True):
    text.set_color(color)
fig.savefig("test.typ")

The result should be:
image
In the created typst file, however, the text is black and not colored.

@cgahr
Copy link
Author

cgahr commented Nov 6, 2024

I think somewhere in the draw_text function, we must call gc.get_rgb() to get the color and adjust draw-text to take a fill argument so that we can do

text(..., fill: color, content)

in prologue.typ.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant