gflGetTextExtent doesn't work correctly?

Discussions on GFL SDK, the graphic library for reading and writing graphic files

Moderators: XnTriq, helmut, xnview

Post Reply
reggi
Posts: 16
Joined: Thu Sep 16, 2004 1:32 pm
Contact:

gflGetTextExtent doesn't work correctly?

Post by reggi »

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
User avatar
AmigoJack
Posts: 33
Joined: Tue Mar 09, 2010 6:40 pm
Contact:

Re: gflGetTextExtent doesn't work correctly?

Post by AmigoJack »

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?
reggi
Posts: 16
Joined: Thu Sep 16, 2004 1:32 pm
Contact:

Re: gflGetTextExtent doesn't work correctly?

Post by reggi »

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 :/
reggi
Posts: 16
Joined: Thu Sep 16, 2004 1:32 pm
Contact:

Re: gflGetTextExtent doesn't work correctly?

Post by reggi »

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
User avatar
AmigoJack
Posts: 33
Joined: Tue Mar 09, 2010 6:40 pm
Contact:

Re: gflGetTextExtent doesn't work correctly?

Post by AmigoJack »

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;
Then you're using an outdated version.
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.
reggi
Posts: 16
Joined: Thu Sep 16, 2004 1:32 pm
Contact:

Re: gflGetTextExtent doesn't work correctly?

Post by reggi »

Thx :)

I found one more bug in gflGetTextExtent(). text_width hold incorrect value if italic is enabled (several px fewer, like for normal text).
User avatar
AmigoJack
Posts: 33
Joined: Tue Mar 09, 2010 6:40 pm
Contact:

Re: gflGetTextExtent doesn't work correctly?

Post by AmigoJack »

Cannot confirm this either. My test scenario:

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 ) );
...which gives me the following output:

Code: Select all

Normal: 46x28 Result=0
Italic: 49x30 Result=0
Bold: 51x30 Result=0
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?
Post Reply