ManimCommunity / ManimPango

Binding for Pango, to use with Manim.
https://manimpango.manim.community
MIT License
41 stars 13 forks source link

Implement rendering attributes #98

Closed naveen521kk closed 1 year ago

naveen521kk commented 1 year ago

Here's a small example to use this feature:

import manimpango

# match the characters from index 0 to 5.
attribute = manimpango.TextAttribute(0, 5)
attribute.family = "Cursive" # set to a cursive font
attribute.background_color = "#123456" # change background_color

new_attribute = manimpango.TextAttribute(5, 10) # characters 5 to 10
new_attribute.family = "Algerian" # font

layout = manimpango.Layout(
    "hello world",
    attributes=[attribute, new_attribute],
    font_desc=manimpango.FontDescription(
        family="Serif",
        size=30,
    ),
)
renderer = manimpango.PNGRenderer("test.png", 1000, 100, layout)
renderer.render()

This should render the following image (test.png): test

Lots of other attributes which Pango provides aren't implemented yet, needs some work there.

naveen521kk commented 1 year ago

I'll merge this once I get time to write some tests

PhilippImhof commented 1 year ago

This looks very nice. Looking forward to you finishing that. 👍