Skip to content
forked from psliwa/PHPPdf

Commit

Permalink
Merge pull request #8 from jobcloud/fix/PRO-698/php81-deprecation-fixes
Browse files Browse the repository at this point in the history
fix/PRO-698/php81-deprecation-fixes
  • Loading branch information
haeber authored Jun 8, 2023
2 parents 60fc4ad + c262967 commit 539d34f
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions lib/PHPPdf/Core/PdfUnitConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,36 @@

/**
* Unit converter
*
*
* @author Piotr Śliwa <peter.pl7@gmail.com>
*/
class PdfUnitConverter extends AbstractUnitConverter
{
private $dpi;
private $unitsPerPixel;

public function __construct($dpi = 96)
{
if(!is_int($dpi) || $dpi < 1)
{
if (!is_int($dpi) || $dpi < 1) {
throw new InvalidArgumentException(sprintf('Dpi must be positive integer, "%s" given.', $dpi));
}

$this->dpi = $dpi;
$this->unitsPerPixel = self::UNITS_PER_INCH/$this->dpi;
$this->unitsPerPixel = self::UNITS_PER_INCH / $this->dpi;
}


/**
* @param string|float|int|null $value
* @param string|null $unit
* @return float|int|string
*/
public function convertUnit($value, $unit = null)
{
if(is_numeric($value) && $unit === null)
{
if (is_numeric($value) && $unit === null) {
return $value;
}
$unit = $unit ? : strtolower(substr($value, -2, 2));

$unit = $unit ?: strtolower(substr((string) $value, -2, 2));

return $this->doConvertUnit($value, $unit);
}
Expand All @@ -51,16 +54,16 @@ protected function convertPxUnit($value)

protected function convertInUnit($value)
{
return ((float) $value)*self::UNITS_PER_INCH;
return ((float) $value) * self::UNITS_PER_INCH;
}

protected function convertPtUnit($value)
{
return (float) $value;
}

protected function convertMmUnit($value)
{
return $this->convertInUnit($value)/self::MM_PER_INCH;
return $this->convertInUnit($value) / self::MM_PER_INCH;
}
}
}

0 comments on commit 539d34f

Please sign in to comment.