Lazarus

Programming => Graphics => Graphics and Multimedia => BGRABitmap and LazPaint => Topic started by: Dibo on May 17, 2012, 01:54:07 pm

Title: Calculating text rect
Post by: Dibo on May 17, 2012, 01:54:07 pm
Hi,

Exists any BGRABitmap function which calculate text rect similar like LCL do?
Code: [Select]
LCLIntf.DrawText(tmp.Canvas.Handle, PChar(AText), Length(AText), ARect,  DT_CENTER or DT_VCENTER or DT_WORDBREAK or DT_CALCRECT);
I need this because there is not solved problem with font height difference between win32, qt and gtk2 in LCL (details: http://www.lazarus.freepascal.org/index.php/topic,16638.15.html ). Above code calculate rect for LCL, but maybe BGRABitmap can somehow create own equivalent for BGRA font support?

Regards
Title: Re: Calculating text rect
Post by: lainz on May 18, 2012, 05:16:25 am
You've checked BGRAText unit?
Title: Re: Calculating text rect
Post by: Dibo on May 18, 2012, 12:29:23 pm
Yes, but there are only functions for calculating font height, but there is no which return me whole height with word break option etc.
Title: Re: Calculating text rect
Post by: circular on May 18, 2012, 05:36:04 pm
There is no function to do this. How should it be done ? With TextFitInfo function ?

Note that you should not use BGRAText directly, because those functions a rather low level.
Title: Re: Calculating text rect
Post by: Dibo on May 18, 2012, 10:06:25 pm
There is no function to do this. How should it be done ? With TextFitInfo function ?
If possible, yes. It should have similar params as TextRect method - text as string, TTextStyle and TRect, but rect should be as var and it height should be calculated like DrawText do. If it is difficult to do, it is not necessary. I'll try to around this in a different way
Title: Re: Calculating text rect
Post by: circular on May 19, 2012, 08:48:33 pm
Well in fact it would be necessary to rewrite TextRect as well so that it gives the same result. For example if the function that returns the total height returns 3 lines and when you use TextRect to draw, there are 2 or 4, that's a problem of inconsistency.

If you do something to handle this, maybe it can be added to BGRABitmap, what do you think ?
Title: Re: Calculating text rect
Post by: circular on May 17, 2018, 08:31:18 pm
Added text measuring with word break in version 9.7 of BGRABitmap:
Code: Delphi  [Select][+][-]
  1.         function TextSize(sUTF8: string; AMaxWidth: integer): TSize; override;
  2.         function TextSize(sUTF8: string; AMaxWidth: integer; ARightToLeft: boolean): TSize; override;
  3.         function TextFitInfo(sUTF8: string; AMaxWidth: integer): integer; override;  
TinyPortal © 2005-2018