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

Allow CMYK colors in Mpdf Output #12

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/Output/Mpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ class Mpdf
* @param float $x position X
* @param float $y position Y
* @param float $w QR code width
* @param int[] $background RGB background color
* @param int[] $color RGB foreground and border color
* @param int[] $background RGB/CMYK background color
* @param int[] $color RGB/CMYK foreground and border color
*/
public function output(QrCode $qrCode, MpdfObject $mpdf, $x, $y, $w, $background = [255, 255, 255], $color = [0, 0, 0])
{
$size = $w;
$qrSize = $qrCode->getQrSize();
$s = $size / $qrCode->getQrDimensions();

$mpdf->SetDrawColor($color[0], $color[1], $color[2]);
$mpdf->SetFillColor($background[0], $background[1], $background[2]);
$background = array_slice($background, 0, 4);
$color = array_slice($color, 0, 4);

$mpdf->SetDrawColor(...$color);
$mpdf->SetFillColor(...$background);

if ($qrCode->isBorderDisabled()) {
$minSize = 4;
Expand All @@ -38,7 +41,7 @@ public function output(QrCode $qrCode, MpdfObject $mpdf, $x, $y, $w, $background
$mpdf->Rect($x, $y, $size, $size, 'FD');
}

$mpdf->SetFillColor($color[0], $color[1], $color[2]);
$mpdf->SetFillColor(...$color);

$final = $qrCode->getFinal();

Expand Down
18 changes: 18 additions & 0 deletions tests/QrCode/Output/MpdfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ public function testOutputQDisableBorder()
$output->output($code, $mpdf, 0, 0, 0);
}

public function testOutputCMYK()
{
$color = [1,2,3,4];
$background = [5,6,7,8];

$code = new QrCode('LOREM IPSUM 2019', QrCode::ERROR_CORRECTION_QUARTILE);

$mpdf = Mockery::mock('Mpdf\Mpdf');

$mpdf->shouldReceive('SetDrawColor')->with(1,2,3,4)->once();
$mpdf->shouldReceive('SetFillColor')->with(1,2,3,4)->once();
$mpdf->shouldReceive('SetFillColor')->with(5,6,7,8)->once();
$mpdf->shouldReceive('Rect')->times(217);

$output = new Mpdf();
$output->output($code, $mpdf, 0, 0, 0, $background, $color);
}

protected function tear_down()
{
parent::tear_down();
Expand Down