Recent

Author Topic: TCanvas.TextOut vs LazFreeType text drawing  (Read 6097 times)

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
TCanvas.TextOut vs LazFreeType text drawing
« on: March 23, 2012, 08:29:52 am »
Hello,

I'd like to get some input from circular on this =)

Basically if you specify a position X, Y to draw a text LazFreeType will draw apparently starting on this position and upwards and to the right, correct?

In TCanvas it goes downwards and to the right, so there is a difference which I need to compensate. I though about just summing up the TextHeight but it doesn't work for me, then the text gets too low. If I sum up 75% * TextHeight then it seams to work perfectly, although it would be good to know if this is reliable or else what would be the best algorithm to convert X,Y text out positions between LazFreeType and TCanvas

Check this for the concrete code which I am talking about this:

http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/lcl/interfaces/customdrawn/customdrawnwinapi.inc?root=lazarus&r1=36243&r2=36242&pathrev=36243

thanks,

Graeme

  • Hero Member
  • *****
  • Posts: 1430
    • Graeme on the web
Re: TCanvas.TextOut vs LazFreeType text drawing
« Reply #1 on: March 23, 2012, 09:37:11 am »
Basically if you specify a position X, Y to draw a text LazFreeType will draw apparently starting on this position and upwards and to the right, correct?
Yes, that is how FreeType's text coordinates work. To make it TCanvas compatible, simply subtract the text height from the TCanvas's text out coordinates, before sending it to FreeType.

Pseudocode example:
Code: [Select]
  TCanvas.TextOut(x, y: integer; txt: string);
  begin
      FreeType.Text(x, y-TextHeight(txt), txt);
  end;

This is what I do in fpGUI+FreeType, and the text position is 100% compatible with fpGUI+[X11|GDI].

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

circular

  • Hero Member
  • *****
  • Posts: 2954
    • Personal webpage
Re: TCanvas.TextOut vs LazFreeType text drawing
« Reply #2 on: March 23, 2012, 01:57:46 pm »
In the last version of LazFreeType, you can supply alignment.

Obviously you're not using the last version. Please check the patch again.
Conscience is the debugger of the mind

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: TCanvas.TextOut vs LazFreeType text drawing
« Reply #3 on: March 23, 2012, 02:45:35 pm »
In the last version of LazFreeType, you can supply alignment.

How exactly? Could you point to which parameter does this?

circular

  • Hero Member
  • *****
  • Posts: 2954
    • Personal webpage
Re: TCanvas.TextOut vs LazFreeType text drawing
« Reply #4 on: March 23, 2012, 04:57:11 pm »
The DrawText function can take parameters after the color. You can supply an alpha value, and also a set of alignments. For example [ftaLeft, ftaTop], which is used in the example :
Code: [Select]
  ftFont1.Hinted := true;
  ftFont1.ClearType := true;
  ftFont1.Quality := grqHighQuality;
  ftFont1.SmallLinePadding := false;
  drawer.DrawText(testtext, ftFont1, x, y, colBlack, [ftaRight, ftaBottom]);

  ftFont2.Hinted := false;
  ftFont2.ClearType := false;
  ftFont2.Quality := grqHighQuality;
  drawer.DrawText(testtext, ftFont2, x, y, colRed, 192, [ftaCenter, ftaBaseline]);

  ftFont3.Hinted := false;
  ftFont3.ClearType := false;
  ftFont3.Quality := grqMonochrome;
  drawer.DrawText(testtext, ftFont3, x, y, colBlack, 128, [ftaLeft, ftaTop]);
Conscience is the debugger of the mind