BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

mixed colors in text

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Graphics
View previous topic :: View next topic  
Author Message
Andrew
Guest





PostPosted: Thu Oct 05, 2006 5:15 pm    Post subject: mixed colors in text Reply with quote



Hi All,

I am trying to draw a listitem caption in a listview with the first part of
it in one color and the remainder in a different color.

I draw the entire string in the color of the first part, then i get the
width of the first part of the string, move the clipping rectangles left
side by that width, then redraw the string with a different font color. I
get the effect i am looking for, but the second part of the text is not
correctly aligned over the text underneath, it is offset by a few pixels so
that the overlayed text does not have the small character space between it
and the end of the first part of the text. I have tried the windows
GetTextCharacterExtra, but it returns 0.

Can anyone help me with this, or recommend a way of drawing multiple colored
text onto a canvas?

TIA
Andrew
Back to top
Peter Below (TeamB)
Guest





PostPosted: Fri Oct 06, 2006 12:48 am    Post subject: Re: mixed colors in text Reply with quote



Andrew wrote:

Quote:
Hi All,

I am trying to draw a listitem caption in a listview with the first
part of it in one color and the remainder in a different color.

I draw the entire string in the color of the first part, then i get
the width of the first part of the string, move the clipping
rectangles left side by that width, then redraw the string with a
different font color. I get the effect i am looking for, but the
second part of the text is not correctly aligned over the text
underneath, it is offset by a few pixels so that the overlayed text
does not have the small character space between it and the end of the
first part of the text. I have tried the windows
GetTextCharacterExtra, but it returns 0.

Can anyone help me with this, or recommend a way of drawing multiple
colored text onto a canvas?


One option is to make use of

SetTextAlign( canvas.handle, TA_UPDATECP );

This changes the behaviour of Textout, it will now ignore the passed
coordinates and continue at the last output position. Unfortunately
Delphis internal management of the TCanvas properties gets in the way
here, so you need to do most of the text output using GDI methods
directly. Here is an example using a TPaintboxes OnPaint handler:

procedure TForm1.PaintBox1Paint(Sender: TObject);
var
PB: TPaintbox;
CV: TCanvas;
F: Cardinal;
begin
PB := Sender as Tpaintbox;
CV := PB.Canvas;
F := GetTextAlign(CV.Handle);
CV.Font.Name := 'Tahoma';
CV.Font.Size := 12;
CV.Font.Color := clBlack;
SetTextAlign( CV.handle, F or TA_UPDATECP );
CV.MoveTo(10,10); //Start position of text
TextOut(CV.Handle, 0, 0, 'Black ', 6);
SetTextColor(CV.Handle, ColorToRGB(clRed));
TextOut(CV.Handle,0, 0, 'Red ', 4);
SetTextColor(CV.Handle, ColorToRGB(clGreen));
TextOut(CV.Handle,0, 0, 'Green ', 6);
SetTextAlign( CV.handle, F);
end;


--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be
Back to top
Andrew
Guest





PostPosted: Fri Oct 06, 2006 8:11 am    Post subject: Re: mixed colors in text Reply with quote



Hi Peter,

Thanks, I'll give it a try.


"Peter Below (TeamB)" <none> wrote in message
news:xn0es4bp927524000 (AT) newsgroups (DOT) borland.com...
Quote:
Andrew wrote:

Hi All,

I am trying to draw a listitem caption in a listview with the first
part of it in one color and the remainder in a different color.

I draw the entire string in the color of the first part, then i get
the width of the first part of the string, move the clipping
rectangles left side by that width, then redraw the string with a
different font color. I get the effect i am looking for, but the
second part of the text is not correctly aligned over the text
underneath, it is offset by a few pixels so that the overlayed text
does not have the small character space between it and the end of the
first part of the text. I have tried the windows
GetTextCharacterExtra, but it returns 0.

Can anyone help me with this, or recommend a way of drawing multiple
colored text onto a canvas?


One option is to make use of

SetTextAlign( canvas.handle, TA_UPDATECP );

This changes the behaviour of Textout, it will now ignore the passed
coordinates and continue at the last output position. Unfortunately
Delphis internal management of the TCanvas properties gets in the way
here, so you need to do most of the text output using GDI methods
directly. Here is an example using a TPaintboxes OnPaint handler:

procedure TForm1.PaintBox1Paint(Sender: TObject);
var
PB: TPaintbox;
CV: TCanvas;
F: Cardinal;
begin
PB := Sender as Tpaintbox;
CV := PB.Canvas;
F := GetTextAlign(CV.Handle);
CV.Font.Name := 'Tahoma';
CV.Font.Size := 12;
CV.Font.Color := clBlack;
SetTextAlign( CV.handle, F or TA_UPDATECP );
CV.MoveTo(10,10); //Start position of text
TextOut(CV.Handle, 0, 0, 'Black ', 6);
SetTextColor(CV.Handle, ColorToRGB(clRed));
TextOut(CV.Handle,0, 0, 'Red ', 4);
SetTextColor(CV.Handle, ColorToRGB(clGreen));
TextOut(CV.Handle,0, 0, 'Green ', 6);
SetTextAlign( CV.handle, F);
end;


--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be
Back to top
Andrew
Guest





PostPosted: Fri Oct 06, 2006 8:11 am    Post subject: Re: mixed colors in text Reply with quote

Hi Peter,

Gave it a try, with a few tweaks, like using ExtTextOut so that the text is
clipped to the column width, and setting the brush style to clear, it works
perfectly. Many, many thanks.

Andrew


"Andrew" <1> wrote in message news:4524f74f (AT) newsgroups (DOT) borland.com...
Quote:
Hi All,

I am trying to draw a listitem caption in a listview with the first part
of it in one color and the remainder in a different color.

I draw the entire string in the color of the first part, then i get the
width of the first part of the string, move the clipping rectangles left
side by that width, then redraw the string with a different font color. I
get the effect i am looking for, but the second part of the text is not
correctly aligned over the text underneath, it is offset by a few pixels
so that the overlayed text does not have the small character space between
it and the end of the first part of the text. I have tried the windows
GetTextCharacterExtra, but it returns 0.

Can anyone help me with this, or recommend a way of drawing multiple
colored text onto a canvas?

TIA
Andrew
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Graphics All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.