|
|
@@ -16,7 +16,7 @@ use chillerlan\QRCode\Data\QRMatrix;
|
|
|
use chillerlan\Settings\SettingsContainerInterface;
|
|
|
use FPDF;
|
|
|
|
|
|
-use function array_values, class_exists, count, intval, is_array, is_numeric, max, min;
|
|
|
+use function class_exists;
|
|
|
|
|
|
/**
|
|
|
* QRFpdf output module (requires fpdf)
|
|
|
@@ -25,6 +25,7 @@ use function array_values, class_exists, count, intval, is_array, is_numeric, ma
|
|
|
* @see http://www.fpdf.org/
|
|
|
*/
|
|
|
class QRFpdf extends QROutputAbstract{
|
|
|
+ use RGBArrayModuleValueTrait;
|
|
|
|
|
|
final public const MIME_TYPE = 'application/pdf';
|
|
|
|
|
|
@@ -42,7 +43,7 @@ class QRFpdf extends QROutputAbstract{
|
|
|
// @codeCoverageIgnoreStart
|
|
|
throw new QRCodeOutputException(
|
|
|
'The QRFpdf output requires FPDF (https://github.com/Setasign/FPDF)'.
|
|
|
- ' as dependency but the class "\\FPDF" couldn\'t be found.'
|
|
|
+ ' as dependency but the class "\\FPDF" could not be found.'
|
|
|
);
|
|
|
// @codeCoverageIgnoreEnd
|
|
|
}
|
|
|
@@ -50,61 +51,6 @@ class QRFpdf extends QROutputAbstract{
|
|
|
parent::__construct($options, $matrix);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @inheritDoc
|
|
|
- */
|
|
|
- public static function moduleValueIsValid(mixed $value):bool{
|
|
|
-
|
|
|
- if(!is_array($value) || count($value) < 3){
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- // check the first 3 values of the array
|
|
|
- foreach(array_values($value) as $i => $val){
|
|
|
-
|
|
|
- if($i > 2){
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- if(!is_numeric($val)){
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @inheritDoc
|
|
|
- * @throws \chillerlan\QRCode\Output\QRCodeOutputException
|
|
|
- */
|
|
|
- protected function prepareModuleValue(mixed $value):array{
|
|
|
- $values = [];
|
|
|
-
|
|
|
- foreach(array_values($value) as $i => $val){
|
|
|
-
|
|
|
- if($i > 2){
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- $values[] = max(0, min(255, intval($val)));
|
|
|
- }
|
|
|
-
|
|
|
- if(count($values) !== 3){
|
|
|
- throw new QRCodeOutputException('invalid color value');
|
|
|
- }
|
|
|
-
|
|
|
- return $values;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @inheritDoc
|
|
|
- */
|
|
|
- protected function getDefaultModuleValue(bool $isDark):array{
|
|
|
- return ($isDark) ? [0, 0, 0] : [255, 255, 255];
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Initializes an FPDF instance
|
|
|
*/
|