Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is $font.height applied with $gfx.say for the resulting text position? #31

Open
tbrowder opened this issue Jul 31, 2023 · 5 comments
Open

Comments

@tbrowder
Copy link

No description provided.

@dwarring
Copy link
Contributor

dwarring commented Aug 1, 2023

Also not well documented yet. By default the x position is the baseline of the font. There is a :baseline option on the .print and .say methods and on text-box objects. :baseline<top>, will cause the height to be taken into account.

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

my PDF::Lite $pdf .= new;

my $page = $pdf.add-page;

$page.text: {
    .text-position = 10, 20;
    .print: '[Default]',;
    .print: '[Bottom]', :baseline<bottom>;
    .print: '[Top]', :baseline<top>;
    .print: '[Middle]', :baseline<middle>;
}

$pdf.save-as: "test.pdf";

@tbrowder
Copy link
Author

tbrowder commented Aug 1, 2023

Is the affect supposed to be the same as :valign<bottom> et al.?

@dwarring
Copy link
Contributor

dwarring commented Aug 1, 2023

It's similar, but :baseline is always a constant shift within a line
test.pdf
. But :valign depends on the number of lines of text, as in the following example, which uses :width` to break the text across multiple lines and shifts the paragraphs as a whole.

use PDF::Lite;

my PDF::Lite $pdf .= new;

my $page = $pdf.add-page;

my $x = 10;
for <center top bottom> -> $valign {
    $page.text: {
        .text-position = $x, 150;
        .print: "A multi line paragraph of $valign aligned text", :$valign, :width(100);
        $x += 150;
    }
}

$pdf.save-as: "test.pdf";

@tbrowder
Copy link
Author

tbrowder commented Aug 1, 2023

Great example, David. Thanks.

@dwarring
Copy link
Contributor

Starting with PDF::Content release 0.70, I've toned down :valign to only affect the text flow of multiple line text boxes. It has no affect now on a single line of text, which is now only be shifted with :baseline.

I made this change after realizing that both :baseline and :valign were "fighting over" the first line of text, allowing it to be moved by up to two lines, so that the text box could be positioned up to a full line above or below the current text position, which seems surprising.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants