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

Fix non-numeric value warning #627

Merged
merged 4 commits into from
Sep 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions tcpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -5467,6 +5467,9 @@ protected function getCellCode($w, $h=0, $txt='', $border=0, $ln=0, $align='', $
$s .= 'q '.$this->TextColor.' ';
}
// rendering mode
if(!is_numeric($this->textstrokewidth)){
$this->textstrokewidth = 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try to track in the code where it changes to a non numeric value ?

	/**
	 * Text stroke width in doc units.
	 * @protected
	 * @since 4.9.008 (2010-04-03)
	 */
	protected $textstrokewidth = 0;

Since it's initialized to 0
Maybe you can add an @var int or @var float or @var int|float phpdoc on this property, for documentation purposes

The fix you propose indeed should work, but if we can catch it earlier to avoid the textstrokewidth being a non numeric that would be cool

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, turns out I was passing a non-numeric value to the Text function for $fstroke. The new commit ignores non-numeric values that are passed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, it looks way better

Is this mistake related to your code of tcpdf code calling the function ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess so, but anybody calling $pdf->Text($x, $y, $text, "non-numeric"); would get the same warning

$s .= sprintf('BT %d Tr %F w ET ', $this->textrendermode, ($this->textstrokewidth * $this->k));
// count number of spaces
$ns = substr_count($txt, chr(32));
Expand Down