drawHTMLinRect
Posted: 31 May 2006 16:46
I couldn't find an "HTML renderer" anywhere. CustomIE provided by Gildas is excellent, but I wanted to have several text boxes in a form, and to print them in their correct position, which has entirely different requirements.
So, here is a class that renders basic HTML, and draws it in a rectangle. Printing is also coded.
The class could be extended to create controls such as buttons and checkboxes to allow pretty text (selected words bold, underlined, green etc.), all defined using standard HTML.
There is a slight bug with the wrapping, but it seems OK 99% of the time. I'll update it when I find out what the problem is.
The html tags understood are (but with angled brackets):
{b}bold...
{u}...
{i}...
{li} (list)
{br}
{hr} (horizontal line)
{color="#AA66FF"}
The example has a single form. The drawHTMLinRect is used in a control called "test_control" (this is not printed), but you can also add text boxes just by clicking in "white space" in the form. These boxes can be printed, and you can edit the text in them by double clicking. You can also drag them to new positions.
<b>The main call is:
drawHTMLinRect::hdraw(WW,HTML,RCT,Font)
</b>
WW is a domain which passes either the drawwindow + GDI, or a printdocument + GDI. There is a missing predicate in pfc printdocument - you need to add getfont. This simply involves adding two lines - just find setfont in printdocument and repeat them for getfont().
Steve Lympany
So, here is a class that renders basic HTML, and draws it in a rectangle. Printing is also coded.
The class could be extended to create controls such as buttons and checkboxes to allow pretty text (selected words bold, underlined, green etc.), all defined using standard HTML.
There is a slight bug with the wrapping, but it seems OK 99% of the time. I'll update it when I find out what the problem is.
The html tags understood are (but with angled brackets):
{b}bold...
{u}...
{i}...
{li} (list)
{br}
{hr} (horizontal line)
{color="#AA66FF"}
The example has a single form. The drawHTMLinRect is used in a control called "test_control" (this is not printed), but you can also add text boxes just by clicking in "white space" in the form. These boxes can be printed, and you can edit the text in them by double clicking. You can also drag them to new positions.
<b>The main call is:
drawHTMLinRect::hdraw(WW,HTML,RCT,Font)
</b>
WW is a domain which passes either the drawwindow + GDI, or a printdocument + GDI. There is a missing predicate in pfc printdocument - you need to add getfont. This simply involves adding two lines - just find setfont in printdocument and repeat them for getfont().
Steve Lympany