Drawing Rich Text String to Picture

How can I draw an imported Rich Text String to a canvas picture so that all of the formattings gets drawn to the canvas? Think of a Microsoft Word document that would have some words bold, some italic, so red font, some underlined font and so on.
There is a specific reason I have to use draw an image to a Cavans with the formatted text, so I any help with this will be appreciated.

Last time I tried, you could use an offscreen styled textarea to render RTF by setting myTextArea.StyledText.RTFData=theRTF Then “print” it to a graphics object using myTextArea.StyledTextPrinter(g,width).DrawBlock(x,y,height)

https://documentation.xojo.com/api/printing/styledtextprinter.html#styledtextprinter-drawblock

StyledText.RTFData doesn’t support everything, but it does a pretty good job.

I have found the best way is to iterate thru the styleruns, and using the inforation in each on, set the graphics object properties (font, color, bold etc), and use DrawString…

That works too, and gives you more control of the final output.

Are there any examples of what the iteration would look like?

http://documentation.xojo.com/api/deprecated/textarea.html
http://documentation.xojo.com/api/text/stylerun.html

Example in the StyleRun page…