@@ -52,34 +52,34 @@ discard block |
||
52 | 52 | */ |
53 | 53 | class List_Bullet_Image_Frame_Decorator extends Frame_Decorator { |
54 | 54 | |
55 | - /** |
|
56 | - * The underlying image frame |
|
57 | - * |
|
58 | - * @var Image_Frame_Decorator |
|
59 | - */ |
|
60 | - protected $_img; |
|
55 | + /** |
|
56 | + * The underlying image frame |
|
57 | + * |
|
58 | + * @var Image_Frame_Decorator |
|
59 | + */ |
|
60 | + protected $_img; |
|
61 | 61 | |
62 | - /** |
|
63 | - * The image's width in pixels |
|
64 | - * |
|
65 | - * @var int |
|
66 | - */ |
|
67 | - protected $_width; |
|
62 | + /** |
|
63 | + * The image's width in pixels |
|
64 | + * |
|
65 | + * @var int |
|
66 | + */ |
|
67 | + protected $_width; |
|
68 | 68 | |
69 | - /** |
|
70 | - * The image's height in pixels |
|
71 | - * |
|
72 | - * @var int |
|
73 | - */ |
|
74 | - protected $_height; |
|
69 | + /** |
|
70 | + * The image's height in pixels |
|
71 | + * |
|
72 | + * @var int |
|
73 | + */ |
|
74 | + protected $_height; |
|
75 | 75 | |
76 | - /** |
|
77 | - * Class constructor |
|
78 | - * |
|
79 | - * @param Frame $frame the bullet frame to decorate |
|
80 | - * @param DOMPDF $dompdf the document's dompdf object |
|
81 | - */ |
|
82 | - function __construct(Frame $frame, DOMPDF $dompdf) { |
|
76 | + /** |
|
77 | + * Class constructor |
|
78 | + * |
|
79 | + * @param Frame $frame the bullet frame to decorate |
|
80 | + * @param DOMPDF $dompdf the document's dompdf object |
|
81 | + */ |
|
82 | + function __construct(Frame $frame, DOMPDF $dompdf) { |
|
83 | 83 | $style = $frame->get_style(); |
84 | 84 | $url = $style->list_style_image; |
85 | 85 | $frame->get_node()->setAttribute("src", $url); |
@@ -104,38 +104,38 @@ discard block |
||
104 | 104 | // $style->min_height = $this->_height; |
105 | 105 | //} |
106 | 106 | //$style->height = "auto"; |
107 | - } |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Return the bullet's width |
|
111 | - * |
|
112 | - * @return int |
|
113 | - */ |
|
114 | - function get_width() { |
|
109 | + /** |
|
110 | + * Return the bullet's width |
|
111 | + * |
|
112 | + * @return int |
|
113 | + */ |
|
114 | + function get_width() { |
|
115 | 115 | //ignore image width, use same width as on predefined bullet List_Bullet_Frame_Decorator |
116 | 116 | //for proper alignment of bullet image and text. Allow image to not fitting on left border. |
117 | 117 | //This controls the distance between bullet image and text |
118 | 118 | //return $this->_width; |
119 | 119 | return $this->_frame->get_style()->get_font_size()*List_Bullet_Frame_Decorator::BULLET_SIZE + |
120 | 120 | 2 * List_Bullet_Frame_Decorator::BULLET_PADDING; |
121 | - } |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * Return the bullet's height |
|
125 | - * |
|
126 | - * @return int |
|
127 | - */ |
|
128 | - function get_height() { |
|
123 | + /** |
|
124 | + * Return the bullet's height |
|
125 | + * |
|
126 | + * @return int |
|
127 | + */ |
|
128 | + function get_height() { |
|
129 | 129 | //based on image height |
130 | 130 | return $this->_height; |
131 | - } |
|
131 | + } |
|
132 | 132 | |
133 | - /** |
|
134 | - * Override get_margin_width |
|
135 | - * |
|
136 | - * @return int |
|
137 | - */ |
|
138 | - function get_margin_width() { |
|
133 | + /** |
|
134 | + * Override get_margin_width |
|
135 | + * |
|
136 | + * @return int |
|
137 | + */ |
|
138 | + function get_margin_width() { |
|
139 | 139 | //ignore image width, use same width as on predefined bullet List_Bullet_Frame_Decorator |
140 | 140 | //for proper alignment of bullet image and text. Allow image to not fitting on left border. |
141 | 141 | //This controls the extra indentation of text to make room for the bullet image. |
@@ -147,42 +147,42 @@ discard block |
||
147 | 147 | // Image Might not exist, then position like on list_bullet_frame_decorator fallback to none. |
148 | 148 | if ( $this->_frame->get_style()->list_style_position === "outside" || |
149 | 149 | $this->_width == 0) |
150 | - return 0; |
|
150 | + return 0; |
|
151 | 151 | //This aligns the "inside" image position with the text. |
152 | 152 | //The text starts to the right of the image. |
153 | 153 | //Between the image and the text there is an added margin of image width. |
154 | 154 | //Where this comes from is unknown. |
155 | 155 | //The corresponding List_Bullet_Frame_Decorator sets a smaller margin. bullet size? |
156 | 156 | return $this->_width + 2 * List_Bullet_Frame_Decorator::BULLET_PADDING; |
157 | - } |
|
157 | + } |
|
158 | 158 | |
159 | - /** |
|
160 | - * Override get_margin_height() |
|
161 | - * |
|
162 | - * @return int |
|
163 | - */ |
|
164 | - function get_margin_height() { |
|
159 | + /** |
|
160 | + * Override get_margin_height() |
|
161 | + * |
|
162 | + * @return int |
|
163 | + */ |
|
164 | + function get_margin_height() { |
|
165 | 165 | //Hits only on "inset" lists items, to increase height of box |
166 | 166 | //based on image height |
167 | 167 | return $this->_height + 2 * List_Bullet_Frame_Decorator::BULLET_PADDING; |
168 | - } |
|
168 | + } |
|
169 | 169 | |
170 | - /** |
|
171 | - * Return image url |
|
172 | - * |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - function get_image_url() { |
|
170 | + /** |
|
171 | + * Return image url |
|
172 | + * |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + function get_image_url() { |
|
176 | 176 | return $this->_img->get_image_url(); |
177 | - } |
|
177 | + } |
|
178 | 178 | |
179 | - /** |
|
180 | - * Return the image extension |
|
181 | - * |
|
182 | - * @return string |
|
183 | - */ |
|
184 | - function get_image_ext() { |
|
179 | + /** |
|
180 | + * Return the image extension |
|
181 | + * |
|
182 | + * @return string |
|
183 | + */ |
|
184 | + function get_image_ext() { |
|
185 | 185 | return $this->_img->get_image_ext(); |
186 | - } |
|
186 | + } |
|
187 | 187 | |
188 | 188 | } |
@@ -34,7 +34,6 @@ discard block |
||
34 | 34 | * @copyright 2004 Benj Carson |
35 | 35 | * @author Benj Carson <[email protected]> |
36 | 36 | * @package dompdf |
37 | - |
|
38 | 37 | */ |
39 | 38 | |
40 | 39 | /* $Id: frame_factory.cls.php 216 2010-03-11 22:49:18Z ryan.masten $ */ |
@@ -52,119 +51,119 @@ discard block |
||
52 | 51 | */ |
53 | 52 | class Frame_Factory { |
54 | 53 | |
55 | - static function decorate_root(Frame $root, DOMPDF $dompdf) { |
|
54 | + static function decorate_root(Frame $root, DOMPDF $dompdf) { |
|
56 | 55 | $frame = new Page_Frame_Decorator($root, $dompdf); |
57 | 56 | $frame->set_reflower( new Page_Frame_Reflower($frame) ); |
58 | 57 | $root->set_decorator($frame); |
59 | 58 | return $frame; |
60 | - } |
|
59 | + } |
|
61 | 60 | |
62 | - // FIXME: this is admittedly a little smelly... |
|
63 | - static function decorate_frame(Frame $frame, $dompdf) { |
|
61 | + // FIXME: this is admittedly a little smelly... |
|
62 | + static function decorate_frame(Frame $frame, $dompdf) { |
|
64 | 63 | if ( is_null($dompdf) ) |
65 | - throw new Exception("foo"); |
|
64 | + throw new Exception("foo"); |
|
66 | 65 | switch ($frame->get_style()->display) { |
67 | 66 | |
68 | 67 | case "block": |
69 | 68 | $positioner = "Block"; |
70 | - $decorator = "Block"; |
|
71 | - $reflower = "Block"; |
|
72 | - break; |
|
69 | + $decorator = "Block"; |
|
70 | + $reflower = "Block"; |
|
71 | + break; |
|
73 | 72 | |
74 | 73 | case "inline-block": |
75 | 74 | $positioner = "Inline"; |
76 | - $decorator = "Block"; |
|
77 | - $reflower = "Block"; |
|
78 | - break; |
|
75 | + $decorator = "Block"; |
|
76 | + $reflower = "Block"; |
|
77 | + break; |
|
79 | 78 | |
80 | 79 | case "inline": |
81 | 80 | $positioner = "Inline"; |
82 | - if ( $frame->get_node()->nodeName === "#text" ) { |
|
81 | + if ( $frame->get_node()->nodeName === "#text" ) { |
|
83 | 82 | $decorator = "Text"; |
84 | 83 | $reflower = "Text"; |
85 | - } else { |
|
84 | + } else { |
|
86 | 85 | $decorator = "Inline"; |
87 | 86 | $reflower = "Inline"; |
88 | - } |
|
89 | - break; |
|
87 | + } |
|
88 | + break; |
|
90 | 89 | |
91 | 90 | case "table": |
92 | 91 | $positioner = "Block"; |
93 | - $decorator = "Table"; |
|
94 | - $reflower = "Table"; |
|
95 | - break; |
|
92 | + $decorator = "Table"; |
|
93 | + $reflower = "Table"; |
|
94 | + break; |
|
96 | 95 | |
97 | 96 | case "inline-table": |
98 | 97 | $positioner = "Inline"; |
99 | - $decorator = "Table"; |
|
100 | - $reflower = "Table"; |
|
101 | - break; |
|
98 | + $decorator = "Table"; |
|
99 | + $reflower = "Table"; |
|
100 | + break; |
|
102 | 101 | |
103 | 102 | case "table-row-group": |
104 | 103 | case "table-header-group": |
105 | 104 | case "table-footer-group": |
106 | 105 | $positioner = "Null"; |
107 | - $decorator = "Table_Row_Group"; |
|
108 | - $reflower = "Table_Row_Group"; |
|
109 | - break; |
|
106 | + $decorator = "Table_Row_Group"; |
|
107 | + $reflower = "Table_Row_Group"; |
|
108 | + break; |
|
110 | 109 | |
111 | 110 | case "table-row": |
112 | 111 | $positioner = "Null"; |
113 | - $decorator = "Table_Row"; |
|
114 | - $reflower = "Table_Row"; |
|
115 | - break; |
|
112 | + $decorator = "Table_Row"; |
|
113 | + $reflower = "Table_Row"; |
|
114 | + break; |
|
116 | 115 | |
117 | 116 | case "table-cell": |
118 | 117 | $positioner = "Table_Cell"; |
119 | - $decorator = "Table_Cell"; |
|
120 | - $reflower = "Table_Cell"; |
|
121 | - break; |
|
118 | + $decorator = "Table_Cell"; |
|
119 | + $reflower = "Table_Cell"; |
|
120 | + break; |
|
122 | 121 | |
123 | 122 | case "list-item": |
124 | 123 | $positioner = "Block"; |
125 | - $decorator = "Block"; |
|
126 | - $reflower = "Block"; |
|
127 | - break; |
|
124 | + $decorator = "Block"; |
|
125 | + $reflower = "Block"; |
|
126 | + break; |
|
128 | 127 | |
129 | 128 | case "-dompdf-list-bullet": |
130 | 129 | if ( $frame->get_style()->list_style_position === "inside" ) |
131 | 130 | $positioner = "Inline"; |
132 | - else |
|
131 | + else |
|
133 | 132 | $positioner = "List_Bullet"; |
134 | 133 | |
135 | - if ( $frame->get_style()->list_style_image !== "none" ) |
|
134 | + if ( $frame->get_style()->list_style_image !== "none" ) |
|
136 | 135 | $decorator = "List_Bullet_Image"; |
137 | - else |
|
136 | + else |
|
138 | 137 | $decorator = "List_Bullet"; |
139 | 138 | |
140 | - $reflower = "List_Bullet"; |
|
141 | - break; |
|
139 | + $reflower = "List_Bullet"; |
|
140 | + break; |
|
142 | 141 | |
143 | 142 | case "-dompdf-image": |
144 | 143 | $positioner = "Inline"; |
145 | - $decorator = "Image"; |
|
146 | - $reflower = "Image"; |
|
147 | - break; |
|
144 | + $decorator = "Image"; |
|
145 | + $reflower = "Image"; |
|
146 | + break; |
|
148 | 147 | |
149 | 148 | case "-dompdf-br": |
150 | 149 | $positioner = "Inline"; |
151 | - $decorator = "Inline"; |
|
152 | - $reflower = "Inline"; |
|
153 | - break; |
|
150 | + $decorator = "Inline"; |
|
151 | + $reflower = "Inline"; |
|
152 | + break; |
|
154 | 153 | |
155 | 154 | default: |
156 | 155 | // FIXME: should throw some sort of warning or something? |
157 | 156 | case "none": |
158 | 157 | $positioner = "Null"; |
159 | - $decorator = "Null"; |
|
160 | - $reflower = "Null"; |
|
161 | - break; |
|
158 | + $decorator = "Null"; |
|
159 | + $reflower = "Null"; |
|
160 | + break; |
|
162 | 161 | |
163 | 162 | } |
164 | 163 | |
165 | 164 | if ( $frame->get_style()->position === "absolute" || |
166 | 165 | $frame->get_style()->position === "fixed" ) |
167 | - $positioner = "Absolute"; |
|
166 | + $positioner = "Absolute"; |
|
168 | 167 | |
169 | 168 | $positioner .= "_Positioner"; |
170 | 169 | $decorator .= "_Frame_Decorator"; |
@@ -176,10 +175,10 @@ discard block |
||
176 | 175 | |
177 | 176 | // Generated content is a special case |
178 | 177 | if ( $frame->get_node()->nodeName === "_dompdf_generated" ) { |
179 | - // Decorate the reflower |
|
180 | - $gen = new Generated_Frame_Reflower( $deco ); |
|
181 | - $gen->set_reflower( $reflow ); |
|
182 | - $reflow = $gen; |
|
178 | + // Decorate the reflower |
|
179 | + $gen = new Generated_Frame_Reflower( $deco ); |
|
180 | + $gen->set_reflower( $reflow ); |
|
181 | + $reflow = $gen; |
|
183 | 182 | } |
184 | 183 | |
185 | 184 | $deco->set_reflower( $reflow ); |
@@ -204,6 +203,6 @@ discard block |
||
204 | 203 | // } |
205 | 204 | |
206 | 205 | return $deco; |
207 | - } |
|
206 | + } |
|
208 | 207 | |
209 | 208 | } |
@@ -34,7 +34,6 @@ discard block |
||
34 | 34 | * @copyright 2004 Benj Carson |
35 | 35 | * @author Benj Carson <[email protected]> |
36 | 36 | * @package dompdf |
37 | - |
|
38 | 37 | */ |
39 | 38 | |
40 | 39 | /* $Id: frame_decorator.cls.php 216 2010-03-11 22:49:18Z ryan.masten $ */ |
@@ -47,62 +46,62 @@ discard block |
||
47 | 46 | */ |
48 | 47 | abstract class Frame_Decorator extends Frame { |
49 | 48 | |
50 | - /** |
|
51 | - * The root node of the DOM tree |
|
52 | - * |
|
53 | - * @var Frame |
|
54 | - */ |
|
55 | - protected $_root; |
|
56 | - |
|
57 | - /** |
|
58 | - * The decorated frame |
|
59 | - * |
|
60 | - * @var Frame |
|
61 | - */ |
|
62 | - protected $_frame; |
|
63 | - |
|
64 | - /** |
|
65 | - * Positioner object used to position this frame (Strategy pattern) |
|
66 | - * |
|
67 | - * @var Positioner |
|
68 | - */ |
|
69 | - protected $_positioner; |
|
70 | - |
|
71 | - /** |
|
72 | - * Reflower object used to calculate frame dimensions (Strategy pattern) |
|
73 | - * |
|
74 | - * @var Frame_Reflower |
|
75 | - */ |
|
76 | - protected $_reflower; |
|
49 | + /** |
|
50 | + * The root node of the DOM tree |
|
51 | + * |
|
52 | + * @var Frame |
|
53 | + */ |
|
54 | + protected $_root; |
|
55 | + |
|
56 | + /** |
|
57 | + * The decorated frame |
|
58 | + * |
|
59 | + * @var Frame |
|
60 | + */ |
|
61 | + protected $_frame; |
|
62 | + |
|
63 | + /** |
|
64 | + * Positioner object used to position this frame (Strategy pattern) |
|
65 | + * |
|
66 | + * @var Positioner |
|
67 | + */ |
|
68 | + protected $_positioner; |
|
69 | + |
|
70 | + /** |
|
71 | + * Reflower object used to calculate frame dimensions (Strategy pattern) |
|
72 | + * |
|
73 | + * @var Frame_Reflower |
|
74 | + */ |
|
75 | + protected $_reflower; |
|
77 | 76 | |
78 | - /** |
|
79 | - * Reference to the current dompdf instance |
|
80 | - * |
|
81 | - * @var DOMPDF |
|
82 | - */ |
|
83 | - protected $_dompdf; |
|
84 | - |
|
85 | - /** |
|
86 | - * Class constructor |
|
87 | - * |
|
88 | - * @param Frame $frame the decoration target |
|
89 | - */ |
|
90 | - function __construct(Frame $frame, DOMPDF $dompdf) { |
|
77 | + /** |
|
78 | + * Reference to the current dompdf instance |
|
79 | + * |
|
80 | + * @var DOMPDF |
|
81 | + */ |
|
82 | + protected $_dompdf; |
|
83 | + |
|
84 | + /** |
|
85 | + * Class constructor |
|
86 | + * |
|
87 | + * @param Frame $frame the decoration target |
|
88 | + */ |
|
89 | + function __construct(Frame $frame, DOMPDF $dompdf) { |
|
91 | 90 | $this->_frame = $frame; |
92 | 91 | $this->_root = null; |
93 | 92 | $this->_dompdf = $dompdf; |
94 | 93 | $frame->set_decorator($this); |
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * "Destructor": foribly free all references held by this object |
|
99 | - * |
|
100 | - * @param bool $recursive if true, call dispose on all children |
|
101 | - */ |
|
102 | - function dispose($recursive = false) { |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * "Destructor": foribly free all references held by this object |
|
98 | + * |
|
99 | + * @param bool $recursive if true, call dispose on all children |
|
100 | + */ |
|
101 | + function dispose($recursive = false) { |
|
103 | 102 | |
104 | 103 | if ( $recursive ) { |
105 | - while ( $child = $this->get_first_child() ) |
|
104 | + while ( $child = $this->get_first_child() ) |
|
106 | 105 | $child->dispose(true); |
107 | 106 | } |
108 | 107 | |
@@ -112,52 +111,52 @@ discard block |
||
112 | 111 | unset($this->_positioner); |
113 | 112 | unset($this->_reflower); |
114 | 113 | |
115 | - } |
|
114 | + } |
|
116 | 115 | |
117 | - // Return a copy of this frame with $node as its node |
|
118 | - function copy(DomNode $node) { |
|
116 | + // Return a copy of this frame with $node as its node |
|
117 | + function copy(DomNode $node) { |
|
119 | 118 | $frame = new Frame($node); |
120 | 119 | $frame->set_style(clone $this->_frame->get_original_style()); |
121 | 120 | $deco = Frame_Factory::decorate_frame($frame, $this->_dompdf); |
122 | 121 | $deco->set_root($this->_root); |
123 | 122 | return $deco; |
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Create a deep copy: copy this node and all children |
|
128 | - * |
|
129 | - * @return Frame |
|
130 | - */ |
|
131 | - function deep_copy() { |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Create a deep copy: copy this node and all children |
|
127 | + * |
|
128 | + * @return Frame |
|
129 | + */ |
|
130 | + function deep_copy() { |
|
132 | 131 | $frame = new Frame($this->get_node()->cloneNode()); |
133 | 132 | $frame->set_style(clone $this->_frame->get_original_style()); |
134 | 133 | $deco = Frame_Factory::decorate_frame($frame, $this->_dompdf); |
135 | 134 | $deco->set_root($this->_root); |
136 | 135 | |
137 | 136 | foreach ($this->get_children() as $child) |
138 | - $deco->append_child($child->deep_copy()); |
|
137 | + $deco->append_child($child->deep_copy()); |
|
139 | 138 | |
140 | 139 | return $deco; |
141 | - } |
|
142 | - //........................................................................ |
|
140 | + } |
|
141 | + //........................................................................ |
|
143 | 142 | |
144 | - // Delegate calls to decorated frame object |
|
145 | - function reset() { |
|
143 | + // Delegate calls to decorated frame object |
|
144 | + function reset() { |
|
146 | 145 | $this->_frame->reset(); |
147 | 146 | |
148 | 147 | // Reset all children |
149 | 148 | foreach ($this->get_children() as $child) |
150 | - $child->reset(); |
|
149 | + $child->reset(); |
|
151 | 150 | |
152 | - } |
|
151 | + } |
|
153 | 152 | |
154 | - function get_node() { return $this->_frame->get_node(); } |
|
155 | - function get_id() { return $this->_frame->get_id(); } |
|
156 | - function get_style() { return $this->_frame->get_style(); } |
|
157 | - function get_original_style() { return $this->_frame->get_original_style(); } |
|
158 | - function get_containing_block($i = null) { return $this->_frame->get_containing_block($i); } |
|
159 | - function get_position($i = null) { return $this->_frame->get_position($i); } |
|
160 | - function get_dompdf() { return $this->_dompdf; } |
|
153 | + function get_node() { return $this->_frame->get_node(); } |
|
154 | + function get_id() { return $this->_frame->get_id(); } |
|
155 | + function get_style() { return $this->_frame->get_style(); } |
|
156 | + function get_original_style() { return $this->_frame->get_original_style(); } |
|
157 | + function get_containing_block($i = null) { return $this->_frame->get_containing_block($i); } |
|
158 | + function get_position($i = null) { return $this->_frame->get_position($i); } |
|
159 | + function get_dompdf() { return $this->_dompdf; } |
|
161 | 160 | // function get_decorator() { |
162 | 161 | // if ( isset($this->_decorator) ) |
163 | 162 | // return $this->_decorator; |
@@ -165,201 +164,201 @@ discard block |
||
165 | 164 | // return $this; |
166 | 165 | // } |
167 | 166 | |
168 | - function get_margin_height() { return $this->_frame->get_margin_height(); } |
|
169 | - function get_margin_width() { return $this->_frame->get_margin_width(); } |
|
170 | - function get_padding_box() { return $this->_frame->get_padding_box(); } |
|
171 | - function get_border_box() { return $this->_frame->get_border_box(); } |
|
167 | + function get_margin_height() { return $this->_frame->get_margin_height(); } |
|
168 | + function get_margin_width() { return $this->_frame->get_margin_width(); } |
|
169 | + function get_padding_box() { return $this->_frame->get_padding_box(); } |
|
170 | + function get_border_box() { return $this->_frame->get_border_box(); } |
|
172 | 171 | |
173 | - function set_id($id) { $this->_frame->set_id($id); } |
|
174 | - function set_style(Style $style) { $this->_frame->set_style($style); } |
|
172 | + function set_id($id) { $this->_frame->set_id($id); } |
|
173 | + function set_style(Style $style) { $this->_frame->set_style($style); } |
|
175 | 174 | |
176 | - function set_containing_block($x = null, $y = null, $w = null, $h = null) { |
|
175 | + function set_containing_block($x = null, $y = null, $w = null, $h = null) { |
|
177 | 176 | $this->_frame->set_containing_block($x, $y, $w, $h); |
178 | - } |
|
177 | + } |
|
179 | 178 | |
180 | - function set_position($x = null, $y = null) { |
|
179 | + function set_position($x = null, $y = null) { |
|
181 | 180 | $this->_frame->set_position($x, $y); |
182 | - } |
|
183 | - function __toString() { return $this->_frame->__toString(); } |
|
181 | + } |
|
182 | + function __toString() { return $this->_frame->__toString(); } |
|
184 | 183 | |
185 | - function prepend_child(Frame $child, $update_node = true) { |
|
184 | + function prepend_child(Frame $child, $update_node = true) { |
|
186 | 185 | while ( $child instanceof Frame_Decorator ) |
187 | - $child = $child->_frame; |
|
186 | + $child = $child->_frame; |
|
188 | 187 | |
189 | 188 | $this->_frame->prepend_child($child, $update_node); |
190 | - } |
|
189 | + } |
|
191 | 190 | |
192 | - function append_child(Frame $child, $update_node = true) { |
|
191 | + function append_child(Frame $child, $update_node = true) { |
|
193 | 192 | while ( $child instanceof Frame_Decorator ) |
194 | - $child = $child->_frame; |
|
193 | + $child = $child->_frame; |
|
195 | 194 | |
196 | 195 | $this->_frame->append_child($child, $update_node); |
197 | - } |
|
196 | + } |
|
198 | 197 | |
199 | - function insert_child_before(Frame $new_child, Frame $ref, $update_node = true) { |
|
198 | + function insert_child_before(Frame $new_child, Frame $ref, $update_node = true) { |
|
200 | 199 | while ( $new_child instanceof Frame_Decorator ) |
201 | - $new_child = $new_child->_frame; |
|
200 | + $new_child = $new_child->_frame; |
|
202 | 201 | |
203 | 202 | if ( $ref instanceof Frame_Decorator ) |
204 | - $ref = $ref->_frame; |
|
203 | + $ref = $ref->_frame; |
|
205 | 204 | |
206 | 205 | $this->_frame->insert_child_before($new_child, $ref, $update_node); |
207 | - } |
|
206 | + } |
|
208 | 207 | |
209 | - function insert_child_after(Frame $new_child, Frame $ref, $update_node = true) { |
|
208 | + function insert_child_after(Frame $new_child, Frame $ref, $update_node = true) { |
|
210 | 209 | while ( $new_child instanceof Frame_Decorator ) |
211 | - $new_child = $new_child->_frame; |
|
210 | + $new_child = $new_child->_frame; |
|
212 | 211 | |
213 | 212 | while ( $ref instanceof Frame_Decorator ) |
214 | - $ref = $ref->_frame; |
|
213 | + $ref = $ref->_frame; |
|
215 | 214 | |
216 | 215 | $this->_frame->insert_child_after($new_child, $ref, $update_node); |
217 | - } |
|
216 | + } |
|
218 | 217 | |
219 | - function remove_child(Frame $child, $update_node = true) { |
|
218 | + function remove_child(Frame $child, $update_node = true) { |
|
220 | 219 | while ( $child instanceof Frame_Decorator ) |
221 | - $child = $new_child->_frame; |
|
220 | + $child = $new_child->_frame; |
|
222 | 221 | |
223 | 222 | $this->_frame->remove_child($child, $update_node); |
224 | - } |
|
223 | + } |
|
225 | 224 | |
226 | - //........................................................................ |
|
225 | + //........................................................................ |
|
227 | 226 | |
228 | - function get_parent() { |
|
227 | + function get_parent() { |
|
229 | 228 | |
230 | 229 | $p = $this->_frame->get_parent(); |
231 | 230 | |
232 | 231 | if ( $p && $deco = $p->get_decorator() ) { |
233 | - while ( $tmp = $deco->get_decorator() ) |
|
232 | + while ( $tmp = $deco->get_decorator() ) |
|
234 | 233 | $deco = $tmp; |
235 | - return $deco; |
|
234 | + return $deco; |
|
236 | 235 | } else if ( $p ) |
237 | - return $p; |
|
236 | + return $p; |
|
238 | 237 | else |
239 | - return null; |
|
240 | - } |
|
238 | + return null; |
|
239 | + } |
|
241 | 240 | |
242 | - function get_first_child() { |
|
241 | + function get_first_child() { |
|
243 | 242 | $c = $this->_frame->get_first_child(); |
244 | 243 | if ( $c && $deco = $c->get_decorator() ) { |
245 | - while ( $tmp = $deco->get_decorator() ) |
|
244 | + while ( $tmp = $deco->get_decorator() ) |
|
246 | 245 | $deco = $tmp; |
247 | - return $deco; |
|
246 | + return $deco; |
|
248 | 247 | } else if ( $c ) |
249 | - return $c; |
|
248 | + return $c; |
|
250 | 249 | else |
251 | - return null; |
|
252 | - } |
|
250 | + return null; |
|
251 | + } |
|
253 | 252 | |
254 | - function get_last_child() { |
|
253 | + function get_last_child() { |
|
255 | 254 | $c = $this->_frame->get_last_child(); |
256 | 255 | if ( $c && $deco = $c->get_decorator() ) { |
257 | - while ( $tmp = $deco->get_decorator() ) |
|
256 | + while ( $tmp = $deco->get_decorator() ) |
|
258 | 257 | $deco = $tmp; |
259 | - return $deco; |
|
258 | + return $deco; |
|
260 | 259 | } else if ( $c ) |
261 | - return $c; |
|
260 | + return $c; |
|
262 | 261 | else |
263 | - return null; |
|
264 | - } |
|
262 | + return null; |
|
263 | + } |
|
265 | 264 | |
266 | - function get_prev_sibling() { |
|
265 | + function get_prev_sibling() { |
|
267 | 266 | $s = $this->_frame->get_prev_sibling(); |
268 | 267 | if ( $s && $deco = $s->get_decorator() ) { |
269 | - while ( $tmp = $deco->get_decorator() ) |
|
268 | + while ( $tmp = $deco->get_decorator() ) |
|
270 | 269 | $deco = $tmp; |
271 | - return $deco; |
|
270 | + return $deco; |
|
272 | 271 | } else if ( $s ) |
273 | - return $s; |
|
272 | + return $s; |
|
274 | 273 | else |
275 | - return null; |
|
276 | - } |
|
274 | + return null; |
|
275 | + } |
|
277 | 276 | |
278 | - function get_next_sibling() { |
|
277 | + function get_next_sibling() { |
|
279 | 278 | $s = $this->_frame->get_next_sibling(); |
280 | 279 | if ( $s && $deco = $s->get_decorator() ) { |
281 | - while ( $tmp = $deco->get_decorator() ) |
|
280 | + while ( $tmp = $deco->get_decorator() ) |
|
282 | 281 | $deco = $tmp; |
283 | - return $deco; |
|
282 | + return $deco; |
|
284 | 283 | } else if ( $s ) |
285 | - return $s; |
|
284 | + return $s; |
|
286 | 285 | else |
287 | - return null; |
|
288 | - } |
|
286 | + return null; |
|
287 | + } |
|
289 | 288 | |
290 | - function get_children() { |
|
289 | + function get_children() { |
|
291 | 290 | return new FrameList($this); |
292 | - } |
|
291 | + } |
|
293 | 292 | |
294 | - function get_subtree() { |
|
293 | + function get_subtree() { |
|
295 | 294 | return new FrameTreeList($this); |
296 | - } |
|
295 | + } |
|
297 | 296 | |
298 | - //........................................................................ |
|
297 | + //........................................................................ |
|
299 | 298 | |
300 | - function set_positioner(Positioner $posn) { |
|
299 | + function set_positioner(Positioner $posn) { |
|
301 | 300 | $this->_positioner = $posn; |
302 | 301 | if ( $this->_frame instanceof Frame_Decorator ) |
303 | - $this->_frame->set_positioner($posn); |
|
304 | - } |
|
302 | + $this->_frame->set_positioner($posn); |
|
303 | + } |
|
305 | 304 | |
306 | - //........................................................................ |
|
305 | + //........................................................................ |
|
307 | 306 | |
308 | - function set_reflower(Frame_Reflower $reflower) { |
|
307 | + function set_reflower(Frame_Reflower $reflower) { |
|
309 | 308 | $this->_reflower = $reflower; |
310 | 309 | if ( $this->_frame instanceof Frame_Decorator ) |
311 | - $this->_frame->set_reflower( $reflower ); |
|
312 | - } |
|
310 | + $this->_frame->set_reflower( $reflower ); |
|
311 | + } |
|
313 | 312 | |
314 | - function get_reflower() { return $this->_reflower; } |
|
313 | + function get_reflower() { return $this->_reflower; } |
|
315 | 314 | |
316 | - //........................................................................ |
|
315 | + //........................................................................ |
|
317 | 316 | |
318 | - function set_root(Frame $root) { |
|
317 | + function set_root(Frame $root) { |
|
319 | 318 | $this->_root = $root; |
320 | - if ( $this->_frame instanceof Frame_Decorator ) |
|
319 | + if ( $this->_frame instanceof Frame_Decorator ) |
|
321 | 320 | $this->_frame->set_root($root); |
322 | - } |
|
321 | + } |
|
323 | 322 | |
324 | - function get_root() { return $this->_root; } |
|
323 | + function get_root() { return $this->_root; } |
|
325 | 324 | |
326 | - //........................................................................ |
|
325 | + //........................................................................ |
|
327 | 326 | |
328 | - function find_block_parent() { |
|
327 | + function find_block_parent() { |
|
329 | 328 | |
330 | 329 | // Find our nearest block level parent |
331 | 330 | $p = $this->get_parent(); |
332 | 331 | |
333 | 332 | while ( $p ) { |
334 | - if ( in_array($p->get_style()->display, Style::$BLOCK_TYPES) ) |
|
333 | + if ( in_array($p->get_style()->display, Style::$BLOCK_TYPES) ) |
|
335 | 334 | break; |
336 | 335 | |
337 | - $p = $p->get_parent(); |
|
336 | + $p = $p->get_parent(); |
|
338 | 337 | } |
339 | 338 | |
340 | 339 | return $p; |
341 | - } |
|
340 | + } |
|
342 | 341 | |
343 | - //........................................................................ |
|
342 | + //........................................................................ |
|
344 | 343 | |
345 | - /** |
|
346 | - * split this frame at $child. |
|
347 | - * |
|
348 | - * The current frame is cloned and $child and all children following |
|
349 | - * $child are added to the clone. The clone is then passed to the |
|
350 | - * current frame's parent->split() method. |
|
351 | - * |
|
352 | - * @param Frame $child |
|
353 | - */ |
|
354 | - function split($child = null) { |
|
344 | + /** |
|
345 | + * split this frame at $child. |
|
346 | + * |
|
347 | + * The current frame is cloned and $child and all children following |
|
348 | + * $child are added to the clone. The clone is then passed to the |
|
349 | + * current frame's parent->split() method. |
|
350 | + * |
|
351 | + * @param Frame $child |
|
352 | + */ |
|
353 | + function split($child = null) { |
|
355 | 354 | |
356 | 355 | if ( is_null( $child ) ) { |
357 | - $this->get_parent()->split($this); |
|
358 | - return; |
|
356 | + $this->get_parent()->split($this); |
|
357 | + return; |
|
359 | 358 | } |
360 | 359 | |
361 | 360 | if ( $child->get_parent() !== $this ) |
362 | - throw new DOMPDF_Exception("Unable to split: frame is not a child of this one."); |
|
361 | + throw new DOMPDF_Exception("Unable to split: frame is not a child of this one."); |
|
363 | 362 | |
364 | 363 | $split = $this->copy( $this->_frame->get_node()->cloneNode() ); |
365 | 364 | $split->reset(); |
@@ -368,29 +367,29 @@ discard block |
||
368 | 367 | // Add $frame and all following siblings to the new split node |
369 | 368 | $iter = $child; |
370 | 369 | while ($iter) { |
371 | - $frame = $iter; |
|
372 | - $iter = $iter->get_next_sibling(); |
|
373 | - $frame->reset(); |
|
374 | - $split->append_child($frame); |
|
370 | + $frame = $iter; |
|
371 | + $iter = $iter->get_next_sibling(); |
|
372 | + $frame->reset(); |
|
373 | + $split->append_child($frame); |
|
375 | 374 | } |
376 | 375 | |
377 | 376 | $this->get_parent()->split($split); |
378 | - } |
|
377 | + } |
|
379 | 378 | |
380 | - //........................................................................ |
|
379 | + //........................................................................ |
|
381 | 380 | |
382 | - final function position() { $this->_positioner->position(); } |
|
381 | + final function position() { $this->_positioner->position(); } |
|
383 | 382 | |
384 | - final function reflow() { |
|
383 | + final function reflow() { |
|
385 | 384 | // Uncomment this to see the frames before they're laid out, instead of |
386 | 385 | // during rendering. |
387 | 386 | //echo $this->_frame; flush(); |
388 | 387 | $this->_reflower->reflow(); |
389 | - } |
|
388 | + } |
|
390 | 389 | |
391 | - final function get_min_max_width() { return $this->get_reflower()->get_min_max_width(); } |
|
390 | + final function get_min_max_width() { return $this->get_reflower()->get_min_max_width(); } |
|
392 | 391 | |
393 | - //........................................................................ |
|
392 | + //........................................................................ |
|
394 | 393 | |
395 | 394 | |
396 | 395 | } |
@@ -35,7 +35,6 @@ discard block |
||
35 | 35 | * @author Benj Carson <[email protected]> |
36 | 36 | * @contributor Helmut Tischer <[email protected]> |
37 | 37 | * @package dompdf |
38 | - |
|
39 | 38 | * |
40 | 39 | * Changes |
41 | 40 | * @contributor Helmut Tischer <[email protected]> |
@@ -54,34 +53,34 @@ discard block |
||
54 | 53 | */ |
55 | 54 | class Text_Renderer extends Abstract_Renderer { |
56 | 55 | |
57 | - const DECO_THICKNESS = 0.04; // Thickness of underline. Screen: 0.08, print: better less, e.g. 0.04 |
|
58 | - |
|
59 | - //Tweaking if $base and $descent are not accurate. |
|
60 | - //Check method_exists( $this->_canvas, "get_cpdf" ) |
|
61 | - //- For cpdf these can and must stay 0, because font metrics are used directly. |
|
62 | - //- For other renderers, if different values are wanted, separate the parameter sets. |
|
63 | - // But $size and $size-$height seem to be accurate enough |
|
64 | - const UNDERLINE_OFFSET = 0.0; // Relative to bottom of text, as fraction of height. |
|
65 | - const OVERLINE_OFFSET = 0.0; // Relative to top of text |
|
66 | - const LINETHROUGH_OFFSET = 0.0; // Relative to centre of text. |
|
67 | - const DECO_EXTENSION = 0.0; // How far to extend lines past either end, in pt |
|
56 | + const DECO_THICKNESS = 0.04; // Thickness of underline. Screen: 0.08, print: better less, e.g. 0.04 |
|
57 | + |
|
58 | + //Tweaking if $base and $descent are not accurate. |
|
59 | + //Check method_exists( $this->_canvas, "get_cpdf" ) |
|
60 | + //- For cpdf these can and must stay 0, because font metrics are used directly. |
|
61 | + //- For other renderers, if different values are wanted, separate the parameter sets. |
|
62 | + // But $size and $size-$height seem to be accurate enough |
|
63 | + const UNDERLINE_OFFSET = 0.0; // Relative to bottom of text, as fraction of height. |
|
64 | + const OVERLINE_OFFSET = 0.0; // Relative to top of text |
|
65 | + const LINETHROUGH_OFFSET = 0.0; // Relative to centre of text. |
|
66 | + const DECO_EXTENSION = 0.0; // How far to extend lines past either end, in pt |
|
68 | 67 | |
69 | - //........................................................................ |
|
68 | + //........................................................................ |
|
70 | 69 | |
71 | - function render(Frame $frame) { |
|
70 | + function render(Frame $frame) { |
|
72 | 71 | |
73 | 72 | $style = $frame->get_style(); |
74 | 73 | list($x, $y) = $frame->get_position(); |
75 | 74 | $cb = $frame->get_containing_block(); |
76 | 75 | |
77 | 76 | if ( ($ml = $style->margin_left) === "auto" || $ml === "none" ) |
78 | - $ml = 0; |
|
77 | + $ml = 0; |
|
79 | 78 | |
80 | 79 | if ( ($pl = $style->padding_left) === "auto" || $pl === "none" ) |
81 | - $pl = 0; |
|
80 | + $pl = 0; |
|
82 | 81 | |
83 | 82 | if ( ($bl = $style->border_left_width) === "auto" || $bl === "none" ) |
84 | - $bl = 0; |
|
83 | + $bl = 0; |
|
85 | 84 | |
86 | 85 | $x += $style->length_in_pt( array($ml, $pl, $bl), $cb["w"] ); |
87 | 86 | |
@@ -96,19 +95,19 @@ discard block |
||
96 | 95 | // return; |
97 | 96 | |
98 | 97 | $this->_canvas->text($x, $y, $text, |
99 | - $font, $size, |
|
100 | - $style->color, $spacing); |
|
98 | + $font, $size, |
|
99 | + $style->color, $spacing); |
|
101 | 100 | |
102 | 101 | if ( method_exists( $this->_canvas, "get_cpdf" ) ) { |
103 | - $base = ($this->_canvas->get_cpdf()->fonts[$this->_canvas->get_cpdf()->currentFont]['FontBBox'][3]*$size)/1000; |
|
104 | - $descent = ($this->_canvas->get_cpdf()->fonts[$this->_canvas->get_cpdf()->currentFont]['FontBBox'][1]*$size)/1000; |
|
105 | - //print '<pre>Text_Renderer cpdf:'.$base.' '.$descent.' '.$size.'</pre>'; |
|
102 | + $base = ($this->_canvas->get_cpdf()->fonts[$this->_canvas->get_cpdf()->currentFont]['FontBBox'][3]*$size)/1000; |
|
103 | + $descent = ($this->_canvas->get_cpdf()->fonts[$this->_canvas->get_cpdf()->currentFont]['FontBBox'][1]*$size)/1000; |
|
104 | + //print '<pre>Text_Renderer cpdf:'.$base.' '.$descent.' '.$size.'</pre>'; |
|
106 | 105 | } else { |
107 | - //Descent is font part below baseline, typically negative. $height is about full height of font box. |
|
108 | - //$descent = -$size/6; is less accurate, depends on font family. |
|
109 | - $base = $size; |
|
110 | - $descent = $size-$height; |
|
111 | - //print '<pre>Text_Renderer other than cpdf:'.$base.' '.$descent.' '.$size.'</pre>'; |
|
106 | + //Descent is font part below baseline, typically negative. $height is about full height of font box. |
|
107 | + //$descent = -$size/6; is less accurate, depends on font family. |
|
108 | + $base = $size; |
|
109 | + $descent = $size-$height; |
|
110 | + //print '<pre>Text_Renderer other than cpdf:'.$base.' '.$descent.' '.$size.'</pre>'; |
|
112 | 111 | } |
113 | 112 | |
114 | 113 | // Handle text decoration: |
@@ -119,42 +118,42 @@ discard block |
||
119 | 118 | $p = $frame; |
120 | 119 | $stack = array(); |
121 | 120 | while ( $p = $p->get_parent() ) |
122 | - $stack[] = $p; |
|
121 | + $stack[] = $p; |
|
123 | 122 | |
124 | 123 | while ( count($stack) > 0 ) { |
125 | - $f = array_pop($stack); |
|
124 | + $f = array_pop($stack); |
|
126 | 125 | |
127 | - $deco_y = $y; |
|
128 | - if ( ($text_deco = $f->get_style()->text_decoration) === "none" ) |
|
126 | + $deco_y = $y; |
|
127 | + if ( ($text_deco = $f->get_style()->text_decoration) === "none" ) |
|
129 | 128 | continue; |
130 | 129 | |
131 | - $color = $f->get_style()->color; |
|
130 | + $color = $f->get_style()->color; |
|
132 | 131 | |
133 | - switch ($text_deco) { |
|
132 | + switch ($text_deco) { |
|
134 | 133 | |
135 | - default: |
|
134 | + default: |
|
136 | 135 | continue; |
137 | 136 | |
138 | - case "underline": |
|
137 | + case "underline": |
|
139 | 138 | $deco_y += $base - $descent+ $size * (self::UNDERLINE_OFFSET - self::DECO_THICKNESS/2); |
140 | 139 | break; |
141 | 140 | |
142 | - case "overline": |
|
141 | + case "overline": |
|
143 | 142 | $deco_y += $size * (self::OVERLINE_OFFSET + self::DECO_THICKNESS/2); |
144 | 143 | break; |
145 | 144 | |
146 | - case "line-through": |
|
145 | + case "line-through": |
|
147 | 146 | $deco_y += $base * 0.7 + $size * self::LINETHROUGH_OFFSET; |
148 | 147 | break; |
149 | 148 | |
150 | - } |
|
149 | + } |
|
151 | 150 | |
152 | - $dx = 0; |
|
153 | - $x1 = $x - self::DECO_EXTENSION; |
|
154 | - $x2 = $x + $style->width + $dx + self::DECO_EXTENSION; |
|
155 | - $this->_canvas->line($x1, $deco_y, $x2, $deco_y, $color, $size * self::DECO_THICKNESS); |
|
151 | + $dx = 0; |
|
152 | + $x1 = $x - self::DECO_EXTENSION; |
|
153 | + $x2 = $x + $style->width + $dx + self::DECO_EXTENSION; |
|
154 | + $this->_canvas->line($x1, $deco_y, $x2, $deco_y, $color, $size * self::DECO_THICKNESS); |
|
156 | 155 | |
157 | 156 | } |
158 | - } |
|
157 | + } |
|
159 | 158 | |
160 | 159 | } |
@@ -74,144 +74,144 @@ discard block |
||
74 | 74 | */ |
75 | 75 | class CPDF_Adapter implements Canvas { |
76 | 76 | |
77 | - /** |
|
78 | - * Dimensions of paper sizes in points |
|
79 | - * |
|
80 | - * @var array; |
|
81 | - */ |
|
82 | - static $PAPER_SIZES = array("4a0" => array(0,0,4767.87,6740.79), |
|
83 | - "2a0" => array(0,0,3370.39,4767.87), |
|
84 | - "a0" => array(0,0,2383.94,3370.39), |
|
85 | - "a1" => array(0,0,1683.78,2383.94), |
|
86 | - "a2" => array(0,0,1190.55,1683.78), |
|
87 | - "a3" => array(0,0,841.89,1190.55), |
|
88 | - "a4" => array(0,0,595.28,841.89), |
|
89 | - "a5" => array(0,0,419.53,595.28), |
|
90 | - "a6" => array(0,0,297.64,419.53), |
|
91 | - "a7" => array(0,0,209.76,297.64), |
|
92 | - "a8" => array(0,0,147.40,209.76), |
|
93 | - "a9" => array(0,0,104.88,147.40), |
|
94 | - "a10" => array(0,0,73.70,104.88), |
|
95 | - "b0" => array(0,0,2834.65,4008.19), |
|
96 | - "b1" => array(0,0,2004.09,2834.65), |
|
97 | - "b2" => array(0,0,1417.32,2004.09), |
|
98 | - "b3" => array(0,0,1000.63,1417.32), |
|
99 | - "b4" => array(0,0,708.66,1000.63), |
|
100 | - "b5" => array(0,0,498.90,708.66), |
|
101 | - "b6" => array(0,0,354.33,498.90), |
|
102 | - "b7" => array(0,0,249.45,354.33), |
|
103 | - "b8" => array(0,0,175.75,249.45), |
|
104 | - "b9" => array(0,0,124.72,175.75), |
|
105 | - "b10" => array(0,0,87.87,124.72), |
|
106 | - "c0" => array(0,0,2599.37,3676.54), |
|
107 | - "c1" => array(0,0,1836.85,2599.37), |
|
108 | - "c2" => array(0,0,1298.27,1836.85), |
|
109 | - "c3" => array(0,0,918.43,1298.27), |
|
110 | - "c4" => array(0,0,649.13,918.43), |
|
111 | - "c5" => array(0,0,459.21,649.13), |
|
112 | - "c6" => array(0,0,323.15,459.21), |
|
113 | - "c7" => array(0,0,229.61,323.15), |
|
114 | - "c8" => array(0,0,161.57,229.61), |
|
115 | - "c9" => array(0,0,113.39,161.57), |
|
116 | - "c10" => array(0,0,79.37,113.39), |
|
117 | - "ra0" => array(0,0,2437.80,3458.27), |
|
118 | - "ra1" => array(0,0,1729.13,2437.80), |
|
119 | - "ra2" => array(0,0,1218.90,1729.13), |
|
120 | - "ra3" => array(0,0,864.57,1218.90), |
|
121 | - "ra4" => array(0,0,609.45,864.57), |
|
122 | - "sra0" => array(0,0,2551.18,3628.35), |
|
123 | - "sra1" => array(0,0,1814.17,2551.18), |
|
124 | - "sra2" => array(0,0,1275.59,1814.17), |
|
125 | - "sra3" => array(0,0,907.09,1275.59), |
|
126 | - "sra4" => array(0,0,637.80,907.09), |
|
127 | - "letter" => array(0,0,612.00,792.00), |
|
128 | - "legal" => array(0,0,612.00,1008.00), |
|
129 | - "ledger" => array(0,0,1224.00, 792.00), |
|
130 | - "tabloid" => array(0,0,792.00, 1224.00), |
|
131 | - "executive" => array(0,0,521.86,756.00), |
|
132 | - "folio" => array(0,0,612.00,936.00), |
|
133 | - "commerical #10 envelope" => array(0,0,684,297), |
|
134 | - "catalog #10 1/2 envelope" => array(0,0,648,864), |
|
135 | - "8.5x11" => array(0,0,612.00,792.00), |
|
136 | - "8.5x14" => array(0,0,612.00,1008.0), |
|
137 | - "11x17" => array(0,0,792.00, 1224.00)); |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * Instance of Cpdf class |
|
142 | - * |
|
143 | - * @var Cpdf |
|
144 | - */ |
|
145 | - private $_pdf; |
|
146 | - |
|
147 | - /** |
|
148 | - * PDF width, in points |
|
149 | - * |
|
150 | - * @var float |
|
151 | - */ |
|
152 | - private $_width; |
|
153 | - |
|
154 | - /** |
|
155 | - * PDF height, in points |
|
156 | - * |
|
157 | - * @var float; |
|
158 | - */ |
|
159 | - private $_height; |
|
160 | - |
|
161 | - /** |
|
162 | - * Current page number |
|
163 | - * |
|
164 | - * @var int |
|
165 | - */ |
|
166 | - private $_page_number; |
|
167 | - |
|
168 | - /** |
|
169 | - * Total number of pages |
|
170 | - * |
|
171 | - * @var int |
|
172 | - */ |
|
173 | - private $_page_count; |
|
174 | - |
|
175 | - /** |
|
176 | - * Text to display on every page |
|
177 | - * |
|
178 | - * @var array |
|
179 | - */ |
|
180 | - private $_page_text; |
|
181 | - |
|
182 | - /** |
|
183 | - * Array of pages for accesing after rendering is initially complete |
|
184 | - * |
|
185 | - * @var array |
|
186 | - */ |
|
187 | - private $_pages; |
|
188 | - |
|
189 | - /** |
|
190 | - * Array of temporary cached images to be deleted when processing is complete |
|
191 | - * |
|
192 | - * @var array |
|
193 | - */ |
|
194 | - private $_image_cache; |
|
77 | + /** |
|
78 | + * Dimensions of paper sizes in points |
|
79 | + * |
|
80 | + * @var array; |
|
81 | + */ |
|
82 | + static $PAPER_SIZES = array("4a0" => array(0,0,4767.87,6740.79), |
|
83 | + "2a0" => array(0,0,3370.39,4767.87), |
|
84 | + "a0" => array(0,0,2383.94,3370.39), |
|
85 | + "a1" => array(0,0,1683.78,2383.94), |
|
86 | + "a2" => array(0,0,1190.55,1683.78), |
|
87 | + "a3" => array(0,0,841.89,1190.55), |
|
88 | + "a4" => array(0,0,595.28,841.89), |
|
89 | + "a5" => array(0,0,419.53,595.28), |
|
90 | + "a6" => array(0,0,297.64,419.53), |
|
91 | + "a7" => array(0,0,209.76,297.64), |
|
92 | + "a8" => array(0,0,147.40,209.76), |
|
93 | + "a9" => array(0,0,104.88,147.40), |
|
94 | + "a10" => array(0,0,73.70,104.88), |
|
95 | + "b0" => array(0,0,2834.65,4008.19), |
|
96 | + "b1" => array(0,0,2004.09,2834.65), |
|
97 | + "b2" => array(0,0,1417.32,2004.09), |
|
98 | + "b3" => array(0,0,1000.63,1417.32), |
|
99 | + "b4" => array(0,0,708.66,1000.63), |
|
100 | + "b5" => array(0,0,498.90,708.66), |
|
101 | + "b6" => array(0,0,354.33,498.90), |
|
102 | + "b7" => array(0,0,249.45,354.33), |
|
103 | + "b8" => array(0,0,175.75,249.45), |
|
104 | + "b9" => array(0,0,124.72,175.75), |
|
105 | + "b10" => array(0,0,87.87,124.72), |
|
106 | + "c0" => array(0,0,2599.37,3676.54), |
|
107 | + "c1" => array(0,0,1836.85,2599.37), |
|
108 | + "c2" => array(0,0,1298.27,1836.85), |
|
109 | + "c3" => array(0,0,918.43,1298.27), |
|
110 | + "c4" => array(0,0,649.13,918.43), |
|
111 | + "c5" => array(0,0,459.21,649.13), |
|
112 | + "c6" => array(0,0,323.15,459.21), |
|
113 | + "c7" => array(0,0,229.61,323.15), |
|
114 | + "c8" => array(0,0,161.57,229.61), |
|
115 | + "c9" => array(0,0,113.39,161.57), |
|
116 | + "c10" => array(0,0,79.37,113.39), |
|
117 | + "ra0" => array(0,0,2437.80,3458.27), |
|
118 | + "ra1" => array(0,0,1729.13,2437.80), |
|
119 | + "ra2" => array(0,0,1218.90,1729.13), |
|
120 | + "ra3" => array(0,0,864.57,1218.90), |
|
121 | + "ra4" => array(0,0,609.45,864.57), |
|
122 | + "sra0" => array(0,0,2551.18,3628.35), |
|
123 | + "sra1" => array(0,0,1814.17,2551.18), |
|
124 | + "sra2" => array(0,0,1275.59,1814.17), |
|
125 | + "sra3" => array(0,0,907.09,1275.59), |
|
126 | + "sra4" => array(0,0,637.80,907.09), |
|
127 | + "letter" => array(0,0,612.00,792.00), |
|
128 | + "legal" => array(0,0,612.00,1008.00), |
|
129 | + "ledger" => array(0,0,1224.00, 792.00), |
|
130 | + "tabloid" => array(0,0,792.00, 1224.00), |
|
131 | + "executive" => array(0,0,521.86,756.00), |
|
132 | + "folio" => array(0,0,612.00,936.00), |
|
133 | + "commerical #10 envelope" => array(0,0,684,297), |
|
134 | + "catalog #10 1/2 envelope" => array(0,0,648,864), |
|
135 | + "8.5x11" => array(0,0,612.00,792.00), |
|
136 | + "8.5x14" => array(0,0,612.00,1008.0), |
|
137 | + "11x17" => array(0,0,792.00, 1224.00)); |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * Instance of Cpdf class |
|
142 | + * |
|
143 | + * @var Cpdf |
|
144 | + */ |
|
145 | + private $_pdf; |
|
146 | + |
|
147 | + /** |
|
148 | + * PDF width, in points |
|
149 | + * |
|
150 | + * @var float |
|
151 | + */ |
|
152 | + private $_width; |
|
153 | + |
|
154 | + /** |
|
155 | + * PDF height, in points |
|
156 | + * |
|
157 | + * @var float; |
|
158 | + */ |
|
159 | + private $_height; |
|
160 | + |
|
161 | + /** |
|
162 | + * Current page number |
|
163 | + * |
|
164 | + * @var int |
|
165 | + */ |
|
166 | + private $_page_number; |
|
167 | + |
|
168 | + /** |
|
169 | + * Total number of pages |
|
170 | + * |
|
171 | + * @var int |
|
172 | + */ |
|
173 | + private $_page_count; |
|
174 | + |
|
175 | + /** |
|
176 | + * Text to display on every page |
|
177 | + * |
|
178 | + * @var array |
|
179 | + */ |
|
180 | + private $_page_text; |
|
181 | + |
|
182 | + /** |
|
183 | + * Array of pages for accesing after rendering is initially complete |
|
184 | + * |
|
185 | + * @var array |
|
186 | + */ |
|
187 | + private $_pages; |
|
188 | + |
|
189 | + /** |
|
190 | + * Array of temporary cached images to be deleted when processing is complete |
|
191 | + * |
|
192 | + * @var array |
|
193 | + */ |
|
194 | + private $_image_cache; |
|
195 | 195 | |
196 | - /** |
|
197 | - * Class constructor |
|
198 | - * |
|
199 | - * @param mixed $paper The size of paper to use in this PDF ({@link CPDF_Adapter::$PAPER_SIZES}) |
|
200 | - * @param string $orientation The orienation of the document (either 'landscape' or 'portrait') |
|
201 | - */ |
|
202 | - function __construct($paper = "letter", $orientation = "portrait") { |
|
196 | + /** |
|
197 | + * Class constructor |
|
198 | + * |
|
199 | + * @param mixed $paper The size of paper to use in this PDF ({@link CPDF_Adapter::$PAPER_SIZES}) |
|
200 | + * @param string $orientation The orienation of the document (either 'landscape' or 'portrait') |
|
201 | + */ |
|
202 | + function __construct($paper = "letter", $orientation = "portrait") { |
|
203 | 203 | |
204 | 204 | if ( is_array($paper) ) |
205 | - $size = $paper; |
|
205 | + $size = $paper; |
|
206 | 206 | else if ( isset(self::$PAPER_SIZES[mb_strtolower($paper)]) ) |
207 | - $size = self::$PAPER_SIZES[mb_strtolower($paper)]; |
|
207 | + $size = self::$PAPER_SIZES[mb_strtolower($paper)]; |
|
208 | 208 | else |
209 | - $size = self::$PAPER_SIZES["letter"]; |
|
209 | + $size = self::$PAPER_SIZES["letter"]; |
|
210 | 210 | |
211 | 211 | if ( mb_strtolower($orientation) === "landscape" ) { |
212 | - $a = $size[3]; |
|
213 | - $size[3] = $size[2]; |
|
214 | - $size[2] = $a; |
|
212 | + $a = $size[3]; |
|
213 | + $size[3] = $size[2]; |
|
214 | + $size[2] = $a; |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | $this->_pdf = new Cpdf($size, DOMPDF_UNICODE_ENABLED, DOMPDF_FONT_CACHE, DOMPDF_TEMP_DIR); |
@@ -219,8 +219,8 @@ discard block |
||
219 | 219 | |
220 | 220 | // Silence pedantic warnings about missing TZ settings |
221 | 221 | $time = substr_replace(date('YmdHisO'), '\'', (0 - 2), 0).'\''; |
222 | - $this->_pdf->addInfo("CreationDate", "D:".$time); |
|
223 | - $this->_pdf->addInfo("ModDate", "D:".$time); |
|
222 | + $this->_pdf->addInfo("CreationDate", "D:".$time); |
|
223 | + $this->_pdf->addInfo("ModDate", "D:".$time); |
|
224 | 224 | |
225 | 225 | |
226 | 226 | $this->_width = $size[2] - $size[0]; |
@@ -233,253 +233,253 @@ discard block |
||
233 | 233 | $this->_pages = array($this->_pdf->getFirstPageId()); |
234 | 234 | |
235 | 235 | $this->_image_cache = array(); |
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * Class destructor |
|
240 | - * |
|
241 | - * Deletes all temporary image files |
|
242 | - */ |
|
243 | - function __destruct() { |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Class destructor |
|
240 | + * |
|
241 | + * Deletes all temporary image files |
|
242 | + */ |
|
243 | + function __destruct() { |
|
244 | 244 | foreach ($this->_image_cache as $img) { |
245 | - //debugpng |
|
246 | - if (DEBUGPNG) print '[__destruct unlink '.$img.']'; |
|
247 | - if (!DEBUGKEEPTEMP) |
|
245 | + //debugpng |
|
246 | + if (DEBUGPNG) print '[__destruct unlink '.$img.']'; |
|
247 | + if (!DEBUGKEEPTEMP) |
|
248 | 248 | unlink($img); |
249 | 249 | } |
250 | - } |
|
250 | + } |
|
251 | 251 | |
252 | - /** |
|
253 | - * Returns the Cpdf instance |
|
254 | - * |
|
255 | - * @return Cpdf |
|
256 | - */ |
|
257 | - function get_cpdf() { return $this->_pdf; } |
|
258 | - |
|
259 | - /** |
|
260 | - * Add meta information to the PDF |
|
261 | - * |
|
262 | - * @param string $label label of the value (Creator, Producter, etc.) |
|
263 | - * @param string $value the text to set |
|
264 | - */ |
|
265 | - function add_info($label, $value) { |
|
252 | + /** |
|
253 | + * Returns the Cpdf instance |
|
254 | + * |
|
255 | + * @return Cpdf |
|
256 | + */ |
|
257 | + function get_cpdf() { return $this->_pdf; } |
|
258 | + |
|
259 | + /** |
|
260 | + * Add meta information to the PDF |
|
261 | + * |
|
262 | + * @param string $label label of the value (Creator, Producter, etc.) |
|
263 | + * @param string $value the text to set |
|
264 | + */ |
|
265 | + function add_info($label, $value) { |
|
266 | 266 | $this->_pdf->addInfo($label, $value); |
267 | - } |
|
268 | - |
|
269 | - /** |
|
270 | - * Opens a new 'object' |
|
271 | - * |
|
272 | - * While an object is open, all drawing actions are recored in the object, |
|
273 | - * as opposed to being drawn on the current page. Objects can be added |
|
274 | - * later to a specific page or to several pages. |
|
275 | - * |
|
276 | - * The return value is an integer ID for the new object. |
|
277 | - * |
|
278 | - * @see CPDF_Adapter::close_object() |
|
279 | - * @see CPDF_Adapter::add_object() |
|
280 | - * |
|
281 | - * @return int |
|
282 | - */ |
|
283 | - function open_object() { |
|
267 | + } |
|
268 | + |
|
269 | + /** |
|
270 | + * Opens a new 'object' |
|
271 | + * |
|
272 | + * While an object is open, all drawing actions are recored in the object, |
|
273 | + * as opposed to being drawn on the current page. Objects can be added |
|
274 | + * later to a specific page or to several pages. |
|
275 | + * |
|
276 | + * The return value is an integer ID for the new object. |
|
277 | + * |
|
278 | + * @see CPDF_Adapter::close_object() |
|
279 | + * @see CPDF_Adapter::add_object() |
|
280 | + * |
|
281 | + * @return int |
|
282 | + */ |
|
283 | + function open_object() { |
|
284 | 284 | $ret = $this->_pdf->openObject(); |
285 | 285 | $this->_pdf->saveState(); |
286 | 286 | return $ret; |
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * Reopens an existing 'object' |
|
291 | - * |
|
292 | - * @see CPDF_Adapter::open_object() |
|
293 | - * @param int $object the ID of a previously opened object |
|
294 | - */ |
|
295 | - function reopen_object($object) { |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * Reopens an existing 'object' |
|
291 | + * |
|
292 | + * @see CPDF_Adapter::open_object() |
|
293 | + * @param int $object the ID of a previously opened object |
|
294 | + */ |
|
295 | + function reopen_object($object) { |
|
296 | 296 | $this->_pdf->reopenObject($object); |
297 | 297 | $this->_pdf->saveState(); |
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * Closes the current 'object' |
|
302 | - * |
|
303 | - * @see CPDF_Adapter::open_object() |
|
304 | - */ |
|
305 | - function close_object() { |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * Closes the current 'object' |
|
302 | + * |
|
303 | + * @see CPDF_Adapter::open_object() |
|
304 | + */ |
|
305 | + function close_object() { |
|
306 | 306 | $this->_pdf->restoreState(); |
307 | 307 | $this->_pdf->closeObject(); |
308 | - } |
|
309 | - |
|
310 | - /** |
|
311 | - * Adds a specified 'object' to the document |
|
312 | - * |
|
313 | - * $object int specifying an object created with {@link |
|
314 | - * CPDF_Adapter::open_object()}. $where can be one of: |
|
315 | - * - 'add' add to current page only |
|
316 | - * - 'all' add to every page from the current one onwards |
|
317 | - * - 'odd' add to all odd numbered pages from now on |
|
318 | - * - 'even' add to all even numbered pages from now on |
|
319 | - * - 'next' add the object to the next page only |
|
320 | - * - 'nextodd' add to all odd numbered pages from the next one |
|
321 | - * - 'nexteven' add to all even numbered pages from the next one |
|
322 | - * |
|
323 | - * @see Cpdf::addObject() |
|
324 | - * |
|
325 | - * @param int $object |
|
326 | - * @param string $where |
|
327 | - */ |
|
328 | - function add_object($object, $where = 'all') { |
|
308 | + } |
|
309 | + |
|
310 | + /** |
|
311 | + * Adds a specified 'object' to the document |
|
312 | + * |
|
313 | + * $object int specifying an object created with {@link |
|
314 | + * CPDF_Adapter::open_object()}. $where can be one of: |
|
315 | + * - 'add' add to current page only |
|
316 | + * - 'all' add to every page from the current one onwards |
|
317 | + * - 'odd' add to all odd numbered pages from now on |
|
318 | + * - 'even' add to all even numbered pages from now on |
|
319 | + * - 'next' add the object to the next page only |
|
320 | + * - 'nextodd' add to all odd numbered pages from the next one |
|
321 | + * - 'nexteven' add to all even numbered pages from the next one |
|
322 | + * |
|
323 | + * @see Cpdf::addObject() |
|
324 | + * |
|
325 | + * @param int $object |
|
326 | + * @param string $where |
|
327 | + */ |
|
328 | + function add_object($object, $where = 'all') { |
|
329 | 329 | $this->_pdf->addObject($object, $where); |
330 | - } |
|
331 | - |
|
332 | - /** |
|
333 | - * Stops the specified 'object' from appearing in the document. |
|
334 | - * |
|
335 | - * The object will stop being displayed on the page following the current |
|
336 | - * one. |
|
337 | - * |
|
338 | - * @param int $object |
|
339 | - */ |
|
340 | - function stop_object($object) { |
|
330 | + } |
|
331 | + |
|
332 | + /** |
|
333 | + * Stops the specified 'object' from appearing in the document. |
|
334 | + * |
|
335 | + * The object will stop being displayed on the page following the current |
|
336 | + * one. |
|
337 | + * |
|
338 | + * @param int $object |
|
339 | + */ |
|
340 | + function stop_object($object) { |
|
341 | 341 | $this->_pdf->stopObject($object); |
342 | - } |
|
342 | + } |
|
343 | 343 | |
344 | - /** |
|
345 | - * @access private |
|
346 | - */ |
|
347 | - function serialize_object($id) { |
|
344 | + /** |
|
345 | + * @access private |
|
346 | + */ |
|
347 | + function serialize_object($id) { |
|
348 | 348 | // Serialize the pdf object's current state for retrieval later |
349 | 349 | return $this->_pdf->serializeObject($id); |
350 | - } |
|
350 | + } |
|
351 | 351 | |
352 | - /** |
|
353 | - * @access private |
|
354 | - */ |
|
355 | - function reopen_serialized_object($obj) { |
|
352 | + /** |
|
353 | + * @access private |
|
354 | + */ |
|
355 | + function reopen_serialized_object($obj) { |
|
356 | 356 | return $this->_pdf->restoreSerializedObject($obj); |
357 | - } |
|
357 | + } |
|
358 | 358 | |
359 | - //........................................................................ |
|
360 | - |
|
361 | - /** |
|
362 | - * Returns the PDF's width in points |
|
363 | - * @return float |
|
364 | - */ |
|
365 | - function get_width() { return $this->_width; } |
|
366 | - |
|
367 | - /** |
|
368 | - * Returns the PDF's height in points |
|
369 | - * @return float |
|
370 | - */ |
|
371 | - function get_height() { return $this->_height; } |
|
372 | - |
|
373 | - /** |
|
374 | - * Returns the current page number |
|
375 | - * @return int |
|
376 | - */ |
|
377 | - function get_page_number() { return $this->_page_number; } |
|
378 | - |
|
379 | - /** |
|
380 | - * Returns the total number of pages in the document |
|
381 | - * @return int |
|
382 | - */ |
|
383 | - function get_page_count() { return $this->_page_count; } |
|
384 | - |
|
385 | - /** |
|
386 | - * Sets the current page number |
|
387 | - * |
|
388 | - * @param int $num |
|
389 | - */ |
|
390 | - function set_page_number($num) { $this->_page_number = $num; } |
|
391 | - |
|
392 | - /** |
|
393 | - * Sets the page count |
|
394 | - * |
|
395 | - * @param int $count |
|
396 | - */ |
|
397 | - function set_page_count($count) { $this->_page_count = $count; } |
|
359 | + //........................................................................ |
|
360 | + |
|
361 | + /** |
|
362 | + * Returns the PDF's width in points |
|
363 | + * @return float |
|
364 | + */ |
|
365 | + function get_width() { return $this->_width; } |
|
366 | + |
|
367 | + /** |
|
368 | + * Returns the PDF's height in points |
|
369 | + * @return float |
|
370 | + */ |
|
371 | + function get_height() { return $this->_height; } |
|
372 | + |
|
373 | + /** |
|
374 | + * Returns the current page number |
|
375 | + * @return int |
|
376 | + */ |
|
377 | + function get_page_number() { return $this->_page_number; } |
|
378 | + |
|
379 | + /** |
|
380 | + * Returns the total number of pages in the document |
|
381 | + * @return int |
|
382 | + */ |
|
383 | + function get_page_count() { return $this->_page_count; } |
|
384 | + |
|
385 | + /** |
|
386 | + * Sets the current page number |
|
387 | + * |
|
388 | + * @param int $num |
|
389 | + */ |
|
390 | + function set_page_number($num) { $this->_page_number = $num; } |
|
391 | + |
|
392 | + /** |
|
393 | + * Sets the page count |
|
394 | + * |
|
395 | + * @param int $count |
|
396 | + */ |
|
397 | + function set_page_count($count) { $this->_page_count = $count; } |
|
398 | 398 | |
399 | - /** |
|
400 | - * Sets the stroke colour |
|
401 | - * |
|
402 | - * See {@link Style::set_colour()} for the format of the color array. |
|
403 | - * @param array $color |
|
404 | - */ |
|
405 | - protected function _set_stroke_color($color) { |
|
399 | + /** |
|
400 | + * Sets the stroke colour |
|
401 | + * |
|
402 | + * See {@link Style::set_colour()} for the format of the color array. |
|
403 | + * @param array $color |
|
404 | + */ |
|
405 | + protected function _set_stroke_color($color) { |
|
406 | 406 | list($r, $g, $b) = $color; |
407 | 407 | $this->_pdf->setStrokeColor($r, $g, $b); |
408 | - } |
|
408 | + } |
|
409 | 409 | |
410 | - /** |
|
411 | - * Sets the fill colour |
|
412 | - * |
|
413 | - * See {@link Style::set_colour()} for the format of the colour array. |
|
414 | - * @param array $color |
|
415 | - */ |
|
416 | - protected function _set_fill_color($color) { |
|
410 | + /** |
|
411 | + * Sets the fill colour |
|
412 | + * |
|
413 | + * See {@link Style::set_colour()} for the format of the colour array. |
|
414 | + * @param array $color |
|
415 | + */ |
|
416 | + protected function _set_fill_color($color) { |
|
417 | 417 | list($r, $g, $b) = $color; |
418 | 418 | $this->_pdf->setColor($r, $g, $b); |
419 | - } |
|
420 | - |
|
421 | - /** |
|
422 | - * Sets line transparency |
|
423 | - * @see Cpdf::setLineTransparency() |
|
424 | - * |
|
425 | - * Valid blend modes are (case-sensitive): |
|
426 | - * |
|
427 | - * Normal, Multiply, Screen, Overlay, Darken, Lighten, |
|
428 | - * ColorDodge, ColorBurn, HardLight, SoftLight, Difference, |
|
429 | - * Exclusion |
|
430 | - * |
|
431 | - * @param string $mode the blending mode to use |
|
432 | - * @param float $opacity 0.0 fully transparent, 1.0 fully opaque |
|
433 | - */ |
|
434 | - protected function _set_line_transparency($mode, $opacity) { |
|
419 | + } |
|
420 | + |
|
421 | + /** |
|
422 | + * Sets line transparency |
|
423 | + * @see Cpdf::setLineTransparency() |
|
424 | + * |
|
425 | + * Valid blend modes are (case-sensitive): |
|
426 | + * |
|
427 | + * Normal, Multiply, Screen, Overlay, Darken, Lighten, |
|
428 | + * ColorDodge, ColorBurn, HardLight, SoftLight, Difference, |
|
429 | + * Exclusion |
|
430 | + * |
|
431 | + * @param string $mode the blending mode to use |
|
432 | + * @param float $opacity 0.0 fully transparent, 1.0 fully opaque |
|
433 | + */ |
|
434 | + protected function _set_line_transparency($mode, $opacity) { |
|
435 | 435 | $this->_pdf->setLineTransparency($mode, $opacity); |
436 | - } |
|
436 | + } |
|
437 | 437 | |
438 | - /** |
|
439 | - * Sets fill transparency |
|
440 | - * @see Cpdf::setFillTransparency() |
|
441 | - * |
|
442 | - * Valid blend modes are (case-sensitive): |
|
443 | - * |
|
444 | - * Normal, Multiply, Screen, Overlay, Darken, Lighten, |
|
445 | - * ColorDogde, ColorBurn, HardLight, SoftLight, Difference, |
|
446 | - * Exclusion |
|
447 | - * |
|
448 | - * @param string $mode the blending mode to use |
|
449 | - * @param float $opacity 0.0 fully transparent, 1.0 fully opaque |
|
450 | - */ |
|
451 | - protected function _set_fill_transparency($mode, $opacity) { |
|
438 | + /** |
|
439 | + * Sets fill transparency |
|
440 | + * @see Cpdf::setFillTransparency() |
|
441 | + * |
|
442 | + * Valid blend modes are (case-sensitive): |
|
443 | + * |
|
444 | + * Normal, Multiply, Screen, Overlay, Darken, Lighten, |
|
445 | + * ColorDogde, ColorBurn, HardLight, SoftLight, Difference, |
|
446 | + * Exclusion |
|
447 | + * |
|
448 | + * @param string $mode the blending mode to use |
|
449 | + * @param float $opacity 0.0 fully transparent, 1.0 fully opaque |
|
450 | + */ |
|
451 | + protected function _set_fill_transparency($mode, $opacity) { |
|
452 | 452 | $this->_pdf->setFillTransparency($mode, $opacity); |
453 | - } |
|
454 | - |
|
455 | - /** |
|
456 | - * Sets the line style |
|
457 | - * |
|
458 | - * @see Cpdf::setLineStyle() |
|
459 | - * |
|
460 | - * @param float width |
|
461 | - * @param string cap |
|
462 | - * @param string join |
|
463 | - * @param array dash |
|
464 | - */ |
|
465 | - protected function _set_line_style($width, $cap, $join, $dash) { |
|
453 | + } |
|
454 | + |
|
455 | + /** |
|
456 | + * Sets the line style |
|
457 | + * |
|
458 | + * @see Cpdf::setLineStyle() |
|
459 | + * |
|
460 | + * @param float width |
|
461 | + * @param string cap |
|
462 | + * @param string join |
|
463 | + * @param array dash |
|
464 | + */ |
|
465 | + protected function _set_line_style($width, $cap, $join, $dash) { |
|
466 | 466 | $this->_pdf->setLineStyle($width, $cap, $join, $dash); |
467 | - } |
|
467 | + } |
|
468 | 468 | |
469 | - //........................................................................ |
|
469 | + //........................................................................ |
|
470 | 470 | |
471 | 471 | |
472 | - /** |
|
473 | - * Remaps y coords from 4th to 1st quadrant |
|
474 | - * |
|
475 | - * @param float $y |
|
476 | - * @return float |
|
477 | - */ |
|
478 | - protected function y($y) { return $this->_height - $y; } |
|
472 | + /** |
|
473 | + * Remaps y coords from 4th to 1st quadrant |
|
474 | + * |
|
475 | + * @param float $y |
|
476 | + * @return float |
|
477 | + */ |
|
478 | + protected function y($y) { return $this->_height - $y; } |
|
479 | 479 | |
480 | - // Canvas implementation |
|
480 | + // Canvas implementation |
|
481 | 481 | |
482 | - function line($x1, $y1, $x2, $y2, $color, $width, $style = array(), |
|
482 | + function line($x1, $y1, $x2, $y2, $color, $width, $style = array(), |
|
483 | 483 | $blend = "Normal", $opacity = 1.0) { |
484 | 484 | //pre_r(compact("x1", "y1", "x2", "y2", "color", "width", "style")); |
485 | 485 | |
@@ -488,35 +488,35 @@ discard block |
||
488 | 488 | $this->_set_line_transparency($blend, $opacity); |
489 | 489 | |
490 | 490 | $this->_pdf->line($x1, $this->y($y1), |
491 | - $x2, $this->y($y2)); |
|
492 | - } |
|
491 | + $x2, $this->y($y2)); |
|
492 | + } |
|
493 | 493 | |
494 | - //........................................................................ |
|
495 | - |
|
496 | - /** |
|
497 | - * Convert a GIF image to a PNG image |
|
498 | - * |
|
499 | - * @return string The url of the newly converted image |
|
500 | - */ |
|
501 | - protected function _convert_gif_to_png($image_url) { |
|
494 | + //........................................................................ |
|
495 | + |
|
496 | + /** |
|
497 | + * Convert a GIF image to a PNG image |
|
498 | + * |
|
499 | + * @return string The url of the newly converted image |
|
500 | + */ |
|
501 | + protected function _convert_gif_to_png($image_url) { |
|
502 | 502 | |
503 | 503 | if ( !function_exists("imagecreatefromgif") ) { |
504 | - throw new DOMPDF_Exception("Function imagecreatefromgif() not found. Cannot convert gif image: $image_url. Please install the image PHP extension."); |
|
504 | + throw new DOMPDF_Exception("Function imagecreatefromgif() not found. Cannot convert gif image: $image_url. Please install the image PHP extension."); |
|
505 | 505 | } |
506 | 506 | |
507 | 507 | $old_err = set_error_handler("record_warnings"); |
508 | 508 | $im = imagecreatefromgif($image_url); |
509 | 509 | |
510 | 510 | if ( $im ) { |
511 | - imageinterlace($im, 0); |
|
511 | + imageinterlace($im, 0); |
|
512 | 512 | |
513 | - $filename = tempnam(DOMPDF_TEMP_DIR, "gifdompdf_img_").'.png'; |
|
514 | - $this->_image_cache[] = $filename; |
|
513 | + $filename = tempnam(DOMPDF_TEMP_DIR, "gifdompdf_img_").'.png'; |
|
514 | + $this->_image_cache[] = $filename; |
|
515 | 515 | |
516 | - imagepng($im, $filename); |
|
516 | + imagepng($im, $filename); |
|
517 | 517 | |
518 | 518 | } else { |
519 | - $filename = DOMPDF_LIB_DIR . "/res/broken_image.png"; |
|
519 | + $filename = DOMPDF_LIB_DIR . "/res/broken_image.png"; |
|
520 | 520 | |
521 | 521 | } |
522 | 522 | |
@@ -524,21 +524,21 @@ discard block |
||
524 | 524 | |
525 | 525 | return $filename; |
526 | 526 | |
527 | - } |
|
527 | + } |
|
528 | 528 | |
529 | - function rectangle($x1, $y1, $w, $h, $color, $width, $style = array(), |
|
530 | - $blend = "Normal", $opacity = 1.0) { |
|
529 | + function rectangle($x1, $y1, $w, $h, $color, $width, $style = array(), |
|
530 | + $blend = "Normal", $opacity = 1.0) { |
|
531 | 531 | |
532 | 532 | $this->_set_stroke_color($color); |
533 | 533 | $this->_set_line_style($width, "square", "miter", $style); |
534 | 534 | $this->_set_line_transparency($blend, $opacity); |
535 | 535 | |
536 | 536 | $this->_pdf->rectangle($x1, $this->y($y1) - $h, $w, $h); |
537 | - } |
|
537 | + } |
|
538 | 538 | |
539 | - //........................................................................ |
|
539 | + //........................................................................ |
|
540 | 540 | |
541 | - function filled_rectangle($x1, $y1, $w, $h, $color, $blend = "Normal", $opacity = 1.0) { |
|
541 | + function filled_rectangle($x1, $y1, $w, $h, $color, $blend = "Normal", $opacity = 1.0) { |
|
542 | 542 | |
543 | 543 | $this->_set_fill_color($color); |
544 | 544 | $this->_set_line_style(1, "square", "miter", array()); |
@@ -546,12 +546,12 @@ discard block |
||
546 | 546 | $this->_set_fill_transparency($blend, $opacity); |
547 | 547 | |
548 | 548 | $this->_pdf->filledRectangle($x1, $this->y($y1) - $h, $w, $h); |
549 | - } |
|
549 | + } |
|
550 | 550 | |
551 | - //........................................................................ |
|
551 | + //........................................................................ |
|
552 | 552 | |
553 | - function polygon($points, $color, $width = null, $style = array(), |
|
554 | - $fill = false, $blend = "Normal", $opacity = 1.0) { |
|
553 | + function polygon($points, $color, $width = null, $style = array(), |
|
554 | + $fill = false, $blend = "Normal", $opacity = 1.0) { |
|
555 | 555 | |
556 | 556 | $this->_set_fill_color($color); |
557 | 557 | $this->_set_stroke_color($color); |
@@ -560,19 +560,19 @@ discard block |
||
560 | 560 | $this->_set_fill_transparency($blend, $opacity); |
561 | 561 | |
562 | 562 | if ( !$fill && isset($width) ) |
563 | - $this->_set_line_style($width, "square", "miter", $style); |
|
563 | + $this->_set_line_style($width, "square", "miter", $style); |
|
564 | 564 | |
565 | 565 | // Adjust y values |
566 | 566 | for ( $i = 1; $i < count($points); $i += 2) |
567 | - $points[$i] = $this->y($points[$i]); |
|
567 | + $points[$i] = $this->y($points[$i]); |
|
568 | 568 | |
569 | 569 | $this->_pdf->polygon($points, count($points) / 2, $fill); |
570 | - } |
|
570 | + } |
|
571 | 571 | |
572 | - //........................................................................ |
|
572 | + //........................................................................ |
|
573 | 573 | |
574 | - function circle($x, $y, $r1, $color, $width = null, $style = null, |
|
575 | - $fill = false, $blend = "Normal", $opacity = 1.0) { |
|
574 | + function circle($x, $y, $r1, $color, $width = null, $style = null, |
|
575 | + $fill = false, $blend = "Normal", $opacity = 1.0) { |
|
576 | 576 | |
577 | 577 | $this->_set_fill_color($color); |
578 | 578 | $this->_set_stroke_color($color); |
@@ -581,14 +581,14 @@ discard block |
||
581 | 581 | $this->_set_fill_transparency($blend, $opacity); |
582 | 582 | |
583 | 583 | if ( !$fill && isset($width) ) |
584 | - $this->_set_line_style($width, "round", "round", $style); |
|
584 | + $this->_set_line_style($width, "round", "round", $style); |
|
585 | 585 | |
586 | 586 | $this->_pdf->ellipse($x, $this->y($y), $r1, 0, 0, 8, 0, 360, 1, $fill); |
587 | - } |
|
587 | + } |
|
588 | 588 | |
589 | - //........................................................................ |
|
589 | + //........................................................................ |
|
590 | 590 | |
591 | - function image($img_url, $img_type, $x, $y, $w, $h) { |
|
591 | + function image($img_url, $img_type, $x, $y, $w, $h) { |
|
592 | 592 | //debugpng |
593 | 593 | if (DEBUGPNG) print '[image:'.$img_url.'|'.$img_type.']'; |
594 | 594 | |
@@ -600,15 +600,15 @@ discard block |
||
600 | 600 | //debugpng |
601 | 601 | if (DEBUGPNG) print '!!!jpg!!!'; |
602 | 602 | |
603 | - $this->_pdf->addJpegFromFile($img_url, $x, $this->y($y) - $h, $w, $h); |
|
604 | - break; |
|
603 | + $this->_pdf->addJpegFromFile($img_url, $x, $this->y($y) - $h, $w, $h); |
|
604 | + break; |
|
605 | 605 | |
606 | 606 | case "png": |
607 | 607 | //debugpng |
608 | 608 | if (DEBUGPNG) print '!!!png!!!'; |
609 | 609 | |
610 | - $this->_pdf->addPngFromFile($img_url, $x, $this->y($y) - $h, $w, $h); |
|
611 | - break; |
|
610 | + $this->_pdf->addPngFromFile($img_url, $x, $this->y($y) - $h, $w, $h); |
|
611 | + break; |
|
612 | 612 | |
613 | 613 | case "gif": |
614 | 614 | // Convert gifs to pngs |
@@ -618,41 +618,41 @@ discard block |
||
618 | 618 | //debugpng |
619 | 619 | if (DEBUGPNG) print '!!!gif addImagePng!!!'; |
620 | 620 | |
621 | - //If optimization to direct png creation from gd object is available, |
|
621 | + //If optimization to direct png creation from gd object is available, |
|
622 | 622 | //don't create temp file, but place gd object directly into the pdf |
623 | - if ( method_exists( $this->_pdf, "image_iscached" ) && |
|
624 | - $this->_pdf->image_iscached($img_url) ) { |
|
625 | - //If same image has occured already before, no need to load because |
|
626 | - //duplicate will anyway be eliminated. |
|
627 | - $img = null; |
|
628 | - } else { |
|
629 | - $img = @imagecreatefromgif($img_url); |
|
630 | - if (!$img) { |
|
631 | - return; |
|
632 | - } |
|
633 | - imageinterlace($img, 0); |
|
634 | - } |
|
635 | - $this->_pdf->addImagePng($img_url, $x, $this->y($y) - $h, $w, $h, $img); |
|
636 | - } else { |
|
623 | + if ( method_exists( $this->_pdf, "image_iscached" ) && |
|
624 | + $this->_pdf->image_iscached($img_url) ) { |
|
625 | + //If same image has occured already before, no need to load because |
|
626 | + //duplicate will anyway be eliminated. |
|
627 | + $img = null; |
|
628 | + } else { |
|
629 | + $img = @imagecreatefromgif($img_url); |
|
630 | + if (!$img) { |
|
631 | + return; |
|
632 | + } |
|
633 | + imageinterlace($img, 0); |
|
634 | + } |
|
635 | + $this->_pdf->addImagePng($img_url, $x, $this->y($y) - $h, $w, $h, $img); |
|
636 | + } else { |
|
637 | 637 | //debugpng |
638 | 638 | if (DEBUGPNG) print '!!!gif addPngFromFile!!!'; |
639 | 639 | $img_url = $this->_convert_gif_to_png($img_url); |
640 | 640 | $this->_pdf->addPngFromFile($img_url, $x, $this->y($y) - $h, $w, $h); |
641 | - } |
|
642 | - break; |
|
641 | + } |
|
642 | + break; |
|
643 | 643 | |
644 | 644 | default: |
645 | 645 | //debugpng |
646 | 646 | if (DEBUGPNG) print '!!!unknown!!!'; |
647 | - break; |
|
647 | + break; |
|
648 | 648 | } |
649 | 649 | |
650 | 650 | return; |
651 | - } |
|
651 | + } |
|
652 | 652 | |
653 | - //........................................................................ |
|
653 | + //........................................................................ |
|
654 | 654 | |
655 | - function text($x, $y, $text, $font, $size, $color = array(0,0,0), |
|
655 | + function text($x, $y, $text, $font, $size, $color = array(0,0,0), |
|
656 | 656 | $adjust = 0, $angle = 0, $blend = "Normal", $opacity = 1.0) { |
657 | 657 | |
658 | 658 | list($r, $g, $b) = $color; |
@@ -693,142 +693,142 @@ discard block |
||
693 | 693 | //print '<pre>['.$font.','.$size.','.$this->_pdf->getFontHeight($size).','.$this->_pdf->getFontDescender($size).','.$this->_pdf->fonts[$this->_pdf->currentFont]['FontBBox'][3].','.$this->_pdf->fonts[$this->_pdf->currentFont]['FontBBox'][1].','.$this->_pdf->fonts[$this->_pdf->currentFont]['FontHeightOffset'].','.$this->_pdf->fonts[$this->_pdf->currentFont]['Ascender'].','.$this->_pdf->fonts[$this->_pdf->currentFont]['Descender'].']</pre>'; |
694 | 694 | // |
695 | 695 | //$this->_pdf->addText($x, $this->y($y) - Font_Metrics::get_font_height($font, $size), $size, $text, $angle, $adjust); |
696 | - //$this->_pdf->addText($x, $this->y($y) - $size, $size, $text, $angle, $adjust); |
|
697 | - //$this->_pdf->addText($x, $this->y($y) - $this->_pdf->getFontHeight($size)-$this->_pdf->getFontDescender($size), $size, $text, $angle, $adjust); |
|
698 | - $this->_pdf->addText($x, $this->y($y) - ($this->_pdf->fonts[$this->_pdf->currentFont]['FontBBox'][3]*$size)/1000, $size, $text, $angle, $adjust); |
|
699 | - } |
|
696 | + //$this->_pdf->addText($x, $this->y($y) - $size, $size, $text, $angle, $adjust); |
|
697 | + //$this->_pdf->addText($x, $this->y($y) - $this->_pdf->getFontHeight($size)-$this->_pdf->getFontDescender($size), $size, $text, $angle, $adjust); |
|
698 | + $this->_pdf->addText($x, $this->y($y) - ($this->_pdf->fonts[$this->_pdf->currentFont]['FontBBox'][3]*$size)/1000, $size, $text, $angle, $adjust); |
|
699 | + } |
|
700 | 700 | |
701 | - //........................................................................ |
|
701 | + //........................................................................ |
|
702 | 702 | |
703 | - function javascript($code) { |
|
703 | + function javascript($code) { |
|
704 | 704 | $this->_pdf->addJavascript($code); |
705 | - } |
|
705 | + } |
|
706 | 706 | |
707 | - //........................................................................ |
|
707 | + //........................................................................ |
|
708 | 708 | |
709 | - /** |
|
710 | - * Add a named destination (similar to <a name="foo">...</a> in html) |
|
711 | - * |
|
712 | - * @param string $anchorname The name of the named destination |
|
713 | - */ |
|
714 | - function add_named_dest($anchorname) { |
|
709 | + /** |
|
710 | + * Add a named destination (similar to <a name="foo">...</a> in html) |
|
711 | + * |
|
712 | + * @param string $anchorname The name of the named destination |
|
713 | + */ |
|
714 | + function add_named_dest($anchorname) { |
|
715 | 715 | $this->_pdf->addDestination($anchorname,"Fit"); |
716 | - } |
|
716 | + } |
|
717 | 717 | |
718 | - //........................................................................ |
|
718 | + //........................................................................ |
|
719 | 719 | |
720 | - /** |
|
721 | - * Add a link to the pdf |
|
722 | - * |
|
723 | - * @param string $url The url to link to |
|
724 | - * @param float $x The x position of the link |
|
725 | - * @param float $y The y position of the link |
|
726 | - * @param float $width The width of the link |
|
727 | - * @param float $height The height of the link |
|
728 | - */ |
|
729 | - function add_link($url, $x, $y, $width, $height) { |
|
720 | + /** |
|
721 | + * Add a link to the pdf |
|
722 | + * |
|
723 | + * @param string $url The url to link to |
|
724 | + * @param float $x The x position of the link |
|
725 | + * @param float $y The y position of the link |
|
726 | + * @param float $width The width of the link |
|
727 | + * @param float $height The height of the link |
|
728 | + */ |
|
729 | + function add_link($url, $x, $y, $width, $height) { |
|
730 | 730 | |
731 | 731 | $y = $this->y($y) - $height; |
732 | 732 | |
733 | 733 | if ( strpos($url, '#') === 0 ) { |
734 | - // Local link |
|
735 | - $name = substr($url,1); |
|
736 | - if ( $name ) |
|
734 | + // Local link |
|
735 | + $name = substr($url,1); |
|
736 | + if ( $name ) |
|
737 | 737 | $this->_pdf->addInternalLink($name, $x, $y, $x + $width, $y + $height); |
738 | 738 | |
739 | 739 | } else { |
740 | - $this->_pdf->addLink(rawurldecode($url), $x, $y, $x + $width, $y + $height); |
|
740 | + $this->_pdf->addLink(rawurldecode($url), $x, $y, $x + $width, $y + $height); |
|
741 | 741 | } |
742 | 742 | |
743 | - } |
|
743 | + } |
|
744 | 744 | |
745 | - //........................................................................ |
|
745 | + //........................................................................ |
|
746 | 746 | |
747 | - function get_text_width($text, $font, $size, $spacing = 0) { |
|
747 | + function get_text_width($text, $font, $size, $spacing = 0) { |
|
748 | 748 | $this->_pdf->selectFont($font); |
749 | 749 | if (!DOMPDF_UNICODE_ENABLED) { |
750 | - $text = mb_convert_encoding($text, 'Windows-1252', 'UTF-8'); |
|
750 | + $text = mb_convert_encoding($text, 'Windows-1252', 'UTF-8'); |
|
751 | 751 | } |
752 | 752 | return $this->_pdf->getTextWidth($size, $text, $spacing); |
753 | - } |
|
753 | + } |
|
754 | 754 | |
755 | - //........................................................................ |
|
755 | + //........................................................................ |
|
756 | 756 | |
757 | - function get_font_height($font, $size) { |
|
757 | + function get_font_height($font, $size) { |
|
758 | 758 | $this->_pdf->selectFont($font); |
759 | 759 | return $this->_pdf->getFontHeight($size); |
760 | - } |
|
760 | + } |
|
761 | 761 | |
762 | - //........................................................................ |
|
762 | + //........................................................................ |
|
763 | 763 | |
764 | - /** |
|
765 | - * Writes text at the specified x and y coordinates on every page |
|
766 | - * |
|
767 | - * The strings '{PAGE_NUM}' and '{PAGE_COUNT}' are automatically replaced |
|
768 | - * with their current values. |
|
769 | - * |
|
770 | - * See {@link Style::munge_colour()} for the format of the colour array. |
|
771 | - * |
|
772 | - * @param float $x |
|
773 | - * @param float $y |
|
774 | - * @param string $text the text to write |
|
775 | - * @param string $font the font file to use |
|
776 | - * @param float $size the font size, in points |
|
777 | - * @param array $color |
|
778 | - * @param float $adjust word spacing adjustment |
|
779 | - * @param float $angle angle to write the text at, measured CW starting from the x-axis |
|
780 | - */ |
|
781 | - function page_text($x, $y, $text, $font, $size, $color = array(0,0,0), |
|
782 | - $adjust = 0, $angle = 0) { |
|
764 | + /** |
|
765 | + * Writes text at the specified x and y coordinates on every page |
|
766 | + * |
|
767 | + * The strings '{PAGE_NUM}' and '{PAGE_COUNT}' are automatically replaced |
|
768 | + * with their current values. |
|
769 | + * |
|
770 | + * See {@link Style::munge_colour()} for the format of the colour array. |
|
771 | + * |
|
772 | + * @param float $x |
|
773 | + * @param float $y |
|
774 | + * @param string $text the text to write |
|
775 | + * @param string $font the font file to use |
|
776 | + * @param float $size the font size, in points |
|
777 | + * @param array $color |
|
778 | + * @param float $adjust word spacing adjustment |
|
779 | + * @param float $angle angle to write the text at, measured CW starting from the x-axis |
|
780 | + */ |
|
781 | + function page_text($x, $y, $text, $font, $size, $color = array(0,0,0), |
|
782 | + $adjust = 0, $angle = 0) { |
|
783 | 783 | $_t = "text"; |
784 | 784 | $this->_page_text[] = compact("_t", "x", "y", "text", "font", "size", "color", "adjust", "angle"); |
785 | - } |
|
785 | + } |
|
786 | 786 | |
787 | - //........................................................................ |
|
787 | + //........................................................................ |
|
788 | 788 | |
789 | - /** |
|
790 | - * Processes a script on every page |
|
791 | - * |
|
792 | - * The variables $pdf, $PAGE_NUM, and $PAGE_COUNT are available. |
|
793 | - * |
|
794 | - * This function can be used to add page numbers to all pages |
|
795 | - * after the first one, for example. |
|
796 | - * |
|
797 | - * @param string $code the script code |
|
798 | - * @param string $type the language type for script |
|
799 | - */ |
|
800 | - function page_script($code, $type = "text/php") { |
|
789 | + /** |
|
790 | + * Processes a script on every page |
|
791 | + * |
|
792 | + * The variables $pdf, $PAGE_NUM, and $PAGE_COUNT are available. |
|
793 | + * |
|
794 | + * This function can be used to add page numbers to all pages |
|
795 | + * after the first one, for example. |
|
796 | + * |
|
797 | + * @param string $code the script code |
|
798 | + * @param string $type the language type for script |
|
799 | + */ |
|
800 | + function page_script($code, $type = "text/php") { |
|
801 | 801 | $_t = "script"; |
802 | 802 | $this->_page_text[] = compact("_t", "code", "type"); |
803 | - } |
|
803 | + } |
|
804 | 804 | |
805 | - //........................................................................ |
|
805 | + //........................................................................ |
|
806 | 806 | |
807 | - function new_page() { |
|
807 | + function new_page() { |
|
808 | 808 | $this->_page_count++; |
809 | 809 | |
810 | 810 | $ret = $this->_pdf->newPage(); |
811 | 811 | $this->_pages[] = $ret; |
812 | 812 | return $ret; |
813 | - } |
|
813 | + } |
|
814 | 814 | |
815 | - //........................................................................ |
|
815 | + //........................................................................ |
|
816 | 816 | |
817 | - /** |
|
818 | - * Add text to each page after rendering is complete |
|
819 | - */ |
|
820 | - protected function _add_page_text() { |
|
817 | + /** |
|
818 | + * Add text to each page after rendering is complete |
|
819 | + */ |
|
820 | + protected function _add_page_text() { |
|
821 | 821 | |
822 | 822 | if ( !count($this->_page_text) ) |
823 | - return; |
|
823 | + return; |
|
824 | 824 | |
825 | 825 | $page_number = 1; |
826 | 826 | $eval = null; |
827 | 827 | |
828 | 828 | foreach ($this->_pages as $pid) { |
829 | - $this->reopen_object($pid); |
|
829 | + $this->reopen_object($pid); |
|
830 | 830 | |
831 | - foreach ($this->_page_text as $pt) { |
|
831 | + foreach ($this->_page_text as $pt) { |
|
832 | 832 | extract($pt); |
833 | 833 | |
834 | 834 | switch ($_t) { |
@@ -837,63 +837,63 @@ discard block |
||
837 | 837 | $text = str_replace(array("{PAGE_NUM}","{PAGE_COUNT}"), |
838 | 838 | array($page_number, $this->_page_count), $text); |
839 | 839 | $this->text($x, $y, $text, $font, $size, $color, $adjust, $angle); |
840 | - break; |
|
840 | + break; |
|
841 | 841 | |
842 | 842 | case "script": |
843 | 843 | if (!$eval) { |
844 | 844 | $eval = new PHP_Evaluator($this); |
845 | - } |
|
846 | - $eval->evaluate($code, array('PAGE_NUM' => $page_number, 'PAGE_COUNT' => $this->_page_count)); |
|
847 | - break; |
|
845 | + } |
|
846 | + $eval->evaluate($code, array('PAGE_NUM' => $page_number, 'PAGE_COUNT' => $this->_page_count)); |
|
847 | + break; |
|
848 | + } |
|
848 | 849 | } |
849 | - } |
|
850 | 850 | |
851 | - $this->close_object(); |
|
852 | - $page_number++; |
|
851 | + $this->close_object(); |
|
852 | + $page_number++; |
|
853 | + } |
|
853 | 854 | } |
854 | - } |
|
855 | 855 | |
856 | - /** |
|
857 | - * Streams the PDF directly to the browser |
|
858 | - * |
|
859 | - * @param string $filename the name of the PDF file |
|
860 | - * @param array $options associative array, 'Attachment' => 0 or 1, 'compress' => 1 or 0 |
|
861 | - */ |
|
862 | - function stream($filename, $options = null) { |
|
856 | + /** |
|
857 | + * Streams the PDF directly to the browser |
|
858 | + * |
|
859 | + * @param string $filename the name of the PDF file |
|
860 | + * @param array $options associative array, 'Attachment' => 0 or 1, 'compress' => 1 or 0 |
|
861 | + */ |
|
862 | + function stream($filename, $options = null) { |
|
863 | 863 | // Add page text |
864 | 864 | $this->_add_page_text(); |
865 | 865 | |
866 | 866 | $options["Content-Disposition"] = $filename; |
867 | 867 | $this->_pdf->stream($options); |
868 | - } |
|
868 | + } |
|
869 | 869 | |
870 | - //........................................................................ |
|
870 | + //........................................................................ |
|
871 | 871 | |
872 | - /** |
|
873 | - * Returns the PDF as a string |
|
874 | - * |
|
875 | - * @return string |
|
876 | - */ |
|
877 | - function output($options = null) { |
|
872 | + /** |
|
873 | + * Returns the PDF as a string |
|
874 | + * |
|
875 | + * @return string |
|
876 | + */ |
|
877 | + function output($options = null) { |
|
878 | 878 | // Add page text |
879 | 879 | $this->_add_page_text(); |
880 | 880 | |
881 | 881 | if ( isset($options["compress"]) && $options["compress"] != 1 ) |
882 | - $debug = 1; |
|
882 | + $debug = 1; |
|
883 | 883 | else |
884 | - $debug = 0; |
|
884 | + $debug = 0; |
|
885 | 885 | |
886 | 886 | return $this->_pdf->output($debug); |
887 | 887 | |
888 | - } |
|
888 | + } |
|
889 | 889 | |
890 | - //........................................................................ |
|
891 | - |
|
892 | - /** |
|
893 | - * Returns logging messages generated by the Cpdf class |
|
894 | - * |
|
895 | - * @return string |
|
896 | - */ |
|
897 | - function get_messages() { return $this->_pdf->messages; } |
|
890 | + //........................................................................ |
|
891 | + |
|
892 | + /** |
|
893 | + * Returns logging messages generated by the Cpdf class |
|
894 | + * |
|
895 | + * @return string |
|
896 | + */ |
|
897 | + function get_messages() { return $this->_pdf->messages; } |
|
898 | 898 | |
899 | 899 | } |
@@ -35,7 +35,6 @@ discard block |
||
35 | 35 | * @author Benj Carson <[email protected]> |
36 | 36 | * @contributor Helmut Tischer <[email protected]> |
37 | 37 | * @package dompdf |
38 | - |
|
39 | 38 | * |
40 | 39 | * Changes |
41 | 40 | * @contributor Helmut Tischer <[email protected]> |
@@ -53,9 +52,9 @@ discard block |
||
53 | 52 | */ |
54 | 53 | class List_Bullet_Renderer extends Abstract_Renderer { |
55 | 54 | |
56 | - //........................................................................ |
|
55 | + //........................................................................ |
|
57 | 56 | |
58 | - function render(Frame $frame) { |
|
57 | + function render(Frame $frame) { |
|
59 | 58 | |
60 | 59 | $style = $frame->get_style(); |
61 | 60 | $font_size = $style->get_font_size(); |
@@ -66,36 +65,36 @@ discard block |
||
66 | 65 | if ( $style->list_style_image !== "none" && |
67 | 66 | strcmp($img = $frame->get_image_url(), DOMPDF_LIB_DIR . "/res/broken_image.png") != 0) { |
68 | 67 | |
69 | - list($x,$y) = $frame->get_position(); |
|
68 | + list($x,$y) = $frame->get_position(); |
|
70 | 69 | |
71 | - //For expected size and aspect, instead of box size, use image natural size scaled to DPI. |
|
72 | - // Resample the bullet image to be consistent with 'auto' sized images |
|
73 | - // See also Image_Frame_Reflower::get_min_max_width |
|
74 | - // Tested php ver: value measured in px, suffix "px" not in value: rtrim unnecessary. |
|
75 | - //$w = $frame->get_width(); |
|
76 | - //$h = $frame->get_height(); |
|
77 | - list($width, $height) = getimagesize($img); |
|
78 | - $w = (((float)rtrim($width, "px")) * 72) / DOMPDF_DPI; |
|
79 | - $h = (((float)rtrim($height, "px")) * 72) / DOMPDF_DPI; |
|
70 | + //For expected size and aspect, instead of box size, use image natural size scaled to DPI. |
|
71 | + // Resample the bullet image to be consistent with 'auto' sized images |
|
72 | + // See also Image_Frame_Reflower::get_min_max_width |
|
73 | + // Tested php ver: value measured in px, suffix "px" not in value: rtrim unnecessary. |
|
74 | + //$w = $frame->get_width(); |
|
75 | + //$h = $frame->get_height(); |
|
76 | + list($width, $height) = getimagesize($img); |
|
77 | + $w = (((float)rtrim($width, "px")) * 72) / DOMPDF_DPI; |
|
78 | + $h = (((float)rtrim($height, "px")) * 72) / DOMPDF_DPI; |
|
80 | 79 | |
81 | - $x -= $w; |
|
82 | - $y -= ($line_height - $font_size)/2; //Reverse hinting of list_bullet_positioner |
|
80 | + $x -= $w; |
|
81 | + $y -= ($line_height - $font_size)/2; //Reverse hinting of list_bullet_positioner |
|
83 | 82 | |
84 | - $this->_canvas->image( $img, $frame->get_image_ext(), $x, $y, $w, $h); |
|
83 | + $this->_canvas->image( $img, $frame->get_image_ext(), $x, $y, $w, $h); |
|
85 | 84 | |
86 | 85 | } else { |
87 | 86 | |
88 | - $bullet_style = $style->list_style_type; |
|
87 | + $bullet_style = $style->list_style_type; |
|
89 | 88 | |
90 | - $fill = false; |
|
89 | + $fill = false; |
|
91 | 90 | |
92 | - switch ($bullet_style) { |
|
91 | + switch ($bullet_style) { |
|
93 | 92 | |
94 | - default: |
|
93 | + default: |
|
95 | 94 | case "disc": |
96 | 95 | $fill = true; |
97 | 96 | |
98 | - case "circle": |
|
97 | + case "circle": |
|
99 | 98 | list($x,$y) = $frame->get_position(); |
100 | 99 | $r = ($font_size*(List_Bullet_Frame_Decorator::BULLET_SIZE /*-List_Bullet_Frame_Decorator::BULLET_THICKNESS*/ ))/2; |
101 | 100 | $x -= $font_size*(List_Bullet_Frame_Decorator::BULLET_SIZE/2); |
@@ -104,7 +103,7 @@ discard block |
||
104 | 103 | $this->_canvas->circle($x, $y, $r, $style->color, $o, null, $fill); |
105 | 104 | break; |
106 | 105 | |
107 | - case "square": |
|
106 | + case "square": |
|
108 | 107 | list($x, $y) = $frame->get_position(); |
109 | 108 | $w = $font_size*List_Bullet_Frame_Decorator::BULLET_SIZE; |
110 | 109 | $x -= $w; |
@@ -112,10 +111,10 @@ discard block |
||
112 | 111 | $this->_canvas->filled_rectangle($x, $y, $w, $w, $style->color); |
113 | 112 | break; |
114 | 113 | |
115 | - case "none": |
|
114 | + case "none": |
|
116 | 115 | break; |
117 | 116 | |
118 | - } |
|
117 | + } |
|
118 | + } |
|
119 | 119 | } |
120 | - } |
|
121 | 120 | } |
@@ -1,46 +1,46 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * DOMPDF - PHP5 HTML to PDF renderer |
|
4 | - * |
|
5 | - * File: $RCSfile: pdflib_adapter.cls.php,v $ |
|
6 | - * Created on: 2005-02-28 |
|
7 | - * |
|
8 | - * Copyright (c) 2004 - Benj Carson <[email protected]> |
|
9 | - * |
|
10 | - * This library is free software; you can redistribute it and/or |
|
11 | - * modify it under the terms of the GNU Lesser General Public |
|
12 | - * License as published by the Free Software Foundation; either |
|
13 | - * version 2.1 of the License, or (at your option) any later version. |
|
14 | - * |
|
15 | - * This library is distributed in the hope that it will be useful, |
|
16 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
18 | - * Lesser General Public License for more details. |
|
19 | - * |
|
20 | - * You should have received a copy of the GNU Lesser General Public License |
|
21 | - * along with this library in the file LICENSE.LGPL; if not, write to the |
|
22 | - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
|
23 | - * 02111-1307 USA |
|
24 | - * |
|
25 | - * Alternatively, you may distribute this software under the terms of the |
|
26 | - * PHP License, version 3.0 or later. A copy of this license should have |
|
27 | - * been distributed with this file in the file LICENSE.PHP . If this is not |
|
28 | - * the case, you can obtain a copy at http://www.php.net/license/3_0.txt. |
|
29 | - * |
|
30 | - * The latest version of DOMPDF might be available at: |
|
31 | - * http://www.dompdf.com/ |
|
32 | - * |
|
33 | - * @link http://www.dompdf.com/ |
|
34 | - * @copyright 2004 Benj Carson |
|
35 | - * @author Benj Carson <[email protected]> |
|
36 | - * @contributor Helmut Tischer <[email protected]> |
|
37 | - * @package dompdf |
|
38 | - * |
|
39 | - * Changes |
|
40 | - * @contributor Helmut Tischer <[email protected]> |
|
41 | - * @version 0.5.1.htischer.20090507 |
|
42 | - * - Clarify temp file name, optional debug output for temp file tracking |
|
43 | - */ |
|
3 | + * DOMPDF - PHP5 HTML to PDF renderer |
|
4 | + * |
|
5 | + * File: $RCSfile: pdflib_adapter.cls.php,v $ |
|
6 | + * Created on: 2005-02-28 |
|
7 | + * |
|
8 | + * Copyright (c) 2004 - Benj Carson <[email protected]> |
|
9 | + * |
|
10 | + * This library is free software; you can redistribute it and/or |
|
11 | + * modify it under the terms of the GNU Lesser General Public |
|
12 | + * License as published by the Free Software Foundation; either |
|
13 | + * version 2.1 of the License, or (at your option) any later version. |
|
14 | + * |
|
15 | + * This library is distributed in the hope that it will be useful, |
|
16 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
18 | + * Lesser General Public License for more details. |
|
19 | + * |
|
20 | + * You should have received a copy of the GNU Lesser General Public License |
|
21 | + * along with this library in the file LICENSE.LGPL; if not, write to the |
|
22 | + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
|
23 | + * 02111-1307 USA |
|
24 | + * |
|
25 | + * Alternatively, you may distribute this software under the terms of the |
|
26 | + * PHP License, version 3.0 or later. A copy of this license should have |
|
27 | + * been distributed with this file in the file LICENSE.PHP . If this is not |
|
28 | + * the case, you can obtain a copy at http://www.php.net/license/3_0.txt. |
|
29 | + * |
|
30 | + * The latest version of DOMPDF might be available at: |
|
31 | + * http://www.dompdf.com/ |
|
32 | + * |
|
33 | + * @link http://www.dompdf.com/ |
|
34 | + * @copyright 2004 Benj Carson |
|
35 | + * @author Benj Carson <[email protected]> |
|
36 | + * @contributor Helmut Tischer <[email protected]> |
|
37 | + * @package dompdf |
|
38 | + * |
|
39 | + * Changes |
|
40 | + * @contributor Helmut Tischer <[email protected]> |
|
41 | + * @version 0.5.1.htischer.20090507 |
|
42 | + * - Clarify temp file name, optional debug output for temp file tracking |
|
43 | + */ |
|
44 | 44 | |
45 | 45 | /* $Id: pdflib_adapter.cls.php 217 2010-03-11 23:03:57Z ryan.masten $ */ |
46 | 46 | |
@@ -61,170 +61,170 @@ discard block |
||
61 | 61 | */ |
62 | 62 | class PDFLib_Adapter implements Canvas { |
63 | 63 | |
64 | - /** |
|
65 | - * Dimensions of paper sizes in points |
|
66 | - * |
|
67 | - * @var array; |
|
68 | - */ |
|
69 | - static public $PAPER_SIZES = array(); // Set to |
|
64 | + /** |
|
65 | + * Dimensions of paper sizes in points |
|
66 | + * |
|
67 | + * @var array; |
|
68 | + */ |
|
69 | + static public $PAPER_SIZES = array(); // Set to |
|
70 | 70 | // CPDF_Adapter::$PAPER_SIZES below. |
71 | 71 | |
72 | - /** |
|
73 | - * Fudge factor to adjust reported font heights |
|
74 | - * |
|
75 | - * CPDF reports larger font heights than PDFLib. This factor |
|
76 | - * adjusts the height reported by get_font_height(). |
|
77 | - * |
|
78 | - * @var float |
|
79 | - */ |
|
80 | - const FONT_HEIGHT_SCALE = 1.2; |
|
81 | - |
|
82 | - /** |
|
83 | - * Whether to create PDFs in memory or on disk |
|
84 | - * |
|
85 | - * @var bool |
|
86 | - */ |
|
87 | - static $IN_MEMORY = true; |
|
88 | - |
|
89 | - /** |
|
90 | - * Instance of PDFLib class |
|
91 | - * |
|
92 | - * @var PDFlib |
|
93 | - */ |
|
94 | - private $_pdf; |
|
95 | - |
|
96 | - /** |
|
97 | - * Name of temporary file used for PDFs created on disk |
|
98 | - * |
|
99 | - * @var string |
|
100 | - */ |
|
101 | - private $_file; |
|
102 | - |
|
103 | - /** |
|
104 | - * PDF width, in points |
|
105 | - * |
|
106 | - * @var float |
|
107 | - */ |
|
108 | - private $_width; |
|
109 | - |
|
110 | - /** |
|
111 | - * PDF height, in points |
|
112 | - * |
|
113 | - * @var height |
|
114 | - */ |
|
115 | - private $_height; |
|
116 | - |
|
117 | - /** |
|
118 | - * Last fill colour used |
|
119 | - * |
|
120 | - * @var array |
|
121 | - */ |
|
122 | - private $_last_fill_color; |
|
123 | - |
|
124 | - /** |
|
125 | - * Last stroke colour used |
|
126 | - * |
|
127 | - * @var array |
|
128 | - */ |
|
129 | - private $_last_stroke_color; |
|
130 | - |
|
131 | - /** |
|
132 | - * Cache of image handles |
|
133 | - * |
|
134 | - * @var array |
|
135 | - */ |
|
136 | - private $_imgs; |
|
137 | - |
|
138 | - /** |
|
139 | - * Cache of font handles |
|
140 | - * |
|
141 | - * @var array |
|
142 | - */ |
|
143 | - private $_fonts; |
|
144 | - |
|
145 | - /** |
|
146 | - * List of objects (templates) to add to multiple pages |
|
147 | - * |
|
148 | - * @var array |
|
149 | - */ |
|
150 | - private $_objs; |
|
151 | - |
|
152 | - /** |
|
153 | - * Current page number |
|
154 | - * |
|
155 | - * @var int |
|
156 | - */ |
|
157 | - private $_page_number; |
|
158 | - |
|
159 | - /** |
|
160 | - * Total number of pages |
|
161 | - * |
|
162 | - * @var int |
|
163 | - */ |
|
164 | - private $_page_count; |
|
165 | - |
|
166 | - /** |
|
167 | - * Text to display on every page |
|
168 | - * |
|
169 | - * @var array |
|
170 | - */ |
|
171 | - private $_page_text; |
|
172 | - |
|
173 | - /** |
|
174 | - * Array of pages for accesing after rendering is initially complete |
|
175 | - * |
|
176 | - * @var array |
|
177 | - */ |
|
178 | - private $_pages; |
|
179 | - |
|
180 | - /** |
|
181 | - * Class constructor |
|
182 | - * |
|
183 | - * @param mixed $paper The size of paper to use either a string (see {@link CPDF_Adapter::$PAPER_SIZES}) or |
|
184 | - * an array(xmin,ymin,xmax,ymax) |
|
185 | - * @param string $orientation The orientation of the document (either 'landscape' or 'portrait') |
|
186 | - */ |
|
187 | - function __construct($paper = "letter", $orientation = "portrait") { |
|
72 | + /** |
|
73 | + * Fudge factor to adjust reported font heights |
|
74 | + * |
|
75 | + * CPDF reports larger font heights than PDFLib. This factor |
|
76 | + * adjusts the height reported by get_font_height(). |
|
77 | + * |
|
78 | + * @var float |
|
79 | + */ |
|
80 | + const FONT_HEIGHT_SCALE = 1.2; |
|
81 | + |
|
82 | + /** |
|
83 | + * Whether to create PDFs in memory or on disk |
|
84 | + * |
|
85 | + * @var bool |
|
86 | + */ |
|
87 | + static $IN_MEMORY = true; |
|
88 | + |
|
89 | + /** |
|
90 | + * Instance of PDFLib class |
|
91 | + * |
|
92 | + * @var PDFlib |
|
93 | + */ |
|
94 | + private $_pdf; |
|
95 | + |
|
96 | + /** |
|
97 | + * Name of temporary file used for PDFs created on disk |
|
98 | + * |
|
99 | + * @var string |
|
100 | + */ |
|
101 | + private $_file; |
|
102 | + |
|
103 | + /** |
|
104 | + * PDF width, in points |
|
105 | + * |
|
106 | + * @var float |
|
107 | + */ |
|
108 | + private $_width; |
|
109 | + |
|
110 | + /** |
|
111 | + * PDF height, in points |
|
112 | + * |
|
113 | + * @var height |
|
114 | + */ |
|
115 | + private $_height; |
|
116 | + |
|
117 | + /** |
|
118 | + * Last fill colour used |
|
119 | + * |
|
120 | + * @var array |
|
121 | + */ |
|
122 | + private $_last_fill_color; |
|
123 | + |
|
124 | + /** |
|
125 | + * Last stroke colour used |
|
126 | + * |
|
127 | + * @var array |
|
128 | + */ |
|
129 | + private $_last_stroke_color; |
|
130 | + |
|
131 | + /** |
|
132 | + * Cache of image handles |
|
133 | + * |
|
134 | + * @var array |
|
135 | + */ |
|
136 | + private $_imgs; |
|
137 | + |
|
138 | + /** |
|
139 | + * Cache of font handles |
|
140 | + * |
|
141 | + * @var array |
|
142 | + */ |
|
143 | + private $_fonts; |
|
144 | + |
|
145 | + /** |
|
146 | + * List of objects (templates) to add to multiple pages |
|
147 | + * |
|
148 | + * @var array |
|
149 | + */ |
|
150 | + private $_objs; |
|
151 | + |
|
152 | + /** |
|
153 | + * Current page number |
|
154 | + * |
|
155 | + * @var int |
|
156 | + */ |
|
157 | + private $_page_number; |
|
158 | + |
|
159 | + /** |
|
160 | + * Total number of pages |
|
161 | + * |
|
162 | + * @var int |
|
163 | + */ |
|
164 | + private $_page_count; |
|
165 | + |
|
166 | + /** |
|
167 | + * Text to display on every page |
|
168 | + * |
|
169 | + * @var array |
|
170 | + */ |
|
171 | + private $_page_text; |
|
172 | + |
|
173 | + /** |
|
174 | + * Array of pages for accesing after rendering is initially complete |
|
175 | + * |
|
176 | + * @var array |
|
177 | + */ |
|
178 | + private $_pages; |
|
179 | + |
|
180 | + /** |
|
181 | + * Class constructor |
|
182 | + * |
|
183 | + * @param mixed $paper The size of paper to use either a string (see {@link CPDF_Adapter::$PAPER_SIZES}) or |
|
184 | + * an array(xmin,ymin,xmax,ymax) |
|
185 | + * @param string $orientation The orientation of the document (either 'landscape' or 'portrait') |
|
186 | + */ |
|
187 | + function __construct($paper = "letter", $orientation = "portrait") { |
|
188 | 188 | if ( is_array($paper) ) |
189 | - $size = $paper; |
|
189 | + $size = $paper; |
|
190 | 190 | else if ( isset(self::$PAPER_SIZES[mb_strtolower($paper)]) ) |
191 | - $size = self::$PAPER_SIZES[mb_strtolower($paper)]; |
|
191 | + $size = self::$PAPER_SIZES[mb_strtolower($paper)]; |
|
192 | 192 | else |
193 | - $size = self::$PAPER_SIZES["letter"]; |
|
193 | + $size = self::$PAPER_SIZES["letter"]; |
|
194 | 194 | |
195 | 195 | if ( mb_strtolower($orientation) === "landscape" ) { |
196 | - $a = $size[3]; |
|
197 | - $size[3] = $size[2]; |
|
198 | - $size[2] = $a; |
|
196 | + $a = $size[3]; |
|
197 | + $size[3] = $size[2]; |
|
198 | + $size[2] = $a; |
|
199 | 199 | } |
200 | 200 | $this->_width = $size[2] - $size[0]; |
201 | 201 | $this->_height= $size[3] - $size[1]; |
202 | 202 | |
203 | 203 | $this->_pdf = new PDFLib(); |
204 | 204 | |
205 | - if ( defined("DOMPDF_PDFLIB_LICENSE") ) |
|
206 | - $this->_pdf->set_parameter( "license", DOMPDF_PDFLIB_LICENSE); |
|
205 | + if ( defined("DOMPDF_PDFLIB_LICENSE") ) |
|
206 | + $this->_pdf->set_parameter( "license", DOMPDF_PDFLIB_LICENSE); |
|
207 | 207 | |
208 | - $this->_pdf->set_parameter("textformat", "utf8"); |
|
208 | + $this->_pdf->set_parameter("textformat", "utf8"); |
|
209 | 209 | $this->_pdf->set_parameter("fontwarning", "false"); |
210 | 210 | |
211 | 211 | $this->_pdf->set_info("Creator", "DOMPDF Converter"); |
212 | 212 | |
213 | 213 | // Silence pedantic warnings about missing TZ settings |
214 | 214 | if ( function_exists("date_default_timezone_get") ) { |
215 | - $tz = @date_default_timezone_get(); |
|
216 | - date_default_timezone_set("UTC"); |
|
217 | - $this->_pdf->set_info("Date", date("Y-m-d")); |
|
218 | - date_default_timezone_set($tz); |
|
215 | + $tz = @date_default_timezone_get(); |
|
216 | + date_default_timezone_set("UTC"); |
|
217 | + $this->_pdf->set_info("Date", date("Y-m-d")); |
|
218 | + date_default_timezone_set($tz); |
|
219 | 219 | } else { |
220 | - $this->_pdf->set_info("Date", date("Y-m-d")); |
|
220 | + $this->_pdf->set_info("Date", date("Y-m-d")); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | if ( self::$IN_MEMORY ) |
224 | - $this->_pdf->begin_document("",""); |
|
224 | + $this->_pdf->begin_document("",""); |
|
225 | 225 | else { |
226 | - $this->_file = tempnam(DOMPDF_TEMP_DIR, "libdompdf_pdf_").'.pdf'; |
|
227 | - $this->_pdf->begin_document($this->_file,""); |
|
226 | + $this->_file = tempnam(DOMPDF_TEMP_DIR, "libdompdf_pdf_").'.pdf'; |
|
227 | + $this->_pdf->begin_document($this->_file,""); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | $this->_pdf->begin_page_ext($this->_width, $this->_height, ""); |
@@ -239,155 +239,155 @@ discard block |
||
239 | 239 | // Set up font paths |
240 | 240 | $families = Font_Metrics::get_font_families(); |
241 | 241 | foreach ($families as $family => $files) { |
242 | - foreach ($files as $style => $file) { |
|
242 | + foreach ($files as $style => $file) { |
|
243 | 243 | $face = basename($file); |
244 | 244 | |
245 | 245 | // Prefer ttfs to afms |
246 | 246 | if ( file_exists($file.".ttf") ) { |
247 | - $outline = "$file.ttf"; |
|
248 | - $afm = null; |
|
247 | + $outline = "$file.ttf"; |
|
248 | + $afm = null; |
|
249 | 249 | |
250 | 250 | } else if ( file_exists($file .".TTF") ) { |
251 | - $outline = "$file.TTF"; |
|
252 | - $afm = null; |
|
251 | + $outline = "$file.TTF"; |
|
252 | + $afm = null; |
|
253 | 253 | |
254 | 254 | } else if ( file_exists($file . ".pfb") ) { |
255 | - $outline = "$file.pfb"; |
|
255 | + $outline = "$file.pfb"; |
|
256 | 256 | |
257 | - if ( file_exists($file . ".afm") ) |
|
257 | + if ( file_exists($file . ".afm") ) |
|
258 | 258 | $afm = "$file.afm"; |
259 | 259 | |
260 | 260 | } else if ( file_exists($file . ".PFB") ) { |
261 | - $outline = "$file.PFB"; |
|
262 | - if ( file_exists($file . ".AFM") ) |
|
261 | + $outline = "$file.PFB"; |
|
262 | + if ( file_exists($file . ".AFM") ) |
|
263 | 263 | $afm = "$file.AFM"; |
264 | 264 | } else |
265 | - continue; |
|
265 | + continue; |
|
266 | 266 | |
267 | 267 | $this->_pdf->set_parameter("FontOutline", "\{$face\}=\{$outline\}"); |
268 | 268 | if ( !is_null($afm) ) |
269 | - $this->_pdf->set_parameter("FontAFM", "\{$face\}=\{$afm\}"); |
|
270 | - } |
|
269 | + $this->_pdf->set_parameter("FontAFM", "\{$face\}=\{$afm\}"); |
|
270 | + } |
|
271 | + } |
|
271 | 272 | } |
272 | - } |
|
273 | 273 | |
274 | - /** |
|
275 | - * Close the pdf |
|
276 | - */ |
|
277 | - protected function _close() { |
|
274 | + /** |
|
275 | + * Close the pdf |
|
276 | + */ |
|
277 | + protected function _close() { |
|
278 | 278 | $this->_place_objects(); |
279 | 279 | |
280 | 280 | // Close all pages |
281 | 281 | $this->_pdf->suspend_page(""); |
282 | 282 | for ($p = 1; $p <= $this->_page_count; $p++) { |
283 | - $this->_pdf->resume_page("pagenumber=$p"); |
|
284 | - $this->_pdf->end_page_ext(""); |
|
283 | + $this->_pdf->resume_page("pagenumber=$p"); |
|
284 | + $this->_pdf->end_page_ext(""); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | $this->_pdf->end_document(""); |
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - /** |
|
292 | - * Returns the PDFLib instance |
|
293 | - * |
|
294 | - * @return PDFLib |
|
295 | - */ |
|
296 | - function get_pdflib() { return $this->_pdf; } |
|
297 | - |
|
298 | - /** |
|
299 | - * Add meta information to the PDF |
|
300 | - * |
|
301 | - * @param string $label label of the value (Creator, Producter, etc.) |
|
302 | - * @param string $value the text to set |
|
303 | - */ |
|
304 | - function add_info($label, $value) { |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + /** |
|
292 | + * Returns the PDFLib instance |
|
293 | + * |
|
294 | + * @return PDFLib |
|
295 | + */ |
|
296 | + function get_pdflib() { return $this->_pdf; } |
|
297 | + |
|
298 | + /** |
|
299 | + * Add meta information to the PDF |
|
300 | + * |
|
301 | + * @param string $label label of the value (Creator, Producter, etc.) |
|
302 | + * @param string $value the text to set |
|
303 | + */ |
|
304 | + function add_info($label, $value) { |
|
305 | 305 | $this->_pdf->set_info($label, $value); |
306 | - } |
|
306 | + } |
|
307 | 307 | |
308 | - /** |
|
309 | - * Opens a new 'object' (template in PDFLib-speak) |
|
310 | - * |
|
311 | - * While an object is open, all drawing actions are recorded to the |
|
312 | - * object instead of being drawn on the current page. Objects can |
|
313 | - * be added later to a specific page or to several pages. |
|
314 | - * |
|
315 | - * The return value is an integer ID for the new object. |
|
316 | - * |
|
317 | - * @see PDFLib_Adapter::close_object() |
|
318 | - * @see PDFLib_Adapter::add_object() |
|
319 | - * |
|
320 | - * @return int |
|
321 | - */ |
|
322 | - function open_object() { |
|
308 | + /** |
|
309 | + * Opens a new 'object' (template in PDFLib-speak) |
|
310 | + * |
|
311 | + * While an object is open, all drawing actions are recorded to the |
|
312 | + * object instead of being drawn on the current page. Objects can |
|
313 | + * be added later to a specific page or to several pages. |
|
314 | + * |
|
315 | + * The return value is an integer ID for the new object. |
|
316 | + * |
|
317 | + * @see PDFLib_Adapter::close_object() |
|
318 | + * @see PDFLib_Adapter::add_object() |
|
319 | + * |
|
320 | + * @return int |
|
321 | + */ |
|
322 | + function open_object() { |
|
323 | 323 | $this->_pdf->suspend_page(""); |
324 | 324 | $ret = $this->_pdf->begin_template($this->_width, $this->_height); |
325 | 325 | $this->_pdf->save(); |
326 | 326 | $this->_objs[$ret] = array("start_page" => $this->_page_number); |
327 | 327 | return $ret; |
328 | - } |
|
329 | - |
|
330 | - /** |
|
331 | - * Reopen an existing object (NOT IMPLEMENTED) |
|
332 | - * |
|
333 | - * PDFLib does not seem to support reopening templates. |
|
334 | - * |
|
335 | - * @param int $object the ID of a previously opened object |
|
336 | - */ |
|
337 | - function reopen_object($object) { |
|
328 | + } |
|
329 | + |
|
330 | + /** |
|
331 | + * Reopen an existing object (NOT IMPLEMENTED) |
|
332 | + * |
|
333 | + * PDFLib does not seem to support reopening templates. |
|
334 | + * |
|
335 | + * @param int $object the ID of a previously opened object |
|
336 | + */ |
|
337 | + function reopen_object($object) { |
|
338 | 338 | throw new DOMPDF_Exception("PDFLib does not support reopening objects."); |
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * Close the current template |
|
343 | - * |
|
344 | - * @see PDFLib_Adapter::open_object() |
|
345 | - */ |
|
346 | - function close_object() { |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * Close the current template |
|
343 | + * |
|
344 | + * @see PDFLib_Adapter::open_object() |
|
345 | + */ |
|
346 | + function close_object() { |
|
347 | 347 | $this->_pdf->restore(); |
348 | 348 | $this->_pdf->end_template(); |
349 | 349 | $this->_pdf->resume_page("pagenumber=".$this->_page_number); |
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * Adds the specified object to the document |
|
354 | - * |
|
355 | - * $where can be one of: |
|
356 | - * - 'add' add to current page only |
|
357 | - * - 'all' add to every page from the current one onwards |
|
358 | - * - 'odd' add to all odd numbered pages from now on |
|
359 | - * - 'even' add to all even numbered pages from now on |
|
360 | - * - 'next' add the object to the next page only |
|
361 | - * - 'nextodd' add to all odd numbered pages from the next one |
|
362 | - * - 'nexteven' add to all even numbered pages from the next one |
|
363 | - * |
|
364 | - * @param int $object the object handle returned by open_object() |
|
365 | - * @param string $where |
|
366 | - */ |
|
367 | - function add_object($object, $where = 'all') { |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * Adds the specified object to the document |
|
354 | + * |
|
355 | + * $where can be one of: |
|
356 | + * - 'add' add to current page only |
|
357 | + * - 'all' add to every page from the current one onwards |
|
358 | + * - 'odd' add to all odd numbered pages from now on |
|
359 | + * - 'even' add to all even numbered pages from now on |
|
360 | + * - 'next' add the object to the next page only |
|
361 | + * - 'nextodd' add to all odd numbered pages from the next one |
|
362 | + * - 'nexteven' add to all even numbered pages from the next one |
|
363 | + * |
|
364 | + * @param int $object the object handle returned by open_object() |
|
365 | + * @param string $where |
|
366 | + */ |
|
367 | + function add_object($object, $where = 'all') { |
|
368 | 368 | |
369 | 369 | if ( mb_strpos($where, "next") !== false ) { |
370 | - $this->_objs[$object]["start_page"]++; |
|
371 | - $where = str_replace("next", "", $where); |
|
372 | - if ( $where == "" ) |
|
370 | + $this->_objs[$object]["start_page"]++; |
|
371 | + $where = str_replace("next", "", $where); |
|
372 | + if ( $where == "" ) |
|
373 | 373 | $where = "add"; |
374 | 374 | } |
375 | 375 | |
376 | 376 | $this->_objs[$object]["where"] = $where; |
377 | - } |
|
378 | - |
|
379 | - /** |
|
380 | - * Stops the specified template from appearing in the document. |
|
381 | - * |
|
382 | - * The object will stop being displayed on the page following the |
|
383 | - * current one. |
|
384 | - * |
|
385 | - * @param int $object |
|
386 | - */ |
|
387 | - function stop_object($object) { |
|
377 | + } |
|
378 | + |
|
379 | + /** |
|
380 | + * Stops the specified template from appearing in the document. |
|
381 | + * |
|
382 | + * The object will stop being displayed on the page following the |
|
383 | + * current one. |
|
384 | + * |
|
385 | + * @param int $object |
|
386 | + */ |
|
387 | + function stop_object($object) { |
|
388 | 388 | |
389 | 389 | if ( !isset($this->_objs[$object]) ) |
390 | - return; |
|
390 | + return; |
|
391 | 391 | |
392 | 392 | $start = $this->_objs[$object]["start_page"]; |
393 | 393 | $where = $this->_objs[$object]["where"]; |
@@ -397,74 +397,74 @@ discard block |
||
397 | 397 | (($this->_page_number % 2 == 0 && $where === "even") || |
398 | 398 | ($this->_page_number % 2 == 1 && $where === "odd") || |
399 | 399 | ($where === "all")) ) |
400 | - $this->_pdf->fit_image($object,0,0,""); |
|
400 | + $this->_pdf->fit_image($object,0,0,""); |
|
401 | 401 | |
402 | 402 | unset($this->_objs[$object]); |
403 | - } |
|
403 | + } |
|
404 | 404 | |
405 | - /** |
|
406 | - * Add all active objects to the current page |
|
407 | - */ |
|
408 | - protected function _place_objects() { |
|
405 | + /** |
|
406 | + * Add all active objects to the current page |
|
407 | + */ |
|
408 | + protected function _place_objects() { |
|
409 | 409 | |
410 | 410 | foreach ( $this->_objs as $obj => $props ) { |
411 | - $start = $props["start_page"]; |
|
412 | - $where = $props["where"]; |
|
411 | + $start = $props["start_page"]; |
|
412 | + $where = $props["where"]; |
|
413 | 413 | |
414 | - // Place the object on this page if required |
|
415 | - if ( $this->_page_number >= $start && |
|
414 | + // Place the object on this page if required |
|
415 | + if ( $this->_page_number >= $start && |
|
416 | 416 | (($this->_page_number % 2 == 0 && $where === "even") || |
417 | 417 | ($this->_page_number % 2 == 1 && $where === "odd") || |
418 | 418 | ($where === "all")) ) { |
419 | 419 | $this->_pdf->fit_image($obj,0,0,""); |
420 | - } |
|
420 | + } |
|
421 | 421 | } |
422 | 422 | |
423 | - } |
|
423 | + } |
|
424 | 424 | |
425 | - function get_width() { return $this->_width; } |
|
425 | + function get_width() { return $this->_width; } |
|
426 | 426 | |
427 | - function get_height() { return $this->_height; } |
|
427 | + function get_height() { return $this->_height; } |
|
428 | 428 | |
429 | - function get_page_number() { return $this->_page_number; } |
|
429 | + function get_page_number() { return $this->_page_number; } |
|
430 | 430 | |
431 | - function get_page_count() { return $this->_page_count; } |
|
431 | + function get_page_count() { return $this->_page_count; } |
|
432 | 432 | |
433 | - function set_page_number($num) { $this->_page_number = (int)$num; } |
|
433 | + function set_page_number($num) { $this->_page_number = (int)$num; } |
|
434 | 434 | |
435 | - function set_page_count($count) { $this->_page_count = (int)$count; } |
|
435 | + function set_page_count($count) { $this->_page_count = (int)$count; } |
|
436 | 436 | |
437 | 437 | |
438 | - /** |
|
439 | - * Sets the line style |
|
440 | - * |
|
441 | - * @param float width |
|
442 | - * @param string corner |
|
443 | - * @param string join |
|
444 | - * @param array dash |
|
445 | - */ |
|
446 | - protected function _set_line_style($width, $cap, $join, $dash) { |
|
438 | + /** |
|
439 | + * Sets the line style |
|
440 | + * |
|
441 | + * @param float width |
|
442 | + * @param string corner |
|
443 | + * @param string join |
|
444 | + * @param array dash |
|
445 | + */ |
|
446 | + protected function _set_line_style($width, $cap, $join, $dash) { |
|
447 | 447 | |
448 | 448 | if ( count($dash) == 1 ) |
449 | - $dash[] = $dash[0]; |
|
449 | + $dash[] = $dash[0]; |
|
450 | 450 | |
451 | 451 | if ( count($dash) > 1 ) |
452 | - $this->_pdf->setdashpattern("dasharray={" . join(" ", $dash) . "}"); |
|
452 | + $this->_pdf->setdashpattern("dasharray={" . join(" ", $dash) . "}"); |
|
453 | 453 | else |
454 | - $this->_pdf->setdash(0,0); |
|
454 | + $this->_pdf->setdash(0,0); |
|
455 | 455 | |
456 | 456 | switch ( $join ) { |
457 | 457 | case "miter": |
458 | 458 | $this->_pdf->setlinejoin(0); |
459 | - break; |
|
459 | + break; |
|
460 | 460 | |
461 | 461 | case "round": |
462 | 462 | $this->_pdf->setlinejoin(1); |
463 | - break; |
|
463 | + break; |
|
464 | 464 | |
465 | 465 | case "bevel": |
466 | 466 | $this->_pdf->setlinejoin(2); |
467 | - break; |
|
467 | + break; |
|
468 | 468 | |
469 | 469 | default: |
470 | 470 | break; |
@@ -473,15 +473,15 @@ discard block |
||
473 | 473 | switch ( $cap ) { |
474 | 474 | case "butt": |
475 | 475 | $this->_pdf->setlinecap(0); |
476 | - break; |
|
476 | + break; |
|
477 | 477 | |
478 | 478 | case "round": |
479 | 479 | $this->_pdf->setlinecap(1); |
480 | - break; |
|
480 | + break; |
|
481 | 481 | |
482 | 482 | case "square": |
483 | 483 | $this->_pdf->setlinecap(2); |
484 | - break; |
|
484 | + break; |
|
485 | 485 | |
486 | 486 | default: |
487 | 487 | break; |
@@ -489,69 +489,69 @@ discard block |
||
489 | 489 | |
490 | 490 | $this->_pdf->setlinewidth($width); |
491 | 491 | |
492 | - } |
|
492 | + } |
|
493 | 493 | |
494 | - /** |
|
495 | - * Sets the line color |
|
496 | - * |
|
497 | - * @param array $color array(r,g,b) |
|
498 | - */ |
|
499 | - protected function _set_stroke_color($color) { |
|
494 | + /** |
|
495 | + * Sets the line color |
|
496 | + * |
|
497 | + * @param array $color array(r,g,b) |
|
498 | + */ |
|
499 | + protected function _set_stroke_color($color) { |
|
500 | 500 | if($this->_last_stroke_color == $color) |
501 | - return; |
|
501 | + return; |
|
502 | 502 | |
503 | 503 | $this->_last_stroke_color = $color; |
504 | 504 | |
505 | 505 | list($r,$g,$b) = $color; |
506 | 506 | $this->_pdf->setcolor("stroke", "rgb", $r, $g, $b, 0); |
507 | - } |
|
508 | - |
|
509 | - /** |
|
510 | - * Sets the fill color |
|
511 | - * |
|
512 | - * @param array $color array(r,g,b) |
|
513 | - */ |
|
514 | - protected function _set_fill_color($color) { |
|
507 | + } |
|
508 | + |
|
509 | + /** |
|
510 | + * Sets the fill color |
|
511 | + * |
|
512 | + * @param array $color array(r,g,b) |
|
513 | + */ |
|
514 | + protected function _set_fill_color($color) { |
|
515 | 515 | if($this->_last_fill_color == $color) |
516 | - return; |
|
516 | + return; |
|
517 | 517 | |
518 | 518 | $this->_last_fill_color = $color; |
519 | 519 | |
520 | 520 | list($r,$g,$b) = $color; |
521 | 521 | $this->_pdf->setcolor("fill", "rgb", $r, $g, $b, 0); |
522 | - } |
|
522 | + } |
|
523 | 523 | |
524 | - /** |
|
525 | - * Loads a specific font and stores the corresponding descriptor. |
|
526 | - * |
|
527 | - * @param string $font |
|
528 | - * @return int the font descriptor for the font |
|
529 | - */ |
|
530 | - protected function _load_font($font, $encoding = null, $options = "") { |
|
524 | + /** |
|
525 | + * Loads a specific font and stores the corresponding descriptor. |
|
526 | + * |
|
527 | + * @param string $font |
|
528 | + * @return int the font descriptor for the font |
|
529 | + */ |
|
530 | + protected function _load_font($font, $encoding = null, $options = "") { |
|
531 | 531 | |
532 | 532 | // Check if the font is a native PDF font |
533 | 533 | // Embed non-native fonts |
534 | 534 | $native_fonts = array("courier", "courier-bold", "courier-oblique", "courier-boldoblique", |
535 | - "helvetica", "helvetica-bold", "helvetica-oblique", "helvetica-boldoblique", |
|
536 | - "times-roman", "times-bold", "times-italic", "times-bolditalic", |
|
537 | - "symbol", "zapfdinbats"); |
|
535 | + "helvetica", "helvetica-bold", "helvetica-oblique", "helvetica-boldoblique", |
|
536 | + "times-roman", "times-bold", "times-italic", "times-bolditalic", |
|
537 | + "symbol", "zapfdinbats"); |
|
538 | 538 | |
539 | 539 | $test = strtolower(basename($font)); |
540 | 540 | if ( in_array($test, $native_fonts) ) { |
541 | - $font = basename($font); |
|
541 | + $font = basename($font); |
|
542 | 542 | |
543 | 543 | } else { |
544 | - // Embed non-native fonts |
|
545 | - $options .= " embedding=true"; |
|
544 | + // Embed non-native fonts |
|
545 | + $options .= " embedding=true"; |
|
546 | 546 | } |
547 | 547 | |
548 | 548 | if ( is_null($encoding) ) { |
549 | 549 | |
550 | - // Unicode encoding is only available for the commerical |
|
551 | - // version of PDFlib and not PDFlib-Lite |
|
552 | - if ( defined("DOMPDF_PDFLIB_LICENSE") ) |
|
550 | + // Unicode encoding is only available for the commerical |
|
551 | + // version of PDFlib and not PDFlib-Lite |
|
552 | + if ( defined("DOMPDF_PDFLIB_LICENSE") ) |
|
553 | 553 | $encoding = "unicode"; |
554 | - else |
|
554 | + else |
|
555 | 555 | $encoding = "auto"; |
556 | 556 | |
557 | 557 | } |
@@ -559,28 +559,28 @@ discard block |
||
559 | 559 | $key = $font .":". $encoding .":". $options; |
560 | 560 | |
561 | 561 | if ( isset($this->_fonts[$key]) ) |
562 | - return $this->_fonts[$key]; |
|
562 | + return $this->_fonts[$key]; |
|
563 | 563 | |
564 | 564 | else { |
565 | 565 | |
566 | - $this->_fonts[$key] = $this->_pdf->load_font($font, $encoding, $options); |
|
567 | - return $this->_fonts[$key]; |
|
566 | + $this->_fonts[$key] = $this->_pdf->load_font($font, $encoding, $options); |
|
567 | + return $this->_fonts[$key]; |
|
568 | 568 | |
569 | 569 | } |
570 | 570 | |
571 | - } |
|
571 | + } |
|
572 | 572 | |
573 | - /** |
|
574 | - * Remaps y coords from 4th to 1st quadrant |
|
575 | - * |
|
576 | - * @param float $y |
|
577 | - * @return float |
|
578 | - */ |
|
579 | - protected function y($y) { return $this->_height - $y; } |
|
573 | + /** |
|
574 | + * Remaps y coords from 4th to 1st quadrant |
|
575 | + * |
|
576 | + * @param float $y |
|
577 | + * @return float |
|
578 | + */ |
|
579 | + protected function y($y) { return $this->_height - $y; } |
|
580 | 580 | |
581 | - //........................................................................ |
|
581 | + //........................................................................ |
|
582 | 582 | |
583 | - function line($x1, $y1, $x2, $y2, $color, $width, $style = null) { |
|
583 | + function line($x1, $y1, $x2, $y2, $color, $width, $style = null) { |
|
584 | 584 | $this->_set_line_style($width, "butt", "", $style); |
585 | 585 | $this->_set_stroke_color($color); |
586 | 586 | |
@@ -590,11 +590,11 @@ discard block |
||
590 | 590 | $this->_pdf->moveto($x1,$y1); |
591 | 591 | $this->_pdf->lineto($x2, $y2); |
592 | 592 | $this->_pdf->stroke(); |
593 | - } |
|
593 | + } |
|
594 | 594 | |
595 | - //........................................................................ |
|
595 | + //........................................................................ |
|
596 | 596 | |
597 | - function rectangle($x1, $y1, $w, $h, $color, $width, $style = null) { |
|
597 | + function rectangle($x1, $y1, $w, $h, $color, $width, $style = null) { |
|
598 | 598 | $this->_set_stroke_color($color); |
599 | 599 | $this->_set_line_style($width, "square", "miter", $style); |
600 | 600 | |
@@ -602,93 +602,93 @@ discard block |
||
602 | 602 | |
603 | 603 | $this->_pdf->rect($x1, $y1, $w, $h); |
604 | 604 | $this->_pdf->stroke(); |
605 | - } |
|
605 | + } |
|
606 | 606 | |
607 | - //........................................................................ |
|
607 | + //........................................................................ |
|
608 | 608 | |
609 | - function filled_rectangle($x1, $y1, $w, $h, $color) { |
|
609 | + function filled_rectangle($x1, $y1, $w, $h, $color) { |
|
610 | 610 | $this->_set_fill_color($color); |
611 | 611 | |
612 | 612 | $y1 = $this->y($y1) - $h; |
613 | 613 | |
614 | 614 | $this->_pdf->rect($x1, $y1, $w, $h); |
615 | 615 | $this->_pdf->fill(); |
616 | - } |
|
616 | + } |
|
617 | 617 | |
618 | - //........................................................................ |
|
618 | + //........................................................................ |
|
619 | 619 | |
620 | - function polygon($points, $color, $width = null, $style = null, $fill = false) { |
|
620 | + function polygon($points, $color, $width = null, $style = null, $fill = false) { |
|
621 | 621 | |
622 | 622 | $this->_set_fill_color($color); |
623 | 623 | $this->_set_stroke_color($color); |
624 | 624 | |
625 | 625 | if ( !$fill && isset($width) ) |
626 | - $this->_set_line_style($width, "square", "miter", $style); |
|
626 | + $this->_set_line_style($width, "square", "miter", $style); |
|
627 | 627 | |
628 | 628 | $y = $this->y(array_pop($points)); |
629 | 629 | $x = array_pop($points); |
630 | 630 | $this->_pdf->moveto($x,$y); |
631 | 631 | |
632 | 632 | while (count($points) > 1) { |
633 | - $y = $this->y(array_pop($points)); |
|
634 | - $x = array_pop($points); |
|
635 | - $this->_pdf->lineto($x,$y); |
|
633 | + $y = $this->y(array_pop($points)); |
|
634 | + $x = array_pop($points); |
|
635 | + $this->_pdf->lineto($x,$y); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | if ( $fill ) |
639 | - $this->_pdf->fill(); |
|
639 | + $this->_pdf->fill(); |
|
640 | 640 | else |
641 | - $this->_pdf->closepath_stroke(); |
|
642 | - } |
|
641 | + $this->_pdf->closepath_stroke(); |
|
642 | + } |
|
643 | 643 | |
644 | - //........................................................................ |
|
644 | + //........................................................................ |
|
645 | 645 | |
646 | - function circle($x, $y, $r, $color, $width = null, $style = null, $fill = false) { |
|
646 | + function circle($x, $y, $r, $color, $width = null, $style = null, $fill = false) { |
|
647 | 647 | |
648 | 648 | $this->_set_fill_color($color); |
649 | 649 | $this->_set_stroke_color($color); |
650 | 650 | |
651 | 651 | if ( !$fill && isset($width) ) |
652 | - $this->_set_line_style($width, "round", "round", $style); |
|
652 | + $this->_set_line_style($width, "round", "round", $style); |
|
653 | 653 | |
654 | 654 | $y = $this->y($y); |
655 | 655 | |
656 | 656 | $this->_pdf->circle($x, $y, $r); |
657 | 657 | |
658 | 658 | if ( $fill ) |
659 | - $this->_pdf->fill(); |
|
659 | + $this->_pdf->fill(); |
|
660 | 660 | else |
661 | - $this->_pdf->stroke(); |
|
661 | + $this->_pdf->stroke(); |
|
662 | 662 | |
663 | - } |
|
663 | + } |
|
664 | 664 | |
665 | - //........................................................................ |
|
665 | + //........................................................................ |
|
666 | 666 | |
667 | - function image($img_url, $img_type, $x, $y, $w, $h) { |
|
667 | + function image($img_url, $img_type, $x, $y, $w, $h) { |
|
668 | 668 | $w = (int)$w; |
669 | 669 | $h = (int)$h; |
670 | 670 | |
671 | 671 | $img_type = strtolower($img_type); |
672 | 672 | |
673 | 673 | if ( $img_type === "jpg" ) |
674 | - $img_type = "jpeg"; |
|
674 | + $img_type = "jpeg"; |
|
675 | 675 | |
676 | 676 | if ( isset($this->_imgs[$img_url]) ) |
677 | - $img = $this->_imgs[$img_url]; |
|
677 | + $img = $this->_imgs[$img_url]; |
|
678 | 678 | |
679 | 679 | else { |
680 | 680 | |
681 | - $img = $this->_imgs[$img_url] = $this->_pdf->load_image($img_type, $img_url, ""); |
|
681 | + $img = $this->_imgs[$img_url] = $this->_pdf->load_image($img_type, $img_url, ""); |
|
682 | 682 | } |
683 | 683 | |
684 | 684 | $y = $this->y($y) - $h; |
685 | 685 | $this->_pdf->fit_image($img, $x, $y, 'boxsize={'. "$w $h" .'} fitmethod=entire'); |
686 | 686 | |
687 | - } |
|
687 | + } |
|
688 | 688 | |
689 | - //........................................................................ |
|
689 | + //........................................................................ |
|
690 | 690 | |
691 | - function text($x, $y, $text, $font, $size, $color = array(0,0,0), $adjust = 0, $angle = 0) { |
|
691 | + function text($x, $y, $text, $font, $size, $color = array(0,0,0), $adjust = 0, $angle = 0) { |
|
692 | 692 | $fh = $this->_load_font($font); |
693 | 693 | |
694 | 694 | $this->_pdf->setfont($fh, $size); |
@@ -701,72 +701,72 @@ discard block |
||
701 | 701 | |
702 | 702 | $this->_pdf->fit_textline($text, $x, $y, "rotate=$angle wordspacing=$adjust"); |
703 | 703 | |
704 | - } |
|
704 | + } |
|
705 | 705 | |
706 | - //........................................................................ |
|
706 | + //........................................................................ |
|
707 | 707 | |
708 | - function javascript($code) { |
|
708 | + function javascript($code) { |
|
709 | 709 | // Not implemented |
710 | - } |
|
710 | + } |
|
711 | 711 | |
712 | - //........................................................................ |
|
712 | + //........................................................................ |
|
713 | 713 | |
714 | - /** |
|
715 | - * Add a named destination (similar to <a name="foo">...</a> in html) |
|
716 | - * |
|
717 | - * @param string $anchorname The name of the named destination |
|
718 | - */ |
|
719 | - function add_named_dest($anchorname) { |
|
714 | + /** |
|
715 | + * Add a named destination (similar to <a name="foo">...</a> in html) |
|
716 | + * |
|
717 | + * @param string $anchorname The name of the named destination |
|
718 | + */ |
|
719 | + function add_named_dest($anchorname) { |
|
720 | 720 | $this->_pdf->add_nameddest($anchorname,""); |
721 | - } |
|
721 | + } |
|
722 | 722 | |
723 | - //........................................................................ |
|
723 | + //........................................................................ |
|
724 | 724 | |
725 | - /** |
|
726 | - * Add a link to the pdf |
|
727 | - * |
|
728 | - * @param string $url The url to link to |
|
729 | - * @param float $x The x position of the link |
|
730 | - * @param float $y The y position of the link |
|
731 | - * @param float $width The width of the link |
|
732 | - * @param float $height The height of the link |
|
733 | - */ |
|
734 | - function add_link($url, $x, $y, $width, $height) { |
|
725 | + /** |
|
726 | + * Add a link to the pdf |
|
727 | + * |
|
728 | + * @param string $url The url to link to |
|
729 | + * @param float $x The x position of the link |
|
730 | + * @param float $y The y position of the link |
|
731 | + * @param float $width The width of the link |
|
732 | + * @param float $height The height of the link |
|
733 | + */ |
|
734 | + function add_link($url, $x, $y, $width, $height) { |
|
735 | 735 | |
736 | 736 | $y = $this->y($y) - $height; |
737 | 737 | if ( strpos($url, '#') === 0 ) { |
738 | - // Local link |
|
739 | - $name = substr($url,1); |
|
740 | - if ( $name ) |
|
738 | + // Local link |
|
739 | + $name = substr($url,1); |
|
740 | + if ( $name ) |
|
741 | 741 | $this->_pdf->create_annotation($x, $y, $x + $width, $y + $height, 'Link', "contents={$url} destname=". substr($url,1) . " linewidth=0"); |
742 | 742 | } else { |
743 | 743 | |
744 | - list($proto, $host, $path, $file) = explode_url($url); |
|
744 | + list($proto, $host, $path, $file) = explode_url($url); |
|
745 | 745 | |
746 | - if ( $proto == "" || $proto === "file://" ) |
|
746 | + if ( $proto == "" || $proto === "file://" ) |
|
747 | 747 | return; // Local links are not allowed |
748 | - $url = build_url($proto, $host, $path, $file); |
|
749 | - $url = '{' . rawurldecode($url) . '}'; |
|
748 | + $url = build_url($proto, $host, $path, $file); |
|
749 | + $url = '{' . rawurldecode($url) . '}'; |
|
750 | 750 | |
751 | - $action = $this->_pdf->create_action("URI", "url=" . $url); |
|
752 | - $this->_pdf->create_annotation($x, $y, $x + $width, $y + $height, 'Link', "contents={$url} action={activate=$action} linewidth=0"); |
|
751 | + $action = $this->_pdf->create_action("URI", "url=" . $url); |
|
752 | + $this->_pdf->create_annotation($x, $y, $x + $width, $y + $height, 'Link', "contents={$url} action={activate=$action} linewidth=0"); |
|
753 | + } |
|
753 | 754 | } |
754 | - } |
|
755 | 755 | |
756 | - //........................................................................ |
|
756 | + //........................................................................ |
|
757 | 757 | |
758 | - function get_text_width($text, $font, $size, $spacing = 0) { |
|
758 | + function get_text_width($text, $font, $size, $spacing = 0) { |
|
759 | 759 | $fh = $this->_load_font($font); |
760 | 760 | |
761 | 761 | // Determine the additional width due to extra spacing |
762 | 762 | $num_spaces = mb_substr_count($text," "); |
763 | 763 | $delta = $spacing * $num_spaces; |
764 | 764 | return $this->_pdf->stringwidth($text, $fh, $size) + $delta; |
765 | - } |
|
765 | + } |
|
766 | 766 | |
767 | - //........................................................................ |
|
767 | + //........................................................................ |
|
768 | 768 | |
769 | - function get_font_height($font, $size) { |
|
769 | + function get_font_height($font, $size) { |
|
770 | 770 | |
771 | 771 | $fh = $this->_load_font($font); |
772 | 772 | |
@@ -777,54 +777,54 @@ discard block |
||
777 | 777 | |
778 | 778 | // $desc is usually < 0, |
779 | 779 | return self::FONT_HEIGHT_SCALE * $size * ($asc - $desc); |
780 | - } |
|
781 | - |
|
782 | - //........................................................................ |
|
783 | - |
|
784 | - /** |
|
785 | - * Writes text at the specified x and y coordinates on every page |
|
786 | - * |
|
787 | - * The strings '{PAGE_NUM}' and '{PAGE_COUNT}' are automatically replaced |
|
788 | - * with their current values. |
|
789 | - * |
|
790 | - * See {@link Style::munge_colour()} for the format of the colour array. |
|
791 | - * |
|
792 | - * @param float $x |
|
793 | - * @param float $y |
|
794 | - * @param string $text the text to write |
|
795 | - * @param string $font the font file to use |
|
796 | - * @param float $size the font size, in points |
|
797 | - * @param array $color |
|
798 | - * @param float $adjust word spacing adjustment |
|
799 | - * @param float $angle angle to write the text at, measured CW starting from the x-axis |
|
800 | - */ |
|
801 | - function page_text($x, $y, $text, $font, $size, $color = array(0,0,0), |
|
802 | - $adjust = 0, $angle = 0, $blend = "Normal", $opacity = 1.0) { |
|
780 | + } |
|
781 | + |
|
782 | + //........................................................................ |
|
783 | + |
|
784 | + /** |
|
785 | + * Writes text at the specified x and y coordinates on every page |
|
786 | + * |
|
787 | + * The strings '{PAGE_NUM}' and '{PAGE_COUNT}' are automatically replaced |
|
788 | + * with their current values. |
|
789 | + * |
|
790 | + * See {@link Style::munge_colour()} for the format of the colour array. |
|
791 | + * |
|
792 | + * @param float $x |
|
793 | + * @param float $y |
|
794 | + * @param string $text the text to write |
|
795 | + * @param string $font the font file to use |
|
796 | + * @param float $size the font size, in points |
|
797 | + * @param array $color |
|
798 | + * @param float $adjust word spacing adjustment |
|
799 | + * @param float $angle angle to write the text at, measured CW starting from the x-axis |
|
800 | + */ |
|
801 | + function page_text($x, $y, $text, $font, $size, $color = array(0,0,0), |
|
802 | + $adjust = 0, $angle = 0, $blend = "Normal", $opacity = 1.0) { |
|
803 | 803 | $_t = "text"; |
804 | 804 | $this->_page_text[] = compact("_t", "x", "y", "text", "font", "size", "color", "adjust", "angle"); |
805 | - } |
|
806 | - |
|
807 | - //........................................................................ |
|
808 | - |
|
809 | - /** |
|
810 | - * Processes a script on every page |
|
811 | - * |
|
812 | - * The variables $pdf, $PAGE_NUM, and $PAGE_COUNT are available. |
|
813 | - * |
|
814 | - * This function can be used to add page numbers to all pages |
|
815 | - * after the first one, for example. |
|
816 | - * |
|
817 | - * @param string $code the script code |
|
818 | - * @param string $type the language type for script |
|
819 | - */ |
|
820 | - function page_script($code, $type = "text/php") { |
|
805 | + } |
|
806 | + |
|
807 | + //........................................................................ |
|
808 | + |
|
809 | + /** |
|
810 | + * Processes a script on every page |
|
811 | + * |
|
812 | + * The variables $pdf, $PAGE_NUM, and $PAGE_COUNT are available. |
|
813 | + * |
|
814 | + * This function can be used to add page numbers to all pages |
|
815 | + * after the first one, for example. |
|
816 | + * |
|
817 | + * @param string $code the script code |
|
818 | + * @param string $type the language type for script |
|
819 | + */ |
|
820 | + function page_script($code, $type = "text/php") { |
|
821 | 821 | $_t = "script"; |
822 | 822 | $this->_page_text[] = compact("_t", "code", "type"); |
823 | - } |
|
823 | + } |
|
824 | 824 | |
825 | - //........................................................................ |
|
825 | + //........................................................................ |
|
826 | 826 | |
827 | - function new_page() { |
|
827 | + function new_page() { |
|
828 | 828 | |
829 | 829 | // Add objects to the current page |
830 | 830 | $this->_place_objects(); |
@@ -833,69 +833,69 @@ discard block |
||
833 | 833 | $this->_pdf->begin_page_ext($this->_width, $this->_height, ""); |
834 | 834 | $this->_page_number = ++$this->_page_count; |
835 | 835 | |
836 | - } |
|
836 | + } |
|
837 | 837 | |
838 | - //........................................................................ |
|
838 | + //........................................................................ |
|
839 | 839 | |
840 | - /** |
|
841 | - * Add text to each page after rendering is complete |
|
842 | - */ |
|
843 | - protected function _add_page_text() { |
|
840 | + /** |
|
841 | + * Add text to each page after rendering is complete |
|
842 | + */ |
|
843 | + protected function _add_page_text() { |
|
844 | 844 | |
845 | 845 | if ( !count($this->_page_text) ) |
846 | - return; |
|
846 | + return; |
|
847 | 847 | |
848 | 848 | $this->_pdf->suspend_page(""); |
849 | 849 | |
850 | 850 | for ($p = 1; $p <= $this->_page_count; $p++) { |
851 | - $this->_pdf->resume_page("pagenumber=$p"); |
|
851 | + $this->_pdf->resume_page("pagenumber=$p"); |
|
852 | 852 | |
853 | - foreach ($this->_page_text as $pt) { |
|
853 | + foreach ($this->_page_text as $pt) { |
|
854 | 854 | extract($pt); |
855 | 855 | |
856 | 856 | switch ($_t) { |
857 | 857 | |
858 | 858 | case "text": |
859 | 859 | $text = str_replace(array("{PAGE_NUM}","{PAGE_COUNT}"), |
860 | - array($p, $this->_page_count), $text); |
|
861 | - $this->text($x, $y, $text, $font, $size, $color, $adjust, $angle); |
|
862 | - break; |
|
860 | + array($p, $this->_page_count), $text); |
|
861 | + $this->text($x, $y, $text, $font, $size, $color, $adjust, $angle); |
|
862 | + break; |
|
863 | 863 | |
864 | 864 | case "script": |
865 | 865 | if (!$eval) { |
866 | 866 | $eval = new PHP_Evaluator($this); |
867 | - } |
|
868 | - $eval->evaluate($code, array('PAGE_NUM' => $p, 'PAGE_COUNT' => $this->_page_count)); |
|
869 | - break; |
|
867 | + } |
|
868 | + $eval->evaluate($code, array('PAGE_NUM' => $p, 'PAGE_COUNT' => $this->_page_count)); |
|
869 | + break; |
|
870 | + } |
|
870 | 871 | } |
871 | - } |
|
872 | 872 | |
873 | - $this->_pdf->suspend_page(""); |
|
873 | + $this->_pdf->suspend_page(""); |
|
874 | 874 | } |
875 | 875 | |
876 | 876 | $this->_pdf->resume_page("pagenumber=".$this->_page_number); |
877 | - } |
|
877 | + } |
|
878 | 878 | |
879 | - //........................................................................ |
|
879 | + //........................................................................ |
|
880 | 880 | |
881 | - function stream($filename, $options = null) { |
|
881 | + function stream($filename, $options = null) { |
|
882 | 882 | |
883 | 883 | // Add page text |
884 | 884 | $this->_add_page_text(); |
885 | 885 | |
886 | 886 | if ( isset($options["compress"]) && $options["compress"] != 1 ) |
887 | - $this->_pdf->set_value("compress", 0); |
|
887 | + $this->_pdf->set_value("compress", 0); |
|
888 | 888 | else |
889 | - $this->_pdf->set_value("compress", 6); |
|
889 | + $this->_pdf->set_value("compress", 6); |
|
890 | 890 | |
891 | 891 | $this->_close(); |
892 | 892 | |
893 | 893 | if ( self::$IN_MEMORY ) { |
894 | - $data = $this->_pdf->get_buffer(); |
|
895 | - $size = strlen($data); |
|
894 | + $data = $this->_pdf->get_buffer(); |
|
895 | + $size = strlen($data); |
|
896 | 896 | |
897 | 897 | } else |
898 | - $size = filesize($this->_file); |
|
898 | + $size = filesize($this->_file); |
|
899 | 899 | |
900 | 900 | |
901 | 901 | $filename = str_replace(array("\n","'"),"", $filename); |
@@ -908,63 +908,63 @@ discard block |
||
908 | 908 | //header("Content-length: " . $size); |
909 | 909 | |
910 | 910 | if ( self::$IN_MEMORY ) |
911 | - echo $data; |
|
911 | + echo $data; |
|
912 | 912 | |
913 | 913 | else { |
914 | 914 | |
915 | - // Chunked readfile() |
|
916 | - $chunk = (1 << 21); // 2 MB |
|
917 | - $fh = fopen($this->_file, "rb"); |
|
918 | - if ( !$fh ) |
|
915 | + // Chunked readfile() |
|
916 | + $chunk = (1 << 21); // 2 MB |
|
917 | + $fh = fopen($this->_file, "rb"); |
|
918 | + if ( !$fh ) |
|
919 | 919 | throw new DOMPDF_Exception("Unable to load temporary PDF file: " . $this->_file); |
920 | 920 | |
921 | - while ( !feof($fh) ) |
|
921 | + while ( !feof($fh) ) |
|
922 | 922 | echo fread($fh,$chunk); |
923 | - fclose($fh); |
|
923 | + fclose($fh); |
|
924 | 924 | |
925 | - //debugpng |
|
926 | - if (DEBUGPNG) print '[pdflib stream unlink '.$this->_file.']'; |
|
927 | - if (!DEBUGKEEPTEMP) |
|
925 | + //debugpng |
|
926 | + if (DEBUGPNG) print '[pdflib stream unlink '.$this->_file.']'; |
|
927 | + if (!DEBUGKEEPTEMP) |
|
928 | 928 | |
929 | - unlink($this->_file); |
|
930 | - $this->_file = null; |
|
929 | + unlink($this->_file); |
|
930 | + $this->_file = null; |
|
931 | 931 | } |
932 | 932 | |
933 | 933 | flush(); |
934 | 934 | |
935 | 935 | |
936 | - } |
|
936 | + } |
|
937 | 937 | |
938 | - //........................................................................ |
|
938 | + //........................................................................ |
|
939 | 939 | |
940 | - function output($options = null) { |
|
940 | + function output($options = null) { |
|
941 | 941 | |
942 | 942 | // Add page text |
943 | 943 | $this->_add_page_text(); |
944 | 944 | |
945 | 945 | if ( isset($options["compress"]) && $options["compress"] != 1 ) |
946 | - $this->_pdf->set_value("compress", 0); |
|
946 | + $this->_pdf->set_value("compress", 0); |
|
947 | 947 | else |
948 | - $this->_pdf->set_value("compress", 6); |
|
948 | + $this->_pdf->set_value("compress", 6); |
|
949 | 949 | |
950 | 950 | $this->_close(); |
951 | 951 | |
952 | 952 | if ( self::$IN_MEMORY ) |
953 | - $data = $this->_pdf->get_buffer(); |
|
953 | + $data = $this->_pdf->get_buffer(); |
|
954 | 954 | |
955 | 955 | else { |
956 | - $data = file_get_contents($this->_file); |
|
956 | + $data = file_get_contents($this->_file); |
|
957 | 957 | |
958 | - //debugpng |
|
959 | - if (DEBUGPNG) print '[pdflib output unlink '.$this->_file.']'; |
|
960 | - if (!DEBUGKEEPTEMP) |
|
958 | + //debugpng |
|
959 | + if (DEBUGPNG) print '[pdflib output unlink '.$this->_file.']'; |
|
960 | + if (!DEBUGKEEPTEMP) |
|
961 | 961 | |
962 | - unlink($this->_file); |
|
963 | - $this->_file = null; |
|
962 | + unlink($this->_file); |
|
963 | + $this->_file = null; |
|
964 | 964 | } |
965 | 965 | |
966 | 966 | return $data; |
967 | - } |
|
967 | + } |
|
968 | 968 | } |
969 | 969 | |
970 | 970 | // Workaround for idiotic limitation on statics... |
@@ -63,18 +63,18 @@ discard block |
||
63 | 63 | */ |
64 | 64 | if ( !function_exists("pre_r") ) { |
65 | 65 | function pre_r($mixed, $return = false) { |
66 | - if ($return) |
|
66 | + if ($return) |
|
67 | 67 | return "<pre>" . print_r($mixed, true) . "</pre>"; |
68 | 68 | |
69 | - if ( php_sapi_name() !== "cli") |
|
69 | + if ( php_sapi_name() !== "cli") |
|
70 | 70 | echo ("<pre>"); |
71 | - print_r($mixed); |
|
71 | + print_r($mixed); |
|
72 | 72 | |
73 | - if ( php_sapi_name() !== "cli") |
|
73 | + if ( php_sapi_name() !== "cli") |
|
74 | 74 | echo("</pre>"); |
75 | - else |
|
75 | + else |
|
76 | 76 | echo ("\n"); |
77 | - flush(); |
|
77 | + flush(); |
|
78 | 78 | |
79 | 79 | } |
80 | 80 | } |
@@ -89,10 +89,10 @@ discard block |
||
89 | 89 | */ |
90 | 90 | if ( !function_exists("pre_var_dump") ) { |
91 | 91 | function pre_var_dump($mixed) { |
92 | - if ( php_sapi_name() !== "cli") |
|
92 | + if ( php_sapi_name() !== "cli") |
|
93 | 93 | echo("<pre>"); |
94 | - var_dump($mixed); |
|
95 | - if ( php_sapi_name() !== "cli") |
|
94 | + var_dump($mixed); |
|
95 | + if ( php_sapi_name() !== "cli") |
|
96 | 96 | echo("</pre>"); |
97 | 97 | } |
98 | 98 | } |
@@ -115,41 +115,41 @@ discard block |
||
115 | 115 | * is appended (o.k. also for Windows) |
116 | 116 | */ |
117 | 117 | function build_url($protocol, $host, $base_path, $url) { |
118 | - if ( mb_strlen($url) == 0 ) { |
|
118 | + if ( mb_strlen($url) == 0 ) { |
|
119 | 119 | //return $protocol . $host . rtrim($base_path, "/\\") . "/"; |
120 | 120 | return $protocol . $host . $base_path; |
121 | - } |
|
121 | + } |
|
122 | 122 | |
123 | - // Is the url already fully qualified? |
|
124 | - if ( mb_strpos($url, "://") !== false ) |
|
123 | + // Is the url already fully qualified? |
|
124 | + if ( mb_strpos($url, "://") !== false ) |
|
125 | 125 | return $url; |
126 | 126 | |
127 | - $ret = $protocol; |
|
127 | + $ret = $protocol; |
|
128 | 128 | |
129 | - if (!in_array(mb_strtolower($protocol), array("http://", "https://", "ftp://", "ftps://"))) { |
|
129 | + if (!in_array(mb_strtolower($protocol), array("http://", "https://", "ftp://", "ftps://"))) { |
|
130 | 130 | //On Windows local file, an abs path can begin also with a '\' or a drive letter and colon |
131 | 131 | //drive: followed by a relative path would be a drive specific default folder. |
132 | 132 | //not known in php app code, treat as abs path |
133 | 133 | //($url[1] !== ':' || ($url[2]!=='\\' && $url[2]!=='/')) |
134 | 134 | if ($url[0] !== '/' && (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' || ($url[0] !== '\\' && $url[1] !== ':'))) { |
135 | - // For rel path and local acess we ignore the host, and run the path through realpath() |
|
136 | - $ret .= realpath($base_path).'/'; |
|
135 | + // For rel path and local acess we ignore the host, and run the path through realpath() |
|
136 | + $ret .= realpath($base_path).'/'; |
|
137 | 137 | } |
138 | 138 | $ret .= $url; |
139 | 139 | return $ret; |
140 | - } |
|
140 | + } |
|
141 | 141 | |
142 | - //remote urls with backslash in html/css are not really correct, but lets be genereous |
|
143 | - if ( $url[0] === '/' || $url[0] === '\\' ) { |
|
142 | + //remote urls with backslash in html/css are not really correct, but lets be genereous |
|
143 | + if ( $url[0] === '/' || $url[0] === '\\' ) { |
|
144 | 144 | // Absolute path |
145 | 145 | $ret .= $host . $url; |
146 | - } else { |
|
146 | + } else { |
|
147 | 147 | // Relative path |
148 | 148 | //$base_path = $base_path !== "" ? rtrim($base_path, "/\\") . "/" : ""; |
149 | 149 | $ret .= $host . $base_path . $url; |
150 | - } |
|
150 | + } |
|
151 | 151 | |
152 | - return $ret; |
|
152 | + return $ret; |
|
153 | 153 | |
154 | 154 | } |
155 | 155 | |
@@ -161,56 +161,56 @@ discard block |
||
161 | 161 | * @return array |
162 | 162 | */ |
163 | 163 | function explode_url($url) { |
164 | - $protocol = ""; |
|
165 | - $host = ""; |
|
166 | - $path = ""; |
|
167 | - $file = ""; |
|
164 | + $protocol = ""; |
|
165 | + $host = ""; |
|
166 | + $path = ""; |
|
167 | + $file = ""; |
|
168 | 168 | |
169 | - $arr = parse_url($url); |
|
169 | + $arr = parse_url($url); |
|
170 | 170 | |
171 | - if ( isset($arr["scheme"]) && |
|
171 | + if ( isset($arr["scheme"]) && |
|
172 | 172 | $arr["scheme"] !== "file" && |
173 | 173 | mb_strlen($arr["scheme"]) > 1 ) // Exclude windows drive letters... |
174 | 174 | { |
175 | 175 | $protocol = $arr["scheme"] . "://"; |
176 | 176 | |
177 | 177 | if ( isset($arr["user"]) ) { |
178 | - $host .= $arr["user"]; |
|
178 | + $host .= $arr["user"]; |
|
179 | 179 | |
180 | - if ( isset($arr["pass"]) ) |
|
180 | + if ( isset($arr["pass"]) ) |
|
181 | 181 | $host .= "@" . $arr["pass"]; |
182 | 182 | |
183 | - $host .= ":"; |
|
183 | + $host .= ":"; |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | if ( isset($arr["host"]) ) |
187 | - $host .= $arr["host"]; |
|
187 | + $host .= $arr["host"]; |
|
188 | 188 | |
189 | 189 | if ( isset($arr["port"]) ) |
190 | - $host .= ":" . $arr["port"]; |
|
190 | + $host .= ":" . $arr["port"]; |
|
191 | 191 | |
192 | 192 | if ( isset($arr["path"]) && $arr["path"] !== "" ) { |
193 | - // Do we have a trailing slash? |
|
194 | - if ( $arr["path"]{ mb_strlen($arr["path"]) - 1 } === "/" ) { |
|
193 | + // Do we have a trailing slash? |
|
194 | + if ( $arr["path"]{ mb_strlen($arr["path"]) - 1 } === "/" ) { |
|
195 | 195 | $path = $arr["path"]; |
196 | 196 | $file = ""; |
197 | - } else { |
|
197 | + } else { |
|
198 | 198 | $path = dirname($arr["path"]) . "/"; |
199 | 199 | $file = basename($arr["path"]); |
200 | - } |
|
200 | + } |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | if ( isset($arr["query"]) ) |
204 | - $file .= "?" . $arr["query"]; |
|
204 | + $file .= "?" . $arr["query"]; |
|
205 | 205 | |
206 | 206 | if ( isset($arr["fragment"]) ) |
207 | - $file .= "#" . $arr["fragment"]; |
|
207 | + $file .= "#" . $arr["fragment"]; |
|
208 | 208 | |
209 | - } else { |
|
209 | + } else { |
|
210 | 210 | |
211 | 211 | $i = mb_strpos($url, "file://"); |
212 | 212 | if ( $i !== false) |
213 | - $url = mb_substr($url, $i + 7); |
|
213 | + $url = mb_substr($url, $i + 7); |
|
214 | 214 | |
215 | 215 | $protocol = ""; // "file://"; ? why doesn't this work... It's because of |
216 | 216 | // network filenames like //COMPU/SHARENAME |
@@ -222,28 +222,28 @@ discard block |
||
222 | 222 | |
223 | 223 | // Check that the path exists |
224 | 224 | if ( $path !== false ) { |
225 | - $path .= '/'; |
|
225 | + $path .= '/'; |
|
226 | 226 | |
227 | 227 | } else { |
228 | - // generate a url to access the file if no real path found. |
|
229 | - $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https://' : 'http://'; |
|
228 | + // generate a url to access the file if no real path found. |
|
229 | + $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https://' : 'http://'; |
|
230 | 230 | |
231 | - $host = isset($_SERVER["HTTP_HOST"]) ? $_SERVER["HTTP_HOST"] : php_uname("n"); |
|
231 | + $host = isset($_SERVER["HTTP_HOST"]) ? $_SERVER["HTTP_HOST"] : php_uname("n"); |
|
232 | 232 | |
233 | - if ( substr($arr["path"], 0, 1) === '/' ) { |
|
233 | + if ( substr($arr["path"], 0, 1) === '/' ) { |
|
234 | 234 | $path = dirname($arr["path"]); |
235 | - } else { |
|
235 | + } else { |
|
236 | 236 | $path = '/' . rtrim(dirname($_SERVER["SCRIPT_NAME"]), '/') . '/' . $arr["path"]; |
237 | - } |
|
237 | + } |
|
238 | + } |
|
238 | 239 | } |
239 | - } |
|
240 | - |
|
241 | - $ret = array($protocol, $host, $path, $file, |
|
242 | - "protocol" => $protocol, |
|
243 | - "host" => $host, |
|
244 | - "path" => $path, |
|
245 | - "file" => $file); |
|
246 | - return $ret; |
|
240 | + |
|
241 | + $ret = array($protocol, $host, $path, $file, |
|
242 | + "protocol" => $protocol, |
|
243 | + "host" => $host, |
|
244 | + "path" => $path, |
|
245 | + "file" => $file); |
|
246 | + return $ret; |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | /** |
@@ -254,41 +254,41 @@ discard block |
||
254 | 254 | */ |
255 | 255 | function dec2roman($num) { |
256 | 256 | |
257 | - static $ones = array("", "i", "ii", "iii", "iv", "v", |
|
258 | - "vi", "vii", "viii", "ix"); |
|
259 | - static $tens = array("", "x", "xx", "xxx", "xl", "l", |
|
260 | - "lx", "lxx", "lxxx", "xc"); |
|
261 | - static $hund = array("", "c", "cc", "ccc", "cd", "d", |
|
262 | - "dc", "dcc", "dccc", "cm"); |
|
263 | - static $thou = array("", "m", "mm", "mmm"); |
|
257 | + static $ones = array("", "i", "ii", "iii", "iv", "v", |
|
258 | + "vi", "vii", "viii", "ix"); |
|
259 | + static $tens = array("", "x", "xx", "xxx", "xl", "l", |
|
260 | + "lx", "lxx", "lxxx", "xc"); |
|
261 | + static $hund = array("", "c", "cc", "ccc", "cd", "d", |
|
262 | + "dc", "dcc", "dccc", "cm"); |
|
263 | + static $thou = array("", "m", "mm", "mmm"); |
|
264 | 264 | |
265 | - if ( !is_numeric($num) ) |
|
265 | + if ( !is_numeric($num) ) |
|
266 | 266 | throw new DOMPDF_Exception("dec2roman() requires a numeric argument."); |
267 | 267 | |
268 | - if ( $num > 4000 || $num < 0 ) |
|
268 | + if ( $num > 4000 || $num < 0 ) |
|
269 | 269 | return "(out of range)"; |
270 | 270 | |
271 | - $num = strrev((string)$num); |
|
271 | + $num = strrev((string)$num); |
|
272 | 272 | |
273 | - $ret = ""; |
|
274 | - switch (mb_strlen($num)) { |
|
273 | + $ret = ""; |
|
274 | + switch (mb_strlen($num)) { |
|
275 | 275 | |
276 | - case 4: |
|
276 | + case 4: |
|
277 | 277 | $ret .= $thou[$num[3]]; |
278 | 278 | |
279 | - case 3: |
|
279 | + case 3: |
|
280 | 280 | $ret .= $hund[$num[2]]; |
281 | 281 | |
282 | - case 2: |
|
282 | + case 2: |
|
283 | 283 | $ret .= $tens[$num[1]]; |
284 | 284 | |
285 | - case 1: |
|
285 | + case 1: |
|
286 | 286 | $ret .= $ones[$num[0]]; |
287 | 287 | |
288 | - default: |
|
288 | + default: |
|
289 | 289 | break; |
290 | - } |
|
291 | - return $ret; |
|
290 | + } |
|
291 | + return $ret; |
|
292 | 292 | |
293 | 293 | } |
294 | 294 | |
@@ -305,84 +305,84 @@ discard block |
||
305 | 305 | */ |
306 | 306 | |
307 | 307 | if ( !function_exists("mb_convert_encoding") ) { |
308 | - function mb_convert_encoding($data, $to_encoding, $from_encoding='UTF-8') { |
|
308 | + function mb_convert_encoding($data, $to_encoding, $from_encoding='UTF-8') { |
|
309 | 309 | if (str_replace('-', '', strtolower($to_encoding)) == 'utf8') { |
310 | - return utf8_encode($data); |
|
310 | + return utf8_encode($data); |
|
311 | 311 | } else { |
312 | - return utf8_decode($data); |
|
312 | + return utf8_decode($data); |
|
313 | + } |
|
313 | 314 | } |
314 | - } |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | if ( !function_exists("mb_detect_encoding") ) { |
318 | - function mb_detect_encoding($data, $encoding_list=array('iso-8859-1'), $strict=false) { |
|
318 | + function mb_detect_encoding($data, $encoding_list=array('iso-8859-1'), $strict=false) { |
|
319 | 319 | return 'iso-8859-1'; |
320 | - } |
|
320 | + } |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | if ( !function_exists("mb_detect_order") ) { |
324 | - function mb_detect_order($encoding_list=array('iso-8859-1')) { |
|
324 | + function mb_detect_order($encoding_list=array('iso-8859-1')) { |
|
325 | 325 | return 'iso-8859-1'; |
326 | - } |
|
326 | + } |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | if ( !function_exists("mb_internal_encoding") ) { |
330 | - function mb_internal_encoding($encoding=NULL) { |
|
330 | + function mb_internal_encoding($encoding=NULL) { |
|
331 | 331 | if (isset($encoding)) { |
332 | - return true; |
|
332 | + return true; |
|
333 | 333 | } else { |
334 | - return 'iso-8859-1'; |
|
334 | + return 'iso-8859-1'; |
|
335 | + } |
|
335 | 336 | } |
336 | - } |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | if ( !function_exists("mb_strlen") ) { |
340 | - function mb_strlen($str, $encoding='iso-8859-1') { |
|
340 | + function mb_strlen($str, $encoding='iso-8859-1') { |
|
341 | 341 | if (str_replace('-', '', strtolower($encoding)) == 'utf8') { |
342 | - return strlen(utf8_encode($data)); |
|
342 | + return strlen(utf8_encode($data)); |
|
343 | 343 | } else { |
344 | - return strlen(utf8_decode($data)); |
|
344 | + return strlen(utf8_decode($data)); |
|
345 | + } |
|
345 | 346 | } |
346 | - } |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | if ( !function_exists("mb_strpos") ) { |
350 | - function mb_strpos($haystack, $needle, $offset = 0) { |
|
350 | + function mb_strpos($haystack, $needle, $offset = 0) { |
|
351 | 351 | return strpos($haystack, $needle, $offset); |
352 | - } |
|
352 | + } |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | if ( !function_exists("mb_strrpos") ) { |
356 | - function mb_strrpos($haystack, $needle, $offset = 0) { |
|
356 | + function mb_strrpos($haystack, $needle, $offset = 0) { |
|
357 | 357 | return strrpos($haystack, $needle, $offset); |
358 | - } |
|
358 | + } |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | if ( !function_exists("mb_strtolower") ) { |
362 | - function mb_strtolower($str) { |
|
362 | + function mb_strtolower($str) { |
|
363 | 363 | return strtolower($str); |
364 | - } |
|
364 | + } |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | if ( !function_exists("mb_strtoupper") ) { |
368 | - function mb_strtoupper($str) { |
|
368 | + function mb_strtoupper($str) { |
|
369 | 369 | return strtoupper($str); |
370 | - } |
|
370 | + } |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | if ( !function_exists("mb_substr") ) { |
374 | - function mb_substr($str, $start, $length=null, $encoding='iso-8859-1') { |
|
374 | + function mb_substr($str, $start, $length=null, $encoding='iso-8859-1') { |
|
375 | 375 | if ( is_null($length) ) |
376 | - return substr($str, $start); |
|
376 | + return substr($str, $start); |
|
377 | 377 | else |
378 | - return substr($str, $start, $length); |
|
379 | - } |
|
378 | + return substr($str, $start, $length); |
|
379 | + } |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | if ( !function_exists("mb_substr_count") ) { |
383 | - function mb_substr_count($haystack, $needle) { |
|
383 | + function mb_substr_count($haystack, $needle) { |
|
384 | 384 | return substr_count($haystack, $needle); |
385 | - } |
|
385 | + } |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | /** |
@@ -402,40 +402,40 @@ discard block |
||
402 | 402 | */ |
403 | 403 | function record_warnings($errno, $errstr, $errfile, $errline) { |
404 | 404 | |
405 | - if ( !($errno & (E_WARNING | E_NOTICE | E_USER_NOTICE | E_USER_WARNING )) ) // Not a warning or notice |
|
405 | + if ( !($errno & (E_WARNING | E_NOTICE | E_USER_NOTICE | E_USER_WARNING )) ) // Not a warning or notice |
|
406 | 406 | throw new DOMPDF_Exception($errstr . " $errno"); |
407 | 407 | |
408 | - global $_dompdf_warnings; |
|
409 | - global $_dompdf_show_warnings; |
|
408 | + global $_dompdf_warnings; |
|
409 | + global $_dompdf_show_warnings; |
|
410 | 410 | |
411 | - if ( $_dompdf_show_warnings ) |
|
411 | + if ( $_dompdf_show_warnings ) |
|
412 | 412 | echo $errstr . "\n"; |
413 | 413 | |
414 | - $_dompdf_warnings[] = $errstr; |
|
414 | + $_dompdf_warnings[] = $errstr; |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | /** |
418 | 418 | * Print a useful backtrace |
419 | 419 | */ |
420 | 420 | function bt() { |
421 | - $bt = debug_backtrace(); |
|
421 | + $bt = debug_backtrace(); |
|
422 | 422 | |
423 | - array_shift($bt); // remove actual bt() call |
|
424 | - echo "\n"; |
|
423 | + array_shift($bt); // remove actual bt() call |
|
424 | + echo "\n"; |
|
425 | 425 | |
426 | - $i = 0; |
|
427 | - foreach ($bt as $call) { |
|
426 | + $i = 0; |
|
427 | + foreach ($bt as $call) { |
|
428 | 428 | $file = basename($call["file"]) . " (" . $call["line"] . ")"; |
429 | 429 | if ( isset($call["class"]) ) { |
430 | - $func = $call["class"] . "->" . $call["function"] . "()"; |
|
430 | + $func = $call["class"] . "->" . $call["function"] . "()"; |
|
431 | 431 | } else { |
432 | - $func = $call["function"] . "()"; |
|
432 | + $func = $call["function"] . "()"; |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | echo "#" . str_pad($i, 2, " ", STR_PAD_RIGHT) . ": " . str_pad($file.":", 42) . " $func\n"; |
436 | 436 | $i++; |
437 | - } |
|
438 | - echo "\n"; |
|
437 | + } |
|
438 | + echo "\n"; |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | /** |
@@ -444,15 +444,15 @@ discard block |
||
444 | 444 | * @param string $type The type of debug messages to print |
445 | 445 | */ |
446 | 446 | function dompdf_debug($type, $msg) { |
447 | - global $_DOMPDF_DEBUG_TYPES; |
|
448 | - global $_dompdf_show_warnings; |
|
449 | - global $_dompdf_debug; |
|
450 | - if ( isset($_DOMPDF_DEBUG_TYPES[$type]) && ($_dompdf_show_warnings || $_dompdf_debug) ) { |
|
447 | + global $_DOMPDF_DEBUG_TYPES; |
|
448 | + global $_dompdf_show_warnings; |
|
449 | + global $_dompdf_debug; |
|
450 | + if ( isset($_DOMPDF_DEBUG_TYPES[$type]) && ($_dompdf_show_warnings || $_dompdf_debug) ) { |
|
451 | 451 | $arr = debug_backtrace(); |
452 | 452 | |
453 | 453 | echo basename($arr[0]["file"]) . " (" . $arr[0]["line"] ."): " . $arr[1]["function"] . ": "; |
454 | 454 | pre_r($msg); |
455 | - } |
|
455 | + } |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | /** |
@@ -460,20 +460,20 @@ discard block |
||
460 | 460 | */ |
461 | 461 | if ( !function_exists("print_memusage") ) { |
462 | 462 | function print_memusage() { |
463 | - global $memusage; |
|
464 | - echo ("Memory Usage\n"); |
|
465 | - $prev = 0; |
|
466 | - $initial = reset($memusage); |
|
467 | - echo (str_pad("Initial:", 40) . $initial . "\n\n"); |
|
463 | + global $memusage; |
|
464 | + echo ("Memory Usage\n"); |
|
465 | + $prev = 0; |
|
466 | + $initial = reset($memusage); |
|
467 | + echo (str_pad("Initial:", 40) . $initial . "\n\n"); |
|
468 | 468 | |
469 | - foreach ($memusage as $key=>$mem) { |
|
469 | + foreach ($memusage as $key=>$mem) { |
|
470 | 470 | $mem -= $initial; |
471 | 471 | echo (str_pad("$key:" , 40)); |
472 | 472 | echo (str_pad("$mem", 12) . "(diff: " . ($mem - $prev) . ")\n"); |
473 | 473 | $prev = $mem; |
474 | - } |
|
474 | + } |
|
475 | 475 | |
476 | - echo ("\n" . str_pad("Total:", 40) . memory_get_usage()) . "\n"; |
|
476 | + echo ("\n" . str_pad("Total:", 40) . memory_get_usage()) . "\n"; |
|
477 | 477 | } |
478 | 478 | } |
479 | 479 | |
@@ -495,8 +495,8 @@ discard block |
||
495 | 495 | */ |
496 | 496 | if ( !function_exists("mark_memusage") ) { |
497 | 497 | function mark_memusage($location) { |
498 | - global $memusage; |
|
499 | - if ( isset($memusage) ) |
|
498 | + global $memusage; |
|
499 | + if ( isset($memusage) ) |
|
500 | 500 | $memusage[$location] = memory_get_usage(); |
501 | 501 | } |
502 | 502 | } |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | * @link http://us.php.net/manual/en/function.sys-get-temp-dir.php#85261 |
508 | 508 | */ |
509 | 509 | if ( !function_exists('sys_get_temp_dir')) { |
510 | - function sys_get_temp_dir() { |
|
510 | + function sys_get_temp_dir() { |
|
511 | 511 | if (!empty($_ENV['TMP'])) { return realpath($_ENV['TMP']); } |
512 | 512 | if (!empty($_ENV['TMPDIR'])) { return realpath( $_ENV['TMPDIR']); } |
513 | 513 | if (!empty($_ENV['TEMP'])) { return realpath( $_ENV['TEMP']); } |
@@ -516,5 +516,5 @@ discard block |
||
516 | 516 | unlink($tempfile); |
517 | 517 | return realpath(dirname($tempfile)); |
518 | 518 | } |
519 | - } |
|
519 | + } |
|
520 | 520 | } |
@@ -1,41 +1,40 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * DOMPDF - PHP5 HTML to PDF renderer |
|
4 | - * |
|
5 | - * File: $RCSfile: block_frame_decorator.cls.php,v $ |
|
6 | - * Created on: 2004-06-02 |
|
7 | - * |
|
8 | - * Copyright (c) 2004 - Benj Carson <[email protected]> |
|
9 | - * |
|
10 | - * This library is free software; you can redistribute it and/or |
|
11 | - * modify it under the terms of the GNU Lesser General Public |
|
12 | - * License as published by the Free Software Foundation; either |
|
13 | - * version 2.1 of the License, or (at your option) any later version. |
|
14 | - * |
|
15 | - * This library is distributed in the hope that it will be useful, |
|
16 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
18 | - * Lesser General Public License for more details. |
|
19 | - * |
|
20 | - * You should have received a copy of the GNU Lesser General Public License |
|
21 | - * along with this library in the file LICENSE.LGPL; if not, write to the |
|
22 | - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
|
23 | - * 02111-1307 USA |
|
24 | - * |
|
25 | - * Alternatively, you may distribute this software under the terms of the |
|
26 | - * PHP License, version 3.0 or later. A copy of this license should have |
|
27 | - * been distributed with this file in the file LICENSE.PHP . If this is not |
|
28 | - * the case, you can obtain a copy at http://www.php.net/license/3_0.txt. |
|
29 | - * |
|
30 | - * The latest version of DOMPDF might be available at: |
|
31 | - * http://www.dompdf.com/ |
|
32 | - * |
|
33 | - * @link http://www.dompdf.com/ |
|
34 | - * @copyright 2004 Benj Carson |
|
35 | - * @author Benj Carson <[email protected]> |
|
36 | - * @package dompdf |
|
37 | - |
|
38 | - */ |
|
3 | + * DOMPDF - PHP5 HTML to PDF renderer |
|
4 | + * |
|
5 | + * File: $RCSfile: block_frame_decorator.cls.php,v $ |
|
6 | + * Created on: 2004-06-02 |
|
7 | + * |
|
8 | + * Copyright (c) 2004 - Benj Carson <[email protected]> |
|
9 | + * |
|
10 | + * This library is free software; you can redistribute it and/or |
|
11 | + * modify it under the terms of the GNU Lesser General Public |
|
12 | + * License as published by the Free Software Foundation; either |
|
13 | + * version 2.1 of the License, or (at your option) any later version. |
|
14 | + * |
|
15 | + * This library is distributed in the hope that it will be useful, |
|
16 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
18 | + * Lesser General Public License for more details. |
|
19 | + * |
|
20 | + * You should have received a copy of the GNU Lesser General Public License |
|
21 | + * along with this library in the file LICENSE.LGPL; if not, write to the |
|
22 | + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
|
23 | + * 02111-1307 USA |
|
24 | + * |
|
25 | + * Alternatively, you may distribute this software under the terms of the |
|
26 | + * PHP License, version 3.0 or later. A copy of this license should have |
|
27 | + * been distributed with this file in the file LICENSE.PHP . If this is not |
|
28 | + * the case, you can obtain a copy at http://www.php.net/license/3_0.txt. |
|
29 | + * |
|
30 | + * The latest version of DOMPDF might be available at: |
|
31 | + * http://www.dompdf.com/ |
|
32 | + * |
|
33 | + * @link http://www.dompdf.com/ |
|
34 | + * @copyright 2004 Benj Carson |
|
35 | + * @author Benj Carson <[email protected]> |
|
36 | + * @package dompdf |
|
37 | + */ |
|
39 | 38 | |
40 | 39 | /* $Id: block_frame_decorator.cls.php 216 2010-03-11 22:49:18Z ryan.masten $ */ |
41 | 40 | |
@@ -47,16 +46,16 @@ discard block |
||
47 | 46 | */ |
48 | 47 | class Block_Frame_Decorator extends Frame_Decorator { |
49 | 48 | |
50 | - const DEFAULT_COUNTER = "-dompdf-default-counter"; |
|
49 | + const DEFAULT_COUNTER = "-dompdf-default-counter"; |
|
51 | 50 | |
52 | - protected $_lines; // array( [num] => array([frames] => array(<frame list>), |
|
53 | - // y, w, h) ) |
|
54 | - protected $_counters; // array([id] => counter_value) (for generated content) |
|
55 | - protected $_cl; // current line index |
|
51 | + protected $_lines; // array( [num] => array([frames] => array(<frame list>), |
|
52 | + // y, w, h) ) |
|
53 | + protected $_counters; // array([id] => counter_value) (for generated content) |
|
54 | + protected $_cl; // current line index |
|
56 | 55 | |
57 | - //........................................................................ |
|
56 | + //........................................................................ |
|
58 | 57 | |
59 | - function __construct(Frame $frame, DOMPDF $dompdf) { |
|
58 | + function __construct(Frame $frame, DOMPDF $dompdf) { |
|
60 | 59 | parent::__construct($frame, $dompdf); |
61 | 60 | $this->_lines = array(array("frames" => array(), |
62 | 61 | "wc" => 0, |
@@ -66,11 +65,11 @@ discard block |
||
66 | 65 | $this->_counters = array(self::DEFAULT_COUNTER => 0); |
67 | 66 | $this->_cl = 0; |
68 | 67 | |
69 | - } |
|
68 | + } |
|
70 | 69 | |
71 | - //........................................................................ |
|
70 | + //........................................................................ |
|
72 | 71 | |
73 | - function reset() { |
|
72 | + function reset() { |
|
74 | 73 | parent::reset(); |
75 | 74 | $this->_lines = array(array("frames" => array(), |
76 | 75 | "wc" => 0, |
@@ -79,67 +78,67 @@ discard block |
||
79 | 78 | "h" => 0)); |
80 | 79 | $this->_counters = array(self::DEFAULT_COUNTER => 0); |
81 | 80 | $this->_cl = 0; |
82 | - } |
|
81 | + } |
|
83 | 82 | |
84 | - //........................................................................ |
|
83 | + //........................................................................ |
|
85 | 84 | |
86 | - // Accessor methods |
|
85 | + // Accessor methods |
|
87 | 86 | |
88 | - function get_current_line($i = null) { |
|
87 | + function get_current_line($i = null) { |
|
89 | 88 | $cl = $this->_lines[$this->_cl]; |
90 | 89 | if ( isset($i) ) |
91 | - return $cl[$i]; |
|
90 | + return $cl[$i]; |
|
92 | 91 | return $cl; |
93 | - } |
|
92 | + } |
|
94 | 93 | |
95 | - function get_lines() { return $this->_lines; } |
|
94 | + function get_lines() { return $this->_lines; } |
|
96 | 95 | |
97 | - //........................................................................ |
|
96 | + //........................................................................ |
|
98 | 97 | |
99 | - // Set methods |
|
100 | - function set_current_line($y = null, $w = null, $h = null) { |
|
98 | + // Set methods |
|
99 | + function set_current_line($y = null, $w = null, $h = null) { |
|
101 | 100 | $this->set_line($this->_cl, $y, $w, $h); |
102 | - } |
|
101 | + } |
|
103 | 102 | |
104 | - function clear_line($i) { |
|
103 | + function clear_line($i) { |
|
105 | 104 | if ( isset($this->_lines[$i]) ) |
106 | - unset($this->_lines[$i]); |
|
107 | - } |
|
105 | + unset($this->_lines[$i]); |
|
106 | + } |
|
108 | 107 | |
109 | - function set_line($lineno, $y = null, $w = null, $h = null) { |
|
108 | + function set_line($lineno, $y = null, $w = null, $h = null) { |
|
110 | 109 | |
111 | 110 | if ( is_array($y) ) |
112 | - extract($y); |
|
111 | + extract($y); |
|
113 | 112 | |
114 | 113 | if (is_numeric($y)) |
115 | - $this->_lines[$lineno]["y"] = $y; |
|
114 | + $this->_lines[$lineno]["y"] = $y; |
|
116 | 115 | |
117 | 116 | if (is_numeric($w)) |
118 | - $this->_lines[$lineno]["w"] = $w; |
|
117 | + $this->_lines[$lineno]["w"] = $w; |
|
119 | 118 | |
120 | 119 | if (is_numeric($h)) |
121 | - $this->_lines[$lineno]["h"] = $h; |
|
120 | + $this->_lines[$lineno]["h"] = $h; |
|
122 | 121 | |
123 | - } |
|
122 | + } |
|
124 | 123 | |
125 | 124 | |
126 | - function add_frame_to_line(Frame $frame) { |
|
125 | + function add_frame_to_line(Frame $frame) { |
|
127 | 126 | |
128 | 127 | // Handle inline frames (which are effectively wrappers) |
129 | 128 | if ( $frame instanceof Inline_Frame_Decorator ) { |
130 | 129 | |
131 | - // Handle line breaks |
|
132 | - if ( $frame->get_node()->nodeName === "br" ) { |
|
130 | + // Handle line breaks |
|
131 | + if ( $frame->get_node()->nodeName === "br" ) { |
|
133 | 132 | $this->maximize_line_height( $frame->get_style()->length_in_pt($frame->get_style()->line_height) ); |
134 | 133 | $this->add_line(); |
135 | 134 | return; |
136 | - } |
|
135 | + } |
|
137 | 136 | |
138 | - // Add each child of the inline frame to the line individually |
|
139 | - foreach ($frame->get_children() as $child) |
|
137 | + // Add each child of the inline frame to the line individually |
|
138 | + foreach ($frame->get_children() as $child) |
|
140 | 139 | $this->add_frame_to_line( $child ); |
141 | 140 | |
142 | - return; |
|
141 | + return; |
|
143 | 142 | } |
144 | 143 | |
145 | 144 | // Trim leading text if this is an empty line. Kinda a hack to put it here, |
@@ -149,15 +148,15 @@ discard block |
||
149 | 148 | ($frame->get_style()->white_space !== "pre" || |
150 | 149 | $frame->get_style()->white_space !== "pre-wrap") ) { |
151 | 150 | |
152 | - $frame->set_text( ltrim($frame->get_text()) ); |
|
153 | - $frame->recalculate_width(); |
|
151 | + $frame->set_text( ltrim($frame->get_text()) ); |
|
152 | + $frame->recalculate_width(); |
|
154 | 153 | |
155 | 154 | } |
156 | 155 | |
157 | 156 | $w = $frame->get_margin_width(); |
158 | 157 | |
159 | 158 | if ( $w == 0 ) |
160 | - return; |
|
159 | + return; |
|
161 | 160 | |
162 | 161 | // Debugging code: |
163 | 162 | /* |
@@ -177,7 +176,7 @@ discard block |
||
177 | 176 | // End debugging |
178 | 177 | |
179 | 178 | if ($this->_lines[$this->_cl]["w"] + $w > $this->get_containing_block("w")) |
180 | - $this->add_line(); |
|
179 | + $this->add_line(); |
|
181 | 180 | |
182 | 181 | $frame->position(); |
183 | 182 | |
@@ -185,55 +184,55 @@ discard block |
||
185 | 184 | $this->_lines[$this->_cl]["frames"][] = $frame; |
186 | 185 | |
187 | 186 | if ( $frame->get_node()->nodeName === "#text") |
188 | - $this->_lines[$this->_cl]["wc"] += count(preg_split("/\s+/", $frame->get_text())); |
|
187 | + $this->_lines[$this->_cl]["wc"] += count(preg_split("/\s+/", $frame->get_text())); |
|
189 | 188 | |
190 | 189 | $this->_lines[$this->_cl]["w"] += $w; |
191 | 190 | $this->_lines[$this->_cl]["h"] = max($this->_lines[$this->_cl]["h"], $frame->get_margin_height()); |
192 | 191 | |
193 | - } |
|
192 | + } |
|
194 | 193 | |
195 | - function remove_frames_from_line(Frame $frame) { |
|
194 | + function remove_frames_from_line(Frame $frame) { |
|
196 | 195 | // Search backwards through the lines for $frame |
197 | 196 | $i = $this->_cl; |
198 | 197 | |
199 | 198 | while ($i >= 0) { |
200 | - if ( ($j = in_array($frame, $this->_lines[$i]["frames"], true)) !== false ) |
|
199 | + if ( ($j = in_array($frame, $this->_lines[$i]["frames"], true)) !== false ) |
|
201 | 200 | break; |
202 | - $i--; |
|
201 | + $i--; |
|
203 | 202 | } |
204 | 203 | |
205 | 204 | if ( $j === false ) |
206 | - return; |
|
205 | + return; |
|
207 | 206 | |
208 | 207 | // Remove $frame and all frames that follow |
209 | 208 | while ($j < count($this->_lines[$i]["frames"])) { |
210 | - $f = $this->_lines[$i]["frames"][$j]; |
|
211 | - unset($this->_lines[$i]["frames"][$j++]); |
|
212 | - $this->_lines[$i]["w"] -= $f->get_margin_width(); |
|
209 | + $f = $this->_lines[$i]["frames"][$j]; |
|
210 | + unset($this->_lines[$i]["frames"][$j++]); |
|
211 | + $this->_lines[$i]["w"] -= $f->get_margin_width(); |
|
213 | 212 | } |
214 | 213 | |
215 | 214 | // Recalculate the height of the line |
216 | 215 | $h = 0; |
217 | 216 | foreach ($this->_lines[$i]["frames"] as $f) |
218 | - $h = max( $h, $f->get_margin_height() ); |
|
217 | + $h = max( $h, $f->get_margin_height() ); |
|
219 | 218 | |
220 | 219 | $this->_lines[$i]["h"] = $h; |
221 | 220 | |
222 | 221 | // Remove all lines that follow |
223 | 222 | while ($this->_cl > $i) |
224 | - unset($this->_lines[ $this->_cl-- ]); |
|
223 | + unset($this->_lines[ $this->_cl-- ]); |
|
225 | 224 | |
226 | - } |
|
225 | + } |
|
227 | 226 | |
228 | - function increase_line_width($w) { |
|
227 | + function increase_line_width($w) { |
|
229 | 228 | $this->_lines[ $this->_cl ]["w"] += $w; |
230 | - } |
|
229 | + } |
|
231 | 230 | |
232 | - function maximize_line_height($val) { |
|
231 | + function maximize_line_height($val) { |
|
233 | 232 | $this->_lines[ $this->_cl ]["h"] = max($this->_lines[ $this->_cl ]["h"], $val); |
234 | - } |
|
233 | + } |
|
235 | 234 | |
236 | - function add_line() { |
|
235 | + function add_line() { |
|
237 | 236 | |
238 | 237 | // if ( $this->_lines[$this->_cl]["h"] == 0 ) //count($this->_lines[$i]["frames"]) == 0 || |
239 | 238 | // return; |
@@ -241,28 +240,28 @@ discard block |
||
241 | 240 | $y = $this->_lines[$this->_cl]["y"] + $this->_lines[$this->_cl]["h"]; |
242 | 241 | |
243 | 242 | $this->_lines[ ++$this->_cl ] = array("frames" => array(), |
244 | - "wc" => 0, |
|
245 | - "y" => $y, "w" => 0, "h" => 0); |
|
246 | - } |
|
243 | + "wc" => 0, |
|
244 | + "y" => $y, "w" => 0, "h" => 0); |
|
245 | + } |
|
247 | 246 | |
248 | - //........................................................................ |
|
247 | + //........................................................................ |
|
249 | 248 | |
250 | - function reset_counter($id = self::DEFAULT_COUNTER, $value = 0) { |
|
249 | + function reset_counter($id = self::DEFAULT_COUNTER, $value = 0) { |
|
251 | 250 | $this->_counters[$id] = $value; |
252 | - } |
|
251 | + } |
|
253 | 252 | |
254 | - function increment_counter($id = self::DEFAULT_COUNTER, $increment = 1) { |
|
253 | + function increment_counter($id = self::DEFAULT_COUNTER, $increment = 1) { |
|
255 | 254 | if ( !isset($this->_counters[$id]) ) |
256 | - $this->_counters[$id] = $increment; |
|
255 | + $this->_counters[$id] = $increment; |
|
257 | 256 | else |
258 | - $this->_counters[$id] += $increment; |
|
257 | + $this->_counters[$id] += $increment; |
|
259 | 258 | |
260 | - } |
|
259 | + } |
|
261 | 260 | |
262 | - function counter_value($id = self::DEFAULT_COUNTER, $type = "decimal") { |
|
261 | + function counter_value($id = self::DEFAULT_COUNTER, $type = "decimal") { |
|
263 | 262 | $type = mb_strtolower($type); |
264 | 263 | if ( !isset($this->_counters[$id]) ) |
265 | - $this->_counters[$id] = 0; |
|
264 | + $this->_counters[$id] = 0; |
|
266 | 265 | |
267 | 266 | switch ($type) { |
268 | 267 | |
@@ -293,5 +292,5 @@ discard block |
||
293 | 292 | case "upper-greek": |
294 | 293 | return chr($this->_counters[$id] + 912); |
295 | 294 | } |
296 | - } |
|
295 | + } |
|
297 | 296 | } |