pdf-raku / PDF-Font-Loader-raku

Font loader for the PDF tool-chain
Artistic License 2.0
1 stars 3 forks source link

When using .print in PDF::Lite, $font.underline-thickness, $font.underline-position, and $font.height are needed #30

Closed tbrowder closed 9 months ago

tbrowder commented 1 year ago

They are helpful for fine-tuning special effects. And they should be sized accordingly by :$font-size.

dwarring commented 1 year ago

Completely undocumented at the moment. Both the .print and .say methods can take a PDF::Content::Text::Box object. This takes the same parameters as the .print and .say, except for the output position. The textbox has .underline-position and .underline-thickness accessors that return scaled values.

I need to add documentation. Also a .font-height accessor.

Code snippet below:

use PDF::Lite;
use PDF::Content;
use PDF::Content::Text::Box;

my PDF::Lite $pdf .= new;

my $font-size = 16;
my $height = 20;
my $text = "Hello.  Ting, ting-ting.";

my PDF::Content::Font::CoreFont $font .= load-font( :family<helvetica>, :weight<bold> );
my PDF::Content::Text::Box $text-box .= new( :$text, :$font, :$font-size, :$height );

say "width:" ~ $text-box.width;
say "height:" ~ $text-box.height;
say "underline-thickness:" ~ $text-box.underline-thickness;
say "underline-position:" ~ $text-box.underline-position;

my $page = $pdf.add-page;

$page.text: {
    .text-position = 10, 20;
    .say: $text-box;
    .text-position = 10, 50;
    .print: $text-box;
}

$pdf.save-as: "test.pdf";
tbrowder commented 9 months ago

Closing since I can use it now.