-
Notifications
You must be signed in to change notification settings - Fork 0
/
anwesenheitsliste-helper.php
273 lines (232 loc) · 9.68 KB
/
anwesenheitsliste-helper.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<?php
require_once('tfpdf/tfpdf.php');
class PDF extends tFPDF
{
protected $columnss = array(); // array of columns anchors
protected $textprops = array(); // array of text anchors
protected $template = 1; // current template number
protected $flag_template = -1; // flag pointing at current template number - if <= 0, regular FPDF processing
protected $templates = array(); // array containing templates
protected $max_cols = 20; // maximum number of columns width for a column anchor
// -----------------------------------------------------
function LoadTemplate(): int
{
setlocale(LC_TIME, 'de_DE');
date_default_timezone_set('Europe/Berlin');
$footer_left = "PSV Herford Badminton: Herford, " . date("d.m.Y H:i");
$lines = array(
"SetDrawColor (64, 64, 64);",
"SetFillColor (200, 255, 160);",
"SetLineWidth (0.5);",
"Line (10, 280, 410, 280);",
"SetFont (\"DejaVu\", \"\", 10);",
"Text (10, 290, \"$footer_left\");",
"SetTextProp (\"FOOTRNB2\", 398, 290, -1, -1, 0, 0, 0,\"DejaVu\", \"\", 9);",
"SetTextColor (0, 0, 0);",
"SetFont (\"DejaVu\", \"\", 24);",
"Text (180, 15,\"Anwesenheitsliste\");",
"SetColumns (\"COLSWDTH\", 122, 38, 167, 38, 38);",
"SetTextProp (\"ROW0COL0\", 5, 25, -1, 8, 0, 0, 0, \"DejaVu\", \"\", 11);",
"SetTextProp (\"ROW1COL0\", 5, 34, -1, 6, 0, 0, 0, \"DejaVu\", \"\", 9);"
);
$this->flag_template = $this->template;
$flag_page = false;
if ($this->page <= 0) {
$flag_page = true;
$this->page = 1; // simulate first page to get around basic FPDF error when no page yet exists
}
$this->templates[$this->template] = ""; // Set current template string to empty string
$num_line = 0;
foreach ($lines as $line) {
$num_line++;
$line = trim($line);
if (strlen($line) <= 0) {
continue;
}
$cc = substr($line, 0, 1);
if (($cc == ";") || ($cc == "*") || ($cc == "/")) {
continue;
} // Ignore comments
$pattern = "/([A-Za-z0-9\s]+)[(].*[)];/";
if (preg_match($pattern, $line, $regs)) {
$func = trim($regs[1]);
} else {
print (" ** Unrecognized instruction format at line $num_line\n");
print (" => $line\n");
continue;
}
switch ($func) {
case "SetTextProp":
$format = $func . " (\"%[^\"]%*c, %f, %f, %f, %f, %d, %d, %d, \"%[^\"]%*c, \"%[^\"]%*c, %f)";
$txtp = sscanf($line, $format);
$id_txtp = $txtp [0];
$this->textprops[$id_txtp] = array_combine(
array('px', 'py', 'ix', 'iy', 'fr', 'fg', 'fb', 'fam', 'sty', 'fsz'),
array_slice($txtp, 1));
break;
case "SetColumns":
for ($jj = 0; $jj < $this->max_cols; $jj++) {
if ($jj > 0) {
$format .= ",";
} else {
$format = "$func (\"%[^\"]%*c,";
}
$format .= "%f";
}
$format .= ")";
$colls = sscanf($line, $format);
$columns = array();
for ($jj = 0, $id_cols = $colls[0]; $jj < $this->max_cols; $jj++) {
$columns [$jj] = -1; // negative number if columns width is not specified
if (isset ($colls [$jj + 1])) {
$columns [$jj] = $colls[$jj + 1];
}
}
$this->columnss[$id_cols] = $columns;
break;
default:
if (method_exists($this, $func)) {
$bufr = "\$this->" . $line;
eval ($bufr);
} else {
print (" ** Unrecognized instruction <$func> at line $num_line\n");
}
break;
}
}
if ($flag_page) {
$this->page = 0; // reset Page number in case it has been forced to 1
$flag_page = false;
}
$ii = $this->template;
$this->template++;
$this->flag_template = -1;
return ($ii);
}
// -----------------------------------------------------
function IncludeTemplate($num_template)
{
$this->PageInfo[$this->page]['templates'][] = $num_template;
}
// -----------------------------------------------------
function ApplyTextProp($id_txtp, $text)
{
if (!isset ($this->textprops[$id_txtp])) {
print (" -- Warning: unknown text anchor [$id_txtp]\n");
return (false);
}
$txtp = $this->textprops[$id_txtp];
$this->SetFont($txtp['fam'], $txtp['sty'], $txtp['fsz']);
$this->SetTextColor($txtp['fr'], $txtp['fg'], $txtp['fb']);
$this->SetXY($txtp['px'], $txtp['py']);
if (strlen($text) > 0) {
$this->Text($txtp['px'], $txtp['py'], $text);
}
return ($txtp);
}
/* ------------------------------------------------------- */
function GetColls($id_cols)
{
if (!isset ($this->columnss[$id_cols])) {
print (" -- Warning: unknown column anchor '$id_cols]\n");
return (false);
}
return ($this->columnss[$id_cols]);
}
/* ------------------------------------------------------- */
function _puttemplates()
{
$nb = $this->template - 1;
if ($nb > 0) {
$this->obj_templates = array();
for ($n = 1; $n <= $nb; $n++) {
$this->_putstreamobject($this->templates[$n]);
$this->obj_templates [$n] = $this->n;
}
}
}
/* ------------------------------------------------------- */
protected function _putpage($n)
{
// ==============================================
// Part identical to original FPDF processing
// ==============================================
$this->_newobj();
$this->_put('<</Type /Page');
$this->_put('/Parent 1 0 R');
if (isset($this->PageInfo[$n]['size']))
$this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]', $this->PageInfo[$n]['size'][0], $this->PageInfo[$n]['size'][1]));
if (isset($this->PageInfo[$n]['rotation']))
$this->_put('/Rotate ' . $this->PageInfo[$n]['rotation']);
$this->_put('/Resources 2 0 R');
if (isset($this->PageLinks[$n])) {
// Links
$annots = '/Annots [';
foreach ($this->PageLinks[$n] as $pl) {
$rect = sprintf('%.2F %.2F %.2F %.2F', $pl[0], $pl[1], $pl[0] + $pl[2], $pl[1] - $pl[3]);
$annots .= '<</Type /Annot /Subtype /Link /Rect [' . $rect . '] /Border [0 0 0] ';
if (is_string($pl[4]))
$annots .= '/A <</S /URI /URI ' . $this->_textstring($pl[4]) . '>>>>';
else {
$l = $this->links[$pl[4]];
if (isset($this->PageInfo[$l[0]]['size']))
$h = $this->PageInfo[$l[0]]['size'][1];
else
$h = ($this->DefOrientation == 'P') ? $this->DefPageSize[1] * $this->k : $this->DefPageSize[0] * $this->k;
$annots .= sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>', $this->PageInfo[$l[0]]['n'], $h - $l[1] * $this->k);
}
}
$this->_put($annots . ']');
}
if ($this->WithAlpha)
$this->_put('/Group <</Type /Group /S /Transparency /CS /DeviceRGB>>');
// ========================================
// Part specific to templates extension
// ========================================
$str_templates = "";
$end_brckt = "";
if (count($this->PageInfo[$n]['templates']) > 0) {
$str_templates = "[";
$templates_num = $this->PageInfo[$n]['templates'];
foreach ($templates_num as $template_num) {
$str_templates .= $this->obj_templates[$template_num] . ' 0 R ';
}
$end_brckt = "]";
}
$this->_put('/Contents ' . $str_templates . ($this->n + 1) . ' 0 R' . "$end_brckt>>");
// ====================================
// Back to original FPDF processing
// ====================================
$this->_put('endobj');
// Page content
if (!empty($this->AliasNbPages))
$this->pages[$n] = str_replace($this->AliasNbPages, $this->page, $this->pages[$n]);
$this->_putstreamobject($this->pages[$n]);
}
/* ------------------------------------------------------- */
function _putpages()
{
$this->_puttemplates();
parent::_putpages();
}
/* ------------------------------------------------------- */
function _out($s)
{
if ($this->flag_template > 0) {
$this->templates[$this->template] .= $s . "\n";
} else {
parent::_out($s);
}
}
/* ------------------------------------------------------- */
function _beginpage($orientation, $size, $rotation)
{
parent::_beginpage($orientation, $size, $rotation);
$this->PageInfo[$this->page]['templates'] = array();
}
function checkPageBreak(): bool
{
return $this->GetY()+15>=$this->PageBreakTrigger;
}
}
?>