typemytype / drawbot

http://www.drawbot.com
Other
398 stars 61 forks source link

textProperties #520

Closed typemytype closed 9 months ago

typemytype commented 1 year ago

textProperties returns a dict with all current properties of an formattedString.

While building the nsAttributedString those properties are stored in the nsAttributedString with the key: "drawBot.formattedString.properties". This allows to slice a formattedString and restore the attributes from the nsAttributedString.

The method is a public one as this can be used to check text properties after creating/building the formattedString.

fixing #518

typemytype commented 9 months ago

@justvanrossum this would be super handy to have!!

justvanrossum commented 9 months ago

Neat!

Could there be a need/use to set the properties from the dict as well? Or is this a read-only thing (from the API's perspective)?

typemytype commented 9 months ago

you can use this properties dict to initiate a new FormattedString("hi Just", **textProperties)

this super handy when you loop over all textBoxCharacterBounds to get properties and only change for the alpha value of the fill color... over an animation

justvanrossum commented 9 months ago

And in between adding text?

fs = Formattedtring(...)
fs.append("Hey ")
fs.???(**textProperties)
fs.append("Frederik")
typemytype commented 9 months ago

works also with append


fs = Formattedtring(...)
fs.append("Hey ", **textProperties)