HTML2PDF::_drawRectangle()   F
last analyzed

Complexity

Conditions 94
Paths > 20000

Size

Total Lines 371
Code Lines 261

Duplication

Lines 165
Ratio 44.47 %

Importance

Changes 0
Metric Value
cc 94
eloc 261
nc 4294967295
nop 8
dl 165
loc 371
rs 2
c 0
b 0
f 0

How to fix   Long Method    Complexity    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 * HTML2PDF Librairy - main class
4
 *
5
 * HTML => PDF convertor
6
 * distributed under the LGPL License
7
 *
8
 * @author  Laurent MINGUET <[email protected]>
9
 * @version 4.03
10
 */
11
12
if ( ! defined('__CLASS_HTML2PDF__')) {
13
14
    define('__CLASS_HTML2PDF__', '4.03');
15
    define('HTML2PDF_USED_TCPDF_VERSION', '5.0.002');
16
17
    require_once('_class/exception.class.php');
18
    require_once('_class/locale.class.php');
19
    require_once('_class/myPdf.class.php');
20
    require_once('_class/parsingHtml.class.php');
21
    require_once('_class/parsingCss.class.php');
22
23
    class HTML2PDF
24
    {
25
        /**
26
         * HTML2PDF_myPdf object, extends from TCPDF
27
         * @var HTML2PDF_myPdf
28
         */
29
        public $pdf = null;
30
31
        /**
32
         * CSS parsing
33
         * @var HTML2PDF_parsingCss
34
         */
35
        public $parsingCss = null;
36
37
        /**
38
         * HTML parsing
39
         * @var HTML2PDF_parsingHtml
40
         */
41
        public $parsingHtml = null;
42
43
        protected $_langue           = 'fr'; // locale of the messages
44
        protected $_orientation      = 'P'; // page orientation : Portrait ou Landscape
45
        protected $_format           = 'A4'; // page format : A4, A3, ...
46
        protected $_encoding         = ''; // charset encoding
47
        protected $_unicode          = true; // means that the input text is unicode (default = true)
48
49
        protected $_testTdInOnepage  = true; // test of TD that can not take more than one page
50
        protected $_testIsImage      = true; // test if the images exist or not
51
        protected $_testIsDeprecated = false; // test the deprecated functions
52
53
        protected $_parsePos         = 0; // position in the parsing
54
        protected $_tempPos          = 0; // temporary position for complex table
55
        protected $_page             = 0; // current page number
56
57
        protected $_subHtml          = null; // sub html
58
        protected $_subPart          = false; // sub HTML2PDF
59
        protected $_subHEADER        = array(); // sub action to make the header
60
        protected $_subFOOTER        = array(); // sub action to make the footer
61
        protected $_subSTATES        = array(); // array to save some parameters
62
63
        protected $_isSubPart        = false; // flag : in a sub html2pdf
64
        protected $_isInThead        = false; // flag : in a thead
65
        protected $_isInTfoot        = false; // flag : in a tfoot
66
        protected $_isInOverflow     = false; // flag : in a overflow
67
        protected $_isInFooter       = false; // flag : in a footer
68
        protected $_isInDraw         = null; // flag : in a draw (svg)
69
        protected $_isAfterFloat     = false; // flag : is just after a float
70
        protected $_isInForm         = false; // flag : is in a float. false / action of the form
71
        protected $_isInLink         = ''; // flag : is in a link. empty / href of the link
72
        protected $_isInParagraph    = false; // flag : is in a paragraph
73
        protected $_isForOneLine     = false; // flag : in a specific sub html2pdf to have the height of the next line
74
75
        protected $_maxX             = 0; // maximum X of the current zone
76
        protected $_maxY             = 0; // maximum Y of the current zone
77
        protected $_maxE             = 0; // number of elements in the current zone
78
        protected $_maxH             = 0; // maximum height of the line in the current zone
79
        protected $_maxSave          = array(); // save the maximums of the current zone
80
        protected $_currentH         = 0; // height of the current line
81
82
        protected $_defaultLeft      = 0; // default marges of the page
83
        protected $_defaultTop       = 0;
84
        protected $_defaultRight     = 0;
85
        protected $_defaultBottom    = 0;
86
        protected $_defaultFont      = null; // default font to use, is the asked font does not exist
87
88
        protected $_margeLeft        = 0; // current marges of the page
89
        protected $_margeTop         = 0;
90
        protected $_margeRight       = 0;
91
        protected $_margeBottom      = 0;
92
        protected $_marges           = array(); // save the different marges of the current page
93
        protected $_pageMarges       = array(); // float marges of the current page
94
        protected $_background       = array(); // background informations
95
96
97
        protected $_firstPage        = true; // flag : first page
98
        protected $_defList          = array(); // table to save the stats of the tags UL and OL
99
100
        protected $_lstAnchor        = array(); // list of the anchors
101
        protected $_lstField         = array(); // list of the fields
102
        protected $_lstSelect        = array(); // list of the options of the current select
103
        protected $_previousCall     = null; // last action called
104
105
        protected $_debugActif       = false; // flag : mode debug is active
106
        protected $_debugOkUsage     = false; // flag : the function memory_get_usage exist
107
        protected $_debugOkPeak      = false; // flag : the function memory_get_peak_usage exist
108
        protected $_debugLevel       = 0; // level in the debug
109
        protected $_debugStartTime   = 0; // debug start time
110
        protected $_debugLastTime    = 0; // debug stop time
111
112
        static protected $_subobj    = null; // object html2pdf prepared in order to accelerate the creation of sub html2pdf
113
        static protected $_tables    = array(); // static table to prepare the nested html tables
114
115
        /**
116
         * class constructor
117
         *
118
         * @access public
119
         * @param  string   $orientation page orientation, same as TCPDF
120
         * @param  string    $format      The format used for pages, same as TCPDF
121
         * @param  $tring   $langue      Langue : fr, en, it...
0 ignored issues
show
Documentation introduced by
The doc-type $tring could not be parsed: Unknown type name "$tring" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
122
         * @param  boolean  $unicode     TRUE means that the input text is unicode (default = true)
123
         * @param  String   $encoding    charset encoding; default is UTF-8
124
         * @param  integer[]    $marges      Default marges (left, top, right, bottom)
125
         * @return HTML2PDF $this
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
126
         */
127
        public function __construct($orientation = 'P', $format = 'A4', $langue = 'en', $unicode = true, $encoding = 'UTF-8', $marges = array(5, 5, 5, 8))
128
        {
129
            // init the page number
130
            $this->_page         = 0;
131
            $this->_firstPage    = true;
132
133
            // save the parameters
134
            $this->_orientation  = $orientation;
135
            $this->_format       = $format;
136
            $this->_langue       = strtolower($langue);
137
            $this->_unicode      = $unicode;
138
            $this->_encoding     = $encoding;
139
140
            // load the Local
141
            HTML2PDF_locale::load($this->_langue);
142
143
            // create the  HTML2PDF_myPdf object
144
            $this->pdf = new HTML2PDF_myPdf($orientation, 'mm', $format, $unicode, $encoding);
145
146
            // init the CSS parsing object
147
            $this->parsingCss = new HTML2PDF_parsingCss($this->pdf);
148
            $this->parsingCss->fontSet();
149
            $this->_defList = array();
150
151
            // init some tests
152
            $this->setTestTdInOnePage(true);
153
            $this->setTestIsImage(true);
154
            $this->setTestIsDeprecated(true);
155
156
            // init the default font
157
            $this->setDefaultFont(null);
158
159
            // init the HTML parsing object
160
            $this->parsingHtml = new HTML2PDF_parsingHtml($this->_encoding);
161
            $this->_subHtml = null;
162
            $this->_subPart = false;
163
164
            // init the marges of the page
165
            if ( ! is_array($marges)) $marges = array($marges, $marges, $marges, $marges);
166
            $this->_setDefaultMargins($marges[0], $marges[1], $marges[2], $marges[3]);
167
            $this->_setMargins();
168
            $this->_marges = array();
169
170
            // init the form's fields
171
            $this->_lstField = array();
172
173
            return $this;
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
174
        }
175
176
        /**
177
         * Destructor
178
         *
179
         * @access public
180
         * @return null
181
         */
182
        public function __destruct()
183
        {
184
185
        }
186
187
        /**
188
         * Clone to create a sub HTML2PDF from HTML2PDF::$_subobj
189
         *
190
         * @access public
191
         */
192
        public function __clone()
193
        {
194
            $this->pdf = clone $this->pdf;
195
            $this->parsingHtml = clone $this->parsingHtml;
196
            $this->parsingCss = clone $this->parsingCss;
197
            $this->parsingCss->setPdfParent($this->pdf);
198
        }
199
200
        /**
201
         * set the debug mode to On
202
         *
203
         * @access public
204
         * @return HTML2PDF $this
205
         */
206
        public function setModeDebug()
207
        {
208
            $time = microtime(true);
209
210
            $this->_debugActif     = true;
211
            $this->_debugOkUsage   = function_exists('memory_get_usage');
212
            $this->_debugOkPeak    = function_exists('memory_get_peak_usage');
213
            $this->_debugStartTime = $time;
0 ignored issues
show
Documentation Bug introduced by
The property $_debugStartTime was declared of type integer, but $time is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
214
            $this->_debugLastTime  = $time;
0 ignored issues
show
Documentation Bug introduced by
The property $_debugLastTime was declared of type integer, but $time is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
215
216
            $this->_DEBUG_stepline('step', 'time', 'delta', 'memory', 'peak');
217
            $this->_DEBUG_add('Init debug');
218
219
            return $this;
220
        }
221
222
        /**
223
         * Set the test of TD thdat can not take more than one page
224
         *
225
         * @access public
226
         * @param  boolean  $mode
227
         * @return HTML2PDF $this
228
         */
229
        public function setTestTdInOnePage($mode = true)
230
        {
231
            $this->_testTdInOnepage = $mode ? true : false;
232
233
            return $this;
234
        }
235
236
        /**
237
         * Set the test if the images exist or not
238
         *
239
         * @access public
240
         * @param  boolean  $mode
241
         * @return HTML2PDF $this
242
         */
243
        public function setTestIsImage($mode = true)
244
        {
245
            $this->_testIsImage = $mode ? true : false;
246
247
            return $this;
248
        }
249
250
        /**
251
         * Set the test on deprecated functions
252
         *
253
         * @access public
254
         * @param  boolean  $mode
255
         * @return HTML2PDF $this
256
         */
257
        public function setTestIsDeprecated($mode = true)
258
        {
259
            $this->_testIsDeprecated = $mode ? true : false;
260
261
            return $this;
262
        }
263
264
        /**
265
         * Set the default font to use, if no font is specify, or if the asked font does not exist
266
         *
267
         * @access public
268
         * @param  string   $default name of the default font to use. If null : Arial is no font is specify, and error if the asked font does not exist
269
         * @return HTML2PDF $this
270
         */
271
        public function setDefaultFont($default = null)
272
        {
273
            $this->_defaultFont = $default;
274
            $this->parsingCss->setDefaultFont($default);
275
276
            return $this;
277
        }
278
279
        /**
280
         * add a font, see TCPDF function addFont
281
         *
282
         * @access public
283
         * @param string $family Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
284
         * @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular (default)</li><li>B: bold</li><li>I: italic</li><li>BI or IB: bold italic</li></ul>
285
         * @return HTML2PDF $this
286
         * @see TCPDF::addFont
287
         */
288
        public function addFont($family, $style = '', $file = '')
289
        {
290
            $this->pdf->AddFont($family, $style, $file);
291
292
            return $this;
293
        }
294
295
        /**
296
         * display a automatic index, from the bookmarks
297
         *
298
         * @access public
299
         * @param  string  $titre         index title
300
         * @param  int     $sizeTitle     font size of the index title, in mm
301
         * @param  int     $sizeBookmark  font size of the index, in mm
302
         * @param  boolean $bookmarkTitle add a bookmark for the index, at his beginning
303
         * @param  boolean $displayPage   display the page numbers
304
         * @param  int     $onPage        if null : at the end of the document on a new page, else on the $onPage page
305
         * @param  string  $fontName      font name to use
306
         * @return null
307
         */
308
        public function createIndex($titre = 'Index', $sizeTitle = 20, $sizeBookmark = 15, $bookmarkTitle = true, $displayPage = true, $onPage = null, $fontName = 'helvetica')
309
        {
310
            $oldPage = $this->_INDEX_NewPage($onPage);
311
            $this->pdf->createIndex($this, $titre, $sizeTitle, $sizeBookmark, $bookmarkTitle, $displayPage, $onPage, $fontName);
312
            if ($oldPage) {
313
            	$this->pdf->setPage($oldPage);
314
            }
315
        }
316
317
        /**
318
         * clean up the objects
319
         *
320
         * @access protected
321
         */
322
        protected function _cleanUp()
323
        {
324
            HTML2PDF::$_subobj = null;
325
            HTML2PDF::$_tables = array();
326
        }
327
328
        /**
329
         * Send the document to a given destination: string, local file or browser.
330
         * Dest can be :
331
         *  I : send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.
332
         *  D : send to the browser and force a file download with the name given by name.
333
         *  F : save to a local server file with the name given by name.
334
         *  S : return the document as a string. name is ignored.
335
         *  FI: equivalent to F + I option
336
         *  FD: equivalent to F + D option
337
         *  true  => I
338
         *  false => S
339
         *
340
         * @param  string $name The name of the file when saved.
341
         * @param  string $dest Destination where to send the document.
342
         * @return string content of the PDF, if $dest=S
343
         * @see TCPDF::close
344
         * @access public
345
346
         */
347
        public function Output($name = '', $dest = false)
348
        {
349
            // close the pdf and clean up
350
            $this->_cleanUp();
351
352
            // if on debug mode
353
            if ($this->_debugActif) {
354
                $this->_DEBUG_add('Before output');
355
                $this->pdf->Close();
356
                exit;
357
            }
358
359
            // complete parameters
360
            if ($dest === false) $dest = 'I';
361
            if ($dest === true)  $dest = 'S';
362
            if ($dest === '')    $dest = 'I';
363
            if ($name == '')     $name = 'document.pdf';
364
365
            // clean up the destination
366
            $dest = strtoupper($dest);
367
            if ( ! in_array($dest, array('I', 'D', 'F', 'S', 'FI', 'FD'))) $dest = 'I';
368
369
            // the name must be a PDF name
370
            if (strtolower(substr($name, -4)) != '.pdf') {
371
                throw new HTML2PDF_exception(0, 'The output document name "'.$name.'" is not a PDF name');
372
            }
373
374
            // call the output of TCPDF
375
            return $this->pdf->Output($name, $dest);
376
        }
377
378
        /**
379
         * convert HTML to PDF
380
         *
381
         * @access public
382
         * @param  string   $html
383
         * @param  boolean  $debugVue  enable the HTML debug vue
384
         * @return null
385
         */
386
        public function writeHTML($html, $debugVue = false)
387
        {
388
            // if it is a real html page, we have to convert it
389
            if (preg_match('/<body/isU', $html)) {
390
                            $html = $this->getHtmlFromPage($html);
391
            }
392
393
            $html = str_replace('[[date_y]]', date('Y'), $html);
394
            $html = str_replace('[[date_m]]', date('m'), $html);
395
            $html = str_replace('[[date_d]]', date('d'), $html);
396
397
            $html = str_replace('[[date_h]]', date('H'), $html);
398
            $html = str_replace('[[date_i]]', date('i'), $html);
399
            $html = str_replace('[[date_s]]', date('s'), $html);
400
401
            // If we are in HTML debug vue : display the HTML
402
            if ($debugVue) {
403
                return $this->_vueHTML($html);
404
            }
405
406
            // convert HTMl to PDF
407
            $this->parsingCss->readStyle($html);
408
            $this->parsingHtml->setHTML($html);
409
            $this->parsingHtml->parse();
410
            $this->_makeHTMLcode();
411
        }
412
413
        /**
414
         * convert the HTML of a real page, to a code adapted to HTML2PDF
415
         *
416
         * @access public
417
         * @param  string HTML of a real page
418
         * @param string $html
419
         * @return string HTML adapted to HTML2PDF
420
         */
421
        public function getHtmlFromPage($html)
422
        {
423
            $html = str_replace('<BODY', '<body', $html);
424
            $html = str_replace('</BODY', '</body', $html);
425
426
            // extract the content
427
            $res = explode('<body', $html);
428
            if (count($res) < 2) return $html;
429
            $content = '<page'.$res[1];
430
            $content = explode('</body', $content);
431
            $content = $content[0].'</page>';
432
433
            // extract the link tags
434
            preg_match_all('/<link([^>]*)>/isU', $html, $match);
435
            foreach ($match[0] as $src)
436
                $content = $src.'</link>'.$content;
437
438
            // extract the css style tags
439
            preg_match_all('/<style[^>]*>(.*)<\/style[^>]*>/isU', $html, $match);
440
            foreach ($match[0] as $src)
441
                $content = $src.$content;
442
443
            return $content;
444
        }
445
446
        /**
447
         * init a sub HTML2PDF. does not use it directly. Only the method createSubHTML must use it
448
         *
449
         * @access public
450
         * @param  string  $format
451
         * @param  string  $orientation
452
         * @param  array   $marge
453
         * @param  integer $page
454
         * @param  array   $defLIST
455
         * @param  integer $myLastPageGroup
456
         * @param  integer $myLastPageGroupNb
457
         */
458
        public function initSubHtml($format, $orientation, $marge, $page, $defLIST, $myLastPageGroup, $myLastPageGroupNb)
459
        {
460
            $this->_isSubPart = true;
461
462
            $this->parsingCss->setOnlyLeft();
463
464
            $this->_setNewPage($format, $orientation, null, null, ($myLastPageGroup !== null));
465
466
            $this->_saveMargin(0, 0, $marge);
0 ignored issues
show
Documentation introduced by
$marge is of type array, but the function expects a double.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
467
            $this->_defList = $defLIST;
468
469
            $this->_page = $page;
470
            $this->pdf->setMyLastPageGroup($myLastPageGroup);
471
            $this->pdf->setMyLastPageGroupNb($myLastPageGroupNb);
472
            $this->pdf->setXY(0, 0);
473
            $this->parsingCss->fontSet();
474
        }
475
476
        /**
477
         * display the content in HTML moden for debug
478
         *
479
         * @access protected
480
         * @param  string $content
481
         */
482
        protected function _vueHTML($content)
483
        {
484
            $content = preg_replace('/<page_header([^>]*)>/isU', '<hr>'.HTML2PDF_locale::get('vue01').' : $1<hr><div$1>', $content);
485
            $content = preg_replace('/<page_footer([^>]*)>/isU', '<hr>'.HTML2PDF_locale::get('vue02').' : $1<hr><div$1>', $content);
486
            $content = preg_replace('/<page([^>]*)>/isU', '<hr>'.HTML2PDF_locale::get('vue03').' : $1<hr><div$1>', $content);
487
            $content = preg_replace('/<\/page([^>]*)>/isU', '</div><hr>', $content);
488
            $content = preg_replace('/<bookmark([^>]*)>/isU', '<hr>bookmark : $1<hr>', $content);
489
            $content = preg_replace('/<\/bookmark([^>]*)>/isU', '', $content);
490
            $content = preg_replace('/<barcode([^>]*)>/isU', '<hr>barcode : $1<hr>', $content);
491
            $content = preg_replace('/<\/barcode([^>]*)>/isU', '', $content);
492
            $content = preg_replace('/<qrcode([^>]*)>/isU', '<hr>qrcode : $1<hr>', $content);
493
            $content = preg_replace('/<\/qrcode([^>]*)>/isU', '', $content);
494
495
            echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
496
<html>
497
    <head>
498
        <title>'.HTML2PDF_locale::get('vue04').' HTML</title>
499
        <meta http-equiv="Content-Type" content="text/html; charset='.$this->_encoding.'" >
500
    </head>
501
    <body style="padding: 10px; font-size: 10pt;font-family:    Verdana;">
502
'.$content.'
503
    </body>
504
</html>';
505
            exit;
506
        }
507
508
        /**
509
         * set the default margins of the page
510
         *
511
         * @access protected
512
         * @param  int $left   (mm, left margin)
513
         * @param  int $top    (mm, top margin)
514
         * @param  int $right  (mm, right margin, if null => left=right)
515
         * @param  int $bottom (mm, bottom margin, if null => bottom=8mm)
516
         */
517
        protected function _setDefaultMargins($left, $top, $right = null, $bottom = null)
518
        {
519
            if ($right === null)  $right = $left;
520
            if ($bottom === null) $bottom = 8;
521
522
            $this->_defaultLeft   = $this->parsingCss->ConvertToMM($left.'mm');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->parsingCss->ConvertToMM($left . 'mm') can also be of type double. However, the property $_defaultLeft is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
523
            $this->_defaultTop    = $this->parsingCss->ConvertToMM($top.'mm');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->parsingCss->ConvertToMM($top . 'mm') can also be of type double. However, the property $_defaultTop is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
524
            $this->_defaultRight  = $this->parsingCss->ConvertToMM($right.'mm');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->parsingCss->ConvertToMM($right . 'mm') can also be of type double. However, the property $_defaultRight is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
525
            $this->_defaultBottom = $this->parsingCss->ConvertToMM($bottom.'mm');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->parsingCss->ConvertToMM($bottom . 'mm') can also be of type double. However, the property $_defaultBottom is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
526
        }
527
528
        /**
529
         * create a new page
530
         *
531
         * @access protected
532
         * @param  mixed   $format
533
         * @param  string  $orientation
534
         * @param  array   $background background information
535
         * @param  integer $curr real position in the html parseur (if break line in the write of a text)
536
         * @param  boolean $resetPageNumber
537
         */
538
        protected function _setNewPage($format = null, $orientation = '', $background = null, $curr = null, $resetPageNumber = false)
539
        {
540
            $this->_firstPage = false;
541
542
            $this->_format = $format ? $format : $this->_format;
543
            $this->_orientation = $orientation ? $orientation : $this->_orientation;
544
            $this->_background = $background !== null ? $background : $this->_background;
545
            $this->_maxY = 0;
546
            $this->_maxX = 0;
547
            $this->_maxH = 0;
548
            $this->_maxE = 0;
549
550
            $this->pdf->SetMargins($this->_defaultLeft, $this->_defaultTop, $this->_defaultRight);
551
552
            if ($resetPageNumber) {
553
                $this->pdf->startPageGroup();
554
            }
555
556
            $this->pdf->AddPage($this->_orientation, $this->_format);
557
558
            if ($resetPageNumber) {
559
                $this->pdf->myStartPageGroup();
560
            }
561
562
            $this->_page++;
563
564
            if ( ! $this->_subPart && ! $this->_isSubPart) {
565
                if (is_array($this->_background)) {
566
                    if (isset($this->_background['color']) && $this->_background['color']) {
567
                        $this->pdf->setFillColorArray($this->_background['color']);
568
                        $this->pdf->Rect(0, 0, $this->pdf->getW(), $this->pdf->getH(), 'F');
569
                    }
570
571
                    if (isset($this->_background['img']) && $this->_background['img']) {
572
                                            $this->pdf->Image($this->_background['img'], $this->_background['posX'], $this->_background['posY'], $this->_background['width']);
573
                    }
574
                }
575
576
                $this->_setPageHeader();
577
                $this->_setPageFooter();
578
            }
579
580
            $this->_setMargins();
581
            $this->pdf->setY($this->_margeTop);
582
583
            $this->_setNewPositionForNewLine($curr);
584
            $this->_maxH = 0;
585
        }
586
587
        /**
588
         * set the real margin, using the default margins and the page margins
589
         *
590
         * @access protected
591
         */
592
        protected function _setMargins()
593
        {
594
            // prepare the margins
595
            $this->_margeLeft   = $this->_defaultLeft + (isset($this->_background['left']) ? $this->_background['left'] : 0);
596
            $this->_margeRight  = $this->_defaultRight + (isset($this->_background['right']) ? $this->_background['right'] : 0);
597
            $this->_margeTop    = $this->_defaultTop + (isset($this->_background['top']) ? $this->_background['top'] : 0);
598
            $this->_margeBottom = $this->_defaultBottom + (isset($this->_background['bottom']) ? $this->_background['bottom'] : 0);
599
600
            // set the PDF margins
601
            $this->pdf->SetMargins($this->_margeLeft, $this->_margeTop, $this->_margeRight);
602
            $this->pdf->SetAutoPageBreak(false, $this->_margeBottom);
603
604
            // set the float Margins
605
            $this->_pageMarges = array();
606
            if ($this->_isInParagraph !== false) {
607
                $this->_pageMarges[floor($this->_margeTop * 100)] = array($this->_isInParagraph[0], $this->pdf->getW() - $this->_isInParagraph[1]);
608
            } else {
609
                $this->_pageMarges[floor($this->_margeTop * 100)] = array($this->_margeLeft, $this->pdf->getW() - $this->_margeRight);
610
            }
611
        }
612
613
        /**
614
         * add a debug step
615
         *
616
         * @access protected
617
         * @param  string  $name step name
618
         * @param  boolean $level (true=up, false=down, null=nothing to do)
619
         * @return $this
620
         */
621
        protected function _DEBUG_add($name, $level = null)
622
        {
623
            // if true : UP
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
624
            if ($level === true) $this->_debugLevel++;
625
626
            $name = str_repeat('  ', $this->_debugLevel).$name.($level === true ? ' Begin' : ($level === false ? ' End' : ''));
627
            $time  = microtime(true);
628
            $usage = ($this->_debugOkUsage ? memory_get_usage() : 0);
629
            $peak  = ($this->_debugOkPeak ? memory_get_peak_usage() : 0);
630
631
            $this->_DEBUG_stepline(
632
                $name,
633
                number_format(($time - $this->_debugStartTime) * 1000, 1, '.', ' ').' ms',
634
                number_format(($time - $this->_debugLastTime) * 1000, 1, '.', ' ').' ms',
635
                number_format($usage / 1024, 1, '.', ' ').' Ko',
636
                number_format($peak / 1024, 1, '.', ' ').' Ko'
637
            );
638
639
            $this->_debugLastTime = $time;
0 ignored issues
show
Documentation Bug introduced by
The property $_debugLastTime was declared of type integer, but $time is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
640
641
            // it false : DOWN
642
            if ($level === false) $this->_debugLevel--;
643
644
            return $this;
645
        }
646
647
        /**
648
         * display a debug line
649
         *
650
         *
651
         * @access protected
652
         * @param  string $name
653
         * @param  string $timeTotal
654
         * @param  string $timeStep
655
         * @param  string $memoryUsage
656
         * @param  string $memoryPeak
657
         */
658
        protected function _DEBUG_stepline($name, $timeTotal, $timeStep, $memoryUsage, $memoryPeak)
659
        {
660
            $txt = str_pad($name, 30, ' ', STR_PAD_RIGHT).
661
                    str_pad($timeTotal, 12, ' ', STR_PAD_LEFT).
662
                    str_pad($timeStep, 12, ' ', STR_PAD_LEFT).
663
                    str_pad($memoryUsage, 15, ' ', STR_PAD_LEFT).
664
                    str_pad($memoryPeak, 15, ' ', STR_PAD_LEFT);
665
666
            echo '<pre style="padding:0; margin:0">'.$txt.'</pre>';
667
        }
668
669
        /**
670
         * get the Min and Max X, for Y (use the float margins)
671
         *
672
         * @access protected
673
         * @param  float $y
674
         * @return array(float, float)
0 ignored issues
show
Documentation introduced by
The doc-type array(float, could not be parsed: Expected "|" or "end of type", but got "(" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
675
         */
676
        protected function _getMargins($y)
677
        {
678
            $y = floor($y * 100);
679
            $x = array($this->pdf->getlMargin(), $this->pdf->getW() - $this->pdf->getrMargin());
680
681
            foreach ($this->_pageMarges as $mY => $mX)
682
                if ($mY <= $y) $x = $mX;
683
684
            return $x;
685
        }
686
687
        /**
688
         * Add margins, for a float
689
         *
690
         * @access protected
691
         * @param  string $float (left / right)
692
         * @param  float  $xLeft
693
         * @param  float  $yTop
694
         * @param  float  $xRight
695
         * @param  float  $yBottom
696
         */
697
        protected function _addMargins($float, $xLeft, $yTop, $xRight, $yBottom)
698
        {
699
            // get the current float margins, for top and bottom
700
            $oldTop    = $this->_getMargins($yTop);
701
            $oldBottom = $this->_getMargins($yBottom);
702
703
            // update the top float margin
704
            if ($float == 'left' && $oldTop[0] < $xRight) $oldTop[0] = $xRight;
705
            if ($float == 'right' && $oldTop[1] > $xLeft)  $oldTop[1] = $xLeft;
706
707
            $yTop = floor($yTop * 100);
708
            $yBottom = floor($yBottom * 100);
709
710
            // erase all the float margins that are smaller than the new one
711
            foreach ($this->_pageMarges as $mY => $mX) {
712
                if ($mY < $yTop) continue;
713
                if ($mY > $yBottom) break;
714
                if ($float == 'left' && $this->_pageMarges[$mY][0] < $xRight)  unset($this->_pageMarges[$mY]);
715
                if ($float == 'right' && $this->_pageMarges[$mY][1] > $xLeft) unset($this->_pageMarges[$mY]);
716
            }
717
718
            // save the new Top and Bottom margins
719
            $this->_pageMarges[$yTop] = $oldTop;
720
            $this->_pageMarges[$yBottom] = $oldBottom;
721
722
            // sort the margins
723
            ksort($this->_pageMarges);
724
725
            // we are just after float
726
            $this->_isAfterFloat = true;
727
        }
728
729
        /**
730
         * Save old margins (push), and set new ones
731
         *
732
         * @access protected
733
         * @param  float  $ml left margin
734
         * @param  float  $mt top margin
735
         * @param  float  $mr right margin
736
         */
737
        protected function _saveMargin($ml, $mt, $mr)
738
        {
739
            // save old margins
740
            $this->_marges[] = array('l' => $this->pdf->getlMargin(), 't' => $this->pdf->gettMargin(), 'r' => $this->pdf->getrMargin(), 'page' => $this->_pageMarges);
741
742
            // set new ones
743
            $this->pdf->SetMargins($ml, $mt, $mr);
744
745
            // prepare for float margins
746
            $this->_pageMarges = array();
747
            $this->_pageMarges[floor($mt * 100)] = array($ml, $this->pdf->getW() - $mr);
748
        }
749
750
        /**
751
         * load the last saved margins (pop)
752
         *
753
         * @access protected
754
         */
755
        protected function _loadMargin()
756
        {
757
            $old = array_pop($this->_marges);
758
            if ($old) {
759
                $ml = $old['l'];
760
                $mt = $old['t'];
761
                $mr = $old['r'];
762
                $mP = $old['page'];
763
            } else {
764
                $ml = $this->_margeLeft;
765
                $mt = 0;
766
                $mr = $this->_margeRight;
767
                $mP = array($mt => array($ml, $this->pdf->getW() - $mr));
768
            }
769
770
            $this->pdf->SetMargins($ml, $mt, $mr);
771
            $this->_pageMarges = $mP;
772
        }
773
774
        /**
775
         * save the current maxs (push)
776
         *
777
         * @access protected
778
         */
779
        protected function _saveMax()
780
        {
781
            $this->_maxSave[] = array($this->_maxX, $this->_maxY, $this->_maxH, $this->_maxE);
782
        }
783
784
        /**
785
         * load the last saved current maxs (pop)
786
         *
787
         * @access protected
788
         */
789
        protected function _loadMax()
790
        {
791
            $old = array_pop($this->_maxSave);
792
793
            if ($old) {
794
                $this->_maxX = $old[0];
795
                $this->_maxY = $old[1];
796
                $this->_maxH = $old[2];
797
                $this->_maxE = $old[3];
798
            } else {
799
                $this->_maxX = 0;
800
                $this->_maxY = 0;
801
                $this->_maxH = 0;
802
                $this->_maxE = 0;
803
            }
804
        }
805
806
        /**
807
         * draw the PDF header with the HTML in page_header
808
         *
809
         * @access protected
810
         */
811
        protected function _setPageHeader()
812
        {
813
            if ( ! count($this->_subHEADER)) return false;
814
815
            $oldParsePos = $this->_parsePos;
816
            $oldParseCode = $this->parsingHtml->code;
817
818
            $this->_parsePos = 0;
819
            $this->parsingHtml->code = $this->_subHEADER;
820
            $this->_makeHTMLcode();
821
822
            $this->_parsePos = $oldParsePos;
823
            $this->parsingHtml->code = $oldParseCode;
824
        }
825
826
        /**
827
         * draw the PDF footer with the HTML in page_footer
828
         *
829
         * @access protected
830
         */
831
        protected function _setPageFooter()
832
        {
833
            if ( ! count($this->_subFOOTER)) return false;
834
835
            $oldParsePos = $this->_parsePos;
836
            $oldParseCode = $this->parsingHtml->code;
837
838
            $this->_parsePos = 0;
839
            $this->parsingHtml->code = $this->_subFOOTER;
840
            $this->_isInFooter = true;
841
            $this->_makeHTMLcode();
842
            $this->_isInFooter = false;
843
844
            $this->_parsePos = $oldParsePos;
845
            $this->parsingHtml->code = $oldParseCode;
846
        }
847
848
        /**
849
         * new line, with a specific height
850
         *
851
         * @access protected
852
         * @param float   $h
853
         * @param integer $curr real current position in the text, if new line in the write of a text
854
         */
855
        protected function _setNewLine($h, $curr = null)
856
        {
857
            $this->pdf->Ln($h);
858
            $this->_setNewPositionForNewLine($curr);
859
        }
860
861
        /**
862
         * calculate the start position of the next line,  depending on the text-align
863
         *
864
         * @access protected
865
         * @param  integer $curr real current position in the text, if new line in the write of a text
866
         */
867
        protected function _setNewPositionForNewLine($curr = null)
868
        {
869
            // get the margins for the current line
870
            list($lx, $rx) = $this->_getMargins($this->pdf->getY());
871
            $this->pdf->setX($lx);
872
            $wMax = $rx - $lx;
873
            $this->_currentH = 0;
874
875
            // if subPart => return because align left
876
            if ($this->_subPart || $this->_isSubPart || $this->_isForOneLine) {
877
                $this->pdf->setWordSpacing(0);
878
                return null;
879
            }
880
881
            // create the sub object
882
            $sub = null;
883
            $this->_createSubHTML($sub);
884
            $sub->_saveMargin(0, 0, $sub->pdf->getW() - $wMax);
885
            $sub->_isForOneLine = true;
886
            $sub->_parsePos = $this->_parsePos;
887
            $sub->parsingHtml->code = $this->parsingHtml->code;
888
889
            // if $curr => adapt the current position of the parsing
890
            if ($curr !== null && $sub->parsingHtml->code[$this->_parsePos]['name'] == 'write') {
891
                $txt = $sub->parsingHtml->code[$this->_parsePos]['param']['txt'];
892
                $txt = str_replace('[[page_cu]]', $sub->pdf->getMyNumPage($this->_page), $txt);
893
                $sub->parsingHtml->code[$this->_parsePos]['param']['txt'] = substr($txt, $curr + 1);
894
            } else
895
                $sub->_parsePos++;
896
897
            // for each element of the parsing => load the action
898
            $res = null;
899
            for ($sub->_parsePos; $sub->_parsePos < count($sub->parsingHtml->code); $sub->_parsePos++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
900
                $action = $sub->parsingHtml->code[$sub->_parsePos];
901
                $res = $sub->_executeAction($action);
902
                if ( ! $res) break;
903
            }
904
905
            $w = $sub->_maxX; // max width
906
            $h = $sub->_maxH; // max height
907
            $e = ($res === null ? $sub->_maxE : 0); // maxnumber of elemets on the line
908
909
            // destroy the sub HTML
910
            $this->_destroySubHTML($sub);
911
912
            // adapt the start of the line, depending on the text-align
913
            if ($this->parsingCss->value['text-align'] == 'center')
914
                $this->pdf->setX(($rx + $this->pdf->getX() - $w) * 0.5 - 0.01);
915
            else if ($this->parsingCss->value['text-align'] == 'right')
916
                $this->pdf->setX($rx - $w - 0.01);
917
            else
918
                $this->pdf->setX($lx);
919
920
            // set the height of the line
921
            $this->_currentH = $h;
922
923
            // if justify => set the word spacing
924
            if ($this->parsingCss->value['text-align'] == 'justify' && $e > 1) {
925
                $this->pdf->setWordSpacing(($wMax - $w) / ($e - 1));
926
            } else {
927
                $this->pdf->setWordSpacing(0);
928
            }
929
        }
930
931
        /**
932
         * prepare HTML2PDF::$_subobj (used for create the sub HTML2PDF objects
933
         *
934
         * @access protected
935
         */
936
        protected function _prepareSubObj()
937
        {
938
            $pdf = null;
939
940
            // create the sub object
941
            HTML2PDF::$_subobj = new HTML2PDF(
942
                                        $this->_orientation,
943
                                        $this->_format,
944
                                        $this->_langue,
945
                                        $this->_unicode,
946
                                        $this->_encoding,
947
                                        array($this->_defaultLeft, $this->_defaultTop, $this->_defaultRight, $this->_defaultBottom)
948
                                    );
949
950
            // init
951
            HTML2PDF::$_subobj->setTestTdInOnePage($this->_testTdInOnepage);
952
            HTML2PDF::$_subobj->setTestIsImage($this->_testIsImage);
953
            HTML2PDF::$_subobj->setTestIsDeprecated($this->_testIsDeprecated);
954
            HTML2PDF::$_subobj->setDefaultFont($this->_defaultFont);
955
            HTML2PDF::$_subobj->parsingCss->css            = &$this->parsingCss->css;
956
            HTML2PDF::$_subobj->parsingCss->cssKeys        = &$this->parsingCss->cssKeys;
957
958
            // clone font from the original PDF
959
            HTML2PDF::$_subobj->pdf->cloneFontFrom($this->pdf);
960
961
            // remove the link to the parent
962
            HTML2PDF::$_subobj->parsingCss->setPdfParent($pdf);
963
        }
964
965
        /**
966
         * create a sub HTML2PDF, to calculate the multi-tables
967
         *
968
         * @access protected
969
         * @param  &HTML2PDF $subHtml sub HTML2PDF to create
0 ignored issues
show
Documentation introduced by
The doc-type &HTML2PDF could not be parsed: Unknown type name "&HTML2PDF" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
970
         * @param  integer   $cellmargin if in a TD : cellmargin of this td
971
         */
972
        protected function _createSubHTML(&$subHtml, $cellmargin = 0)
973
        {
974
            // prepare the subObject, if never prepare before
975
            if (HTML2PDF::$_subobj === null) {
976
                $this->_prepareSubObj();
977
            }
978
979
            // calculate the width to use
980
            if ($this->parsingCss->value['width']) {
981
                $marge = $cellmargin * 2;
982
                $marge += $this->parsingCss->value['padding']['l'] + $this->parsingCss->value['padding']['r'];
983
                $marge += $this->parsingCss->value['border']['l']['width'] + $this->parsingCss->value['border']['r']['width'];
984
                $marge = $this->pdf->getW() - $this->parsingCss->value['width'] + $marge;
985
            } else {
986
                $marge = $this->_margeLeft + $this->_margeRight;
987
            }
988
989
            // BUGFIX : we have to call the method, because of a bug in php 5.1.6
990
            HTML2PDF::$_subobj->pdf->getPage();
991
992
            // clone the sub oject
993
            $subHtml = clone HTML2PDF::$_subobj;
994
            $subHtml->parsingCss->table = $this->parsingCss->table;
995
            $subHtml->parsingCss->value = $this->parsingCss->value;
996
            $subHtml->initSubHtml(
997
                $this->_format,
998
                $this->_orientation,
999
                $marge,
0 ignored issues
show
Documentation introduced by
$marge is of type double|integer, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1000
                $this->_page,
1001
                $this->_defList,
1002
                $this->pdf->getMyLastPageGroup(),
1003
                $this->pdf->getMyLastPageGroupNb()
1004
            );
1005
        }
1006
1007
        /**
1008
         * destroy a subHTML2PDF
1009
         *
1010
         * @access protected
1011
         */
1012
        protected function _destroySubHTML(&$subHtml)
1013
        {
1014
            unset($subHtml);
1015
            $subHtml = null;
1016
        }
1017
1018
        /**
1019
         * Convert a arabic number in roman number
1020
         *
1021
         * @access protected
1022
         * @param  integer $nbArabic
1023
         * @return string  $nbRoman
1024
         */
1025
        protected function _listeArab2Rom($nbArabic)
1026
        {
1027
            $nbBaseTen = array('I', 'X', 'C', 'M');
1028
            $nbBaseFive = array('V', 'L', 'D');
1029
            $nbRoman = '';
1030
1031
            if ($nbArabic < 1)    return $nbArabic;
1032
            if ($nbArabic > 3999) return $nbArabic;
1033
1034
            for ($i = 3; $i >= 0; $i--) {
1035
                $chiffre = floor($nbArabic / pow(10, $i));
1036
                if ($chiffre >= 1) {
1037
                    $nbArabic = $nbArabic - $chiffre * pow(10, $i);
1038
                    if ($chiffre <= 3) {
1039 View Code Duplication
                        for ($j = $chiffre; $j >= 1; $j--) {
1040
                            $nbRoman = $nbRoman.$nbBaseTen[$i];
1041
                        }
1042
                    } else if ($chiffre == 9) {
1043
                        $nbRoman = $nbRoman.$nbBaseTen[$i].$nbBaseTen[$i + 1];
1044
                    } else if ($chiffre == 4) {
1045
                    $nbRoman = $nbRoman.$nbBaseTen[$i].$nbBaseFive[$i];
1046
                    } else {
1047
                        $nbRoman = $nbRoman.$nbBaseFive[$i];
1048 View Code Duplication
                        for ($j = $chiffre - 5; $j >= 1; $j--) {
1049
                            $nbRoman = $nbRoman.$nbBaseTen[$i];
1050
                        }
1051
                    }
1052
                }
1053
            }
1054
            return $nbRoman;
1055
        }
1056
1057
        /**
1058
         * add a LI to the current level
1059
         *
1060
         * @access protected
1061
         */
1062
        protected function _listeAddLi()
1063
        {
1064
            $this->_defList[count($this->_defList) - 1]['nb']++;
1065
        }
1066
1067
        /**
1068
         * get the width to use for the column of the list
1069
         *
1070
         * @access protected
1071
         * @return string $width
1072
         */
1073
        protected function _listeGetWidth()
1074
        {
1075
            return '7mm';
1076
        }
1077
1078
        /**
1079
         * get the padding to use for the column of the list
1080
         *
1081
         * @access protected
1082
         * @return string $padding
1083
         */
1084
        protected function _listeGetPadding()
1085
        {
1086
            return '1mm';
1087
        }
1088
1089
        /**
1090
         * get the information of the li on the current level
1091
         *
1092
         * @access protected
1093
         * @return array(fontName, small size, string)
0 ignored issues
show
Documentation introduced by
The doc-type array(fontName, could not be parsed: Expected "|" or "end of type", but got "(" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
1094
         */
1095
        protected function _listeGetLi()
1096
        {
1097
            $im = $this->_defList[count($this->_defList) - 1]['img'];
1098
            $st = $this->_defList[count($this->_defList) - 1]['style'];
1099
            $nb = $this->_defList[count($this->_defList) - 1]['nb'];
1100
            $up = (substr($st, 0, 6) == 'upper-');
1101
1102
            if ($im) {
1103
            	return array(false, false, $im);
1104
            }
1105
1106
            switch ($st)
1107
            {
1108
                case 'none':
1109
                    return array('helvetica', true, ' ');
1110
1111
                case 'upper-alpha':
1112
                case 'lower-alpha':
1113
                    $str = '';
1114
                    while ($nb > 26) {
1115
                        $str = chr(96 + $nb % 26).$str;
1116
                        $nb = floor($nb / 26);
1117
                    }
1118
                    $str = chr(96 + $nb).$str;
1119
1120
                    return array('helvetica', false, ($up ? strtoupper($str) : $str).'.');
1121
1122
                case 'upper-roman':
1123
                case 'lower-roman':
1124
                    $str = $this->_listeArab2Rom($nb);
1125
1126
                    return array('helvetica', false, ($up ? strtoupper($str) : $str).'.');
1127
1128
                case 'decimal':
1129
                    return array('helvetica', false, $nb.'.');
1130
1131
                case 'square':
1132
                    return array('zapfdingbats', true, chr(110));
1133
1134
                case 'circle':
1135
                    return array('zapfdingbats', true, chr(109));
1136
1137
                case 'disc':
1138
                default:
1139
                    return array('zapfdingbats', true, chr(108));
1140
            }
1141
        }
1142
1143
        /**
1144
         * add a level to the list
1145
         *
1146
         * @access protected
1147
         * @param  string $type  : ul, ol
1148
         * @param  string $style : lower-alpha, ...
1149
         * @param  string $img
1150
         */
1151
        protected function _listeAddLevel($type = 'ul', $style = '', $img = null)
1152
        {
1153
            // get the url of the image, if we want to use a image
1154
            if ($img) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $img of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
1155
                if (preg_match('/^url\(([^)]+)\)$/isU', trim($img), $match)) {
1156
                    $img = $match[1];
1157
                } else {
1158
                    $img = null;
1159
                }
1160
            } else {
1161
                $img = null;
1162
            }
1163
1164
            // prepare the datas
1165
            if ( ! in_array($type, array('ul', 'ol'))) $type = 'ul';
1166
            if ( ! in_array($style, array('lower-alpha', 'upper-alpha', 'upper-roman', 'lower-roman', 'decimal', 'square', 'circle', 'disc', 'none'))) $style = '';
1167
1168
            if ( ! $style) {
1169
                if ($type == 'ul')    $style = 'disc';
1170
                else                $style = 'decimal';
1171
            }
1172
1173
            // add the new level
1174
            $this->_defList[count($this->_defList)] = array('style' => $style, 'nb' => 0, 'img' => $img);
1175
        }
1176
1177
        /**
1178
         * remove a level to the list
1179
         *
1180
         * @access protected
1181
         */
1182
        protected function _listeDelLevel()
1183
        {
1184
            if (count($this->_defList)) {
1185
                unset($this->_defList[count($this->_defList) - 1]);
1186
                $this->_defList = array_values($this->_defList);
1187
            }
1188
        }
1189
1190
        /**
1191
         * execute the actions to convert the html
1192
         *
1193
         * @access protected
1194
         */
1195
        protected function _makeHTMLcode()
1196
        {
1197
            // foreach elements of the parsing
1198
            for ($this->_parsePos = 0; $this->_parsePos < count($this->parsingHtml->code); $this->_parsePos++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
1199
1200
                // get the action to do
1201
                $action = $this->parsingHtml->code[$this->_parsePos];
1202
1203
                // if it is a opening of table / ul / ol
1204
                if (in_array($action['name'], array('table', 'ul', 'ol')) && ! $action['close']) {
1205
1206
                    //  we will work as a sub HTML to calculate the size of the element
1207
                    $this->_subPart = true;
1208
1209
                    // get the name of the opening tag
1210
                    $tagOpen = $action['name'];
1211
1212
                    // save the actual pos on the parsing
1213
                    $this->_tempPos = $this->_parsePos;
1214
1215
                    // foreach elements, while we are in the opened tag
1216
                    while (isset($this->parsingHtml->code[$this->_tempPos]) && ! ($this->parsingHtml->code[$this->_tempPos]['name'] == $tagOpen && $this->parsingHtml->code[$this->_tempPos]['close'])) {
1217
                        // make the action
1218
                        $this->_executeAction($this->parsingHtml->code[$this->_tempPos]);
1219
                        $this->_tempPos++;
1220
                    }
1221
1222
                    // execute the closure of the tag
1223
                    if (isset($this->parsingHtml->code[$this->_tempPos])) {
1224
                        $this->_executeAction($this->parsingHtml->code[$this->_tempPos]);
1225
                    }
1226
1227
                    // end of the sub part
1228
                    $this->_subPart = false;
1229
                }
1230
1231
                // execute the action
1232
                $this->_executeAction($action);
1233
            }
1234
        }
1235
1236
        /**
1237
         * execute the action from the parsing
1238
         *
1239
         * @access protected
1240
         * @param  array $action
1241
         */
1242
        protected function _executeAction($action)
1243
        {
1244
            // name of the action
1245
            $fnc = ($action['close'] ? '_tag_close_' : '_tag_open_').strtoupper($action['name']);
1246
1247
            // parameters of the action
1248
            $param = $action['param'];
1249
1250
            // if it the first action of the first page, and if it is not a open tag of PAGE => create the new page
1251
            if ($fnc != '_tag_open_PAGE' && $this->_firstPage) {
1252
                $this->_setNewPage();
1253
            }
1254
1255
            // the action must exist
1256
            if ( ! is_callable(array(&$this, $fnc))) {
1257
                throw new HTML2PDF_exception(1, strtoupper($action['name']), $this->parsingHtml->getHtmlErrorCode($action['html_pos']));
1258
            }
1259
1260
            // lauch the action
1261
            $res = $this->{$fnc}($param);
1262
1263
            // save the name of the action
1264
            $this->_previousCall = $fnc;
1265
1266
            // return the result
1267
            return $res;
1268
        }
1269
1270
        /**
1271
         * get the position of the element on the current line, depending on his height
1272
         *
1273
         * @access protected
1274
         * @param  float $h
1275
         * @return float
1276
         */
1277
        protected function _getElementY($h)
1278
        {
1279
            if ($this->_subPart || $this->_isSubPart || ! $this->_currentH || $this->_currentH < $h)
1280
                return 0;
1281
1282
            return ($this->_currentH - $h) * 0.8;
1283
        }
1284
1285
        /**
1286
         * make a break line
1287
         *
1288
         * @access protected
1289
         * @param  float $h current line height
1290
         * @param  integer $curr real current position in the text, if new line in the write of a text
1291
         */
1292
        protected function _makeBreakLine($h, $curr = null)
1293
        {
1294
            if ($h) {
1295
                if (($this->pdf->getY() + $h < $this->pdf->getH() - $this->pdf->getbMargin()) || $this->_isInOverflow || $this->_isInFooter)
1296
                    $this->_setNewLine($h, $curr);
1297
                else
1298
                    $this->_setNewPage(null, '', null, $curr);
1299
            } else {
1300
                $this->_setNewPositionForNewLine($curr);
1301
            }
1302
1303
            $this->_maxH = 0;
1304
            $this->_maxE = 0;
1305
        }
1306
1307
        /**
1308
         * display a image
1309
         *
1310
         * @access protected
1311
         * @param  string $src
1312
         * @param  boolean $subLi if true=image of a list
1313
         * @return boolean depending on "isForOneLine"
1314
         */
1315
        protected function _drawImage($src, $subLi = false)
1316
        {
1317
            // get the size of the image
1318
            // WARNING : if URL, "allow_url_fopen" must turned to "on" in php.ini
1319
1320
            $infos = @getimagesize($src);
1321
1322
            // if the image does not exist, or can not be loaded
1323
            if (count($infos) < 2) {
1324
                // if the test is activ => exception
1325
                if ($this->_testIsImage) {
1326
                    throw new HTML2PDF_exception(6, $src);
1327
                }
1328
1329
                // else, display a gray rectangle
1330
                $src = null;
1331
                $infos = array(16, 16);
1332
            }
1333
1334
            // convert the size of the image in the unit of the PDF
1335
            $imageWidth = $infos[0] / $this->pdf->getK();
1336
            $imageHeight = $infos[1] / $this->pdf->getK();
1337
1338
            // calculate the size from the css style
1339
            if ($this->parsingCss->value['width'] && $this->parsingCss->value['height']) {
1340
                $w = $this->parsingCss->value['width'];
1341
                $h = $this->parsingCss->value['height'];
1342
            } else if ($this->parsingCss->value['width']) {
1343
                $w = $this->parsingCss->value['width'];
1344
                $h = $imageHeight * $w / $imageWidth;
1345
            } else if ($this->parsingCss->value['height']) {
1346
                $h = $this->parsingCss->value['height'];
1347
                $w = $imageWidth * $h / $imageHeight;
1348
            } else {
1349
                // convert px to pt
1350
                $w = 72. / 96. * $imageWidth;
1351
                $h = 72. / 96. * $imageHeight;
1352
            }
1353
1354
            // are we in a float
1355
            $float = $this->parsingCss->getFloat();
1356
1357
            // if we are in a float, but if something else if on the line => Break Line
1358
            if ($float && $this->_maxH) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $float of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
1359
                // make the break line (false if we are in "_isForOneLine" mode)
1360
                if ( ! $this->_tag_open_BR(array())) {
1361
                    return false;
1362
                }
1363
            }
1364
1365
            // position of the image
1366
            $x = $this->pdf->getX();
1367
            $y = $this->pdf->getY();
1368
1369
            // if the image can not be put on the current line => new line
1370
            if ( ! $float && ($x + $w > $this->pdf->getW() - $this->pdf->getrMargin()) && $this->_maxH) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $float of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
1371
                if ($this->_isForOneLine) {
1372
                    return false;
1373
                }
1374
1375
                // set the new line
1376
                $hnl = max($this->_maxH, $this->parsingCss->getLineHeight());
1377
                $this->_setNewLine($hnl);
1378
1379
                // get the new position
1380
                $x = $this->pdf->getX();
1381
                $y = $this->pdf->getY();
1382
            }
1383
1384
            // if the image can not be put on the current page
1385
            if (($y + $h > $this->pdf->getH() - $this->pdf->getbMargin()) && ! $this->_isInOverflow) {
1386
                // new page
1387
                $this->_setNewPage();
1388
1389
                // get the new position
1390
                $x = $this->pdf->getX();
1391
                $y = $this->pdf->getY();
1392
            }
1393
1394
            // correction for display the image of a list
1395
            $hT = 0.80 * $this->parsingCss->value['font-size'];
1396
            if ($subLi && $h < $hT) {
1397
                $y += ($hT - $h);
1398
            }
1399
1400
            // add the margin top
1401
            $yc = $y - $this->parsingCss->value['margin']['t'];
1402
1403
            // get the width and the position of the parent
1404
            $old = $this->parsingCss->getOldValues();
1405
            if ($old['width']) {
1406
                $parentWidth = $old['width'];
1407
                $parentX = $x;
1408
            } else {
1409
                $parentWidth = $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin();
1410
                $parentX = $this->pdf->getlMargin();
1411
            }
1412
1413
            // if we are in a gloat => adapt the parent position and width
1414
            if ($float) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $float of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
1415
                list($lx, $rx) = $this->_getMargins($yc);
1416
                $parentX = $lx;
1417
                $parentWidth = $rx - $lx;
1418
            }
1419
1420
            // calculate the position of the image, if align to the right
1421
            if ($parentWidth > $w && $float != 'left') {
1422
                if ($float == 'right' || $this->parsingCss->value['text-align'] == 'li_right')    $x = $parentX + $parentWidth - $w - $this->parsingCss->value['margin']['r'] - $this->parsingCss->value['margin']['l'];
1423
            }
1424
1425
            // display the image
1426
            if ( ! $this->_subPart && ! $this->_isSubPart) {
1427
                if ($src) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $src of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
1428
                    $this->pdf->Image($src, $x, $y, $w, $h, '', $this->_isInLink);
1429
                } else {
1430
                    // rectangle if the image can not be loaded
1431
                    $this->pdf->setFillColorArray(array(240, 220, 220));
1432
                    $this->pdf->Rect($x, $y, $w, $h, 'F');
1433
                }
1434
            }
1435
1436
            // apply the margins
1437
            $x -= $this->parsingCss->value['margin']['l'];
1438
            $y -= $this->parsingCss->value['margin']['t'];
1439
            $w += $this->parsingCss->value['margin']['l'] + $this->parsingCss->value['margin']['r'];
1440
            $h += $this->parsingCss->value['margin']['t'] + $this->parsingCss->value['margin']['b'];
1441
1442
            if ($float == 'left') {
1443
                // save the current max
1444
                $this->_maxX = max($this->_maxX, $x + $w);
0 ignored issues
show
Documentation Bug introduced by
It seems like max($this->_maxX, $x + $w) can also be of type double. However, the property $_maxX is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
1445
                $this->_maxY = max($this->_maxY, $y + $h);
0 ignored issues
show
Documentation Bug introduced by
It seems like max($this->_maxY, $y + $h) can also be of type double. However, the property $_maxY is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
1446
1447
                // add the image to the margins
1448
                $this->_addMargins($float, $x, $y, $x + $w, $y + $h);
1449
1450
                // get the new position
1451
                list($lx, $rx) = $this->_getMargins($yc);
0 ignored issues
show
Unused Code introduced by
The assignment to $rx is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
1452
                $this->pdf->setXY($lx, $yc);
1453
            } else if ($float == 'right') {
1454
                // save the current max. We don't save the X because it is not the real max of the line
1455
                $this->_maxY = max($this->_maxY, $y + $h);
1456
1457
                // add the image to the margins
1458
                $this->_addMargins($float, $x, $y, $x + $w, $y + $h);
1459
1460
                // get the new position
1461
                list($lx, $rx) = $this->_getMargins($yc);
0 ignored issues
show
Unused Code introduced by
The assignment to $rx is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
1462
                $this->pdf->setXY($lx, $yc);
1463
            } else {
1464
                // set the new position at the end of the image
1465
                $this->pdf->setX($x + $w);
1466
1467
                // save the current max
1468
                $this->_maxX = max($this->_maxX, $x + $w);
1469
                $this->_maxY = max($this->_maxY, $y + $h);
1470
                $this->_maxH = max($this->_maxH, $h);
1471
            }
1472
1473
            return true;
1474
        }
1475
1476
        /**
1477
         * draw a rectangle
1478
         *
1479
         * @access protected
1480
         * @param  float $x
1481
         * @param  float $y
1482
         * @param  float $w
1483
         * @param  float $h
1484
         * @param  array $border
1485
         * @param  float $padding - internal marge of the rectanble => not used, but...
1486
         * @param  float $margin  - external marge of the rectanble
1487
         * @param  array $background
1488
         * @return boolean
1489
         */
1490
        protected function _drawRectangle($x, $y, $w, $h, $border, $padding, $margin, $background)
0 ignored issues
show
Unused Code introduced by
The parameter $padding is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1491
        {
1492
            // if we are in a subpart or if height is null => return false
1493
            if ($this->_subPart || $this->_isSubPart || $h === null) return false;
1494
1495
            // add the margin
1496
            $x += $margin;
1497
            $y += $margin;
1498
            $w -= $margin * 2;
1499
            $h -= $margin * 2;
1500
1501
            // get the radius of the border
1502
            $outTL = $border['radius']['tl'];
1503
            $outTR = $border['radius']['tr'];
1504
            $outBR = $border['radius']['br'];
1505
            $outBL = $border['radius']['bl'];
1506
1507
            // prepare the out radius
1508
            $outTL = ($outTL[0] && $outTL[1]) ? $outTL : null;
1509
            $outTR = ($outTR[0] && $outTR[1]) ? $outTR : null;
1510
            $outBR = ($outBR[0] && $outBR[1]) ? $outBR : null;
1511
            $outBL = ($outBL[0] && $outBL[1]) ? $outBL : null;
1512
1513
            // prepare the in radius
1514
            $inTL = $outTL;
1515
            $inTR = $outTR;
1516
            $inBR = $outBR;
1517
            $inBL = $outBL;
1518
1519 View Code Duplication
            if (is_array($inTL)) {
1520
                $inTL[0] -= $border['l']['width'];
1521
                $inTL[1] -= $border['t']['width'];
1522
            }
1523 View Code Duplication
            if (is_array($inTR)) {
1524
                $inTR[0] -= $border['r']['width'];
1525
                $inTR[1] -= $border['t']['width'];
1526
            }
1527 View Code Duplication
            if (is_array($inBR)) {
1528
                $inBR[0] -= $border['r']['width'];
1529
                $inBR[1] -= $border['b']['width'];
1530
            }
1531 View Code Duplication
            if (is_array($inBL)) {
1532
                $inBL[0] -= $border['l']['width'];
1533
                $inBL[1] -= $border['b']['width'];
1534
            }
1535
1536 View Code Duplication
            if ($inTL[0] <= 0 || $inTL[1] <= 0) $inTL = null;
1537 View Code Duplication
            if ($inTR[0] <= 0 || $inTR[1] <= 0) $inTR = null;
1538 View Code Duplication
            if ($inBR[0] <= 0 || $inBR[1] <= 0) $inBR = null;
1539 View Code Duplication
            if ($inBL[0] <= 0 || $inBL[1] <= 0) $inBL = null;
1540
1541
            // prepare the background color
1542
            $pdfStyle = '';
1543
            if ($background['color']) {
1544
                $this->pdf->setFillColorArray($background['color']);
1545
                $pdfStyle .= 'F';
1546
            }
1547
1548
            // if we have a background to fill => fill it with a path (because of the radius)
1549
            if ($pdfStyle) {
1550
                $this->pdf->clippingPathStart($x, $y, $w, $h, $outTL, $outTR, $outBL, $outBR);
1551
                $this->pdf->Rect($x, $y, $w, $h, $pdfStyle);
1552
                $this->pdf->clippingPathStop();
1553
            }
1554
1555
            // prepare the background image
1556
            if ($background['image']) {
1557
                $iName      = $background['image'];
1558
                $iPosition  = $background['position'] !== null ? $background['position'] : array(0, 0);
1559
                $iRepeat    = $background['repeat'] !== null ? $background['repeat'] : array(true, true);
1560
1561
                // size of the background without the borders
1562
                $bX = $x;
1563
                $bY = $y;
1564
                $bW = $w;
1565
                $bH = $h;
1566
1567
                if ($border['b']['width']) {
1568
                    $bH -= $border['b']['width'];
1569
                }
1570
                if ($border['l']['width']) {
1571
                    $bW -= $border['l']['width'];
1572
                    $bX += $border['l']['width'];
1573
                }
1574
                if ($border['t']['width']) {
1575
                    $bH -= $border['t']['width'];
1576
                    $bY += $border['t']['width'];
1577
                }
1578
                if ($border['r']['width']) {
1579
                    $bW -= $border['r']['width'];
1580
                }
1581
1582
                // get the size of the image
1583
                // WARNING : if URL, "allow_url_fopen" must turned to "on" in php.ini
1584
                $imageInfos = @getimagesize($iName);
1585
1586
                // if the image can not be loaded
1587
                if (count($imageInfos) < 2) {
1588
                    if ($this->_testIsImage) {
1589
                        throw new HTML2PDF_exception(6, $iName);
1590
                    }
1591
                } else {
1592
                    // convert the size of the image from pixel to the unit of the PDF
1593
                    $imageWidth = 72. / 96. * $imageInfos[0] / $this->pdf->getK();
1594
                    $imageHeight = 72. / 96. * $imageInfos[1] / $this->pdf->getK();
1595
1596
                    // prepare the position of the backgroung
1597 View Code Duplication
                    if ($iRepeat[0]) $iPosition[0] = $bX;
1598
                    else if (preg_match('/^([-]?[0-9\.]+)%/isU', $iPosition[0], $match)) $iPosition[0] = $bX + $match[1] * ($bW - $imageWidth) / 100;
1599
                    else $iPosition[0] = $bX + $iPosition[0];
1600
1601 View Code Duplication
                    if ($iRepeat[1]) $iPosition[1] = $bY;
1602
                    else if (preg_match('/^([-]?[0-9\.]+)%/isU', $iPosition[1], $match)) $iPosition[1] = $bY + $match[1] * ($bH - $imageHeight) / 100;
1603
                    else $iPosition[1] = $bY + $iPosition[1];
1604
1605
                    $imageXmin = $bX;
1606
                    $imageXmax = $bX + $bW;
1607
                    $imageYmin = $bY;
1608
                    $imageYmax = $bY + $bH;
1609
1610
                    if ( ! $iRepeat[0] && ! $iRepeat[1]) {
1611
                        $imageXmin = $iPosition[0]; $imageXmax = $iPosition[0] + $imageWidth;
1612
                        $imageYmin = $iPosition[1]; $imageYmax = $iPosition[1] + $imageHeight;
1613
                    } else if ($iRepeat[0] && ! $iRepeat[1]) {
1614
                        $imageYmin = $iPosition[1]; $imageYmax = $iPosition[1] + $imageHeight;
1615
                    } else if ( ! $iRepeat[0] && $iRepeat[1]) {
1616
                        $imageXmin = $iPosition[0]; $imageXmax = $iPosition[0] + $imageWidth;
1617
                    }
1618
1619
                    // build the path to display the image (because of radius)
1620
                    $this->pdf->clippingPathStart($bX, $bY, $bW, $bH, $inTL, $inTR, $inBL, $inBR);
1621
1622
                    // repeat the image
1623
                    for ($iY = $imageYmin; $iY < $imageYmax; $iY += $imageHeight) {
1624
                        for ($iX = $imageXmin; $iX < $imageXmax; $iX += $imageWidth) {
1625
                            $cX = null;
1626
                            $cY = null;
1627
                            $cW = $imageWidth;
1628
                            $cH = $imageHeight;
1629
                            if ($imageYmax - $iY < $imageHeight) {
1630
                                $cX = $iX;
1631
                                $cY = $iY;
1632
                                $cH = $imageYmax - $iY;
1633
                            }
1634
                            if ($imageXmax - $iX < $imageWidth) {
1635
                                $cX = $iX;
1636
                                $cY = $iY;
1637
                                $cW = $imageXmax - $iX;
1638
                            }
1639
1640
                            $this->pdf->Image($iName, $iX, $iY, $imageWidth, $imageHeight, '', '');
1641
                        }
1642
                    }
1643
1644
                    // end of the path
1645
                    $this->pdf->clippingPathStop();
1646
                }
1647
            }
1648
1649
            // adding some loose (0.01mm)
1650
            $loose = 0.01;
1651
            $x -= $loose;
1652
            $y -= $loose;
1653
            $w += 2. * $loose;
1654
            $h += 2. * $loose;
1655
            if ($border['l']['width']) $border['l']['width'] += 2. * $loose;
1656
            if ($border['t']['width']) $border['t']['width'] += 2. * $loose;
1657
            if ($border['r']['width']) $border['r']['width'] += 2. * $loose;
1658
            if ($border['b']['width']) $border['b']['width'] += 2. * $loose;
1659
1660
            // prepare the test on borders
1661
            $testBl = ($border['l']['width'] && $border['l']['color'][0] !== null);
1662
            $testBt = ($border['t']['width'] && $border['t']['color'][0] !== null);
1663
            $testBr = ($border['r']['width'] && $border['r']['color'][0] !== null);
1664
            $testBb = ($border['b']['width'] && $border['b']['color'][0] !== null);
1665
1666
            // draw the radius bottom-left
1667 View Code Duplication
            if (is_array($outBL) && ($testBb || $testBl)) {
1668
                if ($inBL) {
1669
                    $courbe = array();
1670
                    $courbe[] = $x + $outBL[0]; $courbe[] = $y + $h;
1671
                    $courbe[] = $x; $courbe[] = $y + $h - $outBL[1];
1672
                    $courbe[] = $x + $outBL[0]; $courbe[] = $y + $h - $border['b']['width'];
1673
                    $courbe[] = $x + $border['l']['width']; $courbe[] = $y + $h - $outBL[1];
1674
                    $courbe[] = $x + $outBL[0]; $courbe[] = $y + $h - $outBL[1];
1675
                } else {
1676
                    $courbe = array();
1677
                    $courbe[] = $x + $outBL[0]; $courbe[] = $y + $h;
1678
                    $courbe[] = $x; $courbe[] = $y + $h - $outBL[1];
1679
                    $courbe[] = $x + $border['l']['width']; $courbe[] = $y + $h - $border['b']['width'];
1680
                    $courbe[] = $x + $outBL[0]; $courbe[] = $y + $h - $outBL[1];
1681
                }
1682
                $this->_drawCurve($courbe, $border['l']['color']);
1683
            }
1684
1685
            // draw the radius left-top
1686
            if (is_array($outTL) && ($testBt || $testBl)) {
1687
                if ($inTL) {
1688
                    $courbe = array();
1689
                    $courbe[] = $x; $courbe[] = $y + $outTL[1];
1690
                    $courbe[] = $x + $outTL[0]; $courbe[] = $y;
1691
                    $courbe[] = $x + $border['l']['width']; $courbe[] = $y + $outTL[1];
1692
                    $courbe[] = $x + $outTL[0]; $courbe[] = $y + $border['t']['width'];
1693
                    $courbe[] = $x + $outTL[0]; $courbe[] = $y + $outTL[1];
1694
                } else {
1695
                    $courbe = array();
1696
                    $courbe[] = $x; $courbe[] = $y + $outTL[1];
1697
                    $courbe[] = $x + $outTL[0]; $courbe[] = $y;
1698
                    $courbe[] = $x + $border['l']['width']; $courbe[] = $y + $border['t']['width'];
1699
                    $courbe[] = $x + $outTL[0]; $courbe[] = $y + $outTL[1];
1700
                }
1701
                $this->_drawCurve($courbe, $border['t']['color']);
1702
            }
1703
1704
            // draw the radius top-right
1705 View Code Duplication
            if (is_array($outTR) && ($testBt || $testBr)) {
1706
                if ($inTR) {
1707
                    $courbe = array();
1708
                    $courbe[] = $x + $w - $outTR[0]; $courbe[] = $y;
1709
                    $courbe[] = $x + $w; $courbe[] = $y + $outTR[1];
1710
                    $courbe[] = $x + $w - $outTR[0]; $courbe[] = $y + $border['t']['width'];
1711
                    $courbe[] = $x + $w - $border['r']['width']; $courbe[] = $y + $outTR[1];
1712
                    $courbe[] = $x + $w - $outTR[0]; $courbe[] = $y + $outTR[1];
1713
                } else {
1714
                    $courbe = array();
1715
                    $courbe[] = $x + $w - $outTR[0]; $courbe[] = $y;
1716
                    $courbe[] = $x + $w; $courbe[] = $y + $outTR[1];
1717
                    $courbe[] = $x + $w - $border['r']['width']; $courbe[] = $y + $border['t']['width'];
1718
                    $courbe[] = $x + $w - $outTR[0]; $courbe[] = $y + $outTR[1];
1719
                }
1720
                $this->_drawCurve($courbe, $border['r']['color']);
1721
            }
1722
1723
            // draw the radius right-bottom
1724
            if (is_array($outBR) && ($testBb || $testBr)) {
1725
                if ($inBR) {
1726
                    $courbe = array();
1727
                    $courbe[] = $x + $w; $courbe[] = $y + $h - $outBR[1];
1728
                    $courbe[] = $x + $w - $outBR[0]; $courbe[] = $y + $h;
1729
                    $courbe[] = $x + $w - $border['r']['width']; $courbe[] = $y + $h - $outBR[1];
1730
                    $courbe[] = $x + $w - $outBR[0]; $courbe[] = $y + $h - $border['b']['width'];
1731
                    $courbe[] = $x + $w - $outBR[0]; $courbe[] = $y + $h - $outBR[1];
1732
                } else {
1733
                    $courbe = array();
1734
                    $courbe[] = $x + $w; $courbe[] = $y + $h - $outBR[1];
1735
                    $courbe[] = $x + $w - $outBR[0]; $courbe[] = $y + $h;
1736
                    $courbe[] = $x + $w - $border['r']['width']; $courbe[] = $y + $h - $border['b']['width'];
1737
                    $courbe[] = $x + $w - $outBR[0]; $courbe[] = $y + $h - $outBR[1];
1738
                }
1739
                $this->_drawCurve($courbe, $border['b']['color']);
1740
            }
1741
1742
            // draw the left border
1743 View Code Duplication
            if ($testBl) {
1744
                $pt = array();
1745
                $pt[] = $x; $pt[] = $y + $h;
1746
                $pt[] = $x; $pt[] = $y + $h - $border['b']['width'];
1747
                $pt[] = $x; $pt[] = $y + $border['t']['width'];
1748
                $pt[] = $x; $pt[] = $y;
1749
                $pt[] = $x + $border['l']['width']; $pt[] = $y + $border['t']['width'];
1750
                $pt[] = $x + $border['l']['width']; $pt[] = $y + $h - $border['b']['width'];
1751
1752
                $bord = 3;
1753
                if (is_array($outBL)) {
1754
                    $bord -= 1;
1755
                    $pt[3] -= $outBL[1] - $border['b']['width'];
1756
                    if ($inBL) $pt[11] -= $inBL[1];
1757
                    unset($pt[0]); unset($pt[1]);
1758
                }
1759
                if (is_array($outTL)) {
1760
                    $bord -= 2;
1761
                    $pt[5] += $outTL[1] - $border['t']['width'];
1762
                    if ($inTL) $pt[9] += $inTL[1];
1763
                    unset($pt[6]); unset($pt[7]);
1764
                }
1765
1766
                $pt = array_values($pt);
1767
                $this->_drawLine($pt, $border['l']['color'], $border['l']['type'], $border['l']['width'], $bord);
1768
            }
1769
1770
            // draw the top border
1771 View Code Duplication
            if ($testBt) {
1772
                $pt = array();
1773
                $pt[] = $x; $pt[] = $y;
1774
                $pt[] = $x + $border['l']['width']; $pt[] = $y;
1775
                $pt[] = $x + $w - $border['r']['width']; $pt[] = $y;
1776
                $pt[] = $x + $w; $pt[] = $y;
1777
                $pt[] = $x + $w - $border['r']['width']; $pt[] = $y + $border['t']['width'];
1778
                $pt[] = $x + $border['l']['width']; $pt[] = $y + $border['t']['width'];
1779
1780
                $bord = 3;
1781
                if (is_array($outTL)) {
1782
                    $bord -= 1;
1783
                    $pt[2] += $outTL[0] - $border['l']['width'];
1784
                    if ($inTL) $pt[10] += $inTL[0];
1785
                    unset($pt[0]); unset($pt[1]);
1786
                }
1787
                if (is_array($outTR)) {
1788
                    $bord -= 2;
1789
                    $pt[4] -= $outTR[0] - $border['r']['width'];
1790
                    if ($inTR) $pt[8] -= $inTR[0];
1791
                    unset($pt[6]); unset($pt[7]);
1792
                }
1793
1794
                $pt = array_values($pt);
1795
                $this->_drawLine($pt, $border['t']['color'], $border['t']['type'], $border['t']['width'], $bord);
1796
            }
1797
1798
            // draw the right border
1799 View Code Duplication
            if ($testBr) {
1800
                $pt = array();
1801
                $pt[] = $x + $w; $pt[] = $y;
1802
                $pt[] = $x + $w; $pt[] = $y + $border['t']['width'];
1803
                $pt[] = $x + $w; $pt[] = $y + $h - $border['b']['width'];
1804
                $pt[] = $x + $w; $pt[] = $y + $h;
1805
                $pt[] = $x + $w - $border['r']['width']; $pt[] = $y + $h - $border['b']['width'];
1806
                $pt[] = $x + $w - $border['r']['width']; $pt[] = $y + $border['t']['width'];
1807
1808
                $bord = 3;
1809
                if (is_array($outTR)) {
1810
                    $bord -= 1;
1811
                    $pt[3] += $outTR[1] - $border['t']['width'];
1812
                    if ($inTR) $pt[11] += $inTR[1];
1813
                    unset($pt[0]); unset($pt[1]);
1814
                }
1815
                if (is_array($outBR)) {
1816
                    $bord -= 2;
1817
                    $pt[5] -= $outBR[1] - $border['b']['width'];
1818
                    if ($inBR) $pt[9] -= $inBR[1];
1819
                    unset($pt[6]); unset($pt[7]);
1820
                }
1821
1822
                $pt = array_values($pt);
1823
                $this->_drawLine($pt, $border['r']['color'], $border['r']['type'], $border['r']['width'], $bord);
1824
            }
1825
1826
            // draw the bottom border
1827 View Code Duplication
            if ($testBb) {
1828
                $pt = array();
1829
                $pt[] = $x + $w; $pt[] = $y + $h;
1830
                $pt[] = $x + $w - $border['r']['width']; $pt[] = $y + $h;
1831
                $pt[] = $x + $border['l']['width']; $pt[] = $y + $h;
1832
                $pt[] = $x; $pt[] = $y + $h;
1833
                $pt[] = $x + $border['l']['width']; $pt[] = $y + $h - $border['b']['width'];
1834
                $pt[] = $x + $w - $border['r']['width']; $pt[] = $y + $h - $border['b']['width'];
1835
1836
                $bord = 3;
1837
                if (is_array($outBL)) {
1838
                    $bord -= 2;
1839
                    $pt[4] += $outBL[0] - $border['l']['width'];
1840
                    if ($inBL) $pt[8] += $inBL[0];
1841
                    unset($pt[6]); unset($pt[7]);
1842
                }
1843
                if (is_array($outBR)) {
1844
                    $bord -= 1;
1845
                    $pt[2] -= $outBR[0] - $border['r']['width'];
1846
                    if ($inBR) $pt[10] -= $inBR[0];
1847
                    unset($pt[0]); unset($pt[1]);
1848
1849
                }
1850
1851
                $pt = array_values($pt);
1852
                $this->_drawLine($pt, $border['b']['color'], $border['b']['type'], $border['b']['width'], $bord);
1853
            }
1854
1855
            if ($background['color']) {
1856
                $this->pdf->setFillColorArray($background['color']);
1857
            }
1858
1859
            return true;
1860
        }
1861
1862
        /**
1863
         * draw a curve (for border radius)
1864
         *
1865
         * @access protected
1866
         * @param  double[] $pt
1867
         * @param  array $color
1868
         */
1869
        protected function _drawCurve($pt, $color)
1870
        {
1871
            $this->pdf->setFillColorArray($color);
1872
1873
            if (count($pt) == 10)
1874
                $this->pdf->drawCurve($pt[0], $pt[1], $pt[2], $pt[3], $pt[4], $pt[5], $pt[6], $pt[7], $pt[8], $pt[9]);
1875
            else
1876
                $this->pdf->drawCorner($pt[0], $pt[1], $pt[2], $pt[3], $pt[4], $pt[5], $pt[6], $pt[7]);
1877
        }
1878
1879
        /**
1880
         * draw a ligne with a specific type, and specific start and end for radius
1881
         *
1882
         * @access protected
1883
         * @param  array   $pt
1884
         * @param  float   $color
1885
         * @param  string  $type (dashed, dotted, double, solid)
1886
         * @param  float   $width
1887
         * @param  integer $radius (binary from 0 to 3 with 1=>start with a radius, 2=>end with a radius)
1888
         */
1889
        protected function _drawLine($pt, $color, $type, $width, $radius = 3)
1890
        {
1891
            // set the fill color
1892
            $this->pdf->setFillColorArray($color);
1893
1894
            // if dashed or dotted
1895
            if ($type == 'dashed' || $type == 'dotted') {
1896
1897
                // clean the end of the line, if radius
1898
                if ($radius == 1) {
1899
                    $tmp = array(); $tmp[] = $pt[0]; $tmp[] = $pt[1]; $tmp[] = $pt[2]; $tmp[] = $pt[3]; $tmp[] = $pt[8]; $tmp[] = $pt[9];
1900
                    $this->pdf->Polygon($tmp, 'F');
1901
1902
                    $tmp = array(); $tmp[] = $pt[2]; $tmp[] = $pt[3]; $tmp[] = $pt[4]; $tmp[] = $pt[5]; $tmp[] = $pt[6]; $tmp[] = $pt[7]; $tmp[] = $pt[8]; $tmp[] = $pt[9];
1903
                    $pt = $tmp;
1904
                } else if ($radius == 2) {
1905
                    $tmp = array(); $tmp[] = $pt[2]; $tmp[] = $pt[3]; $tmp[] = $pt[4]; $tmp[] = $pt[5]; $tmp[] = $pt[6]; $tmp[] = $pt[7];
1906
                    $this->pdf->Polygon($tmp, 'F');
1907
1908
                    $tmp = array(); $tmp[] = $pt[0]; $tmp[] = $pt[1]; $tmp[] = $pt[2]; $tmp[] = $pt[3]; $tmp[] = $pt[6]; $tmp[] = $pt[7]; $tmp[] = $pt[8]; $tmp[] = $pt[9];
1909
                    $pt = $tmp;
1910
                } else if ($radius == 3) {
1911
                    $tmp = array(); $tmp[] = $pt[0]; $tmp[] = $pt[1]; $tmp[] = $pt[2]; $tmp[] = $pt[3]; $tmp[] = $pt[10]; $tmp[] = $pt[11];
1912
                    $this->pdf->Polygon($tmp, 'F');
1913
1914
                    $tmp = array(); $tmp[] = $pt[4]; $tmp[] = $pt[5]; $tmp[] = $pt[6]; $tmp[] = $pt[7]; $tmp[] = $pt[8]; $tmp[] = $pt[9];
1915
                    $this->pdf->Polygon($tmp, 'F');
1916
1917
                    $tmp = array(); $tmp[] = $pt[2]; $tmp[] = $pt[3]; $tmp[] = $pt[4]; $tmp[] = $pt[5]; $tmp[] = $pt[8]; $tmp[] = $pt[9]; $tmp[] = $pt[10]; $tmp[] = $pt[11];
1918
                    $pt = $tmp;
1919
                }
1920
1921
                // horisontal or vertical line
1922
                if ($pt[2] == $pt[0]) {
1923
                    $l = abs(($pt[3] - $pt[1]) * 0.5);
1924
                    $px = 0;
1925
                    $py = $width;
1926
                    $x1 = $pt[0]; $y1 = ($pt[3] + $pt[1]) * 0.5;
1927
                    $x2 = $pt[6]; $y2 = ($pt[7] + $pt[5]) * 0.5;
1928
                } else {
1929
                    $l = abs(($pt[2] - $pt[0]) * 0.5);
1930
                    $px = $width;
1931
                    $py = 0;
1932
                    $x1 = ($pt[2] + $pt[0]) * 0.5; $y1 = $pt[1];
1933
                    $x2 = ($pt[6] + $pt[4]) * 0.5; $y2 = $pt[7];
1934
                }
1935
1936
                // if dashed : 3x bigger than dotted
1937
                if ($type == 'dashed') {
1938
                    $px = $px * 3.;
1939
                    $py = $py * 3.;
1940
                }
1941
                $mode = ($l / ($px + $py) < .5);
1942
1943
                // display the dotted/dashed line
1944
                for ($i = 0; $l - ($px + $py) * ($i - 0.5) > 0; $i++) {
1945
                    if (($i % 2) == $mode) {
1946
                        $j = $i - 0.5;
1947
                        $lx1 = $px * ($j); if ($lx1 < -$l) $lx1 = -$l;
1948
                        $ly1 = $py * ($j); if ($ly1 < -$l) $ly1 = -$l;
1949
                        $lx2 = $px * ($j + 1); if ($lx2 > $l)  $lx2 = $l;
1950
                        $ly2 = $py * ($j + 1); if ($ly2 > $l)  $ly2 = $l;
1951
1952
                        $tmp = array();
1953
                        $tmp[] = $x1 + $lx1; $tmp[] = $y1 + $ly1;
1954
                        $tmp[] = $x1 + $lx2; $tmp[] = $y1 + $ly2;
1955
                        $tmp[] = $x2 + $lx2; $tmp[] = $y2 + $ly2;
1956
                        $tmp[] = $x2 + $lx1; $tmp[] = $y2 + $ly1;
1957
                        $this->pdf->Polygon($tmp, 'F');
1958
1959
                        if ($j > 0) {
1960
                            $tmp = array();
1961
                            $tmp[] = $x1 - $lx1; $tmp[] = $y1 - $ly1;
1962
                            $tmp[] = $x1 - $lx2; $tmp[] = $y1 - $ly2;
1963
                            $tmp[] = $x2 - $lx2; $tmp[] = $y2 - $ly2;
1964
                            $tmp[] = $x2 - $lx1; $tmp[] = $y2 - $ly1;
1965
                            $this->pdf->Polygon($tmp, 'F');
1966
                        }
1967
                    }
1968
                }
1969
            } else if ($type == 'double') {
1970
1971
                // if double, 2 lines : 0=>1/3 and 2/3=>1
0 ignored issues
show
Unused Code Comprehensibility introduced by
52% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1972
                $pt1 = $pt;
1973
                $pt2 = $pt;
1974
1975
                if (count($pt) == 12) {
1976
                    // line 1
1977
                    $pt1[0] = ($pt[0] - $pt[10]) * 0.33 + $pt[10];
1978
                    $pt1[1] = ($pt[1] - $pt[11]) * 0.33 + $pt[11];
1979
                    $pt1[2] = ($pt[2] - $pt[10]) * 0.33 + $pt[10];
1980
                    $pt1[3] = ($pt[3] - $pt[11]) * 0.33 + $pt[11];
1981
                    $pt1[4] = ($pt[4] - $pt[8]) * 0.33 + $pt[8];
1982
                    $pt1[5] = ($pt[5] - $pt[9]) * 0.33 + $pt[9];
1983
                    $pt1[6] = ($pt[6] - $pt[8]) * 0.33 + $pt[8];
1984
                    $pt1[7] = ($pt[7] - $pt[9]) * 0.33 + $pt[9];
1985
                    $pt2[10] = ($pt[10] - $pt[0]) * 0.33 + $pt[0];
1986
                    $pt2[11] = ($pt[11] - $pt[1]) * 0.33 + $pt[1];
1987
1988
                    // line 2
1989
                    $pt2[2] = ($pt[2] - $pt[0]) * 0.33 + $pt[0];
1990
                    $pt2[3] = ($pt[3] - $pt[1]) * 0.33 + $pt[1];
1991
                    $pt2[4] = ($pt[4] - $pt[6]) * 0.33 + $pt[6];
1992
                    $pt2[5] = ($pt[5] - $pt[7]) * 0.33 + $pt[7];
1993
                    $pt2[8] = ($pt[8] - $pt[6]) * 0.33 + $pt[6];
1994
                    $pt2[9] = ($pt[9] - $pt[7]) * 0.33 + $pt[7];
1995
                } else {
1996
                    // line 1
1997
                    $pt1[0] = ($pt[0] - $pt[6]) * 0.33 + $pt[6];
1998
                    $pt1[1] = ($pt[1] - $pt[7]) * 0.33 + $pt[7];
1999
                    $pt1[2] = ($pt[2] - $pt[4]) * 0.33 + $pt[4];
2000
                    $pt1[3] = ($pt[3] - $pt[5]) * 0.33 + $pt[5];
2001
2002
                    // line 2
2003
                    $pt2[6] = ($pt[6] - $pt[0]) * 0.33 + $pt[0];
2004
                    $pt2[7] = ($pt[7] - $pt[1]) * 0.33 + $pt[1];
2005
                    $pt2[4] = ($pt[4] - $pt[2]) * 0.33 + $pt[2];
2006
                    $pt2[5] = ($pt[5] - $pt[3]) * 0.33 + $pt[3];
2007
                }
2008
                $this->pdf->Polygon($pt1, 'F');
2009
                $this->pdf->Polygon($pt2, 'F');
2010
            } else if ($type == 'solid') {
2011
                // solid line : draw directly the polygon
2012
                $this->pdf->Polygon($pt, 'F');
2013
            }
2014
        }
2015
2016
        /**
2017
         * prepare a transform matrix, only for drawing a SVG graphic
2018
         *
2019
         * @access protected
2020
         * @param  string $transform
2021
         * @return array  $matrix
2022
         */
2023
        protected function _prepareTransform($transform)
2024
        {
2025
            // it can not be  empty
2026
            if ( ! $transform) return null;
2027
2028
            // sctions must be like scale(...)
2029
            if ( ! preg_match_all('/([a-z]+)\(([^\)]*)\)/isU', $transform, $match)) return null;
2030
2031
            // prepare the list of the actions
2032
            $actions = array();
2033
2034
            // for actions
2035
            for ($k = 0; $k < count($match[0]); $k++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
2036
2037
                // get the name of the action
2038
                $name = strtolower($match[1][$k]);
2039
2040
                // get the parameters of the action
2041
                $val = explode(',', trim($match[2][$k]));
2042
                foreach ($val as $i => $j) {
2043
                    $val[$i] = trim($j);
2044
                }
2045
2046
                // prepare the matrix, depending on the action
2047
                switch ($name)
2048
                {
2049
                    case 'scale':
2050
                        if ( ! isset($val[0])) $val[0] = 1.; else $val[0] = 1. * $val[0];
2051 View Code Duplication
                        if ( ! isset($val[1])) $val[1] = $val[0]; else $val[1] = 1. * $val[1];
2052
                        $actions[] = array($val[0], 0, 0, $val[1], 0, 0);
2053
                        break;
2054
2055
                    case 'translate':
2056 View Code Duplication
                        if ( ! isset($val[0])) $val[0] = 0.; else $val[0] = $this->parsingCss->ConvertToMM($val[0], $this->_isInDraw['w']);
2057 View Code Duplication
                        if ( ! isset($val[1])) $val[1] = 0.; else $val[1] = $this->parsingCss->ConvertToMM($val[1], $this->_isInDraw['h']);
2058
                        $actions[] = array(1, 0, 0, 1, $val[0], $val[1]);
2059
                        break;
2060
2061
                    case 'rotate':
2062
                        if ( ! isset($val[0])) $val[0] = 0.; else $val[0] = $val[0] * M_PI / 180.;
2063 View Code Duplication
                        if ( ! isset($val[1])) $val[1] = 0.; else $val[1] = $this->parsingCss->ConvertToMM($val[1], $this->_isInDraw['w']);
2064 View Code Duplication
                        if ( ! isset($val[2])) $val[2] = 0.; else $val[2] = $this->parsingCss->ConvertToMM($val[2], $this->_isInDraw['h']);
2065 View Code Duplication
                        if ($val[1] || $val[2]) $actions[] = array(1, 0, 0, 1, -$val[1], -$val[2]);
2066
                        $actions[] = array(cos($val[0]), sin($val[0]), -sin($val[0]), cos($val[0]), 0, 0);
2067 View Code Duplication
                        if ($val[1] || $val[2]) $actions[] = array(1, 0, 0, 1, $val[1], $val[2]);
2068
                        break;
2069
2070 View Code Duplication
                    case 'skewx':
2071
                        if ( ! isset($val[0])) $val[0] = 0.; else $val[0] = $val[0] * M_PI / 180.;
2072
                        $actions[] = array(1, 0, tan($val[0]), 1, 0, 0);
2073
                        break;
2074
2075 View Code Duplication
                    case 'skewy':
2076
                        if ( ! isset($val[0])) $val[0] = 0.; else $val[0] = $val[0] * M_PI / 180.;
2077
                        $actions[] = array(1, tan($val[0]), 0, 1, 0, 0);
2078
                        break;
2079
                    case 'matrix':
2080
                        if ( ! isset($val[0])) $val[0] = 0.; else $val[0] = $val[0] * 1.;
2081
                        if ( ! isset($val[1])) $val[1] = 0.; else $val[1] = $val[1] * 1.;
2082
                        if ( ! isset($val[2])) $val[2] = 0.; else $val[2] = $val[2] * 1.;
2083
                        if ( ! isset($val[3])) $val[3] = 0.; else $val[3] = $val[3] * 1.;
2084 View Code Duplication
                        if ( ! isset($val[4])) $val[4] = 0.; else $val[4] = $this->parsingCss->ConvertToMM($val[4], $this->_isInDraw['w']);
2085 View Code Duplication
                        if ( ! isset($val[5])) $val[5] = 0.; else $val[5] = $this->parsingCss->ConvertToMM($val[5], $this->_isInDraw['h']);
2086
                        $actions[] = $val;
2087
                        break;
2088
                }
2089
            }
2090
2091
            // if ther is no actions => return
2092
            if ( ! $actions) return null;
0 ignored issues
show
Bug Best Practice introduced by
The expression $actions of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
2093
2094
            // get the first matrix
2095
            $m = $actions[0]; unset($actions[0]);
2096
2097
            // foreach matrix => multiply to the last matrix
2098
            foreach ($actions as $n) {
2099
                $m = array(
2100
                    $m[0] * $n[0] + $m[2] * $n[1],
2101
                    $m[1] * $n[0] + $m[3] * $n[1],
2102
                    $m[0] * $n[2] + $m[2] * $n[3],
2103
                    $m[1] * $n[2] + $m[3] * $n[3],
2104
                    $m[0] * $n[4] + $m[2] * $n[5] + $m[4],
2105
                    $m[1] * $n[4] + $m[3] * $n[5] + $m[5]
2106
                );
2107
            }
2108
2109
            // return the matrix
2110
            return $m;
2111
        }
2112
2113
        /**
2114
         * @access protected
2115
         * @param  &array $cases
0 ignored issues
show
Documentation introduced by
The doc-type &array could not be parsed: Unknown type name "&array" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
2116
         * @param  &array $corr
0 ignored issues
show
Documentation introduced by
The doc-type &array could not be parsed: Unknown type name "&array" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
2117
         */
2118
        protected function _calculateTableCellSize(&$cases, &$corr)
2119
        {
2120
            if ( ! isset($corr[0])) return true;
2121
2122
            // for each cell without colspan, we get the max width for each column
2123
            $sw = array();
2124 View Code Duplication
            for ($x = 0; $x < count($corr[0]); $x++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
2125
                $m = 0;
2126
                for ($y = 0; $y < count($corr); $y++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
2127
                    if (isset($corr[$y][$x]) && is_array($corr[$y][$x]) && $corr[$y][$x][2] == 1) {
2128
                        $m = max($m, $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w']);
2129
                    }
2130
                }
2131
                $sw[$x] = $m;
2132
            }
2133
2134
            // for each cell with colspan, we adapt the width of each column
2135 View Code Duplication
            for ($x = 0; $x < count($corr[0]); $x++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
2136
                for ($y = 0; $y < count($corr); $y++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
2137
                    if (isset($corr[$y][$x]) && is_array($corr[$y][$x]) && $corr[$y][$x][2] > 1) {
2138
2139
                        // sum the max width of each column in colspan
2140
                        $s = 0; for ($i = 0; $i < $corr[$y][$x][2]; $i++) $s += $sw[$x + $i];
2141
2142
                        // if the max width is < the width of the cell with colspan => we adapt the width of each max width
2143
                        if ($s > 0 && $s < $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w']) {
2144
                            for ($i = 0; $i < $corr[$y][$x][2]; $i++) {
2145
                                $sw[$x + $i] = $sw[$x + $i] / $s * $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w'];
2146
                            }
2147
                        }
2148
                    }
2149
                }
2150
            }
2151
2152
            // set the new width, for each cell
2153
            for ($x = 0; $x < count($corr[0]); $x++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
2154
                for ($y = 0; $y < count($corr); $y++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
2155
                    if (isset($corr[$y][$x]) && is_array($corr[$y][$x])) {
2156
                        // without colspan
2157
                        if ($corr[$y][$x][2] == 1) {
2158
                            $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w'] = $sw[$x];
2159
                        // with colspan
2160
                        } else {
2161
                            $s = 0;
2162
                            for ($i = 0; $i < $corr[$y][$x][2]; $i++) {
2163
                                $s += $sw[$x + $i];
2164
                            }
2165
                            $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w'] = $s;
2166
                        }
2167
                    }
2168
                }
2169
            }
2170
2171
            // for each cell without rowspan, we get the max height for each line
2172
            $sh = array();
2173 View Code Duplication
            for ($y = 0; $y < count($corr); $y++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
2174
                $m = 0;
2175
                for ($x = 0; $x < count($corr[0]); $x++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
2176
                    if (isset($corr[$y][$x]) && is_array($corr[$y][$x]) && $corr[$y][$x][3] == 1) {
2177
                        $m = max($m, $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h']);
2178
                    }
2179
                }
2180
                $sh[$y] = $m;
2181
            }
2182
2183
            // for each cell with rowspan, we adapt the height of each line
2184 View Code Duplication
            for ($y = 0; $y < count($corr); $y++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
2185
                for ($x = 0; $x < count($corr[0]); $x++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
2186
                    if (isset($corr[$y][$x]) && is_array($corr[$y][$x]) && $corr[$y][$x][3] > 1) {
2187
2188
                        // sum the max height of each line in rowspan
2189
                        $s = 0; for ($i = 0; $i < $corr[$y][$x][3]; $i++) $s += $sh[$y + $i];
2190
2191
                        // if the max height is < the height of the cell with rowspan => we adapt the height of each max height
2192
                        if ($s > 0 && $s < $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h']) {
2193
                            for ($i = 0; $i < $corr[$y][$x][3]; $i++) {
2194
                                $sh[$y + $i] = $sh[$y + $i] / $s * $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h'];
2195
                            }
2196
                        }
2197
                    }
2198
                }
2199
            }
2200
2201
            // set the new height, for each cell
2202
            for ($y = 0; $y < count($corr); $y++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
2203
                for ($x = 0; $x < count($corr[0]); $x++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
2204
                    if (isset($corr[$y][$x]) && is_array($corr[$y][$x])) {
2205
                        // without rowspan
2206
                        if ($corr[$y][$x][3] == 1) {
2207
                            $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h'] = $sh[$y];
2208
                        // with rowspan
2209
                        } else {
2210
                            $s = 0;
2211
                            for ($i = 0; $i < $corr[$y][$x][3]; $i++) {
2212
                                $s += $sh[$y + $i];
2213
                            }
2214
                            $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['h'] = $s;
2215
2216
                            for ($j = 1; $j < $corr[$y][$x][3]; $j++) {
2217
                                $tx = $x + 1;
2218
                                $ty = $y + $j;
2219
                                for (true; isset($corr[$ty][$tx]) && ! is_array($corr[$ty][$tx]); $tx++);
2220
                                if (isset($corr[$ty][$tx])) {
2221
                                    $cases[$corr[$ty][$tx][1]][$corr[$ty][$tx][0]]['dw'] += $cases[$corr[$y][$x][1]][$corr[$y][$x][0]]['w'];
2222
                                }
2223
                            }
2224
                        }
2225
                    }
2226
                }
2227
            }
2228
        }
2229
2230
        /**
2231
         * tag : PAGE
2232
         * mode : OPEN
2233
         *
2234
         * @param  array $param
2235
         * @return boolean
2236
         */
2237
        protected function _tag_open_PAGE($param)
2238
        {
2239
            if ($this->_isForOneLine) return false;
2240
            if ($this->_debugActif) $this->_DEBUG_add('PAGE '.($this->_page + 1), true);
2241
2242
            $newPageSet = ( ! isset($param['pageset']) || $param['pageset'] != 'old');
2243
2244
            $resetPageNumber = (isset($param['pagegroup']) && $param['pagegroup'] == 'new');
2245
2246
            $this->_maxH = 0;
2247
2248
            // if new page set asked
2249
            if ($newPageSet) {
2250
                $this->_subHEADER = array();
2251
                $this->_subFOOTER = array();
2252
2253
                // orientation
2254
                $orientation = '';
2255
                if (isset($param['orientation'])) {
2256
                    $param['orientation'] = strtolower($param['orientation']);
2257
                    if ($param['orientation'] == 'p')         $orientation = 'P';
2258
                    if ($param['orientation'] == 'portrait')  $orientation = 'P';
2259
2260
                    if ($param['orientation'] == 'l')         $orientation = 'L';
2261
                    if ($param['orientation'] == 'paysage')   $orientation = 'L';
2262
                    if ($param['orientation'] == 'landscape') $orientation = 'L';
2263
                }
2264
2265
                // format
2266
                $format = null;
2267
                if (isset($param['format'])) {
2268
                    $format = strtolower($param['format']);
2269
                    if (preg_match('/^([0-9]+)x([0-9]+)$/isU', $format, $match)) {
2270
                        $format = array(intval($match[1]), intval($match[2]));
2271
                    }
2272
                }
2273
2274
                // background
2275
                $background = array();
2276
                if (isset($param['backimg'])) {
2277
                    $background['img']    = isset($param['backimg']) ? $param['backimg'] : ''; // src of the image
2278
                    $background['posX']   = isset($param['backimgx']) ? $param['backimgx'] : 'center'; // horizontale position of the image
2279
                    $background['posY']   = isset($param['backimgy']) ? $param['backimgy'] : 'middle'; // vertical position of the image
2280
                    $background['width']  = isset($param['backimgw']) ? $param['backimgw'] : '100%'; // width of the image (100% = page width)
2281
2282
                    // convert the src of the image, if parameters
2283
                    $background['img'] = str_replace('&amp;', '&', $background['img']);
2284
2285
                    // convert the positions
2286
                    if ($background['posX'] == 'left')    $background['posX'] = '0%';
2287
                    if ($background['posX'] == 'center')  $background['posX'] = '50%';
2288
                    if ($background['posX'] == 'right')   $background['posX'] = '100%';
2289
                    if ($background['posY'] == 'top')     $background['posY'] = '0%';
2290
                    if ($background['posY'] == 'middle')  $background['posY'] = '50%';
2291
                    if ($background['posY'] == 'bottom')  $background['posY'] = '100%';
2292
2293
                    if ($background['img']) {
2294
                        // get the size of the image
2295
                        // WARNING : if URL, "allow_url_fopen" must turned to "on" in php.ini
2296
                        $infos = @getimagesize($background['img']);
2297
                        if (count($infos) > 1) {
2298
                            $imageWidth = $this->parsingCss->ConvertToMM($background['width'], $this->pdf->getW());
2299
                            $imageHeight = $imageWidth * $infos[1] / $infos[0];
2300
2301
                            $background['width'] = $imageWidth;
2302
                            $background['posX']  = $this->parsingCss->ConvertToMM($background['posX'], $this->pdf->getW() - $imageWidth);
2303
                            $background['posY']  = $this->parsingCss->ConvertToMM($background['posY'], $this->pdf->getH() - $imageHeight);
2304
                        } else {
2305
                            $background = array();
2306
                        }
2307
                    } else {
2308
                        $background = array();
2309
                    }
2310
                }
2311
2312
                // margins of the page
2313
                $background['top']    = isset($param['backtop']) ? $param['backtop'] : '0';
2314
                $background['bottom'] = isset($param['backbottom']) ? $param['backbottom'] : '0';
2315
                $background['left']   = isset($param['backleft']) ? $param['backleft'] : '0';
2316
                $background['right']  = isset($param['backright']) ? $param['backright'] : '0';
2317
2318
                // if no unit => mm
2319
                if (preg_match('/^([0-9]*)$/isU', $background['top'])) {
2320
                	$background['top']    .= 'mm';
2321
                }
2322
                if (preg_match('/^([0-9]*)$/isU', $background['bottom'])) {
2323
                	$background['bottom'] .= 'mm';
2324
                }
2325
                if (preg_match('/^([0-9]*)$/isU', $background['left'])) {
2326
                	$background['left']   .= 'mm';
2327
                }
2328
                if (preg_match('/^([0-9]*)$/isU', $background['right'])) {
2329
                	$background['right']  .= 'mm';
2330
                }
2331
2332
                // convert to mm
2333
                $background['top']    = $this->parsingCss->ConvertToMM($background['top'], $this->pdf->getH());
2334
                $background['bottom'] = $this->parsingCss->ConvertToMM($background['bottom'], $this->pdf->getH());
2335
                $background['left']   = $this->parsingCss->ConvertToMM($background['left'], $this->pdf->getW());
2336
                $background['right']  = $this->parsingCss->ConvertToMM($background['right'], $this->pdf->getW());
2337
2338
                // get the background color
2339
                $res = false;
2340
                $background['color'] = isset($param['backcolor']) ? $this->parsingCss->convertToColor($param['backcolor'], $res) : null;
2341
                if ( ! $res) $background['color'] = null;
2342
2343
                $this->parsingCss->save();
2344
                $this->parsingCss->analyse('PAGE', $param);
2345
                $this->parsingCss->setPosition();
2346
                $this->parsingCss->fontSet();
2347
2348
                // new page
2349
                $this->_setNewPage($format, $orientation, $background, null, $resetPageNumber);
2350
2351
                // automatic footer
2352
                if (isset($param['footer'])) {
2353
                    $lst = explode(';', $param['footer']);
2354
                    foreach ($lst as $key => $val) {
2355
                    	$lst[$key] = trim(strtolower($val));
2356
                    }
2357
                    $page    = in_array('page', $lst);
2358
                    $date    = in_array('date', $lst);
2359
                    $hour    = in_array('heure', $lst);
2360
                    $form    = in_array('form', $lst);
2361
                } else {
2362
                    $page    = null;
2363
                    $date    = null;
2364
                    $hour    = null;
2365
                    $form    = null;
2366
                }
2367
                $this->pdf->SetMyFooter($page, $date, $hour, $form);
2368
            // else => we use the last page set used
2369
            } else {
2370
                $this->parsingCss->save();
2371
                $this->parsingCss->analyse('PAGE', $param);
2372
                $this->parsingCss->setPosition();
2373
                $this->parsingCss->fontSet();
2374
2375
                $this->_setNewPage(null, null, null, null, $resetPageNumber);
2376
            }
2377
2378
            return true;
2379
        }
2380
2381
        /**
2382
         * tag : PAGE
2383
         * mode : CLOSE
2384
         *
2385
         * @param  array $param
2386
         * @return boolean
2387
         */
2388
        protected function _tag_close_PAGE($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2389
        {
2390
            if ($this->_isForOneLine) {
2391
            	return false;
2392
            }
2393
2394
            $this->_maxH = 0;
2395
2396
            $this->parsingCss->load();
2397
            $this->parsingCss->fontSet();
2398
2399
            if ($this->_debugActif) {
2400
            	$this->_DEBUG_add('PAGE '.$this->_page, false);
2401
            }
2402
2403
            return true;
2404
        }
2405
2406
        /**
2407
         * tag : PAGE_HEADER
2408
         * mode : OPEN
2409
         *
2410
         * @param  array $param
2411
         * @return boolean
2412
         */
2413 View Code Duplication
        protected function _tag_open_PAGE_HEADER($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2414
        {
2415
            if ($this->_isForOneLine) return false;
2416
2417
            $this->_subHEADER = array();
2418
            for ($this->_parsePos; $this->_parsePos < count($this->parsingHtml->code); $this->_parsePos++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
2419
                $action = $this->parsingHtml->code[$this->_parsePos];
2420
                if ($action['name'] == 'page_header') $action['name'] = 'page_header_sub';
2421
                $this->_subHEADER[] = $action;
2422
                if (strtolower($action['name']) == 'page_header_sub' && $action['close']) break;
2423
            }
2424
2425
            $this->_setPageHeader();
2426
2427
            return true;
2428
        }
2429
2430
        /**
2431
         * tag : PAGE_FOOTER
2432
         * mode : OPEN
2433
         *
2434
         * @param  array $param
2435
         * @return boolean
2436
         */
2437 View Code Duplication
        protected function _tag_open_PAGE_FOOTER($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2438
        {
2439
            if ($this->_isForOneLine) return false;
2440
2441
            $this->_subFOOTER = array();
2442
            for ($this->_parsePos; $this->_parsePos < count($this->parsingHtml->code); $this->_parsePos++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
2443
                $action = $this->parsingHtml->code[$this->_parsePos];
2444
                if ($action['name'] == 'page_footer') $action['name'] = 'page_footer_sub';
2445
                $this->_subFOOTER[] = $action;
2446
                if (strtolower($action['name']) == 'page_footer_sub' && $action['close']) break;
2447
            }
2448
2449
            $this->_setPageFooter();
2450
2451
            return true;
2452
        }
2453
2454
        /**
2455
         * It is not a real tag. Does not use it directly
2456
         *
2457
         * @param  array $param
2458
         * @return boolean
2459
         */
2460
        protected function _tag_open_PAGE_HEADER_SUB($param)
2461
        {
2462
            if ($this->_isForOneLine) {
2463
            	return false;
2464
            }
2465
2466
            // save the current stat
2467
            $this->_subSTATES = array();
2468
            $this->_subSTATES['x']  = $this->pdf->getX();
2469
            $this->_subSTATES['y']  = $this->pdf->getY();
2470
            $this->_subSTATES['s']  = $this->parsingCss->value;
2471
            $this->_subSTATES['t']  = $this->parsingCss->table;
2472
            $this->_subSTATES['ml'] = $this->_margeLeft;
2473
            $this->_subSTATES['mr'] = $this->_margeRight;
2474
            $this->_subSTATES['mt'] = $this->_margeTop;
2475
            $this->_subSTATES['mb'] = $this->_margeBottom;
2476
            $this->_subSTATES['mp'] = $this->_pageMarges;
2477
2478
            // new stat for the header
2479
            $this->_pageMarges = array();
2480
            $this->_margeLeft    = $this->_defaultLeft;
2481
            $this->_margeRight   = $this->_defaultRight;
2482
            $this->_margeTop     = $this->_defaultTop;
2483
            $this->_margeBottom  = $this->_defaultBottom;
2484
            $this->pdf->SetMargins($this->_margeLeft, $this->_margeTop, $this->_margeRight);
2485
            $this->pdf->SetAutoPageBreak(false, $this->_margeBottom);
2486
            $this->pdf->setXY($this->_defaultLeft, $this->_defaultTop);
2487
2488
            $this->parsingCss->initStyle();
2489
            $this->parsingCss->resetStyle();
2490
            $this->parsingCss->value['width'] = $this->pdf->getW() - $this->_defaultLeft - $this->_defaultRight;
2491
            $this->parsingCss->table = array();
2492
2493
            $this->parsingCss->save();
2494
            $this->parsingCss->analyse('page_header_sub', $param);
2495
            $this->parsingCss->setPosition();
2496
            $this->parsingCss->fontSet();
2497
            $this->_setNewPositionForNewLine();
2498
            return true;
2499
        }
2500
2501
        /**
2502
         * It is not a real tag. Does not use it directly
2503
         *
2504
         * @param  array $param
2505
         * @return boolean
2506
         */
2507 View Code Duplication
        protected function _tag_close_PAGE_HEADER_SUB($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2508
        {
2509
            if ($this->_isForOneLine) {
2510
            	return false;
2511
            }
2512
2513
            $this->parsingCss->load();
2514
2515
            // restore the stat
2516
            $this->parsingCss->value = $this->_subSTATES['s'];
2517
            $this->parsingCss->table = $this->_subSTATES['t'];
2518
            $this->_pageMarges       = $this->_subSTATES['mp'];
2519
            $this->_margeLeft        = $this->_subSTATES['ml'];
2520
            $this->_margeRight       = $this->_subSTATES['mr'];
2521
            $this->_margeTop         = $this->_subSTATES['mt'];
2522
            $this->_margeBottom      = $this->_subSTATES['mb'];
2523
            $this->pdf->SetMargins($this->_margeLeft, $this->_margeTop, $this->_margeRight);
2524
            $this->pdf->setbMargin($this->_margeBottom);
2525
            $this->pdf->SetAutoPageBreak(false, $this->_margeBottom);
2526
            $this->pdf->setXY($this->_subSTATES['x'], $this->_subSTATES['y']);
2527
2528
            $this->parsingCss->fontSet();
2529
            $this->_maxH = 0;
2530
2531
            return true;
2532
        }
2533
2534
        /**
2535
         * It is not a real tag. Does not use it directly
2536
         *
2537
         * @param  array $param
2538
         * @return boolean
2539
         */
2540
        protected function _tag_open_PAGE_FOOTER_SUB($param)
2541
        {
2542
            if ($this->_isForOneLine) {
2543
            	return false;
2544
            }
2545
2546
            // save the current stat
2547
            $this->_subSTATES = array();
2548
            $this->_subSTATES['x']    = $this->pdf->getX();
2549
            $this->_subSTATES['y']    = $this->pdf->getY();
2550
            $this->_subSTATES['s']    = $this->parsingCss->value;
2551
            $this->_subSTATES['t']    = $this->parsingCss->table;
2552
            $this->_subSTATES['ml']    = $this->_margeLeft;
2553
            $this->_subSTATES['mr']    = $this->_margeRight;
2554
            $this->_subSTATES['mt']    = $this->_margeTop;
2555
            $this->_subSTATES['mb']    = $this->_margeBottom;
2556
            $this->_subSTATES['mp']    = $this->_pageMarges;
2557
2558
            // new stat for the footer
2559
            $this->_pageMarges  = array();
2560
            $this->_margeLeft   = $this->_defaultLeft;
2561
            $this->_margeRight  = $this->_defaultRight;
2562
            $this->_margeTop    = $this->_defaultTop;
2563
            $this->_margeBottom = $this->_defaultBottom;
2564
            $this->pdf->SetMargins($this->_margeLeft, $this->_margeTop, $this->_margeRight);
2565
            $this->pdf->SetAutoPageBreak(false, $this->_margeBottom);
2566
            $this->pdf->setXY($this->_defaultLeft, $this->_defaultTop);
2567
2568
            $this->parsingCss->initStyle();
2569
            $this->parsingCss->resetStyle();
2570
            $this->parsingCss->value['width'] = $this->pdf->getW() - $this->_defaultLeft - $this->_defaultRight;
2571
            $this->parsingCss->table = array();
2572
2573
            // we create a sub HTML2PFDF, and we execute on it the content of the footer, to get the height of it
2574
            $sub = null;
2575
            $this->_createSubHTML($sub);
2576
            $sub->parsingHtml->code = $this->parsingHtml->getLevel($this->_parsePos);
2577
            $sub->_makeHTMLcode();
2578
            $this->pdf->setY($this->pdf->getH() - $sub->_maxY - $this->_defaultBottom - 0.01);
2579
            $this->_destroySubHTML($sub);
2580
2581
            $this->parsingCss->save();
2582
            $this->parsingCss->analyse('page_footer_sub', $param);
2583
            $this->parsingCss->setPosition();
2584
            $this->parsingCss->fontSet();
2585
            $this->_setNewPositionForNewLine();
2586
2587
            return true;
2588
        }
2589
2590
        /**
2591
         * It is not a real tag. Does not use it directly
2592
         *
2593
         * @param  array $param
2594
         * @return boolean
2595
         */
2596 View Code Duplication
        protected function _tag_close_PAGE_FOOTER_SUB($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2597
        {
2598
            if ($this->_isForOneLine) {
2599
            	return false;
2600
            }
2601
2602
            $this->parsingCss->load();
2603
2604
            $this->parsingCss->value                = $this->_subSTATES['s'];
2605
            $this->parsingCss->table                = $this->_subSTATES['t'];
2606
            $this->_pageMarges = $this->_subSTATES['mp'];
2607
            $this->_margeLeft = $this->_subSTATES['ml'];
2608
            $this->_margeRight = $this->_subSTATES['mr'];
2609
            $this->_margeTop = $this->_subSTATES['mt'];
2610
            $this->_margeBottom = $this->_subSTATES['mb'];
2611
            $this->pdf->SetMargins($this->_margeLeft, $this->_margeTop, $this->_margeRight);
2612
            $this->pdf->SetAutoPageBreak(false, $this->_margeBottom);
2613
            $this->pdf->setXY($this->_subSTATES['x'], $this->_subSTATES['y']);
2614
2615
            $this->parsingCss->fontSet();
2616
            $this->_maxH = 0;
2617
2618
            return true;
2619
        }
2620
2621
        /**
2622
         * tag : NOBREAK
2623
         * mode : OPEN
2624
         *
2625
         * @param  array $param
2626
         * @return boolean
2627
         */
2628
        protected function _tag_open_NOBREAK($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2629
        {
2630
            if ($this->_isForOneLine) {
2631
            	return false;
2632
            }
2633
2634
            $this->_maxH = 0;
2635
2636
            // create a sub HTML2PDF to execute the content of the tag, to get the dimensions
2637
            $sub = null;
2638
            $this->_createSubHTML($sub);
2639
            $sub->parsingHtml->code = $this->parsingHtml->getLevel($this->_parsePos);
2640
            $sub->_makeHTMLcode();
2641
            $y = $this->pdf->getY();
2642
2643
            // if the content does not fit on the page => new page
2644
            if (
2645
                $sub->_maxY < ($this->pdf->getH() - $this->pdf->gettMargin() - $this->pdf->getbMargin()) &&
2646
                $y + $sub->_maxY >= ($this->pdf->getH() - $this->pdf->getbMargin())
2647
            ) {
2648
                $this->_setNewPage();
2649
            }
2650
2651
            // destroy the sub HTML2PDF
2652
            $this->_destroySubHTML($sub);
2653
2654
            return true;
2655
        }
2656
2657
2658
        /**
2659
         * tag : NOBREAK
2660
         * mode : CLOSE
2661
         *
2662
         * @param  array $param
2663
         * @return boolean
2664
         */
2665
        protected function _tag_close_NOBREAK($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2666
        {
2667
            if ($this->_isForOneLine) {
2668
            	return false;
2669
            }
2670
2671
            $this->_maxH = 0;
2672
2673
            return true;
2674
        }
2675
2676
        /**
2677
         * tag : DIV
2678
         * mode : OPEN
2679
         *
2680
         * @param  array $param
2681
         * @param  string $other name of tag that used the div tag
2682
         * @return boolean
2683
         */
2684
        protected function _tag_open_DIV($param, $other = 'div')
2685
        {
2686
            if ($this->_isForOneLine) {
2687
            	return false;
2688
            }
2689
            if ($this->_debugActif) {
2690
            	$this->_DEBUG_add(strtoupper($other), true);
2691
            }
2692
2693
            $this->parsingCss->save();
2694
            $this->parsingCss->analyse($other, $param);
2695
            $this->parsingCss->fontSet();
2696
2697
            // for fieldset and legend
2698
            if (in_array($other, array('fieldset', 'legend'))) {
2699
                if (isset($param['moveTop'])) {
2700
                	$this->parsingCss->value['margin']['t']    += $param['moveTop'];
2701
                }
2702
                if (isset($param['moveLeft'])) {
2703
                	$this->parsingCss->value['margin']['l']    += $param['moveLeft'];
2704
                }
2705
                if (isset($param['moveDown'])) {
2706
                	$this->parsingCss->value['margin']['b']    += $param['moveDown'];
2707
                }
2708
            }
2709
2710
            $alignObject = null;
2711
            if ($this->parsingCss->value['margin-auto']) {
2712
            	$alignObject = 'center';
2713
            }
2714
2715
            $marge = array();
2716
            $marge['l'] = $this->parsingCss->value['border']['l']['width'] + $this->parsingCss->value['padding']['l'] + 0.03;
2717
            $marge['r'] = $this->parsingCss->value['border']['r']['width'] + $this->parsingCss->value['padding']['r'] + 0.03;
2718
            $marge['t'] = $this->parsingCss->value['border']['t']['width'] + $this->parsingCss->value['padding']['t'] + 0.03;
2719
            $marge['b'] = $this->parsingCss->value['border']['b']['width'] + $this->parsingCss->value['padding']['b'] + 0.03;
2720
2721
            // extract the content of the div
2722
            $level = $this->parsingHtml->getLevel($this->_parsePos);
2723
2724
            // create a sub HTML2PDF to get the dimensions of the content of the div
2725
            $w = 0; $h = 0;
2726
            if (count($level)) {
2727
                $sub = null;
2728
                $this->_createSubHTML($sub);
2729
                $sub->parsingHtml->code = $level;
2730
                $sub->_makeHTMLcode();
2731
                $w = $sub->_maxX;
2732
                $h = $sub->_maxY;
2733
                $this->_destroySubHTML($sub);
2734
            }
2735
            $wReel = $w;
2736
            $hReel = $h;
2737
2738
            $w += $marge['l'] + $marge['r'] + 0.001;
2739
            $h += $marge['t'] + $marge['b'] + 0.001;
2740
2741
            if ($this->parsingCss->value['overflow'] == 'hidden') {
2742
                $overW = max($w, $this->parsingCss->value['width']);
2743
                $overH = max($h, $this->parsingCss->value['height']);
2744
                $overflow = true;
2745
                $this->parsingCss->value['old_maxX'] = $this->_maxX;
2746
                $this->parsingCss->value['old_maxY'] = $this->_maxY;
2747
                $this->parsingCss->value['old_maxH'] = $this->_maxH;
2748
                $this->parsingCss->value['old_overflow'] = $this->_isInOverflow;
2749
                $this->_isInOverflow = true;
2750
            } else {
2751
                $overW = null;
2752
                $overH = null;
2753
                $overflow = false;
2754
                $this->parsingCss->value['width'] = max($w, $this->parsingCss->value['width']);
2755
                $this->parsingCss->value['height'] = max($h, $this->parsingCss->value['height']);
2756
            }
2757
2758
            switch ($this->parsingCss->value['rotate'])
2759
            {
2760 View Code Duplication
                case 90:
2761
                    $tmp = $overH; $overH = $overW; $overW = $tmp;
2762
                    $tmp = $hReel; $hReel = $wReel; $wReel = $tmp;
2763
                    unset($tmp);
2764
                    $w = $this->parsingCss->value['height'];
2765
                    $h = $this->parsingCss->value['width'];
2766
                    $tX = -$h;
2767
                    $tY = 0;
2768
                    break;
2769
2770 View Code Duplication
                case 180:
2771
                    $w = $this->parsingCss->value['width'];
2772
                    $h = $this->parsingCss->value['height'];
2773
                    $tX = -$w;
2774
                    $tY = -$h;
2775
                    break;
2776
2777 View Code Duplication
                case 270:
2778
                    $tmp = $overH; $overH = $overW; $overW = $tmp;
2779
                    $tmp = $hReel; $hReel = $wReel; $wReel = $tmp;
2780
                    unset($tmp);
2781
                    $w = $this->parsingCss->value['height'];
2782
                    $h = $this->parsingCss->value['width'];
2783
                    $tX = 0;
2784
                    $tY = -$w;
2785
                    break;
2786
2787 View Code Duplication
                default:
2788
                    $w = $this->parsingCss->value['width'];
2789
                    $h = $this->parsingCss->value['height'];
2790
                    $tX = 0;
2791
                    $tY = 0;
2792
                    break;
2793
            }
2794
2795 View Code Duplication
            if ( ! $this->parsingCss->value['position']) {
2796
                if (
2797
                    $w < ($this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin()) &&
2798
                    $this->pdf->getX() + $w >= ($this->pdf->getW() - $this->pdf->getrMargin())
2799
                    )
2800
                    $this->_tag_open_BR(array());
2801
2802
                if (
2803
                        ($h < ($this->pdf->getH() - $this->pdf->gettMargin() - $this->pdf->getbMargin())) &&
2804
                        ($this->pdf->getY() + $h >= ($this->pdf->getH() - $this->pdf->getbMargin())) &&
2805
                        ! $this->_isInOverflow
2806
                    )
2807
                    $this->_setNewPage();
2808
2809
                $old = $this->parsingCss->getOldValues();
2810
                $parentWidth = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin();
2811
2812
                if ($parentWidth > $w) {
2813
                    if ($alignObject == 'center')        $this->pdf->setX($this->pdf->getX() + ($parentWidth - $w) * 0.5);
2814
                    else if ($alignObject == 'right')    $this->pdf->setX($this->pdf->getX() + $parentWidth - $w);
2815
                }
2816
2817
                $this->parsingCss->setPosition();
2818
            } else {
2819
                $old = $this->parsingCss->getOldValues();
2820
                $parentWidth = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin();
2821
2822
                if ($parentWidth > $w) {
2823
                    if ($alignObject == 'center')        $this->pdf->setX($this->pdf->getX() + ($parentWidth - $w) * 0.5);
2824
                    else if ($alignObject == 'right')    $this->pdf->setX($this->pdf->getX() + $parentWidth - $w);
2825
                }
2826
2827
                $this->parsingCss->setPosition();
2828
                $this->_saveMax();
2829
                $this->_maxX = 0;
2830
                $this->_maxY = 0;
2831
                $this->_maxH = 0;
2832
                $this->_maxE = 0;
2833
            }
2834
2835
            if ($this->parsingCss->value['rotate']) {
2836
                $this->pdf->startTransform();
2837
                $this->pdf->setRotation($this->parsingCss->value['rotate']);
2838
                $this->pdf->setTranslate($tX, $tY);
2839
            }
2840
2841
            $this->_drawRectangle(
2842
                $this->parsingCss->value['x'],
2843
                $this->parsingCss->value['y'],
2844
                $this->parsingCss->value['width'],
2845
                $this->parsingCss->value['height'],
2846
                $this->parsingCss->value['border'],
2847
                $this->parsingCss->value['padding'],
2848
                0,
2849
                $this->parsingCss->value['background']
2850
            );
2851
2852
            $marge = array();
2853
            $marge['l'] = $this->parsingCss->value['border']['l']['width'] + $this->parsingCss->value['padding']['l'] + 0.03;
2854
            $marge['r'] = $this->parsingCss->value['border']['r']['width'] + $this->parsingCss->value['padding']['r'] + 0.03;
2855
            $marge['t'] = $this->parsingCss->value['border']['t']['width'] + $this->parsingCss->value['padding']['t'] + 0.03;
2856
            $marge['b'] = $this->parsingCss->value['border']['b']['width'] + $this->parsingCss->value['padding']['b'] + 0.03;
2857
2858
            $this->parsingCss->value['width'] -= $marge['l'] + $marge['r'];
2859
            $this->parsingCss->value['height'] -= $marge['t'] + $marge['b'];
2860
2861
            $xCorr = 0;
2862
            $yCorr = 0;
2863
            if ( ! $this->_subPart && ! $this->_isSubPart) {
2864
                switch ($this->parsingCss->value['text-align'])
2865
                {
2866
                    case 'right':
2867
                        $xCorr = ($this->parsingCss->value['width'] - $wReel);
2868
                        break;
2869
                    case 'center':
2870
                        $xCorr = ($this->parsingCss->value['width'] - $wReel) * 0.5;
2871
                        break;
2872
                }
2873
                if ($xCorr > 0) $xCorr = 0;
2874
                switch ($this->parsingCss->value['vertical-align'])
2875
                {
2876
                    case 'bottom':
2877
                        $yCorr = ($this->parsingCss->value['height'] - $hReel);
2878
                        break;
2879
                    case 'middle':
2880
                        $yCorr = ($this->parsingCss->value['height'] - $hReel) * 0.5;
2881
                        break;
2882
                }
2883
            }
2884
2885
            if ($overflow) {
2886
                $overW -= $marge['l'] + $marge['r'];
2887
                $overH -= $marge['t'] + $marge['b'];
2888
                $this->pdf->clippingPathStart(
2889
                    $this->parsingCss->value['x'] + $marge['l'],
2890
                    $this->parsingCss->value['y'] + $marge['t'],
2891
                    $this->parsingCss->value['width'],
2892
                    $this->parsingCss->value['height']
2893
                );
2894
2895
                $this->parsingCss->value['x'] += $xCorr;
2896
2897
                // marges from the dimension of the content
2898
                $mL = $this->parsingCss->value['x'] + $marge['l'];
2899
                $mR = $this->pdf->getW() - $mL - $overW;
2900
            } else {
2901
                // marges from the dimension of the div
2902
                $mL = $this->parsingCss->value['x'] + $marge['l'];
2903
                $mR = $this->pdf->getW() - $mL - $this->parsingCss->value['width'];
2904
            }
2905
2906
            $x = $this->parsingCss->value['x'] + $marge['l'];
2907
            $y = $this->parsingCss->value['y'] + $marge['t'] + $yCorr;
2908
            $this->_saveMargin($mL, 0, $mR);
2909
            $this->pdf->setXY($x, $y);
2910
2911
            $this->_setNewPositionForNewLine();
2912
2913
            return true;
2914
        }
2915
2916
        /**
2917
         * tag : BLOCKQUOTE
2918
         * mode : OPEN
2919
         *
2920
         * @param  array $param
2921
         * @return boolean
2922
         */
2923
        protected function _tag_open_BLOCKQUOTE($param)
2924
        {
2925
            return $this->_tag_open_DIV($param, 'blockquote');
2926
        }
2927
2928
        /**
2929
         * tag : LEGEND
2930
         * mode : OPEN
2931
         *
2932
         * @param  array $param
2933
         * @return boolean
2934
         */
2935
        protected function _tag_open_LEGEND($param)
2936
        {
2937
            return $this->_tag_open_DIV($param, 'legend');
2938
        }
2939
2940
        /**
2941
         * tag : FIELDSET
2942
         * mode : OPEN
2943
         *
2944
         * @author Pavel Kochman
2945
         * @param  array $param
2946
         * @return boolean
2947
         */
2948
        protected function _tag_open_FIELDSET($param)
2949
        {
2950
2951
            $this->parsingCss->save();
2952
            $this->parsingCss->analyse('fieldset', $param);
2953
2954
            // get height of LEGEND element and make fieldset corrections
2955
            for ($tempPos = $this->_parsePos + 1; $tempPos < count($this->parsingHtml->code); $tempPos++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
2956
                $action = $this->parsingHtml->code[$tempPos];
2957
                if ($action['name'] == 'fieldset') break;
2958
                if ($action['name'] == 'legend' && ! $action['close']) {
2959
                    $legendOpenPos = $tempPos;
2960
2961
                    $sub = null;
2962
                    $this->_createSubHTML($sub);
2963
                    $sub->parsingHtml->code = $this->parsingHtml->getLevel($tempPos - 1);
2964
2965
                    $res = null;
2966
                    for ($sub->_parsePos = 0; $sub->_parsePos < count($sub->parsingHtml->code); $sub->_parsePos++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
2967
                        $action = $sub->parsingHtml->code[$sub->_parsePos];
2968
                        $sub->_executeAction($action);
2969
2970
                        if ($action['name'] == 'legend' && $action['close']) {
2971
                                                    break;
2972
                        }
2973
                    }
2974
2975
                    $legendH = $sub->_maxY;
2976
                    $this->_destroySubHTML($sub);
2977
2978
                    $move = $this->parsingCss->value['padding']['t'] + $this->parsingCss->value['border']['t']['width'] + 0.03;
2979
2980
                    $param['moveTop'] = $legendH / 2;
2981
2982
                    $this->parsingHtml->code[$legendOpenPos]['param']['moveTop'] = - ($legendH / 2 + $move);
2983
                    $this->parsingHtml->code[$legendOpenPos]['param']['moveLeft'] = 2 - $this->parsingCss->value['border']['l']['width'] - $this->parsingCss->value['padding']['l'];
2984
                    $this->parsingHtml->code[$legendOpenPos]['param']['moveDown'] = $move;
2985
                    break;
2986
                }
2987
            }
2988
            $this->parsingCss->load();
2989
2990
            return $this->_tag_open_DIV($param, 'fieldset');
2991
        }
2992
2993
        /**
2994
         * tag : DIV
2995
         * mode : CLOSE
2996
         *
2997
         * @param  array $param
2998
         * @param  string $other name of tag that used the div tag
2999
         * @return boolean
3000
         */
3001
        protected function _tag_close_DIV($param, $other = 'div')
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
3002
        {
3003
            if ($this->_isForOneLine) {
3004
            	return false;
3005
            }
3006
3007
            if ($this->parsingCss->value['overflow'] == 'hidden') {
3008
                $this->_maxX = $this->parsingCss->value['old_maxX'];
3009
                $this->_maxY = $this->parsingCss->value['old_maxY'];
3010
                $this->_maxH = $this->parsingCss->value['old_maxH'];
3011
                $this->_isInOverflow = $this->parsingCss->value['old_overflow'];
3012
                $this->pdf->clippingPathStop();
3013
            }
3014
3015
            if ($this->parsingCss->value['rotate']) {
3016
                            $this->pdf->stopTransform();
3017
            }
3018
3019
            $marge = array();
3020
            $marge['l'] = $this->parsingCss->value['border']['l']['width'] + $this->parsingCss->value['padding']['l'] + 0.03;
3021
            $marge['r'] = $this->parsingCss->value['border']['r']['width'] + $this->parsingCss->value['padding']['r'] + 0.03;
3022
            $marge['t'] = $this->parsingCss->value['border']['t']['width'] + $this->parsingCss->value['padding']['t'] + 0.03;
3023
            $marge['b'] = $this->parsingCss->value['border']['b']['width'] + $this->parsingCss->value['padding']['b'] + 0.03;
3024
3025
            $x = $this->parsingCss->value['x'];
3026
            $y = $this->parsingCss->value['y'];
3027
            $w = $this->parsingCss->value['width'] + $marge['l'] + $marge['r'] + $this->parsingCss->value['margin']['r'];
3028
            $h = $this->parsingCss->value['height'] + $marge['t'] + $marge['b'] + $this->parsingCss->value['margin']['b'];
3029
3030
            switch ($this->parsingCss->value['rotate'])
3031
            {
3032
                case 90:
3033
                    $t = $w; $w = $h; $h = $t;
3034
                    break;
3035
3036
                case 270:
3037
                    $t = $w; $w = $h; $h = $t;
3038
                    break;
3039
3040
                default:
3041
                    break;
3042
            }
3043
3044
3045 View Code Duplication
            if ($this->parsingCss->value['position'] != 'absolute') {
3046
                $this->pdf->setXY($x + $w, $y);
3047
3048
                $this->_maxX = max($this->_maxX, $x + $w);
3049
                $this->_maxY = max($this->_maxY, $y + $h);
3050
                $this->_maxH = max($this->_maxH, $h);
3051
            } else {
3052
                $this->pdf->setXY($this->parsingCss->value['xc'], $this->parsingCss->value['yc']);
3053
3054
                $this->_loadMax();
3055
            }
3056
3057
            $block = ($this->parsingCss->value['display'] != 'inline' && $this->parsingCss->value['position'] != 'absolute');
3058
3059
            $this->parsingCss->load();
3060
            $this->parsingCss->fontSet();
3061
            $this->_loadMargin();
3062
3063
            if ($block) {
3064
            	$this->_tag_open_BR(array());
3065
            }
3066
            if ($this->_debugActif) {
3067
            	$this->_DEBUG_add(strtoupper($other), false);
3068
            }
3069
3070
            return true;
3071
        }
3072
3073
        /**
3074
         * tag : BLOCKQUOTE
3075
         * mode : CLOSE
3076
         *
3077
         * @param  array $param
3078
         * @return boolean
3079
         */
3080
        protected function _tag_close_BLOCKQUOTE($param)
3081
        {
3082
            return $this->_tag_close_DIV($param, 'blockquote');
3083
        }
3084
3085
        /**
3086
         * tag : FIELDSET
3087
         * mode : CLOSE
3088
         *
3089
         * @param  array $param
3090
         * @return boolean
3091
         */
3092
        protected function _tag_close_FIELDSET($param)
3093
        {
3094
            return $this->_tag_close_DIV($param, 'fieldset');
3095
        }
3096
3097
        /**
3098
         * tag : LEGEND
3099
         * mode : CLOSE
3100
         *
3101
         * @param  array $param
3102
         * @return boolean
3103
         */
3104
        protected function _tag_close_LEGEND($param)
3105
        {
3106
            return $this->_tag_close_DIV($param, 'legend');
3107
        }
3108
3109
        /**
3110
         * tag : BARCODE
3111
         * mode : OPEN
3112
         *
3113
         * @param  array $param
3114
         * @return boolean
3115
         */
3116
        protected function _tag_open_BARCODE($param)
3117
        {
3118
            // for  compatibility with old versions < 3.29
3119
            $lstBarcode = array();
3120
            $lstBarcode['UPC_A']  = 'UPCA';
3121
            $lstBarcode['CODE39'] = 'C39';
3122
3123
            if ( ! isset($param['type']))     $param['type'] = 'C39';
3124
            if ( ! isset($param['value']))    $param['value']    = 0;
3125
            if ( ! isset($param['label']))    $param['label']    = 'label';
3126
            if ( ! isset($param['style']['color'])) $param['style']['color'] = '#000000';
3127
3128
            if ($this->_testIsDeprecated && (isset($param['bar_h']) || isset($param['bar_w'])))
3129
                throw new HTML2PDF_exception(9, array('BARCODE', 'bar_h, bar_w'));
3130
3131
            $param['type'] = strtoupper($param['type']);
3132
            if (isset($lstBarcode[$param['type']])) $param['type'] = $lstBarcode[$param['type']];
3133
3134
            $this->parsingCss->save();
3135
            $this->parsingCss->analyse('barcode', $param);
3136
            $this->parsingCss->setPosition();
3137
            $this->parsingCss->fontSet();
3138
3139
            $x = $this->pdf->getX();
3140
            $y = $this->pdf->getY();
3141
            $w = $this->parsingCss->value['width']; if ( ! $w) $w = $this->parsingCss->ConvertToMM('50mm');
3142
            $h = $this->parsingCss->value['height']; if ( ! $h) $h = $this->parsingCss->ConvertToMM('10mm');
3143
            $txt = ($param['label'] !== 'none' ? $this->parsingCss->value['font-size'] : false);
3144
            $c = $this->parsingCss->value['color'];
3145
            $infos = $this->pdf->myBarcode($param['value'], $param['type'], $x, $y, $w, $h, $txt, $c);
3146
3147
            $this->_maxX = max($this->_maxX, $x + $infos[0]);
3148
            $this->_maxY = max($this->_maxY, $y + $infos[1]);
3149
            $this->_maxH = max($this->_maxH, $infos[1]);
3150
            $this->_maxE++;
3151
3152
            $this->pdf->setXY($x + $infos[0], $y);
3153
3154
            $this->parsingCss->load();
3155
            $this->parsingCss->fontSet();
3156
3157
            return true;
3158
        }
3159
3160
        /**
3161
         * tag : BARCODE
3162
         * mode : CLOSE
3163
         *
3164
         * @param  array $param
3165
         * @return boolean
3166
         */
3167
        protected function _tag_close_BARCODE($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
3168
        {
3169
            // there is nothing to do here
3170
3171
            return true;
3172
        }
3173
3174
        /**
3175
         * tag : QRCODE
3176
         * mode : OPEN
3177
         *
3178
         * @param  array $param
3179
         * @return boolean
3180
         */
3181
        protected function _tag_open_QRCODE($param)
3182
        {
3183
            if ($this->_testIsDeprecated && (isset($param['size']) || isset($param['noborder'])))
3184
                throw new HTML2PDF_exception(9, array('QRCODE', 'size, noborder'));
3185
3186
            if ($this->_debugActif) $this->_DEBUG_add('QRCODE');
3187
3188
            if ( ! isset($param['value']))                     $param['value'] = '';
3189
            if ( ! isset($param['ec']))                        $param['ec'] = 'H';
3190
            if ( ! isset($param['style']['color']))            $param['style']['color'] = '#000000';
3191
            if ( ! isset($param['style']['background-color'])) $param['style']['background-color'] = '#FFFFFF';
3192
            if (isset($param['style']['border'])) {
3193
                $borders = $param['style']['border'] != 'none';
3194
                unset($param['style']['border']);
3195
            } else {
3196
                $borders = true;
3197
            }
3198
3199
            if ($param['value'] === '') return true;
3200 View Code Duplication
            if ( ! in_array($param['ec'], array('L', 'M', 'Q', 'H'))) $param['ec'] = 'H';
3201
3202
            $this->parsingCss->save();
3203
            $this->parsingCss->analyse('qrcode', $param);
3204
            $this->parsingCss->setPosition();
3205
            $this->parsingCss->fontSet();
3206
3207
            $x = $this->pdf->getX();
3208
            $y = $this->pdf->getY();
3209
            $w = $this->parsingCss->value['width'];
3210
            $h = $this->parsingCss->value['height'];
3211
            $size = max($w, $h); if ( ! $size) $size = $this->parsingCss->ConvertToMM('50mm');
3212
3213
            $style = array(
3214
                    'fgcolor' => $this->parsingCss->value['color'],
3215
                    'bgcolor' => $this->parsingCss->value['background']['color'],
3216
                );
3217
3218
            if ($borders) {
3219
                $style['border'] = true;
3220
                $style['padding'] = 'auto';
3221
            } else {
3222
                $style['border'] = false;
3223
                $style['padding'] = 0;
3224
            }
3225
3226
            if ( ! $this->_subPart && ! $this->_isSubPart) {
3227
                $this->pdf->write2DBarcode($param['value'], 'QRCODE,'.$param['ec'], $x, $y, $size, $size, $style);
3228
            }
3229
3230
            $this->_maxX = max($this->_maxX, $x + $size);
3231
            $this->_maxY = max($this->_maxY, $y + $size);
3232
            $this->_maxH = max($this->_maxH, $size);
3233
            $this->_maxE++;
3234
3235
            $this->pdf->setX($x + $size);
3236
3237
            $this->parsingCss->load();
3238
            $this->parsingCss->fontSet();
3239
3240
            return true;
3241
        }
3242
3243
        /**
3244
         * tag : QRCODE
3245
         * mode : CLOSE
3246
         *
3247
         * @param  array $param
3248
         * @return boolean
3249
         */
3250
        protected function _tag_close_QRCODE($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
3251
        {
3252
            // there is nothing to do here
3253
3254
            return true;
3255
        }
3256
3257
        /**
3258
         * tag : BOOKMARK
3259
         * mode : OPEN
3260
         *
3261
         * @param  array $param
3262
         * @return boolean
3263
         */
3264
        protected function _tag_open_BOOKMARK($param)
3265
        {
3266
            $titre = isset($param['title']) ? trim($param['title']) : '';
3267
            $level = isset($param['level']) ? floor($param['level']) : 0;
3268
3269
            if ($level < 0) $level = 0;
3270
            if ($titre) $this->pdf->Bookmark($titre, $level, -1);
3271
3272
            return true;
3273
        }
3274
3275
        /**
3276
         * tag : BOOKMARK
3277
         * mode : CLOSE
3278
         *
3279
         * @param  array $param
3280
         * @return boolean
3281
         */
3282
        protected function _tag_close_BOOKMARK($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
3283
        {
3284
            // there is nothing to do here
3285
3286
            return true;
3287
        }
3288
3289
        /**
3290
         * this is not a real TAG, it is just to write texts
3291
         *
3292
         * @param  array $param
3293
         * @return null|boolean
3294
         */
3295
        protected function _tag_open_WRITE($param)
3296
        {
3297
            $fill = ($this->parsingCss->value['background']['color'] !== null && $this->parsingCss->value['background']['image'] === null);
3298
            if (in_array($this->parsingCss->value['id_tag'], array('fieldset', 'legend', 'div', 'table', 'tr', 'td', 'th'))) {
3299
                $fill = false;
3300
            }
3301
3302
            // get the text to write
3303
            $txt = $param['txt'];
3304
3305
            if ($this->_isAfterFloat) {
3306
                $txt = ltrim($txt);
3307
                $this->_isAfterFloat = false;
3308
            }
3309
3310
            $txt = str_replace('[[page_nb]]', $this->pdf->getMyAliasNbPages(), $txt);
3311
            $txt = str_replace('[[page_cu]]', $this->pdf->getMyNumPage($this->_page), $txt);
3312
3313
            if ($this->parsingCss->value['text-transform'] != 'none') {
3314
                if ($this->parsingCss->value['text-transform'] == 'capitalize')
3315
                    $txt = ucwords($txt);
3316
                else if ($this->parsingCss->value['text-transform'] == 'uppercase')
3317
                    $txt = strtoupper($txt);
3318
                else if ($this->parsingCss->value['text-transform'] == 'lowercase')
3319
                    $txt = strtolower($txt);
3320
            }
3321
3322
            // size of the text
3323
            $h  = 1.08 * $this->parsingCss->value['font-size'];
3324
            $dh = $h * $this->parsingCss->value['mini-decal'];
3325
            $lh = $this->parsingCss->getLineHeight();
3326
3327
            // identify the align
3328
            $align = 'L';
3329
            if ($this->parsingCss->value['text-align'] == 'li_right') {
3330
                $w = $this->parsingCss->value['width'];
3331
                $align = 'R';
3332
            }
3333
3334
            // calculate the width of each words, and of all the sentence
3335
            $w = 0;
3336
            $words = explode(' ', $txt);
3337
            foreach ($words as $k => $word) {
3338
                $words[$k] = array($word, $this->pdf->GetStringWidth($word));
3339
                $w += $words[$k][1];
3340
            }
3341
            $space = $this->pdf->GetStringWidth(' ');
3342
            $w += $space * (count($words) - 1);
3343
3344
            // position in the text
3345
            $currPos = 0;
3346
3347
            // the bigger width of the text, after automatic break line
3348
            $maxX = 0;
3349
3350
            // position of the text
3351
            $x = $this->pdf->getX();
3352
            $y = $this->pdf->getY();
3353
            $dy = $this->_getElementY($lh);
3354
3355
            // margins
3356
            list($left, $right) = $this->_getMargins($y);
3357
3358
            // number of lines after automatic break line
3359
            $nb = 0;
3360
3361
            // while we have words, and the text does not fit on the line => we cut the sentence
3362
            while ($x + $w > $right && $x < $right + $space && count($words)) {
3363
                // adding words 1 by 1 to fit on the line
3364
                $i = 0;
3365
                $old = array('', 0);
3366
                $str = $words[0];
3367
                $add = false;
3368
                while (($x + $str[1]) < $right) {
3369
                    $i++;
3370
                    $add = true;
3371
3372
                    array_shift($words);
3373
                    $old = $str;
3374
3375
                    if ( ! count($words)) break;
3376
                    $str[0] .= ' '.$words[0][0];
3377
                    $str[1] += $space + $words[0][1];
3378
                }
3379
                $str = $old;
3380
3381
                // if  nothing fit on the line, and if the first word does not fit on the line => the word is too long, we put it
3382
                if ($i == 0 && (($left + $words[0][1]) >= $right)) {
3383
                    $str = $words[0];
3384
                    array_shift($words);
3385
                    $i++;
3386
                    $add = true;
3387
                }
3388
                $currPos += ($currPos ? 1 : 0) + strlen($str[0]);
3389
3390
                // write the extract sentence that fit on the page
3391
                $wc = ($align == 'L' ? $str[1] : $this->parsingCss->value['width']);
3392
                if ($right - $left < $wc) $wc = $right - $left;
3393
3394
                if (strlen($str[0])) {
3395
                    $this->pdf->setXY($this->pdf->getX(), $y + $dh + $dy);
3396
                    $this->pdf->Cell($wc, $h, $str[0], 0, 0, $align, $fill, $this->_isInLink);
3397
                    $this->pdf->setXY($this->pdf->getX(), $y);
3398
                }
3399
                $this->_maxH = max($this->_maxH, $lh);
0 ignored issues
show
Documentation Bug introduced by
It seems like max($this->_maxH, $lh) can also be of type double. However, the property $_maxH is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
3400
3401
                // max width
3402
                $maxX = max($maxX, $this->pdf->getX());
3403
3404
                // new position and new width for the "while"
3405
                $w -= $str[1];
3406
                $y = $this->pdf->getY();
3407
                $x = $this->pdf->getX();
3408
                $dy = $this->_getElementY($lh);
3409
3410
                // if we have again words to write
3411
                if (count($words)) {
3412
                    // remove the space at the end
3413
                    if ($add) $w -= $space;
3414
3415
                    // if we don't add any word, and if the first word is empty => useless space to skip
3416
                    if ( ! $add && $words[0][0] === '') {
3417
                        array_shift($words);
3418
                    }
3419
3420
                    // if it is just to calculate for one line => adding the number of words
3421
                    if ($this->_isForOneLine) {
3422
                        $this->_maxE += $i;
3423
                        $this->_maxX = max($this->_maxX, $maxX);
3424
                        return null;
3425
                    }
3426
3427
                    // automatic line break
3428
                    $this->_tag_open_BR(array('style' => ''), $currPos);
3429
3430
                    // new position
3431
                    $y = $this->pdf->getY();
3432
                    $x = $this->pdf->getX();
3433
                    $dy = $this->_getElementY($lh);
3434
3435
                    // if the next line does  not fit on the page => new page
3436
                    if ($y + $h >= $this->pdf->getH() - $this->pdf->getbMargin()) {
3437
                        if ( ! $this->_isInOverflow && ! $this->_isInFooter) {
3438
                            $this->_setNewPage(null, '', null, $currPos);
3439
                            $y = $this->pdf->getY();
3440
                            $x = $this->pdf->getX();
3441
                            $dy = $this->_getElementY($lh);
3442
                        }
3443
                    }
3444
3445
                    // if more than 10000 line => error
3446
                    $nb++;
3447
                    if ($nb > 10000) {
3448
                        $txt = ''; foreach ($words as $k => $word) $txt .= ($k ? ' ' : '').$word[0];
3449
                        throw new HTML2PDF_exception(2, array($txt, $right - $left, $w));
3450
                    }
3451
3452
                    // new margins for the new line
3453
                    list($left, $right) = $this->_getMargins($y);
3454
                }
3455
            }
3456
3457
            // if we have words after automatic cut, it is because they fit on the line => we write the text
3458
            if (count($words)) {
3459
                $txt = ''; foreach ($words as $k => $word) $txt .= ($k ? ' ' : '').$word[0];
3460
                $w += $this->pdf->getWordSpacing() * (count($words));
3461
                $this->pdf->setXY($this->pdf->getX(), $y + $dh + $dy);
3462
                $this->pdf->Cell(($align == 'L' ? $w : $this->parsingCss->value['width']), $h, $txt, 0, 0, $align, $fill, $this->_isInLink);
3463
                $this->pdf->setXY($this->pdf->getX(), $y);
3464
                $this->_maxH = max($this->_maxH, $lh);
3465
                $this->_maxE += count($words);
3466
            }
3467
3468
            $maxX = max($maxX, $this->pdf->getX());
3469
            $maxY = $this->pdf->getY() + $h;
3470
3471
            $this->_maxX = max($this->_maxX, $maxX);
3472
            $this->_maxY = max($this->_maxY, $maxY);
0 ignored issues
show
Documentation Bug introduced by
It seems like max($this->_maxY, $maxY) can also be of type double. However, the property $_maxY is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
3473
3474
            return true;
3475
        }
3476
3477
        /**
3478
         * tag : BR
3479
         * mode : OPEN
3480
         *
3481
         * @param  array   $param
3482
         * @param  integer $curr real position in the html parseur (if break line in the write of a text)
3483
         * @return boolean
3484
         */
3485
        protected function _tag_open_BR($param, $curr = null)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
3486
        {
3487
            if ($this->_isForOneLine) return false;
3488
3489
            $h = max($this->_maxH, $this->parsingCss->getLineHeight());
3490
3491
            if ($this->_maxH == 0) $this->_maxY = max($this->_maxY, $this->pdf->getY() + $h);
0 ignored issues
show
Documentation Bug introduced by
It seems like max($this->_maxY, $this->pdf->getY() + $h) can also be of type double. However, the property $_maxY is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
3492
3493
            $this->_makeBreakLine($h, $curr);
3494
3495
            $this->_maxH = 0;
3496
            $this->_maxE = 0;
3497
3498
            return true;
3499
        }
3500
3501
        /**
3502
         * tag : HR
3503
         * mode : OPEN
3504
         *
3505
         * @param  array $param
3506
         * @return boolean
3507
         */
3508
        protected function _tag_open_HR($param)
3509
        {
3510
            if ($this->_isForOneLine) {
3511
            	return false;
3512
            }
3513
            $oldAlign = $this->parsingCss->value['text-align'];
3514
            $this->parsingCss->value['text-align'] = 'left';
3515
3516
            if ($this->_maxH) {
3517
            	$this->_tag_open_BR($param);
3518
            }
3519
3520
            $fontSize = $this->parsingCss->value['font-size'];
3521
            $this->parsingCss->value['font-size'] = $fontSize * 0.5; $this->_tag_open_BR($param);
3522
            $this->parsingCss->value['font-size'] = 0;
3523
3524
            $param['style']['width'] = '100%';
3525
3526
            $this->parsingCss->save();
3527
            $this->parsingCss->value['height'] = $this->parsingCss->ConvertToMM('1mm');
3528
3529
            $this->parsingCss->analyse('hr', $param);
3530
            $this->parsingCss->setPosition();
3531
            $this->parsingCss->fontSet();
3532
3533
            $h = $this->parsingCss->value['height'];
3534 View Code Duplication
            if ($h)    $h -= $this->parsingCss->value['border']['t']['width'] + $this->parsingCss->value['border']['b']['width'];
3535 View Code Duplication
            if ($h <= 0) $h = $this->parsingCss->value['border']['t']['width'] + $this->parsingCss->value['border']['b']['width'];
3536
3537
            $this->_drawRectangle($this->pdf->getX(), $this->pdf->getY(), $this->parsingCss->value['width'], $h, $this->parsingCss->value['border'], 0, 0, $this->parsingCss->value['background']);
3538
            $this->_maxH = $h;
3539
3540
            $this->parsingCss->load();
3541
            $this->parsingCss->fontSet();
3542
3543
            $this->_tag_open_BR($param);
3544
3545
            $this->parsingCss->value['font-size'] = $fontSize * 0.5; $this->_tag_open_BR($param);
3546
            $this->parsingCss->value['font-size'] = $fontSize;
3547
3548
            $this->parsingCss->value['text-align'] = $oldAlign;
3549
            $this->_setNewPositionForNewLine();
3550
3551
            return true;
3552
        }
3553
3554
        /**
3555
         * tag : B
3556
         * mode : OPEN
3557
         *
3558
         * @param  array $param
3559
         * @param  string $other
3560
         * @return boolean
3561
         */
3562 View Code Duplication
        protected function _tag_open_B($param, $other = 'b')
3563
        {
3564
            $this->parsingCss->save();
3565
            $this->parsingCss->value['font-bold'] = true;
3566
            $this->parsingCss->analyse($other, $param);
3567
            $this->parsingCss->setPosition();
3568
            $this->parsingCss->fontSet();
3569
3570
            return true;
3571
        }
3572
3573
        /**
3574
         * tag : STRONG
3575
         * mode : OPEN
3576
         *
3577
         * @param  array $param
3578
         * @return boolean
3579
         */
3580
        protected function _tag_open_STRONG($param)
3581
        {
3582
            return $this->_tag_open_B($param, 'strong');
3583
        }
3584
3585
        /**
3586
         * tag : B
3587
         * mode : CLOSE
3588
         *
3589
         * @param    array $param
3590
         * @return boolean
3591
         */
3592
        protected function _tag_close_B($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
3593
        {
3594
            $this->parsingCss->load();
3595
            $this->parsingCss->fontSet();
3596
3597
            return true;
3598
        }
3599
3600
        /**
3601
         * tag : STRONG
3602
         * mode : CLOSE
3603
         *
3604
         * @param  array $param
3605
         * @return boolean
3606
         */
3607
        protected function _tag_close_STRONG($param)
3608
        {
3609
            return $this->_tag_close_B($param);
3610
        }
3611
3612
        /**
3613
         * tag : I
3614
         * mode : OPEN
3615
         *
3616
         * @param  array $param
3617
         * @param  string $other
3618
         * @return boolean
3619
         */
3620 View Code Duplication
        protected function _tag_open_I($param, $other = 'i')
3621
        {
3622
            $this->parsingCss->save();
3623
            $this->parsingCss->value['font-italic'] = true;
3624
            $this->parsingCss->analyse($other, $param);
3625
            $this->parsingCss->setPosition();
3626
            $this->parsingCss->fontSet();
3627
3628
            return true;
3629
        }
3630
3631
        /**
3632
         * tag : ADDRESS
3633
         * mode : OPEN
3634
         *
3635
         * @param  array $param
3636
         * @return boolean
3637
         */
3638
        protected function _tag_open_ADDRESS($param)
3639
        {
3640
            return $this->_tag_open_I($param, 'address');
3641
        }
3642
3643
        /**
3644
         * tag : CITE
3645
         * mode : OPEN
3646
         *
3647
         * @param  array $param
3648
         * @return boolean
3649
         */
3650
        protected function _tag_open_CITE($param)
3651
        {
3652
            return $this->_tag_open_I($param, 'cite');
3653
        }
3654
3655
        /**
3656
         * tag : EM
3657
         * mode : OPEN
3658
         *
3659
         * @param  array $param
3660
         * @return boolean
3661
         */
3662
        protected function _tag_open_EM($param)
3663
        {
3664
            return $this->_tag_open_I($param, 'em');
3665
        }
3666
3667
        /**
3668
         * tag : SAMP
3669
         * mode : OPEN
3670
         *
3671
         * @param  array $param
3672
         * @return boolean
3673
         */
3674
        protected function _tag_open_SAMP($param)
3675
        {
3676
            return $this->_tag_open_I($param, 'samp');
3677
        }
3678
3679
        /**
3680
         * tag : I
3681
         * mode : CLOSE
3682
         *
3683
         * @param  array $param
3684
         * @return boolean
3685
         */
3686
        protected function _tag_close_I($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
3687
        {
3688
            $this->parsingCss->load();
3689
            $this->parsingCss->fontSet();
3690
3691
            return true;
3692
        }
3693
3694
        /**
3695
         * tag : ADDRESS
3696
         * mode : CLOSE
3697
         *
3698
         * @param  array $param
3699
         * @return boolean
3700
         */
3701
        protected function _tag_close_ADDRESS($param)
3702
        {
3703
            return $this->_tag_close_I($param);
3704
        }
3705
3706
        /**
3707
         * tag : CITE
3708
         * mode : CLOSE
3709
         *
3710
         * @param  array $param
3711
         * @return boolean
3712
         */
3713
        protected function _tag_close_CITE($param)
3714
        {
3715
            return $this->_tag_close_I($param);
3716
        }
3717
3718
        /**
3719
         * tag : EM
3720
         * mode : CLOSE
3721
         *
3722
         * @param  array $param
3723
         * @return boolean
3724
         */
3725
        protected function _tag_close_EM($param)
3726
        {
3727
            return $this->_tag_close_I($param);
3728
        }
3729
3730
        /**
3731
         * tag : SAMP
3732
         * mode : CLOSE
3733
         *
3734
         * @param  array $param
3735
         * @return boolean
3736
         */
3737
        protected function _tag_close_SAMP($param)
3738
        {
3739
            return $this->_tag_close_I($param);
3740
        }
3741
3742
        /**
3743
         * tag : S
3744
         * mode : OPEN
3745
         *
3746
         * @param  array $param
3747
         * @param  string $other
3748
         * @return boolean
3749
         */
3750 View Code Duplication
        protected function _tag_open_S($param, $other = 's')
3751
        {
3752
            $this->parsingCss->save();
3753
            $this->parsingCss->value['font-linethrough'] = true;
3754
            $this->parsingCss->analyse($other, $param);
3755
            $this->parsingCss->setPosition();
3756
            $this->parsingCss->fontSet();
3757
3758
            return true;
3759
        }
3760
3761
        /**
3762
         * tag : DEL
3763
         * mode : OPEN
3764
         *
3765
         * @param  array $param
3766
         * @return boolean
3767
         */
3768
        protected function _tag_open_DEL($param)
3769
        {
3770
            return $this->_tag_open_S($param, 'del');
3771
        }
3772
3773
        /**
3774
         * tag : S
3775
         * mode : CLOSE
3776
         *
3777
         * @param    array $param
3778
         * @return boolean
3779
         */
3780
        protected function _tag_close_S($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
3781
        {
3782
            $this->parsingCss->load();
3783
            $this->parsingCss->fontSet();
3784
3785
            return true;
3786
        }
3787
3788
        /**
3789
         * tag : DEL
3790
         * mode : CLOSE
3791
         *
3792
         * @param  array $param
3793
         * @return boolean
3794
         */
3795
        protected function _tag_close_DEL($param)
3796
        {
3797
            return $this->_tag_close_S($param);
3798
        }
3799
3800
        /**
3801
         * tag : U
3802
         * mode : OPEN
3803
         *
3804
         * @param  array $param
3805
         * @param  string $other
3806
         * @return boolean
3807
         */
3808 View Code Duplication
        protected function _tag_open_U($param, $other = 'u')
3809
        {
3810
            $this->parsingCss->save();
3811
            $this->parsingCss->value['font-underline'] = true;
3812
            $this->parsingCss->analyse($other, $param);
3813
            $this->parsingCss->setPosition();
3814
            $this->parsingCss->fontSet();
3815
3816
            return true;
3817
        }
3818
3819
        /**
3820
         * tag : INS
3821
         * mode : OPEN
3822
         *
3823
         * @param  array $param
3824
         * @return boolean
3825
         */
3826
        protected function _tag_open_INS($param)
3827
        {
3828
            return $this->_tag_open_U($param, 'ins');
3829
        }
3830
3831
        /**
3832
         * tag : U
3833
         * mode : CLOSE
3834
         *
3835
         * @param    array $param
3836
         * @return boolean
3837
         */
3838
        protected function _tag_close_U($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
3839
        {
3840
            $this->parsingCss->load();
3841
            $this->parsingCss->fontSet();
3842
3843
            return true;
3844
        }
3845
3846
        /**
3847
         * tag : INS
3848
         * mode : CLOSE
3849
         *
3850
         * @param  array $param
3851
         * @return boolean
3852
         */
3853
        protected function _tag_close_INS($param)
3854
        {
3855
            return $this->_tag_close_U($param);
3856
        }
3857
3858
        /**
3859
         * tag : A
3860
         * mode : OPEN
3861
         *
3862
         * @param  array $param
3863
         * @return boolean
3864
         */
3865
        protected function _tag_open_A($param)
3866
        {
3867
            $this->_isInLink = str_replace('&amp;', '&', isset($param['href']) ? $param['href'] : '');
3868
3869
            if (isset($param['name'])) {
3870
                $name = $param['name'];
3871 View Code Duplication
                if ( ! isset($this->_lstAnchor[$name])) $this->_lstAnchor[$name] = array($this->pdf->AddLink(), false);
3872
3873
                if ( ! $this->_lstAnchor[$name][1]) {
3874
                    $this->_lstAnchor[$name][1] = true;
3875
                    $this->pdf->SetLink($this->_lstAnchor[$name][0], -1, -1);
3876
                }
3877
            }
3878
3879
            if (preg_match('/^#([^#]+)$/isU', $this->_isInLink, $match)) {
3880
                $name = $match[1];
3881 View Code Duplication
                if ( ! isset($this->_lstAnchor[$name])) $this->_lstAnchor[$name] = array($this->pdf->AddLink(), false);
3882
3883
                $this->_isInLink = $this->_lstAnchor[$name][0];
3884
            }
3885
3886
            $this->parsingCss->save();
3887
            $this->parsingCss->value['font-underline'] = true;
3888
            $this->parsingCss->value['color'] = array(20, 20, 250);
3889
            $this->parsingCss->analyse('a', $param);
3890
            $this->parsingCss->setPosition();
3891
            $this->parsingCss->fontSet();
3892
3893
            return true;
3894
        }
3895
3896
        /**
3897
         * tag : A
3898
         * mode : CLOSE
3899
         *
3900
         * @param  array $param
3901
         * @return boolean
3902
         */
3903
        protected function _tag_close_A($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
3904
        {
3905
            $this->_isInLink = '';
3906
            $this->parsingCss->load();
3907
            $this->parsingCss->fontSet();
3908
3909
            return true;
3910
        }
3911
3912
        /**
3913
         * tag : H1
3914
         * mode : OPEN
3915
         *
3916
         * @param  array $param
3917
         * @param  string $other
3918
         * @return boolean
3919
         */
3920
        protected function _tag_open_H1($param, $other = 'h1')
3921
        {
3922
            if ($this->_isForOneLine) {
3923
            	return false;
3924
            }
3925
3926
            if ($this->_maxH) {
3927
            	$this->_tag_open_BR(array());
3928
            }
3929
            $this->parsingCss->save();
3930
            $this->parsingCss->value['font-bold'] = true;
3931
3932
            $size = array('h1' => '28px', 'h2' => '24px', 'h3' => '20px', 'h4' => '16px', 'h5' => '12px', 'h6' => '9px');
3933
            $this->parsingCss->value['margin']['l'] = 0;
3934
            $this->parsingCss->value['margin']['r'] = 0;
3935
            $this->parsingCss->value['margin']['t'] = $this->parsingCss->ConvertToMM('16px');
3936
            $this->parsingCss->value['margin']['b'] = $this->parsingCss->ConvertToMM('16px');
3937
            $this->parsingCss->value['font-size'] = $this->parsingCss->ConvertToMM($size[$other]);
3938
3939
            $this->parsingCss->analyse($other, $param);
3940
            $this->parsingCss->setPosition();
3941
            $this->parsingCss->fontSet();
3942
            $this->_setNewPositionForNewLine();
3943
3944
            return true;
3945
        }
3946
3947
        /**
3948
         * tag : H2
3949
         * mode : OPEN
3950
         *
3951
         * @param  array $param
3952
         * @return boolean
3953
         */
3954
        protected function _tag_open_H2($param)
3955
        {
3956
            return $this->_tag_open_H1($param, 'h2');
3957
        }
3958
3959
        /**
3960
         * tag : H3
3961
         * mode : OPEN
3962
         *
3963
         * @param  array $param
3964
         * @return boolean
3965
         */
3966
        protected function _tag_open_H3($param)
3967
        {
3968
            return $this->_tag_open_H1($param, 'h3');
3969
        }
3970
3971
        /**
3972
         * tag : H4
3973
         * mode : OPEN
3974
         *
3975
         * @param  array $param
3976
         * @return boolean
3977
         */
3978
        protected function _tag_open_H4($param)
3979
        {
3980
            return $this->_tag_open_H1($param, 'h4');
3981
        }
3982
3983
        /**
3984
         * tag : H5
3985
         * mode : OPEN
3986
         *
3987
         * @param  array $param
3988
         * @return boolean
3989
         */
3990
        protected function _tag_open_H5($param)
3991
        {
3992
            return $this->_tag_open_H1($param, 'h5');
3993
        }
3994
3995
        /**
3996
         * tag : H6
3997
         * mode : OPEN
3998
         *
3999
         * @param  array $param
4000
         * @return boolean
4001
         */
4002
        protected function _tag_open_H6($param)
4003
        {
4004
            return $this->_tag_open_H1($param, 'h6');
4005
        }
4006
4007
        /**
4008
         * tag : H1
4009
         * mode : CLOSE
4010
         *
4011
         * @param  array $param
4012
         * @return boolean
4013
         */
4014
        protected function _tag_close_H1($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
4015
        {
4016
            if ($this->_isForOneLine) {
4017
            	return false;
4018
            }
4019
4020
            $this->_maxH += $this->parsingCss->value['margin']['b'];
4021
            $h = max($this->_maxH, $this->parsingCss->getLineHeight());
4022
4023
            $this->parsingCss->load();
4024
            $this->parsingCss->fontSet();
4025
4026
            $this->_makeBreakLine($h);
4027
            $this->_maxH = 0;
4028
4029
            $this->_maxY = max($this->_maxY, $this->pdf->getY());
4030
4031
            return true;
4032
        }
4033
4034
        /**
4035
         * tag : H2
4036
         * mode : CLOSE
4037
         *
4038
         * @param  array $param
4039
         * @return boolean
4040
         */
4041
        protected function _tag_close_H2($param)
4042
        {
4043
            return $this->_tag_close_H1($param);
4044
        }
4045
4046
        /**
4047
         * tag : H3
4048
         * mode : CLOSE
4049
         *
4050
         * @param  array $param
4051
         * @return boolean
4052
         */
4053
        protected function _tag_close_H3($param)
4054
        {
4055
            return $this->_tag_close_H1($param);
4056
        }
4057
4058
        /**
4059
         * tag : H4
4060
         * mode : CLOSE
4061
         *
4062
         * @param  array $param
4063
         * @return boolean
4064
         */
4065
        protected function _tag_close_H4($param)
4066
        {
4067
            return $this->_tag_close_H1($param);
4068
        }
4069
4070
        /**
4071
         * tag : H5
4072
         * mode : CLOSE
4073
         *
4074
         * @param  array $param
4075
         * @return boolean
4076
         */
4077
        protected function _tag_close_H5($param)
4078
        {
4079
            return $this->_tag_close_H1($param);
4080
        }
4081
4082
        /**
4083
         * tag : H6
4084
         * mode : CLOSE
4085
         *
4086
         * @param  array $param
4087
         * @return boolean
4088
         */
4089
        protected function _tag_close_H6($param)
4090
        {
4091
            return $this->_tag_close_H1($param);
4092
        }
4093
4094
        /**
4095
         * tag : SPAN
4096
         * mode : OPEN
4097
         *
4098
         * @param  array $param
4099
         * @param  string $other
4100
         * @return boolean
4101
         */
4102
        protected function _tag_open_SPAN($param, $other = 'span')
4103
        {
4104
            $this->parsingCss->save();
4105
            $this->parsingCss->analyse($other, $param);
4106
            $this->parsingCss->setPosition();
4107
            $this->parsingCss->fontSet();
4108
4109
            return true;
4110
        }
4111
4112
        /**
4113
         * tag : FONT
4114
         * mode : OPEN
4115
         *
4116
         * @param  array $param
4117
         * @return boolean
4118
         */
4119
        protected function _tag_open_FONT($param)
4120
        {
4121
            return $this->_tag_open_SPAN($param, 'font');
4122
        }
4123
4124
        /**
4125
         * tag : LABEL
4126
         * mode : OPEN
4127
         *
4128
         * @param  array $param
4129
         * @return boolean
4130
         */
4131
        protected function _tag_open_LABEL($param)
4132
        {
4133
            return $this->_tag_open_SPAN($param, 'label');
4134
        }
4135
4136
        /**
4137
         * tag : SPAN
4138
         * mode : CLOSE
4139
         *
4140
         * @param  array $param
4141
         * @return boolean
4142
         */
4143
        protected function _tag_close_SPAN($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
4144
        {
4145
            $this->parsingCss->restorePosition();
4146
            $this->parsingCss->load();
4147
            $this->parsingCss->fontSet();
4148
4149
            return true;
4150
        }
4151
4152
        /**
4153
         * tag : FONT
4154
         * mode : CLOSE
4155
         *
4156
         * @param  array $param
4157
         * @return boolean
4158
         */
4159
        protected function _tag_close_FONT($param)
4160
        {
4161
            return $this->_tag_close_SPAN($param);
4162
        }
4163
4164
        /**
4165
         * tag : LABEL
4166
         * mode : CLOSE
4167
         *
4168
         * @param  array $param
4169
         * @return boolean
4170
         */
4171
        protected function _tag_close_LABEL($param)
4172
        {
4173
            return $this->_tag_close_SPAN($param);
4174
        }
4175
4176
        /**
4177
         * tag : P
4178
         * mode : OPEN
4179
         *
4180
         * @param    array $param
4181
         * @return boolean
4182
         */
4183
        protected function _tag_open_P($param)
4184
        {
4185
            if ($this->_isForOneLine) return false;
4186
4187
            if ( ! in_array($this->_previousCall, array('_tag_close_P', '_tag_close_UL'))) {
4188
                if ($this->_maxH) $this->_tag_open_BR(array());
4189
            }
4190
4191
            $this->parsingCss->save();
4192
            $this->parsingCss->analyse('p', $param);
4193
            $this->parsingCss->setPosition();
4194
            $this->parsingCss->fontSet();
4195
4196
             // cancel the effects of the setPosition
4197
            $this->pdf->setXY($this->pdf->getX() - $this->parsingCss->value['margin']['l'], $this->pdf->getY() - $this->parsingCss->value['margin']['t']);
4198
4199
            list($mL, $mR) = $this->_getMargins($this->pdf->getY());
4200
            $mR = $this->pdf->getW() - $mR;
4201
            $mL += $this->parsingCss->value['margin']['l'] + $this->parsingCss->value['padding']['l'];
4202
            $mR += $this->parsingCss->value['margin']['r'] + $this->parsingCss->value['padding']['r'];
4203
            $this->_saveMargin($mL, 0, $mR);
4204
4205
            if ($this->parsingCss->value['text-indent'] > 0) {
4206
                $y = $this->pdf->getY() + $this->parsingCss->value['margin']['t'] + $this->parsingCss->value['padding']['t'];
4207
                $this->_pageMarges[floor($y * 100)] = array($mL + $this->parsingCss->value['text-indent'], $this->pdf->getW() - $mR);
4208
                $y += $this->parsingCss->getLineHeight() * 0.1;
4209
                $this->_pageMarges[floor($y * 100)] = array($mL, $this->pdf->getW() - $mR);
4210
            }
4211
            $this->_makeBreakLine($this->parsingCss->value['margin']['t'] + $this->parsingCss->value['padding']['t']);
4212
            $this->_isInParagraph = array($mL, $mR);
0 ignored issues
show
Documentation Bug introduced by
It seems like array($mL, $mR) of type array<integer,?,{"0":"?","1":"double"}> is incompatible with the declared type boolean of property $_isInParagraph.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
4213
            return true;
4214
        }
4215
4216
        /**
4217
         * tag : P
4218
         * mode : CLOSE
4219
         *
4220
         * @param  array $param
4221
         * @return boolean
4222
         */
4223
        protected function _tag_close_P($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
4224
        {
4225
            if ($this->_isForOneLine) {
4226
            	return false;
4227
            }
4228
4229
            if ($this->_maxH) {
4230
            	$this->_tag_open_BR(array());
4231
            }
4232
            $this->_isInParagraph = false;
4233
            $this->_loadMargin();
4234
            $h = $this->parsingCss->value['margin']['b'] + $this->parsingCss->value['padding']['b'];
4235
4236
            $this->parsingCss->load();
4237
            $this->parsingCss->fontSet();
4238
            $this->_makeBreakLine($h);
4239
4240
            return true;
4241
        }
4242
4243
        /**
4244
         * tag : PRE
4245
         * mode : OPEN
4246
         *
4247
         * @param  array $param
4248
         * @param  string $other
4249
         * @return boolean
4250
         */
4251
        protected function _tag_open_PRE($param, $other = 'pre')
4252
        {
4253
            if ($other == 'pre' && $this->_maxH) $this->_tag_open_BR(array());
4254
4255
            $this->parsingCss->save();
4256
            $this->parsingCss->value['font-family'] = 'courier';
4257
            $this->parsingCss->analyse($other, $param);
4258
            $this->parsingCss->setPosition();
4259
            $this->parsingCss->fontSet();
4260
4261
            if ($other == 'pre') return $this->_tag_open_DIV($param, $other);
4262
4263
            return true;
4264
        }
4265
4266
        /**
4267
         * tag : CODE
4268
         * mode : OPEN
4269
         *
4270
         * @param  array $param
4271
         * @return boolean
4272
         */
4273
        protected function _tag_open_CODE($param)
4274
        {
4275
            return $this->_tag_open_PRE($param, 'code');
4276
        }
4277
4278
        /**
4279
         * tag : PRE
4280
         * mode : CLOSE
4281
         *
4282
         * @param  array $param
4283
         * @param  string $other
4284
         * @return boolean
4285
         */
4286
        protected function _tag_close_PRE($param, $other = 'pre')
4287
        {
4288
            if ($other == 'pre') {
4289
                if ($this->_isForOneLine) return false;
4290
4291
                $this->_tag_close_DIV($param, $other);
4292
                $this->_tag_open_BR(array());
4293
            }
4294
            $this->parsingCss->load();
4295
            $this->parsingCss->fontSet();
4296
4297
            return true;
4298
        }
4299
4300
        /**
4301
         * tag : CODE
4302
         * mode : CLOSE
4303
         *
4304
         * @param  array $param
4305
         * @return boolean
4306
         */
4307
        protected function _tag_close_CODE($param)
4308
        {
4309
            return $this->_tag_close_PRE($param, 'code');
4310
        }
4311
4312
        /**
4313
         * tag : BIG
4314
         * mode : OPEN
4315
         *
4316
         * @param    array $param
4317
         * @return boolean
4318
         */
4319 View Code Duplication
        protected function _tag_open_BIG($param)
4320
        {
4321
            $this->parsingCss->save();
4322
            $this->parsingCss->value['mini-decal'] -= $this->parsingCss->value['mini-size'] * 0.12;
4323
            $this->parsingCss->value['mini-size'] *= 1.2;
4324
            $this->parsingCss->analyse('big', $param);
4325
            $this->parsingCss->setPosition();
4326
            $this->parsingCss->fontSet();
4327
            return true;
4328
        }
4329
4330
        /**
4331
         * tag : BIG
4332
         * mode : CLOSE
4333
         *
4334
         * @param    array $param
4335
         * @return boolean
4336
         */
4337
        protected function _tag_close_BIG($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
4338
        {
4339
            $this->parsingCss->load();
4340
            $this->parsingCss->fontSet();
4341
4342
            return true;
4343
        }
4344
4345
        /**
4346
         * tag : SMALL
4347
         * mode : OPEN
4348
         *
4349
         * @param    array $param
4350
         * @return boolean
4351
         */
4352 View Code Duplication
        protected function _tag_open_SMALL($param)
4353
        {
4354
            $this->parsingCss->save();
4355
            $this->parsingCss->value['mini-decal'] += $this->parsingCss->value['mini-size'] * 0.05;
4356
            $this->parsingCss->value['mini-size'] *= 0.82;
4357
            $this->parsingCss->analyse('small', $param);
4358
            $this->parsingCss->setPosition();
4359
            $this->parsingCss->fontSet();
4360
            return true;
4361
        }
4362
4363
        /**
4364
         * tag : SMALL
4365
         * mode : CLOSE
4366
         *
4367
         * @param    array $param
4368
         * @return boolean
4369
         */
4370
        protected function _tag_close_SMALL($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
4371
        {
4372
            $this->parsingCss->load();
4373
            $this->parsingCss->fontSet();
4374
4375
            return true;
4376
        }
4377
4378
        /**
4379
         * tag : SUP
4380
         * mode : OPEN
4381
         *
4382
         * @param    array $param
4383
         * @return boolean
4384
         */
4385 View Code Duplication
        protected function _tag_open_SUP($param)
4386
        {
4387
            $this->parsingCss->save();
4388
            $this->parsingCss->value['mini-decal'] -= $this->parsingCss->value['mini-size'] * 0.15;
4389
            $this->parsingCss->value['mini-size'] *= 0.75;
4390
            $this->parsingCss->analyse('sup', $param);
4391
            $this->parsingCss->setPosition();
4392
            $this->parsingCss->fontSet();
4393
4394
            return true;
4395
        }
4396
4397
        /**
4398
         * tag : SUP
4399
         * mode : CLOSE
4400
         *
4401
         * @param    array $param
4402
         * @return boolean
4403
         */
4404
        protected function _tag_close_SUP($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
4405
        {
4406
            $this->parsingCss->load();
4407
            $this->parsingCss->fontSet();
4408
4409
            return true;
4410
        }
4411
4412
        /**
4413
         * tag : SUB
4414
         * mode : OPEN
4415
         *
4416
         * @param    array $param
4417
         * @return boolean
4418
         */
4419 View Code Duplication
        protected function _tag_open_SUB($param)
4420
        {
4421
            $this->parsingCss->save();
4422
            $this->parsingCss->value['mini-decal'] += $this->parsingCss->value['mini-size'] * 0.15;
4423
            $this->parsingCss->value['mini-size'] *= 0.75;
4424
            $this->parsingCss->analyse('sub', $param);
4425
            $this->parsingCss->setPosition();
4426
            $this->parsingCss->fontSet();
4427
            return true;
4428
        }
4429
4430
        /**
4431
         * tag : SUB
4432
         * mode : CLOSE
4433
         *
4434
         * @param    array $param
4435
         * @return boolean
4436
         */
4437
        protected function _tag_close_SUB($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
4438
        {
4439
            $this->parsingCss->load();
4440
            $this->parsingCss->fontSet();
4441
4442
            return true;
4443
        }
4444
4445
        /**
4446
         * tag : UL
4447
         * mode : OPEN
4448
         *
4449
         * @param  array $param
4450
         * @param  string $other
4451
         * @return boolean
4452
         */
4453
        protected function _tag_open_UL($param, $other = 'ul')
4454
        {
4455
            if ($this->_isForOneLine) return false;
4456
4457
            if ( ! in_array($this->_previousCall, array('_tag_close_P', '_tag_close_UL'))) {
4458
                if ($this->_maxH) $this->_tag_open_BR(array());
4459
                if ( ! count($this->_defList)) $this->_tag_open_BR(array());
4460
            }
4461
4462
            if ( ! isset($param['style']['width'])) $param['allwidth'] = true;
4463
            $param['cellspacing'] = 0;
4464
4465
            // a list is like a table
4466
            $this->_tag_open_TABLE($param, $other);
4467
4468
            // add a level of list
4469
            $this->_listeAddLevel($other, $this->parsingCss->value['list-style-type'], $this->parsingCss->value['list-style-image']);
4470
4471
            return true;
4472
        }
4473
4474
        /**
4475
         * tag : OL
4476
         * mode : OPEN
4477
         *
4478
         * @param  array $param
4479
         * @return boolean
4480
         */
4481
        protected function _tag_open_OL($param)
4482
        {
4483
            return $this->_tag_open_UL($param, 'ol');
4484
        }
4485
4486
        /**
4487
         * tag : UL
4488
         * mode : CLOSE
4489
         *
4490
         * @param  array $param
4491
         * @return boolean
4492
         */
4493
        protected function _tag_close_UL($param)
4494
        {
4495
            if ($this->_isForOneLine) return false;
4496
4497
            $this->_tag_close_TABLE($param);
4498
4499
            $this->_listeDelLevel();
4500
4501
            if ( ! $this->_subPart) {
4502
                if ( ! count($this->_defList)) $this->_tag_open_BR(array());
4503
            }
4504
4505
            return true;
4506
        }
4507
4508
        /**
4509
         * tag : OL
4510
         * mode : CLOSE
4511
         *
4512
         * @param  array $param
4513
         * @return boolean
4514
         */
4515
        protected function _tag_close_OL($param)
4516
        {
4517
            return $this->_tag_close_UL($param);
4518
        }
4519
4520
        /**
4521
         * tag : LI
4522
         * mode : OPEN
4523
         *
4524
         * @param  array $param
4525
         * @return boolean
4526
         */
4527
        protected function _tag_open_LI($param)
4528
        {
4529
            if ($this->_isForOneLine) return false;
4530
4531
            $this->_listeAddLi();
4532
4533
            if ( ! isset($param['style']['width'])) $param['style']['width'] = '100%';
4534
4535
            $paramPUCE = $param;
4536
4537
            $inf = $this->_listeGetLi();
4538
            if ($inf[0]) {
4539
                $paramPUCE['style']['font-family']     = $inf[0];
4540
                $paramPUCE['style']['text-align']      = 'li_right';
4541
                $paramPUCE['style']['vertical-align']  = 'top';
4542
                $paramPUCE['style']['width']           = $this->_listeGetWidth();
4543
                $paramPUCE['style']['padding-right']   = $this->_listeGetPadding();
4544
                $paramPUCE['txt'] = $inf[2];
4545
            } else {
4546
                $paramPUCE['style']['text-align']      = 'li_right';
4547
                $paramPUCE['style']['vertical-align']  = 'top';
4548
                $paramPUCE['style']['width']           = $this->_listeGetWidth();
4549
                $paramPUCE['style']['padding-right']   = $this->_listeGetPadding();
4550
                $paramPUCE['src'] = $inf[2];
4551
                $paramPUCE['sub_li'] = true;
4552
            }
4553
4554
            $this->_tag_open_TR($param, 'li');
4555
4556
            $this->parsingCss->save();
4557
4558
            // if small LI
4559
            if ($inf[1]) {
4560
                $this->parsingCss->value['mini-decal'] += $this->parsingCss->value['mini-size'] * 0.045;
4561
                $this->parsingCss->value['mini-size'] *= 0.75;
4562
            }
4563
4564
            // if we are in a sub html => prepare. Else : display
4565
            if ($this->_subPart) {
4566
                // TD for the puce
4567
                $tmpPos = $this->_tempPos;
4568
                $tmpLst1 = $this->parsingHtml->code[$tmpPos + 1];
4569
                $tmpLst2 = $this->parsingHtml->code[$tmpPos + 2];
4570
                $this->parsingHtml->code[$tmpPos + 1] = array();
4571
                $this->parsingHtml->code[$tmpPos + 1]['name'] = (isset($paramPUCE['src'])) ? 'img' : 'write';
4572
                $this->parsingHtml->code[$tmpPos + 1]['param']    = $paramPUCE; unset($this->parsingHtml->code[$tmpPos + 1]['param']['style']['width']);
4573
                $this->parsingHtml->code[$tmpPos + 1]['close']    = 0;
4574
                $this->parsingHtml->code[$tmpPos + 2] = array();
4575
                $this->parsingHtml->code[$tmpPos + 2]['name'] = 'li';
4576
                $this->parsingHtml->code[$tmpPos + 2]['param']    = $paramPUCE;
4577
                $this->parsingHtml->code[$tmpPos + 2]['close']    = 1;
4578
                $this->_tag_open_TD($paramPUCE, 'li_sub');
4579
                $this->_tag_close_TD($param);
4580
                $this->_tempPos = $tmpPos;
4581
                $this->parsingHtml->code[$tmpPos + 1] = $tmpLst1;
4582
                $this->parsingHtml->code[$tmpPos + 2] = $tmpLst2;
4583
            } else {
4584
                // TD for the puce
4585
                $this->_tag_open_TD($paramPUCE, 'li_sub');
4586
                unset($paramPUCE['style']['width']);
4587
                if (isset($paramPUCE['src'])) {
4588
                	$this->_tag_open_IMG($paramPUCE);
4589
                } else {
4590
                	$this->_tag_open_WRITE($paramPUCE);
4591
                }
4592
                $this->_tag_close_TD($paramPUCE);
4593
            }
4594
            $this->parsingCss->load();
4595
4596
4597
            // TD for the content
4598
            $this->_tag_open_TD($param, 'li');
4599
4600
            return true;
4601
        }
4602
4603
        /**
4604
         * tag : LI
4605
         * mode : CLOSE
4606
         *
4607
         * @param  array $param
4608
         * @return boolean
4609
         */
4610
        protected function _tag_close_LI($param)
4611
        {
4612
            if ($this->_isForOneLine) {
4613
            	return false;
4614
            }
4615
4616
            $this->_tag_close_TD($param);
4617
4618
            $this->_tag_close_TR($param);
4619
4620
            return true;
4621
        }
4622
4623
        /**
4624
         * tag : TBODY
4625
         * mode : OPEN
4626
         *
4627
         * @param  array $param
4628
         * @return boolean
4629
         */
4630 View Code Duplication
        protected function _tag_open_TBODY($param)
4631
        {
4632
            if ($this->_isForOneLine) {
4633
            	return false;
4634
            }
4635
4636
            $this->parsingCss->save();
4637
            $this->parsingCss->analyse('tbody', $param);
4638
            $this->parsingCss->setPosition();
4639
            $this->parsingCss->fontSet();
4640
4641
            return true;
4642
        }
4643
4644
        /**
4645
         * tag : TBODY
4646
         * mode : CLOSE
4647
         *
4648
         * @param  array $param
4649
         * @return boolean
4650
         */
4651
        protected function _tag_close_TBODY($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
4652
        {
4653
            if ($this->_isForOneLine) {
4654
            	return false;
4655
            }
4656
4657
            $this->parsingCss->load();
4658
            $this->parsingCss->fontSet();
4659
4660
            return true;
4661
        }
4662
4663
        /**
4664
         * tag : THEAD
4665
         * mode : OPEN
4666
         *
4667
         * @param  array $param
4668
         * @return boolean
4669
         */
4670 View Code Duplication
        protected function _tag_open_THEAD($param)
4671
        {
4672
            if ($this->_isForOneLine) {
4673
            	return false;
4674
            }
4675
4676
            $this->parsingCss->save();
4677
            $this->parsingCss->analyse('thead', $param);
4678
            $this->parsingCss->setPosition();
4679
            $this->parsingCss->fontSet();
4680
4681
            // if we are in a sub part, save the number of the first TR in the thead
4682
            if ($this->_subPart) {
4683
                HTML2PDF::$_tables[$param['num']]['thead']['tr'][0] = HTML2PDF::$_tables[$param['num']]['tr_curr'];
4684
                HTML2PDF::$_tables[$param['num']]['thead']['code'] = array();
4685
                for ($pos = $this->_tempPos; $pos < count($this->parsingHtml->code); $pos++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
4686
                    $action = $this->parsingHtml->code[$pos];
4687
                    if (strtolower($action['name']) == 'thead') $action['name'] = 'thead_sub';
4688
                    HTML2PDF::$_tables[$param['num']]['thead']['code'][] = $action;
4689
                    if (strtolower($action['name']) == 'thead_sub' && $action['close']) break;
4690
                }
4691
            } else {
4692
                $level = $this->parsingHtml->getLevel($this->_parsePos);
4693
                $this->_parsePos += count($level);
4694
                HTML2PDF::$_tables[$param['num']]['tr_curr'] += count(HTML2PDF::$_tables[$param['num']]['thead']['tr']);
4695
            }
4696
4697
            return true;
4698
        }
4699
4700
        /**
4701
         * tag : THEAD
4702
         * mode : CLOSE
4703
         *
4704
         * @param  array $param
4705
         * @return boolean
4706
         */
4707 View Code Duplication
        protected function _tag_close_THEAD($param)
4708
        {
4709
            if ($this->_isForOneLine) {
4710
            	return false;
4711
            }
4712
4713
            $this->parsingCss->load();
4714
            $this->parsingCss->fontSet();
4715
4716
            // if we are in a sub HTM, construct the list of the TR in the thead
4717
            if ($this->_subPart) {
4718
                $min = HTML2PDF::$_tables[$param['num']]['thead']['tr'][0];
4719
                $max = HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1;
4720
                HTML2PDF::$_tables[$param['num']]['thead']['tr'] = range($min, $max);
4721
            }
4722
4723
            return true;
4724
        }
4725
4726
        /**
4727
         * tag : TFOOT
4728
         * mode : OPEN
4729
         *
4730
         * @param  array $param
4731
         * @return boolean
4732
         */
4733 View Code Duplication
        protected function _tag_open_TFOOT($param)
4734
        {
4735
            if ($this->_isForOneLine) {
4736
            	return false;
4737
            }
4738
4739
            $this->parsingCss->save();
4740
            $this->parsingCss->analyse('tfoot', $param);
4741
            $this->parsingCss->setPosition();
4742
            $this->parsingCss->fontSet();
4743
4744
            // if we are in a sub part, save the number of the first TR in the tfoot
4745
            if ($this->_subPart) {
4746
                HTML2PDF::$_tables[$param['num']]['tfoot']['tr'][0] = HTML2PDF::$_tables[$param['num']]['tr_curr'];
4747
                HTML2PDF::$_tables[$param['num']]['tfoot']['code'] = array();
4748
                for ($pos = $this->_tempPos; $pos < count($this->parsingHtml->code); $pos++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
4749
                    $action = $this->parsingHtml->code[$pos];
4750
                    if (strtolower($action['name']) == 'tfoot') $action['name'] = 'tfoot_sub';
4751
                    HTML2PDF::$_tables[$param['num']]['tfoot']['code'][] = $action;
4752
                    if (strtolower($action['name']) == 'tfoot_sub' && $action['close']) break;
4753
                }
4754
            } else {
4755
                $level = $this->parsingHtml->getLevel($this->_parsePos);
4756
                $this->_parsePos += count($level);
4757
                HTML2PDF::$_tables[$param['num']]['tr_curr'] += count(HTML2PDF::$_tables[$param['num']]['tfoot']['tr']);
4758
            }
4759
4760
            return true;
4761
        }
4762
4763
        /**
4764
         * tag : TFOOT
4765
         * mode : CLOSE
4766
         *
4767
         * @param  array $param
4768
         * @return boolean
4769
         */
4770 View Code Duplication
        protected function _tag_close_TFOOT($param)
4771
        {
4772
            if ($this->_isForOneLine) {
4773
            	return false;
4774
            }
4775
4776
            $this->parsingCss->load();
4777
            $this->parsingCss->fontSet();
4778
4779
            // if we are in a sub HTM, construct the list of the TR in the tfoot
4780
            if ($this->_subPart) {
4781
                $min = HTML2PDF::$_tables[$param['num']]['tfoot']['tr'][0];
4782
                $max = HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1;
4783
                HTML2PDF::$_tables[$param['num']]['tfoot']['tr'] = range($min, $max);
4784
            }
4785
4786
            return true;
4787
        }
4788
4789
        /**
4790
         * It is not a real TAG, does not use it !
4791
         *
4792
         * @param  array $param
4793
         * @return boolean
4794
         */
4795 View Code Duplication
        protected function _tag_open_THEAD_SUB($param)
4796
        {
4797
            if ($this->_isForOneLine) {
4798
            	return false;
4799
            }
4800
4801
            $this->parsingCss->save();
4802
            $this->parsingCss->analyse('thead', $param);
4803
            $this->parsingCss->setPosition();
4804
            $this->parsingCss->fontSet();
4805
4806
            return true;
4807
        }
4808
4809
        /**
4810
         * It is not a real TAG, does not use it !
4811
         *
4812
         * @param  array $param
4813
         * @return boolean
4814
         */
4815
        protected function _tag_close_THEAD_SUB($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
4816
        {
4817
            if ($this->_isForOneLine) {
4818
            	return false;
4819
            }
4820
4821
            $this->parsingCss->load();
4822
            $this->parsingCss->fontSet();
4823
4824
            return true;
4825
        }
4826
4827
        /**
4828
         * It is not a real TAG, does not use it !
4829
         *
4830
         * @param    array $param
4831
         * @return boolean
4832
         */
4833 View Code Duplication
        protected function _tag_open_TFOOT_SUB($param)
4834
        {
4835
            if ($this->_isForOneLine) {
4836
            	return false;
4837
            }
4838
4839
            $this->parsingCss->save();
4840
            $this->parsingCss->analyse('tfoot', $param);
4841
            $this->parsingCss->setPosition();
4842
            $this->parsingCss->fontSet();
4843
4844
            return true;
4845
        }
4846
4847
        /**
4848
         * It is not a real TAG, does not use it !
4849
         *
4850
         * @param  array $param
4851
         * @return boolean
4852
         */
4853
        protected function _tag_close_TFOOT_SUB($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
4854
        {
4855
            if ($this->_isForOneLine) {
4856
            	return false;
4857
            }
4858
4859
            $this->parsingCss->load();
4860
            $this->parsingCss->fontSet();
4861
4862
            return true;
4863
        }
4864
4865
        /**
4866
         * tag : FORM
4867
         * mode : OPEN
4868
         *
4869
         * @param  array $param
4870
         * @return boolean
4871
         */
4872
        protected function _tag_open_FORM($param)
4873
        {
4874
            $this->parsingCss->save();
4875
            $this->parsingCss->analyse('form', $param);
4876
            $this->parsingCss->setPosition();
4877
            $this->parsingCss->fontSet();
4878
4879
            $this->pdf->setFormDefaultProp(
4880
                array(
4881
                    'lineWidth'=>1,
4882
                    'borderStyle'=>'solid',
4883
                    'fillColor'=>array(220, 220, 255),
4884
                    'strokeColor'=>array(128, 128, 200)
4885
                )
4886
            );
4887
4888
            $this->_isInForm = isset($param['action']) ? $param['action'] : '';
4889
4890
            return true;
4891
        }
4892
4893
        /**
4894
         * tag : FORM
4895
         * mode : CLOSE
4896
         *
4897
         * @param  array $param
4898
         * @return boolean
4899
         */
4900
        protected function _tag_close_FORM($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
4901
        {
4902
            $this->_isInForm = false;
4903
            $this->parsingCss->load();
4904
            $this->parsingCss->fontSet();
4905
4906
            return true;
4907
        }
4908
4909
        /**
4910
         * tag : TABLE
4911
         * mode : OPEN
4912
         *
4913
         * @param  array $param
4914
         * @return boolean
4915
         */
4916
        protected function _tag_open_TABLE($param, $other = 'table')
4917
        {
4918
            if ($this->_maxH) {
4919
                if ($this->_isForOneLine) {
4920
                	return false;
4921
                }
4922
                $this->_tag_open_BR(array());
4923
            }
4924
4925
            if ($this->_isForOneLine) {
4926
                $this->_maxX = $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin();
0 ignored issues
show
Documentation Bug introduced by
The property $_maxX was declared of type integer, but $this->pdf->getW() - $th...this->pdf->getrMargin() is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
4927
                return false;
4928
            }
4929
4930
            $this->_maxH = 0;
4931
4932
            $alignObject = isset($param['align']) ? strtolower($param['align']) : 'left';
4933
            if (isset($param['align'])) unset($param['align']);
4934
            if ( ! in_array($alignObject, array('left', 'center', 'right'))) $alignObject = 'left';
4935
4936
            $this->parsingCss->save();
4937
            $this->parsingCss->analyse($other, $param);
4938
            $this->parsingCss->setPosition();
4939
            $this->parsingCss->fontSet();
4940
4941
            if ($this->parsingCss->value['margin-auto']) $alignObject = 'center';
4942
4943
            // collapse table ?
4944
            $collapse = false;
4945
            if ($other == 'table') {
4946
                $collapse = isset($this->parsingCss->value['border']['collapse']) ? $this->parsingCss->value['border']['collapse'] : false;
4947
            }
4948
4949
            // if collapse => no borders for the table, only for TD
4950
            if ($collapse) {
4951
                $param['style']['border'] = 'none';
4952
                $param['cellspacing'] = 0;
4953
                $none = $this->parsingCss->readBorder('none');
4954
                $this->parsingCss->value['border']['t'] = $none;
4955
                $this->parsingCss->value['border']['r'] = $none;
4956
                $this->parsingCss->value['border']['b'] = $none;
4957
                $this->parsingCss->value['border']['l'] = $none;
4958
            }
4959
4960
            // if we are in a SUB html => prepare the properties of the table
4961
            if ($this->_subPart) {
4962
                if ($this->_debugActif) {
4963
                	$this->_DEBUG_add('Table n'.$param['num'], true);
4964
                }
4965
                HTML2PDF::$_tables[$param['num']] = array();
4966
                HTML2PDF::$_tables[$param['num']]['border']          = isset($param['border']) ? $this->parsingCss->readBorder($param['border']) : null;
4967
                HTML2PDF::$_tables[$param['num']]['cellpadding']     = $this->parsingCss->ConvertToMM(isset($param['cellpadding']) ? $param['cellpadding'] : '1px');
4968
                HTML2PDF::$_tables[$param['num']]['cellspacing']     = $this->parsingCss->ConvertToMM(isset($param['cellspacing']) ? $param['cellspacing'] : '2px');
4969
                HTML2PDF::$_tables[$param['num']]['cases']           = array(); // properties of each TR/TD
4970
                HTML2PDF::$_tables[$param['num']]['corr']            = array(); // link between TR/TD and colspan/rowspan
4971
                HTML2PDF::$_tables[$param['num']]['corr_x']          = 0; // position in 'cases'
4972
                HTML2PDF::$_tables[$param['num']]['corr_y']          = 0; // position in 'cases'
4973
                HTML2PDF::$_tables[$param['num']]['td_curr']         = 0; // current column
4974
                HTML2PDF::$_tables[$param['num']]['tr_curr']         = 0; // current row
4975
                HTML2PDF::$_tables[$param['num']]['curr_x']          = $this->pdf->getX();
4976
                HTML2PDF::$_tables[$param['num']]['curr_y']          = $this->pdf->getY();
4977
                HTML2PDF::$_tables[$param['num']]['width']           = 0; // global width
4978
                HTML2PDF::$_tables[$param['num']]['height']          = 0; // global height
4979
                HTML2PDF::$_tables[$param['num']]['align']           = $alignObject;
4980
                HTML2PDF::$_tables[$param['num']]['marge']           = array();
4981
                HTML2PDF::$_tables[$param['num']]['marge']['t']      = $this->parsingCss->value['padding']['t'] + $this->parsingCss->value['border']['t']['width'] + HTML2PDF::$_tables[$param['num']]['cellspacing'] * 0.5;
4982
                HTML2PDF::$_tables[$param['num']]['marge']['r']      = $this->parsingCss->value['padding']['r'] + $this->parsingCss->value['border']['r']['width'] + HTML2PDF::$_tables[$param['num']]['cellspacing'] * 0.5;
4983
                HTML2PDF::$_tables[$param['num']]['marge']['b']      = $this->parsingCss->value['padding']['b'] + $this->parsingCss->value['border']['b']['width'] + HTML2PDF::$_tables[$param['num']]['cellspacing'] * 0.5;
4984
                HTML2PDF::$_tables[$param['num']]['marge']['l']      = $this->parsingCss->value['padding']['l'] + $this->parsingCss->value['border']['l']['width'] + HTML2PDF::$_tables[$param['num']]['cellspacing'] * 0.5;
4985
                HTML2PDF::$_tables[$param['num']]['page']            = 0; // number of pages
4986
                HTML2PDF::$_tables[$param['num']]['new_page']        = true; // flag : new page for the current TR
4987
                HTML2PDF::$_tables[$param['num']]['style_value']     = null; // CSS style of the table
4988
                HTML2PDF::$_tables[$param['num']]['thead']           = array(); // properties on the thead
4989
                HTML2PDF::$_tables[$param['num']]['tfoot']           = array(); // properties on the tfoot
4990
                HTML2PDF::$_tables[$param['num']]['thead']['tr']     = array(); // list of the TRs in the thead
4991
                HTML2PDF::$_tables[$param['num']]['tfoot']['tr']     = array(); // list of the TRs in the tfoot
4992
                HTML2PDF::$_tables[$param['num']]['thead']['height']    = 0; // thead height
4993
                HTML2PDF::$_tables[$param['num']]['tfoot']['height']    = 0; // tfoot height
4994
                HTML2PDF::$_tables[$param['num']]['thead']['code'] = array(); // HTML content of the thead
4995
                HTML2PDF::$_tables[$param['num']]['tfoot']['code'] = array(); // HTML content of the tfoot
4996
                HTML2PDF::$_tables[$param['num']]['cols'] = array(); // properties of the COLs
4997
4998
                $this->_saveMargin($this->pdf->getlMargin(), $this->pdf->gettMargin(), $this->pdf->getrMargin());
4999
5000
                $this->parsingCss->value['width'] -= HTML2PDF::$_tables[$param['num']]['marge']['l'] + HTML2PDF::$_tables[$param['num']]['marge']['r'];
5001
            } else {
5002
                // we start from the first page and the first page of the table
5003
                HTML2PDF::$_tables[$param['num']]['page'] = 0;
5004
                HTML2PDF::$_tables[$param['num']]['td_curr']    = 0;
5005
                HTML2PDF::$_tables[$param['num']]['tr_curr']    = 0;
5006
                HTML2PDF::$_tables[$param['num']]['td_x']        = HTML2PDF::$_tables[$param['num']]['marge']['l'] + HTML2PDF::$_tables[$param['num']]['curr_x'];
5007
                HTML2PDF::$_tables[$param['num']]['td_y']        = HTML2PDF::$_tables[$param['num']]['marge']['t'] + HTML2PDF::$_tables[$param['num']]['curr_y'];
5008
5009
                // draw the borders/background of the first page/part of the table
5010
                $this->_drawRectangle(
5011
                    HTML2PDF::$_tables[$param['num']]['curr_x'],
5012
                    HTML2PDF::$_tables[$param['num']]['curr_y'],
5013
                    HTML2PDF::$_tables[$param['num']]['width'],
5014
                    isset(HTML2PDF::$_tables[$param['num']]['height'][0]) ? HTML2PDF::$_tables[$param['num']]['height'][0] : null,
5015
                    $this->parsingCss->value['border'],
5016
                    $this->parsingCss->value['padding'],
5017
                    0,
5018
                    $this->parsingCss->value['background']
5019
                );
5020
5021
                HTML2PDF::$_tables[$param['num']]['style_value'] = $this->parsingCss->value;
5022
            }
5023
5024
            return true;
5025
        }
5026
5027
        /**
5028
         * tag : TABLE
5029
         * mode : CLOSE
5030
         *
5031
         * @param  array $param
5032
         * @return boolean
5033
         */
5034
        protected function _tag_close_TABLE($param)
5035
        {
5036
            if ($this->_isForOneLine) {
5037
            	return false;
5038
            }
5039
5040
            $this->_maxH = 0;
5041
5042
            // if we are in a sub HTML
5043
            if ($this->_subPart) {
5044
                // calculate the size of each case
5045
                $this->_calculateTableCellSize(HTML2PDF::$_tables[$param['num']]['cases'], HTML2PDF::$_tables[$param['num']]['corr']);
5046
5047
                // calculate the height of the thead and the tfoot
5048
                $lst = array('thead', 'tfoot');
5049
                foreach ($lst as $mode) {
5050
                    HTML2PDF::$_tables[$param['num']][$mode]['height'] = 0;
5051
                    foreach (HTML2PDF::$_tables[$param['num']][$mode]['tr'] as $tr) {
5052
                        // hauteur de la ligne tr
5053
                        $h = 0;
5054
                        for ($i = 0; $i < count(HTML2PDF::$_tables[$param['num']]['cases'][$tr]); $i++)
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
5055 View Code Duplication
                            if (HTML2PDF::$_tables[$param['num']]['cases'][$tr][$i]['rowspan'] == 1)
5056
                                $h = max($h, HTML2PDF::$_tables[$param['num']]['cases'][$tr][$i]['h']);
5057
                        HTML2PDF::$_tables[$param['num']][$mode]['height'] += $h;
5058
                    }
5059
                }
5060
5061
                // calculate the width of the table
5062
                HTML2PDF::$_tables[$param['num']]['width'] = HTML2PDF::$_tables[$param['num']]['marge']['l'] + HTML2PDF::$_tables[$param['num']]['marge']['r'];
5063
                if (isset(HTML2PDF::$_tables[$param['num']]['cases'][0])) {
5064
                    foreach (HTML2PDF::$_tables[$param['num']]['cases'][0] as $case) {
5065
                        HTML2PDF::$_tables[$param['num']]['width'] += $case['w'];
5066
                    }
5067
                }
5068
5069
                // X position of the table
5070
                $old = $this->parsingCss->getOldValues();
5071
                $parentWidth = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin();
5072
                $x = HTML2PDF::$_tables[$param['num']]['curr_x'];
5073
                $w = HTML2PDF::$_tables[$param['num']]['width'];
5074
                if ($parentWidth > $w) {
5075
                    if (HTML2PDF::$_tables[$param['num']]['align'] == 'center')
5076
                        $x = $x + ($parentWidth - $w) * 0.5;
5077
                    else if (HTML2PDF::$_tables[$param['num']]['align'] == 'right')
5078
                        $x = $x + $parentWidth - $w;
5079
5080
                    HTML2PDF::$_tables[$param['num']]['curr_x'] = $x;
5081
                }
5082
5083
                // calculate the height of the table
5084
                HTML2PDF::$_tables[$param['num']]['height'] = array();
5085
5086
                // minimum of the height because of margins, and of the thead and tfoot height
5087
                $h0 = HTML2PDF::$_tables[$param['num']]['marge']['t'] + HTML2PDF::$_tables[$param['num']]['marge']['b'];
5088
                $h0 += HTML2PDF::$_tables[$param['num']]['thead']['height'] + HTML2PDF::$_tables[$param['num']]['tfoot']['height'];
5089
5090
                // max height of the page
5091
                $max = $this->pdf->getH() - $this->pdf->getbMargin();
5092
5093
                // current position on the page
5094
                $y = HTML2PDF::$_tables[$param['num']]['curr_y'];
5095
                $height = $h0;
5096
5097
                // we get the height of each line
5098
                for ($k = 0; $k < count(HTML2PDF::$_tables[$param['num']]['cases']); $k++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
5099
5100
                    // if it is a TR of the thead or of the tfoot => skip
5101
                    if (in_array($k, HTML2PDF::$_tables[$param['num']]['thead']['tr'])) {
5102
                    	continue;
5103
                    }
5104
                    if (in_array($k, HTML2PDF::$_tables[$param['num']]['tfoot']['tr'])) {
5105
                    	continue;
5106
                    }
5107
5108
                    // height of the line
5109
                    $th = 0;
5110
                    $h = 0;
5111
                    for ($i = 0; $i < count(HTML2PDF::$_tables[$param['num']]['cases'][$k]); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
5112
                        $h = max($h, HTML2PDF::$_tables[$param['num']]['cases'][$k][$i]['h']);
5113
5114 View Code Duplication
                        if (HTML2PDF::$_tables[$param['num']]['cases'][$k][$i]['rowspan'] == 1)
5115
                            $th = max($th, HTML2PDF::$_tables[$param['num']]['cases'][$k][$i]['h']);
5116
                    }
5117
5118
                    // if the row does not fit on the page => new page
5119
                    if ($y + $h + $height > $max) {
5120
                        if ($height == $h0) $height = null;
5121
                        HTML2PDF::$_tables[$param['num']]['height'][] = $height;
5122
                        $height = $h0;
5123
                        $y = $this->_margeTop;
5124
                    }
5125
                    $height += $th;
5126
                }
5127
5128
                // if ther is a height at the end, add it
5129
                if ($height != $h0 || $k == 0) HTML2PDF::$_tables[$param['num']]['height'][] = $height;
5130
            } else {
5131
                // if we have tfoor, draw it
5132 View Code Duplication
                if (count(HTML2PDF::$_tables[$param['num']]['tfoot']['code'])) {
5133
                    $tmpTR = HTML2PDF::$_tables[$param['num']]['tr_curr'];
5134
                    $tmpTD = HTML2PDF::$_tables[$param['num']]['td_curr'];
5135
                    $oldParsePos = $this->_parsePos;
5136
                    $oldParseCode = $this->parsingHtml->code;
5137
5138
                    HTML2PDF::$_tables[$param['num']]['tr_curr'] = HTML2PDF::$_tables[$param['num']]['tfoot']['tr'][0];
5139
                    HTML2PDF::$_tables[$param['num']]['td_curr'] = 0;
5140
                    $this->_parsePos = 0;
5141
                    $this->parsingHtml->code = HTML2PDF::$_tables[$param['num']]['tfoot']['code'];
5142
                    $this->_isInTfoot = true;
5143
                    $this->_makeHTMLcode();
5144
                    $this->_isInTfoot = false;
5145
5146
                    $this->_parsePos = $oldParsePos;
5147
                    $this->parsingHtml->code = $oldParseCode;
5148
                    HTML2PDF::$_tables[$param['num']]['tr_curr'] = $tmpTR;
5149
                    HTML2PDF::$_tables[$param['num']]['td_curr'] = $tmpTD;
5150
                }
5151
5152
                // get the positions of the end of the table
5153
                $x = HTML2PDF::$_tables[$param['num']]['curr_x'] + HTML2PDF::$_tables[$param['num']]['width'];
5154
                if (count(HTML2PDF::$_tables[$param['num']]['height']) > 1)
5155
                    $y = $this->_margeTop + HTML2PDF::$_tables[$param['num']]['height'][count(HTML2PDF::$_tables[$param['num']]['height']) - 1];
5156
                else if (count(HTML2PDF::$_tables[$param['num']]['height']) == 1)
5157
                    $y = HTML2PDF::$_tables[$param['num']]['curr_y'] + HTML2PDF::$_tables[$param['num']]['height'][count(HTML2PDF::$_tables[$param['num']]['height']) - 1];
5158
                else
5159
                    $y = HTML2PDF::$_tables[$param['num']]['curr_y'];
5160
5161
                $this->_maxX = max($this->_maxX, $x);
5162
                $this->_maxY = max($this->_maxY, $y);
5163
5164
                $this->pdf->setXY($this->pdf->getlMargin(), $y);
5165
5166
                $this->_loadMargin();
5167
5168
                if ($this->_debugActif) {
5169
                	$this->_DEBUG_add('Table '.$param['num'], false);
5170
                }
5171
            }
5172
5173
            $this->parsingCss->load();
5174
            $this->parsingCss->fontSet();
5175
5176
5177
            return true;
5178
        }
5179
5180
        /**
5181
         * tag : COL
5182
         * mode : OPEN
5183
         *
5184
         * @param  array $param
5185
         * @return boolean|null
5186
         */
5187
        protected function _tag_open_COL($param)
5188
        {
5189
            $span = isset($param['span']) ? $param['span'] : 1;
5190
            for ($k = 0; $k < $span; $k++)
5191
                HTML2PDF::$_tables[$param['num']]['cols'][] = $param;
5192
        }
5193
5194
        /**
5195
         * tag : COL
5196
         * mode : CLOSE
5197
         *
5198
         * @param  array $param
5199
         * @return boolean
5200
         */
5201
        protected function _tag_close_COL($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
5202
        {
5203
            // there is nothing to do here
5204
5205
            return true;
5206
        }
5207
5208
        /**
5209
         * tag : TR
5210
         * mode : OPEN
5211
         *
5212
         * @param  array $param
5213
         * @return boolean
5214
         */
5215
        protected function _tag_open_TR($param, $other = 'tr')
5216
        {
5217
            if ($this->_isForOneLine) {
5218
            	return false;
5219
            }
5220
5221
            $this->_maxH = 0;
5222
5223
            $this->parsingCss->save();
5224
            $this->parsingCss->analyse($other, $param);
5225
            $this->parsingCss->setPosition();
5226
            $this->parsingCss->fontSet();
5227
5228
            // position in the table
5229
            HTML2PDF::$_tables[$param['num']]['tr_curr']++;
5230
            HTML2PDF::$_tables[$param['num']]['td_curr'] = 0;
5231
5232
            // if we are not in a sub html
5233
            if ( ! $this->_subPart) {
5234
5235
                // Y after the row
5236
                $ty = null;
5237
                for ($ii = 0; $ii < count(HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1]); $ii++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
5238
                    $ty = max($ty, HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1][$ii]['h']);
5239
                }
5240
5241
                // height of the tfoot
5242
                $hfoot = HTML2PDF::$_tables[$param['num']]['tfoot']['height'];
5243
5244
                // if the line does not fit on the page => new page
5245
                if ( ! $this->_isInTfoot && HTML2PDF::$_tables[$param['num']]['td_y'] + HTML2PDF::$_tables[$param['num']]['marge']['b'] + $ty + $hfoot > $this->pdf->getH() - $this->pdf->getbMargin()) {
5246
5247
                    // fi ther is a tfoot => draw it
5248 View Code Duplication
                    if (count(HTML2PDF::$_tables[$param['num']]['tfoot']['code'])) {
5249
                        $tmpTR = HTML2PDF::$_tables[$param['num']]['tr_curr'];
5250
                        $tmpTD = HTML2PDF::$_tables[$param['num']]['td_curr'];
5251
                        $oldParsePos = $this->_parsePos;
5252
                        $oldParseCode = $this->parsingHtml->code;
5253
5254
                        HTML2PDF::$_tables[$param['num']]['tr_curr'] = HTML2PDF::$_tables[$param['num']]['tfoot']['tr'][0];
5255
                        HTML2PDF::$_tables[$param['num']]['td_curr'] = 0;
5256
                        $this->_parsePos = 0;
5257
                        $this->parsingHtml->code = HTML2PDF::$_tables[$param['num']]['tfoot']['code'];
5258
                        $this->_isInTfoot = true;
5259
                        $this->_makeHTMLcode();
5260
                        $this->_isInTfoot = false;
5261
5262
                        $this->_parsePos = $oldParsePos;
5263
                        $this->parsingHtml->code = $oldParseCode;
5264
                        HTML2PDF::$_tables[$param['num']]['tr_curr'] = $tmpTR;
5265
                        HTML2PDF::$_tables[$param['num']]['td_curr'] = $tmpTD;
5266
                    }
5267
5268
                    // new page
5269
                    HTML2PDF::$_tables[$param['num']]['new_page'] = true;
5270
                    $this->_setNewPage();
5271
5272
                    // new position
5273
                    HTML2PDF::$_tables[$param['num']]['page']++;
5274
                    HTML2PDF::$_tables[$param['num']]['curr_y'] = $this->pdf->getY();
5275
                    HTML2PDF::$_tables[$param['num']]['td_y'] = HTML2PDF::$_tables[$param['num']]['curr_y'] + HTML2PDF::$_tables[$param['num']]['marge']['t'];
5276
5277
                    // if we have the height of the tbale on the page => draw borders and background
5278
                    if (isset(HTML2PDF::$_tables[$param['num']]['height'][HTML2PDF::$_tables[$param['num']]['page']])) {
5279
                        $old = $this->parsingCss->value;
5280
                        $this->parsingCss->value = HTML2PDF::$_tables[$param['num']]['style_value'];
5281
5282
                        $this->_drawRectangle(
5283
                            HTML2PDF::$_tables[$param['num']]['curr_x'],
5284
                            HTML2PDF::$_tables[$param['num']]['curr_y'],
5285
                            HTML2PDF::$_tables[$param['num']]['width'],
5286
                            HTML2PDF::$_tables[$param['num']]['height'][HTML2PDF::$_tables[$param['num']]['page']],
5287
                            $this->parsingCss->value['border'],
5288
                            $this->parsingCss->value['padding'],
5289
                            HTML2PDF::$_tables[$param['num']]['cellspacing'] * 0.5,
5290
                            $this->parsingCss->value['background']
5291
                        );
5292
5293
                        $this->parsingCss->value = $old;
5294
                    }
5295
                }
5296
5297
                // if we are in a new page, and if we have a thead => draw it
5298
                if (HTML2PDF::$_tables[$param['num']]['new_page'] && count(HTML2PDF::$_tables[$param['num']]['thead']['code'])) {
5299
                    HTML2PDF::$_tables[$param['num']]['new_page'] = false;
5300
                    $tmpTR = HTML2PDF::$_tables[$param['num']]['tr_curr'];
5301
                    $tmpTD = HTML2PDF::$_tables[$param['num']]['td_curr'];
5302
                    $oldParsePos = $this->_parsePos;
5303
                    $oldParseCode = $this->parsingHtml->code;
5304
5305
                    HTML2PDF::$_tables[$param['num']]['tr_curr'] = HTML2PDF::$_tables[$param['num']]['thead']['tr'][0];
5306
                    HTML2PDF::$_tables[$param['num']]['td_curr'] = 0;
5307
                    $this->_parsePos = 0;
5308
                    $this->parsingHtml->code = HTML2PDF::$_tables[$param['num']]['thead']['code'];
5309
                    $this->_isInThead = true;
5310
                    $this->_makeHTMLcode();
5311
                    $this->_isInThead = false;
5312
5313
                    $this->_parsePos = $oldParsePos;
5314
                    $this->parsingHtml->code = $oldParseCode;
5315
                    HTML2PDF::$_tables[$param['num']]['tr_curr'] = $tmpTR;
5316
                    HTML2PDF::$_tables[$param['num']]['td_curr'] = $tmpTD;
5317
                    HTML2PDF::$_tables[$param['num']]['new_page'] = true;
5318
                }
5319
            // else (in a sub HTML)
5320
            } else {
5321
                // prepare it
5322
                HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1] = array();
5323
                if ( ! isset(HTML2PDF::$_tables[$param['num']]['corr'][HTML2PDF::$_tables[$param['num']]['corr_y']]))
5324
                    HTML2PDF::$_tables[$param['num']]['corr'][HTML2PDF::$_tables[$param['num']]['corr_y']] = array();
5325
5326
                HTML2PDF::$_tables[$param['num']]['corr_x'] = 0;
5327 View Code Duplication
                while (isset(HTML2PDF::$_tables[$param['num']]['corr'][HTML2PDF::$_tables[$param['num']]['corr_y']][HTML2PDF::$_tables[$param['num']]['corr_x']]))
5328
                    HTML2PDF::$_tables[$param['num']]['corr_x']++;
5329
            }
5330
5331
            return true;
5332
        }
5333
5334
        /**
5335
         * tag : TR
5336
         * mode : CLOSE
5337
         *
5338
         * @param  array $param
5339
         * @return boolean
5340
         */
5341
        protected function _tag_close_TR($param)
5342
        {
5343
            if ($this->_isForOneLine) {
5344
            	return false;
5345
            }
5346
5347
            $this->_maxH = 0;
5348
5349
            $this->parsingCss->load();
5350
            $this->parsingCss->fontSet();
5351
5352
            // if we are not in a sub HTML
5353
            if ( ! $this->_subPart) {
5354
5355
                // Y of the current line
5356
                $ty = null;
5357
                for ($ii = 0; $ii < count(HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1]); $ii++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
5358
                    if (HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1][$ii]['rowspan'] == 1) {
5359
                        $ty = HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1][$ii]['h'];
5360
                    }
5361
                }
5362
5363
                // new position
5364
                HTML2PDF::$_tables[$param['num']]['td_x'] = HTML2PDF::$_tables[$param['num']]['curr_x'] + HTML2PDF::$_tables[$param['num']]['marge']['l'];
5365
                HTML2PDF::$_tables[$param['num']]['td_y'] += $ty;
5366
                HTML2PDF::$_tables[$param['num']]['new_page'] = false;
5367
            } else {
5368
                HTML2PDF::$_tables[$param['num']]['corr_y']++;
5369
            }
5370
5371
            return true;
5372
        }
5373
5374
        /**
5375
         * tag : TD
5376
         * mode : OPEN
5377
         *
5378
         * @param  array $param
5379
         * @return boolean
5380
         */
5381
        protected function _tag_open_TD($param, $other = 'td')
5382
        {
5383
            if ($this->_isForOneLine) {
5384
            	return false;
5385
            }
5386
5387
            $this->_maxH = 0;
5388
5389
            $param['cellpadding'] = HTML2PDF::$_tables[$param['num']]['cellpadding'].'mm';
5390
            $param['cellspacing'] = HTML2PDF::$_tables[$param['num']]['cellspacing'].'mm';
5391
5392
            // specific style for LI
5393
            if ($other == 'li') {
5394
                $specialLi = true;
5395
            } else {
5396
                $specialLi = false;
5397
                if ($other == 'li_sub') {
5398
                    $param['style']['border'] = 'none';
5399
                    $param['style']['background-color']    = 'transparent';
5400
                    $param['style']['background-image']    = 'none';
5401
                    $param['style']['background-position'] = '';
5402
                    $param['style']['background-repeat']   = '';
5403
                    $other = 'li';
5404
                }
5405
            }
5406
5407
            // get the properties of the TD
5408
            $x = HTML2PDF::$_tables[$param['num']]['td_curr'];
5409
            $y = HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1;
5410
            $colspan = isset($param['colspan']) ? $param['colspan'] : 1;
5411
            $rowspan = isset($param['rowspan']) ? $param['rowspan'] : 1;
5412
5413
            // flag for collapse table
5414
            $collapse = false;
5415
5416
            // specific traitment for TD and TH
5417
            if (in_array($other, array('td', 'th'))) {
5418
                // id of the column
5419
                $numCol = isset(HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['Xr']) ? HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['Xr'] : HTML2PDF::$_tables[$param['num']]['corr_x'];
5420
5421
                // we get the properties of the COL tag, if exist
5422
                if (isset(HTML2PDF::$_tables[$param['num']]['cols'][$numCol])) {
5423
5424
                    $colParam = HTML2PDF::$_tables[$param['num']]['cols'][$numCol];
5425
5426
                    // for colspans => we get all the neede widths
5427
                    $colParam['style']['width'] = array();
5428
                    for ($k = 0; $k < $colspan; $k++) {
5429
                        if (isset(HTML2PDF::$_tables[$param['num']]['cols'][$numCol + $k]['style']['width'])) {
5430
                            $colParam['style']['width'][] = HTML2PDF::$_tables[$param['num']]['cols'][$numCol + $k]['style']['width'];
5431
                        }
5432
                    }
5433
5434
                    // calculate the total width of the column
5435
                    $total = '';
5436
                    $last = $this->parsingCss->getLastWidth();
5437
                    if (count($colParam['style']['width'])) {
5438
                        $total = $colParam['style']['width'][0]; unset($colParam['style']['width'][0]);
5439
                        foreach ($colParam['style']['width'] as $width) {
5440
                            if (substr($total, -1) == '%' && substr($width, -1) == '%')
5441
                                $total = (str_replace('%', '', $total) + str_replace('%', '', $width)).'%';
5442
                            else
5443
                                $total = ($this->parsingCss->ConvertToMM($total, $last) + $this->parsingCss->ConvertToMM($width, $last)).'mm';
5444
                        }
5445
                    }
5446
5447
                    // get the final width
5448
                    if ($total) {
5449
                        $colParam['style']['width'] = $total;
5450
                    } else {
5451
                        unset($colParam['style']['width']);
5452
                    }
5453
5454
5455
                    // merge the styles of the COL and the TD
5456
                    $param['style'] = array_merge($colParam['style'], $param['style']);
5457
5458
                    // merge the class of the COL and the TD
5459
                    if (isset($colParam['class'])) {
5460
                        $param['class'] = $colParam['class'].(isset($param['class']) ? ' '.$param['class'] : '');
5461
                    }
5462
                }
5463
5464
                $collapse = isset($this->parsingCss->value['border']['collapse']) ? $this->parsingCss->value['border']['collapse'] : false;
5465
            }
5466
5467
            $this->parsingCss->save();
5468
5469
            // legacy for TD and TH
5470
            $legacy = null;
5471
            if (in_array($other, array('td', 'th'))) {
5472
                $legacy = array();
5473
5474
                $old = $this->parsingCss->getLastValue('background');
5475
                if ($old && ($old['color'] || $old['image'])) {
5476
                                    $legacy['background'] = $old;
5477
                }
5478
5479
                if (HTML2PDF::$_tables[$param['num']]['border']) {
5480
                    $legacy['border'] = array();
5481
                    $legacy['border']['l'] = HTML2PDF::$_tables[$param['num']]['border'];
5482
                    $legacy['border']['t'] = HTML2PDF::$_tables[$param['num']]['border'];
5483
                    $legacy['border']['r'] = HTML2PDF::$_tables[$param['num']]['border'];
5484
                    $legacy['border']['b'] = HTML2PDF::$_tables[$param['num']]['border'];
5485
                }
5486
            }
5487
            $return = $this->parsingCss->analyse($other, $param, $legacy);
5488
5489
            if ($specialLi) {
5490
                $this->parsingCss->value['width'] -= $this->parsingCss->ConvertToMM($this->_listeGetWidth());
5491
                $this->parsingCss->value['width'] -= $this->parsingCss->ConvertToMM($this->_listeGetPadding());
5492
            }
5493
            $this->parsingCss->setPosition();
5494
            $this->parsingCss->fontSet();
5495
5496
            // if tale collapse => modify the borders
5497
            if ($collapse) {
5498
                if ( ! $this->_subPart) {
5499
                    if (
5500
                        (HTML2PDF::$_tables[$param['num']]['tr_curr'] > 1 && ! HTML2PDF::$_tables[$param['num']]['new_page']) ||
5501
                        ( ! $this->_isInThead && count(HTML2PDF::$_tables[$param['num']]['thead']['code']))
5502
                    ) {
5503
                        $this->parsingCss->value['border']['t'] = $this->parsingCss->readBorder('none');
5504
                    }
5505
                }
5506
5507
                if (HTML2PDF::$_tables[$param['num']]['td_curr'] > 0) {
5508
                    if ( ! $return) $this->parsingCss->value['width'] += $this->parsingCss->value['border']['l']['width'];
5509
                    $this->parsingCss->value['border']['l'] = $this->parsingCss->readBorder('none');
5510
                }
5511
            }
5512
5513
            // margins of the table
5514
            $marge = array();
5515
            $marge['t'] = $this->parsingCss->value['padding']['t'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['t']['width'];
5516
            $marge['r'] = $this->parsingCss->value['padding']['r'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['r']['width'];
5517
            $marge['b'] = $this->parsingCss->value['padding']['b'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['b']['width'];
5518
            $marge['l'] = $this->parsingCss->value['padding']['l'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['l']['width'];
5519
5520
            // if we are in a sub HTML
5521
            if ($this->_subPart) {
5522
                // new position in the table
5523
                HTML2PDF::$_tables[$param['num']]['td_curr']++;
5524
                HTML2PDF::$_tables[$param['num']]['cases'][$y][$x] = array();
5525
                HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['w'] = 0;
5526
                HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['h'] = 0;
5527
                HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['dw'] = 0;
5528
                HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['colspan'] = $colspan;
5529
                HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['rowspan'] = $rowspan;
5530
                HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['Xr'] = HTML2PDF::$_tables[$param['num']]['corr_x'];
5531
                HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['Yr'] = HTML2PDF::$_tables[$param['num']]['corr_y'];
5532
5533
                // prepare the mapping for rowspan and colspan
5534
                for ($j = 0; $j < $rowspan; $j++) {
5535
                    for ($i = 0; $i < $colspan; $i++) {
5536
                        HTML2PDF::$_tables[$param['num']]['corr']
5537
                            [HTML2PDF::$_tables[$param['num']]['corr_y'] + $j]
5538
                            [HTML2PDF::$_tables[$param['num']]['corr_x'] + $i] = ($i + $j > 0) ? '' : array($x, $y, $colspan, $rowspan);
5539
                    }
5540
                }
5541
                HTML2PDF::$_tables[$param['num']]['corr_x'] += $colspan;
5542 View Code Duplication
                while (isset(HTML2PDF::$_tables[$param['num']]['corr'][HTML2PDF::$_tables[$param['num']]['corr_y']][HTML2PDF::$_tables[$param['num']]['corr_x']])) {
5543
                    HTML2PDF::$_tables[$param['num']]['corr_x']++;
5544
                }
5545
5546
                // extract the content of the TD, and calculate his size
5547
                $level = $this->parsingHtml->getLevel($this->_tempPos);
5548
                $this->_createSubHTML($this->_subHtml);
5549
                $this->_subHtml->parsingHtml->code = $level;
5550
                $this->_subHtml->_makeHTMLcode();
5551
                $this->_tempPos += count($level);
5552
            } else {
5553
                // new position in the table
5554
                HTML2PDF::$_tables[$param['num']]['td_curr']++;
5555
                HTML2PDF::$_tables[$param['num']]['td_x'] += HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['dw'];
5556
5557
                // borders and background of the TD
5558
                $this->_drawRectangle(
5559
                    HTML2PDF::$_tables[$param['num']]['td_x'],
5560
                    HTML2PDF::$_tables[$param['num']]['td_y'],
5561
                    HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['w'],
5562
                    HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['h'],
5563
                    $this->parsingCss->value['border'],
5564
                    $this->parsingCss->value['padding'],
5565
                    HTML2PDF::$_tables[$param['num']]['cellspacing'] * 0.5,
5566
                    $this->parsingCss->value['background']
5567
                );
5568
5569
                $this->parsingCss->value['width'] = HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['w'] - $marge['l'] - $marge['r'];
5570
5571
                // marges = size of the TD
5572
                $mL = HTML2PDF::$_tables[$param['num']]['td_x'] + $marge['l'];
5573
                $mR = $this->pdf->getW() - $mL - $this->parsingCss->value['width'];
5574
                $this->_saveMargin($mL, 0, $mR);
5575
5576
                // position of the content, from vertical-align
5577
                $hCorr = HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['h'];
5578
                $hReel = HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['real_h'];
5579
                switch ($this->parsingCss->value['vertical-align'])
5580
                {
5581
                    case 'bottom':
5582
                        $yCorr = $hCorr - $hReel;
5583
                        break;
5584
5585
                    case 'middle':
5586
                        $yCorr = ($hCorr - $hReel) * 0.5;
5587
                        break;
5588
5589
                    case 'top':
5590
                    default:
5591
                        $yCorr = 0;
5592
                        break;
5593
                }
5594
5595
                //  position of the content
5596
                $x = HTML2PDF::$_tables[$param['num']]['td_x'] + $marge['l'];
5597
                $y = HTML2PDF::$_tables[$param['num']]['td_y'] + $marge['t'] + $yCorr;
5598
                $this->pdf->setXY($x, $y);
5599
                $this->_setNewPositionForNewLine();
5600
            }
5601
5602
            return true;
5603
        }
5604
5605
        /**
5606
         * tag : TD
5607
         * mode : CLOSE
5608
         *
5609
         * @param    array $param
5610
         * @return boolean
5611
         */
5612
        protected function _tag_close_TD($param)
5613
        {
5614
            if ($this->_isForOneLine) {
5615
            	return false;
5616
            }
5617
5618
            $this->_maxH = 0;
5619
5620
            // get the margins
5621
            $marge = array();
5622
            $marge['t'] = $this->parsingCss->value['padding']['t'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['t']['width'];
5623
            $marge['r'] = $this->parsingCss->value['padding']['r'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['r']['width'];
5624
            $marge['b'] = $this->parsingCss->value['padding']['b'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['b']['width'];
5625
            $marge['l'] = $this->parsingCss->value['padding']['l'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['l']['width'];
5626
            $marge['t'] += 0.001;
5627
            $marge['r'] += 0.001;
5628
            $marge['b'] += 0.001;
5629
            $marge['l'] += 0.001;
5630
5631
            // if we are in a sub HTML
5632
            if ($this->_subPart) {
5633
5634
                // it msut take only one page
5635
                if ($this->_testTdInOnepage && $this->_subHtml->pdf->getPage() > 1) {
5636
                    throw new HTML2PDF_exception(7);
5637
                }
5638
5639
                // size of the content of the TD
5640
                $w0 = $this->_subHtml->_maxX + $marge['l'] + $marge['r'];
5641
                $h0 = $this->_subHtml->_maxY + $marge['t'] + $marge['b'];
5642
5643
                // size from the CSS style
5644
                $w2 = $this->parsingCss->value['width'] + $marge['l'] + $marge['r'];
5645
                $h2 = $this->parsingCss->value['height'] + $marge['t'] + $marge['b'];
5646
5647
                // final size of the TD
5648
                HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1][HTML2PDF::$_tables[$param['num']]['td_curr'] - 1]['w'] = max(array($w0, $w2));
5649
                HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1][HTML2PDF::$_tables[$param['num']]['td_curr'] - 1]['h'] = max(array($h0, $h2));
5650
5651
                // real position of the content
5652
                HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1][HTML2PDF::$_tables[$param['num']]['td_curr'] - 1]['real_w'] = $w0;
5653
                HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1][HTML2PDF::$_tables[$param['num']]['td_curr'] - 1]['real_h'] = $h0;
5654
5655
                // destroy the sub HTML
5656
                $this->_destroySubHTML($this->_subHtml);
5657
            } else {
5658
                $this->_loadMargin();
5659
5660
                HTML2PDF::$_tables[$param['num']]['td_x'] += HTML2PDF::$_tables[$param['num']]['cases'][HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1][HTML2PDF::$_tables[$param['num']]['td_curr'] - 1]['w'];
5661
            }
5662
5663
            $this->parsingCss->load();
5664
            $this->parsingCss->fontSet();
5665
5666
            return true;
5667
        }
5668
5669
5670
        /**
5671
         * tag : TH
5672
         * mode : OPEN
5673
         *
5674
         * @param  array $param
5675
         * @return boolean
5676
         */
5677
        protected function _tag_open_TH($param)
5678
        {
5679
            if ($this->_isForOneLine) {
5680
            	return false;
5681
            }
5682
5683
            $this->parsingCss->save();
5684
            $this->parsingCss->value['font-bold'] = true;
5685
5686
            $this->_tag_open_TD($param, 'th');
5687
5688
            return true;
5689
        }
5690
5691
        /**
5692
         * tag : TH
5693
         * mode : CLOSE
5694
         *
5695
         * @param  array $param
5696
         * @return boolean
5697
         */
5698
        protected function _tag_close_TH($param)
5699
        {
5700
            if ($this->_isForOneLine) {
5701
            	return false;
5702
            }
5703
5704
            $this->_tag_close_TD($param);
5705
5706
            $this->parsingCss->load();
5707
5708
            return true;
5709
        }
5710
5711
        /**
5712
         * tag : IMG
5713
         * mode : OPEN
5714
         *
5715
         * @param  array $param
5716
         * @return boolean
5717
         */
5718
        protected function _tag_open_IMG($param)
5719
        {
5720
            $src = str_replace('&amp;', '&', $param['src']);
5721
5722
            $this->parsingCss->save();
5723
            $this->parsingCss->value['width'] = 0;
5724
            $this->parsingCss->value['height']    = 0;
5725
            $this->parsingCss->value['border']    = array('type' => 'none', 'width' => 0, 'color' => array(0, 0, 0));
5726
            $this->parsingCss->value['background'] = array('color' => null, 'image' => null, 'position' => null, 'repeat' => null);
5727
            $this->parsingCss->analyse('img', $param);
5728
            $this->parsingCss->setPosition();
5729
            $this->parsingCss->fontSet();
5730
5731
            $res = $this->_drawImage($src, isset($param['sub_li']));
5732
            if ( ! $res) return $res;
5733
5734
            $this->parsingCss->load();
5735
            $this->parsingCss->fontSet();
5736
            $this->_maxE++;
5737
5738
            return true;
5739
        }
5740
5741
        /**
5742
         * tag : SELECT
5743
         * mode : OPEN
5744
         *
5745
         * @param  array $param
5746
         * @return boolean
5747
         */
5748
        protected function _tag_open_SELECT($param)
5749
        {
5750 View Code Duplication
            if ( ! isset($param['name'])) {
5751
                $param['name'] = 'champs_pdf_'.(count($this->_lstField) + 1);
5752
            }
5753
5754
            $param['name'] = strtolower($param['name']);
5755
5756 View Code Duplication
            if (isset($this->_lstField[$param['name']])) {
5757
                $this->_lstField[$param['name']]++;
5758
            } else {
5759
                $this->_lstField[$param['name']] = 1;
5760
            }
5761
5762
            $this->parsingCss->save();
5763
            $this->parsingCss->analyse('select', $param);
5764
            $this->parsingCss->setPosition();
5765
            $this->parsingCss->fontSet();
5766
5767
            $this->_lstSelect = array();
5768
            $this->_lstSelect['name']    = $param['name'];
5769
            $this->_lstSelect['multi'] = isset($param['multiple']) ? true : false;
5770
            $this->_lstSelect['size']    = isset($param['size']) ? $param['size'] : 1;
5771
            $this->_lstSelect['options'] = array();
5772
5773
            if ($this->_lstSelect['multi'] && $this->_lstSelect['size'] < 3) $this->_lstSelect['size'] = 3;
5774
5775
            return true;
5776
        }
5777
5778
        /**
5779
         * tag : OPTION
5780
         * mode : OPEN
5781
         *
5782
         * @param    array $param
5783
         * @return boolean
5784
         */
5785
        protected function _tag_open_OPTION($param)
5786
        {
5787
            // get the content of the option : it is the text of the option
5788
            $level = $this->parsingHtml->getLevel($this->_parsePos);
5789
            $this->_parsePos += count($level);
5790
            $value = isset($param['value']) ? $param['value'] : 'aut_tag_open_opt_'.(count($this->_lstSelect) + 1);
5791
5792
            $this->_lstSelect['options'][$value] = isset($level[0]['param']['txt']) ? $level[0]['param']['txt'] : '';
5793
5794
            return true;
5795
        }
5796
5797
        /**
5798
         * tag : OPTION
5799
         * mode : CLOSE
5800
         *
5801
         * @param    array $param
5802
         * @return boolean
5803
         */
5804
        protected function _tag_close_OPTION($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
5805
        {
5806
            // nothing to do here
5807
5808
            return true;
5809
        }
5810
5811
        /**
5812
         * tag : SELECT
5813
         * mode : CLOSE
5814
         *
5815
         * @return boolean
5816
         */
5817
        protected function _tag_close_SELECT()
5818
        {
5819
            // position of the select
5820
            $x = $this->pdf->getX();
5821
            $y = $this->pdf->getY();
5822
            $f = 1.08 * $this->parsingCss->value['font-size'];
5823
5824
            // width
5825
            $w = $this->parsingCss->value['width']; if ( ! $w) $w = 50;
5826
5827
            // height (automatic)
5828
            $h = ($f * 1.07 * $this->_lstSelect['size'] + 1);
5829
5830
            $prop = $this->parsingCss->getFormStyle();
5831
5832
            // multy select
5833
            if ($this->_lstSelect['multi']) {
5834
                $prop['multipleSelection'] = 'true';
5835
            }
5836
5837
5838
            // single or multi select
5839
            if ($this->_lstSelect['size'] > 1) {
5840
                $this->pdf->ListBox($this->_lstSelect['name'], $w, $h, $this->_lstSelect['options'], $prop);
5841
            } else {
5842
                $this->pdf->ComboBox($this->_lstSelect['name'], $w, $h, $this->_lstSelect['options'], $prop);
5843
            }
5844
5845
            $this->_maxX = max($this->_maxX, $x + $w);
5846
            $this->_maxY = max($this->_maxY, $y + $h);
0 ignored issues
show
Documentation Bug introduced by
It seems like max($this->_maxY, $y + $h) can also be of type double. However, the property $_maxY is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
5847
            $this->_maxH = max($this->_maxH, $h);
0 ignored issues
show
Documentation Bug introduced by
It seems like max($this->_maxH, $h) can also be of type double. However, the property $_maxH is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
5848
            $this->_maxE++;
5849
            $this->pdf->setX($x + $w);
5850
5851
            $this->parsingCss->load();
5852
            $this->parsingCss->fontSet();
5853
5854
            $this->_lstSelect = array();
5855
5856
            return true;
5857
        }
5858
5859
        /**
5860
         * tag : TEXTAREA
5861
         * mode : OPEN
5862
         *
5863
         * @param    array $param
5864
         * @return boolean
5865
         */
5866
        protected function _tag_open_TEXTAREA($param)
5867
        {
5868 View Code Duplication
            if ( ! isset($param['name'])) {
5869
                $param['name'] = 'champs_pdf_'.(count($this->_lstField) + 1);
5870
            }
5871
5872
            $param['name'] = strtolower($param['name']);
5873
5874 View Code Duplication
            if (isset($this->_lstField[$param['name']])) {
5875
                $this->_lstField[$param['name']]++;
5876
            } else {
5877
                $this->_lstField[$param['name']] = 1;
5878
            }
5879
5880
            $this->parsingCss->save();
5881
            $this->parsingCss->analyse('textarea', $param);
5882
            $this->parsingCss->setPosition();
5883
            $this->parsingCss->fontSet();
5884
5885
            $x = $this->pdf->getX();
5886
            $y = $this->pdf->getY();
5887
            $fx = 0.65 * $this->parsingCss->value['font-size'];
5888
            $fy = 1.08 * $this->parsingCss->value['font-size'];
5889
5890
            // extract the content the textarea : value
5891
            $level = $this->parsingHtml->getLevel($this->_parsePos);
5892
            $this->_parsePos += count($level);
5893
5894
            // automatic size, from cols and rows properties
5895
            $w = $fx * (isset($param['cols']) ? $param['cols'] : 22) + 1;
5896
            $h = $fy * 1.07 * (isset($param['rows']) ? $param['rows'] : 3) + 3;
5897
5898
            $prop = $this->parsingCss->getFormStyle();
5899
5900
            $prop['multiline'] = true;
5901
            $prop['value'] = isset($level[0]['param']['txt']) ? $level[0]['param']['txt'] : '';
5902
5903
            $this->pdf->TextField($param['name'], $w, $h, $prop, array(), $x, $y);
5904
5905
            $this->_maxX = max($this->_maxX, $x + $w);
0 ignored issues
show
Documentation Bug introduced by
It seems like max($this->_maxX, $x + $w) can also be of type double. However, the property $_maxX is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
5906
            $this->_maxY = max($this->_maxY, $y + $h);
0 ignored issues
show
Documentation Bug introduced by
It seems like max($this->_maxY, $y + $h) can also be of type double. However, the property $_maxY is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
5907
            $this->_maxH = max($this->_maxH, $h);
0 ignored issues
show
Documentation Bug introduced by
It seems like max($this->_maxH, $h) can also be of type double. However, the property $_maxH is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
5908
            $this->_maxE++;
5909
            $this->pdf->setX($x + $w);
5910
5911
            return true;
5912
        }
5913
5914
        /**
5915
         * tag : TEXTAREA
5916
         * mode : CLOSE
5917
         *
5918
         * @return boolean
5919
         */
5920
        protected function _tag_close_TEXTAREA()
5921
        {
5922
            $this->parsingCss->load();
5923
            $this->parsingCss->fontSet();
5924
5925
            return true;
5926
        }
5927
5928
        /**
5929
         * tag : INPUT
5930
         * mode : OPEN
5931
         *
5932
         * @param  array $param
5933
         * @return boolean
5934
         */
5935
        protected function _tag_open_INPUT($param)
5936
        {
5937 View Code Duplication
            if ( ! isset($param['name']))  $param['name']  = 'champs_pdf_'.(count($this->_lstField) + 1);
5938
            if ( ! isset($param['value'])) $param['value'] = '';
5939
            if ( ! isset($param['type']))  $param['type']  = 'text';
5940
5941
            $param['name'] = strtolower($param['name']);
5942
            $param['type'] = strtolower($param['type']);
5943
5944
            // the type must be valid
5945
            if ( ! in_array($param['type'], array('text', 'checkbox', 'radio', 'hidden', 'submit', 'reset', 'button'))) {
5946
                $param['type'] = 'text';
5947
            }
5948
5949 View Code Duplication
            if (isset($this->_lstField[$param['name']])) {
5950
                $this->_lstField[$param['name']]++;
5951
            } else {
5952
                $this->_lstField[$param['name']] = 1;
5953
            }
5954
5955
            $this->parsingCss->save();
5956
            $this->parsingCss->analyse('input', $param);
5957
            $this->parsingCss->setPosition();
5958
            $this->parsingCss->fontSet();
5959
5960
            $name = $param['name'];
5961
5962
            $x = $this->pdf->getX();
5963
            $y = $this->pdf->getY();
5964
            $f = 1.08 * $this->parsingCss->value['font-size'];
5965
5966
            $prop = $this->parsingCss->getFormStyle();
5967
5968
            switch ($param['type'])
5969
            {
5970
                case 'checkbox':
5971
                    $w = 3;
5972
                    $h = $w;
5973
                    if ($h < $f) $y += ($f - $h) * 0.5;
5974
                    $checked = (isset($param['checked']) && $param['checked'] == 'checked');
5975
                    $this->pdf->CheckBox($name, $w, $checked, $prop, array(), ($param['value'] ? $param['value'] : 'Yes'), $x, $y);
5976
                    break;
5977
5978
                case 'radio':
5979
                    $w = 3;
5980
                    $h = $w;
5981
                    if ($h < $f) $y += ($f - $h) * 0.5;
5982
                    $checked = (isset($param['checked']) && $param['checked'] == 'checked');
5983
                    $this->pdf->RadioButton($name, $w, $prop, array(), ($param['value'] ? $param['value'] : 'On'), $checked, $x, $y);
5984
                    break;
5985
5986
                case 'hidden':
5987
                    $w = 0;
5988
                    $h = 0;
5989
                    $prop['value'] = $param['value'];
5990
                    $this->pdf->TextField($name, $w, $h, $prop, array(), $x, $y);
5991
                    break;
5992
5993
                case 'text':
5994
                    $w = $this->parsingCss->value['width']; if ( ! $w) $w = 40;
5995
                    $h = $f * 1.3;
5996
                    $prop['value'] = $param['value'];
5997
                    $this->pdf->TextField($name, $w, $h, $prop, array(), $x, $y);
5998
                    break;
5999
6000
                case 'submit':
6001
                    $w = $this->parsingCss->value['width']; if ( ! $w) $w = 40;
6002
                    $h = $this->parsingCss->value['height']; if ( ! $h) $h = $f * 1.3;
6003
                    $action = array('S'=>'SubmitForm', 'F'=>$this->_isInForm, 'Flags'=>array('ExportFormat'));
6004
                    $this->pdf->Button($name, $w, $h, $param['value'], $action, $prop, array(), $x, $y);
6005
                    break;
6006
6007
                case 'reset':
6008
                    $w = $this->parsingCss->value['width']; if ( ! $w) $w = 40;
6009
                    $h = $this->parsingCss->value['height']; if ( ! $h) $h = $f * 1.3;
6010
                    $action = array('S'=>'ResetForm');
6011
                    $this->pdf->Button($name, $w, $h, $param['value'], $action, $prop, array(), $x, $y);
6012
                    break;
6013
6014
                case 'button':
6015
                    $w = $this->parsingCss->value['width']; if ( ! $w) $w = 40;
6016
                    $h = $this->parsingCss->value['height']; if ( ! $h) $h = $f * 1.3;
6017
                    $action = isset($param['onclick']) ? $param['onclick'] : '';
6018
                    $this->pdf->Button($name, $w, $h, $param['value'], $action, $prop, array(), $x, $y);
6019
                    break;
6020
6021
                default:
6022
                    $w = 0;
6023
                    $h = 0;
6024
                    break;
6025
            }
6026
6027
            $this->_maxX = max($this->_maxX, $x + $w);
6028
            $this->_maxY = max($this->_maxY, $y + $h);
6029
            $this->_maxH = max($this->_maxH, $h);
6030
            $this->_maxE++;
6031
            $this->pdf->setX($x + $w);
6032
6033
            $this->parsingCss->load();
6034
            $this->parsingCss->fontSet();
6035
6036
            return true;
6037
        }
6038
6039
        /**
6040
         * tag : DRAW
6041
         * mode : OPEN
6042
         *
6043
         * @param  array $param
6044
         * @return boolean
6045
         */
6046
        protected function _tag_open_DRAW($param)
6047
        {
6048
            if ($this->_isForOneLine) {
6049
            	return false;
6050
            }
6051
            if ($this->_debugActif) {
6052
            	$this->_DEBUG_add('DRAW', true);
6053
            }
6054
6055
            $this->parsingCss->save();
6056
            $this->parsingCss->analyse('draw', $param);
6057
            $this->parsingCss->fontSet();
6058
6059
            $alignObject = null;
6060
            if ($this->parsingCss->value['margin-auto']) {
6061
            	$alignObject = 'center';
6062
            }
6063
6064
            $overW = $this->parsingCss->value['width'];
6065
            $overH = $this->parsingCss->value['height'];
6066
            $this->parsingCss->value['old_maxX'] = $this->_maxX;
6067
            $this->parsingCss->value['old_maxY'] = $this->_maxY;
6068
            $this->parsingCss->value['old_maxH'] = $this->_maxH;
6069
6070
            $w = $this->parsingCss->value['width'];
6071
            $h = $this->parsingCss->value['height'];
6072
6073 View Code Duplication
            if ( ! $this->parsingCss->value['position']) {
6074
                if (
6075
                    $w < ($this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin()) &&
6076
                    $this->pdf->getX() + $w >= ($this->pdf->getW() - $this->pdf->getrMargin())
6077
                    )
6078
                    $this->_tag_open_BR(array());
6079
6080
                if (
6081
                        ($h < ($this->pdf->getH() - $this->pdf->gettMargin() - $this->pdf->getbMargin())) &&
6082
                        ($this->pdf->getY() + $h >= ($this->pdf->getH() - $this->pdf->getbMargin())) &&
6083
                        ! $this->_isInOverflow
6084
                    )
6085
                    $this->_setNewPage();
6086
6087
                $old = $this->parsingCss->getOldValues();
6088
                $parentWidth = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin();
6089
6090
                if ($parentWidth > $w) {
6091
                    if ($alignObject == 'center')        $this->pdf->setX($this->pdf->getX() + ($parentWidth - $w) * 0.5);
6092
                    else if ($alignObject == 'right')    $this->pdf->setX($this->pdf->getX() + $parentWidth - $w);
6093
                }
6094
6095
                $this->parsingCss->setPosition();
6096
            } else {
6097
                $old = $this->parsingCss->getOldValues();
6098
                $parentWidth = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin();
6099
6100
                if ($parentWidth > $w) {
6101
                    if ($alignObject == 'center')        $this->pdf->setX($this->pdf->getX() + ($parentWidth - $w) * 0.5);
6102
                    else if ($alignObject == 'right')    $this->pdf->setX($this->pdf->getX() + $parentWidth - $w);
6103
                }
6104
6105
                $this->parsingCss->setPosition();
6106
                $this->_saveMax();
6107
                $this->_maxX = 0;
6108
                $this->_maxY = 0;
6109
                $this->_maxH = 0;
6110
                $this->_maxE = 0;
6111
            }
6112
6113
            $this->_drawRectangle(
6114
                $this->parsingCss->value['x'],
6115
                $this->parsingCss->value['y'],
6116
                $this->parsingCss->value['width'],
6117
                $this->parsingCss->value['height'],
6118
                $this->parsingCss->value['border'],
6119
                $this->parsingCss->value['padding'],
6120
                0,
6121
                $this->parsingCss->value['background']
6122
            );
6123
6124
            $marge = array();
6125
            $marge['l'] = $this->parsingCss->value['border']['l']['width'];
6126
            $marge['r'] = $this->parsingCss->value['border']['r']['width'];
6127
            $marge['t'] = $this->parsingCss->value['border']['t']['width'];
6128
            $marge['b'] = $this->parsingCss->value['border']['b']['width'];
6129
6130
            $this->parsingCss->value['width'] -= $marge['l'] + $marge['r'];
6131
            $this->parsingCss->value['height'] -= $marge['t'] + $marge['b'];
6132
6133
            $overW -= $marge['l'] + $marge['r'];
6134
            $overH -= $marge['t'] + $marge['b'];
6135
6136
            // clipping to draw only in the size opf the DRAW tag
6137
            $this->pdf->clippingPathStart(
6138
                $this->parsingCss->value['x'] + $marge['l'],
6139
                $this->parsingCss->value['y'] + $marge['t'],
6140
                $this->parsingCss->value['width'],
6141
                $this->parsingCss->value['height']
6142
            );
6143
6144
            // left and right of the DRAW tag
6145
            $mL = $this->parsingCss->value['x'] + $marge['l'];
6146
            $mR = $this->pdf->getW() - $mL - $overW;
6147
6148
            // position of the DRAW tag
6149
            $x = $this->parsingCss->value['x'] + $marge['l'];
6150
            $y = $this->parsingCss->value['y'] + $marge['t'];
6151
6152
            // prepare the drawing area
6153
            $this->_saveMargin($mL, 0, $mR);
6154
            $this->pdf->setXY($x, $y);
6155
6156
            // we are in a draw tag
6157
            $this->_isInDraw = array(
6158
                'x' => $x,
6159
                'y' => $y,
6160
                'w' => $overW,
6161
                'h' => $overH,
6162
            );
6163
6164
            // init the translate matrix : (0,0) => ($x, $y)
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
6165
            $this->pdf->doTransform(array(1, 0, 0, 1, $x, $y));
6166
            $this->pdf->SetAlpha(1.);
6167
            return true;
6168
        }
6169
6170
        /**
6171
         * tag : DRAW
6172
         * mode : CLOSE
6173
         *
6174
         * @param  array $param
6175
         * @return boolean
6176
         */
6177
        protected function _tag_close_DRAW($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
6178
        {
6179
            if ($this->_isForOneLine) {
6180
            	return false;
6181
            }
6182
6183
            $this->pdf->SetAlpha(1.);
6184
            $this->pdf->undoTransform();
6185
            $this->pdf->clippingPathStop();
6186
6187
            $this->_maxX = $this->parsingCss->value['old_maxX'];
6188
            $this->_maxY = $this->parsingCss->value['old_maxY'];
6189
            $this->_maxH = $this->parsingCss->value['old_maxH'];
6190
6191
            $marge = array();
6192
            $marge['l'] = $this->parsingCss->value['border']['l']['width'];
6193
            $marge['r'] = $this->parsingCss->value['border']['r']['width'];
6194
            $marge['t'] = $this->parsingCss->value['border']['t']['width'];
6195
            $marge['b'] = $this->parsingCss->value['border']['b']['width'];
6196
6197
            $x = $this->parsingCss->value['x'];
6198
            $y = $this->parsingCss->value['y'];
6199
            $w = $this->parsingCss->value['width'] + $marge['l'] + $marge['r'];
6200
            $h = $this->parsingCss->value['height'] + $marge['t'] + $marge['b'];
6201
6202 View Code Duplication
            if ($this->parsingCss->value['position'] != 'absolute') {
6203
                $this->pdf->setXY($x + $w, $y);
6204
6205
                $this->_maxX = max($this->_maxX, $x + $w);
6206
                $this->_maxY = max($this->_maxY, $y + $h);
6207
                $this->_maxH = max($this->_maxH, $h);
6208
                $this->_maxE++;
6209
            } else {
6210
                // position
6211
                $this->pdf->setXY($this->parsingCss->value['xc'], $this->parsingCss->value['yc']);
6212
6213
                $this->_loadMax();
6214
            }
6215
6216
            $block = ($this->parsingCss->value['display'] != 'inline' && $this->parsingCss->value['position'] != 'absolute');
6217
6218
            $this->parsingCss->load();
6219
            $this->parsingCss->fontSet();
6220
            $this->_loadMargin();
6221
6222
            if ($block) {
6223
            	$this->_tag_open_BR(array());
6224
            }
6225
            if ($this->_debugActif) {
6226
            	$this->_DEBUG_add('DRAW', false);
6227
            }
6228
6229
            $this->_isInDraw = null;
6230
6231
            return true;
6232
        }
6233
6234
        /**
6235
         * tag : LINE
6236
         * mode : OPEN
6237
         *
6238
         * @param  array $param
6239
         * @return boolean|null
6240
         */
6241 View Code Duplication
        protected function _tag_open_LINE($param)
6242
        {
6243
            if ( ! $this->_isInDraw) throw new HTML2PDF_exception(8, 'LINE');
6244
6245
            $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null);
6246
            $this->parsingCss->save();
6247
            $styles = $this->parsingCss->getSvgStyle('path', $param);
6248
            $styles['fill'] = null;
6249
            $style = $this->pdf->svgSetStyle($styles);
6250
6251
            $x1 = isset($param['x1']) ? $this->parsingCss->ConvertToMM($param['x1'], $this->_isInDraw['w']) : 0.;
6252
            $y1 = isset($param['y1']) ? $this->parsingCss->ConvertToMM($param['y1'], $this->_isInDraw['h']) : 0.;
6253
            $x2 = isset($param['x2']) ? $this->parsingCss->ConvertToMM($param['x2'], $this->_isInDraw['w']) : 0.;
6254
            $y2 = isset($param['y2']) ? $this->parsingCss->ConvertToMM($param['y2'], $this->_isInDraw['h']) : 0.;
6255
            $this->pdf->svgLine($x1, $y1, $x2, $y2);
6256
6257
            $this->pdf->undoTransform();
6258
            $this->parsingCss->load();
6259
        }
6260
6261
        /**
6262
         * tag : RECT
6263
         * mode : OPEN
6264
         *
6265
         * @param  array $param
6266
         * @return boolean|null
6267
         */
6268 View Code Duplication
        protected function _tag_open_RECT($param)
6269
        {
6270
            if ( ! $this->_isInDraw) throw new HTML2PDF_exception(8, 'RECT');
6271
6272
            $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null);
6273
            $this->parsingCss->save();
6274
            $styles = $this->parsingCss->getSvgStyle('path', $param);
6275
            $style = $this->pdf->svgSetStyle($styles);
6276
6277
            $x = isset($param['x']) ? $this->parsingCss->ConvertToMM($param['x'], $this->_isInDraw['w']) : 0.;
6278
            $y = isset($param['y']) ? $this->parsingCss->ConvertToMM($param['y'], $this->_isInDraw['h']) : 0.;
6279
            $w = isset($param['w']) ? $this->parsingCss->ConvertToMM($param['w'], $this->_isInDraw['w']) : 0.;
6280
            $h = isset($param['h']) ? $this->parsingCss->ConvertToMM($param['h'], $this->_isInDraw['h']) : 0.;
6281
6282
            $this->pdf->svgRect($x, $y, $w, $h, $style);
6283
6284
            $this->pdf->undoTransform();
6285
            $this->parsingCss->load();
6286
        }
6287
6288
        /**
6289
         * tag : CIRCLE
6290
         * mode : OPEN
6291
         *
6292
         * @param  array $param
6293
         * @return boolean|null
6294
         */
6295
        protected function _tag_open_CIRCLE($param)
6296
        {
6297
            if ( ! $this->_isInDraw) throw new HTML2PDF_exception(8, 'CIRCLE');
6298
6299
            $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null);
6300
            $this->parsingCss->save();
6301
            $styles = $this->parsingCss->getSvgStyle('path', $param);
6302
            $style = $this->pdf->svgSetStyle($styles);
6303
6304
            $cx = isset($param['cx']) ? $this->parsingCss->ConvertToMM($param['cx'], $this->_isInDraw['w']) : 0.;
6305
            $cy = isset($param['cy']) ? $this->parsingCss->ConvertToMM($param['cy'], $this->_isInDraw['h']) : 0.;
6306
            $r = isset($param['r']) ? $this->parsingCss->ConvertToMM($param['r'], $this->_isInDraw['w']) : 0.;
6307
            $this->pdf->svgEllipse($cx, $cy, $r, $r, $style);
6308
6309
            $this->pdf->undoTransform();
6310
            $this->parsingCss->load();
6311
        }
6312
6313
        /**
6314
         * tag : ELLIPSE
6315
         * mode : OPEN
6316
         *
6317
         * @param  array $param
6318
         * @return boolean|null
6319
         */
6320 View Code Duplication
        protected function _tag_open_ELLIPSE($param)
6321
        {
6322
            if ( ! $this->_isInDraw) throw new HTML2PDF_exception(8, 'ELLIPSE');
6323
6324
            $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null);
6325
            $this->parsingCss->save();
6326
            $styles = $this->parsingCss->getSvgStyle('path', $param);
6327
            $style = $this->pdf->svgSetStyle($styles);
6328
6329
            $cx = isset($param['cx']) ? $this->parsingCss->ConvertToMM($param['cx'], $this->_isInDraw['w']) : 0.;
6330
            $cy = isset($param['cy']) ? $this->parsingCss->ConvertToMM($param['cy'], $this->_isInDraw['h']) : 0.;
6331
            $rx = isset($param['ry']) ? $this->parsingCss->ConvertToMM($param['rx'], $this->_isInDraw['w']) : 0.;
6332
            $ry = isset($param['rx']) ? $this->parsingCss->ConvertToMM($param['ry'], $this->_isInDraw['h']) : 0.;
6333
            $this->pdf->svgEllipse($cx, $cy, $rx, $ry, $style);
6334
6335
            $this->pdf->undoTransform();
6336
            $this->parsingCss->load();
6337
        }
6338
6339
6340
        /**
6341
         * tag : POLYLINE
6342
         * mode : OPEN
6343
         *
6344
         * @param  array $param
6345
         * @return boolean|null
6346
         */
6347 View Code Duplication
        protected function _tag_open_POLYLINE($param)
6348
        {
6349
            if ( ! $this->_isInDraw) throw new HTML2PDF_exception(8, 'POLYGON');
6350
6351
            $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null);
6352
            $this->parsingCss->save();
6353
            $styles = $this->parsingCss->getSvgStyle('path', $param);
6354
            $style = $this->pdf->svgSetStyle($styles);
6355
6356
            $path = isset($param['points']) ? $param['points'] : null;
6357
            if ($path) {
6358
                $path = str_replace(',', ' ', $path);
6359
                $path = preg_replace('/[\s]+/', ' ', trim($path));
6360
6361
                // prepare the path
6362
                $path = explode(' ', $path);
6363
                foreach ($path as $k => $v) {
6364
                    $path[$k] = trim($v);
6365
                    if ($path[$k] === '') unset($path[$k]);
6366
                }
6367
                $path = array_values($path);
6368
6369
                $actions = array();
6370
                for ($k = 0; $k < count($path); $k += 2) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
6371
                    $actions[] = array(
6372
                        ($k ? 'L' : 'M'),
6373
                        $this->parsingCss->ConvertToMM($path[$k + 0], $this->_isInDraw['w']),
6374
                        $this->parsingCss->ConvertToMM($path[$k + 1], $this->_isInDraw['h'])
6375
                    );
6376
                }
6377
6378
                // drawing
6379
                $this->pdf->svgPolygone($actions, $style);
6380
            }
6381
6382
            $this->pdf->undoTransform();
6383
            $this->parsingCss->load();
6384
        }
6385
6386
        /**
6387
         * tag : POLYGON
6388
         * mode : OPEN
6389
         *
6390
         * @param  array $param
6391
         * @return boolean|null
6392
         */
6393 View Code Duplication
        protected function _tag_open_POLYGON($param)
6394
        {
6395
            if ( ! $this->_isInDraw) throw new HTML2PDF_exception(8, 'POLYGON');
6396
6397
            $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null);
6398
            $this->parsingCss->save();
6399
            $styles = $this->parsingCss->getSvgStyle('path', $param);
6400
            $style = $this->pdf->svgSetStyle($styles);
6401
6402
            $path = (isset($param['points']) ? $param['points'] : null);
6403
            if ($path) {
6404
                $path = str_replace(',', ' ', $path);
6405
                $path = preg_replace('/[\s]+/', ' ', trim($path));
6406
6407
                // prepare the path
6408
                $path = explode(' ', $path);
6409
                foreach ($path as $k => $v) {
6410
                    $path[$k] = trim($v);
6411
                    if ($path[$k] === '') unset($path[$k]);
6412
                }
6413
                $path = array_values($path);
6414
6415
                $actions = array();
6416
                for ($k = 0; $k < count($path); $k += 2) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
6417
                    $actions[] = array(
6418
                        ($k ? 'L' : 'M'),
6419
                        $this->parsingCss->ConvertToMM($path[$k + 0], $this->_isInDraw['w']),
6420
                        $this->parsingCss->ConvertToMM($path[$k + 1], $this->_isInDraw['h'])
6421
                    );
6422
                }
6423
                $actions[] = array('z');
6424
6425
                // drawing
6426
                $this->pdf->svgPolygone($actions, $style);
6427
            }
6428
6429
            $this->pdf->undoTransform();
6430
            $this->parsingCss->load();
6431
        }
6432
6433
        /**
6434
         * tag : PATH
6435
         * mode : OPEN
6436
         *
6437
         * @param  array $param
6438
         * @return boolean|null
6439
         */
6440
        protected function _tag_open_PATH($param)
6441
        {
6442
            if ( ! $this->_isInDraw) throw new HTML2PDF_exception(8, 'PATH');
6443
6444
            $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null);
6445
            $this->parsingCss->save();
6446
            $styles = $this->parsingCss->getSvgStyle('path', $param);
6447
            $style = $this->pdf->svgSetStyle($styles);
6448
6449
            $path = isset($param['d']) ? $param['d'] : null;
6450
6451
            if ($path) {
6452
                // prepare the path
6453
                $path = str_replace(',', ' ', $path);
6454
                $path = preg_replace('/([a-zA-Z])([0-9\.\-])/', '$1 $2', $path);
6455
                $path = preg_replace('/([0-9\.])([a-zA-Z])/', '$1 $2', $path);
6456
                $path = preg_replace('/[\s]+/', ' ', trim($path));
6457
                $path = preg_replace('/ ([a-z]{2})/', '$1', $path);
6458
6459
                $path = explode(' ', $path);
6460
                foreach ($path as $k => $v) {
6461
                    $path[$k] = trim($v);
6462
                    if ($path[$k] === '') unset($path[$k]);
6463
                }
6464
                $path = array_values($path);
6465
6466
                // read each actions in the path
6467
                $actions = array();
6468
                $action = array();
6469
                $lastAction = null; // last action found
6470
                for ($k = 0; $k < count($path); true) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
6471
6472
                    // for this actions, we can not have multi coordonate
6473
                    if (in_array($lastAction, array('z', 'Z'))) {
6474
                        $lastAction = null;
6475
                    }
6476
6477
                    // read the new action (forcing if no action before)
6478
                    if (preg_match('/^[a-z]+$/i', $path[$k]) || $lastAction === null) {
6479
                        $lastAction = $path[$k];
6480
                        $k++;
6481
                    }
6482
6483
                    // current action
6484
                    $action = array();
6485
                    $action[] = $lastAction;
6486
                    switch ($lastAction)
6487
                    {
6488
                        case 'C':
6489
                        case 'c':
6490
                            $action[] = $this->parsingCss->ConvertToMM($path[$k + 0], $this->_isInDraw['w']); // x1
6491
                            $action[] = $this->parsingCss->ConvertToMM($path[$k + 1], $this->_isInDraw['h']); // y1
6492
                            $action[] = $this->parsingCss->ConvertToMM($path[$k + 2], $this->_isInDraw['w']); // x2
6493
                            $action[] = $this->parsingCss->ConvertToMM($path[$k + 3], $this->_isInDraw['h']); // y2
6494
                            $action[] = $this->parsingCss->ConvertToMM($path[$k + 4], $this->_isInDraw['w']); // x
6495
                            $action[] = $this->parsingCss->ConvertToMM($path[$k + 5], $this->_isInDraw['h']); // y
6496
                            $k += 6;
6497
                            break;
6498
6499
                        case 'Q':
6500
                        case 'S':
6501
                        case 'q':
6502
                        case 's':
6503
                            $action[] = $this->parsingCss->ConvertToMM($path[$k + 0], $this->_isInDraw['w']); // x2
6504
                            $action[] = $this->parsingCss->ConvertToMM($path[$k + 1], $this->_isInDraw['h']); // y2
6505
                            $action[] = $this->parsingCss->ConvertToMM($path[$k + 2], $this->_isInDraw['w']); // x
6506
                            $action[] = $this->parsingCss->ConvertToMM($path[$k + 3], $this->_isInDraw['h']); // y
6507
                            $k += 4;
6508
                            break;
6509
6510
                        case 'A':
6511
                        case 'a':
6512
                            $action[] = $this->parsingCss->ConvertToMM($path[$k + 0], $this->_isInDraw['w']); // rx
6513
                            $action[] = $this->parsingCss->ConvertToMM($path[$k + 1], $this->_isInDraw['h']); // ry
6514
                            $action[] = 1. * $path[$k + 2]; // angle de deviation de l'axe X
6515
                            $action[] = ($path[$k + 3] == '1') ? 1 : 0; // large-arc-flag
6516
                            $action[] = ($path[$k + 4] == '1') ? 1 : 0; // sweep-flag
6517
                            $action[] = $this->parsingCss->ConvertToMM($path[$k + 5], $this->_isInDraw['w']); // x
6518
                            $action[] = $this->parsingCss->ConvertToMM($path[$k + 6], $this->_isInDraw['h']); // y
6519
                            $k += 7;
6520
                            break;
6521
6522
                        case 'M':
6523
                        case 'L':
6524
                        case 'T':
6525
                        case 'm':
6526
                        case 'l':
6527
                        case 't':
6528
                            $action[] = $this->parsingCss->ConvertToMM($path[$k + 0], $this->_isInDraw['w']); // x
6529
                            $action[] = $this->parsingCss->ConvertToMM($path[$k + 1], $this->_isInDraw['h']); // y
6530
                            $k += 2;
6531
                            break;
6532
6533
                        case 'H':
6534 View Code Duplication
                        case 'h':
6535
                            $action[] = $this->parsingCss->ConvertToMM($path[$k + 0], $this->_isInDraw['w']); // x
6536
                            $k += 1;
6537
                            break;
6538
6539
                        case 'V':
6540 View Code Duplication
                        case 'v':
6541
                            $action[] = $this->parsingCss->ConvertToMM($path[$k + 0], $this->_isInDraw['h']); // y
6542
                            $k += 1;
6543
                            break;
6544
6545
                        case 'z':
6546
                        case 'Z':
6547
                        default:
6548
                            break;
6549
                    }
6550
                    // add the action
6551
                    $actions[] = $action;
6552
                }
6553
6554
                // drawing
6555
                $this->pdf->svgPolygone($actions, $style);
6556
            }
6557
6558
            $this->pdf->undoTransform();
6559
            $this->parsingCss->load();
6560
        }
6561
6562
        /**
6563
         * tag : G
6564
         * mode : OPEN
6565
         *
6566
         * @param  array $param
6567
         * @return boolean|null
6568
         */
6569
        protected function _tag_open_G($param)
6570
        {
6571
            if ( ! $this->_isInDraw) throw new HTML2PDF_exception(8, 'G');
6572
6573
            $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null);
6574
            $this->parsingCss->save();
6575
            $styles = $this->parsingCss->getSvgStyle('path', $param);
6576
            $style = $this->pdf->svgSetStyle($styles);
6577
        }
6578
6579
        /**
6580
         * tag : G
6581
         * mode : CLOSE
6582
         *
6583
         * @param  array $param
6584
         * @return boolean|null
6585
         */
6586
        protected function _tag_close_G($param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
6587
        {
6588
            $this->pdf->undoTransform();
6589
            $this->parsingCss->load();
6590
        }
6591
6592
        /**
6593
         * new page for the automatic Index, does not use thie method. Only HTML2PDF_myPdf could use it !!!!
6594
         *
6595
         * @param  &int $page
0 ignored issues
show
Documentation introduced by
The doc-type &int could not be parsed: Unknown type name "&int" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
6596
         * @return integer $oldPage
6597
         */
6598
        public function _INDEX_NewPage(&$page)
6599
        {
6600
            if ($page) {
6601
                $oldPage = $this->pdf->getPage();
6602
                $this->pdf->setPage($page);
6603
                $this->pdf->setXY($this->_margeLeft, $this->_margeTop);
6604
                $this->_maxH = 0;
6605
                $page++;
6606
                return $oldPage;
6607
            } else {
6608
                $this->_setNewPage();
6609
                return null;
6610
            }
6611
        }
6612
6613
    }
6614
}
6615