Hi
I want to set text on the image using gflAddText(). Previously I have to know the width and height of the area with the text. I tried to use gflGetTextExtent() to get that values but this function returns random values. For example for three identical calls of
gflGetTextExtent('Reggi', 'Arial', 30, 0, 0, 0, 0, 0, 0, txtW, txtH)
it returns values (txtH, txtW):
(246, 101)
(303, 101)
(269, 101)
Regards
gflGetTextExtent doesn't work correctly?
Moderators: XnTriq, helmut, xnview
-
- Posts: 33
- Joined: Tue Mar 09, 2010 6:40 pm
Re: gflGetTextExtent doesn't work correctly?
Cannot confirm that. Did it in a loop 10 times with exactly your parameters, using version 3.11 and it always gave me no error and the width/height parameters held the values 66x28.
- Have you called gflLibraryInit() with a result of GFL_NO_ERROR before using gflGetTextExtent?
- Which result does gflGetTextExtent return? If it is not GFL_NO_ERROR then of course the values of the out parameters are undefined.
- Which platform do you use? Is Arial available at all?
-
- Posts: 16
- Joined: Thu Sep 16, 2004 1:32 pm
Re: gflGetTextExtent doesn't work correctly?
I have called gflLibraryInit() with a result of GFL_NO_ERROR
gflGetTextExtent() returns GFL_NO_ERROR
I use it under Windows XP and Delphi 6 Professional. I used odd fonts, they are installed in the system.
I tried to use gflGetTextExtent() in a loop and the width/height parameters was some, but they incorrect (for example 304/182).
But if I destroyed the object of the GFL image and create new instance, the width/height parameters are different (261/182, in next object 301/182 etc.). So - in each time in a loop they are identical, but in each object are different. I've no idea why :/
gflGetTextExtent() returns GFL_NO_ERROR
I use it under Windows XP and Delphi 6 Professional. I used odd fonts, they are installed in the system.
I tried to use gflGetTextExtent() in a loop and the width/height parameters was some, but they incorrect (for example 304/182).
But if I destroyed the object of the GFL image and create new instance, the width/height parameters are different (261/182, in next object 301/182 etc.). So - in each time in a loop they are identical, but in each object are different. I've no idea why :/
-
- Posts: 16
- Joined: Thu Sep 16, 2004 1:32 pm
Re: gflGetTextExtent doesn't work correctly?
OK, I found the error. It is in the libgfl.pas. There is:
function gflGetTextExtent(var text, font_name: PChar;
var font_size, orientation: GFL_INT32;
var italic, bold, strike_out, underline, antialias: GFL_BOOL;
var text_width, text_height: GFL_INT32): GFL_ERROR; stdcall;
Should be (without var):
function gflGetTextExtent(text, font_name: PChar;
font_size, orientation: GFL_INT32;
italic, bold, strike_out, underline, antialias: GFL_BOOL;
var text_width, text_height: GFL_INT32): GFL_ERROR; stdcall;
Of course the keyword var musts be before text_width and text_height
function gflGetTextExtent(var text, font_name: PChar;
var font_size, orientation: GFL_INT32;
var italic, bold, strike_out, underline, antialias: GFL_BOOL;
var text_width, text_height: GFL_INT32): GFL_ERROR; stdcall;
Should be (without var):
function gflGetTextExtent(text, font_name: PChar;
font_size, orientation: GFL_INT32;
italic, bold, strike_out, underline, antialias: GFL_BOOL;
var text_width, text_height: GFL_INT32): GFL_ERROR; stdcall;
Of course the keyword var musts be before text_width and text_height
-
- Posts: 33
- Joined: Tue Mar 09, 2010 6:40 pm
Re: gflGetTextExtent doesn't work correctly?
Then you're using an outdated version.reggi wrote:OK, I found the error. It is in the libgfl.pas. There is:Code: Select all
function gflGetTextExtent([b]var[/b] text, font_name: PChar; var font_size, orientation: GFL_INT32; var italic, bold, strike_out, underline, antialias: GFL_BOOL; var text_width, text_height: GFL_INT32): GFL_ERROR; stdcall;
Check this post http://newsgroup.xnview.com/viewtopic.p ... 821#p82821 - version 20100321 is the most recent one. I corrected quite some errorneous interfaces, since I'm also using Delphi.
-
- Posts: 16
- Joined: Thu Sep 16, 2004 1:32 pm
Re: gflGetTextExtent doesn't work correctly?
Thx 
I found one more bug in gflGetTextExtent(). text_width hold incorrect value if italic is enabled (several px fewer, like for normal text).

I found one more bug in gflGetTextExtent(). text_width hold incorrect value if italic is enabled (several px fewer, like for normal text).
-
- Posts: 33
- Joined: Tue Mar 09, 2010 6:40 pm
Re: gflGetTextExtent doesn't work correctly?
Cannot confirm this either. My test scenario: ...which gives me the following output:
These are reasonable values: normal text is shortest, because italic needs more width because higher pixels are shifted to the right. And bold usually uses more pixels. However, the height is a bit suspicious to me - why is this not 30 in normal also?
Which code are you using?
Code: Select all
var
iWidth, iHeight: GFL_INT32;
iRes: GFL_ERROR;
begin
iRes:= gflGetTextExtent( 'Text', 'Arial', 30, 0, 0, 0, 0, 0, 0, iWidth, iHeight );
Memo1.Lines.Add( 'Normal: '+ IntToStr( iWidth )+ 'x'+ IntToStr( iHeight )+ ' Result='+ IntToStr( iRes ) );
iRes:= gflGetTextExtent( 'Text', 'Arial', 30, 0, 1, 0, 0, 0, 0, iWidth, iHeight );
Memo1.Lines.Add( 'Italic: '+ IntToStr( iWidth )+ 'x'+ IntToStr( iHeight )+ ' Result='+ IntToStr( iRes ) );
iRes:= gflGetTextExtent( 'Text', 'Arial', 30, 0, 0, 1, 0, 0, 0, iWidth, iHeight );
Memo1.Lines.Add( 'Bold: '+ IntToStr( iWidth )+ 'x'+ IntToStr( iHeight )+ ' Result='+ IntToStr( iRes ) );
Code: Select all
Normal: 46x28 Result=0
Italic: 49x30 Result=0
Bold: 51x30 Result=0
Which code are you using?