Re: Painting mixed attribute text into a control?



Richard A. DeVenezia schrieb:

In html it's easy as text := '123 abc <span
style='background:green'>XYZ</span> for sooth';


How might I render an html'ish string into an offscreen buffer and blit it into the control context ?

IMO you'll have to do all the formatting yourself. HTML or RTF components usually are designed to paint onto their own control, not into an user provided (bitmap...) canvas.


You can try to use a hidden control to do the formatting, but since that control is hidden, it most probly will never produce an image of the text.

I just have solved the rendering of attributed text, in my viewer with syntax highlighting. A user supplied handler provides two methods, FirstWord and NextWord, which return both the stripped text snippets, as well as the decoded formatting information. Your TListBox.OnDrawItem handler can call equivalent procedures, set the text attributes in the canvas, and then call Canvas.TextOut to draw the text. A bitmap for the formatted text is not normally required, but you can use the same procedures in writing to a TBitmap.Canvas.

Most of your code will go into the procedures that decode the text attributes, so you should use an format that is easy to parse.

DoDi
.


Quantcast