29
29
*/
30
30
class RoundQuietzoneSVGoutput extends QRMarkupSVG{
31
31
32
+ protected float $ center ;
33
+
32
34
/**
33
35
* @inheritDoc
34
36
*/
@@ -42,13 +44,13 @@ protected function createMarkup(bool $saveToFile):string{
42
44
// update the matrix dimensions to avoid errors in subsequent calculations
43
45
// the moduleCount is now QR Code matrix + 2x quiet zone
44
46
$ this ->setMatrixDimensions ();
45
- // color the quiet zone
46
- $ this ->colorQuietzone ($ quietzoneSize , ($ diameter / 2 ));
47
-
47
+ $ this ->center = ($ this ->moduleCount / 2 );
48
48
// calculate the logo space
49
49
$ logoSpaceSize = (int )(ceil ($ this ->moduleCount * $ this ->options ->svgLogoScale ) + 1 );
50
50
// we're calling QRMatrix::setLogoSpace() manually, so QROptions::$addLogoSpace has no effect here
51
51
$ this ->matrix ->setLogoSpace ($ logoSpaceSize );
52
+ // color the quiet zone
53
+ $ this ->colorQuietzone ($ quietzoneSize , ($ diameter / 2 ));
52
54
53
55
// start SVG output
54
56
$ svg = $ this ->header ();
@@ -64,11 +66,6 @@ protected function createMarkup(bool $saveToFile):string{
64
66
// close svg
65
67
$ svg .= sprintf ('%1$s</svg>%1$s ' , $ this ->options ->eol );
66
68
67
- // transform to data URI only when not saving to file
68
- if (!$ saveToFile && $ this ->options ->outputBase64 ){
69
- $ svg = $ this ->toBase64DataURI ($ svg , 'image/svg+xml ' );
70
- }
71
-
72
69
return $ svg ;
73
70
}
74
71
@@ -109,7 +106,7 @@ protected function colorQuietzone(int $quietzoneSize, float $radius):void{
109
106
110
107
// we need to add 0.5 units to the check values since we're calculating the element centers
111
108
// ($x/$y is the element's assumed top left corner)
112
- if ($ this ->checkIfInsideCircle (($ x + 0.5 ), ($ y + 0.5 ), $ r )){
109
+ if ($ this ->checkIfInsideCircle (($ x + 0.5 ), ($ y + 0.5 ), $ this -> center , $ this -> center , $ r )){
113
110
$ this ->matrix ->set ($ x , $ y , (bool )rand (0 , 1 ), QRMatrix::M_QUIETZONE );
114
111
}
115
112
}
@@ -120,9 +117,9 @@ protected function colorQuietzone(int $quietzoneSize, float $radius):void{
120
117
/**
121
118
* @see https://stackoverflow.com/a/7227057
122
119
*/
123
- protected function checkIfInsideCircle (float $ x , float $ y , float $ radius ):bool {
124
- $ dx = abs ($ x - $ this -> moduleCount / 2 );
125
- $ dy = abs ($ y - $ this -> moduleCount / 2 );
120
+ protected function checkIfInsideCircle (float $ x , float $ y , float $ centerX , float $ centerY , float $ radius ):bool {
121
+ $ dx = abs ($ x - $ centerX );
122
+ $ dy = abs ($ y - $ centerY );
126
123
127
124
if (($ dx + $ dy ) <= $ radius ){
128
125
return true ;
@@ -132,11 +129,7 @@ protected function checkIfInsideCircle(float $x, float $y, float $radius):bool{
132
129
return false ;
133
130
}
134
131
135
- if ((pow ($ dx , 2 ) + pow ($ dy , 2 )) <= pow ($ radius , 2 )){
136
- return true ;
137
- }
138
-
139
- return false ;
132
+ return (pow ($ dx , 2 ) + pow ($ dy , 2 )) <= pow ($ radius , 2 );
140
133
}
141
134
142
135
/**
@@ -145,7 +138,7 @@ protected function checkIfInsideCircle(float $x, float $y, float $radius):bool{
145
138
protected function addCircle (float $ radius ):string {
146
139
return sprintf (
147
140
'%4$s<circle id="circle" cx="%1$s" cy="%1$s" r="%2$s" stroke-width="%3$s"/> ' ,
148
- ( $ this ->moduleCount / 2 ) ,
141
+ $ this ->center ,
149
142
round ($ radius , 5 ),
150
143
($ this ->options ->circleRadius * 2 ),
151
144
$ this ->options ->eol
@@ -194,7 +187,7 @@ protected function collectModules(Closure $transform):array{
194
187
// randomly assign another $M_TYPE_LAYER for the given types
195
188
// note that the layer id has to be an integer value,
196
189
// ideally outside the several bitmask values
197
- if ($ M_TYPE_LAYER === QRMatrix::M_DATA_DARK ){
190
+ if ($ M_TYPE_LAYER === QRMatrix::M_QUIETZONE_DARK ){
198
191
$ M_TYPE_LAYER = array_rand ($ dotColors );
199
192
}
200
193
@@ -329,11 +322,8 @@ protected function set_svgLogoScale(float $svgLogoScale):void{
329
322
$ options ->outputInterface = RoundQuietzoneSVGoutput::class; // load our own output class
330
323
$ options ->drawLightModules = false ; // set to true to add the light modules
331
324
// common SVG options
332
- # $options->connectPaths = true; // this has been set to "always on" internally
325
+ $ options ->connectPaths = true ;
333
326
$ options ->excludeFromConnect = [
334
- QRMatrix::M_FINDER_DARK ,
335
- QRMatrix::M_FINDER_DOT ,
336
- QRMatrix::M_ALIGNMENT_DARK ,
337
327
QRMatrix::M_QUIETZONE_DARK ,
338
328
];
339
329
$ options ->drawCircularModules = true ;
0 commit comments