@@ -2,37 +2,37 @@ |
||
2 | 2 | |
3 | 3 | class Reports |
4 | 4 | { |
5 | - private $db; |
|
6 | - |
|
7 | - public function __construct($database) |
|
8 | - { |
|
9 | - $this->db = $database; |
|
10 | - } |
|
11 | - |
|
12 | - public function data_report($idreport) |
|
13 | - { |
|
14 | - $query = $this->db->prepare('SELECT * FROM `tickets` WHERE `slaid`= ?'); |
|
15 | - $query->bindValue(1, $slaid); |
|
16 | - |
|
17 | - try { |
|
18 | - $query->execute(); |
|
19 | - |
|
20 | - return $query->fetch(); |
|
21 | - } catch (PDOException $e) { |
|
22 | - die($e->getMessage()); |
|
23 | - } |
|
24 | - } |
|
25 | - |
|
26 | - public function data_report_002() |
|
27 | - { |
|
28 | - $query = $this->db->prepare('SELECT * FROM `sla` ORDER BY `slaid` ASC'); |
|
29 | - |
|
30 | - try { |
|
31 | - $query->execute(); |
|
32 | - } catch (PDOException $e) { |
|
33 | - die($e->getMessage()); |
|
34 | - } |
|
35 | - |
|
36 | - return $query->fetchAll(); |
|
37 | - } |
|
5 | + private $db; |
|
6 | + |
|
7 | + public function __construct($database) |
|
8 | + { |
|
9 | + $this->db = $database; |
|
10 | + } |
|
11 | + |
|
12 | + public function data_report($idreport) |
|
13 | + { |
|
14 | + $query = $this->db->prepare('SELECT * FROM `tickets` WHERE `slaid`= ?'); |
|
15 | + $query->bindValue(1, $slaid); |
|
16 | + |
|
17 | + try { |
|
18 | + $query->execute(); |
|
19 | + |
|
20 | + return $query->fetch(); |
|
21 | + } catch (PDOException $e) { |
|
22 | + die($e->getMessage()); |
|
23 | + } |
|
24 | + } |
|
25 | + |
|
26 | + public function data_report_002() |
|
27 | + { |
|
28 | + $query = $this->db->prepare('SELECT * FROM `sla` ORDER BY `slaid` ASC'); |
|
29 | + |
|
30 | + try { |
|
31 | + $query->execute(); |
|
32 | + } catch (PDOException $e) { |
|
33 | + die($e->getMessage()); |
|
34 | + } |
|
35 | + |
|
36 | + return $query->fetchAll(); |
|
37 | + } |
|
38 | 38 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | $query->execute(); |
19 | 19 | |
20 | 20 | return $query->fetch(); |
21 | - } catch (PDOException $e) { |
|
21 | + }catch (PDOException $e) { |
|
22 | 22 | die($e->getMessage()); |
23 | 23 | } |
24 | 24 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | |
30 | 30 | try { |
31 | 31 | $query->execute(); |
32 | - } catch (PDOException $e) { |
|
32 | + }catch (PDOException $e) { |
|
33 | 33 | die($e->getMessage()); |
34 | 34 | } |
35 | 35 |
@@ -2,24 +2,24 @@ |
||
2 | 2 | |
3 | 3 | class General |
4 | 4 | { |
5 | - public function logged_in() |
|
6 | - { |
|
7 | - return(isset($_SESSION['loginid'])) ? true : false; |
|
8 | - } |
|
5 | + public function logged_in() |
|
6 | + { |
|
7 | + return(isset($_SESSION['loginid'])) ? true : false; |
|
8 | + } |
|
9 | 9 | |
10 | - public function logged_in_protect() |
|
11 | - { |
|
12 | - if ($this->logged_in() === true) { |
|
13 | - header('Location: home.php'); |
|
14 | - exit(); |
|
15 | - } |
|
16 | - } |
|
10 | + public function logged_in_protect() |
|
11 | + { |
|
12 | + if ($this->logged_in() === true) { |
|
13 | + header('Location: home.php'); |
|
14 | + exit(); |
|
15 | + } |
|
16 | + } |
|
17 | 17 | |
18 | - public function logged_out_protect() |
|
19 | - { |
|
20 | - if ($this->logged_in() === false) { |
|
21 | - header('Location: index.php'); |
|
22 | - exit(); |
|
23 | - } |
|
24 | - } |
|
18 | + public function logged_out_protect() |
|
19 | + { |
|
20 | + if ($this->logged_in() === false) { |
|
21 | + header('Location: index.php'); |
|
22 | + exit(); |
|
23 | + } |
|
24 | + } |
|
25 | 25 | } |
@@ -2,102 +2,102 @@ |
||
2 | 2 | |
3 | 3 | class SLA |
4 | 4 | { |
5 | - private $db; |
|
6 | - |
|
7 | - public function __construct($database) |
|
8 | - { |
|
9 | - $this->db = $database; |
|
10 | - } |
|
11 | - |
|
12 | - public function sla_exists($slaid) |
|
13 | - { |
|
14 | - $query = $this->db->prepare('SELECT COUNT(`slaid`) FROM `sla` WHERE `slaid`= ?'); |
|
15 | - $query->bindValue(1, $slaid); |
|
16 | - |
|
17 | - try { |
|
18 | - $query->execute(); |
|
19 | - $rows = $query->fetchColumn(); |
|
20 | - if ($rows == 1) { |
|
21 | - return true; |
|
22 | - } else { |
|
23 | - return false; |
|
24 | - } |
|
25 | - } catch (PDOException $e) { |
|
26 | - die($e->getMessage()); |
|
27 | - } |
|
28 | - } |
|
29 | - |
|
30 | - public function add_sla($slaid, $namasla, $responsetime, $resolutiontime, $slawarning) |
|
31 | - { |
|
32 | - $querystring = 'INSERT INTO `sla` (`slaid`,`namasla`,`responsetime`, `resolutiontime`, `slawarning`) VALUES (?, ?, ?, ?, ?)'; |
|
33 | - $query = $this->db->prepare($querystring); |
|
34 | - $query->bindValue(1, $slaid); |
|
35 | - $query->bindValue(2, $namasla); |
|
36 | - $query->bindValue(3, $responsetime); |
|
37 | - $query->bindValue(4, $resolutiontime); |
|
38 | - $query->bindValue(5, $slawarning); |
|
39 | - |
|
40 | - try { |
|
41 | - $query->execute(); |
|
42 | - } catch (PDOException $e) { |
|
43 | - die($e->getMessage()); |
|
44 | - } |
|
45 | - } |
|
46 | - |
|
47 | - public function update_sla($slaid, $namasla, $responsetime, $resolutiontime, $slawarning) |
|
48 | - { |
|
49 | - $querystring = 'UPDATE `sla` SET `namasla` = ? , `responsetime` = ? , `resolutiontime` = ?, `slawarning` = ? WHERE `slaid` = ?'; |
|
50 | - $query = $this->db->prepare($querystring); |
|
51 | - $query->bindValue(1, $namasla); |
|
52 | - $query->bindValue(2, $responsetime); |
|
53 | - $query->bindValue(3, $resolutiontime); |
|
54 | - $query->bindValue(4, $slawarning); |
|
55 | - $query->bindValue(5, $slaid); |
|
56 | - |
|
57 | - try { |
|
58 | - $query->execute(); |
|
59 | - } catch (PDOException $e) { |
|
60 | - die($e->getMessage()); |
|
61 | - } |
|
62 | - } |
|
63 | - |
|
64 | - public function delete($id) |
|
65 | - { |
|
66 | - $sql = 'DELETE FROM `sla` WHERE `slaid` = ?'; |
|
67 | - $query = $this->db->prepare($sql); |
|
68 | - $query->bindValue(1, $id); |
|
69 | - |
|
70 | - try { |
|
71 | - $query->execute(); |
|
72 | - } catch (PDOException $e) { |
|
73 | - die($e->getMessage()); |
|
74 | - } |
|
75 | - } |
|
76 | - |
|
77 | - public function sla_data($slaid) |
|
78 | - { |
|
79 | - $query = $this->db->prepare('SELECT * FROM `sla` WHERE `slaid`= ?'); |
|
80 | - $query->bindValue(1, $slaid); |
|
81 | - |
|
82 | - try { |
|
83 | - $query->execute(); |
|
84 | - |
|
85 | - return $query->fetch(); |
|
86 | - } catch (PDOException $e) { |
|
87 | - die($e->getMessage()); |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - public function get_sla() |
|
92 | - { |
|
93 | - $query = $this->db->prepare('SELECT * FROM `sla` ORDER BY `slaid` ASC'); |
|
94 | - |
|
95 | - try { |
|
96 | - $query->execute(); |
|
97 | - } catch (PDOException $e) { |
|
98 | - die($e->getMessage()); |
|
99 | - } |
|
100 | - |
|
101 | - return $query->fetchAll(); |
|
102 | - } |
|
5 | + private $db; |
|
6 | + |
|
7 | + public function __construct($database) |
|
8 | + { |
|
9 | + $this->db = $database; |
|
10 | + } |
|
11 | + |
|
12 | + public function sla_exists($slaid) |
|
13 | + { |
|
14 | + $query = $this->db->prepare('SELECT COUNT(`slaid`) FROM `sla` WHERE `slaid`= ?'); |
|
15 | + $query->bindValue(1, $slaid); |
|
16 | + |
|
17 | + try { |
|
18 | + $query->execute(); |
|
19 | + $rows = $query->fetchColumn(); |
|
20 | + if ($rows == 1) { |
|
21 | + return true; |
|
22 | + } else { |
|
23 | + return false; |
|
24 | + } |
|
25 | + } catch (PDOException $e) { |
|
26 | + die($e->getMessage()); |
|
27 | + } |
|
28 | + } |
|
29 | + |
|
30 | + public function add_sla($slaid, $namasla, $responsetime, $resolutiontime, $slawarning) |
|
31 | + { |
|
32 | + $querystring = 'INSERT INTO `sla` (`slaid`,`namasla`,`responsetime`, `resolutiontime`, `slawarning`) VALUES (?, ?, ?, ?, ?)'; |
|
33 | + $query = $this->db->prepare($querystring); |
|
34 | + $query->bindValue(1, $slaid); |
|
35 | + $query->bindValue(2, $namasla); |
|
36 | + $query->bindValue(3, $responsetime); |
|
37 | + $query->bindValue(4, $resolutiontime); |
|
38 | + $query->bindValue(5, $slawarning); |
|
39 | + |
|
40 | + try { |
|
41 | + $query->execute(); |
|
42 | + } catch (PDOException $e) { |
|
43 | + die($e->getMessage()); |
|
44 | + } |
|
45 | + } |
|
46 | + |
|
47 | + public function update_sla($slaid, $namasla, $responsetime, $resolutiontime, $slawarning) |
|
48 | + { |
|
49 | + $querystring = 'UPDATE `sla` SET `namasla` = ? , `responsetime` = ? , `resolutiontime` = ?, `slawarning` = ? WHERE `slaid` = ?'; |
|
50 | + $query = $this->db->prepare($querystring); |
|
51 | + $query->bindValue(1, $namasla); |
|
52 | + $query->bindValue(2, $responsetime); |
|
53 | + $query->bindValue(3, $resolutiontime); |
|
54 | + $query->bindValue(4, $slawarning); |
|
55 | + $query->bindValue(5, $slaid); |
|
56 | + |
|
57 | + try { |
|
58 | + $query->execute(); |
|
59 | + } catch (PDOException $e) { |
|
60 | + die($e->getMessage()); |
|
61 | + } |
|
62 | + } |
|
63 | + |
|
64 | + public function delete($id) |
|
65 | + { |
|
66 | + $sql = 'DELETE FROM `sla` WHERE `slaid` = ?'; |
|
67 | + $query = $this->db->prepare($sql); |
|
68 | + $query->bindValue(1, $id); |
|
69 | + |
|
70 | + try { |
|
71 | + $query->execute(); |
|
72 | + } catch (PDOException $e) { |
|
73 | + die($e->getMessage()); |
|
74 | + } |
|
75 | + } |
|
76 | + |
|
77 | + public function sla_data($slaid) |
|
78 | + { |
|
79 | + $query = $this->db->prepare('SELECT * FROM `sla` WHERE `slaid`= ?'); |
|
80 | + $query->bindValue(1, $slaid); |
|
81 | + |
|
82 | + try { |
|
83 | + $query->execute(); |
|
84 | + |
|
85 | + return $query->fetch(); |
|
86 | + } catch (PDOException $e) { |
|
87 | + die($e->getMessage()); |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + public function get_sla() |
|
92 | + { |
|
93 | + $query = $this->db->prepare('SELECT * FROM `sla` ORDER BY `slaid` ASC'); |
|
94 | + |
|
95 | + try { |
|
96 | + $query->execute(); |
|
97 | + } catch (PDOException $e) { |
|
98 | + die($e->getMessage()); |
|
99 | + } |
|
100 | + |
|
101 | + return $query->fetchAll(); |
|
102 | + } |
|
103 | 103 | } |
@@ -19,10 +19,10 @@ discard block |
||
19 | 19 | $rows = $query->fetchColumn(); |
20 | 20 | if ($rows == 1) { |
21 | 21 | return true; |
22 | - } else { |
|
22 | + }else { |
|
23 | 23 | return false; |
24 | 24 | } |
25 | - } catch (PDOException $e) { |
|
25 | + }catch (PDOException $e) { |
|
26 | 26 | die($e->getMessage()); |
27 | 27 | } |
28 | 28 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | |
40 | 40 | try { |
41 | 41 | $query->execute(); |
42 | - } catch (PDOException $e) { |
|
42 | + }catch (PDOException $e) { |
|
43 | 43 | die($e->getMessage()); |
44 | 44 | } |
45 | 45 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | |
57 | 57 | try { |
58 | 58 | $query->execute(); |
59 | - } catch (PDOException $e) { |
|
59 | + }catch (PDOException $e) { |
|
60 | 60 | die($e->getMessage()); |
61 | 61 | } |
62 | 62 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | |
70 | 70 | try { |
71 | 71 | $query->execute(); |
72 | - } catch (PDOException $e) { |
|
72 | + }catch (PDOException $e) { |
|
73 | 73 | die($e->getMessage()); |
74 | 74 | } |
75 | 75 | } |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | $query->execute(); |
84 | 84 | |
85 | 85 | return $query->fetch(); |
86 | - } catch (PDOException $e) { |
|
86 | + }catch (PDOException $e) { |
|
87 | 87 | die($e->getMessage()); |
88 | 88 | } |
89 | 89 | } |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | |
95 | 95 | try { |
96 | 96 | $query->execute(); |
97 | - } catch (PDOException $e) { |
|
97 | + }catch (PDOException $e) { |
|
98 | 98 | die($e->getMessage()); |
99 | 99 | } |
100 | 100 |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | $config = [ |
4 | - 'host' => 'localhost', |
|
5 | - 'username' => 'root', |
|
6 | - 'password' => 'root', |
|
7 | - 'dbname' => 'helpdesk', |
|
4 | + 'host' => 'localhost', |
|
5 | + 'username' => 'root', |
|
6 | + 'password' => 'root', |
|
7 | + 'dbname' => 'helpdesk', |
|
8 | 8 | ]; |
9 | 9 | |
10 | 10 | $db = new PDO('mysql:host='.$config['host'].';dbname='.$config['dbname'], $config['username'], $config['password']); |
@@ -18,21 +18,21 @@ |
||
18 | 18 | </body> |
19 | 19 | </html> |
20 | 20 | '; |
21 | - if ($_POST['format'] == '1') { |
|
22 | - header('Content-type: application/vnd.ms-word'); |
|
23 | - header('Content-Disposition: attachment; Filename="'.$reportname.'.doc"'); |
|
24 | - echo $content; |
|
25 | - } elseif ($_POST['format'] == '2') { |
|
26 | - header('Content-type: application/ms-excel'); |
|
27 | - header('Content-Disposition: attachment; filename="'.$reportname.'.xls"'); |
|
28 | - echo $content; |
|
29 | - } elseif ($_POST['format'] == '3') { |
|
30 | - $filename = $reportname.'.pdf'; |
|
31 | - define('FPDF_FONTPATH', 'pdftable/font/'); |
|
32 | - require 'pdftable/lib/pdftable.inc.php'; |
|
33 | - $p = new PDFTable(); |
|
34 | - $p->AddPage(); |
|
35 | - $p->setfont('times', '', 12); |
|
36 | - $p->htmltable($content); |
|
37 | - $p->output($filename, 'I'); |
|
38 | - } |
|
21 | + if ($_POST['format'] == '1') { |
|
22 | + header('Content-type: application/vnd.ms-word'); |
|
23 | + header('Content-Disposition: attachment; Filename="'.$reportname.'.doc"'); |
|
24 | + echo $content; |
|
25 | + } elseif ($_POST['format'] == '2') { |
|
26 | + header('Content-type: application/ms-excel'); |
|
27 | + header('Content-Disposition: attachment; filename="'.$reportname.'.xls"'); |
|
28 | + echo $content; |
|
29 | + } elseif ($_POST['format'] == '3') { |
|
30 | + $filename = $reportname.'.pdf'; |
|
31 | + define('FPDF_FONTPATH', 'pdftable/font/'); |
|
32 | + require 'pdftable/lib/pdftable.inc.php'; |
|
33 | + $p = new PDFTable(); |
|
34 | + $p->AddPage(); |
|
35 | + $p->setfont('times', '', 12); |
|
36 | + $p->htmltable($content); |
|
37 | + $p->output($filename, 'I'); |
|
38 | + } |
@@ -7,102 +7,102 @@ |
||
7 | 7 | */ |
8 | 8 | class Color |
9 | 9 | { |
10 | - /** |
|
11 | - * @desc Use only for function HSL2RGB() |
|
12 | - */ |
|
13 | - public function _HSL_2_RGB($v1, $v2, $vH) |
|
14 | - { |
|
15 | - if ($vH < 0) { |
|
16 | - $vH += 1; |
|
17 | - } |
|
18 | - if ($vH > 1) { |
|
19 | - $vH -= 1; |
|
20 | - } |
|
21 | - if ((6 * $vH) < 1) { |
|
22 | - return $v1 + ($v2 - $v1) * 6 * $vH; |
|
23 | - } |
|
24 | - if ((2 * $vH) < 1) { |
|
25 | - return $v2; |
|
26 | - } |
|
27 | - if ((3 * $vH) < 2) { |
|
28 | - return $v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6; |
|
29 | - } |
|
10 | + /** |
|
11 | + * @desc Use only for function HSL2RGB() |
|
12 | + */ |
|
13 | + public function _HSL_2_RGB($v1, $v2, $vH) |
|
14 | + { |
|
15 | + if ($vH < 0) { |
|
16 | + $vH += 1; |
|
17 | + } |
|
18 | + if ($vH > 1) { |
|
19 | + $vH -= 1; |
|
20 | + } |
|
21 | + if ((6 * $vH) < 1) { |
|
22 | + return $v1 + ($v2 - $v1) * 6 * $vH; |
|
23 | + } |
|
24 | + if ((2 * $vH) < 1) { |
|
25 | + return $v2; |
|
26 | + } |
|
27 | + if ((3 * $vH) < 2) { |
|
28 | + return $v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6; |
|
29 | + } |
|
30 | 30 | |
31 | - return $v1; |
|
32 | - } |
|
31 | + return $v1; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * @desc Convert HSL to RGB |
|
36 | - * HSL values = From 0 to 1 |
|
37 | - * RGB results = From 0 to 255 |
|
38 | - * Code from http://www.easyrgb.com/math.php?MATH=M19#text19 |
|
39 | - */ |
|
40 | - public function HSL2RGB($H, $S, $L, &$R, &$G, &$B) |
|
41 | - { |
|
42 | - if ($S == 0) { |
|
43 | - $R = $L * 255; |
|
44 | - $G = $L * 255; |
|
45 | - $B = $L * 255; |
|
46 | - } else { |
|
47 | - $var_2 = ($L < 0.5) ? ($L * (1 + $S)) : (($L + $S) - ($S * $L)); |
|
48 | - $var_1 = 2 * $L - $var_2; |
|
49 | - $R = 255 * self::_HSL_2_RGB($var_1, $var_2, $H + (1 / 3)); |
|
50 | - $G = 255 * self::_HSL_2_RGB($var_1, $var_2, $H); |
|
51 | - $B = 255 * self::_HSL_2_RGB($var_1, $var_2, $H - (1 / 3)); |
|
52 | - } |
|
53 | - } |
|
34 | + /** |
|
35 | + * @desc Convert HSL to RGB |
|
36 | + * HSL values = From 0 to 1 |
|
37 | + * RGB results = From 0 to 255 |
|
38 | + * Code from http://www.easyrgb.com/math.php?MATH=M19#text19 |
|
39 | + */ |
|
40 | + public function HSL2RGB($H, $S, $L, &$R, &$G, &$B) |
|
41 | + { |
|
42 | + if ($S == 0) { |
|
43 | + $R = $L * 255; |
|
44 | + $G = $L * 255; |
|
45 | + $B = $L * 255; |
|
46 | + } else { |
|
47 | + $var_2 = ($L < 0.5) ? ($L * (1 + $S)) : (($L + $S) - ($S * $L)); |
|
48 | + $var_1 = 2 * $L - $var_2; |
|
49 | + $R = 255 * self::_HSL_2_RGB($var_1, $var_2, $H + (1 / 3)); |
|
50 | + $G = 255 * self::_HSL_2_RGB($var_1, $var_2, $H); |
|
51 | + $B = 255 * self::_HSL_2_RGB($var_1, $var_2, $H - (1 / 3)); |
|
52 | + } |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @desc Convert decimal color to #ffffff |
|
57 | - */ |
|
58 | - public function RGB2HEX($r, $g, $b) |
|
59 | - { |
|
60 | - $r = ($r < 16) ? '0'.dechex($r) : dechex($r); |
|
61 | - $g = ($g < 16) ? '0'.dechex($g) : dechex($g); |
|
62 | - $b = ($b < 16) ? '0'.dechex($b) : dechex($b); |
|
55 | + /** |
|
56 | + * @desc Convert decimal color to #ffffff |
|
57 | + */ |
|
58 | + public function RGB2HEX($r, $g, $b) |
|
59 | + { |
|
60 | + $r = ($r < 16) ? '0'.dechex($r) : dechex($r); |
|
61 | + $g = ($g < 16) ? '0'.dechex($g) : dechex($g); |
|
62 | + $b = ($b < 16) ? '0'.dechex($b) : dechex($b); |
|
63 | 63 | |
64 | - return "#$r$g$b"; |
|
65 | - } |
|
64 | + return "#$r$g$b"; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @desc Convert color #ffffff to RGB |
|
69 | - */ |
|
70 | - public function HEX2RGB($c) |
|
71 | - { |
|
72 | - if (strlen($c) != 7) { |
|
73 | - return 0; |
|
74 | - } |
|
75 | - $r[] = hexdec($c[1].$c[2]); |
|
76 | - $r[] = hexdec($c[3].$c[4]); |
|
77 | - $r[] = hexdec($c[5].$c[6]); |
|
67 | + /** |
|
68 | + * @desc Convert color #ffffff to RGB |
|
69 | + */ |
|
70 | + public function HEX2RGB($c) |
|
71 | + { |
|
72 | + if (strlen($c) != 7) { |
|
73 | + return 0; |
|
74 | + } |
|
75 | + $r[] = hexdec($c[1].$c[2]); |
|
76 | + $r[] = hexdec($c[3].$c[4]); |
|
77 | + $r[] = hexdec($c[5].$c[6]); |
|
78 | 78 | |
79 | - return $r; |
|
80 | - } |
|
79 | + return $r; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @desc Genereate an array of n colors differents |
|
84 | - */ |
|
85 | - public function getListColor($n) |
|
86 | - { |
|
87 | - $h = 0; |
|
88 | - $s = 1; |
|
89 | - $l = 0.6; |
|
82 | + /** |
|
83 | + * @desc Genereate an array of n colors differents |
|
84 | + */ |
|
85 | + public function getListColor($n) |
|
86 | + { |
|
87 | + $h = 0; |
|
88 | + $s = 1; |
|
89 | + $l = 0.6; |
|
90 | 90 | |
91 | - $d = 1 / ($n + 1); |
|
92 | - $n2 = $n / 2; |
|
93 | - $n3 = intval($n / 3); |
|
94 | - $c = 1; |
|
95 | - for ($i = 0; $i < $n; $i++) { |
|
96 | - self::HSL2RGB($h, $s, $l, $r, $g, $b); |
|
97 | - $color[] = self::RGB2HEX($r, $g, $b); |
|
98 | - $h += 3 * $d; |
|
99 | - if ($i % $n3 == 0) { |
|
100 | - $h = ($c++) * $d; |
|
101 | - $s -= 0.1; |
|
102 | - $l -= 0.07; |
|
103 | - } |
|
104 | - } |
|
91 | + $d = 1 / ($n + 1); |
|
92 | + $n2 = $n / 2; |
|
93 | + $n3 = intval($n / 3); |
|
94 | + $c = 1; |
|
95 | + for ($i = 0; $i < $n; $i++) { |
|
96 | + self::HSL2RGB($h, $s, $l, $r, $g, $b); |
|
97 | + $color[] = self::RGB2HEX($r, $g, $b); |
|
98 | + $h += 3 * $d; |
|
99 | + if ($i % $n3 == 0) { |
|
100 | + $h = ($c++) * $d; |
|
101 | + $s -= 0.1; |
|
102 | + $l -= 0.07; |
|
103 | + } |
|
104 | + } |
|
105 | 105 | |
106 | - return $color; |
|
107 | - } |
|
106 | + return $color; |
|
107 | + } |
|
108 | 108 | } |
@@ -43,7 +43,7 @@ |
||
43 | 43 | $R = $L * 255; |
44 | 44 | $G = $L * 255; |
45 | 45 | $B = $L * 255; |
46 | - } else { |
|
46 | + }else { |
|
47 | 47 | $var_2 = ($L < 0.5) ? ($L * (1 + $S)) : (($L + $S) - ($S * $L)); |
48 | 48 | $var_1 = 2 * $L - $var_2; |
49 | 49 | $R = 255 * self::_HSL_2_RGB($var_1, $var_2, $H + (1 / 3)); |
@@ -33,586 +33,586 @@ |
||
33 | 33 | */ |
34 | 34 | class HTMLParser |
35 | 35 | { |
36 | - /** |
|
37 | - * Field iNodeType. |
|
38 | - * May be one of the NODE_TYPE_* constants above. |
|
39 | - */ |
|
40 | - public $iNodeType; |
|
41 | - |
|
42 | - /** |
|
43 | - * Field iNodeName. |
|
44 | - * For elements, it's the name of the element. |
|
45 | - */ |
|
46 | - public $iNodeName = ''; |
|
47 | - |
|
48 | - /** |
|
49 | - * Field iNodeValue. |
|
50 | - * For text nodes, it's the text. |
|
51 | - */ |
|
52 | - public $iNodeValue = ''; |
|
53 | - |
|
54 | - /** |
|
55 | - * Field iNodeAttributes. |
|
56 | - * A string-indexed array containing attribute values |
|
57 | - * of the current node. Indexes are always lowercase. |
|
58 | - */ |
|
59 | - public $iNodeAttributes; |
|
60 | - |
|
61 | - // The following fields should be |
|
62 | - // considered private: |
|
63 | - |
|
64 | - public $iHtmlText; |
|
65 | - public $iHtmlTextLength; |
|
66 | - public $iHtmlTextIndex = 0; |
|
67 | - public $iHtmlCurrentChar; |
|
68 | - |
|
69 | - /** |
|
70 | - * Constructor. |
|
71 | - * Constructs an HTMLParser instance with |
|
72 | - * the HTML text given. |
|
73 | - */ |
|
74 | - public function HTMLParser($aHtmlText) |
|
75 | - { |
|
76 | - $this->iHtmlText = $aHtmlText; |
|
77 | - $this->iHtmlTextLength = strlen($aHtmlText); |
|
78 | - $this->setTextIndex(0); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Method parse. |
|
83 | - * Parses the next node. Returns false only if |
|
84 | - * the end of the HTML text has been reached. |
|
85 | - * Updates values of iNode* fields. |
|
86 | - */ |
|
87 | - public function parse() |
|
88 | - { |
|
89 | - $text = trim($this->skipToElement()); |
|
90 | - if ($text != '') { |
|
91 | - $this->iNodeType = NODE_TYPE_TEXT; |
|
92 | - $this->iNodeName = 'Text'; |
|
93 | - $this->iNodeValue = $text; |
|
94 | - $this->iNodeAttributes = 0; |
|
95 | - |
|
96 | - return true; |
|
97 | - } |
|
98 | - |
|
99 | - return $this->readTag(); |
|
100 | - } |
|
101 | - |
|
102 | - public function clearAttributes() |
|
103 | - { |
|
104 | - $this->iNodeAttributes = []; |
|
105 | - } |
|
106 | - |
|
107 | - public function readTag() |
|
108 | - { |
|
109 | - global $HTML_ATTRIBUTE_STAND_ALONE; |
|
110 | - if ($this->iCurrentChar != '<') { |
|
111 | - $this->iNodeType = NODE_TYPE_DONE; |
|
112 | - |
|
113 | - return false; |
|
114 | - } |
|
115 | - $this->skipInTag(['<']); |
|
116 | - $this->clearAttributes(); |
|
117 | - $name = $this->skipToBlanksInTag(); |
|
118 | - $pos = strpos($name, '/'); |
|
119 | - if ($pos === 0) { |
|
120 | - $this->iNodeType = NODE_TYPE_ENDELEMENT; |
|
121 | - $this->iNodeName = substr($name, 1); |
|
122 | - $this->iNodeValue = ''; |
|
123 | - } else { |
|
124 | - if (!$this->isValidTagIdentifier($name)) { |
|
125 | - $comment = false; |
|
126 | - if ($name == '!--') { |
|
127 | - $rest = $this->skipToStringInTag('-->'); |
|
128 | - if ($rest != '') { |
|
129 | - $this->iNodeType = NODE_TYPE_COMMENT; |
|
130 | - $this->iNodeName = 'Comment'; |
|
131 | - $this->iNodeValue = '<'.$name.$rest; |
|
132 | - $comment = true; |
|
133 | - } |
|
134 | - } |
|
135 | - if (!$comment) { |
|
136 | - $this->iNodeType = NODE_TYPE_TEXT; |
|
137 | - $this->iNodeName = 'Text'; |
|
138 | - $this->iNodeValue = '<'.$name; |
|
139 | - } |
|
140 | - |
|
141 | - return true; |
|
142 | - } else { |
|
143 | - $this->iNodeType = NODE_TYPE_ELEMENT; |
|
144 | - $this->iNodeValue = ''; |
|
145 | - $nameLength = strlen($name); |
|
146 | - if ($nameLength > 0 && substr($name, $nameLength - 1, 1) == '/') { |
|
147 | - $this->iNodeName = substr($name, 0, $nameLength - 1); |
|
148 | - } else { |
|
149 | - $this->iNodeName = $name; |
|
150 | - } |
|
151 | - $this->iNodeName = strtolower($this->iNodeName); |
|
152 | - } |
|
153 | - } |
|
154 | - while ($this->skipBlanksInTag()) { |
|
155 | - $attrName = $this->skipToBlanksOrEqualsInTag(); |
|
156 | - if ($attrName != '') { |
|
157 | - $attrName = strtolower($attrName); |
|
158 | - if (array_search($attrName, $HTML_ATTRIBUTE_STAND_ALONE) !== false) { |
|
159 | - $this->iNodeAttributes[$attrName] = 1; |
|
160 | - } else { |
|
161 | - $this->skipBlanksInTag(); |
|
162 | - if ($this->iCurrentChar == '=') { |
|
163 | - $this->skipEqualsInTag(); |
|
164 | - $this->skipBlanksInTag(); |
|
165 | - $value = $this->readValueInTag(); |
|
166 | - $this->iNodeAttributes[$attrName] = $value; |
|
167 | - } else { |
|
168 | - $this->iNodeAttributes[$attrName] = ''; |
|
169 | - } |
|
170 | - } |
|
171 | - } |
|
172 | - } |
|
173 | - $this->skipEndOfTag(); |
|
174 | - |
|
175 | - return true; |
|
176 | - } |
|
177 | - |
|
178 | - public function isValidTagIdentifier($name) |
|
179 | - { |
|
180 | - return preg_match('/[A-Za-z0-9]+/', $name); |
|
181 | - } |
|
182 | - |
|
183 | - public function skipBlanksInTag() |
|
184 | - { |
|
185 | - return '' != ($this->skipInTag([' ', "\t", "\r", "\n"])); |
|
186 | - } |
|
187 | - |
|
188 | - public function skipToBlanksOrEqualsInTag() |
|
189 | - { |
|
190 | - return $this->skipToInTag([' ', "\t", "\r", "\n", '=']); |
|
191 | - } |
|
192 | - |
|
193 | - public function skipToBlanksInTag() |
|
194 | - { |
|
195 | - return $this->skipToInTag([' ', "\t", "\r", "\n"]); |
|
196 | - } |
|
197 | - |
|
198 | - public function skipEqualsInTag() |
|
199 | - { |
|
200 | - return $this->skipInTag(['=']); |
|
201 | - } |
|
202 | - |
|
203 | - public function readValueInTag() |
|
204 | - { |
|
205 | - $ch = $this->iCurrentChar; |
|
206 | - $value = ''; |
|
207 | - if ($ch == '"') { |
|
208 | - $this->skipInTag(['"']); |
|
209 | - $value = $this->skipToInTag(['"']); |
|
210 | - $this->skipInTag(['"']); |
|
211 | - } elseif ($ch == "'") { |
|
212 | - $this->skipInTag(["'"]); |
|
213 | - $value = $this->skipToInTag(["'"]); |
|
214 | - $this->skipInTag(["'"]); |
|
215 | - } else { |
|
216 | - $value = $this->skipToBlanksInTag(); |
|
217 | - } |
|
218 | - |
|
219 | - return $value; |
|
220 | - } |
|
221 | - |
|
222 | - public function setTextIndex($index) |
|
223 | - { |
|
224 | - $this->iHtmlTextIndex = $index; |
|
225 | - if ($index >= $this->iHtmlTextLength) { |
|
226 | - $this->iCurrentChar = -1; |
|
227 | - } else { |
|
228 | - $this->iCurrentChar = $this->iHtmlText[$index]; |
|
229 | - } |
|
230 | - } |
|
231 | - |
|
232 | - public function moveNext() |
|
233 | - { |
|
234 | - if ($this->iHtmlTextIndex < $this->iHtmlTextLength) { |
|
235 | - $this->setTextIndex($this->iHtmlTextIndex + 1); |
|
236 | - |
|
237 | - return true; |
|
238 | - } else { |
|
239 | - return false; |
|
240 | - } |
|
241 | - } |
|
242 | - |
|
243 | - public function skipEndOfTag() |
|
244 | - { |
|
245 | - $sb = ''; |
|
246 | - if (($ch = $this->iCurrentChar) !== -1) { |
|
247 | - $match = ($ch == '>'); |
|
248 | - if (!$match) { |
|
249 | - return $sb; |
|
250 | - } |
|
251 | - $sb .= $ch; |
|
252 | - $this->moveNext(); |
|
253 | - } |
|
254 | - |
|
255 | - return $sb; |
|
256 | - } |
|
257 | - |
|
258 | - public function skipInTag($chars) |
|
259 | - { |
|
260 | - $sb = ''; |
|
261 | - while (($ch = $this->iCurrentChar) !== -1) { |
|
262 | - if ($ch == '>') { |
|
263 | - return $sb; |
|
264 | - } else { |
|
265 | - if (array_search($ch, $chars) === false) { |
|
266 | - return $sb; |
|
267 | - } |
|
268 | - $sb .= $ch; |
|
269 | - $this->moveNext(); |
|
270 | - } |
|
271 | - } |
|
272 | - |
|
273 | - return $sb; |
|
274 | - } |
|
275 | - |
|
276 | - public function skipToInTag($chars) |
|
277 | - { |
|
278 | - $sb = ''; |
|
279 | - while (($ch = $this->iCurrentChar) !== -1) { |
|
280 | - if ($ch == '>' || array_search($ch, $chars) !== false) { |
|
281 | - return $sb; |
|
282 | - } |
|
283 | - $sb .= $ch; |
|
284 | - $this->moveNext(); |
|
285 | - } |
|
286 | - |
|
287 | - return $sb; |
|
288 | - } |
|
289 | - |
|
290 | - public function skipToElement() |
|
291 | - { |
|
292 | - $sb = ''; |
|
293 | - while (($ch = $this->iCurrentChar) !== -1) { |
|
294 | - if ($ch == '<') { |
|
295 | - return $sb; |
|
296 | - } |
|
297 | - $sb .= $ch; |
|
298 | - $this->moveNext(); |
|
299 | - } |
|
300 | - |
|
301 | - return $sb; |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * Returns text between current position and $needle, |
|
306 | - * inclusive, or "" if not found. The current index is moved to a point |
|
307 | - * after the location of $needle, or not moved at all |
|
308 | - * if nothing is found. |
|
309 | - */ |
|
310 | - public function skipToStringInTag($needle) |
|
311 | - { |
|
312 | - $pos = strpos($this->iHtmlText, $needle, $this->iHtmlTextIndex); |
|
313 | - if ($pos === false) { |
|
314 | - return ''; |
|
315 | - } |
|
316 | - $top = $pos + strlen($needle); |
|
317 | - $retvalue = substr($this->iHtmlText, $this->iHtmlTextIndex, $top - $this->iHtmlTextIndex); |
|
318 | - $this->setTextIndex($top); |
|
319 | - |
|
320 | - return $retvalue; |
|
321 | - } |
|
36 | + /** |
|
37 | + * Field iNodeType. |
|
38 | + * May be one of the NODE_TYPE_* constants above. |
|
39 | + */ |
|
40 | + public $iNodeType; |
|
41 | + |
|
42 | + /** |
|
43 | + * Field iNodeName. |
|
44 | + * For elements, it's the name of the element. |
|
45 | + */ |
|
46 | + public $iNodeName = ''; |
|
47 | + |
|
48 | + /** |
|
49 | + * Field iNodeValue. |
|
50 | + * For text nodes, it's the text. |
|
51 | + */ |
|
52 | + public $iNodeValue = ''; |
|
53 | + |
|
54 | + /** |
|
55 | + * Field iNodeAttributes. |
|
56 | + * A string-indexed array containing attribute values |
|
57 | + * of the current node. Indexes are always lowercase. |
|
58 | + */ |
|
59 | + public $iNodeAttributes; |
|
60 | + |
|
61 | + // The following fields should be |
|
62 | + // considered private: |
|
63 | + |
|
64 | + public $iHtmlText; |
|
65 | + public $iHtmlTextLength; |
|
66 | + public $iHtmlTextIndex = 0; |
|
67 | + public $iHtmlCurrentChar; |
|
68 | + |
|
69 | + /** |
|
70 | + * Constructor. |
|
71 | + * Constructs an HTMLParser instance with |
|
72 | + * the HTML text given. |
|
73 | + */ |
|
74 | + public function HTMLParser($aHtmlText) |
|
75 | + { |
|
76 | + $this->iHtmlText = $aHtmlText; |
|
77 | + $this->iHtmlTextLength = strlen($aHtmlText); |
|
78 | + $this->setTextIndex(0); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Method parse. |
|
83 | + * Parses the next node. Returns false only if |
|
84 | + * the end of the HTML text has been reached. |
|
85 | + * Updates values of iNode* fields. |
|
86 | + */ |
|
87 | + public function parse() |
|
88 | + { |
|
89 | + $text = trim($this->skipToElement()); |
|
90 | + if ($text != '') { |
|
91 | + $this->iNodeType = NODE_TYPE_TEXT; |
|
92 | + $this->iNodeName = 'Text'; |
|
93 | + $this->iNodeValue = $text; |
|
94 | + $this->iNodeAttributes = 0; |
|
95 | + |
|
96 | + return true; |
|
97 | + } |
|
98 | + |
|
99 | + return $this->readTag(); |
|
100 | + } |
|
101 | + |
|
102 | + public function clearAttributes() |
|
103 | + { |
|
104 | + $this->iNodeAttributes = []; |
|
105 | + } |
|
106 | + |
|
107 | + public function readTag() |
|
108 | + { |
|
109 | + global $HTML_ATTRIBUTE_STAND_ALONE; |
|
110 | + if ($this->iCurrentChar != '<') { |
|
111 | + $this->iNodeType = NODE_TYPE_DONE; |
|
112 | + |
|
113 | + return false; |
|
114 | + } |
|
115 | + $this->skipInTag(['<']); |
|
116 | + $this->clearAttributes(); |
|
117 | + $name = $this->skipToBlanksInTag(); |
|
118 | + $pos = strpos($name, '/'); |
|
119 | + if ($pos === 0) { |
|
120 | + $this->iNodeType = NODE_TYPE_ENDELEMENT; |
|
121 | + $this->iNodeName = substr($name, 1); |
|
122 | + $this->iNodeValue = ''; |
|
123 | + } else { |
|
124 | + if (!$this->isValidTagIdentifier($name)) { |
|
125 | + $comment = false; |
|
126 | + if ($name == '!--') { |
|
127 | + $rest = $this->skipToStringInTag('-->'); |
|
128 | + if ($rest != '') { |
|
129 | + $this->iNodeType = NODE_TYPE_COMMENT; |
|
130 | + $this->iNodeName = 'Comment'; |
|
131 | + $this->iNodeValue = '<'.$name.$rest; |
|
132 | + $comment = true; |
|
133 | + } |
|
134 | + } |
|
135 | + if (!$comment) { |
|
136 | + $this->iNodeType = NODE_TYPE_TEXT; |
|
137 | + $this->iNodeName = 'Text'; |
|
138 | + $this->iNodeValue = '<'.$name; |
|
139 | + } |
|
140 | + |
|
141 | + return true; |
|
142 | + } else { |
|
143 | + $this->iNodeType = NODE_TYPE_ELEMENT; |
|
144 | + $this->iNodeValue = ''; |
|
145 | + $nameLength = strlen($name); |
|
146 | + if ($nameLength > 0 && substr($name, $nameLength - 1, 1) == '/') { |
|
147 | + $this->iNodeName = substr($name, 0, $nameLength - 1); |
|
148 | + } else { |
|
149 | + $this->iNodeName = $name; |
|
150 | + } |
|
151 | + $this->iNodeName = strtolower($this->iNodeName); |
|
152 | + } |
|
153 | + } |
|
154 | + while ($this->skipBlanksInTag()) { |
|
155 | + $attrName = $this->skipToBlanksOrEqualsInTag(); |
|
156 | + if ($attrName != '') { |
|
157 | + $attrName = strtolower($attrName); |
|
158 | + if (array_search($attrName, $HTML_ATTRIBUTE_STAND_ALONE) !== false) { |
|
159 | + $this->iNodeAttributes[$attrName] = 1; |
|
160 | + } else { |
|
161 | + $this->skipBlanksInTag(); |
|
162 | + if ($this->iCurrentChar == '=') { |
|
163 | + $this->skipEqualsInTag(); |
|
164 | + $this->skipBlanksInTag(); |
|
165 | + $value = $this->readValueInTag(); |
|
166 | + $this->iNodeAttributes[$attrName] = $value; |
|
167 | + } else { |
|
168 | + $this->iNodeAttributes[$attrName] = ''; |
|
169 | + } |
|
170 | + } |
|
171 | + } |
|
172 | + } |
|
173 | + $this->skipEndOfTag(); |
|
174 | + |
|
175 | + return true; |
|
176 | + } |
|
177 | + |
|
178 | + public function isValidTagIdentifier($name) |
|
179 | + { |
|
180 | + return preg_match('/[A-Za-z0-9]+/', $name); |
|
181 | + } |
|
182 | + |
|
183 | + public function skipBlanksInTag() |
|
184 | + { |
|
185 | + return '' != ($this->skipInTag([' ', "\t", "\r", "\n"])); |
|
186 | + } |
|
187 | + |
|
188 | + public function skipToBlanksOrEqualsInTag() |
|
189 | + { |
|
190 | + return $this->skipToInTag([' ', "\t", "\r", "\n", '=']); |
|
191 | + } |
|
192 | + |
|
193 | + public function skipToBlanksInTag() |
|
194 | + { |
|
195 | + return $this->skipToInTag([' ', "\t", "\r", "\n"]); |
|
196 | + } |
|
197 | + |
|
198 | + public function skipEqualsInTag() |
|
199 | + { |
|
200 | + return $this->skipInTag(['=']); |
|
201 | + } |
|
202 | + |
|
203 | + public function readValueInTag() |
|
204 | + { |
|
205 | + $ch = $this->iCurrentChar; |
|
206 | + $value = ''; |
|
207 | + if ($ch == '"') { |
|
208 | + $this->skipInTag(['"']); |
|
209 | + $value = $this->skipToInTag(['"']); |
|
210 | + $this->skipInTag(['"']); |
|
211 | + } elseif ($ch == "'") { |
|
212 | + $this->skipInTag(["'"]); |
|
213 | + $value = $this->skipToInTag(["'"]); |
|
214 | + $this->skipInTag(["'"]); |
|
215 | + } else { |
|
216 | + $value = $this->skipToBlanksInTag(); |
|
217 | + } |
|
218 | + |
|
219 | + return $value; |
|
220 | + } |
|
221 | + |
|
222 | + public function setTextIndex($index) |
|
223 | + { |
|
224 | + $this->iHtmlTextIndex = $index; |
|
225 | + if ($index >= $this->iHtmlTextLength) { |
|
226 | + $this->iCurrentChar = -1; |
|
227 | + } else { |
|
228 | + $this->iCurrentChar = $this->iHtmlText[$index]; |
|
229 | + } |
|
230 | + } |
|
231 | + |
|
232 | + public function moveNext() |
|
233 | + { |
|
234 | + if ($this->iHtmlTextIndex < $this->iHtmlTextLength) { |
|
235 | + $this->setTextIndex($this->iHtmlTextIndex + 1); |
|
236 | + |
|
237 | + return true; |
|
238 | + } else { |
|
239 | + return false; |
|
240 | + } |
|
241 | + } |
|
242 | + |
|
243 | + public function skipEndOfTag() |
|
244 | + { |
|
245 | + $sb = ''; |
|
246 | + if (($ch = $this->iCurrentChar) !== -1) { |
|
247 | + $match = ($ch == '>'); |
|
248 | + if (!$match) { |
|
249 | + return $sb; |
|
250 | + } |
|
251 | + $sb .= $ch; |
|
252 | + $this->moveNext(); |
|
253 | + } |
|
254 | + |
|
255 | + return $sb; |
|
256 | + } |
|
257 | + |
|
258 | + public function skipInTag($chars) |
|
259 | + { |
|
260 | + $sb = ''; |
|
261 | + while (($ch = $this->iCurrentChar) !== -1) { |
|
262 | + if ($ch == '>') { |
|
263 | + return $sb; |
|
264 | + } else { |
|
265 | + if (array_search($ch, $chars) === false) { |
|
266 | + return $sb; |
|
267 | + } |
|
268 | + $sb .= $ch; |
|
269 | + $this->moveNext(); |
|
270 | + } |
|
271 | + } |
|
272 | + |
|
273 | + return $sb; |
|
274 | + } |
|
275 | + |
|
276 | + public function skipToInTag($chars) |
|
277 | + { |
|
278 | + $sb = ''; |
|
279 | + while (($ch = $this->iCurrentChar) !== -1) { |
|
280 | + if ($ch == '>' || array_search($ch, $chars) !== false) { |
|
281 | + return $sb; |
|
282 | + } |
|
283 | + $sb .= $ch; |
|
284 | + $this->moveNext(); |
|
285 | + } |
|
286 | + |
|
287 | + return $sb; |
|
288 | + } |
|
289 | + |
|
290 | + public function skipToElement() |
|
291 | + { |
|
292 | + $sb = ''; |
|
293 | + while (($ch = $this->iCurrentChar) !== -1) { |
|
294 | + if ($ch == '<') { |
|
295 | + return $sb; |
|
296 | + } |
|
297 | + $sb .= $ch; |
|
298 | + $this->moveNext(); |
|
299 | + } |
|
300 | + |
|
301 | + return $sb; |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * Returns text between current position and $needle, |
|
306 | + * inclusive, or "" if not found. The current index is moved to a point |
|
307 | + * after the location of $needle, or not moved at all |
|
308 | + * if nothing is found. |
|
309 | + */ |
|
310 | + public function skipToStringInTag($needle) |
|
311 | + { |
|
312 | + $pos = strpos($this->iHtmlText, $needle, $this->iHtmlTextIndex); |
|
313 | + if ($pos === false) { |
|
314 | + return ''; |
|
315 | + } |
|
316 | + $top = $pos + strlen($needle); |
|
317 | + $retvalue = substr($this->iHtmlText, $this->iHtmlTextIndex, $top - $this->iHtmlTextIndex); |
|
318 | + $this->setTextIndex($top); |
|
319 | + |
|
320 | + return $retvalue; |
|
321 | + } |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | class HTMLFileParser extends HTMLParser |
325 | 325 | { |
326 | - public function HTMLFileParser($fileName) |
|
327 | - { |
|
328 | - $fp = fopen($fileName, 'r'); |
|
329 | - $content = ''; |
|
330 | - while (true) { |
|
331 | - $data = fread($fp, 8192); |
|
332 | - if (strlen($data) == 0) { |
|
333 | - break; |
|
334 | - } |
|
335 | - $content .= $data; |
|
336 | - } |
|
337 | - fclose($fp); |
|
338 | - $this->HTMLParser($content); |
|
339 | - } |
|
326 | + public function HTMLFileParser($fileName) |
|
327 | + { |
|
328 | + $fp = fopen($fileName, 'r'); |
|
329 | + $content = ''; |
|
330 | + while (true) { |
|
331 | + $data = fread($fp, 8192); |
|
332 | + if (strlen($data) == 0) { |
|
333 | + break; |
|
334 | + } |
|
335 | + $content .= $data; |
|
336 | + } |
|
337 | + fclose($fp); |
|
338 | + $this->HTMLParser($content); |
|
339 | + } |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | class HTMLURLParser extends HTMLParser |
343 | 343 | { |
344 | - public function HTMLURLParser($url) |
|
345 | - { |
|
346 | - $fp = fopen($url, 'r'); |
|
347 | - $content = ''; |
|
348 | - while (true) { |
|
349 | - $data = fread($fp, 8192); |
|
350 | - if (strlen($data) == 0) { |
|
351 | - break; |
|
352 | - } |
|
353 | - $content .= $data; |
|
354 | - } |
|
355 | - fclose($fp); |
|
356 | - $this->HTMLParser(file_get_contents($content)); |
|
357 | - } |
|
344 | + public function HTMLURLParser($url) |
|
345 | + { |
|
346 | + $fp = fopen($url, 'r'); |
|
347 | + $content = ''; |
|
348 | + while (true) { |
|
349 | + $data = fread($fp, 8192); |
|
350 | + if (strlen($data) == 0) { |
|
351 | + break; |
|
352 | + } |
|
353 | + $content .= $data; |
|
354 | + } |
|
355 | + fclose($fp); |
|
356 | + $this->HTMLParser(file_get_contents($content)); |
|
357 | + } |
|
358 | 358 | } |
359 | 359 | |
360 | 360 | class TreeHTML |
361 | 361 | { |
362 | - public $type = []; |
|
363 | - public $name = []; |
|
364 | - public $value = []; |
|
365 | - public $attribute = []; |
|
366 | - public $field = []; |
|
367 | - public $addText = ''; |
|
368 | - |
|
369 | - /** |
|
370 | - * @return array |
|
371 | - * @desc Tao mot tree node cac phan tu cua HTML |
|
372 | - */ |
|
373 | - public function TreeHTML($parser, $file = true) |
|
374 | - { |
|
375 | - $i = 0; |
|
376 | - if ($file) { |
|
377 | - while ($parser->parse()) { |
|
378 | - if (strtolower($parser->iNodeName) == 'body') { |
|
379 | - break; |
|
380 | - } |
|
381 | - } |
|
382 | - } |
|
383 | - while ($parser->parse()) { |
|
384 | - if ($parser->iNodeType == NODE_TYPE_ENDELEMENT && strtolower($parser->iNodeName) == 'body' && $file) { |
|
385 | - break; |
|
386 | - } |
|
387 | - |
|
388 | - $this->type[$i] = $parser->iNodeType; |
|
389 | - $this->name[$i] = $parser->iNodeName; |
|
390 | - if ($parser->iNodeType == NODE_TYPE_TEXT) { |
|
391 | - $this->value[$i] = $parser->iNodeValue; |
|
392 | - } |
|
393 | - if ($parser->iNodeType == NODE_TYPE_ELEMENT) { |
|
394 | - $this->attribute[$i] = $parser->iNodeAttributes; |
|
395 | - if (isset($parser->iNodeAttributes['name'])) { |
|
396 | - $this->field[$i] = trim($parser->iNodeAttributes['name'], "\"' "); |
|
397 | - } |
|
398 | - if (($file && $parser->iNodeName == 'input' && isset($this->attribute[$i]['type']) && $this->attribute[$i]['type'] == 'text' && !isset($this->attribute[$i]['onkeydown'])) |
|
399 | - || ($file && $parser->iNodeName == 'textarea')) { |
|
400 | - $this->attribute[$i]['onkeyup'] = 'initTyper(this)'; |
|
401 | - } |
|
402 | - } |
|
403 | - $i++; |
|
404 | - } |
|
405 | - } |
|
406 | - |
|
407 | - /** |
|
408 | - * @desc Them hoac sua field co ten $name mot thuoc tinh $attr |
|
409 | - */ |
|
410 | - public function set($name, $attr, $value) |
|
411 | - { |
|
412 | - $index = array_search($name, $this->field); |
|
413 | - if (!$index) { |
|
414 | - return; |
|
415 | - } |
|
416 | - $this->attribute[$index][$attr] = $value; |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * @desc Tra ve thuoc tinh $attr cua field $name |
|
421 | - */ |
|
422 | - public function get($name, $attr) |
|
423 | - { |
|
424 | - $index = array_search($name, $this->field); |
|
425 | - if ($index && isset($this->attribute[$index][$attr])) { |
|
426 | - return $this->attribute[$index][$attr]; |
|
427 | - } |
|
428 | - |
|
429 | - return ''; |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * @desc Tra ve ten cua tag HTML ung voi field $name |
|
434 | - */ |
|
435 | - public function getTag($name) |
|
436 | - { |
|
437 | - $index = array_search($name, $this->field); |
|
438 | - //if (!isset($this->name[$index])) {debug($name);debug($index);} |
|
439 | - return $this->name[$index]; |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * @desc Tra ve cac thuoc tinh gom tabindex, size, maxlength |
|
444 | - */ |
|
445 | - public function getAll($name) |
|
446 | - { |
|
447 | - $index = array_search($name, $this->field); |
|
448 | - if ($index) { |
|
449 | - $t = ''; |
|
450 | - if (isset($this->attribute[$index]['tabindex'])) { |
|
451 | - $t .= ' tabindex='.$this->attribute[$index]['tabindex']; |
|
452 | - } |
|
453 | - if (isset($this->attribute[$index]['size'])) { |
|
454 | - $t .= ' size='.$this->attribute[$index]['size']; |
|
455 | - } |
|
456 | - if (isset($this->attribute[$index]['maxlength'])) { |
|
457 | - $t .= ' maxlength='.$this->attribute[$index]['maxlength']; |
|
458 | - } |
|
459 | - |
|
460 | - return $t; |
|
461 | - } |
|
462 | - |
|
463 | - return ''; |
|
464 | - } |
|
465 | - |
|
466 | - /** |
|
467 | - * @desc Thay doi node ten $name thanh text voi noi dung $text |
|
468 | - */ |
|
469 | - public function replace($name, $text) |
|
470 | - { |
|
471 | - $index = array_search($name, $this->field); |
|
472 | - if (!$index) { |
|
473 | - return; |
|
474 | - } |
|
475 | - $this->removeIndex($index); |
|
476 | - $this->type[$index] = NODE_TYPE_TEXT; |
|
477 | - $this->value[$index] = $text; |
|
478 | - } |
|
479 | - |
|
480 | - /** |
|
481 | - * @desc Thay doi node ten $name thanh text voi noi dung $text |
|
482 | - */ |
|
483 | - public function remove($name) |
|
484 | - { |
|
485 | - $index = array_search($name, $this->field); |
|
486 | - if (!$index) { |
|
487 | - return; |
|
488 | - } |
|
489 | - if (!isset($this->name[$index])) { |
|
490 | - return; |
|
491 | - } //echo "Remove: $name <br>"; |
|
492 | - $rname = $this->name[$index]; |
|
493 | - $len = count($this->name); |
|
494 | - for ($end = $index + 1; $end < $len; $end++) { |
|
495 | - if (isset($this->name[$end]) && $this->name[$end] == $rname) { |
|
496 | - break; |
|
497 | - } |
|
498 | - } |
|
499 | - if (isset($this->type[$end]) && $this->type[$end] == NODE_TYPE_ENDELEMENT) { |
|
500 | - for ($i = $index; $i <= $end; $i++) { |
|
501 | - $this->removeIndex($i); |
|
502 | - } |
|
503 | - } else { |
|
504 | - $this->removeIndex($index); |
|
505 | - } |
|
506 | - } |
|
507 | - |
|
508 | - /** |
|
509 | - * @desc Private: Xoa 1 object trong tree |
|
510 | - */ |
|
511 | - public function removeIndex($index) |
|
512 | - { |
|
513 | - $this->type[$index] = -1; |
|
514 | - unset($this->field[$index]); |
|
515 | - unset($this->name[$index]); |
|
516 | - unset($this->value[$index]); |
|
517 | - unset($this->attribute[$index]); |
|
518 | - } |
|
519 | - |
|
520 | - /** |
|
521 | - * @return string |
|
522 | - * @desc Create a string HTML from a tree<br> |
|
523 | - * An Item have format ($iNodeType, $iNodeName, $iNodeValue, $iNodeAttributes) |
|
524 | - */ |
|
525 | - public function toHTML() |
|
526 | - { |
|
527 | - global $HTML_ATTRIBUTE_STAND_ALONE; |
|
528 | - $result = ''; |
|
529 | - $type = &$this->type; |
|
530 | - $name = &$this->name; |
|
531 | - $valu = &$this->value; |
|
532 | - $attr = &$this->attribute; |
|
533 | - |
|
534 | - $len = count($type); |
|
535 | - for ($i = 0; $i < $len; $i++) { |
|
536 | - $str = ''; |
|
537 | - switch ($type[$i]) { |
|
538 | - case NODE_TYPE_ELEMENT: |
|
539 | - if ($name[$i] != 'textarea') { |
|
540 | - $str .= '<'.$name[$i]; |
|
541 | - if (isset($attr[$i])) { |
|
542 | - foreach ($attr[$i] as $key => $value) { |
|
543 | - if (array_search($value, $HTML_ATTRIBUTE_STAND_ALONE) !== false) { |
|
544 | - $str .= " $key"; |
|
545 | - } else { |
|
546 | - $str .= " $key=\"$value\""; |
|
547 | - } |
|
548 | - } |
|
549 | - } |
|
550 | - $str .= '>'; |
|
551 | - } else {//is tag ATEXTAREA |
|
552 | - $content = ''; |
|
553 | - $str .= '<'.$name[$i]; |
|
554 | - if (isset($attr[$i])) { |
|
555 | - foreach ($attr[$i] as $key => $value) { |
|
556 | - if ($key == 'value') { |
|
557 | - $content = $value; |
|
558 | - } elseif (array_search($value, $HTML_ATTRIBUTE_STAND_ALONE) !== false) { |
|
559 | - $str .= " $key"; |
|
560 | - } else { |
|
561 | - $str .= " $key=\"$value\""; |
|
562 | - } |
|
563 | - } |
|
564 | - } |
|
565 | - $str .= '>'.$content; |
|
566 | - } |
|
567 | - break; |
|
568 | - case NODE_TYPE_ENDELEMENT: |
|
569 | - $str .= '</'.$name[$i].'>'; |
|
570 | - break; |
|
571 | - case NODE_TYPE_TEXT: |
|
572 | - $str = $valu[$i]; |
|
573 | - break; |
|
574 | - } |
|
575 | - $result .= $str; |
|
576 | - //if (isset($nobu[$i])) $result .= $nobu[$i]; |
|
577 | - } |
|
578 | - |
|
579 | - return $result.$this->addText; |
|
580 | - } |
|
581 | - |
|
582 | - /** |
|
583 | - * @desc Set all input text to readonly |
|
584 | - */ |
|
585 | - public function setReadonlyAll() |
|
586 | - { |
|
587 | - foreach ($this->name as $i => $name) { |
|
588 | - if ($name == 'input' && isset($this->attribute[$i]['type'])) { |
|
589 | - switch ($this->attribute[$i]['type']) { |
|
590 | - case 'text': |
|
591 | - $this->attribute[$i]['readonly'] = 'true'; |
|
592 | - $this->attribute[$i]['style'] = 'border: 1 dotted #999999'; |
|
593 | - break; |
|
594 | - case 'select': |
|
595 | - case 'checkbox': |
|
596 | - $this->attribute[$i]['disabled'] = 1; |
|
597 | - break; |
|
598 | - } |
|
599 | - } elseif ($name == 'textarea') { |
|
600 | - $this->attribute[$i]['readonly'] = 'true'; |
|
601 | - $this->attribute[$i]['style'] = 'border: 1 dotted #999999'; |
|
602 | - } |
|
603 | - } |
|
604 | - } |
|
605 | - |
|
606 | - /** |
|
607 | - * @desc Set an input text to readonly |
|
608 | - */ |
|
609 | - public function setReadonly($name) |
|
610 | - { |
|
611 | - $index = array_search($name, $this->field); |
|
612 | - if (!$index) { |
|
613 | - return; |
|
614 | - } |
|
615 | - $this->attribute[$index]['readonly'] = true; |
|
616 | - $this->attribute[$index]['style'] = 'border: 1 dotted #999999'; |
|
617 | - } |
|
362 | + public $type = []; |
|
363 | + public $name = []; |
|
364 | + public $value = []; |
|
365 | + public $attribute = []; |
|
366 | + public $field = []; |
|
367 | + public $addText = ''; |
|
368 | + |
|
369 | + /** |
|
370 | + * @return array |
|
371 | + * @desc Tao mot tree node cac phan tu cua HTML |
|
372 | + */ |
|
373 | + public function TreeHTML($parser, $file = true) |
|
374 | + { |
|
375 | + $i = 0; |
|
376 | + if ($file) { |
|
377 | + while ($parser->parse()) { |
|
378 | + if (strtolower($parser->iNodeName) == 'body') { |
|
379 | + break; |
|
380 | + } |
|
381 | + } |
|
382 | + } |
|
383 | + while ($parser->parse()) { |
|
384 | + if ($parser->iNodeType == NODE_TYPE_ENDELEMENT && strtolower($parser->iNodeName) == 'body' && $file) { |
|
385 | + break; |
|
386 | + } |
|
387 | + |
|
388 | + $this->type[$i] = $parser->iNodeType; |
|
389 | + $this->name[$i] = $parser->iNodeName; |
|
390 | + if ($parser->iNodeType == NODE_TYPE_TEXT) { |
|
391 | + $this->value[$i] = $parser->iNodeValue; |
|
392 | + } |
|
393 | + if ($parser->iNodeType == NODE_TYPE_ELEMENT) { |
|
394 | + $this->attribute[$i] = $parser->iNodeAttributes; |
|
395 | + if (isset($parser->iNodeAttributes['name'])) { |
|
396 | + $this->field[$i] = trim($parser->iNodeAttributes['name'], "\"' "); |
|
397 | + } |
|
398 | + if (($file && $parser->iNodeName == 'input' && isset($this->attribute[$i]['type']) && $this->attribute[$i]['type'] == 'text' && !isset($this->attribute[$i]['onkeydown'])) |
|
399 | + || ($file && $parser->iNodeName == 'textarea')) { |
|
400 | + $this->attribute[$i]['onkeyup'] = 'initTyper(this)'; |
|
401 | + } |
|
402 | + } |
|
403 | + $i++; |
|
404 | + } |
|
405 | + } |
|
406 | + |
|
407 | + /** |
|
408 | + * @desc Them hoac sua field co ten $name mot thuoc tinh $attr |
|
409 | + */ |
|
410 | + public function set($name, $attr, $value) |
|
411 | + { |
|
412 | + $index = array_search($name, $this->field); |
|
413 | + if (!$index) { |
|
414 | + return; |
|
415 | + } |
|
416 | + $this->attribute[$index][$attr] = $value; |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * @desc Tra ve thuoc tinh $attr cua field $name |
|
421 | + */ |
|
422 | + public function get($name, $attr) |
|
423 | + { |
|
424 | + $index = array_search($name, $this->field); |
|
425 | + if ($index && isset($this->attribute[$index][$attr])) { |
|
426 | + return $this->attribute[$index][$attr]; |
|
427 | + } |
|
428 | + |
|
429 | + return ''; |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * @desc Tra ve ten cua tag HTML ung voi field $name |
|
434 | + */ |
|
435 | + public function getTag($name) |
|
436 | + { |
|
437 | + $index = array_search($name, $this->field); |
|
438 | + //if (!isset($this->name[$index])) {debug($name);debug($index);} |
|
439 | + return $this->name[$index]; |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * @desc Tra ve cac thuoc tinh gom tabindex, size, maxlength |
|
444 | + */ |
|
445 | + public function getAll($name) |
|
446 | + { |
|
447 | + $index = array_search($name, $this->field); |
|
448 | + if ($index) { |
|
449 | + $t = ''; |
|
450 | + if (isset($this->attribute[$index]['tabindex'])) { |
|
451 | + $t .= ' tabindex='.$this->attribute[$index]['tabindex']; |
|
452 | + } |
|
453 | + if (isset($this->attribute[$index]['size'])) { |
|
454 | + $t .= ' size='.$this->attribute[$index]['size']; |
|
455 | + } |
|
456 | + if (isset($this->attribute[$index]['maxlength'])) { |
|
457 | + $t .= ' maxlength='.$this->attribute[$index]['maxlength']; |
|
458 | + } |
|
459 | + |
|
460 | + return $t; |
|
461 | + } |
|
462 | + |
|
463 | + return ''; |
|
464 | + } |
|
465 | + |
|
466 | + /** |
|
467 | + * @desc Thay doi node ten $name thanh text voi noi dung $text |
|
468 | + */ |
|
469 | + public function replace($name, $text) |
|
470 | + { |
|
471 | + $index = array_search($name, $this->field); |
|
472 | + if (!$index) { |
|
473 | + return; |
|
474 | + } |
|
475 | + $this->removeIndex($index); |
|
476 | + $this->type[$index] = NODE_TYPE_TEXT; |
|
477 | + $this->value[$index] = $text; |
|
478 | + } |
|
479 | + |
|
480 | + /** |
|
481 | + * @desc Thay doi node ten $name thanh text voi noi dung $text |
|
482 | + */ |
|
483 | + public function remove($name) |
|
484 | + { |
|
485 | + $index = array_search($name, $this->field); |
|
486 | + if (!$index) { |
|
487 | + return; |
|
488 | + } |
|
489 | + if (!isset($this->name[$index])) { |
|
490 | + return; |
|
491 | + } //echo "Remove: $name <br>"; |
|
492 | + $rname = $this->name[$index]; |
|
493 | + $len = count($this->name); |
|
494 | + for ($end = $index + 1; $end < $len; $end++) { |
|
495 | + if (isset($this->name[$end]) && $this->name[$end] == $rname) { |
|
496 | + break; |
|
497 | + } |
|
498 | + } |
|
499 | + if (isset($this->type[$end]) && $this->type[$end] == NODE_TYPE_ENDELEMENT) { |
|
500 | + for ($i = $index; $i <= $end; $i++) { |
|
501 | + $this->removeIndex($i); |
|
502 | + } |
|
503 | + } else { |
|
504 | + $this->removeIndex($index); |
|
505 | + } |
|
506 | + } |
|
507 | + |
|
508 | + /** |
|
509 | + * @desc Private: Xoa 1 object trong tree |
|
510 | + */ |
|
511 | + public function removeIndex($index) |
|
512 | + { |
|
513 | + $this->type[$index] = -1; |
|
514 | + unset($this->field[$index]); |
|
515 | + unset($this->name[$index]); |
|
516 | + unset($this->value[$index]); |
|
517 | + unset($this->attribute[$index]); |
|
518 | + } |
|
519 | + |
|
520 | + /** |
|
521 | + * @return string |
|
522 | + * @desc Create a string HTML from a tree<br> |
|
523 | + * An Item have format ($iNodeType, $iNodeName, $iNodeValue, $iNodeAttributes) |
|
524 | + */ |
|
525 | + public function toHTML() |
|
526 | + { |
|
527 | + global $HTML_ATTRIBUTE_STAND_ALONE; |
|
528 | + $result = ''; |
|
529 | + $type = &$this->type; |
|
530 | + $name = &$this->name; |
|
531 | + $valu = &$this->value; |
|
532 | + $attr = &$this->attribute; |
|
533 | + |
|
534 | + $len = count($type); |
|
535 | + for ($i = 0; $i < $len; $i++) { |
|
536 | + $str = ''; |
|
537 | + switch ($type[$i]) { |
|
538 | + case NODE_TYPE_ELEMENT: |
|
539 | + if ($name[$i] != 'textarea') { |
|
540 | + $str .= '<'.$name[$i]; |
|
541 | + if (isset($attr[$i])) { |
|
542 | + foreach ($attr[$i] as $key => $value) { |
|
543 | + if (array_search($value, $HTML_ATTRIBUTE_STAND_ALONE) !== false) { |
|
544 | + $str .= " $key"; |
|
545 | + } else { |
|
546 | + $str .= " $key=\"$value\""; |
|
547 | + } |
|
548 | + } |
|
549 | + } |
|
550 | + $str .= '>'; |
|
551 | + } else {//is tag ATEXTAREA |
|
552 | + $content = ''; |
|
553 | + $str .= '<'.$name[$i]; |
|
554 | + if (isset($attr[$i])) { |
|
555 | + foreach ($attr[$i] as $key => $value) { |
|
556 | + if ($key == 'value') { |
|
557 | + $content = $value; |
|
558 | + } elseif (array_search($value, $HTML_ATTRIBUTE_STAND_ALONE) !== false) { |
|
559 | + $str .= " $key"; |
|
560 | + } else { |
|
561 | + $str .= " $key=\"$value\""; |
|
562 | + } |
|
563 | + } |
|
564 | + } |
|
565 | + $str .= '>'.$content; |
|
566 | + } |
|
567 | + break; |
|
568 | + case NODE_TYPE_ENDELEMENT: |
|
569 | + $str .= '</'.$name[$i].'>'; |
|
570 | + break; |
|
571 | + case NODE_TYPE_TEXT: |
|
572 | + $str = $valu[$i]; |
|
573 | + break; |
|
574 | + } |
|
575 | + $result .= $str; |
|
576 | + //if (isset($nobu[$i])) $result .= $nobu[$i]; |
|
577 | + } |
|
578 | + |
|
579 | + return $result.$this->addText; |
|
580 | + } |
|
581 | + |
|
582 | + /** |
|
583 | + * @desc Set all input text to readonly |
|
584 | + */ |
|
585 | + public function setReadonlyAll() |
|
586 | + { |
|
587 | + foreach ($this->name as $i => $name) { |
|
588 | + if ($name == 'input' && isset($this->attribute[$i]['type'])) { |
|
589 | + switch ($this->attribute[$i]['type']) { |
|
590 | + case 'text': |
|
591 | + $this->attribute[$i]['readonly'] = 'true'; |
|
592 | + $this->attribute[$i]['style'] = 'border: 1 dotted #999999'; |
|
593 | + break; |
|
594 | + case 'select': |
|
595 | + case 'checkbox': |
|
596 | + $this->attribute[$i]['disabled'] = 1; |
|
597 | + break; |
|
598 | + } |
|
599 | + } elseif ($name == 'textarea') { |
|
600 | + $this->attribute[$i]['readonly'] = 'true'; |
|
601 | + $this->attribute[$i]['style'] = 'border: 1 dotted #999999'; |
|
602 | + } |
|
603 | + } |
|
604 | + } |
|
605 | + |
|
606 | + /** |
|
607 | + * @desc Set an input text to readonly |
|
608 | + */ |
|
609 | + public function setReadonly($name) |
|
610 | + { |
|
611 | + $index = array_search($name, $this->field); |
|
612 | + if (!$index) { |
|
613 | + return; |
|
614 | + } |
|
615 | + $this->attribute[$index]['readonly'] = true; |
|
616 | + $this->attribute[$index]['style'] = 'border: 1 dotted #999999'; |
|
617 | + } |
|
618 | 618 | } |
@@ -587,14 +587,14 @@ |
||
587 | 587 | foreach ($this->name as $i => $name) { |
588 | 588 | if ($name == 'input' && isset($this->attribute[$i]['type'])) { |
589 | 589 | switch ($this->attribute[$i]['type']) { |
590 | - case 'text': |
|
591 | - $this->attribute[$i]['readonly'] = 'true'; |
|
592 | - $this->attribute[$i]['style'] = 'border: 1 dotted #999999'; |
|
593 | - break; |
|
594 | - case 'select': |
|
595 | - case 'checkbox': |
|
596 | - $this->attribute[$i]['disabled'] = 1; |
|
597 | - break; |
|
590 | + case 'text': |
|
591 | + $this->attribute[$i]['readonly'] = 'true'; |
|
592 | + $this->attribute[$i]['style'] = 'border: 1 dotted #999999'; |
|
593 | + break; |
|
594 | + case 'select': |
|
595 | + case 'checkbox': |
|
596 | + $this->attribute[$i]['disabled'] = 1; |
|
597 | + break; |
|
598 | 598 | } |
599 | 599 | } elseif ($name == 'textarea') { |
600 | 600 | $this->attribute[$i]['readonly'] = 'true'; |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | $this->iNodeType = NODE_TYPE_ENDELEMENT; |
121 | 121 | $this->iNodeName = substr($name, 1); |
122 | 122 | $this->iNodeValue = ''; |
123 | - } else { |
|
123 | + }else { |
|
124 | 124 | if (!$this->isValidTagIdentifier($name)) { |
125 | 125 | $comment = false; |
126 | 126 | if ($name == '!--') { |
@@ -139,13 +139,13 @@ discard block |
||
139 | 139 | } |
140 | 140 | |
141 | 141 | return true; |
142 | - } else { |
|
142 | + }else { |
|
143 | 143 | $this->iNodeType = NODE_TYPE_ELEMENT; |
144 | 144 | $this->iNodeValue = ''; |
145 | 145 | $nameLength = strlen($name); |
146 | 146 | if ($nameLength > 0 && substr($name, $nameLength - 1, 1) == '/') { |
147 | 147 | $this->iNodeName = substr($name, 0, $nameLength - 1); |
148 | - } else { |
|
148 | + }else { |
|
149 | 149 | $this->iNodeName = $name; |
150 | 150 | } |
151 | 151 | $this->iNodeName = strtolower($this->iNodeName); |
@@ -157,14 +157,14 @@ discard block |
||
157 | 157 | $attrName = strtolower($attrName); |
158 | 158 | if (array_search($attrName, $HTML_ATTRIBUTE_STAND_ALONE) !== false) { |
159 | 159 | $this->iNodeAttributes[$attrName] = 1; |
160 | - } else { |
|
160 | + }else { |
|
161 | 161 | $this->skipBlanksInTag(); |
162 | 162 | if ($this->iCurrentChar == '=') { |
163 | 163 | $this->skipEqualsInTag(); |
164 | 164 | $this->skipBlanksInTag(); |
165 | 165 | $value = $this->readValueInTag(); |
166 | 166 | $this->iNodeAttributes[$attrName] = $value; |
167 | - } else { |
|
167 | + }else { |
|
168 | 168 | $this->iNodeAttributes[$attrName] = ''; |
169 | 169 | } |
170 | 170 | } |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | $this->skipInTag(["'"]); |
213 | 213 | $value = $this->skipToInTag(["'"]); |
214 | 214 | $this->skipInTag(["'"]); |
215 | - } else { |
|
215 | + }else { |
|
216 | 216 | $value = $this->skipToBlanksInTag(); |
217 | 217 | } |
218 | 218 | |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | $this->iHtmlTextIndex = $index; |
225 | 225 | if ($index >= $this->iHtmlTextLength) { |
226 | 226 | $this->iCurrentChar = -1; |
227 | - } else { |
|
227 | + }else { |
|
228 | 228 | $this->iCurrentChar = $this->iHtmlText[$index]; |
229 | 229 | } |
230 | 230 | } |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | $this->setTextIndex($this->iHtmlTextIndex + 1); |
236 | 236 | |
237 | 237 | return true; |
238 | - } else { |
|
238 | + }else { |
|
239 | 239 | return false; |
240 | 240 | } |
241 | 241 | } |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | while (($ch = $this->iCurrentChar) !== -1) { |
262 | 262 | if ($ch == '>') { |
263 | 263 | return $sb; |
264 | - } else { |
|
264 | + }else { |
|
265 | 265 | if (array_search($ch, $chars) === false) { |
266 | 266 | return $sb; |
267 | 267 | } |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | for ($i = $index; $i <= $end; $i++) { |
501 | 501 | $this->removeIndex($i); |
502 | 502 | } |
503 | - } else { |
|
503 | + }else { |
|
504 | 504 | $this->removeIndex($index); |
505 | 505 | } |
506 | 506 | } |
@@ -542,13 +542,13 @@ discard block |
||
542 | 542 | foreach ($attr[$i] as $key => $value) { |
543 | 543 | if (array_search($value, $HTML_ATTRIBUTE_STAND_ALONE) !== false) { |
544 | 544 | $str .= " $key"; |
545 | - } else { |
|
545 | + }else { |
|
546 | 546 | $str .= " $key=\"$value\""; |
547 | 547 | } |
548 | 548 | } |
549 | 549 | } |
550 | 550 | $str .= '>'; |
551 | - } else {//is tag ATEXTAREA |
|
551 | + }else {//is tag ATEXTAREA |
|
552 | 552 | $content = ''; |
553 | 553 | $str .= '<'.$name[$i]; |
554 | 554 | if (isset($attr[$i])) { |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | $content = $value; |
558 | 558 | } elseif (array_search($value, $HTML_ATTRIBUTE_STAND_ALONE) !== false) { |
559 | 559 | $str .= " $key"; |
560 | - } else { |
|
560 | + }else { |
|
561 | 561 | $str .= " $key=\"$value\""; |
562 | 562 | } |
563 | 563 | } |
@@ -16,1131 +16,1131 @@ |
||
16 | 16 | $PDF_VALIGN = ['top'=>'T', 'middle'=>'M', 'bottom'=>'B']; |
17 | 17 | class PDFTable extends FPDF |
18 | 18 | { |
19 | - public $left; //Toa do le trai cua trang |
|
19 | + public $left; //Toa do le trai cua trang |
|
20 | 20 | public $right; //Toa do le phai cua trang |
21 | 21 | public $top; //Toa do le tren cua trang |
22 | 22 | public $bottom; //Toa do le duoi cua trang |
23 | 23 | public $width; //Width of writable zone of page |
24 | 24 | public $height; //Height of writable zone of page |
25 | 25 | public $defaultFontFamily; |
26 | - public $defaultFontStyle; |
|
27 | - public $defaultFontSize; |
|
28 | - public $isNotYetSetFont; |
|
29 | - public $headerTable; |
|
30 | - public $footerTable; |
|
31 | - public $paddingCell = 1; //(mm) |
|
26 | + public $defaultFontStyle; |
|
27 | + public $defaultFontSize; |
|
28 | + public $isNotYetSetFont; |
|
29 | + public $headerTable; |
|
30 | + public $footerTable; |
|
31 | + public $paddingCell = 1; //(mm) |
|
32 | 32 | public $paddingCell2 = 2; //2*$paddingCell |
33 | 33 | public $spacingLine = 0; //(mm) |
34 | 34 | public $spacingParagraph = 0; //(mm) |
35 | 35 | |
36 | 36 | public function PDFTable($orientation = 'P', $unit = 'mm', $format = 'A4') |
37 | 37 | { |
38 | - parent::FPDF($orientation, $unit, $format); |
|
39 | - $this->SetMargins(20, 20, 20); |
|
40 | - $this->SetAuthor('Pham Minh Dung'); |
|
41 | - $this->_makePageSize(); |
|
42 | - $this->isNotYetSetFont = true; |
|
43 | - $this->headerTable = $this->footerTable = ''; |
|
38 | + parent::FPDF($orientation, $unit, $format); |
|
39 | + $this->SetMargins(20, 20, 20); |
|
40 | + $this->SetAuthor('Pham Minh Dung'); |
|
41 | + $this->_makePageSize(); |
|
42 | + $this->isNotYetSetFont = true; |
|
43 | + $this->headerTable = $this->footerTable = ''; |
|
44 | 44 | } |
45 | 45 | |
46 | - public function SetPadding($s = 1) |
|
47 | - { |
|
48 | - $this->paddingCell = $s; |
|
49 | - $this->paddingCell2 = 2 * $s; |
|
50 | - } |
|
46 | + public function SetPadding($s = 1) |
|
47 | + { |
|
48 | + $this->paddingCell = $s; |
|
49 | + $this->paddingCell2 = 2 * $s; |
|
50 | + } |
|
51 | 51 | |
52 | - public function SetSpacing($linespacing = 1, $paragraphspacing = 2) |
|
53 | - { |
|
54 | - $this->spacingLine = $linespacing; |
|
55 | - $this->spacingParagraph = $paragraphspacing; |
|
56 | - } |
|
52 | + public function SetSpacing($linespacing = 1, $paragraphspacing = 2) |
|
53 | + { |
|
54 | + $this->spacingLine = $linespacing; |
|
55 | + $this->spacingParagraph = $paragraphspacing; |
|
56 | + } |
|
57 | 57 | |
58 | - public function SetMargins($left, $top, $right = null, $bottom = null) |
|
59 | - { |
|
60 | - parent::SetMargins($left, $top, $right); |
|
61 | - $this->bMargin = $bottom ? $bottom : $top; |
|
62 | - $this->_makePageSize(); |
|
63 | - } |
|
58 | + public function SetMargins($left, $top, $right = null, $bottom = null) |
|
59 | + { |
|
60 | + parent::SetMargins($left, $top, $right); |
|
61 | + $this->bMargin = $bottom ? $bottom : $top; |
|
62 | + $this->_makePageSize(); |
|
63 | + } |
|
64 | 64 | |
65 | - public function SetLeftMargin($margin) |
|
66 | - { |
|
67 | - parent::SetLeftMargin($margin); |
|
68 | - $this->_makePageSize(); |
|
69 | - } |
|
65 | + public function SetLeftMargin($margin) |
|
66 | + { |
|
67 | + parent::SetLeftMargin($margin); |
|
68 | + $this->_makePageSize(); |
|
69 | + } |
|
70 | 70 | |
71 | - public function SetRightMargin($margin) |
|
72 | - { |
|
73 | - parent::SetRightMargin($margin); |
|
74 | - $this->_makePageSize(); |
|
75 | - } |
|
71 | + public function SetRightMargin($margin) |
|
72 | + { |
|
73 | + parent::SetRightMargin($margin); |
|
74 | + $this->_makePageSize(); |
|
75 | + } |
|
76 | 76 | |
77 | - public function SetHeaderFooter($header = '', $footer = '') |
|
78 | - { |
|
79 | - if ($header) { |
|
80 | - $this->headerTable = $header; |
|
81 | - } |
|
82 | - if ($footer) { |
|
83 | - $this->footerTable = $footer; |
|
84 | - } |
|
85 | - } |
|
77 | + public function SetHeaderFooter($header = '', $footer = '') |
|
78 | + { |
|
79 | + if ($header) { |
|
80 | + $this->headerTable = $header; |
|
81 | + } |
|
82 | + if ($footer) { |
|
83 | + $this->footerTable = $footer; |
|
84 | + } |
|
85 | + } |
|
86 | 86 | |
87 | - public function Header() |
|
88 | - { |
|
89 | - $this->_makePageSize(); |
|
90 | - if ($this->headerTable) { |
|
91 | - $this->x = $this->left; |
|
92 | - $this->y = 0; |
|
93 | - $this->htmltable($this->headerTable, 0); |
|
94 | - } |
|
95 | - } |
|
87 | + public function Header() |
|
88 | + { |
|
89 | + $this->_makePageSize(); |
|
90 | + if ($this->headerTable) { |
|
91 | + $this->x = $this->left; |
|
92 | + $this->y = 0; |
|
93 | + $this->htmltable($this->headerTable, 0); |
|
94 | + } |
|
95 | + } |
|
96 | 96 | |
97 | - public function Footer() |
|
98 | - { |
|
99 | - if ($this->footerTable) { |
|
100 | - $this->x = $this->left; |
|
101 | - $this->y = $this->bottom; |
|
102 | - $this->htmltable($this->footerTable, 0); |
|
103 | - } |
|
104 | - } |
|
97 | + public function Footer() |
|
98 | + { |
|
99 | + if ($this->footerTable) { |
|
100 | + $this->x = $this->left; |
|
101 | + $this->y = $this->bottom; |
|
102 | + $this->htmltable($this->footerTable, 0); |
|
103 | + } |
|
104 | + } |
|
105 | 105 | |
106 | - private function _makePageSize() |
|
107 | - { |
|
108 | - $this->left = $this->lMargin; |
|
109 | - $this->right = $this->w - $this->rMargin; |
|
110 | - $this->top = $this->tMargin; |
|
111 | - $this->bottom = $this->h - $this->bMargin; |
|
112 | - $this->width = $this->right - $this->left; |
|
113 | - $this->height = $this->bottom - $this->tMargin; |
|
114 | - } |
|
106 | + private function _makePageSize() |
|
107 | + { |
|
108 | + $this->left = $this->lMargin; |
|
109 | + $this->right = $this->w - $this->rMargin; |
|
110 | + $this->top = $this->tMargin; |
|
111 | + $this->bottom = $this->h - $this->bMargin; |
|
112 | + $this->width = $this->right - $this->left; |
|
113 | + $this->height = $this->bottom - $this->tMargin; |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * @return int |
|
118 | - * Tra ve chieu cao cua 1 dong theo font hien hanh |
|
119 | - */ |
|
120 | - public function getLineHeight($fontSize = 0) |
|
121 | - { |
|
122 | - if ($fontSize == 0) { |
|
123 | - $fontSize = $this->FontSizePt; |
|
124 | - } |
|
116 | + /** |
|
117 | + * @return int |
|
118 | + * Tra ve chieu cao cua 1 dong theo font hien hanh |
|
119 | + */ |
|
120 | + public function getLineHeight($fontSize = 0) |
|
121 | + { |
|
122 | + if ($fontSize == 0) { |
|
123 | + $fontSize = $this->FontSizePt; |
|
124 | + } |
|
125 | 125 | |
126 | - return $fontSize * 2 / $this->k; |
|
127 | - } |
|
126 | + return $fontSize * 2 / $this->k; |
|
127 | + } |
|
128 | 128 | |
129 | - private function _cellHeight(&$c) |
|
130 | - { |
|
131 | - $maxw = $c['w0'] - $this->paddingCell; |
|
132 | - $h = 0; |
|
133 | - $x = $this->paddingCell; |
|
134 | - $countline = 0; |
|
135 | - $maxline = 0; |
|
136 | - $c['hline'] = []; |
|
137 | - $c['wlinet'] = [[0, 0]]; |
|
138 | - $c['wlines'] = [0]; |
|
139 | - $space = 0; |
|
140 | - foreach ($c['font'] as &$f) { |
|
141 | - $this->_setFontText($f); |
|
142 | - $hl = $this->getLineHeight(); |
|
143 | - if ($maxline < $hl || $x == $this->paddingCell) { |
|
144 | - $maxline = $hl; |
|
145 | - } |
|
146 | - if (!isset($f['space'])) { |
|
147 | - continue; |
|
148 | - } |
|
149 | - $space = $f['space']; |
|
150 | - foreach ($f['line'] as $i=>&$l) { |
|
151 | - if ($x != $this->paddingCell) { |
|
152 | - $x += $space; |
|
153 | - } |
|
154 | - if (isset($l['str']) && is_array($l['str'])) { |
|
155 | - foreach ($l['str'] as &$t) { |
|
156 | - if (!is_array($t)) { |
|
157 | - continue; |
|
158 | - } |
|
159 | - if ($x == $this->paddingCell || $x + $t[1] <= $maxw) { |
|
160 | - $c['wlinet'][$countline][0] += $t[1]; |
|
161 | - $c['wlinet'][$countline][1]++; |
|
162 | - $x += $t[1] + (($x > $this->paddingCell) ? $space : 0); |
|
163 | - } else {//auto break line |
|
164 | - $h += $maxline * FHR + $this->spacingLine; |
|
165 | - $c['hline'][] = $maxline * FHR + $this->spacingLine; |
|
166 | - $c['wlines'][$countline] = $x - $this->paddingCell; |
|
167 | - $c['autobr'][$countline] = 1; |
|
168 | - $maxline = $hl; |
|
169 | - $countline++; |
|
170 | - $x = $t[1] + $space; |
|
171 | - $c['wlinet'][$countline] = [$t[1], 1]; |
|
172 | - } |
|
173 | - $t[2] = $countline; |
|
174 | - } |
|
175 | - } |
|
176 | - if ($l == 'br') { |
|
177 | - $h += $maxline * FHR + max($this->spacingLine, $this->spacingParagraph); |
|
178 | - $c['hline'][] = $maxline * FHR + $this->spacingLine; |
|
179 | - $c['wlines'][$countline] = $x - $this->paddingCell; |
|
180 | - $maxline = $hl; |
|
181 | - $countline++; |
|
182 | - $x = $this->paddingCell; |
|
183 | - $c['wlinet'][$countline] = [0, 0]; |
|
184 | - } |
|
185 | - } |
|
186 | - } |
|
187 | - $c['wlines'][$countline] = $x - $space - $this->paddingCell; |
|
188 | - if ($maxline) { |
|
189 | - $h += $maxline; |
|
190 | - $c['hline'][] = $maxline * FHR; |
|
191 | - } |
|
192 | - $c['maxh'] = $h; |
|
129 | + private function _cellHeight(&$c) |
|
130 | + { |
|
131 | + $maxw = $c['w0'] - $this->paddingCell; |
|
132 | + $h = 0; |
|
133 | + $x = $this->paddingCell; |
|
134 | + $countline = 0; |
|
135 | + $maxline = 0; |
|
136 | + $c['hline'] = []; |
|
137 | + $c['wlinet'] = [[0, 0]]; |
|
138 | + $c['wlines'] = [0]; |
|
139 | + $space = 0; |
|
140 | + foreach ($c['font'] as &$f) { |
|
141 | + $this->_setFontText($f); |
|
142 | + $hl = $this->getLineHeight(); |
|
143 | + if ($maxline < $hl || $x == $this->paddingCell) { |
|
144 | + $maxline = $hl; |
|
145 | + } |
|
146 | + if (!isset($f['space'])) { |
|
147 | + continue; |
|
148 | + } |
|
149 | + $space = $f['space']; |
|
150 | + foreach ($f['line'] as $i=>&$l) { |
|
151 | + if ($x != $this->paddingCell) { |
|
152 | + $x += $space; |
|
153 | + } |
|
154 | + if (isset($l['str']) && is_array($l['str'])) { |
|
155 | + foreach ($l['str'] as &$t) { |
|
156 | + if (!is_array($t)) { |
|
157 | + continue; |
|
158 | + } |
|
159 | + if ($x == $this->paddingCell || $x + $t[1] <= $maxw) { |
|
160 | + $c['wlinet'][$countline][0] += $t[1]; |
|
161 | + $c['wlinet'][$countline][1]++; |
|
162 | + $x += $t[1] + (($x > $this->paddingCell) ? $space : 0); |
|
163 | + } else {//auto break line |
|
164 | + $h += $maxline * FHR + $this->spacingLine; |
|
165 | + $c['hline'][] = $maxline * FHR + $this->spacingLine; |
|
166 | + $c['wlines'][$countline] = $x - $this->paddingCell; |
|
167 | + $c['autobr'][$countline] = 1; |
|
168 | + $maxline = $hl; |
|
169 | + $countline++; |
|
170 | + $x = $t[1] + $space; |
|
171 | + $c['wlinet'][$countline] = [$t[1], 1]; |
|
172 | + } |
|
173 | + $t[2] = $countline; |
|
174 | + } |
|
175 | + } |
|
176 | + if ($l == 'br') { |
|
177 | + $h += $maxline * FHR + max($this->spacingLine, $this->spacingParagraph); |
|
178 | + $c['hline'][] = $maxline * FHR + $this->spacingLine; |
|
179 | + $c['wlines'][$countline] = $x - $this->paddingCell; |
|
180 | + $maxline = $hl; |
|
181 | + $countline++; |
|
182 | + $x = $this->paddingCell; |
|
183 | + $c['wlinet'][$countline] = [0, 0]; |
|
184 | + } |
|
185 | + } |
|
186 | + } |
|
187 | + $c['wlines'][$countline] = $x - $space - $this->paddingCell; |
|
188 | + if ($maxline) { |
|
189 | + $h += $maxline; |
|
190 | + $c['hline'][] = $maxline * FHR; |
|
191 | + } |
|
192 | + $c['maxh'] = $h; |
|
193 | 193 | |
194 | - return $h; |
|
195 | - } |
|
194 | + return $h; |
|
195 | + } |
|
196 | 196 | |
197 | - private function _drawCellAligned($x0, $y0, &$c) |
|
198 | - { |
|
199 | - $maxh = $c['h0']; |
|
200 | - $maxw = $c['w0'] - $this->paddingCell2; |
|
201 | - $curh = $c['maxh']; |
|
202 | - $x = $y = 0; //Top by default |
|
203 | - if ($c['va'] == 'M') { |
|
204 | - $y = ($maxh - $curh) / 2; |
|
205 | - } //Middle |
|
206 | - elseif ($c['va'] == 'B') { |
|
207 | - $y = $maxh - $curh; |
|
208 | - } //Bottom |
|
209 | - $curline = 0; |
|
210 | - $morespace = 0; |
|
211 | - $cl = $c['hline'][$curline]; |
|
212 | - $this->_cellHorzAlignLine($c, $curline, $maxw, $x, $morespace); |
|
213 | - foreach ($c['font'] as &$f) { |
|
214 | - $this->_setFontText($f); |
|
215 | - if (isset($f['color'])) { |
|
216 | - $color = Color::HEX2RGB($f['color']); |
|
217 | - $this->SetTextColor($color[0], $color[1], $color[2]); |
|
218 | - } else { |
|
219 | - unset($color); |
|
220 | - } |
|
221 | - $hl = $this->getLineHeight(); |
|
222 | - if (!isset($f['space'])) { |
|
223 | - continue; |
|
224 | - } |
|
225 | - $space = $f['space']; |
|
226 | - foreach ($f['line'] as $i=>&$l) { |
|
227 | - if (isset($l['str']) && is_array($l['str'])) { |
|
228 | - foreach ($l['str'] as &$t) { |
|
229 | - if ($t[2] != $curline) { |
|
230 | - $y += $cl; |
|
231 | - $curline++; |
|
232 | - $cl = $c['hline'][$curline]; |
|
233 | - $this->_cellHorzAlignLine($c, $curline, $maxw, $x, $morespace); |
|
234 | - } |
|
235 | - $this->x = $x + $x0; |
|
236 | - $this->y = $y + $y0 + $cl; |
|
237 | - $this->Cell($t[1], 0, $t[0]); |
|
238 | - $x += $t[1] + $space + $morespace; |
|
239 | - } |
|
240 | - } |
|
241 | - if ($l == 'br') { |
|
242 | - $y += $cl; |
|
243 | - $curline++; |
|
244 | - $cl = $c['hline'][$curline]; |
|
245 | - $this->_cellHorzAlignLine($c, $curline, $maxw, $x, $morespace); |
|
246 | - } |
|
247 | - } |
|
248 | - if (isset($color)) { |
|
249 | - $this->SetTextColor(0); |
|
250 | - } |
|
251 | - } |
|
252 | - } |
|
197 | + private function _drawCellAligned($x0, $y0, &$c) |
|
198 | + { |
|
199 | + $maxh = $c['h0']; |
|
200 | + $maxw = $c['w0'] - $this->paddingCell2; |
|
201 | + $curh = $c['maxh']; |
|
202 | + $x = $y = 0; //Top by default |
|
203 | + if ($c['va'] == 'M') { |
|
204 | + $y = ($maxh - $curh) / 2; |
|
205 | + } //Middle |
|
206 | + elseif ($c['va'] == 'B') { |
|
207 | + $y = $maxh - $curh; |
|
208 | + } //Bottom |
|
209 | + $curline = 0; |
|
210 | + $morespace = 0; |
|
211 | + $cl = $c['hline'][$curline]; |
|
212 | + $this->_cellHorzAlignLine($c, $curline, $maxw, $x, $morespace); |
|
213 | + foreach ($c['font'] as &$f) { |
|
214 | + $this->_setFontText($f); |
|
215 | + if (isset($f['color'])) { |
|
216 | + $color = Color::HEX2RGB($f['color']); |
|
217 | + $this->SetTextColor($color[0], $color[1], $color[2]); |
|
218 | + } else { |
|
219 | + unset($color); |
|
220 | + } |
|
221 | + $hl = $this->getLineHeight(); |
|
222 | + if (!isset($f['space'])) { |
|
223 | + continue; |
|
224 | + } |
|
225 | + $space = $f['space']; |
|
226 | + foreach ($f['line'] as $i=>&$l) { |
|
227 | + if (isset($l['str']) && is_array($l['str'])) { |
|
228 | + foreach ($l['str'] as &$t) { |
|
229 | + if ($t[2] != $curline) { |
|
230 | + $y += $cl; |
|
231 | + $curline++; |
|
232 | + $cl = $c['hline'][$curline]; |
|
233 | + $this->_cellHorzAlignLine($c, $curline, $maxw, $x, $morespace); |
|
234 | + } |
|
235 | + $this->x = $x + $x0; |
|
236 | + $this->y = $y + $y0 + $cl; |
|
237 | + $this->Cell($t[1], 0, $t[0]); |
|
238 | + $x += $t[1] + $space + $morespace; |
|
239 | + } |
|
240 | + } |
|
241 | + if ($l == 'br') { |
|
242 | + $y += $cl; |
|
243 | + $curline++; |
|
244 | + $cl = $c['hline'][$curline]; |
|
245 | + $this->_cellHorzAlignLine($c, $curline, $maxw, $x, $morespace); |
|
246 | + } |
|
247 | + } |
|
248 | + if (isset($color)) { |
|
249 | + $this->SetTextColor(0); |
|
250 | + } |
|
251 | + } |
|
252 | + } |
|
253 | 253 | |
254 | - private function _cellHorzAlignLine(&$c, $line, $maxw, &$x, &$morespace) |
|
255 | - { |
|
256 | - $morespace = 0; |
|
257 | - $x = $this->paddingCell; //Left by default |
|
258 | - if (!isset($c['wlines'][$line])) { |
|
259 | - return; |
|
260 | - } |
|
261 | - if ($c['a'] == 'C') {//Center |
|
262 | - $x = ($maxw - $c['wlines'][$line]) / 2; |
|
263 | - } elseif ($c['a'] == 'R') { |
|
264 | - $x = $maxw - $c['wlines'][$line]; |
|
265 | - } elseif ($c['a'] == 'J' && $c['wlinet'][$line][1] > 1 |
|
266 | - && isset($c['autobr'][$line])) {//Justify |
|
267 | - $morespace = ($maxw - $c['wlines'][$line]) / ($c['wlinet'][$line][1] - 1); |
|
268 | - } |
|
269 | - if ($x < $this->paddingCell) { |
|
270 | - $x = $this->paddingCell; |
|
271 | - } |
|
272 | - } |
|
254 | + private function _cellHorzAlignLine(&$c, $line, $maxw, &$x, &$morespace) |
|
255 | + { |
|
256 | + $morespace = 0; |
|
257 | + $x = $this->paddingCell; //Left by default |
|
258 | + if (!isset($c['wlines'][$line])) { |
|
259 | + return; |
|
260 | + } |
|
261 | + if ($c['a'] == 'C') {//Center |
|
262 | + $x = ($maxw - $c['wlines'][$line]) / 2; |
|
263 | + } elseif ($c['a'] == 'R') { |
|
264 | + $x = $maxw - $c['wlines'][$line]; |
|
265 | + } elseif ($c['a'] == 'J' && $c['wlinet'][$line][1] > 1 |
|
266 | + && isset($c['autobr'][$line])) {//Justify |
|
267 | + $morespace = ($maxw - $c['wlines'][$line]) / ($c['wlinet'][$line][1] - 1); |
|
268 | + } |
|
269 | + if ($x < $this->paddingCell) { |
|
270 | + $x = $this->paddingCell; |
|
271 | + } |
|
272 | + } |
|
273 | 273 | |
274 | - private function _calWidth($w) |
|
275 | - { |
|
276 | - $p = strpos($w, '%'); |
|
277 | - if ($p !== false) { |
|
278 | - return intval(substr($w, 0, $p) * $this->width / 100); |
|
279 | - } else { |
|
280 | - return intval($w); |
|
281 | - } |
|
282 | - } |
|
274 | + private function _calWidth($w) |
|
275 | + { |
|
276 | + $p = strpos($w, '%'); |
|
277 | + if ($p !== false) { |
|
278 | + return intval(substr($w, 0, $p) * $this->width / 100); |
|
279 | + } else { |
|
280 | + return intval($w); |
|
281 | + } |
|
282 | + } |
|
283 | 283 | |
284 | - /** |
|
285 | - * @return array |
|
286 | - * @desc Parse a string in html and return array of attribute of table |
|
287 | - */ |
|
288 | - private function _tableParser(&$html) |
|
289 | - { |
|
290 | - $t = new TreeHTML(new HTMLParser($html), 0); |
|
291 | - $row = $col = -1; |
|
292 | - $table['nc'] = $table['nr'] = 0; |
|
293 | - $table['repeat'] = []; |
|
294 | - $cell = []; |
|
295 | - $fontopen = false; |
|
296 | - $tdopen = false; |
|
297 | - foreach ($t->name as $i=>$element) { |
|
298 | - if ($fontopen && $t->type[$i] == NODE_TYPE_ENDELEMENT |
|
299 | - && (in_array($element, ['table', 'tr', 'td', 'font']))) { |
|
300 | - $fontopen = false; |
|
301 | - } |
|
302 | - if ($tdopen && $t->type[$i] == NODE_TYPE_ENDELEMENT |
|
303 | - && (in_array($element, ['table', 'tr', 'td'])) |
|
304 | - && !isset($cell[$row][$col]['miw'])) { |
|
305 | - $c = &$cell[$row][$col]; |
|
306 | - $c['miw'] = $c['maw'] = 0; |
|
307 | - $tdopen = false; |
|
308 | - } |
|
309 | - if ($t->type[$i] != NODE_TYPE_ELEMENT && $t->type[$i] != NODE_TYPE_TEXT) { |
|
310 | - continue; |
|
311 | - } |
|
312 | - switch ($element) { |
|
313 | - case 'table': |
|
314 | - $tdopen = 0; |
|
315 | - $a = &$t->attribute[$i]; |
|
316 | - if (isset($a['width'])) { |
|
317 | - $table['w'] = $this->_calWidth($a['width']); |
|
318 | - } |
|
319 | - if (isset($a['height'])) { |
|
320 | - $table['h'] = intval($a['height']); |
|
321 | - } |
|
322 | - if (isset($a['align'])) { |
|
323 | - $table['a'] = $this->getAlign(strtolower($a['align'])); |
|
324 | - } |
|
325 | - $table['border'] = (isset($a['border'])) ? $a['border'] : 0; |
|
326 | - if (isset($a['bgcolor'])) { |
|
327 | - $table['bgcolor'][-1] = $a['bgcolor']; |
|
328 | - } |
|
329 | - $table['nobreak'] = isset($a['nobreak']); |
|
330 | - break; |
|
331 | - case 'tr': |
|
332 | - $tdopen = 0; |
|
333 | - $row++; |
|
334 | - $table['nr']++; |
|
335 | - $col = -1; |
|
336 | - $a = &$t->attribute[$i]; |
|
337 | - if (isset($a['bgcolor'])) { |
|
338 | - $table['bgcolor'][$row] = $a['bgcolor']; |
|
339 | - } |
|
340 | - if (isset($a['repeat'])) { |
|
341 | - $table['repeat'][] = $row; |
|
342 | - } else { |
|
343 | - if (isset($a['pbr'])) { |
|
344 | - $table['pbr'][$row] = 1; |
|
345 | - } |
|
346 | - if (isset($a['knext'])) { |
|
347 | - $table['knext'][$row] = 1; |
|
348 | - } |
|
349 | - } |
|
350 | - break; |
|
351 | - case 'td': |
|
352 | - $tdopen = 1; |
|
353 | - $col++; while (isset($cell[$row][$col])) { |
|
354 | - $col++; |
|
355 | - } |
|
356 | - //Update number column |
|
357 | - if ($table['nc'] < $col + 1) { |
|
358 | - $table['nc'] = $col + 1; |
|
359 | - } |
|
360 | - $cell[$row][$col] = []; |
|
361 | - $c = &$cell[$row][$col]; |
|
362 | - $a = &$t->attribute[$i]; |
|
363 | - if (isset($a['width'])) { |
|
364 | - $c['w'] = intval($a['width']); |
|
365 | - } |
|
366 | - if (isset($a['height'])) { |
|
367 | - $c['h'] = intval($a['height']); |
|
368 | - } |
|
369 | - $c['a'] = isset($a['align']) ? $this->getAlign($a['align']) : 'L'; |
|
370 | - $c['va'] = isset($a['valign']) ? $this->getVAlign($a['valign']) : 'T'; |
|
371 | - if (isset($a['border'])) { |
|
372 | - $c['border'] = $a['border']; |
|
373 | - } else { |
|
374 | - $c['border'] = $table['border']; |
|
375 | - } |
|
376 | - if (isset($a['bgcolor'])) { |
|
377 | - $c['bgcolor'] = $a['bgcolor']; |
|
378 | - } |
|
379 | - $cs = $rs = 1; |
|
380 | - if (isset($a['colspan']) && $a['colspan'] > 1) { |
|
381 | - $cs = $c['colspan'] = intval($a['colspan']); |
|
382 | - } |
|
383 | - if (isset($a['rowspan']) && $a['rowspan'] > 1) { |
|
384 | - $rs = $c['rowspan'] = intval($a['rowspan']); |
|
385 | - } |
|
386 | - if (isset($a['size'])) { |
|
387 | - $c['font'][0]['size'] = $a['size']; |
|
388 | - } |
|
389 | - if (isset($a['family'])) { |
|
390 | - $c['font'][0]['family'] = $a['family']; |
|
391 | - } |
|
392 | - if (isset($a['style'])) { |
|
393 | - $STYLE = explode(',', strtoupper($a['style'])); |
|
394 | - $fontStyle = ''; |
|
395 | - foreach ($STYLE as $style) { |
|
396 | - $fontStyle .= substr(trim($style), 0, 1); |
|
397 | - } |
|
398 | - $c['font'][0]['style'] = $fontStyle; |
|
399 | - } |
|
400 | - if (isset($a['color'])) { |
|
401 | - $c['font'][0]['color'] = $a['color']; |
|
402 | - } |
|
403 | - //Chiem dung vi tri de danh cho cell span |
|
404 | - for ($k = $row; $k < $row + $rs; $k++) { |
|
405 | - for ($l = $col; $l < $col + $cs; $l++) { |
|
406 | - if ($k - $row || $l - $col) { |
|
407 | - $cell[$k][$l] = 0; |
|
408 | - } |
|
409 | - } |
|
410 | - } |
|
411 | - if (isset($a['nowrap'])) { |
|
412 | - $c['nowrap'] = 1; |
|
413 | - } |
|
414 | - $fontopen = true; |
|
415 | - if (!isset($c['font'])) { |
|
416 | - $c['font'][] = []; |
|
417 | - } |
|
418 | - break; |
|
419 | - case 'Text': |
|
420 | - $c = &$cell[$row][$col]; |
|
421 | - if (!$fontopen || !isset($c['font'])) { |
|
422 | - $c['font'][] = []; |
|
423 | - } |
|
424 | - $f = &$c['font'][count($c['font']) - 1]; |
|
425 | - $this->_setTextAndSize($c, $f, $this->_html2text($t->value[$i])); |
|
426 | - break; |
|
427 | - case 'font': |
|
428 | - $a = &$t->attribute[$i]; |
|
429 | - $c = &$cell[$row][$col]; |
|
430 | - $c['font'][] = []; |
|
431 | - $f = &$c['font'][count($c['font']) - 1]; |
|
432 | - if (isset($a['size'])) { |
|
433 | - $f['size'] = $a['size']; |
|
434 | - } |
|
435 | - if (isset($a['family'])) { |
|
436 | - $f['family'] = $a['family']; |
|
437 | - } |
|
438 | - if (isset($a['style'])) { |
|
439 | - $STYLE = explode(',', strtoupper($a['style'])); |
|
440 | - $fontStyle = ''; |
|
441 | - foreach ($STYLE as $style) { |
|
442 | - $fontStyle .= substr(trim($style), 0, 1); |
|
443 | - } |
|
444 | - $f['style'] = $fontStyle; |
|
445 | - } |
|
446 | - if (isset($a['color'])) { |
|
447 | - $f['color'] = $a['color']; |
|
448 | - } |
|
449 | - break; |
|
450 | - case 'img': |
|
451 | - $a = &$t->attribute[$i]; |
|
452 | - if (isset($a['src'])) { |
|
453 | - $this->_setImage($c, $a); |
|
454 | - } |
|
455 | - break; |
|
456 | - case 'br': |
|
457 | - $c = &$cell[$row][$col]; |
|
458 | - $cn = isset($c['font']) ? count($c['font']) - 1 : 0; |
|
459 | - $c['font'][$cn]['line'][] = 'br'; |
|
460 | - break; |
|
461 | - } |
|
462 | - } |
|
463 | - $table['cells'] = $cell; |
|
464 | - $table['wc'] = array_pad([], $table['nc'], ['miw'=>0, 'maw'=>0]); |
|
465 | - $table['hr'] = array_pad([], $table['nr'], 0); |
|
284 | + /** |
|
285 | + * @return array |
|
286 | + * @desc Parse a string in html and return array of attribute of table |
|
287 | + */ |
|
288 | + private function _tableParser(&$html) |
|
289 | + { |
|
290 | + $t = new TreeHTML(new HTMLParser($html), 0); |
|
291 | + $row = $col = -1; |
|
292 | + $table['nc'] = $table['nr'] = 0; |
|
293 | + $table['repeat'] = []; |
|
294 | + $cell = []; |
|
295 | + $fontopen = false; |
|
296 | + $tdopen = false; |
|
297 | + foreach ($t->name as $i=>$element) { |
|
298 | + if ($fontopen && $t->type[$i] == NODE_TYPE_ENDELEMENT |
|
299 | + && (in_array($element, ['table', 'tr', 'td', 'font']))) { |
|
300 | + $fontopen = false; |
|
301 | + } |
|
302 | + if ($tdopen && $t->type[$i] == NODE_TYPE_ENDELEMENT |
|
303 | + && (in_array($element, ['table', 'tr', 'td'])) |
|
304 | + && !isset($cell[$row][$col]['miw'])) { |
|
305 | + $c = &$cell[$row][$col]; |
|
306 | + $c['miw'] = $c['maw'] = 0; |
|
307 | + $tdopen = false; |
|
308 | + } |
|
309 | + if ($t->type[$i] != NODE_TYPE_ELEMENT && $t->type[$i] != NODE_TYPE_TEXT) { |
|
310 | + continue; |
|
311 | + } |
|
312 | + switch ($element) { |
|
313 | + case 'table': |
|
314 | + $tdopen = 0; |
|
315 | + $a = &$t->attribute[$i]; |
|
316 | + if (isset($a['width'])) { |
|
317 | + $table['w'] = $this->_calWidth($a['width']); |
|
318 | + } |
|
319 | + if (isset($a['height'])) { |
|
320 | + $table['h'] = intval($a['height']); |
|
321 | + } |
|
322 | + if (isset($a['align'])) { |
|
323 | + $table['a'] = $this->getAlign(strtolower($a['align'])); |
|
324 | + } |
|
325 | + $table['border'] = (isset($a['border'])) ? $a['border'] : 0; |
|
326 | + if (isset($a['bgcolor'])) { |
|
327 | + $table['bgcolor'][-1] = $a['bgcolor']; |
|
328 | + } |
|
329 | + $table['nobreak'] = isset($a['nobreak']); |
|
330 | + break; |
|
331 | + case 'tr': |
|
332 | + $tdopen = 0; |
|
333 | + $row++; |
|
334 | + $table['nr']++; |
|
335 | + $col = -1; |
|
336 | + $a = &$t->attribute[$i]; |
|
337 | + if (isset($a['bgcolor'])) { |
|
338 | + $table['bgcolor'][$row] = $a['bgcolor']; |
|
339 | + } |
|
340 | + if (isset($a['repeat'])) { |
|
341 | + $table['repeat'][] = $row; |
|
342 | + } else { |
|
343 | + if (isset($a['pbr'])) { |
|
344 | + $table['pbr'][$row] = 1; |
|
345 | + } |
|
346 | + if (isset($a['knext'])) { |
|
347 | + $table['knext'][$row] = 1; |
|
348 | + } |
|
349 | + } |
|
350 | + break; |
|
351 | + case 'td': |
|
352 | + $tdopen = 1; |
|
353 | + $col++; while (isset($cell[$row][$col])) { |
|
354 | + $col++; |
|
355 | + } |
|
356 | + //Update number column |
|
357 | + if ($table['nc'] < $col + 1) { |
|
358 | + $table['nc'] = $col + 1; |
|
359 | + } |
|
360 | + $cell[$row][$col] = []; |
|
361 | + $c = &$cell[$row][$col]; |
|
362 | + $a = &$t->attribute[$i]; |
|
363 | + if (isset($a['width'])) { |
|
364 | + $c['w'] = intval($a['width']); |
|
365 | + } |
|
366 | + if (isset($a['height'])) { |
|
367 | + $c['h'] = intval($a['height']); |
|
368 | + } |
|
369 | + $c['a'] = isset($a['align']) ? $this->getAlign($a['align']) : 'L'; |
|
370 | + $c['va'] = isset($a['valign']) ? $this->getVAlign($a['valign']) : 'T'; |
|
371 | + if (isset($a['border'])) { |
|
372 | + $c['border'] = $a['border']; |
|
373 | + } else { |
|
374 | + $c['border'] = $table['border']; |
|
375 | + } |
|
376 | + if (isset($a['bgcolor'])) { |
|
377 | + $c['bgcolor'] = $a['bgcolor']; |
|
378 | + } |
|
379 | + $cs = $rs = 1; |
|
380 | + if (isset($a['colspan']) && $a['colspan'] > 1) { |
|
381 | + $cs = $c['colspan'] = intval($a['colspan']); |
|
382 | + } |
|
383 | + if (isset($a['rowspan']) && $a['rowspan'] > 1) { |
|
384 | + $rs = $c['rowspan'] = intval($a['rowspan']); |
|
385 | + } |
|
386 | + if (isset($a['size'])) { |
|
387 | + $c['font'][0]['size'] = $a['size']; |
|
388 | + } |
|
389 | + if (isset($a['family'])) { |
|
390 | + $c['font'][0]['family'] = $a['family']; |
|
391 | + } |
|
392 | + if (isset($a['style'])) { |
|
393 | + $STYLE = explode(',', strtoupper($a['style'])); |
|
394 | + $fontStyle = ''; |
|
395 | + foreach ($STYLE as $style) { |
|
396 | + $fontStyle .= substr(trim($style), 0, 1); |
|
397 | + } |
|
398 | + $c['font'][0]['style'] = $fontStyle; |
|
399 | + } |
|
400 | + if (isset($a['color'])) { |
|
401 | + $c['font'][0]['color'] = $a['color']; |
|
402 | + } |
|
403 | + //Chiem dung vi tri de danh cho cell span |
|
404 | + for ($k = $row; $k < $row + $rs; $k++) { |
|
405 | + for ($l = $col; $l < $col + $cs; $l++) { |
|
406 | + if ($k - $row || $l - $col) { |
|
407 | + $cell[$k][$l] = 0; |
|
408 | + } |
|
409 | + } |
|
410 | + } |
|
411 | + if (isset($a['nowrap'])) { |
|
412 | + $c['nowrap'] = 1; |
|
413 | + } |
|
414 | + $fontopen = true; |
|
415 | + if (!isset($c['font'])) { |
|
416 | + $c['font'][] = []; |
|
417 | + } |
|
418 | + break; |
|
419 | + case 'Text': |
|
420 | + $c = &$cell[$row][$col]; |
|
421 | + if (!$fontopen || !isset($c['font'])) { |
|
422 | + $c['font'][] = []; |
|
423 | + } |
|
424 | + $f = &$c['font'][count($c['font']) - 1]; |
|
425 | + $this->_setTextAndSize($c, $f, $this->_html2text($t->value[$i])); |
|
426 | + break; |
|
427 | + case 'font': |
|
428 | + $a = &$t->attribute[$i]; |
|
429 | + $c = &$cell[$row][$col]; |
|
430 | + $c['font'][] = []; |
|
431 | + $f = &$c['font'][count($c['font']) - 1]; |
|
432 | + if (isset($a['size'])) { |
|
433 | + $f['size'] = $a['size']; |
|
434 | + } |
|
435 | + if (isset($a['family'])) { |
|
436 | + $f['family'] = $a['family']; |
|
437 | + } |
|
438 | + if (isset($a['style'])) { |
|
439 | + $STYLE = explode(',', strtoupper($a['style'])); |
|
440 | + $fontStyle = ''; |
|
441 | + foreach ($STYLE as $style) { |
|
442 | + $fontStyle .= substr(trim($style), 0, 1); |
|
443 | + } |
|
444 | + $f['style'] = $fontStyle; |
|
445 | + } |
|
446 | + if (isset($a['color'])) { |
|
447 | + $f['color'] = $a['color']; |
|
448 | + } |
|
449 | + break; |
|
450 | + case 'img': |
|
451 | + $a = &$t->attribute[$i]; |
|
452 | + if (isset($a['src'])) { |
|
453 | + $this->_setImage($c, $a); |
|
454 | + } |
|
455 | + break; |
|
456 | + case 'br': |
|
457 | + $c = &$cell[$row][$col]; |
|
458 | + $cn = isset($c['font']) ? count($c['font']) - 1 : 0; |
|
459 | + $c['font'][$cn]['line'][] = 'br'; |
|
460 | + break; |
|
461 | + } |
|
462 | + } |
|
463 | + $table['cells'] = $cell; |
|
464 | + $table['wc'] = array_pad([], $table['nc'], ['miw'=>0, 'maw'=>0]); |
|
465 | + $table['hr'] = array_pad([], $table['nr'], 0); |
|
466 | 466 | |
467 | - return $table; |
|
468 | - } |
|
467 | + return $table; |
|
468 | + } |
|
469 | 469 | |
470 | - private function _setTextAndSize(&$cell, &$f, $text) |
|
471 | - { |
|
472 | - if ($text == '') { |
|
473 | - return; |
|
474 | - } |
|
475 | - $this->_setFontText($f); |
|
476 | - if (!isset($f['line'][0])) { |
|
477 | - $f['line'][0]['min'] = $f['line'][0]['max'] = 0; |
|
478 | - } |
|
479 | - $text = preg_split('/[\s]+/', $text, -1, PREG_SPLIT_NO_EMPTY); |
|
480 | - $l = &$f['line'][count($f['line']) - 1]; |
|
481 | - if ($l == 'br') { |
|
482 | - $f['line'][] = ['min'=>0, 'max'=>0, 'str'=>[]]; |
|
483 | - $l = &$f['line'][count($f['line']) - 1]; |
|
484 | - } |
|
485 | - if (!isset($f['space'])) { |
|
486 | - $f['space'] = $this->GetStringWidth(' '); |
|
487 | - } |
|
488 | - $ct = count($text); |
|
489 | - foreach ($text as $item) { |
|
490 | - $s = $this->GetStringWidth($item); |
|
491 | - if ($l['min'] < $s) { |
|
492 | - $l['min'] = $s; |
|
493 | - } |
|
494 | - $l['max'] += $s; |
|
495 | - if ($ct > 1) { |
|
496 | - $l['max'] += $f['space']; |
|
497 | - } |
|
498 | - $l['str'][] = [$item, $s]; |
|
499 | - } |
|
500 | - if (isset($cell['nowrap'])) { |
|
501 | - $l['min'] = $l['max']; |
|
502 | - } |
|
503 | - if (!isset($cell['miw']) || $cell['miw'] - $this->paddingCell2 < $l['min']) { |
|
504 | - $cell['miw'] = $l['min'] + $this->paddingCell2; |
|
505 | - } |
|
506 | - if (!isset($cell['maw']) || $cell['maw'] - $this->paddingCell2 < $l['max']) { |
|
507 | - $cell['maw'] = $l['max'] + $this->paddingCell2; |
|
508 | - } |
|
509 | - } |
|
470 | + private function _setTextAndSize(&$cell, &$f, $text) |
|
471 | + { |
|
472 | + if ($text == '') { |
|
473 | + return; |
|
474 | + } |
|
475 | + $this->_setFontText($f); |
|
476 | + if (!isset($f['line'][0])) { |
|
477 | + $f['line'][0]['min'] = $f['line'][0]['max'] = 0; |
|
478 | + } |
|
479 | + $text = preg_split('/[\s]+/', $text, -1, PREG_SPLIT_NO_EMPTY); |
|
480 | + $l = &$f['line'][count($f['line']) - 1]; |
|
481 | + if ($l == 'br') { |
|
482 | + $f['line'][] = ['min'=>0, 'max'=>0, 'str'=>[]]; |
|
483 | + $l = &$f['line'][count($f['line']) - 1]; |
|
484 | + } |
|
485 | + if (!isset($f['space'])) { |
|
486 | + $f['space'] = $this->GetStringWidth(' '); |
|
487 | + } |
|
488 | + $ct = count($text); |
|
489 | + foreach ($text as $item) { |
|
490 | + $s = $this->GetStringWidth($item); |
|
491 | + if ($l['min'] < $s) { |
|
492 | + $l['min'] = $s; |
|
493 | + } |
|
494 | + $l['max'] += $s; |
|
495 | + if ($ct > 1) { |
|
496 | + $l['max'] += $f['space']; |
|
497 | + } |
|
498 | + $l['str'][] = [$item, $s]; |
|
499 | + } |
|
500 | + if (isset($cell['nowrap'])) { |
|
501 | + $l['min'] = $l['max']; |
|
502 | + } |
|
503 | + if (!isset($cell['miw']) || $cell['miw'] - $this->paddingCell2 < $l['min']) { |
|
504 | + $cell['miw'] = $l['min'] + $this->paddingCell2; |
|
505 | + } |
|
506 | + if (!isset($cell['maw']) || $cell['maw'] - $this->paddingCell2 < $l['max']) { |
|
507 | + $cell['maw'] = $l['max'] + $this->paddingCell2; |
|
508 | + } |
|
509 | + } |
|
510 | 510 | |
511 | - private function _setImage(&$c, &$a) |
|
512 | - { |
|
513 | - $path = $a['src']; |
|
514 | - if (!is_file($path)) { |
|
515 | - $this->Error('Image is not exists: '.$path); |
|
516 | - } else { |
|
517 | - list($u, $d) = $this->_getResolution($path); |
|
518 | - $c['img'] = $path; |
|
519 | - list($c['w'], $c['h']) = getimagesize($path); |
|
520 | - if (isset($a['width'])) { |
|
521 | - $c['w'] = $a['width']; |
|
522 | - } |
|
523 | - if (isset($a['height'])) { |
|
524 | - $c['h'] = $a['height']; |
|
525 | - } |
|
526 | - $scale = 1; |
|
527 | - if ($u == 1) { |
|
528 | - $scale = 25.4 / $d; |
|
529 | - } elseif ($u == 2) { |
|
530 | - $scale = 10 / $d; |
|
531 | - } |
|
532 | - $c['w'] = intval($c['w'] * $scale); |
|
533 | - $c['h'] = intval($c['h'] * $scale); |
|
534 | - } |
|
535 | - } |
|
511 | + private function _setImage(&$c, &$a) |
|
512 | + { |
|
513 | + $path = $a['src']; |
|
514 | + if (!is_file($path)) { |
|
515 | + $this->Error('Image is not exists: '.$path); |
|
516 | + } else { |
|
517 | + list($u, $d) = $this->_getResolution($path); |
|
518 | + $c['img'] = $path; |
|
519 | + list($c['w'], $c['h']) = getimagesize($path); |
|
520 | + if (isset($a['width'])) { |
|
521 | + $c['w'] = $a['width']; |
|
522 | + } |
|
523 | + if (isset($a['height'])) { |
|
524 | + $c['h'] = $a['height']; |
|
525 | + } |
|
526 | + $scale = 1; |
|
527 | + if ($u == 1) { |
|
528 | + $scale = 25.4 / $d; |
|
529 | + } elseif ($u == 2) { |
|
530 | + $scale = 10 / $d; |
|
531 | + } |
|
532 | + $c['w'] = intval($c['w'] * $scale); |
|
533 | + $c['h'] = intval($c['h'] * $scale); |
|
534 | + } |
|
535 | + } |
|
536 | 536 | |
537 | - private function _getResolution($path) |
|
538 | - { |
|
539 | - $pos = strrpos($path, '.'); |
|
540 | - if (!$pos) { |
|
541 | - $this->Error('Image file has no extension and no type was specified: '.$path); |
|
542 | - } |
|
543 | - $type = substr($path, $pos + 1); |
|
544 | - $type = strtolower($type); |
|
545 | - if ($type == 'jpeg') { |
|
546 | - $type = 'jpg'; |
|
547 | - } |
|
548 | - if ($type != 'jpg') { |
|
549 | - $this->Error('Unsupported image type: '.$path); |
|
550 | - } |
|
551 | - $f = fopen($path, 'r'); |
|
552 | - fseek($f, 13, SEEK_SET); |
|
553 | - $info = fread($f, 3); |
|
554 | - fclose($f); |
|
555 | - $iUnit = ord($info[0]); |
|
556 | - $iX = ord($info[1]) * 256 + ord($info[2]); |
|
537 | + private function _getResolution($path) |
|
538 | + { |
|
539 | + $pos = strrpos($path, '.'); |
|
540 | + if (!$pos) { |
|
541 | + $this->Error('Image file has no extension and no type was specified: '.$path); |
|
542 | + } |
|
543 | + $type = substr($path, $pos + 1); |
|
544 | + $type = strtolower($type); |
|
545 | + if ($type == 'jpeg') { |
|
546 | + $type = 'jpg'; |
|
547 | + } |
|
548 | + if ($type != 'jpg') { |
|
549 | + $this->Error('Unsupported image type: '.$path); |
|
550 | + } |
|
551 | + $f = fopen($path, 'r'); |
|
552 | + fseek($f, 13, SEEK_SET); |
|
553 | + $info = fread($f, 3); |
|
554 | + fclose($f); |
|
555 | + $iUnit = ord($info[0]); |
|
556 | + $iX = ord($info[1]) * 256 + ord($info[2]); |
|
557 | 557 | |
558 | - return [$iUnit, $iX]; |
|
559 | - } |
|
558 | + return [$iUnit, $iX]; |
|
559 | + } |
|
560 | 560 | |
561 | - private function _html2text($text) |
|
562 | - { |
|
563 | - $text = str_replace(' ', ' ', $text); |
|
564 | - $text = str_replace('<', '<', $text); |
|
561 | + private function _html2text($text) |
|
562 | + { |
|
563 | + $text = str_replace(' ', ' ', $text); |
|
564 | + $text = str_replace('<', '<', $text); |
|
565 | 565 | |
566 | - return $text; |
|
567 | - } |
|
566 | + return $text; |
|
567 | + } |
|
568 | 568 | |
569 | - /** |
|
570 | - * table Array of (w, h, bc, nr, wc, hr, cells) |
|
571 | - * w Width of table |
|
572 | - * h Height of table |
|
573 | - * bc Number column |
|
574 | - * nr Number row |
|
575 | - * hr List of height of each row |
|
576 | - * wc List of width of each column |
|
577 | - * cells List of cells of each rows, cells[i][j] is a cell in table. |
|
578 | - */ |
|
579 | - private function _tableColumnWidth(&$table) |
|
580 | - { |
|
581 | - $cs = &$table['cells']; |
|
582 | - $nc = $table['nc']; |
|
583 | - $nr = $table['nr']; |
|
584 | - $listspan = []; |
|
585 | - //Xac dinh do rong cua cac cell va cac cot tuong ung |
|
586 | - for ($j = 0; $j < $nc; $j++) { |
|
587 | - $wc = &$table['wc'][$j]; |
|
588 | - for ($i = 0; $i < $nr; $i++) { |
|
589 | - if (isset($cs[$i][$j]['miw'])) { |
|
590 | - $c = &$cs[$i][$j]; |
|
591 | - if (isset($c['nowrap'])) { |
|
592 | - $c['miw'] = $c['maw']; |
|
593 | - } |
|
594 | - if (isset($c['w'])) { |
|
595 | - if ($c['miw'] < $c['w']) { |
|
596 | - $c['miw'] = $c['w']; |
|
597 | - } elseif ($c['miw'] > $c['w']) { |
|
598 | - $c['w'] = $c['miw'] + $this->paddingCell2; |
|
599 | - } |
|
600 | - if (!isset($wc['w'])) { |
|
601 | - $wc['w'] = 1; |
|
602 | - } |
|
603 | - } |
|
604 | - if ($c['maw'] < $c['miw']) { |
|
605 | - $c['maw'] = $c['miw']; |
|
606 | - } |
|
607 | - if (!isset($c['colspan'])) { |
|
608 | - if ($wc['miw'] < $c['miw']) { |
|
609 | - $wc['miw'] = $c['miw']; |
|
610 | - } |
|
611 | - if ($wc['maw'] < $c['maw']) { |
|
612 | - $wc['maw'] = $c['maw']; |
|
613 | - } |
|
614 | - if (isset($wc['w']) && $wc['w'] < $wc['miw']) { |
|
615 | - $wc['w'] = $wc['miw']; |
|
616 | - } |
|
617 | - } else { |
|
618 | - $listspan[] = [$i, $j]; |
|
619 | - } |
|
620 | - } |
|
621 | - } |
|
622 | - } |
|
623 | - //Xac dinh su anh huong cua cac cell colspan len cac cot va nguoc lai |
|
624 | - $wc = &$table['wc']; |
|
625 | - foreach ($listspan as $span) { |
|
626 | - list($i, $j) = $span; |
|
627 | - $c = &$cs[$i][$j]; |
|
628 | - $lc = $j + $c['colspan']; |
|
629 | - if ($lc > $nc) { |
|
630 | - $lc = $nc; |
|
631 | - } |
|
569 | + /** |
|
570 | + * table Array of (w, h, bc, nr, wc, hr, cells) |
|
571 | + * w Width of table |
|
572 | + * h Height of table |
|
573 | + * bc Number column |
|
574 | + * nr Number row |
|
575 | + * hr List of height of each row |
|
576 | + * wc List of width of each column |
|
577 | + * cells List of cells of each rows, cells[i][j] is a cell in table. |
|
578 | + */ |
|
579 | + private function _tableColumnWidth(&$table) |
|
580 | + { |
|
581 | + $cs = &$table['cells']; |
|
582 | + $nc = $table['nc']; |
|
583 | + $nr = $table['nr']; |
|
584 | + $listspan = []; |
|
585 | + //Xac dinh do rong cua cac cell va cac cot tuong ung |
|
586 | + for ($j = 0; $j < $nc; $j++) { |
|
587 | + $wc = &$table['wc'][$j]; |
|
588 | + for ($i = 0; $i < $nr; $i++) { |
|
589 | + if (isset($cs[$i][$j]['miw'])) { |
|
590 | + $c = &$cs[$i][$j]; |
|
591 | + if (isset($c['nowrap'])) { |
|
592 | + $c['miw'] = $c['maw']; |
|
593 | + } |
|
594 | + if (isset($c['w'])) { |
|
595 | + if ($c['miw'] < $c['w']) { |
|
596 | + $c['miw'] = $c['w']; |
|
597 | + } elseif ($c['miw'] > $c['w']) { |
|
598 | + $c['w'] = $c['miw'] + $this->paddingCell2; |
|
599 | + } |
|
600 | + if (!isset($wc['w'])) { |
|
601 | + $wc['w'] = 1; |
|
602 | + } |
|
603 | + } |
|
604 | + if ($c['maw'] < $c['miw']) { |
|
605 | + $c['maw'] = $c['miw']; |
|
606 | + } |
|
607 | + if (!isset($c['colspan'])) { |
|
608 | + if ($wc['miw'] < $c['miw']) { |
|
609 | + $wc['miw'] = $c['miw']; |
|
610 | + } |
|
611 | + if ($wc['maw'] < $c['maw']) { |
|
612 | + $wc['maw'] = $c['maw']; |
|
613 | + } |
|
614 | + if (isset($wc['w']) && $wc['w'] < $wc['miw']) { |
|
615 | + $wc['w'] = $wc['miw']; |
|
616 | + } |
|
617 | + } else { |
|
618 | + $listspan[] = [$i, $j]; |
|
619 | + } |
|
620 | + } |
|
621 | + } |
|
622 | + } |
|
623 | + //Xac dinh su anh huong cua cac cell colspan len cac cot va nguoc lai |
|
624 | + $wc = &$table['wc']; |
|
625 | + foreach ($listspan as $span) { |
|
626 | + list($i, $j) = $span; |
|
627 | + $c = &$cs[$i][$j]; |
|
628 | + $lc = $j + $c['colspan']; |
|
629 | + if ($lc > $nc) { |
|
630 | + $lc = $nc; |
|
631 | + } |
|
632 | 632 | |
633 | - $wis = $wisa = 0; |
|
634 | - $was = $wasa = 0; |
|
635 | - $list = []; |
|
636 | - for ($k = $j; $k < $lc; $k++) { |
|
637 | - $wis += $wc[$k]['miw']; |
|
638 | - $was += $wc[$k]['maw']; |
|
639 | - if (!isset($c['w'])) { |
|
640 | - $list[] = $k; |
|
641 | - $wisa += $wc[$k]['miw']; |
|
642 | - $wasa += $wc[$k]['maw']; |
|
643 | - } |
|
644 | - } |
|
645 | - if ($c['miw'] > $wis) { |
|
646 | - if (!$wis) {//Cac cot chua co kich thuoc => chia deu |
|
647 | - for ($k = $j; $k < $lc; $k++) { |
|
648 | - $wc[$k]['miw'] = $c['miw'] / $c['colspan']; |
|
649 | - } |
|
650 | - } elseif (!count($list)) {//Khong co cot nao co kich thuoc auto => chia deu phan du cho tat ca |
|
651 | - $wi = $c['miw'] - $wis; |
|
652 | - for ($k = $j; $k < $lc; $k++) { |
|
653 | - $wc[$k]['miw'] += ($wc[$k]['miw'] / $wis) * $wi; |
|
654 | - } |
|
655 | - } else {//Co mot so cot co kich thuoc auto => chia deu phan du cho cac cot auto |
|
656 | - $wi = $c['miw'] - $wis; |
|
657 | - foreach ($list as $_z2=>$k) { |
|
658 | - $wc[$k]['miw'] += ($wc[$k]['miw'] / $wisa) * $wi; |
|
659 | - } |
|
660 | - } |
|
661 | - } |
|
662 | - if ($c['maw'] > $was) { |
|
663 | - if (!$wis) {//Cac cot chua co kich thuoc => chia deu |
|
664 | - for ($k = $j; $k < $lc; $k++) { |
|
665 | - $wc[$k]['maw'] = $c['maw'] / $c['colspan']; |
|
666 | - } |
|
667 | - } elseif (!count($list)) {//Khong co cot nao co kich thuoc auto => chia deu phan du cho tat ca |
|
668 | - $wi = $c['maw'] - $was; |
|
669 | - for ($k = $j; $k < $lc; $k++) { |
|
670 | - $wc[$k]['maw'] += ($wc[$k]['maw'] / $was) * $wi; |
|
671 | - } |
|
672 | - } else {//Co mot so cot co kich thuoc auto => chia deu phan du cho cac cot auto |
|
673 | - $wi = $c['maw'] - $was; |
|
674 | - foreach ($list as $_z2=>$k) { |
|
675 | - $wc[$k]['maw'] += ($wc[$k]['maw'] / $wasa) * $wi; |
|
676 | - } |
|
677 | - } |
|
678 | - } |
|
679 | - } |
|
680 | - } |
|
633 | + $wis = $wisa = 0; |
|
634 | + $was = $wasa = 0; |
|
635 | + $list = []; |
|
636 | + for ($k = $j; $k < $lc; $k++) { |
|
637 | + $wis += $wc[$k]['miw']; |
|
638 | + $was += $wc[$k]['maw']; |
|
639 | + if (!isset($c['w'])) { |
|
640 | + $list[] = $k; |
|
641 | + $wisa += $wc[$k]['miw']; |
|
642 | + $wasa += $wc[$k]['maw']; |
|
643 | + } |
|
644 | + } |
|
645 | + if ($c['miw'] > $wis) { |
|
646 | + if (!$wis) {//Cac cot chua co kich thuoc => chia deu |
|
647 | + for ($k = $j; $k < $lc; $k++) { |
|
648 | + $wc[$k]['miw'] = $c['miw'] / $c['colspan']; |
|
649 | + } |
|
650 | + } elseif (!count($list)) {//Khong co cot nao co kich thuoc auto => chia deu phan du cho tat ca |
|
651 | + $wi = $c['miw'] - $wis; |
|
652 | + for ($k = $j; $k < $lc; $k++) { |
|
653 | + $wc[$k]['miw'] += ($wc[$k]['miw'] / $wis) * $wi; |
|
654 | + } |
|
655 | + } else {//Co mot so cot co kich thuoc auto => chia deu phan du cho cac cot auto |
|
656 | + $wi = $c['miw'] - $wis; |
|
657 | + foreach ($list as $_z2=>$k) { |
|
658 | + $wc[$k]['miw'] += ($wc[$k]['miw'] / $wisa) * $wi; |
|
659 | + } |
|
660 | + } |
|
661 | + } |
|
662 | + if ($c['maw'] > $was) { |
|
663 | + if (!$wis) {//Cac cot chua co kich thuoc => chia deu |
|
664 | + for ($k = $j; $k < $lc; $k++) { |
|
665 | + $wc[$k]['maw'] = $c['maw'] / $c['colspan']; |
|
666 | + } |
|
667 | + } elseif (!count($list)) {//Khong co cot nao co kich thuoc auto => chia deu phan du cho tat ca |
|
668 | + $wi = $c['maw'] - $was; |
|
669 | + for ($k = $j; $k < $lc; $k++) { |
|
670 | + $wc[$k]['maw'] += ($wc[$k]['maw'] / $was) * $wi; |
|
671 | + } |
|
672 | + } else {//Co mot so cot co kich thuoc auto => chia deu phan du cho cac cot auto |
|
673 | + $wi = $c['maw'] - $was; |
|
674 | + foreach ($list as $_z2=>$k) { |
|
675 | + $wc[$k]['maw'] += ($wc[$k]['maw'] / $wasa) * $wi; |
|
676 | + } |
|
677 | + } |
|
678 | + } |
|
679 | + } |
|
680 | + } |
|
681 | 681 | |
682 | - /** |
|
683 | - * @desc Xac dinh chieu rong cua table |
|
684 | - */ |
|
685 | - private function _tableWidth(&$table) |
|
686 | - { |
|
687 | - $wc = &$table['wc']; |
|
688 | - $nc = $table['nc']; |
|
689 | - $a = 0; |
|
690 | - for ($i = 0; $i < $nc; $i++) { |
|
691 | - $a += isset($wc[$i]['w']) ? $wc[$i]['miw'] : $wc[$i]['maw']; |
|
692 | - } |
|
693 | - if ($a > $this->width) { |
|
694 | - $table['w'] = $this->width; |
|
695 | - } |
|
682 | + /** |
|
683 | + * @desc Xac dinh chieu rong cua table |
|
684 | + */ |
|
685 | + private function _tableWidth(&$table) |
|
686 | + { |
|
687 | + $wc = &$table['wc']; |
|
688 | + $nc = $table['nc']; |
|
689 | + $a = 0; |
|
690 | + for ($i = 0; $i < $nc; $i++) { |
|
691 | + $a += isset($wc[$i]['w']) ? $wc[$i]['miw'] : $wc[$i]['maw']; |
|
692 | + } |
|
693 | + if ($a > $this->width) { |
|
694 | + $table['w'] = $this->width; |
|
695 | + } |
|
696 | 696 | |
697 | - if (isset($table['w'])) { |
|
698 | - $wis = $wisa = 0; |
|
699 | - $list = []; |
|
700 | - for ($i = 0; $i < $nc; $i++) { |
|
701 | - $wis += $wc[$i]['miw']; |
|
702 | - if (!isset($wc[$i]['w'])) { |
|
703 | - $list[] = $i; |
|
704 | - $wisa += $wc[$i]['miw']; |
|
705 | - } |
|
706 | - } |
|
707 | - if ($table['w'] > $wis) { |
|
708 | - if (!count($list)) { |
|
709 | - //Khong co cot nao co kich thuoc auto => chia deu phan du cho tat ca |
|
710 | - $wi = ($table['w'] - $wis) / $nc; |
|
711 | - for ($k = 0; $k < $nc; $k++) { |
|
712 | - $wc[$k]['miw'] += $wi; |
|
713 | - } |
|
714 | - } else { |
|
715 | - //Co mot so cot co kich thuoc auto => chia deu phan du cho cac cot auto |
|
716 | - $wi = ($table['w'] - $wis) / count($list); |
|
717 | - foreach ($list as $k) { |
|
718 | - $wc[$k]['miw'] += $wi; |
|
719 | - } |
|
720 | - } |
|
721 | - } |
|
722 | - for ($i = 0; $i < $nc; $i++) { |
|
723 | - $a = $wc[$i]['miw']; |
|
724 | - unset($wc[$i]); |
|
725 | - $wc[$i] = $a; |
|
726 | - } |
|
727 | - } else { |
|
728 | - $table['w'] = $a; |
|
729 | - for ($i = 0; $i < $nc; $i++) { |
|
730 | - $a = isset($wc[$i]['w']) ? $wc[$i]['miw'] : $wc[$i]['maw']; |
|
731 | - unset($wc[$i]); |
|
732 | - $wc[$i] = $a; |
|
733 | - } |
|
734 | - } |
|
735 | - $table['w'] = array_sum($wc); |
|
736 | - } |
|
697 | + if (isset($table['w'])) { |
|
698 | + $wis = $wisa = 0; |
|
699 | + $list = []; |
|
700 | + for ($i = 0; $i < $nc; $i++) { |
|
701 | + $wis += $wc[$i]['miw']; |
|
702 | + if (!isset($wc[$i]['w'])) { |
|
703 | + $list[] = $i; |
|
704 | + $wisa += $wc[$i]['miw']; |
|
705 | + } |
|
706 | + } |
|
707 | + if ($table['w'] > $wis) { |
|
708 | + if (!count($list)) { |
|
709 | + //Khong co cot nao co kich thuoc auto => chia deu phan du cho tat ca |
|
710 | + $wi = ($table['w'] - $wis) / $nc; |
|
711 | + for ($k = 0; $k < $nc; $k++) { |
|
712 | + $wc[$k]['miw'] += $wi; |
|
713 | + } |
|
714 | + } else { |
|
715 | + //Co mot so cot co kich thuoc auto => chia deu phan du cho cac cot auto |
|
716 | + $wi = ($table['w'] - $wis) / count($list); |
|
717 | + foreach ($list as $k) { |
|
718 | + $wc[$k]['miw'] += $wi; |
|
719 | + } |
|
720 | + } |
|
721 | + } |
|
722 | + for ($i = 0; $i < $nc; $i++) { |
|
723 | + $a = $wc[$i]['miw']; |
|
724 | + unset($wc[$i]); |
|
725 | + $wc[$i] = $a; |
|
726 | + } |
|
727 | + } else { |
|
728 | + $table['w'] = $a; |
|
729 | + for ($i = 0; $i < $nc; $i++) { |
|
730 | + $a = isset($wc[$i]['w']) ? $wc[$i]['miw'] : $wc[$i]['maw']; |
|
731 | + unset($wc[$i]); |
|
732 | + $wc[$i] = $a; |
|
733 | + } |
|
734 | + } |
|
735 | + $table['w'] = array_sum($wc); |
|
736 | + } |
|
737 | 737 | |
738 | - private function _tableHeight(&$table) |
|
739 | - { |
|
740 | - $cs = &$table['cells']; |
|
741 | - $nc = $table['nc']; |
|
742 | - $nr = $table['nr']; |
|
743 | - $listspan = []; |
|
744 | - for ($i = 0; $i < $nr; $i++) { |
|
745 | - $hr = &$table['hr'][$i]; |
|
746 | - for ($j = 0; $j < $nc; $j++) { |
|
747 | - if (isset($cs[$i][$j]['miw'])) { |
|
748 | - $c = &$cs[$i][$j]; |
|
749 | - $this->_tableGetWCell($table, $i, $j); //create $c['x0'], $c['w0'] |
|
738 | + private function _tableHeight(&$table) |
|
739 | + { |
|
740 | + $cs = &$table['cells']; |
|
741 | + $nc = $table['nc']; |
|
742 | + $nr = $table['nr']; |
|
743 | + $listspan = []; |
|
744 | + for ($i = 0; $i < $nr; $i++) { |
|
745 | + $hr = &$table['hr'][$i]; |
|
746 | + for ($j = 0; $j < $nc; $j++) { |
|
747 | + if (isset($cs[$i][$j]['miw'])) { |
|
748 | + $c = &$cs[$i][$j]; |
|
749 | + $this->_tableGetWCell($table, $i, $j); //create $c['x0'], $c['w0'] |
|
750 | 750 | |
751 | - $ch = $this->_cellHeight($c); |
|
752 | - $c['ch'] = $ch; |
|
751 | + $ch = $this->_cellHeight($c); |
|
752 | + $c['ch'] = $ch; |
|
753 | 753 | |
754 | - if (isset($c['h']) && $c['h'] > $ch) { |
|
755 | - $ch = $c['h']; |
|
756 | - } |
|
754 | + if (isset($c['h']) && $c['h'] > $ch) { |
|
755 | + $ch = $c['h']; |
|
756 | + } |
|
757 | 757 | |
758 | - if (isset($c['rowspan'])) { |
|
759 | - $listspan[] = [$i, $j]; |
|
760 | - } elseif ($hr < $ch) { |
|
761 | - $hr = $ch; |
|
762 | - } |
|
763 | - $c['mih'] = $ch; |
|
764 | - } |
|
765 | - } |
|
766 | - } |
|
767 | - $hr = &$table['hr']; |
|
768 | - foreach ($listspan as $span) { |
|
769 | - list($i, $j) = $span; |
|
770 | - $c = &$cs[$i][$j]; |
|
771 | - $lr = $i + $c['rowspan']; |
|
772 | - if ($lr > $nr) { |
|
773 | - $lr = $nr; |
|
774 | - } |
|
775 | - $hs = $hsa = 0; |
|
776 | - $list = []; |
|
777 | - for ($k = $i; $k < $lr; $k++) { |
|
778 | - $hs += $hr[$k]; |
|
779 | - if (!isset($c['h'])) { |
|
780 | - $list[] = $k; |
|
781 | - $hsa += $hr[$k]; |
|
782 | - } |
|
783 | - } |
|
784 | - if ($c['mih'] > $hs) { |
|
785 | - if (!$hs) {//Cac dong chua co kich thuoc => chia deu |
|
786 | - for ($k = $i; $k < $lr; $k++) { |
|
787 | - $hr[$k] = $c['mih'] / $c['rowspan']; |
|
788 | - } |
|
789 | - } elseif (!count($list)) { |
|
790 | - //Khong co dong nao co kich thuoc auto => chia deu phan du cho tat ca |
|
791 | - $hi = $c['mih'] - $hs; |
|
792 | - for ($k = $i; $k < $lr; $k++) { |
|
793 | - $hr[$k] += ($hr[$k] / $hs) * $hi; |
|
794 | - } |
|
795 | - } else { |
|
796 | - //Co mot so dong co kich thuoc auto => chia deu phan du cho cac dong auto |
|
797 | - $hi = $c['mih'] - $hsa; |
|
798 | - foreach ($list as $k) { |
|
799 | - $hr[$k] += ($hr[$k] / $hsa) * $hi; |
|
800 | - } |
|
801 | - } |
|
802 | - } |
|
803 | - } |
|
804 | - $table['repeatH'] = 0; |
|
805 | - if (count($table['repeat'])) { |
|
806 | - foreach ($table['repeat'] as $i) { |
|
807 | - $table['repeatH'] += $hr[$i]; |
|
808 | - } |
|
809 | - } else { |
|
810 | - $table['repeat'] = 0; |
|
811 | - } |
|
812 | - $tth = 0; |
|
813 | - foreach ($hr as $v) { |
|
814 | - $tth += $v; |
|
815 | - } |
|
816 | - $table['tth'] = $tth; |
|
817 | - } |
|
758 | + if (isset($c['rowspan'])) { |
|
759 | + $listspan[] = [$i, $j]; |
|
760 | + } elseif ($hr < $ch) { |
|
761 | + $hr = $ch; |
|
762 | + } |
|
763 | + $c['mih'] = $ch; |
|
764 | + } |
|
765 | + } |
|
766 | + } |
|
767 | + $hr = &$table['hr']; |
|
768 | + foreach ($listspan as $span) { |
|
769 | + list($i, $j) = $span; |
|
770 | + $c = &$cs[$i][$j]; |
|
771 | + $lr = $i + $c['rowspan']; |
|
772 | + if ($lr > $nr) { |
|
773 | + $lr = $nr; |
|
774 | + } |
|
775 | + $hs = $hsa = 0; |
|
776 | + $list = []; |
|
777 | + for ($k = $i; $k < $lr; $k++) { |
|
778 | + $hs += $hr[$k]; |
|
779 | + if (!isset($c['h'])) { |
|
780 | + $list[] = $k; |
|
781 | + $hsa += $hr[$k]; |
|
782 | + } |
|
783 | + } |
|
784 | + if ($c['mih'] > $hs) { |
|
785 | + if (!$hs) {//Cac dong chua co kich thuoc => chia deu |
|
786 | + for ($k = $i; $k < $lr; $k++) { |
|
787 | + $hr[$k] = $c['mih'] / $c['rowspan']; |
|
788 | + } |
|
789 | + } elseif (!count($list)) { |
|
790 | + //Khong co dong nao co kich thuoc auto => chia deu phan du cho tat ca |
|
791 | + $hi = $c['mih'] - $hs; |
|
792 | + for ($k = $i; $k < $lr; $k++) { |
|
793 | + $hr[$k] += ($hr[$k] / $hs) * $hi; |
|
794 | + } |
|
795 | + } else { |
|
796 | + //Co mot so dong co kich thuoc auto => chia deu phan du cho cac dong auto |
|
797 | + $hi = $c['mih'] - $hsa; |
|
798 | + foreach ($list as $k) { |
|
799 | + $hr[$k] += ($hr[$k] / $hsa) * $hi; |
|
800 | + } |
|
801 | + } |
|
802 | + } |
|
803 | + } |
|
804 | + $table['repeatH'] = 0; |
|
805 | + if (count($table['repeat'])) { |
|
806 | + foreach ($table['repeat'] as $i) { |
|
807 | + $table['repeatH'] += $hr[$i]; |
|
808 | + } |
|
809 | + } else { |
|
810 | + $table['repeat'] = 0; |
|
811 | + } |
|
812 | + $tth = 0; |
|
813 | + foreach ($hr as $v) { |
|
814 | + $tth += $v; |
|
815 | + } |
|
816 | + $table['tth'] = $tth; |
|
817 | + } |
|
818 | 818 | |
819 | - /** |
|
820 | - * @desc Xac dinh toa do va do rong cua mot cell |
|
821 | - */ |
|
822 | - private function _tableGetWCell(&$table, $i, $j) |
|
823 | - { |
|
824 | - $c = &$table['cells'][$i][$j]; |
|
825 | - if ($c) { |
|
826 | - if (isset($c['x0'])) { |
|
827 | - return [$c['x0'], $c['w0']]; |
|
828 | - } |
|
829 | - $x = 0; |
|
830 | - $wc = &$table['wc']; |
|
831 | - for ($k = 0; $k < $j; $k++) { |
|
832 | - $x += $wc[$k]; |
|
833 | - } |
|
834 | - $w = $wc[$j]; |
|
835 | - if (isset($c['colspan'])) { |
|
836 | - for ($k = $j + $c['colspan'] - 1; $k > $j; $k--) { |
|
837 | - $w += @$wc[$k]; |
|
838 | - } |
|
839 | - } |
|
840 | - $c['x0'] = $x; |
|
841 | - $c['w0'] = $w; |
|
819 | + /** |
|
820 | + * @desc Xac dinh toa do va do rong cua mot cell |
|
821 | + */ |
|
822 | + private function _tableGetWCell(&$table, $i, $j) |
|
823 | + { |
|
824 | + $c = &$table['cells'][$i][$j]; |
|
825 | + if ($c) { |
|
826 | + if (isset($c['x0'])) { |
|
827 | + return [$c['x0'], $c['w0']]; |
|
828 | + } |
|
829 | + $x = 0; |
|
830 | + $wc = &$table['wc']; |
|
831 | + for ($k = 0; $k < $j; $k++) { |
|
832 | + $x += $wc[$k]; |
|
833 | + } |
|
834 | + $w = $wc[$j]; |
|
835 | + if (isset($c['colspan'])) { |
|
836 | + for ($k = $j + $c['colspan'] - 1; $k > $j; $k--) { |
|
837 | + $w += @$wc[$k]; |
|
838 | + } |
|
839 | + } |
|
840 | + $c['x0'] = $x; |
|
841 | + $c['w0'] = $w; |
|
842 | 842 | |
843 | - return [$x, $w]; |
|
844 | - } |
|
843 | + return [$x, $w]; |
|
844 | + } |
|
845 | 845 | |
846 | - return [0, 0]; |
|
847 | - } |
|
846 | + return [0, 0]; |
|
847 | + } |
|
848 | 848 | |
849 | - private function _tableGetHCell(&$table, $i, $j) |
|
850 | - { |
|
851 | - $c = &$table['cells'][$i][$j]; |
|
852 | - if ($c) { |
|
853 | - if (isset($c['h0'])) { |
|
854 | - return $c['h0']; |
|
855 | - } |
|
856 | - $hr = &$table['hr']; |
|
857 | - $h = $hr[$i]; |
|
858 | - if (isset($c['rowspan'])) { |
|
859 | - for ($k = $i + $c['rowspan'] - 1; $k > $i; $k--) { |
|
860 | - $h += $hr[$k]; |
|
861 | - } |
|
862 | - } |
|
863 | - $c['h0'] = $h; |
|
849 | + private function _tableGetHCell(&$table, $i, $j) |
|
850 | + { |
|
851 | + $c = &$table['cells'][$i][$j]; |
|
852 | + if ($c) { |
|
853 | + if (isset($c['h0'])) { |
|
854 | + return $c['h0']; |
|
855 | + } |
|
856 | + $hr = &$table['hr']; |
|
857 | + $h = $hr[$i]; |
|
858 | + if (isset($c['rowspan'])) { |
|
859 | + for ($k = $i + $c['rowspan'] - 1; $k > $i; $k--) { |
|
860 | + $h += $hr[$k]; |
|
861 | + } |
|
862 | + } |
|
863 | + $c['h0'] = $h; |
|
864 | 864 | |
865 | - return $h; |
|
866 | - } |
|
865 | + return $h; |
|
866 | + } |
|
867 | 867 | |
868 | - return 0; |
|
869 | - } |
|
868 | + return 0; |
|
869 | + } |
|
870 | 870 | |
871 | - private function _tableRect($x, $y, $w, $h, $type = 1) |
|
872 | - { |
|
873 | - if (strlen($type) == 4) { |
|
874 | - $x2 = $x + $w; |
|
875 | - $y2 = $y + $h; |
|
876 | - if (intval($type[0])) { |
|
877 | - $this->Line($x, $y, $x2, $y); |
|
878 | - } |
|
879 | - if (intval($type[1])) { |
|
880 | - $this->Line($x2, $y, $x2, $y2); |
|
881 | - } |
|
882 | - if (intval($type[2])) { |
|
883 | - $this->Line($x, $y2, $x2, $y2); |
|
884 | - } |
|
885 | - if (intval($type[3])) { |
|
886 | - $this->Line($x, $y, $x, $y2); |
|
887 | - } |
|
888 | - } elseif ((int) $type === 1) { |
|
889 | - $this->Rect($x, $y, $w, $h); |
|
890 | - } elseif ((int) $type > 1 && (int) $type < 11) { |
|
891 | - $width = $this->LineWidth; |
|
892 | - $this->SetLineWidth($type * $this->LineWidth); |
|
893 | - $this->Rect($x, $y, $w, $h); |
|
894 | - $this->SetLineWidth($width); |
|
895 | - } |
|
896 | - } |
|
871 | + private function _tableRect($x, $y, $w, $h, $type = 1) |
|
872 | + { |
|
873 | + if (strlen($type) == 4) { |
|
874 | + $x2 = $x + $w; |
|
875 | + $y2 = $y + $h; |
|
876 | + if (intval($type[0])) { |
|
877 | + $this->Line($x, $y, $x2, $y); |
|
878 | + } |
|
879 | + if (intval($type[1])) { |
|
880 | + $this->Line($x2, $y, $x2, $y2); |
|
881 | + } |
|
882 | + if (intval($type[2])) { |
|
883 | + $this->Line($x, $y2, $x2, $y2); |
|
884 | + } |
|
885 | + if (intval($type[3])) { |
|
886 | + $this->Line($x, $y, $x, $y2); |
|
887 | + } |
|
888 | + } elseif ((int) $type === 1) { |
|
889 | + $this->Rect($x, $y, $w, $h); |
|
890 | + } elseif ((int) $type > 1 && (int) $type < 11) { |
|
891 | + $width = $this->LineWidth; |
|
892 | + $this->SetLineWidth($type * $this->LineWidth); |
|
893 | + $this->Rect($x, $y, $w, $h); |
|
894 | + $this->SetLineWidth($width); |
|
895 | + } |
|
896 | + } |
|
897 | 897 | |
898 | - private function _tableDrawBorder(&$table) |
|
899 | - { |
|
900 | - //When fill a cell, it overwrite the border of prevous cell, then I have to draw border at the end |
|
901 | - foreach ($table['listborder'] as $c) { |
|
902 | - list($x, $y, $w, $h, $s) = $c; |
|
903 | - $this->_tableRect($x, $y, $w, $h, $s); |
|
904 | - } |
|
898 | + private function _tableDrawBorder(&$table) |
|
899 | + { |
|
900 | + //When fill a cell, it overwrite the border of prevous cell, then I have to draw border at the end |
|
901 | + foreach ($table['listborder'] as $c) { |
|
902 | + list($x, $y, $w, $h, $s) = $c; |
|
903 | + $this->_tableRect($x, $y, $w, $h, $s); |
|
904 | + } |
|
905 | 905 | |
906 | - $table['listborder'] = []; |
|
907 | - } |
|
906 | + $table['listborder'] = []; |
|
907 | + } |
|
908 | 908 | |
909 | - private function _getRowHeight(&$table, $i) |
|
910 | - { |
|
911 | - $maxh = 0; |
|
912 | - for ($j = 0; $j < $table['nc']; $j++) { |
|
913 | - $h = $this->_tableGetHCell($table, $i, $j); |
|
914 | - if ($maxh < $h) { |
|
915 | - $maxh = $h; |
|
916 | - } |
|
917 | - } |
|
909 | + private function _getRowHeight(&$table, $i) |
|
910 | + { |
|
911 | + $maxh = 0; |
|
912 | + for ($j = 0; $j < $table['nc']; $j++) { |
|
913 | + $h = $this->_tableGetHCell($table, $i, $j); |
|
914 | + if ($maxh < $h) { |
|
915 | + $maxh = $h; |
|
916 | + } |
|
917 | + } |
|
918 | 918 | |
919 | - return $maxh; |
|
920 | - } |
|
919 | + return $maxh; |
|
920 | + } |
|
921 | 921 | |
922 | - private function _checkLimitHeight(&$table, $maxh) |
|
923 | - { |
|
924 | - if ($maxh + $table['repeatH'] > $this->height) { |
|
925 | - $msg = 'Height of this row is greater than page height!'; |
|
926 | - $this->SetFillColor(255, 0, 0); |
|
927 | - $h = $this->bottom - $table['lasty']; |
|
928 | - $this->Rect($this->x, $this->y = $table['lasty'], $table['w'], $h, 'F'); |
|
929 | - $this->MultiCell($table['w'], $h, $msg); |
|
930 | - $table['lasty'] += $h; |
|
922 | + private function _checkLimitHeight(&$table, $maxh) |
|
923 | + { |
|
924 | + if ($maxh + $table['repeatH'] > $this->height) { |
|
925 | + $msg = 'Height of this row is greater than page height!'; |
|
926 | + $this->SetFillColor(255, 0, 0); |
|
927 | + $h = $this->bottom - $table['lasty']; |
|
928 | + $this->Rect($this->x, $this->y = $table['lasty'], $table['w'], $h, 'F'); |
|
929 | + $this->MultiCell($table['w'], $h, $msg); |
|
930 | + $table['lasty'] += $h; |
|
931 | 931 | |
932 | - return 1; |
|
933 | - } |
|
932 | + return 1; |
|
933 | + } |
|
934 | 934 | |
935 | - return 0; |
|
936 | - } |
|
935 | + return 0; |
|
936 | + } |
|
937 | 937 | |
938 | - private function _tableWriteRow(&$table, $i, $x0) |
|
939 | - { |
|
940 | - $maxh = $this->_getRowHeight($table, $i); |
|
941 | - if ($table['multipage']) { |
|
942 | - $newpage = 0; |
|
943 | - if ($table['lasty'] + $maxh > $this->bottom) { |
|
944 | - if ($this->_checkLimitHeight($table, $maxh)) { |
|
945 | - return; |
|
946 | - } |
|
947 | - $newpage = 1; |
|
948 | - } elseif (isset($table['pbr'][$i])) { |
|
949 | - $newpage = 1; |
|
950 | - unset($table['pbr'][$i]); |
|
951 | - } elseif (isset($table['knext'][$i]) && $i < $table['nr'] - 1) { |
|
952 | - $mrowh = $maxh; |
|
953 | - for ($j = $i + 1; $j < $table['nr']; $j++) { |
|
954 | - $mrowh += $this->_getRowHeight($table, $j); |
|
955 | - if (!isset($table['knext'][$j])) { |
|
956 | - break; |
|
957 | - } |
|
958 | - unset($table['knext'][$j]); |
|
959 | - } |
|
960 | - if ($this->_checkLimitHeight($table, $mrowh)) { |
|
961 | - return; |
|
962 | - } |
|
963 | - $newpage = $table['lasty'] + $mrowh > $this->bottom; |
|
964 | - } |
|
965 | - if ($newpage) { |
|
966 | - $this->_tableDrawBorder($table); |
|
967 | - $this->AddPage($this->CurOrientation); |
|
938 | + private function _tableWriteRow(&$table, $i, $x0) |
|
939 | + { |
|
940 | + $maxh = $this->_getRowHeight($table, $i); |
|
941 | + if ($table['multipage']) { |
|
942 | + $newpage = 0; |
|
943 | + if ($table['lasty'] + $maxh > $this->bottom) { |
|
944 | + if ($this->_checkLimitHeight($table, $maxh)) { |
|
945 | + return; |
|
946 | + } |
|
947 | + $newpage = 1; |
|
948 | + } elseif (isset($table['pbr'][$i])) { |
|
949 | + $newpage = 1; |
|
950 | + unset($table['pbr'][$i]); |
|
951 | + } elseif (isset($table['knext'][$i]) && $i < $table['nr'] - 1) { |
|
952 | + $mrowh = $maxh; |
|
953 | + for ($j = $i + 1; $j < $table['nr']; $j++) { |
|
954 | + $mrowh += $this->_getRowHeight($table, $j); |
|
955 | + if (!isset($table['knext'][$j])) { |
|
956 | + break; |
|
957 | + } |
|
958 | + unset($table['knext'][$j]); |
|
959 | + } |
|
960 | + if ($this->_checkLimitHeight($table, $mrowh)) { |
|
961 | + return; |
|
962 | + } |
|
963 | + $newpage = $table['lasty'] + $mrowh > $this->bottom; |
|
964 | + } |
|
965 | + if ($newpage) { |
|
966 | + $this->_tableDrawBorder($table); |
|
967 | + $this->AddPage($this->CurOrientation); |
|
968 | 968 | |
969 | - $table['lasty'] = $this->y; |
|
970 | - if ($table['repeat']) { |
|
971 | - foreach ($table['repeat'] as $r) { |
|
972 | - if ($r == $i) { |
|
973 | - continue; |
|
974 | - } |
|
975 | - $this->_tableWriteRow($table, $r, $x0); |
|
976 | - } |
|
977 | - } |
|
978 | - } |
|
979 | - } |
|
980 | - $y = $table['lasty']; |
|
981 | - for ($j = 0; $j < $table['nc']; $j++) { |
|
982 | - if (isset($table['cells'][$i][$j]['miw'])) { |
|
983 | - $c = &$table['cells'][$i][$j]; |
|
984 | - list($x, $w) = $this->_tableGetWCell($table, $i, $j); |
|
985 | - $h = $this->_tableGetHCell($table, $i, $j); |
|
986 | - $x += $x0; |
|
969 | + $table['lasty'] = $this->y; |
|
970 | + if ($table['repeat']) { |
|
971 | + foreach ($table['repeat'] as $r) { |
|
972 | + if ($r == $i) { |
|
973 | + continue; |
|
974 | + } |
|
975 | + $this->_tableWriteRow($table, $r, $x0); |
|
976 | + } |
|
977 | + } |
|
978 | + } |
|
979 | + } |
|
980 | + $y = $table['lasty']; |
|
981 | + for ($j = 0; $j < $table['nc']; $j++) { |
|
982 | + if (isset($table['cells'][$i][$j]['miw'])) { |
|
983 | + $c = &$table['cells'][$i][$j]; |
|
984 | + list($x, $w) = $this->_tableGetWCell($table, $i, $j); |
|
985 | + $h = $this->_tableGetHCell($table, $i, $j); |
|
986 | + $x += $x0; |
|
987 | 987 | |
988 | - //Fill |
|
989 | - $fill = isset($c['bgcolor']) ? $c['bgcolor'] |
|
990 | - : (isset($table['bgcolor'][$i]) ? $table['bgcolor'][$i] |
|
991 | - : (isset($table['bgcolor'][-1]) ? $table['bgcolor'][-1] : 0)); |
|
992 | - if ($fill) { |
|
993 | - $color = Color::HEX2RGB($fill); |
|
994 | - $this->SetFillColor($color[0], $color[1], $color[2]); |
|
995 | - $this->Rect($x, $y, $w, $h, 'F'); |
|
996 | - } |
|
997 | - //Content |
|
998 | - if (isset($c['img'])) { |
|
999 | - $this->Image($c['img'], $x, $y, $c['w'], $c['h']); |
|
1000 | - } else { |
|
1001 | - $this->_drawCellAligned($x, $y, $c); |
|
1002 | - } |
|
1003 | - //Border |
|
1004 | - if (isset($c['border'])) { |
|
1005 | - $table['listborder'][] = [$x, $y, $w, $h, $c['border']]; |
|
1006 | - } elseif (isset($table['border']) && $table['border']) { |
|
1007 | - $table['listborder'][] = [$x, $y, $w, $h, $table['border']]; |
|
1008 | - } |
|
1009 | - } |
|
1010 | - } |
|
1011 | - $table['lasty'] += $table['hr'][$i]; |
|
1012 | - $this->y = $table['lasty']; |
|
1013 | - } |
|
988 | + //Fill |
|
989 | + $fill = isset($c['bgcolor']) ? $c['bgcolor'] |
|
990 | + : (isset($table['bgcolor'][$i]) ? $table['bgcolor'][$i] |
|
991 | + : (isset($table['bgcolor'][-1]) ? $table['bgcolor'][-1] : 0)); |
|
992 | + if ($fill) { |
|
993 | + $color = Color::HEX2RGB($fill); |
|
994 | + $this->SetFillColor($color[0], $color[1], $color[2]); |
|
995 | + $this->Rect($x, $y, $w, $h, 'F'); |
|
996 | + } |
|
997 | + //Content |
|
998 | + if (isset($c['img'])) { |
|
999 | + $this->Image($c['img'], $x, $y, $c['w'], $c['h']); |
|
1000 | + } else { |
|
1001 | + $this->_drawCellAligned($x, $y, $c); |
|
1002 | + } |
|
1003 | + //Border |
|
1004 | + if (isset($c['border'])) { |
|
1005 | + $table['listborder'][] = [$x, $y, $w, $h, $c['border']]; |
|
1006 | + } elseif (isset($table['border']) && $table['border']) { |
|
1007 | + $table['listborder'][] = [$x, $y, $w, $h, $table['border']]; |
|
1008 | + } |
|
1009 | + } |
|
1010 | + } |
|
1011 | + $table['lasty'] += $table['hr'][$i]; |
|
1012 | + $this->y = $table['lasty']; |
|
1013 | + } |
|
1014 | 1014 | |
1015 | - public function SetFont($family, $style = '', $size = 0, $default = false) |
|
1016 | - { |
|
1017 | - parent::SetFont($family, $style, $size); |
|
1018 | - if ($default || $this->isNotYetSetFont) { |
|
1019 | - $this->defaultFontFamily = $family; |
|
1020 | - $this->defaultFontSize = $size; |
|
1021 | - $this->defaultFontStyle = $style; |
|
1022 | - $this->isNotYetSetFont = false; |
|
1023 | - } |
|
1024 | - } |
|
1015 | + public function SetFont($family, $style = '', $size = 0, $default = false) |
|
1016 | + { |
|
1017 | + parent::SetFont($family, $style, $size); |
|
1018 | + if ($default || $this->isNotYetSetFont) { |
|
1019 | + $this->defaultFontFamily = $family; |
|
1020 | + $this->defaultFontSize = $size; |
|
1021 | + $this->defaultFontStyle = $style; |
|
1022 | + $this->isNotYetSetFont = false; |
|
1023 | + } |
|
1024 | + } |
|
1025 | 1025 | |
1026 | - private function _setFontText(&$f) |
|
1027 | - { |
|
1028 | - if (isset($f['size']) && ($f['size'] > 0)) { |
|
1029 | - $fontSize = $f['size']; |
|
1030 | - } else { |
|
1031 | - $fontSize = $this->defaultFontSize; |
|
1032 | - } |
|
1033 | - if (isset($f['family'])) { |
|
1034 | - $fontFamily = $f['family']; |
|
1035 | - } else { |
|
1036 | - $fontFamily = $this->defaultFontFamily; |
|
1037 | - } |
|
1038 | - if (isset($f['style'])) { |
|
1039 | - $fontStyle = $f['style']; |
|
1040 | - } else { |
|
1041 | - $fontStyle = $this->defaultFontStyle; |
|
1042 | - } |
|
1043 | - $this->SetFont($fontFamily, $fontStyle, $fontSize); |
|
1026 | + private function _setFontText(&$f) |
|
1027 | + { |
|
1028 | + if (isset($f['size']) && ($f['size'] > 0)) { |
|
1029 | + $fontSize = $f['size']; |
|
1030 | + } else { |
|
1031 | + $fontSize = $this->defaultFontSize; |
|
1032 | + } |
|
1033 | + if (isset($f['family'])) { |
|
1034 | + $fontFamily = $f['family']; |
|
1035 | + } else { |
|
1036 | + $fontFamily = $this->defaultFontFamily; |
|
1037 | + } |
|
1038 | + if (isset($f['style'])) { |
|
1039 | + $fontStyle = $f['style']; |
|
1040 | + } else { |
|
1041 | + $fontStyle = $this->defaultFontStyle; |
|
1042 | + } |
|
1043 | + $this->SetFont($fontFamily, $fontStyle, $fontSize); |
|
1044 | 1044 | |
1045 | - return $fontSize; |
|
1046 | - } |
|
1045 | + return $fontSize; |
|
1046 | + } |
|
1047 | 1047 | |
1048 | - private function _tableWrite(&$table) |
|
1049 | - { |
|
1050 | - if ($this->CurOrientation == 'P' && $table['w'] > $this->width + 5) { |
|
1051 | - $this->AddPage('L'); |
|
1052 | - } |
|
1053 | - if ($this->x == null) { |
|
1054 | - $this->x = $this->lMargin; |
|
1055 | - } |
|
1056 | - if ($this->y == null) { |
|
1057 | - $this->y = $this->tMargin; |
|
1058 | - } |
|
1059 | - $x0 = $this->x; |
|
1060 | - $y0 = $this->y; |
|
1061 | - if (isset($table['a'])) { |
|
1062 | - if ($table['a'] == 'C') { |
|
1063 | - $x0 += (($this->right - $x0) - $table['w']) / 2; |
|
1064 | - } elseif ($table['a'] == 'R') { |
|
1065 | - $x0 = $this->right - $table['w']; |
|
1066 | - } |
|
1067 | - } |
|
1068 | - if (isset($table['nobreak']) && $table['nobreak'] |
|
1069 | - && $table['tth'] + $y0 > $this->bottom && $table['multipage']) { |
|
1070 | - $this->AddPage($this->CurOrientation); |
|
1071 | - $table['lasty'] = $this->y; |
|
1072 | - } else { |
|
1073 | - $table['lasty'] = $y0; |
|
1074 | - } |
|
1048 | + private function _tableWrite(&$table) |
|
1049 | + { |
|
1050 | + if ($this->CurOrientation == 'P' && $table['w'] > $this->width + 5) { |
|
1051 | + $this->AddPage('L'); |
|
1052 | + } |
|
1053 | + if ($this->x == null) { |
|
1054 | + $this->x = $this->lMargin; |
|
1055 | + } |
|
1056 | + if ($this->y == null) { |
|
1057 | + $this->y = $this->tMargin; |
|
1058 | + } |
|
1059 | + $x0 = $this->x; |
|
1060 | + $y0 = $this->y; |
|
1061 | + if (isset($table['a'])) { |
|
1062 | + if ($table['a'] == 'C') { |
|
1063 | + $x0 += (($this->right - $x0) - $table['w']) / 2; |
|
1064 | + } elseif ($table['a'] == 'R') { |
|
1065 | + $x0 = $this->right - $table['w']; |
|
1066 | + } |
|
1067 | + } |
|
1068 | + if (isset($table['nobreak']) && $table['nobreak'] |
|
1069 | + && $table['tth'] + $y0 > $this->bottom && $table['multipage']) { |
|
1070 | + $this->AddPage($this->CurOrientation); |
|
1071 | + $table['lasty'] = $this->y; |
|
1072 | + } else { |
|
1073 | + $table['lasty'] = $y0; |
|
1074 | + } |
|
1075 | 1075 | |
1076 | - $table['listborder'] = []; |
|
1077 | - for ($i = 0; $i < $table['nr']; $i++) { |
|
1078 | - $this->_tableWriteRow($table, $i, $x0); |
|
1079 | - } |
|
1080 | - $this->_tableDrawBorder($table); |
|
1081 | - $this->x = $x0; |
|
1082 | - } |
|
1076 | + $table['listborder'] = []; |
|
1077 | + for ($i = 0; $i < $table['nr']; $i++) { |
|
1078 | + $this->_tableWriteRow($table, $i, $x0); |
|
1079 | + } |
|
1080 | + $this->_tableDrawBorder($table); |
|
1081 | + $this->x = $x0; |
|
1082 | + } |
|
1083 | 1083 | |
1084 | - public function htmltable(&$html, $multipage = 1) |
|
1085 | - { |
|
1086 | - $a = $this->AutoPageBreak; |
|
1087 | - $this->SetAutoPageBreak(0, $this->bMargin); |
|
1088 | - $HTML = explode('<table', $html); |
|
1089 | - $oldMargin = $this->cMargin; |
|
1090 | - $this->cMargin = 0; |
|
1091 | - $x = $this->x; |
|
1092 | - foreach ($HTML as $i=>$table) { |
|
1093 | - $this->x = $x; |
|
1094 | - if (strlen($table) < 6) { |
|
1095 | - continue; |
|
1096 | - } |
|
1097 | - $table = '<table'.$table; |
|
1098 | - $table = $this->_tableParser($table); |
|
1099 | - $table['multipage'] = $multipage; |
|
1100 | - $this->_tableColumnWidth($table); |
|
1101 | - $this->_tableWidth($table); |
|
1102 | - $this->_tableHeight($table); |
|
1103 | - $this->_tableWrite($table); |
|
1104 | - } |
|
1105 | - $this->cMargin = $oldMargin; |
|
1106 | - $this->SetAutoPageBreak($a, $this->bMargin); |
|
1107 | - } |
|
1084 | + public function htmltable(&$html, $multipage = 1) |
|
1085 | + { |
|
1086 | + $a = $this->AutoPageBreak; |
|
1087 | + $this->SetAutoPageBreak(0, $this->bMargin); |
|
1088 | + $HTML = explode('<table', $html); |
|
1089 | + $oldMargin = $this->cMargin; |
|
1090 | + $this->cMargin = 0; |
|
1091 | + $x = $this->x; |
|
1092 | + foreach ($HTML as $i=>$table) { |
|
1093 | + $this->x = $x; |
|
1094 | + if (strlen($table) < 6) { |
|
1095 | + continue; |
|
1096 | + } |
|
1097 | + $table = '<table'.$table; |
|
1098 | + $table = $this->_tableParser($table); |
|
1099 | + $table['multipage'] = $multipage; |
|
1100 | + $this->_tableColumnWidth($table); |
|
1101 | + $this->_tableWidth($table); |
|
1102 | + $this->_tableHeight($table); |
|
1103 | + $this->_tableWrite($table); |
|
1104 | + } |
|
1105 | + $this->cMargin = $oldMargin; |
|
1106 | + $this->SetAutoPageBreak($a, $this->bMargin); |
|
1107 | + } |
|
1108 | 1108 | |
1109 | - public function _putinfo() |
|
1110 | - { |
|
1111 | - $this->_out('/Producer '.$this->_textstring('PDFTable '. |
|
1112 | - PDFTABLE_VERSION.' based on FPDF '.FPDF_VERSION)); |
|
1113 | - if (!empty($this->title)) { |
|
1114 | - $this->_out('/Title '.$this->_textstring($this->title)); |
|
1115 | - } |
|
1116 | - if (!empty($this->subject)) { |
|
1117 | - $this->_out('/Subject '.$this->_textstring($this->subject)); |
|
1118 | - } |
|
1119 | - if (!empty($this->author)) { |
|
1120 | - $this->_out('/Author '.$this->_textstring($this->author)); |
|
1121 | - } |
|
1122 | - if (!empty($this->keywords)) { |
|
1123 | - $this->_out('/Keywords '.$this->_textstring($this->keywords)); |
|
1124 | - } |
|
1125 | - if (!empty($this->creator)) { |
|
1126 | - $this->_out('/Creator '.$this->_textstring($this->creator)); |
|
1127 | - } |
|
1128 | - $this->_out('/CreationDate '.$this->_textstring('D:'.@date('YmdHis'))); |
|
1129 | - } |
|
1109 | + public function _putinfo() |
|
1110 | + { |
|
1111 | + $this->_out('/Producer '.$this->_textstring('PDFTable '. |
|
1112 | + PDFTABLE_VERSION.' based on FPDF '.FPDF_VERSION)); |
|
1113 | + if (!empty($this->title)) { |
|
1114 | + $this->_out('/Title '.$this->_textstring($this->title)); |
|
1115 | + } |
|
1116 | + if (!empty($this->subject)) { |
|
1117 | + $this->_out('/Subject '.$this->_textstring($this->subject)); |
|
1118 | + } |
|
1119 | + if (!empty($this->author)) { |
|
1120 | + $this->_out('/Author '.$this->_textstring($this->author)); |
|
1121 | + } |
|
1122 | + if (!empty($this->keywords)) { |
|
1123 | + $this->_out('/Keywords '.$this->_textstring($this->keywords)); |
|
1124 | + } |
|
1125 | + if (!empty($this->creator)) { |
|
1126 | + $this->_out('/Creator '.$this->_textstring($this->creator)); |
|
1127 | + } |
|
1128 | + $this->_out('/CreationDate '.$this->_textstring('D:'.@date('YmdHis'))); |
|
1129 | + } |
|
1130 | 1130 | |
1131 | - private function getAlign($v) |
|
1132 | - { |
|
1133 | - global $PDF_ALIGN; |
|
1134 | - $v = strtolower($v); |
|
1131 | + private function getAlign($v) |
|
1132 | + { |
|
1133 | + global $PDF_ALIGN; |
|
1134 | + $v = strtolower($v); |
|
1135 | 1135 | |
1136 | - return isset($PDF_ALIGN[$v]) ? $PDF_ALIGN[$v] : 'L'; |
|
1137 | - } |
|
1136 | + return isset($PDF_ALIGN[$v]) ? $PDF_ALIGN[$v] : 'L'; |
|
1137 | + } |
|
1138 | 1138 | |
1139 | - private function getVAlign($v) |
|
1140 | - { |
|
1141 | - global $PDF_VALIGN; |
|
1142 | - $v = strtolower($v); |
|
1139 | + private function getVAlign($v) |
|
1140 | + { |
|
1141 | + global $PDF_VALIGN; |
|
1142 | + $v = strtolower($v); |
|
1143 | 1143 | |
1144 | - return isset($PDF_VALIGN[$v]) ? $PDF_VALIGN[$v] : 'T'; |
|
1145 | - } |
|
1144 | + return isset($PDF_VALIGN[$v]) ? $PDF_VALIGN[$v] : 'T'; |
|
1145 | + } |
|
1146 | 1146 | }//PDFTable |
@@ -310,154 +310,154 @@ |
||
310 | 310 | continue; |
311 | 311 | } |
312 | 312 | switch ($element) { |
313 | - case 'table': |
|
314 | - $tdopen = 0; |
|
315 | - $a = &$t->attribute[$i]; |
|
316 | - if (isset($a['width'])) { |
|
317 | - $table['w'] = $this->_calWidth($a['width']); |
|
318 | - } |
|
319 | - if (isset($a['height'])) { |
|
320 | - $table['h'] = intval($a['height']); |
|
321 | - } |
|
322 | - if (isset($a['align'])) { |
|
323 | - $table['a'] = $this->getAlign(strtolower($a['align'])); |
|
324 | - } |
|
325 | - $table['border'] = (isset($a['border'])) ? $a['border'] : 0; |
|
326 | - if (isset($a['bgcolor'])) { |
|
327 | - $table['bgcolor'][-1] = $a['bgcolor']; |
|
328 | - } |
|
329 | - $table['nobreak'] = isset($a['nobreak']); |
|
330 | - break; |
|
331 | - case 'tr': |
|
332 | - $tdopen = 0; |
|
333 | - $row++; |
|
334 | - $table['nr']++; |
|
335 | - $col = -1; |
|
336 | - $a = &$t->attribute[$i]; |
|
337 | - if (isset($a['bgcolor'])) { |
|
338 | - $table['bgcolor'][$row] = $a['bgcolor']; |
|
339 | - } |
|
340 | - if (isset($a['repeat'])) { |
|
341 | - $table['repeat'][] = $row; |
|
342 | - } else { |
|
343 | - if (isset($a['pbr'])) { |
|
344 | - $table['pbr'][$row] = 1; |
|
345 | - } |
|
346 | - if (isset($a['knext'])) { |
|
347 | - $table['knext'][$row] = 1; |
|
348 | - } |
|
349 | - } |
|
350 | - break; |
|
351 | - case 'td': |
|
352 | - $tdopen = 1; |
|
353 | - $col++; while (isset($cell[$row][$col])) { |
|
354 | - $col++; |
|
355 | - } |
|
356 | - //Update number column |
|
357 | - if ($table['nc'] < $col + 1) { |
|
358 | - $table['nc'] = $col + 1; |
|
359 | - } |
|
360 | - $cell[$row][$col] = []; |
|
361 | - $c = &$cell[$row][$col]; |
|
362 | - $a = &$t->attribute[$i]; |
|
363 | - if (isset($a['width'])) { |
|
364 | - $c['w'] = intval($a['width']); |
|
365 | - } |
|
366 | - if (isset($a['height'])) { |
|
367 | - $c['h'] = intval($a['height']); |
|
368 | - } |
|
369 | - $c['a'] = isset($a['align']) ? $this->getAlign($a['align']) : 'L'; |
|
370 | - $c['va'] = isset($a['valign']) ? $this->getVAlign($a['valign']) : 'T'; |
|
371 | - if (isset($a['border'])) { |
|
372 | - $c['border'] = $a['border']; |
|
373 | - } else { |
|
374 | - $c['border'] = $table['border']; |
|
375 | - } |
|
376 | - if (isset($a['bgcolor'])) { |
|
377 | - $c['bgcolor'] = $a['bgcolor']; |
|
378 | - } |
|
379 | - $cs = $rs = 1; |
|
380 | - if (isset($a['colspan']) && $a['colspan'] > 1) { |
|
381 | - $cs = $c['colspan'] = intval($a['colspan']); |
|
382 | - } |
|
383 | - if (isset($a['rowspan']) && $a['rowspan'] > 1) { |
|
384 | - $rs = $c['rowspan'] = intval($a['rowspan']); |
|
385 | - } |
|
386 | - if (isset($a['size'])) { |
|
387 | - $c['font'][0]['size'] = $a['size']; |
|
388 | - } |
|
389 | - if (isset($a['family'])) { |
|
390 | - $c['font'][0]['family'] = $a['family']; |
|
391 | - } |
|
392 | - if (isset($a['style'])) { |
|
393 | - $STYLE = explode(',', strtoupper($a['style'])); |
|
394 | - $fontStyle = ''; |
|
395 | - foreach ($STYLE as $style) { |
|
396 | - $fontStyle .= substr(trim($style), 0, 1); |
|
397 | - } |
|
398 | - $c['font'][0]['style'] = $fontStyle; |
|
399 | - } |
|
400 | - if (isset($a['color'])) { |
|
401 | - $c['font'][0]['color'] = $a['color']; |
|
402 | - } |
|
403 | - //Chiem dung vi tri de danh cho cell span |
|
404 | - for ($k = $row; $k < $row + $rs; $k++) { |
|
405 | - for ($l = $col; $l < $col + $cs; $l++) { |
|
406 | - if ($k - $row || $l - $col) { |
|
407 | - $cell[$k][$l] = 0; |
|
408 | - } |
|
409 | - } |
|
410 | - } |
|
411 | - if (isset($a['nowrap'])) { |
|
412 | - $c['nowrap'] = 1; |
|
413 | - } |
|
414 | - $fontopen = true; |
|
415 | - if (!isset($c['font'])) { |
|
416 | - $c['font'][] = []; |
|
417 | - } |
|
418 | - break; |
|
419 | - case 'Text': |
|
420 | - $c = &$cell[$row][$col]; |
|
421 | - if (!$fontopen || !isset($c['font'])) { |
|
422 | - $c['font'][] = []; |
|
423 | - } |
|
424 | - $f = &$c['font'][count($c['font']) - 1]; |
|
425 | - $this->_setTextAndSize($c, $f, $this->_html2text($t->value[$i])); |
|
426 | - break; |
|
427 | - case 'font': |
|
428 | - $a = &$t->attribute[$i]; |
|
429 | - $c = &$cell[$row][$col]; |
|
430 | - $c['font'][] = []; |
|
431 | - $f = &$c['font'][count($c['font']) - 1]; |
|
432 | - if (isset($a['size'])) { |
|
433 | - $f['size'] = $a['size']; |
|
434 | - } |
|
435 | - if (isset($a['family'])) { |
|
436 | - $f['family'] = $a['family']; |
|
437 | - } |
|
438 | - if (isset($a['style'])) { |
|
439 | - $STYLE = explode(',', strtoupper($a['style'])); |
|
440 | - $fontStyle = ''; |
|
441 | - foreach ($STYLE as $style) { |
|
442 | - $fontStyle .= substr(trim($style), 0, 1); |
|
443 | - } |
|
444 | - $f['style'] = $fontStyle; |
|
445 | - } |
|
446 | - if (isset($a['color'])) { |
|
447 | - $f['color'] = $a['color']; |
|
448 | - } |
|
449 | - break; |
|
450 | - case 'img': |
|
451 | - $a = &$t->attribute[$i]; |
|
452 | - if (isset($a['src'])) { |
|
453 | - $this->_setImage($c, $a); |
|
454 | - } |
|
455 | - break; |
|
456 | - case 'br': |
|
457 | - $c = &$cell[$row][$col]; |
|
458 | - $cn = isset($c['font']) ? count($c['font']) - 1 : 0; |
|
459 | - $c['font'][$cn]['line'][] = 'br'; |
|
460 | - break; |
|
313 | + case 'table': |
|
314 | + $tdopen = 0; |
|
315 | + $a = &$t->attribute[$i]; |
|
316 | + if (isset($a['width'])) { |
|
317 | + $table['w'] = $this->_calWidth($a['width']); |
|
318 | + } |
|
319 | + if (isset($a['height'])) { |
|
320 | + $table['h'] = intval($a['height']); |
|
321 | + } |
|
322 | + if (isset($a['align'])) { |
|
323 | + $table['a'] = $this->getAlign(strtolower($a['align'])); |
|
324 | + } |
|
325 | + $table['border'] = (isset($a['border'])) ? $a['border'] : 0; |
|
326 | + if (isset($a['bgcolor'])) { |
|
327 | + $table['bgcolor'][-1] = $a['bgcolor']; |
|
328 | + } |
|
329 | + $table['nobreak'] = isset($a['nobreak']); |
|
330 | + break; |
|
331 | + case 'tr': |
|
332 | + $tdopen = 0; |
|
333 | + $row++; |
|
334 | + $table['nr']++; |
|
335 | + $col = -1; |
|
336 | + $a = &$t->attribute[$i]; |
|
337 | + if (isset($a['bgcolor'])) { |
|
338 | + $table['bgcolor'][$row] = $a['bgcolor']; |
|
339 | + } |
|
340 | + if (isset($a['repeat'])) { |
|
341 | + $table['repeat'][] = $row; |
|
342 | + } else { |
|
343 | + if (isset($a['pbr'])) { |
|
344 | + $table['pbr'][$row] = 1; |
|
345 | + } |
|
346 | + if (isset($a['knext'])) { |
|
347 | + $table['knext'][$row] = 1; |
|
348 | + } |
|
349 | + } |
|
350 | + break; |
|
351 | + case 'td': |
|
352 | + $tdopen = 1; |
|
353 | + $col++; while (isset($cell[$row][$col])) { |
|
354 | + $col++; |
|
355 | + } |
|
356 | + //Update number column |
|
357 | + if ($table['nc'] < $col + 1) { |
|
358 | + $table['nc'] = $col + 1; |
|
359 | + } |
|
360 | + $cell[$row][$col] = []; |
|
361 | + $c = &$cell[$row][$col]; |
|
362 | + $a = &$t->attribute[$i]; |
|
363 | + if (isset($a['width'])) { |
|
364 | + $c['w'] = intval($a['width']); |
|
365 | + } |
|
366 | + if (isset($a['height'])) { |
|
367 | + $c['h'] = intval($a['height']); |
|
368 | + } |
|
369 | + $c['a'] = isset($a['align']) ? $this->getAlign($a['align']) : 'L'; |
|
370 | + $c['va'] = isset($a['valign']) ? $this->getVAlign($a['valign']) : 'T'; |
|
371 | + if (isset($a['border'])) { |
|
372 | + $c['border'] = $a['border']; |
|
373 | + } else { |
|
374 | + $c['border'] = $table['border']; |
|
375 | + } |
|
376 | + if (isset($a['bgcolor'])) { |
|
377 | + $c['bgcolor'] = $a['bgcolor']; |
|
378 | + } |
|
379 | + $cs = $rs = 1; |
|
380 | + if (isset($a['colspan']) && $a['colspan'] > 1) { |
|
381 | + $cs = $c['colspan'] = intval($a['colspan']); |
|
382 | + } |
|
383 | + if (isset($a['rowspan']) && $a['rowspan'] > 1) { |
|
384 | + $rs = $c['rowspan'] = intval($a['rowspan']); |
|
385 | + } |
|
386 | + if (isset($a['size'])) { |
|
387 | + $c['font'][0]['size'] = $a['size']; |
|
388 | + } |
|
389 | + if (isset($a['family'])) { |
|
390 | + $c['font'][0]['family'] = $a['family']; |
|
391 | + } |
|
392 | + if (isset($a['style'])) { |
|
393 | + $STYLE = explode(',', strtoupper($a['style'])); |
|
394 | + $fontStyle = ''; |
|
395 | + foreach ($STYLE as $style) { |
|
396 | + $fontStyle .= substr(trim($style), 0, 1); |
|
397 | + } |
|
398 | + $c['font'][0]['style'] = $fontStyle; |
|
399 | + } |
|
400 | + if (isset($a['color'])) { |
|
401 | + $c['font'][0]['color'] = $a['color']; |
|
402 | + } |
|
403 | + //Chiem dung vi tri de danh cho cell span |
|
404 | + for ($k = $row; $k < $row + $rs; $k++) { |
|
405 | + for ($l = $col; $l < $col + $cs; $l++) { |
|
406 | + if ($k - $row || $l - $col) { |
|
407 | + $cell[$k][$l] = 0; |
|
408 | + } |
|
409 | + } |
|
410 | + } |
|
411 | + if (isset($a['nowrap'])) { |
|
412 | + $c['nowrap'] = 1; |
|
413 | + } |
|
414 | + $fontopen = true; |
|
415 | + if (!isset($c['font'])) { |
|
416 | + $c['font'][] = []; |
|
417 | + } |
|
418 | + break; |
|
419 | + case 'Text': |
|
420 | + $c = &$cell[$row][$col]; |
|
421 | + if (!$fontopen || !isset($c['font'])) { |
|
422 | + $c['font'][] = []; |
|
423 | + } |
|
424 | + $f = &$c['font'][count($c['font']) - 1]; |
|
425 | + $this->_setTextAndSize($c, $f, $this->_html2text($t->value[$i])); |
|
426 | + break; |
|
427 | + case 'font': |
|
428 | + $a = &$t->attribute[$i]; |
|
429 | + $c = &$cell[$row][$col]; |
|
430 | + $c['font'][] = []; |
|
431 | + $f = &$c['font'][count($c['font']) - 1]; |
|
432 | + if (isset($a['size'])) { |
|
433 | + $f['size'] = $a['size']; |
|
434 | + } |
|
435 | + if (isset($a['family'])) { |
|
436 | + $f['family'] = $a['family']; |
|
437 | + } |
|
438 | + if (isset($a['style'])) { |
|
439 | + $STYLE = explode(',', strtoupper($a['style'])); |
|
440 | + $fontStyle = ''; |
|
441 | + foreach ($STYLE as $style) { |
|
442 | + $fontStyle .= substr(trim($style), 0, 1); |
|
443 | + } |
|
444 | + $f['style'] = $fontStyle; |
|
445 | + } |
|
446 | + if (isset($a['color'])) { |
|
447 | + $f['color'] = $a['color']; |
|
448 | + } |
|
449 | + break; |
|
450 | + case 'img': |
|
451 | + $a = &$t->attribute[$i]; |
|
452 | + if (isset($a['src'])) { |
|
453 | + $this->_setImage($c, $a); |
|
454 | + } |
|
455 | + break; |
|
456 | + case 'br': |
|
457 | + $c = &$cell[$row][$col]; |
|
458 | + $cn = isset($c['font']) ? count($c['font']) - 1 : 0; |
|
459 | + $c['font'][$cn]['line'][] = 'br'; |
|
460 | + break; |
|
461 | 461 | } |
462 | 462 | } |
463 | 463 | $table['cells'] = $cell; |
@@ -16,12 +16,12 @@ discard block |
||
16 | 16 | $PDF_VALIGN = ['top'=>'T', 'middle'=>'M', 'bottom'=>'B']; |
17 | 17 | class PDFTable extends FPDF |
18 | 18 | { |
19 | - public $left; //Toa do le trai cua trang |
|
20 | -public $right; //Toa do le phai cua trang |
|
21 | -public $top; //Toa do le tren cua trang |
|
22 | -public $bottom; //Toa do le duoi cua trang |
|
23 | -public $width; //Width of writable zone of page |
|
24 | -public $height; //Height of writable zone of page |
|
19 | + public $left; //Toa do le trai cua trang |
|
20 | +public $right; //Toa do le phai cua trang |
|
21 | +public $top; //Toa do le tren cua trang |
|
22 | +public $bottom; //Toa do le duoi cua trang |
|
23 | +public $width; //Width of writable zone of page |
|
24 | +public $height; //Height of writable zone of page |
|
25 | 25 | public $defaultFontFamily; |
26 | 26 | public $defaultFontStyle; |
27 | 27 | public $defaultFontSize; |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | $c['wlinet'][$countline][0] += $t[1]; |
161 | 161 | $c['wlinet'][$countline][1]++; |
162 | 162 | $x += $t[1] + (($x > $this->paddingCell) ? $space : 0); |
163 | - } else {//auto break line |
|
163 | + }else {//auto break line |
|
164 | 164 | $h += $maxline * FHR + $this->spacingLine; |
165 | 165 | $c['hline'][] = $maxline * FHR + $this->spacingLine; |
166 | 166 | $c['wlines'][$countline] = $x - $this->paddingCell; |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | if (isset($f['color'])) { |
216 | 216 | $color = Color::HEX2RGB($f['color']); |
217 | 217 | $this->SetTextColor($color[0], $color[1], $color[2]); |
218 | - } else { |
|
218 | + }else { |
|
219 | 219 | unset($color); |
220 | 220 | } |
221 | 221 | $hl = $this->getLineHeight(); |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | $p = strpos($w, '%'); |
277 | 277 | if ($p !== false) { |
278 | 278 | return intval(substr($w, 0, $p) * $this->width / 100); |
279 | - } else { |
|
279 | + }else { |
|
280 | 280 | return intval($w); |
281 | 281 | } |
282 | 282 | } |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | } |
340 | 340 | if (isset($a['repeat'])) { |
341 | 341 | $table['repeat'][] = $row; |
342 | - } else { |
|
342 | + }else { |
|
343 | 343 | if (isset($a['pbr'])) { |
344 | 344 | $table['pbr'][$row] = 1; |
345 | 345 | } |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | $c['va'] = isset($a['valign']) ? $this->getVAlign($a['valign']) : 'T'; |
371 | 371 | if (isset($a['border'])) { |
372 | 372 | $c['border'] = $a['border']; |
373 | - } else { |
|
373 | + }else { |
|
374 | 374 | $c['border'] = $table['border']; |
375 | 375 | } |
376 | 376 | if (isset($a['bgcolor'])) { |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | $path = $a['src']; |
514 | 514 | if (!is_file($path)) { |
515 | 515 | $this->Error('Image is not exists: '.$path); |
516 | - } else { |
|
516 | + }else { |
|
517 | 517 | list($u, $d) = $this->_getResolution($path); |
518 | 518 | $c['img'] = $path; |
519 | 519 | list($c['w'], $c['h']) = getimagesize($path); |
@@ -614,7 +614,7 @@ discard block |
||
614 | 614 | if (isset($wc['w']) && $wc['w'] < $wc['miw']) { |
615 | 615 | $wc['w'] = $wc['miw']; |
616 | 616 | } |
617 | - } else { |
|
617 | + }else { |
|
618 | 618 | $listspan[] = [$i, $j]; |
619 | 619 | } |
620 | 620 | } |
@@ -652,7 +652,7 @@ discard block |
||
652 | 652 | for ($k = $j; $k < $lc; $k++) { |
653 | 653 | $wc[$k]['miw'] += ($wc[$k]['miw'] / $wis) * $wi; |
654 | 654 | } |
655 | - } else {//Co mot so cot co kich thuoc auto => chia deu phan du cho cac cot auto |
|
655 | + }else {//Co mot so cot co kich thuoc auto => chia deu phan du cho cac cot auto |
|
656 | 656 | $wi = $c['miw'] - $wis; |
657 | 657 | foreach ($list as $_z2=>$k) { |
658 | 658 | $wc[$k]['miw'] += ($wc[$k]['miw'] / $wisa) * $wi; |
@@ -669,7 +669,7 @@ discard block |
||
669 | 669 | for ($k = $j; $k < $lc; $k++) { |
670 | 670 | $wc[$k]['maw'] += ($wc[$k]['maw'] / $was) * $wi; |
671 | 671 | } |
672 | - } else {//Co mot so cot co kich thuoc auto => chia deu phan du cho cac cot auto |
|
672 | + }else {//Co mot so cot co kich thuoc auto => chia deu phan du cho cac cot auto |
|
673 | 673 | $wi = $c['maw'] - $was; |
674 | 674 | foreach ($list as $_z2=>$k) { |
675 | 675 | $wc[$k]['maw'] += ($wc[$k]['maw'] / $wasa) * $wi; |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | for ($k = 0; $k < $nc; $k++) { |
712 | 712 | $wc[$k]['miw'] += $wi; |
713 | 713 | } |
714 | - } else { |
|
714 | + }else { |
|
715 | 715 | //Co mot so cot co kich thuoc auto => chia deu phan du cho cac cot auto |
716 | 716 | $wi = ($table['w'] - $wis) / count($list); |
717 | 717 | foreach ($list as $k) { |
@@ -724,7 +724,7 @@ discard block |
||
724 | 724 | unset($wc[$i]); |
725 | 725 | $wc[$i] = $a; |
726 | 726 | } |
727 | - } else { |
|
727 | + }else { |
|
728 | 728 | $table['w'] = $a; |
729 | 729 | for ($i = 0; $i < $nc; $i++) { |
730 | 730 | $a = isset($wc[$i]['w']) ? $wc[$i]['miw'] : $wc[$i]['maw']; |
@@ -792,7 +792,7 @@ discard block |
||
792 | 792 | for ($k = $i; $k < $lr; $k++) { |
793 | 793 | $hr[$k] += ($hr[$k] / $hs) * $hi; |
794 | 794 | } |
795 | - } else { |
|
795 | + }else { |
|
796 | 796 | //Co mot so dong co kich thuoc auto => chia deu phan du cho cac dong auto |
797 | 797 | $hi = $c['mih'] - $hsa; |
798 | 798 | foreach ($list as $k) { |
@@ -806,7 +806,7 @@ discard block |
||
806 | 806 | foreach ($table['repeat'] as $i) { |
807 | 807 | $table['repeatH'] += $hr[$i]; |
808 | 808 | } |
809 | - } else { |
|
809 | + }else { |
|
810 | 810 | $table['repeat'] = 0; |
811 | 811 | } |
812 | 812 | $tth = 0; |
@@ -997,7 +997,7 @@ discard block |
||
997 | 997 | //Content |
998 | 998 | if (isset($c['img'])) { |
999 | 999 | $this->Image($c['img'], $x, $y, $c['w'], $c['h']); |
1000 | - } else { |
|
1000 | + }else { |
|
1001 | 1001 | $this->_drawCellAligned($x, $y, $c); |
1002 | 1002 | } |
1003 | 1003 | //Border |
@@ -1027,17 +1027,17 @@ discard block |
||
1027 | 1027 | { |
1028 | 1028 | if (isset($f['size']) && ($f['size'] > 0)) { |
1029 | 1029 | $fontSize = $f['size']; |
1030 | - } else { |
|
1030 | + }else { |
|
1031 | 1031 | $fontSize = $this->defaultFontSize; |
1032 | 1032 | } |
1033 | 1033 | if (isset($f['family'])) { |
1034 | 1034 | $fontFamily = $f['family']; |
1035 | - } else { |
|
1035 | + }else { |
|
1036 | 1036 | $fontFamily = $this->defaultFontFamily; |
1037 | 1037 | } |
1038 | 1038 | if (isset($f['style'])) { |
1039 | 1039 | $fontStyle = $f['style']; |
1040 | - } else { |
|
1040 | + }else { |
|
1041 | 1041 | $fontStyle = $this->defaultFontStyle; |
1042 | 1042 | } |
1043 | 1043 | $this->SetFont($fontFamily, $fontStyle, $fontSize); |
@@ -1069,7 +1069,7 @@ discard block |
||
1069 | 1069 | && $table['tth'] + $y0 > $this->bottom && $table['multipage']) { |
1070 | 1070 | $this->AddPage($this->CurOrientation); |
1071 | 1071 | $table['lasty'] = $this->y; |
1072 | - } else { |
|
1072 | + }else { |
|
1073 | 1073 | $table['lasty'] = $y0; |
1074 | 1074 | } |
1075 | 1075 |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | class FPDF |
13 | 13 | { |
14 | - public $page; //current page number |
|
14 | + public $page; //current page number |
|
15 | 15 | public $n; //current object number |
16 | 16 | public $offsets; //array of object offsets |
17 | 17 | public $buffer; //buffer holding in-memory PDF |
@@ -26,16 +26,16 @@ discard block |
||
26 | 26 | public $CurPageFormat; //current page format |
27 | 27 | public $PageSizes; //array storing non-default page sizes |
28 | 28 | public $wPt; |
29 | - public $hPt; //dimensions of current page in points |
|
30 | - public $w; |
|
31 | - public $h; //dimensions of current page in user unit |
|
29 | + public $hPt; //dimensions of current page in points |
|
30 | + public $w; |
|
31 | + public $h; //dimensions of current page in user unit |
|
32 | 32 | public $lMargin; //left margin |
33 | 33 | public $tMargin; //top margin |
34 | 34 | public $rMargin; //right margin |
35 | 35 | public $bMargin; //page break margin |
36 | 36 | public $cMargin; //cell margin |
37 | 37 | public $x; |
38 | - public $y; //current position in user unit |
|
38 | + public $y; //current position in user unit |
|
39 | 39 | public $lasth; //height of last printed cell |
40 | 40 | public $LineWidth; //line width in user unit |
41 | 41 | public $CoreFonts; //array of standard font names |
@@ -75,1714 +75,1714 @@ discard block |
||
75 | 75 | * Public methods * |
76 | 76 | * * |
77 | 77 | *******************************************************************************/ |
78 | - public function FPDF($orientation = 'P', $unit = 'mm', $format = 'A4') |
|
79 | - { |
|
80 | - //Some checks |
|
81 | - $this->_dochecks(); |
|
82 | - //Initialization of properties |
|
83 | - $this->page = 0; |
|
84 | - $this->n = 2; |
|
85 | - $this->buffer = ''; |
|
86 | - $this->pages = []; |
|
87 | - $this->PageSizes = []; |
|
88 | - $this->state = 0; |
|
89 | - $this->fonts = []; |
|
90 | - $this->FontFiles = []; |
|
91 | - $this->diffs = []; |
|
92 | - $this->images = []; |
|
93 | - $this->links = []; |
|
94 | - $this->InHeader = false; |
|
95 | - $this->InFooter = false; |
|
96 | - $this->lasth = 0; |
|
97 | - $this->FontFamily = ''; |
|
98 | - $this->FontStyle = ''; |
|
99 | - $this->FontSizePt = 12; |
|
100 | - $this->underline = false; |
|
101 | - $this->DrawColor = '0 G'; |
|
102 | - $this->FillColor = '0 g'; |
|
103 | - $this->TextColor = '0 g'; |
|
104 | - $this->ColorFlag = false; |
|
105 | - $this->ws = 0; |
|
106 | - //Standard fonts |
|
107 | - $this->CoreFonts = ['courier'=> 'Courier', 'courierB'=>'Courier-Bold', 'courierI'=>'Courier-Oblique', 'courierBI'=>'Courier-BoldOblique', |
|
108 | - 'helvetica' => 'Helvetica', 'helveticaB'=>'Helvetica-Bold', 'helveticaI'=>'Helvetica-Oblique', 'helveticaBI'=>'Helvetica-BoldOblique', |
|
109 | - 'times' => 'Times-Roman', 'timesB'=>'Times-Bold', 'timesI'=>'Times-Italic', 'timesBI'=>'Times-BoldItalic', |
|
110 | - 'symbol' => 'Symbol', 'zapfdingbats'=>'ZapfDingbats', ]; |
|
111 | - //Scale factor |
|
112 | - if ($unit == 'pt') { |
|
113 | - $this->k = 1; |
|
114 | - } elseif ($unit == 'mm') { |
|
115 | - $this->k = 72 / 25.4; |
|
116 | - } elseif ($unit == 'cm') { |
|
117 | - $this->k = 72 / 2.54; |
|
118 | - } elseif ($unit == 'in') { |
|
119 | - $this->k = 72; |
|
120 | - } else { |
|
121 | - $this->Error('Incorrect unit: '.$unit); |
|
122 | - } |
|
123 | - //Page format |
|
124 | - $this->PageFormats = ['a3'=> [841.89, 1190.55], 'a4'=>[595.28, 841.89], 'a5'=>[420.94, 595.28], |
|
125 | - 'letter' => [612, 792], 'legal'=>[612, 1008], ]; |
|
126 | - if (is_string($format)) { |
|
127 | - $format = $this->_getpageformat($format); |
|
128 | - } |
|
129 | - $this->DefPageFormat = $format; |
|
130 | - $this->CurPageFormat = $format; |
|
131 | - //Page orientation |
|
132 | - $orientation = strtolower($orientation); |
|
133 | - if ($orientation == 'p' || $orientation == 'portrait') { |
|
134 | - $this->DefOrientation = 'P'; |
|
135 | - $this->w = $this->DefPageFormat[0]; |
|
136 | - $this->h = $this->DefPageFormat[1]; |
|
137 | - } elseif ($orientation == 'l' || $orientation == 'landscape') { |
|
138 | - $this->DefOrientation = 'L'; |
|
139 | - $this->w = $this->DefPageFormat[1]; |
|
140 | - $this->h = $this->DefPageFormat[0]; |
|
141 | - } else { |
|
142 | - $this->Error('Incorrect orientation: '.$orientation); |
|
143 | - } |
|
144 | - $this->CurOrientation = $this->DefOrientation; |
|
145 | - $this->wPt = $this->w * $this->k; |
|
146 | - $this->hPt = $this->h * $this->k; |
|
147 | - //Page margins (1 cm) |
|
148 | - $margin = 28.35 / $this->k; |
|
149 | - $this->SetMargins($margin, $margin); |
|
150 | - //Interior cell margin (1 mm) |
|
151 | - $this->cMargin = $margin / 10; |
|
152 | - //Line width (0.2 mm) |
|
153 | - $this->LineWidth = .567 / $this->k; |
|
154 | - //Automatic page break |
|
155 | - $this->SetAutoPageBreak(true, 2 * $margin); |
|
156 | - //Full width display mode |
|
157 | - $this->SetDisplayMode('fullwidth'); |
|
158 | - //Enable compression |
|
159 | - $this->SetCompression(true); |
|
160 | - //Set default PDF version number |
|
161 | - $this->PDFVersion = '1.3'; |
|
162 | - } |
|
163 | - |
|
164 | - public function SetMargins($left, $top, $right = null) |
|
165 | - { |
|
166 | - //Set left, top and right margins |
|
167 | - $this->lMargin = $left; |
|
168 | - $this->tMargin = $top; |
|
169 | - if ($right === null) { |
|
170 | - $right = $left; |
|
171 | - } |
|
172 | - $this->rMargin = $right; |
|
173 | - } |
|
174 | - |
|
175 | - public function SetLeftMargin($margin) |
|
176 | - { |
|
177 | - //Set left margin |
|
178 | - $this->lMargin = $margin; |
|
179 | - if ($this->page > 0 && $this->x < $margin) { |
|
180 | - $this->x = $margin; |
|
181 | - } |
|
182 | - } |
|
183 | - |
|
184 | - public function SetTopMargin($margin) |
|
185 | - { |
|
186 | - //Set top margin |
|
187 | - $this->tMargin = $margin; |
|
188 | - } |
|
189 | - |
|
190 | - public function SetRightMargin($margin) |
|
191 | - { |
|
192 | - //Set right margin |
|
193 | - $this->rMargin = $margin; |
|
194 | - } |
|
195 | - |
|
196 | - public function SetAutoPageBreak($auto, $margin = 0) |
|
197 | - { |
|
198 | - //Set auto page break mode and triggering margin |
|
199 | - $this->AutoPageBreak = $auto; |
|
200 | - $this->bMargin = $margin; |
|
201 | - $this->PageBreakTrigger = $this->h - $margin; |
|
202 | - } |
|
203 | - |
|
204 | - public function SetDisplayMode($zoom, $layout = 'continuous') |
|
205 | - { |
|
206 | - //Set display mode in viewer |
|
207 | - if ($zoom == 'fullpage' || $zoom == 'fullwidth' || $zoom == 'real' || $zoom == 'default' || !is_string($zoom)) { |
|
208 | - $this->ZoomMode = $zoom; |
|
209 | - } else { |
|
210 | - $this->Error('Incorrect zoom display mode: '.$zoom); |
|
211 | - } |
|
212 | - if ($layout == 'single' || $layout == 'continuous' || $layout == 'two' || $layout == 'default') { |
|
213 | - $this->LayoutMode = $layout; |
|
214 | - } else { |
|
215 | - $this->Error('Incorrect layout display mode: '.$layout); |
|
216 | - } |
|
217 | - } |
|
218 | - |
|
219 | - public function SetCompression($compress) |
|
220 | - { |
|
221 | - //Set page compression |
|
222 | - if (function_exists('gzcompress')) { |
|
223 | - $this->compress = $compress; |
|
224 | - } else { |
|
225 | - $this->compress = false; |
|
226 | - } |
|
227 | - } |
|
228 | - |
|
229 | - public function SetTitle($title, $isUTF8 = false) |
|
230 | - { |
|
231 | - //Title of document |
|
232 | - if ($isUTF8) { |
|
233 | - $title = $this->_UTF8toUTF16($title); |
|
234 | - } |
|
235 | - $this->title = $title; |
|
236 | - } |
|
237 | - |
|
238 | - public function SetSubject($subject, $isUTF8 = false) |
|
239 | - { |
|
240 | - //Subject of document |
|
241 | - if ($isUTF8) { |
|
242 | - $subject = $this->_UTF8toUTF16($subject); |
|
243 | - } |
|
244 | - $this->subject = $subject; |
|
245 | - } |
|
246 | - |
|
247 | - public function SetAuthor($author, $isUTF8 = false) |
|
248 | - { |
|
249 | - //Author of document |
|
250 | - if ($isUTF8) { |
|
251 | - $author = $this->_UTF8toUTF16($author); |
|
252 | - } |
|
253 | - $this->author = $author; |
|
254 | - } |
|
255 | - |
|
256 | - public function SetKeywords($keywords, $isUTF8 = false) |
|
257 | - { |
|
258 | - //Keywords of document |
|
259 | - if ($isUTF8) { |
|
260 | - $keywords = $this->_UTF8toUTF16($keywords); |
|
261 | - } |
|
262 | - $this->keywords = $keywords; |
|
263 | - } |
|
264 | - |
|
265 | - public function SetCreator($creator, $isUTF8 = false) |
|
266 | - { |
|
267 | - //Creator of document |
|
268 | - if ($isUTF8) { |
|
269 | - $creator = $this->_UTF8toUTF16($creator); |
|
270 | - } |
|
271 | - $this->creator = $creator; |
|
272 | - } |
|
273 | - |
|
274 | - public function AliasNbPages($alias = '{nb}') |
|
275 | - { |
|
276 | - //Define an alias for total number of pages |
|
277 | - $this->AliasNbPages = $alias; |
|
278 | - } |
|
279 | - |
|
280 | - public function Error($msg) |
|
281 | - { |
|
282 | - //Fatal error |
|
283 | - die('<b>FPDF error:</b> '.$msg); |
|
284 | - } |
|
285 | - |
|
286 | - public function Open() |
|
287 | - { |
|
288 | - //Begin document |
|
289 | - $this->state = 1; |
|
290 | - } |
|
291 | - |
|
292 | - public function Close() |
|
293 | - { |
|
294 | - //Terminate document |
|
295 | - if ($this->state == 3) { |
|
296 | - return; |
|
297 | - } |
|
298 | - if ($this->page == 0) { |
|
299 | - $this->AddPage(); |
|
300 | - } |
|
301 | - //Page footer |
|
302 | - $this->InFooter = true; |
|
303 | - $this->Footer(); |
|
304 | - $this->InFooter = false; |
|
305 | - //Close page |
|
306 | - $this->_endpage(); |
|
307 | - //Close document |
|
308 | - $this->_enddoc(); |
|
309 | - } |
|
310 | - |
|
311 | - public function AddPage($orientation = '', $format = '') |
|
312 | - { |
|
313 | - //Start a new page |
|
314 | - if ($this->state == 0) { |
|
315 | - $this->Open(); |
|
316 | - } |
|
317 | - $family = $this->FontFamily; |
|
318 | - $style = $this->FontStyle.($this->underline ? 'U' : ''); |
|
319 | - $size = $this->FontSizePt; |
|
320 | - $lw = $this->LineWidth; |
|
321 | - $dc = $this->DrawColor; |
|
322 | - $fc = $this->FillColor; |
|
323 | - $tc = $this->TextColor; |
|
324 | - $cf = $this->ColorFlag; |
|
325 | - if ($this->page > 0) { |
|
326 | - //Page footer |
|
327 | - $this->InFooter = true; |
|
328 | - $this->Footer(); |
|
329 | - $this->InFooter = false; |
|
330 | - //Close page |
|
331 | - $this->_endpage(); |
|
332 | - } |
|
333 | - //Start new page |
|
334 | - $this->_beginpage($orientation, $format); |
|
335 | - //Set line cap style to square |
|
336 | - $this->_out('2 J'); |
|
337 | - //Set line width |
|
338 | - $this->LineWidth = $lw; |
|
339 | - $this->_out(sprintf('%.2F w', $lw * $this->k)); |
|
340 | - //Set font |
|
341 | - if ($family) { |
|
342 | - $this->SetFont($family, $style, $size); |
|
343 | - } |
|
344 | - //Set colors |
|
345 | - $this->DrawColor = $dc; |
|
346 | - if ($dc != '0 G') { |
|
347 | - $this->_out($dc); |
|
348 | - } |
|
349 | - $this->FillColor = $fc; |
|
350 | - if ($fc != '0 g') { |
|
351 | - $this->_out($fc); |
|
352 | - } |
|
353 | - $this->TextColor = $tc; |
|
354 | - $this->ColorFlag = $cf; |
|
355 | - //Page header |
|
356 | - $this->InHeader = true; |
|
357 | - $this->Header(); |
|
358 | - $this->InHeader = false; |
|
359 | - //Restore line width |
|
360 | - if ($this->LineWidth != $lw) { |
|
361 | - $this->LineWidth = $lw; |
|
362 | - $this->_out(sprintf('%.2F w', $lw * $this->k)); |
|
363 | - } |
|
364 | - //Restore font |
|
365 | - if ($family) { |
|
366 | - $this->SetFont($family, $style, $size); |
|
367 | - } |
|
368 | - //Restore colors |
|
369 | - if ($this->DrawColor != $dc) { |
|
370 | - $this->DrawColor = $dc; |
|
371 | - $this->_out($dc); |
|
372 | - } |
|
373 | - if ($this->FillColor != $fc) { |
|
374 | - $this->FillColor = $fc; |
|
375 | - $this->_out($fc); |
|
376 | - } |
|
377 | - $this->TextColor = $tc; |
|
378 | - $this->ColorFlag = $cf; |
|
379 | - } |
|
380 | - |
|
381 | - public function Header() |
|
382 | - { |
|
383 | - //To be implemented in your own inherited class |
|
384 | - } |
|
385 | - |
|
386 | - public function Footer() |
|
387 | - { |
|
388 | - //To be implemented in your own inherited class |
|
389 | - } |
|
390 | - |
|
391 | - public function PageNo() |
|
392 | - { |
|
393 | - //Get current page number |
|
394 | - return $this->page; |
|
395 | - } |
|
396 | - |
|
397 | - public function SetDrawColor($r, $g = null, $b = null) |
|
398 | - { |
|
399 | - //Set color for all stroking operations |
|
400 | - if (($r == 0 && $g == 0 && $b == 0) || $g === null) { |
|
401 | - $this->DrawColor = sprintf('%.3F G', $r / 255); |
|
402 | - } else { |
|
403 | - $this->DrawColor = sprintf('%.3F %.3F %.3F RG', $r / 255, $g / 255, $b / 255); |
|
404 | - } |
|
405 | - if ($this->page > 0) { |
|
406 | - $this->_out($this->DrawColor); |
|
407 | - } |
|
408 | - } |
|
409 | - |
|
410 | - public function SetFillColor($r, $g = null, $b = null) |
|
411 | - { |
|
412 | - //Set color for all filling operations |
|
413 | - if (($r == 0 && $g == 0 && $b == 0) || $g === null) { |
|
414 | - $this->FillColor = sprintf('%.3F g', $r / 255); |
|
415 | - } else { |
|
416 | - $this->FillColor = sprintf('%.3F %.3F %.3F rg', $r / 255, $g / 255, $b / 255); |
|
417 | - } |
|
418 | - $this->ColorFlag = ($this->FillColor != $this->TextColor); |
|
419 | - if ($this->page > 0) { |
|
420 | - $this->_out($this->FillColor); |
|
421 | - } |
|
422 | - } |
|
423 | - |
|
424 | - public function SetTextColor($r, $g = null, $b = null) |
|
425 | - { |
|
426 | - //Set color for text |
|
427 | - if (($r == 0 && $g == 0 && $b == 0) || $g === null) { |
|
428 | - $this->TextColor = sprintf('%.3F g', $r / 255); |
|
429 | - } else { |
|
430 | - $this->TextColor = sprintf('%.3F %.3F %.3F rg', $r / 255, $g / 255, $b / 255); |
|
431 | - } |
|
432 | - $this->ColorFlag = ($this->FillColor != $this->TextColor); |
|
433 | - } |
|
434 | - |
|
435 | - public function GetStringWidth($s) |
|
436 | - { |
|
437 | - //Get width of a string in the current font |
|
438 | - $s = (string) $s; |
|
439 | - $cw = &$this->CurrentFont['cw']; |
|
440 | - $w = 0; |
|
441 | - $l = strlen($s); |
|
442 | - for ($i = 0; $i < $l; $i++) { |
|
443 | - $w += $cw[$s[$i]]; |
|
444 | - } |
|
445 | - |
|
446 | - return $w * $this->FontSize / 1000; |
|
447 | - } |
|
448 | - |
|
449 | - public function SetLineWidth($width) |
|
450 | - { |
|
451 | - //Set line width |
|
452 | - $this->LineWidth = $width; |
|
453 | - if ($this->page > 0) { |
|
454 | - $this->_out(sprintf('%.2F w', $width * $this->k)); |
|
455 | - } |
|
456 | - } |
|
457 | - |
|
458 | - public function Line($x1, $y1, $x2, $y2) |
|
459 | - { |
|
460 | - //Draw a line |
|
461 | - $this->_out(sprintf('%.2F %.2F m %.2F %.2F l S', $x1 * $this->k, ($this->h - $y1) * $this->k, $x2 * $this->k, ($this->h - $y2) * $this->k)); |
|
462 | - } |
|
463 | - |
|
464 | - public function Rect($x, $y, $w, $h, $style = '') |
|
465 | - { |
|
466 | - //Draw a rectangle |
|
467 | - if ($style == 'F') { |
|
468 | - $op = 'f'; |
|
469 | - } elseif ($style == 'FD' || $style == 'DF') { |
|
470 | - $op = 'B'; |
|
471 | - } else { |
|
472 | - $op = 'S'; |
|
473 | - } |
|
474 | - $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s', $x * $this->k, ($this->h - $y) * $this->k, $w * $this->k, -$h * $this->k, $op)); |
|
475 | - } |
|
476 | - |
|
477 | - public function AddFont($family, $style = '', $file = '') |
|
478 | - { |
|
479 | - //Add a TrueType or Type1 font |
|
480 | - $family = strtolower($family); |
|
481 | - if ($file == '') { |
|
482 | - $file = str_replace(' ', '', $family).strtolower($style).'.php'; |
|
483 | - } |
|
484 | - if ($family == 'arial') { |
|
485 | - $family = 'helvetica'; |
|
486 | - } |
|
487 | - $style = strtoupper($style); |
|
488 | - if ($style == 'IB') { |
|
489 | - $style = 'BI'; |
|
490 | - } |
|
491 | - $fontkey = $family.$style; |
|
492 | - if (isset($this->fonts[$fontkey])) { |
|
493 | - return; |
|
494 | - } |
|
495 | - include $this->_getfontpath().$file; |
|
496 | - if (!isset($name)) { |
|
497 | - $this->Error('Could not include font definition file'); |
|
498 | - } |
|
499 | - $i = count($this->fonts) + 1; |
|
500 | - $this->fonts[$fontkey] = ['i'=>$i, 'type'=>$type, 'name'=>$name, 'desc'=>$desc, 'up'=>$up, 'ut'=>$ut, 'cw'=>$cw, 'enc'=>$enc, 'file'=>$file]; |
|
501 | - if ($diff) { |
|
502 | - //Search existing encodings |
|
503 | - $d = 0; |
|
504 | - $nb = count($this->diffs); |
|
505 | - for ($i = 1; $i <= $nb; $i++) { |
|
506 | - if ($this->diffs[$i] == $diff) { |
|
507 | - $d = $i; |
|
508 | - break; |
|
509 | - } |
|
510 | - } |
|
511 | - if ($d == 0) { |
|
512 | - $d = $nb + 1; |
|
513 | - $this->diffs[$d] = $diff; |
|
514 | - } |
|
515 | - $this->fonts[$fontkey]['diff'] = $d; |
|
516 | - } |
|
517 | - if ($file) { |
|
518 | - if ($type == 'TrueType') { |
|
519 | - $this->FontFiles[$file] = ['length1'=>$originalsize]; |
|
520 | - } else { |
|
521 | - $this->FontFiles[$file] = ['length1'=>$size1, 'length2'=>$size2]; |
|
522 | - } |
|
523 | - } |
|
524 | - } |
|
525 | - |
|
526 | - public function SetFont($family, $style = '', $size = 0) |
|
527 | - { |
|
528 | - //Select a font; size given in points |
|
529 | - global $fpdf_charwidths; |
|
530 | - |
|
531 | - $family = strtolower($family); |
|
532 | - if ($family == '') { |
|
533 | - $family = $this->FontFamily; |
|
534 | - } |
|
535 | - if ($family == 'arial') { |
|
536 | - $family = 'helvetica'; |
|
537 | - } elseif ($family == 'symbol' || $family == 'zapfdingbats') { |
|
538 | - $style = ''; |
|
539 | - } |
|
540 | - $style = strtoupper($style); |
|
541 | - if (strpos($style, 'U') !== false) { |
|
542 | - $this->underline = true; |
|
543 | - $style = str_replace('U', '', $style); |
|
544 | - } else { |
|
545 | - $this->underline = false; |
|
546 | - } |
|
547 | - if ($style == 'IB') { |
|
548 | - $style = 'BI'; |
|
549 | - } |
|
550 | - if ($size == 0) { |
|
551 | - $size = $this->FontSizePt; |
|
552 | - } |
|
553 | - //Test if font is already selected |
|
554 | - if ($this->FontFamily == $family && $this->FontStyle == $style && $this->FontSizePt == $size) { |
|
555 | - return; |
|
556 | - } |
|
557 | - //Test if used for the first time |
|
558 | - $fontkey = $family.$style; |
|
559 | - if (!isset($this->fonts[$fontkey])) { |
|
560 | - //Check if one of the standard fonts |
|
561 | - if (isset($this->CoreFonts[$fontkey])) { |
|
562 | - if (!isset($fpdf_charwidths[$fontkey])) { |
|
563 | - //Load metric file |
|
564 | - $file = $family; |
|
565 | - if ($family == 'times' || $family == 'helvetica') { |
|
566 | - $file .= strtolower($style); |
|
567 | - } |
|
568 | - include $this->_getfontpath().$file.'.php'; |
|
569 | - if (!isset($fpdf_charwidths[$fontkey])) { |
|
570 | - $this->Error('Could not include font metric file'); |
|
571 | - } |
|
572 | - } |
|
573 | - $i = count($this->fonts) + 1; |
|
574 | - $name = $this->CoreFonts[$fontkey]; |
|
575 | - $cw = $fpdf_charwidths[$fontkey]; |
|
576 | - $this->fonts[$fontkey] = ['i'=>$i, 'type'=>'core', 'name'=>$name, 'up'=>-100, 'ut'=>50, 'cw'=>$cw]; |
|
577 | - } else { |
|
578 | - $this->Error('Undefined font: '.$family.' '.$style); |
|
579 | - } |
|
580 | - } |
|
581 | - //Select it |
|
582 | - $this->FontFamily = $family; |
|
583 | - $this->FontStyle = $style; |
|
584 | - $this->FontSizePt = $size; |
|
585 | - $this->FontSize = $size / $this->k; |
|
586 | - $this->CurrentFont = &$this->fonts[$fontkey]; |
|
587 | - if ($this->page > 0) { |
|
588 | - $this->_out(sprintf('BT /F%d %.2F Tf ET', $this->CurrentFont['i'], $this->FontSizePt)); |
|
589 | - } |
|
590 | - } |
|
591 | - |
|
592 | - public function SetFontSize($size) |
|
593 | - { |
|
594 | - //Set font size in points |
|
595 | - if ($this->FontSizePt == $size) { |
|
596 | - return; |
|
597 | - } |
|
598 | - $this->FontSizePt = $size; |
|
599 | - $this->FontSize = $size / $this->k; |
|
600 | - if ($this->page > 0) { |
|
601 | - $this->_out(sprintf('BT /F%d %.2F Tf ET', $this->CurrentFont['i'], $this->FontSizePt)); |
|
602 | - } |
|
603 | - } |
|
604 | - |
|
605 | - public function AddLink() |
|
606 | - { |
|
607 | - //Create a new internal link |
|
608 | - $n = count($this->links) + 1; |
|
609 | - $this->links[$n] = [0, 0]; |
|
610 | - |
|
611 | - return $n; |
|
612 | - } |
|
613 | - |
|
614 | - public function SetLink($link, $y = 0, $page = -1) |
|
615 | - { |
|
616 | - //Set destination of internal link |
|
617 | - if ($y == -1) { |
|
618 | - $y = $this->y; |
|
619 | - } |
|
620 | - if ($page == -1) { |
|
621 | - $page = $this->page; |
|
622 | - } |
|
623 | - $this->links[$link] = [$page, $y]; |
|
624 | - } |
|
625 | - |
|
626 | - public function Link($x, $y, $w, $h, $link) |
|
627 | - { |
|
628 | - //Put a link on the page |
|
629 | - $this->PageLinks[$this->page][] = [$x * $this->k, $this->hPt - $y * $this->k, $w * $this->k, $h * $this->k, $link]; |
|
630 | - } |
|
631 | - |
|
632 | - public function Text($x, $y, $txt) |
|
633 | - { |
|
634 | - //Output a string |
|
635 | - $s = sprintf('BT %.2F %.2F Td (%s) Tj ET', $x * $this->k, ($this->h - $y) * $this->k, $this->_escape($txt)); |
|
636 | - if ($this->underline && $txt != '') { |
|
637 | - $s .= ' '.$this->_dounderline($x, $y, $txt); |
|
638 | - } |
|
639 | - if ($this->ColorFlag) { |
|
640 | - $s = 'q '.$this->TextColor.' '.$s.' Q'; |
|
641 | - } |
|
642 | - $this->_out($s); |
|
643 | - } |
|
644 | - |
|
645 | - public function AcceptPageBreak() |
|
646 | - { |
|
647 | - //Accept automatic page break or not |
|
648 | - return $this->AutoPageBreak; |
|
649 | - } |
|
650 | - |
|
651 | - public function Cell($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = false, $link = '') |
|
652 | - { |
|
653 | - //Output a cell |
|
654 | - $k = $this->k; |
|
655 | - if ($this->y + $h > $this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) { |
|
656 | - //Automatic page break |
|
657 | - $x = $this->x; |
|
658 | - $ws = $this->ws; |
|
659 | - if ($ws > 0) { |
|
660 | - $this->ws = 0; |
|
661 | - $this->_out('0 Tw'); |
|
662 | - } |
|
663 | - $this->AddPage($this->CurOrientation, $this->CurPageFormat); |
|
664 | - $this->x = $x; |
|
665 | - if ($ws > 0) { |
|
666 | - $this->ws = $ws; |
|
667 | - $this->_out(sprintf('%.3F Tw', $ws * $k)); |
|
668 | - } |
|
669 | - } |
|
670 | - if ($w == 0) { |
|
671 | - $w = $this->w - $this->rMargin - $this->x; |
|
672 | - } |
|
673 | - $s = ''; |
|
674 | - if ($fill || $border == 1) { |
|
675 | - if ($fill) { |
|
676 | - $op = ($border == 1) ? 'B' : 'f'; |
|
677 | - } else { |
|
678 | - $op = 'S'; |
|
679 | - } |
|
680 | - $s = sprintf('%.2F %.2F %.2F %.2F re %s ', $this->x * $k, ($this->h - $this->y) * $k, $w * $k, -$h * $k, $op); |
|
681 | - } |
|
682 | - if (is_string($border)) { |
|
683 | - $x = $this->x; |
|
684 | - $y = $this->y; |
|
685 | - if (strpos($border, 'L') !== false) { |
|
686 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', $x * $k, ($this->h - $y) * $k, $x * $k, ($this->h - ($y + $h)) * $k); |
|
687 | - } |
|
688 | - if (strpos($border, 'T') !== false) { |
|
689 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', $x * $k, ($this->h - $y) * $k, ($x + $w) * $k, ($this->h - $y) * $k); |
|
690 | - } |
|
691 | - if (strpos($border, 'R') !== false) { |
|
692 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', ($x + $w) * $k, ($this->h - $y) * $k, ($x + $w) * $k, ($this->h - ($y + $h)) * $k); |
|
693 | - } |
|
694 | - if (strpos($border, 'B') !== false) { |
|
695 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', $x * $k, ($this->h - ($y + $h)) * $k, ($x + $w) * $k, ($this->h - ($y + $h)) * $k); |
|
696 | - } |
|
697 | - } |
|
698 | - if ($txt !== '') { |
|
699 | - if ($align == 'R') { |
|
700 | - $dx = $w - $this->cMargin - $this->GetStringWidth($txt); |
|
701 | - } elseif ($align == 'C') { |
|
702 | - $dx = ($w - $this->GetStringWidth($txt)) / 2; |
|
703 | - } else { |
|
704 | - $dx = $this->cMargin; |
|
705 | - } |
|
706 | - if ($this->ColorFlag) { |
|
707 | - $s .= 'q '.$this->TextColor.' '; |
|
708 | - } |
|
709 | - $txt2 = str_replace(')', '\\)', str_replace('(', '\\(', str_replace('\\', '\\\\', $txt))); |
|
710 | - $s .= sprintf('BT %.2F %.2F Td (%s) Tj ET', ($this->x + $dx) * $k, ($this->h - ($this->y + .5 * $h + .3 * $this->FontSize)) * $k, $txt2); |
|
711 | - if ($this->underline) { |
|
712 | - $s .= ' '.$this->_dounderline($this->x + $dx, $this->y + .5 * $h + .3 * $this->FontSize, $txt); |
|
713 | - } |
|
714 | - if ($this->ColorFlag) { |
|
715 | - $s .= ' Q'; |
|
716 | - } |
|
717 | - if ($link) { |
|
718 | - $this->Link($this->x + $dx, $this->y + .5 * $h - .5 * $this->FontSize, $this->GetStringWidth($txt), $this->FontSize, $link); |
|
719 | - } |
|
720 | - } |
|
721 | - if ($s) { |
|
722 | - $this->_out($s); |
|
723 | - } |
|
724 | - $this->lasth = $h; |
|
725 | - if ($ln > 0) { |
|
726 | - //Go to next line |
|
727 | - $this->y += $h; |
|
728 | - if ($ln == 1) { |
|
729 | - $this->x = $this->lMargin; |
|
730 | - } |
|
731 | - } else { |
|
732 | - $this->x += $w; |
|
733 | - } |
|
734 | - } |
|
735 | - |
|
736 | - public function MultiCell($w, $h, $txt, $border = 0, $align = 'J', $fill = false) |
|
737 | - { |
|
738 | - //Output text with automatic or explicit line breaks |
|
739 | - $cw = &$this->CurrentFont['cw']; |
|
740 | - if ($w == 0) { |
|
741 | - $w = $this->w - $this->rMargin - $this->x; |
|
742 | - } |
|
743 | - $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; |
|
744 | - $s = str_replace("\r", '', $txt); |
|
745 | - $nb = strlen($s); |
|
746 | - if ($nb > 0 && $s[$nb - 1] == "\n") { |
|
747 | - $nb--; |
|
748 | - } |
|
749 | - $b = 0; |
|
750 | - if ($border) { |
|
751 | - if ($border == 1) { |
|
752 | - $border = 'LTRB'; |
|
753 | - $b = 'LRT'; |
|
754 | - $b2 = 'LR'; |
|
755 | - } else { |
|
756 | - $b2 = ''; |
|
757 | - if (strpos($border, 'L') !== false) { |
|
758 | - $b2 .= 'L'; |
|
759 | - } |
|
760 | - if (strpos($border, 'R') !== false) { |
|
761 | - $b2 .= 'R'; |
|
762 | - } |
|
763 | - $b = (strpos($border, 'T') !== false) ? $b2.'T' : $b2; |
|
764 | - } |
|
765 | - } |
|
766 | - $sep = -1; |
|
767 | - $i = 0; |
|
768 | - $j = 0; |
|
769 | - $l = 0; |
|
770 | - $ns = 0; |
|
771 | - $nl = 1; |
|
772 | - while ($i < $nb) { |
|
773 | - //Get next character |
|
774 | - $c = $s[$i]; |
|
775 | - if ($c == "\n") { |
|
776 | - //Explicit line break |
|
777 | - if ($this->ws > 0) { |
|
778 | - $this->ws = 0; |
|
779 | - $this->_out('0 Tw'); |
|
780 | - } |
|
781 | - $this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill); |
|
782 | - $i++; |
|
783 | - $sep = -1; |
|
784 | - $j = $i; |
|
785 | - $l = 0; |
|
786 | - $ns = 0; |
|
787 | - $nl++; |
|
788 | - if ($border && $nl == 2) { |
|
789 | - $b = $b2; |
|
790 | - } |
|
791 | - continue; |
|
792 | - } |
|
793 | - if ($c == ' ') { |
|
794 | - $sep = $i; |
|
795 | - $ls = $l; |
|
796 | - $ns++; |
|
797 | - } |
|
798 | - $l += $cw[$c]; |
|
799 | - if ($l > $wmax) { |
|
800 | - //Automatic line break |
|
801 | - if ($sep == -1) { |
|
802 | - if ($i == $j) { |
|
803 | - $i++; |
|
804 | - } |
|
805 | - if ($this->ws > 0) { |
|
806 | - $this->ws = 0; |
|
807 | - $this->_out('0 Tw'); |
|
808 | - } |
|
809 | - $this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill); |
|
810 | - } else { |
|
811 | - if ($align == 'J') { |
|
812 | - $this->ws = ($ns > 1) ? ($wmax - $ls) / 1000 * $this->FontSize / ($ns - 1) : 0; |
|
813 | - $this->_out(sprintf('%.3F Tw', $this->ws * $this->k)); |
|
814 | - } |
|
815 | - $this->Cell($w, $h, substr($s, $j, $sep - $j), $b, 2, $align, $fill); |
|
816 | - $i = $sep + 1; |
|
817 | - } |
|
818 | - $sep = -1; |
|
819 | - $j = $i; |
|
820 | - $l = 0; |
|
821 | - $ns = 0; |
|
822 | - $nl++; |
|
823 | - if ($border && $nl == 2) { |
|
824 | - $b = $b2; |
|
825 | - } |
|
826 | - } else { |
|
827 | - $i++; |
|
828 | - } |
|
829 | - } |
|
830 | - //Last chunk |
|
831 | - if ($this->ws > 0) { |
|
832 | - $this->ws = 0; |
|
833 | - $this->_out('0 Tw'); |
|
834 | - } |
|
835 | - if ($border && strpos($border, 'B') !== false) { |
|
836 | - $b .= 'B'; |
|
837 | - } |
|
838 | - $this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill); |
|
839 | - $this->x = $this->lMargin; |
|
840 | - } |
|
841 | - |
|
842 | - public function Write($h, $txt, $link = '') |
|
843 | - { |
|
844 | - //Output text in flowing mode |
|
845 | - $cw = &$this->CurrentFont['cw']; |
|
846 | - $w = $this->w - $this->rMargin - $this->x; |
|
847 | - $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; |
|
848 | - $s = str_replace("\r", '', $txt); |
|
849 | - $nb = strlen($s); |
|
850 | - $sep = -1; |
|
851 | - $i = 0; |
|
852 | - $j = 0; |
|
853 | - $l = 0; |
|
854 | - $nl = 1; |
|
855 | - while ($i < $nb) { |
|
856 | - //Get next character |
|
857 | - $c = $s[$i]; |
|
858 | - if ($c == "\n") { |
|
859 | - //Explicit line break |
|
860 | - $this->Cell($w, $h, substr($s, $j, $i - $j), 0, 2, '', 0, $link); |
|
861 | - $i++; |
|
862 | - $sep = -1; |
|
863 | - $j = $i; |
|
864 | - $l = 0; |
|
865 | - if ($nl == 1) { |
|
866 | - $this->x = $this->lMargin; |
|
867 | - $w = $this->w - $this->rMargin - $this->x; |
|
868 | - $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; |
|
869 | - } |
|
870 | - $nl++; |
|
871 | - continue; |
|
872 | - } |
|
873 | - if ($c == ' ') { |
|
874 | - $sep = $i; |
|
875 | - } |
|
876 | - $l += $cw[$c]; |
|
877 | - if ($l > $wmax) { |
|
878 | - //Automatic line break |
|
879 | - if ($sep == -1) { |
|
880 | - if ($this->x > $this->lMargin) { |
|
881 | - //Move to next line |
|
882 | - $this->x = $this->lMargin; |
|
883 | - $this->y += $h; |
|
884 | - $w = $this->w - $this->rMargin - $this->x; |
|
885 | - $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; |
|
886 | - $i++; |
|
887 | - $nl++; |
|
888 | - continue; |
|
889 | - } |
|
890 | - if ($i == $j) { |
|
891 | - $i++; |
|
892 | - } |
|
893 | - $this->Cell($w, $h, substr($s, $j, $i - $j), 0, 2, '', 0, $link); |
|
894 | - } else { |
|
895 | - $this->Cell($w, $h, substr($s, $j, $sep - $j), 0, 2, '', 0, $link); |
|
896 | - $i = $sep + 1; |
|
897 | - } |
|
898 | - $sep = -1; |
|
899 | - $j = $i; |
|
900 | - $l = 0; |
|
901 | - if ($nl == 1) { |
|
902 | - $this->x = $this->lMargin; |
|
903 | - $w = $this->w - $this->rMargin - $this->x; |
|
904 | - $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; |
|
905 | - } |
|
906 | - $nl++; |
|
907 | - } else { |
|
908 | - $i++; |
|
909 | - } |
|
910 | - } |
|
911 | - //Last chunk |
|
912 | - if ($i != $j) { |
|
913 | - $this->Cell($l / 1000 * $this->FontSize, $h, substr($s, $j), 0, 0, '', 0, $link); |
|
914 | - } |
|
915 | - } |
|
916 | - |
|
917 | - public function Ln($h = null) |
|
918 | - { |
|
919 | - //Line feed; default value is last cell height |
|
920 | - $this->x = $this->lMargin; |
|
921 | - if ($h === null) { |
|
922 | - $this->y += $this->lasth; |
|
923 | - } else { |
|
924 | - $this->y += $h; |
|
925 | - } |
|
926 | - } |
|
927 | - |
|
928 | - public function Image($file, $x = null, $y = null, $w = 0, $h = 0, $type = '', $link = '') |
|
929 | - { |
|
930 | - //Put an image on the page |
|
931 | - if (!isset($this->images[$file])) { |
|
932 | - //First use of this image, get info |
|
933 | - if ($type == '') { |
|
934 | - $pos = strrpos($file, '.'); |
|
935 | - if (!$pos) { |
|
936 | - $this->Error('Image file has no extension and no type was specified: '.$file); |
|
937 | - } |
|
938 | - $type = substr($file, $pos + 1); |
|
939 | - } |
|
940 | - $type = strtolower($type); |
|
941 | - if ($type == 'jpeg') { |
|
942 | - $type = 'jpg'; |
|
943 | - } |
|
944 | - $mtd = '_parse'.$type; |
|
945 | - if (!method_exists($this, $mtd)) { |
|
946 | - $this->Error('Unsupported image type: '.$type); |
|
947 | - } |
|
948 | - $info = $this->$mtd($file); |
|
949 | - $info['i'] = count($this->images) + 1; |
|
950 | - $this->images[$file] = $info; |
|
951 | - } else { |
|
952 | - $info = $this->images[$file]; |
|
953 | - } |
|
954 | - //Automatic width and height calculation if needed |
|
955 | - if ($w == 0 && $h == 0) { |
|
956 | - //Put image at 72 dpi |
|
957 | - $w = $info['w'] / $this->k; |
|
958 | - $h = $info['h'] / $this->k; |
|
959 | - } elseif ($w == 0) { |
|
960 | - $w = $h * $info['w'] / $info['h']; |
|
961 | - } elseif ($h == 0) { |
|
962 | - $h = $w * $info['h'] / $info['w']; |
|
963 | - } |
|
964 | - //Flowing mode |
|
965 | - if ($y === null) { |
|
966 | - if ($this->y + $h > $this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) { |
|
967 | - //Automatic page break |
|
968 | - $x2 = $this->x; |
|
969 | - $this->AddPage($this->CurOrientation, $this->CurPageFormat); |
|
970 | - $this->x = $x2; |
|
971 | - } |
|
972 | - $y = $this->y; |
|
973 | - $this->y += $h; |
|
974 | - } |
|
975 | - if ($x === null) { |
|
976 | - $x = $this->x; |
|
977 | - } |
|
978 | - $this->_out(sprintf('q %.2F 0 0 %.2F %.2F %.2F cm /I%d Do Q', $w * $this->k, $h * $this->k, $x * $this->k, ($this->h - ($y + $h)) * $this->k, $info['i'])); |
|
979 | - if ($link) { |
|
980 | - $this->Link($x, $y, $w, $h, $link); |
|
981 | - } |
|
982 | - } |
|
983 | - |
|
984 | - public function GetX() |
|
985 | - { |
|
986 | - //Get x position |
|
987 | - return $this->x; |
|
988 | - } |
|
989 | - |
|
990 | - public function SetX($x) |
|
991 | - { |
|
992 | - //Set x position |
|
993 | - if ($x >= 0) { |
|
994 | - $this->x = $x; |
|
995 | - } else { |
|
996 | - $this->x = $this->w + $x; |
|
997 | - } |
|
998 | - } |
|
999 | - |
|
1000 | - public function GetY() |
|
1001 | - { |
|
1002 | - //Get y position |
|
1003 | - return $this->y; |
|
1004 | - } |
|
1005 | - |
|
1006 | - public function SetY($y) |
|
1007 | - { |
|
1008 | - //Set y position and reset x |
|
1009 | - $this->x = $this->lMargin; |
|
1010 | - if ($y >= 0) { |
|
1011 | - $this->y = $y; |
|
1012 | - } else { |
|
1013 | - $this->y = $this->h + $y; |
|
1014 | - } |
|
1015 | - } |
|
1016 | - |
|
1017 | - public function SetXY($x, $y) |
|
1018 | - { |
|
1019 | - //Set x and y positions |
|
1020 | - $this->SetY($y); |
|
1021 | - $this->SetX($x); |
|
1022 | - } |
|
1023 | - |
|
1024 | - public function Output($name = '', $dest = '') |
|
1025 | - { |
|
1026 | - //Output PDF to some destination |
|
1027 | - if ($this->state < 3) { |
|
1028 | - $this->Close(); |
|
1029 | - } |
|
1030 | - $dest = strtoupper($dest); |
|
1031 | - if ($dest == '') { |
|
1032 | - if ($name == '') { |
|
1033 | - $name = 'doc.pdf'; |
|
1034 | - $dest = 'I'; |
|
1035 | - } else { |
|
1036 | - $dest = 'F'; |
|
1037 | - } |
|
1038 | - } |
|
1039 | - switch ($dest) { |
|
1040 | - case 'I': |
|
1041 | - //Send to standard output |
|
1042 | - if (ob_get_length()) { |
|
1043 | - $this->Error('Some data has already been output, can\'t send PDF file'); |
|
1044 | - } |
|
1045 | - if (php_sapi_name() != 'cli') { |
|
1046 | - //We send to a browser |
|
1047 | - header('Content-Type: application/pdf'); |
|
1048 | - if (headers_sent()) { |
|
1049 | - $this->Error('Some data has already been output, can\'t send PDF file'); |
|
1050 | - } |
|
1051 | - header('Content-Length: '.strlen($this->buffer)); |
|
1052 | - header('Content-Disposition: inline; filename="'.$name.'"'); |
|
1053 | - header('Cache-Control: private, max-age=0, must-revalidate'); |
|
1054 | - header('Pragma: public'); |
|
1055 | - ini_set('zlib.output_compression', '0'); |
|
1056 | - } |
|
1057 | - echo $this->buffer; |
|
1058 | - break; |
|
1059 | - case 'D': |
|
1060 | - //Download file |
|
1061 | - if (ob_get_length()) { |
|
1062 | - $this->Error('Some data has already been output, can\'t send PDF file'); |
|
1063 | - } |
|
1064 | - header('Content-Type: application/x-download'); |
|
1065 | - if (headers_sent()) { |
|
1066 | - $this->Error('Some data has already been output, can\'t send PDF file'); |
|
1067 | - } |
|
1068 | - header('Content-Length: '.strlen($this->buffer)); |
|
1069 | - header('Content-Disposition: attachment; filename="'.$name.'"'); |
|
1070 | - header('Cache-Control: private, max-age=0, must-revalidate'); |
|
1071 | - header('Pragma: public'); |
|
1072 | - ini_set('zlib.output_compression', '0'); |
|
1073 | - echo $this->buffer; |
|
1074 | - break; |
|
1075 | - case 'F': |
|
1076 | - //Save to local file |
|
1077 | - $f = fopen($name, 'wb'); |
|
1078 | - if (!$f) { |
|
1079 | - $this->Error('Unable to create output file: '.$name); |
|
1080 | - } |
|
1081 | - fwrite($f, $this->buffer, strlen($this->buffer)); |
|
1082 | - fclose($f); |
|
1083 | - break; |
|
1084 | - case 'S': |
|
1085 | - //Return as a string |
|
1086 | - return $this->buffer; |
|
1087 | - default: |
|
1088 | - $this->Error('Incorrect output destination: '.$dest); |
|
1089 | - } |
|
1090 | - |
|
1091 | - return ''; |
|
1092 | - } |
|
1093 | - |
|
1094 | - /******************************************************************************* |
|
78 | + public function FPDF($orientation = 'P', $unit = 'mm', $format = 'A4') |
|
79 | + { |
|
80 | + //Some checks |
|
81 | + $this->_dochecks(); |
|
82 | + //Initialization of properties |
|
83 | + $this->page = 0; |
|
84 | + $this->n = 2; |
|
85 | + $this->buffer = ''; |
|
86 | + $this->pages = []; |
|
87 | + $this->PageSizes = []; |
|
88 | + $this->state = 0; |
|
89 | + $this->fonts = []; |
|
90 | + $this->FontFiles = []; |
|
91 | + $this->diffs = []; |
|
92 | + $this->images = []; |
|
93 | + $this->links = []; |
|
94 | + $this->InHeader = false; |
|
95 | + $this->InFooter = false; |
|
96 | + $this->lasth = 0; |
|
97 | + $this->FontFamily = ''; |
|
98 | + $this->FontStyle = ''; |
|
99 | + $this->FontSizePt = 12; |
|
100 | + $this->underline = false; |
|
101 | + $this->DrawColor = '0 G'; |
|
102 | + $this->FillColor = '0 g'; |
|
103 | + $this->TextColor = '0 g'; |
|
104 | + $this->ColorFlag = false; |
|
105 | + $this->ws = 0; |
|
106 | + //Standard fonts |
|
107 | + $this->CoreFonts = ['courier'=> 'Courier', 'courierB'=>'Courier-Bold', 'courierI'=>'Courier-Oblique', 'courierBI'=>'Courier-BoldOblique', |
|
108 | + 'helvetica' => 'Helvetica', 'helveticaB'=>'Helvetica-Bold', 'helveticaI'=>'Helvetica-Oblique', 'helveticaBI'=>'Helvetica-BoldOblique', |
|
109 | + 'times' => 'Times-Roman', 'timesB'=>'Times-Bold', 'timesI'=>'Times-Italic', 'timesBI'=>'Times-BoldItalic', |
|
110 | + 'symbol' => 'Symbol', 'zapfdingbats'=>'ZapfDingbats', ]; |
|
111 | + //Scale factor |
|
112 | + if ($unit == 'pt') { |
|
113 | + $this->k = 1; |
|
114 | + } elseif ($unit == 'mm') { |
|
115 | + $this->k = 72 / 25.4; |
|
116 | + } elseif ($unit == 'cm') { |
|
117 | + $this->k = 72 / 2.54; |
|
118 | + } elseif ($unit == 'in') { |
|
119 | + $this->k = 72; |
|
120 | + } else { |
|
121 | + $this->Error('Incorrect unit: '.$unit); |
|
122 | + } |
|
123 | + //Page format |
|
124 | + $this->PageFormats = ['a3'=> [841.89, 1190.55], 'a4'=>[595.28, 841.89], 'a5'=>[420.94, 595.28], |
|
125 | + 'letter' => [612, 792], 'legal'=>[612, 1008], ]; |
|
126 | + if (is_string($format)) { |
|
127 | + $format = $this->_getpageformat($format); |
|
128 | + } |
|
129 | + $this->DefPageFormat = $format; |
|
130 | + $this->CurPageFormat = $format; |
|
131 | + //Page orientation |
|
132 | + $orientation = strtolower($orientation); |
|
133 | + if ($orientation == 'p' || $orientation == 'portrait') { |
|
134 | + $this->DefOrientation = 'P'; |
|
135 | + $this->w = $this->DefPageFormat[0]; |
|
136 | + $this->h = $this->DefPageFormat[1]; |
|
137 | + } elseif ($orientation == 'l' || $orientation == 'landscape') { |
|
138 | + $this->DefOrientation = 'L'; |
|
139 | + $this->w = $this->DefPageFormat[1]; |
|
140 | + $this->h = $this->DefPageFormat[0]; |
|
141 | + } else { |
|
142 | + $this->Error('Incorrect orientation: '.$orientation); |
|
143 | + } |
|
144 | + $this->CurOrientation = $this->DefOrientation; |
|
145 | + $this->wPt = $this->w * $this->k; |
|
146 | + $this->hPt = $this->h * $this->k; |
|
147 | + //Page margins (1 cm) |
|
148 | + $margin = 28.35 / $this->k; |
|
149 | + $this->SetMargins($margin, $margin); |
|
150 | + //Interior cell margin (1 mm) |
|
151 | + $this->cMargin = $margin / 10; |
|
152 | + //Line width (0.2 mm) |
|
153 | + $this->LineWidth = .567 / $this->k; |
|
154 | + //Automatic page break |
|
155 | + $this->SetAutoPageBreak(true, 2 * $margin); |
|
156 | + //Full width display mode |
|
157 | + $this->SetDisplayMode('fullwidth'); |
|
158 | + //Enable compression |
|
159 | + $this->SetCompression(true); |
|
160 | + //Set default PDF version number |
|
161 | + $this->PDFVersion = '1.3'; |
|
162 | + } |
|
163 | + |
|
164 | + public function SetMargins($left, $top, $right = null) |
|
165 | + { |
|
166 | + //Set left, top and right margins |
|
167 | + $this->lMargin = $left; |
|
168 | + $this->tMargin = $top; |
|
169 | + if ($right === null) { |
|
170 | + $right = $left; |
|
171 | + } |
|
172 | + $this->rMargin = $right; |
|
173 | + } |
|
174 | + |
|
175 | + public function SetLeftMargin($margin) |
|
176 | + { |
|
177 | + //Set left margin |
|
178 | + $this->lMargin = $margin; |
|
179 | + if ($this->page > 0 && $this->x < $margin) { |
|
180 | + $this->x = $margin; |
|
181 | + } |
|
182 | + } |
|
183 | + |
|
184 | + public function SetTopMargin($margin) |
|
185 | + { |
|
186 | + //Set top margin |
|
187 | + $this->tMargin = $margin; |
|
188 | + } |
|
189 | + |
|
190 | + public function SetRightMargin($margin) |
|
191 | + { |
|
192 | + //Set right margin |
|
193 | + $this->rMargin = $margin; |
|
194 | + } |
|
195 | + |
|
196 | + public function SetAutoPageBreak($auto, $margin = 0) |
|
197 | + { |
|
198 | + //Set auto page break mode and triggering margin |
|
199 | + $this->AutoPageBreak = $auto; |
|
200 | + $this->bMargin = $margin; |
|
201 | + $this->PageBreakTrigger = $this->h - $margin; |
|
202 | + } |
|
203 | + |
|
204 | + public function SetDisplayMode($zoom, $layout = 'continuous') |
|
205 | + { |
|
206 | + //Set display mode in viewer |
|
207 | + if ($zoom == 'fullpage' || $zoom == 'fullwidth' || $zoom == 'real' || $zoom == 'default' || !is_string($zoom)) { |
|
208 | + $this->ZoomMode = $zoom; |
|
209 | + } else { |
|
210 | + $this->Error('Incorrect zoom display mode: '.$zoom); |
|
211 | + } |
|
212 | + if ($layout == 'single' || $layout == 'continuous' || $layout == 'two' || $layout == 'default') { |
|
213 | + $this->LayoutMode = $layout; |
|
214 | + } else { |
|
215 | + $this->Error('Incorrect layout display mode: '.$layout); |
|
216 | + } |
|
217 | + } |
|
218 | + |
|
219 | + public function SetCompression($compress) |
|
220 | + { |
|
221 | + //Set page compression |
|
222 | + if (function_exists('gzcompress')) { |
|
223 | + $this->compress = $compress; |
|
224 | + } else { |
|
225 | + $this->compress = false; |
|
226 | + } |
|
227 | + } |
|
228 | + |
|
229 | + public function SetTitle($title, $isUTF8 = false) |
|
230 | + { |
|
231 | + //Title of document |
|
232 | + if ($isUTF8) { |
|
233 | + $title = $this->_UTF8toUTF16($title); |
|
234 | + } |
|
235 | + $this->title = $title; |
|
236 | + } |
|
237 | + |
|
238 | + public function SetSubject($subject, $isUTF8 = false) |
|
239 | + { |
|
240 | + //Subject of document |
|
241 | + if ($isUTF8) { |
|
242 | + $subject = $this->_UTF8toUTF16($subject); |
|
243 | + } |
|
244 | + $this->subject = $subject; |
|
245 | + } |
|
246 | + |
|
247 | + public function SetAuthor($author, $isUTF8 = false) |
|
248 | + { |
|
249 | + //Author of document |
|
250 | + if ($isUTF8) { |
|
251 | + $author = $this->_UTF8toUTF16($author); |
|
252 | + } |
|
253 | + $this->author = $author; |
|
254 | + } |
|
255 | + |
|
256 | + public function SetKeywords($keywords, $isUTF8 = false) |
|
257 | + { |
|
258 | + //Keywords of document |
|
259 | + if ($isUTF8) { |
|
260 | + $keywords = $this->_UTF8toUTF16($keywords); |
|
261 | + } |
|
262 | + $this->keywords = $keywords; |
|
263 | + } |
|
264 | + |
|
265 | + public function SetCreator($creator, $isUTF8 = false) |
|
266 | + { |
|
267 | + //Creator of document |
|
268 | + if ($isUTF8) { |
|
269 | + $creator = $this->_UTF8toUTF16($creator); |
|
270 | + } |
|
271 | + $this->creator = $creator; |
|
272 | + } |
|
273 | + |
|
274 | + public function AliasNbPages($alias = '{nb}') |
|
275 | + { |
|
276 | + //Define an alias for total number of pages |
|
277 | + $this->AliasNbPages = $alias; |
|
278 | + } |
|
279 | + |
|
280 | + public function Error($msg) |
|
281 | + { |
|
282 | + //Fatal error |
|
283 | + die('<b>FPDF error:</b> '.$msg); |
|
284 | + } |
|
285 | + |
|
286 | + public function Open() |
|
287 | + { |
|
288 | + //Begin document |
|
289 | + $this->state = 1; |
|
290 | + } |
|
291 | + |
|
292 | + public function Close() |
|
293 | + { |
|
294 | + //Terminate document |
|
295 | + if ($this->state == 3) { |
|
296 | + return; |
|
297 | + } |
|
298 | + if ($this->page == 0) { |
|
299 | + $this->AddPage(); |
|
300 | + } |
|
301 | + //Page footer |
|
302 | + $this->InFooter = true; |
|
303 | + $this->Footer(); |
|
304 | + $this->InFooter = false; |
|
305 | + //Close page |
|
306 | + $this->_endpage(); |
|
307 | + //Close document |
|
308 | + $this->_enddoc(); |
|
309 | + } |
|
310 | + |
|
311 | + public function AddPage($orientation = '', $format = '') |
|
312 | + { |
|
313 | + //Start a new page |
|
314 | + if ($this->state == 0) { |
|
315 | + $this->Open(); |
|
316 | + } |
|
317 | + $family = $this->FontFamily; |
|
318 | + $style = $this->FontStyle.($this->underline ? 'U' : ''); |
|
319 | + $size = $this->FontSizePt; |
|
320 | + $lw = $this->LineWidth; |
|
321 | + $dc = $this->DrawColor; |
|
322 | + $fc = $this->FillColor; |
|
323 | + $tc = $this->TextColor; |
|
324 | + $cf = $this->ColorFlag; |
|
325 | + if ($this->page > 0) { |
|
326 | + //Page footer |
|
327 | + $this->InFooter = true; |
|
328 | + $this->Footer(); |
|
329 | + $this->InFooter = false; |
|
330 | + //Close page |
|
331 | + $this->_endpage(); |
|
332 | + } |
|
333 | + //Start new page |
|
334 | + $this->_beginpage($orientation, $format); |
|
335 | + //Set line cap style to square |
|
336 | + $this->_out('2 J'); |
|
337 | + //Set line width |
|
338 | + $this->LineWidth = $lw; |
|
339 | + $this->_out(sprintf('%.2F w', $lw * $this->k)); |
|
340 | + //Set font |
|
341 | + if ($family) { |
|
342 | + $this->SetFont($family, $style, $size); |
|
343 | + } |
|
344 | + //Set colors |
|
345 | + $this->DrawColor = $dc; |
|
346 | + if ($dc != '0 G') { |
|
347 | + $this->_out($dc); |
|
348 | + } |
|
349 | + $this->FillColor = $fc; |
|
350 | + if ($fc != '0 g') { |
|
351 | + $this->_out($fc); |
|
352 | + } |
|
353 | + $this->TextColor = $tc; |
|
354 | + $this->ColorFlag = $cf; |
|
355 | + //Page header |
|
356 | + $this->InHeader = true; |
|
357 | + $this->Header(); |
|
358 | + $this->InHeader = false; |
|
359 | + //Restore line width |
|
360 | + if ($this->LineWidth != $lw) { |
|
361 | + $this->LineWidth = $lw; |
|
362 | + $this->_out(sprintf('%.2F w', $lw * $this->k)); |
|
363 | + } |
|
364 | + //Restore font |
|
365 | + if ($family) { |
|
366 | + $this->SetFont($family, $style, $size); |
|
367 | + } |
|
368 | + //Restore colors |
|
369 | + if ($this->DrawColor != $dc) { |
|
370 | + $this->DrawColor = $dc; |
|
371 | + $this->_out($dc); |
|
372 | + } |
|
373 | + if ($this->FillColor != $fc) { |
|
374 | + $this->FillColor = $fc; |
|
375 | + $this->_out($fc); |
|
376 | + } |
|
377 | + $this->TextColor = $tc; |
|
378 | + $this->ColorFlag = $cf; |
|
379 | + } |
|
380 | + |
|
381 | + public function Header() |
|
382 | + { |
|
383 | + //To be implemented in your own inherited class |
|
384 | + } |
|
385 | + |
|
386 | + public function Footer() |
|
387 | + { |
|
388 | + //To be implemented in your own inherited class |
|
389 | + } |
|
390 | + |
|
391 | + public function PageNo() |
|
392 | + { |
|
393 | + //Get current page number |
|
394 | + return $this->page; |
|
395 | + } |
|
396 | + |
|
397 | + public function SetDrawColor($r, $g = null, $b = null) |
|
398 | + { |
|
399 | + //Set color for all stroking operations |
|
400 | + if (($r == 0 && $g == 0 && $b == 0) || $g === null) { |
|
401 | + $this->DrawColor = sprintf('%.3F G', $r / 255); |
|
402 | + } else { |
|
403 | + $this->DrawColor = sprintf('%.3F %.3F %.3F RG', $r / 255, $g / 255, $b / 255); |
|
404 | + } |
|
405 | + if ($this->page > 0) { |
|
406 | + $this->_out($this->DrawColor); |
|
407 | + } |
|
408 | + } |
|
409 | + |
|
410 | + public function SetFillColor($r, $g = null, $b = null) |
|
411 | + { |
|
412 | + //Set color for all filling operations |
|
413 | + if (($r == 0 && $g == 0 && $b == 0) || $g === null) { |
|
414 | + $this->FillColor = sprintf('%.3F g', $r / 255); |
|
415 | + } else { |
|
416 | + $this->FillColor = sprintf('%.3F %.3F %.3F rg', $r / 255, $g / 255, $b / 255); |
|
417 | + } |
|
418 | + $this->ColorFlag = ($this->FillColor != $this->TextColor); |
|
419 | + if ($this->page > 0) { |
|
420 | + $this->_out($this->FillColor); |
|
421 | + } |
|
422 | + } |
|
423 | + |
|
424 | + public function SetTextColor($r, $g = null, $b = null) |
|
425 | + { |
|
426 | + //Set color for text |
|
427 | + if (($r == 0 && $g == 0 && $b == 0) || $g === null) { |
|
428 | + $this->TextColor = sprintf('%.3F g', $r / 255); |
|
429 | + } else { |
|
430 | + $this->TextColor = sprintf('%.3F %.3F %.3F rg', $r / 255, $g / 255, $b / 255); |
|
431 | + } |
|
432 | + $this->ColorFlag = ($this->FillColor != $this->TextColor); |
|
433 | + } |
|
434 | + |
|
435 | + public function GetStringWidth($s) |
|
436 | + { |
|
437 | + //Get width of a string in the current font |
|
438 | + $s = (string) $s; |
|
439 | + $cw = &$this->CurrentFont['cw']; |
|
440 | + $w = 0; |
|
441 | + $l = strlen($s); |
|
442 | + for ($i = 0; $i < $l; $i++) { |
|
443 | + $w += $cw[$s[$i]]; |
|
444 | + } |
|
445 | + |
|
446 | + return $w * $this->FontSize / 1000; |
|
447 | + } |
|
448 | + |
|
449 | + public function SetLineWidth($width) |
|
450 | + { |
|
451 | + //Set line width |
|
452 | + $this->LineWidth = $width; |
|
453 | + if ($this->page > 0) { |
|
454 | + $this->_out(sprintf('%.2F w', $width * $this->k)); |
|
455 | + } |
|
456 | + } |
|
457 | + |
|
458 | + public function Line($x1, $y1, $x2, $y2) |
|
459 | + { |
|
460 | + //Draw a line |
|
461 | + $this->_out(sprintf('%.2F %.2F m %.2F %.2F l S', $x1 * $this->k, ($this->h - $y1) * $this->k, $x2 * $this->k, ($this->h - $y2) * $this->k)); |
|
462 | + } |
|
463 | + |
|
464 | + public function Rect($x, $y, $w, $h, $style = '') |
|
465 | + { |
|
466 | + //Draw a rectangle |
|
467 | + if ($style == 'F') { |
|
468 | + $op = 'f'; |
|
469 | + } elseif ($style == 'FD' || $style == 'DF') { |
|
470 | + $op = 'B'; |
|
471 | + } else { |
|
472 | + $op = 'S'; |
|
473 | + } |
|
474 | + $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s', $x * $this->k, ($this->h - $y) * $this->k, $w * $this->k, -$h * $this->k, $op)); |
|
475 | + } |
|
476 | + |
|
477 | + public function AddFont($family, $style = '', $file = '') |
|
478 | + { |
|
479 | + //Add a TrueType or Type1 font |
|
480 | + $family = strtolower($family); |
|
481 | + if ($file == '') { |
|
482 | + $file = str_replace(' ', '', $family).strtolower($style).'.php'; |
|
483 | + } |
|
484 | + if ($family == 'arial') { |
|
485 | + $family = 'helvetica'; |
|
486 | + } |
|
487 | + $style = strtoupper($style); |
|
488 | + if ($style == 'IB') { |
|
489 | + $style = 'BI'; |
|
490 | + } |
|
491 | + $fontkey = $family.$style; |
|
492 | + if (isset($this->fonts[$fontkey])) { |
|
493 | + return; |
|
494 | + } |
|
495 | + include $this->_getfontpath().$file; |
|
496 | + if (!isset($name)) { |
|
497 | + $this->Error('Could not include font definition file'); |
|
498 | + } |
|
499 | + $i = count($this->fonts) + 1; |
|
500 | + $this->fonts[$fontkey] = ['i'=>$i, 'type'=>$type, 'name'=>$name, 'desc'=>$desc, 'up'=>$up, 'ut'=>$ut, 'cw'=>$cw, 'enc'=>$enc, 'file'=>$file]; |
|
501 | + if ($diff) { |
|
502 | + //Search existing encodings |
|
503 | + $d = 0; |
|
504 | + $nb = count($this->diffs); |
|
505 | + for ($i = 1; $i <= $nb; $i++) { |
|
506 | + if ($this->diffs[$i] == $diff) { |
|
507 | + $d = $i; |
|
508 | + break; |
|
509 | + } |
|
510 | + } |
|
511 | + if ($d == 0) { |
|
512 | + $d = $nb + 1; |
|
513 | + $this->diffs[$d] = $diff; |
|
514 | + } |
|
515 | + $this->fonts[$fontkey]['diff'] = $d; |
|
516 | + } |
|
517 | + if ($file) { |
|
518 | + if ($type == 'TrueType') { |
|
519 | + $this->FontFiles[$file] = ['length1'=>$originalsize]; |
|
520 | + } else { |
|
521 | + $this->FontFiles[$file] = ['length1'=>$size1, 'length2'=>$size2]; |
|
522 | + } |
|
523 | + } |
|
524 | + } |
|
525 | + |
|
526 | + public function SetFont($family, $style = '', $size = 0) |
|
527 | + { |
|
528 | + //Select a font; size given in points |
|
529 | + global $fpdf_charwidths; |
|
530 | + |
|
531 | + $family = strtolower($family); |
|
532 | + if ($family == '') { |
|
533 | + $family = $this->FontFamily; |
|
534 | + } |
|
535 | + if ($family == 'arial') { |
|
536 | + $family = 'helvetica'; |
|
537 | + } elseif ($family == 'symbol' || $family == 'zapfdingbats') { |
|
538 | + $style = ''; |
|
539 | + } |
|
540 | + $style = strtoupper($style); |
|
541 | + if (strpos($style, 'U') !== false) { |
|
542 | + $this->underline = true; |
|
543 | + $style = str_replace('U', '', $style); |
|
544 | + } else { |
|
545 | + $this->underline = false; |
|
546 | + } |
|
547 | + if ($style == 'IB') { |
|
548 | + $style = 'BI'; |
|
549 | + } |
|
550 | + if ($size == 0) { |
|
551 | + $size = $this->FontSizePt; |
|
552 | + } |
|
553 | + //Test if font is already selected |
|
554 | + if ($this->FontFamily == $family && $this->FontStyle == $style && $this->FontSizePt == $size) { |
|
555 | + return; |
|
556 | + } |
|
557 | + //Test if used for the first time |
|
558 | + $fontkey = $family.$style; |
|
559 | + if (!isset($this->fonts[$fontkey])) { |
|
560 | + //Check if one of the standard fonts |
|
561 | + if (isset($this->CoreFonts[$fontkey])) { |
|
562 | + if (!isset($fpdf_charwidths[$fontkey])) { |
|
563 | + //Load metric file |
|
564 | + $file = $family; |
|
565 | + if ($family == 'times' || $family == 'helvetica') { |
|
566 | + $file .= strtolower($style); |
|
567 | + } |
|
568 | + include $this->_getfontpath().$file.'.php'; |
|
569 | + if (!isset($fpdf_charwidths[$fontkey])) { |
|
570 | + $this->Error('Could not include font metric file'); |
|
571 | + } |
|
572 | + } |
|
573 | + $i = count($this->fonts) + 1; |
|
574 | + $name = $this->CoreFonts[$fontkey]; |
|
575 | + $cw = $fpdf_charwidths[$fontkey]; |
|
576 | + $this->fonts[$fontkey] = ['i'=>$i, 'type'=>'core', 'name'=>$name, 'up'=>-100, 'ut'=>50, 'cw'=>$cw]; |
|
577 | + } else { |
|
578 | + $this->Error('Undefined font: '.$family.' '.$style); |
|
579 | + } |
|
580 | + } |
|
581 | + //Select it |
|
582 | + $this->FontFamily = $family; |
|
583 | + $this->FontStyle = $style; |
|
584 | + $this->FontSizePt = $size; |
|
585 | + $this->FontSize = $size / $this->k; |
|
586 | + $this->CurrentFont = &$this->fonts[$fontkey]; |
|
587 | + if ($this->page > 0) { |
|
588 | + $this->_out(sprintf('BT /F%d %.2F Tf ET', $this->CurrentFont['i'], $this->FontSizePt)); |
|
589 | + } |
|
590 | + } |
|
591 | + |
|
592 | + public function SetFontSize($size) |
|
593 | + { |
|
594 | + //Set font size in points |
|
595 | + if ($this->FontSizePt == $size) { |
|
596 | + return; |
|
597 | + } |
|
598 | + $this->FontSizePt = $size; |
|
599 | + $this->FontSize = $size / $this->k; |
|
600 | + if ($this->page > 0) { |
|
601 | + $this->_out(sprintf('BT /F%d %.2F Tf ET', $this->CurrentFont['i'], $this->FontSizePt)); |
|
602 | + } |
|
603 | + } |
|
604 | + |
|
605 | + public function AddLink() |
|
606 | + { |
|
607 | + //Create a new internal link |
|
608 | + $n = count($this->links) + 1; |
|
609 | + $this->links[$n] = [0, 0]; |
|
610 | + |
|
611 | + return $n; |
|
612 | + } |
|
613 | + |
|
614 | + public function SetLink($link, $y = 0, $page = -1) |
|
615 | + { |
|
616 | + //Set destination of internal link |
|
617 | + if ($y == -1) { |
|
618 | + $y = $this->y; |
|
619 | + } |
|
620 | + if ($page == -1) { |
|
621 | + $page = $this->page; |
|
622 | + } |
|
623 | + $this->links[$link] = [$page, $y]; |
|
624 | + } |
|
625 | + |
|
626 | + public function Link($x, $y, $w, $h, $link) |
|
627 | + { |
|
628 | + //Put a link on the page |
|
629 | + $this->PageLinks[$this->page][] = [$x * $this->k, $this->hPt - $y * $this->k, $w * $this->k, $h * $this->k, $link]; |
|
630 | + } |
|
631 | + |
|
632 | + public function Text($x, $y, $txt) |
|
633 | + { |
|
634 | + //Output a string |
|
635 | + $s = sprintf('BT %.2F %.2F Td (%s) Tj ET', $x * $this->k, ($this->h - $y) * $this->k, $this->_escape($txt)); |
|
636 | + if ($this->underline && $txt != '') { |
|
637 | + $s .= ' '.$this->_dounderline($x, $y, $txt); |
|
638 | + } |
|
639 | + if ($this->ColorFlag) { |
|
640 | + $s = 'q '.$this->TextColor.' '.$s.' Q'; |
|
641 | + } |
|
642 | + $this->_out($s); |
|
643 | + } |
|
644 | + |
|
645 | + public function AcceptPageBreak() |
|
646 | + { |
|
647 | + //Accept automatic page break or not |
|
648 | + return $this->AutoPageBreak; |
|
649 | + } |
|
650 | + |
|
651 | + public function Cell($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = false, $link = '') |
|
652 | + { |
|
653 | + //Output a cell |
|
654 | + $k = $this->k; |
|
655 | + if ($this->y + $h > $this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) { |
|
656 | + //Automatic page break |
|
657 | + $x = $this->x; |
|
658 | + $ws = $this->ws; |
|
659 | + if ($ws > 0) { |
|
660 | + $this->ws = 0; |
|
661 | + $this->_out('0 Tw'); |
|
662 | + } |
|
663 | + $this->AddPage($this->CurOrientation, $this->CurPageFormat); |
|
664 | + $this->x = $x; |
|
665 | + if ($ws > 0) { |
|
666 | + $this->ws = $ws; |
|
667 | + $this->_out(sprintf('%.3F Tw', $ws * $k)); |
|
668 | + } |
|
669 | + } |
|
670 | + if ($w == 0) { |
|
671 | + $w = $this->w - $this->rMargin - $this->x; |
|
672 | + } |
|
673 | + $s = ''; |
|
674 | + if ($fill || $border == 1) { |
|
675 | + if ($fill) { |
|
676 | + $op = ($border == 1) ? 'B' : 'f'; |
|
677 | + } else { |
|
678 | + $op = 'S'; |
|
679 | + } |
|
680 | + $s = sprintf('%.2F %.2F %.2F %.2F re %s ', $this->x * $k, ($this->h - $this->y) * $k, $w * $k, -$h * $k, $op); |
|
681 | + } |
|
682 | + if (is_string($border)) { |
|
683 | + $x = $this->x; |
|
684 | + $y = $this->y; |
|
685 | + if (strpos($border, 'L') !== false) { |
|
686 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', $x * $k, ($this->h - $y) * $k, $x * $k, ($this->h - ($y + $h)) * $k); |
|
687 | + } |
|
688 | + if (strpos($border, 'T') !== false) { |
|
689 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', $x * $k, ($this->h - $y) * $k, ($x + $w) * $k, ($this->h - $y) * $k); |
|
690 | + } |
|
691 | + if (strpos($border, 'R') !== false) { |
|
692 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', ($x + $w) * $k, ($this->h - $y) * $k, ($x + $w) * $k, ($this->h - ($y + $h)) * $k); |
|
693 | + } |
|
694 | + if (strpos($border, 'B') !== false) { |
|
695 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', $x * $k, ($this->h - ($y + $h)) * $k, ($x + $w) * $k, ($this->h - ($y + $h)) * $k); |
|
696 | + } |
|
697 | + } |
|
698 | + if ($txt !== '') { |
|
699 | + if ($align == 'R') { |
|
700 | + $dx = $w - $this->cMargin - $this->GetStringWidth($txt); |
|
701 | + } elseif ($align == 'C') { |
|
702 | + $dx = ($w - $this->GetStringWidth($txt)) / 2; |
|
703 | + } else { |
|
704 | + $dx = $this->cMargin; |
|
705 | + } |
|
706 | + if ($this->ColorFlag) { |
|
707 | + $s .= 'q '.$this->TextColor.' '; |
|
708 | + } |
|
709 | + $txt2 = str_replace(')', '\\)', str_replace('(', '\\(', str_replace('\\', '\\\\', $txt))); |
|
710 | + $s .= sprintf('BT %.2F %.2F Td (%s) Tj ET', ($this->x + $dx) * $k, ($this->h - ($this->y + .5 * $h + .3 * $this->FontSize)) * $k, $txt2); |
|
711 | + if ($this->underline) { |
|
712 | + $s .= ' '.$this->_dounderline($this->x + $dx, $this->y + .5 * $h + .3 * $this->FontSize, $txt); |
|
713 | + } |
|
714 | + if ($this->ColorFlag) { |
|
715 | + $s .= ' Q'; |
|
716 | + } |
|
717 | + if ($link) { |
|
718 | + $this->Link($this->x + $dx, $this->y + .5 * $h - .5 * $this->FontSize, $this->GetStringWidth($txt), $this->FontSize, $link); |
|
719 | + } |
|
720 | + } |
|
721 | + if ($s) { |
|
722 | + $this->_out($s); |
|
723 | + } |
|
724 | + $this->lasth = $h; |
|
725 | + if ($ln > 0) { |
|
726 | + //Go to next line |
|
727 | + $this->y += $h; |
|
728 | + if ($ln == 1) { |
|
729 | + $this->x = $this->lMargin; |
|
730 | + } |
|
731 | + } else { |
|
732 | + $this->x += $w; |
|
733 | + } |
|
734 | + } |
|
735 | + |
|
736 | + public function MultiCell($w, $h, $txt, $border = 0, $align = 'J', $fill = false) |
|
737 | + { |
|
738 | + //Output text with automatic or explicit line breaks |
|
739 | + $cw = &$this->CurrentFont['cw']; |
|
740 | + if ($w == 0) { |
|
741 | + $w = $this->w - $this->rMargin - $this->x; |
|
742 | + } |
|
743 | + $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; |
|
744 | + $s = str_replace("\r", '', $txt); |
|
745 | + $nb = strlen($s); |
|
746 | + if ($nb > 0 && $s[$nb - 1] == "\n") { |
|
747 | + $nb--; |
|
748 | + } |
|
749 | + $b = 0; |
|
750 | + if ($border) { |
|
751 | + if ($border == 1) { |
|
752 | + $border = 'LTRB'; |
|
753 | + $b = 'LRT'; |
|
754 | + $b2 = 'LR'; |
|
755 | + } else { |
|
756 | + $b2 = ''; |
|
757 | + if (strpos($border, 'L') !== false) { |
|
758 | + $b2 .= 'L'; |
|
759 | + } |
|
760 | + if (strpos($border, 'R') !== false) { |
|
761 | + $b2 .= 'R'; |
|
762 | + } |
|
763 | + $b = (strpos($border, 'T') !== false) ? $b2.'T' : $b2; |
|
764 | + } |
|
765 | + } |
|
766 | + $sep = -1; |
|
767 | + $i = 0; |
|
768 | + $j = 0; |
|
769 | + $l = 0; |
|
770 | + $ns = 0; |
|
771 | + $nl = 1; |
|
772 | + while ($i < $nb) { |
|
773 | + //Get next character |
|
774 | + $c = $s[$i]; |
|
775 | + if ($c == "\n") { |
|
776 | + //Explicit line break |
|
777 | + if ($this->ws > 0) { |
|
778 | + $this->ws = 0; |
|
779 | + $this->_out('0 Tw'); |
|
780 | + } |
|
781 | + $this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill); |
|
782 | + $i++; |
|
783 | + $sep = -1; |
|
784 | + $j = $i; |
|
785 | + $l = 0; |
|
786 | + $ns = 0; |
|
787 | + $nl++; |
|
788 | + if ($border && $nl == 2) { |
|
789 | + $b = $b2; |
|
790 | + } |
|
791 | + continue; |
|
792 | + } |
|
793 | + if ($c == ' ') { |
|
794 | + $sep = $i; |
|
795 | + $ls = $l; |
|
796 | + $ns++; |
|
797 | + } |
|
798 | + $l += $cw[$c]; |
|
799 | + if ($l > $wmax) { |
|
800 | + //Automatic line break |
|
801 | + if ($sep == -1) { |
|
802 | + if ($i == $j) { |
|
803 | + $i++; |
|
804 | + } |
|
805 | + if ($this->ws > 0) { |
|
806 | + $this->ws = 0; |
|
807 | + $this->_out('0 Tw'); |
|
808 | + } |
|
809 | + $this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill); |
|
810 | + } else { |
|
811 | + if ($align == 'J') { |
|
812 | + $this->ws = ($ns > 1) ? ($wmax - $ls) / 1000 * $this->FontSize / ($ns - 1) : 0; |
|
813 | + $this->_out(sprintf('%.3F Tw', $this->ws * $this->k)); |
|
814 | + } |
|
815 | + $this->Cell($w, $h, substr($s, $j, $sep - $j), $b, 2, $align, $fill); |
|
816 | + $i = $sep + 1; |
|
817 | + } |
|
818 | + $sep = -1; |
|
819 | + $j = $i; |
|
820 | + $l = 0; |
|
821 | + $ns = 0; |
|
822 | + $nl++; |
|
823 | + if ($border && $nl == 2) { |
|
824 | + $b = $b2; |
|
825 | + } |
|
826 | + } else { |
|
827 | + $i++; |
|
828 | + } |
|
829 | + } |
|
830 | + //Last chunk |
|
831 | + if ($this->ws > 0) { |
|
832 | + $this->ws = 0; |
|
833 | + $this->_out('0 Tw'); |
|
834 | + } |
|
835 | + if ($border && strpos($border, 'B') !== false) { |
|
836 | + $b .= 'B'; |
|
837 | + } |
|
838 | + $this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill); |
|
839 | + $this->x = $this->lMargin; |
|
840 | + } |
|
841 | + |
|
842 | + public function Write($h, $txt, $link = '') |
|
843 | + { |
|
844 | + //Output text in flowing mode |
|
845 | + $cw = &$this->CurrentFont['cw']; |
|
846 | + $w = $this->w - $this->rMargin - $this->x; |
|
847 | + $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; |
|
848 | + $s = str_replace("\r", '', $txt); |
|
849 | + $nb = strlen($s); |
|
850 | + $sep = -1; |
|
851 | + $i = 0; |
|
852 | + $j = 0; |
|
853 | + $l = 0; |
|
854 | + $nl = 1; |
|
855 | + while ($i < $nb) { |
|
856 | + //Get next character |
|
857 | + $c = $s[$i]; |
|
858 | + if ($c == "\n") { |
|
859 | + //Explicit line break |
|
860 | + $this->Cell($w, $h, substr($s, $j, $i - $j), 0, 2, '', 0, $link); |
|
861 | + $i++; |
|
862 | + $sep = -1; |
|
863 | + $j = $i; |
|
864 | + $l = 0; |
|
865 | + if ($nl == 1) { |
|
866 | + $this->x = $this->lMargin; |
|
867 | + $w = $this->w - $this->rMargin - $this->x; |
|
868 | + $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; |
|
869 | + } |
|
870 | + $nl++; |
|
871 | + continue; |
|
872 | + } |
|
873 | + if ($c == ' ') { |
|
874 | + $sep = $i; |
|
875 | + } |
|
876 | + $l += $cw[$c]; |
|
877 | + if ($l > $wmax) { |
|
878 | + //Automatic line break |
|
879 | + if ($sep == -1) { |
|
880 | + if ($this->x > $this->lMargin) { |
|
881 | + //Move to next line |
|
882 | + $this->x = $this->lMargin; |
|
883 | + $this->y += $h; |
|
884 | + $w = $this->w - $this->rMargin - $this->x; |
|
885 | + $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; |
|
886 | + $i++; |
|
887 | + $nl++; |
|
888 | + continue; |
|
889 | + } |
|
890 | + if ($i == $j) { |
|
891 | + $i++; |
|
892 | + } |
|
893 | + $this->Cell($w, $h, substr($s, $j, $i - $j), 0, 2, '', 0, $link); |
|
894 | + } else { |
|
895 | + $this->Cell($w, $h, substr($s, $j, $sep - $j), 0, 2, '', 0, $link); |
|
896 | + $i = $sep + 1; |
|
897 | + } |
|
898 | + $sep = -1; |
|
899 | + $j = $i; |
|
900 | + $l = 0; |
|
901 | + if ($nl == 1) { |
|
902 | + $this->x = $this->lMargin; |
|
903 | + $w = $this->w - $this->rMargin - $this->x; |
|
904 | + $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; |
|
905 | + } |
|
906 | + $nl++; |
|
907 | + } else { |
|
908 | + $i++; |
|
909 | + } |
|
910 | + } |
|
911 | + //Last chunk |
|
912 | + if ($i != $j) { |
|
913 | + $this->Cell($l / 1000 * $this->FontSize, $h, substr($s, $j), 0, 0, '', 0, $link); |
|
914 | + } |
|
915 | + } |
|
916 | + |
|
917 | + public function Ln($h = null) |
|
918 | + { |
|
919 | + //Line feed; default value is last cell height |
|
920 | + $this->x = $this->lMargin; |
|
921 | + if ($h === null) { |
|
922 | + $this->y += $this->lasth; |
|
923 | + } else { |
|
924 | + $this->y += $h; |
|
925 | + } |
|
926 | + } |
|
927 | + |
|
928 | + public function Image($file, $x = null, $y = null, $w = 0, $h = 0, $type = '', $link = '') |
|
929 | + { |
|
930 | + //Put an image on the page |
|
931 | + if (!isset($this->images[$file])) { |
|
932 | + //First use of this image, get info |
|
933 | + if ($type == '') { |
|
934 | + $pos = strrpos($file, '.'); |
|
935 | + if (!$pos) { |
|
936 | + $this->Error('Image file has no extension and no type was specified: '.$file); |
|
937 | + } |
|
938 | + $type = substr($file, $pos + 1); |
|
939 | + } |
|
940 | + $type = strtolower($type); |
|
941 | + if ($type == 'jpeg') { |
|
942 | + $type = 'jpg'; |
|
943 | + } |
|
944 | + $mtd = '_parse'.$type; |
|
945 | + if (!method_exists($this, $mtd)) { |
|
946 | + $this->Error('Unsupported image type: '.$type); |
|
947 | + } |
|
948 | + $info = $this->$mtd($file); |
|
949 | + $info['i'] = count($this->images) + 1; |
|
950 | + $this->images[$file] = $info; |
|
951 | + } else { |
|
952 | + $info = $this->images[$file]; |
|
953 | + } |
|
954 | + //Automatic width and height calculation if needed |
|
955 | + if ($w == 0 && $h == 0) { |
|
956 | + //Put image at 72 dpi |
|
957 | + $w = $info['w'] / $this->k; |
|
958 | + $h = $info['h'] / $this->k; |
|
959 | + } elseif ($w == 0) { |
|
960 | + $w = $h * $info['w'] / $info['h']; |
|
961 | + } elseif ($h == 0) { |
|
962 | + $h = $w * $info['h'] / $info['w']; |
|
963 | + } |
|
964 | + //Flowing mode |
|
965 | + if ($y === null) { |
|
966 | + if ($this->y + $h > $this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) { |
|
967 | + //Automatic page break |
|
968 | + $x2 = $this->x; |
|
969 | + $this->AddPage($this->CurOrientation, $this->CurPageFormat); |
|
970 | + $this->x = $x2; |
|
971 | + } |
|
972 | + $y = $this->y; |
|
973 | + $this->y += $h; |
|
974 | + } |
|
975 | + if ($x === null) { |
|
976 | + $x = $this->x; |
|
977 | + } |
|
978 | + $this->_out(sprintf('q %.2F 0 0 %.2F %.2F %.2F cm /I%d Do Q', $w * $this->k, $h * $this->k, $x * $this->k, ($this->h - ($y + $h)) * $this->k, $info['i'])); |
|
979 | + if ($link) { |
|
980 | + $this->Link($x, $y, $w, $h, $link); |
|
981 | + } |
|
982 | + } |
|
983 | + |
|
984 | + public function GetX() |
|
985 | + { |
|
986 | + //Get x position |
|
987 | + return $this->x; |
|
988 | + } |
|
989 | + |
|
990 | + public function SetX($x) |
|
991 | + { |
|
992 | + //Set x position |
|
993 | + if ($x >= 0) { |
|
994 | + $this->x = $x; |
|
995 | + } else { |
|
996 | + $this->x = $this->w + $x; |
|
997 | + } |
|
998 | + } |
|
999 | + |
|
1000 | + public function GetY() |
|
1001 | + { |
|
1002 | + //Get y position |
|
1003 | + return $this->y; |
|
1004 | + } |
|
1005 | + |
|
1006 | + public function SetY($y) |
|
1007 | + { |
|
1008 | + //Set y position and reset x |
|
1009 | + $this->x = $this->lMargin; |
|
1010 | + if ($y >= 0) { |
|
1011 | + $this->y = $y; |
|
1012 | + } else { |
|
1013 | + $this->y = $this->h + $y; |
|
1014 | + } |
|
1015 | + } |
|
1016 | + |
|
1017 | + public function SetXY($x, $y) |
|
1018 | + { |
|
1019 | + //Set x and y positions |
|
1020 | + $this->SetY($y); |
|
1021 | + $this->SetX($x); |
|
1022 | + } |
|
1023 | + |
|
1024 | + public function Output($name = '', $dest = '') |
|
1025 | + { |
|
1026 | + //Output PDF to some destination |
|
1027 | + if ($this->state < 3) { |
|
1028 | + $this->Close(); |
|
1029 | + } |
|
1030 | + $dest = strtoupper($dest); |
|
1031 | + if ($dest == '') { |
|
1032 | + if ($name == '') { |
|
1033 | + $name = 'doc.pdf'; |
|
1034 | + $dest = 'I'; |
|
1035 | + } else { |
|
1036 | + $dest = 'F'; |
|
1037 | + } |
|
1038 | + } |
|
1039 | + switch ($dest) { |
|
1040 | + case 'I': |
|
1041 | + //Send to standard output |
|
1042 | + if (ob_get_length()) { |
|
1043 | + $this->Error('Some data has already been output, can\'t send PDF file'); |
|
1044 | + } |
|
1045 | + if (php_sapi_name() != 'cli') { |
|
1046 | + //We send to a browser |
|
1047 | + header('Content-Type: application/pdf'); |
|
1048 | + if (headers_sent()) { |
|
1049 | + $this->Error('Some data has already been output, can\'t send PDF file'); |
|
1050 | + } |
|
1051 | + header('Content-Length: '.strlen($this->buffer)); |
|
1052 | + header('Content-Disposition: inline; filename="'.$name.'"'); |
|
1053 | + header('Cache-Control: private, max-age=0, must-revalidate'); |
|
1054 | + header('Pragma: public'); |
|
1055 | + ini_set('zlib.output_compression', '0'); |
|
1056 | + } |
|
1057 | + echo $this->buffer; |
|
1058 | + break; |
|
1059 | + case 'D': |
|
1060 | + //Download file |
|
1061 | + if (ob_get_length()) { |
|
1062 | + $this->Error('Some data has already been output, can\'t send PDF file'); |
|
1063 | + } |
|
1064 | + header('Content-Type: application/x-download'); |
|
1065 | + if (headers_sent()) { |
|
1066 | + $this->Error('Some data has already been output, can\'t send PDF file'); |
|
1067 | + } |
|
1068 | + header('Content-Length: '.strlen($this->buffer)); |
|
1069 | + header('Content-Disposition: attachment; filename="'.$name.'"'); |
|
1070 | + header('Cache-Control: private, max-age=0, must-revalidate'); |
|
1071 | + header('Pragma: public'); |
|
1072 | + ini_set('zlib.output_compression', '0'); |
|
1073 | + echo $this->buffer; |
|
1074 | + break; |
|
1075 | + case 'F': |
|
1076 | + //Save to local file |
|
1077 | + $f = fopen($name, 'wb'); |
|
1078 | + if (!$f) { |
|
1079 | + $this->Error('Unable to create output file: '.$name); |
|
1080 | + } |
|
1081 | + fwrite($f, $this->buffer, strlen($this->buffer)); |
|
1082 | + fclose($f); |
|
1083 | + break; |
|
1084 | + case 'S': |
|
1085 | + //Return as a string |
|
1086 | + return $this->buffer; |
|
1087 | + default: |
|
1088 | + $this->Error('Incorrect output destination: '.$dest); |
|
1089 | + } |
|
1090 | + |
|
1091 | + return ''; |
|
1092 | + } |
|
1093 | + |
|
1094 | + /******************************************************************************* |
|
1095 | 1095 | * * |
1096 | 1096 | * Protected methods * |
1097 | 1097 | * * |
1098 | 1098 | *******************************************************************************/ |
1099 | - public function _dochecks() |
|
1100 | - { |
|
1101 | - //Check availability of %F |
|
1102 | - if (sprintf('%.1F', 1.0) != '1.0') { |
|
1103 | - $this->Error('This version of PHP is not supported'); |
|
1104 | - } |
|
1105 | - //Check mbstring overloading |
|
1106 | - if (ini_get('mbstring.func_overload') & 2) { |
|
1107 | - $this->Error('mbstring overloading must be disabled'); |
|
1108 | - } |
|
1109 | - //Disable runtime magic quotes |
|
1110 | - if (get_magic_quotes_runtime()) { |
|
1111 | - @set_magic_quotes_runtime(0); |
|
1112 | - } |
|
1113 | - } |
|
1114 | - |
|
1115 | - public function _getpageformat($format) |
|
1116 | - { |
|
1117 | - $format = strtolower($format); |
|
1118 | - if (!isset($this->PageFormats[$format])) { |
|
1119 | - $this->Error('Unknown page format: '.$format); |
|
1120 | - } |
|
1121 | - $a = $this->PageFormats[$format]; |
|
1122 | - |
|
1123 | - return [$a[0] / $this->k, $a[1] / $this->k]; |
|
1124 | - } |
|
1125 | - |
|
1126 | - public function _getfontpath() |
|
1127 | - { |
|
1128 | - if (!defined('FPDF_FONTPATH') && is_dir(dirname(__FILE__).'/font')) { |
|
1129 | - define('FPDF_FONTPATH', dirname(__FILE__).'/font/'); |
|
1130 | - } |
|
1131 | - |
|
1132 | - return defined('FPDF_FONTPATH') ? FPDF_FONTPATH : ''; |
|
1133 | - } |
|
1134 | - |
|
1135 | - public function _beginpage($orientation, $format) |
|
1136 | - { |
|
1137 | - $this->page++; |
|
1138 | - $this->pages[$this->page] = ''; |
|
1139 | - $this->state = 2; |
|
1140 | - $this->x = $this->lMargin; |
|
1141 | - $this->y = $this->tMargin; |
|
1142 | - $this->FontFamily = ''; |
|
1143 | - //Check page size |
|
1144 | - if ($orientation == '') { |
|
1145 | - $orientation = $this->DefOrientation; |
|
1146 | - } else { |
|
1147 | - $orientation = strtoupper($orientation[0]); |
|
1148 | - } |
|
1149 | - if ($format == '') { |
|
1150 | - $format = $this->DefPageFormat; |
|
1151 | - } else { |
|
1152 | - if (is_string($format)) { |
|
1153 | - $format = $this->_getpageformat($format); |
|
1154 | - } |
|
1155 | - } |
|
1156 | - if ($orientation != $this->CurOrientation || $format[0] != $this->CurPageFormat[0] || $format[1] != $this->CurPageFormat[1]) { |
|
1157 | - //New size |
|
1158 | - if ($orientation == 'P') { |
|
1159 | - $this->w = $format[0]; |
|
1160 | - $this->h = $format[1]; |
|
1161 | - } else { |
|
1162 | - $this->w = $format[1]; |
|
1163 | - $this->h = $format[0]; |
|
1164 | - } |
|
1165 | - $this->wPt = $this->w * $this->k; |
|
1166 | - $this->hPt = $this->h * $this->k; |
|
1167 | - $this->PageBreakTrigger = $this->h - $this->bMargin; |
|
1168 | - $this->CurOrientation = $orientation; |
|
1169 | - $this->CurPageFormat = $format; |
|
1170 | - } |
|
1171 | - if ($orientation != $this->DefOrientation || $format[0] != $this->DefPageFormat[0] || $format[1] != $this->DefPageFormat[1]) { |
|
1172 | - $this->PageSizes[$this->page] = [$this->wPt, $this->hPt]; |
|
1173 | - } |
|
1174 | - } |
|
1175 | - |
|
1176 | - public function _endpage() |
|
1177 | - { |
|
1178 | - $this->state = 1; |
|
1179 | - } |
|
1180 | - |
|
1181 | - public function _escape($s) |
|
1182 | - { |
|
1183 | - //Escape special characters in strings |
|
1184 | - $s = str_replace('\\', '\\\\', $s); |
|
1185 | - $s = str_replace('(', '\\(', $s); |
|
1186 | - $s = str_replace(')', '\\)', $s); |
|
1187 | - $s = str_replace("\r", '\\r', $s); |
|
1188 | - |
|
1189 | - return $s; |
|
1190 | - } |
|
1191 | - |
|
1192 | - public function _textstring($s) |
|
1193 | - { |
|
1194 | - //Format a text string |
|
1195 | - return '('.$this->_escape($s).')'; |
|
1196 | - } |
|
1197 | - |
|
1198 | - public function _UTF8toUTF16($s) |
|
1199 | - { |
|
1200 | - //Convert UTF-8 to UTF-16BE with BOM |
|
1201 | - $res = "\xFE\xFF"; |
|
1202 | - $nb = strlen($s); |
|
1203 | - $i = 0; |
|
1204 | - while ($i < $nb) { |
|
1205 | - $c1 = ord($s[$i++]); |
|
1206 | - if ($c1 >= 224) { |
|
1207 | - //3-byte character |
|
1208 | - $c2 = ord($s[$i++]); |
|
1209 | - $c3 = ord($s[$i++]); |
|
1210 | - $res .= chr((($c1 & 0x0F) << 4) + (($c2 & 0x3C) >> 2)); |
|
1211 | - $res .= chr((($c2 & 0x03) << 6) + ($c3 & 0x3F)); |
|
1212 | - } elseif ($c1 >= 192) { |
|
1213 | - //2-byte character |
|
1214 | - $c2 = ord($s[$i++]); |
|
1215 | - $res .= chr(($c1 & 0x1C) >> 2); |
|
1216 | - $res .= chr((($c1 & 0x03) << 6) + ($c2 & 0x3F)); |
|
1217 | - } else { |
|
1218 | - //Single-byte character |
|
1219 | - $res .= "\0".chr($c1); |
|
1220 | - } |
|
1221 | - } |
|
1222 | - |
|
1223 | - return $res; |
|
1224 | - } |
|
1225 | - |
|
1226 | - public function _dounderline($x, $y, $txt) |
|
1227 | - { |
|
1228 | - //Underline text |
|
1229 | - $up = $this->CurrentFont['up']; |
|
1230 | - $ut = $this->CurrentFont['ut']; |
|
1231 | - $w = $this->GetStringWidth($txt) + $this->ws * substr_count($txt, ' '); |
|
1232 | - |
|
1233 | - return sprintf('%.2F %.2F %.2F %.2F re f', $x * $this->k, ($this->h - ($y - $up / 1000 * $this->FontSize)) * $this->k, $w * $this->k, -$ut / 1000 * $this->FontSizePt); |
|
1234 | - } |
|
1235 | - |
|
1236 | - public function _parsejpg($file) |
|
1237 | - { |
|
1238 | - //Extract info from a JPEG file |
|
1239 | - $a = getimagesize($file); |
|
1240 | - if (!$a) { |
|
1241 | - $this->Error('Missing or incorrect image file: '.$file); |
|
1242 | - } |
|
1243 | - if ($a[2] != 2) { |
|
1244 | - $this->Error('Not a JPEG file: '.$file); |
|
1245 | - } |
|
1246 | - if (!isset($a['channels']) || $a['channels'] == 3) { |
|
1247 | - $colspace = 'DeviceRGB'; |
|
1248 | - } elseif ($a['channels'] == 4) { |
|
1249 | - $colspace = 'DeviceCMYK'; |
|
1250 | - } else { |
|
1251 | - $colspace = 'DeviceGray'; |
|
1252 | - } |
|
1253 | - $bpc = isset($a['bits']) ? $a['bits'] : 8; |
|
1254 | - //Read whole file |
|
1255 | - $f = fopen($file, 'rb'); |
|
1256 | - $data = ''; |
|
1257 | - while (!feof($f)) { |
|
1258 | - $data .= fread($f, 8192); |
|
1259 | - } |
|
1260 | - fclose($f); |
|
1261 | - |
|
1262 | - return ['w'=>$a[0], 'h'=>$a[1], 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'DCTDecode', 'data'=>$data]; |
|
1263 | - } |
|
1264 | - |
|
1265 | - public function _parsepng($file) |
|
1266 | - { |
|
1267 | - //Extract info from a PNG file |
|
1268 | - $f = fopen($file, 'rb'); |
|
1269 | - if (!$f) { |
|
1270 | - $this->Error('Can\'t open image file: '.$file); |
|
1271 | - } |
|
1272 | - //Check signature |
|
1273 | - if ($this->_readstream($f, 8) != chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) { |
|
1274 | - $this->Error('Not a PNG file: '.$file); |
|
1275 | - } |
|
1276 | - //Read header chunk |
|
1277 | - $this->_readstream($f, 4); |
|
1278 | - if ($this->_readstream($f, 4) != 'IHDR') { |
|
1279 | - $this->Error('Incorrect PNG file: '.$file); |
|
1280 | - } |
|
1281 | - $w = $this->_readint($f); |
|
1282 | - $h = $this->_readint($f); |
|
1283 | - $bpc = ord($this->_readstream($f, 1)); |
|
1284 | - if ($bpc > 8) { |
|
1285 | - $this->Error('16-bit depth not supported: '.$file); |
|
1286 | - } |
|
1287 | - $ct = ord($this->_readstream($f, 1)); |
|
1288 | - if ($ct == 0) { |
|
1289 | - $colspace = 'DeviceGray'; |
|
1290 | - } elseif ($ct == 2) { |
|
1291 | - $colspace = 'DeviceRGB'; |
|
1292 | - } elseif ($ct == 3) { |
|
1293 | - $colspace = 'Indexed'; |
|
1294 | - } else { |
|
1295 | - $this->Error('Alpha channel not supported: '.$file); |
|
1296 | - } |
|
1297 | - if (ord($this->_readstream($f, 1)) != 0) { |
|
1298 | - $this->Error('Unknown compression method: '.$file); |
|
1299 | - } |
|
1300 | - if (ord($this->_readstream($f, 1)) != 0) { |
|
1301 | - $this->Error('Unknown filter method: '.$file); |
|
1302 | - } |
|
1303 | - if (ord($this->_readstream($f, 1)) != 0) { |
|
1304 | - $this->Error('Interlacing not supported: '.$file); |
|
1305 | - } |
|
1306 | - $this->_readstream($f, 4); |
|
1307 | - $parms = '/DecodeParms <</Predictor 15 /Colors '.($ct == 2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>'; |
|
1308 | - //Scan chunks looking for palette, transparency and image data |
|
1309 | - $pal = ''; |
|
1310 | - $trns = ''; |
|
1311 | - $data = ''; |
|
1312 | - do { |
|
1313 | - $n = $this->_readint($f); |
|
1314 | - $type = $this->_readstream($f, 4); |
|
1315 | - if ($type == 'PLTE') { |
|
1316 | - //Read palette |
|
1317 | - $pal = $this->_readstream($f, $n); |
|
1318 | - $this->_readstream($f, 4); |
|
1319 | - } elseif ($type == 'tRNS') { |
|
1320 | - //Read transparency info |
|
1321 | - $t = $this->_readstream($f, $n); |
|
1322 | - if ($ct == 0) { |
|
1323 | - $trns = [ord(substr($t, 1, 1))]; |
|
1324 | - } elseif ($ct == 2) { |
|
1325 | - $trns = [ord(substr($t, 1, 1)), ord(substr($t, 3, 1)), ord(substr($t, 5, 1))]; |
|
1326 | - } else { |
|
1327 | - $pos = strpos($t, chr(0)); |
|
1328 | - if ($pos !== false) { |
|
1329 | - $trns = [$pos]; |
|
1330 | - } |
|
1331 | - } |
|
1332 | - $this->_readstream($f, 4); |
|
1333 | - } elseif ($type == 'IDAT') { |
|
1334 | - //Read image data block |
|
1335 | - $data .= $this->_readstream($f, $n); |
|
1336 | - $this->_readstream($f, 4); |
|
1337 | - } elseif ($type == 'IEND') { |
|
1338 | - break; |
|
1339 | - } else { |
|
1340 | - $this->_readstream($f, $n + 4); |
|
1341 | - } |
|
1342 | - } while ($n); |
|
1343 | - if ($colspace == 'Indexed' && empty($pal)) { |
|
1344 | - $this->Error('Missing palette in '.$file); |
|
1345 | - } |
|
1346 | - fclose($f); |
|
1347 | - |
|
1348 | - return ['w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'FlateDecode', 'parms'=>$parms, 'pal'=>$pal, 'trns'=>$trns, 'data'=>$data]; |
|
1349 | - } |
|
1350 | - |
|
1351 | - public function _readstream($f, $n) |
|
1352 | - { |
|
1353 | - //Read n bytes from stream |
|
1354 | - $res = ''; |
|
1355 | - while ($n > 0 && !feof($f)) { |
|
1356 | - $s = fread($f, $n); |
|
1357 | - if ($s === false) { |
|
1358 | - $this->Error('Error while reading stream'); |
|
1359 | - } |
|
1360 | - $n -= strlen($s); |
|
1361 | - $res .= $s; |
|
1362 | - } |
|
1363 | - if ($n > 0) { |
|
1364 | - $this->Error('Unexpected end of stream'); |
|
1365 | - } |
|
1366 | - |
|
1367 | - return $res; |
|
1368 | - } |
|
1369 | - |
|
1370 | - public function _readint($f) |
|
1371 | - { |
|
1372 | - //Read a 4-byte integer from stream |
|
1373 | - $a = unpack('Ni', $this->_readstream($f, 4)); |
|
1374 | - |
|
1375 | - return $a['i']; |
|
1376 | - } |
|
1377 | - |
|
1378 | - public function _parsegif($file) |
|
1379 | - { |
|
1380 | - //Extract info from a GIF file (via PNG conversion) |
|
1381 | - if (!function_exists('imagepng')) { |
|
1382 | - $this->Error('GD extension is required for GIF support'); |
|
1383 | - } |
|
1384 | - if (!function_exists('imagecreatefromgif')) { |
|
1385 | - $this->Error('GD has no GIF read support'); |
|
1386 | - } |
|
1387 | - $im = imagecreatefromgif($file); |
|
1388 | - if (!$im) { |
|
1389 | - $this->Error('Missing or incorrect image file: '.$file); |
|
1390 | - } |
|
1391 | - imageinterlace($im, 0); |
|
1392 | - $tmp = tempnam('.', 'gif'); |
|
1393 | - if (!$tmp) { |
|
1394 | - $this->Error('Unable to create a temporary file'); |
|
1395 | - } |
|
1396 | - if (!imagepng($im, $tmp)) { |
|
1397 | - $this->Error('Error while saving to temporary file'); |
|
1398 | - } |
|
1399 | - imagedestroy($im); |
|
1400 | - $info = $this->_parsepng($tmp); |
|
1401 | - unlink($tmp); |
|
1402 | - |
|
1403 | - return $info; |
|
1404 | - } |
|
1405 | - |
|
1406 | - public function _newobj() |
|
1407 | - { |
|
1408 | - //Begin a new object |
|
1409 | - $this->n++; |
|
1410 | - $this->offsets[$this->n] = strlen($this->buffer); |
|
1411 | - $this->_out($this->n.' 0 obj'); |
|
1412 | - } |
|
1413 | - |
|
1414 | - public function _putstream($s) |
|
1415 | - { |
|
1416 | - $this->_out('stream'); |
|
1417 | - $this->_out($s); |
|
1418 | - $this->_out('endstream'); |
|
1419 | - } |
|
1420 | - |
|
1421 | - public function _out($s) |
|
1422 | - { |
|
1423 | - //Add a line to the document |
|
1424 | - if ($this->state == 2) { |
|
1425 | - $this->pages[$this->page] .= $s."\n"; |
|
1426 | - } else { |
|
1427 | - $this->buffer .= $s."\n"; |
|
1428 | - } |
|
1429 | - } |
|
1430 | - |
|
1431 | - public function _putpages() |
|
1432 | - { |
|
1433 | - $nb = $this->page; |
|
1434 | - if (!empty($this->AliasNbPages)) { |
|
1435 | - //Replace number of pages |
|
1436 | - for ($n = 1; $n <= $nb; $n++) { |
|
1437 | - $this->pages[$n] = str_replace($this->AliasNbPages, $nb, $this->pages[$n]); |
|
1438 | - } |
|
1439 | - } |
|
1440 | - if ($this->DefOrientation == 'P') { |
|
1441 | - $wPt = $this->DefPageFormat[0] * $this->k; |
|
1442 | - $hPt = $this->DefPageFormat[1] * $this->k; |
|
1443 | - } else { |
|
1444 | - $wPt = $this->DefPageFormat[1] * $this->k; |
|
1445 | - $hPt = $this->DefPageFormat[0] * $this->k; |
|
1446 | - } |
|
1447 | - $filter = ($this->compress) ? '/Filter /FlateDecode ' : ''; |
|
1448 | - for ($n = 1; $n <= $nb; $n++) { |
|
1449 | - //Page |
|
1450 | - $this->_newobj(); |
|
1451 | - $this->_out('<</Type /Page'); |
|
1452 | - $this->_out('/Parent 1 0 R'); |
|
1453 | - if (isset($this->PageSizes[$n])) { |
|
1454 | - $this->_out(sprintf('/MediaBox [0 0 %.2F %.2F]', $this->PageSizes[$n][0], $this->PageSizes[$n][1])); |
|
1455 | - } |
|
1456 | - $this->_out('/Resources 2 0 R'); |
|
1457 | - if (isset($this->PageLinks[$n])) { |
|
1458 | - //Links |
|
1459 | - $annots = '/Annots ['; |
|
1460 | - foreach ($this->PageLinks[$n] as $pl) { |
|
1461 | - $rect = sprintf('%.2F %.2F %.2F %.2F', $pl[0], $pl[1], $pl[0] + $pl[2], $pl[1] - $pl[3]); |
|
1462 | - $annots .= '<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] '; |
|
1463 | - if (is_string($pl[4])) { |
|
1464 | - $annots .= '/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>'; |
|
1465 | - } else { |
|
1466 | - $l = $this->links[$pl[4]]; |
|
1467 | - $h = isset($this->PageSizes[$l[0]]) ? $this->PageSizes[$l[0]][1] : $hPt; |
|
1468 | - $annots .= sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>', 1 + 2 * $l[0], $h - $l[1] * $this->k); |
|
1469 | - } |
|
1470 | - } |
|
1471 | - $this->_out($annots.']'); |
|
1472 | - } |
|
1473 | - $this->_out('/Contents '.($this->n + 1).' 0 R>>'); |
|
1474 | - $this->_out('endobj'); |
|
1475 | - //Page content |
|
1476 | - $p = ($this->compress) ? gzcompress($this->pages[$n]) : $this->pages[$n]; |
|
1477 | - $this->_newobj(); |
|
1478 | - $this->_out('<<'.$filter.'/Length '.strlen($p).'>>'); |
|
1479 | - $this->_putstream($p); |
|
1480 | - $this->_out('endobj'); |
|
1481 | - } |
|
1482 | - //Pages root |
|
1483 | - $this->offsets[1] = strlen($this->buffer); |
|
1484 | - $this->_out('1 0 obj'); |
|
1485 | - $this->_out('<</Type /Pages'); |
|
1486 | - $kids = '/Kids ['; |
|
1487 | - for ($i = 0; $i < $nb; $i++) { |
|
1488 | - $kids .= (3 + 2 * $i).' 0 R '; |
|
1489 | - } |
|
1490 | - $this->_out($kids.']'); |
|
1491 | - $this->_out('/Count '.$nb); |
|
1492 | - $this->_out(sprintf('/MediaBox [0 0 %.2F %.2F]', $wPt, $hPt)); |
|
1493 | - $this->_out('>>'); |
|
1494 | - $this->_out('endobj'); |
|
1495 | - } |
|
1496 | - |
|
1497 | - public function _putfonts() |
|
1498 | - { |
|
1499 | - $nf = $this->n; |
|
1500 | - foreach ($this->diffs as $diff) { |
|
1501 | - //Encodings |
|
1502 | - $this->_newobj(); |
|
1503 | - $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>'); |
|
1504 | - $this->_out('endobj'); |
|
1505 | - } |
|
1506 | - foreach ($this->FontFiles as $file=>$info) { |
|
1507 | - //Font file embedding |
|
1508 | - $this->_newobj(); |
|
1509 | - $this->FontFiles[$file]['n'] = $this->n; |
|
1510 | - $font = ''; |
|
1511 | - $f = fopen($this->_getfontpath().$file, 'rb', 1); |
|
1512 | - if (!$f) { |
|
1513 | - $this->Error('Font file not found'); |
|
1514 | - } |
|
1515 | - while (!feof($f)) { |
|
1516 | - $font .= fread($f, 8192); |
|
1517 | - } |
|
1518 | - fclose($f); |
|
1519 | - $compressed = (substr($file, -2) == '.z'); |
|
1520 | - if (!$compressed && isset($info['length2'])) { |
|
1521 | - $header = (ord($font[0]) == 128); |
|
1522 | - if ($header) { |
|
1523 | - //Strip first binary header |
|
1524 | - $font = substr($font, 6); |
|
1525 | - } |
|
1526 | - if ($header && ord($font[$info['length1']]) == 128) { |
|
1527 | - //Strip second binary header |
|
1528 | - $font = substr($font, 0, $info['length1']).substr($font, $info['length1'] + 6); |
|
1529 | - } |
|
1530 | - } |
|
1531 | - $this->_out('<</Length '.strlen($font)); |
|
1532 | - if ($compressed) { |
|
1533 | - $this->_out('/Filter /FlateDecode'); |
|
1534 | - } |
|
1535 | - $this->_out('/Length1 '.$info['length1']); |
|
1536 | - if (isset($info['length2'])) { |
|
1537 | - $this->_out('/Length2 '.$info['length2'].' /Length3 0'); |
|
1538 | - } |
|
1539 | - $this->_out('>>'); |
|
1540 | - $this->_putstream($font); |
|
1541 | - $this->_out('endobj'); |
|
1542 | - } |
|
1543 | - foreach ($this->fonts as $k=>$font) { |
|
1544 | - //Font objects |
|
1545 | - $this->fonts[$k]['n'] = $this->n + 1; |
|
1546 | - $type = $font['type']; |
|
1547 | - $name = $font['name']; |
|
1548 | - if ($type == 'core') { |
|
1549 | - //Standard font |
|
1550 | - $this->_newobj(); |
|
1551 | - $this->_out('<</Type /Font'); |
|
1552 | - $this->_out('/BaseFont /'.$name); |
|
1553 | - $this->_out('/Subtype /Type1'); |
|
1554 | - if ($name != 'Symbol' && $name != 'ZapfDingbats') { |
|
1555 | - $this->_out('/Encoding /WinAnsiEncoding'); |
|
1556 | - } |
|
1557 | - $this->_out('>>'); |
|
1558 | - $this->_out('endobj'); |
|
1559 | - } elseif ($type == 'Type1' || $type == 'TrueType') { |
|
1560 | - //Additional Type1 or TrueType font |
|
1561 | - $this->_newobj(); |
|
1562 | - $this->_out('<</Type /Font'); |
|
1563 | - $this->_out('/BaseFont /'.$name); |
|
1564 | - $this->_out('/Subtype /'.$type); |
|
1565 | - $this->_out('/FirstChar 32 /LastChar 255'); |
|
1566 | - $this->_out('/Widths '.($this->n + 1).' 0 R'); |
|
1567 | - $this->_out('/FontDescriptor '.($this->n + 2).' 0 R'); |
|
1568 | - if ($font['enc']) { |
|
1569 | - if (isset($font['diff'])) { |
|
1570 | - $this->_out('/Encoding '.($nf + $font['diff']).' 0 R'); |
|
1571 | - } else { |
|
1572 | - $this->_out('/Encoding /WinAnsiEncoding'); |
|
1573 | - } |
|
1574 | - } |
|
1575 | - $this->_out('>>'); |
|
1576 | - $this->_out('endobj'); |
|
1577 | - //Widths |
|
1578 | - $this->_newobj(); |
|
1579 | - $cw = &$font['cw']; |
|
1580 | - $s = '['; |
|
1581 | - for ($i = 32; $i <= 255; $i++) { |
|
1582 | - $s .= $cw[chr($i)].' '; |
|
1583 | - } |
|
1584 | - $this->_out($s.']'); |
|
1585 | - $this->_out('endobj'); |
|
1586 | - //Descriptor |
|
1587 | - $this->_newobj(); |
|
1588 | - $s = '<</Type /FontDescriptor /FontName /'.$name; |
|
1589 | - foreach ($font['desc'] as $k=>$v) { |
|
1590 | - $s .= ' /'.$k.' '.$v; |
|
1591 | - } |
|
1592 | - $file = $font['file']; |
|
1593 | - if ($file) { |
|
1594 | - $s .= ' /FontFile'.($type == 'Type1' ? '' : '2').' '.$this->FontFiles[$file]['n'].' 0 R'; |
|
1595 | - } |
|
1596 | - $this->_out($s.'>>'); |
|
1597 | - $this->_out('endobj'); |
|
1598 | - } else { |
|
1599 | - //Allow for additional types |
|
1600 | - $mtd = '_put'.strtolower($type); |
|
1601 | - if (!method_exists($this, $mtd)) { |
|
1602 | - $this->Error('Unsupported font type: '.$type); |
|
1603 | - } |
|
1604 | - $this->$mtd($font); |
|
1605 | - } |
|
1606 | - } |
|
1607 | - } |
|
1608 | - |
|
1609 | - public function _putimages() |
|
1610 | - { |
|
1611 | - $filter = ($this->compress) ? '/Filter /FlateDecode ' : ''; |
|
1612 | - reset($this->images); |
|
1613 | - while (list($file, $info) = each($this->images)) { |
|
1614 | - $this->_newobj(); |
|
1615 | - $this->images[$file]['n'] = $this->n; |
|
1616 | - $this->_out('<</Type /XObject'); |
|
1617 | - $this->_out('/Subtype /Image'); |
|
1618 | - $this->_out('/Width '.$info['w']); |
|
1619 | - $this->_out('/Height '.$info['h']); |
|
1620 | - if ($info['cs'] == 'Indexed') { |
|
1621 | - $this->_out('/ColorSpace [/Indexed /DeviceRGB '.(strlen($info['pal']) / 3 - 1).' '.($this->n + 1).' 0 R]'); |
|
1622 | - } else { |
|
1623 | - $this->_out('/ColorSpace /'.$info['cs']); |
|
1624 | - if ($info['cs'] == 'DeviceCMYK') { |
|
1625 | - $this->_out('/Decode [1 0 1 0 1 0 1 0]'); |
|
1626 | - } |
|
1627 | - } |
|
1628 | - $this->_out('/BitsPerComponent '.$info['bpc']); |
|
1629 | - if (isset($info['f'])) { |
|
1630 | - $this->_out('/Filter /'.$info['f']); |
|
1631 | - } |
|
1632 | - if (isset($info['parms'])) { |
|
1633 | - $this->_out($info['parms']); |
|
1634 | - } |
|
1635 | - if (isset($info['trns']) && is_array($info['trns'])) { |
|
1636 | - $trns = ''; |
|
1637 | - for ($i = 0; $i < count($info['trns']); $i++) { |
|
1638 | - $trns .= $info['trns'][$i].' '.$info['trns'][$i].' '; |
|
1639 | - } |
|
1640 | - $this->_out('/Mask ['.$trns.']'); |
|
1641 | - } |
|
1642 | - $this->_out('/Length '.strlen($info['data']).'>>'); |
|
1643 | - $this->_putstream($info['data']); |
|
1644 | - unset($this->images[$file]['data']); |
|
1645 | - $this->_out('endobj'); |
|
1646 | - //Palette |
|
1647 | - if ($info['cs'] == 'Indexed') { |
|
1648 | - $this->_newobj(); |
|
1649 | - $pal = ($this->compress) ? gzcompress($info['pal']) : $info['pal']; |
|
1650 | - $this->_out('<<'.$filter.'/Length '.strlen($pal).'>>'); |
|
1651 | - $this->_putstream($pal); |
|
1652 | - $this->_out('endobj'); |
|
1653 | - } |
|
1654 | - } |
|
1655 | - } |
|
1656 | - |
|
1657 | - public function _putxobjectdict() |
|
1658 | - { |
|
1659 | - foreach ($this->images as $image) { |
|
1660 | - $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R'); |
|
1661 | - } |
|
1662 | - } |
|
1663 | - |
|
1664 | - public function _putresourcedict() |
|
1665 | - { |
|
1666 | - $this->_out('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]'); |
|
1667 | - $this->_out('/Font <<'); |
|
1668 | - foreach ($this->fonts as $font) { |
|
1669 | - $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R'); |
|
1670 | - } |
|
1671 | - $this->_out('>>'); |
|
1672 | - $this->_out('/XObject <<'); |
|
1673 | - $this->_putxobjectdict(); |
|
1674 | - $this->_out('>>'); |
|
1675 | - } |
|
1676 | - |
|
1677 | - public function _putresources() |
|
1678 | - { |
|
1679 | - $this->_putfonts(); |
|
1680 | - $this->_putimages(); |
|
1681 | - //Resource dictionary |
|
1682 | - $this->offsets[2] = strlen($this->buffer); |
|
1683 | - $this->_out('2 0 obj'); |
|
1684 | - $this->_out('<<'); |
|
1685 | - $this->_putresourcedict(); |
|
1686 | - $this->_out('>>'); |
|
1687 | - $this->_out('endobj'); |
|
1688 | - } |
|
1689 | - |
|
1690 | - public function _putinfo() |
|
1691 | - { |
|
1692 | - $this->_out('/Producer '.$this->_textstring('FPDF '.FPDF_VERSION)); |
|
1693 | - if (!empty($this->title)) { |
|
1694 | - $this->_out('/Title '.$this->_textstring($this->title)); |
|
1695 | - } |
|
1696 | - if (!empty($this->subject)) { |
|
1697 | - $this->_out('/Subject '.$this->_textstring($this->subject)); |
|
1698 | - } |
|
1699 | - if (!empty($this->author)) { |
|
1700 | - $this->_out('/Author '.$this->_textstring($this->author)); |
|
1701 | - } |
|
1702 | - if (!empty($this->keywords)) { |
|
1703 | - $this->_out('/Keywords '.$this->_textstring($this->keywords)); |
|
1704 | - } |
|
1705 | - if (!empty($this->creator)) { |
|
1706 | - $this->_out('/Creator '.$this->_textstring($this->creator)); |
|
1707 | - } |
|
1708 | - $this->_out('/CreationDate '.$this->_textstring('D:'.@date('YmdHis'))); |
|
1709 | - } |
|
1710 | - |
|
1711 | - public function _putcatalog() |
|
1712 | - { |
|
1713 | - $this->_out('/Type /Catalog'); |
|
1714 | - $this->_out('/Pages 1 0 R'); |
|
1715 | - if ($this->ZoomMode == 'fullpage') { |
|
1716 | - $this->_out('/OpenAction [3 0 R /Fit]'); |
|
1717 | - } elseif ($this->ZoomMode == 'fullwidth') { |
|
1718 | - $this->_out('/OpenAction [3 0 R /FitH null]'); |
|
1719 | - } elseif ($this->ZoomMode == 'real') { |
|
1720 | - $this->_out('/OpenAction [3 0 R /XYZ null null 1]'); |
|
1721 | - } elseif (!is_string($this->ZoomMode)) { |
|
1722 | - $this->_out('/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode / 100).']'); |
|
1723 | - } |
|
1724 | - if ($this->LayoutMode == 'single') { |
|
1725 | - $this->_out('/PageLayout /SinglePage'); |
|
1726 | - } elseif ($this->LayoutMode == 'continuous') { |
|
1727 | - $this->_out('/PageLayout /OneColumn'); |
|
1728 | - } elseif ($this->LayoutMode == 'two') { |
|
1729 | - $this->_out('/PageLayout /TwoColumnLeft'); |
|
1730 | - } |
|
1731 | - } |
|
1732 | - |
|
1733 | - public function _putheader() |
|
1734 | - { |
|
1735 | - $this->_out('%PDF-'.$this->PDFVersion); |
|
1736 | - } |
|
1737 | - |
|
1738 | - public function _puttrailer() |
|
1739 | - { |
|
1740 | - $this->_out('/Size '.($this->n + 1)); |
|
1741 | - $this->_out('/Root '.$this->n.' 0 R'); |
|
1742 | - $this->_out('/Info '.($this->n - 1).' 0 R'); |
|
1743 | - } |
|
1744 | - |
|
1745 | - public function _enddoc() |
|
1746 | - { |
|
1747 | - $this->_putheader(); |
|
1748 | - $this->_putpages(); |
|
1749 | - $this->_putresources(); |
|
1750 | - //Info |
|
1751 | - $this->_newobj(); |
|
1752 | - $this->_out('<<'); |
|
1753 | - $this->_putinfo(); |
|
1754 | - $this->_out('>>'); |
|
1755 | - $this->_out('endobj'); |
|
1756 | - //Catalog |
|
1757 | - $this->_newobj(); |
|
1758 | - $this->_out('<<'); |
|
1759 | - $this->_putcatalog(); |
|
1760 | - $this->_out('>>'); |
|
1761 | - $this->_out('endobj'); |
|
1762 | - //Cross-ref |
|
1763 | - $o = strlen($this->buffer); |
|
1764 | - $this->_out('xref'); |
|
1765 | - $this->_out('0 '.($this->n + 1)); |
|
1766 | - $this->_out('0000000000 65535 f '); |
|
1767 | - for ($i = 1; $i <= $this->n; $i++) { |
|
1768 | - $this->_out(sprintf('%010d 00000 n ', $this->offsets[$i])); |
|
1769 | - } |
|
1770 | - //Trailer |
|
1771 | - $this->_out('trailer'); |
|
1772 | - $this->_out('<<'); |
|
1773 | - $this->_puttrailer(); |
|
1774 | - $this->_out('>>'); |
|
1775 | - $this->_out('startxref'); |
|
1776 | - $this->_out($o); |
|
1777 | - $this->_out('%%EOF'); |
|
1778 | - $this->state = 3; |
|
1779 | - } |
|
1780 | - |
|
1781 | - //End of class |
|
1099 | + public function _dochecks() |
|
1100 | + { |
|
1101 | + //Check availability of %F |
|
1102 | + if (sprintf('%.1F', 1.0) != '1.0') { |
|
1103 | + $this->Error('This version of PHP is not supported'); |
|
1104 | + } |
|
1105 | + //Check mbstring overloading |
|
1106 | + if (ini_get('mbstring.func_overload') & 2) { |
|
1107 | + $this->Error('mbstring overloading must be disabled'); |
|
1108 | + } |
|
1109 | + //Disable runtime magic quotes |
|
1110 | + if (get_magic_quotes_runtime()) { |
|
1111 | + @set_magic_quotes_runtime(0); |
|
1112 | + } |
|
1113 | + } |
|
1114 | + |
|
1115 | + public function _getpageformat($format) |
|
1116 | + { |
|
1117 | + $format = strtolower($format); |
|
1118 | + if (!isset($this->PageFormats[$format])) { |
|
1119 | + $this->Error('Unknown page format: '.$format); |
|
1120 | + } |
|
1121 | + $a = $this->PageFormats[$format]; |
|
1122 | + |
|
1123 | + return [$a[0] / $this->k, $a[1] / $this->k]; |
|
1124 | + } |
|
1125 | + |
|
1126 | + public function _getfontpath() |
|
1127 | + { |
|
1128 | + if (!defined('FPDF_FONTPATH') && is_dir(dirname(__FILE__).'/font')) { |
|
1129 | + define('FPDF_FONTPATH', dirname(__FILE__).'/font/'); |
|
1130 | + } |
|
1131 | + |
|
1132 | + return defined('FPDF_FONTPATH') ? FPDF_FONTPATH : ''; |
|
1133 | + } |
|
1134 | + |
|
1135 | + public function _beginpage($orientation, $format) |
|
1136 | + { |
|
1137 | + $this->page++; |
|
1138 | + $this->pages[$this->page] = ''; |
|
1139 | + $this->state = 2; |
|
1140 | + $this->x = $this->lMargin; |
|
1141 | + $this->y = $this->tMargin; |
|
1142 | + $this->FontFamily = ''; |
|
1143 | + //Check page size |
|
1144 | + if ($orientation == '') { |
|
1145 | + $orientation = $this->DefOrientation; |
|
1146 | + } else { |
|
1147 | + $orientation = strtoupper($orientation[0]); |
|
1148 | + } |
|
1149 | + if ($format == '') { |
|
1150 | + $format = $this->DefPageFormat; |
|
1151 | + } else { |
|
1152 | + if (is_string($format)) { |
|
1153 | + $format = $this->_getpageformat($format); |
|
1154 | + } |
|
1155 | + } |
|
1156 | + if ($orientation != $this->CurOrientation || $format[0] != $this->CurPageFormat[0] || $format[1] != $this->CurPageFormat[1]) { |
|
1157 | + //New size |
|
1158 | + if ($orientation == 'P') { |
|
1159 | + $this->w = $format[0]; |
|
1160 | + $this->h = $format[1]; |
|
1161 | + } else { |
|
1162 | + $this->w = $format[1]; |
|
1163 | + $this->h = $format[0]; |
|
1164 | + } |
|
1165 | + $this->wPt = $this->w * $this->k; |
|
1166 | + $this->hPt = $this->h * $this->k; |
|
1167 | + $this->PageBreakTrigger = $this->h - $this->bMargin; |
|
1168 | + $this->CurOrientation = $orientation; |
|
1169 | + $this->CurPageFormat = $format; |
|
1170 | + } |
|
1171 | + if ($orientation != $this->DefOrientation || $format[0] != $this->DefPageFormat[0] || $format[1] != $this->DefPageFormat[1]) { |
|
1172 | + $this->PageSizes[$this->page] = [$this->wPt, $this->hPt]; |
|
1173 | + } |
|
1174 | + } |
|
1175 | + |
|
1176 | + public function _endpage() |
|
1177 | + { |
|
1178 | + $this->state = 1; |
|
1179 | + } |
|
1180 | + |
|
1181 | + public function _escape($s) |
|
1182 | + { |
|
1183 | + //Escape special characters in strings |
|
1184 | + $s = str_replace('\\', '\\\\', $s); |
|
1185 | + $s = str_replace('(', '\\(', $s); |
|
1186 | + $s = str_replace(')', '\\)', $s); |
|
1187 | + $s = str_replace("\r", '\\r', $s); |
|
1188 | + |
|
1189 | + return $s; |
|
1190 | + } |
|
1191 | + |
|
1192 | + public function _textstring($s) |
|
1193 | + { |
|
1194 | + //Format a text string |
|
1195 | + return '('.$this->_escape($s).')'; |
|
1196 | + } |
|
1197 | + |
|
1198 | + public function _UTF8toUTF16($s) |
|
1199 | + { |
|
1200 | + //Convert UTF-8 to UTF-16BE with BOM |
|
1201 | + $res = "\xFE\xFF"; |
|
1202 | + $nb = strlen($s); |
|
1203 | + $i = 0; |
|
1204 | + while ($i < $nb) { |
|
1205 | + $c1 = ord($s[$i++]); |
|
1206 | + if ($c1 >= 224) { |
|
1207 | + //3-byte character |
|
1208 | + $c2 = ord($s[$i++]); |
|
1209 | + $c3 = ord($s[$i++]); |
|
1210 | + $res .= chr((($c1 & 0x0F) << 4) + (($c2 & 0x3C) >> 2)); |
|
1211 | + $res .= chr((($c2 & 0x03) << 6) + ($c3 & 0x3F)); |
|
1212 | + } elseif ($c1 >= 192) { |
|
1213 | + //2-byte character |
|
1214 | + $c2 = ord($s[$i++]); |
|
1215 | + $res .= chr(($c1 & 0x1C) >> 2); |
|
1216 | + $res .= chr((($c1 & 0x03) << 6) + ($c2 & 0x3F)); |
|
1217 | + } else { |
|
1218 | + //Single-byte character |
|
1219 | + $res .= "\0".chr($c1); |
|
1220 | + } |
|
1221 | + } |
|
1222 | + |
|
1223 | + return $res; |
|
1224 | + } |
|
1225 | + |
|
1226 | + public function _dounderline($x, $y, $txt) |
|
1227 | + { |
|
1228 | + //Underline text |
|
1229 | + $up = $this->CurrentFont['up']; |
|
1230 | + $ut = $this->CurrentFont['ut']; |
|
1231 | + $w = $this->GetStringWidth($txt) + $this->ws * substr_count($txt, ' '); |
|
1232 | + |
|
1233 | + return sprintf('%.2F %.2F %.2F %.2F re f', $x * $this->k, ($this->h - ($y - $up / 1000 * $this->FontSize)) * $this->k, $w * $this->k, -$ut / 1000 * $this->FontSizePt); |
|
1234 | + } |
|
1235 | + |
|
1236 | + public function _parsejpg($file) |
|
1237 | + { |
|
1238 | + //Extract info from a JPEG file |
|
1239 | + $a = getimagesize($file); |
|
1240 | + if (!$a) { |
|
1241 | + $this->Error('Missing or incorrect image file: '.$file); |
|
1242 | + } |
|
1243 | + if ($a[2] != 2) { |
|
1244 | + $this->Error('Not a JPEG file: '.$file); |
|
1245 | + } |
|
1246 | + if (!isset($a['channels']) || $a['channels'] == 3) { |
|
1247 | + $colspace = 'DeviceRGB'; |
|
1248 | + } elseif ($a['channels'] == 4) { |
|
1249 | + $colspace = 'DeviceCMYK'; |
|
1250 | + } else { |
|
1251 | + $colspace = 'DeviceGray'; |
|
1252 | + } |
|
1253 | + $bpc = isset($a['bits']) ? $a['bits'] : 8; |
|
1254 | + //Read whole file |
|
1255 | + $f = fopen($file, 'rb'); |
|
1256 | + $data = ''; |
|
1257 | + while (!feof($f)) { |
|
1258 | + $data .= fread($f, 8192); |
|
1259 | + } |
|
1260 | + fclose($f); |
|
1261 | + |
|
1262 | + return ['w'=>$a[0], 'h'=>$a[1], 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'DCTDecode', 'data'=>$data]; |
|
1263 | + } |
|
1264 | + |
|
1265 | + public function _parsepng($file) |
|
1266 | + { |
|
1267 | + //Extract info from a PNG file |
|
1268 | + $f = fopen($file, 'rb'); |
|
1269 | + if (!$f) { |
|
1270 | + $this->Error('Can\'t open image file: '.$file); |
|
1271 | + } |
|
1272 | + //Check signature |
|
1273 | + if ($this->_readstream($f, 8) != chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) { |
|
1274 | + $this->Error('Not a PNG file: '.$file); |
|
1275 | + } |
|
1276 | + //Read header chunk |
|
1277 | + $this->_readstream($f, 4); |
|
1278 | + if ($this->_readstream($f, 4) != 'IHDR') { |
|
1279 | + $this->Error('Incorrect PNG file: '.$file); |
|
1280 | + } |
|
1281 | + $w = $this->_readint($f); |
|
1282 | + $h = $this->_readint($f); |
|
1283 | + $bpc = ord($this->_readstream($f, 1)); |
|
1284 | + if ($bpc > 8) { |
|
1285 | + $this->Error('16-bit depth not supported: '.$file); |
|
1286 | + } |
|
1287 | + $ct = ord($this->_readstream($f, 1)); |
|
1288 | + if ($ct == 0) { |
|
1289 | + $colspace = 'DeviceGray'; |
|
1290 | + } elseif ($ct == 2) { |
|
1291 | + $colspace = 'DeviceRGB'; |
|
1292 | + } elseif ($ct == 3) { |
|
1293 | + $colspace = 'Indexed'; |
|
1294 | + } else { |
|
1295 | + $this->Error('Alpha channel not supported: '.$file); |
|
1296 | + } |
|
1297 | + if (ord($this->_readstream($f, 1)) != 0) { |
|
1298 | + $this->Error('Unknown compression method: '.$file); |
|
1299 | + } |
|
1300 | + if (ord($this->_readstream($f, 1)) != 0) { |
|
1301 | + $this->Error('Unknown filter method: '.$file); |
|
1302 | + } |
|
1303 | + if (ord($this->_readstream($f, 1)) != 0) { |
|
1304 | + $this->Error('Interlacing not supported: '.$file); |
|
1305 | + } |
|
1306 | + $this->_readstream($f, 4); |
|
1307 | + $parms = '/DecodeParms <</Predictor 15 /Colors '.($ct == 2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>'; |
|
1308 | + //Scan chunks looking for palette, transparency and image data |
|
1309 | + $pal = ''; |
|
1310 | + $trns = ''; |
|
1311 | + $data = ''; |
|
1312 | + do { |
|
1313 | + $n = $this->_readint($f); |
|
1314 | + $type = $this->_readstream($f, 4); |
|
1315 | + if ($type == 'PLTE') { |
|
1316 | + //Read palette |
|
1317 | + $pal = $this->_readstream($f, $n); |
|
1318 | + $this->_readstream($f, 4); |
|
1319 | + } elseif ($type == 'tRNS') { |
|
1320 | + //Read transparency info |
|
1321 | + $t = $this->_readstream($f, $n); |
|
1322 | + if ($ct == 0) { |
|
1323 | + $trns = [ord(substr($t, 1, 1))]; |
|
1324 | + } elseif ($ct == 2) { |
|
1325 | + $trns = [ord(substr($t, 1, 1)), ord(substr($t, 3, 1)), ord(substr($t, 5, 1))]; |
|
1326 | + } else { |
|
1327 | + $pos = strpos($t, chr(0)); |
|
1328 | + if ($pos !== false) { |
|
1329 | + $trns = [$pos]; |
|
1330 | + } |
|
1331 | + } |
|
1332 | + $this->_readstream($f, 4); |
|
1333 | + } elseif ($type == 'IDAT') { |
|
1334 | + //Read image data block |
|
1335 | + $data .= $this->_readstream($f, $n); |
|
1336 | + $this->_readstream($f, 4); |
|
1337 | + } elseif ($type == 'IEND') { |
|
1338 | + break; |
|
1339 | + } else { |
|
1340 | + $this->_readstream($f, $n + 4); |
|
1341 | + } |
|
1342 | + } while ($n); |
|
1343 | + if ($colspace == 'Indexed' && empty($pal)) { |
|
1344 | + $this->Error('Missing palette in '.$file); |
|
1345 | + } |
|
1346 | + fclose($f); |
|
1347 | + |
|
1348 | + return ['w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'FlateDecode', 'parms'=>$parms, 'pal'=>$pal, 'trns'=>$trns, 'data'=>$data]; |
|
1349 | + } |
|
1350 | + |
|
1351 | + public function _readstream($f, $n) |
|
1352 | + { |
|
1353 | + //Read n bytes from stream |
|
1354 | + $res = ''; |
|
1355 | + while ($n > 0 && !feof($f)) { |
|
1356 | + $s = fread($f, $n); |
|
1357 | + if ($s === false) { |
|
1358 | + $this->Error('Error while reading stream'); |
|
1359 | + } |
|
1360 | + $n -= strlen($s); |
|
1361 | + $res .= $s; |
|
1362 | + } |
|
1363 | + if ($n > 0) { |
|
1364 | + $this->Error('Unexpected end of stream'); |
|
1365 | + } |
|
1366 | + |
|
1367 | + return $res; |
|
1368 | + } |
|
1369 | + |
|
1370 | + public function _readint($f) |
|
1371 | + { |
|
1372 | + //Read a 4-byte integer from stream |
|
1373 | + $a = unpack('Ni', $this->_readstream($f, 4)); |
|
1374 | + |
|
1375 | + return $a['i']; |
|
1376 | + } |
|
1377 | + |
|
1378 | + public function _parsegif($file) |
|
1379 | + { |
|
1380 | + //Extract info from a GIF file (via PNG conversion) |
|
1381 | + if (!function_exists('imagepng')) { |
|
1382 | + $this->Error('GD extension is required for GIF support'); |
|
1383 | + } |
|
1384 | + if (!function_exists('imagecreatefromgif')) { |
|
1385 | + $this->Error('GD has no GIF read support'); |
|
1386 | + } |
|
1387 | + $im = imagecreatefromgif($file); |
|
1388 | + if (!$im) { |
|
1389 | + $this->Error('Missing or incorrect image file: '.$file); |
|
1390 | + } |
|
1391 | + imageinterlace($im, 0); |
|
1392 | + $tmp = tempnam('.', 'gif'); |
|
1393 | + if (!$tmp) { |
|
1394 | + $this->Error('Unable to create a temporary file'); |
|
1395 | + } |
|
1396 | + if (!imagepng($im, $tmp)) { |
|
1397 | + $this->Error('Error while saving to temporary file'); |
|
1398 | + } |
|
1399 | + imagedestroy($im); |
|
1400 | + $info = $this->_parsepng($tmp); |
|
1401 | + unlink($tmp); |
|
1402 | + |
|
1403 | + return $info; |
|
1404 | + } |
|
1405 | + |
|
1406 | + public function _newobj() |
|
1407 | + { |
|
1408 | + //Begin a new object |
|
1409 | + $this->n++; |
|
1410 | + $this->offsets[$this->n] = strlen($this->buffer); |
|
1411 | + $this->_out($this->n.' 0 obj'); |
|
1412 | + } |
|
1413 | + |
|
1414 | + public function _putstream($s) |
|
1415 | + { |
|
1416 | + $this->_out('stream'); |
|
1417 | + $this->_out($s); |
|
1418 | + $this->_out('endstream'); |
|
1419 | + } |
|
1420 | + |
|
1421 | + public function _out($s) |
|
1422 | + { |
|
1423 | + //Add a line to the document |
|
1424 | + if ($this->state == 2) { |
|
1425 | + $this->pages[$this->page] .= $s."\n"; |
|
1426 | + } else { |
|
1427 | + $this->buffer .= $s."\n"; |
|
1428 | + } |
|
1429 | + } |
|
1430 | + |
|
1431 | + public function _putpages() |
|
1432 | + { |
|
1433 | + $nb = $this->page; |
|
1434 | + if (!empty($this->AliasNbPages)) { |
|
1435 | + //Replace number of pages |
|
1436 | + for ($n = 1; $n <= $nb; $n++) { |
|
1437 | + $this->pages[$n] = str_replace($this->AliasNbPages, $nb, $this->pages[$n]); |
|
1438 | + } |
|
1439 | + } |
|
1440 | + if ($this->DefOrientation == 'P') { |
|
1441 | + $wPt = $this->DefPageFormat[0] * $this->k; |
|
1442 | + $hPt = $this->DefPageFormat[1] * $this->k; |
|
1443 | + } else { |
|
1444 | + $wPt = $this->DefPageFormat[1] * $this->k; |
|
1445 | + $hPt = $this->DefPageFormat[0] * $this->k; |
|
1446 | + } |
|
1447 | + $filter = ($this->compress) ? '/Filter /FlateDecode ' : ''; |
|
1448 | + for ($n = 1; $n <= $nb; $n++) { |
|
1449 | + //Page |
|
1450 | + $this->_newobj(); |
|
1451 | + $this->_out('<</Type /Page'); |
|
1452 | + $this->_out('/Parent 1 0 R'); |
|
1453 | + if (isset($this->PageSizes[$n])) { |
|
1454 | + $this->_out(sprintf('/MediaBox [0 0 %.2F %.2F]', $this->PageSizes[$n][0], $this->PageSizes[$n][1])); |
|
1455 | + } |
|
1456 | + $this->_out('/Resources 2 0 R'); |
|
1457 | + if (isset($this->PageLinks[$n])) { |
|
1458 | + //Links |
|
1459 | + $annots = '/Annots ['; |
|
1460 | + foreach ($this->PageLinks[$n] as $pl) { |
|
1461 | + $rect = sprintf('%.2F %.2F %.2F %.2F', $pl[0], $pl[1], $pl[0] + $pl[2], $pl[1] - $pl[3]); |
|
1462 | + $annots .= '<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] '; |
|
1463 | + if (is_string($pl[4])) { |
|
1464 | + $annots .= '/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>'; |
|
1465 | + } else { |
|
1466 | + $l = $this->links[$pl[4]]; |
|
1467 | + $h = isset($this->PageSizes[$l[0]]) ? $this->PageSizes[$l[0]][1] : $hPt; |
|
1468 | + $annots .= sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>', 1 + 2 * $l[0], $h - $l[1] * $this->k); |
|
1469 | + } |
|
1470 | + } |
|
1471 | + $this->_out($annots.']'); |
|
1472 | + } |
|
1473 | + $this->_out('/Contents '.($this->n + 1).' 0 R>>'); |
|
1474 | + $this->_out('endobj'); |
|
1475 | + //Page content |
|
1476 | + $p = ($this->compress) ? gzcompress($this->pages[$n]) : $this->pages[$n]; |
|
1477 | + $this->_newobj(); |
|
1478 | + $this->_out('<<'.$filter.'/Length '.strlen($p).'>>'); |
|
1479 | + $this->_putstream($p); |
|
1480 | + $this->_out('endobj'); |
|
1481 | + } |
|
1482 | + //Pages root |
|
1483 | + $this->offsets[1] = strlen($this->buffer); |
|
1484 | + $this->_out('1 0 obj'); |
|
1485 | + $this->_out('<</Type /Pages'); |
|
1486 | + $kids = '/Kids ['; |
|
1487 | + for ($i = 0; $i < $nb; $i++) { |
|
1488 | + $kids .= (3 + 2 * $i).' 0 R '; |
|
1489 | + } |
|
1490 | + $this->_out($kids.']'); |
|
1491 | + $this->_out('/Count '.$nb); |
|
1492 | + $this->_out(sprintf('/MediaBox [0 0 %.2F %.2F]', $wPt, $hPt)); |
|
1493 | + $this->_out('>>'); |
|
1494 | + $this->_out('endobj'); |
|
1495 | + } |
|
1496 | + |
|
1497 | + public function _putfonts() |
|
1498 | + { |
|
1499 | + $nf = $this->n; |
|
1500 | + foreach ($this->diffs as $diff) { |
|
1501 | + //Encodings |
|
1502 | + $this->_newobj(); |
|
1503 | + $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>'); |
|
1504 | + $this->_out('endobj'); |
|
1505 | + } |
|
1506 | + foreach ($this->FontFiles as $file=>$info) { |
|
1507 | + //Font file embedding |
|
1508 | + $this->_newobj(); |
|
1509 | + $this->FontFiles[$file]['n'] = $this->n; |
|
1510 | + $font = ''; |
|
1511 | + $f = fopen($this->_getfontpath().$file, 'rb', 1); |
|
1512 | + if (!$f) { |
|
1513 | + $this->Error('Font file not found'); |
|
1514 | + } |
|
1515 | + while (!feof($f)) { |
|
1516 | + $font .= fread($f, 8192); |
|
1517 | + } |
|
1518 | + fclose($f); |
|
1519 | + $compressed = (substr($file, -2) == '.z'); |
|
1520 | + if (!$compressed && isset($info['length2'])) { |
|
1521 | + $header = (ord($font[0]) == 128); |
|
1522 | + if ($header) { |
|
1523 | + //Strip first binary header |
|
1524 | + $font = substr($font, 6); |
|
1525 | + } |
|
1526 | + if ($header && ord($font[$info['length1']]) == 128) { |
|
1527 | + //Strip second binary header |
|
1528 | + $font = substr($font, 0, $info['length1']).substr($font, $info['length1'] + 6); |
|
1529 | + } |
|
1530 | + } |
|
1531 | + $this->_out('<</Length '.strlen($font)); |
|
1532 | + if ($compressed) { |
|
1533 | + $this->_out('/Filter /FlateDecode'); |
|
1534 | + } |
|
1535 | + $this->_out('/Length1 '.$info['length1']); |
|
1536 | + if (isset($info['length2'])) { |
|
1537 | + $this->_out('/Length2 '.$info['length2'].' /Length3 0'); |
|
1538 | + } |
|
1539 | + $this->_out('>>'); |
|
1540 | + $this->_putstream($font); |
|
1541 | + $this->_out('endobj'); |
|
1542 | + } |
|
1543 | + foreach ($this->fonts as $k=>$font) { |
|
1544 | + //Font objects |
|
1545 | + $this->fonts[$k]['n'] = $this->n + 1; |
|
1546 | + $type = $font['type']; |
|
1547 | + $name = $font['name']; |
|
1548 | + if ($type == 'core') { |
|
1549 | + //Standard font |
|
1550 | + $this->_newobj(); |
|
1551 | + $this->_out('<</Type /Font'); |
|
1552 | + $this->_out('/BaseFont /'.$name); |
|
1553 | + $this->_out('/Subtype /Type1'); |
|
1554 | + if ($name != 'Symbol' && $name != 'ZapfDingbats') { |
|
1555 | + $this->_out('/Encoding /WinAnsiEncoding'); |
|
1556 | + } |
|
1557 | + $this->_out('>>'); |
|
1558 | + $this->_out('endobj'); |
|
1559 | + } elseif ($type == 'Type1' || $type == 'TrueType') { |
|
1560 | + //Additional Type1 or TrueType font |
|
1561 | + $this->_newobj(); |
|
1562 | + $this->_out('<</Type /Font'); |
|
1563 | + $this->_out('/BaseFont /'.$name); |
|
1564 | + $this->_out('/Subtype /'.$type); |
|
1565 | + $this->_out('/FirstChar 32 /LastChar 255'); |
|
1566 | + $this->_out('/Widths '.($this->n + 1).' 0 R'); |
|
1567 | + $this->_out('/FontDescriptor '.($this->n + 2).' 0 R'); |
|
1568 | + if ($font['enc']) { |
|
1569 | + if (isset($font['diff'])) { |
|
1570 | + $this->_out('/Encoding '.($nf + $font['diff']).' 0 R'); |
|
1571 | + } else { |
|
1572 | + $this->_out('/Encoding /WinAnsiEncoding'); |
|
1573 | + } |
|
1574 | + } |
|
1575 | + $this->_out('>>'); |
|
1576 | + $this->_out('endobj'); |
|
1577 | + //Widths |
|
1578 | + $this->_newobj(); |
|
1579 | + $cw = &$font['cw']; |
|
1580 | + $s = '['; |
|
1581 | + for ($i = 32; $i <= 255; $i++) { |
|
1582 | + $s .= $cw[chr($i)].' '; |
|
1583 | + } |
|
1584 | + $this->_out($s.']'); |
|
1585 | + $this->_out('endobj'); |
|
1586 | + //Descriptor |
|
1587 | + $this->_newobj(); |
|
1588 | + $s = '<</Type /FontDescriptor /FontName /'.$name; |
|
1589 | + foreach ($font['desc'] as $k=>$v) { |
|
1590 | + $s .= ' /'.$k.' '.$v; |
|
1591 | + } |
|
1592 | + $file = $font['file']; |
|
1593 | + if ($file) { |
|
1594 | + $s .= ' /FontFile'.($type == 'Type1' ? '' : '2').' '.$this->FontFiles[$file]['n'].' 0 R'; |
|
1595 | + } |
|
1596 | + $this->_out($s.'>>'); |
|
1597 | + $this->_out('endobj'); |
|
1598 | + } else { |
|
1599 | + //Allow for additional types |
|
1600 | + $mtd = '_put'.strtolower($type); |
|
1601 | + if (!method_exists($this, $mtd)) { |
|
1602 | + $this->Error('Unsupported font type: '.$type); |
|
1603 | + } |
|
1604 | + $this->$mtd($font); |
|
1605 | + } |
|
1606 | + } |
|
1607 | + } |
|
1608 | + |
|
1609 | + public function _putimages() |
|
1610 | + { |
|
1611 | + $filter = ($this->compress) ? '/Filter /FlateDecode ' : ''; |
|
1612 | + reset($this->images); |
|
1613 | + while (list($file, $info) = each($this->images)) { |
|
1614 | + $this->_newobj(); |
|
1615 | + $this->images[$file]['n'] = $this->n; |
|
1616 | + $this->_out('<</Type /XObject'); |
|
1617 | + $this->_out('/Subtype /Image'); |
|
1618 | + $this->_out('/Width '.$info['w']); |
|
1619 | + $this->_out('/Height '.$info['h']); |
|
1620 | + if ($info['cs'] == 'Indexed') { |
|
1621 | + $this->_out('/ColorSpace [/Indexed /DeviceRGB '.(strlen($info['pal']) / 3 - 1).' '.($this->n + 1).' 0 R]'); |
|
1622 | + } else { |
|
1623 | + $this->_out('/ColorSpace /'.$info['cs']); |
|
1624 | + if ($info['cs'] == 'DeviceCMYK') { |
|
1625 | + $this->_out('/Decode [1 0 1 0 1 0 1 0]'); |
|
1626 | + } |
|
1627 | + } |
|
1628 | + $this->_out('/BitsPerComponent '.$info['bpc']); |
|
1629 | + if (isset($info['f'])) { |
|
1630 | + $this->_out('/Filter /'.$info['f']); |
|
1631 | + } |
|
1632 | + if (isset($info['parms'])) { |
|
1633 | + $this->_out($info['parms']); |
|
1634 | + } |
|
1635 | + if (isset($info['trns']) && is_array($info['trns'])) { |
|
1636 | + $trns = ''; |
|
1637 | + for ($i = 0; $i < count($info['trns']); $i++) { |
|
1638 | + $trns .= $info['trns'][$i].' '.$info['trns'][$i].' '; |
|
1639 | + } |
|
1640 | + $this->_out('/Mask ['.$trns.']'); |
|
1641 | + } |
|
1642 | + $this->_out('/Length '.strlen($info['data']).'>>'); |
|
1643 | + $this->_putstream($info['data']); |
|
1644 | + unset($this->images[$file]['data']); |
|
1645 | + $this->_out('endobj'); |
|
1646 | + //Palette |
|
1647 | + if ($info['cs'] == 'Indexed') { |
|
1648 | + $this->_newobj(); |
|
1649 | + $pal = ($this->compress) ? gzcompress($info['pal']) : $info['pal']; |
|
1650 | + $this->_out('<<'.$filter.'/Length '.strlen($pal).'>>'); |
|
1651 | + $this->_putstream($pal); |
|
1652 | + $this->_out('endobj'); |
|
1653 | + } |
|
1654 | + } |
|
1655 | + } |
|
1656 | + |
|
1657 | + public function _putxobjectdict() |
|
1658 | + { |
|
1659 | + foreach ($this->images as $image) { |
|
1660 | + $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R'); |
|
1661 | + } |
|
1662 | + } |
|
1663 | + |
|
1664 | + public function _putresourcedict() |
|
1665 | + { |
|
1666 | + $this->_out('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]'); |
|
1667 | + $this->_out('/Font <<'); |
|
1668 | + foreach ($this->fonts as $font) { |
|
1669 | + $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R'); |
|
1670 | + } |
|
1671 | + $this->_out('>>'); |
|
1672 | + $this->_out('/XObject <<'); |
|
1673 | + $this->_putxobjectdict(); |
|
1674 | + $this->_out('>>'); |
|
1675 | + } |
|
1676 | + |
|
1677 | + public function _putresources() |
|
1678 | + { |
|
1679 | + $this->_putfonts(); |
|
1680 | + $this->_putimages(); |
|
1681 | + //Resource dictionary |
|
1682 | + $this->offsets[2] = strlen($this->buffer); |
|
1683 | + $this->_out('2 0 obj'); |
|
1684 | + $this->_out('<<'); |
|
1685 | + $this->_putresourcedict(); |
|
1686 | + $this->_out('>>'); |
|
1687 | + $this->_out('endobj'); |
|
1688 | + } |
|
1689 | + |
|
1690 | + public function _putinfo() |
|
1691 | + { |
|
1692 | + $this->_out('/Producer '.$this->_textstring('FPDF '.FPDF_VERSION)); |
|
1693 | + if (!empty($this->title)) { |
|
1694 | + $this->_out('/Title '.$this->_textstring($this->title)); |
|
1695 | + } |
|
1696 | + if (!empty($this->subject)) { |
|
1697 | + $this->_out('/Subject '.$this->_textstring($this->subject)); |
|
1698 | + } |
|
1699 | + if (!empty($this->author)) { |
|
1700 | + $this->_out('/Author '.$this->_textstring($this->author)); |
|
1701 | + } |
|
1702 | + if (!empty($this->keywords)) { |
|
1703 | + $this->_out('/Keywords '.$this->_textstring($this->keywords)); |
|
1704 | + } |
|
1705 | + if (!empty($this->creator)) { |
|
1706 | + $this->_out('/Creator '.$this->_textstring($this->creator)); |
|
1707 | + } |
|
1708 | + $this->_out('/CreationDate '.$this->_textstring('D:'.@date('YmdHis'))); |
|
1709 | + } |
|
1710 | + |
|
1711 | + public function _putcatalog() |
|
1712 | + { |
|
1713 | + $this->_out('/Type /Catalog'); |
|
1714 | + $this->_out('/Pages 1 0 R'); |
|
1715 | + if ($this->ZoomMode == 'fullpage') { |
|
1716 | + $this->_out('/OpenAction [3 0 R /Fit]'); |
|
1717 | + } elseif ($this->ZoomMode == 'fullwidth') { |
|
1718 | + $this->_out('/OpenAction [3 0 R /FitH null]'); |
|
1719 | + } elseif ($this->ZoomMode == 'real') { |
|
1720 | + $this->_out('/OpenAction [3 0 R /XYZ null null 1]'); |
|
1721 | + } elseif (!is_string($this->ZoomMode)) { |
|
1722 | + $this->_out('/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode / 100).']'); |
|
1723 | + } |
|
1724 | + if ($this->LayoutMode == 'single') { |
|
1725 | + $this->_out('/PageLayout /SinglePage'); |
|
1726 | + } elseif ($this->LayoutMode == 'continuous') { |
|
1727 | + $this->_out('/PageLayout /OneColumn'); |
|
1728 | + } elseif ($this->LayoutMode == 'two') { |
|
1729 | + $this->_out('/PageLayout /TwoColumnLeft'); |
|
1730 | + } |
|
1731 | + } |
|
1732 | + |
|
1733 | + public function _putheader() |
|
1734 | + { |
|
1735 | + $this->_out('%PDF-'.$this->PDFVersion); |
|
1736 | + } |
|
1737 | + |
|
1738 | + public function _puttrailer() |
|
1739 | + { |
|
1740 | + $this->_out('/Size '.($this->n + 1)); |
|
1741 | + $this->_out('/Root '.$this->n.' 0 R'); |
|
1742 | + $this->_out('/Info '.($this->n - 1).' 0 R'); |
|
1743 | + } |
|
1744 | + |
|
1745 | + public function _enddoc() |
|
1746 | + { |
|
1747 | + $this->_putheader(); |
|
1748 | + $this->_putpages(); |
|
1749 | + $this->_putresources(); |
|
1750 | + //Info |
|
1751 | + $this->_newobj(); |
|
1752 | + $this->_out('<<'); |
|
1753 | + $this->_putinfo(); |
|
1754 | + $this->_out('>>'); |
|
1755 | + $this->_out('endobj'); |
|
1756 | + //Catalog |
|
1757 | + $this->_newobj(); |
|
1758 | + $this->_out('<<'); |
|
1759 | + $this->_putcatalog(); |
|
1760 | + $this->_out('>>'); |
|
1761 | + $this->_out('endobj'); |
|
1762 | + //Cross-ref |
|
1763 | + $o = strlen($this->buffer); |
|
1764 | + $this->_out('xref'); |
|
1765 | + $this->_out('0 '.($this->n + 1)); |
|
1766 | + $this->_out('0000000000 65535 f '); |
|
1767 | + for ($i = 1; $i <= $this->n; $i++) { |
|
1768 | + $this->_out(sprintf('%010d 00000 n ', $this->offsets[$i])); |
|
1769 | + } |
|
1770 | + //Trailer |
|
1771 | + $this->_out('trailer'); |
|
1772 | + $this->_out('<<'); |
|
1773 | + $this->_puttrailer(); |
|
1774 | + $this->_out('>>'); |
|
1775 | + $this->_out('startxref'); |
|
1776 | + $this->_out($o); |
|
1777 | + $this->_out('%%EOF'); |
|
1778 | + $this->state = 3; |
|
1779 | + } |
|
1780 | + |
|
1781 | + //End of class |
|
1782 | 1782 | } |
1783 | 1783 | |
1784 | 1784 | //Handle special IE contype request |
1785 | 1785 | if (isset($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT'] == 'contype') { |
1786 | - header('Content-Type: application/pdf'); |
|
1787 | - exit; |
|
1786 | + header('Content-Type: application/pdf'); |
|
1787 | + exit; |
|
1788 | 1788 | } |
@@ -1037,55 +1037,55 @@ |
||
1037 | 1037 | } |
1038 | 1038 | } |
1039 | 1039 | switch ($dest) { |
1040 | - case 'I': |
|
1041 | - //Send to standard output |
|
1042 | - if (ob_get_length()) { |
|
1043 | - $this->Error('Some data has already been output, can\'t send PDF file'); |
|
1044 | - } |
|
1045 | - if (php_sapi_name() != 'cli') { |
|
1046 | - //We send to a browser |
|
1047 | - header('Content-Type: application/pdf'); |
|
1048 | - if (headers_sent()) { |
|
1049 | - $this->Error('Some data has already been output, can\'t send PDF file'); |
|
1050 | - } |
|
1051 | - header('Content-Length: '.strlen($this->buffer)); |
|
1052 | - header('Content-Disposition: inline; filename="'.$name.'"'); |
|
1053 | - header('Cache-Control: private, max-age=0, must-revalidate'); |
|
1054 | - header('Pragma: public'); |
|
1055 | - ini_set('zlib.output_compression', '0'); |
|
1056 | - } |
|
1057 | - echo $this->buffer; |
|
1058 | - break; |
|
1059 | - case 'D': |
|
1060 | - //Download file |
|
1061 | - if (ob_get_length()) { |
|
1062 | - $this->Error('Some data has already been output, can\'t send PDF file'); |
|
1063 | - } |
|
1064 | - header('Content-Type: application/x-download'); |
|
1065 | - if (headers_sent()) { |
|
1066 | - $this->Error('Some data has already been output, can\'t send PDF file'); |
|
1067 | - } |
|
1068 | - header('Content-Length: '.strlen($this->buffer)); |
|
1069 | - header('Content-Disposition: attachment; filename="'.$name.'"'); |
|
1070 | - header('Cache-Control: private, max-age=0, must-revalidate'); |
|
1071 | - header('Pragma: public'); |
|
1072 | - ini_set('zlib.output_compression', '0'); |
|
1073 | - echo $this->buffer; |
|
1074 | - break; |
|
1075 | - case 'F': |
|
1076 | - //Save to local file |
|
1077 | - $f = fopen($name, 'wb'); |
|
1078 | - if (!$f) { |
|
1079 | - $this->Error('Unable to create output file: '.$name); |
|
1080 | - } |
|
1081 | - fwrite($f, $this->buffer, strlen($this->buffer)); |
|
1082 | - fclose($f); |
|
1083 | - break; |
|
1084 | - case 'S': |
|
1085 | - //Return as a string |
|
1086 | - return $this->buffer; |
|
1087 | - default: |
|
1088 | - $this->Error('Incorrect output destination: '.$dest); |
|
1040 | + case 'I': |
|
1041 | + //Send to standard output |
|
1042 | + if (ob_get_length()) { |
|
1043 | + $this->Error('Some data has already been output, can\'t send PDF file'); |
|
1044 | + } |
|
1045 | + if (php_sapi_name() != 'cli') { |
|
1046 | + //We send to a browser |
|
1047 | + header('Content-Type: application/pdf'); |
|
1048 | + if (headers_sent()) { |
|
1049 | + $this->Error('Some data has already been output, can\'t send PDF file'); |
|
1050 | + } |
|
1051 | + header('Content-Length: '.strlen($this->buffer)); |
|
1052 | + header('Content-Disposition: inline; filename="'.$name.'"'); |
|
1053 | + header('Cache-Control: private, max-age=0, must-revalidate'); |
|
1054 | + header('Pragma: public'); |
|
1055 | + ini_set('zlib.output_compression', '0'); |
|
1056 | + } |
|
1057 | + echo $this->buffer; |
|
1058 | + break; |
|
1059 | + case 'D': |
|
1060 | + //Download file |
|
1061 | + if (ob_get_length()) { |
|
1062 | + $this->Error('Some data has already been output, can\'t send PDF file'); |
|
1063 | + } |
|
1064 | + header('Content-Type: application/x-download'); |
|
1065 | + if (headers_sent()) { |
|
1066 | + $this->Error('Some data has already been output, can\'t send PDF file'); |
|
1067 | + } |
|
1068 | + header('Content-Length: '.strlen($this->buffer)); |
|
1069 | + header('Content-Disposition: attachment; filename="'.$name.'"'); |
|
1070 | + header('Cache-Control: private, max-age=0, must-revalidate'); |
|
1071 | + header('Pragma: public'); |
|
1072 | + ini_set('zlib.output_compression', '0'); |
|
1073 | + echo $this->buffer; |
|
1074 | + break; |
|
1075 | + case 'F': |
|
1076 | + //Save to local file |
|
1077 | + $f = fopen($name, 'wb'); |
|
1078 | + if (!$f) { |
|
1079 | + $this->Error('Unable to create output file: '.$name); |
|
1080 | + } |
|
1081 | + fwrite($f, $this->buffer, strlen($this->buffer)); |
|
1082 | + fclose($f); |
|
1083 | + break; |
|
1084 | + case 'S': |
|
1085 | + //Return as a string |
|
1086 | + return $this->buffer; |
|
1087 | + default: |
|
1088 | + $this->Error('Incorrect output destination: '.$dest); |
|
1089 | 1089 | } |
1090 | 1090 | |
1091 | 1091 | return ''; |
@@ -11,64 +11,64 @@ discard block |
||
11 | 11 | |
12 | 12 | class FPDF |
13 | 13 | { |
14 | - public $page; //current page number |
|
15 | -public $n; //current object number |
|
16 | -public $offsets; //array of object offsets |
|
17 | -public $buffer; //buffer holding in-memory PDF |
|
18 | -public $pages; //array containing pages |
|
19 | -public $state; //current document state |
|
20 | -public $compress; //compression flag |
|
21 | -public $k; //scale factor (number of points in user unit) |
|
22 | -public $DefOrientation; //default orientation |
|
23 | -public $CurOrientation; //current orientation |
|
24 | -public $PageFormats; //available page formats |
|
25 | -public $DefPageFormat; //default page format |
|
26 | -public $CurPageFormat; //current page format |
|
27 | -public $PageSizes; //array storing non-default page sizes |
|
14 | + public $page; //current page number |
|
15 | +public $n; //current object number |
|
16 | +public $offsets; //array of object offsets |
|
17 | +public $buffer; //buffer holding in-memory PDF |
|
18 | +public $pages; //array containing pages |
|
19 | +public $state; //current document state |
|
20 | +public $compress; //compression flag |
|
21 | +public $k; //scale factor (number of points in user unit) |
|
22 | +public $DefOrientation; //default orientation |
|
23 | +public $CurOrientation; //current orientation |
|
24 | +public $PageFormats; //available page formats |
|
25 | +public $DefPageFormat; //default page format |
|
26 | +public $CurPageFormat; //current page format |
|
27 | +public $PageSizes; //array storing non-default page sizes |
|
28 | 28 | public $wPt; |
29 | - public $hPt; //dimensions of current page in points |
|
29 | + public $hPt; //dimensions of current page in points |
|
30 | 30 | public $w; |
31 | - public $h; //dimensions of current page in user unit |
|
32 | -public $lMargin; //left margin |
|
33 | -public $tMargin; //top margin |
|
34 | -public $rMargin; //right margin |
|
35 | -public $bMargin; //page break margin |
|
36 | -public $cMargin; //cell margin |
|
31 | + public $h; //dimensions of current page in user unit |
|
32 | +public $lMargin; //left margin |
|
33 | +public $tMargin; //top margin |
|
34 | +public $rMargin; //right margin |
|
35 | +public $bMargin; //page break margin |
|
36 | +public $cMargin; //cell margin |
|
37 | 37 | public $x; |
38 | - public $y; //current position in user unit |
|
39 | -public $lasth; //height of last printed cell |
|
40 | -public $LineWidth; //line width in user unit |
|
41 | -public $CoreFonts; //array of standard font names |
|
42 | -public $fonts; //array of used fonts |
|
43 | -public $FontFiles; //array of font files |
|
44 | -public $diffs; //array of encoding differences |
|
45 | -public $FontFamily; //current font family |
|
46 | -public $FontStyle; //current font style |
|
47 | -public $underline; //underlining flag |
|
48 | -public $CurrentFont; //current font info |
|
49 | -public $FontSizePt; //current font size in points |
|
50 | -public $FontSize; //current font size in user unit |
|
51 | -public $DrawColor; //commands for drawing color |
|
52 | -public $FillColor; //commands for filling color |
|
53 | -public $TextColor; //commands for text color |
|
54 | -public $ColorFlag; //indicates whether fill and text colors are different |
|
55 | -public $ws; //word spacing |
|
56 | -public $images; //array of used images |
|
57 | -public $PageLinks; //array of links in pages |
|
58 | -public $links; //array of internal links |
|
59 | -public $AutoPageBreak; //automatic page breaking |
|
60 | -public $PageBreakTrigger; //threshold used to trigger page breaks |
|
61 | -public $InHeader; //flag set when processing header |
|
62 | -public $InFooter; //flag set when processing footer |
|
63 | -public $ZoomMode; //zoom display mode |
|
64 | -public $LayoutMode; //layout display mode |
|
65 | -public $title; //title |
|
66 | -public $subject; //subject |
|
67 | -public $author; //author |
|
68 | -public $keywords; //keywords |
|
69 | -public $creator; //creator |
|
70 | -public $AliasNbPages; //alias for total number of pages |
|
71 | -public $PDFVersion; //PDF version number |
|
38 | + public $y; //current position in user unit |
|
39 | +public $lasth; //height of last printed cell |
|
40 | +public $LineWidth; //line width in user unit |
|
41 | +public $CoreFonts; //array of standard font names |
|
42 | +public $fonts; //array of used fonts |
|
43 | +public $FontFiles; //array of font files |
|
44 | +public $diffs; //array of encoding differences |
|
45 | +public $FontFamily; //current font family |
|
46 | +public $FontStyle; //current font style |
|
47 | +public $underline; //underlining flag |
|
48 | +public $CurrentFont; //current font info |
|
49 | +public $FontSizePt; //current font size in points |
|
50 | +public $FontSize; //current font size in user unit |
|
51 | +public $DrawColor; //commands for drawing color |
|
52 | +public $FillColor; //commands for filling color |
|
53 | +public $TextColor; //commands for text color |
|
54 | +public $ColorFlag; //indicates whether fill and text colors are different |
|
55 | +public $ws; //word spacing |
|
56 | +public $images; //array of used images |
|
57 | +public $PageLinks; //array of links in pages |
|
58 | +public $links; //array of internal links |
|
59 | +public $AutoPageBreak; //automatic page breaking |
|
60 | +public $PageBreakTrigger; //threshold used to trigger page breaks |
|
61 | +public $InHeader; //flag set when processing header |
|
62 | +public $InFooter; //flag set when processing footer |
|
63 | +public $ZoomMode; //zoom display mode |
|
64 | +public $LayoutMode; //layout display mode |
|
65 | +public $title; //title |
|
66 | +public $subject; //subject |
|
67 | +public $author; //author |
|
68 | +public $keywords; //keywords |
|
69 | +public $creator; //creator |
|
70 | +public $AliasNbPages; //alias for total number of pages |
|
71 | +public $PDFVersion; //PDF version number |
|
72 | 72 | |
73 | 73 | /******************************************************************************* |
74 | 74 | * * |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | $this->k = 72 / 2.54; |
118 | 118 | } elseif ($unit == 'in') { |
119 | 119 | $this->k = 72; |
120 | - } else { |
|
120 | + }else { |
|
121 | 121 | $this->Error('Incorrect unit: '.$unit); |
122 | 122 | } |
123 | 123 | //Page format |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | $this->DefOrientation = 'L'; |
139 | 139 | $this->w = $this->DefPageFormat[1]; |
140 | 140 | $this->h = $this->DefPageFormat[0]; |
141 | - } else { |
|
141 | + }else { |
|
142 | 142 | $this->Error('Incorrect orientation: '.$orientation); |
143 | 143 | } |
144 | 144 | $this->CurOrientation = $this->DefOrientation; |
@@ -206,12 +206,12 @@ discard block |
||
206 | 206 | //Set display mode in viewer |
207 | 207 | if ($zoom == 'fullpage' || $zoom == 'fullwidth' || $zoom == 'real' || $zoom == 'default' || !is_string($zoom)) { |
208 | 208 | $this->ZoomMode = $zoom; |
209 | - } else { |
|
209 | + }else { |
|
210 | 210 | $this->Error('Incorrect zoom display mode: '.$zoom); |
211 | 211 | } |
212 | 212 | if ($layout == 'single' || $layout == 'continuous' || $layout == 'two' || $layout == 'default') { |
213 | 213 | $this->LayoutMode = $layout; |
214 | - } else { |
|
214 | + }else { |
|
215 | 215 | $this->Error('Incorrect layout display mode: '.$layout); |
216 | 216 | } |
217 | 217 | } |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | //Set page compression |
222 | 222 | if (function_exists('gzcompress')) { |
223 | 223 | $this->compress = $compress; |
224 | - } else { |
|
224 | + }else { |
|
225 | 225 | $this->compress = false; |
226 | 226 | } |
227 | 227 | } |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | //Set color for all stroking operations |
400 | 400 | if (($r == 0 && $g == 0 && $b == 0) || $g === null) { |
401 | 401 | $this->DrawColor = sprintf('%.3F G', $r / 255); |
402 | - } else { |
|
402 | + }else { |
|
403 | 403 | $this->DrawColor = sprintf('%.3F %.3F %.3F RG', $r / 255, $g / 255, $b / 255); |
404 | 404 | } |
405 | 405 | if ($this->page > 0) { |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | //Set color for all filling operations |
413 | 413 | if (($r == 0 && $g == 0 && $b == 0) || $g === null) { |
414 | 414 | $this->FillColor = sprintf('%.3F g', $r / 255); |
415 | - } else { |
|
415 | + }else { |
|
416 | 416 | $this->FillColor = sprintf('%.3F %.3F %.3F rg', $r / 255, $g / 255, $b / 255); |
417 | 417 | } |
418 | 418 | $this->ColorFlag = ($this->FillColor != $this->TextColor); |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | //Set color for text |
427 | 427 | if (($r == 0 && $g == 0 && $b == 0) || $g === null) { |
428 | 428 | $this->TextColor = sprintf('%.3F g', $r / 255); |
429 | - } else { |
|
429 | + }else { |
|
430 | 430 | $this->TextColor = sprintf('%.3F %.3F %.3F rg', $r / 255, $g / 255, $b / 255); |
431 | 431 | } |
432 | 432 | $this->ColorFlag = ($this->FillColor != $this->TextColor); |
@@ -468,7 +468,7 @@ discard block |
||
468 | 468 | $op = 'f'; |
469 | 469 | } elseif ($style == 'FD' || $style == 'DF') { |
470 | 470 | $op = 'B'; |
471 | - } else { |
|
471 | + }else { |
|
472 | 472 | $op = 'S'; |
473 | 473 | } |
474 | 474 | $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s', $x * $this->k, ($this->h - $y) * $this->k, $w * $this->k, -$h * $this->k, $op)); |
@@ -517,7 +517,7 @@ discard block |
||
517 | 517 | if ($file) { |
518 | 518 | if ($type == 'TrueType') { |
519 | 519 | $this->FontFiles[$file] = ['length1'=>$originalsize]; |
520 | - } else { |
|
520 | + }else { |
|
521 | 521 | $this->FontFiles[$file] = ['length1'=>$size1, 'length2'=>$size2]; |
522 | 522 | } |
523 | 523 | } |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | if (strpos($style, 'U') !== false) { |
542 | 542 | $this->underline = true; |
543 | 543 | $style = str_replace('U', '', $style); |
544 | - } else { |
|
544 | + }else { |
|
545 | 545 | $this->underline = false; |
546 | 546 | } |
547 | 547 | if ($style == 'IB') { |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | $name = $this->CoreFonts[$fontkey]; |
575 | 575 | $cw = $fpdf_charwidths[$fontkey]; |
576 | 576 | $this->fonts[$fontkey] = ['i'=>$i, 'type'=>'core', 'name'=>$name, 'up'=>-100, 'ut'=>50, 'cw'=>$cw]; |
577 | - } else { |
|
577 | + }else { |
|
578 | 578 | $this->Error('Undefined font: '.$family.' '.$style); |
579 | 579 | } |
580 | 580 | } |
@@ -674,7 +674,7 @@ discard block |
||
674 | 674 | if ($fill || $border == 1) { |
675 | 675 | if ($fill) { |
676 | 676 | $op = ($border == 1) ? 'B' : 'f'; |
677 | - } else { |
|
677 | + }else { |
|
678 | 678 | $op = 'S'; |
679 | 679 | } |
680 | 680 | $s = sprintf('%.2F %.2F %.2F %.2F re %s ', $this->x * $k, ($this->h - $this->y) * $k, $w * $k, -$h * $k, $op); |
@@ -700,7 +700,7 @@ discard block |
||
700 | 700 | $dx = $w - $this->cMargin - $this->GetStringWidth($txt); |
701 | 701 | } elseif ($align == 'C') { |
702 | 702 | $dx = ($w - $this->GetStringWidth($txt)) / 2; |
703 | - } else { |
|
703 | + }else { |
|
704 | 704 | $dx = $this->cMargin; |
705 | 705 | } |
706 | 706 | if ($this->ColorFlag) { |
@@ -728,7 +728,7 @@ discard block |
||
728 | 728 | if ($ln == 1) { |
729 | 729 | $this->x = $this->lMargin; |
730 | 730 | } |
731 | - } else { |
|
731 | + }else { |
|
732 | 732 | $this->x += $w; |
733 | 733 | } |
734 | 734 | } |
@@ -752,7 +752,7 @@ discard block |
||
752 | 752 | $border = 'LTRB'; |
753 | 753 | $b = 'LRT'; |
754 | 754 | $b2 = 'LR'; |
755 | - } else { |
|
755 | + }else { |
|
756 | 756 | $b2 = ''; |
757 | 757 | if (strpos($border, 'L') !== false) { |
758 | 758 | $b2 .= 'L'; |
@@ -807,7 +807,7 @@ discard block |
||
807 | 807 | $this->_out('0 Tw'); |
808 | 808 | } |
809 | 809 | $this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill); |
810 | - } else { |
|
810 | + }else { |
|
811 | 811 | if ($align == 'J') { |
812 | 812 | $this->ws = ($ns > 1) ? ($wmax - $ls) / 1000 * $this->FontSize / ($ns - 1) : 0; |
813 | 813 | $this->_out(sprintf('%.3F Tw', $this->ws * $this->k)); |
@@ -823,7 +823,7 @@ discard block |
||
823 | 823 | if ($border && $nl == 2) { |
824 | 824 | $b = $b2; |
825 | 825 | } |
826 | - } else { |
|
826 | + }else { |
|
827 | 827 | $i++; |
828 | 828 | } |
829 | 829 | } |
@@ -891,7 +891,7 @@ discard block |
||
891 | 891 | $i++; |
892 | 892 | } |
893 | 893 | $this->Cell($w, $h, substr($s, $j, $i - $j), 0, 2, '', 0, $link); |
894 | - } else { |
|
894 | + }else { |
|
895 | 895 | $this->Cell($w, $h, substr($s, $j, $sep - $j), 0, 2, '', 0, $link); |
896 | 896 | $i = $sep + 1; |
897 | 897 | } |
@@ -904,7 +904,7 @@ discard block |
||
904 | 904 | $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; |
905 | 905 | } |
906 | 906 | $nl++; |
907 | - } else { |
|
907 | + }else { |
|
908 | 908 | $i++; |
909 | 909 | } |
910 | 910 | } |
@@ -920,7 +920,7 @@ discard block |
||
920 | 920 | $this->x = $this->lMargin; |
921 | 921 | if ($h === null) { |
922 | 922 | $this->y += $this->lasth; |
923 | - } else { |
|
923 | + }else { |
|
924 | 924 | $this->y += $h; |
925 | 925 | } |
926 | 926 | } |
@@ -948,7 +948,7 @@ discard block |
||
948 | 948 | $info = $this->$mtd($file); |
949 | 949 | $info['i'] = count($this->images) + 1; |
950 | 950 | $this->images[$file] = $info; |
951 | - } else { |
|
951 | + }else { |
|
952 | 952 | $info = $this->images[$file]; |
953 | 953 | } |
954 | 954 | //Automatic width and height calculation if needed |
@@ -992,7 +992,7 @@ discard block |
||
992 | 992 | //Set x position |
993 | 993 | if ($x >= 0) { |
994 | 994 | $this->x = $x; |
995 | - } else { |
|
995 | + }else { |
|
996 | 996 | $this->x = $this->w + $x; |
997 | 997 | } |
998 | 998 | } |
@@ -1009,7 +1009,7 @@ discard block |
||
1009 | 1009 | $this->x = $this->lMargin; |
1010 | 1010 | if ($y >= 0) { |
1011 | 1011 | $this->y = $y; |
1012 | - } else { |
|
1012 | + }else { |
|
1013 | 1013 | $this->y = $this->h + $y; |
1014 | 1014 | } |
1015 | 1015 | } |
@@ -1032,7 +1032,7 @@ discard block |
||
1032 | 1032 | if ($name == '') { |
1033 | 1033 | $name = 'doc.pdf'; |
1034 | 1034 | $dest = 'I'; |
1035 | - } else { |
|
1035 | + }else { |
|
1036 | 1036 | $dest = 'F'; |
1037 | 1037 | } |
1038 | 1038 | } |
@@ -1143,12 +1143,12 @@ discard block |
||
1143 | 1143 | //Check page size |
1144 | 1144 | if ($orientation == '') { |
1145 | 1145 | $orientation = $this->DefOrientation; |
1146 | - } else { |
|
1146 | + }else { |
|
1147 | 1147 | $orientation = strtoupper($orientation[0]); |
1148 | 1148 | } |
1149 | 1149 | if ($format == '') { |
1150 | 1150 | $format = $this->DefPageFormat; |
1151 | - } else { |
|
1151 | + }else { |
|
1152 | 1152 | if (is_string($format)) { |
1153 | 1153 | $format = $this->_getpageformat($format); |
1154 | 1154 | } |
@@ -1158,7 +1158,7 @@ discard block |
||
1158 | 1158 | if ($orientation == 'P') { |
1159 | 1159 | $this->w = $format[0]; |
1160 | 1160 | $this->h = $format[1]; |
1161 | - } else { |
|
1161 | + }else { |
|
1162 | 1162 | $this->w = $format[1]; |
1163 | 1163 | $this->h = $format[0]; |
1164 | 1164 | } |
@@ -1214,7 +1214,7 @@ discard block |
||
1214 | 1214 | $c2 = ord($s[$i++]); |
1215 | 1215 | $res .= chr(($c1 & 0x1C) >> 2); |
1216 | 1216 | $res .= chr((($c1 & 0x03) << 6) + ($c2 & 0x3F)); |
1217 | - } else { |
|
1217 | + }else { |
|
1218 | 1218 | //Single-byte character |
1219 | 1219 | $res .= "\0".chr($c1); |
1220 | 1220 | } |
@@ -1247,7 +1247,7 @@ discard block |
||
1247 | 1247 | $colspace = 'DeviceRGB'; |
1248 | 1248 | } elseif ($a['channels'] == 4) { |
1249 | 1249 | $colspace = 'DeviceCMYK'; |
1250 | - } else { |
|
1250 | + }else { |
|
1251 | 1251 | $colspace = 'DeviceGray'; |
1252 | 1252 | } |
1253 | 1253 | $bpc = isset($a['bits']) ? $a['bits'] : 8; |
@@ -1291,7 +1291,7 @@ discard block |
||
1291 | 1291 | $colspace = 'DeviceRGB'; |
1292 | 1292 | } elseif ($ct == 3) { |
1293 | 1293 | $colspace = 'Indexed'; |
1294 | - } else { |
|
1294 | + }else { |
|
1295 | 1295 | $this->Error('Alpha channel not supported: '.$file); |
1296 | 1296 | } |
1297 | 1297 | if (ord($this->_readstream($f, 1)) != 0) { |
@@ -1323,7 +1323,7 @@ discard block |
||
1323 | 1323 | $trns = [ord(substr($t, 1, 1))]; |
1324 | 1324 | } elseif ($ct == 2) { |
1325 | 1325 | $trns = [ord(substr($t, 1, 1)), ord(substr($t, 3, 1)), ord(substr($t, 5, 1))]; |
1326 | - } else { |
|
1326 | + }else { |
|
1327 | 1327 | $pos = strpos($t, chr(0)); |
1328 | 1328 | if ($pos !== false) { |
1329 | 1329 | $trns = [$pos]; |
@@ -1336,7 +1336,7 @@ discard block |
||
1336 | 1336 | $this->_readstream($f, 4); |
1337 | 1337 | } elseif ($type == 'IEND') { |
1338 | 1338 | break; |
1339 | - } else { |
|
1339 | + }else { |
|
1340 | 1340 | $this->_readstream($f, $n + 4); |
1341 | 1341 | } |
1342 | 1342 | } while ($n); |
@@ -1423,7 +1423,7 @@ discard block |
||
1423 | 1423 | //Add a line to the document |
1424 | 1424 | if ($this->state == 2) { |
1425 | 1425 | $this->pages[$this->page] .= $s."\n"; |
1426 | - } else { |
|
1426 | + }else { |
|
1427 | 1427 | $this->buffer .= $s."\n"; |
1428 | 1428 | } |
1429 | 1429 | } |
@@ -1440,7 +1440,7 @@ discard block |
||
1440 | 1440 | if ($this->DefOrientation == 'P') { |
1441 | 1441 | $wPt = $this->DefPageFormat[0] * $this->k; |
1442 | 1442 | $hPt = $this->DefPageFormat[1] * $this->k; |
1443 | - } else { |
|
1443 | + }else { |
|
1444 | 1444 | $wPt = $this->DefPageFormat[1] * $this->k; |
1445 | 1445 | $hPt = $this->DefPageFormat[0] * $this->k; |
1446 | 1446 | } |
@@ -1462,7 +1462,7 @@ discard block |
||
1462 | 1462 | $annots .= '<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] '; |
1463 | 1463 | if (is_string($pl[4])) { |
1464 | 1464 | $annots .= '/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>'; |
1465 | - } else { |
|
1465 | + }else { |
|
1466 | 1466 | $l = $this->links[$pl[4]]; |
1467 | 1467 | $h = isset($this->PageSizes[$l[0]]) ? $this->PageSizes[$l[0]][1] : $hPt; |
1468 | 1468 | $annots .= sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>', 1 + 2 * $l[0], $h - $l[1] * $this->k); |
@@ -1568,7 +1568,7 @@ discard block |
||
1568 | 1568 | if ($font['enc']) { |
1569 | 1569 | if (isset($font['diff'])) { |
1570 | 1570 | $this->_out('/Encoding '.($nf + $font['diff']).' 0 R'); |
1571 | - } else { |
|
1571 | + }else { |
|
1572 | 1572 | $this->_out('/Encoding /WinAnsiEncoding'); |
1573 | 1573 | } |
1574 | 1574 | } |
@@ -1595,7 +1595,7 @@ discard block |
||
1595 | 1595 | } |
1596 | 1596 | $this->_out($s.'>>'); |
1597 | 1597 | $this->_out('endobj'); |
1598 | - } else { |
|
1598 | + }else { |
|
1599 | 1599 | //Allow for additional types |
1600 | 1600 | $mtd = '_put'.strtolower($type); |
1601 | 1601 | if (!method_exists($this, $mtd)) { |
@@ -1619,7 +1619,7 @@ discard block |
||
1619 | 1619 | $this->_out('/Height '.$info['h']); |
1620 | 1620 | if ($info['cs'] == 'Indexed') { |
1621 | 1621 | $this->_out('/ColorSpace [/Indexed /DeviceRGB '.(strlen($info['pal']) / 3 - 1).' '.($this->n + 1).' 0 R]'); |
1622 | - } else { |
|
1622 | + }else { |
|
1623 | 1623 | $this->_out('/ColorSpace /'.$info['cs']); |
1624 | 1624 | if ($info['cs'] == 'DeviceCMYK') { |
1625 | 1625 | $this->_out('/Decode [1 0 1 0 1 0 1 0]'); |