X-Git-Url: https://git.llucax.com/mecon/meconlib.git/blobdiff_plain/f82ac09838f49891a683ca0cf345adf06b5e75f9..df6d0dd1ecb626f80aa8fc64524374107df839e9:/lib/MECON/PDF.php diff --git a/lib/MECON/PDF.php b/lib/MECON/PDF.php index b88e8a0..e4f1b3c 100644 --- a/lib/MECON/PDF.php +++ b/lib/MECON/PDF.php @@ -31,17 +31,33 @@ 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 * @access protected */ - var $config; + var $_config = array (); /** * Libreria externa. * @var int $pdf - * @access private + * @access protected */ var $_pdf; @@ -57,35 +73,60 @@ 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 hojas (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]; + $this->_config = include 'MECON/PDF/medidas.php'; + $this->_config = $this->_config[$tam]; } /** * Permite agregar nuevas paginas al pdf que se esta armando. * * @param string $pagina Tipo de pagina que se va a utilizar. + * @param string $orientacion Orientacion de la pagina en particular. * * @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, toma la orientacion de la ultima pagina. + * + * @param int $pagina Numero de la pagina. + * + * @access public + * @return int + */ + function getOrientation($pagina = null) + { + if(is_null($pagina)) + $pagina = $this->numPage(); + + if(isset($this->_orientacion_distinta[$pagina])) + return $this->_orientacion_distinta[$pagina]; + else + return $this->orientacion; } /** @@ -126,11 +167,12 @@ 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) { $x = $X; $y = $Y; + if(is_null($transformacion)) + $transformacion = $this->getOrientation($pag); switch (strtolower($transformacion)) { case 'portrait': $X = $this->_portraitX($x,$y); @@ -139,7 +181,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 +202,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 +242,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 +282,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,14 +407,16 @@ class MECON_PDF { * @return int * @access public */ - function getWidth($orientacion = 'portrait') + function getWidth($pagina = null, $orientacion = null) { - switch (strtolower($orientacion)) { + if(is_null($orientacion)) + $orientacion = $this->getOrientation($pagina); + switch (strtolower($orientacion)) { case 'landscape': - $width = $this->config['Yf'] - $this->config['Yi']; + $width = $this->_config['Yf'] - $this->_config['Yi']; break; default: - $width = $this->config['Xf'] - $this->config['Xi']; + $width = $this->_config['Xf'] - $this->_config['Xi']; } return $width; @@ -380,14 +430,16 @@ class MECON_PDF { * @return int * @access public */ - function getHeight($orientacion = 'portrait') + function getHeight($pagina = null, $orientacion = null) { - switch (strtolower($orientacion)) { + if(is_null($orientacion)) + $orientacion = $this->getOrientation($pagina); + switch (strtolower($orientacion)) { case 'landscape': - $height = $this->config['Xf'] - $this->config['Xi']; + $height = $this->_config['Xf'] - $this->_config['Xi']; break; default: - $height = $this->config['Yf'] - $this->config['Yi']; + $height = $this->_config['Yf'] - $this->_config['Yi']; } return $height; } @@ -403,7 +455,7 @@ class MECON_PDF { */ function _landscapeX($x, $y) { - return -$y + $this->config['Xf']; + return -$y + $this->_config['Xf']; } /** @@ -417,7 +469,7 @@ class MECON_PDF { */ function _landscapeY($x, $y) { - return $x + $this->config['Yi']; + return $x + $this->_config['Yi']; } /** @@ -431,7 +483,7 @@ class MECON_PDF { */ function _portraitX($x, $y) { - return $x + $this->config['Xi']; + return $x + $this->_config['Xi']; } /** @@ -445,7 +497,7 @@ class MECON_PDF { */ function _portraitY($x, $y) { - return $y + $this->config['Yi']; + return $y + $this->_config['Yi']; } } ?> \ No newline at end of file