@@ -48,18 +48,27 @@ class PDF extends Fpdi {
48
48
49
49
private $ pageStarted = false ;
50
50
private $ pageEnded = false ;
51
+ private $ usedTemplateId = null ;
51
52
52
53
/**
53
54
* Overridden to set the template on the page
54
- * TODO check if this is still necessary, if useTemplate is called in PDFTemplate::output() now
55
55
*/
56
56
public function Header () {
57
57
parent ::Header ();
58
- if ($ this ->currentTemplateId ) {
59
- $ this ->useTemplate ($ this ->currentTemplateId );
58
+ if ($ this ->usedTemplateId ) {
59
+ $ this ->useTemplate ($ this ->usedTemplateId );
60
60
}
61
61
}
62
62
63
+ /**
64
+ * Overridden to set the template id
65
+ * @param $templateId
66
+ */
67
+ public function useTemplate ($ tpl , $ x =0 , $ y =0 , $ width =null , $ height =null , $ adjustPageSize =false ) {
68
+ parent ::useTemplate ($ tpl );
69
+ $ this ->usedTemplateId = $ tpl ;
70
+ }
71
+
63
72
/**
64
73
* Call this method when rendering a new page
65
74
*/
@@ -148,6 +157,106 @@ public function UnsetClipping() {
148
157
$ this ->_out ('Q ' );
149
158
}
150
159
160
+ /**
161
+ * The following code is taken from FPDF Add-On 'Transformations'
162
+ * @see http://fpdf.de/Addon-79-transformations.html
163
+ */
164
+
165
+ /**
166
+ * Start a transformation (Scale, Translate, Rotate calls follow)
167
+ */
168
+ public function StartTransform () {
169
+ // save the current graphic state
170
+ $ this ->_out ('q ' );
171
+ }
172
+
173
+ /**
174
+ * Scale the following content
175
+ * @param $s_x
176
+ * @param $s_y
177
+ * @param $x
178
+ * @param $y
179
+ */
180
+ public function Scale ($ s_x , $ s_y , $ x ='' , $ y ='' ) {
181
+ if ($ x === '' ) {
182
+ $ x = $ this ->x ;
183
+ }
184
+ if ($ y === '' ) {
185
+ $ y = $ this ->y ;
186
+ }
187
+ if ($ s_x == 0 || $ s_y == 0 ) {
188
+ $ this ->Error ('Please use values unequal to zero for Scaling ' );
189
+ }
190
+ $ y = ($ this ->h -$ y )*$ this ->k ;
191
+ $ x *= $ this ->k ;
192
+ // calculate elements of transformation matrix
193
+ $ s_x /= 100 ;
194
+ $ s_y /= 100 ;
195
+ $ tm [0 ] = $ s_x ;
196
+ $ tm [1 ] = 0 ;
197
+ $ tm [2 ] = 0 ;
198
+ $ tm [3 ] = $ s_y ;
199
+ $ tm [4 ] = $ x *(1 -$ s_x );
200
+ $ tm [5 ] = $ y *(1 -$ s_y );
201
+ // scale the coordinate system
202
+ $ this ->Transform ($ tm );
203
+ }
204
+
205
+ /**
206
+ * Move the following content
207
+ * @param $t_x
208
+ * @param $t_y
209
+ */
210
+ public function Translate ($ t_x , $ t_y ) {
211
+ // calculate elements of transformation matrix
212
+ $ tm [0 ]=1 ;
213
+ $ tm [1 ]=0 ;
214
+ $ tm [2 ]=0 ;
215
+ $ tm [3 ]=1 ;
216
+ $ tm [4 ]=$ t_x *$ this ->k ;
217
+ $ tm [5 ]=-$ t_y *$ this ->k ;
218
+ // translate the coordinate system
219
+ $ this ->Transform ($ tm );
220
+ }
221
+
222
+ /**
223
+ * Rotate the following content
224
+ * @param $angle
225
+ * @param $x
226
+ * @param $y
227
+ */
228
+ public function Rotate ($ angle , $ x ='' , $ y ='' ) {
229
+ if ($ x === '' ) {
230
+ $ x = $ this ->x ;
231
+ }
232
+ if ($ y === '' ) {
233
+ $ y = $ this ->y ;
234
+ }
235
+ $ y = ($ this ->h -$ y )*$ this ->k ;
236
+ $ x *= $ this ->k ;
237
+ // calculate elements of transformation matrix
238
+ $ tm [0 ] = cos (deg2rad ($ angle ));
239
+ $ tm [1 ] = sin (deg2rad ($ angle ));
240
+ $ tm [2 ] = -$ tm [1 ];
241
+ $ tm [3 ] = $ tm [0 ];
242
+ $ tm [4 ] = $ x +$ tm [1 ]*$ y -$ tm [0 ]*$ x ;
243
+ $ tm [5 ] = $ y -$ tm [0 ]*$ y -$ tm [1 ]*$ x ;
244
+ // rotate the coordinate system around ($x,$y)
245
+ $ this ->Transform ($ tm );
246
+ }
247
+
248
+ private function Transform ($ tm ) {
249
+ $ this ->_out (sprintf ('%.3F %.3F %.3F %.3F %.3F %.3F cm ' , $ tm [0 ], $ tm [1 ], $ tm [2 ], $ tm [3 ], $ tm [4 ], $ tm [5 ]));
250
+ }
251
+
252
+ /**
253
+ * End a transformation
254
+ */
255
+ function StopTransform () {
256
+ // restore previous graphic state
257
+ $ this ->_out ('Q ' );
258
+ }
259
+
151
260
/**
152
261
* The following code is taken from FPDF Add-On 'Table with MultiCells'
153
262
* @see http://fpdf.de/Addon-3-table-with-multicells.html
0 commit comments