1 <?php /* vim: set binary expandtab tabstop=4 shiftwidth=4 textwidth=80:
2 -------------------------------------------------------------------------------
3 Ministerio de EconomÃa
5 -------------------------------------------------------------------------------
6 This file is part of meconlib.
8 meconlib is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2 of the License, or (at your option)
13 meconlib is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License; if not,
18 write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19 Boston, MA 02111-1307 USA
20 -------------------------------------------------------------------------------
21 Creado: Fri Oct 24 16:34:11 2003
22 Autor: Martin Marrese <mmarre@mecon.gov.ar>
23 -------------------------------------------------------------------------------
25 -----------------------------------------------------------------------------*/
27 require_once 'MECON/PDF/Marco.php';
30 * Libreria que permite agregar una tabla a un pdf.
32 class MECON_PDF_Tabla extends MECON_PDF_Marco {
35 * Funcion que envia el archivo a pantalla (para que el usuario haga un
42 if ($this->getRowCount()) {
43 $this->_agregarContenido();
46 $this->_pdf->newPage($this->_tamanio);
47 $this->_pdf->addText($this->_config['Xi'],
48 $this->_config['contenido']['Y'],
49 'No hay contenido para mostrar.',
50 $this->_config['contenido']);
53 $this->_pdf->display();
57 * Funcion que devuelve el estilo de la celda segun la configuracion.
59 * @param int $row Indicador de la fila
60 * @param int $col Indicador de la columna
65 function _obtenerEstiloCelda($row, $col) {
66 $clase = $this->getCellAttributes($row, $col);
67 switch ($clase['class']) {
68 case 'mecon_html_tabla_comun_cabecera':
69 $estilo = $this->_config['celda_cabecera'];
71 case 'mecon_html_tabla_comun_titulo':
72 $estilo = $this->_config['celda_titulo'];
75 $estilo = $this->_config['celda_comun'];
82 * Funcion que agrega las filas y columnas a la pagina.
87 function _agregarContenido() {
88 //Calculo el ancho de la columnas basandome en el ancho que tienen las
89 //mismas en la primer fila {{{
90 $ancho_pagina = abs($this->_config['Xf'] -
91 $this->_config['Xi']) ;
92 for ($i=0; $i<$this->getColCount(); $i++ ) {
93 $tmp = $this->getCellAttributes(0,$i);
94 if (is_null(@$tmp['width'])) {
95 die ('Todas las columnas deben tener asignado un ancho.');
97 $attr[$i] = intval($tmp['width']);
99 $tmp = array_sum($attr);
100 $attr2[0] = $this->_config['Xi'];
101 for ($i=1; $i<count($attr); $i++) {
102 $attr2[$i] = intval(($ancho_pagina * $attr[$i-1] / $tmp) +
105 $attr2[$i] = $this->_config['Xf'];
108 $this->_pdf->newPage($this->_tamanio);
110 $alto = $this->_getAvailableSpace($this->_pdf->numPage());
112 for ($i = 0; $i < $this->getRowCount(); $i++) {
114 for ($j = 0; $j < $this->getColCount(); $j++) {
115 $estilo = $this->_obtenerEstiloCelda($i, $j);
116 $txt = $this->_pdf->wordWrap($this->getCellContents($i,$j),
117 $attr2[$j+1] - $attr2[$j], $estilo);
118 $max = max($estilo['alto_linea'] * count($txt), $max);
123 if ($alto < $this->_config['Yi']) {
124 $this->_pdf->newPage($this->_tamanio);
125 $alto = $this->_getAvailableSpace($this->_pdf->numPage());
127 for ($j = 0; $j < $this->getColCount(); $j++) {
128 $estilo = $this->_obtenerEstiloCelda($i, $j);
130 $this->_pdf->addRectangle($alto, $attr2[$j],
132 $attr2[$j+1], @$estilo['fill']);
134 $txt = $this->_pdf->wordWrap($this->getCellContents($i,$j),
135 $attr2[$j+1] - $attr2[$j], $estilo);
136 $alto1 = $alto + $max;
137 foreach ($txt as $t) {
138 $alto1 -= $estilo['alto_linea'];
139 $this->_pdf->addText($attr2[$j] + 1, $alto1 + 1,
145 foreach ($this->_pdf->getPages() as $page) {
146 $this->_pdf->_pagina_actual = $page;
147 $this->buildPage($t, $t);