Forum > LazUtils
TCanvas.TextOut vs LazFreeType text drawing
(1/1)
felipemdc:
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:
--- Quote from: felipemdc on March 23, 2012, 08:29:52 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?
--- End quote ---
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: --- TCanvas.TextOut(x, y: integer; txt: string);
begin
FreeType.Text(x, y-TextHeight(txt), txt);
end;
--- End code ---
This is what I do in fpGUI+FreeType, and the text position is 100% compatible with fpGUI+[X11|GDI].
circular:
In the last version of LazFreeType, you can supply alignment.
Obviously you're not using the last version. Please check the patch again.
felipemdc:
--- Quote from: circular on March 23, 2012, 01:57:46 pm ---In the last version of LazFreeType, you can supply alignment.
--- End quote ---
How exactly? Could you point to which parameter does this?
circular:
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: --- 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]);
--- End code ---
Navigation
[0] Message Index