Board index » delphi » Changing font characteristics word-by-word in a block of wrapped text

Changing font characteristics word-by-word in a block of wrapped text

I have a lot of experience drawing text to canvases (both screen and
printer). However, I am faced with recreating the static text on some
government forms that include blocks of text within which certain words are
highlighted by bold, italic, underline and sometimes even a font family
change.

I usually use the DrawText function to handle wrapped text blocks, and I was
hoping there was a way to pass it (or another API call) RichText or
something similar to achieve the desired results -- but it appears not to be
available in the API.

Have I missed something in the API? Or, am I going to have to write my own
routine for this? If so -- any suggestions?

Basically I need something where I can pass a canvas, a string of tagged
text, and a TRect for the wrapping boundary, and have it output something
like:

"This is some test text in which this word is *BOLD*
and another word might be *ITALIC* and the whole
thing wraps to a rectangle."

Thanks,
Jeff Hamblin

 

Re:Changing font characteristics word-by-word in a block of wrapped text


On Mon, 10 Jul 2000 11:04:52 -0700, "Jeff H"

Quote
<jphamb...@REMOVE.home.net> wrote:
> Have I missed something in the API?

No.

Quote
> Or, am I going to have to write my own
> routine for this?

Yes.

Quote
> If so -- any suggestions?

Use inline markup to indicate the inline font changes. You might as
well use the standard HTML tags where you can, like this:

"This is some test text in which this word is <B>BOLD</B> and another
word might be <I>ITALIC</I> and the whole thing wraps to a rectangle."

You could also use an XML parser to parse this into its constituent
parts. The drawing isn't hard, but it is mundane... you'll just need
to call DrawText multiple times, keeping track of state and position.
--
Rick Rogers (TeamB)
www.fenestra.com and www.componentfactory.com

Re:Changing font characteristics word-by-word in a block of wrapped text


Thanks for the response, Rick. I was afraid of that :)

I have written a function DrawHTMLText to draw formatted text to a canvas.
The function parameters are very similar to DrawText.

If you (or anyone else) are interested in having a look or are in need of
something like this, I put the unit on borland.public.attachments as:
"DrawHTMLtext draws formatted text to Canvas"

It's also on my company's website at:
http://www.qtools.com/dev/DrawHTMLText.zip

Regards,
Jeff Hamblin
Qtools Software

"Rick Rogers (TeamB)"  wrote in message

Quote
> "Jeff H"wrote:

> > Have I missed something in the API?

> No.

> > Or, am I going to have to write my own
> > routine for this?

> Yes.

> > If so -- any suggestions?

> Use inline markup to indicate the inline font changes. You might as
> well use the standard HTML tags where you can, like this:

> "This is some test text in which this word is <B>BOLD</B> and another
> word might be <I>ITALIC</I> and the whole thing wraps to a rectangle."

> You could also use an XML parser to parse this into its constituent
> parts. The drawing isn't hard, but it is mundane... you'll just need
> to call DrawText multiple times, keeping track of state and position.
> --
> Rick Rogers (TeamB)
> www.fenestra.com and www.componentfactory.com

Re:Changing font characteristics word-by-word in a block of wrapped text


Have you considered using a rich edit control and EM_FORMATRANGE??  Perhaps
this would be appropriate with your app.  HTH

Regards,

Jon T. Camp
Applied Research Associates
jc...@ara.com

Quote
"Jeff H" <jphamb...@REMOVE.home.net> wrote in message news:396a0e05@dnews...
> I have a lot of experience drawing text to canvases (both screen and
> printer). However, I am faced with recreating the static text on some
> government forms that include blocks of text within which certain words
are
> highlighted by bold, italic, underline and sometimes even a font family
> change.

> I usually use the DrawText function to handle wrapped text blocks, and I
was
> hoping there was a way to pass it (or another API call) RichText or
> something similar to achieve the desired results -- but it appears not to
be
> available in the API.

> Have I missed something in the API? Or, am I going to have to write my own
> routine for this? If so -- any suggestions?

> Basically I need something where I can pass a canvas, a string of tagged
> text, and a TRect for the wrapping boundary, and have it output something
> like:

> "This is some test text in which this word is *BOLD*
> and another word might be *ITALIC* and the whole
> thing wraps to a rectangle."

> Thanks,
> Jeff Hamblin

Other Threads