Recent

Author Topic: Replace SetTextAlign  (Read 12001 times)

lfrodrigues

  • New Member
  • *
  • Posts: 25
Replace SetTextAlign
« on: September 05, 2007, 03:09:34 am »
I'm translating a Delphi app with uses SetTextAlign and then TextOut.

I found  TCanvas.TextStyle.Alignment on Canvas and tried to use (win32) but they didn't produce the same result.

Are they compatible?

Best regards,

Luis

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Replace SetTextAlign
« Reply #1 on: September 05, 2007, 04:15:24 am »
Quote from: "lfrodrigues"
I'm translating a Delphi app with uses SetTextAlign and then TextOut.

I found  TCanvas.TextStyle.Alignment on Canvas and tried to use (win32) but they didn't produce the same result.

Are they compatible?


SetTextAlign is a Win API function. You can simulate it by using GetTextMetrics to get information about the device context, then adjusting the X and Y coordinates appropriately (based on the flags passed to SetTextAlign) before passing the coords to TextOut.

Thanks.

-Phil

lfrodrigues

  • New Member
  • *
  • Posts: 25
RE: Re: Replace SetTextAlign
« Reply #2 on: September 05, 2007, 01:55:25 pm »
Thanks for the reply.

Could you please provide me with an example. If I have SetTExtAlign(canvas.handle, TA_LEFT) what should be the corresponding code?

By the way, what is the use for TCanvas.TextStyle.Alignment ?

antonio

  • Hero Member
  • *****
  • Posts: 605
RE: Re: Replace SetTextAlign
« Reply #3 on: September 05, 2007, 02:20:49 pm »
See Delphi's help for it.

Zaher

  • Hero Member
  • *****
  • Posts: 683
    • parmaja.org
RE: Re: Replace SetTextAlign
« Reply #4 on: September 06, 2007, 02:41:57 am »
TCanvas.TextStyle is the default TextStyle for TextRect not for TextOut

But maybe some one can hack TextOut to change
MoveTo(X + TextWidth(Text), Y);
to
MoveTo(X - TextWidth(Text), Y);
depending on Alignment, but before that my ask why we need it?, is your work is right to left, why not using TextRect.

lfrodrigues

  • New Member
  • *
  • Posts: 25
RE: Re: Replace SetTextAlign
« Reply #5 on: September 06, 2007, 03:52:57 am »
I was porting some Delphi code. I haven't used Lazarus for sometime so forgot about TextRect.

Thanks.

 

TinyPortal © 2005-2018