Skip to content

Commit

Permalink
:octocat: QRFpdf: support bgColor and drawLightModules
Browse files Browse the repository at this point in the history
  • Loading branch information
codemasher committed Nov 10, 2022
1 parent 7213a84 commit 00f47b4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
14 changes: 8 additions & 6 deletions examples/fpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
require_once __DIR__ . '/../vendor/autoload.php';

$options = new QROptions([
'version' => 7,
'outputType' => QROutputInterface::FPDF,
'eccLevel' => EccLevel::L,
'scale' => 5,
'imageBase64' => false,
'moduleValues' => [
'version' => 7,
'outputType' => QROutputInterface::FPDF,
'eccLevel' => EccLevel::L,
'scale' => 5,
'bgColor' => [234, 234, 234],
'drawLightModules' => false,
'imageBase64' => false,
'moduleValues' => [
// finder
QRMatrix::M_FINDER | QRMatrix::IS_DARK => [0, 63, 255], // dark (true)
QRMatrix::M_FINDER => [255, 255, 255], // light (false), white is the transparency color and is enabled by default
Expand Down
14 changes: 13 additions & 1 deletion src/Output/QRFpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,23 @@ public function dump(string $file = null){
$fpdf = new FPDF('P', $this->options->fpdfMeasureUnit, [$this->length, $this->length]);
$fpdf->AddPage();

if($this->moduleValueIsValid($this->options->bgColor)){
$bgColor = $this->getModuleValue($this->options->bgColor);

$fpdf->SetFillColor(...$bgColor);
$fpdf->Rect(0, 0, $this->length, $this->length, 'F');
}

$prevColor = null;

foreach($this->matrix->matrix() as $y => $row){

foreach($row as $x => $M_TYPE){

if(!$this->options->drawLightModules && !$this->matrix->check($x, $y)){
continue;
}

/** @var int $M_TYPE */
$color = $this->moduleValues[$M_TYPE];

Expand All @@ -109,7 +121,7 @@ public function dump(string $file = null){
$prevColor = $color;
}

$fpdf->Rect($x * $this->scale, $y * $this->scale, 1 * $this->scale, 1 * $this->scale, 'F');
$fpdf->Rect($x * $this->scale, $y * $this->scale, $this->scale, $this->scale, 'F');
}

}
Expand Down

0 comments on commit 00f47b4

Please sign in to comment.