freepdf - Version 1.2.0.0

Version Notes

1.2

Download this release

Release Info

Developer ecommerceoffice
Extension freepdf
Version 1.2.0.0
Comparing to
See all releases


Code changes from version 1.0.9 to 1.2.0.0

app/code/community/Ip/Promopdf/Block/.DS_Store ADDED
Binary file
app/code/community/Ip/Promopdf/Block/Developer.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Ip_Promopdf_Block_Developer extends Mage_Adminhtml_Block_System_Config_Form_Fieldset {
4
+
5
+ protected function _prepareLayout() {
6
+ parent::_prepareLayout();
7
+
8
+ }
9
+
10
+ public function render(Varien_Data_Form_Element_Abstract $element) {
11
+ $content = '<p></p>';
12
+ $content.= '<style>';
13
+ $content.= '.developer {
14
+ background:#FAFAFA;
15
+ border: 1px solid #CCCCCC;
16
+ margin-bottom: 10px;
17
+ padding: 10px;
18
+ height:auto;
19
+
20
+ }
21
+ .developer h3 {
22
+ color: #EA7601;
23
+ }
24
+ .contact-type {
25
+ color: #EA7601;
26
+ font-weight:bold;
27
+ }
28
+ .developer img {
29
+
30
+ float:left;
31
+ height:255px;
32
+ width:220px;
33
+ }
34
+ .developer .info {
35
+ border: 1px solid #CCCCCC;
36
+ background:#E7EFEF;
37
+ padding: 5px 10px 0 5px;
38
+ margin-left:230px;
39
+ height:250px;
40
+ }
41
+ ';
42
+ $content.= '</style>';
43
+
44
+
45
+ $content.= '<div class="developer">';
46
+ $content.= '<a href="http://www.magazento.com/english/magento-ext/magazento-extensions" target="_blank"><img src="'.Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN).'frontend/base/default/ip_promopdf/promo.jpg" alt="www.ecommerceoffice.com" /></a>';
47
+ $content.= '<div class="info">';
48
+ $content.= '<h3>PROFESSIONAL MAGENTO DEVELOPMENT</h3>';
49
+ $content.= '<p>As a company, we provide a wide range of services related to the Website development, their design and installation as well as their configuration on Magento e-commerce platform.</p>';
50
+ $content.= '--------------------------------------------------------<br>';
51
+ $content.= '<span class="contact-type">Websites:</span> <br/><a href="http://www.magazento.com/" target="_blank">www.magazento.com</a> <br/>';
52
+ $content.= ' <a href="http://www.ecommerceoffice.com/" target="_blank">www.ecommerceoffice.com</a> <br/>';
53
+ $content.= '<span class="contact-type">E-mail:</span> <br/>service@magazento.com / ';
54
+ $content.= 'service@ecommerceoffice.com <br/>';
55
+ $content.= '<span class="contact-type">LinkedIn:</span> <br/><a href="http://www.linkedin.com/pub/ivan-proskuryakov/31/200/316" target="_blank">http://www.linkedin.com/pub/ivan-proskuryakov/31/200/316</a> <br/>';
56
+
57
+ $content.= '</div>';
58
+
59
+ $content.= '</div>';
60
+
61
+ return $content;
62
+
63
+
64
+ }
65
+
66
+
67
+ }
app/code/community/Ip/Promopdf/Block/Promo.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Ip_Promopdf_Block_Promo extends Mage_Adminhtml_Block_System_Config_Form_Fieldset {
4
+
5
+ protected function _prepareLayout() {
6
+ parent::_prepareLayout();
7
+
8
+ }
9
+
10
+ public function render(Varien_Data_Form_Element_Abstract $element) {
11
+ $content = '<p></p>';
12
+ $content.= '<style>';
13
+ $content.= '.promotion {
14
+ background:#FAFAFA;
15
+ border: 1px solid #CCCCCC;
16
+ margin-bottom: 10px;
17
+ padding: 10px;
18
+ height:auto;
19
+
20
+ }
21
+ .promotion a {
22
+ font-weight:bold;
23
+ }
24
+ .promotion h3 {
25
+ color: #BC0000;
26
+ font-size: 20px;
27
+ margin-bottom: 30px;
28
+ text-transform: uppercase;
29
+ }
30
+ .contact-type {
31
+ color: #EA7601;
32
+ font-weight:bold;
33
+ }
34
+ .promotion img {
35
+ float:left;
36
+ height:255px;
37
+ width:360px;
38
+ }
39
+ .promotion .info {
40
+ border: 1px solid #CCCCCC;
41
+ background:#E7EFEF;
42
+ padding: 5px 10px 0 5px;
43
+ margin-left:370px;
44
+ height:250px;
45
+ }
46
+ ';
47
+ $content.= '</style>';
48
+
49
+
50
+ $content.= '<div class="promotion">';
51
+ $content.= '<a href="http://www.magazento.com/english/magento-ext/magazento-extensions/pdf-export" target="_blank"><img src="'.Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN).'frontend/base/default/ip_promopdf/logo_pdf.jpg" alt="www.ecommerceoffice.com" /></a>';
52
+ $content.= '<div class="info">';
53
+ $content.= '<h3>PRO - PROFESSIONAL PDF EXPORT</h3>';
54
+ $content.= '<a href="http://www.linkedin.com/pub/ivan-proskuryakov/31/200/316" target="_blank"> EXTENSION PAGE @ MAGENTOCONNECT </a> <br/><br/>';
55
+ $content.= '<a href="http://www.magazento.com/english/magento-ext/magazento-extensions/pdf-export" target="_blank"> VISIT PURCHASE PAGE </a> <br/><br/>';
56
+ $content.= '<p>PDF EXPORT for Magento is a professional PDF solution, with it you can generate printable copy of ALL store products! PDF EXPORT also lets your customers to generate PDF\'s of ALL products directly from category page of your website without other 3rd party websites or applications. <br/><b>Export ALL product catalog, categories and single products in few clicks!</b></p>';
57
+ $content.= '</div>';
58
+ $content.= '</div>';
59
+
60
+ $content.= '<div class="promotion">';
61
+ $content.= '<a href="http://www.magazento.com/english/magento-ext/magazento-extensions/pdf-export" target="_blank"><img src="'.Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN).'frontend/base/default/ip_promopdf/logo_pdffree.jpg" alt="www.ecommerceoffice.com" /></a>';
62
+ $content.= '<div class="info">';
63
+ $content.= '<h3>FREE - ONLY CATEGORIES AND PRODUCTS</h3>';
64
+ $content.= '<a href="http://www.magazento.com/english/magento-ext/magazento-extensions/free-pdf-export" target="_blank">VISIT DOWNLOAD PAGE </a> <br/><br/>';
65
+ $content.= '<p>FREE PDF is FREE extensions similar to PDF EXPORT, but with some limitations. With PDF FREE your customers can export only products they see on screen(current category,not ALL products ) or generate PDF with 1 product from current product page. PDF FREE uses the old free algorithm, so it is slower than PDF EXPORT and you can\'t export all your products to PDF file. </p>';
66
+ $content.= '</div>';
67
+
68
+ $content.= '</div>';
69
+
70
+ return $content;
71
+
72
+
73
+ }
74
+
75
+
76
+ }
app/code/community/Ip/Promopdf/Helper/Data.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Created on April 4, 2012
4
+ * Author Ivan Proskuryakov - volgodark@gmail.com - ecommerceoffice.com
5
+ * Copyright Proskuryakov Ivan. ecommerceoffice.com © 2011. All Rights Reserved.
6
+ * Single Use, Limited Licence and Single Use No Resale Licence ["Single Use"]
7
+ */
8
+ ?>
9
+ <?php class Ip_Promopdf_Helper_Data extends Mage_Core_Helper_Abstract {
10
+
11
+ }
12
+
13
+
app/code/community/Ip/Promopdf/etc/config.xml ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <config>
3
+ <modules>
4
+ <Ip_Promopdf>
5
+ <version>1.0.0</version>
6
+ </Ip_Promopdf>
7
+ </modules>
8
+ <global>
9
+ <blocks>
10
+ <promopdf>
11
+ <class>Ip_Promopdf_Block</class>
12
+ </promopdf>
13
+ </blocks>
14
+ <helpers>
15
+ <promopdf>
16
+ <class>Ip_Promopdf_Helper</class>
17
+ </promopdf>
18
+ </helpers>
19
+ </global>
20
+ <adminhtml>
21
+ <acl>
22
+ <resources>
23
+ <admin>
24
+ <children>
25
+ <system>
26
+ <children>
27
+ <config>
28
+ <children>
29
+ <promopdf>
30
+ <title>promopdf</title>
31
+ <sort_order>101</sort_order>
32
+ </promopdf>
33
+ </children>
34
+ </config>
35
+ </children>
36
+ </system>
37
+ </children>
38
+ </admin>
39
+ </resources>
40
+ </acl>
41
+ </adminhtml>
42
+
43
+ </config>
app/code/community/Ip/Promopdf/etc/system.xml ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <ip translate="label">
5
+ <label>EcommerceOffice.com</label>
6
+ <sort_order>250</sort_order>
7
+ </ip>
8
+ </tabs>
9
+ <sections>
10
+ <promopdf translate="label" module="promopdf">
11
+ <label>PDF Download</label>
12
+ <tab>ip</tab>
13
+ <frontend_type>text</frontend_type>
14
+ <sort_order>100</sort_order>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>1</show_in_website>
17
+ <show_in_store>1</show_in_store>
18
+ <groups>
19
+ <promo>
20
+ <frontend_model>promopdf/promo</frontend_model>
21
+ <sort_order>99999</sort_order>
22
+ <show_in_default>1</show_in_default>
23
+ <show_in_website>1</show_in_website>
24
+ <show_in_store>1</show_in_store>
25
+ </promo>
26
+ <developer>
27
+ <frontend_model>promopdf/developer</frontend_model>
28
+ <sort_order>999999</sort_order>
29
+ <show_in_default>1</show_in_default>
30
+ <show_in_website>1</show_in_website>
31
+ <show_in_store>1</show_in_store>
32
+ </developer>
33
+ </groups>
34
+ </promopdf>
35
+ </sections>
36
+ </config>
lib/ip_pdffree/dompdf6/lib/res/broken_image.png DELETED
Binary file
lib/ip_pdffree/dompdf6/lib/res/class.pdf.php DELETED
@@ -1,4969 +0,0 @@
1
- <?php
2
- /**
3
- * A PHP class to provide the basic functionality to create a pdf document without
4
- * any requirement for additional modules.
5
- *
6
- * Extended by Orion Richardson to support Unicode / UTF-8 characters using
7
- * TCPDF and others as a guide.
8
- *
9
- * @author Wayne Munro <pdf@ros.co.nz>
10
- * @author Orion Richardson <orionr@yahoo.com>
11
- * @author Helmut Tischer <htischer@weihenstephan.org>
12
- * @author Ryan H. Masten <ryan.masten@gmail.com>
13
- * @author Brian Sweeney <eclecticgeek@gmail.com>
14
- * @author Fabien M�nager <fabien.menager@gmail.com>
15
- * @version $Id: class.pdf.php 469 2012-02-05 22:25:30Z fabien.menager $
16
- * @license Public Domain http://creativecommons.org/licenses/publicdomain/
17
- * @package Cpdf
18
- */
19
- class Cpdf {
20
-
21
- /**
22
- * @var integer The current number of pdf objects in the document
23
- */
24
- public $numObj = 0;
25
-
26
- /**
27
- * @var array This array contains all of the pdf objects, ready for final assembly
28
- */
29
- public $objects = array();
30
-
31
- /**
32
- * @var integer The objectId (number within the objects array) of the document catalog
33
- */
34
- public $catalogId;
35
-
36
- /**
37
- * @var array Array carrying information about the fonts that the system currently knows about
38
- * Used to ensure that a font is not loaded twice, among other things
39
- */
40
- public $fonts = array();
41
-
42
- /**
43
- * @var string The default font metrics file to use if no other font has been loaded.
44
- * The path to the directory containing the font metrics should be included
45
- */
46
- public $defaultFont = './fonts/Helvetica.afm';
47
-
48
- /**
49
- * @string A record of the current font
50
- */
51
- public $currentFont = '';
52
-
53
- /**
54
- * @var string The current base font
55
- */
56
- public $currentBaseFont = '';
57
-
58
- /**
59
- * @var integer The number of the current font within the font array
60
- */
61
- public $currentFontNum = 0;
62
-
63
- /**
64
- * @var integer
65
- */
66
- public $currentNode;
67
-
68
- /**
69
- * @var integer Object number of the current page
70
- */
71
- public $currentPage;
72
-
73
- /**
74
- * @var integer Object number of the currently active contents block
75
- */
76
- public $currentContents;
77
-
78
- /**
79
- * @var integer Number of fonts within the system
80
- */
81
- public $numFonts = 0;
82
-
83
- /**
84
- * @var integer Number of graphic state resources used
85
- */
86
- private $numStates = 0;
87
-
88
- /**
89
- * @var array Current colour for fill operations, defaults to inactive value,
90
- * all three components should be between 0 and 1 inclusive when active
91
- */
92
- public $currentColour = null;
93
-
94
- /**
95
- * @var array Current colour for stroke operations (lines etc.)
96
- */
97
- public $currentStrokeColour = null;
98
-
99
- /**
100
- * @var string Current style that lines are drawn in
101
- */
102
- public $currentLineStyle = '';
103
-
104
- /**
105
- * @var array Current line transparency (partial graphics state)
106
- */
107
- public $currentLineTransparency = array("mode" => "Normal", "opacity" => 1.0);
108
-
109
- /**
110
- * array Current fill transparency (partial graphics state)
111
- */
112
- public $currentFillTransparency = array("mode" => "Normal", "opacity" => 1.0);
113
-
114
- /**
115
- * @var array An array which is used to save the state of the document, mainly the colours and styles
116
- * it is used to temporarily change to another state, the change back to what it was before
117
- */
118
- public $stateStack = array();
119
-
120
- /**
121
- * @var integer Number of elements within the state stack
122
- */
123
- public $nStateStack = 0;
124
-
125
- /**
126
- * @var integer Number of page objects within the document
127
- */
128
- public $numPages = 0;
129
-
130
- /**
131
- * @var array Object Id storage stack
132
- */
133
- public $stack = array();
134
-
135
- /**
136
- * @var integer Number of elements within the object Id storage stack
137
- */
138
- public $nStack = 0;
139
-
140
- /**
141
- * an array which contains information about the objects which are not firmly attached to pages
142
- * these have been added with the addObject function
143
- */
144
- public $looseObjects = array();
145
-
146
- /**
147
- * array contains infomation about how the loose objects are to be added to the document
148
- */
149
- public $addLooseObjects = array();
150
-
151
- /**
152
- * @var integer The objectId of the information object for the document
153
- * this contains authorship, title etc.
154
- */
155
- public $infoObject = 0;
156
-
157
- /**
158
- * @var integer Number of images being tracked within the document
159
- */
160
- public $numImages = 0;
161
-
162
- /**
163
- * @var array An array containing options about the document
164
- * it defaults to turning on the compression of the objects
165
- */
166
- public $options = array('compression'=>true);
167
-
168
- /**
169
- * @var integer The objectId of the first page of the document
170
- */
171
- public $firstPageId;
172
-
173
- /**
174
- * @var float Used to track the last used value of the inter-word spacing, this is so that it is known
175
- * when the spacing is changed.
176
- */
177
- public $wordSpaceAdjust = 0;
178
-
179
- /**
180
- * @var float Used to track the last used value of the inter-letter spacing, this is so that it is known
181
- * when the spacing is changed.
182
- */
183
- public $charSpaceAdjust = 0;
184
-
185
- /**
186
- * @var integer The object Id of the procset object
187
- */
188
- public $procsetObjectId;
189
-
190
- /**
191
- * @var array Store the information about the relationship between font families
192
- * this used so that the code knows which font is the bold version of another font, etc.
193
- * the value of this array is initialised in the constuctor function.
194
- */
195
- public $fontFamilies = array();
196
-
197
- /**
198
- * @var string Folder for php serialized formats of font metrics files.
199
- * If empty string, use same folder as original metrics files.
200
- * This can be passed in from class creator.
201
- * If this folder does not exist or is not writable, Cpdf will be **much** slower.
202
- * Because of potential trouble with php safe mode, folder cannot be created at runtime.
203
- */
204
- public $fontcache = '';
205
-
206
- /**
207
- * @var integer The version of the font metrics cache file.
208
- * This value must be manually incremented whenever the internal font data structure is modified.
209
- */
210
- public $fontcacheVersion = 5;
211
-
212
- /**
213
- * @var string Temporary folder.
214
- * If empty string, will attempty system tmp folder.
215
- * This can be passed in from class creator.
216
- * Only used for conversion of gd images to jpeg images.
217
- */
218
- public $tmp = '';
219
-
220
- /**
221
- * @var string Track if the current font is bolded or italicised
222
- */
223
- public $currentTextState = '';
224
-
225
- /**
226
- * @var string Messages are stored here during processing, these can be selected afterwards to give some useful debug information
227
- */
228
- public $messages = '';
229
-
230
- /**
231
- * @var string The ancryption array for the document encryption is stored here
232
- */
233
- public $arc4 = '';
234
-
235
- /**
236
- * @var integer The object Id of the encryption information
237
- */
238
- public $arc4_objnum = 0;
239
-
240
- /**
241
- * @var string The file identifier, used to uniquely identify a pdf document
242
- */
243
- public $fileIdentifier = '';
244
-
245
- /**
246
- * @var boolean A flag to say if a document is to be encrypted or not
247
- */
248
- public $encrypted = false;
249
-
250
- /**
251
- * @var string The encryption key for the encryption of all the document content (structure is not encrypted)
252
- */
253
- public $encryptionKey = '';
254
-
255
- /**
256
- * @var array Array which forms a stack to keep track of nested callback functions
257
- */
258
- public $callback = array();
259
-
260
- /**
261
- * @var integer The number of callback functions in the callback array
262
- */
263
- public $nCallback = 0;
264
-
265
- /**
266
- * @var array Store label->id pairs for named destinations, these will be used to replace internal links
267
- * done this way so that destinations can be defined after the location that links to them
268
- */
269
- public $destinations = array();
270
-
271
- /**
272
- * @var array Store the stack for the transaction commands, each item in here is a record of the values of all the
273
- * publiciables within the class, so that the user can rollback at will (from each 'start' command)
274
- * note that this includes the objects array, so these can be large.
275
- */
276
- public $checkpoint = '';
277
-
278
- /**
279
- * @var array Table of Image origin filenames and image labels which were already added with o_image().
280
- * Allows to merge identical images
281
- */
282
- public $imagelist = array();
283
-
284
- /**
285
- * @var boolean Whether the text passed in should be treated as Unicode or just local character set.
286
- */
287
- public $isUnicode = false;
288
-
289
- /**
290
- * @var string the JavaScript code of the document
291
- */
292
- public $javascript = '';
293
-
294
- /**
295
- * @var boolean whether the compression is possible
296
- */
297
- protected $compressionReady = false;
298
-
299
- /**
300
- * @var array Current page size
301
- */
302
- protected $currentPageSize = array("width" => 0, "height" => 0);
303
-
304
- /**
305
- * @var array All the chars that will be required in the font subsets
306
- */
307
- protected $stringSubsets = array();
308
-
309
- /**
310
- * @var string The target internal encoding
311
- */
312
- static protected $targetEncoding = 'iso-8859-1';
313
-
314
- /**
315
- * @var array The list of the core fonts
316
- */
317
- static protected $coreFonts = array(
318
- 'courier', 'courier-bold', 'courier-oblique', 'courier-boldoblique',
319
- 'helvetica', 'helvetica-bold', 'helvetica-oblique', 'helvetica-boldoblique',
320
- 'times-roman', 'times-bold', 'times-italic', 'times-bolditalic',
321
- 'symbol', 'zapfdingbats'
322
- );
323
-
324
- /**
325
- * class constructor
326
- * this will start a new document
327
- * @var array $pageSize Array of 4 numbers, defining the bottom left and upper right corner of the page. first two are normally zero.
328
- * @var boolean $isUnicode Whether text will be treated as Unicode or not.
329
- * @var string $fontcache The font cache folder
330
- * @var string $tmp The temporary folder
331
- */
332
- function __construct ($pageSize = array(0, 0, 612, 792), $isUnicode = false, $fontcache = '', $tmp = '') {
333
- $this->isUnicode = $isUnicode;
334
- $this->fontcache = $fontcache;
335
- $this->tmp = $tmp;
336
- $this->newDocument($pageSize);
337
-
338
- $this->compressionReady = function_exists('gzcompress');
339
-
340
- if ( in_array('Windows-1252', mb_list_encodings()) ) {
341
- self::$targetEncoding = 'Windows-1252';
342
- }
343
-
344
- // also initialize the font families that are known about already
345
- $this->setFontFamily('init');
346
- // $this->fileIdentifier = md5('xxxxxxxx'.time());
347
- }
348
-
349
- /**
350
- * Document object methods (internal use only)
351
- *
352
- * There is about one object method for each type of object in the pdf document
353
- * Each function has the same call list ($id,$action,$options).
354
- * $id = the object ID of the object, or what it is to be if it is being created
355
- * $action = a string specifying the action to be performed, though ALL must support:
356
- * 'new' - create the object with the id $id
357
- * 'out' - produce the output for the pdf object
358
- * $options = optional, a string or array containing the various parameters for the object
359
- *
360
- * These, in conjunction with the output function are the ONLY way for output to be produced
361
- * within the pdf 'file'.
362
- */
363
-
364
- /**
365
- *destination object, used to specify the location for the user to jump to, presently on opening
366
- */
367
- protected function o_destination($id, $action, $options = '') {
368
- if ($action !== 'new') {
369
- $o = & $this->objects[$id];
370
- }
371
-
372
- switch ($action) {
373
- case 'new':
374
- $this->objects[$id] = array('t'=>'destination', 'info'=>array());
375
- $tmp = '';
376
- switch ($options['type']) {
377
- case 'XYZ':
378
- case 'FitR':
379
- $tmp = ' '.$options['p3'].$tmp;
380
- case 'FitH':
381
- case 'FitV':
382
- case 'FitBH':
383
- case 'FitBV':
384
- $tmp = ' '.$options['p1'].' '.$options['p2'].$tmp;
385
- case 'Fit':
386
- case 'FitB':
387
- $tmp = $options['type'].$tmp;
388
- $this->objects[$id]['info']['string'] = $tmp;
389
- $this->objects[$id]['info']['page'] = $options['page'];
390
- }
391
- break;
392
-
393
- case 'out':
394
- $tmp = $o['info'];
395
- $res = "\n$id 0 obj\n".'['.$tmp['page'].' 0 R /'.$tmp['string']."]\nendobj";
396
- return $res;
397
- }
398
- }
399
-
400
- /**
401
- * set the viewer preferences
402
- */
403
- protected function o_viewerPreferences($id, $action, $options = '') {
404
- if ($action !== 'new') {
405
- $o = & $this->objects[$id];
406
- }
407
-
408
- switch ($action) {
409
- case 'new':
410
- $this->objects[$id] = array('t'=>'viewerPreferences', 'info'=>array());
411
- break;
412
-
413
- case 'add':
414
- foreach($options as $k=>$v) {
415
- switch ($k) {
416
- case 'HideToolbar':
417
- case 'HideMenubar':
418
- case 'HideWindowUI':
419
- case 'FitWindow':
420
- case 'CenterWindow':
421
- case 'NonFullScreenPageMode':
422
- case 'Direction':
423
- $o['info'][$k] = $v;
424
- break;
425
- }
426
- }
427
- break;
428
-
429
- case 'out':
430
- $res = "\n$id 0 obj\n<< ";
431
- foreach($o['info'] as $k=>$v) {
432
- $res.= "\n/$k $v";
433
- }
434
- $res.= "\n>>\n";
435
- return $res;
436
- }
437
- }
438
-
439
- /**
440
- * define the document catalog, the overall controller for the document
441
- */
442
- protected function o_catalog($id, $action, $options = '') {
443
- if ($action !== 'new') {
444
- $o = & $this->objects[$id];
445
- }
446
-
447
- switch ($action) {
448
- case 'new':
449
- $this->objects[$id] = array('t'=>'catalog', 'info'=>array());
450
- $this->catalogId = $id;
451
- break;
452
-
453
- case 'outlines':
454
- case 'pages':
455
- case 'openHere':
456
- case 'javascript':
457
- $o['info'][$action] = $options;
458
- break;
459
-
460
- case 'viewerPreferences':
461
- if (!isset($o['info']['viewerPreferences'])) {
462
- $this->numObj++;
463
- $this->o_viewerPreferences($this->numObj, 'new');
464
- $o['info']['viewerPreferences'] = $this->numObj;
465
- }
466
-
467
- $vp = $o['info']['viewerPreferences'];
468
- $this->o_viewerPreferences($vp, 'add', $options);
469
-
470
- break;
471
-
472
- case 'out':
473
- $res = "\n$id 0 obj\n<< /Type /Catalog";
474
-
475
- foreach($o['info'] as $k=>$v) {
476
- switch ($k) {
477
- case 'outlines':
478
- $res.= "\n/Outlines $v 0 R";
479
- break;
480
-
481
- case 'pages':
482
- $res.= "\n/Pages $v 0 R";
483
- break;
484
-
485
- case 'viewerPreferences':
486
- $res.= "\n/ViewerPreferences $v 0 R";
487
- break;
488
-
489
- case 'openHere':
490
- $res.= "\n/OpenAction $v 0 R";
491
- break;
492
-
493
- case 'javascript':
494
- $res.= "\n/Names <</JavaScript $v 0 R>>";
495
- break;
496
- }
497
- }
498
-
499
- $res.= " >>\nendobj";
500
- return $res;
501
- }
502
- }
503
-
504
- /**
505
- * object which is a parent to the pages in the document
506
- */
507
- protected function o_pages($id, $action, $options = '') {
508
- if ($action !== 'new') {
509
- $o = & $this->objects[$id];
510
- }
511
-
512
- switch ($action) {
513
- case 'new':
514
- $this->objects[$id] = array('t'=>'pages', 'info'=>array());
515
- $this->o_catalog($this->catalogId, 'pages', $id);
516
- break;
517
-
518
- case 'page':
519
- if (!is_array($options)) {
520
- // then it will just be the id of the new page
521
- $o['info']['pages'][] = $options;
522
- } else {
523
- // then it should be an array having 'id','rid','pos', where rid=the page to which this one will be placed relative
524
- // and pos is either 'before' or 'after', saying where this page will fit.
525
- if (isset($options['id']) && isset($options['rid']) && isset($options['pos'])) {
526
- $i = array_search($options['rid'], $o['info']['pages']);
527
- if (isset($o['info']['pages'][$i]) && $o['info']['pages'][$i] == $options['rid']) {
528
-
529
- // then there is a match
530
- // make a space
531
- switch ($options['pos']) {
532
- case 'before':
533
- $k = $i;
534
- break;
535
-
536
- case 'after':
537
- $k = $i+1;
538
- break;
539
-
540
- default:
541
- $k = -1;
542
- break;
543
- }
544
-
545
- if ($k >= 0) {
546
- for ($j = count($o['info']['pages']) -1;$j >= $k;$j--) {
547
- $o['info']['pages'][$j+1] = $o['info']['pages'][$j];
548
- }
549
-
550
- $o['info']['pages'][$k] = $options['id'];
551
- }
552
- }
553
- }
554
- }
555
- break;
556
-
557
- case 'procset':
558
- $o['info']['procset'] = $options;
559
- break;
560
-
561
- case 'mediaBox':
562
- $o['info']['mediaBox'] = $options;
563
- // which should be an array of 4 numbers
564
- $this->currentPageSize = array('width' => $options[2], 'height' => $options[3]);
565
- break;
566
-
567
- case 'font':
568
- $o['info']['fonts'][] = array('objNum'=>$options['objNum'], 'fontNum'=>$options['fontNum']);
569
- break;
570
-
571
- case 'extGState':
572
- $o['info']['extGStates'][] = array('objNum' => $options['objNum'], 'stateNum' => $options['stateNum']);
573
- break;
574
-
575
- case 'xObject':
576
- $o['info']['xObjects'][] = array('objNum'=>$options['objNum'], 'label'=>$options['label']);
577
- break;
578
-
579
- case 'out':
580
- if (count($o['info']['pages'])) {
581
- $res = "\n$id 0 obj\n<< /Type /Pages\n/Kids [";
582
- foreach($o['info']['pages'] as $v) {
583
- $res.= "$v 0 R\n";
584
- }
585
-
586
- $res.= "]\n/Count ".count($this->objects[$id]['info']['pages']);
587
-
588
- if ( (isset($o['info']['fonts']) && count($o['info']['fonts'])) ||
589
- isset($o['info']['procset']) ||
590
- (isset($o['info']['extGStates']) && count($o['info']['extGStates']))) {
591
- $res.= "\n/Resources <<";
592
-
593
- if (isset($o['info']['procset'])) {
594
- $res.= "\n/ProcSet ".$o['info']['procset']." 0 R";
595
- }
596
-
597
- if (isset($o['info']['fonts']) && count($o['info']['fonts'])) {
598
- $res.= "\n/Font << ";
599
- foreach($o['info']['fonts'] as $finfo) {
600
- $res.= "\n/F".$finfo['fontNum']." ".$finfo['objNum']." 0 R";
601
- }
602
- $res.= "\n>>";
603
- }
604
-
605
- if (isset($o['info']['xObjects']) && count($o['info']['xObjects'])) {
606
- $res.= "\n/XObject << ";
607
- foreach($o['info']['xObjects'] as $finfo) {
608
- $res.= "\n/".$finfo['label']." ".$finfo['objNum']." 0 R";
609
- }
610
- $res.= "\n>>";
611
- }
612
-
613
- if ( isset($o['info']['extGStates']) && count($o['info']['extGStates'])) {
614
- $res.= "\n/ExtGState << ";
615
- foreach ($o['info']['extGStates'] as $gstate) {
616
- $res.= "\n/GS" . $gstate['stateNum'] . " " . $gstate['objNum'] . " 0 R";
617
- }
618
- $res.= "\n>>";
619
- }
620
-
621
- $res.= "\n>>";
622
- if (isset($o['info']['mediaBox'])) {
623
- $tmp = $o['info']['mediaBox'];
624
- $res.= "\n/MediaBox [".sprintf('%.3F %.3F %.3F %.3F', $tmp[0], $tmp[1], $tmp[2], $tmp[3]) .']';
625
- }
626
- }
627
-
628
- $res.= "\n >>\nendobj";
629
- } else {
630
- $res = "\n$id 0 obj\n<< /Type /Pages\n/Count 0\n>>\nendobj";
631
- }
632
-
633
- return $res;
634
- }
635
- }
636
-
637
- /**
638
- * define the outlines in the doc, empty for now
639
- */
640
- protected function o_outlines($id, $action, $options = '') {
641
- if ($action !== 'new') {
642
- $o = & $this->objects[$id];
643
- }
644
-
645
- switch ($action) {
646
- case 'new':
647
- $this->objects[$id] = array('t'=>'outlines', 'info'=>array('outlines'=>array()));
648
- $this->o_catalog($this->catalogId, 'outlines', $id);
649
- break;
650
-
651
- case 'outline':
652
- $o['info']['outlines'][] = $options;
653
- break;
654
-
655
- case 'out':
656
- if (count($o['info']['outlines'])) {
657
- $res = "\n$id 0 obj\n<< /Type /Outlines /Kids [";
658
- foreach($o['info']['outlines'] as $v) {
659
- $res.= "$v 0 R ";
660
- }
661
-
662
- $res.= "] /Count ".count($o['info']['outlines']) ." >>\nendobj";
663
- } else {
664
- $res = "\n$id 0 obj\n<< /Type /Outlines /Count 0 >>\nendobj";
665
- }
666
-
667
- return $res;
668
- }
669
- }
670
-
671
- /**
672
- * an object to hold the font description
673
- */
674
- protected function o_font($id, $action, $options = '') {
675
- if ($action !== 'new') {
676
- $o = & $this->objects[$id];
677
- }
678
-
679
- switch ($action) {
680
- case 'new':
681
- $this->objects[$id] = array('t' => 'font', 'info' => array('name' => $options['name'], 'fontFileName' => $options['fontFileName'], 'SubType' => 'Type1'));
682
- $fontNum = $this->numFonts;
683
- $this->objects[$id]['info']['fontNum'] = $fontNum;
684
-
685
- // deal with the encoding and the differences
686
- if (isset($options['differences'])) {
687
- // then we'll need an encoding dictionary
688
- $this->numObj++;
689
- $this->o_fontEncoding($this->numObj, 'new', $options);
690
- $this->objects[$id]['info']['encodingDictionary'] = $this->numObj;
691
- } else if (isset($options['encoding'])) {
692
- // we can specify encoding here
693
- switch ($options['encoding']) {
694
- case 'WinAnsiEncoding':
695
- case 'MacRomanEncoding':
696
- case 'MacExpertEncoding':
697
- $this->objects[$id]['info']['encoding'] = $options['encoding'];
698
- break;
699
-
700
- case 'none':
701
- break;
702
-
703
- default:
704
- $this->objects[$id]['info']['encoding'] = 'WinAnsiEncoding';
705
- break;
706
- }
707
- } else {
708
- $this->objects[$id]['info']['encoding'] = 'WinAnsiEncoding';
709
- }
710
-
711
- if ($this->fonts[$options['fontFileName']]['isUnicode']) {
712
- // For Unicode fonts, we need to incorporate font data into
713
- // sub-sections that are linked from the primary font section.
714
- // Look at o_fontGIDtoCID and o_fontDescendentCID functions
715
- // for more informaiton.
716
- //
717
- // All of this code is adapted from the excellent changes made to
718
- // transform FPDF to TCPDF (http://tcpdf.sourceforge.net/)
719
-
720
- $toUnicodeId = ++$this->numObj;
721
- $this->o_contents($toUnicodeId, 'new', 'raw');
722
- $this->objects[$id]['info']['toUnicode'] = $toUnicodeId;
723
-
724
- $stream = <<<EOT
725
- /CIDInit /ProcSet findresource begin
726
- 12 dict begin
727
- begincmap
728
- /CIDSystemInfo
729
- <</Registry (Adobe)
730
- /Ordering (UCS)
731
- /Supplement 0
732
- >> def
733
- /CMapName /Adobe-Identity-UCS def
734
- /CMapType 2 def
735
- 1 begincodespacerange
736
- <0000> <FFFF>
737
- endcodespacerange
738
- 1 beginbfrange
739
- <0000> <FFFF> <0000>
740
- endbfrange
741
- endcmap
742
- CMapName currentdict /CMap defineresource pop
743
- end
744
- end
745
- EOT;
746
-
747
- $res = "<</Length " . mb_strlen($stream, '8bit') . " >>\n";
748
- $res .= "stream\n" . $stream . "endstream";
749
-
750
- $this->objects[$toUnicodeId]['c'] = $res;
751
-
752
- $cidFontId = ++$this->numObj;
753
- $this->o_fontDescendentCID($cidFontId, 'new', $options);
754
- $this->objects[$id]['info']['cidFont'] = $cidFontId;
755
- }
756
-
757
- // also tell the pages node about the new font
758
- $this->o_pages($this->currentNode, 'font', array('fontNum' => $fontNum, 'objNum' => $id));
759
- break;
760
-
761
- case 'add':
762
- foreach ($options as $k => $v) {
763
- switch ($k) {
764
- case 'BaseFont':
765
- $o['info']['name'] = $v;
766
- break;
767
- case 'FirstChar':
768
- case 'LastChar':
769
- case 'Widths':
770
- case 'FontDescriptor':
771
- case 'SubType':
772
- $this->addMessage('o_font '.$k." : ".$v);
773
- $o['info'][$k] = $v;
774
- break;
775
- }
776
- }
777
-
778
- // pass values down to descendent font
779
- if (isset($o['info']['cidFont'])) {
780
- $this->o_fontDescendentCID($o['info']['cidFont'], 'add', $options);
781
- }
782
- break;
783
-
784
- case 'out':
785
- if ($this->fonts[$this->objects[$id]['info']['fontFileName']]['isUnicode']) {
786
- // For Unicode fonts, we need to incorporate font data into
787
- // sub-sections that are linked from the primary font section.
788
- // Look at o_fontGIDtoCID and o_fontDescendentCID functions
789
- // for more informaiton.
790
- //
791
- // All of this code is adapted from the excellent changes made to
792
- // transform FPDF to TCPDF (http://tcpdf.sourceforge.net/)
793
-
794
- $res = "\n$id 0 obj\n<</Type /Font\n/Subtype /Type0\n";
795
- $res.= "/BaseFont /".$o['info']['name']."\n";
796
-
797
- // The horizontal identity mapping for 2-byte CIDs; may be used
798
- // with CIDFonts using any Registry, Ordering, and Supplement values.
799
- $res.= "/Encoding /Identity-H\n";
800
- $res.= "/DescendantFonts [".$o['info']['cidFont']." 0 R]\n";
801
- $res.= "/ToUnicode ".$o['info']['toUnicode']." 0 R\n";
802
- $res.= ">>\n";
803
- $res.= "endobj";
804
- } else {
805
- $res = "\n$id 0 obj\n<< /Type /Font\n/Subtype /".$o['info']['SubType']."\n";
806
- $res.= "/Name /F".$o['info']['fontNum']."\n";
807
- $res.= "/BaseFont /".$o['info']['name']."\n";
808
-
809
- if (isset($o['info']['encodingDictionary'])) {
810
- // then place a reference to the dictionary
811
- $res.= "/Encoding ".$o['info']['encodingDictionary']." 0 R\n";
812
- } else if (isset($o['info']['encoding'])) {
813
- // use the specified encoding
814
- $res.= "/Encoding /".$o['info']['encoding']."\n";
815
- }
816
-
817
- if (isset($o['info']['FirstChar'])) {
818
- $res.= "/FirstChar ".$o['info']['FirstChar']."\n";
819
- }
820
-
821
- if (isset($o['info']['LastChar'])) {
822
- $res.= "/LastChar ".$o['info']['LastChar']."\n";
823
- }
824
-
825
- if (isset($o['info']['Widths'])) {
826
- $res.= "/Widths ".$o['info']['Widths']." 0 R\n";
827
- }
828
-
829
- if (isset($o['info']['FontDescriptor'])) {
830
- $res.= "/FontDescriptor ".$o['info']['FontDescriptor']." 0 R\n";
831
- }
832
-
833
- $res.= ">>\n";
834
- $res.= "endobj";
835
- }
836
-
837
- return $res;
838
- }
839
- }
840
-
841
- /**
842
- * a font descriptor, needed for including additional fonts
843
- */
844
- protected function o_fontDescriptor($id, $action, $options = '') {
845
- if ($action !== 'new') {
846
- $o = & $this->objects[$id];
847
- }
848
-
849
- switch ($action) {
850
- case 'new':
851
- $this->objects[$id] = array('t'=>'fontDescriptor', 'info'=>$options);
852
- break;
853
-
854
- case 'out':
855
- $res = "\n$id 0 obj\n<< /Type /FontDescriptor\n";
856
- foreach ($o['info'] as $label => $value) {
857
- switch ($label) {
858
- case 'Ascent':
859
- case 'CapHeight':
860
- case 'Descent':
861
- case 'Flags':
862
- case 'ItalicAngle':
863
- case 'StemV':
864
- case 'AvgWidth':
865
- case 'Leading':
866
- case 'MaxWidth':
867
- case 'MissingWidth':
868
- case 'StemH':
869
- case 'XHeight':
870
- case 'CharSet':
871
- if (mb_strlen($value, '8bit')) {
872
- $res.= "/$label $value\n";
873
- }
874
-
875
- break;
876
- case 'FontFile':
877
- case 'FontFile2':
878
- case 'FontFile3':
879
- $res.= "/$label $value 0 R\n";
880
- break;
881
-
882
- case 'FontBBox':
883
- $res.= "/$label [$value[0] $value[1] $value[2] $value[3]]\n";
884
- break;
885
-
886
- case 'FontName':
887
- $res.= "/$label /$value\n";
888
- break;
889
- }
890
- }
891
-
892
- $res.= ">>\nendobj";
893
-
894
- return $res;
895
- }
896
- }
897
-
898
- /**
899
- * the font encoding
900
- */
901
- protected function o_fontEncoding($id, $action, $options = '') {
902
- if ($action !== 'new') {
903
- $o = & $this->objects[$id];
904
- }
905
-
906
- switch ($action) {
907
- case 'new':
908
- // the options array should contain 'differences' and maybe 'encoding'
909
- $this->objects[$id] = array('t'=>'fontEncoding', 'info'=>$options);
910
- break;
911
-
912
- case 'out':
913
- $res = "\n$id 0 obj\n<< /Type /Encoding\n";
914
- if (!isset($o['info']['encoding'])) {
915
- $o['info']['encoding'] = 'WinAnsiEncoding';
916
- }
917
-
918
- if ($o['info']['encoding'] !== 'none') {
919
- $res.= "/BaseEncoding /".$o['info']['encoding']."\n";
920
- }
921
-
922
- $res.= "/Differences \n[";
923
-
924
- $onum = -100;
925
-
926
- foreach($o['info']['differences'] as $num=>$label) {
927
- if ($num != $onum+1) {
928
- // we cannot make use of consecutive numbering
929
- $res.= "\n$num /$label";
930
- } else {
931
- $res.= " /$label";
932
- }
933
-
934
- $onum = $num;
935
- }
936
-
937
- $res.= "\n]\n>>\nendobj";
938
- return $res;
939
- }
940
- }
941
-
942
- /**
943
- * a descendent cid font, needed for unicode fonts
944
- */
945
- protected function o_fontDescendentCID($id, $action, $options = '') {
946
- if ($action !== 'new') {
947
- $o = & $this->objects[$id];
948
- }
949
-
950
- switch ($action) {
951
- case 'new':
952
- $this->objects[$id] = array('t'=>'fontDescendentCID', 'info'=>$options);
953
-
954
- // we need a CID system info section
955
- $cidSystemInfoId = ++$this->numObj;
956
- $this->o_contents($cidSystemInfoId, 'new', 'raw');
957
- $this->objects[$id]['info']['cidSystemInfo'] = $cidSystemInfoId;
958
- $res= "<</Registry (Adobe)\n"; // A string identifying an issuer of character collections
959
- $res.= "/Ordering (UCS)\n"; // A string that uniquely names a character collection issued by a specific registry
960
- $res.= "/Supplement 0\n"; // The supplement number of the character collection.
961
- $res.= ">>";
962
- $this->objects[$cidSystemInfoId]['c'] = $res;
963
-
964
- // and a CID to GID map
965
- $cidToGidMapId = ++$this->numObj;
966
- $this->o_fontGIDtoCIDMap($cidToGidMapId, 'new', $options);
967
- $this->objects[$id]['info']['cidToGidMap'] = $cidToGidMapId;
968
- break;
969
-
970
- case 'add':
971
- foreach ($options as $k => $v) {
972
- switch ($k) {
973
- case 'BaseFont':
974
- $o['info']['name'] = $v;
975
- break;
976
-
977
- case 'FirstChar':
978
- case 'LastChar':
979
- case 'MissingWidth':
980
- case 'FontDescriptor':
981
- case 'SubType':
982
- $this->addMessage("o_fontDescendentCID $k : $v");
983
- $o['info'][$k] = $v;
984
- break;
985
- }
986
- }
987
-
988
- // pass values down to cid to gid map
989
- $this->o_fontGIDtoCIDMap($o['info']['cidToGidMap'], 'add', $options);
990
- break;
991
-
992
- case 'out':
993
- $res = "\n$id 0 obj\n";
994
- $res.= "<</Type /Font\n";
995
- $res.= "/Subtype /CIDFontType2\n";
996
- $res.= "/BaseFont /".$o['info']['name']."\n";
997
- $res.= "/CIDSystemInfo ".$o['info']['cidSystemInfo']." 0 R\n";
998
- // if (isset($o['info']['FirstChar'])) {
999
- // $res.= "/FirstChar ".$o['info']['FirstChar']."\n";
1000
- // }
1001
-
1002
- // if (isset($o['info']['LastChar'])) {
1003
- // $res.= "/LastChar ".$o['info']['LastChar']."\n";
1004
- // }
1005
- if (isset($o['info']['FontDescriptor'])) {
1006
- $res.= "/FontDescriptor ".$o['info']['FontDescriptor']." 0 R\n";
1007
- }
1008
-
1009
- if (isset($o['info']['MissingWidth'])) {
1010
- $res.= "/DW ".$o['info']['MissingWidth']."\n";
1011
- }
1012
-
1013
- if (isset($o['info']['fontFileName']) && isset($this->fonts[$o['info']['fontFileName']]['CIDWidths'])) {
1014
- $cid_widths = &$this->fonts[$o['info']['fontFileName']]['CIDWidths'];
1015
- $w = '';
1016
- foreach ($cid_widths as $cid => $width) {
1017
- $w .= "$cid [$width] ";
1018
- }
1019
- $res.= "/W [$w]\n";
1020
- }
1021
-
1022
- $res.= "/CIDToGIDMap ".$o['info']['cidToGidMap']." 0 R\n";
1023
- $res.= ">>\n";
1024
- $res.= "endobj";
1025
-
1026
- return $res;
1027
- }
1028
- }
1029
-
1030
- /**
1031
- * a font glyph to character map, needed for unicode fonts
1032
- */
1033
- protected function o_fontGIDtoCIDMap($id, $action, $options = '') {
1034
- if ($action !== 'new') {
1035
- $o = & $this->objects[$id];
1036
- }
1037
-
1038
- switch ($action) {
1039
- case 'new':
1040
- $this->objects[$id] = array('t'=>'fontGIDtoCIDMap', 'info'=>$options);
1041
- break;
1042
-
1043
- case 'out':
1044
- $res = "\n$id 0 obj\n";
1045
- $fontFileName = $o['info']['fontFileName'];
1046
- $tmp = $this->fonts[$fontFileName]['CIDtoGID'] = base64_decode($this->fonts[$fontFileName]['CIDtoGID']);
1047
-
1048
- $compressed = isset($this->fonts[$fontFileName]['CIDtoGID_Compressed']) &&
1049
- $this->fonts[$fontFileName]['CIDtoGID_Compressed'];
1050
-
1051
- if (!$compressed && isset($o['raw'])) {
1052
- $res.= $tmp;
1053
- } else {
1054
- $res.= "<<";
1055
-
1056
- if (!$compressed && $this->compressionReady && $this->options['compression']) {
1057
- // then implement ZLIB based compression on this content stream
1058
- $compressed = true;
1059
- $tmp = gzcompress($tmp, 6);
1060
- }
1061
- if ($compressed) {
1062
- $res.= "\n/Filter /FlateDecode";
1063
- }
1064
-
1065
- $res.= "\n/Length ".mb_strlen($tmp, '8bit') .">>\nstream\n$tmp\nendstream";
1066
- }
1067
-
1068
- $res.= "\nendobj";
1069
- return $res;
1070
- }
1071
- }
1072
-
1073
- /**
1074
- * the document procset, solves some problems with printing to old PS printers
1075
- */
1076
- protected function o_procset($id, $action, $options = '') {
1077
- if ($action !== 'new') {
1078
- $o = & $this->objects[$id];
1079
- }
1080
-
1081
- switch ($action) {
1082
- case 'new':
1083
- $this->objects[$id] = array('t'=>'procset', 'info'=>array('PDF'=>1, 'Text'=>1));
1084
- $this->o_pages($this->currentNode, 'procset', $id);
1085
- $this->procsetObjectId = $id;
1086
- break;
1087
-
1088
- case 'add':
1089
- // this is to add new items to the procset list, despite the fact that this is considered
1090
- // obselete, the items are required for printing to some postscript printers
1091
- switch ($options) {
1092
- case 'ImageB':
1093
- case 'ImageC':
1094
- case 'ImageI':
1095
- $o['info'][$options] = 1;
1096
- break;
1097
- }
1098
- break;
1099
-
1100
- case 'out':
1101
- $res = "\n$id 0 obj\n[";
1102
- foreach ($o['info'] as $label=>$val) {
1103
- $res.= "/$label ";
1104
- }
1105
- $res.= "]\nendobj";
1106
- return $res;
1107
- }
1108
- }
1109
-
1110
- /**
1111
- * define the document information
1112
- */
1113
- protected function o_info($id, $action, $options = '') {
1114
- if ($action !== 'new') {
1115
- $o = & $this->objects[$id];
1116
- }
1117
-
1118
- switch ($action) {
1119
- case 'new':
1120
- $this->infoObject = $id;
1121
- $date = 'D:'.@date('Ymd');
1122
- $this->objects[$id] = array('t'=>'info', 'info'=>array('Creator'=>'R and OS php pdf writer, http://www.ros.co.nz', 'CreationDate'=>$date));
1123
- break;
1124
- case 'Title':
1125
- case 'Author':
1126
- case 'Subject':
1127
- case 'Keywords':
1128
- case 'Creator':
1129
- case 'Producer':
1130
- case 'CreationDate':
1131
- case 'ModDate':
1132
- case 'Trapped':
1133
- $o['info'][$action] = $options;
1134
- break;
1135
-
1136
- case 'out':
1137
- if ($this->encrypted) {
1138
- $this->encryptInit($id);
1139
- }
1140
-
1141
- $res = "\n$id 0 obj\n<<\n";
1142
- foreach ($o['info'] as $k=>$v) {
1143
- $res.= "/$k (";
1144
- // dates must be outputted as-is, without Unicode transformations
1145
- $raw = ($k === 'CreationDate' || $k === 'ModDate');
1146
- $c = $v;
1147
-
1148
- if ($this->encrypted) {
1149
- $c = $this->ARC4($c);
1150
- }
1151
-
1152
- $res.= ($raw) ? $c : $this->filterText($c);
1153
- $res.= ")\n";
1154
- }
1155
-
1156
- $res.= ">>\nendobj";
1157
- return $res;
1158
- }
1159
- }
1160
-
1161
- /**
1162
- * an action object, used to link to URLS initially
1163
- */
1164
- protected function o_action($id, $action, $options = '') {
1165
- if ($action !== 'new') {
1166
- $o = & $this->objects[$id];
1167
- }
1168
-
1169
- switch ($action) {
1170
- case 'new':
1171
- if (is_array($options)) {
1172
- $this->objects[$id] = array('t'=>'action', 'info'=>$options, 'type'=>$options['type']);
1173
- } else {
1174
- // then assume a URI action
1175
- $this->objects[$id] = array('t'=>'action', 'info'=>$options, 'type'=>'URI');
1176
- }
1177
- break;
1178
-
1179
- case 'out':
1180
- if ($this->encrypted) {
1181
- $this->encryptInit($id);
1182
- }
1183
-
1184
- $res = "\n$id 0 obj\n<< /Type /Action";
1185
- switch ($o['type']) {
1186
- case 'ilink':
1187
- if (!isset($this->destinations[(string)$o['info']['label']])) break;
1188
-
1189
- // there will be an 'label' setting, this is the name of the destination
1190
- $res.= "\n/S /GoTo\n/D ".$this->destinations[(string)$o['info']['label']]." 0 R";
1191
- break;
1192
-
1193
- case 'URI':
1194
- $res.= "\n/S /URI\n/URI (";
1195
- if ($this->encrypted) {
1196
- $res.= $this->filterText($this->ARC4($o['info']), true, false);
1197
- } else {
1198
- $res.= $this->filterText($o['info'], true, false);
1199
- }
1200
-
1201
- $res.= ")";
1202
- break;
1203
- }
1204
-
1205
- $res.= "\n>>\nendobj";
1206
- return $res;
1207
- }
1208
- }
1209
-
1210
- /**
1211
- * an annotation object, this will add an annotation to the current page.
1212
- * initially will support just link annotations
1213
- */
1214
- protected function o_annotation($id, $action, $options = '') {
1215
- if ($action !== 'new') {
1216
- $o = & $this->objects[$id];
1217
- }
1218
-
1219
- switch ($action) {
1220
- case 'new':
1221
- // add the annotation to the current page
1222
- $pageId = $this->currentPage;
1223
- $this->o_page($pageId, 'annot', $id);
1224
-
1225
- // and add the action object which is going to be required
1226
- switch ($options['type']) {
1227
- case 'link':
1228
- $this->objects[$id] = array('t'=>'annotation', 'info'=>$options);
1229
- $this->numObj++;
1230
- $this->o_action($this->numObj, 'new', $options['url']);
1231
- $this->objects[$id]['info']['actionId'] = $this->numObj;
1232
- break;
1233
-
1234
- case 'ilink':
1235
- // this is to a named internal link
1236
- $label = $options['label'];
1237
- $this->objects[$id] = array('t'=>'annotation', 'info'=>$options);
1238
- $this->numObj++;
1239
- $this->o_action($this->numObj, 'new', array('type'=>'ilink', 'label'=>$label));
1240
- $this->objects[$id]['info']['actionId'] = $this->numObj;
1241
- break;
1242
- }
1243
- break;
1244
-
1245
- case 'out':
1246
- $res = "\n$id 0 obj\n<< /Type /Annot";
1247
- switch ($o['info']['type']) {
1248
- case 'link':
1249
- case 'ilink':
1250
- $res.= "\n/Subtype /Link";
1251
- break;
1252
- }
1253
- $res.= "\n/A ".$o['info']['actionId']." 0 R";
1254
- $res.= "\n/Border [0 0 0]";
1255
- $res.= "\n/H /I";
1256
- $res.= "\n/Rect [ ";
1257
-
1258
- foreach($o['info']['rect'] as $v) {
1259
- $res.= sprintf("%.4F ", $v);
1260
- }
1261
-
1262
- $res.= "]";
1263
- $res.= "\n>>\nendobj";
1264
- return $res;
1265
- }
1266
- }
1267
-
1268
- /**
1269
- * a page object, it also creates a contents object to hold its contents
1270
- */
1271
- protected function o_page($id, $action, $options = '') {
1272
- if ($action !== 'new') {
1273
- $o = & $this->objects[$id];
1274
- }
1275
-
1276
- switch ($action) {
1277
- case 'new':
1278
- $this->numPages++;
1279
- $this->objects[$id] = array('t'=>'page', 'info'=>array('parent'=>$this->currentNode, 'pageNum'=>$this->numPages));
1280
-
1281
- if (is_array($options)) {
1282
- // then this must be a page insertion, array should contain 'rid','pos'=[before|after]
1283
- $options['id'] = $id;
1284
- $this->o_pages($this->currentNode, 'page', $options);
1285
- } else {
1286
- $this->o_pages($this->currentNode, 'page', $id);
1287
- }
1288
-
1289
- $this->currentPage = $id;
1290
- //make a contents object to go with this page
1291
- $this->numObj++;
1292
- $this->o_contents($this->numObj, 'new', $id);
1293
- $this->currentContents = $this->numObj;
1294
- $this->objects[$id]['info']['contents'] = array();
1295
- $this->objects[$id]['info']['contents'][] = $this->numObj;
1296
-
1297
- $match = ($this->numPages%2 ? 'odd' : 'even');
1298
- foreach($this->addLooseObjects as $oId=>$target) {
1299
- if ($target === 'all' || $match === $target) {
1300
- $this->objects[$id]['info']['contents'][] = $oId;
1301
- }
1302
- }
1303
- break;
1304
-
1305
- case 'content':
1306
- $o['info']['contents'][] = $options;
1307
- break;
1308
-
1309
- case 'annot':
1310
- // add an annotation to this page
1311
- if (!isset($o['info']['annot'])) {
1312
- $o['info']['annot'] = array();
1313
- }
1314
-
1315
- // $options should contain the id of the annotation dictionary
1316
- $o['info']['annot'][] = $options;
1317
- break;
1318
-
1319
- case 'out':
1320
- $res = "\n$id 0 obj\n<< /Type /Page";
1321
- $res.= "\n/Parent ".$o['info']['parent']." 0 R";
1322
-
1323
- if (isset($o['info']['annot'])) {
1324
- $res.= "\n/Annots [";
1325
- foreach($o['info']['annot'] as $aId) {
1326
- $res.= " $aId 0 R";
1327
- }
1328
- $res.= " ]";
1329
- }
1330
-
1331
- $count = count($o['info']['contents']);
1332
- if ($count == 1) {
1333
- $res.= "\n/Contents ".$o['info']['contents'][0]." 0 R";
1334
- } else if ($count>1) {
1335
- $res.= "\n/Contents [\n";
1336
-
1337
- // reverse the page contents so added objects are below normal content
1338
- //foreach (array_reverse($o['info']['contents']) as $cId) {
1339
- // Back to normal now that I've got transparency working --Benj
1340
- foreach ($o['info']['contents'] as $cId) {
1341
- $res.= "$cId 0 R\n";
1342
- }
1343
- $res.= "]";
1344
- }
1345
-
1346
- $res.= "\n>>\nendobj";
1347
- return $res;
1348
- }
1349
- }
1350
-
1351
- /**
1352
- * the contents objects hold all of the content which appears on pages
1353
- */
1354
- protected function o_contents($id, $action, $options = '') {
1355
- if ($action !== 'new') {
1356
- $o = & $this->objects[$id];
1357
- }
1358
-
1359
- switch ($action) {
1360
- case 'new':
1361
- $this->objects[$id] = array('t'=>'contents', 'c'=>'', 'info'=>array());
1362
- if (mb_strlen($options, '8bit') && intval($options)) {
1363
- // then this contents is the primary for a page
1364
- $this->objects[$id]['onPage'] = $options;
1365
- } else if ($options === 'raw') {
1366
- // then this page contains some other type of system object
1367
- $this->objects[$id]['raw'] = 1;
1368
- }
1369
- break;
1370
-
1371
- case 'add':
1372
- // add more options to the decleration
1373
- foreach ($options as $k=>$v) {
1374
- $o['info'][$k] = $v;
1375
- }
1376
-
1377
- case 'out':
1378
- $tmp = $o['c'];
1379
- $res = "\n$id 0 obj\n";
1380
-
1381
- if (isset($this->objects[$id]['raw'])) {
1382
- $res.= $tmp;
1383
- } else {
1384
- $res.= "<<";
1385
- if ($this->compressionReady && $this->options['compression']) {
1386
- // then implement ZLIB based compression on this content stream
1387
- $res.= " /Filter /FlateDecode";
1388
- $tmp = gzcompress($tmp, 6);
1389
- }
1390
-
1391
- if ($this->encrypted) {
1392
- $this->encryptInit($id);
1393
- $tmp = $this->ARC4($tmp);
1394
- }
1395
-
1396
- foreach($o['info'] as $k=>$v) {
1397
- $res.= "\n/$k $v";
1398
- }
1399
-
1400
- $res.= "\n/Length ".mb_strlen($tmp, '8bit') ." >>\nstream\n$tmp\nendstream";
1401
- }
1402
-
1403
- $res.= "\nendobj";
1404
- return $res;
1405
- }
1406
- }
1407
-
1408
- protected function o_embedjs($id, $action, $code = '') {
1409
- if ($action !== 'new') {
1410
- $o = & $this->objects[$id];
1411
- }
1412
-
1413
- switch ($action) {
1414
- case 'new':
1415
- $this->objects[$id] = array('t'=>'embedjs', 'info'=>array(
1416
- 'Names' => '[(EmbeddedJS) '.($id+1).' 0 R]'
1417
- ));
1418
- break;
1419
-
1420
- case 'out':
1421
- $res = "\n$id 0 obj\n<< ";
1422
- foreach($o['info'] as $k=>$v) {
1423
- $res.= "\n/$k $v";
1424
- }
1425
- $res.= "\n>>\nendobj";
1426
- return $res;
1427
- }
1428
- }
1429
-
1430
- protected function o_javascript($id, $action, $code = '') {
1431
- if ($action !== 'new') {
1432
- $o = & $this->objects[$id];
1433
- }
1434
-
1435
- switch ($action) {
1436
- case 'new':
1437
- $this->objects[$id] = array('t'=>'javascript', 'info'=>array(
1438
- 'S' => '/JavaScript',
1439
- 'JS' => '('.$this->filterText($code).')',
1440
- ));
1441
- break;
1442
-
1443
- case 'out':
1444
- $res = "\n$id 0 obj\n<< ";
1445
- foreach($o['info'] as $k=>$v) {
1446
- $res.= "\n/$k $v";
1447
- }
1448
- $res.= "\n>>\nendobj";
1449
- return $res;
1450
- }
1451
- }
1452
-
1453
- /**
1454
- * an image object, will be an XObject in the document, includes description and data
1455
- */
1456
- protected function o_image($id, $action, $options = '') {
1457
- if ($action !== 'new') {
1458
- $o = & $this->objects[$id];
1459
- }
1460
-
1461
- switch ($action) {
1462
- case 'new':
1463
- // make the new object
1464
- $this->objects[$id] = array('t'=>'image', 'data'=>&$options['data'], 'info'=>array());
1465
-
1466
- $info =& $this->objects[$id]['info'];
1467
-
1468
- $info['Type'] = '/XObject';
1469
- $info['Subtype'] = '/Image';
1470
- $info['Width'] = $options['iw'];
1471
- $info['Height'] = $options['ih'];
1472
-
1473
- if (isset($options['masked']) && $options['masked']) {
1474
- $info['SMask'] = ($this->numObj-1).' 0 R';
1475
- }
1476
-
1477
- if (!isset($options['type']) || $options['type'] === 'jpg') {
1478
- if (!isset($options['channels'])) {
1479
- $options['channels'] = 3;
1480
- }
1481
-
1482
- switch ($options['channels']) {
1483
- case 1: $info['ColorSpace'] = '/DeviceGray'; break;
1484
- case 4: $info['ColorSpace'] = '/DeviceCMYK'; break;
1485
- default: $info['ColorSpace'] = '/DeviceRGB'; break;
1486
- }
1487
-
1488
- if ($info['ColorSpace'] === '/DeviceCMYK') {
1489
- $info['Decode'] = '[1 0 1 0 1 0 1 0]';
1490
- }
1491
-
1492
- $info['Filter'] = '/DCTDecode';
1493
- $info['BitsPerComponent'] = 8;
1494
- }
1495
-
1496
- else if ($options['type'] === 'png') {
1497
- $info['Filter'] = '/FlateDecode';
1498
- $info['DecodeParms'] = '<< /Predictor 15 /Colors '.$options['ncolor'].' /Columns '.$options['iw'].' /BitsPerComponent '.$options['bitsPerComponent'].'>>';
1499
-
1500
- if ($options['isMask']) {
1501
- $info['ColorSpace'] = '/DeviceGray';
1502
- }
1503
- else {
1504
- if (mb_strlen($options['pdata'], '8bit')) {
1505
- $tmp = ' [ /Indexed /DeviceRGB '.(mb_strlen($options['pdata'], '8bit') /3-1) .' ';
1506
- $this->numObj++;
1507
- $this->o_contents($this->numObj, 'new');
1508
- $this->objects[$this->numObj]['c'] = $options['pdata'];
1509
- $tmp.= $this->numObj.' 0 R';
1510
- $tmp.= ' ]';
1511
- $info['ColorSpace'] = $tmp;
1512
-
1513
- if (isset($options['transparency'])) {
1514
- $transparency = $options['transparency'];
1515
- switch ($transparency['type']) {
1516
- case 'indexed':
1517
- $tmp = ' [ '.$transparency['data'].' '.$transparency['data'].'] ';
1518
- $info['Mask'] = $tmp;
1519
- break;
1520
-
1521
- case 'color-key':
1522
- $tmp = ' [ '.
1523
- $transparency['r'] . ' ' . $transparency['r'] .
1524
- $transparency['g'] . ' ' . $transparency['g'] .
1525
- $transparency['b'] . ' ' . $transparency['b'] .
1526
- ' ] ';
1527
- $info['Mask'] = $tmp;
1528
- break;
1529
- }
1530
- }
1531
- } else {
1532
- if (isset($options['transparency'])) {
1533
- $transparency = $options['transparency'];
1534
-
1535
- switch ($transparency['type']) {
1536
- case 'indexed':
1537
- $tmp = ' [ '.$transparency['data'].' '.$transparency['data'].'] ';
1538
- $info['Mask'] = $tmp;
1539
- break;
1540
-
1541
- case 'color-key':
1542
- $tmp = ' [ '.
1543
- $transparency['r'] . ' ' . $transparency['r'] . ' ' .
1544
- $transparency['g'] . ' ' . $transparency['g'] . ' ' .
1545
- $transparency['b'] . ' ' . $transparency['b'] .
1546
- ' ] ';
1547
- $info['Mask'] = $tmp;
1548
- break;
1549
- }
1550
- }
1551
- $info['ColorSpace'] = '/'.$options['color'];
1552
- }
1553
- }
1554
-
1555
- $info['BitsPerComponent'] = $options['bitsPerComponent'];
1556
- }
1557
-
1558
- // assign it a place in the named resource dictionary as an external object, according to
1559
- // the label passed in with it.
1560
- $this->o_pages($this->currentNode, 'xObject', array('label'=>$options['label'], 'objNum'=>$id));
1561
-
1562
- // also make sure that we have the right procset object for it.
1563
- $this->o_procset($this->procsetObjectId, 'add', 'ImageC');
1564
- break;
1565
-
1566
- case 'out':
1567
- $tmp = &$o['data'];
1568
- $res = "\n$id 0 obj\n<<";
1569
-
1570
- foreach($o['info'] as $k=>$v) {
1571
- $res.= "\n/$k $v";
1572
- }
1573
-
1574
- if ($this->encrypted) {
1575
- $this->encryptInit($id);
1576
- $tmp = $this->ARC4($tmp);
1577
- }
1578
-
1579
- $res.= "\n/Length ".mb_strlen($tmp, '8bit') .">>\nstream\n$tmp\nendstream\nendobj";
1580
-
1581
- return $res;
1582
- }
1583
- }
1584
-
1585
- /**
1586
- * graphics state object
1587
- */
1588
- protected function o_extGState($id, $action, $options = "") {
1589
- static $valid_params = array("LW", "LC", "LC", "LJ", "ML",
1590
- "D", "RI", "OP", "op", "OPM",
1591
- "Font", "BG", "BG2", "UCR",
1592
- "TR", "TR2", "HT", "FL",
1593
- "SM", "SA", "BM", "SMask",
1594
- "CA", "ca", "AIS", "TK");
1595
-
1596
- if ($action !== "new") {
1597
- $o = & $this->objects[$id];
1598
- }
1599
-
1600
- switch ($action) {
1601
- case "new":
1602
- $this->objects[$id] = array('t' => 'extGState', 'info' => $options);
1603
-
1604
- // Tell the pages about the new resource
1605
- $this->numStates++;
1606
- $this->o_pages($this->currentNode, 'extGState', array("objNum" => $id, "stateNum" => $this->numStates));
1607
- break;
1608
-
1609
- case "out":
1610
- $res = "\n$id 0 obj\n<< /Type /ExtGState\n";
1611
-
1612
- foreach ($o["info"] as $k => $v) {
1613
- if ( !in_array($k, $valid_params))
1614
- continue;
1615
- $res.= "/$k $v\n";
1616
- }
1617
-
1618
- $res.= ">>\nendobj";
1619
- return $res;
1620
- }
1621
- }
1622
-
1623
- /**
1624
- * encryption object.
1625
- */
1626
- protected function o_encryption($id, $action, $options = '') {
1627
- if ($action !== 'new') {
1628
- $o = & $this->objects[$id];
1629
- }
1630
-
1631
- switch ($action) {
1632
- case 'new':
1633
- // make the new object
1634
- $this->objects[$id] = array('t'=>'encryption', 'info'=>$options);
1635
- $this->arc4_objnum = $id;
1636
-
1637
- // figure out the additional paramaters required
1638
- $pad = chr(0x28) .chr(0xBF) .chr(0x4E) .chr(0x5E) .chr(0x4E) .chr(0x75) .chr(0x8A) .chr(0x41)
1639
- .chr(0x64) .chr(0x00) .chr(0x4E) .chr(0x56) .chr(0xFF) .chr(0xFA) .chr(0x01) .chr(0x08)
1640
- .chr(0x2E) .chr(0x2E) .chr(0x00) .chr(0xB6) .chr(0xD0) .chr(0x68) .chr(0x3E) .chr(0x80)
1641
- .chr(0x2F) .chr(0x0C) .chr(0xA9) .chr(0xFE) .chr(0x64) .chr(0x53) .chr(0x69) .chr(0x7A);
1642
-
1643
- $len = mb_strlen($options['owner'], '8bit');
1644
-
1645
- if ($len>32) {
1646
- $owner = substr($options['owner'], 0, 32);
1647
- } else if ($len<32) {
1648
- $owner = $options['owner'].substr($pad, 0, 32-$len);
1649
- } else {
1650
- $owner = $options['owner'];
1651
- }
1652
-
1653
- $len = mb_strlen($options['user'], '8bit');
1654
- if ($len>32) {
1655
- $user = substr($options['user'], 0, 32);
1656
- } else if ($len<32) {
1657
- $user = $options['user'].substr($pad, 0, 32-$len);
1658
- } else {
1659
- $user = $options['user'];
1660
- }
1661
-
1662
- $tmp = $this->md5_16($owner);
1663
- $okey = substr($tmp, 0, 5);
1664
- $this->ARC4_init($okey);
1665
- $ovalue = $this->ARC4($user);
1666
- $this->objects[$id]['info']['O'] = $ovalue;
1667
-
1668
- // now make the u value, phew.
1669
- $tmp = $this->md5_16($user.$ovalue.chr($options['p']) .chr(255) .chr(255) .chr(255) .$this->fileIdentifier);
1670
-
1671
- $ukey = substr($tmp, 0, 5);
1672
- $this->ARC4_init($ukey);
1673
- $this->encryptionKey = $ukey;
1674
- $this->encrypted = true;
1675
- $uvalue = $this->ARC4($pad);
1676
- $this->objects[$id]['info']['U'] = $uvalue;
1677
- $this->encryptionKey = $ukey;
1678
- // initialize the arc4 array
1679
- break;
1680
-
1681
- case 'out':
1682
- $res = "\n$id 0 obj\n<<";
1683
- $res.= "\n/Filter /Standard";
1684
- $res.= "\n/V 1";
1685
- $res.= "\n/R 2";
1686
- $res.= "\n/O (".$this->filterText($o['info']['O'], true, false) .')';
1687
- $res.= "\n/U (".$this->filterText($o['info']['U'], true, false) .')';
1688
- // and the p-value needs to be converted to account for the twos-complement approach
1689
- $o['info']['p'] = (($o['info']['p']^255) +1) *-1;
1690
- $res.= "\n/P ".($o['info']['p']);
1691
- $res.= "\n>>\nendobj";
1692
- return $res;
1693
- }
1694
- }
1695
-
1696
- /**
1697
- * ARC4 functions
1698
- * A series of function to implement ARC4 encoding in PHP
1699
- */
1700
-
1701
- /**
1702
- * calculate the 16 byte version of the 128 bit md5 digest of the string
1703
- */
1704
- function md5_16($string) {
1705
- $tmp = md5($string);
1706
- $out = '';
1707
- for ($i = 0;$i <= 30;$i = $i+2) {
1708
- $out.= chr(hexdec(substr($tmp, $i, 2)));
1709
- }
1710
- return $out;
1711
- }
1712
-
1713
- /**
1714
- * initialize the encryption for processing a particular object
1715
- */
1716
- function encryptInit($id) {
1717
- $tmp = $this->encryptionKey;
1718
- $hex = dechex($id);
1719
- if (mb_strlen($hex, '8bit') <6) {
1720
- $hex = substr('000000', 0, 6-mb_strlen($hex, '8bit')) .$hex;
1721
- }
1722
- $tmp.= chr(hexdec(substr($hex, 4, 2))) .chr(hexdec(substr($hex, 2, 2))) .chr(hexdec(substr($hex, 0, 2))) .chr(0) .chr(0);
1723
- $key = $this->md5_16($tmp);
1724
- $this->ARC4_init(substr($key, 0, 10));
1725
- }
1726
-
1727
- /**
1728
- * initialize the ARC4 encryption
1729
- */
1730
- function ARC4_init($key = '') {
1731
- $this->arc4 = '';
1732
-
1733
- // setup the control array
1734
- if (mb_strlen($key, '8bit') == 0) {
1735
- return;
1736
- }
1737
-
1738
- $k = '';
1739
- while (mb_strlen($k, '8bit') <256) {
1740
- $k.= $key;
1741
- }
1742
-
1743
- $k = substr($k, 0, 256);
1744
- for ($i = 0;$i<256;$i++) {
1745
- $this->arc4.= chr($i);
1746
- }
1747
-
1748
- $j = 0;
1749
-
1750
- for ($i = 0;$i<256;$i++) {
1751
- $t = $this->arc4[$i];
1752
- $j = ($j + ord($t) + ord($k[$i])) %256;
1753
- $this->arc4[$i] = $this->arc4[$j];
1754
- $this->arc4[$j] = $t;
1755
- }
1756
- }
1757
-
1758
- /**
1759
- * ARC4 encrypt a text string
1760
- */
1761
- function ARC4($text) {
1762
- $len = mb_strlen($text, '8bit');
1763
- $a = 0;
1764
- $b = 0;
1765
- $c = $this->arc4;
1766
- $out = '';
1767
- for ($i = 0;$i<$len;$i++) {
1768
- $a = ($a+1) %256;
1769
- $t = $c[$a];
1770
- $b = ($b+ord($t)) %256;
1771
- $c[$a] = $c[$b];
1772
- $c[$b] = $t;
1773
- $k = ord($c[(ord($c[$a]) +ord($c[$b])) %256]);
1774
- $out.= chr(ord($text[$i]) ^ $k);
1775
- }
1776
- return $out;
1777
- }
1778
-
1779
- /**
1780
- * functions which can be called to adjust or add to the document
1781
- */
1782
-
1783
- /**
1784
- * add a link in the document to an external URL
1785
- */
1786
- function addLink($url, $x0, $y0, $x1, $y1) {
1787
- $this->numObj++;
1788
- $info = array('type'=>'link', 'url'=>$url, 'rect'=>array($x0, $y0, $x1, $y1));
1789
- $this->o_annotation($this->numObj, 'new', $info);
1790
- }
1791
-
1792
- /**
1793
- * add a link in the document to an internal destination (ie. within the document)
1794
- */
1795
- function addInternalLink($label, $x0, $y0, $x1, $y1) {
1796
- $this->numObj++;
1797
- $info = array('type'=>'ilink', 'label'=>$label, 'rect'=>array($x0, $y0, $x1, $y1));
1798
- $this->o_annotation($this->numObj, 'new', $info);
1799
- }
1800
-
1801
- /**
1802
- * set the encryption of the document
1803
- * can be used to turn it on and/or set the passwords which it will have.
1804
- * also the functions that the user will have are set here, such as print, modify, add
1805
- */
1806
- function setEncryption($userPass = '', $ownerPass = '', $pc = array()) {
1807
- $p = bindec("11000000");
1808
-
1809
- $options = array('print'=>4, 'modify'=>8, 'copy'=>16, 'add'=>32);
1810
-
1811
- foreach($pc as $k=>$v) {
1812
- if ($v && isset($options[$k])) {
1813
- $p+= $options[$k];
1814
- } else if (isset($options[$v])) {
1815
- $p+= $options[$v];
1816
- }
1817
- }
1818
-
1819
- // implement encryption on the document
1820
- if ($this->arc4_objnum == 0) {
1821
- // then the block does not exist already, add it.
1822
- $this->numObj++;
1823
- if (mb_strlen($ownerPass) == 0) {
1824
- $ownerPass = $userPass;
1825
- }
1826
-
1827
- $this->o_encryption($this->numObj, 'new', array('user'=>$userPass, 'owner'=>$ownerPass, 'p'=>$p));
1828
- }
1829
- }
1830
-
1831
- /**
1832
- * should be used for internal checks, not implemented as yet
1833
- */
1834
- function checkAllHere() {
1835
- }
1836
-
1837
- /**
1838
- * return the pdf stream as a string returned from the function
1839
- */
1840
- function output($debug = false) {
1841
- if ($debug) {
1842
- // turn compression off
1843
- $this->options['compression'] = false;
1844
- }
1845
-
1846
- if ($this->javascript) {
1847
- $this->numObj++;
1848
-
1849
- $js_id = $this->numObj;
1850
- $this->o_embedjs($js_id, 'new');
1851
- $this->o_javascript(++$this->numObj, 'new', $this->javascript);
1852
-
1853
- $id = $this->catalogId;
1854
-
1855
- $this->o_catalog($id, 'javascript', $js_id);
1856
- }
1857
-
1858
- if ($this->arc4_objnum) {
1859
- $this->ARC4_init($this->encryptionKey);
1860
- }
1861
-
1862
- $this->checkAllHere();
1863
-
1864
-
1865
- $xref = array();
1866
- $content = '%PDF-1.3';
1867
- $pos = mb_strlen($content, '8bit');
1868
-
1869
- foreach($this->objects as $k=>$v) {
1870
- $tmp = 'o_'.$v['t'];
1871
- $cont = $this->$tmp($k, 'out');
1872
- $content.= $cont;
1873
- $xref[] = $pos;
1874
- $pos+= mb_strlen($cont, '8bit');
1875
- }
1876
-
1877
- $content.= "\nxref\n0 ".(count($xref) +1) ."\n0000000000 65535 f \n";
1878
-
1879
- foreach($xref as $p) {
1880
- $content.= str_pad($p, 10, "0", STR_PAD_LEFT) . " 00000 n \n";
1881
- }
1882
-
1883
- $content.= "trailer\n<<\n/Size ".(count($xref) +1) ."\n/Root 1 0 R\n/Info $this->infoObject 0 R\n";
1884
-
1885
- // if encryption has been applied to this document then add the marker for this dictionary
1886
- if ($this->arc4_objnum > 0) {
1887
- $content.= "/Encrypt $this->arc4_objnum 0 R\n";
1888
- }
1889
-
1890
- if (mb_strlen($this->fileIdentifier, '8bit')) {
1891
- $content.= "/ID[<$this->fileIdentifier><$this->fileIdentifier>]\n";
1892
- }
1893
-
1894
- $content.= ">>\nstartxref\n$pos\n%%EOF\n";
1895
-
1896
- return $content;
1897
- }
1898
-
1899
- /**
1900
- * intialize a new document
1901
- * if this is called on an existing document results may be unpredictable, but the existing document would be lost at minimum
1902
- * this function is called automatically by the constructor function
1903
- *
1904
- * @access private
1905
- */
1906
- function newDocument($pageSize = array(0, 0, 612, 792)) {
1907
- $this->numObj = 0;
1908
- $this->objects = array();
1909
-
1910
- $this->numObj++;
1911
- $this->o_catalog($this->numObj, 'new');
1912
-
1913
- $this->numObj++;
1914
- $this->o_outlines($this->numObj, 'new');
1915
-
1916
- $this->numObj++;
1917
- $this->o_pages($this->numObj, 'new');
1918
-
1919
- $this->o_pages($this->numObj, 'mediaBox', $pageSize);
1920
- $this->currentNode = 3;
1921
-
1922
- $this->numObj++;
1923
- $this->o_procset($this->numObj, 'new');
1924
-
1925
- $this->numObj++;
1926
- $this->o_info($this->numObj, 'new');
1927
-
1928
- $this->numObj++;
1929
- $this->o_page($this->numObj, 'new');
1930
-
1931
- // need to store the first page id as there is no way to get it to the user during
1932
- // startup
1933
- $this->firstPageId = $this->currentContents;
1934
- }
1935
-
1936
- /**
1937
- * open the font file and return a php structure containing it.
1938
- * first check if this one has been done before and saved in a form more suited to php
1939
- * note that if a php serialized version does not exist it will try and make one, but will
1940
- * require write access to the directory to do it... it is MUCH faster to have these serialized
1941
- * files.
1942
- *
1943
- * @access private
1944
- */
1945
- function openFont($font) {
1946
- // assume that $font contains the path and file but not the extension
1947
- $pos = strrpos($font, '/');
1948
-
1949
- if ($pos === false) {
1950
- $dir = './';
1951
- $name = $font;
1952
- } else {
1953
- $dir = substr($font, 0, $pos+1);
1954
- $name = substr($font, $pos+1);
1955
- }
1956
-
1957
- $fontcache = $this->fontcache;
1958
- if ($fontcache == '') {
1959
- $fontcache = $dir;
1960
- }
1961
-
1962
- //$name filename without folder and extension of font metrics
1963
- //$dir folder of font metrics
1964
- //$fontcache folder of runtime created php serialized version of font metrics.
1965
- // If this is not given, the same folder as the font metrics will be used.
1966
- // Storing and reusing serialized versions improves speed much
1967
-
1968
- $this->addMessage("openFont: $font - $name");
1969
-
1970
- if ( !$this->isUnicode || in_array(mb_strtolower(basename($name)), self::$coreFonts) ) {
1971
- $metrics_name = "$name.afm";
1972
- }
1973
- else {
1974
- $metrics_name = "$name.ufm";
1975
- }
1976
-
1977
- $cache_name = "$metrics_name.php";
1978
- $this->addMessage("metrics: $metrics_name, cache: $cache_name");
1979
-
1980
- if (file_exists($fontcache . $cache_name)) {
1981
- $this->addMessage("openFont: php file exists $fontcache$cache_name");
1982
- $this->fonts[$font] = require($fontcache . $cache_name);
1983
-
1984
- if (!isset($this->fonts[$font]['_version_']) || $this->fonts[$font]['_version_'] != $this->fontcacheVersion) {
1985
- // if the font file is old, then clear it out and prepare for re-creation
1986
- $this->addMessage('openFont: clear out, make way for new version.');
1987
- $this->fonts[$font] = null;
1988
- unset($this->fonts[$font]);
1989
- }
1990
- }
1991
- else {
1992
- $old_cache_name = "php_$metrics_name";
1993
- if (file_exists($fontcache . $old_cache_name)) {
1994
- $this->addMessage("openFont: php file doesn't exist $fontcache$cache_name, creating it from the old format");
1995
- $old_cache = file_get_contents($fontcache . $old_cache_name);
1996
- file_put_contents($fontcache . $cache_name, '<?php return ' . $old_cache . ';');
1997
- return $this->openFont($font);
1998
- }
1999
- }
2000
-
2001
- if (!isset($this->fonts[$font]) && file_exists($dir . $metrics_name)) {
2002
- // then rebuild the php_<font>.afm file from the <font>.afm file
2003
- $this->addMessage("openFont: build php file from $dir$metrics_name");
2004
- $data = array();
2005
-
2006
- // 20 => 'space'
2007
- $data['codeToName'] = array();
2008
-
2009
- // Since we're not going to enable Unicode for the core fonts we need to use a font-based
2010
- // setting for Unicode support rather than a global setting.
2011
- $data['isUnicode'] = (strtolower(substr($metrics_name, -3)) !== 'afm');
2012
-
2013
- $cidtogid = '';
2014
- if ($data['isUnicode']) {
2015
- $cidtogid = str_pad('', 256*256*2, "\x00");
2016
- }
2017
-
2018
- $file = file($dir . $metrics_name);
2019
-
2020
- foreach ($file as $rowA) {
2021
- $row = trim($rowA);
2022
- $pos = strpos($row, ' ');
2023
-
2024
- if ($pos) {
2025
- // then there must be some keyword
2026
- $key = substr($row, 0, $pos);
2027
- switch ($key) {
2028
- case 'FontName':
2029
- case 'FullName':
2030
- case 'FamilyName':
2031
- case 'PostScriptName':
2032
- case 'Weight':
2033
- case 'ItalicAngle':
2034
- case 'IsFixedPitch':
2035
- case 'CharacterSet':
2036
- case 'UnderlinePosition':
2037
- case 'UnderlineThickness':
2038
- case 'Version':
2039
- case 'EncodingScheme':
2040
- case 'CapHeight':
2041
- case 'XHeight':
2042
- case 'Ascender':
2043
- case 'Descender':
2044
- case 'StdHW':
2045
- case 'StdVW':
2046
- case 'StartCharMetrics':
2047
- case 'FontHeightOffset': // OAR - Added so we can offset the height calculation of a Windows font. Otherwise it's too big.
2048
- $data[$key] = trim(substr($row, $pos));
2049
- break;
2050
-
2051
- case 'FontBBox':
2052
- $data[$key] = explode(' ', trim(substr($row, $pos)));
2053
- break;
2054
-
2055
- //C 39 ; WX 222 ; N quoteright ; B 53 463 157 718 ;
2056
- case 'C': // Found in AFM files
2057
- $bits = explode(';', trim($row));
2058
- $dtmp = array();
2059
-
2060
- foreach($bits as $bit) {
2061
- $bits2 = explode(' ', trim($bit));
2062
- if (mb_strlen($bits2[0], '8bit') == 0) continue;
2063
-
2064
- if (count($bits2) >2) {
2065
- $dtmp[$bits2[0]] = array();
2066
- for ($i = 1;$i<count($bits2);$i++) {
2067
- $dtmp[$bits2[0]][] = $bits2[$i];
2068
- }
2069
- } else if (count($bits2) == 2) {
2070
- $dtmp[$bits2[0]] = $bits2[1];
2071
- }
2072
- }
2073
-
2074
- $c = (int)$dtmp['C'];
2075
- $n = $dtmp['N'];
2076
- $width = floatval($dtmp['WX']);
2077
-
2078
- if ($c >= 0) {
2079
- if ($c != hexdec($n)) {
2080
- $data['codeToName'][$c] = $n;
2081
- }
2082
- $data['C'][$c] = $width;
2083
- } else {
2084
- $data['C'][$n] = $width;
2085
- }
2086
-
2087
- if (!isset($data['MissingWidth']) && $c == -1 && $n === '.notdef') {
2088
- $data['MissingWidth'] = $width;
2089
- }
2090
-
2091
- break;
2092
-
2093
- // U 827 ; WX 0 ; N squaresubnosp ; G 675 ;
2094
- case 'U': // Found in UFM files
2095
- if (!$data['isUnicode']) break;
2096
-
2097
- $bits = explode(';', trim($row));
2098
- $dtmp = array();
2099
-
2100
- foreach($bits as $bit) {
2101
- $bits2 = explode(' ', trim($bit));
2102
- if (mb_strlen($bits2[0], '8bit') === 0) continue;
2103
-
2104
- if (count($bits2) >2) {
2105
- $dtmp[$bits2[0]] = array();
2106
- for ($i = 1;$i<count($bits2);$i++) {
2107
- $dtmp[$bits2[0]][] = $bits2[$i];
2108
- }
2109
- } else if (count($bits2) == 2) {
2110
- $dtmp[$bits2[0]] = $bits2[1];
2111
- }
2112
- }
2113
-
2114
- $c = (int)$dtmp['U'];
2115
- $n = $dtmp['N'];
2116
- $glyph = $dtmp['G'];
2117
- $width = floatval($dtmp['WX']);
2118
-
2119
- if ($c >= 0) {
2120
- // Set values in CID to GID map
2121
- if ($c >= 0 && $c < 0xFFFF && $glyph) {
2122
- $cidtogid[$c*2] = chr($glyph >> 8);
2123
- $cidtogid[$c*2 + 1] = chr($glyph & 0xFF);
2124
- }
2125
-
2126
- if ($c != hexdec($n)) {
2127
- $data['codeToName'][$c] = $n;
2128
- }
2129
- $data['C'][$c] = $width;
2130
- } else {
2131
- $data['C'][$n] = $width;
2132
- }
2133
-
2134
- if (!isset($data['MissingWidth']) && $c == -1 && $n === '.notdef') {
2135
- $data['MissingWidth'] = $width;
2136
- }
2137
-
2138
- break;
2139
-
2140
- case 'KPX':
2141
- break; // don't include them as they are not used yet
2142
- //KPX Adieresis yacute -40
2143
- $bits = explode(' ', trim($row));
2144
- $data['KPX'][$bits[1]][$bits[2]] = $bits[3];
2145
- break;
2146
- }
2147
- }
2148
- }
2149
-
2150
- // echo $cidtogid; die("CIDtoGID Displayed!");
2151
- if ($this->compressionReady && $this->options['compression']) {
2152
- // then implement ZLIB based compression on CIDtoGID string
2153
- $data['CIDtoGID_Compressed'] = true;
2154
- $cidtogid = gzcompress($cidtogid, 6);
2155
- }
2156
- $data['CIDtoGID'] = base64_encode($cidtogid);
2157
- $data['_version_'] = $this->fontcacheVersion;
2158
- $this->fonts[$font] = $data;
2159
-
2160
- //Because of potential trouble with php safe mode, expect that the folder already exists.
2161
- //If not existing, this will hit performance because of missing cached results.
2162
- if ( is_dir(substr($fontcache,0,-1)) && is_writable(substr($fontcache,0,-1)) ) {
2163
- file_put_contents($fontcache . $cache_name, '<?php return ' . var_export($data, true) . ';');
2164
- }
2165
- $data = null;
2166
- }
2167
-
2168
- if (!isset($this->fonts[$font])) {
2169
- $this->addMessage("openFont: no font file found for $font. Do you need to run load_font.php?");
2170
- //echo 'Font not Found '.$font;
2171
- }
2172
-
2173
- //pre_r($this->messages);
2174
- }
2175
-
2176
- /**
2177
- * if the font is not loaded then load it and make the required object
2178
- * else just make it the current font
2179
- * the encoding array can contain 'encoding'=> 'none','WinAnsiEncoding','MacRomanEncoding' or 'MacExpertEncoding'
2180
- * note that encoding='none' will need to be used for symbolic fonts
2181
- * and 'differences' => an array of mappings between numbers 0->255 and character names.
2182
- *
2183
- */
2184
- function selectFont($fontName, $encoding = '', $set = true) {
2185
- $ext = substr($fontName, -4);
2186
- if ($ext === '.afm' || $ext === '.ufm') {
2187
- $fontName = substr($fontName, 0, mb_strlen($fontName)-4);
2188
- }
2189
-
2190
- if (!isset($this->fonts[$fontName])) {
2191
- $this->addMessage("selectFont: selecting - $fontName - $encoding, $set");
2192
-
2193
- // load the file
2194
- $this->openFont($fontName);
2195
-
2196
- if (isset($this->fonts[$fontName])) {
2197
- $this->numObj++;
2198
- $this->numFonts++;
2199
-
2200
- $font = &$this->fonts[$fontName];
2201
-
2202
- //$this->numFonts = md5($fontName);
2203
- $pos = strrpos($fontName, '/');
2204
- // $dir = substr($fontName,0,$pos+1);
2205
- $name = substr($fontName, $pos+1);
2206
- $options = array('name' => $name, 'fontFileName' => $fontName);
2207
-
2208
- if (is_array($encoding)) {
2209
- // then encoding and differences might be set
2210
- if (isset($encoding['encoding'])) {
2211
- $options['encoding'] = $encoding['encoding'];
2212
- }
2213
-
2214
- if (isset($encoding['differences'])) {
2215
- $options['differences'] = $encoding['differences'];
2216
- }
2217
- } else if (mb_strlen($encoding, '8bit')) {
2218
- // then perhaps only the encoding has been set
2219
- $options['encoding'] = $encoding;
2220
- }
2221
-
2222
- $fontObj = $this->numObj;
2223
- $this->o_font($this->numObj, 'new', $options);
2224
- $font['fontNum'] = $this->numFonts;
2225
-
2226
- // if this is a '.afm' font, and there is a '.pfa' file to go with it ( as there
2227
- // should be for all non-basic fonts), then load it into an object and put the
2228
- // references into the font object
2229
- $basefile = $fontName;
2230
-
2231
- $fbtype = '';
2232
- if (file_exists("$basefile.pfb")) {
2233
- $fbtype = 'pfb';
2234
- }
2235
- elseif (file_exists("$basefile.ttf")) {
2236
- $fbtype = 'ttf';
2237
- }
2238
-
2239
- $fbfile = "$basefile.$fbtype";
2240
-
2241
- // $pfbfile = substr($fontName,0,strlen($fontName)-4).'.pfb';
2242
- // $ttffile = substr($fontName,0,strlen($fontName)-4).'.ttf';
2243
- $this->addMessage('selectFont: checking for - '.$fbfile);
2244
-
2245
- // OAR - I don't understand this old check
2246
- // if (substr($fontName, -4) === '.afm' && strlen($fbtype)) {
2247
- if ($fbtype) {
2248
- $adobeFontName = isset($font['PostScriptName']) ? $font['PostScriptName'] : $font['FontName'];
2249
- // $fontObj = $this->numObj;
2250
- $this->addMessage("selectFont: adding font file - $fbfile - $adobeFontName");
2251
-
2252
- // find the array of font widths, and put that into an object.
2253
- $firstChar = -1;
2254
- $lastChar = 0;
2255
- $widths = array();
2256
- $cid_widths = array();
2257
-
2258
- foreach ($font['C'] as $num => $d) {
2259
- if (intval($num) >0 || $num == '0') {
2260
- if (!$font['isUnicode']) {
2261
- // With Unicode, widths array isn't used
2262
- if ($lastChar>0 && $num>$lastChar+1) {
2263
- for ($i = $lastChar+1;$i<$num;$i++) {
2264
- $widths[] = 0;
2265
- }
2266
- }
2267
- }
2268
-
2269
- $widths[] = $d;
2270
-
2271
- if ($font['isUnicode']) {
2272
- $cid_widths[$num] = $d;
2273
- }
2274
-
2275
- if ($firstChar == -1) {
2276
- $firstChar = $num;
2277
- }
2278
-
2279
- $lastChar = $num;
2280
- }
2281
- }
2282
-
2283
- // also need to adjust the widths for the differences array
2284
- if (isset($options['differences'])) {
2285
- foreach($options['differences'] as $charNum => $charName) {
2286
- if ($charNum > $lastChar) {
2287
- if (!$font['isUnicode']) {
2288
- // With Unicode, widths array isn't used
2289
- for ($i = $lastChar + 1; $i <= $charNum; $i++) {
2290
- $widths[] = 0;
2291
- }
2292
- }
2293
-
2294
- $lastChar = $charNum;
2295
- }
2296
-
2297
- if (isset($font['C'][$charName])) {
2298
- $widths[$charNum-$firstChar] = $font['C'][$charName];
2299
- if ($font['isUnicode']) {
2300
- $cid_widths[$charName] = $font['C'][$charName];
2301
- }
2302
- }
2303
- }
2304
- }
2305
-
2306
- if ($font['isUnicode']) {
2307
- $font['CIDWidths'] = $cid_widths;
2308
- }
2309
-
2310
- $this->addMessage('selectFont: FirstChar = '.$firstChar);
2311
- $this->addMessage('selectFont: LastChar = '.$lastChar);
2312
-
2313
- $widthid = -1;
2314
-
2315
- if (!$font['isUnicode']) {
2316
- // With Unicode, widths array isn't used
2317
-
2318
- $this->numObj++;
2319
- $this->o_contents($this->numObj, 'new', 'raw');
2320
- $this->objects[$this->numObj]['c'].= '['.implode(' ', $widths).']';
2321
- $widthid = $this->numObj;
2322
- }
2323
-
2324
- $missing_width = 500;
2325
- $stemV = 70;
2326
-
2327
- if (isset($font['MissingWidth'])) {
2328
- $missing_width = $font['MissingWidth'];
2329
- }
2330
- if (isset($font['StdVW'])) {
2331
- $stemV = $font['StdVW'];
2332
- } elseif (isset($font['Weight']) && preg_match('!(bold|black)!i', $font['Weight'])) {
2333
- $stemV = 120;
2334
- }
2335
-
2336
- // load the pfb file, and put that into an object too.
2337
- // note that pdf supports only binary format type 1 font files, though there is a
2338
- // simple utility to convert them from pfa to pfb.
2339
- if (!$this->isUnicode || $fbtype !== 'ttf' || empty($this->stringSubsets)) {
2340
- $data = file_get_contents($fbfile);
2341
- }
2342
- else {
2343
- require_once dirname(__FILE__)."/php-font-lib/classes/font.cls.php";
2344
-
2345
- $this->stringSubsets[$fontName][] = 32; // Force space if not in yet
2346
-
2347
- $subset = $this->stringSubsets[$fontName];
2348
- sort($subset);
2349
-
2350
- // Load font
2351
- $font_obj = Font::load($fbfile);
2352
- $font_obj->parse();
2353
-
2354
- // Define subset
2355
- $font_obj->setSubset($subset);
2356
- $font_obj->reduce();
2357
-
2358
- // Write new font
2359
- $tmp_name = "$fbfile.tmp.".sprintf("%u", crc32(implode($subset)));
2360
- $font_obj->open($tmp_name, Font_Binary_Stream::modeWrite);
2361
- $font_obj->encode(array("OS/2"));
2362
- $font_obj->close();
2363
-
2364
- // Parse the new font to get cid2gid and widths
2365
- $font_obj = Font::load($tmp_name);
2366
-
2367
- // Find Unicode char map table
2368
- $subtable = null;
2369
- foreach($font_obj->getData("cmap", "subtables") as $_subtable) {
2370
- if ($_subtable["platformID"] == 0 || $_subtable["platformID"] == 3 && $_subtable["platformSpecificID"] == 1) {
2371
- $subtable = $_subtable;
2372
- break;
2373
- }
2374
- }
2375
-
2376
- if ($subtable) {
2377
- $glyphIndexArray = $subtable["glyphIndexArray"];
2378
- $hmtx = $font_obj->getData("hmtx");
2379
-
2380
- unset($glyphIndexArray[0xFFFF]);
2381
-
2382
- $cidtogid = str_pad('', max(array_keys($glyphIndexArray))*2+1, "\x00");
2383
- $font['CIDWidths'] = array();
2384
-
2385
- foreach($glyphIndexArray as $cid => $gid) {
2386
- if ($cid >= 0 && $cid < 0xFFFF && $gid) {
2387
- $cidtogid[$cid*2] = chr($gid >> 8);
2388
- $cidtogid[$cid*2 + 1] = chr($gid & 0xFF);
2389
- }
2390
-
2391
- $width = $font_obj->normalizeFUnit(isset($hmtx[$gid]) ? $hmtx[$gid][0] : $hmtx[0][0]);
2392
- $font['CIDWidths'][$cid] = $width;
2393
- }
2394
-
2395
- $font['CIDtoGID'] = base64_encode(gzcompress($cidtogid));
2396
- $font['CIDtoGID_Compressed'] = true;
2397
-
2398
- $data = file_get_contents($tmp_name);
2399
- }
2400
- else {
2401
- $data = file_get_contents($fbfile);
2402
- }
2403
-
2404
- $font_obj->close();
2405
- unlink($tmp_name);
2406
- }
2407
-
2408
- // create the font descriptor
2409
- $this->numObj++;
2410
- $fontDescriptorId = $this->numObj;
2411
-
2412
- $this->numObj++;
2413
- $pfbid = $this->numObj;
2414
-
2415
- // determine flags (more than a little flakey, hopefully will not matter much)
2416
- $flags = 0;
2417
-
2418
- if ($font['ItalicAngle'] != 0) {
2419
- $flags+= pow(2, 6);
2420
- }
2421
-
2422
- if ($font['IsFixedPitch'] === 'true') {
2423
- $flags+= 1;
2424
- }
2425
-
2426
- $flags+= pow(2, 5); // assume non-sybolic
2427
- $list = array(
2428
- 'Ascent' => 'Ascender',
2429
- 'CapHeight' => 'CapHeight',
2430
- 'MissingWidth' => 'MissingWidth',
2431
- 'Descent' => 'Descender',
2432
- 'FontBBox' => 'FontBBox',
2433
- 'ItalicAngle' => 'ItalicAngle'
2434
- );
2435
- $fdopt = array(
2436
- 'Flags' => $flags,
2437
- 'FontName' => $adobeFontName,
2438
- 'StemV' => $stemV
2439
- );
2440
-
2441
- foreach($list as $k => $v) {
2442
- if (isset($font[$v])) {
2443
- $fdopt[$k] = $font[$v];
2444
- }
2445
- }
2446
-
2447
- if ($fbtype === 'pfb') {
2448
- $fdopt['FontFile'] = $pfbid;
2449
- } else if ($fbtype === 'ttf') {
2450
- $fdopt['FontFile2'] = $pfbid;
2451
- }
2452
-
2453
- $this->o_fontDescriptor($fontDescriptorId, 'new', $fdopt);
2454
-
2455
- // embed the font program
2456
- $this->o_contents($this->numObj, 'new');
2457
- $this->objects[$pfbid]['c'].= $data;
2458
-
2459
- // determine the cruicial lengths within this file
2460
- if ($fbtype === 'pfb') {
2461
- $l1 = strpos($data, 'eexec') +6;
2462
- $l2 = strpos($data, '00000000') -$l1;
2463
- $l3 = mb_strlen($data, '8bit') -$l2-$l1;
2464
- $this->o_contents($this->numObj, 'add', array('Length1' => $l1, 'Length2' => $l2, 'Length3' => $l3));
2465
- } else if ($fbtype == 'ttf') {
2466
- $l1 = mb_strlen($data, '8bit');
2467
- $this->o_contents($this->numObj, 'add', array('Length1' => $l1));
2468
- }
2469
-
2470
- // tell the font object about all this new stuff
2471
- $tmp = array(
2472
- 'BaseFont' => $adobeFontName,
2473
- 'MissingWidth' => $missing_width,
2474
- 'Widths' => $widthid,
2475
- 'FirstChar' => $firstChar,
2476
- 'LastChar' => $lastChar,
2477
- 'FontDescriptor' => $fontDescriptorId,
2478
- );
2479
-
2480
- if ($fbtype === 'ttf') {
2481
- $tmp['SubType'] = 'TrueType';
2482
- }
2483
-
2484
- $this->addMessage("adding extra info to font.($fontObj)");
2485
-
2486
- foreach($tmp as $fk => $fv) {
2487
- $this->addMessage("$fk : $fv");
2488
- }
2489
-
2490
- $this->o_font($fontObj, 'add', $tmp);
2491
- } else {
2492
- $this->addMessage('selectFont: pfb or ttf file not found, ok if this is one of the 14 standard fonts');
2493
- }
2494
-
2495
- // also set the differences here, note that this means that these will take effect only the
2496
- //first time that a font is selected, else they are ignored
2497
- if (isset($options['differences'])) {
2498
- $font['differences'] = $options['differences'];
2499
- }
2500
- }
2501
- }
2502
-
2503
- if ($set && isset($this->fonts[$fontName])) {
2504
- // so if for some reason the font was not set in the last one then it will not be selected
2505
- $this->currentBaseFont = $fontName;
2506
-
2507
- // the next lines mean that if a new font is selected, then the current text state will be
2508
- // applied to it as well.
2509
- $this->currentFont = $this->currentBaseFont;
2510
- $this->currentFontNum = $this->fonts[$this->currentFont]['fontNum'];
2511
-
2512
- //$this->setCurrentFont();
2513
- }
2514
-
2515
- return $this->currentFontNum;
2516
- //return $this->numObj;
2517
- }
2518
-
2519
- /**
2520
- * sets up the current font, based on the font families, and the current text state
2521
- * note that this system is quite flexible, a bold-italic font can be completely different to a
2522
- * italic-bold font, and even bold-bold will have to be defined within the family to have meaning
2523
- * This function is to be called whenever the currentTextState is changed, it will update
2524
- * the currentFont setting to whatever the appropriatte family one is.
2525
- * If the user calls selectFont themselves then that will reset the currentBaseFont, and the currentFont
2526
- * This function will change the currentFont to whatever it should be, but will not change the
2527
- * currentBaseFont.
2528
- *
2529
- * @access private
2530
- */
2531
- function setCurrentFont() {
2532
- // if (strlen($this->currentBaseFont) == 0){
2533
- // // then assume an initial font
2534
- // $this->selectFont($this->defaultFont);
2535
- // }
2536
- // $cf = substr($this->currentBaseFont,strrpos($this->currentBaseFont,'/')+1);
2537
- // if (strlen($this->currentTextState)
2538
- // && isset($this->fontFamilies[$cf])
2539
- // && isset($this->fontFamilies[$cf][$this->currentTextState])){
2540
- // // then we are in some state or another
2541
- // // and this font has a family, and the current setting exists within it
2542
- // // select the font, then return it
2543
- // $nf = substr($this->currentBaseFont,0,strrpos($this->currentBaseFont,'/')+1).$this->fontFamilies[$cf][$this->currentTextState];
2544
- // $this->selectFont($nf,'',0);
2545
- // $this->currentFont = $nf;
2546
- // $this->currentFontNum = $this->fonts[$nf]['fontNum'];
2547
- // } else {
2548
- // // the this font must not have the right family member for the current state
2549
- // // simply assume the base font
2550
- $this->currentFont = $this->currentBaseFont;
2551
- $this->currentFontNum = $this->fonts[$this->currentFont]['fontNum'];
2552
- // }
2553
- }
2554
-
2555
- /**
2556
- * function for the user to find out what the ID is of the first page that was created during
2557
- * startup - useful if they wish to add something to it later.
2558
- */
2559
- function getFirstPageId() {
2560
- return $this->firstPageId;
2561
- }
2562
-
2563
- /**
2564
- * add content to the currently active object
2565
- *
2566
- * @access private
2567
- */
2568
- function addContent($content) {
2569
- $this->objects[$this->currentContents]['c'].= $content;
2570
- }
2571
-
2572
- /**
2573
- * sets the colour for fill operations
2574
- */
2575
- function setColor($color, $force = false) {
2576
- $new_color = array($color[0], $color[1], $color[2], isset($color[3]) ? $color[3] : null);
2577
-
2578
- if (!$force && $this->currentColour == $new_color) return;
2579
-
2580
- if (isset($new_color[3])) {
2581
- $this->currentColour = $new_color;
2582
- $this->objects[$this->currentContents]['c'] .= vsprintf("\n%.3F %.3F %.3F %.3F k", $this->currentColour);
2583
- }
2584
-
2585
- elseif (isset($new_color[2])) {
2586
- $this->currentColour = $new_color;
2587
- $this->objects[$this->currentContents]['c'] .= vsprintf("\n%.3F %.3F %.3F rg", $this->currentColour);
2588
- }
2589
- }
2590
-
2591
- /**
2592
- * sets the colour for stroke operations
2593
- */
2594
- function setStrokeColor($color, $force = false) {
2595
- $new_color = array($color[0], $color[1], $color[2], isset($color[3]) ? $color[3] : null);
2596
-
2597
- if (!$force && $this->currentStrokeColour == $new_color) return;
2598
-
2599
- if (isset($new_color[3])) {
2600
- $this->currentStrokeColour = $new_color;
2601
- $this->objects[$this->currentContents]['c'] .= vsprintf("\n%.3F %.3F %.3F %.3F K", $this->currentStrokeColour);
2602
- }
2603
-
2604
- elseif (isset($new_color[2])) {
2605
- $this->currentStrokeColour = $new_color;
2606
- $this->objects[$this->currentContents]['c'] .= vsprintf("\n%.3F %.3F %.3F RG", $this->currentStrokeColour);
2607
- }
2608
- }
2609
-
2610
- /**
2611
- * Set the graphics state for compositions
2612
- */
2613
- function setGraphicsState($parameters) {
2614
- // Create a new graphics state object
2615
- // FIXME: should actually keep track of states that have already been created...
2616
- $this->numObj++;
2617
- $this->o_extGState($this->numObj, 'new', $parameters);
2618
- $this->objects[ $this->currentContents ]['c'].= "\n/GS$this->numStates gs";
2619
- }
2620
-
2621
- /**
2622
- * Set current blend mode & opacity for lines.
2623
- *
2624
- * Valid blend modes are:
2625
- *
2626
- * Normal, Multiply, Screen, Overlay, Darken, Lighten,
2627
- * ColorDogde, ColorBurn, HardLight, SoftLight, Difference,
2628
- * Exclusion
2629
- *
2630
- * @param string $mode the blend mode to use
2631
- * @param float $opacity 0.0 fully transparent, 1.0 fully opaque
2632
- */
2633
- function setLineTransparency($mode, $opacity) {
2634
- static $blend_modes = array("Normal", "Multiply", "Screen",
2635
- "Overlay", "Darken", "Lighten",
2636
- "ColorDogde", "ColorBurn", "HardLight",
2637
- "SoftLight", "Difference", "Exclusion");
2638
-
2639
- if ( !in_array($mode, $blend_modes) )
2640
- $mode = "Normal";
2641
-
2642
- // Only create a new graphics state if required
2643
- if ( $mode === $this->currentLineTransparency["mode"] &&
2644
- $opacity == $this->currentLineTransparency["opacity"] )
2645
- return;
2646
-
2647
- $this->currentLineTransparency["mode"] = $mode;
2648
- $this->currentLineTransparency["opacity"] = $opacity;
2649
-
2650
- $options = array("BM" => "/$mode",
2651
- "CA" => (float)$opacity);
2652
-
2653
- $this->setGraphicsState($options);
2654
- }
2655
-
2656
- /**
2657
- * Set current blend mode & opacity for filled objects.
2658
- *
2659
- * Valid blend modes are:
2660
- *
2661
- * Normal, Multiply, Screen, Overlay, Darken, Lighten,
2662
- * ColorDogde, ColorBurn, HardLight, SoftLight, Difference,
2663
- * Exclusion
2664
- *
2665
- * @param string $mode the blend mode to use
2666
- * @param float $opacity 0.0 fully transparent, 1.0 fully opaque
2667
- */
2668
- function setFillTransparency($mode, $opacity) {
2669
- static $blend_modes = array("Normal", "Multiply", "Screen",
2670
- "Overlay", "Darken", "Lighten",
2671
- "ColorDogde", "ColorBurn", "HardLight",
2672
- "SoftLight", "Difference", "Exclusion");
2673
-
2674
- if ( !in_array($mode, $blend_modes) )
2675
- $mode = "Normal";
2676
-
2677
- if ( $mode === $this->currentFillTransparency["mode"] &&
2678
- $opacity == $this->currentFillTransparency["opacity"] )
2679
- return;
2680
-
2681
- $this->currentFillTransparency["mode"] = $mode;
2682
- $this->currentFillTransparency["opacity"] = $opacity;
2683
-
2684
- $options = array("BM" => "/$mode",
2685
- "ca" => (float)$opacity);
2686
-
2687
- $this->setGraphicsState($options);
2688
- }
2689
-
2690
- /**
2691
- * draw a line from one set of coordinates to another
2692
- */
2693
- function line($x1, $y1, $x2, $y2) {
2694
- $this->objects[$this->currentContents]['c'] .= sprintf("\n%.3F %.3F m %.3F %.3F l S", $x1, $y1, $x2, $y2);
2695
- }
2696
-
2697
- /**
2698
- * draw a bezier curve based on 4 control points
2699
- */
2700
- function curve($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3) {
2701
- // in the current line style, draw a bezier curve from (x0,y0) to (x3,y3) using the other two points
2702
- // as the control points for the curve.
2703
- $this->objects[$this->currentContents]['c'] .=
2704
- sprintf("\n%.3F %.3F m %.3F %.3F %.3F %.3F %.3F %.3F c S", $x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3);
2705
- }
2706
-
2707
- /**
2708
- * draw a part of an ellipse
2709
- */
2710
- function partEllipse($x0, $y0, $astart, $afinish, $r1, $r2 = 0, $angle = 0, $nSeg = 8) {
2711
- $this->ellipse($x0, $y0, $r1, $r2, $angle, $nSeg, $astart, $afinish, false);
2712
- }
2713
-
2714
- /**
2715
- * draw a filled ellipse
2716
- */
2717
- function filledEllipse($x0, $y0, $r1, $r2 = 0, $angle = 0, $nSeg = 8, $astart = 0, $afinish = 360) {
2718
- return $this->ellipse($x0, $y0, $r1, $r2 = 0, $angle, $nSeg, $astart, $afinish, true, true);
2719
- }
2720
-
2721
- /**
2722
- * draw an ellipse
2723
- * note that the part and filled ellipse are just special cases of this function
2724
- *
2725
- * draws an ellipse in the current line style
2726
- * centered at $x0,$y0, radii $r1,$r2
2727
- * if $r2 is not set, then a circle is drawn
2728
- * nSeg is not allowed to be less than 2, as this will simply draw a line (and will even draw a
2729
- * pretty crappy shape at 2, as we are approximating with bezier curves.
2730
- */
2731
- function ellipse($x0, $y0, $r1, $r2 = 0, $angle = 0, $nSeg = 8, $astart = 0, $afinish = 360, $close = true, $fill = false) {
2732
- if ($r1 == 0) {
2733
- return;
2734
- }
2735
-
2736
- if ($r2 == 0) {
2737
- $r2 = $r1;
2738
- }
2739
-
2740
- if ($nSeg < 2) {
2741
- $nSeg = 2;
2742
- }
2743
-
2744
- $astart = deg2rad((float)$astart);
2745
- $afinish = deg2rad((float)$afinish);
2746
- $totalAngle = $afinish-$astart;
2747
-
2748
- $dt = $totalAngle/$nSeg;
2749
- $dtm = $dt/3;
2750
-
2751
- if ($angle != 0) {
2752
- $a = -1*deg2rad((float)$angle);
2753
-
2754
- $this->objects[$this->currentContents]['c'] .=
2755
- sprintf("\n q %.3F %.3F %.3F %.3F %.3F %.3F cm", cos($a), -sin($a), sin($a), cos($a), $x0, $y0);
2756
-
2757
- $x0 = 0;
2758
- $y0 = 0;
2759
- }
2760
-
2761
- $t1 = $astart;
2762
- $a0 = $x0 + $r1*cos($t1);
2763
- $b0 = $y0 + $r2*sin($t1);
2764
- $c0 = -$r1 * sin($t1);
2765
- $d0 = $r2 * cos($t1);
2766
-
2767
- $this->objects[$this->currentContents]['c'] .= sprintf("\n%.3F %.3F m ", $a0, $b0);
2768
-
2769
- for ($i = 1; $i <= $nSeg; $i++) {
2770
- // draw this bit of the total curve
2771
- $t1 = $i * $dt + $astart;
2772
- $a1 = $x0 + $r1 * cos($t1);
2773
- $b1 = $y0 + $r2 * sin($t1);
2774
- $c1 = -$r1 * sin($t1);
2775
- $d1 = $r2 * cos($t1);
2776
-
2777
- $this->objects[$this->currentContents]['c'] .=
2778
- sprintf("\n%.3F %.3F %.3F %.3F %.3F %.3F c", ($a0+$c0*$dtm), ($b0+$d0*$dtm), ($a1-$c1*$dtm), ($b1-$d1*$dtm), $a1, $b1);
2779
-
2780
- $a0 = $a1;
2781
- $b0 = $b1;
2782
- $c0 = $c1;
2783
- $d0 = $d1;
2784
- }
2785
-
2786
- if ($fill) {
2787
- $this->objects[$this->currentContents]['c'].= ' f';
2788
- } else if ($close) {
2789
- $this->objects[$this->currentContents]['c'].= ' s'; // small 's' signifies closing the path as well
2790
- } else {
2791
- $this->objects[$this->currentContents]['c'].= ' S';
2792
- }
2793
-
2794
- if ($angle != 0) {
2795
- $this->objects[$this->currentContents]['c'].= ' Q';
2796
- }
2797
- }
2798
-
2799
- /**
2800
- * this sets the line drawing style.
2801
- * width, is the thickness of the line in user units
2802
- * cap is the type of cap to put on the line, values can be 'butt','round','square'
2803
- * where the diffference between 'square' and 'butt' is that 'square' projects a flat end past the
2804
- * end of the line.
2805
- * join can be 'miter', 'round', 'bevel'
2806
- * dash is an array which sets the dash pattern, is a series of length values, which are the lengths of the
2807
- * on and off dashes.
2808
- * (2) represents 2 on, 2 off, 2 on , 2 off ...
2809
- * (2,1) is 2 on, 1 off, 2 on, 1 off.. etc
2810
- * phase is a modifier on the dash pattern which is used to shift the point at which the pattern starts.
2811
- */
2812
- function setLineStyle($width = 1, $cap = '', $join = '', $dash = '', $phase = 0) {
2813
- // this is quite inefficient in that it sets all the parameters whenever 1 is changed, but will fix another day
2814
- $string = '';
2815
-
2816
- if ($width>0) {
2817
- $string.= "$width w";
2818
- }
2819
-
2820
- $ca = array('butt' => 0, 'round' => 1, 'square' => 2);
2821
-
2822
- if (isset($ca[$cap])) {
2823
- $string.= " $ca[$cap] J";
2824
- }
2825
-
2826
- $ja = array('miter' => 0, 'round' => 1, 'bevel' => 2);
2827
-
2828
- if (isset($ja[$join])) {
2829
- $string.= " $ja[$join] j";
2830
- }
2831
-
2832
- if (is_array($dash)) {
2833
- $string.= ' [ ' . implode(' ', $dash) . " ] $phase d";
2834
- }
2835
-
2836
- $this->currentLineStyle = $string;
2837
- $this->objects[$this->currentContents]['c'].= "\n$string";
2838
- }
2839
-
2840
- /**
2841
- * draw a polygon, the syntax for this is similar to the GD polygon command
2842
- */
2843
- function polygon($p, $np, $f = false) {
2844
- $this->objects[$this->currentContents]['c'].= sprintf("\n%.3F %.3F m ", $p[0], $p[1]);
2845
-
2846
- for ($i = 2; $i < $np * 2; $i = $i + 2) {
2847
- $this->objects[$this->currentContents]['c'].= sprintf("%.3F %.3F l ", $p[$i], $p[$i+1]);
2848
- }
2849
-
2850
- if ($f) {
2851
- $this->objects[$this->currentContents]['c'].= ' f';
2852
- } else {
2853
- $this->objects[$this->currentContents]['c'].= ' S';
2854
- }
2855
- }
2856
-
2857
- /**
2858
- * a filled rectangle, note that it is the width and height of the rectangle which are the secondary paramaters, not
2859
- * the coordinates of the upper-right corner
2860
- */
2861
- function filledRectangle($x1, $y1, $width, $height) {
2862
- $this->objects[$this->currentContents]['c'].= sprintf("\n%.3F %.3F %.3F %.3F re f", $x1, $y1, $width, $height);
2863
- }
2864
-
2865
- /**
2866
- * draw a rectangle, note that it is the width and height of the rectangle which are the secondary paramaters, not
2867
- * the coordinates of the upper-right corner
2868
- */
2869
- function rectangle($x1, $y1, $width, $height) {
2870
- $this->objects[$this->currentContents]['c'].= sprintf("\n%.3F %.3F %.3F %.3F re S", $x1, $y1, $width, $height);
2871
- }
2872
-
2873
- /**
2874
- * save the current graphic state
2875
- */
2876
- function save() {
2877
- // we must reset the colour cache or it will keep bad colours after clipping
2878
- $this->currentColour = null;
2879
- $this->currentStrokeColour = null;
2880
- $this->objects[$this->currentContents]['c'].= "\nq";
2881
- }
2882
-
2883
- /**
2884
- * restore the last graphic state
2885
- */
2886
- function restore() {
2887
- $this->objects[$this->currentContents]['c'].= "\nQ";
2888
- }
2889
-
2890
- /**
2891
- * draw a clipping rectangle, all the elements added after this will be clipped
2892
- */
2893
- function clippingRectangle($x1, $y1, $width, $height) {
2894
- $this->save();
2895
- $this->objects[$this->currentContents]['c'].= sprintf("\n%.3F %.3F %.3F %.3F re W n", $x1, $y1, $width, $height);
2896
- }
2897
-
2898
- /**
2899
- * ends the last clipping shape
2900
- */
2901
- function clippingEnd() {
2902
- $this->restore();
2903
- }
2904
-
2905
- /**
2906
- * scale
2907
- * @param float $s_x scaling factor for width as percent
2908
- * @param float $s_y scaling factor for height as percent
2909
- * @param float $x Origin abscisse
2910
- * @param float $y Origin ordinate
2911
- */
2912
- function scale($s_x, $s_y, $x, $y) {
2913
- $y = $this->currentPageSize["height"] - $y;
2914
-
2915
- $tm = array(
2916
- $s_x, 0,
2917
- 0, $s_y,
2918
- $x*(1-$s_x), $y*(1-$s_y)
2919
- );
2920
-
2921
- $this->transform($tm);
2922
- }
2923
-
2924
- /**
2925
- * translate
2926
- * @param float $t_x movement to the right
2927
- * @param float $t_y movement to the bottom
2928
- */
2929
- function translate($t_x, $t_y) {
2930
- $tm = array(
2931
- 1, 0,
2932
- 0, 1,
2933
- $t_x, -$t_y
2934
- );
2935
-
2936
- $this->transform($tm);
2937
- }
2938
-
2939
- /**
2940
- * rotate
2941
- * @param float $angle angle in degrees for counter-clockwise rotation
2942
- * @param float $x Origin abscisse
2943
- * @param float $y Origin ordinate
2944
- */
2945
- function rotate($angle, $x, $y) {
2946
- $y = $this->currentPageSize["height"] - $y;
2947
-
2948
- $a = deg2rad($angle);
2949
- $cos_a = cos($a);
2950
- $sin_a = sin($a);
2951
-
2952
- $tm = array(
2953
- $cos_a, -$sin_a,
2954
- $sin_a, $cos_a,
2955
- $x - $sin_a*$y - $cos_a*$x, $y - $cos_a*$y + $sin_a*$x,
2956
- );
2957
-
2958
- $this->transform($tm);
2959
- }
2960
-
2961
- /**
2962
- * skew
2963
- * @param float $angle_x
2964
- * @param float $angle_y
2965
- * @param float $x Origin abscisse
2966
- * @param float $y Origin ordinate
2967
- */
2968
- function skew($angle_x, $angle_y, $x, $y) {
2969
- $y = $this->currentPageSize["height"] - $y;
2970
-
2971
- $tan_x = tan(deg2rad($angle_x));
2972
- $tan_y = tan(deg2rad($angle_y));
2973
-
2974
- $tm = array(
2975
- 1, -$tan_y,
2976
- -$tan_x, 1,
2977
- $tan_x*$y, $tan_y*$x,
2978
- );
2979
-
2980
- $this->transform($tm);
2981
- }
2982
-
2983
- /**
2984
- * apply graphic transformations
2985
- * @param array $tm transformation matrix
2986
- */
2987
- function transform($tm) {
2988
- $this->objects[$this->currentContents]['c'].=
2989
- vsprintf("\n %.3F %.3F %.3F %.3F %.3F %.3F cm", $tm);
2990
- }
2991
-
2992
- /**
2993
- * add a new page to the document
2994
- * this also makes the new page the current active object
2995
- */
2996
- function newPage($insert = 0, $id = 0, $pos = 'after') {
2997
- // if there is a state saved, then go up the stack closing them
2998
- // then on the new page, re-open them with the right setings
2999
-
3000
- if ($this->nStateStack) {
3001
- for ($i = $this->nStateStack;$i >= 1;$i--) {
3002
- $this->restoreState($i);
3003
- }
3004
- }
3005
-
3006
- $this->numObj++;
3007
-
3008
- if ($insert) {
3009
- // the id from the ezPdf class is the id of the contents of the page, not the page object itself
3010
- // query that object to find the parent
3011
- $rid = $this->objects[$id]['onPage'];
3012
- $opt = array('rid' => $rid, 'pos' => $pos);
3013
- $this->o_page($this->numObj, 'new', $opt);
3014
- } else {
3015
- $this->o_page($this->numObj, 'new');
3016
- }
3017
-
3018
- // if there is a stack saved, then put that onto the page
3019
- if ($this->nStateStack) {
3020
- for ($i = 1;$i <= $this->nStateStack;$i++) {
3021
- $this->saveState($i);
3022
- }
3023
- }
3024
-
3025
- // and if there has been a stroke or fill colour set, then transfer them
3026
- if (isset($this->currentColour)) {
3027
- $this->setColor($this->currentColour, true);
3028
- }
3029
-
3030
- if (isset($this->currentStrokeColour)) {
3031
- $this->setStrokeColor($this->currentStrokeColour, true);
3032
- }
3033
-
3034
- // if there is a line style set, then put this in too
3035
- if (mb_strlen($this->currentLineStyle, '8bit')) {
3036
- $this->objects[$this->currentContents]['c'].= "\n$this->currentLineStyle";
3037
- }
3038
-
3039
- // the call to the o_page object set currentContents to the present page, so this can be returned as the page id
3040
- return $this->currentContents;
3041
- }
3042
-
3043
- /**
3044
- * output the pdf code, streaming it to the browser
3045
- * the relevant headers are set so that hopefully the browser will recognise it
3046
- */
3047
- function stream($options = '') {
3048
- // setting the options allows the adjustment of the headers
3049
- // values at the moment are:
3050
- // 'Content-Disposition' => 'filename' - sets the filename, though not too sure how well this will
3051
- // work as in my trial the browser seems to use the filename of the php file with .pdf on the end
3052
- // 'Accept-Ranges' => 1 or 0 - if this is not set to 1, then this header is not included, off by default
3053
- // this header seems to have caused some problems despite tha fact that it is supposed to solve
3054
- // them, so I am leaving it off by default.
3055
- // 'compress' = > 1 or 0 - apply content stream compression, this is on (1) by default
3056
- // 'Attachment' => 1 or 0 - if 1, force the browser to open a download dialog
3057
- if (!is_array($options)) {
3058
- $options = array();
3059
- }
3060
-
3061
- if ( headers_sent())
3062
- die("Unable to stream pdf: headers already sent");
3063
-
3064
- $debug = empty($options['compression']);
3065
- $tmp = ltrim($this->output($debug));
3066
-
3067
- header("Cache-Control: private");
3068
- header("Content-type: application/pdf");
3069
-
3070
- //FIXME: I don't know that this is sufficient for determining content length (i.e. what about transport compression?)
3071
- header("Content-Length: " . mb_strlen($tmp, '8bit'));
3072
- $fileName = (isset($options['Content-Disposition']) ? $options['Content-Disposition'] : 'file.pdf');
3073
-
3074
- if ( !isset($options["Attachment"]))
3075
- $options["Attachment"] = true;
3076
-
3077
- $attachment = $options["Attachment"] ? "attachment" : "inline";
3078
-
3079
- header("Content-Disposition: $attachment; filename=\"$fileName\"");
3080
-
3081
- if (isset($options['Accept-Ranges']) && $options['Accept-Ranges'] == 1) {
3082
- //FIXME: Is this the correct value ... spec says 1#range-unit
3083
- header("Accept-Ranges: " . mb_strlen($tmp, '8bit'));
3084
- }
3085
-
3086
- echo $tmp;
3087
- flush();
3088
- }
3089
-
3090
- /**
3091
- * return the height in units of the current font in the given size
3092
- */
3093
- function getFontHeight($size) {
3094
- if (!$this->numFonts) {
3095
- $this->selectFont($this->defaultFont);
3096
- }
3097
-
3098
- $font = $this->fonts[$this->currentFont];
3099
-
3100
- // for the current font, and the given size, what is the height of the font in user units
3101
- if ( isset($font['Ascender']) && isset($font['Descender']) ) {
3102
- $h = $font['Ascender']-$font['Descender'];
3103
- }
3104
- else {
3105
- $h = $font['FontBBox'][3]-$font['FontBBox'][1];
3106
- }
3107
-
3108
- // have to adjust by a font offset for Windows fonts. unfortunately it looks like
3109
- // the bounding box calculations are wrong and I don't know why.
3110
- if (isset($font['FontHeightOffset'])) {
3111
- // For CourierNew from Windows this needs to be -646 to match the
3112
- // Adobe native Courier font.
3113
- //
3114
- // For FreeMono from GNU this needs to be -337 to match the
3115
- // Courier font.
3116
- //
3117
- // Both have been added manually to the .afm and .ufm files.
3118
- $h += (int)$font['FontHeightOffset'];
3119
- }
3120
-
3121
- return $size*$h/1000;
3122
- }
3123
-
3124
- function getFontXHeight($size) {
3125
- if (!$this->numFonts) {
3126
- $this->selectFont($this->defaultFont);
3127
- }
3128
-
3129
- $font = $this->fonts[$this->currentFont];
3130
-
3131
- // for the current font, and the given size, what is the height of the font in user units
3132
- if ( isset($font['XHeight']) ) {
3133
- $xh = $font['Ascender']-$font['Descender'];
3134
- }
3135
- else {
3136
- $xh = $this->getFontHeight($size) / 2;
3137
- }
3138
-
3139
- return $size*$xh/1000;
3140
- }
3141
-
3142
- /**
3143
- * return the font descender, this will normally return a negative number
3144
- * if you add this number to the baseline, you get the level of the bottom of the font
3145
- * it is in the pdf user units
3146
- */
3147
- function getFontDescender($size) {
3148
- // note that this will most likely return a negative value
3149
- if (!$this->numFonts) {
3150
- $this->selectFont($this->defaultFont);
3151
- }
3152
-
3153
- //$h = $this->fonts[$this->currentFont]['FontBBox'][1];
3154
- $h = $this->fonts[$this->currentFont]['Descender'];
3155
-
3156
- return $size*$h/1000;
3157
- }
3158
-
3159
- /**
3160
- * filter the text, this is applied to all text just before being inserted into the pdf document
3161
- * it escapes the various things that need to be escaped, and so on
3162
- *
3163
- * @access private
3164
- */
3165
- function filterText($text, $bom = true, $convert_encoding = true) {
3166
- if (!$this->numFonts) {
3167
- $this->selectFont($this->defaultFont);
3168
- }
3169
-
3170
- if ($convert_encoding) {
3171
- $cf = $this->currentFont;
3172
- if (isset($this->fonts[$cf]) && $this->fonts[$cf]['isUnicode']) {
3173
- //$text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
3174
- $text = $this->utf8toUtf16BE($text, $bom);
3175
- } else {
3176
- //$text = html_entity_decode($text, ENT_QUOTES);
3177
- $text = mb_convert_encoding($text, self::$targetEncoding, 'UTF-8');
3178
- }
3179
- }
3180
-
3181
- // the chr(13) substitution fixes a bug seen in TCPDF (bug #1421290)
3182
- return strtr($text, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r'));
3183
- }
3184
-
3185
- /**
3186
- * return array containing codepoints (UTF-8 character values) for the
3187
- * string passed in.
3188
- *
3189
- * based on the excellent TCPDF code by Nicola Asuni and the
3190
- * RFC for UTF-8 at http://www.faqs.org/rfcs/rfc3629.html
3191
- *
3192
- * @access private
3193
- * @author Orion Richardson
3194
- * @since January 5, 2008
3195
- * @param string $text UTF-8 string to process
3196
- * @return array UTF-8 codepoints array for the string
3197
- */
3198
- function utf8toCodePointsArray(&$text) {
3199
- $length = mb_strlen($text, '8bit'); // http://www.php.net/manual/en/function.mb-strlen.php#77040
3200
- $unicode = array(); // array containing unicode values
3201
- $bytes = array(); // array containing single character byte sequences
3202
- $numbytes = 1; // number of octetc needed to represent the UTF-8 character
3203
-
3204
- for ($i = 0; $i < $length; $i++) {
3205
- $c = ord($text[$i]); // get one string character at time
3206
- if (count($bytes) === 0) { // get starting octect
3207
- if ($c <= 0x7F) {
3208
- $unicode[] = $c; // use the character "as is" because is ASCII
3209
- $numbytes = 1;
3210
- } elseif (($c >> 0x05) === 0x06) { // 2 bytes character (0x06 = 110 BIN)
3211
- $bytes[] = ($c - 0xC0) << 0x06;
3212
- $numbytes = 2;
3213
- } elseif (($c >> 0x04) === 0x0E) { // 3 bytes character (0x0E = 1110 BIN)
3214
- $bytes[] = ($c - 0xE0) << 0x0C;
3215
- $numbytes = 3;
3216
- } elseif (($c >> 0x03) === 0x1E) { // 4 bytes character (0x1E = 11110 BIN)
3217
- $bytes[] = ($c - 0xF0) << 0x12;
3218
- $numbytes = 4;
3219
- } else {
3220
- // use replacement character for other invalid sequences
3221
- $unicode[] = 0xFFFD;
3222
- $bytes = array();
3223
- $numbytes = 1;
3224
- }
3225
- } elseif (($c >> 0x06) === 0x02) { // bytes 2, 3 and 4 must start with 0x02 = 10 BIN
3226
- $bytes[] = $c - 0x80;
3227
- if (count($bytes) === $numbytes) {
3228
- // compose UTF-8 bytes to a single unicode value
3229
- $c = $bytes[0];
3230
- for ($j = 1; $j < $numbytes; $j++) {
3231
- $c += ($bytes[$j] << (($numbytes - $j - 1) * 0x06));
3232
- }
3233
- if ((($c >= 0xD800) AND ($c <= 0xDFFF)) OR ($c >= 0x10FFFF)) {
3234
- // The definition of UTF-8 prohibits encoding character numbers between
3235
- // U+D800 and U+DFFF, which are reserved for use with the UTF-16
3236
- // encoding form (as surrogate pairs) and do not directly represent
3237
- // characters.
3238
- $unicode[] = 0xFFFD; // use replacement character
3239
- } else {
3240
- $unicode[] = $c; // add char to array
3241
- }
3242
- // reset data for next char
3243
- $bytes = array();
3244
- $numbytes = 1;
3245
- }
3246
- } else {
3247
- // use replacement character for other invalid sequences
3248
- $unicode[] = 0xFFFD;
3249
- $bytes = array();
3250
- $numbytes = 1;
3251
- }
3252
- }
3253
- return $unicode;
3254
- }
3255
-
3256
- /**
3257
- * convert UTF-8 to UTF-16 with an additional byte order marker
3258
- * at the front if required.
3259
- *
3260
- * based on the excellent TCPDF code by Nicola Asuni and the
3261
- * RFC for UTF-8 at http://www.faqs.org/rfcs/rfc3629.html
3262
- *
3263
- * @access private
3264
- * @author Orion Richardson
3265
- * @since January 5, 2008
3266
- * @param string $text UTF-8 string to process
3267
- * @param boolean $bom whether to add the byte order marker
3268
- * @return string UTF-16 result string
3269
- */
3270
- function utf8toUtf16BE(&$text, $bom = true) {
3271
- $cf = $this->currentFont;
3272
- if (!$this->fonts[$cf]['isUnicode']) return $text;
3273
- $out = $bom ? "\xFE\xFF" : '';
3274
-
3275
- $unicode = $this->utf8toCodePointsArray($text);
3276
- foreach ($unicode as $c) {
3277
- if ($c === 0xFFFD) {
3278
- $out .= "\xFF\xFD"; // replacement character
3279
- } elseif ($c < 0x10000) {
3280
- $out .= chr($c >> 0x08) . chr($c & 0xFF);
3281
- } else {
3282
- $c -= 0x10000;
3283
- $w1 = 0xD800 | ($c >> 0x10);
3284
- $w2 = 0xDC00 | ($c & 0x3FF);
3285
- $out .= chr($w1 >> 0x08) . chr($w1 & 0xFF) . chr($w2 >> 0x08) . chr($w2 & 0xFF);
3286
- }
3287
- }
3288
- return $out;
3289
- }
3290
-
3291
- /**
3292
- * given a start position and information about how text is to be laid out, calculate where
3293
- * on the page the text will end
3294
- *
3295
- * @access private
3296
- */
3297
- function PRVTgetTextPosition($x, $y, $angle, $size, $wa, $text) {
3298
- // given this information return an array containing x and y for the end position as elements 0 and 1
3299
- $w = $this->getTextWidth($size, $text);
3300
-
3301
- // need to adjust for the number of spaces in this text
3302
- $words = explode(' ', $text);
3303
- $nspaces = count($words) -1;
3304
- $w+= $wa*$nspaces;
3305
- $a = deg2rad((float)$angle);
3306
-
3307
- return array(cos($a) *$w+$x, -sin($a) *$w+$y);
3308
- }
3309
-
3310
- /**
3311
- * wrapper function for PRVTcheckTextDirective1
3312
- *
3313
- * @access private
3314
- */
3315
- function PRVTcheckTextDirective(&$text, $i, &$f) {
3316
- return 0;
3317
- $x = 0;
3318
- $y = 0;
3319
- return $this->PRVTcheckTextDirective1($text, $i, $f, 0, $x, $y);
3320
- }
3321
-
3322
- /**
3323
- * checks if the text stream contains a control directive
3324
- * if so then makes some changes and returns the number of characters involved in the directive
3325
- * this has been re-worked to include everything neccesary to find the current writing point, so that
3326
- * the location can be sent to the callback function if required
3327
- * if the directive does not require a font change, then $f should be set to 0
3328
- *
3329
- * @access private
3330
- */
3331
- function PRVTcheckTextDirective1(&$text, $i, &$f, $final, &$x, &$y, $size = 0, $angle = 0, $wordSpaceAdjust = 0) {
3332
- return 0;
3333
- $directive = 0;
3334
- $j = $i;
3335
- if ($text[$j] === '<') {
3336
- $j++;
3337
- switch ($text[$j]) {
3338
- case '/':
3339
- $j++;
3340
- if (mb_strlen($text) <= $j) {
3341
- return $directive;
3342
- }
3343
-
3344
- switch ($text[$j]) {
3345
- case 'b':
3346
- case 'i':
3347
- $j++;
3348
- if ($text[$j] === '>') {
3349
- $p = mb_strrpos($this->currentTextState, $text[$j-1]);
3350
-
3351
- if ($p !== false) {
3352
- // then there is one to remove
3353
- $this->currentTextState = mb_substr($this->currentTextState, 0, $p) .substr($this->currentTextState, $p+1);
3354
- }
3355
-
3356
- $directive = $j-$i+1;
3357
- }
3358
- break;
3359
-
3360
- case 'c':
3361
- // this this might be a callback function
3362
- $j++;
3363
- $k = mb_strpos($text, '>', $j);
3364
-
3365
- if ($k !== false && $text[$j] === ':') {
3366
- // then this will be treated as a callback directive
3367
- $directive = $k-$i+1;
3368
- $f = 0;
3369
- // split the remainder on colons to get the function name and the paramater
3370
- $tmp = mb_substr($text, $j+1, $k-$j-1);
3371
- $b1 = mb_strpos($tmp, ':');
3372
-
3373
- if ($b1 !== false) {
3374
- $func = mb_substr($tmp, 0, $b1);
3375
- $parm = mb_substr($tmp, $b1+1);
3376
- } else {
3377
- $func = $tmp;
3378
- $parm = '';
3379
- }
3380
-
3381
- if (!isset($func) || !mb_strlen(trim($func), '8bit')) {
3382
- $directive = 0;
3383
- } else {
3384
- // only call the function if this is the final call
3385
- if ($final) {
3386
- // need to assess the text position, calculate the text width to this point
3387
- // can use getTextWidth to find the text width I think
3388
- $tmp = $this->PRVTgetTextPosition($x, $y, $angle, $size, $wordSpaceAdjust, mb_substr($text, 0, $i));
3389
-
3390
- $info = array('x' => $tmp[0], 'y' => $tmp[1], 'angle' => $angle, 'status' => 'end', 'p' => $parm, 'nCallback' => $this->nCallback);
3391
- $x = $tmp[0];
3392
- $y = $tmp[1];
3393
- $ret = $this->$func($info);
3394
-
3395
- if (is_array($ret)) {
3396
- // then the return from the callback function could set the position, to start with, later will do font colour, and font
3397
- foreach($ret as $rk => $rv) {
3398
- switch ($rk) {
3399
- case 'x':
3400
- case 'y':
3401
- $$rk = $rv;
3402
- break;
3403
- }
3404
- }
3405
- }
3406
-
3407
- // also remove from to the stack
3408
- // for simplicity, just take from the end, fix this another day
3409
- $this->nCallback--;
3410
- if ($this->nCallback<0) {
3411
- $this->nCallBack = 0;
3412
- }
3413
- }
3414
- }
3415
- }
3416
- break;
3417
- }
3418
- break;
3419
-
3420
- case 'b':
3421
- case 'i':
3422
- $j++;
3423
- if ($text[$j] === '>') {
3424
- $this->currentTextState.= $text[$j-1];
3425
- $directive = $j-$i+1;
3426
- }
3427
- break;
3428
-
3429
- case 'C':
3430
- $noClose = 1;
3431
- case 'c':
3432
- // this this might be a callback function
3433
- $j++;
3434
- $k = mb_strpos($text, '>', $j);
3435
-
3436
- if ($k !== false && $text[$j] === ':') {
3437
- // then this will be treated as a callback directive
3438
- $directive = $k-$i+1;
3439
-
3440
- $f = 0;
3441
-
3442
- // split the remainder on colons to get the function name and the paramater
3443
- // $bits = explode(':',substr($text,$j+1,$k-$j-1));
3444
- $tmp = mb_substr($text, $j+1, $k-$j-1);
3445
- $b1 = mb_strpos($tmp, ':');
3446
-
3447
- if ($b1 !== false) {
3448
- $func = mb_substr($tmp, 0, $b1);
3449
- $parm = mb_substr($tmp, $b1+1);
3450
- } else {
3451
- $func = $tmp;
3452
- $parm = '';
3453
- }
3454
-
3455
- if (!isset($func) || !mb_strlen(trim($func), '8bit')) {
3456
- $directive = 0;
3457
- } else {
3458
- // only call the function if this is the final call, ie, the one actually doing printing, not measurement
3459
- if ($final) {
3460
- // need to assess the text position, calculate the text width to this point
3461
- // can use getTextWidth to find the text width I think
3462
- // also add the text height and descender
3463
- $tmp = $this->PRVTgetTextPosition($x, $y, $angle, $size, $wordSpaceAdjust, mb_substr($text, 0, $i));
3464
-
3465
- $info = array(
3466
- 'x' => $tmp[0],
3467
- 'y' => $tmp[1],
3468
- 'angle' => $angle,
3469
- 'status' => 'start',
3470
- 'p' => $parm,
3471
- 'f' => $func,
3472
- 'height' => $this->getFontHeight($size),
3473
- 'descender' => $this->getFontDescender($size)
3474
- );
3475
- $x = $tmp[0];
3476
- $y = $tmp[1];
3477
-
3478
- if (!isset($noClose) || !$noClose) {
3479
- // only add to the stack if this is a small 'c', therefore is a start-stop pair
3480
- $this->nCallback++;
3481
- $info['nCallback'] = $this->nCallback;
3482
- $this->callback[$this->nCallback] = $info;
3483
- }
3484
-
3485
- $ret = $this->$func($info);
3486
- if (is_array($ret)) {
3487
- // then the return from the callback function could set the position, to start with, later will do font colour, and font
3488
- foreach($ret as $rk => $rv) {
3489
- switch ($rk) {
3490
- case 'x':
3491
- case 'y':
3492
- $$rk = $rv;
3493
- break;
3494
- }
3495
- }
3496
- }
3497
- }
3498
- }
3499
- }
3500
- break;
3501
- }
3502
- }
3503
-
3504
- return $directive;
3505
- }
3506
-
3507
- /**
3508
- * Callback method used by smallCaps
3509
- *
3510
- * @param array $matches
3511
- * @return string
3512
- */
3513
- function toUpper($matches) {
3514
- return mb_strtoupper($matches[0]);
3515
- }
3516
-
3517
- function concatMatches($matches) {
3518
- $str = "";
3519
- foreach($matches as $match){
3520
- $str .= $match[0];
3521
- }
3522
- return $str;
3523
- }
3524
-
3525
- /**
3526
- * add text to the document, at a specified location, size and angle on the page
3527
- */
3528
- function registerText($font, $text) {
3529
- if ( !$this->isUnicode || in_array(mb_strtolower(basename($font)), self::$coreFonts) ) {
3530
- return;
3531
- }
3532
-
3533
- if ( !isset($this->stringSubsets[$font]) ) {
3534
- $this->stringSubsets[$font] = array();
3535
- }
3536
-
3537
- $this->stringSubsets[$font] = array_unique(array_merge($this->stringSubsets[$font], $this->utf8toCodePointsArray($text)));
3538
- }
3539
-
3540
- /**
3541
- * add text to the document, at a specified location, size and angle on the page
3542
- */
3543
- function addText($x, $y, $size, $text, $angle = 0, $wordSpaceAdjust = 0, $charSpaceAdjust = 0, $smallCaps = false) {
3544
- if (!$this->numFonts) {
3545
- $this->selectFont($this->defaultFont);
3546
- }
3547
-
3548
- $text = str_replace(array("\r", "\n"), "", $text);
3549
-
3550
- if ( $smallCaps ) {
3551
- preg_match_all("/(\P{Ll}+)/u", $text, $matches, PREG_SET_ORDER);
3552
- $lower = $this->concatMatches($matches);
3553
- d($lower);
3554
-
3555
- preg_match_all("/(\p{Ll}+)/u", $text, $matches, PREG_SET_ORDER);
3556
- $other = $this->concatMatches($matches);
3557
- d($other);
3558
-
3559
- //$text = preg_replace_callback("/\p{Ll}/u", array($this, "toUpper"), $text);
3560
- }
3561
-
3562
- // if there are any open callbacks, then they should be called, to show the start of the line
3563
- if ($this->nCallback>0) {
3564
- for ($i = $this->nCallback;$i>0;$i--) {
3565
- // call each function
3566
- $info = array('x' => $x,
3567
- 'y' => $y,
3568
- 'angle' => $angle,
3569
- 'status' => 'sol',
3570
- 'p' => $this->callback[$i]['p'],
3571
- 'nCallback' => $this->callback[$i]['nCallback'],
3572
- 'height' => $this->callback[$i]['height'],
3573
- 'descender' => $this->callback[$i]['descender']);
3574
-
3575
- $func = $this->callback[$i]['f'];
3576
- $this->$func($info);
3577
- }
3578
- }
3579
-
3580
- if ($angle == 0) {
3581
- $this->objects[$this->currentContents]['c'].= sprintf("\nBT %.3F %.3F Td", $x, $y);
3582
- } else {
3583
- $a = deg2rad((float)$angle);
3584
- $this->objects[$this->currentContents]['c'].=
3585
- sprintf("\nBT %.3F %.3F %.3F %.3F %.3F %.3F Tm", cos($a), -sin($a), sin($a), cos($a), $x, $y);
3586
- }
3587
-
3588
- if ($wordSpaceAdjust != 0 || $wordSpaceAdjust != $this->wordSpaceAdjust) {
3589
- $this->wordSpaceAdjust = $wordSpaceAdjust;
3590
- $this->objects[$this->currentContents]['c'].= sprintf(" %.3F Tw", $wordSpaceAdjust);
3591
- }
3592
-
3593
- if ($charSpaceAdjust != 0 || $charSpaceAdjust != $this->charSpaceAdjust) {
3594
- $this->charSpaceAdjust = $charSpaceAdjust;
3595
- $this->objects[$this->currentContents]['c'].= sprintf(" %.3F Tc", $charSpaceAdjust);
3596
- }
3597
-
3598
- $len = mb_strlen($text);
3599
- $start = 0;
3600
-
3601
- /*
3602
- for ($i = 0;$i<$len;$i++){
3603
- $f = 1;
3604
- $directive = 0; //$this->PRVTcheckTextDirective($text,$i,$f);
3605
- if ($directive){
3606
- // then we should write what we need to
3607
- if ($i>$start){
3608
- $part = mb_substr($text,$start,$i-$start);
3609
- $this->objects[$this->currentContents]['c'] .= ' /F'.$this->currentFontNum.' '.sprintf('%.1F',$size).' Tf ';
3610
- $this->objects[$this->currentContents]['c'] .= ' ('.$this->filterText($part, false).') Tj';
3611
- }
3612
- if ($f){
3613
- // then there was nothing drastic done here, restore the contents
3614
- $this->setCurrentFont();
3615
- } else {
3616
- $this->objects[$this->currentContents]['c'] .= ' ET';
3617
- $f = 1;
3618
- $xp = $x;
3619
- $yp = $y;
3620
- $directive = 0; //$this->PRVTcheckTextDirective1($text,$i,$f,1,$xp,$yp,$size,$angle,$wordSpaceAdjust);
3621
-
3622
- // restart the text object
3623
- if ($angle == 0){
3624
- $this->objects[$this->currentContents]['c'] .= "\n".'BT '.sprintf('%.3F',$xp).' '.sprintf('%.3F',$yp).' Td';
3625
- } else {
3626
- $a = deg2rad((float)$angle);
3627
- $tmp = "\n".'BT ';
3628
- $tmp .= sprintf('%.3F',cos($a)).' '.sprintf('%.3F',(-1.0*sin($a))).' '.sprintf('%.3F',sin($a)).' '.sprintf('%.3F',cos($a)).' ';
3629
- $tmp .= sprintf('%.3F',$xp).' '.sprintf('%.3F',$yp).' Tm';
3630
- $this->objects[$this->currentContents]['c'] .= $tmp;
3631
- }
3632
- if ($wordSpaceAdjust != 0 || $wordSpaceAdjust != $this->wordSpaceAdjust){
3633
- $this->wordSpaceAdjust = $wordSpaceAdjust;
3634
- $this->objects[$this->currentContents]['c'] .= ' '.sprintf('%.3F',$wordSpaceAdjust).' Tw';
3635
- }
3636
- }
3637
- // and move the writing point to the next piece of text
3638
- $i = $i+$directive-1;
3639
- $start = $i+1;
3640
- }
3641
-
3642
- }
3643
- */
3644
- if ($start < $len) {
3645
- $part = $text; // OAR - Don't need this anymore, given that $start always equals zero. substr($text, $start);
3646
- $place_text = $this->filterText($part, false);
3647
- // modify unicode text so that extra word spacing is manually implemented (bug #)
3648
- $cf = $this->currentFont;
3649
- if ($this->fonts[$cf]['isUnicode'] && $wordSpaceAdjust != 0) {
3650
- $space_scale = 1000 / $size;
3651
- //$place_text = str_replace(' ', ') ( ) '.($this->getTextWidth($size, chr(32), $wordSpaceAdjust)*-75).' (', $place_text);
3652
- $place_text = str_replace(' ', ' ) '.(-round($space_scale*$wordSpaceAdjust)).' (', $place_text);
3653
- }
3654
- $this->objects[$this->currentContents]['c'].= " /F$this->currentFontNum ".sprintf('%.1F Tf ', $size);
3655
- $this->objects[$this->currentContents]['c'].= " [($place_text)] TJ";
3656
- }
3657
-
3658
- $this->objects[$this->currentContents]['c'].= ' ET';
3659
-
3660
- // if there are any open callbacks, then they should be called, to show the end of the line
3661
- if ($this->nCallback>0) {
3662
- for ($i = $this->nCallback;$i>0;$i--) {
3663
- // call each function
3664
- $tmp = $this->PRVTgetTextPosition($x, $y, $angle, $size, $wordSpaceAdjust, $text);
3665
- $info = array(
3666
- 'x' => $tmp[0],
3667
- 'y' => $tmp[1],
3668
- 'angle' => $angle,
3669
- 'status' => 'eol',
3670
- 'p' => $this->callback[$i]['p'],
3671
- 'nCallback' => $this->callback[$i]['nCallback'],
3672
- 'height' => $this->callback[$i]['height'],
3673
- 'descender' => $this->callback[$i]['descender']
3674
- );
3675
- $func = $this->callback[$i]['f'];
3676
- $this->$func($info);
3677
- }
3678
- }
3679
- }
3680
-
3681
- /**
3682
- * calculate how wide a given text string will be on a page, at a given size.
3683
- * this can be called externally, but is alse used by the other class functions
3684
- */
3685
- function getTextWidth($size, $text, $word_spacing = 0, $char_spacing = 0) {
3686
- static $ord_cache = array();
3687
-
3688
- // this function should not change any of the settings, though it will need to
3689
- // track any directives which change during calculation, so copy them at the start
3690
- // and put them back at the end.
3691
- $store_currentTextState = $this->currentTextState;
3692
-
3693
- if (!$this->numFonts) {
3694
- $this->selectFont($this->defaultFont);
3695
- }
3696
-
3697
- $text = str_replace(array("\r", "\n"), "", $text);
3698
-
3699
- // converts a number or a float to a string so it can get the width
3700
- $text = "$text";
3701
-
3702
- // hmm, this is where it all starts to get tricky - use the font information to
3703
- // calculate the width of each character, add them up and convert to user units
3704
- $w = 0;
3705
- $cf = $this->currentFont;
3706
- $current_font = $this->fonts[$cf];
3707
- $space_scale = 1000 / $size;
3708
- $n_spaces = 0;
3709
-
3710
- if ( $current_font['isUnicode']) {
3711
- // for Unicode, use the code points array to calculate width rather
3712
- // than just the string itself
3713
- $unicode = $this->utf8toCodePointsArray($text);
3714
-
3715
- foreach ($unicode as $char) {
3716
- // check if we have to replace character
3717
- if ( isset($current_font['differences'][$char])) {
3718
- $char = $current_font['differences'][$char];
3719
- }
3720
-
3721
- if ( isset($current_font['C'][$char]) ) {
3722
- $char_width = $current_font['C'][$char];
3723
-
3724
- // add the character width
3725
- $w += $char_width;
3726
-
3727
- // add additional padding for space
3728
- if ( isset($current_font['codeToName'][$char]) && $current_font['codeToName'][$char] === 'space' ) { // Space
3729
- $w += $word_spacing * $space_scale;
3730
- $n_spaces++;
3731
- }
3732
- }
3733
- }
3734
-
3735
- // add additionnal char spacing
3736
- if ( $char_spacing != 0 ) {
3737
- $w += $char_spacing * $space_scale * (count($unicode) + $n_spaces);
3738
- }
3739
-
3740
- } else {
3741
- // If CPDF is in Unicode mode but the current font does not support Unicode we need to convert the character set to Windows-1252
3742
- if ( $this->isUnicode ) {
3743
- $text = mb_convert_encoding($text, 'Windows-1252', 'UTF-8');
3744
- }
3745
-
3746
- $len = mb_strlen($text, 'Windows-1252');
3747
-
3748
- for ($i = 0; $i < $len; $i++) {
3749
- $c = $text[$i];
3750
- $char = isset($ord_cache[$c]) ? $ord_cache[$c] : ($ord_cache[$c] = ord($c));
3751
-
3752
- // check if we have to replace character
3753
- if ( isset($current_font['differences'][$char])) {
3754
- $char = $current_font['differences'][$char];
3755
- }
3756
-
3757
- if ( isset($current_font['C'][$char]) ) {
3758
- $char_width = $current_font['C'][$char];
3759
-
3760
- // add the character width
3761
- $w += $char_width;
3762
-
3763
- // add additional padding for space
3764
- if ( isset($current_font['codeToName'][$char]) && $current_font['codeToName'][$char] === 'space' ) { // Space
3765
- $w += $word_spacing * $space_scale;
3766
- $n_spaces++;
3767
- }
3768
- }
3769
- }
3770
-
3771
- // add additionnal char spacing
3772
- if ( $char_spacing != 0 ) {
3773
- $w += $char_spacing * $space_scale * ($len + $n_spaces);
3774
- }
3775
- }
3776
-
3777
- $this->currentTextState = $store_currentTextState;
3778
- $this->setCurrentFont();
3779
-
3780
- return $w*$size/1000;
3781
- }
3782
-
3783
- /**
3784
- * do a part of the calculation for sorting out the justification of the text
3785
- *
3786
- * @access private
3787
- */
3788
- function PRVTadjustWrapText($text, $actual, $width, &$x, &$adjust, $justification) {
3789
- switch ($justification) {
3790
- case 'left':
3791
- return;
3792
-
3793
- case 'right':
3794
- $x+= $width-$actual;
3795
- break;
3796
-
3797
- case 'center':
3798
- case 'centre':
3799
- $x+= ($width-$actual) /2;
3800
- break;
3801
-
3802
- case 'full':
3803
- // count the number of words
3804
- $words = explode(' ', $text);
3805
- $nspaces = count($words) -1;
3806
-
3807
- if ($nspaces>0) {
3808
- $adjust = ($width-$actual) /$nspaces;
3809
- } else {
3810
- $adjust = 0;
3811
- }
3812
- break;
3813
- }
3814
- }
3815
-
3816
- /**
3817
- * add text to the page, but ensure that it fits within a certain width
3818
- * if it does not fit then put in as much as possible, splitting at word boundaries
3819
- * and return the remainder.
3820
- * justification and angle can also be specified for the text
3821
- */
3822
- function addTextWrap($x, $y, $width, $size, $text, $justification = 'left', $angle = 0, $test = 0) {
3823
- // TODO - need to support Unicode
3824
- $cf = $this->currentFont;
3825
- if ($this->fonts[$cf]['isUnicode']) {
3826
- die("addTextWrap does not support Unicode yet!");
3827
- }
3828
-
3829
- // this will display the text, and if it goes beyond the width $width, will backtrack to the
3830
- // previous space or hyphen, and return the remainder of the text.
3831
-
3832
- // $justification can be set to 'left','right','center','centre','full'
3833
-
3834
- // need to store the initial text state, as this will change during the width calculation
3835
- // but will need to be re-set before printing, so that the chars work out right
3836
- $store_currentTextState = $this->currentTextState;
3837
-
3838
- if (!$this->numFonts) {
3839
- $this->selectFont($this->defaultFont);
3840
- }
3841
-
3842
- if ($width <= 0) {
3843
- // error, pretend it printed ok, otherwise risking a loop
3844
- return '';
3845
- }
3846
-
3847
- $w = 0;
3848
- $break = 0;
3849
- $breakWidth = 0;
3850
- $len = mb_strlen($text);
3851
- $cf = $this->currentFont;
3852
- $tw = $width/$size*1000;
3853
-
3854
- for ($i = 0;$i<$len;$i++) {
3855
- $f = 1;
3856
- $directive = 0;
3857
- //$this->PRVTcheckTextDirective($text,$i,$f);
3858
- if ($directive) {
3859
- if ($f) {
3860
- $this->setCurrentFont();
3861
- $cf = $this->currentFont;
3862
- }
3863
-
3864
- $i = $i+$directive-1;
3865
- } else {
3866
- $cOrd = ord($text[$i]);
3867
-
3868
- if (isset($this->fonts[$cf]['differences'][$cOrd])) {
3869
- // then this character is being replaced by another
3870
- $cOrd2 = $this->fonts[$cf]['differences'][$cOrd];
3871
- } else {
3872
- $cOrd2 = $cOrd;
3873
- }
3874
-
3875
- if (isset($this->fonts[$cf]['C'][$cOrd2])) {
3876
- $w+= $this->fonts[$cf]['C'][$cOrd2];
3877
- }
3878
-
3879
- if ($w>$tw) {
3880
- // then we need to truncate this line
3881
- if ($break>0) {
3882
- // then we have somewhere that we can split :)
3883
- if ($text[$break] === ' ') {
3884
- $tmp = mb_substr($text, 0, $break);
3885
- } else {
3886
- $tmp = mb_substr($text, 0, $break+1);
3887
- }
3888
-
3889
- $adjust = 0;
3890
- $this->PRVTadjustWrapText($tmp, $breakWidth, $width, $x, $adjust, $justification);
3891
-
3892
- // reset the text state
3893
- $this->currentTextState = $store_currentTextState;
3894
- $this->setCurrentFont();
3895
-
3896
- if (!$test) {
3897
- $this->addText($x, $y, $size, $tmp, $angle, $adjust);
3898
- }
3899
-
3900
- return mb_substr($text, $break+1);
3901
- } else {
3902
- // just split before the current character
3903
- $tmp = mb_substr($text, 0, $i);
3904
- $adjust = 0;
3905
- $ctmp = ord($text[$i]);
3906
-
3907
- if (isset($this->fonts[$cf]['differences'][$ctmp])) {
3908
- $ctmp = $this->fonts[$cf]['differences'][$ctmp];
3909
- }
3910
-
3911
- $tmpw = ($w-$this->fonts[$cf]['C'][$ctmp]) *$size/1000;
3912
- $this->PRVTadjustWrapText($tmp, $tmpw, $width, $x, $adjust, $justification);
3913
-
3914
- // reset the text state
3915
- $this->currentTextState = $store_currentTextState;
3916
- $this->setCurrentFont();
3917
-
3918
- if (!$test) {
3919
- $this->addText($x, $y, $size, $tmp, $angle, $adjust);
3920
- }
3921
-
3922
- return mb_substr($text, $i);
3923
- }
3924
- }
3925
-
3926
- if ($text[$i] === '-') {
3927
- $break = $i;
3928
- $breakWidth = $w*$size/1000;
3929
- }
3930
-
3931
- if ($text[$i] === ' ') {
3932
- $break = $i;
3933
- $ctmp = ord($text[$i]);
3934
-
3935
- if (isset($this->fonts[$cf]['differences'][$ctmp])) {
3936
- $ctmp = $this->fonts[$cf]['differences'][$ctmp];
3937
- }
3938
-
3939
- $breakWidth = ($w-$this->fonts[$cf]['C'][$ctmp]) *$size/1000;
3940
- }
3941
- }
3942
- }
3943
-
3944
- // then there was no need to break this line
3945
- if ($justification === 'full') {
3946
- $justification = 'left';
3947
- }
3948
-
3949
- $adjust = 0;
3950
- $tmpw = $w*$size/1000;
3951
-
3952
- $this->PRVTadjustWrapText($text, $tmpw, $width, $x, $adjust, $justification);
3953
-
3954
- // reset the text state
3955
- $this->currentTextState = $store_currentTextState;
3956
- $this->setCurrentFont();
3957
-
3958
- if (!$test) {
3959
- $this->addText($x, $y, $size, $text, $angle, $adjust);
3960
- }
3961
-
3962
- return '';
3963
- }
3964
-
3965
- /**
3966
- * this will be called at a new page to return the state to what it was on the
3967
- * end of the previous page, before the stack was closed down
3968
- * This is to get around not being able to have open 'q' across pages
3969
- *
3970
- */
3971
- function saveState($pageEnd = 0) {
3972
- if ($pageEnd) {
3973
- // this will be called at a new page to return the state to what it was on the
3974
- // end of the previous page, before the stack was closed down
3975
- // This is to get around not being able to have open 'q' across pages
3976
- $opt = $this->stateStack[$pageEnd];
3977
- // ok to use this as stack starts numbering at 1
3978
- $this->setColor($opt['col'], true);
3979
- $this->setStrokeColor($opt['str'], true);
3980
- $this->objects[$this->currentContents]['c'].= "\n".$opt['lin'];
3981
- // $this->currentLineStyle = $opt['lin'];
3982
- } else {
3983
- $this->nStateStack++;
3984
- $this->stateStack[$this->nStateStack] = array(
3985
- 'col' => $this->currentColour,
3986
- 'str' => $this->currentStrokeColour,
3987
- 'lin' => $this->currentLineStyle
3988
- );
3989
- }
3990
-
3991
- $this->save();
3992
- }
3993
-
3994
- /**
3995
- * restore a previously saved state
3996
- */
3997
- function restoreState($pageEnd = 0) {
3998
- if (!$pageEnd) {
3999
- $n = $this->nStateStack;
4000
- $this->currentColour = $this->stateStack[$n]['col'];
4001
- $this->currentStrokeColour = $this->stateStack[$n]['str'];
4002
- $this->objects[$this->currentContents]['c'].= "\n".$this->stateStack[$n]['lin'];
4003
- $this->currentLineStyle = $this->stateStack[$n]['lin'];
4004
- $this->stateStack[$n] = null;
4005
- unset($this->stateStack[$n]);
4006
- $this->nStateStack--;
4007
- }
4008
-
4009
- $this->restore();
4010
- }
4011
-
4012
- /**
4013
- * make a loose object, the output will go into this object, until it is closed, then will revert to
4014
- * the current one.
4015
- * this object will not appear until it is included within a page.
4016
- * the function will return the object number
4017
- */
4018
- function openObject() {
4019
- $this->nStack++;
4020
- $this->stack[$this->nStack] = array('c' => $this->currentContents, 'p' => $this->currentPage);
4021
- // add a new object of the content type, to hold the data flow
4022
- $this->numObj++;
4023
- $this->o_contents($this->numObj, 'new');
4024
- $this->currentContents = $this->numObj;
4025
- $this->looseObjects[$this->numObj] = 1;
4026
-
4027
- return $this->numObj;
4028
- }
4029
-
4030
- /**
4031
- * open an existing object for editing
4032
- */
4033
- function reopenObject($id) {
4034
- $this->nStack++;
4035
- $this->stack[$this->nStack] = array('c' => $this->currentContents, 'p' => $this->currentPage);
4036
- $this->currentContents = $id;
4037
-
4038
- // also if this object is the primary contents for a page, then set the current page to its parent
4039
- if (isset($this->objects[$id]['onPage'])) {
4040
- $this->currentPage = $this->objects[$id]['onPage'];
4041
- }
4042
- }
4043
-
4044
- /**
4045
- * close an object
4046
- */
4047
- function closeObject() {
4048
- // close the object, as long as there was one open in the first place, which will be indicated by
4049
- // an objectId on the stack.
4050
- if ($this->nStack>0) {
4051
- $this->currentContents = $this->stack[$this->nStack]['c'];
4052
- $this->currentPage = $this->stack[$this->nStack]['p'];
4053
- $this->nStack--;
4054
- // easier to probably not worry about removing the old entries, they will be overwritten
4055
- // if there are new ones.
4056
- }
4057
- }
4058
-
4059
- /**
4060
- * stop an object from appearing on pages from this point on
4061
- */
4062
- function stopObject($id) {
4063
- // if an object has been appearing on pages up to now, then stop it, this page will
4064
- // be the last one that could contian it.
4065
- if (isset($this->addLooseObjects[$id])) {
4066
- $this->addLooseObjects[$id] = '';
4067
- }
4068
- }
4069
-
4070
- /**
4071
- * after an object has been created, it wil only show if it has been added, using this function.
4072
- */
4073
- function addObject($id, $options = 'add') {
4074
- // add the specified object to the page
4075
- if (isset($this->looseObjects[$id]) && $this->currentContents != $id) {
4076
- // then it is a valid object, and it is not being added to itself
4077
- switch ($options) {
4078
- case 'all':
4079
- // then this object is to be added to this page (done in the next block) and
4080
- // all future new pages.
4081
- $this->addLooseObjects[$id] = 'all';
4082
-
4083
- case 'add':
4084
- if (isset($this->objects[$this->currentContents]['onPage'])) {
4085
- // then the destination contents is the primary for the page
4086
- // (though this object is actually added to that page)
4087
- $this->o_page($this->objects[$this->currentContents]['onPage'], 'content', $id);
4088
- }
4089
- break;
4090
-
4091
- case 'even':
4092
- $this->addLooseObjects[$id] = 'even';
4093
- $pageObjectId = $this->objects[$this->currentContents]['onPage'];
4094
- if ($this->objects[$pageObjectId]['info']['pageNum']%2 == 0) {
4095
- $this->addObject($id);
4096
- // hacky huh :)
4097
- }
4098
- break;
4099
-
4100
- case 'odd':
4101
- $this->addLooseObjects[$id] = 'odd';
4102
- $pageObjectId = $this->objects[$this->currentContents]['onPage'];
4103
- if ($this->objects[$pageObjectId]['info']['pageNum']%2 == 1) {
4104
- $this->addObject($id);
4105
- // hacky huh :)
4106
- }
4107
- break;
4108
-
4109
- case 'next':
4110
- $this->addLooseObjects[$id] = 'all';
4111
- break;
4112
-
4113
- case 'nexteven':
4114
- $this->addLooseObjects[$id] = 'even';
4115
- break;
4116
-
4117
- case 'nextodd':
4118
- $this->addLooseObjects[$id] = 'odd';
4119
- break;
4120
- }
4121
- }
4122
- }
4123
-
4124
- /**
4125
- * return a storable representation of a specific object
4126
- */
4127
- function serializeObject($id) {
4128
- if ( array_key_exists($id, $this->objects))
4129
- return var_export($this->objects[$id], true);
4130
- }
4131
-
4132
- /**
4133
- * restore an object from its stored representation. returns its new object id.
4134
- */
4135
- function restoreSerializedObject($obj) {
4136
- $obj_id = $this->openObject();
4137
- eval('$this->objects[$obj_id] = ' . $obj . ';');
4138
- $this->closeObject();
4139
- return $obj_id;
4140
- }
4141
-
4142
- /**
4143
- * add content to the documents info object
4144
- */
4145
- function addInfo($label, $value = 0) {
4146
- // this will only work if the label is one of the valid ones.
4147
- // modify this so that arrays can be passed as well.
4148
- // if $label is an array then assume that it is key => value pairs
4149
- // else assume that they are both scalar, anything else will probably error
4150
- if (is_array($label)) {
4151
- foreach ($label as $l => $v) {
4152
- $this->o_info($this->infoObject, $l, $v);
4153
- }
4154
- } else {
4155
- $this->o_info($this->infoObject, $label, $value);
4156
- }
4157
- }
4158
-
4159
- /**
4160
- * set the viewer preferences of the document, it is up to the browser to obey these.
4161
- */
4162
- function setPreferences($label, $value = 0) {
4163
- // this will only work if the label is one of the valid ones.
4164
- if (is_array($label)) {
4165
- foreach ($label as $l => $v) {
4166
- $this->o_catalog($this->catalogId, 'viewerPreferences', array($l => $v));
4167
- }
4168
- } else {
4169
- $this->o_catalog($this->catalogId, 'viewerPreferences', array($label => $value));
4170
- }
4171
- }
4172
-
4173
- /**
4174
- * extract an integer from a position in a byte stream
4175
- *
4176
- * @access private
4177
- */
4178
- function PRVT_getBytes(&$data, $pos, $num) {
4179
- // return the integer represented by $num bytes from $pos within $data
4180
- $ret = 0;
4181
- for ($i = 0;$i<$num;$i++) {
4182
- $ret = $ret*256;
4183
- $ret+= ord($data[$pos+$i]);
4184
- }
4185
-
4186
- return $ret;
4187
- }
4188
-
4189
- /**
4190
- * Check if image already added to pdf image directory.
4191
- * If yes, need not to create again (pass empty data)
4192
- */
4193
- function image_iscached($imgname) {
4194
- return isset($this->imagelist[$imgname]);
4195
- }
4196
-
4197
- /**
4198
- * add a PNG image into the document, from a GD object
4199
- * this should work with remote files
4200
- *
4201
- * @param string $file The PNG file
4202
- * @param float $x X position
4203
- * @param float $y Y position
4204
- * @param float $w Width
4205
- * @param float $h Height
4206
- * @param resource $img A GD resource
4207
- * @param bool $is_mask true if the image is a mask
4208
- * @param bool $mask true if the image is masked
4209
- */
4210
- function addImagePng($file, $x, $y, $w = 0, $h = 0, &$img, $is_mask = false, $mask = null) {
4211
- //if already cached, need not to read again
4212
- if ( isset($this->imagelist[$file]) ) {
4213
- $data = null;
4214
- }
4215
- else {
4216
- // Example for transparency handling on new image. Retain for current image
4217
- // $tIndex = imagecolortransparent($img);
4218
- // if ($tIndex > 0) {
4219
- // $tColor = imagecolorsforindex($img, $tIndex);
4220
- // $new_tIndex = imagecolorallocate($new_img, $tColor['red'], $tColor['green'], $tColor['blue']);
4221
- // imagefill($new_img, 0, 0, $new_tIndex);
4222
- // imagecolortransparent($new_img, $new_tIndex);
4223
- // }
4224
- // blending mode (literal/blending) on drawing into current image. not relevant when not saved or not drawn
4225
- //imagealphablending($img, true);
4226
-
4227
- //default, but explicitely set to ensure pdf compatibility
4228
- imagesavealpha($img, false/*!$is_mask && !$mask*/);
4229
-
4230
- $error = 0;
4231
- //DEBUG_IMG_TEMP
4232
- //debugpng
4233
- if (DEBUGPNG) print '[addImagePng '.$file.']';
4234
-
4235
- ob_start();
4236
- @imagepng($img);
4237
- $data = ob_get_clean();
4238
-
4239
- if ($data == '') {
4240
- $error = 1;
4241
- $errormsg = 'trouble writing file from GD';
4242
- //DEBUG_IMG_TEMP
4243
- //debugpng
4244
- if (DEBUGPNG) print 'trouble writing file from GD';
4245
- }
4246
-
4247
- if ($error) {
4248
- $this->addMessage('PNG error - ('.$file.') '.$errormsg);
4249
- return;
4250
- }
4251
- } //End isset($this->imagelist[$file]) (png Duplicate removal)
4252
-
4253
- $this->addPngFromBuf($file, $x, $y, $w, $h, $data, $is_mask, $mask);
4254
- }
4255
-
4256
- protected function addImagePngAlpha($file, $x, $y, $w, $h, $byte) {
4257
- // generate images
4258
- $img = imagecreatefrompng($file);
4259
-
4260
- if ($img === false) {
4261
- return;
4262
- }
4263
-
4264
- // FIXME The pixel transformation doesn't work well with 8bit PNGs
4265
- $eight_bit = ($byte & 4) !== 4;
4266
-
4267
- $wpx = imagesx($img);
4268
- $hpx = imagesy($img);
4269
-
4270
- imagesavealpha($img, false);
4271
-
4272
- // create temp alpha file
4273
- $tempfile_alpha = tempnam($this->tmp, "cpdf_img_");
4274
- @unlink($tempfile_alpha);
4275
- $tempfile_alpha = "$tempfile_alpha.png";
4276
-
4277
- // create temp plain file
4278
- $tempfile_plain = tempnam($this->tmp, "cpdf_img_");
4279
- @unlink($tempfile_plain);
4280
- $tempfile_plain = "$tempfile_plain.png";
4281
-
4282
- $imgalpha = imagecreate($wpx, $hpx);
4283
- imagesavealpha($imgalpha, false);
4284
-
4285
- // generate gray scale palette (0 -> 255)
4286
- for ($c = 0; $c < 256; ++$c) {
4287
- imagecolorallocate($imgalpha, $c, $c, $c);
4288
- }
4289
-
4290
- // Use PECL gmagick + Graphics Magic to process transparent PNG images
4291
- if (extension_loaded("gmagick")) {
4292
- $gmagick = new Gmagick($file);
4293
- $gmagick->setimageformat('png');
4294
-
4295
- // Get opacity channel (negative of alpha channel)
4296
- $alpha_channel_neg = clone $gmagick;
4297
- $alpha_channel_neg->separateimagechannel(Gmagick::CHANNEL_OPACITY);
4298
-
4299
- // Negate opacity channel
4300
- $alpha_channel = new Gmagick();
4301
- $alpha_channel->newimage($wpx, $hpx, "#FFFFFF", "png");
4302
- $alpha_channel->compositeimage($alpha_channel_neg, Gmagick::COMPOSITE_DIFFERENCE, 0, 0);
4303
- $alpha_channel->separateimagechannel(Gmagick::CHANNEL_RED);
4304
- $alpha_channel->writeimage($tempfile_alpha);
4305
-
4306
- // Cast to 8bit+palette
4307
- $imgalpha_ = imagecreatefrompng($tempfile_alpha);
4308
- imagecopy($imgalpha, $imgalpha_, 0, 0, 0, 0, $wpx, $hpx);
4309
- imagedestroy($imgalpha_);
4310
- imagepng($imgalpha, $tempfile_alpha);
4311
-
4312
- // Make opaque image
4313
- $color_channels = new Gmagick();
4314
- $color_channels->newimage($wpx, $hpx, "#FFFFFF", "png");
4315
- $color_channels->compositeimage($gmagick, Gmagick::COMPOSITE_COPYRED, 0, 0);
4316
- $color_channels->compositeimage($gmagick, Gmagick::COMPOSITE_COPYGREEN, 0, 0);
4317
- $color_channels->compositeimage($gmagick, Gmagick::COMPOSITE_COPYBLUE, 0, 0);
4318
- $color_channels->writeimage($tempfile_plain);
4319
-
4320
- $imgplain = imagecreatefrompng($tempfile_plain);
4321
- }
4322
-
4323
- // Use PECL imagick + ImageMagic to process transparent PNG images
4324
- elseif (extension_loaded("imagick")) {
4325
- $imagick = new Imagick($file);
4326
- $imagick->setFormat('png');
4327
-
4328
- // Get opacity channel (negative of alpha channel)
4329
- $alpha_channel = clone $imagick;
4330
- $alpha_channel->separateImageChannel(Imagick::CHANNEL_ALPHA);
4331
- $alpha_channel->negateImage(true);
4332
- $alpha_channel->writeImage($tempfile_alpha);
4333
-
4334
- // Cast to 8bit+palette
4335
- $imgalpha_ = imagecreatefrompng($tempfile_alpha);
4336
- imagecopy($imgalpha, $imgalpha_, 0, 0, 0, 0, $wpx, $hpx);
4337
- imagedestroy($imgalpha_);
4338
- imagepng($imgalpha, $tempfile_alpha);
4339
-
4340
- // Make opaque image
4341
- $color_channels = new Imagick();
4342
- $color_channels->newImage($wpx, $hpx, "#FFFFFF", "png");
4343
- $color_channels->compositeImage($imagick, Imagick::COMPOSITE_COPYRED, 0, 0);
4344
- $color_channels->compositeImage($imagick, Imagick::COMPOSITE_COPYGREEN, 0, 0);
4345
- $color_channels->compositeImage($imagick, Imagick::COMPOSITE_COPYBLUE, 0, 0);
4346
- $color_channels->writeImage($tempfile_plain);
4347
-
4348
- $imgplain = imagecreatefrompng($tempfile_plain);
4349
- }
4350
- else {
4351
- // allocated colors cache
4352
- $allocated_colors = array();
4353
-
4354
- // extract alpha channel
4355
- for ($xpx = 0; $xpx < $wpx; ++$xpx) {
4356
- for ($ypx = 0; $ypx < $hpx; ++$ypx) {
4357
- $color = imagecolorat($img, $xpx, $ypx);
4358
- $col = imagecolorsforindex($img, $color);
4359
- $alpha = $col['alpha'];
4360
-
4361
- if ($eight_bit) {
4362
- // with gamma correction
4363
- $gammacorr = 2.2;
4364
- $pixel = pow((((127 - $alpha) * 255 / 127) / 255), $gammacorr) * 255;
4365
- }
4366
-
4367
- else {
4368
- // without gamma correction
4369
- $pixel = (127 - $alpha) * 2;
4370
-
4371
- $key = $col['red'].$col['green'].$col['blue'];
4372
-
4373
- if (!isset($allocated_colors[$key])) {
4374
- $pixel_img = imagecolorallocate($img, $col['red'], $col['green'], $col['blue']);
4375
- $allocated_colors[$key] = $pixel_img;
4376
- }
4377
- else {
4378
- $pixel_img = $allocated_colors[$key];
4379
- }
4380
-
4381
- imagesetpixel($img, $xpx, $ypx, $pixel_img);
4382
- }
4383
-
4384
- imagesetpixel($imgalpha, $xpx, $ypx, $pixel);
4385
- }
4386
- }
4387
-
4388
- // extract image without alpha channel
4389
- $imgplain = imagecreatetruecolor($wpx, $hpx);
4390
- imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx);
4391
- imagedestroy($img);
4392
-
4393
- imagepng($imgalpha, $tempfile_alpha);
4394
- imagepng($imgplain, $tempfile_plain);
4395
- }
4396
-
4397
- // embed mask image
4398
- $this->addImagePng($tempfile_alpha, $x, $y, $w, $h, $imgalpha, true);
4399
- imagedestroy($imgalpha);
4400
-
4401
- // embed image, masked with previously embedded mask
4402
- $this->addImagePng($tempfile_plain, $x, $y, $w, $h, $imgplain, false, true);
4403
- imagedestroy($imgplain);
4404
-
4405
- // remove temp files
4406
- unlink($tempfile_alpha);
4407
- unlink($tempfile_plain);
4408
- }
4409
-
4410
- /**
4411
- * add a PNG image into the document, from a file
4412
- * this should work with remote files
4413
- */
4414
- function addPngFromFile($file, $x, $y, $w = 0, $h = 0) {
4415
- //if already cached, need not to read again
4416
- if ( isset($this->imagelist[$file]) ) {
4417
- $img = null;
4418
- }
4419
-
4420
- else {
4421
- $info = file_get_contents ($file, false, null, 24, 5);
4422
- $meta = unpack("CbitDepth/CcolorType/CcompressionMethod/CfilterMethod/CinterlaceMethod", $info);
4423
- $bit_depth = $meta["bitDepth"];
4424
- $color_type = $meta["colorType"];
4425
-
4426
- // http://www.w3.org/TR/PNG/#11IHDR
4427
- // 3 => indexed
4428
- // 4 => greyscale with alpha
4429
- // 6 => fullcolor with alpha
4430
- $is_alpha = in_array($color_type, array(4, 6)) || ($color_type == 3 && $bit_depth != 4);
4431
-
4432
- if ($is_alpha) { // exclude grayscale alpha
4433
- return $this->addImagePngAlpha($file, $x, $y, $w, $h, $color_type);
4434
- }
4435
-
4436
- //png files typically contain an alpha channel.
4437
- //pdf file format or class.pdf does not support alpha blending.
4438
- //on alpha blended images, more transparent areas have a color near black.
4439
- //This appears in the result on not storing the alpha channel.
4440
- //Correct would be the box background image or its parent when transparent.
4441
- //But this would make the image dependent on the background.
4442
- //Therefore create an image with white background and copy in
4443
- //A more natural background than black is white.
4444
- //Therefore create an empty image with white background and merge the
4445
- //image in with alpha blending.
4446
- $imgtmp = @imagecreatefrompng($file);
4447
- if (!$imgtmp) {
4448
- return;
4449
- }
4450
- $sx = imagesx($imgtmp);
4451
- $sy = imagesy($imgtmp);
4452
- $img = imagecreatetruecolor($sx,$sy);
4453
- imagealphablending($img, true);
4454
-
4455
- // @todo is it still needed ??
4456
- $ti = imagecolortransparent($imgtmp);
4457
- if ($ti >= 0) {
4458
- $tc = imagecolorsforindex($imgtmp,$ti);
4459
- $ti = imagecolorallocate($img,$tc['red'],$tc['green'],$tc['blue']);
4460
- imagefill($img,0,0,$ti);
4461
- imagecolortransparent($img, $ti);
4462
- } else {
4463
- imagefill($img,1,1,imagecolorallocate($img,255,255,255));
4464
- }
4465
-
4466
- imagecopy($img,$imgtmp,0,0,0,0,$sx,$sy);
4467
- imagedestroy($imgtmp);
4468
- }
4469
- $this->addImagePng($file, $x, $y, $w, $h, $img);
4470
-
4471
- if ( $img ) {
4472
- imagedestroy($img);
4473
- }
4474
- }
4475
-
4476
- /**
4477
- * add a PNG image into the document, from a memory buffer of the file
4478
- */
4479
- function addPngFromBuf($file, $x, $y, $w = 0, $h = 0, &$data, $is_mask = false, $mask = null) {
4480
- if ( isset($this->imagelist[$file]) ) {
4481
- $data = null;
4482
- $info['width'] = $this->imagelist[$file]['w'];
4483
- $info['height'] = $this->imagelist[$file]['h'];
4484
- $label = $this->imagelist[$file]['label'];
4485
- }
4486
-
4487
- else {
4488
- if ($data == null) {
4489
- $this->addMessage('addPngFromBuf error - ('.$imgname.') data not present!');
4490
- return;
4491
- }
4492
-
4493
- $error = 0;
4494
-
4495
- if (!$error) {
4496
- $header = chr(137) .chr(80) .chr(78) .chr(71) .chr(13) .chr(10) .chr(26) .chr(10);
4497
-
4498
- if (mb_substr($data, 0, 8, '8bit') != $header) {
4499
- $error = 1;
4500
-
4501
- if (DEBUGPNG) print '[addPngFromFile this file does not have a valid header '.$file.']';
4502
-
4503
- $errormsg = 'this file does not have a valid header';
4504
- }
4505
- }
4506
-
4507
- if (!$error) {
4508
- // set pointer
4509
- $p = 8;
4510
- $len = mb_strlen($data, '8bit');
4511
-
4512
- // cycle through the file, identifying chunks
4513
- $haveHeader = 0;
4514
- $info = array();
4515
- $idata = '';
4516
- $pdata = '';
4517
-
4518
- while ($p < $len) {
4519
- $chunkLen = $this->PRVT_getBytes($data, $p, 4);
4520
- $chunkType = mb_substr($data, $p+4, 4, '8bit');
4521
-
4522
- switch ($chunkType) {
4523
- case 'IHDR':
4524
- // this is where all the file information comes from
4525
- $info['width'] = $this->PRVT_getBytes($data, $p+8, 4);
4526
- $info['height'] = $this->PRVT_getBytes($data, $p+12, 4);
4527
- $info['bitDepth'] = ord($data[$p+16]);
4528
- $info['colorType'] = ord($data[$p+17]);
4529
- $info['compressionMethod'] = ord($data[$p+18]);
4530
- $info['filterMethod'] = ord($data[$p+19]);
4531
- $info['interlaceMethod'] = ord($data[$p+20]);
4532
-
4533
- //print_r($info);
4534
- $haveHeader = 1;
4535
- if ($info['compressionMethod'] != 0) {
4536
- $error = 1;
4537
-
4538
- //debugpng
4539
- if (DEBUGPNG) print '[addPngFromFile unsupported compression method '.$file.']';
4540
-
4541
- $errormsg = 'unsupported compression method';
4542
- }
4543
-
4544
- if ($info['filterMethod'] != 0) {
4545
- $error = 1;
4546
-
4547
- //debugpng
4548
- if (DEBUGPNG) print '[addPngFromFile unsupported filter method '.$file.']';
4549
-
4550
- $errormsg = 'unsupported filter method';
4551
- }
4552
- break;
4553
-
4554
- case 'PLTE':
4555
- $pdata.= mb_substr($data, $p+8, $chunkLen, '8bit');
4556
- break;
4557
-
4558
- case 'IDAT':
4559
- $idata.= mb_substr($data, $p+8, $chunkLen, '8bit');
4560
- break;
4561
-
4562
- case 'tRNS':
4563
- //this chunk can only occur once and it must occur after the PLTE chunk and before IDAT chunk
4564
- //print "tRNS found, color type = ".$info['colorType']."\n";
4565
- $transparency = array();
4566
-
4567
- switch ($info['colorType']) {
4568
- // indexed color, rbg
4569
- case 3:
4570
- /* corresponding to entries in the plte chunk
4571
- Alpha for palette index 0: 1 byte
4572
- Alpha for palette index 1: 1 byte
4573
- ...etc...
4574
- */
4575
- // there will be one entry for each palette entry. up until the last non-opaque entry.
4576
- // set up an array, stretching over all palette entries which will be o (opaque) or 1 (transparent)
4577
- $transparency['type'] = 'indexed';
4578
-
4579
- $numPalette = mb_strlen($pdata, '8bit')/3;
4580
- $trans = 0;
4581
-
4582
- for ($i = $chunkLen;$i >= 0;$i--) {
4583
- if (ord($data[$p+8+$i]) == 0) {
4584
- $trans = $i;
4585
- }
4586
- }
4587
-
4588
- $transparency['data'] = $trans;
4589
- break;
4590
-
4591
- // grayscale
4592
- case 0:
4593
- /* corresponding to entries in the plte chunk
4594
- Gray: 2 bytes, range 0 .. (2^bitdepth)-1
4595
- */
4596
- // $transparency['grayscale'] = $this->PRVT_getBytes($data,$p+8,2); // g = grayscale
4597
- $transparency['type'] = 'indexed';
4598
- $transparency['data'] = ord($data[$p+8+1]);
4599
- break;
4600
-
4601
- // truecolor
4602
- case 2:
4603
- /* corresponding to entries in the plte chunk
4604
- Red: 2 bytes, range 0 .. (2^bitdepth)-1
4605
- Green: 2 bytes, range 0 .. (2^bitdepth)-1
4606
- Blue: 2 bytes, range 0 .. (2^bitdepth)-1
4607
- */
4608
- $transparency['r'] = $this->PRVT_getBytes($data, $p+8, 2);
4609
- // r from truecolor
4610
- $transparency['g'] = $this->PRVT_getBytes($data, $p+10, 2);
4611
- // g from truecolor
4612
- $transparency['b'] = $this->PRVT_getBytes($data, $p+12, 2);
4613
- // b from truecolor
4614
-
4615
- $transparency['type'] = 'color-key';
4616
- break;
4617
-
4618
- //unsupported transparency type
4619
- default:
4620
- if (DEBUGPNG) print '[addPngFromFile unsupported transparency type '.$file.']';
4621
- break;
4622
- }
4623
-
4624
- // KS End new code
4625
- break;
4626
-
4627
- default:
4628
- break;
4629
- }
4630
-
4631
- $p += $chunkLen+12;
4632
- }
4633
-
4634
- if (!$haveHeader) {
4635
- $error = 1;
4636
-
4637
- //debugpng
4638
- if (DEBUGPNG) print '[addPngFromFile information header is missing '.$file.']';
4639
-
4640
- $errormsg = 'information header is missing';
4641
- }
4642
-
4643
- if (isset($info['interlaceMethod']) && $info['interlaceMethod']) {
4644
- $error = 1;
4645
-
4646
- //debugpng
4647
- if (DEBUGPNG) print '[addPngFromFile no support for interlaced images in pdf '.$file.']';
4648
-
4649
- $errormsg = 'There appears to be no support for interlaced images in pdf.';
4650
- }
4651
- }
4652
-
4653
- if (!$error && $info['bitDepth'] > 8) {
4654
- $error = 1;
4655
-
4656
- //debugpng
4657
- if (DEBUGPNG) print '[addPngFromFile bit depth of 8 or less is supported '.$file.']';
4658
-
4659
- $errormsg = 'only bit depth of 8 or less is supported';
4660
- }
4661
-
4662
- if (!$error) {
4663
- switch ($info['colorType']) {
4664
- case 3:
4665
- $color = 'DeviceRGB';
4666
- $ncolor = 1;
4667
- break;
4668
-
4669
- case 2:
4670
- $color = 'DeviceRGB';
4671
- $ncolor = 3;
4672
- break;
4673
-
4674
- case 0:
4675
- $color = 'DeviceGray';
4676
- $ncolor = 1;
4677
- break;
4678
-
4679
- default:
4680
- $error = 1;
4681
-
4682
- //debugpng
4683
- if (DEBUGPNG) print '[addPngFromFile alpha channel not supported: '.$info['colorType'].' '.$file.']';
4684
-
4685
- $errormsg = 'transparancey alpha channel not supported, transparency only supported for palette images.';
4686
- }
4687
- }
4688
-
4689
- if ($error) {
4690
- $this->addMessage('PNG error - ('.$file.') '.$errormsg);
4691
- return;
4692
- }
4693
-
4694
- //print_r($info);
4695
- // so this image is ok... add it in.
4696
- $this->numImages++;
4697
- $im = $this->numImages;
4698
- $label = "I$im";
4699
- $this->numObj++;
4700
-
4701
- // $this->o_image($this->numObj,'new',array('label' => $label,'data' => $idata,'iw' => $w,'ih' => $h,'type' => 'png','ic' => $info['width']));
4702
- $options = array(
4703
- 'label' => $label,
4704
- 'data' => $idata,
4705
- 'bitsPerComponent' => $info['bitDepth'],
4706
- 'pdata' => $pdata,
4707
- 'iw' => $info['width'],
4708
- 'ih' => $info['height'],
4709
- 'type' => 'png',
4710
- 'color' => $color,
4711
- 'ncolor' => $ncolor,
4712
- 'masked' => $mask,
4713
- 'isMask' => $is_mask,
4714
- );
4715
-
4716
- if (isset($transparency)) {
4717
- $options['transparency'] = $transparency;
4718
- }
4719
-
4720
- $this->o_image($this->numObj, 'new', $options);
4721
- $this->imagelist[$file] = array('label' =>$label, 'w' => $info['width'], 'h' => $info['height']);
4722
- }
4723
-
4724
- if ($is_mask) {
4725
- return;
4726
- }
4727
-
4728
- if ($w <= 0 && $h <= 0) {
4729
- $w = $info['width'];
4730
- $h = $info['height'];
4731
- }
4732
-
4733
- if ($w <= 0) {
4734
- $w = $h/$info['height']*$info['width'];
4735
- }
4736
-
4737
- if ($h <= 0) {
4738
- $h = $w*$info['height']/$info['width'];
4739
- }
4740
-
4741
- $this->objects[$this->currentContents]['c'].= sprintf("\nq\n%.3F 0 0 %.3F %.3F %.3F cm /%s Do\nQ", $w, $h, $x, $y, $label);
4742
- }
4743
-
4744
- /**
4745
- * add a JPEG image into the document, from a file
4746
- */
4747
- function addJpegFromFile($img, $x, $y, $w = 0, $h = 0) {
4748
- // attempt to add a jpeg image straight from a file, using no GD commands
4749
- // note that this function is unable to operate on a remote file.
4750
-
4751
- if (!file_exists($img)) {
4752
- return;
4753
- }
4754
-
4755
- if ( $this->image_iscached($img) ) {
4756
- $data = null;
4757
- $imageWidth = $this->imagelist[$img]['w'];
4758
- $imageHeight = $this->imagelist[$img]['h'];
4759
- $channels = $this->imagelist[$img]['c'];
4760
- }
4761
- else {
4762
- $tmp = getimagesize($img);
4763
- $imageWidth = $tmp[0];
4764
- $imageHeight = $tmp[1];
4765
-
4766
- if ( isset($tmp['channels']) ) {
4767
- $channels = $tmp['channels'];
4768
- } else {
4769
- $channels = 3;
4770
- }
4771
-
4772
- $data = file_get_contents($img);
4773
- }
4774
-
4775
- if ($w <= 0 && $h <= 0) {
4776
- $w = $imageWidth;
4777
- }
4778
-
4779
- if ($w == 0) {
4780
- $w = $h/$imageHeight*$imageWidth;
4781
- }
4782
-
4783
- if ($h == 0) {
4784
- $h = $w*$imageHeight/$imageWidth;
4785
- }
4786
-
4787
- $this->addJpegImage_common($data, $x, $y, $w, $h, $imageWidth, $imageHeight, $channels, $img);
4788
- }
4789
-
4790
- /**
4791
- * common code used by the two JPEG adding functions
4792
- *
4793
- * @access private
4794
- */
4795
- function addJpegImage_common(&$data, $x, $y, $w = 0, $h = 0, $imageWidth, $imageHeight, $channels = 3, $imgname) {
4796
- if ( $this->image_iscached($imgname) ) {
4797
- $label = $this->imagelist[$imgname]['label'];
4798
- //debugpng
4799
- //if (DEBUGPNG) print '[addJpegImage_common Duplicate '.$imgname.']';
4800
-
4801
- } else {
4802
- if ($data == null) {
4803
- $this->addMessage('addJpegImage_common error - ('.$imgname.') data not present!');
4804
- return;
4805
- }
4806
-
4807
- // note that this function is not to be called externally
4808
- // it is just the common code between the GD and the file options
4809
- $this->numImages++;
4810
- $im = $this->numImages;
4811
- $label = "I$im";
4812
- $this->numObj++;
4813
-
4814
- $this->o_image($this->numObj, 'new', array(
4815
- 'label' => $label,
4816
- 'data' => &$data,
4817
- 'iw' => $imageWidth,
4818
- 'ih' => $imageHeight,
4819
- 'channels' => $channels
4820
- ));
4821
-
4822
- $this->imagelist[$imgname] = array('label' =>$label, 'w' => $imageWidth, 'h' => $imageHeight, 'c'=> $channels );
4823
- }
4824
-
4825
- $this->objects[$this->currentContents]['c'].= sprintf("\nq\n%.3F 0 0 %.3F %.3F %.3F cm /%s Do\nQ ", $w, $h, $x, $y, $label);
4826
- }
4827
-
4828
- /**
4829
- * specify where the document should open when it first starts
4830
- */
4831
- function openHere($style, $a = 0, $b = 0, $c = 0) {
4832
- // this function will open the document at a specified page, in a specified style
4833
- // the values for style, and the required paramters are:
4834
- // 'XYZ' left, top, zoom
4835
- // 'Fit'
4836
- // 'FitH' top
4837
- // 'FitV' left
4838
- // 'FitR' left,bottom,right
4839
- // 'FitB'
4840
- // 'FitBH' top
4841
- // 'FitBV' left
4842
- $this->numObj++;
4843
- $this->o_destination($this->numObj, 'new', array('page' => $this->currentPage, 'type' => $style, 'p1' => $a, 'p2' => $b, 'p3' => $c));
4844
- $id = $this->catalogId;
4845
- $this->o_catalog($id, 'openHere', $this->numObj);
4846
- }
4847
-
4848
- /**
4849
- * Add JavaScript code to the PDF document
4850
- *
4851
- * @param string $code
4852
- * @return void
4853
- */
4854
- function addJavascript($code) {
4855
- $this->javascript .= $code;
4856
- }
4857
-
4858
- /**
4859
- * create a labelled destination within the document
4860
- */
4861
- function addDestination($label, $style, $a = 0, $b = 0, $c = 0) {
4862
- // associates the given label with the destination, it is done this way so that a destination can be specified after
4863
- // it has been linked to
4864
- // styles are the same as the 'openHere' function
4865
- $this->numObj++;
4866
- $this->o_destination($this->numObj, 'new', array('page' => $this->currentPage, 'type' => $style, 'p1' => $a, 'p2' => $b, 'p3' => $c));
4867
- $id = $this->numObj;
4868
-
4869
- // store the label->idf relationship, note that this means that labels can be used only once
4870
- $this->destinations["$label"] = $id;
4871
- }
4872
-
4873
- /**
4874
- * define font families, this is used to initialize the font families for the default fonts
4875
- * and for the user to add new ones for their fonts. The default bahavious can be overridden should
4876
- * that be desired.
4877
- */
4878
- function setFontFamily($family, $options = '') {
4879
- if (!is_array($options)) {
4880
- if ($family === 'init') {
4881
- // set the known family groups
4882
- // these font families will be used to enable bold and italic markers to be included
4883
- // within text streams. html forms will be used... <b></b> <i></i>
4884
- $this->fontFamilies['Helvetica.afm'] =
4885
- array('b' => 'Helvetica-Bold.afm',
4886
- 'i' => 'Helvetica-Oblique.afm',
4887
- 'bi' => 'Helvetica-BoldOblique.afm',
4888
- 'ib' => 'Helvetica-BoldOblique.afm');
4889
-
4890
- $this->fontFamilies['Courier.afm'] =
4891
- array('b' => 'Courier-Bold.afm',
4892
- 'i' => 'Courier-Oblique.afm',
4893
- 'bi' => 'Courier-BoldOblique.afm',
4894
- 'ib' => 'Courier-BoldOblique.afm');
4895
-
4896
- $this->fontFamilies['Times-Roman.afm'] =
4897
- array('b' => 'Times-Bold.afm',
4898
- 'i' => 'Times-Italic.afm',
4899
- 'bi' => 'Times-BoldItalic.afm',
4900
- 'ib' => 'Times-BoldItalic.afm');
4901
- }
4902
- } else {
4903
-
4904
- // the user is trying to set a font family
4905
- // note that this can also be used to set the base ones to something else
4906
- if (mb_strlen($family)) {
4907
- $this->fontFamilies[$family] = $options;
4908
- }
4909
- }
4910
- }
4911
-
4912
- /**
4913
- * used to add messages for use in debugging
4914
- */
4915
- function addMessage($message) {
4916
- $this->messages.= $message."\n";
4917
- }
4918
-
4919
- /**
4920
- * a few functions which should allow the document to be treated transactionally.
4921
- */
4922
- function transaction($action) {
4923
- switch ($action) {
4924
- case 'start':
4925
- // store all the data away into the checkpoint variable
4926
- $data = get_object_vars($this);
4927
- $this->checkpoint = $data;
4928
- unset($data);
4929
- break;
4930
-
4931
- case 'commit':
4932
- if (is_array($this->checkpoint) && isset($this->checkpoint['checkpoint'])) {
4933
- $tmp = $this->checkpoint['checkpoint'];
4934
- $this->checkpoint = $tmp;
4935
- unset($tmp);
4936
- } else {
4937
- $this->checkpoint = '';
4938
- }
4939
- break;
4940
-
4941
- case 'rewind':
4942
- // do not destroy the current checkpoint, but move us back to the state then, so that we can try again
4943
- if (is_array($this->checkpoint)) {
4944
- // can only abort if were inside a checkpoint
4945
- $tmp = $this->checkpoint;
4946
-
4947
- foreach ($tmp as $k => $v) {
4948
- if ($k !== 'checkpoint') {
4949
- $this->$k = $v;
4950
- }
4951
- }
4952
- unset($tmp);
4953
- }
4954
- break;
4955
-
4956
- case 'abort':
4957
- if (is_array($this->checkpoint)) {
4958
- // can only abort if were inside a checkpoint
4959
- $tmp = $this->checkpoint;
4960
- foreach ($tmp as $k => $v) {
4961
- $this->$k = $v;
4962
- }
4963
- unset($tmp);
4964
- }
4965
- break;
4966
- }
4967
- }
4968
- }
4969
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/ip_pdffree/dompdf6/lib/res/html.css DELETED
@@ -1,426 +0,0 @@
1
- /**
2
- * dompdf default stylesheet.
3
- *
4
- * The Original Code is mozilla.org code.
5
- *
6
- * The Initial Developer of the Original Code is Netscape Communications Corporation.
7
- * Portions created by the Initial Developer are Copyright (C) 1998 the Initial Developer.
8
- * All Rights Reserved.
9
- *
10
- * @package dompdf
11
- * @link http://www.dompdf.com/
12
- * @author Benj Carson <benjcarson@digitaljunkies.ca>
13
- * @author Blake Ross <BlakeR1234@aol.com>
14
- * @author Fabien M�nager <fabien.menager@gmail.com>
15
- * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
16
- * @version $Id: html.css 456 2012-01-21 11:20:37Z fabien.menager $
17
- */
18
-
19
- @page {
20
- margin: 1.2cm;
21
- }
22
-
23
- html {
24
- display: -dompdf-page;
25
- counter-reset: page;
26
- }
27
-
28
- /* blocks */
29
-
30
- div, map, dt, isindex {
31
- display: block;
32
- }
33
-
34
- body {
35
- page-break-before: avoid;
36
- display: block;
37
- counter-increment: page;
38
- }
39
-
40
- p, dl, multicol {
41
- display: block;
42
- margin: 1em 0;
43
- }
44
-
45
- dd {
46
- display: block;
47
- margin-left: 40px;
48
- }
49
-
50
- blockquote {
51
- display: block;
52
- margin: 1em 40px;
53
- }
54
-
55
- address {
56
- display: block;
57
- font-style: italic;
58
- }
59
-
60
- center {
61
- display: block;
62
- text-align: center;
63
- }
64
-
65
- blockquote[type=cite] {
66
- display: block;
67
- margin: 1em 0px;
68
- padding-left: 1em;
69
- border-left: solid;
70
- border-color: blue;
71
- border-width: thin;
72
- }
73
-
74
- h1, h2, h3, h4, h5, h6 {
75
- display: block;
76
- font-weight: bold;
77
- }
78
-
79
- h1 {
80
- font-size: 2em;
81
- margin: .67em 0;
82
- }
83
-
84
- h2 {
85
- font-size: 1.5em;
86
- margin: .83em 0;
87
- }
88
-
89
- h3 {
90
- font-size: 1.17em;
91
- margin: 1em 0;
92
- }
93
-
94
- h4 {
95
- margin: 1.33em 0;
96
- }
97
-
98
- h5 {
99
- font-size: 0.83em;
100
- margin: 1.67em 0;
101
- }
102
-
103
- h6 {
104
- font-size: 0.67em;
105
- margin: 2.33em 0;
106
- }
107
-
108
- listing {
109
- display: block;
110
- font-family: fixed;
111
- font-size: medium;
112
- white-space: pre;
113
- margin: 1em 0;
114
- }
115
-
116
- plaintext, xmp, pre {
117
- display: block;
118
- font-family: fixed;
119
- white-space: pre;
120
- margin: 1em 0;
121
- }
122
-
123
- article, aside, details,
124
- figcaption, figure,
125
- footer, header, hgroup,
126
- nav, section {
127
- display: block;
128
- }
129
-
130
- /* tables */
131
-
132
- table {
133
- display: table;
134
- border-spacing: 2px;
135
- border-collapse: separate;
136
- margin-top: 0;
137
- margin-bottom: 0;
138
- text-indent: 0;
139
- text-align: left; /* quirk */
140
- }
141
-
142
- table[border] {
143
- border-style: outset;
144
- border-color: gray;
145
- }
146
-
147
- /* This won't work (???) */
148
- /*
149
- table[border] td,
150
- table[border] th {
151
- border: 1pt solid grey;
152
- }*/
153
-
154
- /* make sure backgrounds are inherited in tables -- see bug 4510 */
155
- td, th, tr {
156
- background: inherit;
157
- }
158
-
159
- /* caption inherits from table not table-outer */
160
- caption {
161
- display: block;
162
- text-align: center;
163
- }
164
-
165
- tr {
166
- display: table-row;
167
- vertical-align: inherit;
168
- }
169
-
170
- col {
171
- display: table-column;
172
- }
173
-
174
- colgroup {
175
- display: table-column-group;
176
- }
177
-
178
- tbody {
179
- display: table-row-group;
180
- vertical-align: middle;
181
- }
182
-
183
- thead {
184
- display: table-header-group;
185
- vertical-align: middle;
186
- }
187
-
188
- tfoot {
189
- display: table-footer-group;
190
- vertical-align: middle;
191
- }
192
-
193
- /* To simulate tbody auto-insertion */
194
- table > tr {
195
- vertical-align: middle;
196
- }
197
-
198
- td {
199
- display: table-cell;
200
- vertical-align: inherit;
201
- text-align: inherit;
202
- padding: 1px;
203
- }
204
-
205
- th {
206
- display: table-cell;
207
- vertical-align: inherit;
208
- font-weight: bold;
209
- padding: 1px;
210
- text-align: center;
211
- }
212
-
213
- /* inlines */
214
- q {
215
- quotes: '"' '"' "'" "'"; /* FIXME only the first level is used */
216
- }
217
-
218
- q:before {
219
- content: open-quote;
220
- }
221
-
222
- q:after {
223
- content: close-quote;
224
- }
225
-
226
- :link {
227
- color: #00c;
228
- text-decoration: underline;
229
- }
230
-
231
- b, strong {
232
- font-weight: bolder;
233
- }
234
-
235
- i, cite, em, var, dfn {
236
- font-style: italic;
237
- }
238
-
239
- tt, code, kbd, samp {
240
- font-family: fixed;
241
- }
242
-
243
- u, ins {
244
- text-decoration: underline;
245
- }
246
-
247
- s, strike, del {
248
- text-decoration: line-through;
249
- }
250
-
251
- blink {
252
- text-decoration: blink;
253
- }
254
-
255
- big {
256
- font-size: larger;
257
- }
258
-
259
- small {
260
- font-size: smaller;
261
- }
262
-
263
- sub {
264
- vertical-align: sub;
265
- font-size: smaller;
266
- line-height: normal;
267
- }
268
-
269
- sup {
270
- vertical-align: super;
271
- font-size: smaller;
272
- line-height: normal;
273
- }
274
-
275
- nobr {
276
- white-space: nowrap;
277
- }
278
-
279
- /* lists */
280
-
281
- ul, menu, dir {
282
- display: block;
283
- list-style-type: disc;
284
- margin: 1em 0;
285
- padding-left: 40px;
286
- }
287
-
288
- ol {
289
- display: block;
290
- list-style-type: decimal;
291
- margin: 1em 0;
292
- padding-left: 40px;
293
- }
294
-
295
- li {
296
- display: list-item;
297
- }
298
-
299
- /*li:before {
300
- display: -dompdf-list-bullet !important;
301
- content: counter(-dompdf-default-counter) ". ";
302
- padding-right: 0.5em;
303
- }*/
304
-
305
- /* nested lists have no top/bottom margins */
306
- ul ul, ul ol, ul dir, ul menu, ul dl,
307
- ol ul, ol ol, ol dir, ol menu, ol dl,
308
- dir ul, dir ol, dir dir, dir menu, dir dl,
309
- menu ul, menu ol, menu dir, menu menu, menu dl,
310
- dl ul, dl ol, dl dir, dl menu, dl dl {
311
- margin-top: 0;
312
- margin-bottom: 0;
313
- }
314
-
315
- /* 2 deep unordered lists use a circle */
316
- ol ul, ul ul, menu ul, dir ul,
317
- ol menu, ul menu, menu menu, dir menu,
318
- ol dir, ul dir, menu dir, dir dir {
319
- list-style-type: circle;
320
- }
321
-
322
- /* 3 deep (or more) unordered lists use a square */
323
- ol ol ul, ol ul ul, ol menu ul, ol dir ul,
324
- ol ol menu, ol ul menu, ol menu menu, ol dir menu,
325
- ol ol dir, ol ul dir, ol menu dir, ol dir dir,
326
- ul ol ul, ul ul ul, ul menu ul, ul dir ul,
327
- ul ol menu, ul ul menu, ul menu menu, ul dir menu,
328
- ul ol dir, ul ul dir, ul menu dir, ul dir dir,
329
- menu ol ul, menu ul ul, menu menu ul, menu dir ul,
330
- menu ol menu, menu ul menu, menu menu menu, menu dir menu,
331
- menu ol dir, menu ul dir, menu menu dir, menu dir dir,
332
- dir ol ul, dir ul ul, dir menu ul, dir dir ul,
333
- dir ol menu, dir ul menu, dir menu menu, dir dir menu,
334
- dir ol dir, dir ul dir, dir menu dir, dir dir dir {
335
- list-style-type: square;
336
- }
337
-
338
- /* forms */
339
- /* From http://dev.w3.org/csswg/css3-ui/#appearance */
340
- input {
341
- -dompdf-appearance: textfield;
342
- }
343
-
344
- input[type=password] {
345
- -dompdf-appearance: radio-button;
346
- }
347
-
348
- input[type=radio] {
349
- -dompdf-appearance: password;
350
- }
351
-
352
- input[type=checkbox] {
353
- -dompdf-appearance: checkbox;
354
- }
355
-
356
- input[type=button],
357
- input[type=submit],
358
- input[type=reset] {
359
- -dompdf-appearance: button;
360
- }
361
-
362
- select {
363
- -dompdf-appearance: pop-up-menu;
364
- }
365
-
366
- textarea {
367
- -dompdf-appearance: field;
368
- display: block;
369
- }
370
-
371
- fieldset {
372
- display: block;
373
- margin-left: 2px;
374
- margin-right: 2px;
375
- padding: 0.35em 0.625em 0.75em;
376
- border: 1pt groove #666;
377
- position: relative;
378
- }
379
-
380
- fieldset > legend {
381
- position: absolute;
382
- top: -1em;
383
- white-space: nowrap;
384
- padding-left: 4px;
385
- padding-right: 2px;
386
- background: white;
387
- }
388
-
389
- legend {
390
- display: inline-block;
391
- }
392
-
393
- /* leafs */
394
-
395
- hr {
396
- display: block;
397
- height: 0;
398
- border: 1px inset;
399
- margin: 0.5em auto 0.5em auto;
400
- }
401
-
402
- iframe {
403
- border: 2px inset;
404
- }
405
-
406
- noframes {
407
- display: none;
408
- }
409
-
410
- br {
411
- display: -dompdf-br;
412
- }
413
-
414
- img, img_generated {
415
- display: -dompdf-image;
416
- }
417
-
418
- dompdf_generated {
419
- display: inline;
420
- }
421
-
422
- /* hidden elements */
423
- area, base, basefont, head, meta, script, style, title,
424
- noembed, noscript, param {
425
- display: none;
426
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>freepdf</name>
4
- <version>1.0.9</version>
5
  <stability>stable</stability>
6
  <license>Single user license</license>
7
  <channel>community</channel>
@@ -10,11 +10,11 @@
10
  <description>PDF is the de facto standard for the secure and reliable distribution and exchange of electronic documents and forms around the world.&#xA0;It is also a great Marketing feature for Brochures, price lists!&#xD;
11
  &#xD;
12
  So why not let your customers download PDF versions of categories and product they look.</description>
13
- <notes>1.0.9</notes>
14
- <authors><author><name>ecommerceoffice</name><user>auto-converted</user><email>office.ecommerce@gmail.com</email></author></authors>
15
- <date>2012-04-09</date>
16
- <time>12:04:49</time>
17
- <contents><target name="magelib"><dir name="ip_pdffree"><dir name="dompdf6"><dir name="lib"><dir name="res"><file name="broken_image.png" hash="fe23f9cf6ea52869af7c2f1d1188befe"/><file name="class.pdf.php" hash="ab5c62b1af242d660d87ef6bf6972eee"/><file name="html.css" hash="3b3de2922e3462ca1b6080b651e6a960"/></dir></dir></dir></dir></target></contents>
18
  <compatible/>
19
- <dependencies/>
20
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>freepdf</name>
4
+ <version>1.2.0.0</version>
5
  <stability>stable</stability>
6
  <license>Single user license</license>
7
  <channel>community</channel>
10
  <description>PDF is the de facto standard for the secure and reliable distribution and exchange of electronic documents and forms around the world.&#xA0;It is also a great Marketing feature for Brochures, price lists!&#xD;
11
  &#xD;
12
  So why not let your customers download PDF versions of categories and product they look.</description>
13
+ <notes>1.2</notes>
14
+ <authors><author><name>ecommerceoffice</name><user>ecommerceoffice</user><email>office.ecommerce@gmail.com</email></author></authors>
15
+ <date>2012-05-02</date>
16
+ <time>07:17:58</time>
17
+ <contents><target name="magecommunity"><dir name="Ip"><dir name="Promopdf"><dir name="Block"><file name="Developer.php" hash="7d6e6d70b63ba67eab65a5ce529207b0"/><file name="Promo.php" hash="b79954fd7b71dd779bf60d876db37879"/><file name=".DS_Store" hash="7cd0186800e9075dd306f4a06cc44e3b"/></dir><dir name="Helper"><file name="Data.php" hash="fd1ea7381fcd0b365216cde7774ec755"/></dir><dir name="etc"><file name="config.xml" hash="d04c4ad874219bd02f63e9aaabd84675"/><file name="system.xml" hash="4caee55316b7d9c8b57e6dcda0e00133"/></dir></dir></dir></target><target name="mageetc"><dir name="."><file name="Ip_Promopdf.xml" hash=""/></dir></target></contents>
18
  <compatible/>
19
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
20
  </package>