Skip to content

Commit dfb7728

Browse files
committed
:octocat: removed QROptionsTrait::$markupDark and QROptionsTrait::$markupLight, added QROptionsTrait::$svgUseFillAttributes
1 parent 07eb6e3 commit dfb7728

10 files changed

+82
-89
lines changed

examples/authenticator.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,29 @@
2626
*
2727
* @see https://github.com/chillerlan/php-authenticator
2828
*/
29-
$options->mode = AuthenticatorInterface::TOTP;
30-
$options->digits = 8;
31-
$options->algorithm = AuthenticatorInterface::ALGO_SHA512;
29+
$options->mode = AuthenticatorInterface::TOTP;
30+
$options->digits = 8;
31+
$options->algorithm = AuthenticatorInterface::ALGO_SHA512;
3232

3333
/*
3434
* QROptionsTrait
3535
*/
36-
$options->version = 7;
37-
$options->addQuietzone = false;
38-
$options->outputBase64 = false;
39-
$options->svgAddXmlHeader = false;
40-
$options->cssClass = 'my-qrcode';
41-
$options->drawLightModules = false;
42-
$options->markupDark = '';
43-
$options->markupLight = '';
44-
$options->drawCircularModules = true;
45-
$options->circleRadius = 0.4;
46-
$options->connectPaths = true;
47-
$options->keepAsSquare = [
36+
$options->version = 7;
37+
$options->addQuietzone = false;
38+
$options->outputBase64 = false;
39+
$options->svgAddXmlHeader = false;
40+
$options->cssClass = 'my-qrcode';
41+
$options->drawLightModules = false;
42+
$options->svgUseFillAttributes = false;
43+
$options->drawCircularModules = true;
44+
$options->circleRadius = 0.4;
45+
$options->connectPaths = true;
46+
$options->keepAsSquare = [
4847
QRMatrix::M_FINDER_DARK,
4948
QRMatrix::M_FINDER_DOT,
5049
QRMatrix::M_ALIGNMENT_DARK,
5150
];
52-
$options->svgDefs = '
51+
$options->svgDefs = '
5352
<linearGradient id="gradient" x1="1" y2="1">
5453
<stop id="stop1" offset="0" />
5554
<stop id="stop2" offset="0.5"/>

examples/html.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
$options->version = 5;
2020
$options->outputType = QROutputInterface::MARKUP_HTML;
2121
$options->cssClass = 'qrcode';
22-
$options->markupDark = '#555';
23-
$options->markupLight = '#CCC';
2422
$options->moduleValues = [
2523
// finder
2624
QRMatrix::M_FINDER_DARK => '#A71111', // dark (true)

examples/imagickConvertSVGtoPNG.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,23 @@ public function dump(string $file = null):string{
8484
// SVG from the basic example
8585
$options = new QROptions;
8686

87-
$options->version = 7;
88-
$options->outputType = QROutputInterface::CUSTOM;
89-
$options->outputInterface = SVGConvert::class;
90-
$options->imagickFormat = 'png32';
91-
$options->scale = 20;
92-
$options->outputBase64 = false;
93-
$options->drawLightModules = true;
94-
$options->markupDark = '';
95-
$options->markupLight = '';
96-
$options->drawCircularModules = true;
97-
$options->circleRadius = 0.4;
98-
$options->connectPaths = true;
99-
$options->keepAsSquare = [
87+
$options->version = 7;
88+
$options->outputType = QROutputInterface::CUSTOM;
89+
$options->outputInterface = SVGConvert::class;
90+
$options->imagickFormat = 'png32';
91+
$options->scale = 20;
92+
$options->outputBase64 = false;
93+
$options->drawLightModules = true;
94+
$options->svgUseFillAttributes = false;
95+
$options->drawCircularModules = true;
96+
$options->circleRadius = 0.4;
97+
$options->connectPaths = true;
98+
$options->keepAsSquare = [
10099
QRMatrix::M_FINDER_DARK,
101100
QRMatrix::M_FINDER_DOT,
102101
QRMatrix::M_ALIGNMENT_DARK,
103102
];
104-
$options->svgDefs = '
103+
$options->svgDefs = '
105104
<linearGradient id="rainbow" x1="1" y2="1">
106105
<stop stop-color="#e2453c" offset="0"/>
107106
<stop stop-color="#e07e39" offset="0.2"/>

examples/imagickImageAsBackground.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919

2020
class QRImagickImageAsBackground extends QRImagick{
2121

22+
/**
23+
* @inheritDoc
24+
*/
25+
protected function getDefaultModuleValue(bool $isDark):ImagickPixel{
26+
// RGBA, adjust opacity to increase contrast
27+
return $this->prepareModuleValue(($isDark) ? '#00000040' : '#ffffffa0');
28+
}
29+
2230
/**
2331
* @inheritDoc
2432
*/
@@ -81,18 +89,17 @@ protected function set_background(string $background):void{
8189

8290
$options = new ImageAsBackgroundOptions;
8391

84-
$options->background = __DIR__.'/background.jpg'; // setting from the augmented options
85-
$options->version = 5;
86-
$options->outputType = QROutputInterface::CUSTOM;
87-
$options->outputInterface = QRImagickImageAsBackground::class; // use the custom output class
88-
$options->eccLevel = EccLevel::H;
89-
$options->outputBase64 = false;
90-
$options->scale = 10;
91-
$options->drawLightModules = true;
92-
$options->markupDark = '#00000040'; // RGBA, adjust opacity to increase contrast
93-
$options->markupLight = '#ffffffa0';
94-
$options->invertMatrix = false;
95-
$options->quietzoneSize = 1;
92+
$options->background = __DIR__.'/background.jpg'; // setting from the augmented options
93+
$options->version = 5;
94+
$options->outputType = QROutputInterface::CUSTOM;
95+
$options->outputInterface = QRImagickImageAsBackground::class; // use the custom output class
96+
$options->eccLevel = EccLevel::H;
97+
$options->outputBase64 = false;
98+
$options->scale = 10;
99+
$options->drawLightModules = true;
100+
$options->svgUseFillAttributes = false;
101+
$options->invertMatrix = false;
102+
$options->quietzoneSize = 1;
96103

97104

98105
// dump the output, with an additional logo

examples/svg.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,19 @@
1818

1919
$options = new QROptions;
2020

21-
$options->version = 7;
22-
$options->outputType = QROutputInterface::MARKUP_SVG;
23-
$options->outputBase64 = false;
21+
$options->version = 7;
22+
$options->outputType = QROutputInterface::MARKUP_SVG;
23+
$options->outputBase64 = false;
2424
// if set to false, the light modules won't be rendered
25-
$options->drawLightModules = true;
26-
// empty the default value to remove the fill* and opacity* attributes from the <path> elements
27-
$options->markupDark = '';
28-
$options->markupLight = '';
25+
$options->drawLightModules = true;
26+
$options->svgUseFillAttributes = false;
2927
// draw the modules as circles isntead of squares
30-
$options->drawCircularModules = true;
31-
$options->circleRadius = 0.4;
28+
$options->drawCircularModules = true;
29+
$options->circleRadius = 0.4;
3230
// connect paths
33-
$options->connectPaths = true;
31+
$options->connectPaths = true;
3432
// keep modules of these types as square
35-
$options->keepAsSquare = [
33+
$options->keepAsSquare = [
3634
QRMatrix::M_FINDER_DARK,
3735
QRMatrix::M_FINDER_DOT,
3836
QRMatrix::M_ALIGNMENT_DARK,
@@ -58,7 +56,6 @@
5856
}
5957
catch(Throwable $e){
6058
// handle the exception in whatever way you need
61-
6259
exit($e->getMessage());
6360
}
6461

examples/svgConvertViaCanvas.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,17 @@
1818

1919
$options = new QROptions;
2020

21-
$options->version = 7;
22-
$options->outputType = QROutputInterface::MARKUP_SVG;
23-
$options->outputBase64 = false;
24-
$options->svgAddXmlHeader = false;
25-
$options->drawLightModules = false;
26-
$options->markupDark = '';
27-
$options->markupLight = '';
28-
$options->drawCircularModules = true;
29-
$options->circleRadius = 0.4;
30-
$options->connectPaths = true;
21+
$options->version = 7;
22+
$options->outputType = QROutputInterface::MARKUP_SVG;
23+
$options->outputBase64 = false;
24+
$options->svgAddXmlHeader = false;
25+
$options->svgUseFillAttributes = false;
26+
$options->drawLightModules = false;
27+
$options->drawCircularModules = true;
28+
$options->circleRadius = 0.4;
29+
$options->connectPaths = true;
3130

32-
$options->keepAsSquare = [
31+
$options->keepAsSquare = [
3332
QRMatrix::M_FINDER_DARK,
3433
QRMatrix::M_FINDER_DOT,
3534
QRMatrix::M_ALIGNMENT_DARK,

src/Output/QRImagick.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ protected function prepareModuleValue($value):ImagickPixel{
106106
* @inheritDoc
107107
*/
108108
protected function getDefaultModuleValue(bool $isDark):ImagickPixel{
109-
return $this->prepareModuleValue(($isDark) ? $this->options->markupDark : $this->options->markupLight);
109+
return $this->prepareModuleValue(($isDark) ? '#000' : '#fff');
110110
}
111111

112112
/**

src/Output/QRMarkup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected function prepareModuleValue($value):string{
6565
* @inheritDoc
6666
*/
6767
protected function getDefaultModuleValue(bool $isDark):string{
68-
return ($isDark) ? $this->options->markupDark : $this->options->markupLight;
68+
return ($isDark) ? '#000' : '#fff';
6969
}
7070

7171
/**

src/Output/QRMarkupSVG.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ protected function paths():string{
145145
* @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/path
146146
*/
147147
protected function path(string $path, int $M_TYPE):string{
148+
149+
if($this->options->svgUseFillAttributes){
150+
return sprintf(
151+
'<path class="%s" fill="%s" d="%s"/>',
152+
$this->getCssClass($M_TYPE),
153+
$this->getModuleValue($M_TYPE),
154+
$path
155+
);
156+
}
157+
148158
return sprintf('<path class="%s" d="%s"/>', $this->getCssClass($M_TYPE), $path);
149159
}
150160

src/QROptionsTrait.php

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -362,17 +362,6 @@ trait QROptionsTrait{
362362
*/
363363
protected string $cssClass = 'qrcode';
364364

365-
/**
366-
* Markup substitute for dark (CSS value)
367-
*/
368-
protected string $markupDark = '#000';
369-
370-
/**
371-
* Markup substitute for light (CSS value)
372-
*/
373-
protected string $markupLight = '#fff';
374-
375-
376365
/*
377366
* QRMarkupSVG settings
378367
*/
@@ -384,15 +373,6 @@ trait QROptionsTrait{
384373
*/
385374
protected bool $svgAddXmlHeader = true;
386375

387-
/**
388-
* SVG path opacity
389-
*
390-
* Sets the value for the SVG "fill-opacity" on a `<path>` element. Only in effect when non-empty values
391-
* for `QROptions::$markupDark` and `QROptions::$markupLight` are given.
392-
* The opacity value is the same for all paths - please use CSS for more sophisticated implementations.
393-
*/
394-
protected float $svgOpacity = 1.0;
395-
396376
/**
397377
* Anything in the SVG `<defs>` tag
398378
*
@@ -420,6 +400,10 @@ trait QROptionsTrait{
420400
*/
421401
protected string $svgPreserveAspectRatio = 'xMidYMid';
422402

403+
/**
404+
* Whether to use the SVG `fill` attributes and set them with the given module values
405+
*/
406+
protected bool $svgUseFillAttributes = true;
423407

424408
/*
425409
* QRString settings

0 commit comments

Comments
 (0)