Changeset 19716 for branches/version-2_5-dev/data/module/fpdf/fpdf_tpl.php
- Timestamp:
- 2010/12/11 12:15:20 (12 years ago)
- Location:
- branches/version-2_5-dev/data/module/fpdf
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_5-dev/data/module/fpdf/fpdf_tpl.php
r18701 r19716 1 1 <?php 2 2 // 3 // FPDF_TPL - Version 1. 1.14 // 5 // Copyright 2004-20 07Setasign - Jan Slabon3 // FPDF_TPL - Version 1.2 4 // 5 // Copyright 2004-2010 Setasign - Jan Slabon 6 6 // 7 7 // Licensed under the Apache License, Version 2.0 (the "License"); … … 18 18 // 19 19 20 require_once("fpdf.php");21 22 20 class FPDF_TPL extends FPDF { 23 21 /** … … 52 50 53 51 /** 54 * Constructor 55 * See FPDF-Documentation 56 * @param string $orientation 57 * @param string $unit 58 * @param mixed $format 59 */ 60 function fpdf_tpl($orientation='P',$unit='mm',$format='A4') { 61 parent::fpdf($orientation,$unit,$format); 62 } 52 * Last used Template data 53 * 54 * @var array 55 */ 56 var $lastUsedTemplateData = array(); 63 57 64 58 /** … … 80 74 * @return int The ID of new created Template 81 75 */ 82 function beginTemplate($x=null,$y=null,$w=null,$h=null) { 76 function beginTemplate($x = null, $y = null, $w = null, $h = null) { 77 if (is_subclass_of($this, 'TCPDF')) { 78 $this->Error('This method is only usable with FPDF. Use TCPDF methods startTemplate() instead.'); 79 return; 80 } 81 83 82 if ($this->page <= 0) 84 83 $this->error("You have to add a page to fpdf first!"); … … 120 119 121 120 $this->_intpl = true; 122 $this->SetXY($x +$this->lMargin,$y+$this->tMargin);123 $this->SetRightMargin($this->w -$w+$this->rMargin);121 $this->SetXY($x + $this->lMargin, $y + $this->tMargin); 122 $this->SetRightMargin($this->w - $w + $this->rMargin); 124 123 125 124 return $this->tpl; … … 134 133 */ 135 134 function endTemplate() { 135 if (is_subclass_of($this, 'TCPDF')) { 136 $args = func_get_args(); 137 return call_user_func_array(array($this, 'TCPDF::endTemplate'), $args); 138 } 139 136 140 if ($this->_intpl) { 137 141 $this->_intpl = false; … … 168 172 * @retrun array The height and width of the template 169 173 */ 170 function useTemplate($tplidx, $_x =null, $_y=null, $_w=0, $_h=0) {174 function useTemplate($tplidx, $_x = null, $_y = null, $_w = 0, $_h = 0) { 171 175 if ($this->page <= 0) 172 $this->error("You have to add a page to fpdf first!");173 176 $this->error('You have to add a page first!'); 177 174 178 if (!isset($this->tpls[$tplidx])) 175 $this->error( "Template does not exist!");179 $this->error('Template does not exist!'); 176 180 177 181 if ($this->_intpl) { … … 180 184 181 185 $tpl =& $this->tpls[$tplidx]; 182 $x = $tpl['x'];183 $y = $tpl['y'];184 186 $w = $tpl['w']; 185 187 $h = $tpl['h']; 186 188 187 189 if ($_x == null) 188 $_x = $x;190 $_x = 0; 189 191 if ($_y == null) 190 $_y = $y; 191 $wh = $this->getTemplateSize($tplidx,$_w,$_h); 192 $_y = 0; 193 194 $_x += $tpl['x']; 195 $_y += $tpl['y']; 196 197 $wh = $this->getTemplateSize($tplidx, $_w, $_h); 192 198 $_w = $wh['w']; 193 199 $_h = $wh['h']; 194 200 195 $this->_out(sprintf("q %.4f 0 0 %.4f %.2f %.2f cm", ($_w/$w), ($_h/$h), $_x*$this->k, ($this->h-($_y+$_h))*$this->k)); // Translate 196 $this->_out($this->tplprefix.$tplidx." Do Q"); 197 198 return array("w" => $_w, "h" => $_h); 201 $tData = array( 202 'x' => $this->x, 203 'y' => $this->y, 204 'w' => $_w, 205 'h' => $_h, 206 'scaleX' => ($_w / $w), 207 'scaleY' => ($_h / $h), 208 'tx' => $_x, 209 'ty' => ($this->h - $_y - $_h), 210 'lty' => ($this->h - $_y - $_h) - ($this->h - $h) * ($_h / $h) 211 ); 212 213 $this->_out(sprintf('q %.4F 0 0 %.4F %.4F %.4F cm', $tData['scaleX'], $tData['scaleY'], $tData['tx'] * $this->k, $tData['ty'] * $this->k)); // Translate 214 $this->_out(sprintf('%s%d Do Q', $this->tplprefix, $tplidx)); 215 216 // reset font in the outer graphic state 217 if ($this->FontFamily) { 218 $family = $this->FontFamily; 219 $this->FontFamily = ''; 220 $this->SetFont($family); 221 } 222 223 $this->lastUsedTemplateData = $tData; 224 225 return array('w' => $_w, 'h' => $_h); 199 226 } 200 227 … … 209 236 * @return array The height and width of the template 210 237 */ 211 function getTemplateSize($tplidx, $_w =0, $_h=0) {238 function getTemplateSize($tplidx, $_w = 0, $_h = 0) { 212 239 if (!$this->tpls[$tplidx]) 213 240 return false; … … 222 249 } 223 250 224 if($_w ==0)225 $_w =$_h*$w/$h;226 if($_h ==0)227 $_h =$_w*$h/$w;251 if($_w == 0) 252 $_w = $_h * $w / $h; 253 if($_h == 0) 254 $_h = $_w * $h / $w; 228 255 229 256 return array("w" => $_w, "h" => $_h); … … 231 258 232 259 /** 233 * See FPDF-Documentation ;-) 234 */ 235 function SetFont($family,$style='',$size=0) { 260 * See FPDF/TCPDF-Documentation ;-) 261 */ 262 public function SetFont($family, $style = '', $size = 0) { 263 if (is_subclass_of($this, 'TCPDF')) { 264 $args = func_get_args(); 265 return call_user_func_array(array($this, 'TCPDF::SetFont'), $args); 266 } 267 236 268 /** 237 269 * force the resetting of font changes in a template … … 242 274 parent::SetFont($family, $style, $size); 243 275 244 $fontkey = $this->FontFamily .$this->FontStyle;276 $fontkey = $this->FontFamily . $this->FontStyle; 245 277 246 278 if ($this->_intpl) { … … 252 284 253 285 /** 254 * See FPDF-Documentation ;-) 255 */ 256 function Image($file,$x,$y,$w=0,$h=0,$type='',$link='') { 257 parent::Image($file,$x,$y,$w,$h,$type,$link); 286 * See FPDF/TCPDF-Documentation ;-) 287 */ 288 function Image($file, $x = null, $y = null, $w = 0, $h = 0, $type = '', $link = '') { 289 if (is_subclass_of($this, 'TCPDF')) { 290 $args = func_get_args(); 291 return call_user_func_array(array($this, 'TCPDF::Image'), $args); 292 } 293 294 $ret = parent::Image($file, $x, $y, $w, $h, $type, $link); 258 295 if ($this->_intpl) { 259 296 $this->_res['tpl'][$this->tpl]['images'][$file] =& $this->images[$file]; … … 261 298 $this->_res['page'][$this->page]['images'][$file] =& $this->images[$file]; 262 299 } 300 301 return $ret; 263 302 } 264 303 … … 268 307 * AddPage is not available when you're "in" a template. 269 308 */ 270 function AddPage($orientation='') { 309 function AddPage($orientation = '', $format = '') { 310 if (is_subclass_of($this, 'TCPDF')) { 311 $args = func_get_args(); 312 return call_user_func_array(array($this, 'TCPDF::AddPage'), $args); 313 } 314 271 315 if ($this->_intpl) 272 316 $this->Error('Adding pages in templates isn\'t possible!'); 273 parent::AddPage($orientation); 317 318 parent::AddPage($orientation, $format); 274 319 } 275 320 … … 277 322 * Preserve adding Links in Templates ...won't work 278 323 */ 279 function Link($x,$y,$w,$h,$link) { 324 function Link($x, $y, $w, $h, $link) { 325 if (is_subclass_of($this, 'TCPDF')) { 326 $args = func_get_args(); 327 return call_user_func_array(array($this, 'TCPDF::Link'), $args); 328 } 329 280 330 if ($this->_intpl) 281 331 $this->Error('Using links in templates aren\'t possible!'); 282 parent::Link($x,$y,$w,$h,$link); 332 333 parent::Link($x, $y, $w, $h, $link); 283 334 } 284 335 285 336 function AddLink() { 337 if (is_subclass_of($this, 'TCPDF')) { 338 $args = func_get_args(); 339 return call_user_func_array(array($this, 'TCPDF::AddLink'), $args); 340 } 341 286 342 if ($this->_intpl) 287 343 $this->Error('Adding links in templates aren\'t possible!'); … … 289 345 } 290 346 291 function SetLink($link,$y=0,$page=-1) { 347 function SetLink($link, $y = 0, $page = -1) { 348 if (is_subclass_of($this, 'TCPDF')) { 349 $args = func_get_args(); 350 return call_user_func_array(array($this, 'TCPDF::SetLink'), $args); 351 } 352 292 353 if ($this->_intpl) 293 354 $this->Error('Setting links in templates aren\'t possible!'); 294 parent::SetLink($link, $y,$page);355 parent::SetLink($link, $y, $page); 295 356 } 296 357 … … 309 370 $this->_out('/Subtype /Form'); 310 371 $this->_out('/FormType 1'); 311 $this->_out(sprintf('/BBox [%.2f %.2f %.2f %.2f]',$tpl['x']*$this->k, ($tpl['h']-$tpl['y'])*$this->k, $tpl['w']*$this->k, ($tpl['h']-$tpl['y']-$tpl['h'])*$this->k)); 372 $this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]', 373 // llx 374 $tpl['x'] * $this->k, 375 // lly 376 -$tpl['y'] * $this->k, 377 // urx 378 ($tpl['w'] + $tpl['x']) * $this->k, 379 // ury 380 ($tpl['h'] - $tpl['y']) * $this->k 381 )); 382 383 if ($tpl['x'] != 0 || $tpl['y'] != 0) { 384 $this->_out(sprintf('/Matrix [1 0 0 1 %.5F %.5F]', 385 -$tpl['x'] * $this->k * 2, $tpl['y'] * $this->k * 2 386 )); 387 } 388 312 389 $this->_out('/Resources '); 313 390 … … 316 393 $this->_out('/Font <<'); 317 394 foreach($this->_res['tpl'][$tplidx]['fonts'] as $font) 318 $this->_out('/F' .$font['i'].' '.$font['n'].' 0 R');395 $this->_out('/F' . $font['i'] . ' ' . $font['n'] . ' 0 R'); 319 396 $this->_out('>>'); 320 397 } … … 325 402 if (isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images'])) { 326 403 foreach($this->_res['tpl'][$tplidx]['images'] as $image) 327 $this->_out('/I' .$image['i'].' '.$image['n'].' 0 R');404 $this->_out('/I' . $image['i'] . ' ' . $image['n'] . ' 0 R'); 328 405 } 329 406 if (isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls'])) { 330 407 foreach($this->_res['tpl'][$tplidx]['tpls'] as $i => $tpl) 331 $this->_out($this->tplprefix .$i.' '.$tpl['n'].' 0 R');408 $this->_out($this->tplprefix . $i . ' ' . $tpl['n'] . ' 0 R'); 332 409 } 333 410 $this->_out('>>'); … … 335 412 $this->_out('>>'); 336 413 337 $this->_out('/Length ' .strlen($p).' >>');414 $this->_out('/Length ' . strlen($p) . ' >>'); 338 415 $this->_putstream($p); 339 416 $this->_out('endobj'); … … 342 419 343 420 /** 344 * Private Method 345 */ 346 function _putresources() { 347 $this->_putfonts(); 348 $this->_putimages(); 349 $this->_putformxobjects(); 350 //Resource dictionary 351 $this->offsets[2]=strlen($this->buffer); 352 $this->_out('2 0 obj'); 353 $this->_out('<<'); 354 $this->_putresourcedict(); 355 $this->_out('>>'); 356 $this->_out('endobj'); 421 * Overwritten to add _putformxobjects() after _putimages() 422 * 423 */ 424 function _putimages() { 425 parent::_putimages(); 426 $this->_putformxobjects(); 357 427 } 358 428 … … 362 432 if (count($this->tpls)) { 363 433 foreach($this->tpls as $tplidx => $tpl) { 364 $this->_out( $this->tplprefix.$tplidx.' '.$tpl['n'].' 0 R');434 $this->_out(sprintf('%s%d %d 0 R', $this->tplprefix, $tplidx, $tpl['n'])); 365 435 } 366 436 } … … 371 441 */ 372 442 function _out($s) { 373 //Add a line to the document 374 if ($this->state==2) { 375 if (!$this->_intpl) 376 $this->pages[$this->page].=$s."\n"; 377 else 378 $this->tpls[$this->tpl]['buffer'] .= $s."\n"; 379 } else { 380 $this->buffer.=$s."\n"; 381 } 443 if ($this->state == 2 && $this->_intpl) { 444 $this->tpls[$this->tpl]['buffer'] .= $s . "\n"; 445 } else { 446 parent::_out($s); 447 } 382 448 } 383 449 } 384 385 ?>
Note: See TracChangeset
for help on using the changeset viewer.