diff --git a/src/Output/QRFpdf.php b/src/Output/QRFpdf.php index fdaa0c299..bb5e537ec 100644 --- a/src/Output/QRFpdf.php +++ b/src/Output/QRFpdf.php @@ -69,7 +69,7 @@ class QRFpdf extends QROutputAbstract{ public function dump(string $file = null):string{ $file ??= $this->options->cachefile; - $fpdf = new FPDF('P', 'pt', [$this->length, $this->length]); + $fpdf = new FPDF('P', $this->options->fpdfMeasureUnit, [$this->length, $this->length]); $fpdf->AddPage(); $prevColor = null; diff --git a/src/QROptions.php b/src/QROptions.php index 985c304dd..5dbc1d4a2 100644 --- a/src/QROptions.php +++ b/src/QROptions.php @@ -45,6 +45,7 @@ use chillerlan\Settings\SettingsContainerAbstract; * @property int $jpegQuality * @property string $imagickFormat * @property string|null $imagickBG + * @property string $fpdfMeasureUnit * @property array|null $moduleValues */ class QROptions extends SettingsContainerAbstract{ diff --git a/src/QROptionsTrait.php b/src/QROptionsTrait.php index 0a2fd8247..69c8b1a54 100644 --- a/src/QROptionsTrait.php +++ b/src/QROptionsTrait.php @@ -14,7 +14,7 @@ namespace chillerlan\QRCode; -use function array_values, count, is_numeric, max, min, sprintf; +use function array_values, count, in_array, is_numeric, max, min, sprintf, strtolower; /** * The QRCode plug-in settings & setter functionality @@ -197,6 +197,13 @@ trait QROptionsTrait{ */ protected ?string $imagickBG = null; + /** + * Measurement unit for FPDF output: pt, mm, cm, in (defaults to "pt") + * + * @see \FPDF::__construct() + */ + protected string $fpdfMeasureUnit = 'pt'; + /** * Module values map * @@ -299,4 +306,17 @@ trait QROptionsTrait{ } + /** + * sets the FPDF measurement unit + */ + protected function set_fpdfMeasureUnit(string $unit):void{ + $unit = strtolower($unit); + + if(in_array($unit, ['cm', 'in', 'mm', 'pt'], true)){ + $this->fpdfMeasureUnit = $unit; + } + + // @todo throw or ignore silently? + } + }