-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathQRsvgOutput.php
169 lines (123 loc) · 4.52 KB
/
QRsvgOutput.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
/*
* PHP QR Code encoder
*
* SVG output support
*
* Based on libqrencode C library distributed under LGPL 2.1
* Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <[email protected]>
*
* PHP QR Code is distributed under LGPL 3
* Copyright (C) 2010-2013 Dominik Dzienia <deltalab at poczta dot fm>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/** @addtogroup OutputGroup */
/** @{ */
class QRsvgOutput extends QRarea {
public function __construct($source_tab)
{
parent::__construct($source_tab);
}
//----------------------------------------------------------------------
public function mapX($px)
{
return $px;
}
//----------------------------------------------------------------------
public function mapY($py)
{
return $py;
}
//----------------------------------------------------------------------
public function getRawSvg()
{
$lib = array();
$svg = array();
$aggregate_paths = array();
foreach ($this->paths as $path) {
switch ($path[0]) {
case QR_AREA_PATH:
$pNum = 0;
foreach($path[1] as $pathDetails) {
$px = array_shift($pathDetails);
$py = array_shift($pathDetails);
$rle_steps = array_shift($pathDetails);
$aggregate_add = 'M'.$px.','.$py.' ';
while(count($rle_steps) > 0) {
$delta = 1;
$operator = array_shift($rle_steps);
if (($operator != 'R') && ($operator != 'L') && ($operator != 'T') && ($operator != 'B')) {
$delta = (int)$operator;
$operator = array_shift($rle_steps);
}
if ($operator == 'R') $aggregate_add .= 'h'.$delta;
if ($operator == 'L') $aggregate_add .= 'h-'.$delta;
if ($operator == 'T') $aggregate_add .= 'v-'.$delta;
if ($operator == 'B') $aggregate_add .= 'v'.$delta;
}
$aggregate_paths[] = $aggregate_add;
$pNum++;
}
break;
case QR_AREA_POINT:
$symb = array_shift($path);
while(count($path) > 0) {
$px = array_shift($path);
$py = array_shift($path);
$aggregate_paths[] = 'M'.$px.','.$py.' v1h1v-1h-1';
}
break;
case QR_AREA_RECT:
$symb = array_shift($path);
while(count($path) > 0) {
$px = array_shift($path);
$py = array_shift($path);
$ex = array_shift($path);
$ey = array_shift($path);
$w = $ex-$px;
$h = $ey-$py;
$aggregate_paths[] = 'M'.$px.','.$py.' h'.$w.'v'.$h.'h-'.$w.'v-'.$h;
}
break;
case QR_AREA_LSHAPE:
$symb = array_shift($path);
$l_shapes[0] = 'm1,0h1v2h-2v-1h1z';
$l_shapes[1] = 'h1v1h1v1h-2z';
$l_shapes[2] = 'h2v2h-1v-1h-1z';
$l_shapes[3] = 'h2v1h-1v1h-1z';
while(count($path) > 0) {
$px = array_shift($path);
$py = array_shift($path);
$mode = (int)array_shift($path);
$aggregate_paths[] = 'M'.$px.','.$py.' '.$l_shapes[$mode];
}
break;
case QR_AREA_TRACKER:
if (!isset($lib['tracker'])) {
$lib['tracker'] = '<symbol id="tracker"><path d="m 0 7 0 7 7 0 0 -7 -7 0 z m 1 1 5 0 0 5 -5 0 0 -5 z m 1 1 0 3 3 0 0 -3 -3 0 z" style="fill:#000000;stroke:none"></path></symbol>';
}
$symb = array_shift($path);
$px = array_shift($path);
$py = array_shift($path);
$svg[] = '<use x="'.$px.'" y="'.($py-7).'" xlink:href="#tracker"></use>';
break;
}
}
$svg[] = '<path d="'.join(' ', $aggregate_paths).'" style="fill:#000000;stroke:none" ></path>';
return join("\n", $lib)."\n".join("\n", $svg);
}
}
/** @} */