Recent

Author Topic: How To: Draw HTML Formatted Text  (Read 4379 times)

Marion

  • Full Member
  • ***
  • Posts: 125
How To: Draw HTML Formatted Text
« on: August 17, 2012, 07:28:53 pm »
I have to write a control (TLabel) that will accepted simple HTML tags and render the rich text on the control canvas. I am wondering if anyone has found a tutorial on the best practices for this. Some of the questions I have are:

How do you anticipate word breaks?
How do you calculate the total RECT since some of the lines may be different heights?
How do I keep track of where I am as I render the text on the Canvas?

Any hints on how to do this will be appreciated.
Thank you,
Marion
(A recovering Windows programmer.)

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: How To: Draw HTML Formatted Text
« Reply #1 on: August 17, 2012, 07:33:31 pm »
I have to write a control (TLabel) that will accepted simple HTML tags and render the rich text on the control canvas. I am wondering if anyone has found a tutorial on the best practices for this. Some of the questions I have are:

How do you anticipate word breaks?
How do you calculate the total RECT since some of the lines may be different heights?
How do I keep track of where I am as I render the text on the Canvas?

Any hints on how to do this will be appreciated.

This might be more than you need:

http://wiki.lazarus.freepascal.org/THtmlPort

You might be able to use a narrow THtmlViewer as a label.

In any case, you can see how it renders HTML.

Thanks.

-Phil

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How To: Draw HTML Formatted Text
« Reply #2 on: August 17, 2012, 11:43:46 pm »
Quote
How do you anticipate word breaks?
How do you calculate the total RECT since some of the lines may be different heights?
By making a good use of TextExtent
Quote
How do I keep track of where I am as I render the text on the Canvas?
Use additional variables. Update as you draw.

 

TinyPortal © 2005-2018