[Lazarus] PDF generator: please test
Ondrej Pokorny
lazarus at kluug.net
Sun Apr 10 08:03:59 CEST 2016
On 10.04.2016 1:02, Graeme Geldenhuys wrote:
>> P.WriteUTF8Text(25, 20, 'Sample Text');
>> >
>> > xFontCache := TFPFontCacheList.Create;
>> > try
>> > xFont := TFPFontCacheItem.Create('fonts\FreeSans.ttf');
>> > xFontCache.Add(xFont);
>> > xWidth := xFont.TextWidth('Sample Text', cFontSize) * 25.4 / 72; //
>> >25.4 / 72 = conversion PDFTomm (?)
> I believe here is your mistake. Your system is probably 96 DPI, not 72.
IMO it's not about my system DPI (fppdf is headless and doesn't use the
GUI DPI). It's the default value in TFPFontCacheList.DPI. Correct?
I expected fpttf it to use 72 DPI which is the default for PDF
(cDefaultDPI in fppdf.pas). My mistake.
> If you use gTTFontCache.DPI it would have given you the correct result.
Indeed, thanks!
> At the moment the FontCache object defaults to the most common desktop
> DPI, which is 96, but in your actual application you can query it with
> whatever GUI you have and set the value yourself.
Great, thanks Graeme for the code and clarifying, it works!
(IMO it would be great to update the example code with "box around text"
code. It is a usual task to get text width/height and so you spare your
time to clarify it to another person who needs it in the future.)
Ondrej
More information about the Lazarus
mailing list