TQuickPDF0813.DrawText
Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2074
Printed Date: 21 May 25 at 11:17AM Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com
Topic: TQuickPDF0813.DrawText
Posted By: micha
Subject: TQuickPDF0813.DrawText
Date Posted: 18 Dec 11 at 3:48PM
hello, im using delphi 7 when using the DrawText function the text is drawn over the y position does anyone know how to draw the text under the y position ? thanks micha
|
Replies:
Posted By: Ingo
Date Posted: 18 Dec 11 at 8:15PM
Hi Micha!
Perhaps it's better to post the used code-snippet. If you're asking about orientation you should use SetOrigin. Please read here: http://www.quickpdflibrary.com/help/quickpdf/SetOrigin.php
Cheers and welcome here, Ingo
|
Posted By: AndrewC
Date Posted: 19 Dec 11 at 10:04PM
Text is a PDF file is drawn on the baseline. If you want to draw text from the top of the font cell or the top of the characters then you would use either GetTextHeight or GetTextAscent
QP.SetOrigin(1); QP.DrawLine(30, 30, 400, 30); QP.DrawText(30, 30 - QP.GetTextHeight(), "Hello World using text height");
QP.DrawLine(30, 60, 400, 60); QP.DrawText(30, 60 - QP.GetTextAscent(), "Hello World using ascent");
|
Posted By: edvoigt
Date Posted: 20 Dec 11 at 2:31PM
Hi Micha,
Here an overview on the properties around Textheight:
To have text of different size readable in a line, all is drawn on the baseline. It's so in Word, in PDF and it makes sense. But inside a technical drawing, you may want a spezial alignment and so you need some calculations around size. You may get all information by GetTextAscent, GetTextDescent, GetTextBound(...), GetTextHeight, GetTextWidth. But keep in mind, that SetTextSize works ever with points.
Here a codesnippet for the above painting in D7:
var QP: TQuickPDF; s: string; x, y, tf, ta, td, tt, th, ts, tw: double; begin QP := TQuickPDF.Create; QP.UnlockKey(... QP.SetMeasurementUnits(1); // millimeters QP.SetPageDimensions(210, 297); // DIN A4 QP.SetOrigin(0); // bottomleft x := 20; y := 20; s := 'Ä happy ÉgʦÇ'; // to have real things on all lines
QP.AddStandardFont(11); // as you like tf := 24*72/25.4; // 24 mm as points QP.SetTextSize(tf); ta := QP.GetTextAscent; // get all we can need td := QP.GetTextDescent; tt := QP.GetTextBound(2); th := QP.GetTextHeight; ts := QP.GetTextSize*25.4/72; // points to mm tw := QP.GetTextWidth(s); QP.DrawText(x, y, s);
tf := 4*72/25.4; // 4 mm as points QP.SetTextSize(tf);
QP.SetLineWidth(0.1); QP.SetLineColor(1, 0, 0); // Baseline QP.DrawLine(x-10, y, x+tw+5, y); QP.DrawText(x+tw+6, y, 'Baseline'); QP.SetLineColor(0, 1, 0); // Ascent QP.DrawLine(x-10, y+ta, x+tw+5, y+ta); QP.DrawText(x+tw+6, y+ta, 'Ascent'); QP.SetLineColor(0, 0, 1); // Descent = abs(Bottom) QP.DrawLine(x-10, y+td, x+tw+5, y+td); QP.DrawText(x+tw+6, y+td, 'Descent'); QP.SetLineColor(0, 0.5, 0.5); // Top QP.DrawLine(x-10, y+tt, x+tw+5, y+tt); QP.DrawText(x+tw+6, y+tt, 'Top');
QP.AddStandardFont(4); QP.SetTextSize(tf); QP.DrawText(x, y-10, Format('Ascent=%.2f Descent=%.2f Top=%.2f Textsize=%.2f Delta=%.2f',[ta, td, tt, ts, tt-ta]));
Cheers,
Werner
|
|