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

Write() does not wrap if the line ends with bold text just before the specified page margin. #650

Open
DerPapst opened this issue Oct 2, 2023 · 7 comments

Comments

@DerPapst
Copy link

DerPapst commented Oct 2, 2023

When a line ends just before the specified page margin with bold text, additional text appended with Write() is clipped.

Steps to reproduce this issue (include TCPDF with composer):

<?php
require_once(__DIR__.'/vendor/autoload.php');

$content = [
    ['Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy ', ''],
    ['eirmod', 'B'],
    ['tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.', ''],
];

$pdf = new TCPDF();
$pdf->setLeftMargin(26);
$pdf->setRightMargin(26);
$pdf->addPage();

foreach ($content as $item) {
    $tmp = $pdf->getFontStyle();
    $pdf->setFont('', $item[1]);
    $pdf->Write($pdf->getFontSizePt() / 2, $item[0]);
    $pdf->setFont('', $tmp);
}
$pdf->Output();

Result:

is

Expected result:
should be

@DerPapst
Copy link
Author

DerPapst commented Oct 2, 2023

Basically, it boils down to the return ''; in line 6441. When I remove it, it appears to be working as expected, but I assume it is there for a reason.

@wayne530
Copy link

I have a similar issue, but it doesn't require any text formatting at the end of the line. Text of a certain size will get up to the boundary of the max page width (less margins) and not trigger wrapping. All remaining text vanishes. Doing something to purposely trigger a word wrap, such as adding extra spaces, will fix the issue. Similarly, disabling line 6448 (6.7.5) solves the issue, but as @DerPapst says, it must be there for a reason and removing it may cause other issues.

@wayne530
Copy link

wayne530 commented Jun 27, 2024

This will reproduce the issue without any formatting changes. I think the formatting changes are potentially a red herring:

<?php
require_once(__DIR__.'/vendor/autoload.php');

$content = [
    ['Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmodx', ''],
    ['tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.', ''],
];

$pdf = new TCPDF();
$pdf->setLeftMargin(26);
$pdf->setRightMargin(26);
$pdf->addPage();

foreach ($content as $item) {
    $pdf->Write($pdf->getFontSizePt() / 2, $item[0]);
}

$pdf->Output();

@wayne530
Copy link

image

@wayne530
Copy link

You can change eirmodx to eirmodxl and it'll exhibit the same behavior. However, add enough characters and it forces a correct wrapping and the problem does not appear.

Exhibits the issue:

$content = [
    ['Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmodxl', ''],
    ['tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.', ''],
];

Does NOT exhibit the issue:

$content = [
    ['Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmodxll', ''],
    ['tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.', ''],
];

@wayne530
Copy link

This seems like some sort of boundary edge case.

@wayne530
Copy link

@williamdes @nicolaasuni possible to get someone to take a look and at least verify it is reproducible by others?

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