Levente
asked on
Get the position of a word in a line written on a canvas?
I have a function which writes a line onto a canvas. This line should fit the entire width of my canvas so that I call SetTextJustification API function which "distributes the specified extra space evenly among the specified "number of spaces".
But how can I retrieve the X, Y position of the word - say - 'sample' on my canvas ?
Any help is greatly appreciated.
Greetings from Hungary,
Levente
slv@mcse.hu
-------------------------- ---------- ---------- ---------- ---------- ----------
-----------------------
var Text : PChar;
TextW : integer; { TextWidth }
begin
Text:=StrAlloc(128);
Text:='This is a sample text for SetTextJustification.';
{ TextWidth}
TextW:=LoWord( GetTextExtent(Image1.Canva s.Handle, Text, StrLen(Text)));
SetTextJustification( Image1.Canvas.Handle, Image1.Width - TextW, 6 );
TextOut(Image1.Canvas.Hand le, 0, 0, Text, StrLen(Text) );
StrDispose(Text);
end;
-------------------------- ---------- ---------- ---------- ---------- ----------
-------------------------- --
But how can I retrieve the X, Y position of the word - say - 'sample' on my canvas ?
Any help is greatly appreciated.
Greetings from Hungary,
Levente
slv@mcse.hu
--------------------------
-----------------------
var Text : PChar;
TextW : integer; { TextWidth }
begin
Text:=StrAlloc(128);
Text:='This is a sample text for SetTextJustification.';
{ TextWidth}
TextW:=LoWord( GetTextExtent(Image1.Canva
SetTextJustification( Image1.Canvas.Handle, Image1.Width - TextW, 6 );
TextOut(Image1.Canvas.Hand
StrDispose(Text);
end;
--------------------------
--------------------------
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanx for your answer. It exactly does what I needed.
(I used API calls because they're significantly faster (>50 %)
than Delphi functions - accodring to MY measurements.)
Levente
(I used API calls because they're significantly faster (>50 %)
than Delphi functions - accodring to MY measurements.)
Levente
ASKER