source: trunk/reports/inc/class.uireports_fpdf.inc.php @ 7673

Revision 7673, 3.3 KB checked in by douglasz, 11 years ago (diff)

Ticket #3236 - Correcoes para Performance: Function Within Loop Declaration.

Line 
1<?php
2/*******************************************************************************
3 * FPDF                                                                         *
4 *                                                                              *
5 * Version: 1.6                                                                 *
6 * Date:    2008-08-03                                                          *
7 * Author:  Olivier PLATHEY                                                     *
8 *******************************************************************************/
9
10require('class.fpdf.inc.php');
11
12class uireports_fpdf extends FPDF
13{
14        var $a = "1";
15        var $b = "1";
16
17        var $widths;
18        var $aligns;
19
20        function __construct($orientation = "P") {
21                parent::__construct($orientation);
22        }
23         
24        function SetWidths($w)
25        {
26                //Set the array of column widths
27                $this->widths=$w;
28        }
29
30        function SetAligns($a)
31        {
32                //Set the array of column alignments
33                $this->aligns=$a;
34        }
35
36        function Row($data)
37        {
38                //Calculate the height of the row
39                $nb=0;
40        $data_count = count($data);
41                for($i=0;$i< $data_count;++$i)
42                $nb=max($nb,$this->NbLines($this->widths[$i],$data[$i]));
43                $h=5*$nb;
44                //Issue a page break first if needed
45                $this->CheckPageBreak($h);
46                //Draw the cells of the row
47        $data_count = count($data);
48                for($i=0;$i< $data_count;++$i)
49                {
50                        $w=$this->widths[$i];
51                        $a=isset($this->aligns[$i]) ? $this->aligns[$i] : 'L';
52                        //Save the current position
53                        $x=$this->GetX();
54                        $y=$this->GetY();
55                        //Draw the border
56                        $this->Rect($x,$y,$w,$h);
57                        //Print the text
58                        $this->MultiCell($w,5,$data[$i],0,$a);
59                        //Put the position to the right of the cell
60                        $this->SetXY($x+$w,$y);
61                }
62                //Go to the next line
63                $this->Ln($h);
64        }
65
66        function CheckPageBreak($h)
67        {
68                //If the height h would cause an overflow, add a new page immediately
69                if($this->GetY()+$h>$this->PageBreakTrigger)
70                $this->AddPage($this->CurOrientation);
71        }
72
73        function NbLines($w,$txt)
74        {
75                //Computes the number of lines a MultiCell of width w will take
76                $cw=&$this->CurrentFont['cw'];
77                if($w==0)
78                $w=$this->w-$this->rMargin-$this->x;
79                $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
80                $s=str_replace("\r",'',$txt);
81                $nb=strlen($s);
82                if($nb>0 and $s[$nb-1]=="\n")
83                $nb--;
84                $sep=-1;
85                $i=0;
86                $j=0;
87                $l=0;
88                $nl=1;
89                while($i<$nb)
90                {
91                        $c=$s[$i];
92                        if($c=="\n")
93                        {
94                                ++$i;
95                                $sep=-1;
96                                $j=$i;
97                                $l=0;
98                                ++$nl;
99                                continue;
100                        }
101                        if($c==' ')
102                        $sep=$i;
103                        $l+=$cw[$c];
104                        if($l>$wmax)
105                        {
106                                if($sep==-1)
107                                {
108                                        if($i==$j)
109                                        ++$i;
110                                }
111                                else
112                                $i=$sep+1;
113                                $sep=-1;
114                                $j=$i;
115                                $l=0;
116                                ++$nl;
117                        }
118                        else
119                        ++$i;
120                }
121                return $nl;
122        }
123
124        function Footer()
125        {
126                // Esta função foi implemantada para realizar o rodapé dos relatórios
127                $titulo_system = $GLOBALS['phpgw_info']['apps']['reports']['title'];
128                $SubTitulo = $GLOBALS['phpgw_info']['apps']['reports']['subtitle'];
129
130                //Seleciona Arial itálico 8
131                $this->SetY(-15);
132                $this->SetFont('Arial','I',8);
133                $this->SetTextColor(0,0,100);
134                $this->SetFillColor(224,235,255);
135
136                //Imprime o número da página
137                $this->Rect(9,281,197,6,'D');
138                $this->Cell(55,4,$titulo_system,0,0,'L',1);
139                $this->Cell(100,4,$SubTitulo,0,0,'C',1);
140                $this->Cell(40,4,'Página n. '.$this->PageNo(),0,1,'R',1);
141        }
142
143}
144?>
Note: See TracBrowser for help on using the repository browser.