Re: RichText formation/attributes
Posted by Ian Bartholomew-19 on Feb 10, 2005; 10:29am
URL: https://forum.world.st/RichText-formation-attributes-tp3372990p3372993.html
Shaping wrote:
> Can someone explain how to create a colored RTF string, without building it
> at the lowest possible level (appending braces,'ansi' designators, RGB
> values, etc)? I'm looking for a practical protocol for converting a String
> to a Text (now RichText) and coloring and emboldening it. Something like
>
> 'abc' asRichText color: Color red; emboldened
>
> would be nice. I feel like I've missed something.
Have a look at the RichTextEdit class. It's not particularly user
friendly though.
r := RichTextEdit new parentView: View desktop; create; yourself.
"set defaults _if needed_"
r font: (Font name: 'Arial' pointSize: 12).
r forecolor: Color green.
r beNonBold.
r beNonItalic.
r plainText: 'Hello to the world'.
"select and change"
r selectionRange: (7 to: 12).
r selectionColor: Color red.
r selectionRange: (14 to: 18).
r beItalic.
r selectionRange: (1 to: 5).
r beBold.
"append"
r selectionRange: (-1 to: -1).
r beNonItalic.
r selectionFont: (Font name: 'Arial' pointSize: 16).
r selectionPlainText: '
and to the rest of the Universe'.
"to see the RichText evaluate"
r rtfText
"to display it evaluate"
r show
"then hide it with"
r close
--
Ian
Use the Reply-To address to contact me.
Mail sent to the From address is ignored.