X-Git-Url: https://git.llucax.com/mecon/meconlib.git/blobdiff_plain/67d328b236b5531e94572af215772303e022bcfd..0dbb40b231defb31e62e2c0a56c1bc1abd85ec06:/lib/MECON/PDF.php?ds=inline diff --git a/lib/MECON/PDF.php b/lib/MECON/PDF.php index dff59a2..fc4011e 100644 --- a/lib/MECON/PDF.php +++ b/lib/MECON/PDF.php @@ -31,6 +31,22 @@ require_once 'MECON/PDF/external/phppdflib.class.php'; */ class MECON_PDF { + /** + * Orientacion (portrait o landscape). + * @var sting $orientacion + * @access public + */ + var $orientacion = "portrait"; + + /** + * + * Orientacion cambiada, indica la orientacion de la pagina cuando es + * distinto al comun + * @var array $orientacion_distinta + * @access protected + */ + var $_orientacion_distinta = array(); + /** * Configuracion * @var arary $config @@ -57,18 +73,20 @@ class MECON_PDF { * @var array $paginas * @access private */ - var $_paginas; + var $_paginas = array(); /** * Class constructor. * * @param string $tam Tipo de hoja + * @param string $ori Orientacion de las hojaz (portrait o landscape). * * @return void * @access public */ - function MECON_PDF($tam = "a4") + function MECON_PDF($tam = "a4", $ori = "portrait") { + $this->orientacion = $ori; $this->_pdf = new pdffile; $this->_config = include 'MECON/PDF/medidas.php'; $this->_config = $this->_config[$tam]; @@ -82,10 +100,28 @@ class MECON_PDF { * @return void * @access public */ - function newPage($pagina = "a4") + function newPage($pagina = "a4", $orientacion = null) { $this->_pagina_actual = $this->_pdf->new_page($pagina); $this->_paginas[] = $this->_pagina_actual; + if(!is_null($orientacion) && $orientacion != $this->orientacion) + $this->_orientacion_distinta[$this->numPage()] = $orientacion; + } + + /** + * Funcion que retorna la orientacion de la pagina indicada + * Si no se indica, la orientacion de la ultima pagina + * @access public + * @return int + */ + function getOrientation($pagina = null) + { + if(is_null($pagina)) + $pagina = $this->numPage(); + if(isset($this->_orientacion_distinta[$pagina])) + $o = $this->_orientacion_distinta[$pagina]; + else $o = $this->orientacion; + return $o; } /** @@ -126,11 +162,14 @@ class MECON_PDF { * @return void * @access public */ - function addText($X, $Y, $texto, $estilo = '', $pag = null, $transformacion = '') { + function addText($X, $Y, $texto, $estilo = '', $pag = null, $transformacion + = null) { //@TODO Ver si $texto es un objeto $x = $X; $y = $Y; + if(is_null($transformacion)) + $transformacion = $this->getOrientation($pag); switch (strtolower($transformacion)) { case 'portrait': $X = $this->_portraitX($x,$y); @@ -139,7 +178,7 @@ class MECON_PDF { case 'landscape': $X = $this->_landscapeX($x,$y); $Y = $this->_landscapeY($x,$y); - $estilo['rotation'] = 90; + @$estilo['rotation'] += 90; break; } $this->_pdf->draw_text($X, $Y, $texto, $this->refPage($pag), $estilo); @@ -160,12 +199,14 @@ class MECON_PDF { * @access public */ function addRectangle($Xi, $Yi, $Xf, $Yf, $estilo = '', $pag = null, - $transformacion = 'portrait') + $transformacion = null) { $xi = $Xi; $yi = $Yi; $xf = $Xf; $yf = $Yf; + if(is_null($transformacion)) + $transformacion = $this->getOrientation($pag); switch (strtolower($transformacion)) { case 'portrait': $Xi = $this->_portraitX($xi,$yi); @@ -198,12 +239,14 @@ class MECON_PDF { * @access public */ function addLine($Xi, $Yi, $Xf, $Yf, $estilo = '', $pag = null, - $transformacion = 'portrait') + $transformacion = null) { $xi = $Xi; $yi = $Yi; $xf = $Xf; $yf = $Yf; + if(is_null($transformacion)) + $transformacion = $this->getOrientation($pag); switch (strtolower($transformacion)) { case 'portrait': $Xi = $this->_portraitX($xi,$yi); @@ -236,9 +279,11 @@ class MECON_PDF { * @access public */ function addImage($archivo, $X, $Y, $pag = null, $formato = null, - $transformacion = 'portrait') { + $transformacion = null) { $x = $X; $y = $Y; + if(is_null($transformacion)) + $transformacion = $this->getOrientation($pag); switch (strtolower($transformacion)) { case 'portrait': $X = $this->_portraitX($x,$y); @@ -359,8 +404,10 @@ class MECON_PDF { * @return int * @access public */ - function getWidth($orientacion = 'portrait') + function getWidth($pagina = null, $orientacion = null) { + if(is_null($orientacion)) + $orientacion = $this->getOrientation($pagina); switch (strtolower($orientacion)) { case 'landscape': $width = $this->_config['Yf'] - $this->_config['Yi']; @@ -380,8 +427,10 @@ class MECON_PDF { * @return int * @access public */ - function getHeight($orientacion = 'portrait') + function getHeight($pagina = null, $orientacion = null) { + if(is_null($orientacion)) + $orientacion = $this->getOrientation($pagina); switch (strtolower($orientacion)) { case 'landscape': $height = $this->_config['Xf'] - $this->_config['Xi'];