Recent

Author Topic: Calculating text rect  (Read 7727 times)

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Calculating text rect
« 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

lainz

  • Guest
Re: Calculating text rect
« Reply #1 on: May 18, 2012, 05:16:25 am »
You've checked BGRAText unit?

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Re: Calculating text rect
« Reply #2 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.

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: Calculating text rect
« Reply #3 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.
Conscience is the debugger of the mind

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Re: Calculating text rect
« Reply #4 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

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: Calculating text rect
« Reply #5 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 ?
Conscience is the debugger of the mind

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: Calculating text rect
« Reply #6 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;  
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018