Restaurant Reservations - Version 2.0.15

Version Description

(2020-03-02) = - Correction for the success messages and PDF export

Download this release

Release Info

Developer Rustaurius
Plugin Icon 128x128 Restaurant Reservations
Version 2.0.15
Comparing to
See all releases

Code changes from version 2.0.14 to 2.0.15

includes/CustomFields.class.php CHANGED
@@ -1,193 +1,193 @@
1
- <?php
2
- /**
3
- * A class that handles the main custom field functions
4
- */
5
- if ( ! defined( 'ABSPATH' ) )
6
- exit;
7
-
8
- if ( !class_exists( 'rtbCustomFields' ) ) {
9
- class rtbCustomFields {
10
-
11
- /**
12
- * Option name for storing modified default fields
13
- *
14
- * @since 0.1
15
- */
16
- public $modified_option_key;
17
-
18
- /**
19
- * Common string tacked onto the end of error messages
20
- *
21
- * @since 0.1
22
- */
23
- public $common_error_msg;
24
-
25
- /**
26
- * Initialize the plugin and register hooks
27
- *
28
- * @since 0.1
29
- */
30
- public function __construct() {
31
-
32
- // Option key where information about default fields that have
33
- // been modified and disabled is stored in the database
34
- $this->modified_option_key = apply_filters( 'cffrtb_modified_fields_option_key', 'cffrtb_modified_fields' );
35
-
36
- // Common string tacked onto the end of error messages
37
- $this->common_error_msg = sprintf( _x( 'Please try again. If the problem persists, you may need to refresh the page. If that does not solve the problem, please %scontact support%s for help.', 'A common phrase added to the end of error messages', 'custom-fields-for-rtb' ), '<a href="http://fivestarplugins.com/contact-us/">', '</a>' );
38
-
39
- // Validate user input for custom fields
40
- add_action( 'rtb_validate_booking_submission', array( $this, 'validate_custom_fields_input' ) );
41
-
42
- // Filter required phone setting when phone field is disabled
43
- add_filter( 'rtb-setting-require-phone', array( $this, 'never_require_phone' ) );
44
-
45
- // Insert/load custom field input with booking metadata
46
- add_filter( 'rtb_insert_booking_metadata', array( $this, 'insert_booking_metadata' ), 10, 2 );
47
- add_action( 'rtb_booking_load_post_data', array( $this, 'load_booking_meta_data' ), 10, 2 );
48
-
49
- // Print custom fields in notification template tags
50
- add_filter( 'rtb_notification_template_tags', array( $this, 'add_notification_template_tags' ), 10, 2 );
51
- add_filter( 'rtb_notification_template_tag_descriptions', array( $this, 'add_notification_template_tag_descriptions' ) );
52
-
53
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
54
- }
55
-
56
- public function enqueue_scripts() {
57
- $currentScreen = get_current_screen();
58
- if ( $currentScreen->id == 'bookings_page_cffrtb-editor' ) {
59
- wp_enqueue_style( 'rtb-admin-css', RTB_PLUGIN_URL . '/assets/css/admin.css', array(), RTB_VERSION );
60
- wp_enqueue_script( 'rtb-admin-js', RTB_PLUGIN_URL . '/assets/js/admin.js', array( 'jquery' ), RTB_VERSION, true );
61
- }
62
- }
63
-
64
- /**
65
- * Validate user input for custom fields
66
- *
67
- * @since 0.1
68
- */
69
- public function validate_custom_fields_input( $booking ) {
70
-
71
- $fields = rtb_get_custom_fields();
72
-
73
- if ( !count( $fields ) ) {
74
- return;
75
- }
76
-
77
- foreach( $fields as $field ) {
78
- $validation = $field->validate_input( $booking );
79
- }
80
- }
81
-
82
- /**
83
- * Add custom fields to metadata when a booking is saved
84
- *
85
- * @since 0.1
86
- */
87
- public function insert_booking_metadata( $meta, $booking ) {
88
-
89
- if ( empty( $booking->custom_fields ) ) {
90
- return $meta;
91
- }
92
-
93
- if ( !is_array( $meta ) ) {
94
- $meta = array();
95
- }
96
-
97
- if ( !isset( $meta['custom_fields'] ) ) {
98
- $meta['custom_fields'] = array();
99
- }
100
-
101
- $meta['custom_fields'] = $booking->custom_fields;
102
-
103
- return $meta;
104
- }
105
-
106
- /**
107
- * Add custom fields to metadata when booking is loaded
108
- *
109
- * @since 0.1
110
- */
111
- public function load_booking_meta_data( $booking, $post ) {
112
-
113
- $meta = get_post_meta( $booking->ID, 'rtb', true );
114
-
115
- if ( empty( $meta['custom_fields'] ) ) {
116
- return;
117
- }
118
-
119
- $booking->custom_fields = $meta['custom_fields'];
120
- }
121
-
122
- /**
123
- * Add custom fields as notification template tags
124
- *
125
- * @since 0.1
126
- */
127
- public function add_notification_template_tags( $tags, $notification ) {
128
- global $rtb_controller;
129
-
130
- $fields = rtb_get_custom_fields();
131
-
132
- $cf = isset( $notification->booking->custom_fields ) ? $notification->booking->custom_fields : array();
133
- $checkbox_icon = apply_filters( 'cffrtb_checkbox_icon_notification', '', $notification );
134
-
135
- foreach( $fields as $field ) {
136
-
137
- if ( $field->type == 'fieldset' ) {
138
- continue;
139
- }
140
-
141
- if ( isset( $cf[ $field->slug ] ) ) {
142
- $display_val = apply_filters( 'cffrtb_display_value_notification', $rtb_controller->fields->get_display_value( $cf[ $field->slug ], $field, $checkbox_icon ), $cf[ $field->slug ], $field, $notification );
143
- } else {
144
- $display_val = '';
145
- }
146
- $tags[ '{cf-' . esc_attr( $field->slug ) . '}' ] = $display_val;
147
- }
148
-
149
- return $tags;
150
- }
151
-
152
- /**
153
- * Add custom field notification template tag descriptions
154
- *
155
- * @since 0.1
156
- */
157
- public function add_notification_template_tag_descriptions( $tags ) {
158
-
159
- $fields = rtb_get_custom_fields();
160
-
161
- foreach( $fields as $field ) {
162
-
163
- if ( $field->type == 'fieldset' ) {
164
- continue;
165
- }
166
-
167
- $tags[ '{cf-' . esc_attr( $field->slug ) . '}' ] = esc_html( $field->title );
168
- }
169
-
170
- return $tags;
171
- }
172
-
173
- /**
174
- * Override the required phone setting when the phone field has been
175
- * disabled.
176
- *
177
- * @param string $value The value of the setting
178
- * @since 1.2.3
179
- */
180
- public function never_require_phone( $value ) {
181
- global $rtb_controller;
182
-
183
- $modified = get_option( $rtb_controller->custom_fields->modified_option_key );
184
-
185
- if ( $modified && isset( $modified['phone'] ) && !empty( $modified['phone']['disabled'] ) ) {
186
- return '';
187
- }
188
-
189
- return $value;
190
- }
191
-
192
- }
193
- } // endif;
1
+ <?php
2
+ /**
3
+ * A class that handles the main custom field functions
4
+ */
5
+ if ( ! defined( 'ABSPATH' ) )
6
+ exit;
7
+
8
+ if ( !class_exists( 'rtbCustomFields' ) ) {
9
+ class rtbCustomFields {
10
+
11
+ /**
12
+ * Option name for storing modified default fields
13
+ *
14
+ * @since 0.1
15
+ */
16
+ public $modified_option_key;
17
+
18
+ /**
19
+ * Common string tacked onto the end of error messages
20
+ *
21
+ * @since 0.1
22
+ */
23
+ public $common_error_msg;
24
+
25
+ /**
26
+ * Initialize the plugin and register hooks
27
+ *
28
+ * @since 0.1
29
+ */
30
+ public function __construct() {
31
+
32
+ // Option key where information about default fields that have
33
+ // been modified and disabled is stored in the database
34
+ $this->modified_option_key = apply_filters( 'cffrtb_modified_fields_option_key', 'cffrtb_modified_fields' );
35
+
36
+ // Common string tacked onto the end of error messages
37
+ $this->common_error_msg = sprintf( _x( 'Please try again. If the problem persists, you may need to refresh the page. If that does not solve the problem, please %scontact support%s for help.', 'A common phrase added to the end of error messages', 'custom-fields-for-rtb' ), '<a href="http://fivestarplugins.com/contact-us/">', '</a>' );
38
+
39
+ // Validate user input for custom fields
40
+ add_action( 'rtb_validate_booking_submission', array( $this, 'validate_custom_fields_input' ) );
41
+
42
+ // Filter required phone setting when phone field is disabled
43
+ add_filter( 'rtb-setting-require-phone', array( $this, 'never_require_phone' ) );
44
+
45
+ // Insert/load custom field input with booking metadata
46
+ add_filter( 'rtb_insert_booking_metadata', array( $this, 'insert_booking_metadata' ), 10, 2 );
47
+ add_action( 'rtb_booking_load_post_data', array( $this, 'load_booking_meta_data' ), 10, 2 );
48
+
49
+ // Print custom fields in notification template tags
50
+ add_filter( 'rtb_notification_template_tags', array( $this, 'add_notification_template_tags' ), 10, 2 );
51
+ add_filter( 'rtb_notification_template_tag_descriptions', array( $this, 'add_notification_template_tag_descriptions' ) );
52
+
53
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
54
+ }
55
+
56
+ public function enqueue_scripts() {
57
+ $currentScreen = get_current_screen();
58
+ if ( $currentScreen->id == 'bookings_page_cffrtb-editor' ) {
59
+ wp_enqueue_style( 'rtb-admin-css', RTB_PLUGIN_URL . '/assets/css/admin.css', array(), RTB_VERSION );
60
+ wp_enqueue_script( 'rtb-admin-js', RTB_PLUGIN_URL . '/assets/js/admin.js', array( 'jquery' ), RTB_VERSION, true );
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Validate user input for custom fields
66
+ *
67
+ * @since 0.1
68
+ */
69
+ public function validate_custom_fields_input( $booking ) {
70
+
71
+ $fields = rtb_get_custom_fields();
72
+
73
+ if ( !count( $fields ) ) {
74
+ return;
75
+ }
76
+
77
+ foreach( $fields as $field ) {
78
+ $validation = $field->validate_input( $booking );
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Add custom fields to metadata when a booking is saved
84
+ *
85
+ * @since 0.1
86
+ */
87
+ public function insert_booking_metadata( $meta, $booking ) {
88
+
89
+ if ( empty( $booking->custom_fields ) ) {
90
+ return $meta;
91
+ }
92
+
93
+ if ( !is_array( $meta ) ) {
94
+ $meta = array();
95
+ }
96
+
97
+ if ( !isset( $meta['custom_fields'] ) ) {
98
+ $meta['custom_fields'] = array();
99
+ }
100
+
101
+ $meta['custom_fields'] = $booking->custom_fields;
102
+
103
+ return $meta;
104
+ }
105
+
106
+ /**
107
+ * Add custom fields to metadata when booking is loaded
108
+ *
109
+ * @since 0.1
110
+ */
111
+ public function load_booking_meta_data( $booking, $post ) {
112
+
113
+ $meta = get_post_meta( $booking->ID, 'rtb', true );
114
+
115
+ if ( empty( $meta['custom_fields'] ) ) {
116
+ return;
117
+ }
118
+
119
+ $booking->custom_fields = $meta['custom_fields'];
120
+ }
121
+
122
+ /**
123
+ * Add custom fields as notification template tags
124
+ *
125
+ * @since 0.1
126
+ */
127
+ public function add_notification_template_tags( $tags, $notification ) {
128
+ global $rtb_controller;
129
+
130
+ $fields = rtb_get_custom_fields();
131
+
132
+ $cf = isset( $notification->booking->custom_fields ) ? $notification->booking->custom_fields : array();
133
+ $checkbox_icon = apply_filters( 'cffrtb_checkbox_icon_notification', '', $notification );
134
+
135
+ foreach( $fields as $field ) {
136
+
137
+ if ( $field->type == 'fieldset' ) {
138
+ continue;
139
+ }
140
+
141
+ if ( isset( $cf[ $field->slug ] ) ) {
142
+ $display_val = apply_filters( 'cffrtb_display_value_notification', $rtb_controller->fields->get_display_value( $cf[ $field->slug ], $field, $checkbox_icon ), $cf[ $field->slug ], $field, $notification );
143
+ } else {
144
+ $display_val = '';
145
+ }
146
+ $tags[ '{cf-' . esc_attr( $field->slug ) . '}' ] = $display_val;
147
+ }
148
+
149
+ return $tags;
150
+ }
151
+
152
+ /**
153
+ * Add custom field notification template tag descriptions
154
+ *
155
+ * @since 0.1
156
+ */
157
+ public function add_notification_template_tag_descriptions( $tags ) {
158
+
159
+ $fields = rtb_get_custom_fields();
160
+
161
+ foreach( $fields as $field ) {
162
+
163
+ if ( $field->type == 'fieldset' ) {
164
+ continue;
165
+ }
166
+
167
+ $tags[ '{cf-' . esc_attr( $field->slug ) . '}' ] = esc_html( $field->title );
168
+ }
169
+
170
+ return $tags;
171
+ }
172
+
173
+ /**
174
+ * Override the required phone setting when the phone field has been
175
+ * disabled.
176
+ *
177
+ * @param string $value The value of the setting
178
+ * @since 1.2.3
179
+ */
180
+ public function never_require_phone( $value ) {
181
+ global $rtb_controller;
182
+
183
+ $modified = get_option( $rtb_controller->custom_fields->modified_option_key );
184
+
185
+ if ( $modified && isset( $modified['phone'] ) && !empty( $modified['phone']['disabled'] ) ) {
186
+ return '';
187
+ }
188
+
189
+ return $value;
190
+ }
191
+
192
+ }
193
+ } // endif;
includes/Export.PDF.class.php CHANGED
@@ -248,9 +248,9 @@ class ebfrtbExportPDF extends ebfrtbExport {
248
  }
249
 
250
  // Load mPDF library
251
- require_once( RTB_PLUGIN_DIR . '/lib/mpdf/mpdf.php' );
252
 
253
- $mpdf = new mPDF( '', $this->paper_size, '', '', 15, 15, 25 );
254
  $mpdf = $this->set_doc_info( $mpdf );
255
 
256
  // Support languages automatically
248
  }
249
 
250
  // Load mPDF library
251
+ require_once( RTB_PLUGIN_DIR . '/lib/mpdf/vendor/autoload.php' );
252
 
253
+ $mpdf = new \Mpdf\Mpdf( [], $this->paper_size, '', '', 15, 15, 25 );
254
  $mpdf = $this->set_doc_info( $mpdf );
255
 
256
  // Support languages automatically
includes/ExportHandler.class.php CHANGED
@@ -53,7 +53,7 @@ class rtbExportHandler {
53
 
54
 
55
  // No warning needed if the directory is writable
56
- if ( wp_is_writable( RTB_PLUGIN_DIR . '/lib/mpdf/ttfontdata/' ) ) {
57
  return;
58
  }
59
 
@@ -288,7 +288,7 @@ class rtbExportHandler {
288
  <a href="#" class="button" id="ebfrtb-cancel-export-modal">
289
  <?php esc_html_e( 'Cancel', 'restaurant-reservations' ); ?>
290
  </a>
291
- <a href="<?php echo admin_url( 'admin.php?page=rtb-settings&tab=rtb-export' ); ?>" class="settings">
292
  <?php esc_html_e( 'Settings', 'restaurant-reservations' ); ?>
293
  </a>
294
  </form>
53
 
54
 
55
  // No warning needed if the directory is writable
56
+ if ( wp_is_writable( RTB_PLUGIN_DIR . '/lib/mpdf/vendor/mpdf/mpdf/tmp/ttfontdata/' ) ) {
57
  return;
58
  }
59
 
288
  <a href="#" class="button" id="ebfrtb-cancel-export-modal">
289
  <?php esc_html_e( 'Cancel', 'restaurant-reservations' ); ?>
290
  </a>
291
+ <a href="<?php echo admin_url( 'admin.php?page=rtb-settings&tab=rtb-export-tab' ); ?>" class="settings">
292
  <?php esc_html_e( 'Settings', 'restaurant-reservations' ); ?>
293
  </a>
294
  </form>
includes/Import.class.php CHANGED
@@ -1,279 +1,279 @@
1
- <?php
2
-
3
- /**
4
- * Class to import bookings from a spreadsheet (not working atm)
5
- */
6
-
7
- if ( !defined( 'ABSPATH' ) )
8
- exit;
9
-
10
- if (!class_exists('ComposerAutoloaderInit4618f5c41cf5e27cc7908556f031e4d4')) {require_once FDM_PLUGIN_DIR . '/lib/PHPSpreadsheet/vendor/autoload.php';}
11
- use PhpOffice\PhpSpreadsheet\Spreadsheet;
12
- class rtbImport {
13
-
14
- /**
15
- * Hook suffix for the page
16
- *
17
- * @since 0.1
18
- */
19
- public $hook_suffix;
20
-
21
- /**
22
- * The success/error message content
23
- *
24
- * @since 0.1
25
- */
26
- public $status;
27
-
28
- /**
29
- * Whether the operation was a success or not
30
- *
31
- * @since 0.1
32
- */
33
- public $message;
34
-
35
- public function __construct() {
36
- add_action( 'admin_menu', array($this, 'register_install_screen' ));
37
-
38
- if ( isset( $_POST['rtbImport'] ) ) { add_action( 'admin_init', array($this, 'import_bookings' )); }
39
-
40
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_import_scripts' ) );
41
- }
42
-
43
- public function register_install_screen() {
44
- $this->hook_suffix = add_submenu_page(
45
- 'rtb-bookings',
46
- _x( 'Import', 'Title of the Imports page', 'restaurant-reservations' ),
47
- _x( 'Import', 'Title of Imports link in the admin menu', 'restaurant-reservations' ),
48
- 'manage_options',
49
- 'rtb-imports',
50
- array( $this, 'display_editor_page' )
51
- );
52
-
53
- // Print the error modal and enqueue assets
54
- add_action( 'load-' . $this->hook_suffix, array( $this, 'enqueue_admin_assets' ) );
55
- }
56
-
57
- public function display_import_screen() {
58
- global $rtb_controller;
59
-
60
- $import_permission = $rtb_controller->permissions->check_permission( 'import' );
61
- ?>
62
- <div class='wrap'>
63
- <h2>Import</h2>
64
- <?php if ( $import_permission ) { ?>
65
- <form method='post' enctype="multipart/form-data">
66
- <p>
67
- <label for="rtb_bookings_spreadsheet"><?php _e("Spreadsheet Containing Bookings", 'restaurant-reservations') ?></label><br />
68
- <input name="rtb_bookings_spreadsheet" type="file" value=""/>
69
- </p>
70
- <input type='submit' name='rtbImport' value='Import Bookings' class='button button-primary' />
71
- </form>
72
- <?php } else { ?>
73
- <div class='rtb-premium-locked'>
74
- <a href="https://www.fivestarplugins.com/license-payment/?Selected=RTB&Quantity=1" target="_blank">Upgrade</a> to the premium version to use this feature
75
- </div>
76
- <?php } ?>
77
- </div>
78
- <?php }
79
-
80
- public function import_bookings() {
81
- global $rtb_controller;
82
-
83
- $fields = $rtb_controller->settings->get_booking_form_fields();
84
-
85
- $update = $this->handle_spreadsheet_upload();
86
-
87
- if ( $update['message_type'] != 'Success' ) :
88
- $this->status = false;
89
- $this->message = $update['message'];
90
-
91
- add_action( 'admin_notices', array( $this, 'display_notice' ) );
92
-
93
- return;
94
- endif;
95
-
96
- $excel_url = RTB_PLUGIN_DIR . '/user-sheets/' . $update['filename'];
97
-
98
- // Build the workbook object out of the uploaded spreadsheet
99
- $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($excel_url);
100
-
101
- // Create a worksheet object out of the product sheet in the workbook
102
- $sheet = $spreadsheet->getActiveSheet();
103
-
104
- $allowable_fields = array();
105
- foreach ($fields as $field) {$allowable_fields[] = $field->name;}
106
- //List of fields that can be accepted via upload
107
- //$allowed_fields = array("ID", "Title", "Description", "Price", "Sections");
108
-
109
-
110
- // Get column names
111
- $highest_column = $sheet->getHighestColumn();
112
- $highest_column_index = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::columnIndexFromString($highest_column);
113
- for ($column = 1; $column <= $highest_column_index; $column++) {
114
- /*if (trim($sheet->getCellByColumnAndRow($column, 1)->getValue()) == "ID") {$ID_column = $column;}
115
- if (trim($sheet->getCellByColumnAndRow($column, 1)->getValue()) == "Title") {$title_column = $column;}
116
- if (trim($sheet->getCellByColumnAndRow($column, 1)->getValue()) == "Description") {$description_column = $column;}
117
- if (trim($sheet->getCellByColumnAndRow($column, 1)->getValue()) == "Price") {$price_column = $column;}
118
- if (trim($sheet->getCellByColumnAndRow($column, 1)->getValue()) == "Sections") {$sections_column = $column;}*/
119
-
120
- foreach ($fields as $key => $field) {
121
- if (trim($sheet->getCellByColumnAndRow($column, 1)->getValue()) == $field->name) {$field->column = $column;}
122
- }
123
- }
124
-
125
-
126
- // Put the spreadsheet data into a multi-dimensional array to facilitate processing
127
- $highest_row = $sheet->getHighestRow();
128
- for ($row = 2; $row <= $highest_row; $row++) {
129
- for ($column = 1; $column <= $highest_column_index; $column++) {
130
- $data[$row][$column] = $sheet->getCellByColumnAndRow($column, $row)->getValue();
131
- }
132
- }
133
-
134
- // Create the query to insert the products one at a time into the database and then run it
135
- foreach ($data as $booking) {
136
- // Create an array of the values that are being inserted for each order,
137
- // edit if it's a current order, otherwise add it
138
- foreach ($booking as $col_index => $value) {
139
- if ($col_index == $ID_column and $ID_column !== null) {$post['ID'] = esc_sql($value);}
140
- if ($col_index == $title_column and $title_column !== null) {$post['post_title'] = esc_sql($value);}
141
- if ($col_index == $description_column and $description_column !== null) {$post['post_content'] = esc_sql($value);}
142
- if ($col_index == $price_column and $price_column !== null) {$post_prices = explode(",", esc_sql($value));}
143
- if (isset($sections_column) and $col_index == $sections_column and $sections_column !== null) {$post_sections = explode(",", esc_sql($value));}
144
- }
145
-
146
- if (!is_array($post_prices)) {$post_prices = array();}
147
- if (!is_array($post_sections)) {$post_sections = array();}
148
-
149
- if ($post['post_title'] == '') {continue;}
150
-
151
- $post['post_status'] = 'publish';
152
- $post['post_type'] = 'fdm-menu-item';
153
-
154
- if ( isset( $post['ID'] ) and $post['ID'] != '') { $post_id = wp_update_post($post); }
155
- else { $post_id = wp_insert_post($post); }
156
-
157
- if ( $post_id != 0 ) {
158
- foreach ( $post_sections as $section ) {
159
- $menu_section = term_exists($section, 'fdm-menu-section');
160
- if ( $menu_section !== 0 && $menu_section !== null ) { $menu_section_ids[] = (int) $menu_section['term_id']; }
161
- }
162
- if ( isset($menu_section_ids) and is_array($menu_section_ids) ) { wp_set_object_terms($post_id, $menu_section_ids, 'fdm-menu-section'); }
163
-
164
- update_post_meta( $post_id, 'fdm_item_price', implode(",", $post_prices) );
165
-
166
- $field_values = array();
167
- foreach ( $fields as $field ) {
168
- if (isset($field->column) and isset($menu_item[$field->column])) {
169
- $field_values[$field->slug] = esc_sql($menu_item[$field->column]);
170
-
171
- }
172
- }
173
- update_post_meta($post_id, '_fdm_menu_item_custom_fields', $field_values);
174
- }
175
-
176
- unset($post);
177
- unset($post_sections);
178
- unset($menu_section_ids);
179
- unset($post_prices);
180
- unset($field_values);
181
- }
182
-
183
- $this->status = true;
184
- $this->message = __("Menu items added successfully.", 'food-and-drink-menu');
185
-
186
- add_action( 'admin_notices', array( $this, 'display_notice' ) );
187
- }
188
-
189
- function handle_spreadsheet_upload() {
190
- /* Test if there is an error with the uploaded spreadsheet and return that error if there is */
191
- if (!empty($_FILES['fdm_menu_items_spreadsheet']['error']))
192
- {
193
- switch($_FILES['fdm_menu_items_spreadsheet']['error'])
194
- {
195
-
196
- case '1':
197
- $error = __('The uploaded file exceeds the upload_max_filesize directive in php.ini', 'food-and-drink-menu');
198
- break;
199
- case '2':
200
- $error = __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form', 'food-and-drink-menu');
201
- break;
202
- case '3':
203
- $error = __('The uploaded file was only partially uploaded', 'food-and-drink-menu');
204
- break;
205
- case '4':
206
- $error = __('No file was uploaded.', 'food-and-drink-menu');
207
- break;
208
-
209
- case '6':
210
- $error = __('Missing a temporary folder', 'food-and-drink-menu');
211
- break;
212
- case '7':
213
- $error = __('Failed to write file to disk', 'food-and-drink-menu');
214
- break;
215
- case '8':
216
- $error = __('File upload stopped by extension', 'food-and-drink-menu');
217
- break;
218
- case '999':
219
- default:
220
- $error = __('No error code avaiable', 'food-and-drink-menu');
221
- }
222
- }
223
- /* Make sure that the file exists */
224
- elseif (empty($_FILES['fdm_menu_items_spreadsheet']['tmp_name']) || $_FILES['fdm_menu_items_spreadsheet']['tmp_name'] == 'none') {
225
- $error = __('No file was uploaded here..', 'food-and-drink-menu');
226
- }
227
- /* Move the file and store the URL to pass it onwards*/
228
- /* Check that it is a .xls or .xlsx file */
229
- if(!isset($_FILES['fdm_menu_items_spreadsheet']['name']) or (!preg_match("/\.(xls.?)$/", $_FILES['fdm_menu_items_spreadsheet']['name']) and !preg_match("/\.(csv.?)$/", $_FILES['fdm_menu_items_spreadsheet']['name']))) {
230
- $error = __('File must be .csv, .xls or .xlsx', 'food-and-drink-menu');
231
- }
232
- else {
233
- $filename = basename( $_FILES['fdm_menu_items_spreadsheet']['name']);
234
- $filename = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $filename);
235
- $filename = mb_ereg_replace("([\.]{2,})", '', $filename);
236
-
237
- //for security reason, we force to remove all uploaded file
238
- $target_path = FDM_PLUGIN_DIR . "/user-sheets/";
239
-
240
- $target_path = $target_path . $filename;
241
-
242
- if (!move_uploaded_file($_FILES['fdm_menu_items_spreadsheet']['tmp_name'], $target_path)) {
243
- $error .= "There was an error uploading the file, please try again!";
244
- }
245
- else {
246
- $excel_file_name = $filename;
247
- }
248
- }
249
-
250
- /* Pass the data to the appropriate function in Update_Admin_Databases.php to create the products */
251
- if (!isset($error)) {
252
- $update = array("message_type" => "Success", "filename" => $excel_file_name);
253
- }
254
- else {
255
- $update = array("message_type" => "Error", "message" => $error);
256
- }
257
- return $update;
258
- }
259
-
260
- public function enqueue_import_scripts() {
261
- $screen = get_current_screen();
262
- if($screen->id == 'fdm-menu_page_fdm-import'){
263
- wp_enqueue_style( 'fdm-admin', FDM_PLUGIN_URL . '/assets/css/admin.css', array(), RTB_VERSION );
264
- wp_enqueue_script( 'fdm-admin-js', FDM_PLUGIN_URL . '/assets/js/admin.js', array( 'jquery' ), RTB_VERSION, true );
265
- }
266
- }
267
-
268
- public function display_notice() {
269
- if ( $this->status ) {
270
- echo "<div class='updated'><p>" . $this->message . "</p></div>";
271
- }
272
- else {
273
- echo "<div class='error'><p>" . $this->message . "</p></div>";
274
- }
275
- }
276
-
277
- }
278
-
279
-
1
+ <?php
2
+
3
+ /**
4
+ * Class to import bookings from a spreadsheet (not working atm)
5
+ */
6
+
7
+ if ( !defined( 'ABSPATH' ) )
8
+ exit;
9
+
10
+ if (!class_exists('ComposerAutoloaderInit4618f5c41cf5e27cc7908556f031e4d4')) {require_once FDM_PLUGIN_DIR . '/lib/PHPSpreadsheet/vendor/autoload.php';}
11
+ use PhpOffice\PhpSpreadsheet\Spreadsheet;
12
+ class rtbImport {
13
+
14
+ /**
15
+ * Hook suffix for the page
16
+ *
17
+ * @since 0.1
18
+ */
19
+ public $hook_suffix;
20
+
21
+ /**
22
+ * The success/error message content
23
+ *
24
+ * @since 0.1
25
+ */
26
+ public $status;
27
+
28
+ /**
29
+ * Whether the operation was a success or not
30
+ *
31
+ * @since 0.1
32
+ */
33
+ public $message;
34
+
35
+ public function __construct() {
36
+ add_action( 'admin_menu', array($this, 'register_install_screen' ));
37
+
38
+ if ( isset( $_POST['rtbImport'] ) ) { add_action( 'admin_init', array($this, 'import_bookings' )); }
39
+
40
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_import_scripts' ) );
41
+ }
42
+
43
+ public function register_install_screen() {
44
+ $this->hook_suffix = add_submenu_page(
45
+ 'rtb-bookings',
46
+ _x( 'Import', 'Title of the Imports page', 'restaurant-reservations' ),
47
+ _x( 'Import', 'Title of Imports link in the admin menu', 'restaurant-reservations' ),
48
+ 'manage_options',
49
+ 'rtb-imports',
50
+ array( $this, 'display_editor_page' )
51
+ );
52
+
53
+ // Print the error modal and enqueue assets
54
+ add_action( 'load-' . $this->hook_suffix, array( $this, 'enqueue_admin_assets' ) );
55
+ }
56
+
57
+ public function display_import_screen() {
58
+ global $rtb_controller;
59
+
60
+ $import_permission = $rtb_controller->permissions->check_permission( 'import' );
61
+ ?>
62
+ <div class='wrap'>
63
+ <h2>Import</h2>
64
+ <?php if ( $import_permission ) { ?>
65
+ <form method='post' enctype="multipart/form-data">
66
+ <p>
67
+ <label for="rtb_bookings_spreadsheet"><?php _e("Spreadsheet Containing Bookings", 'restaurant-reservations') ?></label><br />
68
+ <input name="rtb_bookings_spreadsheet" type="file" value=""/>
69
+ </p>
70
+ <input type='submit' name='rtbImport' value='Import Bookings' class='button button-primary' />
71
+ </form>
72
+ <?php } else { ?>
73
+ <div class='rtb-premium-locked'>
74
+ <a href="https://www.fivestarplugins.com/license-payment/?Selected=RTB&Quantity=1" target="_blank">Upgrade</a> to the premium version to use this feature
75
+ </div>
76
+ <?php } ?>
77
+ </div>
78
+ <?php }
79
+
80
+ public function import_bookings() {
81
+ global $rtb_controller;
82
+
83
+ $fields = $rtb_controller->settings->get_booking_form_fields();
84
+
85
+ $update = $this->handle_spreadsheet_upload();
86
+
87
+ if ( $update['message_type'] != 'Success' ) :
88
+ $this->status = false;
89
+ $this->message = $update['message'];
90
+
91
+ add_action( 'admin_notices', array( $this, 'display_notice' ) );
92
+
93
+ return;
94
+ endif;
95
+
96
+ $excel_url = RTB_PLUGIN_DIR . '/user-sheets/' . $update['filename'];
97
+
98
+ // Build the workbook object out of the uploaded spreadsheet
99
+ $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($excel_url);
100
+
101
+ // Create a worksheet object out of the product sheet in the workbook
102
+ $sheet = $spreadsheet->getActiveSheet();
103
+
104
+ $allowable_fields = array();
105
+ foreach ($fields as $field) {$allowable_fields[] = $field->name;}
106
+ //List of fields that can be accepted via upload
107
+ //$allowed_fields = array("ID", "Title", "Description", "Price", "Sections");
108
+
109
+
110
+ // Get column names
111
+ $highest_column = $sheet->getHighestColumn();
112
+ $highest_column_index = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::columnIndexFromString($highest_column);
113
+ for ($column = 1; $column <= $highest_column_index; $column++) {
114
+ /*if (trim($sheet->getCellByColumnAndRow($column, 1)->getValue()) == "ID") {$ID_column = $column;}
115
+ if (trim($sheet->getCellByColumnAndRow($column, 1)->getValue()) == "Title") {$title_column = $column;}
116
+ if (trim($sheet->getCellByColumnAndRow($column, 1)->getValue()) == "Description") {$description_column = $column;}
117
+ if (trim($sheet->getCellByColumnAndRow($column, 1)->getValue()) == "Price") {$price_column = $column;}
118
+ if (trim($sheet->getCellByColumnAndRow($column, 1)->getValue()) == "Sections") {$sections_column = $column;}*/
119
+
120
+ foreach ($fields as $key => $field) {
121
+ if (trim($sheet->getCellByColumnAndRow($column, 1)->getValue()) == $field->name) {$field->column = $column;}
122
+ }
123
+ }
124
+
125
+
126
+ // Put the spreadsheet data into a multi-dimensional array to facilitate processing
127
+ $highest_row = $sheet->getHighestRow();
128
+ for ($row = 2; $row <= $highest_row; $row++) {
129
+ for ($column = 1; $column <= $highest_column_index; $column++) {
130
+ $data[$row][$column] = $sheet->getCellByColumnAndRow($column, $row)->getValue();
131
+ }
132
+ }
133
+
134
+ // Create the query to insert the products one at a time into the database and then run it
135
+ foreach ($data as $booking) {
136
+ // Create an array of the values that are being inserted for each order,
137
+ // edit if it's a current order, otherwise add it
138
+ foreach ($booking as $col_index => $value) {
139
+ if ($col_index == $ID_column and $ID_column !== null) {$post['ID'] = esc_sql($value);}
140
+ if ($col_index == $title_column and $title_column !== null) {$post['post_title'] = esc_sql($value);}
141
+ if ($col_index == $description_column and $description_column !== null) {$post['post_content'] = esc_sql($value);}
142
+ if ($col_index == $price_column and $price_column !== null) {$post_prices = explode(",", esc_sql($value));}
143
+ if (isset($sections_column) and $col_index == $sections_column and $sections_column !== null) {$post_sections = explode(",", esc_sql($value));}
144
+ }
145
+
146
+ if (!is_array($post_prices)) {$post_prices = array();}
147
+ if (!is_array($post_sections)) {$post_sections = array();}
148
+
149
+ if ($post['post_title'] == '') {continue;}
150
+
151
+ $post['post_status'] = 'publish';
152
+ $post['post_type'] = 'fdm-menu-item';
153
+
154
+ if ( isset( $post['ID'] ) and $post['ID'] != '') { $post_id = wp_update_post($post); }
155
+ else { $post_id = wp_insert_post($post); }
156
+
157
+ if ( $post_id != 0 ) {
158
+ foreach ( $post_sections as $section ) {
159
+ $menu_section = term_exists($section, 'fdm-menu-section');
160
+ if ( $menu_section !== 0 && $menu_section !== null ) { $menu_section_ids[] = (int) $menu_section['term_id']; }
161
+ }
162
+ if ( isset($menu_section_ids) and is_array($menu_section_ids) ) { wp_set_object_terms($post_id, $menu_section_ids, 'fdm-menu-section'); }
163
+
164
+ update_post_meta( $post_id, 'fdm_item_price', implode(",", $post_prices) );
165
+
166
+ $field_values = array();
167
+ foreach ( $fields as $field ) {
168
+ if (isset($field->column) and isset($menu_item[$field->column])) {
169
+ $field_values[$field->slug] = esc_sql($menu_item[$field->column]);
170
+
171
+ }
172
+ }
173
+ update_post_meta($post_id, '_fdm_menu_item_custom_fields', $field_values);
174
+ }
175
+
176
+ unset($post);
177
+ unset($post_sections);
178
+ unset($menu_section_ids);
179
+ unset($post_prices);
180
+ unset($field_values);
181
+ }
182
+
183
+ $this->status = true;
184
+ $this->message = __("Menu items added successfully.", 'food-and-drink-menu');
185
+
186
+ add_action( 'admin_notices', array( $this, 'display_notice' ) );
187
+ }
188
+
189
+ function handle_spreadsheet_upload() {
190
+ /* Test if there is an error with the uploaded spreadsheet and return that error if there is */
191
+ if (!empty($_FILES['fdm_menu_items_spreadsheet']['error']))
192
+ {
193
+ switch($_FILES['fdm_menu_items_spreadsheet']['error'])
194
+ {
195
+
196
+ case '1':
197
+ $error = __('The uploaded file exceeds the upload_max_filesize directive in php.ini', 'food-and-drink-menu');
198
+ break;
199
+ case '2':
200
+ $error = __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form', 'food-and-drink-menu');
201
+ break;
202
+ case '3':
203
+ $error = __('The uploaded file was only partially uploaded', 'food-and-drink-menu');
204
+ break;
205
+ case '4':
206
+ $error = __('No file was uploaded.', 'food-and-drink-menu');
207
+ break;
208
+
209
+ case '6':
210
+ $error = __('Missing a temporary folder', 'food-and-drink-menu');
211
+ break;
212
+ case '7':
213
+ $error = __('Failed to write file to disk', 'food-and-drink-menu');
214
+ break;
215
+ case '8':
216
+ $error = __('File upload stopped by extension', 'food-and-drink-menu');
217
+ break;
218
+ case '999':
219
+ default:
220
+ $error = __('No error code avaiable', 'food-and-drink-menu');
221
+ }
222
+ }
223
+ /* Make sure that the file exists */
224
+ elseif (empty($_FILES['fdm_menu_items_spreadsheet']['tmp_name']) || $_FILES['fdm_menu_items_spreadsheet']['tmp_name'] == 'none') {
225
+ $error = __('No file was uploaded here..', 'food-and-drink-menu');
226
+ }
227
+ /* Move the file and store the URL to pass it onwards*/
228
+ /* Check that it is a .xls or .xlsx file */
229
+ if(!isset($_FILES['fdm_menu_items_spreadsheet']['name']) or (!preg_match("/\.(xls.?)$/", $_FILES['fdm_menu_items_spreadsheet']['name']) and !preg_match("/\.(csv.?)$/", $_FILES['fdm_menu_items_spreadsheet']['name']))) {
230
+ $error = __('File must be .csv, .xls or .xlsx', 'food-and-drink-menu');
231
+ }
232
+ else {
233
+ $filename = basename( $_FILES['fdm_menu_items_spreadsheet']['name']);
234
+ $filename = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $filename);
235
+ $filename = mb_ereg_replace("([\.]{2,})", '', $filename);
236
+
237
+ //for security reason, we force to remove all uploaded file
238
+ $target_path = FDM_PLUGIN_DIR . "/user-sheets/";
239
+
240
+ $target_path = $target_path . $filename;
241
+
242
+ if (!move_uploaded_file($_FILES['fdm_menu_items_spreadsheet']['tmp_name'], $target_path)) {
243
+ $error .= "There was an error uploading the file, please try again!";
244
+ }
245
+ else {
246
+ $excel_file_name = $filename;
247
+ }
248
+ }
249
+
250
+ /* Pass the data to the appropriate function in Update_Admin_Databases.php to create the products */
251
+ if (!isset($error)) {
252
+ $update = array("message_type" => "Success", "filename" => $excel_file_name);
253
+ }
254
+ else {
255
+ $update = array("message_type" => "Error", "message" => $error);
256
+ }
257
+ return $update;
258
+ }
259
+
260
+ public function enqueue_import_scripts() {
261
+ $screen = get_current_screen();
262
+ if($screen->id == 'fdm-menu_page_fdm-import'){
263
+ wp_enqueue_style( 'fdm-admin', FDM_PLUGIN_URL . '/assets/css/admin.css', array(), RTB_VERSION );
264
+ wp_enqueue_script( 'fdm-admin-js', FDM_PLUGIN_URL . '/assets/js/admin.js', array( 'jquery' ), RTB_VERSION, true );
265
+ }
266
+ }
267
+
268
+ public function display_notice() {
269
+ if ( $this->status ) {
270
+ echo "<div class='updated'><p>" . $this->message . "</p></div>";
271
+ }
272
+ else {
273
+ echo "<div class='error'><p>" . $this->message . "</p></div>";
274
+ }
275
+ }
276
+
277
+ }
278
+
279
+
includes/Settings.class.php CHANGED
@@ -92,6 +92,7 @@ class rtbSettings {
92
  'auto-confirm-max-party-size' => 1,
93
  'rtb-dining-block-length' => '120_minutes',
94
  'success-message' => _x( 'Thanks, your booking request is waiting to be confirmed. Updates will be sent to the email address you provided.', 'restaurant-reservations' ),
 
95
  'date-format' => _x( 'mmmm d, yyyy', 'Default date format for display. Must match formatting rules at http://amsul.ca/pickadate.js/date/#formats', 'restaurant-reservations' ),
96
  'time-format' => _x( 'h:i A', 'Default time format for display. Must match formatting rules at http://amsul.ca/pickadate.js/time/#formats', 'restaurant-reservations' ),
97
  'time-interval' => _x( '30', 'Default interval in minutes when selecting a time.', 'restaurant-reservations' ),
@@ -565,12 +566,24 @@ If you won\'t be able to make it, please let us know so that we can release your
565
  'textarea',
566
  array(
567
  'id' => 'success-message',
568
- 'title' => __( 'Success Message', 'restaurant-reservations' ),
569
- 'description' => __( 'Enter the message to display when a booking request is made.', 'restaurant-reservations' ),
570
  'placeholder' => $this->defaults['success-message'],
571
  )
572
  );
573
 
 
 
 
 
 
 
 
 
 
 
 
 
574
  $sap->add_section(
575
  'rtb-settings',
576
  array(
92
  'auto-confirm-max-party-size' => 1,
93
  'rtb-dining-block-length' => '120_minutes',
94
  'success-message' => _x( 'Thanks, your booking request is waiting to be confirmed. Updates will be sent to the email address you provided.', 'restaurant-reservations' ),
95
+ 'confirmed-message' => _x( 'Thanks, your booking request has been automatically confirmed. We look forward to seeing you soon!', 'restaurant-reservations' ),
96
  'date-format' => _x( 'mmmm d, yyyy', 'Default date format for display. Must match formatting rules at http://amsul.ca/pickadate.js/date/#formats', 'restaurant-reservations' ),
97
  'time-format' => _x( 'h:i A', 'Default time format for display. Must match formatting rules at http://amsul.ca/pickadate.js/time/#formats', 'restaurant-reservations' ),
98
  'time-interval' => _x( '30', 'Default interval in minutes when selecting a time.', 'restaurant-reservations' ),
566
  'textarea',
567
  array(
568
  'id' => 'success-message',
569
+ 'title' => __( 'Pending Confirmation Message', 'restaurant-reservations' ),
570
+ 'description' => __( 'Enter the message to display when a booking request is made and is set to pending confirmation.', 'restaurant-reservations' ),
571
  'placeholder' => $this->defaults['success-message'],
572
  )
573
  );
574
 
575
+ $sap->add_setting(
576
+ 'rtb-settings',
577
+ 'rtb-general',
578
+ 'textarea',
579
+ array(
580
+ 'id' => 'confirmed-message',
581
+ 'title' => __( 'Confirmed Booking Message', 'restaurant-reservations' ),
582
+ 'description' => __( 'Enter the message to display when a booking is made that has been automatically confirmed.', 'restaurant-reservations' ),
583
+ 'placeholder' => $this->defaults['confirmed-message'],
584
+ )
585
+ );
586
+
587
  $sap->add_section(
588
  'rtb-settings',
589
  array(
includes/template-functions.php CHANGED
@@ -90,7 +90,7 @@ function rtb_print_booking_form( $args = array() ) {
90
  <div class="rtb-booking-form">
91
  <?php if ( $rtb_controller->request->request_inserted === true ) : ?>
92
  <div class="rtb-message">
93
- <p><?php echo ($rtb_controller->request->post_status == 'confirmed') ? $rtb_controller->settings->get_setting( 'confirmed-message' ) : $rtb_controller->settings->get_setting( 'success-message' ); ?></p>
94
  </div>
95
  <?php else : ?>
96
  <form method="POST" action="<?php echo esc_attr( $booking_page ); ?>">
@@ -229,6 +229,10 @@ function rtb_print_view_bookings_form( $args = array() ) {
229
 
230
  ?>
231
 
 
 
 
 
232
  <div class="rtb-view-bookings-form">
233
 
234
  <div class='rtb-view-bookings-form-date-selector-div'>
90
  <div class="rtb-booking-form">
91
  <?php if ( $rtb_controller->request->request_inserted === true ) : ?>
92
  <div class="rtb-message">
93
+ <p><?php echo ($rtb_controller->request->post_status == 'confirmed' ? $rtb_controller->settings->get_setting( 'confirmed-message' ) : $rtb_controller->settings->get_setting( 'success-message' )); ?></p>
94
  </div>
95
  <?php else : ?>
96
  <form method="POST" action="<?php echo esc_attr( $booking_page ); ?>">
229
 
230
  ?>
231
 
232
+ <script type="text/javascript">
233
+ var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
234
+ </script>
235
+
236
  <div class="rtb-view-bookings-form">
237
 
238
  <div class='rtb-view-bookings-form-date-selector-div'>
lib/mpdf/CHANGELOG.txt DELETED
@@ -1,3110 +0,0 @@
1
- ===========================
2
- mPDF 6.0
3
- 20/12/2014
4
- ===========================
5
- New features / Improvements
6
- ---------------------------
7
- Support for OpenTypeLayout tables / features for complex scripts and Advances Typography.
8
- Improved bidirectional text handling.
9
- Improved line-breaking, including for complex scripts e.g. Lao, Thai and Khmer.
10
- Updated page-breaking options.
11
- Automatic language mark-up and font selection using autoScriptToLang and autoLangToFont.
12
- Kashida for text-justification in arabic scripts.
13
- Index collation for non-ASCII characters.
14
- Index mark-up allowing control over layout using CSS.
15
- {PAGENO} and {nbpg} can use any of the number types as in list-style e.g. set in <pagebreak> using pagenumstyle.
16
- CSS support for lists.
17
- Default stylesheet - mpdf.css - updated.
18
-
19
-
20
- Added CSS support
21
- -----------------
22
- - lang attribute selector e.g. :lang(fr), [lang="fr"]
23
- - font-variant-position
24
- - font-variant-caps
25
- - font-variant-ligatures
26
- - font-variant-numeric
27
- - font-variant-alternates - Only [normal | historical-forms] supported (i.e. most are NOT supported)
28
- - font-variant - as above, and except for: east-asian-variant-values, east-asian-width-values, ruby
29
- - font-language-override
30
- - font-feature-settings
31
- - text-outline is now supported on TD/TH tags
32
- - hebrew, khmer, cambodian, lao, and cjk-decimal recognised as values for "list-style-type" in numbered lists and page numbering.
33
- - list-style-image and list-style-position
34
- - transform (on <img> only)
35
- - text-decoration:overline
36
- - image-rendering
37
- - unicode-bidi (also <bdi> tag)
38
- - vertical-align can use lengths e.g. 0.5em
39
- - line-stacking-strategy
40
- - line-stacking-shift
41
-
42
- ================
43
- mPDF 5.7.4
44
- 15/12/2014
45
- ================
46
- Bug Fixes & Minor Additions
47
- ---------------------------
48
- - SVG images now support embedded images e.g. <image xlink:href="image.png" width="100px" height="100px" />
49
- - SVG images now supports <tspan> element e.g. <tspan x,y,dx,dy,text-anchor >, and also <tref>
50
- - SVG images now can use Autofont (see top of classes/svg.php file)
51
- - SVG images now has limited support for CSS classes (see top of classes/svg.php file)
52
- - SVG images - style inheritance improved
53
- - SVG images - improved handling of comments and other extraneous code
54
- - SVG images - fix to ensure opacity is reset before another element
55
- - SVG images - font-size not resetting after a <text> element
56
- - SVG radial gradients bug (if the focus [fx,fy] lies outside circle defined by [cx,cy] and r) cf. pservers-grad-15-b.svg
57
- - SVG allows spaces in attribute definitions in <use> or <defs> e.g. <use x = "0" y = "0" xlink:href = "#s3" />
58
- - SVG text which contains a < sign, it will break the text - now processed as &lt; (despite the fact that this does not conform to XML spec)
59
- - SVG images - support automatic font selection and (minimal) use of CSS classes - cf. the defined constants at top of svg.php file
60
- - SVG images - text-anchor now supported as a CSS style, as well as an HTML attribute
61
- - CSS support for :nth-child() selector improved to fully support the draft CSS3 spec - http://www.w3.org/TR/selectors/#nth-child-pseudo
62
- [NB only works on table columns or rows]
63
- - text-indent when set as "em" - incorrectly calculated if last text in line in different font size than for block
64
- - CSS not applying cascaded styles on <A> elements - [changed MergeCSS() type to INLINE for 'A', LEGEND, METER and PROGRESS]
65
- - fix for underline/strikethrough/overline so that line position(s) are based correctly on font-size/font in nested situations
66
- - Error: Strict warning: Only variables should be passed by reference - in PHP5.5.9
67
- - bug accessing images from some servers (HTTP 403 Forbidden whn accessed using fopen etc.)
68
- - Setting page format incorrectly set default twice and missed some options
69
- - bug fixed in Overwrite() when specifying replacement as a string
70
- - barcode C93 - updated C93 code from TCPDF because of bug - incorrect checksum character for "153-2-4"
71
- - Tables - bug when using colspan across columns which may have a cell width specified
72
- cf. http://www.mpdf1.com/forum/discussion/2221/colspan-bug
73
- - Tables - cell height (when specified) is not resized when table is shrunk
74
- - Tables - if table width specified, but narrower than minimum cell wdith, and less than page width - table will expand to
75
- minimum cell width(s) as long as $keep_table_proportions = true
76
- - Tables - if using packTableData, and borders-collapse, wider border is overwriting content of adjacent cell
77
- Test case:
78
- <table style="border-collapse: collapse;">
79
- <tr><td style="border-bottom: 42px solid #0FF; "> Hallo world </td></tr>
80
- <tr><td style="border-top: 14px solid #0F0; "> Hallo world </td></tr>
81
- </table>
82
- - Images - image height is reset proportional to original if width is set to maximum e.g. <img width="100%" height="20mm"
83
- - URL handling changed to work with special characters in path fragments; affects <a> links, <mg> images and
84
- CSS url() e.g background-image
85
- - also to ignore "../" included as a query value
86
- - Barcodes with bottom numerals e.g. EAN-13 - incorrect numeral size when using core fonts
87
- --------------------------------
88
- NB Spec. for embedded SVG images:
89
- as per http://www.w3.org/TR/2003/REC-SVG11-20030114/struct.html#ImageElement
90
- Attributes supported:
91
- x
92
- y
93
- xlink:href (required) - can be jpeg, png or gif image - not vector (SVG or WMF) image
94
- width (required)
95
- height (required)
96
- preserveAspectRatio
97
-
98
- Note: all attribute names and values are case-sensitive
99
- width and height cannot be assigned by CSS - must be attributes
100
- ---------------------------------
101
- ================
102
- mPDF 5.7.3
103
- 24/8/2014
104
- ================
105
- Bug Fixes & Minor Additions
106
- ---------------------------
107
- - Tables - cellSpacing and cellPadding taking preference over CSS stylesheet
108
- - Tables - background images in table inside HTML Footer incorrectly positioned
109
- - Tables - cell in a nested table with a specified width, should determine width of parent table cell
110
- (cf. http://www.mpdf1.com/forum/discussion/1648/nested-table-bug-)
111
- - Tables - colspan (on a row after first row) exceeds number of columns in table
112
- - Gradients in Imported documents (mPDFI) causing error in some browsers
113
- - Fatal error after page-break-after:always on root level block element
114
- - Support for 'https/SSL' if file_get_contents_by_socket required (e.g. getting images with allow_url_fopen turned off)
115
- - Improved support for specified ports when getting external CSS stylesheets e.g. www.domain.com:80
116
- - error accessing local .css files with dummy queries (cache-busting) e.g. mpdfstyleA4.css?v=2.0.18.9
117
- - start of end tag in PRE incorrectly changed to &lt;
118
- - error thrown when open.basedir restriction in effect (deleting temporary files)
119
- - image which forces pagebreak incorrectly positioned at top of page
120
- - [changes to avoid warning notices by checking if (isset(x)) before referencing it]
121
- - text with letter-spacing set inside table which needs to be resixed (shrunk) - letter-spacing was not adjusted
122
- - nested table incorrectly calculating width and unnecessarily wrapping text
123
- - vertical-align:super|sub can be nested using <span> elements
124
- - inline elements can be nested e.g. text <sup>text<sup>13</sup>text</sup> text
125
- - CSS vertical-align:0.5em (or %) now supported
126
- - underline and strikethrough now use the parent inline block baseline/fontsize/color for child inline elements *** change in behaviour
127
- (Adjusts line height to take account of superscript and subscript except in tables)
128
- - nested table incorrectly calculating width and unnecessarily wrapping text
129
- - tables - font size carrying over from one nested table to the next nested table
130
- - tables - border set as attribute on <TABLE> overrides border set as CSS on <TD>
131
- - tables - if table width set to 100% and one cell/column is empty with no padding/border, sizing incorrectly
132
- (http://www.mpdf1.com/forum/discussion/1886/td-fontsize-in-nested-table-bug-#Item_5)
133
- - <main> added as recognised tag
134
- - CSS style transform supported on <img> element (only)
135
- All transform functions are supported except matrix() i.e. translate(), translateX(), translateY(), skew(), skewX(), skewY(),
136
- scale(), scaleX(), scaleY(), rotate()
137
- NB When using Columns or Keep-with-table (use_kwt), cannot use transform
138
- - CSS background-color now supported on <img> element
139
- - @page :first not recognised unless @page {} has styles set
140
- - left/right margins not allowed on @page :first
141
-
142
-
143
-
144
- ================
145
- mPDF 5.7.2
146
- 28/12/2013
147
- ================
148
- Bug Fixes
149
- ---------
150
- - <tfoot> not printing at all (since v5.7)
151
- - list-style incorrectly overriding list-style-type in cascading CSS
152
- - page-break-after:avoid not taking into account bottom padding and margin when estimating if next line can fit on page
153
- - images not displayed when using "https://" if images are referenced by src="//domain.com/image"
154
- - +aCJK incorrectly parsed when instantiating class e.g. new mpDF('ja+aCJK')
155
- - line-breaking - zero-width object at end of line (e.g. index entry) causing a space left untrimmed at end of line
156
- - ToC since v5.7 incorrectly handling non-ascii characters, entities or tags
157
- - cell height miscalculated when using hard-hyphenate
158
- - border colors set with transparency not working
159
- - transparency settings for stroke and fill interfering with one another
160
- - 'float' inside a HTML header/footer - not clearing the float before first line of text
161
- - error if script run across date change at midnight
162
- - temporary file name collisions (e.g. when processing images) if numerous users
163
- - <watermarkimage> position attribute not working
164
- - < (less-than sign) inside a PRE element, and NOT start of a valid tag, was incorrectly removed
165
- - file attachments not opening in Reader XI
166
- - JPG images not recognised if not containing JFIF or Exif markers
167
- - instance of preg_replace with /e modifier causing error in PHP 5.5
168
- - correctly handle CSS URLs with no scheme
169
- - Index entries causing errors when repeat entries are used within page-break-inside:avoid, rotated tables etc.
170
- - table with fixed width column and long word in cell set to colspan across this column (adding spare width to all columns)
171
- - incorrect hyphenation if multiple soft-hyphens on line before break
172
- - SVG images - objects contained in <defs> being displayed
173
- - SVG images - multiple, or quoted fonts e.g. style="font-family:'lucida grande', verdana" not recognised
174
- - SVG images - line with opacity=0 still visible (only in some PDF viewers/browsers)
175
- - text in an SVG image displaying with incorrect font in some PDF viewers/browsers
176
- - SVG images - fill:RGB(0,0,0) not recognised when uppercase
177
- - background images using data:image\/(jpeg|gif|png);base64 format - error when reading in stylesheet
178
-
179
- New CSS support
180
- ---------------
181
- - added support for style="opacity:0.6;" in SVG images - previously only supported style="fill-opacity:0.6; stroke-opacity: 0.6;"
182
- - improved PNG image handling for some cases of alpha channel transparency
183
- - khmer, cambodian and lao recognised as list-style-type for numbered lists
184
-
185
- SVG Images
186
- ----------
187
- Limited support for <use> and <defs>
188
-
189
- ================
190
- mPDF 5.7.1
191
- 1/09/2013
192
- ================
193
- 1) FILES: mpdf.php
194
- Bug fix; Dollar sign enclosed by <pre> tag causing error.
195
- Test e.g.: <pre>Test $1.00 Test</pre> <pre>Test $2.00 Test</pre> <pre>Test $3.00 Test</pre> <pre>Test $4.00 Test</pre>
196
- -----------------------------
197
- 2) FILES: includes/functions.php AND mpdf.php
198
- Changes to preg_replace with /e modifier to use preg_replace_callback
199
- (/e depracated from PHP 5.5)
200
- -----------------------------
201
- 3) FILES: classes/barcode.php
202
- Small change to function barcode_c128() which allows ASCII 0 - 31 to be used in C128A e.g. chr(13) in:
203
- <barcode code="5432&#013;1068" type="C128A" />
204
- -----------------------------
205
- 4) FILES: mpdf.php
206
- Using $use_kwt ("keep-[heading]-with-table") if <h4></h4> before table is on 2 lines and pagebreak occurs after first line
207
- the first line is displayed at the bottom of the 2nd page.
208
- Edited so that $use_kwt only works if the HEADING is only one line. Else ignores (but prints correctly)
209
- -----------------------------
210
- 5) FILES: mpdf.php
211
- Clearing old temporary files from _MPDF_TEMP_PATH will now ignore "hidden" files e.g. starting with a "." .htaccess, .gitignore etc.
212
- and also leave dummy.txt alone
213
- -----------------------------
214
-
215
-
216
- ===========================
217
- mPDF 5.7
218
- 14/07/2013
219
- ===========================
220
-
221
- Files changed
222
- -------------
223
- config.php
224
- mpdf.php
225
- classes/tocontents.php
226
- classes/cssmgr.php
227
- classes/svg.php
228
- includes/functions.php
229
- includes/out.php
230
- examples/formsubmit.php [Important - Security update]
231
-
232
- Updated Example Files in /examples/
233
- -----------------------------------
234
- All example files
235
- mpdfstyleA4.css
236
-
237
-
238
- config.php
239
- ----------
240
- Removed:
241
- $this->hyphenateTables
242
- $this->hyphenate
243
- $this->orphansAllowed
244
- Edited:
245
- "hyphens: manual" - Added to $this->defaultCSS
246
- $this->allowedCSStags now includes '|TEXTCIRCLE|DOTTAB'
247
- New:
248
- $this->decimal_align = array('DP'=>'.', 'DC'=>',', 'DM'=>"\xc2\xb7", 'DA'=>"\xd9\xab", 'DD'=>'-');
249
- $this->h2toc = array('H1'=>0, 'H2'=>1, 'H3'=>2);
250
- $this->h2bookmarks = array('H1'=>0, 'H2'=>1, 'H3'=>2);
251
- $this->CJKforceend = false; // Forces overflowng punctuation to hang outside right margin (used with CJK script)
252
-
253
-
254
- Backwards compatability
255
- -----------------------
256
- Changes in mPDF 5.7 may cause some changes to the way your documents appear. There are two main differences:
257
- 1) Hyphenation. To retain appearance compatible with earlier versions, set the CSS property "hyphens: auto" whenever
258
- you previously used $mpdf->hyphenate=true;
259
- 2) Table of Contents - appearance can now be controlled with CSS styles. By default, in mPDF 5.7, no styling is applied so you will get:
260
- - No indent (previous default of 5mm) - ($tocindent is ignored)
261
- - Any font, font-size set ($tocfont or $tocfontsize) will not work
262
- - HyperLinks will appear with your default appearance - usually blue and underlined
263
- - line spacing will be narrower (can use line-height or margin-top in CSS)
264
-
265
-
266
- New features / Improvements
267
- ---------------------------
268
- Layout of Table of Content ToC now controlled using CSS styles
269
- Text alignment on decimal mark inside tables
270
- Automatically generated bookmarks and/or ToC entries from H1 - H6 tags
271
- Support for unit of "rem" as size e.g. font-size: 1rem;
272
- Origin and clipping for background images and gradients controlled by CSS i.e. background-origin, background-size, background-clip
273
- Text-outline controlled by CSS (compatible with CSS3 spec.)
274
- Use of <dottab> enhanced by custom CSS "outdent" property
275
- Image HTML attributes <img> added: max-height, max-width, min-height and min-width
276
- Spotcolor can now be defined as it is used e.g. color: spot(PANTONE 534 EC, 100%, 85, 65, 47, 9);
277
- Lists - added support for "start" attribute in <ol> e.g. <ol start="5">
278
- Hyphenation controlled using CSS, consistent with CSS3 spec.
279
- Line breaking improved to avoid breaks within words where HTML tags are used e.g. H<sub>2<sub>0
280
- Line breaking in CJK scripts improved (and ability to force hanging punctuation)
281
- Numerals in a CJK script are kept together
282
- RTL improved support for phrases containing numerals and \ and /
283
- Bidi override codes supported - Right-to-Left Embedding [RLE] U+202B, Left-to-Right Embedding [LRE] U+202A,
284
- U+202C POP DIRECTIONAL FORMATTING (PDF)
285
- Support for <base href=""> in HTML - uses it to SetBasePath for relative URLs.
286
- HTML tag - added support for <wbr> or <wbr /> - converted to a soft-hyphen
287
- CSS now takes precedence over HTML attribute e.g. <table bgcolor="black" style="background-color:yellow">
288
-
289
-
290
-
291
- Added CSS support
292
- -----------------
293
- - max-height, max-width, min-height and min-width for images <img>
294
- - "hyphens: none|manual|auto" as per CSS3 spec.
295
- - Decimal mark alignment e.g. text-align: "." center;
296
- - "rem" accepted as a valid (font)size in CSS e.g. font-size: 1.5rem
297
- - text-outline, text-outline-width and text-outline-color supported everywhere except in tables (blur not supported)
298
- - background-origin, background-size, background-clip are now supported everywhere except in tables
299
- - "visibility: hidden|visible|printonly|screenonly" for inline elements e.g. <span>
300
- - Colors: device-cmyk(c,m,y,k) as per CSS3 spec. For consistency, device-cmyka also supported (not CSS3 spec)
301
- - "z-index" can be used to utilise layers in the PDF document
302
- - Custom CSS property added: "outdent" - opposite of indent
303
-
304
- The HTML elements <dottab> and <textcircle> can now have CSS properties applied to them.
305
-
306
-
307
- Bug fixes
308
- ---------
309
- - SVG images - path including e.g. 1.234E-15 incorrectly parsed (not recognising capital E)
310
- - Tables - if a table starts when the Y position on page is below bottom margin caused endless loop
311
- - Float-ing DIVs - starting a float at bottom of page and it causes page break before anything output, second new page is forced
312
- - Tables - Warning notice now given in Table footer or header if <tfoot> placed after <tbody> and table spans page
313
- - Columns - block with border-width wider than the length of the border line, line overflows
314
- - Columns - block with no padding containing a block with borders but no backgound colour, borders not printed
315
- - Table in Columns - when background color set by surrounding block element - colour missing for height of half bottom border.
316
- - TOCpagebreakByArray() when called by function was not adding the pagebreak
317
- - Border around block element - dashed not showing correctly (not resetting linewidth between different edges)
318
- - Double border in table - when background colour set in surrounding block element - shows as black line between the 2 bits of double
319
- - Borders around DIVs - "double" border problem if not all 4 sides equally - fixed
320
- - Borders around DIVs - solid (and double) borders overlap as in tables - now fixed so mitred joins as in browser
321
- [Inadvertently improves borders in Columns because of change in LineCap]
322
- - Page numbering - $mpdf->pagenumSuffix etc not suppressed in HTML headers/footers if number suppressed
323
- - Page numbering - Page number total {nbpg} incorrect - e.g. showing decreasing numbers through document, when ToC present
324
- - RTL numerals - incorrectly reversing a number followed by a comma
325
- - Transform to uppercase/lowercase not working for chars > ASCII 128 when using core fonts
326
- - TOCpagebreak - Not setting TOC-FOOTER
327
- - TOCpagebreak - toc-even-header-name etc. not working
328
- - Parsing some relative URLs incorrectly
329
- - Textcircle - when moved to next page by "page-break-inside: avoid"
330
- - Bookmarks will now work if jump more than one level e.g. 0,2,1 Inserts a new blank entry at level 1
331
- - Paths to img or stylesheets - incorrectly reading "//www.domain.com" i.e. when starting with two /
332
- - data:image as background url() - incorrectly adjusting path on server if MPDF_PATH not specified (included in release mPDF 5.6.1)
333
- - Image problem if spaces or commas in path using http:// URL (included in release mPDF 5.6.1)
334
- - Image URL parsing rewritten to handle both urlencoded URLs and not urlencoded (included in release mPDF 5.6.1)
335
- - <dottab> fixed to allow color, font-size and font-family to be correctly used, avoid dots being moved to new page, and to work in RTL
336
- - Table {colsum} summed figures in table header
337
- - list-style-type (custom) colour not working
338
- - <tocpagebreak> toc-preHTML and toc-postHTML can now contain quotes
339
-
340
-
341
-
342
- ===========================
343
- mPDF 5.6
344
- 20/01/2013
345
- ===========================
346
-
347
- Files changed
348
- -------------
349
- mpdf.php
350
- config.php
351
- includes/functions.php
352
- classes/meter.php
353
- classes/directw.php
354
-
355
-
356
- config.php changes
357
- ------------------
358
- $this->allowedCSStags - added HTML5 tags + textcircle AND
359
- $this->outerblocktags - added HTML5 tags
360
- $this->defaultCSS - added default CSS properties
361
-
362
-
363
- New features / Improvements
364
- ---------------------------
365
- CSS support added for for min-height, min-width, max-height and max-width in <img>
366
-
367
- Images embedded in CSS
368
- <img src="data:image/gif;base64,...."> improved to make it more robust, and
369
- background: url(data:image... now added to work
370
-
371
- HTML5 tags supported
372
- - as generic block elements: <article><aside><details><figure><figcaption><footer><header><hgroup><nav><section><summary>
373
- - as in-line elements: <mark><time><meter><progress>
374
- - <mark> has a default CSS set in config.php to yellow highlight
375
- - <meter> and <progress> support attributes as for HTML5
376
- - custom appearances for <meter> and <progress> can be made by editing classes/meter.php file
377
- - <meter> and <progress> suppress text inside the tags
378
-
379
- Textcircle/Circular
380
- font: "auto" added: automatically sizes text to fill semicircle (if both set) or full circle (if only one set)
381
- NB for this AND ALL CSS on <textcircle>: does not inherit CSS styles
382
- attribute: divider="[characters including HTML entities]" added
383
- <textcircle r="30mm" top-text="Text Circular Text Circular" bottom-text="Text Circular Text Circular"
384
- divider="&nbsp;&bull;&nbsp;" style="font-size: auto" />
385
-
386
- &raquo; &rsquo; &sbquo; &bdquo; are now included in "orphan"-management at the end of lines
387
-
388
- Improved CJK line wrapping (if CJK character at end of line, breaks there rather than previous wordspace)
389
-
390
- NB mPDF 5.5 added support for <fieldset> and <legend> (omitted from ChangeLog)
391
-
392
- Bug fixes
393
- ---------
394
- - embedded fonts: Panose string incorrectly output as decimals - changed to hexadecimal
395
- Only a problem in limited circumstances.
396
- *****Need to delete all ttfontdata/ files in order for fix to have effect.
397
- - <textCircle> background white even when set to none/transparent
398
- - border="0" causing mPDF to add border to table CELLS as well as table
399
- - iteration counter in THEAD crashed in some circumstances
400
- - CSS color now supports spaces in the rgb() format e.g. border: 1px solid rgb(170, 170, 170);
401
- - CJK not working in table following changes made in v5.4
402
- - images fixed to work with Google Chart API (now mPDF does not urldecode the query part of the src)
403
- - CSS <style> within HTML page crashed if CSS is too large (? > 32Kb)
404
- - SVG image nested int eht HTML failed to show if code too large (? > 32Kb)
405
- - cyrillic character p &#1088; at end of table cell caused cell height to be incorrectly calculated
406
-
407
-
408
- ===========================
409
- mPDF 5.5
410
- 02/03/2012
411
- ===========================
412
-
413
- Files changed
414
- -------------
415
- mpdf.php
416
- classes/ttfontsuni.php
417
- classes/svg.php
418
- classes/tocontents.php
419
- config.php
420
- config_fonts.php
421
- utils/font_collections.php
422
- utils/font_coverage.php
423
- utils/font_dump.php
424
-
425
- Files added
426
- -----------
427
- classes/ttfontsuni_analysis.php
428
-
429
- config.php changes
430
- ------------------
431
- To avoid just the border/background-color of the (empty) end of a block being moved on to next page (</div></div>)
432
- $this->margBuffer = 0; // Allow an (empty) end of block to extend beyond the bottom margin by this amount (mm)
433
-
434
- config_fonts.php changes
435
- ------------------------
436
- Added to (arabic) fonts to allow "use non-mapped Arabic Glyphs" e.g. for Pashto
437
- 'unAGlyphs' => true,
438
-
439
- Arabic text
440
- -----------
441
- Arabic text (RTL) rewritten with improved support for Pashto/Sindhi/Urdu/Kurdish
442
- Presentation forms added:
443
- U+0649, U+0681, U+0682, U+0685, U+069A-U+069E, U+06A0, U+06A2, U+06A3, U+06A5, U+06AB-U+06AE,
444
- U+06B0-U+06B4, U+06B5-U+06B9, U+06BB, U+06BC, U+06BE, U+06BF, U+06C0, U+06CD, U+06CE, U+06D1, U+06D3, U+0678
445
- Joining improved:
446
- U+0672, U+0675, U+0676, U+0677, U+0679-U+067D, U+067F, U+0680, U+0683, U+0684, U+0687, U+0687, U+0688-U+0692,
447
- U+0694, U+0695, U+0697, U+0699, U+068F, U+06A1, U+06A4, U+06A6, U+06A7, U+06A8, U+06AA, U+06BA, U+06C2-U+06CB, U+06CF
448
-
449
- Note -
450
- Some characters in Pashto/Sindhi/Urdu/Kurdish do not have Unicode values for the final/initial/medial forms of the characters.
451
- However, some fonts include these characters "un-mapped" to Unicode (including XB Zar and XB Riyaz, which are bundled with mPDF).
452
- 'unAGlyphs' => true,
453
- added to the config_fonts.php file for appropriate fonts will
454
-
455
- This requires the font file to include a Format 2.0 POST table which references the glyphs as e.g. uni067C.med or uni067C.medi:
456
- e.g. XB Riyaz, XB Zar, Arabic Typesetting (MS), Arial (MS)
457
- NB If you want to know if a font file is suitable, you can open a .ttf file in a text editor and search for "uni067C.med"
458
- - if it exists, it may work!
459
- Using "unAGlyphs" forces subsetting of fonts, and will not work with SIP/SMP fonts (using characters beyond the Unicode BMP Plane).
460
-
461
- mPDF maps these characters to part of the Private Use Area allocated by Unicode U+F500-F7FF. This could interfere with correct use
462
- if the font already utilises these codes (unlikely).
463
-
464
- mPDF now deletes U+200C,U+200D,U+200E,U+200F zero-widthjoiner/non-joiner, LTR and RTL marks so they will not appear
465
- even though some fonts contain glyphs for these characters.
466
-
467
-
468
- Other New features / Improvements
469
- ---------------------------------
470
- Avoid just the border/background-color of the (empty) end of a block being moved on to next page (</div></div>)
471
- using configurable variable: $this->margBuffer;
472
-
473
-
474
- The TTFontsUni class contained a long function (extractcoreinfo) which is not used routinely in mPDF
475
- This has been moved to a new file: classes/ttfontsuni_analysis.php
476
- The 3 utility scripts have been updated to use the new extended class:
477
- - utils/font_collections.php
478
- - utils/font_coverage.php
479
- - utils/font_dump.php
480
-
481
-
482
- Bug fixes
483
- ---------
484
- - Border & background when closing 2 blocks (e.g. </div></div>) incorrectly being moved to next page because incorrectly
485
- calculating how much space required
486
- - Fixed/Absolute-positioned elements not inheriting letter-spacing style
487
- - Rotated cell - error if text-rotate set on a table cell, but no text content in cell
488
- - SVG images, text-anchor not working
489
- - Nested table - not resetting cell style (font, color etc) after nested table, if text follows immediately
490
- - Nested table - font-size 70% set in extenal style sheet; if repeated nested tables, sets 70% of 70% etc etc
491
- - SVG setting font-size as percent on successive <text> elements gives progressively smaller text
492
- - mPDF will check if magic_quotes_runtime set ON even >= PHP 5.3 (will now cause an error message)
493
- - not resetting after 2 nested tags of same type e.g. <b><b>bold</b></b> still bold
494
- - When using charset_in other than utf-8, HTML Footers using tags e.g. <htmlpageheader> do not decode correctly
495
- - ToC if nested > 3 levels, line spacing reduces and starts to overlap
496
-
497
-
498
-
499
-
500
- ===========================
501
- mPDF 5.4
502
- 14/02/2012
503
- ===========================
504
- Files changed
505
- -------------
506
- mpdf.php
507
- config.php
508
- compress.php
509
- classes/ttfontsuni.php
510
- classes/barcode.php
511
- classes/indic.php
512
- classes/svg.php
513
- examples/show_code.php ----- SECURITY RISK**
514
- examples/example49_changelog.php
515
- examples/example57_new_mPDF_v5-3_active_forms_b (replace example57_new_mPDF_v5-3_active_forms)
516
- includes/out.php
517
- mpdfi/fpdi_pdf_parser.php
518
-
519
- Files added
520
- -----------
521
- classes/bmp.php
522
- classes/directw.php
523
- classes/form.php
524
- classes/grad.php
525
- classes/tocontents.php
526
- classes/wmf.php
527
- examples/example58_new_mPDF_v5-4_features
528
-
529
- config.php changes
530
- ------------------
531
- Edited: $this->allowedCSStags, $this->innerblocktags, $this->defaultCSS; (CAPTION added in each case)
532
- Moved: Numerous $form_.. variables are now in /classes/form.php
533
-
534
- New config variables
535
- --------------------
536
- $this->bookmarkStyles = array();
537
- $this->cacheTables = true;
538
-
539
- New methods
540
- -----------
541
- function CircularText()
542
- function SetVisibility()
543
-
544
- New/Extended CSS
545
- ----------------
546
- box-shadow (block elements - does NOT support "inset")
547
- text-shadow (all text elements - does NOT support "blur")
548
- visibility: visible|hidden|printonly|screenonly (block-level elements and images IMG only)
549
- text-transform: capitalize|uppercase|lowercase (extended to support TD/TH)
550
- tr|td|th:nth-child(odd|even|2n+1)
551
- color, strikethrough, underline and background-color (extended to support rotated TD/TH)
552
- underline and strike-through (extended to support TD/TH)
553
- underline (line colour) (extended to work correctly in watermark)
554
- page-break-after: left|right|always (block elements and tables)
555
- NB respects $mpdf->restoreBlockPagebreaks = true; i.e. will make pagebreak act like formfeed
556
- background[-color]: extended to support rgba|cmyka|cmyk|hsla|hsl|spot
557
- border(extended to support inline elements)
558
-
559
-
560
- New HTML
561
- --------
562
- <caption>
563
- <textcircle />
564
-
565
-
566
- New features / Improvements
567
- ---------------------------
568
- Tables - Zebra Stripes
569
- Tables: overlapping rowspans (partially) supported
570
- Tables - Disk caching
571
- Using progress bars (or $showStats) now reports 'real' memory usage i.e. get_memory_usage(true)
572
- Support for query string in the URLs for external stylesheets e.g. @import url("style.css?ltcyy7");
573
- Table caption partially supported
574
- CircularText
575
- BookMark styling
576
- Spread tables i.e. can split table (columns) across several pages width.
577
- Can use chelvetica, ctimes and ccourier to specify core fonts in a non-core font document
578
- Spread tables i.e. can split table (columns) across several pages width.
579
- {colsum} in <tfoot> cell will insert a column total per page.
580
- SVG embedded as island in HTML supported
581
- Active Forms
582
- textarea and input (text types) now accept javascript as:
583
- onKeystroke, onValidate, onCalculate and onFormat
584
- onChange is depracated but works as onCalculate (for textarea and input)
585
- (PS Select still accepts onChange cf. 5.3.37)
586
- Ledger and Tabloid added as page formats recognised. NB Ledger is same as tabloid but landscape. In mPDF, both give the same size (portrait)
587
- so need to add -L e.g. Ledger-L for landscape.
588
-
589
-
590
- Internal script changes
591
- -----------------------
592
- Changed this->k to _MPDFK throughout all scripts
593
- Changes to color (packed binary data in string rather than array) to reduce memory usage esp in tables
594
- Internal variables Removed
595
- $usetableheader;
596
- $tableheadernrows;
597
- $tablefooternrows;
598
- vars $ChangePage, $p_bottom_border, $img_margin_top(+) $issetcolor + other similar removed
599
-
600
- Removed a whole load of // comments
601
- Updates to remove some more Warning Notices (not all marked in text)
602
- Border set on TR - changed so set on each cell, rather than retrospectively at end of TR
603
- All references to table['text'] removed as not needed - uses ['textbuffer'] instead
604
- OpenTag(TD) changes to reduce memory usage with tables
605
- Includes different method to set a default timezone
606
- fn _smallCaps does not need (undefined) $space
607
- this->chrs and this->ords replaced by chr() and ord()
608
- Headers in out.php updated to match those used in Output()
609
- Change to SetFont() to improve performance time
610
- Change to GetStringWidth() to improve performance time
611
- Corrected copying of Glyphs 0,1,2, to all subset fonts (non-SMP/SIP), and only setting 32->127 in subset
612
- Subset fonts (non-SMP/SIP) have additionally Unicode CMap tables (0,0,4 and 0,3,4) as well as Microsoft (3,1,4)
613
- Subset fonts (SMP/SIP) have CMap tables (1,0,6 and 3,0,4) - rather than 1,0,6 and 3,0,6
614
- Subset fonts (SMP/SIP) have 'name' table changed to give 1,0 and 3,0. As it is a symbol font (not Unicode encoded) :
615
- needs to have a name entry in 3,0 (e.g. symbol) - original font will have 3,1 (i.e. Unicode)
616
- Automatically checks for HTML code length > 100000 characters and gives error warning if
617
- PHP < 5.2.0 (as not configurable) or increases pcre.backtrack_limit if PHP < 5.3.7
618
-
619
- Removed/Depracated
620
- ------------------
621
- function UseTableHeader($opt=true) fn removed / depracated
622
- function UsePRE($opt=true) removed
623
- $attr['REPEAT_HEADER'] == true CSS removed / depracated
624
- $this->usepre=true; removed / depracated as never needed - always respects PRE whitespace
625
-
626
- ToC: NB Values can no longer be set directly e.g. as in example
627
- $mpdf->TOCheader = array(); // array as for setting header/footer
628
- $mpdf->TOCfooter = array(); // array as for setting header/footer
629
- $mpdf->TOCpreHTML = '<h2>Contents - Portrait</h2>'; // HTML text to appear before table of contents
630
- $mpdf->TOCpostHTML = ''; // HTML text to appear after table of contents
631
- $mpdf->TOCbookmarkText = 'Content list'; // Text as it will appear in the Bookmarks (leave blank for none)
632
- Need to use TOCpagebreak either direct (or array version) or as HTML
633
- OR if absolutley necessary, could use:
634
- $mpdf->tocontents->TOCheader = array(); // array as for setting header/footer
635
- $mpdf->tocontents->TOCfooter = array(); // array as for setting header/footer
636
- $mpdf->tocontents->TOCpreHTML = '<h2>Contents - Portrait</h2>'; // HTML text to appear before table of contents
637
- $mpdf->tocontents->TOCpostHTML = ''; // HTML text to appear after table of contents
638
- $mpdf->tocontents->TOCbookmarkText = 'Content list'; // Text as it will appear in the Bookmarks (leave blank for none)
639
-
640
-
641
-
642
- Further Details
643
- ===============
644
-
645
- CSS border on inline elements
646
- -----------------------------
647
- Support for CSS border (and variants) on inline elements e.g. <span style="border-bottom: 1px dashed #000000;">
648
- Border styles solid|dotted|dashed|double only are supported. Border radius not supported.
649
- Nested inline elements will have repeat left|right borders on the nested content (unlike browsers)
650
-
651
- Tables - Zebra Stripes
652
- ----------------------
653
- TABLE - striped rows cf. http://dev.opera.com/articles/view/zebra-striping-tables-with-css3/
654
- tr:nth-child(odd) { background-color: #99ff99; }
655
- thead tr:nth-child(3n+2) { background-color: #FFBBFF; }
656
- td:nth-child(2n+1) { background-color: #BBBBFF; }
657
- table.zebraTable td:nth-child(2n+1) { background-color: #BBBBFF; }
658
- table.zebraTable th:nth-child(2n+1) { background-color: #BBBBFF; }
659
-
660
- NB mPDF does NOT correctly apply specificity to all CSS
661
- table.zebra tbody tr:nth-child(2n+1) td { background-color: #FFFFBB; }
662
- table.zebra tbody td:nth-child(odd) { background-color: #BBBBFF; }
663
-
664
- should make every odd row yellow, and every odd coloumn blue, but with the row/yellow overriding the column/blue.
665
- In mPDF the td:nth-child(odd) trumps the plain td, so the column colour wins out. You can force the effect you want by using
666
- table.zebra tbody tr:nth-child(2n+1) td:nth-child(1n+0) { background-color: #FFFFBB; }
667
-
668
- (The :nth-child(1n+0) selector just selects every td cell.)
669
-
670
-
671
-
672
- Tables - Disk caching
673
- ---------------------
674
- TABLES: using disk caching
675
- // Using disk to cache table data can reduce memory usage dramatically, but at a cost of increased
676
- // executon time and disk access (read and write)
677
- $this->cacheTables = true;
678
- NB $this->packTableData will be overridden to => true; // required for cacheTables
679
- $this->simpleTables will be overridden to => false; // Cannot co-exist with cacheTables
680
-
681
-
682
- Table caption
683
- -------------
684
- Must come immediately after <table...>
685
- CSS caption-side and HTML align attribute of top|bottom supported (not attribute left|right)
686
- Handled as a separate block element brought outside the table, so:
687
- CSS will not cascade correctly on the table
688
- width of caption block is that of page or of the block element containing the table
689
- so alignment will be to the page-width not the table width
690
- if table page-break-after: always, the caption will follow the pagebreak.
691
- This does work:
692
- <style>
693
- .tablecaption { caption-side: bottom; text-align: left; font-weight: bold; color: green; }
694
- </style>
695
- ...
696
- <table>
697
- <caption class="tablecaption">Caption title here</caption>
698
- <tbody>
699
-
700
- CSS visibility: printonly, screenonly
701
- -------------------------------------
702
- Roughly based on CSS
703
-
704
- Works on Block elements P, DIV etc, or Image
705
- Cannot nest / layer.
706
- Inner blocks/image with set visibility are ignored if already set on enclosing block element.
707
- (Block element) does not work inside table (image does)
708
- So 'visible' does nothing but is set as default
709
- (NB Changes output to PDF version 1.5)
710
- Incompatible with PDFA / PDFX
711
-
712
- 'visibility'
713
- Value: visible | hidden | (collapse | inherit)
714
- Initial: visible
715
- Applies to: all elements
716
- Inherited: yes
717
-
718
- The 'visibility' property specifies whether the boxes generated by an element are rendered.
719
- Invisible boxes still affect layout (set the 'display' property to 'none' to suppress box generation altogether).
720
- Values have the following meanings:
721
-
722
- visible
723
- The generated box is visible.
724
- hidden
725
- The generated box is invisible (fully transparent, nothing is drawn), but still affects layout.
726
- Furthermore, descendants of the element will be visible if they have 'visibility: visible'.
727
- collapse | inherit
728
- NOT supported in mPDF
729
-
730
- CUSTOM:
731
- printonly | screenonly
732
-
733
-
734
- Added VISIBILITY function
735
- $mpdf->SetVisibility('screenonly'); or 'printonly' 'visible' or 'hidden'
736
- (NB Changes output to PDF version 1.5)
737
- Incompatible with PDFA / PDFX
738
-
739
- CircularText
740
- ------------
741
- function CircularText($x, $y, $r, $text, $align='top', $kerning=120, $fontwidth=100) {
742
- x: abscissa of center
743
- y: ordinate of center
744
- r: radius of circle
745
- text: text to be printed
746
- align: text alignment: top or bottom. Default value: top
747
- kerning: spacing between letters in percentage. Default value: 120. Zero is not allowed.
748
- fontwidth: width of letters in percentage. Default value: 100. Zero is not allowed
749
-
750
- - now uses Kerning between letters if useKerning == true (set manually see example)
751
-
752
- BookMark styling
753
- ----------------
754
- New configurable variable to control appearance of Bookmarks e.g.
755
- $this->bookmarkStyles = array(
756
- 0 => array('color'=> array(0,64,128), 'style'=>'B'),
757
- 1 => array('color'=> array(128,0,0), 'style'=>''),
758
- 2 => array('color'=> array(0,128,0), 'style'=>'I'),
759
- );
760
-
761
- Column sums
762
- -----------
763
- (Also changed some preg_replace to str_replace to improve performance)
764
- To use: just add {colsum} to any cells of the table footer <tfoot>
765
- Add a number to specify a fixed number of decimal points e.g. <td>�{colsum2}</td> will give you �123.40
766
- The width of the column will be calculated using the actual string {colsum} as a placeholder.
767
- If you need the column to be wider, use underscores "_" to pad it e.g. {colsum2_____}
768
-
769
-
770
- Spread tables
771
- -------------
772
- i.e. can split table (columns) across several pages width.
773
- CSS <table style="overflow: visible">
774
- Cannot use with:
775
- $this->kwt - ignored
776
- $this->table_rotate - ignored
777
- $this->table_keep_together - ignored
778
- $this->ColActive - cancels spread tables
779
-
780
- Messes up with:
781
- $mpdf->forcePortraitHeaders = true;
782
- $mpdf->forcePortraitMargins = true;
783
- Problems with CJK, and RTL
784
-
785
- Will do no resizing of fonts at all.
786
- Maximum width of column = page width i.e. will not split columns across pages - NB will keep colspan>1 on one page
787
- If table row too high for page will die with error message.
788
- Will override some specs for width if this creates conflicts
789
- Recommended to specify absolute value of width on each column.
790
-
791
-
792
-
793
-
794
- Bug fixes
795
- =========
796
- Dottab - if text after dottab is hyperlinked <a></a> then dots are underlined
797
-
798
- page-break-before now respects $mpdf->restoreBlockPagebreaks = true; i.e. will make pagebreak act like formfeed
799
- Annotation() function called directly with colorarray(r,g,b)
800
-
801
- Added urldecode to _getImage to cope with ../name%20of%20image.jpg
802
- Added urldecode AND htmlspecials_decode to href in <a> link e.g. https://www.google.com/search?hl=en&amp;q=mpdf&amp;filename=name%20of%20file
803
- [barcode.php] Allow &nbsp; in C39 codes - will be changed to spaces
804
-
805
- <table> inside a <div position:fixed, left:300px;> not calculating table width correctly
806
- - leading to either upside down table or error width less than 1 character
807
-
808
- Depracated magic_quotes_runtime() in compress.php
809
-
810
- DIRECTW included twice in compress.php
811
- FORMS mark up for compress.php corrected
812
-
813
- double backslashes not preserved inside <pre> or <textarea>
814
-
815
- font-weight and font-style not recognised in <pageheader>
816
-
817
- Progress bars causing corrupt PDF file (out.php) changed fopen from "r" mode to "rb" (binary)
818
- Target around image - <a href="#internaltarget"><img ... /></a> - not working
819
-
820
- SmallCaps in <thead> error
821
-
822
- Fonts with "name" table in format 1 not recognised correctly
823
- Rotated table which does not fit on remaining page, forces a new page even if already at top of page
824
-
825
- Locale causing problems - all instances of sprintf() using %.3f changed to %.3F so not locale aware
826
-
827
- CSS border radius not implemented on fixed/absolute positioned block element
828
-
829
- Background color in rotated table extending way beyond bottom of table
830
-
831
- Nested table containing <thead> or <tfoot> was confused with <thead> or <tfoot> of parent table
832
-
833
- Correct handling of spaces, < or & in textarea
834
-
835
- <option> and <input ..> attributes value/title decoded with fn lesser_entity_decode instead of htmlspecialchars_decode to include &apos;
836
-
837
- line width not restored to correct value after "line-through" text in Cell()
838
-
839
- Kannada - incorrect positioning of Reph
840
-
841
- Forms - In <input> or <option> (select) not correctly handling HTML named entities e.g. &lt; in value or title
842
- Active forms - &nbsp; as Value or Title incorrectly showing as Euro - PDFDocEncoding fixed
843
-
844
- Unicode data in embedded fonts not encrypted when doc encrypted
845
-
846
- Nested block elements which are empty including innermost one, top margin of innermost block was ignored
847
-
848
- font-size: xx% inside a block was setting on block's parent font-size
849
-
850
- Active forms - radio buttons (removed name from Widget - leave on Radio group)
851
- causing problems accessing field for radio buttons
852
-
853
- When using simple tables and border-collapse, if table border set, but cell borders not set, should display table border (fixed)
854
- position:fixed block - if neither top nor bottom nor height specified, was positioned incorrectly (y)
855
- Leave - if top, bottom, margin-top, margiin-bottom and height are all left unspecified (or auto), will centre vertically
856
- on the page (specific to mPDF - not consistent with CSS2.1)
857
- But if any one of them are specified (including e.g. margin-top=0), follows CSS spec, so top is the current "static" position
858
-
859
- background-image-opacity=0 not working on BODY or BLOCK
860
-
861
- Lists - if LI continues after a nested List, would add as a new LI item (should continue as part of earlier LI item)
862
-
863
- fn WriteCell() converts to 'windows-1252' when required
864
- if multiple calls to mPDF used, cannot redefine function cmp()
865
- internal link targets <a name="xx" /> in ToC not moved when using: page-break-inside:avoid
866
- internal link targets <a name="xx" /> not moved when using: columns, page-break-inside:avoid, keep-with-table or table rotate
867
-
868
- Active Forms - onChange not working for SELECT (cf. 5.3.25) Example 57 only worked by chance as JS was carried over from Select to Text field
869
- Bug is fixed, but example file needed updating to onCalculate for the display field.
870
-
871
- Table cell: if height set as %, currently sets it as % of page-width; instead this now ignores it.
872
-
873
- Bengali letter Khanda Ta (U+09CE) character not recognised; was added in Unicode v4.1 and prior to this, (U+09A4 U+09CD U+200D)
874
- so mPDF converts to this string and seems to work.
875
-
876
- OCR characters wrong size in barcodes if using different ocr font - fixed
877
-
878
- ===========================
879
- mPDF v5.3 (21/07/2011)
880
- ===========================
881
-
882
- New Features
883
- ------------
884
- - Active forms (see on-line manual for details)
885
- - 128-bit encryption (optional) with additional user-permissions (see on-line manual)
886
-
887
- PLEASE READ - Change in Font management
888
- ---------------------------------------
889
- The font name imported from the font and included by mPDF in the PDF file was stripping any '-' in the name.
890
- This is the PostScript name which is utilised by some PostScript programmes.
891
- mPDF has been changed to leave the PostScript font name unchanged. In 99% cases no difference will be noted, but
892
- you MUST delete all the temporary font data files cached in the /ttfontdata/ folder for this to be effective.
893
-
894
-
895
- Minor changes
896
- -------------
897
- If @page CSS is used to select a first page with settings different from the default, mPDF did create a blank page
898
- then pagebreak to the new @page settings - this has been changed so it now will start with the new page settings.
899
-
900
- New function added: DeletePages($start_page, $end_page=-1) e.g. $mpdf->DeletePages(1);
901
- Can be used just before calling Output()
902
-
903
- compress.php utility extended to exclude active forms and images-svg
904
-
905
-
906
- Bug fixes
907
- ---------
908
- - list-style-type: (custom version, user-defined bullet) colour change not working if colour is set on the list item line
909
- - background-image: SVG or WMF images as background-images in tables/tr/cells not working
910
- - font-weight: bold font not always reset after inline <b>...</b> thus miscalculating width
911
- - forms (inactive) in 'c' core fonts using unicode characters 127-255 incorrect display in input text and button text
912
- - form elements (inactive) if in-line with mixed size fonts, error in vertical positioning of text related to box
913
- - ToC: wrapped lines in ToC not retaining formatting e.g. bold style
914
- - HTMLHeaders: using setAutoTopMargin="pad"; not correctly setting top margin for first page
915
- - output headers changed: Content-length not used if server uses output compression
916
- - embedded font subsets from fonts which contain non-BMP plane 0 characters (incl. e.g. dejavusanscondensed)
917
- - causing Adobe Reader to create a CJK encoded font subset internally when loading interactive Forms
918
- - Changed so unsets the flag in the subset font to show no non-BMP characters.
919
-
920
-
921
- Configurable variables added (see config.php file):
922
- --------------------------------------------------
923
- All for Active Forms:
924
- $this->useActiveForms
925
- $this->formExportType
926
- $this->formSubmitNoValueFields
927
- $this->formSelectDefaultOption
928
- $this->form_border_color
929
- $this->form_background_color
930
- $this->form_border_width
931
- $this->form_border_style
932
- $this->form_button_border_color
933
- $this->form_button_background_color
934
- $this->form_button_border_width
935
- $this->form_button_border_style
936
- $this->form_radio_color
937
- $this->form_radio_background_color
938
-
939
- PLUS: see additional values added to $this->allowedCSStags close to bottom of file - required for Active forms
940
-
941
-
942
- Updated files
943
- -------------
944
- mpdf.php
945
- config.php (NB as well as form stuff at top, 5.2.07 $this->allowedCSStags close to bottom of file)
946
- compress.php
947
- classes/ttfontsuni.php
948
- examples/example57...
949
- examples/formsubmit.php
950
-
951
-
952
-
953
- ===========================
954
- mPDF v5.2 (18/06/2011)
955
- ===========================
956
-
957
- New Features
958
- ------------------
959
- Improvements in font handling resulting in clearer display of fonts on screen, and improved compatibility with PostScript drivers
960
- (e.g. use with GSView/GhostScript, see below)
961
-
962
- CJK line-breaking implemented (roughly) according to rules. Configurable variables allow control of behaviour (except in tables).
963
-
964
- Viewer preferences: added options for initial 2 page display where you can specify whether
965
- 1st page is on left or right (cf. SetDisplayMode).
966
-
967
- Custom list-style-type for a list (ul,ol) or a list-item (li) in which you can determine the character and colour of the bullet:
968
- list-style-type: U+263Argb(255,0,0); - where U+263A is the Unicode HEX value of the character you want for the bullet
969
- - character MUST be included in the font used for that list item. rgb() bit is optional
970
-
971
-
972
- Bug fixes
973
- ---------
974
- - Fonts: embedding a BMP TTC font (e.g. Cambria) as a full font caused error
975
- - Table: If cell width set by CSS as %, and page-break-inside avoid requires a new page, was losing the sizing
976
- - Table: table borders CSS parsing error; if border-width, border-style, border-color set, not inherited correctly
977
- - Table: Table background image or gradient not working in HTMLHeader/Footer
978
- - Table: background color set on table (anywhere) will overwrite image/gradient
979
- - Table Background image/gradient: If left/right margin is set on table, gradient/image set on table is too wide
980
- - Table: rotated table - height (after first page does not correctly allow for thead i.e. too much)
981
- - Table: blank <tr></tr> causes error
982
- - Table/Letter-spacing: If letter-spacing set inside table, not calculating table width correctly, and if oversized, freezes
983
- - ToC: ToC at top of page (non-mirrored or already ODD) did not reset page_number if told
984
- - Character subsititutions: characters missed if first element in a $html code e.g. WriteHTML('Not in a tag &#10003;');
985
- - Kerning: kerning info: if reading font file for first time (or if not cached in ttfontdata/) did not register kerning info
986
- - Textarea: multiple new lines run into only one newline
987
- - QRCode - colors wrong because QRcode class only accepts RGB input (hardcoded now to always give black on white)
988
- - QRCode always producing "Your message here"
989
- - Columns: if transforming height of column, not always closing transform Q
990
- - CakePHP compatibility
991
- - compress.php - error due to markup comments in mpdf.php script file
992
-
993
- Backwards compatibility
994
- -----------------------
995
- Changes in mPDF 5.2 are backwards compatible with version 5.1
996
- Your document fonts may appear slightly different in the PDF viewer because of the changes to embedded font subsets (cf.)
997
- The new Indic fonts may result in a change in spacing (due to the different character width of the space character from the original font)
998
-
999
- PostScript e.g. GSView/GhostScript
1000
- ----------------------------------
1001
- A number of errors have been reported when opening mPDF-created PDF files with a PostScript programme. Some of the errors were due to mPDF,
1002
- but others were due to peculiarities of GSView/GhostScript.
1003
- - Diacritic Characters were not displayed when embedding a font subset
1004
- - Fonts containing SIP/SMP characters (supplementary Unicode planes) caused errors
1005
- - Error with text justification (word-spacing) when embedding a full font can occur in some fonts*
1006
- The first 2 problems should now be fixed in v5.2
1007
- *The error with text justification can be optionally fixed by setting the configurable variable in config.php:
1008
- $this->repackageTTF = true;
1009
- When mPDF embeds a full font, it simply embeds the whole original TTF file into the PDF document. For some fonts (containing
1010
- a GSUB table) this was causing problems. $this->repackageTTF forces mPDF to repackage the original TTF file excluding some of
1011
- the tables like GSUB.
1012
- (See ADDITIONAL INFO FONTS.txt in downloaded files)
1013
-
1014
-
1015
- Font appearance in PDF viewer
1016
- -----------------------------
1017
- Font subsetting has been improved to include additional information in the embedded file. Overall the effects are of greater clarity
1018
- when viewing the document on a screen (it will not affect print output), but the changes are dependent on:
1019
- - the original TTF font i.e. the options that the font's author has built into the file
1020
- - the PDF viewer i.e. whether the programme chooses to use the available information
1021
- - the resolution (zoom) of the page you are viewing
1022
- (See ADDITIONAL INFO FONTS.txt in downloaded files)
1023
-
1024
-
1025
- Indic fonts
1026
- -----------
1027
- A new set of Indic fonts (ind_xx_1_001) is distributed with version 5.2 containing the additional font information as described above.
1028
- In addition, some changes have been made to the ASCII characters in the font from the files previously distributed:
1029
- The original files (Raghu font files) do not contain the characters a-z and A-Z. When the first version indic files were created for mPDF,
1030
- ALL of the ASCII characters (32-127) were inserted/overwritten from DejaVuSansCondensed to make the font more usable.
1031
- In the latest version, only the missing characters are taken from DejaVuSansCondensed, leaving punctuation and numerals from the original
1032
- fonts. This also means that the space character has a different width, and this will cause slight changes to the word spacing in documents.
1033
- (See ADDITIONAL INFO FONTS.txt in downloaded files)
1034
-
1035
-
1036
- CJK line-breaking (text wrapping)
1037
- ---------------------------------
1038
- CJK (chinese-japanese-korean) text often contains no spaces. mPDF previously has wrapped text whenever a character reached the end of
1039
- the line. mPDF version 5.2 attempts to follow the line-breaking rules described for each of the languages. Configurable variables
1040
- allow some control over this behaviour, especially whether to squeeze a character into the space available at the end of a line, or
1041
- whether to allow it to overflow the right margin.
1042
-
1043
-
1044
- Configurable variables (see config.php file):
1045
- ----------------------
1046
- Control wrapping of CJK text:
1047
- $this->allowCJKorphans = true; // FALSE=always wrap to next line; TRUE=squeeze or overflow
1048
- $this->allowCJKoverflow = false; // FALSE=squeeze; TRUE=overflow (only selected)
1049
- When Embedding full TTF font files, remakes the font file using only core tables
1050
- May improve function with PostScript printers
1051
- $this->repackageTTF = false;
1052
-
1053
- Updated files
1054
- -------------
1055
- mpdf.php
1056
- compress.php
1057
- utils/font_dump.php
1058
- classes/ttfontsuni.php
1059
- config.php (3 new variables - see above)
1060
-
1061
- All ttfonts/ind_*
1062
- New set of Indic fonts for PostScript compatibilty - and clearer font display
1063
-
1064
-
1065
-
1066
- ===========================
1067
- mPDF v5.1 (27/02/2011)
1068
- ===========================
1069
-
1070
- New Features
1071
- ------------
1072
- - CSS background (images, colours or gradients) on <TR> and <TABLE>
1073
- - CSS border on <TR> (only in border-collapsed mode)
1074
- - support for Mozilla and CSS3 gradient syntax:
1075
- -moz-linear-gradient, linear-gradient
1076
- -moz-radial-gradient, radial-gradient
1077
- -moz-repeating-linear-gradient, linear-repeating-gradient
1078
- -moz-repeating-radial-gradient, radial-repeating-gradient
1079
- - expanded support for gradients (including in SVG images):
1080
- - multiple colour 'stops'
1081
- - opacity (transparency)
1082
- - angle and/or position can be specified
1083
- - gradient can be used as an image mask (custom mPDF styles: gradient-mask)
1084
- - image-orientation supported for <IMG> (similar to existing custom mPDF attribute: rotate) [CSS3]
1085
- - image-resolution supported for <IMG> [CSS3]
1086
- - background-image-resolution (custom mPDF CSS-type style) to define resolution of background images
1087
- - improved support for SVG images
1088
- - SVG and WMF images supported in background-image
1089
- - file attachments
1090
- - numeric list-styles added e.g. arabic-indic, bengali, devanagari, persian, thai [CSS3]
1091
- - font kerning supported (inter-character spacing between specific pairs)
1092
- - letter-spacing and word-spacing supported [CSS3]
1093
- - colors supported as rgb(), rgba(), hsl(), hsla(), cmyk(), cmyka(), or spot()
1094
- - spot colors supported e.g PANTONE 310 EC
1095
- - PDF/X compatible files
1096
- - optionally force use of grayscale, RGB or CMYK colorspace
1097
- - automatic colour conversion for most objects between grayscale, RGB and CMYK
1098
-
1099
- Backwards compatibility
1100
- -----------------------
1101
- Most changes in mPDF 5.1 are backwards compatible with version 5.0 i.e. your documents should
1102
- look the same running 5.1 However some changes may alter display from previous versions:
1103
- - RTL (right-to-left) languages - see below
1104
- - bleed margins when using @page CSS - see below
1105
- - Default distance for "cross" from inner margin changed 10->5mm [hardcoded in fn. Footer()]
1106
- - If height set on a block element, will force a new page if set-height will not fit on page
1107
- - If table rotated, 5mm margin at bottom is now reduced to 1mm
1108
- - If image is too big for page and automatically sixed to maximum height of page, 10mm margin at bottom reduced to 1mm
1109
-
1110
- Colours may appear more vibrant
1111
- -------------------------------
1112
- Unless specifically set, Adobe Reader uses the RGB colorSpace by default when displaying documents. However
1113
- if an image or gradient using transparency (or alpha channel) is included in the document, Adobe Reader
1114
- automatically sets the default colorSpace to CMYK - which makes the colours look less vibrant/bright on screen.
1115
- mPDF 5.1 now specifies by default a colorSpace RGB for each page, and this will maintain the more
1116
- vibrant colours. This is overridden if you use on of the options to restrict the colorSpace (cf.)
1117
-
1118
- RTL
1119
- ---
1120
- **** IMPORTANT - PLEASE READ IF USING RTL SCRIPTS ****
1121
- Handling of RTL (right-to-left) languages has been significantly rewritten, and is likely to cause
1122
- changes to the resulting files if you have previously been using mPDF. The changes have made mPDF
1123
- act more like a browser, respecting the HTML/CSS rules.
1124
- Changes include:
1125
- - the document now has a baseline direction; this determines the
1126
- - behaviour of blocks for which text-align has not been specifically set
1127
- - layout of mirrored page-margins, columns, ToC and Indexes, headers and footers
1128
- - base direction can be set by any of:
1129
- - $mpdf->SetDirectionality('rtl');
1130
- - <html dir="rtl" or style="direction: rtl;">
1131
- - <body dir="rtl" or style="direction: rtl;">
1132
- - base direction is an inherited CSS property, so will affect all content, unless...
1133
- - direction can be set for all HTML block elements e.g. <DIV><P><TABLE><UL> etc using
1134
- - CSS property < style="direction: rtl;">
1135
- - direction can only be set on the top-level element of nested lists
1136
- - direction can only be set on <TABLE>, NOT on THEAD, TBODY, TD etc.
1137
- - nested tables CAN have different directions
1138
- - NOTE that block/table margins/paddings are NOT reversed by direction
1139
- NB mPDF <5.1 reversed the margins/paddings for blocks when RTL set.
1140
- - language (either CSS "lang", using Autofont, or through initial set-up e.g. $mpdf = new mPDF('ar') )
1141
- no longer affects direction in any way.
1142
- NB config_cp.php has been changed as a result; any values of "dir" set here are now ineffective
1143
- - default text-align is now as per CSS spec: "a nameless value which is dependent on direction"
1144
- NB default text-align removed in default stylesheet in config.php
1145
- - once text-align is specified, it is respected and inherited
1146
- NB mPDF <5.1 reversed the text-align property for all blocks when RTL set.
1147
- - the configurable value $rtlcss is depracated, as it is no longer required
1148
- - improved algorithm for dtermining text direction
1149
- - english word blocks are handled in text reversal as one block i.e. dir="rtl"
1150
- [arabic text] this will not be reversed [arabic text]
1151
- - arabic numerals 0-9 handled correctly
1152
-
1153
- Although the control of direction for block elements is now more configurable, the control of
1154
- text direction (RTL arabic characters) remains fully automatic and unconfigurable.
1155
- <BDO> etc has no effect. Enclosing text in silent tags can sometimes help e.g.
1156
- content<span>[arabic text]</span>content
1157
-
1158
- Justified text
1159
- --------------
1160
- Text-align: justify - no longer uses configurable variable $jSpacing= C | W | ''
1161
- The default value is for mixed letter- and word-spacing, set by jSWord and jSmaxChar
1162
- If a line contains a cursive script (RTL or Indic [devanagari, punjabi, bengali]) then it prevents letter-spacing
1163
- for justification on that line - effectively the same as setting letter-spacing:0
1164
- Spacing values have been removed from the config_cp.php configuration file, so the "lang" property
1165
- (in config_cp) no longer determines justification behaviour (this includes the use of Autofont()).
1166
- When using RTL or Indic [devanagari, punjabi, bengali] scripts, you should set CSS letter-spacing:0
1167
- whenever you use text-align:justify.
1168
-
1169
-
1170
- @page media
1171
- -----------
1172
- When using @page to create a print publication with page-size less than sheet-size
1173
- - bleed margin is now configurable (also crop- and cross-mark margins)
1174
- - backgrounds/gradients/images now use the bleed box as their "container box"
1175
- - odd-header-name: supports the value "_default" - allows current non-HTML header to remain unchanged
1176
- - marks: crop cross; i.e. both together supported
1177
- - background-image-opacity and background-image-resize now work with @page CSS
1178
-
1179
-
1180
- SVG images - extended support
1181
- -----------------------------
1182
- - support for spreadMethod property for gradients (repeat and reflect)
1183
- - support for style="font-family; font-size; font-style; font-weight" i.e. inline CSS
1184
- - when viewPort="" and width="" height="" all specified, uses width to set SVG size of a "pixel"
1185
- - support for opacity and multiple "stops" (and colorspace) in gradients
1186
-
1187
-
1188
-
1189
- Minor Enhancements
1190
- ------------------
1191
- - support for colors as rgb(87%, 56%, 25%) [used especially in SVG]
1192
- - added option of "NoPrintScaling" in SetDisplayPreferences
1193
- - compress.php - now combines BACKGROUND-IMAGES and GRADIENTS as BACKGROUNDS, and added PROGRESS-BAR
1194
- - table with THEAD row will force a new page if no room for the THEAD AND a row from TBODY
1195
- - Small-Caps now works properly together with text-align justify
1196
- - embedded font subsets restructured (minor) for greater compatibility e.g. with Postscript printers
1197
- - PDF/A will convert everything except grayscale to RGB (by default) or CMYK (optionally)
1198
-
1199
-
1200
-
1201
-
1202
- Bug fixes
1203
- ---------
1204
- - Display changed to CMYK colour gamut when document contained an object with transparency set.
1205
- Now will retain RGB colorspace (brighter colours)
1206
- - If using dir="rtl", tables containing nested tables were not properly reversed
1207
- - "text-rotate: 0" set in CSS stylesheet did not 'undo' any text-rotate set on the row (TR)
1208
- - Malayalam - character re-ordering
1209
- - If height set on a block element, was not taking account of padding top/bottom
1210
- - embedded font subsets: error in array of Font Widths fixed
1211
- - <style>..</style> containing /* import url() */ the comments were not ignored
1212
- - If call mPDF class more than once, error using multiple barcodes or gif files because classes not reinstantiated
1213
- - Floating blocks were collapsing bottom/top margins - incorrectly
1214
- - Table: if colspan>1 contents are wider than the width of the included columns, did not increase column width(s) to accommodate
1215
- - Resizing table - script hanging and new page forced when not required (still)
1216
- - If a table style="page-break-inside:avoid" not fit on the page, was adding new page before resizing EVEN IF on a blank page
1217
- - End of 2 blocks (e.g. </div></div>) at very bottom of page, forcing unwanted pagebreak
1218
- - Corrected handling of tags inside <pre>
1219
- - RTL left-aligned text - line ending with <br /> not correctly left-aligned
1220
- - <input type=submit|reset etc name="xxx" e.g. Google button showed as I&039;m feeling lucky
1221
- - Annotations all linked to Page 1 (parent object)
1222
- - Error "division by zero" using columns
1223
- - MultiCell() and Write() [direct writing functions] - miscalculating length of line in non-core fonts (+ other bugs)
1224
- - error if CJK space at end or beginning of line with 0x20 spaces in as well
1225
-
1226
- Configurable variables (see config.php file):
1227
- ----------------------
1228
- $this->printers_info
1229
- $this->bleedMargin
1230
- $this->crossMarkMargin
1231
- $this->cropMarkMargin
1232
- $this->cropMarkLength
1233
- $this->nonPrintMargin
1234
- $this->restrictColorSpace
1235
- $this->PDFX
1236
- $this->PDFXauto;
1237
- $this->useKerning
1238
- [$this->rtlcss removed]
1239
-
1240
- Updated files
1241
- -------------
1242
- mpdf.php
1243
- config.php
1244
- config_cp.php (removed references to dir - but not essential to update - just redundant information)
1245
- compress.php
1246
- includes/out.php
1247
- includes/functions.php
1248
- classes/svg.php
1249
- classes/ttfontsuni.php
1250
- classes/indic.php
1251
- /font/helvetica*.php and /times*.php
1252
-
1253
- Added CSS support
1254
- =================
1255
- All Block elements including <BODY> <TABLE> <TR>
1256
- ------------------------------------------------
1257
- background-image-resolution: normal | [ from-image || <dpi> ]
1258
- direction: [ rtl | ltr ] (HTML attribute dir also supported)
1259
- background: [ gradients ]
1260
- background-image: [gradients ]
1261
-
1262
- For [ gradients ] syntax see:
1263
- - Mozilla linear - https://developer.mozilla.org/en/CSS/-moz-linear-gradient
1264
- - Mozilla radial - https://developer.mozilla.org/en/CSS/-moz-radial-gradient
1265
- - Mozilla gradients use - https://developer.mozilla.org/en/Using_gradients
1266
- - CSS3 linear gradients - http://dev.w3.org/csswg/css3-images/#linear-gradients
1267
- - CSS3 radial gradients - http://dev.w3.org/csswg/css3-images/#radial-gradients
1268
-
1269
-
1270
- Almost all elements - block and in-line
1271
- ---------------------------------------
1272
- font-kerning: auto | normal | none // need to set $mpdf->useKerning = true;
1273
- letter-spacing: normal | <length>
1274
- word-spacing: normal | <length>
1275
-
1276
- Colours
1277
- -------
1278
- Anywhere that color is specified (e.g. color, background-color, borders)
1279
- - rgb(255,255,255)
1280
- - rgba(255,255,255,1) // last value is transparency (alpha) - between 0-1
1281
- - rgb(100%,100%,100%)
1282
- - hsl(360,100%,100%) // H: 0-360; S/L: 0-100%; a:0-1
1283
- - hsla(360,100%,100%,1)
1284
- - cmyk(100,100,100,100) // or 0-100%
1285
- - spot(COLOR NAME, 100%) // e.g PANTONE 310 EC; use AddSpotColor() to define first
1286
-
1287
- <TR>
1288
- border:
1289
-
1290
- <TABLE> <TR>
1291
- background:
1292
- background-color:
1293
- background-image:
1294
-
1295
- <IMG>
1296
- gradient-mask: [can use any of the gradient syntax]
1297
- image-orientation: <angle> - supports deg, rad or grad
1298
- image-resolution: normal | [ from-image || <dpi> ]
1299
-
1300
- <OL|UL>
1301
- list-style: arabic-indic | bengali | devanagari | gujarati | gurmukhi | kannada | malayalam | oriya |
1302
- persian | telugu | thai | urdu | tamil
1303
-
1304
-
1305
- @page
1306
- marks: [ crop || cross ] - i.e. crop and cross can be used together
1307
- odd-header-name: "_default" - allows current non-HTML header to remain unchanged
1308
- background-image-opacity: [ 0-1 ]
1309
- background-image-resize: [ 1-6 ] - see Manual
1310
-
1311
-
1312
- ===========================
1313
- mPDF v5.0 (30/09/2010)
1314
- ===========================
1315
-
1316
- New Features
1317
- ------------
1318
- - Font handling simplified, reads TrueType font files directly
1319
-
1320
-
1321
- Minor Enhancements
1322
- ------------------
1323
- - rotation of fixed-position block elements (see example 10 and manual for supported CSS)
1324
- - support for CSS Small-Caps font-variant added
1325
- - utility scripts in /utils/ folder to help font management
1326
- - new simplified functions AddPageByArray() and TOCPageBreakByArray() added
1327
- - progress bar simplified and customisable
1328
- - improved word-wrapping for CJK langauges
1329
- - improved recognition of CJK/Indic/Arabic characters
1330
- - invalid UTF-8 input now outputs a meaningful error by displaying input html with errors marked
1331
- - GIF or PNG images with transparency/interlaced/non-standard compression handled as internal data
1332
- if /tmp/ folder is not present or writeable
1333
- - support for <html dir="rtl">
1334
- - support for "display: none" on inline elements
1335
- - annotations supported in fixed-position block elements
1336
-
1337
-
1338
- Bug fixes
1339
- ---------
1340
- - <br /> preceded by space does not correctly text-align to right
1341
- - zero-width character in middle of line caused line-break (e.g. diacritic or U+200C = ZWNJ)
1342
- - HTML attributes not recognised if spaces e.g. 'src = "..."'
1343
- - Headers changed for output - problem reported on IE8 64-bit using SSL
1344
- - using SetAutoPageBreak(false) used caused unexpected behaviour with table rows at page break
1345
- - (from Beta) incorrect check for temporary font data folder causing errors
1346
- - artificial Bold/Italic not working in table cell when using rotated text
1347
- - allow <dottab> to inherit font color correctly
1348
- - SVG now works with Adobe 7
1349
- - background in header overwriting text
1350
- - vertical text in table header not correctly horizontally positioned when repeated
1351
- - compatibility with PHP >= 4.3 (htmlspecialchars_decode, stripos)
1352
- - updated depracated script PHP 5.3.0 ($string{1} to $string[1], $var =& new Object(), set_magic_quotes_runtime)
1353
- - index (CreateIndex) number string incorrect if arabic(rtl) text anywhere in document
1354
- - MultiCell incorrectly calculate string length/width when using core fonts
1355
- - page-break-inside:avoid - used with non-HTML footer had space inserted for footer height
1356
- - page-break-inside:avoid - error if more than 1 page height but not enough to trigger second pagebreak
1357
- - page-break-inside:avoid - incorrectly layering page backgrounds (headers and content brought forward)
1358
-
1359
-
1360
- Changes from 5.0 Beta
1361
- ---------------------
1362
- If you are upgrading from the Beta version - you MUST delete all files in the /ttfontdata/ temporary directory
1363
- - config.php file has been changed (extra CJK characters to recognise CJK blocks)
1364
- - $this->backupSubsFont (in config_fonts.php) optionally now takes an array
1365
- - no need to define 'cjk'=>true or 'sip|smp'=>true in config_fonts.php (ignored; cf. $this->BMPonly)
1366
- - Indic language fonts have been altered to add Latin and Latin-1 Supplement characters
1367
- - progress bars now has an external progbar.css and configurable main heading
1368
- - added initial parameter new mPDF('+aCJK') or '-aCJK' to override default useAdobeCJK at runtime
1369
- - QRCode is not included in main download (but as an extra package)
1370
-
1371
- BACKWARD COMPATIBILITY
1372
- ----------------------
1373
- If you have been using earlier versions of mPDF, most scripts should work as before. But note:
1374
- - Arial, Helvetica, Times and Courier are now treated like any other font
1375
- - the whole CSS font string is parsed e.g. style="font-family:'Lucida Grande';" will look for a font 'lucidagrande'
1376
- and not 'lucida'
1377
-
1378
- Configurable variables (see config.php file):
1379
- ----------------------
1380
- - $mpdf->useSubstitutionsMB is now depracated, but will work as an alias for $mpdf->useSubstitutions
1381
- The initial parameters e.g. new mPDF('utf-8') have all changed. Old ones may be recognised, or will be ignored.
1382
- - $mpdf->useOnlyCoreFonts is now depracated and is ignored. Use new mPDF('c')
1383
- - $this->use_CJK_only is now depracated and is ignored. See $this->useAdobeCJK and new mPDF('+aCJK') or '-aCJK'
1384
- Control SmallCaps appearance
1385
- - $mpdf->smCapsScale = 0.75; // Factor of 1 to scale capital letters
1386
- - $mpdf->smCapsStretch = 115; // % to stretch small caps horizontally
1387
- Customisable Progress bar
1388
- - $mpdf->progbar_heading = 'mPDF file progress';
1389
- - $mpdf->progbar_altHTML = '';
1390
- Control fonts/subsetting
1391
- - $mpdf->maxTTFFilesize = 2000;
1392
- - $mpdf->percentSubset = 30;
1393
- - $mpdf->debugfonts // show font errors and warnings
1394
- Replaceable alias
1395
- - $mpdf->iterationCounter = false; // Allow use of {iteration varname} in THEAD
1396
-
1397
-
1398
- ===========================
1399
- mPDF v5.0Beta (21/07/2010)
1400
- ===========================
1401
-
1402
- New features
1403
- ------------
1404
- The main change in mPDF v5 is the handling of TTF and TTC fonts directly.
1405
- See README.txt and FONT INFO.txt for more information
1406
-
1407
-
1408
- QR-code (2-dimensional barcode) Added
1409
- -------------------------------------
1410
- type="QR"
1411
- Size=1 is an arbitrary 25mm widthxheight. error="L|M|H|Q"
1412
- text="" can be numeric, alphanumeric or binary(?)
1413
- Required whitespace is always included around it
1414
-
1415
-
1416
- Enhancements
1417
- ------------
1418
- - progress-bar is simplified (no javascript class)
1419
- - dir="rtl" supported in <html> or <body> tag
1420
-
1421
- Bug fixes
1422
- ---------
1423
- - artificial Bold/Italic now working in table cells with rotated text
1424
- - "-" is now allowed in a font name e.g. sun-exta
1425
- - <dottab> now inherits font color correctly
1426
- - SVG class bugs fixed (was crashing in Adobe Reader v 7)
1427
- - background color/image in header no longer overwrites the header text
1428
-
1429
- Changed Config variables
1430
- ------------------------
1431
- $this->useSubstitutionsMB is depracated
1432
- Character substitution always occurs when using core fonts.
1433
- Use $this->useSubstitutions for all cases.
1434
-
1435
-
1436
- New Configurable variables
1437
- --------------------------
1438
- $this->useAdobeCJK = true; // Uses Adobe CJK fonts for CJK languages
1439
- // default TRUE; only set false if you have defined some available fonts that support CJK
1440
- // If true this will not stop other CJK fonts if specified by font-family:
1441
- // and vice versa i.e. only dictates behaviour when specified by lang="" incl. AutoFont()
1442
-
1443
- // Set maximum size of TTF font file to allow non-subsets - in kB
1444
- // Used to avoid e.g. Arial Unicode MS (perhaps used for substituteCharsMB) to ever be fully embedded
1445
- // NB Free serif is 1.5MB, most files are <= 600kB (most 200-400KB)
1446
- $this->maxTTFFilesize = 2000;
1447
-
1448
- // If not -s (i.e. forced subset) this value determines whether to subset or not
1449
- // 0 - 100 = percent characters
1450
- // i.e. if ==40, mPDF will embed whole font if >40% characters in that font
1451
- // or embed subset if <40% characters
1452
- // 0 will force whole file to be embedded
1453
- // 100 will force always to subset
1454
- $this->percentSubset = 30;
1455
-
1456
- $this->debugfonts - show errors and warnings for font parsing
1457
-
1458
- Config variables removed
1459
- ------------------------
1460
- $this->use_CJK_only
1461
- $this->useOnlyCoreFonts
1462
-
1463
- ================================================================================
1464
-
1465
- ====
1466
- 4.6
1467
- ====
1468
-
1469
- mPDF
1470
-
1471
- files changed:
1472
- mpdf.php
1473
- config.php
1474
- makefonts/makefonts.php
1475
- class/t1asm.php
1476
- class/svg.php
1477
- graph.php
1478
-
1479
- examples_04 (images)
1480
-
1481
- config var added:
1482
- $this->tableMinSizePriority
1483
-
1484
- 4.5.015
1485
- Bug fix:
1486
- Complex page with ToC entries ++ (example_ToC_bug4_5_015.php) caused Apache to crash
1487
- AdjustHTML() preg_pattern for matching <hx>... </hx> <table for keep-together - altered and fixed ? matching
1488
- Seemed to crash when content="Graph 12" between the <h> - 2 numbers (12) crash, 1 didn't!!!
1489
-
1490
-
1491
- 4.5.014
1492
- Bug fix:
1493
- Using TrueType fonts, unused font is not embedded in the PDF doc. This was fine except an error message appeared after printing in Adobe Reader,
1494
- because Font reference /F1 still present in doc pointing to non-existent resource.
1495
- Edited so that the reference is now removed from the page if font unused.
1496
-
1497
-
1498
- 4.5.013
1499
- Enhancement
1500
- TrueTypeUnicode fonts width array inserted as shortened form array (smaller file size)
1501
-
1502
- 4.5.012
1503
- Bug fix: Incorrect handling orphan characters in table
1504
- (cf. http://mpdf.bpm1.com/forum/comments.php?DiscussionID=193 fixed in 4.2 - but going back to it still problems)
1505
- If xxxxx. fits but xxxxx.. doesn't: WriteFlowingBlock wraps it to next line, TableWordWrap sqeezed it onto one line
1506
- TableWordWrap fixed to only allow one orphan char. even if it fits with that one.
1507
-
1508
-
1509
- 4.5.011
1510
- Added Windows BMP image support
1511
-
1512
- 4.5.010
1513
- SVG class:
1514
- - improved recognition of lineargradients/radialgradients referenced by xlink:href
1515
- - does not die if empty text string
1516
- - support for many text properties as style="" as well as currently as attributes (bold, fill etc)
1517
- - if using MB font, was respecting "Times" and "Courier" from the SVG file but using as ANSI not utf-8
1518
-
1519
- 4.5.009
1520
- graph.php updated to include SVG - need to define in graph.php (as well as set up TTF fonts)
1521
- (SVG graph does not include CSIM, 3D skew.)
1522
-
1523
- 4.5.008
1524
- t1asm.php has an error in the error message if .dat fontfile not found (".char.dat")
1525
-
1526
- 4.5.007
1527
- Bug fix: Using page-break-inside:avoid, if nothing would have been printed on page 1 before next page, elements going all over the place!
1528
- Also problem shifting images - fixed
1529
- Also wasn't shifting WMF/SVG images - fixed
1530
-
1531
- 4.5.006
1532
- New config var
1533
- $this->tableMinSizePriority = false;
1534
- If page-break-inside:avoid but cannot fit on full page without
1535
- exceeding autosize; setting this value to true will force respsect for
1536
- autosize, and disable the page-break-inside:avoid
1537
- [NB edit Manual Table>>autolayout algorithm]
1538
-
1539
-
1540
- 4.5.005
1541
- Bug fix
1542
- Table set to avoid page-break-inside: in some circumstances entered loop with recalculating size
1543
- Fudge factor added of 0.001 in tbsqrt to calculate shrink factor
1544
-
1545
- 4.5.004
1546
- Bug fix
1547
- If table set to avoid page-break-inside and table height (resized) exactly==remaining page - was triggering page break
1548
- Fudge factor added of 0.001 in tablewrite to query pagebreak
1549
-
1550
- 4.5.003
1551
- Bug fix in makefonts/makefonts.php
1552
- Also changed the links in Step4 & 8 which move the newly created files to the font directory - will now show error message if error -
1553
- will NOT overwrite existing files. (Put in manual already)
1554
-
1555
- 4.5.002
1556
- Bug fix in class/t1asm.php
1557
- If you have magic_quotes_runtime set On - problems using embedded subset.
1558
-
1559
- 4.5.001
1560
- JPG "Exif" file recognised from header, and handled much more quickly and efficiently (not using GD)
1561
-
1562
-
1563
-
1564
- ===========================
1565
- mPDF v4.5 (21/04/2010)
1566
- ===========================
1567
-
1568
- New Features
1569
- ------------
1570
- The main change in 4.5 is the improved class for importing SVG images. (See details below)
1571
-
1572
- Font files
1573
- ----------
1574
- Some bugs in the "makefonts" utility caused some errors in the files produced for embedding font subsets.
1575
- Surprisingly these are not easily detectable (I have yet to find one!).
1576
- All the font files used for embedding font subsets (the .dat and .dat.php files in /unifont/ folder)
1577
- have been re-generated. Download them if you are having problems with any fonts - otherwise, you probably
1578
- don't need to bother.
1579
-
1580
- Minor Enhancements
1581
- ------------------
1582
- If keepColumns = true (i.e. disable readjustment of column length), mPDF will now reproduce
1583
- table header/footer rows in each column [4.4.015]
1584
-
1585
- A number of changes to improve processing time [4.4.012]
1586
- [Thanks to carlholmberg http://mpdf.bpm1.com/forum/comments.php?DiscussionID=274&page=1#Item_3]
1587
-
1588
- JPG files with header marked as "progressive DCT-based JPEG" are now supported [4.4.004]
1589
-
1590
- Configurable variable (config.php) $dpi can be set to vary size interpreted from "px" values in HTML/CSS
1591
- NB Recommended that $dpi should always be set the same as $img_dpi
1592
-
1593
- Support added for "ex" as a size value (approximates "ex" as half of font height)
1594
-
1595
- Configurable variable (config.php) $watermarkImgAlphaBlend will determine how watermark images
1596
- will blend with underlying objects.
1597
-
1598
-
1599
- Bug fixes
1600
- ---------
1601
- - Make-fonts utility : makefonts/makefonts.php [4.4.016]
1602
- (All font files have been updated)
1603
- - Table header of only one column width - not printing right border [4.4.014]
1604
- - WMF and SVG images not rotating correctly to 90 or -90 degrees [4.4.013]
1605
- - Using templates, error if imported doc contains templates itself [4.4.001]
1606
-
1607
-
1608
- Updated Files
1609
- -------------
1610
- mpdf.php
1611
- config.php
1612
- classes/svg.php
1613
- makefonts/makefonts.php
1614
- ALL subset font files (/unifont/ .dat and .dat.php files), and all garuda and norasi files
1615
-
1616
- New files
1617
- ---------
1618
- None
1619
-
1620
- New config variables
1621
- --------------------
1622
- $this->watermarkImgAlphaBlend
1623
- $this->dpi
1624
-
1625
- BACKWARD COMPATIBILITY
1626
- ----------------------
1627
- All but one changes in mPDF 4.5 are fully backwards compatible.
1628
- The configurable variable $this->watermarkImgBehind was introduced in v4.4 and was unintentionally set to TRUE
1629
- In v4.5 this is set to FALSE in the config.php file.
1630
-
1631
-
1632
- SVG Images
1633
- ----------
1634
- [svg.php CHANGED]
1635
- - Text stroke-width default changed to 1 [4.4.011]
1636
- - Text stroke - line-join type changed [4.4.010]
1637
- - Default value for fill changed to "black" [4.4.008]
1638
- - Bug fixes:
1639
- * to correct calculation of text-length (and therefore alignment R and C) [4.4.009]
1640
- * Corrected errors in path implementation esp. quadratic Bezier curves
1641
- * rounded corners to rectangles - error corrected
1642
- * Recognition of font-family improved
1643
- * remove \n (and other non-printable chars) from text
1644
- * zero length shapes are not output e.g. zero-width rectangle, zero-length line, zero-radius circle
1645
- - Support added for:
1646
- * gradient stop offsets and gradientUnits="userSpaceOnUse" [4.4.007]
1647
- In mpdf.php enabled define inner radius for radial gradients - only used internally by SVG at present
1648
- * user defined <ENTITY /> cf. 'render-elems-03-t.svg' in SVG Test Suite [4.4.006]
1649
- * "color" attribute and "currentColor" value for fill and stroke [4.4.005]
1650
- * fill:url(#...) in a style as well as attribute
1651
- * xlink:href for gradients
1652
- * 1.3002e-005 in svg path
1653
- * text-style changes (e.g. text-anchor) set on <g> element - not just on <text>
1654
- * fill-rule=evenodd|nozero
1655
- * dashed lines / stroke-dasharray & stroke-dashoffset
1656
- * gradientUnits=userSpaceOnUse;
1657
- * units e.g. 3mm or 14pt in Rectangle, Circle, Ellipse, Line and Text position
1658
- * transform on <text> element
1659
- * stroke as well as fill on text
1660
-
1661
- NB The following are still NOT supported for SVG
1662
- - filters
1663
- - <marker>
1664
- - images
1665
- - DOM
1666
- - <pattern>
1667
- - textlength; lengthadjust; tspan, tref, toap, textPath;
1668
- - <use ../>
1669
- - gradient on stroke/text;
1670
- - <clipPath>
1671
- - text-underline and strikethrough
1672
- - text opacity
1673
- - colors as rgb(87%, 56%, 25%)
1674
- - rect using units for dimensions
1675
- - Only uses default spreadMethod = "pad" for gradients
1676
-
1677
-
1678
-
1679
-
1680
-
1681
- ===========================
1682
- mPDF v4.4 (24/03/2010)
1683
- ===========================
1684
-
1685
- New Features
1686
- ------------
1687
- - Support SVG image files (partial)
1688
- - Rotate images or graphs (by multiples of 90 degrees)
1689
- - Set opacity (transparency) for background images
1690
- - Control resizing of background images
1691
- - Set whether to print watermark images behind or in front of page contents
1692
- - Reduced memory usage when printing tables (partly configurable)
1693
- - Option to set path to folder for temporary files
1694
- - Improved compliance for CSS text-align justify
1695
- - Increased support for CSS "media"
1696
- - Improved performance when accessing local image files
1697
-
1698
-
1699
- Minor Enhancements
1700
- ------------------
1701
- - Allows space in output file name e.g. $mpdf->Output('t est.pdf','D'); [4.3.007B]
1702
- - Header changed in Output to improve compatability with IE6 (affects 'D' and 'I') [4.3.012B]
1703
- - background-images do not show noimage.jpg if missing [4.3.012D]
1704
- - simpleTables (which improves performance) now also allows: background-color, -gradient and -image, padding
1705
- and rotated text to be set for each cell. Only borders are not supported cell-by-cell. [4.3.006]
1706
-
1707
-
1708
- Bug fixes
1709
- ---------
1710
- - Page width not correctly reset when defining default page margins (L/R) by @page [4.3.007C]
1711
- - Table row <TR> with a background-color, paints the whole row, including the spaces between cells [4.3.005]
1712
- NB This should have been fixed in [4.2.028] but got left out!
1713
- - UseSubstitutionsMB causes errors inside <textarea> and <select> so now disabled in these 2 situations [4.3.004]
1714
- - CSS background: 'none' did not cancel background-image/background-color if it comes later [4.3.002, 4.3.011]
1715
- - Warning message 'depracated' (as of PHP 5.3) when using Templates [4.3.007]
1716
- - AutoFont incorrectly altering multibyte characters ending in \xa0 [4.3.012C]
1717
- - "Initial" default value for border-width changed from 1px to 'medium' e.g. border-top: solid #000000; [4.3.010]
1718
- - WMF image sometimes inverted [4.3.016]
1719
-
1720
- Updated Files
1721
- -------------
1722
- mpdf.php
1723
- config.php
1724
- changelog.txt
1725
-
1726
-
1727
- New files
1728
- ---------
1729
- classes/svg.php
1730
-
1731
-
1732
- New config variables
1733
- --------------------
1734
- $this->justifyB4br=false;
1735
- $this->CSSselectMedia='print';
1736
- $this->watermarkImgBehind = false;
1737
-
1738
- BACKWARD COMPATIBILITY
1739
- ----------------------
1740
- All changes are backwards compatible except the handling of some background-images - please see notes below.
1741
-
1742
-
1743
- Watermark Image z-order
1744
- -----------------------
1745
- By default mPDF prints watermarks on top of the page contents to ensure that they are not hidden by backgrounds
1746
- (especially table cells).
1747
- You can specify watermark images to be printed behind page contents by setting a configurable variable:
1748
- $this->watermarkImgBehind = true; // default=false
1749
- [4.3.018]
1750
-
1751
-
1752
- Rotating Images and Graphs
1753
- --------------------------
1754
- Images or graphs can be rotated (by multiples of 90 degrees) using a custom HTML attribute e.g.
1755
- <img rotate="90|-90|180" ... />
1756
- <jpgraph rotate="90" ... />
1757
- Valid options are: 90|-90|180.
1758
- Positive values are clockwise.
1759
- If width is specified e.g. width="3cm" this is applied to the rotated image i.e. will be width 3cm after rotating
1760
- [4.3.016]
1761
-
1762
-
1763
- Background Image Opacity
1764
- ------------------------
1765
- A custom CSS property "background-image-opacity": is now supported on BODY, DIV+ (block elements) and TD
1766
- Takes values between 0 and 1.0
1767
-
1768
-
1769
- Resizing Background Images
1770
- --------------------------
1771
- A custom CSS property "background-image-resize": is now supported on BODY, DIV+ (block elements) and TD
1772
- 0 - No resizing (default)
1773
- 1 - Shrink-to-fit w (keep aspect ratio)
1774
- 2 - Shrink-to-fit h (keep aspect ratio)
1775
- 3 - Shrink-to-fit w and/or h (keep aspect ratio)
1776
- 4 - Resize-to-fit w (keep aspect ratio)
1777
- 5 - Resize-to-fit h (keep aspect ratio)
1778
- 6 - Resize-to-fit w and h
1779
-
1780
- N.B. Prior to v4.4 background-images were incorrectly constrained to maximum width of the containing block.
1781
- The default is now to do NO resizing on background-images. Setting "background-image-resize:3" should be used
1782
- for backwards compatibility.
1783
- [4.3.015, 4.3.012D]
1784
-
1785
-
1786
- SVG Image files
1787
- ---------------
1788
- SVG image files are now partially supported (but as for WMF - not as background-images).
1789
- viewBox (preserveAspectRatio is not supported) viewBox="0 0 400 200" width="400" height="200"
1790
- Takes viewBox in preference to width/height if present on <svg>
1791
- If neither present, will size to width of page (square) as the containing box.
1792
- Units are interpreted as pixels if undefined.
1793
- Doesn't recognise internal CSS <style> elements
1794
- Gradients only take 2 colours which are taken as stop-offset 0% and 100%
1795
- [4.3.013 & 4.3.017]
1796
-
1797
-
1798
- Reduced Memory Usage printing Tables
1799
- ------------------------------------
1800
- mPDF uses a lot of memory when processing large tables. Parts of the script have been rewritten to
1801
- reduce memory consumption when writing tables which use collapsed borders (10-25% saving).
1802
-
1803
- Memory usage can be reduced further by setting a configurable variable:
1804
- $this->packTableData = true; // default=false
1805
- but note that this causes a significant increase in processing time.
1806
- [4.3.008, 4.3.019, 4.3.014]
1807
-
1808
-
1809
-
1810
- User-defined path to Temporary folder
1811
- -------------------------------------
1812
- mPDF uses a folder to write and store temporary files when processing images. By default this is the
1813
- [your_path_to_mpdf]/tmp/
1814
- This is now user-definable by defining the constant _MPDF_TEMP_PATH before including mpdf.php script.
1815
-
1816
-
1817
- Text Justification
1818
- ------------------
1819
- In a justified text block, an inline image, textarea, input, or select causing a new line will now force
1820
- the previous line to be justified. HR and BR do NOT force justification (as in browsers).
1821
- For optional compliance of MS Word behaviour, there is a new configurable variable:
1822
- $this->justifyB4br = false; // Change to true to force justification before a <BR> (as in MS Word)
1823
- [4.3.003]
1824
-
1825
-
1826
- CSS support for @media
1827
- ----------------------
1828
- Now supports media-dependent CSS styles e.g.
1829
- @media print {
1830
- p { color: red; }
1831
- }
1832
- as well as
1833
- <style media="...">...</style> and
1834
- <link rel="stylesheet" media="print" href="..." />
1835
- Proper matching of CSS media to select using configurable variable:
1836
- $this->CSSselectMedia='print'; // default="print" set in config.php : screen, print, or any other CSS @media type (not "all")
1837
- N.B. $this->disablePrintCSS in now depracated
1838
- [4.3.001]
1839
-
1840
-
1841
-
1842
-
1843
- ===========================
1844
- mPDF v4.3 (28/02/2010)
1845
- ===========================
1846
-
1847
- NEW FEATURES
1848
- ------------
1849
- - Page (sheet) size can be reset within document (http://mpdf1.com/manual/index.php?tid=436) [4.2.024, 4.2.025]
1850
- - PDF/A1-b compliant files (http://mpdf1.com/manual/index.php?tid=420)
1851
- - Improve performance using simpleTables (http://mpdf1.com/manual/index.php?tid=430)
1852
- - mPDFI incorporated into main mPDF class (http://mpdf1.com/manual/index.php?tid=432)
1853
- - <dottab> added as custom HTML tag: inserts dots to the following text, which is right-aligned [4.2.031]
1854
-
1855
- See Example files 38 and 39 for PDFA compliant file and <dottab>
1856
-
1857
- BACKWARD COMPATIBILITY
1858
- ----------------------
1859
- All changes are backwards compatible except the use of mPDFI. You will need to make minor changes to your scripts.
1860
- See the manual http://mpdf1.com/manual/index.php?tid=432 for details.
1861
-
1862
- BUG FIXES
1863
- ---------
1864
- - When using Table of Contents and not resetting page numbers: HTML headers/footers showed incorrect page number [4.2.020]
1865
- - Table of Contents: last page not printing page background-color [4.2.023]
1866
- - Image file with space " " in the file name failing [4.2.016]
1867
- - Image file path unnecessarily resolved to full URI - changed to use relative path if possible [4.2.029] ***
1868
- - Table - not calculating height of cell correctly [4.2.015, 4.2.012, 4.2.011, 4.2.009]
1869
- - Table row breaking after/during cell when image in cell taller than font-height [4.2.008]
1870
- - When Table row(cell) greater height than the page-height but requiring resizing greater than allowed by autosize - not resizing [4.2.005]
1871
- - Table cell border not resized correctly [4.2.002]
1872
- - Table row <TR> with a background-color, paints the whole row, including the spaces between cells [4.2.028] ****
1873
- - Background-image in HTMLFooter not correctly setting 0,0 origin [4.2.014]
1874
- - Background-image set as an in-line style not working [4.2.013]
1875
- - Background-image set in CSS @page or <body> was being constrained to less than page size [4.2.032]
1876
- - Imported Templates overwriting Headers (with images or gradients) [4.2.004]
1877
- - When using imports/templates, HTML header with background-image causing page to disappear [4.2.001]
1878
- - block-style element breaking over more than 2 pages incorrectly adjusting L/R margins [4.2.022]
1879
- - CSS @page property "size" set on :left :right or :first pseudo-selectors - disabled [4.2.022]
1880
- - Annotations default colour incorrectly set in PDF as [100 100 0] corrected to [1 1 0] (seemed to work ok?) [4.2.026]
1881
- - Overwrite() now parses input file more tolerantly recognising more source files [4.2.030]
1882
-
1883
- **** Bug fix 4.2.028 never got into the release of v4.3 Included in next release [4.3.005]
1884
- **** Bug fix 4.2.029 never not fully implmented in v4.3 Included in next release [4.3.012]
1885
-
1886
- Changed files
1887
- -------------
1888
- mpdf.php
1889
- compress.php
1890
- config.php
1891
- classes/t1asm.php
1892
- includes/functions.php
1893
- mpdfi/fpdi_pdf_parser.php
1894
- Added files/folder: /mpdfi/filters/*.*
1895
- Added file/folder: /iccprofiles/sRGB_IEC61966-2-1.icc
1896
- mpdfi/mpdfi.php (no longer required)
1897
-
1898
- New Configuration variables
1899
- ---------------------------
1900
- [config.php]
1901
- $this->enableImports
1902
- $this->simpleTables
1903
- $this->PDFA
1904
- $this->ICCProfile
1905
- $this->PDFAauto
1906
-
1907
-
1908
- Minor changes
1909
- -------------
1910
- Increased PDF file compatibility with spec 1.4
1911
- - PDF version changed to 1.4
1912
- - A binary file marker (a comment line with 4 characters > 127 ASCII) is added just after the first line
1913
- - %%EOF no longer has line break after it [4.2.010]
1914
- - /ID object is added to trailer object when not encrypted [4.2.010]
1915
-
1916
- When using progress bars, one of the JS scripts is now referenced as an external file
1917
- to allow it to be cached by user's browser and improve performance for end-user [4.2.007]
1918
-
1919
- Importing external PDF files: LZW encoded PDF files are now supported
1920
-
1921
- When adding an annotation, the popup window can be set be either open or closed when the document is opened [4.2.027]
1922
- - size and position of the popup can also be specified
1923
-
1924
-
1925
-
1926
- ===========================
1927
- mPDF v4.2 (27/01/2010)
1928
- ===========================
1929
-
1930
- NEW FEATURES
1931
- ------------
1932
- - image handling improved
1933
- - table layout - additional control over resizing
1934
- - vertical-alignment of images - better support for all CSS types
1935
- - top and bottom margins collapse between block elements
1936
- - improved support for CSS line-height
1937
- - display progress bar whilst generating file
1938
- - CSS @page selector can be specified when adding a pagebreak
1939
- - CSS @page selector allows different margins, backgrounds, headers/footers on :first :left and :right pages
1940
- - PNG images with alpha channel fully supported
1941
- - ability to generate italic and bold font variants from base font file
1942
- - CJK fonts to embed as subsets
1943
- - "double" border on block elements
1944
- - character substitution for missing characters in UTF-8 fonts
1945
- - direct passing of dynamically produced image data
1946
- - background-gradient and background-image can now co-exist
1947
-
1948
-
1949
-
1950
- Bug fixes
1951
- ---------
1952
- - empty variable (undefined var, false, null, array() etc.) sent to WriteHTML produced error message "Invalid UTF-8"
1953
- - CJK in tables when not using CJK (utf-8-s) autosized very small as characters did not word-wrap
1954
- - parsing stylesheets: background image not recognised if containbed uppercase characters in file name
1955
- - "double" border on table used white between the lines instead of current background colour
1956
- - $this->shrink_tables_to_fit = 0 or false caused fatal errors
1957
- - background color or images not printing correctly when breaking across pages
1958
- - background not printed for List inside a block element
1959
- - columns starting near end of page with no room for a line triggering column change (resulting in text misplaced) not page break
1960
- - table cell not calculating cell height correctly when "orphan" characters (;:,.?! etc.) at end of line
1961
- - table breaking page in column 2 when col 1 is rowspan'ned
1962
- - margin-collapse at top of page not working if bookmark/annotation/indexentry/toc
1963
- - column break triggered by HR triggering a second column break
1964
- - an empty 'position:fixed' element with no/auto width or height caused fatal error
1965
- - mPDFI: template documents were overwriting HTML headers
1966
- - mPDFI: function Overwrite (to change text in existing PDF) - fatal error if using with encrypted file
1967
-
1968
- Bug - not fixed
1969
- - WriteHTML('',2) with '2' parameter not recognising 'margin-collapse:collapse' for DIVs or 'line-height' set in default CSS 'BODY'
1970
-
1971
-
1972
-
1973
- New or Updated Files
1974
- --------------------
1975
- mpdf.php
1976
- compress.php
1977
- config.php
1978
- config_cp.php
1979
- config_fonts.php
1980
- mpdf.css
1981
- classes/gif.php
1982
- classes/indic.php
1983
- includes/subs_core.php
1984
- mpdfi/mpdfi.php
1985
- unifont/ar_k_001.uni2gn.php
1986
- All files in new folder: /progress/*.*
1987
-
1988
- NEW FOLDER /tmp/ required with read/write permissions - used for temporary image files or progress bars
1989
-
1990
-
1991
-
1992
-
1993
- ===========================
1994
- mPDF v4.1.1 (21/12/2009)
1995
- ===========================
1996
- Error corrected in /makefont/makefonts.php file (moved completed Unicode files to font folder instead of unifont)
1997
-
1998
- ===========================
1999
- mPDF v4.1 (20/12/2009)
2000
- ===========================
2001
- MySQL support for embedded font subsets abandoned, and replaced with file-based.
2002
-
2003
-
2004
- Files no longer required
2005
- ------------------------
2006
- config_db.php
2007
- /unifont/RUNME.php
2008
- /unifont/*.ufm and /unifont/*.t1a font files
2009
-
2010
- MySQL Database no longer required
2011
-
2012
- Files Updated
2013
- -------------
2014
- mpdf.php
2015
- /classes/t1asm.php
2016
- /makefont/makefonts.php
2017
-
2018
- New files
2019
- ---------
2020
- /unifont/*.dat and /unifont/*.dat.php font files
2021
-
2022
-
2023
- Bug-fixes
2024
- ---------
2025
- - Image - If automatically resizing to fit maximum page size incorrectly subtracted margin-header
2026
- - Annotation and textarea in same HTML chunk causes mPDF to crash (preg_replace textarea with /u modifier in AdjustHTML)
2027
- - set_magic_quotes_runtime error ($mgr not $mqr)
2028
- - Table align did not reverse when using RTL document
2029
-
2030
- Alteration: Image - if writing Image in fixedpos div position:absolute - to allow Image to be resized to full page size
2031
-
2032
-
2033
- ===========================
2034
- mPDF v4.0 (17/12/2009)
2035
- ===========================
2036
-
2037
- Major additions
2038
- ---------------
2039
- - Ability to embed font subsets (creating much smaller files)
2040
- - Much improved support for Arabic languages
2041
- - Support for Indic languages including consonant conjuncts
2042
- - Support for Fixed position block elements
2043
- - New utility to help create your own fonts
2044
- - PNG alpha channel transparency supported
2045
- - New utility to create smaller mpdf script with reduced functionality (less memory)
2046
- - Multiple Barcode types supported
2047
-
2048
- **********************************************************************************************
2049
- * For more details see the documentation manual: http://mpdf1.com/manual/index.php?tid=410 *
2050
- **********************************************************************************************
2051
-
2052
- Bug fixes (parsing CSS)
2053
- -----------------------
2054
- - <link href="" ... was not recognised if > 1 space between words
2055
- - #Content p em { font-style:italic; } was applied to "#Content p"
2056
- - @import url() embedded in a stylesheet file requires path fixed relative to stylesheet file
2057
- - background-image url() embedded in a stylesheet file requires path fixed relative to stylesheet file
2058
- - comment tags inside CSS <style> embedded in the HTML were removed
2059
- Now fixed so <style><!-- ... --></style> works; <!-- <style>...</style> --> is removed
2060
-
2061
- Bug fixes (other)
2062
- -----------------
2063
- - clear (CSS property for floating elements) caused properties for that element to reset to defaults
2064
- - width: auto caused collapse of border and padding on L & R of ordinary block elements
2065
- - text-indent not inherited correctly (including em and % values)
2066
- - named colour "steelblue" corrected RRGGBB hex code
2067
- - table cell widths in %: if width of table cells set to >=100%, and not all columns are set
2068
- This was fixed in 3.2 but led to problem where 2 cols: 1) 80% and 2) not set (see Table sizing test)
2069
- Now fixed again to work for both(?)
2070
- - parse PNG error fixed
2071
- - bachground-image not correctly positioned in HTMLFooter and HTMLHeader (Not fixed properly in 3.2!)
2072
- - fonts not supported with 0-9 in the name
2073
- - font list in GetCodepage() in htmltoolkit.php (now config_cp.php) containing space " " not recognised
2074
- - list number positioning
2075
- - list font size set in CSS for UL/OL not working for first level list
2076
- - table width (real value, not %) not working in nested table
2077
- - GIF file failed if PDF file not compressed
2078
- - list-style-type incorrectly inherited
2079
- - line-height inheritance in lists
2080
- - SetColumns added a new line - not required if at start of document/page
2081
- - footer_line_spacing did not work
2082
- - table cellPadding="" overwrote cell padding set on cell CSS
2083
- - could not turn off Default non-HTML foter LINE
2084
- - border specified as "em"
2085
- - default values set in mpdf.css overriden by inherited properties e.g. <div><h1>Here</h1></div> lost font-size for H1
2086
-
2087
-
2088
-
2089
- ===========================
2090
- mPDF v3.2 (25/10/2009)
2091
- ===========================
2092
- Bug fixes
2093
- ---------
2094
- - Table cell widths in %: if width of table cells set to >=100%, and not all columns are set -> froze, because tries to produce a column of no width
2095
- - Ouput download file changed to allow compatability with IE6 (http://mpdf.bpm1.com/forum/comments.php?DiscussionID=120&page=1#Item_4)
2096
- - Image error if relative path used on domain root (e.g. img src="image.png" and basepath is http://www.yourdomain.com) [attempted fix in 3.1 not working]
2097
- - Table: if font changed in cell, font was not retoring properly afterwards causing errors (restoreInlineProperties())
2098
- - Lists: list items containing <br />, font not restoring after bullet
2099
- - Graceful support for block elements inside list items e.g. <li><p>... (not supported, but tolerated)
2100
- - Index: Created dividing letters separately for Uppercase and lowercase
2101
- - Incorrectly changing input character set when encountering e.g. charset=iso-8859-1 in the text of the document
2102
- - Changed so only detects it if within <head>...</head>
2103
- - If Keep-with-table (i.e. H1-6 before table and use_kwt true), if pagebreak forced anyway, borders did not print on previous page
2104
- - Background-image used in HTML footer not appearing (correctly)
2105
- - RTL tables: nested tables will not automatically transpose L->R
2106
- - "Keep heading with table" - changed to allow <h1 style=".."> not just <h1>
2107
- - "Keep heading with table" - backgrounds (bgcolor, image or gradient) incorrectly handled - now removed
2108
- - Rotated table spread over more than 1 page caused enclosing block background colours to be be rotated along with table
2109
- - CSS text-indent % now correctly suported (% of containing block width)
2110
- - CSS width em on a block element e.g. DIV now correctly suported
2111
- - calculating _tableheight, if remainingpage==0, get error (div by zero)
2112
- - Table moved to next page with page-break-inside=avoid, produced an enlarged table (font)
2113
- - RTL text-align override on BODY text was not working consistently
2114
- - Arab characters: Character &#x647; (HEH) appearing in Final presentation form instead of Isolated
2115
- - Vertical position of background-image on whole page incorrect
2116
- - SetProtection can now be used with no permissions set (was not working unless at least one permission set)
2117
-
2118
-
2119
- Developers
2120
- ----------
2121
- Some more undefined indexes and variables declared (courtesy of DSmart http://mpdf.bpm1.com/forum/comments.php?DiscussionID=117&page=1#Item_0 )
2122
- Comment lines removed for < v3.0 to tidy up code
2123
-
2124
-
2125
- Enhancements
2126
- ------------
2127
- CSS style height now partially supported on block elements DIV, P, H1 etc. --IF--
2128
- - block is all on one page
2129
- - will extend the block but not shorten it
2130
- - will not force a pagebreak (max. at bottom of page)
2131
- - % is interpreted as % of printable page height (inside margins)
2132
- <TFOOT> now supported (placed at start as in HTML spec) displays at end of table, and repeats as a footer
2133
- Background-image and background-gradient now supported in TD and TH (works in all cases except: background-image is not rotated or
2134
- positioned correctly if table is rotated)
2135
- NB Background images and background-gradients do not work if Columns are being used, or if $use_kwt is TRUE (keep-with-table),
2136
- or if page-break-inside:avoid is active.
2137
-
2138
-
2139
- Updated files
2140
- -------------
2141
- mpdf.php
2142
- htmltoolkit.php
2143
-
2144
-
2145
-
2146
-
2147
- ===========================
2148
- mPDF v3.1 (30/08/2009)
2149
- ===========================
2150
-
2151
- Bug fixes
2152
- ---------
2153
- - Image error if relative path used on domain root (e.g. img src="image.png" and basepath is http://www.yourdomain.com
2154
- was giving http://www.yourdomain.com//image.png) [3.1]
2155
- - Errors in parsing background CSS (background-repeat, background-position etc) [3.1]
2156
- - Textarea did not corectly convert width or height in units relating to font e.g. em [3.0beta_01]
2157
- - If page margin-bottom set to zero, SetHTMLfooter() crashes with "Division by zero" error [3.0beta_01]
2158
- - Table with header row and rowspan in tbody, not calculating maxrowheightcorrectly
2159
- - Prevent Index breaking column just after a dividing letter
2160
- - Select or input form field when text around it is justified had text in the form field justified
2161
- - TocBookMarkText needs to be htmlspecialchar-ed - decoded when entered inside <tocpagebreak>
2162
- - <img src="" /> caused crash
2163
- - DisplayPreferences used as a variable name and a function: function renamed to SetDisplayPreferences()
2164
- - Image with src file not including a "." incorrectly parsed (e.g. http://www.domain.com/imagegenerator?params=23)
2165
-
2166
- New Features
2167
- ------------
2168
- - var $debug (true|false) default false; show or hide error reporting at output stage [3.1]
2169
- - var $autoPageBreak (true|false) default true; allows overriding of automatic page breaks [3.0beta_02]
2170
- - <indexinsert /> HTML equivalent of CreateIndex() [was CreateReference()]
2171
- - 2nd attribute/parameter "xref" in IndexEntry() and <indexentry> - works like IndexEntrySee() as cross-reference entry
2172
- - function SetWatermarkText allows null parameters to be passed i.e. SetWatermarkText() - will clear the WatermarkText
2173
- - <watermarktext content="" alpha="" /> - HTML equivalent of SetWatermarkText()
2174
- - <watermarkimage src="" alpha="" position="" size="" /> - HTML equivalent of SetWatermarkImage()
2175
-
2176
- Documentation
2177
- -------------
2178
- See Manual at http://mpdf.bpm1.com/manual/ for more information - especially:
2179
- - User's Guide>>What Else Can I Do?>>Backgrounds & Borders
2180
- - User's Guide>>What Else Can I Do?>>Floating blocks
2181
-
2182
- Files updated:
2183
- -------------
2184
- mpdf.php
2185
- htmltoolkit.php
2186
- graph.php
2187
-
2188
-
2189
- Developers only
2190
- ---------------
2191
- mPDF<=3.1 generated a large number of warning "Notices" if run with full eror_reporting on, due to array indexes not being initiated e.g.
2192
- $arr = array();
2193
- ...
2194
- if ($arr['index'] == 5 ) {...}
2195
-
2196
- To prevent this, lines were added at the start of the mpdf.php script to turn error notices OFF.
2197
- In a move towards making mPDF able to run with full error_reporting on, a large amount of the script has been altered
2198
- e.g. the line above would be changed to:
2199
- if (isset($arr['index'] && $arr['index'] == 5 ) {...}
2200
-
2201
- Although I have tested this with a number of examples, it is almost certainly not complete. Therefore the error_reporting for Notices is still turned
2202
- off in mPDF 3.1
2203
- If you care to test it, please uncomment line 43 (//error_reporting(E_ALL);) and report any warning notices that you get.
2204
- NB This has added about 40kB to the script size.
2205
-
2206
-
2207
-
2208
- ===========================
2209
- mPDF v3.0beta (14/06/2009)
2210
- ===========================
2211
-
2212
-
2213
- New Features
2214
- ------------
2215
- - CSS "float" partially supported (as well as clear:left|right|both)
2216
- - CSS "background-image" "background-position" "background-repeat" "background-color" "background" supported for block-level elements
2217
- - CSS background-color and background-image for <body > element added: this covers the whole page i.e. not just inside the "margins"
2218
- - CSS background-color and background-image can be defined for CSS @page{}
2219
- - Background gradients (linear or radial) can be defined using a custom CSS style property
2220
- - Border radius can be defined to give rounded edges to block elements (uses draft CSS3 spec.)
2221
- - page number can be reset to any value during the document (in AddPage() <pagebreak> etc.)
2222
- - PNG images: Interlaced and alpha-channel-set PNG images now supported
2223
- - internal links supported in Indexes (parameter added to CreateIndex()/CreateReference(): $useLinking=true;)
2224
- - HTML Headers and footers now support hyperlinks
2225
- - improved handling of <br>, block elements, and text lines inside table - approximates better to browser handling
2226
- - borders of block-level elements & table cell borders supported (partially) in columns
2227
- - optional error reporting for problems with Images ($showImageErrors)
2228
- - ToC will word-wrap long entries
2229
- - internal links (Bookmarks, IndexEntry and ToCEntry) rewritten to give more accurate positioning (when used as <tag>)
2230
- - autofont algorithm improved for CJK languages
2231
- - define text before and after page numbers ($pagenumPrefix; $pagenumSuffix; $nbpgPrefix; $nbpgSuffix;)
2232
- - Additional color names supported - full list from SVG1.0
2233
-
2234
- Bug fixes
2235
- ---------
2236
- - Column width not resetting after an automatic pagebreak, or after setting HTMLheader
2237
- - using AutoFont unnecssarily changed htmlspecialchars to code causing errors
2238
- - Lists inside a table - incorrectly calculating table cell height
2239
- - CJK - 4-byte utf-8 chars not displaying properly (includes HKCS characters)
2240
- - mailto: links incorrectly handled
2241
- - TOCpagebreak() - usePaging default clarified: true unless specified as '', 0, '0' or false; (null ->true)
2242
- - <tocpagebreak> (as html tag) with no "name" defined, used at start of page, added a further blank page(s)
2243
- - Lists - inaccurate calculation of space required for numbers in certain circumstances
2244
- - Generated images (.php) only working if cURL enabled - (fixed, but rquires allow_url_fopen if remote file)
2245
- - flag added to turn off error reporting when buffering used ($allow_output_buffering = false;)
2246
- - RTL text in Bookmark, Title, Author, Creator, Keywords, and Subject was reversed - Adobe Reader 9 now correctly handles RTL text ( which Reader 8 did not)
2247
- - TOC - if not using ODD/EVEN paging, did not add extra page and messed up
2248
- - Rotated table which did not fit on remaining page resized to bigger than default
2249
- - HR of width less than 100% - text continued on line after it
2250
- - HR alignment not working (fixed so both CSS text-align and margin: 0 0 0 auto etc work)
2251
- - HR in table did not correctly re-size when necessary
2252
- - characters in symbols/zapfdingbats which in non-utf-8 mode are represented as chr(173) incorrectly handled as soft-hyphens
2253
- (bug introduced 2.5 with soft-hyphens - affects symbols &#8593; arrow-up and Zapfdingbats &#9313; encircled 2)
2254
- - Internal links (anchors) - Annotation/Bookmarks etc. incorrectly positioned when page orientation changed
2255
- - ToC - when using multiple ToCs, internal links were not correctly adjusted
2256
- - anchor (a name="") used inside a table was incorrectly positioned at the end of table
2257
- - Tables: cell height calculated incorrectly when BR used
2258
- - Table rotated with "page-break-inside:avoid" not kept on one page
2259
- - Table rotated and split over > 1 page - vertical alignment inaccurate
2260
- - Headers/Footers (non_html) when no style set caused errors
2261
- - Table: breaking page when using rowspan error (line 17142)
2262
- - ToC: If no indent defined in HTML tag <tocpagebreak> or defined as 0 gave error
2263
-
2264
- Note
2265
- ----
2266
- In mPDF 3.0 the following sections of code have been significantly rewritten:
2267
- - painting of borders and background colours for block-elements
2268
- - table of contents
2269
- - Index
2270
- - vertical justification in columns (uses scaling to stretch vertically)
2271
-
2272
- NB changed htmltoolkit AdjustHTML - does not now remove <br> before </div>
2273
- Warning - may display differently in normal text as well as tables
2274
-
2275
-
2276
- Files updated:
2277
- -------------
2278
- mpdf.php
2279
- htmltoolkit.php
2280
-
2281
-
2282
- Developers only
2283
- ---------------
2284
- - Background-color handling in CSS changed so only inherited/cascaded when Columns active or Keep-block-together
2285
- - otherwise would overwrite background image with inherited color
2286
- - all %.2f used in sprintf() changed to %.3f in htmltoolkit.php and mpdf.php to increase accuracy of div border lines in columns etc.
2287
- - variable $use_embeddedfonts_1252 renamed to $useOnlyCoreFonts as more precise: depracated but still supported.
2288
- - this version included quite abit of tidying up/future-proofing some code:
2289
- $var{0} changed to substr($var,0,1) etc. (due to go in PHP6)
2290
- ereg_ changed to preg_ (depracated in PHP5.3) - (NB mainly in htmltoolkit.php)
2291
-
2292
-
2293
-
2294
- ===========================
2295
- mPDF v2.5 (01/05/2009)
2296
- ===========================
2297
-
2298
- New Features
2299
- ------------
2300
- - Automatic Hyphenation added, and support for soft-hyphens
2301
- - Encryption works now for CJK language documents
2302
- - Improved text justification
2303
- - Support for 'generated' images e.g. "../ontheflyimage.php"
2304
-
2305
-
2306
- Bug fixes
2307
- ---------
2308
- - Tables: cell height did not reduce if font-size used was smaller than table default
2309
- - Columns: if setcolumns() to the same number already active - did not print out last bit of previous columns
2310
- - Page-break in the middle of a block caused incorrect margin and padding on next lines until end of block ($cMargin reset to 0 in AddPage)
2311
- - <HR> in table cell was printing in incorrect position (bug introduced in mPDF 2.4)
2312
- - Justification
2313
- - if only one word on line, did not respect maximum character spacing
2314
- - last character of line incorrectly had character spacing applied
2315
- - Space at the end of last line of a Right Justify block - e.g. "end. </p>" now correctly ignored
2316
- - &nbsp; incorrectly treated as a character when justifying text with word/char spacing
2317
- - CJK punctuation (.,) added as 'orphans' to keep at end of line
2318
- - PNG files - was still buggy reading larger PNG files (due to fread)
2319
-
2320
-
2321
- Files updated:
2322
- -------------
2323
- mpdf.php
2324
- htmltoolkit.php
2325
- CJKdata.php
2326
- /patterns/.. (new files)
2327
-
2328
-
2329
- Developers only
2330
- ---------------
2331
- Variables renamed as more accurate or appropriate:
2332
- - var $isunicode renamed as $is_MB
2333
- - var $usingembeddedfonts renamed as $usingCoreFont
2334
- CJK changed to act internally as UTF-8 encoded
2335
- - (NB CJK Half-widths not supported from 2.5+ i.e. big5-hw gb-hw)
2336
-
2337
-
2338
-
2339
- ===========================
2340
- mPDF v2.4 (23/04/2009)
2341
- ===========================
2342
- Files updated
2343
- -------------
2344
- mpdf.php
2345
- htmltoolkit.php
2346
- mpdfi/mpdfi.php
2347
-
2348
- New files
2349
- ---------
2350
- graph.php
2351
- Graphs - Requires new folder: path_to_mpdf/graph_cache/ (must be writeable)
2352
-
2353
- New features
2354
- ------------
2355
- Annotations improved so they appear as a pop-up
2356
- Re-use Document Templates (cf. RestartDocTemplate() in manual)
2357
- Limited support for CSS float property on an IMG element allowing text wrapping e.g. <img style="float: right;"> (cf. Images in manual)
2358
- Utility function PreparePreText() allows output of a text file which may include <pre>
2359
- Automatic generation of graphs from data in tables (requires integration with JPGraph) (cf. Graphs in manual)
2360
-
2361
- Other Changes
2362
- -------------
2363
- IMPORTANT - User rights removed as not working with newer version of Adobe Reader 9 (affects Active forms and ability for users to modify annotations)
2364
- Corrects text alignment when using {nb} or {nbpg} in (non-HTML) headers/footers
2365
- Sets default timezone if not already set (at top of mpdf.php) to prevent E_STRICT ERROR message
2366
- Suppresses E_NOTICE error reporting (at top of mpdf.php)
2367
- Error capture in Output() to avoid PDF header being sent when error messages generated
2368
- A function str_ireplace added to htmltoolkit to allow PHP4 to function
2369
-
2370
- Bug fixes
2371
- ---------
2372
- WMF images incorrectly positioned when in-line
2373
- PNG images > 8kB failed to load - (fix in 2.3 didn't work - fixed properly this time)
2374
- Annotations containing a new line (\n) causing an error
2375
- Evaluation of <pre> text: "<code>[TAB] " evaluated incorrect number of spaces to follow to align tabs, because < was calculated as 4 chars (&lt;)
2376
-
2377
-
2378
-
2379
- ===========================
2380
- mPDF v2.3 (22/03/2009)
2381
- ===========================
2382
-
2383
- New Features
2384
- ------------
2385
- - Optionally detect language and when to use special fonts i.e. RTL (arabic), CJK (chinese), Thai (see SetAutoFont() etc.)
2386
- - Supports HTML attribute "lang" in all tags and uses special fonts when required (see $useLang)
2387
- - Joins Arabic and Farsi/Persian text into presentation forms
2388
- - Import another PDF file and use as templates in your document (see UseTemplate() and mPDFI in the manual.)
2389
- - Replace specified text strings in an existing PDF file (see OverWrite() etc.)
2390
- - More than one Table of Contents can be used in a document (see tocpagebreak etc.)
2391
- - Restore properties of open HTML block elements after a page break (variable $restoreBlockPagebreaks or new tag <formfeed>)
2392
- - <annotation> <bookmark> <indexentry> <tocentry> can now accept characters <>'"& as htmlentities - htmlspecialchars(..., ENT_QUOTES)
2393
- - <annotation> can now accept "\n" for new line
2394
- - support for opacity (CSS3 property) for images
2395
- - specify the number of spaces to substitute for TAB when parsing <pre> tags
2396
- - greater control over margins and display when changing page orientation during document (see $forcePortraitMargins and $displayDefaultOrientation)
2397
-
2398
-
2399
-
2400
- Bug fixes
2401
- ---------
2402
- Fonts in CSS - Not parsing font-family: Trebuchet MS; correctly as trebuchet
2403
- Fonts in CSS - CSS font-family: [unknown]; setting first $available_unifont rather than ignoring
2404
- Images - not displaying on IIS platform
2405
- Images - .wmf not displaying if (allow_url_fopen) not set
2406
- Table borders - in defaultCSS, 'MARGIN-COLLAPSE'=> collapase not quoted therefore not working
2407
- Line-break inside table - printing a blank background across page rather than just going down a line
2408
- Form fields inside tables - will now resize if the table is autosized (shrunk)
2409
- <pre> containing a '<' was changed to '&lt;'
2410
- Tabs inside <pre> were all changed to 8 spaces, not the remainder following a string
2411
- Header on first page was inset by 1mm left and right ($cMarginL and $cMarginR not set to zero)
2412
- Table nested inside a cell with colspan > 1 was incorrectly handled
2413
- PNG file crashed (?incorrectly defined PNG file) [adapted _parsepng to account for unexpected]
2414
- Table or Cell - if font-size not recognised, mPDF set font-size to zero
2415
- Font-sizes - [xx-small|x-small|small|medium|large|x-large|xx-large] were not recognised in tables
2416
-
2417
-
2418
- ===========================
2419
- mPDF v2.2.1 (17/02/2009)
2420
- ===========================
2421
- Bug fix - (bug introduced in 2.2)
2422
- Table - header row did not return to top of page when repeating across pages.
2423
-
2424
-
2425
- ===========================
2426
- mPDF v2.2 (15/02/2009)
2427
- ===========================
2428
- Updated files from mPDF 2.1
2429
- mpdf.php
2430
- htmltoolkit.php
2431
- mpdf.css (new)
2432
- ===========================
2433
- New files from mPDF <2.0 (only required for EAN Barcodes)
2434
- font/ocrb.xx (several)
2435
- unifont/ocrb.xx (several)
2436
- IMPORTANT - you need to make sure the ocrb font is added to the config.php file
2437
- - add 'ocrb' to the end of 3 arrays: $this->available_fonts $this->available_unifonts and $this->mono_fonts
2438
- ===========================
2439
-
2440
- Summary of changes
2441
- - external stylesheet file (mpdf.css) is used to configure default values ($useDefaultCSS2 and $defaultCSS2 are no longer used)
2442
- - special comment tags to hide mPDF tags from browsers: <!--mpdf ... mpdf-->
2443
- - AddColumn() function added (equivalent to <columnbreak>)
2444
- - annotations - pop-up messages the reader can move or delete (if you set permissions)
2445
- - support for WMF images as well as GIF, JPG, PNG
2446
- - watermark image can be set instead of, or as well as text
2447
- - nested tables can include other content
2448
- - improved control over table layout
2449
- - margin: auto now supported for table and block elements
2450
-
2451
- A number of methods and variables have been renamed or reCapitalised for consistency.
2452
- Changes should be backwards comaptible.
2453
- All user methods start with a Capital, all user-defined variables start with lowercase.
2454
- Affected:
2455
- Reference() -> IndexEntry()
2456
- CreateReference() -> CreateIndex()
2457
- $TopicIsUnvalidated -> $showWatermark
2458
- setUnvalidatedText() -> SetWatermarkText()
2459
-
2460
- PHP appears at present to be case-insensitive for function/method names
2461
- All the following functions have been renamed in the script with a capital first letter:
2462
- setUserRights()
2463
- setBasePath()
2464
- setAnchor2Bookmark()
2465
- setHeader()
2466
- setFooter()
2467
- defHeaderByName()
2468
- defFooterByName()
2469
- setHeaderByName()
2470
- setFooterByName()
2471
- setHTMLHeader()
2472
- setHTMLFooter()
2473
- defHTMLHeaderByName()
2474
- defHTMLFooterByName()
2475
- setHTMLHeaderByName()
2476
- setHTMLFooterByName()
2477
- shaded_box()
2478
- writeBarcode()
2479
-
2480
- Variable names changed to lowercase first letter:
2481
- (Variables are case-sensitive therefore aliases have been set up)
2482
- Anchor2Bookmark
2483
- BiDirectional
2484
- KeepColumns
2485
- AliasNbPg
2486
- AliasNbPgGp
2487
-
2488
- =========
2489
- Bug fixes
2490
- =========
2491
- Columns - $keepColumns=true was incorrectly calculating the place to continue printing after 1 and half columns (of 3)
2492
- Table cell height - incorrectly setting table cell height when cell contained a line of text of large size which wrapped to more than one line
2493
- HR in Table cell - if table cell contains only HR (and column otherwise empty), HR was printed outside cell
2494
- HR in Table cell - if table cell ended with a HR, height was one line too much
2495
- Table page-break-inside:avoid - caused mPDF into permanent loop in some circumstances
2496
- Paging - Total Pages/Group {nb} and {nbgp} didn't work in CJK
2497
- CSS - Border size thin, medium and thick were only recognised in lowercase
2498
- Table-header - rowspan not correctly output in THEAD
2499
- Default CSS - table empty-cell:hide changed to show (CSS specification)
2500
-
2501
- ===========================
2502
- mPDF v2.1 (24/01/2009)
2503
- ===========================
2504
-
2505
- New Features in Version 2.1
2506
- ---------------------------
2507
- - CSS support improved generally (especially for cascading CSS, lists)
2508
- - TableHeader changed to allow multiple rows in THEAD
2509
-
2510
-
2511
- CSS changes
2512
- -----------
2513
- - display: none (block elements only - not lists or tables, nor HR)
2514
- - width (TD/TH)
2515
- - list-style-type (will also recognise the list-style-type from list-style) (OL/UL)
2516
- recognised values: disc|circle|square|decimal|lower-roman|upper-roman|lower-latin|upper-latin|lower-alpha|upper-alpha|none
2517
- - CSS support for <LI>: font-family, font-size, font-style, font-weight, color, background-color, text-decoration, text-transform, and list-style-type (will also recognise the list-style-type from list-style)
2518
- - table cell borders - CSS rules have been adapted slightly - if a coloured/black line conflicts with a white line, and is the same width, coloured/black will overwrite even if Bottom or Right
2519
-
2520
-
2521
- Numbered Lists
2522
- --------------
2523
- Variables set at the top of mpdf.php can be set to change:
2524
- - text alignment of numbers in numbered lists (default Right)
2525
- var $list_align_style = 'R';
2526
- - content to follow a numbered list marker e.g. '.' gives 1. or IV. whereas ')' gives 1) or a)
2527
- var $list_number_suffix = '.';
2528
- (These can be altered at run time, but are not changeable through stylesheets or in-line style)
2529
-
2530
-
2531
- Writing broken segments of HTML
2532
- -------------------------------
2533
- 2 new parameters have been added to WriteHTML()
2534
- function WriteHTML($html,$sub=0,$init=true,$close=true) {
2535
- $close - Leaves buffers/variables etc. in current state, so that it can continue to write the HTML where it leaves off
2536
- $init - Clears and resets buffers/variables
2537
- (N.B. You must end with a WriteHTML that calls $close=true)
2538
- Example:
2539
- $mpdf->WriteHTML('<p>This is the beginning...', 2, true, false);
2540
- $mpdf->WriteHTML('...this is the middle...', 2, false, false);
2541
- $mpdf->WriteHTML('...and this is the end</p>', 2, false, true);
2542
-
2543
-
2544
- Rotated text in table cells
2545
- ---------------------------
2546
- NB This UPDATE will change expected output from previous versions******
2547
-
2548
- Prior to v2.1 any cell set to rotate text anticlockwise was forced to vertical align = bottom.
2549
- This has been changed so that it only overrides when the rotate angle is between 45 and 89 degrees: text rotated exactly 90 degrees will respect the set value for vertical-align.
2550
-
2551
-
2552
- =========
2553
- Bug fixes
2554
- =========
2555
- - List - list starting after "<div>Then some text not in a block element<ol>" incorrectly output
2556
- - Tables - if cell font-size set smaller than default for the table, does not shrink the cell height
2557
- - Columns (tables) - columns breaking across rows e.g. in the middle of a table cell
2558
- - Tables - if table width set to e.g. 100% but cols are less, was not making up to set width
2559
- - Watermark - was not printing if using HTMLFooter
2560
- - Lists - not aligning numbering correctly if different font sizes used for bullet & text etc.
2561
- - Lists - indent of text did not correctly allow for Maximum number in <ol> list
2562
- - Table does not always move correctly to a new page
2563
- - Table cell incorrectly calculated height causing text to overflow cell when printed
2564
- - Table borders in columns not being correctly handled (bug since 2.0 introduced a buffer to save the borders and print at the end of the table - fixed so does not use buffer if in columns - potentially does not deal with conflicting borders as well, but works in columns)
2565
- - Table cell width if set as a percent was being downsized when autosizing table
2566
- - Table CSS was buggy - improved
2567
- - SetBasePath (when fetching remote website) - now handles string with query string on it e.g. http://www.domain.com/index.php?tid=42
2568
- - Table cells with Rotated text - text not positioned correctly
2569
- - Page number totals not working in utf-8 mode
2570
-
2571
-
2572
- ============================
2573
- Code efficiency improvements
2574
- ============================
2575
- - BIG speed improvement (compared with 2.0) with tables (especially large tables)
2576
- - considerable increase in speed if writing long HTML segments to mPDF
2577
- - speed improvement for tables (may be very significant if some cells have a lot of text in them causing uneven column widths)
2578
-
2579
- NB To speed up program more, consider setting $mpdf->useSubstitutions=false; if you do not use any characters outside the codepage selected
2580
-
2581
-
2582
- ===============
2583
- Keep-with-table
2584
- ===============
2585
- (This was introduced in v2.0 but I forgot to document it)
2586
- If you set $this->use_kwt = true;
2587
- All H1-H6 elements will try to keep with a table that follows immediately afterwards - (this is done in htmltoolkit, by adding an attribute KEEP-WITH-TABLE)
2588
- See Known Issues re: Using kwt inside a div with border/background (doesn't work)
2589
-
2590
-
2591
-
2592
-
2593
- ===========================
2594
- mPDF v2.0 (07/12/2008)
2595
- ===========================
2596
- Main New Features in Version 2.0
2597
- - nested tables are supported
2598
- - supports both models of table border: separate and collapsed
2599
- - improved parsing of CSS stylesheets, and better handling of styles throughout
2600
- - additional recognised CSS styles
2601
- - page orientation, size, and margins can be changed within the document, using PHP script or custom HTML
2602
- - some limited support for @page CSS to define page-box areas, with crop/cross marks for printing
2603
- - improved control over headers and footers (including HTML headers/footers)
2604
- - improved presentation of Form elements including image-type input fields
2605
- - generates an EAN barcode suitable for a book/printed publication
2606
- - active forms can be generated - EXPERIMENTAL at present
2607
- - change document permissions to allow the user to make annotations - EXPERIMENTAL at present
2608
-
2609
- NB Lines are commented in mPDF script as changes for mPDF 1.4 - this became v2.0
2610
-
2611
- =========
2612
- UPGRADING
2613
- =========
2614
- IMPORTANT - Before Upgrading: Please note that some of the changes will cause mPDF 2.0 to render the pages differently from earlier versions i.e. it is not totally backwards comaptible. Read the notes on Backward compatibility before deleting your original set-up.
2615
-
2616
- To upgrade from v<=1.3 to v2.0 you only need to copy and overwrite the following 2 files:
2617
- mpdf.php
2618
- htmltoolkit.php
2619
-
2620
- Plus (optionally) if you want to use the EAN Barcode function, you will also need:
2621
- font/ocrb.xx (several)
2622
- unifont/ocrb.xx (several)
2623
- IMPORTANT - you need to make sure the ocrb font is added to the config.php file
2624
- - add 'ocrb' to the end of 3 arrays: $this->available_fonts $this->available_unifonts and $this->mono_fonts
2625
-
2626
-
2627
- ==========
2628
- Bug Fixes
2629
- ==========
2630
- <columns column-count="0"> did not turn off columns - Fixed
2631
-
2632
- Margins as % - e.g. margin-right: 50% set from CSS incorrectly applied 50% of the fontsize
2633
- (Fixed - adding parameter to fn. ConvertSize in htmltoolkit.php and in calls to that function)
2634
-
2635
- DIV Width - e.g. div style="width: 50% was not working
2636
- (Fixed - fn.SetCSS and OpenTag()'DIV')
2637
-
2638
- CSS values as Zero - p { margin: 0; } did not work in stylesheet unless 0 had a unit
2639
-
2640
- Multiple Non-breaking spaces collapsed - e.g. "1&nbsp; &nbsp; &nbsp;2" - was contracted to "1 2"
2641
- (Fixed - fn.adjustHTML in htmltoolkit.php)
2642
-
2643
- Table cell too narrow causing incorrect printing - If two characters are too wide to print (only likely within a table cf. example tables - Periodic table) the first character was not printed, just a new line
2644
- (Fixed in fn.WriteFlowingBlock)
2645
-
2646
- Font size by inline style for form elements <input> <textarea> gave wrong size when using a relative size 0.9em
2647
- (Fixed - fn.ConvertSize in htmltoolkit.php)
2648
-
2649
- Creation Date not correctly showing
2650
- (Fixed - did not need to convert to UTF16)
2651
-
2652
- New block element started at end of page - block borders not painted
2653
- (Fixed - fn.AddPage)
2654
-
2655
- DL did not close block correctly
2656
- (Fixed - mistype in fn. CloseTag)
2657
-
2658
- Transparent not recognised as color/background-color
2659
- (Attempted a fix by setting to ignore it! - fn. convertcolor in htmltoolkit.php)
2660
-
2661
- Zero (0) not displaying if only thing in table cell or tags e.g. <td>0</td> <p>0</p>
2662
- (Fixed - fn.WriteHTML)
2663
-
2664
- Page Headers/Footers - Simple Headers or Footers defined as e.g. '|{PAGENO}|' were not split into 3 components, but output |6| in the outer margin.
2665
- (Fixed)
2666
-
2667
- Could not copy from a completed PDF doc to clipboard when using a TrueTypeUnicode font
2668
- (Fixed - fn._puttruetypeunicode - added CIDToGIDMap)
2669
-
2670
- Creating an Index (confusing called CreateReference in mPDF) based on only 1 column (i.e. columns off) caused it to print FAIL
2671
- (Fixed - fn. CreateReference())
2672
-
2673
- Table of Contents - If a ToC entry reached other side of page a warning notice was produced
2674
- Fixed - printing is now suppressed and it is moved down a line (but not when using rtl)
2675
-
2676
- "Keep Block Together" (i.e. page-break-inside: avoid for a block element)
2677
- If this property causes some text to be moved to the next page, internal link targets (i.e. <a name="xxx">) were incremented pagenumber by +1 - as this used the calculated document page number, didn't work if using e.g. roman numerals
2678
- (Fixed)
2679
- NB This is now ALWAYS disabled when it meets a table - can use page-break-inside:avoid for the table
2680
-
2681
- @import url(style.css) without quotation marks "" was not picked up, although it is valid HTML
2682
- (Fixed - fn.ReadCSS())
2683
-
2684
- Reading CSS from external style sheets included all media
2685
- Now set by default to ignore media="aural|braille"
2686
- Allows media="print" but can exclude by: $mpdf->disablePrintCSS = true; (default = false)
2687
- Works on both <link... and <style media="print">@import...
2688
- See the web page example - this stops the CSS stylesheets specifically marked for "print" to be ignored
2689
-
2690
- Table borders (in collapsed model) incorrectly calculated which border had dominance (mPDF <=1.3 determined the overriding border by its color)
2691
- (Fixed to follow CSS 2.1 specifications: width >> CSS dominance (cell>table) >> T & L > B & R)
2692
- In the border-collapse=collapse mode, the following rules determine which border style "wins" in case of a conflict:
2693
- 1. Borders with the 'border-style' of 'hidden' take precedence over all other conflicting borders.
2694
- 2. narrow borders are discarded in favor of wider ones.
2695
- 3. styles are preferred in this order: 'double', 'solid', 'dashed', 'dotted', 'ridge', 'outset', 'groove', and the lowest: 'inset'.
2696
- 4. If border styles differ only in color, then a style set on a cell wins over one on a table.
2697
- 5. When two elements of the same type conflict, then the one further to the left or top wins out.
2698
-
2699
- Parsing CSS, a missed level would not be picked up i.e. CSS = div.refstr1 p {...} would not pick up:
2700
- <div class="refstr1"> <div class="another"> <p>...
2701
- (Fixed - fn. MergeCSS by carrying everything forwards)
2702
- Note: I removed - && !$this->blk[$this->blklvl-1]['cascadeCSS']['CLASS>>'.$attr['CLASS']]['depth']
2703
- Not sure why I put it there in the first place!
2704
- In a later bit of function - && $this->blk[$this->blklvl-1]['cascadeCSS'][$tag]['depth']>1
2705
- Haven't removed this, but is it needed???
2706
-
2707
- CSS inline style set in TD/TH (font-size, color, weight, font-family or italic) didn't turn off at the end of the cell (and also formatted the top left cell)
2708
- (Fixed)
2709
-
2710
- CSS properties color, font-weight, and font-style set on a table were not inherited by the table cells
2711
- (Fixed - var $base_table_properties)
2712
-
2713
- When rotating a table, the text following was positioned incorrectly
2714
- (Fixed - fn. printtablebuffer)
2715
-
2716
- When rotating a table, links were not adjusted in position e.g. <a href="">...
2717
- (Fixed - fn. printtablebuffer)
2718
-
2719
- If a larger border-thickness was set for a cell in the middle of a table, cells before that inaccurately calculated the cell wdith needed
2720
- (Fixed)
2721
-
2722
- Text in a table cell which was not in a block and followed a list, there was no line break e.g. </ol>Text following</td>
2723
- (Fixed - var $listjustfinished;)
2724
-
2725
- Setting the default font-family from the body tag using in-line CSS did not work e.g. <body style="font-family:mono"> (did work in external stylesheets)
2726
- (Fixed - fn.WriteHTML)
2727
-
2728
- <link href="..." rel="stylesheet"> was not recognised (because the href comes before the rel)
2729
- (Fixed)
2730
-
2731
- Read linked CSS stylesheet OR @import stylesheet - now includes both.
2732
-
2733
- <tag class="class1 class2"> did not set either class1 or class2. Fixed so that it will now pick out class1 (better than nothing!)
2734
-
2735
- CSS line-height as % - interpreted 120% as 120 (x the font-size) - Fixed so it now accepts % and numbers
2736
-
2737
- Setting the basepath (used for relative links/external stylesheets etc) with $mpdf->setBasePath() was generally buggy!
2738
- Now allows a domain e.g. $mpdf->setBasePath("http://www.domain.com"); (previously needed slash on end)
2739
- (Fixed - hopefully!)
2740
-
2741
- If you were repeatedly calling mPDF in a loop to produce more than one PDF file, it would crash with error: "You have restricted the number of available fonts to 0". Fixed by editing line 751 require(_MPDF_PATH.'mpdf_config.php'); to require(...
2742
-
2743
-
2744
- =============
2745
- Improvements(?)
2746
- =============
2747
- Unsupported image files - mPDF died with an error message if image files didn't meet expected format e.g. an interlaced PNG file
2748
- Changed so images are now replaced by the NOIMG image.
2749
-
2750
- Footer margin (HTML and normal footers) now determines the lowest point that is printed (rather than the place to start printing the footer)
2751
- NB IMPORTANT CHANGE - not backwards comaptible
2752
-
2753
- Tabs in <pre> or <textarea> are now replaced by 8 spaces rather than 6 (consistent with http://www.w3.org/TR/1998/REC-html40-19980424/struct/text.html#edef-PRE) [fn. AdjustHTML() in htmltoolkit.php]
2754
-
2755
- To insert the total number of pages in the document anywhere in the doc, just use '{nb}'
2756
- The line: $mpdf->AliasNbPages();
2757
- has now been uncommented allowing {nb} to be used
2758
- NB This will always give the total no. of pages in the whole document regardless of any changes you have made to page numbering.
2759
- You can change the default placeholder '{nb}' to any string using: $mpdf->AliasNbPages('[**my Chars**]');
2760
-
2761
- $mpdf->AliasNbPageGroups(); default="{nbpg}"
2762
- Can be used to set the total number of pages in the current group i.e. between where page numbering is reset
2763
-
2764
- CSS border correctly fixes "solid 3mm #000000" i.e. (style width color) - (not a bug, but this is often incorrectly specified)
2765
-
2766
- Can now print div background behind a rotated table.
2767
-
2768
- You can keep columns as they are i.e. 1st column will finish page then start on second, by setting
2769
- $mpdf->KeepColumns = true;
2770
-
2771
- Image constrain
2772
- ===============
2773
- Image size is constrained to current margins and page position. Extra parameter added to end of fn. allows you to override this.
2774
- $mpdf->Image('files/images/frontcover.jpg',0,0,210,297,'jpg','',true, false); // e.g. the last "false" allows a full page picture
2775
- Useful for e.g. a cover page for your document
2776
-
2777
- Cumulative CSS
2778
- ==============
2779
- In version <=1.3, if you call:
2780
- $mpdf->WriteHTML($stylesheet,1);
2781
- $mpdf->WriteHTML($html); // this one cleared the array $this->cascadeCSS; conatining cascaded CSS information from stylesheets
2782
- You were meant to call:
2783
- $mpdf->WriteHTML($html,2); // which doesn't re-parse the CSS information
2784
- v2.0 changed so that
2785
- $mpdf->WriteHTML($html); no longers clears the array $this->cascadeCSS and so can be used repeatedly;
2786
-
2787
-
2788
-
2789
- ================================================
2790
- Additional CSSstyles & HTML attributes supported
2791
- ================================================
2792
- <BODY> - font-style, font-weight, color
2793
-
2794
- <IMG> - html attributes width="" and height=""
2795
-
2796
- <TABLE|TD|TH> - border: 'thin' 'medium' and 'thick' are now converted to 1px, 3px and 5px
2797
- <TABLE|TD|TH> - border now respects all types - e.g. 'double', 'solid', 'dashed', 'dotted', 'ridge', 'outset', 'groove', and 'inset'
2798
- (NB mPDF only supports a full declaration of border e.g. "border: thin double #000000;")
2799
-
2800
- <TD|TH> - CSS style="white-space: nowrap" and HTML attribute nowrap="nowrap"
2801
- <TABLE> - page-break-inside: avoid
2802
- <TABLE> - border-collapse: separate|collapse
2803
- <TABLE> - border-spacing: 2px 2px; (horizontal/vertical) or just one figure (both) NB same as cellSpacing
2804
- <TABLE> - empty-cells: hide|show (border-collapse:separate only)
2805
- <TABLE> - margin-left and margin-right (previously only supported top and bottom)
2806
- <TABLE> - padding: (this was incorrectly used for TD/TH before) (border-collapse:separate only)
2807
- <TD|TH> - padding:
2808
- <TABLE|TD|TH> - inline style "background" works (with a color only) the same as "background-color"
2809
-
2810
- NB Table page-break-inside, autosize values and rotate are only respected for that set on first level table of nested tables
2811
-
2812
- <TABLE> - cellSpacing and cellPadding HTML attributes:
2813
- NB cellSpacing is the same as CSS style "border-spacing"
2814
- NB cellPadding is a <table> attribute, but sets the cell padding - not table padding
2815
-
2816
- <TABLE> - align="..." now works with a rotated table - but sets the alignment ignoring the rotation i.e. align=right sets the table to the right side of the page (looking as though it is bottom-aligned)
2817
-
2818
- <BLOCK ELEMENTS> - page-break-before: always|left|right - NB any surrounding block tags will be closed before the new page is inserted.
2819
-
2820
- @page - see notes on Paged Media
2821
-
2822
- ==========================
2823
- Unsupported HTML attribute
2824
- ==========================
2825
- <TD border="1"> - not valid HTML - no longer supported
2826
-
2827
-
2828
- =========
2829
- Additions
2830
- =========
2831
- "Keep-with-table"
2832
- $mpdf->use_kwt = true; // default=false
2833
- If set to true, will force any H1-H6 header immediately preceding a table to be kept together with the table
2834
- - automatically sets the table to fit on one page (i.e. page-break-inside=avoid) if it is a rotated table
2835
- - ignored if: Columns on, Keep-block-together active (page-break-inside=avoid for surrounding BLOCK), active Forms
2836
-
2837
-
2838
- =====
2839
- Notes
2840
- =====
2841
-
2842
- NB Not a change - but note you can use this to allow you to feed html code encoded in other than utf-8:
2843
- $mpdf->allow_charset_conversion=true;
2844
- $mpdf->charset_in='windows-1252'; (needs suitable codes for iconv i.e. windows-1252 not win-1252)
2845
-
2846
- Fixing Optional tags
2847
- ====================
2848
- php.net website has illegal nesting of <dt>.. <dd> .. </dd> .. </dt> and <p>.. <div> .. </div> .. </p>
2849
- The example wich parses the php.net webpage will not show correctly unless you change: $mpdf->allow_html_optional_endtags=false;
2850
- Trying to fix incorrect (X)HTML with $mpdf->allow_html_optional_endtags==true cancels the P when it meets a DIV etc.
2851
-
2852
-
2853
-
2854
- EAN barcode
2855
- ===========
2856
- An EAN barcode can be generated
2857
- function writeBarcode($code, $showisbn=1, $x='', $y='', $size=1, $border=0, $paddingL=1, $paddingR=1, $paddingT=2, $paddingB=2) {
2858
- It accepts 12 or 13 digits with or without - hyphens as $code e.g.
2859
- $mpdf->writeBarcode('978-1234-567-890', 1, $mpdf->x, $mpdf->y);
2860
- NB - IMPORTANT***
2861
- A new font - OCR-B font/unifont is required, and needs to be added to the config.php file
2862
- cf. http://www.gs1uk.org/downloads/bar_code/Bar coding getting it right.pdf
2863
- Barcode size must be between 0.8 and 2.0 (80% to 200%)
2864
-
2865
- CMYK Colors
2866
- ===========
2867
- Functions - SetDrawColor, SetTextColor and SetFillColor all now take an optional 4th parameter.
2868
- If defined this will interpret the input as CMYK color i.e.
2869
- SetDrawColor(15,82,0,10) // NB all values out of 100 - not 255 as for RGB
2870
-
2871
- htmltoolkit.php fn.ConvertColor() - now interprets custom color definition: cmyk(15,82,0,10)
2872
- like rgb(r,g,b) except values out of 100
2873
- Intended to be used for calling the functions separately - BUT works in a limited way with CSS - does not get reset or inherited correctly
2874
- <p style="color:cmyk(215,31,15,10)"> does work
2875
-
2876
-
2877
- DEFAULT CSS
2878
- ===========
2879
- $defaultCSS has been updated to reflect better the standard HTML default e.g. using serif, table borders separate, cell vertical-align top
2880
- To keep mPDF 1.3 (my favourites) I have introduced:
2881
- $mpdf->useDefaultCSS2 = true;
2882
-
2883
-
2884
- ===================================
2885
- Permissions - forms and Annotations - Experimental!
2886
- ===================================
2887
- You can set the Permissions for the PDF file to allow the user to make Comments (annotations)
2888
- $mpdf->setUserRights($enabled=true[default]|false, $annots="/Create/Delete/Modify/Copy/Import/Export",
2889
- $form="/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate", $signature="/Modify") )
2890
-
2891
- If you encrypt the file, make sure the permissions match e.g.:
2892
- $mpdf->setUserRights();
2893
- $mpdf->SetProtection(array('print','annots'),'yourPassword','myPassword');
2894
-
2895
- To allow this, changed the PDF-file version to %PDF1.5 (NB Probably needs PDF version > 1.5 but can't test for this...)
2896
-
2897
- NOTE: If you output the PDF file straight to the browser, it will only allow annotations after you save the document
2898
-
2899
-
2900
- ===========================
2901
- Active Forms - Experimental!
2902
- ===========================
2903
- At present , using active forms will prevent any internal and external links - that appear before active forms(?) - from working (why?)
2904
- May need to save form for proper use - see example, when scroll forwards and back, the form disappears??
2905
- Need to set Userrights (see above), and $mpdf->useActiveForms=true;
2906
- For Output options, see separate notes.
2907
-
2908
-
2909
-
2910
- ============================
2911
- Internal Programming changes
2912
- ============================
2913
- NB fn. tablerotate in htmltoolkit no longer used; now uses a 'transform' to shift the whole block of PDF code
2914
-
2915
- Graphics State
2916
- ==============
2917
- ExtGState does not need to be redefined - e.g. if a watermark added on every page, turning on and off alpha/transparency
2918
- Unnecessary file size.
2919
- function AddExtGState() edited to check if graphics state already exists before adding new one
2920
-
2921
- ASCII-proof code
2922
- ================
2923
- "���" used as a special identifier in the program changed to "\xbb\xa4\xac" to make the mpdf.php script file immune from someone saving it as a utf-8 encoded file
2924
-
2925
- Images
2926
- ======
2927
- 1) When copying remote images locally - incorrectly used "unset" now changed to "unlink"
2928
- 2) When parsing image files - was using CURL for any image src="http://... - even if this was on the local server - edited so it only uses CURL if necessary/appropriate.
2929
- NB Handling images was updated in v1.3 because my ISP changed allow_url_fopen to false
2930
- Fixed so mPDF tests if the file is available as a local call e.g. getimage('images/test.jpg') even if it is defined as a full URI e.g. http://www.mydomain.com/images/test.jpg as this is quicker(?), and permitted even if allow_url_fopen is false.
2931
- If not available as a local file (and allow_url_fopen is set) mPDF tries to use fopen/file_get_contents using an http wrapper;
2932
- Else, if CURL is available and allow_url_fopen is false: then tries using CURL.
2933
- (Clear as mud???!!)
2934
-
2935
-
2936
- ===========================
2937
- mPDF v1.3 (21/09/2008)
2938
- ===========================
2939
- --------------
2940
- Page Numbering
2941
- --------------
2942
- Program changes:
2943
- fn. startPageNums() replaced with blank function
2944
- fn. stopPageNums() - deleted
2945
- fn. numPageNo() - deleted (all it did was return this->page anyway).
2946
- var $_numbering - deleted
2947
- var $_numberingFooter - deleted
2948
- var $_numPageNum - deleted
2949
-
2950
- NEW
2951
- New: fn. AddPages() (as for AddPage but with type=NEXT-ODD or NEXT-EVEN see below)
2952
- Edited: fn. AddPage() - new parameters added
2953
- AddPage(orientation(NO),type="E|O", resetpagenum="1|0", pagenumstyle="I|i|A|a|1", suppress="on|off")
2954
- New: fn. docPageNum() - returns the document page number (or '') based on...
2955
- New : PageNumSubstitutions(array)
2956
- New attributes:
2957
- <pagebreak resetpagenum="1" // resets document page numbering to 1 from the new page onwards
2958
- <pagebreak suppress="on" // turns on suppression of page numbering i.e. in headers and footers, {PAGENO} is replaced by blank string
2959
- // ="0" turns suppression off
2960
- <pagebreak pagenumstyle="I|i|A|a|1" // (re)sets page number stle/type from the new page onwards - as for lists
2961
- // 1 - decimal; A/a - alpha (uppercase/lowercase); I/i - Roman (uppercase/lowercase)
2962
- <pagebreak type="NEXT-ODD" // always adds a page + another if required to make odd
2963
- <pagebreak type="NEXT-EVEN" // always adds a page + another if required to make even
2964
-
2965
- Edited: fn. TOC() // sets the marker for a Table of Contents
2966
- New parameters allow the page-numbering details to be set
2967
- NB the page-numbering details set are for the page which follows on after the TOC marker is inserted. The page-numbering for the actual ToC is set later, when the ToC is generated and inserted here
2968
- new parameters as above for pagebreak resetpagenum="1|0", pagenumstyle="I|i|A|a|1", suppress="on|off"
2969
-
2970
- Can also be set by attribute in the <TOC>
2971
- <TOC resetpagenum="1" pagenumstyle="I|i|A|a|1", suppress="on|off" />
2972
-
2973
- --------------------------------------------
2974
- Changes to allow Rotated Text in table Cells
2975
- --------------------------------------------
2976
- Edited:
2977
- fn. OpenTag()
2978
- fn. _tableColumnWidth()
2979
- fn. _tableHeight()
2980
- fn. _tableWrite()
2981
- fn. tableHeader()
2982
-
2983
- New custom style or attribute -- "text-rotate" -- can be set for either <tr> or <th|td>
2984
- Allowed values: 45 - 90 (written as integers) - rotates text anticlockwise, and -90 (clockwise)
2985
- Positive values less than 90 force cell to: vertical-align:bottom
2986
-
2987
- Limitations:
2988
- Only allows single line of text;
2989
- Font, font-size, and style are determined by those set fro the cell, and cannot be changed;
2990
- No changes in font (or any other in-line changes e.g. <sup>) are supported within the text
2991
-
2992
- Example: <tr style="text-rotate:90">...
2993
-
2994
- ---------
2995
- Bug fixes
2996
- ---------
2997
- 1) HTML footer containing table was triggering page break.
2998
- Added $this->InHTMLFooter as flag to prevent page triggering in footers containing table
2999
- Set in fn.writeHTMLFooters() -> in fn.tableWrite() stops the pageBreak being reset
3000
-
3001
- 2) Crashing when libcurl not installed.
3002
- Edited OpenTag() curl_init - added if (function_exists) to exclude crash when libcurl not installed
3003
-
3004
- 3) Single cell with borders not showing the borders.
3005
- e.g. <table><tr><td style="border:1px solid #000000?>Hi</td></tr></table>
3006
- Problem: mPDF overrides cell border properties with table border properties for external borders. $defaultCSS had CSS defined for table as '0px solid #000000'
3007
- Quick fix - line 273 removed. A more complete fix will require reprogramming to distinguish between "border property not set" and border property set as "none".
3008
-
3009
- 4) Empty textarea incorrectly handled (the following HTML code being output in the textarea)
3010
- The html code for an empty textarea was incorrectly handled in htmltoolkit fn. AdjustHTML which has been edited
3011
-
3012
-
3013
- ===========================
3014
- mPDF v1.2 (2008-05-01)
3015
- ===========================
3016
- // Added v1.2 option to continue if invalid UTF-8 chars - used in function is_utf8()
3017
- var $ignore_invalid_utf8 = false;
3018
-
3019
- Reading CSS in fn. ReadCSS() and applying in fn. MergeCSS() -
3020
- Edited to allow Tags, class and id with the same name to be distinct i.e. h5 {...} .h5 {...} #h5 {...}
3021
- * mPDF 1.2 This version supports: .class {...} / #id { .... }
3022
- * ADDED p {...} h1[-h6] {...} a {...} table {...} thead {...} th {...} td {...} hr {...}
3023
- * body {...} sets default font and fontsize
3024
- * It supports some cascaded CSS e.g. div.topic table.type1 td
3025
- * Does not support non-block level e.g. a#hover { ... }
3026
-
3027
- Table: font-size, weight, style, family and color should all work
3028
- TD/TH: font-size, weight, style, family and color should all work
3029
-
3030
- Added to htmltoolkit - fn.array_merge_recursive_unique()
3031
-
3032
- memory_opt Removed in mPDF v1.2 - not working properly
3033
-
3034
- fn. _begindoc() - changed to %PDF1.4 (was 1.3) as PDF version
3035
-
3036
- Write HTML Headers and Footers
3037
- ------------------------------
3038
- fn. Close() - calls writeHTMLHeaders/Footers() before finishing doc
3039
- fn. WriteHTML() - added parameter
3040
- fn. _out - writes to outputbuffer when writing HTML footers/headers
3041
-
3042
- New
3043
- fn. writeHTMLHeaders()
3044
- fn. writeHTMLFooters()
3045
-
3046
-
3047
-
3048
-
3049
- =======================
3050
- mPDF v1.1 (2008-05-01)
3051
- =======================
3052
-
3053
- Programming changes to increase efficiency
3054
- ------------------------------------------
3055
- fn. WriteHTML() - added lines to combine substituted characters <tta> etc
3056
-
3057
- Memory Optimization added (script from FPDF site) - edited fn. _putpages() and fn. _endpage()
3058
-
3059
- fn. SetFont() edited to return val quicker if font already set (increase efficiency)
3060
-
3061
- new vars chrs and ords are used to store chr() and ord() - quicker than using functions
3062
-
3063
- fn.setMBencoding() - only call mb_internal_encoding if need to change
3064
-
3065
- Bugs
3066
- ----
3067
- fn. SetDefaultFontSize() - edited to allow to override that set in defaultCSS
3068
-
3069
- fn. Output() - Added temporary(?) disablement of encryption in CJK as it doesn't work!
3070
-
3071
- fn. OpenTag() [LI] $this->blockjustfinished=false to prevents newline after first bullet of list within table
3072
-
3073
- Uses of mb_ereg_replace removed, and mb_split changed - requires regex_encoding (regex_encoding only used as UTF-8)
3074
-
3075
- fn. WriteHTML: attributes are trimmed with trim() to allow correct handling of e.g. class="bpmBook "
3076
-
3077
- fn. printbuffer() and fn. openTag() to ensure
3078
- <div><div><p> outputs top margins/padding for both 1st and 2nd div
3079
- and </p></div></div> ...
3080
-
3081
- fn. SetFont() added line - bug fixing in CJK fonts
3082
-
3083
- CSS functionality
3084
- -----------------
3085
- Added special CSS 'thead-underline' (similar to topntail)
3086
-
3087
- var $thead_font_weight; added (openTag) to enable setting of font-weight for <TH> cells
3088
-
3089
- Fixed table border inheritance: Table border inherits border="1" to cells, but not table style="border..."
3090
-
3091
- "page-break-inside: avoid" added (var keep_block_together) to allow a DIV or P to be kept on one page
3092
- - not compatible with table autosize or table rotate
3093
- - only works over maximum of 2 pages
3094
-
3095
- Enhancements
3096
- ------------
3097
- Orphans in line justification: R. Bracket ) added to defined list of orphans
3098
-
3099
- allow_url_open
3100
- --------------
3101
- Following a change in the PHP ini config set on my website by my ISP, changes made to allow mPDF to work with allow_url_open=OFF.
3102
- - file_get_contents() changed to use libcurl (for CSS files)
3103
- - openTag('IMG') @fopen() and 3 functions _parsegif, _parseJPG, _parsePNG, edited to copy remote image files to local file to include images
3104
-
3105
- FlowChart
3106
- ---------
3107
- Changes to enable mPDF work with a custom script producing Flowcharts:
3108
- - WriteHTML() second parameter=3 will allow HTML to be parsed but not output
3109
- - fn. Arrow() added
3110
- - TableWordWrap() added parameter to force array return
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/mpdf/CREDITS.txt DELETED
@@ -1,92 +0,0 @@
1
-
2
-
3
- /*******************************************************************************
4
- * Software: FPDF *
5
- * Version: 1.53 *
6
- * Date: 2004-12-31 *
7
- * Author: Olivier PLATHEY *
8
- * License: Freeware *
9
- * *
10
- * You may use and modify this software as you wish. *
11
- *******************************************************************************/
12
-
13
- /*******************************************************************************
14
- * HTML2FPDF is a php script to read a HTML text and generate a PDF file. *
15
- * Copyright (C) 2004-2005 Renato Coelho *
16
- * *
17
- * html2fpdf.php, htmltoolkit.php *
18
- *******************************************************************************/
19
-
20
- CREDITS From HTML2FPDF:
21
-
22
- -Olivier Plathey for the fpdf.php class [http://www.fpdf.org]
23
- -Damon Kohler for the Flowing Block script [mailto:damonkohler@yahoo.com]
24
- -Cl�ment Lavoillotte for HTML-oriented FPDF idea
25
- -Yamasoft for the gif.php class [http://www.yamasoft.com/]
26
- -J�r�me Fenal for the _parsegif() function
27
- -"VIETCOM" for the PDFTable code [http://www.freepgs.com/vietcom/tool/pdftable/] [mailto:vncommando@yahoo.com]
28
- -Yukihiro O. for the SetDash() function [mailto:yukihiro_o@infoseek.jp]
29
- -Ron Korving for the WordWrap() function
30
- -Michel Poulain for the DisplayPreferences() function
31
- -Patrick Benny for the MultiCellBlt() function idea [no longer in use]
32
- -Seb for the _SetTextRendering() and SetTextOutline() functions [mailto:captainseb@wanadoo.fr]
33
- -MorphSoft for the colornames list idea
34
- -W3SCHOOLS for HTML-related reference info [http://www.w3schools.com/]
35
-
36
-
37
-
38
- /****************************************************************************
39
- * Software: FPDF_Protection *
40
- * Version: 1.02 *
41
- * Date: 2005/05/08 *
42
- * Author: Klemen VODOPIVEC *
43
- * License: Freeware *
44
- * *
45
- * You may use and modify this software as you wish as stated in original *
46
- * FPDF package. *
47
- ****************************************************************************/
48
-
49
- /****************************************************************************
50
- // FPDI - Version 1.2
51
- //
52
- // Copyright 2004-2007 Setasign - Jan Slabon
53
- //
54
- // Licensed under the Apache License, Version 2.0 (the "License");
55
- // you may not use this file except in compliance with the License.
56
- // You may obtain a copy of the License at
57
- //
58
- // http://www.apache.org/licenses/LICENSE-2.0
59
- //
60
- // Unless required by applicable law or agreed to in writing, software
61
- // distributed under the License is distributed on an "AS IS" BASIS,
62
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
63
- // See the License for the specific language governing permissions and
64
- // limitations under the License.
65
- ****************************************************************************/
66
-
67
- /****************************************************************************
68
- * @copyright Khaled Al-Shamaa 2008
69
- * @link http://www.ar-php.org
70
- * @author Khaled Al-Shamaa <khaled@ar-php.org>
71
- * @desc Set of PHP5 / UTF-8 Classes developed to enhance Arabic web
72
- * applications by providing set of tools includes stem-based searching,
73
- * translitiration, soundex, Hijri calendar, charset detection and
74
- * converter, spell numbers, keyboard language, Muslim prayer time,
75
- * auto-summarization, and more...
76
- * @package Arabic
77
- *
78
- * @version 1.8 released in Feb 15, 2009
79
- *
80
- * @license LGPL
81
- ****************************************************************************/
82
-
83
-
84
- This library is free software; you can redistribute it and/or
85
- modify it under the terms of the GNU Lesser General Public
86
- License as published by the Free Software Foundation;
87
- This library is distributed in the hope that it will be useful,
88
- but WITHOUT ANY WARRANTY; without even the implied warranty of
89
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
90
- Lesser General Public License for more details.
91
- [http://www.opensource.org/licenses/lgpl-license.php]
92
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/mpdf/LICENSE.txt DELETED
@@ -1,340 +0,0 @@
1
- GNU GENERAL PUBLIC LICENSE
2
- Version 2, June 1991
3
-
4
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5
- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
6
- Everyone is permitted to copy and distribute verbatim copies
7
- of this license document, but changing it is not allowed.
8
-
9
- Preamble
10
-
11
- The licenses for most software are designed to take away your
12
- freedom to share and change it. By contrast, the GNU General Public
13
- License is intended to guarantee your freedom to share and change free
14
- software--to make sure the software is free for all its users. This
15
- General Public License applies to most of the Free Software
16
- Foundation's software and to any other program whose authors commit to
17
- using it. (Some other Free Software Foundation software is covered by
18
- the GNU Library General Public License instead.) You can apply it to
19
- your programs, too.
20
-
21
- When we speak of free software, we are referring to freedom, not
22
- price. Our General Public Licenses are designed to make sure that you
23
- have the freedom to distribute copies of free software (and charge for
24
- this service if you wish), that you receive source code or can get it
25
- if you want it, that you can change the software or use pieces of it
26
- in new free programs; and that you know you can do these things.
27
-
28
- To protect your rights, we need to make restrictions that forbid
29
- anyone to deny you these rights or to ask you to surrender the rights.
30
- These restrictions translate to certain responsibilities for you if you
31
- distribute copies of the software, or if you modify it.
32
-
33
- For example, if you distribute copies of such a program, whether
34
- gratis or for a fee, you must give the recipients all the rights that
35
- you have. You must make sure that they, too, receive or can get the
36
- source code. And you must show them these terms so they know their
37
- rights.
38
-
39
- We protect your rights with two steps: (1) copyright the software, and
40
- (2) offer you this license which gives you legal permission to copy,
41
- distribute and/or modify the software.
42
-
43
- Also, for each author's protection and ours, we want to make certain
44
- that everyone understands that there is no warranty for this free
45
- software. If the software is modified by someone else and passed on, we
46
- want its recipients to know that what they have is not the original, so
47
- that any problems introduced by others will not reflect on the original
48
- authors' reputations.
49
-
50
- Finally, any free program is threatened constantly by software
51
- patents. We wish to avoid the danger that redistributors of a free
52
- program will individually obtain patent licenses, in effect making the
53
- program proprietary. To prevent this, we have made it clear that any
54
- patent must be licensed for everyone's free use or not licensed at all.
55
-
56
- The precise terms and conditions for copying, distribution and
57
- modification follow.
58
-
59
- GNU GENERAL PUBLIC LICENSE
60
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
-
62
- 0. This License applies to any program or other work which contains
63
- a notice placed by the copyright holder saying it may be distributed
64
- under the terms of this General Public License. The "Program", below,
65
- refers to any such program or work, and a "work based on the Program"
66
- means either the Program or any derivative work under copyright law:
67
- that is to say, a work containing the Program or a portion of it,
68
- either verbatim or with modifications and/or translated into another
69
- language. (Hereinafter, translation is included without limitation in
70
- the term "modification".) Each licensee is addressed as "you".
71
-
72
- Activities other than copying, distribution and modification are not
73
- covered by this License; they are outside its scope. The act of
74
- running the Program is not restricted, and the output from the Program
75
- is covered only if its contents constitute a work based on the
76
- Program (independent of having been made by running the Program).
77
- Whether that is true depends on what the Program does.
78
-
79
- 1. You may copy and distribute verbatim copies of the Program's
80
- source code as you receive it, in any medium, provided that you
81
- conspicuously and appropriately publish on each copy an appropriate
82
- copyright notice and disclaimer of warranty; keep intact all the
83
- notices that refer to this License and to the absence of any warranty;
84
- and give any other recipients of the Program a copy of this License
85
- along with the Program.
86
-
87
- You may charge a fee for the physical act of transferring a copy, and
88
- you may at your option offer warranty protection in exchange for a fee.
89
-
90
- 2. You may modify your copy or copies of the Program or any portion
91
- of it, thus forming a work based on the Program, and copy and
92
- distribute such modifications or work under the terms of Section 1
93
- above, provided that you also meet all of these conditions:
94
-
95
- a) You must cause the modified files to carry prominent notices
96
- stating that you changed the files and the date of any change.
97
-
98
- b) You must cause any work that you distribute or publish, that in
99
- whole or in part contains or is derived from the Program or any
100
- part thereof, to be licensed as a whole at no charge to all third
101
- parties under the terms of this License.
102
-
103
- c) If the modified program normally reads commands interactively
104
- when run, you must cause it, when started running for such
105
- interactive use in the most ordinary way, to print or display an
106
- announcement including an appropriate copyright notice and a
107
- notice that there is no warranty (or else, saying that you provide
108
- a warranty) and that users may redistribute the program under
109
- these conditions, and telling the user how to view a copy of this
110
- License. (Exception: if the Program itself is interactive but
111
- does not normally print such an announcement, your work based on
112
- the Program is not required to print an announcement.)
113
-
114
- These requirements apply to the modified work as a whole. If
115
- identifiable sections of that work are not derived from the Program,
116
- and can be reasonably considered independent and separate works in
117
- themselves, then this License, and its terms, do not apply to those
118
- sections when you distribute them as separate works. But when you
119
- distribute the same sections as part of a whole which is a work based
120
- on the Program, the distribution of the whole must be on the terms of
121
- this License, whose permissions for other licensees extend to the
122
- entire whole, and thus to each and every part regardless of who wrote it.
123
-
124
- Thus, it is not the intent of this section to claim rights or contest
125
- your rights to work written entirely by you; rather, the intent is to
126
- exercise the right to control the distribution of derivative or
127
- collective works based on the Program.
128
-
129
- In addition, mere aggregation of another work not based on the Program
130
- with the Program (or with a work based on the Program) on a volume of
131
- a storage or distribution medium does not bring the other work under
132
- the scope of this License.
133
-
134
- 3. You may copy and distribute the Program (or a work based on it,
135
- under Section 2) in object code or executable form under the terms of
136
- Sections 1 and 2 above provided that you also do one of the following:
137
-
138
- a) Accompany it with the complete corresponding machine-readable
139
- source code, which must be distributed under the terms of Sections
140
- 1 and 2 above on a medium customarily used for software interchange; or,
141
-
142
- b) Accompany it with a written offer, valid for at least three
143
- years, to give any third party, for a charge no more than your
144
- cost of physically performing source distribution, a complete
145
- machine-readable copy of the corresponding source code, to be
146
- distributed under the terms of Sections 1 and 2 above on a medium
147
- customarily used for software interchange; or,
148
-
149
- c) Accompany it with the information you received as to the offer
150
- to distribute corresponding source code. (This alternative is
151
- allowed only for noncommercial distribution and only if you
152
- received the program in object code or executable form with such
153
- an offer, in accord with Subsection b above.)
154
-
155
- The source code for a work means the preferred form of the work for
156
- making modifications to it. For an executable work, complete source
157
- code means all the source code for all modules it contains, plus any
158
- associated interface definition files, plus the scripts used to
159
- control compilation and installation of the executable. However, as a
160
- special exception, the source code distributed need not include
161
- anything that is normally distributed (in either source or binary
162
- form) with the major components (compiler, kernel, and so on) of the
163
- operating system on which the executable runs, unless that component
164
- itself accompanies the executable.
165
-
166
- If distribution of executable or object code is made by offering
167
- access to copy from a designated place, then offering equivalent
168
- access to copy the source code from the same place counts as
169
- distribution of the source code, even though third parties are not
170
- compelled to copy the source along with the object code.
171
-
172
- 4. You may not copy, modify, sublicense, or distribute the Program
173
- except as expressly provided under this License. Any attempt
174
- otherwise to copy, modify, sublicense or distribute the Program is
175
- void, and will automatically terminate your rights under this License.
176
- However, parties who have received copies, or rights, from you under
177
- this License will not have their licenses terminated so long as such
178
- parties remain in full compliance.
179
-
180
- 5. You are not required to accept this License, since you have not
181
- signed it. However, nothing else grants you permission to modify or
182
- distribute the Program or its derivative works. These actions are
183
- prohibited by law if you do not accept this License. Therefore, by
184
- modifying or distributing the Program (or any work based on the
185
- Program), you indicate your acceptance of this License to do so, and
186
- all its terms and conditions for copying, distributing or modifying
187
- the Program or works based on it.
188
-
189
- 6. Each time you redistribute the Program (or any work based on the
190
- Program), the recipient automatically receives a license from the
191
- original licensor to copy, distribute or modify the Program subject to
192
- these terms and conditions. You may not impose any further
193
- restrictions on the recipients' exercise of the rights granted herein.
194
- You are not responsible for enforcing compliance by third parties to
195
- this License.
196
-
197
- 7. If, as a consequence of a court judgment or allegation of patent
198
- infringement or for any other reason (not limited to patent issues),
199
- conditions are imposed on you (whether by court order, agreement or
200
- otherwise) that contradict the conditions of this License, they do not
201
- excuse you from the conditions of this License. If you cannot
202
- distribute so as to satisfy simultaneously your obligations under this
203
- License and any other pertinent obligations, then as a consequence you
204
- may not distribute the Program at all. For example, if a patent
205
- license would not permit royalty-free redistribution of the Program by
206
- all those who receive copies directly or indirectly through you, then
207
- the only way you could satisfy both it and this License would be to
208
- refrain entirely from distribution of the Program.
209
-
210
- If any portion of this section is held invalid or unenforceable under
211
- any particular circumstance, the balance of the section is intended to
212
- apply and the section as a whole is intended to apply in other
213
- circumstances.
214
-
215
- It is not the purpose of this section to induce you to infringe any
216
- patents or other property right claims or to contest validity of any
217
- such claims; this section has the sole purpose of protecting the
218
- integrity of the free software distribution system, which is
219
- implemented by public license practices. Many people have made
220
- generous contributions to the wide range of software distributed
221
- through that system in reliance on consistent application of that
222
- system; it is up to the author/donor to decide if he or she is willing
223
- to distribute software through any other system and a licensee cannot
224
- impose that choice.
225
-
226
- This section is intended to make thoroughly clear what is believed to
227
- be a consequence of the rest of this License.
228
-
229
- 8. If the distribution and/or use of the Program is restricted in
230
- certain countries either by patents or by copyrighted interfaces, the
231
- original copyright holder who places the Program under this License
232
- may add an explicit geographical distribution limitation excluding
233
- those countries, so that distribution is permitted only in or among
234
- countries not thus excluded. In such case, this License incorporates
235
- the limitation as if written in the body of this License.
236
-
237
- 9. The Free Software Foundation may publish revised and/or new versions
238
- of the General Public License from time to time. Such new versions will
239
- be similar in spirit to the present version, but may differ in detail to
240
- address new problems or concerns.
241
-
242
- Each version is given a distinguishing version number. If the Program
243
- specifies a version number of this License which applies to it and "any
244
- later version", you have the option of following the terms and conditions
245
- either of that version or of any later version published by the Free
246
- Software Foundation. If the Program does not specify a version number of
247
- this License, you may choose any version ever published by the Free Software
248
- Foundation.
249
-
250
- 10. If you wish to incorporate parts of the Program into other free
251
- programs whose distribution conditions are different, write to the author
252
- to ask for permission. For software which is copyrighted by the Free
253
- Software Foundation, write to the Free Software Foundation; we sometimes
254
- make exceptions for this. Our decision will be guided by the two goals
255
- of preserving the free status of all derivatives of our free software and
256
- of promoting the sharing and reuse of software generally.
257
-
258
- NO WARRANTY
259
-
260
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
- FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
- OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
- PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
- OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
- TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
- PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
- REPAIR OR CORRECTION.
269
-
270
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
- WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
- REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
- INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
- OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
- TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
- YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
- PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
- POSSIBILITY OF SUCH DAMAGES.
279
-
280
- END OF TERMS AND CONDITIONS
281
-
282
- How to Apply These Terms to Your New Programs
283
-
284
- If you develop a new program, and you want it to be of the greatest
285
- possible use to the public, the best way to achieve this is to make it
286
- free software which everyone can redistribute and change under these terms.
287
-
288
- To do so, attach the following notices to the program. It is safest
289
- to attach them to the start of each source file to most effectively
290
- convey the exclusion of warranty; and each file should have at least
291
- the "copyright" line and a pointer to where the full notice is found.
292
-
293
- <one line to give the program's name and a brief idea of what it does.>
294
- Copyright (C) <year> <name of author>
295
-
296
- This program is free software; you can redistribute it and/or modify
297
- it under the terms of the GNU General Public License as published by
298
- the Free Software Foundation; either version 2 of the License, or
299
- (at your option) any later version.
300
-
301
- This program is distributed in the hope that it will be useful,
302
- but WITHOUT ANY WARRANTY; without even the implied warranty of
303
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
- GNU General Public License for more details.
305
-
306
- You should have received a copy of the GNU General Public License
307
- along with this program; if not, write to the Free Software
308
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
309
-
310
-
311
- Also add information on how to contact you by electronic and paper mail.
312
-
313
- If the program is interactive, make it output a short notice like this
314
- when it starts in an interactive mode:
315
-
316
- Gnomovision version 69, Copyright (C) year name of author
317
- Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
318
- This is free software, and you are welcome to redistribute it
319
- under certain conditions; type `show c' for details.
320
-
321
- The hypothetical commands `show w' and `show c' should show the appropriate
322
- parts of the General Public License. Of course, the commands you use may
323
- be called something other than `show w' and `show c'; they could even be
324
- mouse-clicks or menu items--whatever suits your program.
325
-
326
- You should also get your employer (if you work as a programmer) or your
327
- school, if any, to sign a "copyright disclaimer" for the program, if
328
- necessary. Here is a sample; alter the names:
329
-
330
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
331
- `Gnomovision' (which makes passes at compilers) written by James Hacker.
332
-
333
- <signature of Ty Coon>, 1 April 1989
334
- Ty Coon, President of Vice
335
-
336
- This General Public License does not permit incorporating your program into
337
- proprietary programs. If your program is a subroutine library, you may
338
- consider it more useful to permit linking proprietary applications with the
339
- library. If this is what you want to do, use the GNU Library General
340
- Public License instead of this License.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/mpdf/README.txt DELETED
@@ -1,130 +0,0 @@
1
- Installation
2
- ============
3
- * Download the .zip file and unzip it
4
- * Create a folder e.g. /mpdf on your server
5
- * Upload all of the files to the server, maintaining the folders as they are
6
- * Ensure that you have write permissions set (CHMOD 6xx or 7xx) for the following folders:
7
- /ttfontdata/ - used to cache font data; improves performance a lot
8
- /tmp/ - used for some images and ProgressBar
9
- /graph_cache/ - if you are using JpGraph in conjunction with mPDF
10
-
11
- To test the installation, point your browser to the basic example file : [path_to_mpdf_folder]/mpdf/examples/example01_basic.php
12
-
13
- If you wish to define a different folder for temporary files rather than /tmp/ see the note on 'Folder for temporary files' in
14
- the section on Installation & Setup in the manual (http://mpdf1.com/manual/).
15
-
16
- If you have problems, please read the section on troubleshooting in the manual.
17
-
18
-
19
- Fonts
20
- =====
21
- Let us refer to font names in 2 ways:
22
- "CSS font-family name" - mPDF is designed primarily to read HTML and CSS. This is the name used in CSS e.g.
23
- <p style="font-family: 'Trebuchet MS';">
24
-
25
- "mPDF font-family name" - the name used internally to process fonts. This could be anything you like,
26
- but by default mPDF will convert CSS font-family names by removing any spaces and changing
27
- to lowercase. Reading the name above, mPDF will look for a "mPDF font-family name" of
28
- 'trebuchetms'.
29
-
30
- The configurable values referred to below are set in the config_fonts.php file
31
-
32
- When parsing HTML/CSS, mPDF will read the CSS font-family name (e.g. 'Trebuchet MS') and convert
33
- by removing any spaces and changing to lowercase, to look for a mPDF font-family name (trebuchetms).
34
-
35
- Next it will look for a translation (if set) in config_font.php e.g.:
36
- $this->fonttrans = array(
37
- 'trebuchetms' => 'trebuchet'
38
- )
39
-
40
- Now the mPDF font-family name to be used is 'trebuchet'
41
-
42
- If you wish to make this font available, you need to specify the Truetype .ttf font files for each variant.
43
- These should be defined in config_font.php in the array:
44
- $this->fontdata = array(
45
- "trebuchet" => array(
46
- 'R' => "trebuc.ttf",
47
- 'B' => "trebucbd.ttf",
48
- 'I' => "trebucit.ttf",
49
- 'BI' => "trebucbi.ttf",
50
- )
51
- )
52
-
53
- This is the array which determines whether a font is available to mPDF. Each font-family must have a
54
- Regular ['R'] file defined - the others (bold, italic, bold-italic) are optional.
55
-
56
- mPDF will try to load the font-file. If you have defined _MPDF_SYSTEM_TTFONTS at the top of the
57
- config_fonts.php file, it will first look for the font-file there. This is useful if you are running
58
- mPDF on a computer which already has a folder with TTF fonts in (e.g. on Windows)
59
-
60
- If the font-file is not there, or _MPDF_SYSTEM_TTFONTS is not defined, mPDF will look in the folder
61
- /[your_path_to_mpdf]/ttfonts/
62
-
63
- Note that the font-file names are case-sensitive and can contain capitals.
64
-
65
- If the folder /ttfontdata/ is writeable (CHMOD 644 or 755), mPDF will save files there which it can
66
- re-use next time it accesses a particular font. This will significantly improve processing time
67
- and is strongly recommended.
68
-
69
- mPDF should be able to read most TrueType Unicode font files with a .ttf extension
70
- Truetype fonts with .otf extension that are OpenType also work OK.
71
- TrueType collections (.ttc) will also work if they contain TrueType Unicode fonts.
72
-
73
-
74
- Character substitution
75
- ----------------------
76
- Most people will have access to a Pan-Unicode font with most Unicode characters in it such as
77
- Arial Unicode MS. Set $this->backupSubsFont = array('arialunicodems'); at the top of the config_fonts.php file
78
- to use this font when substituting any characters not found in the specific font being used.
79
-
80
- Example:
81
- You can set $mpdf->useSubstitutions = true; at runtime
82
- or $this->useSubstitutions = true; in the config.php file
83
-
84
- <p style="font-family: 'Comic Sans MS'">This text contains a Thai character &#3617; which does not exist
85
- in the Comic Sans MS font file</p>
86
-
87
- When useSubstitutions is true, mPDF will try to find substitutions for any missing characters:
88
- 1) firstly looks if the character is available in the inbuilt Symbols or ZapfDingbats fonts;
89
- 2) [If defined] looks in each of the the font(s) set by $this->backupSubsFont array
90
-
91
- NB There is an increase in processing time when using substitutions, and even more so if
92
- a backupSubsFont is defined.
93
-
94
- Controlling mPDF mode
95
- =====================
96
- The first parameter of new mPDF('') works as follows:
97
- new mPDF('c') - forces mPDF to only use the built-in [c]ore Adobe fonts (Helvetica, Times etc)
98
-
99
- new mPDF('') - default - font subsetting behaviour is determined by the configurable variables
100
- $this->maxTTFFilesize and $this->percentSubset (see below)
101
- Default values are set so that: 1) very large font files are always subset
102
- 2) Fonts are embedded as subsets if < 30% of the characters are used
103
-
104
- new mPDF('..+aCJK') new mPDF('+aCJK')
105
- new mPDF('..-aCJK') new mPDF('-aCJK')
106
- - used optionally together with a language or language/country code, +aCJK will force mPDF
107
- to use the Adobe non-embedded CJK fonts when a passage is marked with e.g. "lang: ja"
108
- This can be used at runtime to override the value set for $mpdf->useAdobeCJK in config.php
109
- Use in conjunction with settings in config_cp.php
110
-
111
- For backwards compatibility, new mPDF('-s') and new mPDF('s') will force subsetting by
112
- setting $this->percentSubset=100
113
- new mPDF('utf-8-s') and new mPDF('ar-s') are also recognised
114
-
115
-
116
-
117
-
118
- Configuration variables changed
119
- ===============================
120
- Configuration variables are documented in the on-line manual (http://mpdf1.com/manual/).
121
-
122
-
123
- Font folders
124
- ============
125
- If you wish to define your own font file folders (perhaps to share),
126
- you can define the 2 constants in your script before including the mpdf.php script e.g.:
127
-
128
- define('_MPDF_TTFONTPATH','your_path/ttfonts/');
129
- define('_MPDF_TTFONTDATAPATH','your_path/ttfontdata/'); // should be writeable
130
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/mpdf/classes/barcode.php DELETED
@@ -1,1972 +0,0 @@
1
- <?php
2
-
3
- // Adapted for mPDF from TCPDF barcode. Original Details left below.
4
-
5
- //============================================================+
6
- // File name : barcodes.php
7
- // Begin : 2008-06-09
8
- // Last Update : 2009-04-15
9
- // Version : 1.0.008
10
- // License : GNU LGPL (http://www.gnu.org/copyleft/lesser.html)
11
- // ----------------------------------------------------------------------------
12
- // Copyright (C) 2008-2009 Nicola Asuni - Tecnick.com S.r.l.
13
- //
14
- // This program is free software: you can redistribute it and/or modify
15
- // it under the terms of the GNU Lesser General Public License as published by
16
- // the Free Software Foundation, either version 2.1 of the License, or
17
- // (at your option) any later version.
18
- //
19
- // This program is distributed in the hope that it will be useful,
20
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
21
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
- // GNU Lesser General Public License for more details.
23
- //
24
- // You should have received a copy of the GNU Lesser General Public License
25
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
26
- //
27
- // See LICENSE.TXT file for more information.
28
- // ----------------------------------------------------------------------------
29
- //
30
- // Description : PHP class to creates array representations for
31
- // common 1D barcodes to be used with TCPDF.
32
- //
33
- // Author: Nicola Asuni
34
- //
35
- // (c) Copyright:
36
- // Nicola Asuni
37
- // Tecnick.com S.r.l.
38
- // Via della Pace, 11
39
- // 09044 Quartucciu (CA)
40
- // ITALY
41
- // www.tecnick.com
42
- // info@tecnick.com
43
- //============================================================+
44
-
45
- class PDFBarcode {
46
-
47
- protected $barcode_array;
48
- protected $gapwidth;
49
- protected $print_ratio;
50
- protected $daft;
51
-
52
- public function __construct() {
53
-
54
- }
55
-
56
- public function getBarcodeArray($code, $type, $pr='') {
57
- $this->setBarcode($code, $type, $pr);
58
- return $this->barcode_array;
59
- }
60
- public function getChecksum($code, $type) {
61
- $this->setBarcode($code, $type);
62
- if (!$this->barcode_array) { return ''; }
63
- else { return $this->barcode_array['checkdigit']; }
64
- }
65
-
66
- public function setBarcode($code, $type, $pr='') {
67
- $this->print_ratio = 1;
68
- switch (strtoupper($type)) {
69
- case 'ISBN':
70
- case 'ISSN':
71
- case 'EAN13': { // EAN 13
72
- $arrcode = $this->barcode_eanupc($code, 13);
73
- $arrcode['lightmL'] = 11; // LEFT light margin = x X-dim (http://www.gs1uk.org)
74
- $arrcode['lightmR'] = 7; // RIGHT light margin = x X-dim (http://www.gs1uk.org)
75
- $arrcode['nom-X'] = 0.33; // Nominal value for X-dim in mm (http://www.gs1uk.org)
76
- $arrcode['nom-H'] = 25.93; // Nominal bar height in mm incl. numerals (http://www.gs1uk.org)
77
- break;
78
- }
79
- case 'UPCA': { // UPC-A
80
- $arrcode = $this->barcode_eanupc($code, 12);
81
- $arrcode['lightmL'] = 9; // LEFT light margin = x X-dim (http://www.gs1uk.org)
82
- $arrcode['lightmR'] = 9; // RIGHT light margin = x X-dim (http://www.gs1uk.org)
83
- $arrcode['nom-X'] = 0.33; // Nominal value for X-dim in mm (http://www.gs1uk.org)
84
- $arrcode['nom-H'] = 25.91; // Nominal bar height in mm incl. numerals (http://www.gs1uk.org)
85
- break;
86
- }
87
- case 'UPCE': { // UPC-E
88
- $arrcode = $this->barcode_eanupc($code, 6);
89
- $arrcode['lightmL'] = 9; // LEFT light margin = x X-dim (http://www.gs1uk.org)
90
- $arrcode['lightmR'] = 7; // RIGHT light margin = x X-dim (http://www.gs1uk.org)
91
- $arrcode['nom-X'] = 0.33; // Nominal value for X-dim in mm (http://www.gs1uk.org)
92
- $arrcode['nom-H'] = 25.93; // Nominal bar height in mm incl. numerals (http://www.gs1uk.org)
93
- break;
94
- }
95
- case 'EAN8': { // EAN 8
96
- $arrcode = $this->barcode_eanupc($code, 8);
97
- $arrcode['lightmL'] = 7; // LEFT light margin = x X-dim (http://www.gs1uk.org)
98
- $arrcode['lightmR'] = 7; // RIGHT light margin = x X-dim (http://www.gs1uk.org)
99
- $arrcode['nom-X'] = 0.33; // Nominal value for X-dim in mm (http://www.gs1uk.org)
100
- $arrcode['nom-H'] = 21.64; // Nominal bar height in mm incl. numerals (http://www.gs1uk.org)
101
- break;
102
- }
103
- case 'EAN2': { // 2-Digits UPC-Based Extention
104
- $arrcode = $this->barcode_eanext($code, 2);
105
- $arrcode['lightmL'] = 7; // LEFT light margin = x X-dim (estimated)
106
- $arrcode['lightmR'] = 7; // RIGHT light margin = x X-dim (estimated)
107
- $arrcode['sepM'] = 9; // SEPARATION margin = x X-dim (http://web.archive.org/web/19990501035133/http://www.uc-council.org/d36-d.htm)
108
- $arrcode['nom-X'] = 0.33; // Nominal value for X-dim in mm (http://www.gs1uk.org)
109
- $arrcode['nom-H'] = 20; // Nominal bar height in mm incl. numerals (estimated) not used when combined
110
- break;
111
- }
112
- case 'EAN5': { // 5-Digits UPC-Based Extention
113
- $arrcode = $this->barcode_eanext($code, 5);
114
- $arrcode['lightmL'] = 7; // LEFT light margin = x X-dim (estimated)
115
- $arrcode['lightmR'] = 7; // RIGHT light margin = x X-dim (estimated)
116
- $arrcode['sepM'] = 9; // SEPARATION margin = x X-dim (http://web.archive.org/web/19990501035133/http://www.uc-council.org/d36-d.htm)
117
- $arrcode['nom-X'] = 0.33; // Nominal value for X-dim in mm (http://www.gs1uk.org)
118
- $arrcode['nom-H'] = 20; // Nominal bar height in mm incl. numerals (estimated) not used when combined
119
- break;
120
- }
121
-
122
- case 'IMB': { // IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200
123
- $xdim = 0.508; // Nominal value for X-dim (bar width) in mm (spec.)
124
- $bpi = 22; // Bars per inch
125
- // Ratio of Nominal value for width of spaces in mm / Nominal value for X-dim (bar width) in mm based on bars per inch
126
- $this->gapwidth = ((25.4/$bpi) - $xdim)/$xdim;
127
- $this->daft = array('D'=>2, 'A'=>2, 'F'=>3, 'T'=>1); // Descender; Ascender; Full; Tracker bar heights
128
- $arrcode = $this->barcode_imb($code);
129
- $arrcode['nom-X'] = $xdim ;
130
- $arrcode['nom-H'] = 3.68; // Nominal value for Height of Full bar in mm (spec.)
131
- // USPS-B-3200 Revision C = 4.623
132
- // USPS-B-3200 Revision E = 3.68
133
- $arrcode['quietL'] = 3.175; // LEFT Quiet margin = mm (spec.)
134
- $arrcode['quietR'] = 3.175; // RIGHT Quiet margin = mm (spec.)
135
- $arrcode['quietTB'] = 0.711; // TOP/BOTTOM Quiet margin = mm (spec.)
136
- break;
137
- }
138
- case 'RM4SCC': { // RM4SCC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)
139
- $xdim = 0.508; // Nominal value for X-dim (bar width) in mm (spec.)
140
- $bpi = 22; // Bars per inch
141
- // Ratio of Nominal value for width of spaces in mm / Nominal value for X-dim (bar width) in mm based on bars per inch
142
- $this->gapwidth = ((25.4/$bpi) - $xdim)/$xdim;
143
- $this->daft = array('D'=>5, 'A'=>5, 'F'=>8, 'T'=>2); // Descender; Ascender; Full; Tracker bar heights
144
- $arrcode = $this->barcode_rm4scc($code, false);
145
- $arrcode['nom-X'] = $xdim ;
146
- $arrcode['nom-H'] = 5.0; // Nominal value for Height of Full bar in mm (spec.)
147
- $arrcode['quietL'] = 2; // LEFT Quiet margin = mm (spec.)
148
- $arrcode['quietR'] = 2; // RIGHT Quiet margin = mm (spec.)
149
- $arrcode['quietTB'] = 2; // TOP/BOTTOM Quiet margin = mm (spec?)
150
- break;
151
- }
152
- case 'KIX': { // KIX (Klant index - Customer index)
153
- $xdim = 0.508; // Nominal value for X-dim (bar width) in mm (spec.)
154
- $bpi = 22; // Bars per inch
155
- // Ratio of Nominal value for width of spaces in mm / Nominal value for X-dim (bar width) in mm based on bars per inch
156
- $this->gapwidth = ((25.4/$bpi) - $xdim)/$xdim;
157
- $this->daft = array('D'=>5, 'A'=>5, 'F'=>8, 'T'=>2); // Descender; Ascender; Full; Tracker bar heights
158
- $arrcode = $this->barcode_rm4scc($code, true);
159
- $arrcode['nom-X'] = $xdim ;
160
- $arrcode['nom-H'] = 5.0; // Nominal value for Height of Full bar in mm (? spec.)
161
- $arrcode['quietL'] = 2; // LEFT Quiet margin = mm (spec.)
162
- $arrcode['quietR'] = 2; // RIGHT Quiet margin = mm (spec.)
163
- $arrcode['quietTB'] = 2; // TOP/BOTTOM Quiet margin = mm (spec.)
164
- break;
165
- }
166
- case 'POSTNET': { // POSTNET
167
- $xdim = 0.508; // Nominal value for X-dim (bar width) in mm (spec.)
168
- $bpi = 22; // Bars per inch
169
- // Ratio of Nominal value for width of spaces in mm / Nominal value for X-dim (bar width) in mm based on bars per inch
170
- $this->gapwidth = ((25.4/$bpi) - $xdim)/$xdim;
171
- $arrcode = $this->barcode_postnet($code, false);
172
- $arrcode['nom-X'] = $xdim ;
173
- $arrcode['nom-H'] = 3.175; // Nominal value for Height of Full bar in mm (spec.)
174
- $arrcode['quietL'] = 3.175; // LEFT Quiet margin = mm (?spec.)
175
- $arrcode['quietR'] = 3.175; // RIGHT Quiet margin = mm (?spec.)
176
- $arrcode['quietTB'] = 1.016; // TOP/BOTTOM Quiet margin = mm (?spec.)
177
- break;
178
- }
179
- case 'PLANET': { // PLANET
180
- $xdim = 0.508; // Nominal value for X-dim (bar width) in mm (spec.)
181
- $bpi = 22; // Bars per inch
182
- // Ratio of Nominal value for width of spaces in mm / Nominal value for X-dim (bar width) in mm based on bars per inch
183
- $this->gapwidth = ((25.4/$bpi) - $xdim)/$xdim;
184
- $arrcode = $this->barcode_postnet($code, true);
185
- $arrcode['nom-X'] = $xdim ;
186
- $arrcode['nom-H'] = 3.175; // Nominal value for Height of Full bar in mm (spec.)
187
- $arrcode['quietL'] = 3.175; // LEFT Quiet margin = mm (?spec.)
188
- $arrcode['quietR'] = 3.175; // RIGHT Quiet margin = mm (?spec.)
189
- $arrcode['quietTB'] = 1.016; // TOP/BOTTOM Quiet margin = mm (?spec.)
190
- break;
191
- }
192
-
193
- case 'C93': { // CODE 93 - USS-93
194
- $arrcode = $this->barcode_code93($code);
195
- if ($arrcode == false) { break; }
196
- $arrcode['nom-X'] = 0.381; // Nominal value for X-dim (bar width) in mm (2 X min. spec.)
197
- $arrcode['nom-H'] = 10; // Nominal value for Height of Full bar in mm (non-spec.)
198
- $arrcode['lightmL'] = 10; // LEFT light margin = x X-dim (spec.)
199
- $arrcode['lightmR'] = 10; // RIGHT light margin = x X-dim (spec.)
200
- $arrcode['lightTB'] = 0; // TOP/BOTTOM light margin = x X-dim (non-spec.)
201
- break;
202
- }
203
- case 'CODE11': { // CODE 11
204
- if ($pr > 0) { $this->print_ratio = $pr; }
205
- else { $this->print_ratio = 3; } // spec: Pr= 1:2.24 - 1:3.5
206
- $arrcode = $this->barcode_code11($code);
207
- if ($arrcode == false) { break; }
208
- $arrcode['nom-X'] = 0.381; // Nominal value for X-dim (bar width) in mm (2 X min. spec.)
209
- $arrcode['nom-H'] = 10; // Nominal value for Height of Full bar in mm (non-spec.)
210
- $arrcode['lightmL'] = 10; // LEFT light margin = x X-dim (spec.)
211
- $arrcode['lightmR'] = 10; // RIGHT light margin = x X-dim (spec.)
212
- $arrcode['lightTB'] = 0; // TOP/BOTTOM light margin = x X-dim (non-spec.)
213
- break;
214
- }
215
- case 'MSI': // MSI (Variation of Plessey code)
216
- case 'MSI+': { // MSI + CHECKSUM (modulo 11)
217
- if (strtoupper($type)=='MSI') { $arrcode = $this->barcode_msi($code, false); }
218
- if (strtoupper($type)=='MSI+') { $arrcode = $this->barcode_msi($code, true); }
219
- if ($arrcode == false) { break; }
220
- $arrcode['nom-X'] = 0.381; // Nominal value for X-dim (bar width) in mm (2 X min. spec.)
221
- $arrcode['nom-H'] = 10; // Nominal value for Height of Full bar in mm (non-spec.)
222
- $arrcode['lightmL'] = 12; // LEFT light margin = x X-dim (spec.)
223
- $arrcode['lightmR'] = 12; // RIGHT light margin = x X-dim (spec.)
224
- $arrcode['lightTB'] = 0; // TOP/BOTTOM light margin = x X-dim (non-spec.)
225
- break;
226
- }
227
- case 'CODABAR': { // CODABAR
228
- if ($pr > 0) { $this->print_ratio = $pr; }
229
- else { $this->print_ratio = 2.5; } // spec: Pr= 1:2 - 1:3 (>2.2 if X<0.50)
230
- if (strtoupper($type)=='CODABAR') { $arrcode = $this->barcode_codabar($code); }
231
- if ($arrcode == false) { break; }
232
- $arrcode['nom-X'] = 0.381; // Nominal value for X-dim (bar width) in mm (2 X min. spec.)
233
- $arrcode['nom-H'] = 10; // Nominal value for Height of Full bar in mm (non-spec.)
234
- $arrcode['lightmL'] = 10; // LEFT light margin = x X-dim (spec.)
235
- $arrcode['lightmR'] = 10; // RIGHT light margin = x X-dim (spec.)
236
- $arrcode['lightTB'] = 0; // TOP/BOTTOM light margin = x X-dim (non-spec.)
237
- break;
238
- }
239
- case 'C128A': // CODE 128 A
240
- case 'C128B': // CODE 128 B
241
- case 'C128C': // CODE 128 C
242
- case 'EAN128A': // EAN 128 A
243
- case 'EAN128B': // EAN 128 B
244
- case 'EAN128C': { // EAN 128 C
245
- if (strtoupper($type)=='C128A') { $arrcode = $this->barcode_c128($code, 'A'); }
246
- if (strtoupper($type)=='C128B') { $arrcode = $this->barcode_c128($code, 'B'); }
247
- if (strtoupper($type)=='C128C') { $arrcode = $this->barcode_c128($code, 'C'); }
248
- if (strtoupper($type)=='EAN128A') { $arrcode = $this->barcode_c128($code, 'A', true); }
249
- if (strtoupper($type)=='EAN128B') { $arrcode = $this->barcode_c128($code, 'B', true); }
250
- if (strtoupper($type)=='EAN128C') { $arrcode = $this->barcode_c128($code, 'C', true); }
251
- if ($arrcode == false) { break; }
252
- $arrcode['nom-X'] = 0.381; // Nominal value for X-dim (bar width) in mm (2 X min. spec.)
253
- $arrcode['nom-H'] = 10; // Nominal value for Height of Full bar in mm (non-spec.)
254
- $arrcode['lightmL'] = 10; // LEFT light margin = x X-dim (spec.)
255
- $arrcode['lightmR'] = 10; // RIGHT light margin = x X-dim (spec.)
256
- $arrcode['lightTB'] = 0; // TOP/BOTTOM light margin = x X-dim (non-spec.)
257
- break;
258
- }
259
- case 'C39': // CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
260
- case 'C39+': // CODE 39 with checksum
261
- case 'C39E': // CODE 39 EXTENDED
262
- case 'C39E+': { // CODE 39 EXTENDED + CHECKSUM
263
- if ($pr > 0) { $this->print_ratio = $pr; }
264
- else { $this->print_ratio = 2.5; } // spec: Pr= 1:2 - 1:3 (>2.2 if X<0.50)
265
- $code = str_replace(chr(194).chr(160), ' ', $code); // mPDF 5.3.95 (for utf-8 encoded)
266
- $code = str_replace(chr(160), ' ', $code); // mPDF 5.3.95 (for win-1252)
267
- if (strtoupper($type)=='C39') { $arrcode = $this->barcode_code39($code, false, false); }
268
- if (strtoupper($type)=='C39+') { $arrcode = $this->barcode_code39($code, false, true); }
269
- if (strtoupper($type)=='C39E') { $arrcode = $this->barcode_code39($code, true, false); }
270
- if (strtoupper($type)=='C39E+') { $arrcode = $this->barcode_code39($code, true, true); }
271
- if ($arrcode == false) { break; }
272
- $arrcode['nom-X'] = 0.381; // Nominal value for X-dim (bar width) in mm (2 X min. spec.)
273
- $arrcode['nom-H'] = 10; // Nominal value for Height of Full bar in mm (non-spec.)
274
- $arrcode['lightmL'] = 10; // LEFT light margin = x X-dim (spec.)
275
- $arrcode['lightmR'] = 10; // RIGHT light margin = x X-dim (spec.)
276
- $arrcode['lightTB'] = 0; // TOP/BOTTOM light margin = x X-dim (non-spec.)
277
- break;
278
- }
279
- case 'S25': // Standard 2 of 5
280
- case 'S25+': { // Standard 2 of 5 + CHECKSUM
281
- if ($pr > 0) { $this->print_ratio = $pr; }
282
- else { $this->print_ratio = 3; } // spec: Pr=1:3/1:4.5
283
- if (strtoupper($type)=='S25') { $arrcode = $this->barcode_s25($code, false); }
284
- if (strtoupper($type)=='S25+') { $arrcode = $this->barcode_s25($code, true); }
285
- if ($arrcode == false) { break; }
286
- $arrcode['nom-X'] = 0.381; // Nominal value for X-dim (bar width) in mm (2 X min. spec.)
287
- $arrcode['nom-H'] = 10; // Nominal value for Height of Full bar in mm (non-spec.)
288
- $arrcode['lightmL'] = 10; // LEFT light margin = x X-dim (spec.)
289
- $arrcode['lightmR'] = 10; // RIGHT light margin = x X-dim (spec.)
290
- $arrcode['lightTB'] = 0; // TOP/BOTTOM light margin = x X-dim (non-spec.)
291
- break;
292
- }
293
- case 'I25': // Interleaved 2 of 5
294
- case 'I25+': { // Interleaved 2 of 5 + CHECKSUM
295
- if ($pr > 0) { $this->print_ratio = $pr; }
296
- else { $this->print_ratio = 2.5; } // spec: Pr= 1:2 - 1:3 (>2.2 if X<0.50)
297
- if (strtoupper($type)=='I25') { $arrcode = $this->barcode_i25($code, false); }
298
- if (strtoupper($type)=='I25+') { $arrcode = $this->barcode_i25($code, true); }
299
- if ($arrcode == false) { break; }
300
- $arrcode['nom-X'] = 0.381; // Nominal value for X-dim (bar width) in mm (2 X min. spec.)
301
- $arrcode['nom-H'] = 10; // Nominal value for Height of Full bar in mm (non-spec.)
302
- $arrcode['lightmL'] = 10; // LEFT light margin = x X-dim (spec.)
303
- $arrcode['lightmR'] = 10; // RIGHT light margin = x X-dim (spec.)
304
- $arrcode['lightTB'] = 0; // TOP/BOTTOM light margin = x X-dim (non-spec.)
305
- break;
306
- }
307
- case 'I25B': // Interleaved 2 of 5 + Bearer bars
308
- case 'I25B+': { // Interleaved 2 of 5 + CHECKSUM + Bearer bars
309
- if ($pr > 0) { $this->print_ratio = $pr; }
310
- else { $this->print_ratio = 2.5; } // spec: Pr= 1:2 - 1:3 (>2.2 if X<0.50)
311
- if (strtoupper($type)=='I25B') { $arrcode = $this->barcode_i25($code, false); }
312
- if (strtoupper($type)=='I25B+') { $arrcode = $this->barcode_i25($code, true); }
313
- if ($arrcode == false) { break; }
314
- $arrcode['nom-X'] = 0.381; // Nominal value for X-dim (bar width) in mm (2 X min. spec.)
315
- $arrcode['nom-H'] = 10; // Nominal value for Height of Full bar in mm (non-spec.)
316
- $arrcode['lightmL'] = 10; // LEFT light margin = x X-dim (spec.)
317
- $arrcode['lightmR'] = 10; // RIGHT light margin = x X-dim (spec.)
318
- $arrcode['lightTB'] = 2; // TOP/BOTTOM light margin = x X-dim (non-spec.) - used for bearer bars
319
- break;
320
- }
321
- default: {
322
- $this->barcode_array = false;
323
- }
324
- }
325
- $this->barcode_array = $arrcode;
326
- }
327
-
328
- /**
329
- * CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
330
- */
331
- protected function barcode_code39($code, $extended=false, $checksum=false) {
332
- $chr['0'] = '111221211';
333
- $chr['1'] = '211211112';
334
- $chr['2'] = '112211112';
335
- $chr['3'] = '212211111';
336
- $chr['4'] = '111221112';
337
- $chr['5'] = '211221111';
338
- $chr['6'] = '112221111';
339
- $chr['7'] = '111211212';
340
- $chr['8'] = '211211211';
341
- $chr['9'] = '112211211';
342
- $chr['A'] = '211112112';
343
- $chr['B'] = '112112112';
344
- $chr['C'] = '212112111';
345
- $chr['D'] = '111122112';
346
- $chr['E'] = '211122111';
347
- $chr['F'] = '112122111';
348
- $chr['G'] = '111112212';
349
- $chr['H'] = '211112211';
350
- $chr['I'] = '112112211';
351
- $chr['J'] = '111122211';
352
- $chr['K'] = '211111122';
353
- $chr['L'] = '112111122';
354
- $chr['M'] = '212111121';
355
- $chr['N'] = '111121122';
356
- $chr['O'] = '211121121';
357
- $chr['P'] = '112121121';
358
- $chr['Q'] = '111111222';
359
- $chr['R'] = '211111221';
360
- $chr['S'] = '112111221';
361
- $chr['T'] = '111121221';
362
- $chr['U'] = '221111112';
363
- $chr['V'] = '122111112';
364
- $chr['W'] = '222111111';
365
- $chr['X'] = '121121112';
366
- $chr['Y'] = '221121111';
367
- $chr['Z'] = '122121111';
368
- $chr['-'] = '121111212';
369
- $chr['.'] = '221111211';
370
- $chr[' '] = '122111211';
371
- $chr['$'] = '121212111';
372
- $chr['/'] = '121211121';
373
- $chr['+'] = '121112121';
374
- $chr['%'] = '111212121';
375
- $chr['*'] = '121121211';
376
-
377
- $code = strtoupper($code);
378
- $checkdigit = '';
379
- if ($extended) {
380
- // extended mode
381
- $code = $this->encode_code39_ext($code);
382
- }
383
- if ($code === false) {
384
- return false;
385
- }
386
- if ($checksum) {
387
- // checksum
388
- $checkdigit = $this->checksum_code39($code);
389
- $code .= $checkdigit ;
390
- }
391
- // add start and stop codes
392
- $code = '*'.$code.'*';
393
-
394
- $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
395
- $k = 0;
396
- $clen = strlen($code);
397
- for ($i = 0; $i < $clen; ++$i) {
398
- $char = $code[$i];
399
- if(!isset($chr[$char])) {
400
- // invalid character
401
- return false;
402
- }
403
- for ($j = 0; $j < 9; ++$j) {
404
- if (($j % 2) == 0) {
405
- $t = true; // bar
406
- } else {
407
- $t = false; // space
408
- }
409
- $x = $chr[$char][$j];
410
- if ($x == 2) { $w = $this->print_ratio; }
411
- else { $w = 1; }
412
-
413
- $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
414
- $bararray['maxw'] += $w;
415
- ++$k;
416
- }
417
- $bararray['bcode'][$k] = array('t' => false, 'w' => 1, 'h' => 1, 'p' => 0);
418
- $bararray['maxw'] += 1;
419
- ++$k;
420
- }
421
- $bararray['checkdigit'] = $checkdigit;
422
- return $bararray;
423
- }
424
-
425
- /**
426
- * Encode a string to be used for CODE 39 Extended mode.
427
- */
428
- protected function encode_code39_ext($code) {
429
- $encode = array(
430
- chr(0) => '%U', chr(1) => '$A', chr(2) => '$B', chr(3) => '$C',
431
- chr(4) => '$D', chr(5) => '$E', chr(6) => '$F', chr(7) => '$G',
432
- chr(8) => '$H', chr(9) => '$I', chr(10) => '$J', chr(11) => '�K',
433
- chr(12) => '$L', chr(13) => '$M', chr(14) => '$N', chr(15) => '$O',
434
- chr(16) => '$P', chr(17) => '$Q', chr(18) => '$R', chr(19) => '$S',
435
- chr(20) => '$T', chr(21) => '$U', chr(22) => '$V', chr(23) => '$W',
436
- chr(24) => '$X', chr(25) => '$Y', chr(26) => '$Z', chr(27) => '%A',
437
- chr(28) => '%B', chr(29) => '%C', chr(30) => '%D', chr(31) => '%E',
438
- chr(32) => ' ', chr(33) => '/A', chr(34) => '/B', chr(35) => '/C',
439
- chr(36) => '/D', chr(37) => '/E', chr(38) => '/F', chr(39) => '/G',
440
- chr(40) => '/H', chr(41) => '/I', chr(42) => '/J', chr(43) => '/K',
441
- chr(44) => '/L', chr(45) => '-', chr(46) => '.', chr(47) => '/O',
442
- chr(48) => '0', chr(49) => '1', chr(50) => '2', chr(51) => '3',
443
- chr(52) => '4', chr(53) => '5', chr(54) => '6', chr(55) => '7',
444
- chr(56) => '8', chr(57) => '9', chr(58) => '/Z', chr(59) => '%F',
445
- chr(60) => '%G', chr(61) => '%H', chr(62) => '%I', chr(63) => '%J',
446
- chr(64) => '%V', chr(65) => 'A', chr(66) => 'B', chr(67) => 'C',
447
- chr(68) => 'D', chr(69) => 'E', chr(70) => 'F', chr(71) => 'G',
448
- chr(72) => 'H', chr(73) => 'I', chr(74) => 'J', chr(75) => 'K',
449
- chr(76) => 'L', chr(77) => 'M', chr(78) => 'N', chr(79) => 'O',
450
- chr(80) => 'P', chr(81) => 'Q', chr(82) => 'R', chr(83) => 'S',
451
- chr(84) => 'T', chr(85) => 'U', chr(86) => 'V', chr(87) => 'W',
452
- chr(88) => 'X', chr(89) => 'Y', chr(90) => 'Z', chr(91) => '%K',
453
- chr(92) => '%L', chr(93) => '%M', chr(94) => '%N', chr(95) => '%O',
454
- chr(96) => '%W', chr(97) => '+A', chr(98) => '+B', chr(99) => '+C',
455
- chr(100) => '+D', chr(101) => '+E', chr(102) => '+F', chr(103) => '+G',
456
- chr(104) => '+H', chr(105) => '+I', chr(106) => '+J', chr(107) => '+K',
457
- chr(108) => '+L', chr(109) => '+M', chr(110) => '+N', chr(111) => '+O',
458
- chr(112) => '+P', chr(113) => '+Q', chr(114) => '+R', chr(115) => '+S',
459
- chr(116) => '+T', chr(117) => '+U', chr(118) => '+V', chr(119) => '+W',
460
- chr(120) => '+X', chr(121) => '+Y', chr(122) => '+Z', chr(123) => '%P',
461
- chr(124) => '%Q', chr(125) => '%R', chr(126) => '%S', chr(127) => '%T');
462
- $code_ext = '';
463
- $clen = strlen($code);
464
- for ($i = 0 ; $i < $clen; ++$i) {
465
- if (ord($code[$i]) > 127) {
466
- return false;
467
- }
468
- $code_ext .= $encode[$code[$i]];
469
- }
470
- return $code_ext;
471
- }
472
-
473
- /**
474
- * Calculate CODE 39 checksum (modulo 43).
475
- */
476
- protected function checksum_code39($code) {
477
- $chars = array(
478
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
479
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
480
- 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
481
- 'W', 'X', 'Y', 'Z', '-', '.', ' ', '$', '/', '+', '%');
482
- $sum = 0;
483
- $clen = strlen($code);
484
- for ($i = 0 ; $i < $clen; ++$i) {
485
- $k = array_keys($chars, $code[$i]);
486
- $sum += $k[0];
487
- }
488
- $j = ($sum % 43);
489
- return $chars[$j];
490
- }
491
-
492
- /**
493
- * CODE 93 - USS-93
494
- * Compact code similar to Code 39
495
- */
496
- protected function barcode_code93($code) {
497
- $chr[48] = '131112'; // 0
498
- $chr[49] = '111213'; // 1
499
- $chr[50] = '111312'; // 2
500
- $chr[51] = '111411'; // 3
501
- $chr[52] = '121113'; // 4
502
- $chr[53] = '121212'; // 5
503
- $chr[54] = '121311'; // 6
504
- $chr[55] = '111114'; // 7
505
- $chr[56] = '131211'; // 8
506
- $chr[57] = '141111'; // 9
507
- $chr[65] = '211113'; // A
508
- $chr[66] = '211212'; // B
509
- $chr[67] = '211311'; // C
510
- $chr[68] = '221112'; // D
511
- $chr[69] = '221211'; // E
512
- $chr[70] = '231111'; // F
513
- $chr[71] = '112113'; // G
514
- $chr[72] = '112212'; // H
515
- $chr[73] = '112311'; // I
516
- $chr[74] = '122112'; // J
517
- $chr[75] = '132111'; // K
518
- $chr[76] = '111123'; // L
519
- $chr[77] = '111222'; // M
520
- $chr[78] = '111321'; // N
521
- $chr[79] = '121122'; // O
522
- $chr[80] = '131121'; // P
523
- $chr[81] = '212112'; // Q
524
- $chr[82] = '212211'; // R
525
- $chr[83] = '211122'; // S
526
- $chr[84] = '211221'; // T
527
- $chr[85] = '221121'; // U
528
- $chr[86] = '222111'; // V
529
- $chr[87] = '112122'; // W
530
- $chr[88] = '112221'; // X
531
- $chr[89] = '122121'; // Y
532
- $chr[90] = '123111'; // Z
533
- $chr[45] = '121131'; // -
534
- $chr[46] = '311112'; // .
535
- $chr[32] = '311211'; //
536
- $chr[36] = '321111'; // $
537
- $chr[47] = '112131'; // /
538
- $chr[43] = '113121'; // +
539
- $chr[37] = '211131'; // %
540
- $chr[128] = '121221'; // ($)
541
- $chr[129] = '311121'; // (/)
542
- $chr[130] = '122211'; // (+)
543
- $chr[131] = '312111'; // (%)
544
- $chr[42] = '111141'; // start-stop
545
- $code = strtoupper($code);
546
- $encode = array(
547
- chr(0) => chr(131).'U', chr(1) => chr(128).'A', chr(2) => chr(128).'B', chr(3) => chr(128).'C',
548
- chr(4) => chr(128).'D', chr(5) => chr(128).'E', chr(6) => chr(128).'F', chr(7) => chr(128).'G',
549
- chr(8) => chr(128).'H', chr(9) => chr(128).'I', chr(10) => chr(128).'J', chr(11) => '�K',
550
- chr(12) => chr(128).'L', chr(13) => chr(128).'M', chr(14) => chr(128).'N', chr(15) => chr(128).'O',
551
- chr(16) => chr(128).'P', chr(17) => chr(128).'Q', chr(18) => chr(128).'R', chr(19) => chr(128).'S',
552
- chr(20) => chr(128).'T', chr(21) => chr(128).'U', chr(22) => chr(128).'V', chr(23) => chr(128).'W',
553
- chr(24) => chr(128).'X', chr(25) => chr(128).'Y', chr(26) => chr(128).'Z', chr(27) => chr(131).'A',
554
- chr(28) => chr(131).'B', chr(29) => chr(131).'C', chr(30) => chr(131).'D', chr(31) => chr(131).'E',
555
- chr(32) => ' ', chr(33) => chr(129).'A', chr(34) => chr(129).'B', chr(35) => chr(129).'C',
556
- chr(36) => chr(129).'D', chr(37) => chr(129).'E', chr(38) => chr(129).'F', chr(39) => chr(129).'G',
557
- chr(40) => chr(129).'H', chr(41) => chr(129).'I', chr(42) => chr(129).'J', chr(43) => chr(129).'K',
558
- chr(44) => chr(129).'L', chr(45) => '-', chr(46) => '.', chr(47) => chr(129).'O',
559
- chr(48) => '0', chr(49) => '1', chr(50) => '2', chr(51) => '3',
560
- chr(52) => '4', chr(53) => '5', chr(54) => '6', chr(55) => '7',
561
- chr(56) => '8', chr(57) => '9', chr(58) => chr(129).'Z', chr(59) => chr(131).'F',
562
- chr(60) => chr(131).'G', chr(61) => chr(131).'H', chr(62) => chr(131).'I', chr(63) => chr(131).'J',
563
- chr(64) => chr(131).'V', chr(65) => 'A', chr(66) => 'B', chr(67) => 'C',
564
- chr(68) => 'D', chr(69) => 'E', chr(70) => 'F', chr(71) => 'G',
565
- chr(72) => 'H', chr(73) => 'I', chr(74) => 'J', chr(75) => 'K',
566
- chr(76) => 'L', chr(77) => 'M', chr(78) => 'N', chr(79) => 'O',
567
- chr(80) => 'P', chr(81) => 'Q', chr(82) => 'R', chr(83) => 'S',
568
- chr(84) => 'T', chr(85) => 'U', chr(86) => 'V', chr(87) => 'W',
569
- chr(88) => 'X', chr(89) => 'Y', chr(90) => 'Z', chr(91) => chr(131).'K',
570
- chr(92) => chr(131).'L', chr(93) => chr(131).'M', chr(94) => chr(131).'N', chr(95) => chr(131).'O',
571
- chr(96) => chr(131).'W', chr(97) => chr(130).'A', chr(98) => chr(130).'B', chr(99) => chr(130).'C',
572
- chr(100) => chr(130).'D', chr(101) => chr(130).'E', chr(102) => chr(130).'F', chr(103) => chr(130).'G',
573
- chr(104) => chr(130).'H', chr(105) => chr(130).'I', chr(106) => chr(130).'J', chr(107) => chr(130).'K',
574
- chr(108) => chr(130).'L', chr(109) => chr(130).'M', chr(110) => chr(130).'N', chr(111) => chr(130).'O',
575
- chr(112) => chr(130).'P', chr(113) => chr(130).'Q', chr(114) => chr(130).'R', chr(115) => chr(130).'S',
576
- chr(116) => chr(130).'T', chr(117) => chr(130).'U', chr(118) => chr(130).'V', chr(119) => chr(130).'W',
577
- chr(120) => chr(130).'X', chr(121) => chr(130).'Y', chr(122) => chr(130).'Z', chr(123) => chr(131).'P',
578
- chr(124) => chr(131).'Q', chr(125) => chr(131).'R', chr(126) => chr(131).'S', chr(127) => chr(131).'T');
579
- $code_ext = '';
580
- $clen = strlen($code);
581
- for ($i = 0 ; $i < $clen; ++$i) {
582
- if (ord($code{$i}) > 127) {
583
- return false;
584
- }
585
- $code_ext .= $encode[$code{$i}];
586
- }
587
- // checksum
588
- $code_ext .= $this->checksum_code93($code_ext);
589
- // add start and stop codes
590
- $code = '*'.$code_ext.'*';
591
- $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
592
- $k = 0;
593
- $clen = strlen($code);
594
- for ($i = 0; $i < $clen; ++$i) {
595
- $char = ord($code{$i});
596
- if(!isset($chr[$char])) {
597
- // invalid character
598
- return false;
599
- }
600
- for ($j = 0; $j < 6; ++$j) {
601
- if (($j % 2) == 0) {
602
- $t = true; // bar
603
- } else {
604
- $t = false; // space
605
- }
606
- $w = $chr[$char]{$j};
607
- $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
608
- $bararray['maxw'] += $w;
609
- ++$k;
610
- }
611
- }
612
- $bararray['bcode'][$k] = array('t' => true, 'w' => 1, 'h' => 1, 'p' => 0);
613
- $bararray['maxw'] += 1;
614
- ++$k;
615
- return $bararray;
616
- }
617
-
618
- /**
619
- * Calculate CODE 93 checksum (modulo 47).
620
- */
621
- protected function checksum_code93($code) {
622
- $chars = array(
623
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
624
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
625
- 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
626
- 'W', 'X', 'Y', 'Z', '-', '.', ' ', '$', '/', '+', '%',
627
- '<', '=', '>', '?');
628
- // translate special characters
629
- $code = strtr($code, chr(128).chr(131).chr(129).chr(130), '<=>?');
630
- $len = strlen($code);
631
- // calculate check digit C
632
- $p = 1;
633
- $check = 0;
634
- for ($i = ($len - 1); $i >= 0; --$i) {
635
- $k = array_keys($chars, $code{$i});
636
- $check += ($k[0] * $p);
637
- ++$p;
638
- if ($p > 20) {
639
- $p = 1;
640
- }
641
- }
642
- $check %= 47;
643
- $c = $chars[$check];
644
- $code .= $c;
645
- // calculate check digit K
646
- $p = 1;
647
- $check = 0;
648
- for ($i = $len; $i >= 0; --$i) {
649
- $k = array_keys($chars, $code{$i});
650
- $check += ($k[0] * $p);
651
- ++$p;
652
- if ($p > 15) {
653
- $p = 1;
654
- }
655
- }
656
- $check %= 47;
657
- $k = $chars[$check];
658
- $checksum = $c.$k;
659
- // resto respecial characters
660
- $checksum = strtr($checksum, '<=>?', chr(128).chr(131).chr(129).chr(130));
661
- return $checksum;
662
- }
663
-
664
- /**
665
- * Checksum for standard 2 of 5 barcodes.
666
- */
667
- protected function checksum_s25($code) {
668
- $len = strlen($code);
669
- $sum = 0;
670
- for ($i = 0; $i < $len; $i+=2) {
671
- $sum += $code[$i];
672
- }
673
- $sum *= 3;
674
- for ($i = 1; $i < $len; $i+=2) {
675
- $sum += ($code[$i]);
676
- }
677
- $r = $sum % 10;
678
- if($r > 0) {
679
- $r = (10 - $r);
680
- }
681
- return $r;
682
- }
683
-
684
- /**
685
- * MSI.
686
- * Variation of Plessey code, with similar applications
687
- * Contains digits (0 to 9) and encodes the data only in the width of bars.
688
- */
689
- protected function barcode_msi($code, $checksum=false) {
690
- $chr['0'] = '100100100100';
691
- $chr['1'] = '100100100110';
692
- $chr['2'] = '100100110100';
693
- $chr['3'] = '100100110110';
694
- $chr['4'] = '100110100100';
695
- $chr['5'] = '100110100110';
696
- $chr['6'] = '100110110100';
697
- $chr['7'] = '100110110110';
698
- $chr['8'] = '110100100100';
699
- $chr['9'] = '110100100110';
700
- $chr['A'] = '110100110100';
701
- $chr['B'] = '110100110110';
702
- $chr['C'] = '110110100100';
703
- $chr['D'] = '110110100110';
704
- $chr['E'] = '110110110100';
705
- $chr['F'] = '110110110110';
706
- $checkdigit = '';
707
- if ($checksum) {
708
- // add checksum
709
- $clen = strlen($code);
710
- $p = 2;
711
- $check = 0;
712
- for ($i = ($clen - 1); $i >= 0; --$i) {
713
- $check += (hexdec($code[$i]) * $p);
714
- ++$p;
715
- if ($p > 7) {
716
- $p = 2;
717
- }
718
- }
719
- $check %= 11;
720
- if ($check > 0) {
721
- $check = 11 - $check;
722
- }
723
- $code .= $check;
724
- $checkdigit = $check;
725
- }
726
- $seq = '110'; // left guard
727
- $clen = strlen($code);
728
- for ($i = 0; $i < $clen; ++$i) {
729
- $digit = $code[$i];
730
- if (!isset($chr[$digit])) {
731
- // invalid character
732
- return false;
733
- }
734
- $seq .= $chr[$digit];
735
- }
736
- $seq .= '1001'; // right guard
737
- $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
738
- $bararray['checkdigit'] = $checkdigit;
739
- return $this->binseq_to_array($seq, $bararray);
740
- }
741
-
742
- /**
743
- * Standard 2 of 5 barcodes.
744
- * Used in airline ticket marking, photofinishing
745
- * Contains digits (0 to 9) and encodes the data only in the width of bars.
746
- */
747
- protected function barcode_s25($code, $checksum=false) {
748
- $chr['0'] = '10101110111010';
749
- $chr['1'] = '11101010101110';
750
- $chr['2'] = '10111010101110';
751
- $chr['3'] = '11101110101010';
752
- $chr['4'] = '10101110101110';
753
- $chr['5'] = '11101011101010';
754
- $chr['6'] = '10111011101010';
755
- $chr['7'] = '10101011101110';
756
- $chr['8'] = '10101110111010';
757
- $chr['9'] = '10111010111010';
758
- $checkdigit = '';
759
- if ($checksum) {
760
- // add checksum
761
- $checkdigit = $this->checksum_s25($code);
762
- $code .= $checkdigit ;
763
- }
764
- if((strlen($code) % 2) != 0) {
765
- // add leading zero if code-length is odd
766
- $code = '0'.$code;
767
- }
768
- $seq = '11011010';
769
- $clen = strlen($code);
770
- for ($i = 0; $i < $clen; ++$i) {
771
- $digit = $code[$i];
772
- if (!isset($chr[$digit])) {
773
- // invalid character
774
- return false;
775
- }
776
- $seq .= $chr[$digit];
777
- }
778
- $seq .= '1101011';
779
- $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
780
- $bararray['checkdigit'] = $checkdigit;
781
- return $this->binseq_to_array($seq, $bararray);
782
- }
783
-
784
- /**
785
- * Convert binary barcode sequence to barcode array
786
- */
787
- protected function binseq_to_array($seq, $bararray) {
788
- $len = strlen($seq);
789
- $w = 0;
790
- $k = 0;
791
- for ($i = 0; $i < $len; ++$i) {
792
- $w += 1;
793
- if (($i == ($len - 1)) OR (($i < ($len - 1)) AND ($seq[$i] != $seq[($i+1)]))) {
794
- if ($seq[$i] == '1') {
795
- $t = true; // bar
796
- } else {
797
- $t = false; // space
798
- }
799
- $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
800
- $bararray['maxw'] += $w;
801
- ++$k;
802
- $w = 0;
803
- }
804
- }
805
- return $bararray;
806
- }
807
-
808
- /**
809
- * Interleaved 2 of 5 barcodes.
810
- * Compact numeric code, widely used in industry, air cargo
811
- * Contains digits (0 to 9) and encodes the data in the width of both bars and spaces.
812
- */
813
- protected function barcode_i25($code, $checksum=false) {
814
- $chr['0'] = '11221';
815
- $chr['1'] = '21112';
816
- $chr['2'] = '12112';
817
- $chr['3'] = '22111';
818
- $chr['4'] = '11212';
819
- $chr['5'] = '21211';
820
- $chr['6'] = '12211';
821
- $chr['7'] = '11122';
822
- $chr['8'] = '21121';
823
- $chr['9'] = '12121';
824
- $chr['A'] = '11';
825
- $chr['Z'] = '21';
826
- $checkdigit = '';
827
- if ($checksum) {
828
- // add checksum
829
- $checkdigit = $this->checksum_s25($code);
830
- $code .= $checkdigit ;
831
- }
832
- if((strlen($code) % 2) != 0) {
833
- // add leading zero if code-length is odd
834
- $code = '0'.$code;
835
- }
836
- // add start and stop codes
837
- $code = 'AA'.strtolower($code).'ZA';
838
-
839
- $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
840
- $k = 0;
841
- $clen = strlen($code);
842
- for ($i = 0; $i < $clen; $i = ($i + 2)) {
843
- $char_bar = $code[$i];
844
- $char_space = $code[$i+1];
845
- if((!isset($chr[$char_bar])) OR (!isset($chr[$char_space]))) {
846
- // invalid character
847
- return false;
848
- }
849
- // create a bar-space sequence
850
- $seq = '';
851
- $chrlen = strlen($chr[$char_bar]);
852
- for ($s = 0; $s < $chrlen; $s++){
853
- $seq .= $chr[$char_bar][$s] . $chr[$char_space][$s];
854
- }
855
- $seqlen = strlen($seq);
856
- for ($j = 0; $j < $seqlen; ++$j) {
857
- if (($j % 2) == 0) {
858
- $t = true; // bar
859
- } else {
860
- $t = false; // space
861
- }
862
- $x = $seq[$j];
863
- if ($x == 2) { $w = $this->print_ratio; }
864
- else { $w = 1; }
865
-
866
- $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
867
- $bararray['maxw'] += $w;
868
- ++$k;
869
- }
870
- }
871
- $bararray['checkdigit'] = $checkdigit;
872
- return $bararray;
873
- }
874
-
875
- /**
876
- * C128 barcodes.
877
- * Very capable code, excellent density, high reliability; in very wide use world-wide
878
- */
879
- protected function barcode_c128($code, $type='B', $ean=false) {
880
- $code = strcode2utf($code); // mPDF 5.7.1 Allows e.g. <barcode code="5432&#013;1068" type="C128A" />
881
- $chr = array(
882
- '212222', /* 00 */
883
- '222122', /* 01 */
884
- '222221', /* 02 */
885
- '121223', /* 03 */
886
- '121322', /* 04 */
887
- '131222', /* 05 */
888
- '122213', /* 06 */
889
- '122312', /* 07 */
890
- '132212', /* 08 */
891
- '221213', /* 09 */
892
- '221312', /* 10 */
893
- '231212', /* 11 */
894
- '112232', /* 12 */
895
- '122132', /* 13 */
896
- '122231', /* 14 */
897
- '113222', /* 15 */
898
- '123122', /* 16 */
899
- '123221', /* 17 */
900
- '223211', /* 18 */
901
- '221132', /* 19 */
902
- '221231', /* 20 */
903
- '213212', /* 21 */
904
- '223112', /* 22 */
905
- '312131', /* 23 */
906
- '311222', /* 24 */
907
- '321122', /* 25 */
908
- '321221', /* 26 */
909
- '312212', /* 27 */
910
- '322112', /* 28 */
911
- '322211', /* 29 */
912
- '212123', /* 30 */
913
- '212321', /* 31 */
914
- '232121', /* 32 */
915
- '111323', /* 33 */
916
- '131123', /* 34 */
917
- '131321', /* 35 */
918
- '112313', /* 36 */
919
- '132113', /* 37 */
920
- '132311', /* 38 */
921
- '211313', /* 39 */
922
- '231113', /* 40 */
923
- '231311', /* 41 */
924
- '112133', /* 42 */
925
- '112331', /* 43 */
926
- '132131', /* 44 */
927
- '113123', /* 45 */
928
- '113321', /* 46 */
929
- '133121', /* 47 */
930
- '313121', /* 48 */
931
- '211331', /* 49 */
932
- '231131', /* 50 */
933
- '213113', /* 51 */
934
- '213311', /* 52 */
935
- '213131', /* 53 */
936
- '311123', /* 54 */
937
- '311321', /* 55 */
938
- '331121', /* 56 */
939
- '312113', /* 57 */
940
- '312311', /* 58 */
941
- '332111', /* 59 */
942
- '314111', /* 60 */
943
- '221411', /* 61 */
944
- '431111', /* 62 */
945
- '111224', /* 63 */
946
- '111422', /* 64 */
947
- '121124', /* 65 */
948
- '121421', /* 66 */
949
- '141122', /* 67 */
950
- '141221', /* 68 */
951
- '112214', /* 69 */
952
- '112412', /* 70 */
953
- '122114', /* 71 */
954
- '122411', /* 72 */
955
- '142112', /* 73 */
956
- '142211', /* 74 */
957
- '241211', /* 75 */
958
- '221114', /* 76 */
959
- '413111', /* 77 */
960
- '241112', /* 78 */
961
- '134111', /* 79 */
962
- '111242', /* 80 */
963
- '121142', /* 81 */
964
- '121241', /* 82 */
965
- '114212', /* 83 */
966
- '124112', /* 84 */
967
- '124211', /* 85 */
968
- '411212', /* 86 */
969
- '421112', /* 87 */
970
- '421211', /* 88 */
971
- '212141', /* 89 */
972
- '214121', /* 90 */
973
- '412121', /* 91 */
974
- '111143', /* 92 */
975
- '111341', /* 93 */
976
- '131141', /* 94 */
977
- '114113', /* 95 */
978
- '114311', /* 96 */
979
- '411113', /* 97 */
980
- '411311', /* 98 */
981
- '113141', /* 99 */
982
- '114131', /* 100 */
983
- '311141', /* 101 */
984
- '411131', /* 102 */
985
- '211412', /* 103 START A */
986
- '211214', /* 104 START B */
987
- '211232', /* 105 START C */
988
- '233111', /* STOP */
989
- '200000' /* END */
990
- );
991
- $keys = '';
992
- switch(strtoupper($type)) {
993
- case 'A': {
994
- $startid = 103;
995
- $keys = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_';
996
- for ($i = 0; $i < 32; ++$i) {
997
- $keys .= chr($i);
998
- }
999
- break;
1000
- }
1001
- case 'B': {
1002
- $startid = 104;
1003
- $keys = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'.chr(127);
1004
- break;
1005
- }
1006
- case 'C': {
1007
- $startid = 105;
1008
- $keys = '';
1009
- if ((strlen($code) % 2) != 0) {
1010
- // The length of barcode value must be even ($code). You must pad the number with zeros
1011
- return false;
1012
- }
1013
- for ($i = 0; $i <= 99; ++$i) {
1014
- $keys .= chr($i);
1015
- }
1016
- $new_code = '';
1017
- $hclen = (strlen($code) / 2);
1018
- for ($i = 0; $i < $hclen; ++$i) {
1019
- $new_code .= chr(intval($code{(2 * $i)}.$code{(2 * $i + 1)}));
1020
- }
1021
- $code = $new_code;
1022
- break;
1023
- }
1024
- default: {
1025
- return false;
1026
- }
1027
- }
1028
-
1029
- // calculate check character
1030
- $sum = $startid;
1031
- if ($ean) { $code = chr(102) . $code; } // Add FNC 1 - which identifies it as EAN-128
1032
- $clen = strlen($code);
1033
- for ($i = 0; $i < $clen; ++$i) {
1034
- if ($ean && $i==0) { $sum += 102; }
1035
- else { $sum += (strpos($keys, $code[$i]) * ($i+1)); }
1036
- }
1037
- $check = ($sum % 103);
1038
- $checkdigit = $check ;
1039
- // add start, check and stop codes
1040
- $code = chr($startid).$code.chr($check).chr(106).chr(107);
1041
- $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1042
- $k = 0;
1043
- $len = strlen($code);
1044
- for ($i = 0; $i < $len; ++$i) {
1045
- $ck = strpos($keys, $code[$i]);
1046
- if (($i == 0) || ($ean && $i==1) | ($i > ($len-4))) {
1047
- $char_num = ord($code[$i]);
1048
- $seq = $chr[$char_num];
1049
- } elseif(($ck >= 0) AND isset($chr[$ck])) {
1050
- $seq = $chr[$ck];
1051
- } else {
1052
- // invalid character
1053
- return false;
1054
- }
1055
- for ($j = 0; $j < 6; ++$j) {
1056
- if (($j % 2) == 0) {
1057
- $t = true; // bar
1058
- } else {
1059
- $t = false; // space
1060
- }
1061
- $w = $seq[$j];
1062
- $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
1063
- $bararray['maxw'] += $w;
1064
- ++$k;
1065
- }
1066
- }
1067
- $bararray['checkdigit'] = $checkdigit;
1068
- return $bararray;
1069
- }
1070
-
1071
- /**
1072
- * EAN13 and UPC-A barcodes.
1073
- * EAN13: European Article Numbering international retail product code
1074
- * UPC-A: Universal product code seen on almost all retail products in the USA and Canada
1075
- * UPC-E: Short version of UPC symbol
1076
- */
1077
- protected function barcode_eanupc($code, $len=13) {
1078
- $upce = false;
1079
- $checkdigit = false;
1080
- if ($len == 6) {
1081
- $len = 12; // UPC-A
1082
- $upce = true; // UPC-E mode
1083
- }
1084
- $data_len = $len - 1;
1085
- //Padding
1086
- $code = str_pad($code, $data_len, '0', STR_PAD_LEFT);
1087
- $code_len = strlen($code);
1088
- // calculate check digit
1089
- $sum_a = 0;
1090
- for ($i = 1; $i < $data_len; $i+=2) {
1091
- $sum_a += $code[$i];
1092
- }
1093
- if ($len > 12) {
1094
- $sum_a *= 3;
1095
- }
1096
- $sum_b = 0;
1097
- for ($i = 0; $i < $data_len; $i+=2) {
1098
- $sum_b += ($code[$i]);
1099
- }
1100
- if ($len < 13) {
1101
- $sum_b *= 3;
1102
- }
1103
- $r = ($sum_a + $sum_b) % 10;
1104
- if($r > 0) {
1105
- $r = (10 - $r);
1106
- }
1107
- if ($code_len == $data_len) {
1108
- // add check digit
1109
- $code .= $r;
1110
- $checkdigit = $r;
1111
- } elseif ($r !== intval($code[$data_len])) {
1112
- // wrong checkdigit
1113
- return false;
1114
- }
1115
- if ($len == 12) {
1116
- // UPC-A
1117
- $code = '0'.$code;
1118
- ++$len;
1119
- }
1120
- if ($upce) {
1121
- // convert UPC-A to UPC-E
1122
- $tmp = substr($code, 4, 3);
1123
- $prod_code = intval(substr($code,7,5)); // product code
1124
- $invalid_upce = false;
1125
- if (($tmp == '000') OR ($tmp == '100') OR ($tmp == '200')) {
1126
- // manufacturer code ends in 000, 100, or 200
1127
- $upce_code = substr($code, 2, 2).substr($code, 9, 3).substr($code, 4, 1);
1128
- if ($prod_code > 999) { $invalid_upce = true; }
1129
- } else {
1130
- $tmp = substr($code, 5, 2);
1131
- if ($tmp == '00') {
1132
- // manufacturer code ends in 00
1133
- $upce_code = substr($code, 2, 3).substr($code, 10, 2).'3';
1134
- if ($prod_code > 99) { $invalid_upce = true; }
1135
- } else {
1136
- $tmp = substr($code, 6, 1);
1137
- if ($tmp == '0') {
1138
- // manufacturer code ends in 0
1139
- $upce_code = substr($code, 2, 4).substr($code, 11, 1).'4';
1140
- if ($prod_code > 9) { $invalid_upce = true; }
1141
- } else {
1142
- // manufacturer code does not end in zero
1143
- $upce_code = substr($code, 2, 5).substr($code, 11, 1);
1144
- if ($prod_code > 9) { $invalid_upce = true; }
1145
- }
1146
- }
1147
- }
1148
- if ($invalid_upce) { die("Error - UPC-A cannot produce a valid UPC-E barcode"); } // Error generating a UPCE code
1149
- }
1150
- //Convert digits to bars
1151
- $codes = array(
1152
- 'A'=>array( // left odd parity
1153
- '0'=>'0001101',
1154
- '1'=>'0011001',
1155
- '2'=>'0010011',
1156
- '3'=>'0111101',
1157
- '4'=>'0100011',
1158
- '5'=>'0110001',
1159
- '6'=>'0101111',
1160
- '7'=>'0111011',
1161
- '8'=>'0110111',
1162
- '9'=>'0001011'),
1163
- 'B'=>array( // left even parity
1164
- '0'=>'0100111',
1165
- '1'=>'0110011',
1166
- '2'=>'0011011',
1167
- '3'=>'0100001',
1168
- '4'=>'0011101',
1169
- '5'=>'0111001',
1170
- '6'=>'0000101',
1171
- '7'=>'0010001',
1172
- '8'=>'0001001',
1173
- '9'=>'0010111'),
1174
- 'C'=>array( // right
1175
- '0'=>'1110010',
1176
- '1'=>'1100110',
1177
- '2'=>'1101100',
1178
- '3'=>'1000010',
1179
- '4'=>'1011100',
1180
- '5'=>'1001110',
1181
- '6'=>'1010000',
1182
- '7'=>'1000100',
1183
- '8'=>'1001000',
1184
- '9'=>'1110100')
1185
- );
1186
- $parities = array(
1187
- '0'=>array('A','A','A','A','A','A'),
1188
- '1'=>array('A','A','B','A','B','B'),
1189
- '2'=>array('A','A','B','B','A','B'),
1190
- '3'=>array('A','A','B','B','B','A'),
1191
- '4'=>array('A','B','A','A','B','B'),
1192
- '5'=>array('A','B','B','A','A','B'),
1193
- '6'=>array('A','B','B','B','A','A'),
1194
- '7'=>array('A','B','A','B','A','B'),
1195
- '8'=>array('A','B','A','B','B','A'),
1196
- '9'=>array('A','B','B','A','B','A')
1197
- );
1198
- $upce_parities = array();
1199
- $upce_parities[0] = array(
1200
- '0'=>array('B','B','B','A','A','A'),
1201
- '1'=>array('B','B','A','B','A','A'),
1202
- '2'=>array('B','B','A','A','B','A'),
1203
- '3'=>array('B','B','A','A','A','B'),
1204
- '4'=>array('B','A','B','B','A','A'),
1205
- '5'=>array('B','A','A','B','B','A'),
1206
- '6'=>array('B','A','A','A','B','B'),
1207
- '7'=>array('B','A','B','A','B','A'),
1208
- '8'=>array('B','A','B','A','A','B'),
1209
- '9'=>array('B','A','A','B','A','B')
1210
- );
1211
- $upce_parities[1] = array(
1212
- '0'=>array('A','A','A','B','B','B'),
1213
- '1'=>array('A','A','B','A','B','B'),
1214
- '2'=>array('A','A','B','B','A','B'),
1215
- '3'=>array('A','A','B','B','B','A'),
1216
- '4'=>array('A','B','A','A','B','B'),
1217
- '5'=>array('A','B','B','A','A','B'),
1218
- '6'=>array('A','B','B','B','A','A'),
1219
- '7'=>array('A','B','A','B','A','B'),
1220
- '8'=>array('A','B','A','B','B','A'),
1221
- '9'=>array('A','B','B','A','B','A')
1222
- );
1223
- $k = 0;
1224
- $seq = '101'; // left guard bar
1225
- if ($upce) {
1226
- $bararray = array('code' => $upce_code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1227
- $p = $upce_parities[$code{1}][$r];
1228
- for ($i = 0; $i < 6; ++$i) {
1229
- $seq .= $codes[$p[$i]][$upce_code[$i]];
1230
- }
1231
- $seq .= '010101'; // right guard bar
1232
- } else {
1233
- $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1234
- $half_len = ceil($len / 2);
1235
- if ($len == 8) {
1236
- for ($i = 0; $i < $half_len; ++$i) {
1237
- $seq .= $codes['A'][$code[$i]];
1238
- }
1239
- } else {
1240
- $p = $parities[$code{0}];
1241
- for ($i = 1; $i < $half_len; ++$i) {
1242
- $seq .= $codes[$p[$i-1]][$code[$i]];
1243
- }
1244
- }
1245
- $seq .= '01010'; // center guard bar
1246
- for ($i = $half_len; $i < $len; ++$i) {
1247
- $seq .= $codes['C'][$code[$i]];
1248
- }
1249
- $seq .= '101'; // right guard bar
1250
- }
1251
- $clen = strlen($seq);
1252
- $w = 0;
1253
- for ($i = 0; $i < $clen; ++$i) {
1254
- $w += 1;
1255
- if (($i == ($clen - 1)) OR (($i < ($clen - 1)) AND ($seq[$i] != $seq[($i+1)]))) {
1256
- if ($seq[$i] == '1') {
1257
- $t = true; // bar
1258
- } else {
1259
- $t = false; // space
1260
- }
1261
- $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
1262
- $bararray['maxw'] += $w;
1263
- ++$k;
1264
- $w = 0;
1265
- }
1266
- }
1267
- $bararray['checkdigit'] = $checkdigit;
1268
- return $bararray;
1269
- }
1270
-
1271
- /**
1272
- * UPC-Based Extentions
1273
- * 2-Digit Ext.: Used to indicate magazines and newspaper issue numbers
1274
- * 5-Digit Ext.: Used to mark suggested retail price of books
1275
- */
1276
- protected function barcode_eanext($code, $len=5) {
1277
- //Padding
1278
- $code = str_pad($code, $len, '0', STR_PAD_LEFT);
1279
- // calculate check digit
1280
- if ($len == 2) {
1281
- $r = $code % 4;
1282
- } elseif ($len == 5) {
1283
- $r = (3 * ($code{0} + $code{2} + $code{4})) + (9 * ($code{1} + $code{3}));
1284
- $r %= 10;
1285
- } else {
1286
- return false;
1287
- }
1288
- //Convert digits to bars
1289
- $codes = array(
1290
- 'A'=>array( // left odd parity
1291
- '0'=>'0001101',
1292
- '1'=>'0011001',
1293
- '2'=>'0010011',
1294
- '3'=>'0111101',
1295
- '4'=>'0100011',
1296
- '5'=>'0110001',
1297
- '6'=>'0101111',
1298
- '7'=>'0111011',
1299
- '8'=>'0110111',
1300
- '9'=>'0001011'),
1301
- 'B'=>array( // left even parity
1302
- '0'=>'0100111',
1303
- '1'=>'0110011',
1304
- '2'=>'0011011',
1305
- '3'=>'0100001',
1306
- '4'=>'0011101',
1307
- '5'=>'0111001',
1308
- '6'=>'0000101',
1309
- '7'=>'0010001',
1310
- '8'=>'0001001',
1311
- '9'=>'0010111')
1312
- );
1313
- $parities = array();
1314
- $parities[2] = array(
1315
- '0'=>array('A','A'),
1316
- '1'=>array('A','B'),
1317
- '2'=>array('B','A'),
1318
- '3'=>array('B','B')
1319
- );
1320
- $parities[5] = array(
1321
- '0'=>array('B','B','A','A','A'),
1322
- '1'=>array('B','A','B','A','A'),
1323
- '2'=>array('B','A','A','B','A'),
1324
- '3'=>array('B','A','A','A','B'),
1325
- '4'=>array('A','B','B','A','A'),
1326
- '5'=>array('A','A','B','B','A'),
1327
- '6'=>array('A','A','A','B','B'),
1328
- '7'=>array('A','B','A','B','A'),
1329
- '8'=>array('A','B','A','A','B'),
1330
- '9'=>array('A','A','B','A','B')
1331
- );
1332
- $p = $parities[$len][$r];
1333
- $seq = '1011'; // left guard bar
1334
- $seq .= $codes[$p[0]][$code{0}];
1335
- for ($i = 1; $i < $len; ++$i) {
1336
- $seq .= '01'; // separator
1337
- $seq .= $codes[$p[$i]][$code[$i]];
1338
- }
1339
- $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1340
- return $this->binseq_to_array($seq, $bararray);
1341
- }
1342
-
1343
- /**
1344
- * POSTNET and PLANET barcodes.
1345
- * Used by U.S. Postal Service for automated mail sorting
1346
- */
1347
- protected function barcode_postnet($code, $planet=false) {
1348
- // bar lenght
1349
- if ($planet) {
1350
- $barlen = Array(
1351
- 0 => Array(1,1,2,2,2),
1352
- 1 => Array(2,2,2,1,1),
1353
- 2 => Array(2,2,1,2,1),
1354
- 3 => Array(2,2,1,1,2),
1355
- 4 => Array(2,1,2,2,1),
1356
- 5 => Array(2,1,2,1,2),
1357
- 6 => Array(2,1,1,2,2),
1358
- 7 => Array(1,2,2,2,1),
1359
- 8 => Array(1,2,2,1,2),
1360
- 9 => Array(1,2,1,2,2)
1361
- );
1362
- } else {
1363
- $barlen = Array(
1364
- 0 => Array(2,2,1,1,1),
1365
- 1 => Array(1,1,1,2,2),
1366
- 2 => Array(1,1,2,1,2),
1367
- 3 => Array(1,1,2,2,1),
1368
- 4 => Array(1,2,1,1,2),
1369
- 5 => Array(1,2,1,2,1),
1370
- 6 => Array(1,2,2,1,1),
1371
- 7 => Array(2,1,1,1,2),
1372
- 8 => Array(2,1,1,2,1),
1373
- 9 => Array(2,1,2,1,1)
1374
- );
1375
- }
1376
- $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 5, 'bcode' => array());
1377
- $k = 0;
1378
- $code = str_replace('-', '', $code);
1379
- $code = str_replace(' ', '', $code);
1380
- $len = strlen($code);
1381
- // calculate checksum
1382
- $sum = 0;
1383
- for ($i = 0; $i < $len; ++$i) {
1384
- $sum += intval($code[$i]);
1385
- }
1386
- $chkd = ($sum % 10);
1387
- if($chkd > 0) {
1388
- $chkd = (10 - $chkd);
1389
- }
1390
- $code .= $chkd;
1391
- $checkdigit = $chkd;
1392
- $len = strlen($code);
1393
- // start bar
1394
- $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => 5, 'p' => 0);
1395
- $bararray['bcode'][$k++] = array('t' => 0, 'w' => $this->gapwidth , 'h' => 5, 'p' => 0);
1396
- $bararray['maxw'] += (1 + $this->gapwidth );
1397
- for ($i = 0; $i < $len; ++$i) {
1398
- for ($j = 0; $j < 5; ++$j) {
1399
- $bh = $barlen[$code[$i]][$j];
1400
- if ($bh == 2) {
1401
- $h = 5;
1402
- $p = 0;
1403
- }
1404
- else {
1405
- $h = 2;
1406
- $p = 3;
1407
- }
1408
- $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $h, 'p' => $p);
1409
- $bararray['bcode'][$k++] = array('t' => 0, 'w' => $this->gapwidth , 'h' => 2, 'p' => 0);
1410
- $bararray['maxw'] += (1 + $this->gapwidth );
1411
- }
1412
- }
1413
- // end bar
1414
- $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => 5, 'p' => 0);
1415
- $bararray['maxw'] += 1;
1416
- $bararray['checkdigit'] = $checkdigit;
1417
- return $bararray;
1418
- }
1419
-
1420
- /**
1421
- * RM4SCC - CBC - KIX
1422
- * RM4SCC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code) - KIX (Klant index - Customer index)
1423
- * RM4SCC is the name of the barcode symbology used by the Royal Mail for its Cleanmail service.
1424
- */
1425
- protected function barcode_rm4scc($code, $kix=false) {
1426
- $notkix = !$kix;
1427
- // bar mode
1428
- // 1 = pos 1, length 2
1429
- // 2 = pos 1, length 3
1430
- // 3 = pos 2, length 1
1431
- // 4 = pos 2, length 2
1432
- $barmode = array(
1433
- '0' => array(3,3,2,2),
1434
- '1' => array(3,4,1,2),
1435
- '2' => array(3,4,2,1),
1436
- '3' => array(4,3,1,2),
1437
- '4' => array(4,3,2,1),
1438
- '5' => array(4,4,1,1),
1439
- '6' => array(3,1,4,2),
1440
- '7' => array(3,2,3,2),
1441
- '8' => array(3,2,4,1),
1442
- '9' => array(4,1,3,2),
1443
- 'A' => array(4,1,4,1),
1444
- 'B' => array(4,2,3,1),
1445
- 'C' => array(3,1,2,4),
1446
- 'D' => array(3,2,1,4),
1447
- 'E' => array(3,2,2,3),
1448
- 'F' => array(4,1,1,4),
1449
- 'G' => array(4,1,2,3),
1450
- 'H' => array(4,2,1,3),
1451
- 'I' => array(1,3,4,2),
1452
- 'J' => array(1,4,3,2),
1453
- 'K' => array(1,4,4,1),
1454
- 'L' => array(2,3,3,2),
1455
- 'M' => array(2,3,4,1),
1456
- 'N' => array(2,4,3,1),
1457
- 'O' => array(1,3,2,4),
1458
- 'P' => array(1,4,1,4),
1459
- 'Q' => array(1,4,2,3),
1460
- 'R' => array(2,3,1,4),
1461
- 'S' => array(2,3,2,3),
1462
- 'T' => array(2,4,1,3),
1463
- 'U' => array(1,1,4,4),
1464
- 'V' => array(1,2,3,4),
1465
- 'W' => array(1,2,4,3),
1466
- 'X' => array(2,1,3,4),
1467
- 'Y' => array(2,1,4,3),
1468
- 'Z' => array(2,2,3,3)
1469
- );
1470
- $code = strtoupper($code);
1471
- $len = strlen($code);
1472
- $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => $this->daft['F'], 'bcode' => array());
1473
- if ($notkix) {
1474
- // table for checksum calculation (row,col)
1475
- $checktable = array(
1476
- '0' => array(1,1),
1477
- '1' => array(1,2),
1478
- '2' => array(1,3),
1479
- '3' => array(1,4),
1480
- '4' => array(1,5),
1481
- '5' => array(1,0),
1482
- '6' => array(2,1),
1483
- '7' => array(2,2),
1484
- '8' => array(2,3),
1485
- '9' => array(2,4),
1486
- 'A' => array(2,5),
1487
- 'B' => array(2,0),
1488
- 'C' => array(3,1),
1489
- 'D' => array(3,2),
1490
- 'E' => array(3,3),
1491
- 'F' => array(3,4),
1492
- 'G' => array(3,5),
1493
- 'H' => array(3,0),
1494
- 'I' => array(4,1),
1495
- 'J' => array(4,2),
1496
- 'K' => array(4,3),
1497
- 'L' => array(4,4),
1498
- 'M' => array(4,5),
1499
- 'N' => array(4,0),
1500
- 'O' => array(5,1),
1501
- 'P' => array(5,2),
1502
- 'Q' => array(5,3),
1503
- 'R' => array(5,4),
1504
- 'S' => array(5,5),
1505
- 'T' => array(5,0),
1506
- 'U' => array(0,1),
1507
- 'V' => array(0,2),
1508
- 'W' => array(0,3),
1509
- 'X' => array(0,4),
1510
- 'Y' => array(0,5),
1511
- 'Z' => array(0,0)
1512
- );
1513
- $row = 0;
1514
- $col = 0;
1515
- for ($i = 0; $i < $len; ++$i) {
1516
- $row += $checktable[$code[$i]][0];
1517
- $col += $checktable[$code[$i]][1];
1518
- }
1519
- $row %= 6;
1520
- $col %= 6;
1521
- $chk = array_keys($checktable, array($row,$col));
1522
- $code .= $chk[0];
1523
- $bararray['checkdigit'] = $chk[0];
1524
- ++$len;
1525
- }
1526
- $k = 0;
1527
- if ($notkix) {
1528
- // start bar
1529
- $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $this->daft['A'] , 'p' => 0);
1530
- $bararray['bcode'][$k++] = array('t' => 0, 'w' => $this->gapwidth , 'h' => $this->daft['A'] , 'p' => 0);
1531
- $bararray['maxw'] += (1 + $this->gapwidth) ;
1532
- }
1533
- for ($i = 0; $i < $len; ++$i) {
1534
- for ($j = 0; $j < 4; ++$j) {
1535
- switch ($barmode[$code[$i]][$j]) {
1536
- case 1: {
1537
- // ascender (A)
1538
- $p = 0;
1539
- $h = $this->daft['A'];
1540
- break;
1541
- }
1542
- case 2: {
1543
- // full bar (F)
1544
- $p = 0;
1545
- $h = $this->daft['F'];
1546
- break;
1547
- }
1548
- case 3: {
1549
- // tracker (T)
1550
- $p = ($this->daft['F'] - $this->daft['T'])/2;
1551
- $h = $this->daft['T'];
1552
- break;
1553
- }
1554
- case 4: {
1555
- // descender (D)
1556
- $p = $this->daft['F'] - $this->daft['D'];
1557
- $h = $this->daft['D'];
1558
- break;
1559
- }
1560
- }
1561
-
1562
- $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $h, 'p' => $p);
1563
- $bararray['bcode'][$k++] = array('t' => 0, 'w' => $this->gapwidth, 'h' => 2, 'p' => 0);
1564
- $bararray['maxw'] += (1 + $this->gapwidth) ;
1565
- }
1566
- }
1567
- if ($notkix) {
1568
- // stop bar
1569
- $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $this->daft['F'], 'p' => 0);
1570
- $bararray['maxw'] += 1;
1571
- }
1572
- return $bararray;
1573
- }
1574
-
1575
- /**
1576
- * CODABAR barcodes.
1577
- * Older code often used in library systems, sometimes in blood banks
1578
- */
1579
- protected function barcode_codabar($code) {
1580
- $chr = array(
1581
- '0' => '11111221',
1582
- '1' => '11112211',
1583
- '2' => '11121121',
1584
- '3' => '22111111',
1585
- '4' => '11211211',
1586
- '5' => '21111211',
1587
- '6' => '12111121',
1588
- '7' => '12112111',
1589
- '8' => '12211111',
1590
- '9' => '21121111',
1591
- '-' => '11122111',
1592
- '$' => '11221111',
1593
- ':' => '21112121',
1594
- '/' => '21211121',
1595
- '.' => '21212111',
1596
- '+' => '11222221',
1597
- 'A' => '11221211',
1598
- 'B' => '12121121',
1599
- 'C' => '11121221',
1600
- 'D' => '11122211'
1601
- );
1602
- $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1603
- $k = 0;
1604
- $w = 0;
1605
- $seq = '';
1606
- $code = strtoupper($code);
1607
- $len = strlen($code);
1608
- for ($i = 0; $i < $len; ++$i) {
1609
- if (!isset($chr[$code[$i]])) {
1610
- return false;
1611
- }
1612
- $seq = $chr[$code[$i]];
1613
- for ($j = 0; $j < 8; ++$j) {
1614
- if (($j % 2) == 0) {
1615
- $t = true; // bar
1616
- } else {
1617
- $t = false; // space
1618
- }
1619
- $x = $seq[$j];
1620
- if ($x == 2) { $w = $this->print_ratio; }
1621
- else { $w = 1; }
1622
- $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
1623
- $bararray['maxw'] += $w;
1624
- ++$k;
1625
- }
1626
- }
1627
- return $bararray;
1628
- }
1629
-
1630
- /**
1631
- * CODE11 barcodes.
1632
- * Used primarily for labeling telecommunications equipment
1633
- */
1634
- protected function barcode_code11($code) {
1635
- $chr = array(
1636
- '0' => '111121',
1637
- '1' => '211121',
1638
- '2' => '121121',
1639
- '3' => '221111',
1640
- '4' => '112121',
1641
- '5' => '212111',
1642
- '6' => '122111',
1643
- '7' => '111221',
1644
- '8' => '211211',
1645
- '9' => '211111',
1646
- '-' => '112111',
1647
- 'S' => '112211'
1648
- );
1649
-
1650
- $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1651
- $k = 0;
1652
- $w = 0;
1653
- $seq = '';
1654
- $len = strlen($code);
1655
- // calculate check digit C
1656
- $p = 1;
1657
- $check = 0;
1658
- for ($i = ($len - 1); $i >= 0; --$i) {
1659
- $digit = $code[$i];
1660
- if ($digit == '-') {
1661
- $dval = 10;
1662
- } else {
1663
- $dval = intval($digit);
1664
- }
1665
- $check += ($dval * $p);
1666
- ++$p;
1667
- if ($p > 10) {
1668
- $p = 1;
1669
- }
1670
- }
1671
- $check %= 11;
1672
- if ($check == 10) {
1673
- $check = '-';
1674
- }
1675
- $code .= $check;
1676
- $checkdigit = $check;
1677
- if ($len > 10) {
1678
- // calculate check digit K
1679
- $p = 1;
1680
- $check = 0;
1681
- for ($i = $len; $i >= 0; --$i) {
1682
- $digit = $code[$i];
1683
- if ($digit == '-') {
1684
- $dval = 10;
1685
- } else {
1686
- $dval = intval($digit);
1687
- }
1688
- $check += ($dval * $p);
1689
- ++$p;
1690
- if ($p > 9) {
1691
- $p = 1;
1692
- }
1693
- }
1694
- $check %= 11;
1695
- $code .= $check;
1696
- $checkdigit .= $check;
1697
- ++$len;
1698
- }
1699
- $code = 'S'.$code.'S';
1700
- $len += 3;
1701
- for ($i = 0; $i < $len; ++$i) {
1702
- if (!isset($chr[$code[$i]])) {
1703
- return false;
1704
- }
1705
- $seq = $chr[$code[$i]];
1706
- for ($j = 0; $j < 6; ++$j) {
1707
- if (($j % 2) == 0) {
1708
- $t = true; // bar
1709
- } else {
1710
- $t = false; // space
1711
- }
1712
- $x = $seq[$j];
1713
- if ($x == 2) { $w = $this->print_ratio; }
1714
- else { $w = 1; }
1715
- $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
1716
- $bararray['maxw'] += $w;
1717
- ++$k;
1718
- }
1719
- }
1720
- $bararray['checkdigit'] = $checkdigit;
1721
- return $bararray;
1722
- }
1723
-
1724
-
1725
- /**
1726
- * IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200
1727
- * (requires PHP bcmath extension)
1728
- * Intelligent Mail barcode is a 65-bar code for use on mail in the United States.
1729
- * The fields are described as follows:<ul><li>The Barcode Identifier shall be assigned by USPS to encode the presort identification that is currently printed in human readable form on the optional endorsement line (OEL) as well as for future USPS use. This shall be two digits, with the second digit in the range of 0-4. The allowable encoding ranges shall be 00-04, 10-14, 20-24, 30-34, 40-44, 50-54, 60-64, 70-74, 80-84, and 90-94.</li><li>The Service Type Identifier shall be assigned by USPS for any combination of services requested on the mailpiece. The allowable encoding range shall be 000-999. Each 3-digit value shall correspond to a particular mail class with a particular combination of service(s). Each service program, such as OneCode Confirm and OneCode ACS, shall provide the list of Service Type Identifier values.</li><li>The Mailer or Customer Identifier shall be assigned by USPS as a unique, 6 or 9 digit number that identifies a business entity. The allowable encoding range for the 6 digit Mailer ID shall be 000000- 899999, while the allowable encoding range for the 9 digit Mailer ID shall be 900000000-999999999.</li><li>The Serial or Sequence Number shall be assigned by the mailer for uniquely identifying and tracking mailpieces. The allowable encoding range shall be 000000000-999999999 when used with a 6 digit Mailer ID and 000000-999999 when used with a 9 digit Mailer ID. e. The Delivery Point ZIP Code shall be assigned by the mailer for routing the mailpiece. This shall replace POSTNET for routing the mailpiece to its final delivery point. The length may be 0, 5, 9, or 11 digits. The allowable encoding ranges shall be no ZIP Code, 00000-99999, 000000000-999999999, and 00000000000-99999999999.</li></ul>
1730
- */
1731
- protected function barcode_imb($code) {
1732
- $asc_chr = array(4,0,2,6,3,5,1,9,8,7,1,2,0,6,4,8,2,9,5,3,0,1,3,7,4,6,8,9,2,0,5,1,9,4,3,8,6,7,1,2,4,3,9,5,7,8,3,0,2,1,4,0,9,1,7,0,2,4,6,3,7,1,9,5,8);
1733
- $dsc_chr = array(7,1,9,5,8,0,2,4,6,3,5,8,9,7,3,0,6,1,7,4,6,8,9,2,5,1,7,5,4,3,8,7,6,0,2,5,4,9,3,0,1,6,8,2,0,4,5,9,6,7,5,2,6,3,8,5,1,9,8,7,4,0,2,6,3);
1734
- $asc_pos = array(3,0,8,11,1,12,8,11,10,6,4,12,2,7,9,6,7,9,2,8,4,0,12,7,10,9,0,7,10,5,7,9,6,8,2,12,1,4,2,0,1,5,4,6,12,1,0,9,4,7,5,10,2,6,9,11,2,12,6,7,5,11,0,3,2);
1735
- $dsc_pos = array(2,10,12,5,9,1,5,4,3,9,11,5,10,1,6,3,4,1,10,0,2,11,8,6,1,12,3,8,6,4,4,11,0,6,1,9,11,5,3,7,3,10,7,11,8,2,10,3,5,8,0,3,12,11,8,4,5,1,3,0,7,12,9,8,10);
1736
- $code_arr = explode('-', $code);
1737
- $tracking_number = $code_arr[0];
1738
- if (isset($code_arr[1])) {
1739
- $routing_code = $code_arr[1];
1740
- } else {
1741
- $routing_code = '';
1742
- }
1743
- // Conversion of Routing Code
1744
- switch (strlen($routing_code)) {
1745
- case 0: {
1746
- $binary_code = 0;
1747
- break;
1748
- }
1749
- case 5: {
1750
- $binary_code = bcadd($routing_code, '1');
1751
- break;
1752
- }
1753
- case 9: {
1754
- $binary_code = bcadd($routing_code, '100001');
1755
- break;
1756
- }
1757
- case 11: {
1758
- $binary_code = bcadd($routing_code, '1000100001');
1759
- break;
1760
- }
1761
- default: {
1762
- return false;
1763
- break;
1764
- }
1765
- }
1766
- $binary_code = bcmul($binary_code, 10);
1767
- $binary_code = bcadd($binary_code, $tracking_number{0});
1768
- $binary_code = bcmul($binary_code, 5);
1769
- $binary_code = bcadd($binary_code, $tracking_number{1});
1770
- $binary_code .= substr($tracking_number, 2, 18);
1771
- // convert to hexadecimal
1772
- $binary_code = $this->dec_to_hex($binary_code);
1773
- // pad to get 13 bytes
1774
- $binary_code = str_pad($binary_code, 26, '0', STR_PAD_LEFT);
1775
- // convert string to array of bytes
1776
- $binary_code_arr = chunk_split($binary_code, 2, "\r");
1777
- $binary_code_arr = substr($binary_code_arr, 0, -1);
1778
- $binary_code_arr = explode("\r", $binary_code_arr);
1779
- // calculate frame check sequence
1780
- $fcs = $this->imb_crc11fcs($binary_code_arr);
1781
- // exclude first 2 bits from first byte
1782
- $first_byte = sprintf('%2s', dechex((hexdec($binary_code_arr[0]) << 2) >> 2));
1783
- $binary_code_102bit = $first_byte.substr($binary_code, 2);
1784
- // convert binary data to codewords
1785
- $codewords = array();
1786
- $data = $this->hex_to_dec($binary_code_102bit);
1787
- $codewords[0] = bcmod($data, 636) * 2;
1788
- $data = bcdiv($data, 636);
1789
- for ($i = 1; $i < 9; ++$i) {
1790
- $codewords[$i] = bcmod($data, 1365);
1791
- $data = bcdiv($data, 1365);
1792
- }
1793
- $codewords[9] = $data;
1794
- if (($fcs >> 10) == 1) {
1795
- $codewords[9] += 659;
1796
- }
1797
- // generate lookup tables
1798
- $table2of13 = $this->imb_tables(2, 78);
1799
- $table5of13 = $this->imb_tables(5, 1287);
1800
- // convert codewords to characters
1801
- $characters = array();
1802
- $bitmask = 512;
1803
- foreach($codewords as $k => $val) {
1804
- if ($val <= 1286) {
1805
- $chrcode = $table5of13[$val];
1806
- } else {
1807
- $chrcode = $table2of13[($val - 1287)];
1808
- }
1809
- if (($fcs & $bitmask) > 0) {
1810
- // bitwise invert
1811
- $chrcode = ((~$chrcode) & 8191);
1812
- }
1813
- $characters[] = $chrcode;
1814
- $bitmask /= 2;
1815
- }
1816
- $characters = array_reverse($characters);
1817
- // build bars
1818
- $k = 0;
1819
- $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => $this->daft['F'], 'bcode' => array());
1820
- for ($i = 0; $i < 65; ++$i) {
1821
- $asc = (($characters[$asc_chr[$i]] & pow(2, $asc_pos[$i])) > 0);
1822
- $dsc = (($characters[$dsc_chr[$i]] & pow(2, $dsc_pos[$i])) > 0);
1823
- if ($asc AND $dsc) {
1824
- // full bar (F)
1825
- $p = 0;
1826
- $h = $this->daft['F'];
1827
- } elseif ($asc) {
1828
- // ascender (A)
1829
- $p = 0;
1830
- $h = $this->daft['A'];
1831
- } elseif ($dsc) {
1832
- // descender (D)
1833
- $p = $this->daft['F'] - $this->daft['D'];
1834
- $h = $this->daft['D'];
1835
- } else {
1836
- // tracker (T)
1837
- $p = ($this->daft['F'] - $this->daft['T'])/2;
1838
- $h = $this->daft['T'];
1839
- }
1840
- $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $h, 'p' => $p);
1841
- // Gap
1842
- $bararray['bcode'][$k++] = array('t' => 0, 'w' => $this->gapwidth , 'h' => 1, 'p' => 0);
1843
- $bararray['maxw'] += (1 + $this->gapwidth );
1844
- }
1845
- unset($bararray['bcode'][($k - 1)]);
1846
- $bararray['maxw'] -= $this->gapwidth ;
1847
- return $bararray;
1848
- }
1849
-
1850
- /**
1851
- * Convert large integer number to hexadecimal representation.
1852
- * (requires PHP bcmath extension)
1853
- */
1854
- public function dec_to_hex($number) {
1855
- $i = 0;
1856
- $hex = array();
1857
- if($number == 0) {
1858
- return '00';
1859
- }
1860
- while($number > 0) {
1861
- if($number == 0) {
1862
- array_push($hex, '0');
1863
- } else {
1864
- array_push($hex, strtoupper(dechex(bcmod($number, '16'))));
1865
- $number = bcdiv($number, '16', 0);
1866
- }
1867
- }
1868
- $hex = array_reverse($hex);
1869
- return implode($hex);
1870
- }
1871
-
1872
- /**
1873
- * Convert large hexadecimal number to decimal representation (string).
1874
- * (requires PHP bcmath extension)
1875
- */
1876
- public function hex_to_dec($hex) {
1877
- $dec = 0;
1878
- $bitval = 1;
1879
- $len = strlen($hex);
1880
- for($pos = ($len - 1); $pos >= 0; --$pos) {
1881
- $dec = bcadd($dec, bcmul(hexdec($hex[$pos]), $bitval));
1882
- $bitval = bcmul($bitval, 16);
1883
- }
1884
- return $dec;
1885
- }
1886
-
1887
- /**
1888
- * Intelligent Mail Barcode calculation of Frame Check Sequence
1889
- */
1890
- protected function imb_crc11fcs($code_arr) {
1891
- $genpoly = 0x0F35; // generator polynomial
1892
- $fcs = 0x07FF; // Frame Check Sequence
1893
- // do most significant byte skipping the 2 most significant bits
1894
- $data = hexdec($code_arr[0]) << 5;
1895
- for ($bit = 2; $bit < 8; ++$bit) {
1896
- if (($fcs ^ $data) & 0x400) {
1897
- $fcs = ($fcs << 1) ^ $genpoly;
1898
- } else {
1899
- $fcs = ($fcs << 1);
1900
- }
1901
- $fcs &= 0x7FF;
1902
- $data <<= 1;
1903
- }
1904
- // do rest of bytes
1905
- for ($byte = 1; $byte < 13; ++$byte) {
1906
- $data = hexdec($code_arr[$byte]) << 3;
1907
- for ($bit = 0; $bit < 8; ++$bit) {
1908
- if (($fcs ^ $data) & 0x400) {
1909
- $fcs = ($fcs << 1) ^ $genpoly;
1910
- } else {
1911
- $fcs = ($fcs << 1);
1912
- }
1913
- $fcs &= 0x7FF;
1914
- $data <<= 1;
1915
- }
1916
- }
1917
- return $fcs;
1918
- }
1919
-
1920
- /**
1921
- * Reverse unsigned short value
1922
- */
1923
- protected function imb_reverse_us($num) {
1924
- $rev = 0;
1925
- for ($i = 0; $i < 16; ++$i) {
1926
- $rev <<= 1;
1927
- $rev |= ($num & 1);
1928
- $num >>= 1;
1929
- }
1930
- return $rev;
1931
- }
1932
-
1933
- /**
1934
- * generate Nof13 tables used for Intelligent Mail Barcode
1935
- */
1936
- protected function imb_tables($n, $size) {
1937
- $table = array();
1938
- $lli = 0; // LUT lower index
1939
- $lui = $size - 1; // LUT upper index
1940
- for ($count = 0; $count < 8192; ++$count) {
1941
- $bit_count = 0;
1942
- for ($bit_index = 0; $bit_index < 13; ++$bit_index) {
1943
- $bit_count += intval(($count & (1 << $bit_index)) != 0);
1944
- }
1945
- // if we don't have the right number of bits on, go on to the next value
1946
- if ($bit_count == $n) {
1947
- $reverse = ($this->imb_reverse_us($count) >> 3);
1948
- // if the reverse is less than count, we have already visited this pair before
1949
- if ($reverse >= $count) {
1950
- // If count is symmetric, place it at the first free slot from the end of the list.
1951
- // Otherwise, place it at the first free slot from the beginning of the list AND place $reverse ath the next free slot from the beginning of the list
1952
- if ($reverse == $count) {
1953
- $table[$lui] = $count;
1954
- --$lui;
1955
- } else {
1956
- $table[$lli] = $count;
1957
- ++$lli;
1958
- $table[$lli] = $reverse;
1959
- ++$lli;
1960
- }
1961
- }
1962
- }
1963
- }
1964
- return $table;
1965
- }
1966
-
1967
- } // end of class
1968
-
1969
- //============================================================+
1970
- // END OF FILE
1971
- //============================================================+
1972
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/mpdf/classes/bmp.php DELETED
@@ -1,248 +0,0 @@
1
- <?php
2
-
3
- class bmp {
4
-
5
- var $mpdf = null;
6
-
7
- function bmp(&$mpdf) {
8
- $this->mpdf = $mpdf;
9
- }
10
-
11
-
12
- function _getBMPimage($data, $file) {
13
- $info = array();
14
- // Adapted from script by Valentin Schmidt
15
- // http://staff.dasdeck.de/valentin/fpdf/fpdf_bmp/
16
- $bfOffBits=$this->_fourbytes2int_le(substr($data,10,4));
17
- $width=$this->_fourbytes2int_le(substr($data,18,4));
18
- $height=$this->_fourbytes2int_le(substr($data,22,4));
19
- $flip = ($height<0);
20
- if ($flip) $height =-$height;
21
- $biBitCount=$this->_twobytes2int_le(substr($data,28,2));
22
- $biCompression=$this->_fourbytes2int_le(substr($data,30,4));
23
- $info = array('w'=>$width, 'h'=>$height);
24
- if ($biBitCount<16){
25
- $info['cs'] = 'Indexed';
26
- $info['bpc'] = $biBitCount;
27
- $palStr = substr($data,54,($bfOffBits-54));
28
- $pal = '';
29
- $cnt = strlen($palStr)/4;
30
- for ($i=0;$i<$cnt;$i++){
31
- $n = 4*$i;
32
- $pal .= $palStr[$n+2].$palStr[$n+1].$palStr[$n];
33
- }
34
- $info['pal'] = $pal;
35
- }
36
- else{
37
- $info['cs'] = 'DeviceRGB';
38
- $info['bpc'] = 8;
39
- }
40
-
41
- if ($this->mpdf->restrictColorSpace==1 || $this->mpdf->PDFX || $this->mpdf->restrictColorSpace==3) {
42
- if (($this->mpdf->PDFA && !$this->mpdf->PDFAauto) || ($this->mpdf->PDFX && !$this->mpdf->PDFXauto)) { $this->mpdf->PDFAXwarnings[] = "Image cannot be converted to suitable colour space for PDFA or PDFX file - ".$file." - (Image replaced by 'no-image'.)"; }
43
- return array('error' => "BMP Image cannot be converted to suitable colour space - ".$file." - (Image replaced by 'no-image'.)");
44
- }
45
-
46
- $biXPelsPerMeter=$this->_fourbytes2int_le(substr($data,38,4)); // horizontal pixels per meter, usually set to zero
47
- //$biYPelsPerMeter=$this->_fourbytes2int_le(substr($data,42,4)); // vertical pixels per meter, usually set to zero
48
- $biXPelsPerMeter=round($biXPelsPerMeter/1000 *25.4);
49
- //$biYPelsPerMeter=round($biYPelsPerMeter/1000 *25.4);
50
- $info['set-dpi'] = $biXPelsPerMeter;
51
-
52
- switch ($biCompression){
53
- case 0:
54
- $str = substr($data,$bfOffBits);
55
- break;
56
- case 1: # BI_RLE8
57
- $str = $this->rle8_decode(substr($data,$bfOffBits), $width);
58
- break;
59
- case 2: # BI_RLE4
60
- $str = $this->rle4_decode(substr($data,$bfOffBits), $width);
61
- break;
62
- }
63
- $bmpdata = '';
64
- $padCnt = (4-ceil(($width/(8/$biBitCount)))%4)%4;
65
- switch ($biBitCount){
66
- case 1:
67
- case 4:
68
- case 8:
69
- $w = floor($width/(8/$biBitCount)) + ($width%(8/$biBitCount)?1:0);
70
- $w_row = $w + $padCnt;
71
- if ($flip){
72
- for ($y=0;$y<$height;$y++){
73
- $y0 = $y*$w_row;
74
- for ($x=0;$x<$w;$x++)
75
- $bmpdata .= $str[$y0+$x];
76
- }
77
- }else{
78
- for ($y=$height-1;$y>=0;$y--){
79
- $y0 = $y*$w_row;
80
- for ($x=0;$x<$w;$x++)
81
- $bmpdata .= $str[$y0+$x];
82
- }
83
- }
84
- break;
85
-
86
- case 16:
87
- $w_row = $width*2 + $padCnt;
88
- if ($flip){
89
- for ($y=0;$y<$height;$y++){
90
- $y0 = $y*$w_row;
91
- for ($x=0;$x<$width;$x++){
92
- $n = (ord( $str[$y0 + 2*$x + 1])*256 + ord( $str[$y0 + 2*$x]));
93
- $b = ($n & 31)<<3; $g = ($n & 992)>>2; $r = ($n & 31744)>>7128;
94
- $bmpdata .= chr($r) . chr($g) . chr($b);
95
- }
96
- }
97
- }else{
98
- for ($y=$height-1;$y>=0;$y--){
99
- $y0 = $y*$w_row;
100
- for ($x=0;$x<$width;$x++){
101
- $n = (ord( $str[$y0 + 2*$x + 1])*256 + ord( $str[$y0 + 2*$x]));
102
- $b = ($n & 31)<<3; $g = ($n & 992)>>2; $r = ($n & 31744)>>7;
103
- $bmpdata .= chr($r) . chr($g) . chr($b);
104
- }
105
- }
106
- }
107
- break;
108
-
109
- case 24:
110
- case 32:
111
- $byteCnt = $biBitCount/8;
112
- $w_row = $width*$byteCnt + $padCnt;
113
-
114
- if ($flip){
115
- for ($y=0;$y<$height;$y++){
116
- $y0 = $y*$w_row;
117
- for ($x=0;$x<$width;$x++){
118
- $i = $y0 + $x*$byteCnt ; # + 1
119
- $bmpdata .= $str[$i+2].$str[$i+1].$str[$i];
120
- }
121
- }
122
- }else{
123
- for ($y=$height-1;$y>=0;$y--){
124
- $y0 = $y*$w_row;
125
- for ($x=0;$x<$width;$x++){
126
- $i = $y0 + $x*$byteCnt ; # + 1
127
- $bmpdata .= $str[$i+2].$str[$i+1].$str[$i];
128
- }
129
- }
130
- }
131
- break;
132
-
133
- default:
134
- return array('error' => 'Error parsing BMP image - Unsupported image biBitCount');
135
- }
136
- if ($this->mpdf->compress) {
137
- $bmpdata=gzcompress($bmpdata);
138
- $info['f']='FlateDecode';
139
- }
140
- $info['data']=$bmpdata;
141
- $info['type']='bmp';
142
- return $info;
143
- }
144
-
145
- function _fourbytes2int_le($s) {
146
- //Read a 4-byte integer from string
147
- return (ord($s[3])<<24) + (ord($s[2])<<16) + (ord($s[1])<<8) + ord($s[0]);
148
- }
149
-
150
- function _twobytes2int_le($s) {
151
- //Read a 2-byte integer from string
152
- return (ord(substr($s, 1, 1))<<8) + ord(substr($s, 0, 1));
153
- }
154
-
155
-
156
- # Decoder for RLE8 compression in windows bitmaps
157
- # see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_6x0u.asp
158
- function rle8_decode ($str, $width){
159
- $lineWidth = $width + (3 - ($width-1) % 4);
160
- $out = '';
161
- $cnt = strlen($str);
162
- for ($i=0;$i<$cnt;$i++){
163
- $o = ord($str[$i]);
164
- switch ($o){
165
- case 0: # ESCAPE
166
- $i++;
167
- switch (ord($str[$i])){
168
- case 0: # NEW LINE
169
- $padCnt = $lineWidth - strlen($out)%$lineWidth;
170
- if ($padCnt<$lineWidth) $out .= str_repeat(chr(0), $padCnt); # pad line
171
- break;
172
- case 1: # END OF FILE
173
- $padCnt = $lineWidth - strlen($out)%$lineWidth;
174
- if ($padCnt<$lineWidth) $out .= str_repeat(chr(0), $padCnt); # pad line
175
- break 3;
176
- case 2: # DELTA
177
- $i += 2;
178
- break;
179
- default: # ABSOLUTE MODE
180
- $num = ord($str[$i]);
181
- for ($j=0;$j<$num;$j++)
182
- $out .= $str[++$i];
183
- if ($num % 2) $i++;
184
- }
185
- break;
186
- default:
187
- $out .= str_repeat($str[++$i], $o);
188
- }
189
- }
190
- return $out;
191
- }
192
-
193
- # Decoder for RLE4 compression in windows bitmaps
194
- # see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_6x0u.asp
195
- function rle4_decode ($str, $width){
196
- $w = floor($width/2) + ($width % 2);
197
- $lineWidth = $w + (3 - ( ($width-1) / 2) % 4);
198
- $pixels = array();
199
- $cnt = strlen($str);
200
- for ($i=0;$i<$cnt;$i++){
201
- $o = ord($str[$i]);
202
- switch ($o){
203
- case 0: # ESCAPE
204
- $i++;
205
- switch (ord($str[$i])){
206
- case 0: # NEW LINE
207
- while (count($pixels)%$lineWidth!=0)
208
- $pixels[]=0;
209
- break;
210
- case 1: # END OF FILE
211
- while (count($pixels)%$lineWidth!=0)
212
- $pixels[]=0;
213
- break 3;
214
- case 2: # DELTA
215
- $i += 2;
216
- break;
217
- default: # ABSOLUTE MODE
218
- $num = ord($str[$i]);
219
- for ($j=0;$j<$num;$j++){
220
- if ($j%2==0){
221
- $c = ord($str[++$i]);
222
- $pixels[] = ($c & 240)>>4;
223
- } else
224
- $pixels[] = $c & 15;
225
- }
226
- if ($num % 2) $i++;
227
- }
228
- break;
229
- default:
230
- $c = ord($str[++$i]);
231
- for ($j=0;$j<$o;$j++)
232
- $pixels[] = ($j%2==0 ? ($c & 240)>>4 : $c & 15);
233
- }
234
- }
235
-
236
- $out = '';
237
- if (count($pixels)%2) $pixels[]=0;
238
- $cnt = count($pixels)/2;
239
- for ($i=0;$i<$cnt;$i++)
240
- $out .= chr(16*$pixels[2*$i] + $pixels[2*$i+1]);
241
- return $out;
242
- }
243
-
244
-
245
-
246
- }
247
-
248
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/mpdf/classes/cssmgr.php DELETED
@@ -1,1721 +0,0 @@
1
- <?php
2
-
3
- class cssmgr {
4
-
5
- var $mpdf = null;
6
-
7
- var $tablecascadeCSS;
8
- var $cascadeCSS;
9
- var $CSS;
10
- var $tbCSSlvl;
11
-
12
-
13
- function cssmgr(&$mpdf) {
14
- $this->mpdf = $mpdf;
15
- $this->tablecascadeCSS = array();
16
- $this->CSS=array();
17
- $this->cascadeCSS = array();
18
- $this->tbCSSlvl = 0;
19
- }
20
-
21
- function ReadCSS($html) {
22
- preg_match_all('/<style[^>]*media=["\']([^"\'>]*)["\'].*?<\/style>/is',$html,$m);
23
- for($i=0; $i<count($m[0]); $i++) {
24
- if ($this->mpdf->CSSselectMedia && !preg_match('/('.trim($this->mpdf->CSSselectMedia).'|all)/i',$m[1][$i])) {
25
- $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$html);
26
- }
27
- }
28
- preg_match_all('/<link[^>]*media=["\']([^"\'>]*)["\'].*?>/is',$html,$m);
29
- for($i=0; $i<count($m[0]); $i++) {
30
- if ($this->mpdf->CSSselectMedia && !preg_match('/('.trim($this->mpdf->CSSselectMedia).'|all)/i',$m[1][$i])) {
31
- $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$html);
32
- }
33
- }
34
-
35
- // mPDF 5.5.02
36
- // Remove Comment tags <!-- ... --> inside CSS as <style> in HTML document
37
- // Remove Comment tags /* ... */ inside CSS as <style> in HTML document
38
- // But first, we replace upper and mixed case closing style tag with lower
39
- // case so we can use str_replace later.
40
- preg_replace('/<\/style>/i', '</style>', $html);
41
- preg_match_all('/<style.*?>(.*?)<\/style>/si',$html,$m);
42
- if (count($m[1])) {
43
- for($i=0;$i<count($m[1]);$i++) {
44
- // Remove comment tags
45
- $sub = preg_replace('/(<\!\-\-|\-\->)/s',' ',$m[1][$i]);
46
- $sub = '>'.preg_replace('|/\*.*?\*/|s',' ',$sub).'</style>';
47
- $html = str_replace('>'.$m[1][$i].'</style>', $sub, $html);
48
- }
49
- }
50
-
51
-
52
- $html = preg_replace('/<!--mpdf/i','',$html);
53
- $html = preg_replace('/mpdf-->/i','',$html);
54
- $html = preg_replace('/<\!\-\-.*?\-\->/s',' ',$html);
55
-
56
- $match = 0; // no match for instance
57
- $regexp = ''; // This helps debugging: showing what is the REAL string being processed
58
- $CSSext = array();
59
-
60
- //CSS inside external files
61
- $regexp = '/<link[^>]*rel=["\']stylesheet["\'][^>]*href=["\']([^>"\']*)["\'].*?>/si';
62
- $x = preg_match_all($regexp,$html,$cxt);
63
- if ($x) {
64
- $match += $x;
65
- $CSSext = $cxt[1];
66
- }
67
- $regexp = '/<link[^>]*href=["\']([^>"\']*)["\'][^>]*?rel=["\']stylesheet["\'].*?>/si';
68
- $x = preg_match_all($regexp,$html,$cxt);
69
- if ($x) {
70
- $match += $x;
71
- $CSSext = array_merge($CSSext,$cxt[1]);
72
- }
73
-
74
- // look for @import stylesheets
75
- //$regexp = '/@import url\([\'\"]{0,1}([^\)]*?\.css)[\'\"]{0,1}\)/si';
76
- $regexp = '/@import url\([\'\"]{0,1}([^\)]*?\.css(\?\S+)?)[\'\"]{0,1}\)/si';
77
- $x = preg_match_all($regexp,$html,$cxt);
78
- if ($x) {
79
- $match += $x;
80
- $CSSext = array_merge($CSSext,$cxt[1]);
81
- }
82
-
83
- // look for @import without the url()
84
- //$regexp = '/@import [\'\"]{0,1}([^;]*?\.css)[\'\"]{0,1}/si';
85
- $regexp = '/@import [\'\"]{0,1}([^;]*?\.css(\?\S+)?)[\'\"]{0,1}/si';
86
- $x = preg_match_all($regexp,$html,$cxt);
87
- if ($x) {
88
- $match += $x;
89
- $CSSext = array_merge($CSSext,$cxt[1]);
90
- }
91
-
92
- $ind = 0;
93
- $CSSstr = '';
94
-
95
- if (!is_array($this->cascadeCSS)) $this->cascadeCSS = array();
96
-
97
- while($match){
98
- $path = $CSSext[$ind];
99
-
100
- $path = htmlspecialchars_decode($path); // mPDF 6
101
-
102
- $this->mpdf->GetFullPath($path);
103
- $CSSextblock = $this->mpdf->_get_file($path);
104
- if ($CSSextblock) {
105
- // look for embedded @import stylesheets in other stylesheets
106
- // and fix url paths (including background-images) relative to stylesheet
107
- //$regexpem = '/@import url\([\'\"]{0,1}(.*?\.css)[\'\"]{0,1}\)/si';
108
- $regexpem = '/@import url\([\'\"]{0,1}(.*?\.css(\?\S+)?)[\'\"]{0,1}\)/si';
109
- $xem = preg_match_all($regexpem,$CSSextblock,$cxtem);
110
- $cssBasePath = preg_replace('/\/[^\/]*$/','',$path) . '/';
111
- if ($xem) {
112
- foreach($cxtem[1] AS $cxtembedded) {
113
- // path is relative to original stlyesheet!!
114
- $this->mpdf->GetFullPath($cxtembedded, $cssBasePath );
115
- $match++;
116
- $CSSext[] = $cxtembedded;
117
- }
118
- }
119
- $regexpem = '/(background[^;]*url\s*\(\s*[\'\"]{0,1})([^\)\'\"]*)([\'\"]{0,1}\s*\))/si';
120
- $xem = preg_match_all($regexpem,$CSSextblock,$cxtem);
121
- if ($xem) {
122
- for ($i=0;$i<count($cxtem[0]);$i++) {
123
- // path is relative to original stlyesheet!!
124
- $embedded = $cxtem[2][$i];
125
- if (!preg_match('/^data:image/i', $embedded)) { // mPDF 5.5.13
126
- $this->mpdf->GetFullPath($embedded, $cssBasePath );
127
- $CSSextblock = preg_replace('/'.preg_quote($cxtem[0][$i],'/').'/', ($cxtem[1][$i].$embedded.$cxtem[3][$i]), $CSSextblock);
128
- }
129
- }
130
- }
131
- $CSSstr .= ' '.$CSSextblock;
132
- }
133
- $match--;
134
- $ind++;
135
- } //end of match
136
-
137
- $match = 0; // reset value, if needed
138
- // CSS as <style> in HTML document
139
- $regexp = '/<style.*?>(.*?)<\/style>/si';
140
- $match = preg_match_all($regexp,$html,$CSSblock);
141
- if ($match) {
142
- $tmpCSSstr = implode(' ',$CSSblock[1]);
143
- $regexpem = '/(background[^;]*url\s*\(\s*[\'\"]{0,1})([^\)\'\"]*)([\'\"]{0,1}\s*\))/si';
144
- $xem = preg_match_all($regexpem,$tmpCSSstr ,$cxtem);
145
- if ($xem) {
146
- for ($i=0;$i<count($cxtem[0]);$i++) {
147
- $embedded = $cxtem[2][$i];
148
- if (!preg_match('/^data:image/i', $embedded)) { // mPDF 5.5.13
149
- $this->mpdf->GetFullPath($embedded);
150
- $tmpCSSstr = preg_replace('/'.preg_quote($cxtem[0][$i],'/').'/', ($cxtem[1][$i].$embedded.$cxtem[3][$i]), $tmpCSSstr );
151
- }
152
- }
153
- }
154
- $CSSstr .= ' '.$tmpCSSstr;
155
- }
156
- // Remove comments
157
- $CSSstr = preg_replace('|/\*.*?\*/|s',' ',$CSSstr);
158
- $CSSstr = preg_replace('/[\s\n\r\t\f]/s',' ',$CSSstr);
159
-
160
- if (preg_match('/@media/',$CSSstr)) {
161
- preg_match_all('/@media(.*?)\{(([^\{\}]*\{[^\{\}]*\})+)\s*\}/is',$CSSstr,$m);
162
- for($i=0; $i<count($m[0]); $i++) {
163
- if ($this->mpdf->CSSselectMedia && !preg_match('/('.trim($this->mpdf->CSSselectMedia).'|all)/i',$m[1][$i])) {
164
- $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$CSSstr);
165
- }
166
- else {
167
- $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/',' '.$m[2][$i].' ',$CSSstr);
168
- }
169
- }
170
- }
171
-
172
- // Replace any background: url(data:image... with temporary image file reference
173
- preg_match_all("/(url\(data:image\/(jpeg|gif|png);base64,(.*?)\))/si", $CSSstr, $idata); // mPDF 5.7.2
174
- if (count($idata[0])) {
175
- for($i=0;$i<count($idata[0]);$i++) {
176
- $file = _MPDF_TEMP_PATH.'_tempCSSidata'.RAND(1,10000).'_'.$i.'.'.$idata[2][$i];
177
- //Save to local file
178
- file_put_contents($file, base64_decode($idata[3][$i]));
179
- // $this->mpdf->GetFullPath($file); // ? is this needed - NO mPDF 5.6.03
180
- $CSSstr = str_replace($idata[0][$i], 'url("'.$file.'")', $CSSstr); // mPDF 5.5.17
181
- }
182
- }
183
-
184
- $CSSstr = preg_replace('/(<\!\-\-|\-\->)/s',' ',$CSSstr);
185
-
186
- // mPDF 5.7.4 URLs
187
- // Characters "(" ")" and ";" in url() e.g. background-image, cause problems parsing the CSS string
188
- // URLencode ( and ), but change ";" to a code which can be converted back after parsing (so as not to confuse ;
189
- // with a segment delimiter in the URI)
190
- $tempmarker = '%ZZ';
191
- if (strpos($CSSstr,'url(')!==false) {
192
- preg_match_all( '/url\(\"(.*?)\"\)/', $CSSstr, $m);
193
- for($i = 0; $i < count($m[1]) ; $i++) {
194
- $tmp = str_replace(array('(',')',';'),array('%28','%29',$tempmarker),$m[1][$i]);
195
- $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/', 'url(\''.$tmp.'\')', $CSSstr);
196
- }
197
- preg_match_all( '/url\(\'(.*?)\'\)/', $CSSstr, $m);
198
- for($i = 0; $i < count($m[1]) ; $i++) {
199
- $tmp = str_replace(array('(',')',';'),array('%28','%29',$tempmarker),$m[1][$i]);
200
- $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/', 'url(\''.$tmp.'\')', $CSSstr);
201
- }
202
- preg_match_all( '/url\(([^\'\"].*?[^\'\"])\)/', $CSSstr, $m);
203
- for($i = 0; $i < count($m[1]) ; $i++) {
204
- $tmp = str_replace(array('(',')',';'),array('%28','%29',$tempmarker),$m[1][$i]);
205
- $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/', 'url(\''.$tmp.'\')', $CSSstr);
206
- }
207
- }
208
-
209
-
210
-
211
- if ($CSSstr ) {
212
- $classproperties = array(); // mPDF 6
213
- preg_match_all('/(.*?)\{(.*?)\}/',$CSSstr,$styles);
214
- for($i=0; $i < count($styles[1]) ; $i++) {
215
- // SET array e.g. $classproperties['COLOR'] = '#ffffff';
216
- $stylestr= trim($styles[2][$i]);
217
- $stylearr = explode(';',$stylestr);
218
- foreach($stylearr AS $sta) {
219
- if (trim($sta)) {
220
- // Changed to allow style="background: url('http://www.bpm1.com/bg.jpg')"
221
- $tmp = explode(':',$sta,2);
222
- $property = $tmp[0];
223
- if (isset($tmp[1])) { $value = $tmp[1]; }
224
- else { $value = ''; }
225
- $value = str_replace($tempmarker,';',$value); // mPDF 5.7.4 URLs
226
- $property = trim($property);
227
- $value = preg_replace('/\s*!important/i','',$value);
228
- $value = trim($value);
229
- if ($property && ($value || $value==='0')) {
230
- // Ignores -webkit-gradient so doesn't override -moz-
231
- if ((strtoupper($property)=='BACKGROUND-IMAGE' || strtoupper($property)=='BACKGROUND') && preg_match('/-webkit-gradient/i',$value)) {
232
- continue;
233
- }
234
- $classproperties[strtoupper($property)] = $value;
235
- }
236
- }
237
- }
238
- $classproperties = $this->fixCSS($classproperties);
239
- $tagstr = strtoupper(trim($styles[1][$i]));
240
- $tagarr = explode(',',$tagstr);
241
- $pageselectors = false; // used to turn on $this->mpdf->mirrorMargins
242
- foreach($tagarr AS $tg) {
243
- // mPDF 5.7.4
244
- if (preg_match('/NTH-CHILD\((\s*(([\-+]?\d*)N(\s*[\-+]\s*\d+)?|[\-+]?\d+|ODD|EVEN)\s*)\)/',$tg,$m) ) {
245
- $tg = preg_replace('/NTH-CHILD\(.*\)/', 'NTH-CHILD('.str_replace(' ','',$m[1]).')', $tg);
246
- }
247
- $tags = preg_split('/\s+/',trim($tg));
248
- $level = count($tags);
249
- $t = '';
250
- $t2 = '';
251
- $t3 = '';
252
- if (trim($tags[0])=='@PAGE') {
253
- if (isset($tags[0])) { $t = trim($tags[0]); }
254
- if (isset($tags[1])) { $t2 = trim($tags[1]); }
255
- if (isset($tags[2])) { $t3 = trim($tags[2]); }
256
- $tag = '';
257
- if ($level==1) { $tag = $t; }
258
- else if ($level==2 && preg_match('/^[:](.*)$/',$t2,$m)) {
259
- $tag = $t.'>>PSEUDO>>'.$m[1];
260
- if ($m[1]=='LEFT' || $m[1]=='RIGHT') { $pageselectors = true; } // used to turn on $this->mpdf->mirrorMargins
261
- }
262
- else if ($level==2) { $tag = $t.'>>NAMED>>'.$t2; }
263
- else if ($level==3 && preg_match('/^[:](.*)$/',$t3,$m)) {
264
- $tag = $t.'>>NAMED>>'.$t2.'>>PSEUDO>>'.$m[1];
265
- if ($m[1]=='LEFT' || $m[1]=='RIGHT') { $pageselectors = true; } // used to turn on $this->mpdf->mirrorMargins
266
- }
267
- if (isset($this->CSS[$tag]) && $tag) { $this->CSS[$tag] = $this->array_merge_recursive_unique($this->CSS[$tag], $classproperties); }
268
- else if ($tag) { $this->CSS[$tag] = $classproperties; }
269
- }
270
-
271
- else if ($level == 1) { // e.g. p or .class or #id or p.class or p#id
272
- if (isset($tags[0])) { $t = trim($tags[0]); }
273
- if ($t) {
274
- $tag = '';
275
- if (preg_match('/^[.](.*)$/',$t,$m)) { $tag = 'CLASS>>'.$m[1]; }
276
- else if (preg_match('/^[#](.*)$/',$t,$m)) { $tag = 'ID>>'.$m[1]; }
277
- else if (preg_match('/^\[LANG=[\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\]$/',$t,$m)) { $tag = 'LANG>>'.strtolower($m[1]); } // mPDF 6 Special case for lang as attribute selector
278
- else if (preg_match('/^:LANG\([\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\)$/',$t,$m)) { $tag = 'LANG>>'.strtolower($m[1]); } // mPDF 6 Special case for lang as attribute selector
279
- else if (preg_match('/^('.$this->mpdf->allowedCSStags.')[.](.*)$/',$t,$m)) { $tag = $m[1].'>>CLASS>>'.$m[2]; }
280
- else if (preg_match('/^('.$this->mpdf->allowedCSStags.')\s*:NTH-CHILD\((.*)\)$/',$t,$m)) { $tag = $m[1].'>>SELECTORNTHCHILD>>'.$m[2]; }
281
- else if (preg_match('/^('.$this->mpdf->allowedCSStags.')[#](.*)$/',$t,$m)) { $tag = $m[1].'>>ID>>'.$m[2]; }
282
- else if (preg_match('/^('.$this->mpdf->allowedCSStags.')\[LANG=[\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\]$/',$t,$m)) { $tag = $m[1].'>>LANG>>'.strtolower($m[2]); } // mPDF 6 Special case for lang as attribute selector
283
- else if (preg_match('/^('.$this->mpdf->allowedCSStags.'):LANG\([\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\)$/',$t,$m)) { $tag = $m[1].'>>LANG>>'.strtolower($m[2]); } // mPDF 6 Special case for lang as attribute selector
284
- else if (preg_match('/^('.$this->mpdf->allowedCSStags.')$/',$t)) { $tag= $t; }
285
- if (isset($this->CSS[$tag]) && $tag) { $this->CSS[$tag] = $this->array_merge_recursive_unique($this->CSS[$tag], $classproperties); }
286
- else if ($tag) { $this->CSS[$tag] = $classproperties; }
287
- }
288
- }
289
- else {
290
- $tmp = array();
291
- for($n=0;$n<$level;$n++) {
292
- if (isset($tags[$n])) { $t = trim($tags[$n]); }
293
- else { $t = ''; }
294
- if ($t) {
295
- $tag = '';
296
- if (preg_match('/^[.](.*)$/',$t,$m)) { $tag = 'CLASS>>'.$m[1]; }
297
- else if (preg_match('/^[#](.*)$/',$t,$m)) { $tag = 'ID>>'.$m[1]; }
298
- else if (preg_match('/^\[LANG=[\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\]$/',$t,$m)) { $tag = 'LANG>>'.strtolower($m[1]); } // mPDF 6 Special case for lang as attribute selector
299
- else if (preg_match('/^:LANG\([\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\)$/',$t,$m)) { $tag = 'LANG>>'.strtolower($m[1]); } // mPDF 6 Special case for lang as attribute selector
300
- else if (preg_match('/^('.$this->mpdf->allowedCSStags.')[.](.*)$/',$t,$m)) { $tag = $m[1].'>>CLASS>>'.$m[2]; }
301
- else if (preg_match('/^('.$this->mpdf->allowedCSStags.')\s*:NTH-CHILD\((.*)\)$/',$t,$m)) { $tag = $m[1].'>>SELECTORNTHCHILD>>'.$m[2]; }
302
- else if (preg_match('/^('.$this->mpdf->allowedCSStags.')[#](.*)$/',$t,$m)) { $tag = $m[1].'>>ID>>'.$m[2]; }
303
- else if (preg_match('/^('.$this->mpdf->allowedCSStags.')\[LANG=[\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\]$/',$t,$m)) { $tag = $m[1].'>>LANG>>'.strtolower($m[2]); } // mPDF 6 Special case for lang as attribute selector
304
- else if (preg_match('/^('.$this->mpdf->allowedCSStags.'):LANG\([\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\)$/',$t,$m)) { $tag = $m[1].'>>LANG>>'.strtolower($m[2]); } // mPDF 6 Special case for lang as attribute selector
305
- else if (preg_match('/^('.$this->mpdf->allowedCSStags.')$/',$t)) { $tag= $t; }
306
-
307
- if ($tag) $tmp[] = $tag;
308
- else { break; }
309
- }
310
- }
311
-
312
- if ($tag) {
313
- $x = &$this->cascadeCSS;
314
- foreach($tmp AS $tp) { $x = &$x[$tp]; }
315
- $x = $this->array_merge_recursive_unique($x, $classproperties);
316
- $x['depth'] = $level;
317
- }
318
- }
319
- }
320
- if ($pageselectors) { $this->mpdf->mirrorMargins = true; }
321
- $properties = array();
322
- $values = array();
323
- $classproperties = array();
324
- }
325
- } // end of if
326
- //Remove CSS (tags and content), if any
327
- $regexp = '/<style.*?>(.*?)<\/style>/si'; // it can be <style> or <style type="txt/css">
328
- $html = preg_replace($regexp,'',$html);
329
- //print_r($this->CSS); exit;
330
- //print_r($this->cascadeCSS); exit;
331
- return $html;
332
- }
333
-
334
-
335
-
336
- function readInlineCSS($html) {
337
- $html=htmlspecialchars_decode($html); // mPDF 5.7.4 URLs
338
- // mPDF 5.7.4 URLs
339
- // Characters "(" ")" and ";" in url() e.g. background-image, cause probems parsing the CSS string
340
- // URLencode ( and ), but change ";" to a code which can be converted back after parsing (so as not to confuse ;
341
- // with a segment delimiter in the URI)
342
- $tempmarker = '%ZZ';
343
- if (strpos($html,'url(')!==false) {
344
- preg_match_all( '/url\(\"(.*?)\"\)/', $html, $m);
345
- for($i = 0; $i < count($m[1]) ; $i++) {
346
- $tmp = str_replace(array('(',')',';'),array('%28','%29',$tempmarker),$m[1][$i]);
347
- $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/', 'url(\''.$tmp.'\')', $html);
348
- }
349
- preg_match_all( '/url\(\'(.*?)\'\)/', $html, $m);
350
- for($i = 0; $i < count($m[1]) ; $i++) {
351
- $tmp = str_replace(array('(',')',';'),array('%28','%29',$tempmarker),$m[1][$i]);
352
- $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/', 'url(\''.$tmp.'\')', $html);
353
- }
354
- preg_match_all( '/url\(([^\'\"].*?[^\'\"])\)/', $html, $m);
355
- for($i = 0; $i < count($m[1]) ; $i++) {
356
- $tmp = str_replace(array('(',')',';'),array('%28','%29',$tempmarker),$m[1][$i]);
357
- $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/', 'url(\''.$tmp.'\')', $html);
358
- }
359
- }
360
- //Fix incomplete CSS code
361
- $size = strlen($html)-1;
362
- if (substr($html,$size,1) != ';') $html .= ';';
363
- //Make CSS[Name-of-the-class] = array(key => value)
364
- $regexp = '|\\s*?(\\S+?):(.+?);|i';
365
- preg_match_all( $regexp, $html, $styleinfo);
366
- $properties = $styleinfo[1];
367
- $values = $styleinfo[2];
368
- //Array-properties and Array-values must have the SAME SIZE!
369
- $classproperties = array();
370
- for($i = 0; $i < count($properties) ; $i++) {
371
- // Ignores -webkit-gradient so doesn't override -moz-
372
- if ((strtoupper($properties[$i])=='BACKGROUND-IMAGE' || strtoupper($properties[$i])=='BACKGROUND') && preg_match('/-webkit-gradient/i',$values[$i])) {
373
- continue;
374
- }
375
- $values[$i] = str_replace($tempmarker,';',$values[$i]); // mPDF 5.7.4 URLs
376
- $classproperties[strtoupper($properties[$i])] = trim($values[$i]);
377
- }
378
- return $this->fixCSS($classproperties);
379
- }
380
-
381
-
382
-
383
- function _fix_borderStr($bd) {
384
- preg_match_all("/\((.*?)\)/", $bd, $m);
385
- if (count($m[1])) {
386
- for($i=0;$i<count($m[1]);$i++) {
387
- $sub = preg_replace("/ /", "", $m[1][$i]);
388
- $bd = preg_replace('/'.preg_quote($m[1][$i], '/').'/si', $sub, $bd);
389
- }
390
- }
391
-
392
- $prop = preg_split('/\s+/',trim($bd));
393
- $w = 'medium';
394
- $c = '#000000';
395
- $s = 'none';
396
-
397
- if ( count($prop) == 1 ) {
398
- // solid
399
- if (in_array($prop[0],$this->mpdf->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) { $s = $prop[0]; }
400
- // #000000
401
- else if (is_array($this->mpdf->ConvertColor($prop[0]))) { $c = $prop[0]; }
402
- // 1px
403
- else { $w = $prop[0]; }
404
- }
405
- else if (count($prop) == 2 ) {
406
- // 1px solid
407
- if (in_array($prop[1],$this->mpdf->borderstyles) || $prop[1] == 'none' || $prop[1] == 'hidden' ) { $w = $prop[0]; $s = $prop[1]; }
408
- // solid #000000
409
- else if (in_array($prop[0],$this->mpdf->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) { $s = $prop[0]; $c = $prop[1]; }
410
- // 1px #000000
411
- else { $w = $prop[0]; $c = $prop[1]; }
412
- }
413
- else if ( count($prop) == 3 ) {
414
- // Change #000000 1px solid to 1px solid #000000 (proper)
415
- if (substr($prop[0],0,1) == '#') { $c = $prop[0]; $w = $prop[1]; $s = $prop[2]; }
416
- // Change solid #000000 1px to 1px solid #000000 (proper)
417
- else if (substr($prop[0],1,1) == '#') { $s = $prop[0]; $c = $prop[1]; $w = $prop[2]; }
418
- // Change solid 1px #000000 to 1px solid #000000 (proper)
419
- else if (in_array($prop[0],$this->mpdf->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) {
420
- $s = $prop[0]; $w = $prop[1]; $c = $prop[2];
421
- }
422
- else { $w = $prop[0]; $s = $prop[1]; $c = $prop[2]; }
423
- }
424
- else { return ''; }
425
- $s = strtolower($s);
426
- return $w.' '.$s.' '.$c;
427
- }
428
-
429
-
430
-
431
- function fixCSS($prop) {
432
- if (!is_array($prop) || (count($prop)==0)) return array();
433
- $newprop = array();
434
- foreach($prop AS $k => $v) {
435
- if ($k != 'BACKGROUND-IMAGE' && $k != 'BACKGROUND' && $k != 'ODD-HEADER-NAME' && $k != 'EVEN-HEADER-NAME' && $k != 'ODD-FOOTER-NAME' && $k != 'EVEN-FOOTER-NAME' && $k != 'HEADER' && $k != 'FOOTER') {
436
- $v = strtolower($v);
437
- }
438
-
439
- if ($k == 'FONT') {
440
- $s = trim($v);
441
- preg_match_all('/\"(.*?)\"/',$s,$ff);
442
- if (count($ff[1])) {
443
- foreach($ff[1] AS $ffp) {
444
- $w = preg_split('/\s+/',$ffp);
445
- $s = preg_replace('/\"'.$ffp.'\"/',$w[0],$s);
446
- }
447
- }
448
- preg_match_all('/\'(.*?)\'/',$s,$ff);
449
- if (count($ff[1])) {
450
- foreach($ff[1] AS $ffp) {
451
- $w = preg_split('/\s+/',$ffp);
452
- $s = preg_replace('/\''.$ffp.'\'/',$w[0],$s);
453
- }
454
- }
455
- $s = preg_replace('/\s*,\s*/',',',$s);
456
- $bits = preg_split('/\s+/',$s);
457
- if (count($bits)>1) {
458
- $k = 'FONT-FAMILY'; $v = $bits[(count($bits)-1)];
459
- $fs = $bits[(count($bits)-2)];
460
- if (preg_match('/(.*?)\/(.*)/',$fs, $fsp)) {
461
- $newprop['FONT-SIZE'] = $fsp[1];
462
- $newprop['LINE-HEIGHT'] = $fsp[2];
463
- }
464
- else { $newprop['FONT-SIZE'] = $fs; }
465
- if (preg_match('/(italic|oblique)/i',$s)) { $newprop['FONT-STYLE'] = 'italic'; }
466
- else { $newprop['FONT-STYLE'] = 'normal'; }
467
- if (preg_match('/bold/i',$s)) { $newprop['FONT-WEIGHT'] = 'bold'; }
468
- else { $newprop['FONT-WEIGHT'] = 'normal'; }
469
- if (preg_match('/small-caps/i',$s)) { $newprop['TEXT-TRANSFORM'] = 'uppercase'; }
470
- }
471
- }
472
- else if ($k == 'FONT-FAMILY') {
473
- $aux_fontlist = explode(",",$v);
474
- $found = 0;
475
- foreach($aux_fontlist AS $f) {
476
- $fonttype = trim($f);
477
- $fonttype = preg_replace('/["\']*(.*?)["\']*/','\\1',$fonttype);
478
- $fonttype = preg_replace('/ /','',$fonttype);
479
- $v = strtolower(trim($fonttype));
480
- if (isset($this->mpdf->fonttrans[$v]) && $this->mpdf->fonttrans[$v]) { $v = $this->mpdf->fonttrans[$v]; }
481
- if ((!$this->mpdf->onlyCoreFonts && in_array($v,$this->mpdf->available_unifonts)) ||
482
- in_array($v,array('ccourier','ctimes','chelvetica')) ||
483
- ($this->mpdf->onlyCoreFonts && in_array($v,array('courier','times','helvetica','arial'))) ||
484
- in_array($v, array('sjis','uhc','big5','gb'))) {
485
- $newprop[$k] = $v;
486
- $found = 1;
487
- break;
488
- }
489
- }
490
- if (!$found) {
491
- foreach($aux_fontlist AS $f) {
492
- $fonttype = trim($f);
493
- $fonttype = preg_replace('/["\']*(.*?)["\']*/','\\1',$fonttype);
494
- $fonttype = preg_replace('/ /','',$fonttype);
495
- $v = strtolower(trim($fonttype));
496
- if (isset($this->mpdf->fonttrans[$v]) && $this->mpdf->fonttrans[$v]) { $v = $this->mpdf->fonttrans[$v]; }
497
- if (in_array($v,$this->mpdf->sans_fonts) || in_array($v,$this->mpdf->serif_fonts) || in_array($v,$this->mpdf->mono_fonts) ) {
498
- $newprop[$k] = $v;
499
- break;
500
- }
501
- }
502
- }
503
- }
504
- // mPDF 5.7.1
505
- else if ($k == 'FONT-VARIANT') {
506
- if (preg_match('/(normal|none)/',$v, $m)) { // mPDF 6
507
- $newprop['FONT-VARIANT-LIGATURES'] = $m[1];
508
- $newprop['FONT-VARIANT-CAPS'] = $m[1];
509
- $newprop['FONT-VARIANT-NUMERIC'] = $m[1];
510
- $newprop['FONT-VARIANT-ALTERNATES'] = $m[1];
511
- }
512
- else {
513
- if (preg_match_all('/(no-common-ligatures|\bcommon-ligatures|no-discretionary-ligatures|\bdiscretionary-ligatures|no-historical-ligatures|\bhistorical-ligatures|no-contextual|\bcontextual)/i',$v, $m)) {
514
- $newprop['FONT-VARIANT-LIGATURES'] = implode(' ',$m[1]);
515
- }
516
- if (preg_match('/(all-small-caps|\bsmall-caps|all-petite-caps|\bpetite-caps|unicase|titling-caps)/i',$v, $m)) {
517
- $newprop['FONT-VARIANT-CAPS'] = $m[1];
518
- }
519
- if (preg_match_all('/(lining-nums|oldstyle-nums|proportional-nums|tabular-nums|diagonal-fractions|stacked-fractions)/i',$v, $m)) {
520
- $newprop['FONT-VARIANT-NUMERIC'] = implode(' ',$m[1]);
521
- }
522
- if (preg_match('/(historical-forms)/i',$v, $m)) {
523
- $newprop['FONT-VARIANT-ALTERNATES'] = $m[1];
524
- }
525
- }
526
- }
527
- else if ($k == 'MARGIN') {
528
- $tmp = $this->expand24($v);
529
- $newprop['MARGIN-TOP'] = $tmp['T'];
530
- $newprop['MARGIN-RIGHT'] = $tmp['R'];
531
- $newprop['MARGIN-BOTTOM'] = $tmp['B'];
532
- $newprop['MARGIN-LEFT'] = $tmp['L'];
533
- }
534
- /*-- BORDER-RADIUS --*/
535
- else if ($k == 'BORDER-RADIUS' || $k == 'BORDER-TOP-LEFT-RADIUS' || $k == 'BORDER-TOP-RIGHT-RADIUS' || $k == 'BORDER-BOTTOM-LEFT-RADIUS' || $k == 'BORDER-BOTTOM-RIGHT-RADIUS') {
536
- $tmp = $this->border_radius_expand($v,$k);
537
- if (isset($tmp['TL-H'])) $newprop['BORDER-TOP-LEFT-RADIUS-H'] = $tmp['TL-H'];
538
- if (isset($tmp['TL-V'])) $newprop['BORDER-TOP-LEFT-RADIUS-V'] = $tmp['TL-V'];
539
- if (isset($tmp['TR-H'])) $newprop['BORDER-TOP-RIGHT-RADIUS-H'] = $tmp['TR-H'];
540
- if (isset($tmp['TR-V'])) $newprop['BORDER-TOP-RIGHT-RADIUS-V'] = $tmp['TR-V'];
541
- if (isset($tmp['BL-H'])) $newprop['BORDER-BOTTOM-LEFT-RADIUS-H'] = $tmp['BL-H'];
542
- if (isset($tmp['BL-V'])) $newprop['BORDER-BOTTOM-LEFT-RADIUS-V'] = $tmp['BL-V'];
543
- if (isset($tmp['BR-H'])) $newprop['BORDER-BOTTOM-RIGHT-RADIUS-H'] = $tmp['BR-H'];
544
- if (isset($tmp['BR-V'])) $newprop['BORDER-BOTTOM-RIGHT-RADIUS-V'] = $tmp['BR-V'];
545
- }
546
- /*-- END BORDER-RADIUS --*/
547
- else if ($k == 'PADDING') {
548
- $tmp = $this->expand24($v);
549
- $newprop['PADDING-TOP'] = $tmp['T'];
550
- $newprop['PADDING-RIGHT'] = $tmp['R'];
551
- $newprop['PADDING-BOTTOM'] = $tmp['B'];
552
- $newprop['PADDING-LEFT'] = $tmp['L'];
553
- }
554
- else if ($k == 'BORDER') {
555
- if ($v == '1') { $v = '1px solid #000000'; }
556
- else { $v = $this->_fix_borderStr($v); }
557
- $newprop['BORDER-TOP'] = $v;
558
- $newprop['BORDER-RIGHT'] = $v;
559
- $newprop['BORDER-BOTTOM'] = $v;
560
- $newprop['BORDER-LEFT'] = $v;
561
- }
562
- else if ($k == 'BORDER-TOP') {
563
- $newprop['BORDER-TOP'] = $this->_fix_borderStr($v);
564
- }
565
- else if ($k == 'BORDER-RIGHT') {
566
- $newprop['BORDER-RIGHT'] = $this->_fix_borderStr($v);
567
- }
568
- else if ($k == 'BORDER-BOTTOM') {
569
- $newprop['BORDER-BOTTOM'] = $this->_fix_borderStr($v);
570
- }
571
- else if ($k == 'BORDER-LEFT') {
572
- $newprop['BORDER-LEFT'] = $this->_fix_borderStr($v);
573
- }
574
- else if ($k == 'BORDER-STYLE') {
575
- $e = $this->expand24($v);
576
- if (!empty($e)) {
577
- $newprop['BORDER-TOP-STYLE'] = $e['T'];
578
- $newprop['BORDER-RIGHT-STYLE'] = $e['R'];
579
- $newprop['BORDER-BOTTOM-STYLE'] = $e['B'];
580
- $newprop['BORDER-LEFT-STYLE'] = $e['L'];
581
- }
582
- }
583
- else if ($k == 'BORDER-WIDTH') {
584
- $e = $this->expand24($v);
585
- if (!empty($e)) {
586
- $newprop['BORDER-TOP-WIDTH'] = $e['T'];
587
- $newprop['BORDER-RIGHT-WIDTH'] = $e['R'];
588
- $newprop['BORDER-BOTTOM-WIDTH'] = $e['B'];
589
- $newprop['BORDER-LEFT-WIDTH'] = $e['L'];
590
- }
591
- }
592
- else if ($k == 'BORDER-COLOR') {
593
- $e = $this->expand24($v);
594
- if (!empty($e)) {
595
- $newprop['BORDER-TOP-COLOR'] = $e['T'];
596
- $newprop['BORDER-RIGHT-COLOR'] = $e['R'];
597
- $newprop['BORDER-BOTTOM-COLOR'] = $e['B'];
598
- $newprop['BORDER-LEFT-COLOR'] = $e['L'];
599
- }
600
- }
601
-
602
- else if ($k == 'BORDER-SPACING') {
603
- $prop = preg_split('/\s+/',trim($v));
604
- if (count($prop) == 1 ) {
605
- $newprop['BORDER-SPACING-H'] = $prop[0];
606
- $newprop['BORDER-SPACING-V'] = $prop[0];
607
- }
608
- else if (count($prop) == 2 ) {
609
- $newprop['BORDER-SPACING-H'] = $prop[0];
610
- $newprop['BORDER-SPACING-V'] = $prop[1];
611
- }
612
- }
613
- else if ($k == 'TEXT-OUTLINE') { // mPDF 5.6.07
614
- $prop = preg_split('/\s+/',trim($v));
615
- if (trim(strtolower($v)) == 'none' ) {
616
- $newprop['TEXT-OUTLINE'] = 'none';
617
- }
618
- else if (count($prop) == 2 ) {
619
- $newprop['TEXT-OUTLINE-WIDTH'] = $prop[0];
620
- $newprop['TEXT-OUTLINE-COLOR'] = $prop[1];
621
- }
622
- else if (count($prop) == 3 ) {
623
- $newprop['TEXT-OUTLINE-WIDTH'] = $prop[0];
624
- $newprop['TEXT-OUTLINE-COLOR'] = $prop[2];
625
- }
626
- }
627
- else if ($k == 'SIZE') {
628
- $prop = preg_split('/\s+/',trim($v));
629
- if (preg_match('/(auto|portrait|landscape)/',$prop[0])) {
630
- $newprop['SIZE'] = strtoupper($prop[0]);
631
- }
632
- else if (count($prop) == 1 ) {
633
- $newprop['SIZE']['W'] = $this->mpdf->ConvertSize($prop[0]);
634
- $newprop['SIZE']['H'] = $this->mpdf->ConvertSize($prop[0]);
635
- }
636
- else if (count($prop) == 2 ) {
637
- $newprop['SIZE']['W'] = $this->mpdf->ConvertSize($prop[0]);
638
- $newprop['SIZE']['H'] = $this->mpdf->ConvertSize($prop[1]);
639
- }
640
- }
641
- else if ($k == 'SHEET-SIZE') {
642
- $prop = preg_split('/\s+/',trim($v));
643
- if (count($prop) == 2 ) {
644
- $newprop['SHEET-SIZE'] = array($this->mpdf->ConvertSize($prop[0]), $this->mpdf->ConvertSize($prop[1]));
645
- }
646
- else {
647
- if(preg_match('/([0-9a-zA-Z]*)-L/i',$v,$m)) { // e.g. A4-L = A$ landscape
648
- $ft = $this->mpdf->_getPageFormat($m[1]);
649
- $format = array($ft[1],$ft[0]);
650
- }
651
- else { $format = $this->mpdf->_getPageFormat($v); }
652
- if ($format) { $newprop['SHEET-SIZE'] = array($format[0]/_MPDFK, $format[1]/_MPDFK); }
653
- }
654
- }
655
- else if ($k == 'BACKGROUND') {
656
- $bg = $this->parseCSSbackground($v);
657
- if ($bg['c']) { $newprop['BACKGROUND-COLOR'] = $bg['c']; }
658
- else { $newprop['BACKGROUND-COLOR'] = 'transparent'; }
659
- /*-- BACKGROUNDS --*/
660
- if ($bg['i']) {
661
- $newprop['BACKGROUND-IMAGE'] = $bg['i'];
662
- if ($bg['r']) { $newprop['BACKGROUND-REPEAT'] = $bg['r']; }
663
- if ($bg['p']) { $newprop['BACKGROUND-POSITION'] = $bg['p']; }
664
- }
665
- else { $newprop['BACKGROUND-IMAGE'] = ''; }
666
- /*-- END BACKGROUNDS --*/
667
- }
668
- /*-- BACKGROUNDS --*/
669
- else if ($k == 'BACKGROUND-IMAGE') {
670
- if (preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient\(.*\)/i',$v,$m)) {
671
- $newprop['BACKGROUND-IMAGE'] = $m[0];
672
- continue;
673
- }
674
- if (preg_match('/url\([\'\"]{0,1}(.*?)[\'\"]{0,1}\)/i',$v,$m)) {
675
- $newprop['BACKGROUND-IMAGE'] = $m[1];
676
- }
677
-
678
- else if (strtolower($v)=='none') { $newprop['BACKGROUND-IMAGE'] = ''; }
679
-
680
- }
681
- else if ($k == 'BACKGROUND-REPEAT') {
682
- if (preg_match('/(repeat-x|repeat-y|no-repeat|repeat)/i',$v,$m)) {
683
- $newprop['BACKGROUND-REPEAT'] = strtolower($m[1]);
684
- }
685
- }
686
- else if ($k == 'BACKGROUND-POSITION') {
687
- $s = $v;
688
- $bits = preg_split('/\s+/',trim($s));
689
- // These should be Position x1 or x2
690
- if (count($bits)==1) {
691
- if (preg_match('/bottom/',$bits[0])) { $bg['p'] = '50% 100%'; }
692
- else if (preg_match('/top/',$bits[0])) { $bg['p'] = '50% 0%'; }
693
- else { $bg['p'] = $bits[0] . ' 50%'; }
694
- }
695
- else if (count($bits)==2) {
696
- // Can be either right center or center right
697
- if (preg_match('/(top|bottom)/',$bits[0]) || preg_match('/(left|right)/',$bits[1])) {
698
- $bg['p'] = $bits[1] . ' '.$bits[0];
699
- }
700
- else {
701
- $bg['p'] = $bits[0] . ' '.$bits[1];
702
- }
703
- }
704
- if ($bg['p']) {
705
- $bg['p'] = preg_replace('/(left|top)/','0%',$bg['p']);
706
- $bg['p'] = preg_replace('/(right|bottom)/','100%',$bg['p']);
707
- $bg['p'] = preg_replace('/(center)/','50%',$bg['p']);
708
- if (!preg_match('/[\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)* [\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)*/',$bg['p'])) {
709
- $bg['p'] = false;
710
- }
711
- }
712
- if ($bg['p']) { $newprop['BACKGROUND-POSITION'] = $bg['p']; }
713
- }
714
- /*-- END BACKGROUNDS --*/
715
- else if ($k == 'IMAGE-ORIENTATION') {
716
- if (preg_match('/([\-]*[0-9\.]+)(deg|grad|rad)/i',$v,$m)) {
717
- $angle = $m[1] + 0;
718
- if (strtolower($m[2])=='deg') { $angle = $angle; }
719
- else if (strtolower($m[2])=='grad') { $angle *= (360/400); }
720
- else if (strtolower($m[2])=='rad') { $angle = rad2deg($angle); }
721
- while($angle < 0) { $angle += 360; }
722
- $angle = ($angle % 360);
723
- $angle /= 90;
724
- $angle = round($angle) * 90;
725
- $newprop['IMAGE-ORIENTATION'] = $angle;
726
- }
727
- }
728
- else if ($k == 'TEXT-ALIGN') {
729
- if (preg_match('/["\'](.){1}["\']/i',$v,$m)) {
730
- $d = array_search($m[1],$this->mpdf->decimal_align);
731
- if ($d !== false) { $newprop['TEXT-ALIGN'] = $d; }
732
- if (preg_match('/(center|left|right)/i',$v,$m)) { $newprop['TEXT-ALIGN'] .= strtoupper(substr($m[1],0,1)); }
733
- else { $newprop['TEXT-ALIGN'] .= 'R'; } // default = R
734
- }
735
- else if (preg_match('/["\'](\\\[a-fA-F0-9]{1,6})["\']/i',$v,$m)) {
736
- $utf8 = codeHex2utf(substr($m[1],1,6));
737
- $d = array_search($utf8,$this->mpdf->decimal_align);
738
- if ($d !== false) { $newprop['TEXT-ALIGN'] = $d; }
739
- if (preg_match('/(center|left|right)/i',$v,$m)) { $newprop['TEXT-ALIGN'] .= strtoupper(substr($m[1],0,1)); }
740
- else { $newprop['TEXT-ALIGN'] .= 'R'; } // default = R
741
- }
742
- else { $newprop[$k] = $v; }
743
- }
744
- // mpDF 6 Lists
745
- else if ($k == 'LIST-STYLE') {
746
- if (preg_match('/none/i',$v,$m)) {
747
- $newprop['LIST-STYLE-TYPE'] = 'none';
748
- $newprop['LIST-STYLE-IMAGE'] = 'none';
749
- }
750
- if (preg_match('/(lower-roman|upper-roman|lower-latin|lower-alpha|upper-latin|upper-alpha|decimal|disc|circle|square|arabic-indic|bengali|devanagari|gujarati|gurmukhi|kannada|malayalam|oriya|persian|tamil|telugu|thai|urdu|cambodian|khmer|lao|cjk-decimal|hebrew)/i',$v,$m)) {
751
- $newprop['LIST-STYLE-TYPE'] = strtolower(trim($m[1]));
752
- }
753
- else if (preg_match('/U\+([a-fA-F0-9]+)/i',$v,$m)) {
754
- $newprop['LIST-STYLE-TYPE'] = strtolower(trim($m[1]));
755
- }
756
- if (preg_match('/url\([\'\"]{0,1}(.*?)[\'\"]{0,1}\)/i',$v,$m)) {
757
- $newprop['LIST-STYLE-IMAGE'] = strtolower(trim($m[1]));
758
- }
759
- if (preg_match('/(inside|outside)/i',$v,$m)) {
760
- $newprop['LIST-STYLE-POSITION'] = strtolower(trim($m[1]));
761
- }
762
- }
763
-
764
- else {
765
- $newprop[$k] = $v;
766
- }
767
- }
768
-
769
- return $newprop;
770
- }
771
-
772
- function setCSSboxshadow($v) {
773
- $sh = array();
774
- $c = preg_match_all('/(rgba|rgb|device-cmyka|cmyka|device-cmyk|cmyk|hsla|hsl)\(.*?\)/',$v,$x); // mPDF 5.6.05
775
- for($i=0; $i<$c; $i++) {
776
- $col = preg_replace('/,/','*',$x[0][$i]);
777
- $v = preg_replace('/'.preg_quote($x[0][$i],'/').'/',$col,$v);
778
- }
779
- $ss = explode(',',$v);
780
- foreach ($ss AS $s) {
781
- $new = array('inset'=>false, 'blur'=>0, 'spread'=>0);
782
- if (preg_match('/inset/i',$s)) { $new['inset'] = true; $s = preg_replace('/\s*inset\s*/','',$s); }
783
- $p = explode(' ',trim($s));
784
- if (isset($p[0])) { $new['x'] = $this->mpdf->ConvertSize(trim($p[0]),$this->mpdf->blk[$this->mpdf->blklvl-1]['inner_width'],$this->mpdf->FontSize,false); }
785
- if (isset($p[1])) { $new['y'] = $this->mpdf->ConvertSize(trim($p[1]),$this->mpdf->blk[$this->mpdf->blklvl-1]['inner_width'],$this->mpdf->FontSize,false); }
786
- if (isset($p[2])) {
787
- if (preg_match('/^\s*[\.\-0-9]/',$p[2])) {
788
- $new['blur'] = $this->mpdf->ConvertSize(trim($p[2]),$this->mpdf->blk[$this->mpdf->blklvl-1]['inner_width'],$this->mpdf->FontSize,false);
789
- }
790
- else { $new['col'] = $this->mpdf->ConvertColor(preg_replace('/\*/',',',$p[2])); }
791
- if (isset($p[3])) {
792
- if (preg_match('/^\s*[\.\-0-9]/',$p[3])) {
793
- $new['spread'] = $this->mpdf->ConvertSize(trim($p[3]),$this->mpdf->blk[$this->mpdf->blklvl-1]['inner_width'],$this->mpdf->FontSize,false);
794
- }
795
- else { $new['col'] = $this->mpdf->ConvertColor(preg_replace('/\*/',',',$p[3])); }
796
- if (isset($p[4])) {
797
- $new['col'] = $this->mpdf->ConvertColor(preg_replace('/\*/',',',$p[4]));
798
- }
799
- }
800
- }
801
- if (!$new['col']) { $new['col'] = $this->mpdf->ConvertColor('#888888'); }
802
- if (isset($new['y'])) { array_unshift($sh, $new); }
803
- }
804
- return $sh;
805
- }
806
-
807
- function setCSStextshadow($v) {
808
- $sh = array();
809
- $c = preg_match_all('/(rgba|rgb|device-cmyka|cmyka|device-cmyk|cmyk|hsla|hsl)\(.*?\)/',$v,$x); // mPDF 5.6.05
810
- for($i=0; $i<$c; $i++) {
811
- $col = preg_replace('/,/','*',$x[0][$i]);
812
- $v = preg_replace('/'.preg_quote($x[0][$i],'/').'/',$col,$v);
813
- }
814
- $ss = explode(',',$v);
815
- foreach ($ss AS $s) {
816
- $new = array('blur'=>0);
817
- $p = explode(' ',trim($s));
818
- if (isset($p[0])) { $new['x'] = $this->mpdf->ConvertSize(trim($p[0]),$this->mpdf->FontSize,$this->mpdf->FontSize,false); }
819
- if (isset($p[1])) { $new['y'] = $this->mpdf->ConvertSize(trim($p[1]),$this->mpdf->FontSize,$this->mpdf->FontSize,false); }
820
- if (isset($p[2])) {
821
- if (preg_match('/^\s*[\.\-0-9]/',$p[2])) {
822
- $new['blur'] = $this->mpdf->ConvertSize(trim($p[2]),$this->mpdf->blk[$this->mpdf->blklvl]['inner_width'],$this->mpdf->FontSize,false);
823
- }
824
- else { $new['col'] = $this->mpdf->ConvertColor(preg_replace('/\*/',',',$p[2])); }
825
- if (isset($p[3])) {
826
- $new['col'] = $this->mpdf->ConvertColor(preg_replace('/\*/',',',$p[3]));
827
- }
828
- }
829
- if (!isset($new['col']) || !$new['col']) { $new['col'] = $this->mpdf->ConvertColor('#888888'); }
830
- if (isset($new['y'])) { array_unshift($sh, $new); }
831
- }
832
- return $sh;
833
- }
834
-
835
- function parseCSSbackground($s) {
836
- $bg = array('c'=>false, 'i'=>false, 'r'=>false, 'p'=>false, );
837
- /*-- BACKGROUNDS --*/
838
- if (preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient\(.*\)/i',$s,$m)) {
839
- $bg['i'] = $m[0];
840
- }
841
- else
842
- /*-- END BACKGROUNDS --*/
843
- if (preg_match('/url\(/i',$s)) {
844
- // If color, set and strip it off
845
- // mPDF 5.6.05
846
- if (preg_match('/^\s*(#[0-9a-fA-F]{3,6}|(rgba|rgb|device-cmyka|cmyka|device-cmyk|cmyk|hsla|hsl|spot)\(.*?\)|[a-zA-Z]{3,})\s+(url\(.*)/i',$s,$m)) {
847
- $bg['c'] = strtolower($m[1]);
848
- $s = $m[3];
849
- }
850
- /*-- BACKGROUNDS --*/
851
- if (preg_match('/url\([\'\"]{0,1}(.*?)[\'\"]{0,1}\)\s*(.*)/i',$s,$m)) {
852
- $bg['i'] = $m[1];
853
- $s = strtolower($m[2]);
854
- if (preg_match('/(repeat-x|repeat-y|no-repeat|repeat)/',$s,$m)) {
855
- $bg['r'] = $m[1];
856
- }
857
- // Remove repeat, attachment (discarded) and also any inherit
858
- $s = preg_replace('/(repeat-x|repeat-y|no-repeat|repeat|scroll|fixed|inherit)/','',$s);
859
- $bits = preg_split('/\s+/',trim($s));
860
- // These should be Position x1 or x2
861
- if (count($bits)==1) {
862
- if (preg_match('/bottom/',$bits[0])) { $bg['p'] = '50% 100%'; }
863
- else if (preg_match('/top/',$bits[0])) { $bg['p'] = '50% 0%'; }
864
- else { $bg['p'] = $bits[0] . ' 50%'; }
865
- }
866
- else if (count($bits)==2) {
867
- // Can be either right center or center right
868
- if (preg_match('/(top|bottom)/',$bits[0]) || preg_match('/(left|right)/',$bits[1])) {
869
- $bg['p'] = $bits[1] . ' '.$bits[0];
870
- }
871
- else {
872
- $bg['p'] = $bits[0] . ' '.$bits[1];
873
- }
874
- }
875
- if ($bg['p']) {
876
- $bg['p'] = preg_replace('/(left|top)/','0%',$bg['p']);
877
- $bg['p'] = preg_replace('/(right|bottom)/','100%',$bg['p']);
878
- $bg['p'] = preg_replace('/(center)/','50%',$bg['p']);
879
- if (!preg_match('/[\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)* [\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)*/',$bg['p'])) {
880
- $bg['p'] = false;
881
- }
882
- }
883
- }
884
- /*-- END BACKGROUNDS --*/
885
- }
886
- else if (preg_match('/^\s*(#[0-9a-fA-F]{3,6}|(rgba|rgb|device-cmyka|cmyka|device-cmyk|cmyk|hsla|hsl|spot)\(.*?\)|[a-zA-Z]{3,})/i',$s,$m)) { $bg['c'] = strtolower($m[1]); } // mPDF 5.6.05
887
- return ($bg);
888
- }
889
-
890
-
891
- function expand24($mp) {
892
- $prop = preg_split('/\s+/',trim($mp));
893
- if (count($prop) == 1 ) {
894
- return array('T' => $prop[0], 'R' => $prop[0], 'B' => $prop[0], 'L'=> $prop[0]);
895
- }
896
- if (count($prop) == 2 ) {
897
- return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[0], 'L'=> $prop[1]);
898
- }
899
-
900
- if (count($prop) == 3 ) {
901
- return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[2], 'L'=> $prop[1]);
902
- }
903
- if (count($prop) == 4 ) {
904
- return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[2], 'L'=> $prop[3]);
905
- }
906
- return array();
907
- }
908
-
909
- /*-- BORDER-RADIUS --*/
910
- function border_radius_expand($val,$k) {
911
- $b = array();
912
- if ($k == 'BORDER-RADIUS') {
913
- $hv = explode('/',trim($val));
914
- $prop = preg_split('/\s+/',trim($hv[0]));
915
- if (count($prop)==1) {
916
- $b['TL-H'] = $b['TR-H'] = $b['BR-H'] = $b['BL-H'] = $prop[0];
917
- }
918
- else if (count($prop)==2) {
919
- $b['TL-H'] = $b['BR-H'] = $prop[0];
920
- $b['TR-H'] = $b['BL-H'] = $prop[1];
921
- }
922
- else if (count($prop)==3) {
923
- $b['TL-H'] = $prop[0];
924
- $b['TR-H'] = $b['BL-H'] = $prop[1];
925
- $b['BR-H'] = $prop[2];
926
- }
927
- else if (count($prop)==4) {
928
- $b['TL-H'] = $prop[0];
929
- $b['TR-H'] = $prop[1];
930
- $b['BR-H'] = $prop[2];
931
- $b['BL-H'] = $prop[3];
932
- }
933
- if (count($hv)==2) {
934
- $prop = preg_split('/\s+/',trim($hv[1]));
935
- if (count($prop)==1) {
936
- $b['TL-V'] = $b['TR-V'] = $b['BR-V'] = $b['BL-V'] = $prop[0];
937
- }
938
- else if (count($prop)==2) {
939
- $b['TL-V'] = $b['BR-V'] = $prop[0];
940
- $b['TR-V'] = $b['BL-V'] = $prop[1];
941
- }
942
- else if (count($prop)==3) {
943
- $b['TL-V'] = $prop[0];
944
- $b['TR-V'] = $b['BL-V'] = $prop[1];
945
- $b['BR-V'] = $prop[2];
946
- }
947
- else if (count($prop)==4) {
948
- $b['TL-V'] = $prop[0];
949
- $b['TR-V'] = $prop[1];
950
- $b['BR-V'] = $prop[2];
951
- $b['BL-V'] = $prop[3];
952
- }
953
- }
954
- else {
955
- $b['TL-V'] = $b['TL-H'];
956
- $b['TR-V'] = $b['TR-H'];
957
- $b['BL-V'] = $b['BL-H'];
958
- $b['BR-V'] = $b['BR-H'];
959
- }
960
- return $b;
961
- }
962
-
963
- // Parse 2
964
- $h = 0;
965
- $v = 0;
966
- $prop = preg_split('/\s+/',trim($val));
967
- if (count($prop)==1) { $h = $v = $val; }
968
- else { $h = $prop[0]; $v = $prop[1]; }
969
- if ($h==0 || $v==0) { $h = $v = 0; }
970
- if ($k == 'BORDER-TOP-LEFT-RADIUS') {
971
- $b['TL-H'] = $h;
972
- $b['TL-V'] = $v;
973
- }
974
- else if ($k == 'BORDER-TOP-RIGHT-RADIUS') {
975
- $b['TR-H'] = $h;
976
- $b['TR-V'] = $v;
977
- }
978
- else if ($k == 'BORDER-BOTTOM-LEFT-RADIUS') {
979
- $b['BL-H'] = $h;
980
- $b['BL-V'] = $v;
981
- }
982
- else if ($k == 'BORDER-BOTTOM-RIGHT-RADIUS') {
983
- $b['BR-H'] = $h;
984
- $b['BR-V'] = $v;
985
- }
986
- return $b;
987
-
988
- }
989
- /*-- END BORDER-RADIUS --*/
990
-
991
- function _mergeCSS($p, &$t) {
992
- // Save Cascading CSS e.g. "div.topic p" at this block level
993
- if (isset($p) && $p) {
994
- if ($t) {
995
- $t = $this->array_merge_recursive_unique($t, $p);
996
- }
997
- else { $t = $p; }
998
- }
999
- }
1000
-
1001
- // for CSS handling
1002
- function array_merge_recursive_unique($array1, $array2) {
1003
- $arrays = func_get_args();
1004
- $narrays = count($arrays);
1005
- $ret = $arrays[0];
1006
- for ($i = 1; $i < $narrays; $i ++) {
1007
- foreach ($arrays[$i] as $key => $value) {
1008
- if (((string) $key) === ((string) intval($key))) { // integer or string as integer key - append
1009
- $ret[] = $value;
1010
- }
1011
- else { // string key - merge
1012
- if (is_array($value) && isset($ret[$key])) {
1013
- $ret[$key] = $this->array_merge_recursive_unique($ret[$key], $value);
1014
- }
1015
- else {
1016
- $ret[$key] = $value;
1017
- }
1018
- }
1019
- }
1020
- }
1021
- return $ret;
1022
- }
1023
-
1024
-
1025
-
1026
- function _mergeFullCSS($p, &$t, $tag, $classes, $id, $lang) { // mPDF 6
1027
- if (isset($p[$tag])) { $this->_mergeCSS($p[$tag], $t); }
1028
- // STYLESHEET CLASS e.g. .smallone{} .redletter{}
1029
- foreach($classes AS $class) {
1030
- if (isset($p['CLASS>>'.$class])) { $this->_mergeCSS($p['CLASS>>'.$class], $t); }
1031
- }
1032
- // STYLESHEET nth-child SELECTOR e.g. tr:nth-child(odd) td:nth-child(2n+1)
1033
- if ($tag=='TR' && isset($p) && $p) {
1034
- foreach($p AS $k=>$val) {
1035
- if (preg_match('/'.$tag.'>>SELECTORNTHCHILD>>(.*)/',$k, $m)) {
1036
- $select = false;
1037
- if ($tag=='TR') {
1038
- $row = $this->mpdf->row;
1039
- $thnr = (isset($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_thead']) ? count($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_thead']) : 0);
1040
- $tfnr = (isset($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_tfoot']) ? count($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_tfoot']) : 0);
1041
- if ($this->mpdf->tabletfoot) { $row -= $thnr; }
1042
- else if (!$this->mpdf->tablethead) { $row -= ($thnr + $tfnr); }
1043
- if (preg_match('/(([\-+]?\d*)?N([\-+]\d+)?|[\-+]?\d+|ODD|EVEN)/',$m[1],$a)) { // mPDF 5.7.4
1044
- $select = $this->_nthchild($a, $row);
1045
- }
1046
- }
1047
- else if ($tag=='TD' || $tag=='TH') {
1048
- if (preg_match('/(([\-+]?\d*)?N([\-+]\d+)?|[\-+]?\d+|ODD|EVEN)/',$m[1],$a)) { // mPDF 5.7.4
1049
- $select = $this->_nthchild($a, $this->mpdf->col);
1050
- }
1051
- }
1052
- if ($select) {
1053
- $this->_mergeCSS($p[$tag.'>>SELECTORNTHCHILD>>'.$m[1]], $t);
1054
- }
1055
- }
1056
- }
1057
- }
1058
- // STYLESHEET CLASS e.g. [lang=fr]{} or :lang(fr)
1059
- if (isset($lang) && isset($p['LANG>>'.$lang])) {
1060
- $this->_mergeCSS($p['LANG>>'.$lang], $t);
1061
- }
1062
- // STYLESHEET CLASS e.g. #smallone{} #redletter{}
1063
- if (isset($id) && isset($p['ID>>'.$id])) {
1064
- $this->_mergeCSS($p['ID>>'.$id], $t);
1065
- }
1066
-
1067
- // STYLESHEET CLASS e.g. .smallone{} .redletter{}
1068
- foreach($classes AS $class) {
1069
- if (isset($p[$tag.'>>CLASS>>'.$class])) { $this->_mergeCSS($p[$tag.'>>CLASS>>'.$class], $t); }
1070
- }
1071
- // STYLESHEET CLASS e.g. [lang=fr]{} or :lang(fr)
1072
- if (isset($lang) && isset($p[$tag.'>>LANG>>'.$lang])) {
1073
- $this->_mergeCSS($p[$tag.'>>LANG>>'.$lang], $t);
1074
- }
1075
- // STYLESHEET CLASS e.g. #smallone{} #redletter{}
1076
- if (isset($id) && isset($p[$tag.'>>ID>>'.$id])) {
1077
- $this->_mergeCSS($p[$tag.'>>ID>>'.$id], $t);
1078
- }
1079
- }
1080
-
1081
- function setBorderDominance($prop, $val) {
1082
- if (isset($prop['BORDER-LEFT']) && $prop['BORDER-LEFT']) { $this->cell_border_dominance_L = $val; }
1083
- if (isset($prop['BORDER-RIGHT']) && $prop['BORDER-RIGHT']) { $this->cell_border_dominance_R = $val; }
1084
- if (isset($prop['BORDER-TOP']) && $prop['BORDER-TOP']) { $this->cell_border_dominance_T = $val; }
1085
- if (isset($prop['BORDER-BOTTOM']) && $prop['BORDER-BOTTOM']) { $this->cell_border_dominance_B = $val; }
1086
- }
1087
-
1088
- function _set_mergedCSS(&$m, &$p, $d=true, $bd=false) {
1089
- if (isset($m)) {
1090
- if ((isset($m['depth']) && $m['depth']>1) || $d==false) { // include check for 'depth'
1091
- if ($bd) { $this->setBorderDominance($m, $bd); } // *TABLES*
1092
- if (is_array($m)) {
1093
- $p = array_merge($p,$m);
1094
- $this->_mergeBorders($p,$m);
1095
- }
1096
- }
1097
- }
1098
- }
1099
-
1100
-
1101
- function _mergeBorders(&$b, &$a) { // Merges $a['BORDER-TOP-STYLE'] to $b['BORDER-TOP'] etc.
1102
- foreach(array('TOP','RIGHT','BOTTOM','LEFT') AS $side) {
1103
- foreach(array('STYLE','WIDTH','COLOR') AS $el) {
1104
- if (isset($a['BORDER-'.$side.'-'.$el])) { // e.g. $b['BORDER-TOP-STYLE']
1105
- $s = trim($a['BORDER-'.$side.'-'.$el]);
1106
- if (isset($b['BORDER-'.$side])) { // e.g. $b['BORDER-TOP']
1107
- $p = trim($b['BORDER-'.$side]);
1108
- }
1109
- else { $p = ''; }
1110
- if ($el=='STYLE') {
1111
- if ($p) { $b['BORDER-'.$side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', '\\1 '.$s.' \\3', $p); }
1112
- else { $b['BORDER-'.$side] = '0px '.$s.' #000000'; }
1113
- }
1114
- else if ($el=='WIDTH') {
1115
- if ($p) { $b['BORDER-'.$side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', $s.' \\2 \\3', $p); }
1116
- else { $b['BORDER-'.$side] = $s.' none #000000'; }
1117
- }
1118
- else if ($el=='COLOR') {
1119
- if ($p) { $b['BORDER-'.$side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', '\\1 \\2 '.$s, $p); }
1120
- else { $b['BORDER-'.$side] = '0px none '.$s; }
1121
- }
1122
- }
1123
- }
1124
- }
1125
- }
1126
-
1127
-
1128
- function MergeCSS($inherit,$tag,$attr) {
1129
- $p = array();
1130
- $zp = array();
1131
-
1132
- $classes = array();
1133
- if (isset($attr['CLASS'])) {
1134
- $classes = preg_split('/\s+/',$attr['CLASS']);
1135
- }
1136
- if (!isset($attr['ID'])) { $attr['ID']=''; }
1137
- // mPDF 6
1138
- $shortlang = '';
1139
- if (!isset($attr['LANG'])) { $attr['LANG']=''; }
1140
- else {
1141
- $attr['LANG'] = strtolower($attr['LANG']);
1142
- if (strlen($attr['LANG']) == 5) {
1143
- $shortlang = substr($attr['LANG'],0,2);
1144
- }
1145
- }
1146
- //===============================================
1147
- /*-- TABLES --*/
1148
- // Set Inherited properties
1149
- if ($inherit == 'TOPTABLE') { // $tag = TABLE
1150
- //===============================================
1151
- // Save Cascading CSS e.g. "div.topic p" at this block level
1152
-
1153
- if (isset($this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'])) {
1154
- $this->tablecascadeCSS[0] = $this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'];
1155
- }
1156
- else {
1157
- $this->tablecascadeCSS[0] = $this->cascadeCSS;
1158
- }
1159
- }
1160
- //===============================================
1161
- // Set Inherited properties
1162
- if ($inherit == 'TOPTABLE' || $inherit == 'TABLE') {
1163
- //Cascade everything from last level that is not an actual property, or defined by current tag/attributes
1164
- if (isset($this->tablecascadeCSS[$this->tbCSSlvl-1]) && is_array($this->tablecascadeCSS[$this->tbCSSlvl-1])) {
1165
- foreach($this->tablecascadeCSS[$this->tbCSSlvl-1] AS $k=>$v) {
1166
- $this->tablecascadeCSS[$this->tbCSSlvl][$k] = $v;
1167
- }
1168
- }
1169
- $this->_mergeFullCSS($this->cascadeCSS, $this->tablecascadeCSS[$this->tbCSSlvl], $tag, $classes, $attr['ID'], $attr['LANG']);
1170
- //===============================================
1171
- // Cascading forward CSS e.g. "table.topic td" for this table in $this->tablecascadeCSS
1172
- //===============================================
1173
- // STYLESHEET TAG e.g. table
1174
- $this->_mergeFullCSS($this->tablecascadeCSS[$this->tbCSSlvl-1], $this->tablecascadeCSS[$this->tbCSSlvl], $tag, $classes, $attr['ID'], $attr['LANG']);
1175
- //===============================================
1176
- }
1177
- /*-- END TABLES --*/
1178
- //===============================================
1179
- // Set Inherited properties
1180
- if ($inherit == 'BLOCK') {
1181
- if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS']) && is_array($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS'])) {
1182
- foreach($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS'] AS $k=>$v) {
1183
- $this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'][$k] = $v;
1184
-
1185
- }
1186
- }
1187
-
1188
- //===============================================
1189
- // Save Cascading CSS e.g. "div.topic p" at this block level
1190
- $this->_mergeFullCSS($this->cascadeCSS, $this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'], $tag, $classes, $attr['ID'], $attr['LANG']);
1191
- //===============================================
1192
- // Cascading forward CSS
1193
- //===============================================
1194
- if (isset($this->mpdf->blk[$this->mpdf->blklvl-1])) {
1195
- $this->_mergeFullCSS($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS'], $this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'], $tag, $classes, $attr['ID'], $attr['LANG']);
1196
- }
1197
- //===============================================
1198
- // Block properties which are inherited
1199
- if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['margin_collapse']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['margin_collapse']) { $p['MARGIN-COLLAPSE'] = 'COLLAPSE'; } // custom tag, but follows CSS principle that border-collapse is inherited
1200
- if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['line_height']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['line_height']) { $p['LINE-HEIGHT'] = $this->mpdf->blk[$this->mpdf->blklvl-1]['line_height']; }
1201
- // mPDF 6
1202
- if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['line_stacking_strategy']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['line_stacking_strategy']) { $p['LINE-STACKING-STRATEGY'] = $this->mpdf->blk[$this->mpdf->blklvl-1]['line_stacking_strategy']; }
1203
- if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['line_stacking_shift']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['line_stacking_shift']) { $p['LINE-STACKING-SHIFT'] = $this->mpdf->blk[$this->mpdf->blklvl-1]['line_stacking_shift']; }
1204
-
1205
- if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['direction']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['direction']) { $p['DIRECTION'] = $this->mpdf->blk[$this->mpdf->blklvl-1]['direction']; }
1206
- // mPDF 6 Lists
1207
- if ($tag == 'LI') {
1208
- if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_type']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_type']) { $p['LIST-STYLE-TYPE'] = $this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_type']; }
1209
- }
1210
- if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_image']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_image']) { $p['LIST-STYLE-IMAGE'] = $this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_image']; }
1211
- if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_position']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_position']) { $p['LIST-STYLE-POSITION'] = $this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_position']; }
1212
-
1213
- if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['align']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['align']) {
1214
- if ($this->mpdf->blk[$this->mpdf->blklvl-1]['align'] == 'L') { $p['TEXT-ALIGN'] = 'left'; }
1215
- else if ($this->mpdf->blk[$this->mpdf->blklvl-1]['align'] == 'J') { $p['TEXT-ALIGN'] = 'justify'; }
1216
- else if ($this->mpdf->blk[$this->mpdf->blklvl-1]['align'] == 'R') { $p['TEXT-ALIGN'] = 'right'; }
1217
- else if ($this->mpdf->blk[$this->mpdf->blklvl-1]['align'] == 'C') { $p['TEXT-ALIGN'] = 'center'; }
1218
- }
1219
- if ($this->mpdf->ColActive || $this->mpdf->keep_block_together) {
1220
- if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['bgcolor']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['bgcolor']) { // Doesn't officially inherit, but default value is transparent (?=inherited)
1221
- $cor = $this->mpdf->blk[$this->mpdf->blklvl-1]['bgcolorarray' ];
1222
- $p['BACKGROUND-COLOR'] = $this->mpdf->_colAtoString($cor);
1223
- }
1224
- }
1225
-
1226
- if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['text_indent']) && ($this->mpdf->blk[$this->mpdf->blklvl-1]['text_indent'] || $this->mpdf->blk[$this->mpdf->blklvl-1]['text_indent']===0)) { $p['TEXT-INDENT'] = $this->mpdf->blk[$this->mpdf->blklvl-1]['text_indent']; }
1227
- if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['InlineProperties'])) {
1228
- $biilp = $this->mpdf->blk[$this->mpdf->blklvl-1]['InlineProperties'];
1229
- $this->inlinePropsToCSS($biilp, $p); // mPDF 5.7.1
1230
- }
1231
- else { $biilp = null; }
1232
- }
1233
- //===============================================
1234
- //===============================================
1235
- // INLINE HTML ATTRIBUTES e.g. .. ALIGN="CENTER">
1236
- // mPDF 6 (added)
1237
- if (isset($attr['DIR']) and $attr['DIR']!='') {
1238
- $p['DIRECTION'] = $attr['DIR'];
1239
- }
1240
- // mPDF 6 (moved)
1241
- if (isset($attr['LANG']) and $attr['LANG']!='') {
1242
- $p['LANG'] = $attr['LANG'];
1243
- }
1244
- if (isset($attr['COLOR']) and $attr['COLOR']!='') {
1245
- $p['COLOR'] = $attr['COLOR'];
1246
- }
1247
-
1248
- if ($tag != 'INPUT') {
1249
- if (isset($attr['WIDTH']) and $attr['WIDTH']!='') {
1250
- $p['WIDTH'] = $attr['WIDTH'];
1251
- }
1252
- if (isset($attr['HEIGHT']) and $attr['HEIGHT']!='') {
1253
- $p['HEIGHT'] = $attr['HEIGHT'];
1254
- }
1255
- }
1256
- if ($tag == 'FONT') {
1257
- if (isset($attr['FACE'])) {
1258
- $p['FONT-FAMILY'] = $attr['FACE'];
1259
- }
1260
- if (isset($attr['SIZE']) and $attr['SIZE']!='') {
1261
- $s = '';
1262
- if ($attr['SIZE'] === '+1') { $s = '120%'; }
1263
- else if ($attr['SIZE'] === '-1') { $s = '86%'; }
1264
- else if ($attr['SIZE'] === '1') { $s = 'XX-SMALL'; }
1265
- else if ($attr['SIZE'] == '2') { $s = 'X-SMALL'; }
1266
- else if ($attr['SIZE'] == '3') { $s = 'SMALL'; }
1267
- else if ($attr['SIZE'] == '4') { $s = 'MEDIUM'; }
1268
- else if ($attr['SIZE'] == '5') { $s = 'LARGE'; }
1269
- else if ($attr['SIZE'] == '6') { $s = 'X-LARGE'; }
1270
- else if ($attr['SIZE'] == '7') { $s = 'XX-LARGE'; }
1271
- if ($s) $p['FONT-SIZE'] = $s;
1272
- }
1273
- }
1274
- if (isset($attr['VALIGN']) and $attr['VALIGN']!='') {
1275
- $p['VERTICAL-ALIGN'] = $attr['VALIGN'];
1276
- }
1277
- if (isset($attr['VSPACE']) and $attr['VSPACE']!='') {
1278
- $p['MARGIN-TOP'] = $attr['VSPACE'];
1279
- $p['MARGIN-BOTTOM'] = $attr['VSPACE'];
1280
- }
1281
- if (isset($attr['HSPACE']) and $attr['HSPACE']!='') {
1282
- $p['MARGIN-LEFT'] = $attr['HSPACE'];
1283
- $p['MARGIN-RIGHT'] = $attr['HSPACE'];
1284
- }
1285
- //===============================================
1286
- //===============================================
1287
- // DEFAULT for this TAG set in DefaultCSS
1288
- if (isset($this->mpdf->defaultCSS[$tag])) {
1289
- $zp = $this->fixCSS($this->mpdf->defaultCSS[$tag]);
1290
- if (is_array($zp)) { // Default overwrites Inherited
1291
- $p = array_merge($p,$zp); // !! Note other way round !!
1292
- $this->_mergeBorders($p,$zp);
1293
- }
1294
- }
1295
- //===============================================
1296
- /*-- TABLES --*/
1297
- // mPDF 5.7.3
1298
- // cellSpacing overwrites TABLE default but not specific CSS set on table
1299
- if ($tag=='TABLE' && isset($attr['CELLSPACING'])) {
1300
- $p['BORDER-SPACING-H'] = $p['BORDER-SPACING-V'] = $attr['CELLSPACING'];
1301
- }
1302
- // cellPadding overwrites TD/TH default but not specific CSS set on cell
1303
- if (($tag=='TD' || $tag=='TH') && isset($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding']) && ($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding'] || $this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding']==='0')) { // mPDF 5.7.3
1304
- $p['PADDING-LEFT'] = $this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding'];
1305
- $p['PADDING-RIGHT'] = $this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding'];
1306
- $p['PADDING-TOP'] = $this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding'];
1307
- $p['PADDING-BOTTOM'] = $this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding'];
1308
- }
1309
- /*-- END TABLES --*/
1310
- //===============================================
1311
- // STYLESHEET TAG e.g. h1 p div table
1312
- if (isset($this->CSS[$tag]) && $this->CSS[$tag]) {
1313
- $zp = $this->CSS[$tag];
1314
- if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1315
- if (is_array($zp)) {
1316
- $p = array_merge($p,$zp);
1317
- $this->_mergeBorders($p,$zp);
1318
- }
1319
- }
1320
- //===============================================
1321
- // STYLESHEET CLASS e.g. .smallone{} .redletter{}
1322
- foreach($classes AS $class) {
1323
- $zp = array();
1324
- if (isset($this->CSS['CLASS>>'.$class]) && $this->CSS['CLASS>>'.$class]) { $zp = $this->CSS['CLASS>>'.$class]; }
1325
- if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1326
- if (is_array($zp)) {
1327
- $p = array_merge($p,$zp);
1328
- $this->_mergeBorders($p,$zp);
1329
- }
1330
- }
1331
- //===============================================
1332
- /*-- TABLES --*/
1333
- // STYLESHEET nth-child SELECTOR e.g. tr:nth-child(odd) td:nth-child(2n+1)
1334
- if ($tag=='TR' || $tag=='TD' || $tag=='TH') {
1335
- foreach($this->CSS AS $k=>$val) {
1336
- if (preg_match('/'.$tag.'>>SELECTORNTHCHILD>>(.*)/',$k, $m)) {
1337
- $select = false;
1338
- if ($tag=='TR') {
1339
- $row = $this->mpdf->row;
1340
- $thnr = (isset($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_thead']) ? count($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_thead']) : 0);
1341
- $tfnr = (isset($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_tfoot']) ? count($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_tfoot']) : 0);
1342
- if ($this->mpdf->tabletfoot) { $row -= $thnr; }
1343
- else if (!$this->mpdf->tablethead) { $row -= ($thnr + $tfnr); }
1344
- if (preg_match('/(([\-+]?\d*)?N([\-+]\d+)?|[\-+]?\d+|ODD|EVEN)/',$m[1],$a)) { // mPDF 5.7.4
1345
- $select = $this->_nthchild($a, $row);
1346
- }
1347
- }
1348
- else if ($tag=='TD' || $tag=='TH') {
1349
- if (preg_match('/(([\-+]?\d*)?N([\-+]\d+)?|[\-+]?\d+|ODD|EVEN)/',$m[1],$a)) { // mPDF 5.7.4
1350
- $select = $this->_nthchild($a, $this->mpdf->col);
1351
- }
1352
- }
1353
- if ($select) {
1354
- $zp = $this->CSS[$tag.'>>SELECTORNTHCHILD>>'.$m[1]];
1355
- if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); }
1356
- if (is_array($zp)) {
1357
- $p = array_merge($p,$zp);
1358
- $this->_mergeBorders($p,$zp);
1359
- }
1360
- }
1361
- }
1362
- }
1363
- }
1364
- /*-- END TABLES --*/
1365
- //===============================================
1366
- // STYLESHEET LANG e.g. [lang=fr]{} or :lang(fr)
1367
- if (isset($attr['LANG'])) {
1368
- if (isset($this->CSS['LANG>>'.$attr['LANG']]) && $this->CSS['LANG>>'.$attr['LANG']]) {
1369
- $zp = $this->CSS['LANG>>'.$attr['LANG']];
1370
- if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1371
- if (is_array($zp)) {
1372
- $p = array_merge($p,$zp);
1373
- $this->_mergeBorders($p,$zp);
1374
- }
1375
- }
1376
- else if (isset($this->CSS['LANG>>'.$shortlang]) && $this->CSS['LANG>>'.$shortlang]) {
1377
- $zp = $this->CSS['LANG>>'.$shortlang];
1378
- if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1379
- if (is_array($zp)) {
1380
- $p = array_merge($p,$zp);
1381
- $this->_mergeBorders($p,$zp);
1382
- }
1383
- }
1384
- }
1385
- //===============================================
1386
- // STYLESHEET ID e.g. #smallone{} #redletter{}
1387
- if (isset($attr['ID']) && isset($this->CSS['ID>>'.$attr['ID']]) && $this->CSS['ID>>'.$attr['ID']]) {
1388
- $zp = $this->CSS['ID>>'.$attr['ID']];
1389
- if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1390
- if (is_array($zp)) {
1391
- $p = array_merge($p,$zp);
1392
- $this->_mergeBorders($p,$zp);
1393
- }
1394
- }
1395
-
1396
- //===============================================
1397
- // STYLESHEET CLASS e.g. p.smallone{} div.redletter{}
1398
- foreach($classes AS $class) {
1399
- $zp = array();
1400
- if (isset($this->CSS[$tag.'>>CLASS>>'.$class]) && $this->CSS[$tag.'>>CLASS>>'.$class]) { $zp = $this->CSS[$tag.'>>CLASS>>'.$class]; }
1401
- if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1402
- if (is_array($zp)) {
1403
- $p = array_merge($p,$zp);
1404
- $this->_mergeBorders($p,$zp);
1405
- }
1406
- }
1407
- //===============================================
1408
- // STYLESHEET LANG e.g. [lang=fr]{} or :lang(fr)
1409
- if (isset($attr['LANG'])) {
1410
- if (isset($this->CSS[$tag.'>>LANG>>'.$attr['LANG']]) && $this->CSS[$tag.'>>LANG>>'.$attr['LANG']]) {
1411
- $zp = $this->CSS[$tag.'>>LANG>>'.$attr['LANG']];
1412
- if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1413
- if (is_array($zp)) {
1414
- $p = array_merge($p,$zp);
1415
- $this->_mergeBorders($p,$zp);
1416
- }
1417
- }
1418
- else if (isset($this->CSS[$tag.'>>LANG>>'.$shortlang]) && $this->CSS[$tag.'>>LANG>>'.$shortlang]) {
1419
- $zp = $this->CSS[$tag.'>>LANG>>'.$shortlang];
1420
- if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1421
- if (is_array($zp)) {
1422
- $p = array_merge($p,$zp);
1423
- $this->_mergeBorders($p,$zp);
1424
- }
1425
- }
1426
- }
1427
- //===============================================
1428
- // STYLESHEET CLASS e.g. p#smallone{} div#redletter{}
1429
- if (isset($attr['ID']) && isset($this->CSS[$tag.'>>ID>>'.$attr['ID']]) && $this->CSS[$tag.'>>ID>>'.$attr['ID']]) {
1430
- $zp = $this->CSS[$tag.'>>ID>>'.$attr['ID']];
1431
- if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1432
- if (is_array($zp)) {
1433
- $p = array_merge($p,$zp);
1434
- $this->_mergeBorders($p,$zp);
1435
- }
1436
- }
1437
- //===============================================
1438
- // Cascaded e.g. div.class p only works for block level
1439
- if ($inherit == 'BLOCK') {
1440
- if (isset($this->mpdf->blk[$this->mpdf->blklvl-1])) { // mPDF 6
1441
- $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS'][$tag], $p);
1442
- foreach($classes AS $class) {
1443
- $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS']['CLASS>>'.$class], $p);
1444
- }
1445
- $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS']['ID>>'.$attr['ID']], $p);
1446
- foreach($classes AS $class) {
1447
- $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS'][$tag.'>>CLASS>>'.$class], $p);
1448
- }
1449
- $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS'][$tag.'>>ID>>'.$attr['ID']], $p);
1450
- }
1451
- }
1452
- else if ($inherit == 'INLINE') {
1453
- $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'][$tag], $p);
1454
- foreach($classes AS $class) {
1455
- $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS']['CLASS>>'.$class], $p);
1456
- }
1457
- $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS']['ID>>'.$attr['ID']], $p);
1458
- foreach($classes AS $class) {
1459
- $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'][$tag.'>>CLASS>>'.$class], $p);
1460
- }
1461
- $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'][$tag.'>>ID>>'.$attr['ID']], $p);
1462
- }
1463
- /*-- TABLES --*/
1464
- else if ($inherit == 'TOPTABLE' || $inherit == 'TABLE') { // NB looks at $this->tablecascadeCSS-1 for cascading CSS
1465
- if (isset($this->tablecascadeCSS[$this->tbCSSlvl-1])) { // mPDF 6
1466
- // false, 9 = don't check for 'depth' and do set border dominance
1467
- $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag], $p, false, 9);
1468
- foreach($classes AS $class) {
1469
- $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1]['CLASS>>'.$class], $p, false, 9);
1470
- }
1471
- // STYLESHEET nth-child SELECTOR e.g. tr:nth-child(odd) td:nth-child(2n+1)
1472
- if ($tag=='TR' || $tag=='TD' || $tag=='TH') {
1473
- foreach($this->tablecascadeCSS[$this->tbCSSlvl-1] AS $k=>$val) {
1474
- if (preg_match('/'.$tag.'>>SELECTORNTHCHILD>>(.*)/',$k, $m)) {
1475
- $select = false;
1476
- if ($tag=='TR') {
1477
- $row = $this->mpdf->row;
1478
- $thnr = (isset($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_thead']) ? count($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_thead']) : 0);
1479
- $tfnr = (isset($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_tfoot']) ? count($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_tfoot']) : 0);
1480
- if ($this->mpdf->tabletfoot) { $row -= $thnr; }
1481
- else if (!$this->mpdf->tablethead) { $row -= ($thnr + $tfnr); }
1482
- if (preg_match('/(([\-+]?\d*)?N([\-+]\d+)?|[\-+]?\d+|ODD|EVEN)/',$m[1],$a)) { // mPDF 5.7.4
1483
- $select = $this->_nthchild($a, $row);
1484
- }
1485
- }
1486
- else if ($tag=='TD' || $tag=='TH') {
1487
- if (preg_match('/(([\-+]?\d*)?N([\-+]\d+)?|[\-+]?\d+|ODD|EVEN)/',$m[1],$a)) { // mPDF 5.7.4
1488
- $select = $this->_nthchild($a, $this->mpdf->col);
1489
- }
1490
- }
1491
- if ($select) {
1492
- $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag.'>>SELECTORNTHCHILD>>'.$m[1]], $p, false, 9);
1493
- }
1494
- }
1495
- }
1496
- }
1497
- }
1498
- $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1]['ID>>'.$attr['ID']], $p, false, 9);
1499
- foreach($classes AS $class) {
1500
- $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag.'>>CLASS>>'.$class], $p, false, 9);
1501
- }
1502
- $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag.'>>ID>>'.$attr['ID']], $p, false, 9);
1503
- }
1504
- /*-- END TABLES --*/
1505
- //===============================================
1506
- //===============================================
1507
- // INLINE STYLE e.g. style="CSS:property"
1508
- if (isset($attr['STYLE'])) {
1509
- $zp = $this->readInlineCSS($attr['STYLE']);
1510
- if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1511
- if (is_array($zp)) {
1512
- $p = array_merge($p,$zp);
1513
- $this->_mergeBorders($p,$zp);
1514
- }
1515
- }
1516
- //===============================================
1517
- //===============================================
1518
- return $p;
1519
- }
1520
-
1521
-
1522
- // Convert inline Properties back to CSS
1523
- function inlinePropsToCSS($bilp, &$p) {
1524
- if (isset($bilp[ 'family' ]) && $bilp[ 'family' ]) { $p['FONT-FAMILY'] = $bilp[ 'family' ]; }
1525
- if (isset($bilp[ 'I' ]) && $bilp[ 'I' ]) { $p['FONT-STYLE'] = 'italic'; }
1526
- if (isset($bilp[ 'sizePt' ]) && $bilp[ 'sizePt' ]) { $p['FONT-SIZE'] = $bilp[ 'sizePt' ] . 'pt'; }
1527
- if (isset($bilp[ 'B' ]) && $bilp[ 'B' ]) { $p['FONT-WEIGHT'] = 'bold'; }
1528
- if (isset($bilp[ 'colorarray' ]) && $bilp[ 'colorarray' ]) {
1529
- $cor = $bilp[ 'colorarray' ];
1530
- $p['COLOR'] = $this->mpdf->_colAtoString($cor);
1531
- }
1532
- if (isset($bilp[ 'lSpacingCSS' ]) && $bilp[ 'lSpacingCSS' ]) { $p['LETTER-SPACING'] = $bilp[ 'lSpacingCSS' ]; }
1533
- if (isset($bilp[ 'wSpacingCSS' ]) && $bilp[ 'wSpacingCSS' ]) { $p['WORD-SPACING'] = $bilp[ 'wSpacingCSS' ]; }
1534
-
1535
- if (isset($bilp[ 'textparam' ]) && $bilp[ 'textparam' ]) {
1536
- if (isset($bilp[ 'textparam' ]['hyphens'])) {
1537
- if ($bilp[ 'textparam' ]['hyphens']==2) { $p['HYPHENS'] = 'none'; }
1538
- if ($bilp[ 'textparam' ]['hyphens']==1) { $p['HYPHENS'] = 'auto'; }
1539
- if ($bilp[ 'textparam' ]['hyphens']==0) { $p['HYPHENS'] = 'manual'; }
1540
- }
1541
- if (isset($bilp[ 'textparam' ]['outline-s']) && !$bilp[ 'textparam' ]['outline-s']) { $p['TEXT-OUTLINE'] = 'none'; }
1542
- if (isset($bilp[ 'textparam' ]['outline-COLOR']) && $bilp[ 'textparam' ]['outline-COLOR']) { $p['TEXT-OUTLINE-COLOR'] = $this->mpdf->_colAtoString($bilp[ 'textparam' ]['outline-COLOR']); }
1543
- if (isset($bilp[ 'textparam' ]['outline-WIDTH']) && $bilp[ 'textparam' ]['outline-WIDTH']) { $p['TEXT-OUTLINE-WIDTH'] = $bilp[ 'textparam' ]['outline-WIDTH'].'mm'; }
1544
- }
1545
-
1546
- if (isset($bilp[ 'textvar' ]) && $bilp[ 'textvar' ]) {
1547
- // CSS says text-decoration is not inherited, but IE7 does??
1548
- if ($bilp[ 'textvar' ] & FD_LINETHROUGH) {
1549
- if ($bilp[ 'textvar' ] & FD_UNDERLINE) { $p['TEXT-DECORATION'] = 'underline line-through'; }
1550
- else { $p['TEXT-DECORATION'] = 'line-through'; }
1551
- }
1552
- else if ($bilp[ 'textvar' ] & FD_UNDERLINE) { $p['TEXT-DECORATION'] = 'underline'; }
1553
- else { $p['TEXT-DECORATION'] = 'none'; }
1554
-
1555
- if ($bilp[ 'textvar' ] & FA_SUPERSCRIPT) { $p['VERTICAL-ALIGN'] = 'super'; }
1556
- else if ($bilp[ 'textvar' ] & FA_SUBSCRIPT) { $p['VERTICAL-ALIGN'] = 'sub'; }
1557
- else { $p['VERTICAL-ALIGN'] = 'baseline'; }
1558
-
1559
- if ($bilp[ 'textvar' ] & FT_CAPITALIZE) { $p['TEXT-TRANSFORM'] = 'capitalize'; }
1560
- else if ($bilp[ 'textvar' ] & FT_UPPERCASE) { $p['TEXT-TRANSFORM'] = 'uppercase'; }
1561
- else if ($bilp[ 'textvar' ] & FT_LOWERCASE) { $p['TEXT-TRANSFORM'] = 'lowercase'; }
1562
- else { $p['TEXT-TRANSFORM'] = 'none'; }
1563
-
1564
- if ($bilp[ 'textvar' ] & FC_KERNING) { $p['FONT-KERNING'] = 'normal'; } // ignore 'auto' as default already applied
1565
- //if (isset($bilp[ 'OTLtags' ]) && $bilp[ 'OTLtags' ]['Plus'] contains 'kern'
1566
- else { $p['FONT-KERNING'] = 'none'; }
1567
-
1568
- if ($bilp[ 'textvar' ] & FA_SUPERSCRIPT) { $p['FONT-VARIANT-POSITION'] = 'super'; }
1569
- //if (isset($bilp[ 'OTLtags' ]) && $bilp[ 'OTLtags' ]['Plus'] contains 'sups' / 'subs'
1570
- else if ($bilp[ 'textvar' ] & FA_SUBSCRIPT) { $p['FONT-VARIANT-POSITION'] = 'sub'; }
1571
- else { $p['FONT-VARIANT-POSITION'] = 'normal'; }
1572
-
1573
- if ($bilp[ 'textvar' ] & FC_SMALLCAPS) { $p['FONT-VARIANT-CAPS'] = 'small-caps'; }
1574
- }
1575
- if (isset($bilp[ 'fontLanguageOverride' ])) {
1576
- if ($bilp[ 'fontLanguageOverride' ]) { $p['FONT-LANGUAGE-OVERRIDE'] = $bilp[ 'fontLanguageOverride' ]; }
1577
- else { $p['FONT-LANGUAGE-OVERRIDE'] = 'normal'; }
1578
- }
1579
- // All the variations of font-variant-* we are going to set as font-feature-settings...
1580
- if (isset($bilp[ 'OTLtags' ]) && $bilp[ 'OTLtags' ]) {
1581
- $ffs = array();
1582
- if (isset($bilp['OTLtags']['Minus']) && $bilp['OTLtags']['Minus']) {
1583
- $f = preg_split('/\s+/', trim($bilp['OTLtags']['Minus']));
1584
- foreach($f AS $ff) { $ffs[] = "'".$ff."' 0"; }
1585
- }
1586
- if (isset($bilp['OTLtags']['FFMinus']) && $bilp['OTLtags']['FFMinus']) {
1587
- $f = preg_split('/\s+/', trim($bilp['OTLtags']['FFMinus']));
1588
- foreach($f AS $ff) { $ffs[] = "'".$ff."' 0"; }
1589
- }
1590
- if (isset($bilp['OTLtags']['Plus']) && $bilp['OTLtags']['Plus']) {
1591
- $f = preg_split('/\s+/', trim($bilp['OTLtags']['Plus']));
1592
- foreach($f AS $ff) { $ffs[] = "'".$ff."' 1"; }
1593
- }
1594
- if (isset($bilp['OTLtags']['FFPlus']) && $bilp['OTLtags']['FFPlus']) { // May contain numeric value e.g. salt4
1595
- $f = preg_split('/\s+/', trim($bilp['OTLtags']['FFPlus']));
1596
- foreach($f AS $ff) {
1597
- if (strlen($ff)>4) { $ffs[] = "'".substr($ff,0,4)."' ".substr($ff,4); }
1598
- else { $ffs[] = "'".$ff."' 1"; }
1599
- }
1600
- }
1601
- $p['FONT-FEATURE-SETTINGS'] = implode(', ', $ffs);
1602
- }
1603
-
1604
-
1605
- }
1606
-
1607
- function PreviewBlockCSS($tag,$attr) {
1608
- // Looks ahead from current block level to a new level
1609
- $p = array();
1610
- $zp = array();
1611
- $oldcascadeCSS = $this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'];
1612
- $classes = array();
1613
- if (isset($attr['CLASS'])) { $classes = preg_split('/\s+/',$attr['CLASS']); }
1614
- //===============================================
1615
- // DEFAULT for this TAG set in DefaultCSS
1616
- if (isset($this->mpdf->defaultCSS[$tag])) {
1617
- $zp = $this->fixCSS($this->mpdf->defaultCSS[$tag]);
1618
- if (is_array($zp)) { $p = array_merge($zp,$p); } // Inherited overwrites default
1619
- }
1620
- // STYLESHEET TAG e.g. h1 p div table
1621
- if (isset($this->CSS[$tag])) {
1622
- $zp = $this->CSS[$tag];
1623
- if (is_array($zp)) { $p = array_merge($p,$zp); }
1624
- }
1625
- // STYLESHEET CLASS e.g. .smallone{} .redletter{}
1626
- foreach($classes AS $class) {
1627
- $zp = array();
1628
- if (isset($this->CSS['CLASS>>'.$class])) { $zp = $this->CSS['CLASS>>'.$class]; }
1629
- if (is_array($zp)) { $p = array_merge($p,$zp); }
1630
- }
1631
- // STYLESHEET ID e.g. #smallone{} #redletter{}
1632
- if (isset($attr['ID']) && isset($this->CSS['ID>>'.$attr['ID']])) {
1633
- $zp = $this->CSS['ID>>'.$attr['ID']];
1634
- if (is_array($zp)) { $p = array_merge($p,$zp); }
1635
- }
1636
- // STYLESHEET CLASS e.g. p.smallone{} div.redletter{}
1637
- foreach($classes AS $class) {
1638
- $zp = array();
1639
- if (isset($this->CSS[$tag.'>>CLASS>>'.$class])) { $zp = $this->CSS[$tag.'>>CLASS>>'.$class]; }
1640
- if (is_array($zp)) { $p = array_merge($p,$zp); }
1641
- }
1642
- // STYLESHEET CLASS e.g. p#smallone{} div#redletter{}
1643
- if (isset($attr['ID']) && isset($this->CSS[$tag.'>>ID>>'.$attr['ID']])) {
1644
- $zp = $this->CSS[$tag.'>>ID>>'.$attr['ID']];
1645
- if (is_array($zp)) { $p = array_merge($p,$zp); }
1646
- }
1647
- //===============================================
1648
- // STYLESHEET TAG e.g. div h1 div p
1649
-
1650
- $this->_set_mergedCSS($oldcascadeCSS[$tag], $p);
1651
- // STYLESHEET CLASS e.g. .smallone{} .redletter{}
1652
- foreach($classes AS $class) {
1653
-
1654
- $this->_set_mergedCSS($oldcascadeCSS['CLASS>>'.$class], $p);
1655
- }
1656
- // STYLESHEET CLASS e.g. #smallone{} #redletter{}
1657
- if (isset($attr['ID'])) {
1658
-
1659
- $this->_set_mergedCSS($oldcascadeCSS['ID>>'.$attr['ID']], $p);
1660
- }
1661
- // STYLESHEET CLASS e.g. div.smallone{} p.redletter{}
1662
- foreach($classes AS $class) {
1663
-
1664
- $this->_set_mergedCSS($oldcascadeCSS[$tag.'>>CLASS>>'.$class], $p);
1665
- }
1666
- // STYLESHEET CLASS e.g. div#smallone{} p#redletter{}
1667
- if (isset($attr['ID'])) {
1668
-
1669
- $this->_set_mergedCSS($oldcascadeCSS[$tag.'>>ID>>'.$attr['ID']], $p);
1670
- }
1671
- //===============================================
1672
- // INLINE STYLE e.g. style="CSS:property"
1673
- if (isset($attr['STYLE'])) {
1674
- $zp = $this->readInlineCSS($attr['STYLE']);
1675
- if (is_array($zp)) { $p = array_merge($p,$zp); }
1676
- }
1677
- //===============================================
1678
- return $p;
1679
- }
1680
-
1681
-
1682
- // mPDF 5.7.4 nth-child
1683
- function _nthchild($f, $c) {
1684
- // $f is formual e.g. 2N+1 spilt into a preg_match array
1685
- // $c is the comparator value e.g row or column number
1686
- $c += 1;
1687
- $select = false;
1688
- $a=1; $b=1;
1689
- if ($f[0]=='ODD') { $a=2; $b=1; }
1690
- else if ($f[0]=='EVEN') { $a=2; $b=0; }
1691
- else if (count($f)==2) { $a=0; $b=$f[1]+0; } // e.g. (+6)
1692
- else if (count($f)==3) { // e.g. (2N)
1693
- if ($f[2]=='') { $a=1; }
1694
- else if ($f[2]=='-') { $a=-1; }
1695
- else { $a=$f[2]+0; }
1696
- $b=0;
1697
- }
1698
- else if (count($f)==4) { // e.g. (2N+6)
1699
- if ($f[2]=='') { $a=1; }
1700
- else if ($f[2]=='-') { $a=-1; }
1701
- else { $a=$f[2]+0; }
1702
- $b=$f[3]+0;
1703
- }
1704
- else { return false; }
1705
- if ($a>0) {
1706
- if (((($c % $a) - $b) % $a) == 0 && $c >= $b) { $select = true; }
1707
- }
1708
- else if ($a==0) {
1709
- if ($c == $b) { $select = true; }
1710
- }
1711
- else { // if ($a<0)
1712
- if (((($c % $a) - $b) % $a) == 0 && $c <= $b) { $select = true; }
1713
- }
1714
- return $select;
1715
- }
1716
-
1717
-
1718
-
1719
- } // end of class
1720
-
1721
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/mpdf/classes/desktop.ini DELETED
@@ -1,4 +0,0 @@
1
- [ViewState]
2
- Mode=
3
- Vid=
4
- FolderType=Documents
 
 
 
 
lib/mpdf/classes/directw.php DELETED
@@ -1,412 +0,0 @@
1
- <?php
2
-
3
- class directw {
4
-
5
- var $mpdf = null;
6
-
7
- function directw(&$mpdf) {
8
- $this->mpdf = $mpdf;
9
- }
10
-
11
-
12
- function Write($h,$txt,$currentx=0,$link='',$directionality='ltr',$align='') {
13
- if (!$align) {
14
- if ($directionality=='rtl') { $align = 'R'; }
15
- else { $align = 'L'; }
16
- }
17
- if ($h == 0) { $this->mpdf->SetLineHeight(); $h = $this->mpdf->lineheight; }
18
- //Output text in flowing mode
19
- $w = $this->mpdf->w - $this->mpdf->rMargin - $this->mpdf->x;
20
-
21
- $wmax = ($w - ($this->mpdf->cMarginL+$this->mpdf->cMarginR));
22
- $s=str_replace("\r",'',$txt);
23
- if ($this->mpdf->usingCoreFont) { $nb=strlen($s); }
24
- else {
25
- $nb=mb_strlen($s, $this->mpdf->mb_enc );
26
- // handle single space character
27
- if(($nb==1) && $s == " ") {
28
- $this->mpdf->x += $this->mpdf->GetStringWidth($s);
29
- return;
30
- }
31
- }
32
- $sep=-1;
33
- $i=0;
34
- $j=0;
35
- $l=0;
36
- $nl=1;
37
- if (!$this->mpdf->usingCoreFont) {
38
- if (preg_match("/([".$this->mpdf->pregRTLchars."])/u", $txt)) { $this->mpdf->biDirectional = true; } // *RTL*
39
- while($i<$nb) {
40
- //Get next character
41
- $c = mb_substr($s,$i,1,$this->mpdf->mb_enc );
42
- if($c == "\n") {
43
- // WORD SPACING
44
- $this->mpdf->ResetSpacing();
45
- //Explicit line break
46
- $tmp = rtrim(mb_substr($s,$j,$i-$j,$this->mpdf->mb_enc));
47
- $this->mpdf->Cell($w, $h, $tmp, 0, 2, $align, $fill, $link);
48
- $i++;
49
- $sep = -1;
50
- $j = $i;
51
- $l = 0;
52
- if($nl == 1) {
53
- if ($currentx != 0) $this->mpdf->x=$currentx;
54
- else $this->mpdf->x=$this->mpdf->lMargin;
55
- $w = $this->mpdf->w - $this->mpdf->rMargin - $this->mpdf->x;
56
- $wmax = ($w - ($this->mpdf->cMarginL+$this->mpdf->cMarginR));
57
- }
58
- $nl++;
59
- continue;
60
- }
61
- if($c == " ") { $sep= $i; }
62
- $l += $this->mpdf->GetCharWidthNonCore($c); // mPDF 5.3.04
63
- if($l > $wmax) {
64
- //Automatic line break (word wrapping)
65
- if($sep == -1) {
66
- // WORD SPACING
67
- $this->mpdf->ResetSpacing();
68
- if($this->mpdf->x > $this->mpdf->lMargin) {
69
- //Move to next line
70
- if ($currentx != 0) $this->mpdf->x=$currentx;
71
- else $this->mpdf->x=$this->mpdf->lMargin;
72
- $this->mpdf->y+=$h;
73
- $w=$this->mpdf->w-$this->mpdf->rMargin-$this->mpdf->x;
74
- $wmax = ($w - ($this->mpdf->cMarginL+$this->mpdf->cMarginR));
75
- $i++;
76
- $nl++;
77
- continue;
78
- }
79
- if($i==$j) { $i++; }
80
- $tmp = rtrim(mb_substr($s,$j,$i-$j,$this->mpdf->mb_enc));
81
- $this->mpdf->Cell($w, $h, $tmp, 0, 2, $align, $fill, $link);
82
- }
83
- else {
84
- $tmp = rtrim(mb_substr($s,$j,$sep-$j,$this->mpdf->mb_enc));
85
-
86
- if($align=='J') {
87
- //////////////////////////////////////////
88
- // JUSTIFY J using Unicode fonts (Word spacing doesn't work)
89
- // WORD SPACING
90
- // Change NON_BREAKING SPACE to spaces so they are 'spaced' properly
91
- $tmp = str_replace(chr(194).chr(160),chr(32),$tmp );
92
- $len_ligne = $this->mpdf->GetStringWidth($tmp );
93
- $nb_carac = mb_strlen( $tmp , $this->mpdf->mb_enc ) ;
94
- $nb_spaces = mb_substr_count( $tmp ,' ', $this->mpdf->mb_enc ) ;
95
- $inclCursive=false;
96
- if (isset($this->mpdf->CurrentFont['useOTL']) && $this->mpdf->CurrentFont['useOTL']) {
97
- if (preg_match("/([".$this->mpdf->pregCURSchars."])/u", $tmp)) { $inclCursive = true; }
98
- }
99
- list($charspacing,$ws) = $this->mpdf->GetJspacing($nb_carac,$nb_spaces,((($w-2) - $len_ligne) * _MPDFK),$inclCursive);
100
- $this->mpdf->SetSpacing($charspacing,$ws);
101
- //////////////////////////////////////////
102
- }
103
- $this->mpdf->Cell($w, $h, $tmp, 0, 2, $align, $fill, $link);
104
- $i=$sep+1;
105
- }
106
- $sep = -1;
107
- $j = $i;
108
- $l = 0;
109
- if($nl==1) {
110
- if ($currentx != 0) $this->mpdf->x=$currentx;
111
- else $this->mpdf->x=$this->mpdf->lMargin;
112
- $w=$this->mpdf->w-$this->mpdf->rMargin-$this->mpdf->x;
113
- $wmax = ($w - ($this->mpdf->cMarginL+$this->mpdf->cMarginR));
114
- }
115
- $nl++;
116
- }
117
- else { $i++; }
118
- }
119
- //Last chunk
120
- // WORD SPACING
121
- $this->mpdf->ResetSpacing();
122
- }
123
- else {
124
- while($i<$nb) {
125
- //Get next character
126
- $c=$s[$i];
127
- if($c == "\n") {
128
- //Explicit line break
129
- // WORD SPACING
130
- $this->mpdf->ResetSpacing();
131
- $this->mpdf->Cell($w, $h, substr($s, $j, $i-$j), 0, 2, $align, $fill, $link);
132
- $i++;
133
- $sep = -1;
134
- $j = $i;
135
- $l = 0;
136
- if($nl == 1) {
137
- if ($currentx != 0) $this->mpdf->x=$currentx;
138
- else $this->mpdf->x=$this->mpdf->lMargin;
139
- $w = $this->mpdf->w - $this->mpdf->rMargin - $this->mpdf->x;
140
- $wmax=$w-($this->mpdf->cMarginL+$this->mpdf->cMarginR);
141
- }
142
- $nl++;
143
- continue;
144
- }
145
- if($c == " ") { $sep= $i; }
146
- $l += $this->mpdf->GetCharWidthCore($c); // mPDF 5.3.04
147
- if($l > $wmax) {
148
- //Automatic line break (word wrapping)
149
- if($sep == -1) {
150
- // WORD SPACING
151
- $this->mpdf->ResetSpacing();
152
- if($this->mpdf->x > $this->mpdf->lMargin) {
153
- //Move to next line
154
- if ($currentx != 0) $this->mpdf->x=$currentx;
155
- else $this->mpdf->x=$this->mpdf->lMargin;
156
- $this->mpdf->y+=$h;
157
- $w=$this->mpdf->w-$this->mpdf->rMargin-$this->mpdf->x;
158
- $wmax=$w-($this->mpdf->cMarginL+$this->mpdf->cMarginR);
159
- $i++;
160
- $nl++;
161
- continue;
162
- }
163
- if($i==$j) { $i++; }
164
- $this->mpdf->Cell($w, $h, substr($s, $j, $i-$j), 0, 2, $align, $fill, $link);
165
- }
166
- else {
167
- $tmp = substr($s, $j, $sep-$j);
168
- if($align=='J') {
169
- //////////////////////////////////////////
170
- // JUSTIFY J using Unicode fonts
171
- // WORD SPACING is not fully supported for complex scripts
172
- // Change NON_BREAKING SPACE to spaces so they are 'spaced' properly
173
- $tmp = str_replace(chr(160),chr(32),$tmp );
174
- $len_ligne = $this->mpdf->GetStringWidth($tmp );
175
- $nb_carac = strlen( $tmp ) ;
176
- $nb_spaces = substr_count( $tmp ,' ' ) ;
177
- list($charspacing,$ws) = $this->mpdf->GetJspacing($nb_carac,$nb_spaces,((($w-2) - $len_ligne) * _MPDFK),$false);
178
- $this->mpdf->SetSpacing($charspacing,$ws);
179
- //////////////////////////////////////////
180
- }
181
- $this->mpdf->Cell($w, $h, $tmp, 0, 2, $align, $fill, $link);
182
- $i=$sep+1;
183
- }
184
- $sep = -1;
185
- $j = $i;
186
- $l = 0;
187
- if($nl==1) {
188
- if ($currentx != 0) $this->mpdf->x=$currentx;
189
- else $this->mpdf->x=$this->mpdf->lMargin;
190
- $w=$this->mpdf->w-$this->mpdf->rMargin-$this->mpdf->x;
191
- $wmax=$w-($this->mpdf->cMarginL+$this->mpdf->cMarginR);
192
- }
193
- $nl++;
194
- }
195
- else {
196
- $i++;
197
- }
198
- }
199
- // WORD SPACING
200
- $this->mpdf->ResetSpacing();
201
- }
202
- //Last chunk
203
- if($i!=$j) {
204
- if ($currentx != 0) $this->mpdf->x=$currentx;
205
- else $this->mpdf->x=$this->mpdf->lMargin;
206
- if ($this->mpdf->usingCoreFont) { $tmp = substr($s,$j,$i-$j); }
207
- else { $tmp = mb_substr($s,$j,$i-$j,$this->mpdf->mb_enc); }
208
- $this->mpdf->Cell($w,$h,$tmp,0,0,$align,$fill,$link);
209
- }
210
- }
211
-
212
-
213
- function CircularText($x, $y, $r, $text, $align='top', $fontfamily='', $fontsizePt=0, $fontstyle='', $kerning=120, $fontwidth=100, $divider='') {
214
- if ($fontfamily || $fontstyle || $fontsizePt) $this->mpdf->SetFont($fontfamily,$fontstyle,$fontsizePt);
215
- $kerning/=100;
216
- $fontwidth/=100;
217
- if($kerning==0) $this->mpdf->Error('Please use values unequal to zero for kerning (CircularText)');
218
- if($fontwidth==0) $this->mpdf->Error('Please use values unequal to zero for font width (CircularText)');
219
- $text=str_replace("\r",'',$text);
220
- //circumference
221
- $u=($r*2)*M_PI;
222
- $checking = true;
223
- $autoset = false;
224
- while($checking) {
225
- $t=0;
226
- $w = array();
227
- if ($this->mpdf->usingCoreFont) {
228
- $nb=strlen($text);
229
- for($i=0; $i<$nb; $i++){
230
- $w[$i]=$this->mpdf->GetStringWidth($text[$i]);
231
- $w[$i]*=$kerning*$fontwidth;
232
- $t+=$w[$i];
233
- }
234
- }
235
- else {
236
- $nb=mb_strlen($text, $this->mpdf->mb_enc );
237
- $lastchar = '';
238
- $unicode = $this->mpdf->UTF8StringToArray($text);
239
- for($i=0; $i<$nb; $i++){
240
- $c = mb_substr($text,$i,1,$this->mpdf->mb_enc );
241
- $w[$i]=$this->mpdf->GetStringWidth($c);
242
- $w[$i]*=$kerning*$fontwidth;
243
- $char = $unicode[$i];
244
- if ($this->mpdf->useKerning && $lastchar) {
245
- if (isset($this->mpdf->CurrentFont['kerninfo'][$lastchar][$char])) {
246
- $tk = $this->mpdf->CurrentFont['kerninfo'][$lastchar][$char] * ($this->mpdf->FontSize/ 1000) * $kerning * $fontwidth;
247
- $w[$i] += $tk/2;
248
- $w[$i-1] += $tk/2;
249
- $t+=$tk;
250
- }
251
- }
252
- $lastchar = $char;
253
- $t+=$w[$i];
254
- }
255
- }
256
- if ($fontsizePt>=0 || $autoset) { $checking = false; }
257
- else {
258
- $t+=$this->mpdf->GetStringWidth(' ');
259
- if ($divider)
260
- $t+=$this->mpdf->GetStringWidth(' ');
261
- if ($fontsizePt==-2)
262
- $fontsizePt = $this->mpdf->FontSizePt * 0.5 * $u/$t;
263
- else
264
- $fontsizePt = $this->mpdf->FontSizePt * $u/$t;
265
- $this->mpdf->SetFontSize($fontsizePt);
266
- $autoset = true;
267
- }
268
- }
269
-
270
- //total width of string in degrees
271
- $d=($t/$u)*360;
272
-
273
- $this->mpdf->StartTransform();
274
- // rotate matrix for the first letter to center the text
275
- // (half of total degrees)
276
- if($align=='top'){
277
- $this->mpdf->transformRotate(-$d/2, $x, $y);
278
- }
279
- else{
280
- $this->mpdf->transformRotate($d/2, $x, $y);
281
- }
282
- //run through the string
283
- for($i=0; $i<$nb; $i++){
284
- if($align=='top'){
285
- //rotate matrix half of the width of current letter + half of the width of preceding letter
286
- if($i==0){
287
- $this->mpdf->transformRotate((($w[$i]/2)/$u)*360, $x, $y);
288
- }
289
- else{
290
- $this->mpdf->transformRotate((($w[$i]/2+$w[$i-1]/2)/$u)*360, $x, $y);
291
- }
292
- if($fontwidth!=1){
293
- $this->mpdf->StartTransform();
294
- $this->mpdf->transformScale($fontwidth*100, 100, $x, $y);
295
- }
296
- $this->mpdf->SetXY($x-$w[$i]/2, $y-$r);
297
- }
298
- else{
299
- //rotate matrix half of the width of current letter + half of the width of preceding letter
300
- if($i==0){
301
- $this->mpdf->transformRotate(-(($w[$i]/2)/$u)*360, $x, $y);
302
- }
303
- else{
304
- $this->mpdf->transformRotate(-(($w[$i]/2+$w[$i-1]/2)/$u)*360, $x, $y);
305
- }
306
- if($fontwidth!=1){
307
- $this->mpdf->StartTransform();
308
- $this->mpdf->transformScale($fontwidth*100, 100, $x, $y);
309
- }
310
- $this->mpdf->SetXY($x-$w[$i]/2, $y+$r-($this->mpdf->FontSize));
311
- }
312
- if ($this->mpdf->usingCoreFont) { $c=$text[$i]; }
313
- else { $c = mb_substr($text,$i,1,$this->mpdf->mb_enc ); }
314
- $this->mpdf->Cell(($w[$i]),$this->mpdf->FontSize,$c,0,0,'C'); // mPDF 5.3.53
315
- if($fontwidth!=1){
316
- $this->mpdf->StopTransform();
317
- }
318
- }
319
- $this->mpdf->StopTransform();
320
-
321
- // mPDF 5.5.23
322
- if($align=='top' && $divider!=''){
323
- $wc=$this->mpdf->GetStringWidth($divider);
324
- $wc*=$kerning*$fontwidth;
325
-
326
- $this->mpdf->StartTransform();
327
- $this->mpdf->transformRotate(90, $x, $y);
328
- $this->mpdf->SetXY($x-$wc/2, $y-$r);
329
- $this->mpdf->Cell(($wc),$this->mpdf->FontSize,$divider,0,0,'C');
330
- $this->mpdf->StopTransform();
331
-
332
- $this->mpdf->StartTransform();
333
- $this->mpdf->transformRotate(-90, $x, $y);
334
- $this->mpdf->SetXY($x-$wc/2, $y-$r);
335
- $this->mpdf->Cell(($wc),$this->mpdf->FontSize,$divider,0,0,'C');
336
- $this->mpdf->StopTransform();
337
- }
338
- }
339
-
340
- function Shaded_box( $text,$font='',$fontstyle='B',$szfont='',$width='70%',$style='DF',$radius=2.5,$fill='#FFFFFF',$color='#000000',$pad=2 ) {
341
- // F (shading - no line),S (line, no shading),DF (both)
342
- if (!$font) { $font= $this->mpdf->default_font; }
343
- if (!$szfont) { $szfont = ($this->mpdf->default_font_size * 1.8); }
344
-
345
- $text = ' '.$text.' ';
346
- $this->mpdf->SetFont( $font, $fontstyle, $szfont, false );
347
-
348
- $text = $this->mpdf->purify_utf8_text($text);
349
- if ($this->mpdf->text_input_as_HTML) {
350
- $text = $this->mpdf->all_entities_to_utf8($text);
351
- }
352
- if ($this->mpdf->usingCoreFont) { $text = mb_convert_encoding($text,$this->mpdf->mb_enc,'UTF-8'); }
353
-
354
-
355
- // DIRECTIONALITY
356
- if (preg_match("/([".$this->mpdf->pregRTLchars."])/u", $text)) { $this->mpdf->biDirectional = true; } // *RTL*
357
-
358
- $textvar = 0;
359
- $save_OTLtags = $this->mpdf->OTLtags;
360
- $this->mpdf->OTLtags = array();
361
- if ($this->mpdf->useKerning) {
362
- if ($this->mpdf->CurrentFont['haskernGPOS']) { $this->mpdf->OTLtags['Plus'] .= ' kern'; }
363
- else { $textvar = ($textvar | FC_KERNING); }
364
- }
365
- // Use OTL OpenType Table Layout - GSUB & GPOS
366
- if (isset($this->mpdf->CurrentFont['useOTL']) && $this->mpdf->CurrentFont['useOTL']) {
367
- $text = $this->mpdf->otl->applyOTL($text, $this->mpdf->CurrentFont['useOTL']);
368
- $OTLdata = $this->mpdf->otl->OTLdata;
369
- }
370
- $this->mpdf->OTLtags = $save_OTLtags ;
371
-
372
- $this->mpdf->magic_reverse_dir($text, $this->mpdf->directionality, $OTLdata);
373
-
374
- if (!$width) { $width = $this->mpdf->pgwidth; } else { $width=$this->mpdf->ConvertSize($width,$this->mpdf->pgwidth); }
375
- $midpt = $this->mpdf->lMargin+($this->mpdf->pgwidth/2);
376
- $r1 = $midpt-($width/2); //($this->mpdf->w / 2) - 40;
377
- $r2 = $r1 + $width; //$r1 + 80;
378
- $y1 = $this->mpdf->y;
379
-
380
-
381
- $mid = ($r1 + $r2 ) / 2;
382
- $loop = 0;
383
-
384
- while ( $loop == 0 )
385
- {
386
- $this->mpdf->SetFont( $font, $fontstyle, $szfont, false );
387
- $sz = $this->mpdf->GetStringWidth( $text, true, $OTLdata, $textvar );
388
- if ( ($r1+$sz) > $r2 )
389
- $szfont --;
390
- else
391
- $loop ++;
392
- }
393
- $this->mpdf->SetFont( $font, $fontstyle, $szfont, true, true );
394
-
395
- $y2 = $this->mpdf->FontSize+($pad*2);
396
-
397
- $this->mpdf->SetLineWidth(0.1);
398
- $fc = $this->mpdf->ConvertColor($fill);
399
- $tc = $this->mpdf->ConvertColor($color);
400
- $this->mpdf->SetFColor($fc);
401
- $this->mpdf->SetTColor($tc);
402
- $this->mpdf->RoundedRect($r1, $y1, ($r2 - $r1), $y2, $radius, $style);
403
- $this->mpdf->SetX( $r1);
404
- $this->mpdf->Cell($r2-$r1, $y2, $text, 0, 1, "C",0,'',0,0,0,'M', 0, false, $OTLdata, $textvar );
405
- $this->mpdf->SetY($y1+$y2+2); // +2 = mm margin below shaded box
406
- $this->mpdf->Reset();
407
- }
408
-
409
-
410
- }
411
-
412
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/mpdf/classes/gif.php DELETED
@@ -1,700 +0,0 @@
1
- <?php
2
- ///////////////////////////////////////////////////////////////////////////////////////////////////
3
- // 2009-12-22 Adapted for mPDF 4.2
4
- ///////////////////////////////////////////////////////////////////////////////////////////////////
5
- // GIF Util - (C) 2003 Yamasoft (S/C)
6
- // http://www.yamasoft.com
7
- // All Rights Reserved
8
- // This file can be freely copied, distributed, modified, updated by anyone under the only
9
- // condition to leave the original address (Yamasoft, http://www.yamasoft.com) and this header.
10
- ///////////////////////////////////////////////////////////////////////////////////////////////////
11
- ///////////////////////////////////////////////////////////////////////////////////////////////////
12
- // 2009-12-22 Adapted INB
13
- // Functions calling functionname($x, $len = 0) were not working on PHP5.1.5 as pass by reference
14
- // All edited to $len = 0; then call function.
15
- ///////////////////////////////////////////////////////////////////////////////////////////////////
16
-
17
-
18
- ///////////////////////////////////////////////////////////////////////////////////////////////////
19
-
20
- class CGIFLZW
21
- {
22
- var $MAX_LZW_BITS;
23
- var $Fresh, $CodeSize, $SetCodeSize, $MaxCode, $MaxCodeSize, $FirstCode, $OldCode;
24
- var $ClearCode, $EndCode, $Next, $Vals, $Stack, $sp, $Buf, $CurBit, $LastBit, $Done, $LastByte;
25
-
26
- ///////////////////////////////////////////////////////////////////////////
27
-
28
- // CONSTRUCTOR
29
- function CGIFLZW()
30
- {
31
- $this->MAX_LZW_BITS = 12;
32
- unSet($this->Next);
33
- unSet($this->Vals);
34
- unSet($this->Stack);
35
- unSet($this->Buf);
36
-
37
- $this->Next = range(0, (1 << $this->MAX_LZW_BITS) - 1);
38
- $this->Vals = range(0, (1 << $this->MAX_LZW_BITS) - 1);
39
- $this->Stack = range(0, (1 << ($this->MAX_LZW_BITS + 1)) - 1);
40
- $this->Buf = range(0, 279);
41
- }
42
-
43
- ///////////////////////////////////////////////////////////////////////////
44
-
45
- function deCompress($data, &$datLen)
46
- {
47
- $stLen = strlen($data);
48
- $datLen = 0;
49
- $ret = "";
50
- $dp = 0; // data pointer
51
-
52
- // INITIALIZATION
53
- $this->LZWCommandInit($data, $dp);
54
-
55
- while(($iIndex = $this->LZWCommand($data, $dp)) >= 0) {
56
- $ret .= chr($iIndex);
57
- }
58
-
59
- $datLen = $dp;
60
-
61
- if($iIndex != -2) {
62
- return false;
63
- }
64
-
65
- return $ret;
66
- }
67
-
68
- ///////////////////////////////////////////////////////////////////////////
69
- function LZWCommandInit(&$data, &$dp)
70
- {
71
- $this->SetCodeSize = ord($data[0]);
72
- $dp += 1;
73
-
74
- $this->CodeSize = $this->SetCodeSize + 1;
75
- $this->ClearCode = 1 << $this->SetCodeSize;
76
- $this->EndCode = $this->ClearCode + 1;
77
- $this->MaxCode = $this->ClearCode + 2;
78
- $this->MaxCodeSize = $this->ClearCode << 1;
79
-
80
- $this->GetCodeInit($data, $dp);
81
-
82
- $this->Fresh = 1;
83
- for($i = 0; $i < $this->ClearCode; $i++) {
84
- $this->Next[$i] = 0;
85
- $this->Vals[$i] = $i;
86
- }
87
-
88
- for(; $i < (1 << $this->MAX_LZW_BITS); $i++) {
89
- $this->Next[$i] = 0;
90
- $this->Vals[$i] = 0;
91
- }
92
-
93
- $this->sp = 0;
94
- return 1;
95
- }
96
-
97
- function LZWCommand(&$data, &$dp)
98
- {
99
- if($this->Fresh) {
100
- $this->Fresh = 0;
101
- do {
102
- $this->FirstCode = $this->GetCode($data, $dp);
103
- $this->OldCode = $this->FirstCode;
104
- }
105
- while($this->FirstCode == $this->ClearCode);
106
-
107
- return $this->FirstCode;
108
- }
109
-
110
- if($this->sp > 0) {
111
- $this->sp--;
112
- return $this->Stack[$this->sp];
113
- }
114
-
115
- while(($Code = $this->GetCode($data, $dp)) >= 0) {
116
- if($Code == $this->ClearCode) {
117
- for($i = 0; $i < $this->ClearCode; $i++) {
118
- $this->Next[$i] = 0;
119
- $this->Vals[$i] = $i;
120
- }
121
-
122
- for(; $i < (1 << $this->MAX_LZW_BITS); $i++) {
123
- $this->Next[$i] = 0;
124
- $this->Vals[$i] = 0;
125
- }
126
-
127
- $this->CodeSize = $this->SetCodeSize + 1;
128
- $this->MaxCodeSize = $this->ClearCode << 1;
129
- $this->MaxCode = $this->ClearCode + 2;
130
- $this->sp = 0;
131
- $this->FirstCode = $this->GetCode($data, $dp);
132
- $this->OldCode = $this->FirstCode;
133
-
134
- return $this->FirstCode;
135
- }
136
-
137
- if($Code == $this->EndCode) {
138
- return -2;
139
- }
140
-
141
- $InCode = $Code;
142
- if($Code >= $this->MaxCode) {
143
- $this->Stack[$this->sp++] = $this->FirstCode;
144
- $Code = $this->OldCode;
145
- }
146
-
147
- while($Code >= $this->ClearCode) {
148
- $this->Stack[$this->sp++] = $this->Vals[$Code];
149
-
150
- if($Code == $this->Next[$Code]) // Circular table entry, big GIF Error!
151
- return -1;
152
-
153
- $Code = $this->Next[$Code];
154
- }
155
-
156
- $this->FirstCode = $this->Vals[$Code];
157
- $this->Stack[$this->sp++] = $this->FirstCode;
158
-
159
- if(($Code = $this->MaxCode) < (1 << $this->MAX_LZW_BITS)) {
160
- $this->Next[$Code] = $this->OldCode;
161
- $this->Vals[$Code] = $this->FirstCode;
162
- $this->MaxCode++;
163
-
164
- if(($this->MaxCode >= $this->MaxCodeSize) && ($this->MaxCodeSize < (1 << $this->MAX_LZW_BITS))) {
165
- $this->MaxCodeSize *= 2;
166
- $this->CodeSize++;
167
- }
168
- }
169
-
170
- $this->OldCode = $InCode;
171
- if($this->sp > 0) {
172
- $this->sp--;
173
- return $this->Stack[$this->sp];
174
- }
175
- }
176
-
177
- return $Code;
178
- }
179
-
180
- ///////////////////////////////////////////////////////////////////////////
181
-
182
- function GetCodeInit(&$data, &$dp)
183
- {
184
- $this->CurBit = 0;
185
- $this->LastBit = 0;
186
- $this->Done = 0;
187
- $this->LastByte = 2;
188
- return 1;
189
- }
190
-
191
- function GetCode(&$data, &$dp)
192
- {
193
- if(($this->CurBit + $this->CodeSize) >= $this->LastBit) {
194
- if($this->Done) {
195
- if($this->CurBit >= $this->LastBit) {
196
- // Ran off the end of my bits
197
- return 0;
198
- }
199
- return -1;
200
- }
201
-
202
- $this->Buf[0] = $this->Buf[$this->LastByte - 2];
203
- $this->Buf[1] = $this->Buf[$this->LastByte - 1];
204
-
205
- $Count = ord($data[$dp]);
206
- $dp += 1;
207
-
208
- if($Count) {
209
- for($i = 0; $i < $Count; $i++) {
210
- $this->Buf[2 + $i] = ord($data[$dp+$i]);
211
- }
212
- $dp += $Count;
213
- }
214
- else {
215
- $this->Done = 1;
216
- }
217
-
218
- $this->LastByte = 2 + $Count;
219
- $this->CurBit = ($this->CurBit - $this->LastBit) + 16;
220
- $this->LastBit = (2 + $Count) << 3;
221
- }
222
-
223
- $iRet = 0;
224
- for($i = $this->CurBit, $j = 0; $j < $this->CodeSize; $i++, $j++) {
225
- $iRet |= (($this->Buf[intval($i / 8)] & (1 << ($i % 8))) != 0) << $j;
226
- }
227
-
228
- $this->CurBit += $this->CodeSize;
229
- return $iRet;
230
- }
231
- }
232
-
233
- ///////////////////////////////////////////////////////////////////////////////////////////////////
234
-
235
- class CGIFCOLORTABLE
236
- {
237
- var $m_nColors;
238
- var $m_arColors;
239
-
240
- ///////////////////////////////////////////////////////////////////////////
241
-
242
- // CONSTRUCTOR
243
- function CGIFCOLORTABLE()
244
- {
245
- unSet($this->m_nColors);
246
- unSet($this->m_arColors);
247
- }
248
-
249
- ///////////////////////////////////////////////////////////////////////////
250
-
251
- function load($lpData, $num)
252
- {
253
- $this->m_nColors = 0;
254
- $this->m_arColors = array();
255
-
256
- for($i = 0; $i < $num; $i++) {
257
- $rgb = substr($lpData, $i * 3, 3);
258
- if(strlen($rgb) < 3) {
259
- return false;
260
- }
261
-
262
- $this->m_arColors[] = (ord($rgb[2]) << 16) + (ord($rgb[1]) << 8) + ord($rgb[0]);
263
- $this->m_nColors++;
264
- }
265
-
266
- return true;
267
- }
268
-
269
- ///////////////////////////////////////////////////////////////////////////
270
-
271
- function toString()
272
- {
273
- $ret = "";
274
-
275
- for($i = 0; $i < $this->m_nColors; $i++) {
276
- $ret .=
277
- chr(($this->m_arColors[$i] & 0x000000FF)) . // R
278
- chr(($this->m_arColors[$i] & 0x0000FF00) >> 8) . // G
279
- chr(($this->m_arColors[$i] & 0x00FF0000) >> 16); // B
280
- }
281
-
282
- return $ret;
283
- }
284
-
285
-
286
- ///////////////////////////////////////////////////////////////////////////
287
-
288
- function colorIndex($rgb)
289
- {
290
- $rgb = intval($rgb) & 0xFFFFFF;
291
- $r1 = ($rgb & 0x0000FF);
292
- $g1 = ($rgb & 0x00FF00) >> 8;
293
- $b1 = ($rgb & 0xFF0000) >> 16;
294
- $idx = -1;
295
-
296
- for($i = 0; $i < $this->m_nColors; $i++) {
297
- $r2 = ($this->m_arColors[$i] & 0x000000FF);
298
- $g2 = ($this->m_arColors[$i] & 0x0000FF00) >> 8;
299
- $b2 = ($this->m_arColors[$i] & 0x00FF0000) >> 16;
300
- $d = abs($r2 - $r1) + abs($g2 - $g1) + abs($b2 - $b1);
301
-
302
- if(($idx == -1) || ($d < $dif)) {
303
- $idx = $i;
304
- $dif = $d;
305
- }
306
- }
307
-
308
- return $idx;
309
- }
310
- }
311
-
312
- ///////////////////////////////////////////////////////////////////////////////////////////////////
313
-
314
- class CGIFFILEHEADER
315
- {
316
- var $m_lpVer;
317
- var $m_nWidth;
318
- var $m_nHeight;
319
- var $m_bGlobalClr;
320
- var $m_nColorRes;
321
- var $m_bSorted;
322
- var $m_nTableSize;
323
- var $m_nBgColor;
324
- var $m_nPixelRatio;
325
- var $m_colorTable;
326
-
327
- ///////////////////////////////////////////////////////////////////////////
328
-
329
- // CONSTRUCTOR
330
- function CGIFFILEHEADER()
331
- {
332
- unSet($this->m_lpVer);
333
- unSet($this->m_nWidth);
334
- unSet($this->m_nHeight);
335
- unSet($this->m_bGlobalClr);
336
- unSet($this->m_nColorRes);
337
- unSet($this->m_bSorted);
338
- unSet($this->m_nTableSize);
339
- unSet($this->m_nBgColor);
340
- unSet($this->m_nPixelRatio);
341
- unSet($this->m_colorTable);
342
- }
343
-
344
- ///////////////////////////////////////////////////////////////////////////
345
-
346
- function load($lpData, &$hdrLen)
347
- {
348
- $hdrLen = 0;
349
-
350
- $this->m_lpVer = substr($lpData, 0, 6);
351
- if(($this->m_lpVer <> "GIF87a") && ($this->m_lpVer <> "GIF89a")) {
352
- return false;
353
- }
354
-
355
- $this->m_nWidth = $this->w2i(substr($lpData, 6, 2));
356
- $this->m_nHeight = $this->w2i(substr($lpData, 8, 2));
357
- if(!$this->m_nWidth || !$this->m_nHeight) {
358
- return false;
359
- }
360
-
361
- $b = ord(substr($lpData, 10, 1));
362
- $this->m_bGlobalClr = ($b & 0x80) ? true : false;
363
- $this->m_nColorRes = ($b & 0x70) >> 4;
364
- $this->m_bSorted = ($b & 0x08) ? true : false;
365
- $this->m_nTableSize = 2 << ($b & 0x07);
366
- $this->m_nBgColor = ord(substr($lpData, 11, 1));
367
- $this->m_nPixelRatio = ord(substr($lpData, 12, 1));
368
- $hdrLen = 13;
369
-
370
- if($this->m_bGlobalClr) {
371
- $this->m_colorTable = new CGIFCOLORTABLE();
372
- if(!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) {
373
- return false;
374
- }
375
- $hdrLen += 3 * $this->m_nTableSize;
376
- }
377
-
378
- return true;
379
- }
380
-
381
- ///////////////////////////////////////////////////////////////////////////
382
-
383
- function w2i($str)
384
- {
385
- return ord(substr($str, 0, 1)) + (ord(substr($str, 1, 1)) << 8);
386
- }
387
- }
388
-
389
- ///////////////////////////////////////////////////////////////////////////////////////////////////
390
-
391
- class CGIFIMAGEHEADER
392
- {
393
- var $m_nLeft;
394
- var $m_nTop;
395
- var $m_nWidth;
396
- var $m_nHeight;
397
- var $m_bLocalClr;
398
- var $m_bInterlace;
399
- var $m_bSorted;
400
- var $m_nTableSize;
401
- var $m_colorTable;
402
-
403
- ///////////////////////////////////////////////////////////////////////////
404
-
405
- // CONSTRUCTOR
406
- function CGIFIMAGEHEADER()
407
- {
408
- unSet($this->m_nLeft);
409
- unSet($this->m_nTop);
410
- unSet($this->m_nWidth);
411
- unSet($this->m_nHeight);
412
- unSet($this->m_bLocalClr);
413
- unSet($this->m_bInterlace);
414
- unSet($this->m_bSorted);
415
- unSet($this->m_nTableSize);
416
- unSet($this->m_colorTable);
417
- }
418
-
419
- ///////////////////////////////////////////////////////////////////////////
420
-
421
- function load($lpData, &$hdrLen)
422
- {
423
- $hdrLen = 0;
424
-
425
- $this->m_nLeft = $this->w2i(substr($lpData, 0, 2));
426
- $this->m_nTop = $this->w2i(substr($lpData, 2, 2));
427
- $this->m_nWidth = $this->w2i(substr($lpData, 4, 2));
428
- $this->m_nHeight = $this->w2i(substr($lpData, 6, 2));
429
-
430
- if(!$this->m_nWidth || !$this->m_nHeight) {
431
- return false;
432
- }
433
-
434
- $b = ord($lpData{8});
435
- $this->m_bLocalClr = ($b & 0x80) ? true : false;
436
- $this->m_bInterlace = ($b & 0x40) ? true : false;
437
- $this->m_bSorted = ($b & 0x20) ? true : false;
438
- $this->m_nTableSize = 2 << ($b & 0x07);
439
- $hdrLen = 9;
440
-
441
- if($this->m_bLocalClr) {
442
- $this->m_colorTable = new CGIFCOLORTABLE();
443
- if(!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) {
444
- return false;
445
- }
446
- $hdrLen += 3 * $this->m_nTableSize;
447
- }
448
-
449
- return true;
450
- }
451
-
452
- ///////////////////////////////////////////////////////////////////////////
453
-
454
- function w2i($str)
455
- {
456
- return ord(substr($str, 0, 1)) + (ord(substr($str, 1, 1)) << 8);
457
- }
458
- }
459
-
460
- ///////////////////////////////////////////////////////////////////////////////////////////////////
461
-
462
- class CGIFIMAGE
463
- {
464
- var $m_disp;
465
- var $m_bUser;
466
- var $m_bTrans;
467
- var $m_nDelay;
468
- var $m_nTrans;
469
- var $m_lpComm;
470
- var $m_gih;
471
- var $m_data;
472
- var $m_lzw;
473
-
474
- ///////////////////////////////////////////////////////////////////////////
475
-
476
- function CGIFIMAGE()
477
- {
478
- unSet($this->m_disp);
479
- unSet($this->m_bUser);
480
- unSet($this->m_bTrans);
481
- unSet($this->m_nDelay);
482
- unSet($this->m_nTrans);
483
- unSet($this->m_lpComm);
484
- unSet($this->m_data);
485
- $this->m_gih = new CGIFIMAGEHEADER();
486
- $this->m_lzw = new CGIFLZW();
487
- }
488
-
489
- ///////////////////////////////////////////////////////////////////////////
490
-
491
- function load($data, &$datLen)
492
- {
493
- $datLen = 0;
494
-
495
- while(true) {
496
- $b = ord($data[0]);
497
- $data = substr($data, 1);
498
- $datLen++;
499
-
500
- switch($b) {
501
- case 0x21: // Extension
502
- $len = 0;
503
- if(!$this->skipExt($data, $len)) {
504
- return false;
505
- }
506
- $datLen += $len;
507
- break;
508
-
509
- case 0x2C: // Image
510
- // LOAD HEADER & COLOR TABLE
511
- $len = 0;
512
- if(!$this->m_gih->load($data, $len)) {
513
- return false;
514
- }
515
- $data = substr($data, $len);
516
- $datLen += $len;
517
-
518
- // ALLOC BUFFER
519
- $len = 0;
520
-
521
- if(!($this->m_data = $this->m_lzw->deCompress($data, $len))) {
522
- return false;
523
- }
524
-
525
- $data = substr($data, $len);
526
- $datLen += $len;
527
-
528
- if($this->m_gih->m_bInterlace) {
529
- $this->deInterlace();
530
- }
531
-
532
- return true;
533
-
534
- case 0x3B: // EOF
535
- default:
536
- return false;
537
- }
538
- }
539
- return false;
540
- }
541
-
542
- ///////////////////////////////////////////////////////////////////////////
543
-
544
- function skipExt(&$data, &$extLen)
545
- {
546
- $extLen = 0;
547
-
548
- $b = ord($data[0]);
549
- $data = substr($data, 1);
550
- $extLen++;
551
-
552
- switch($b) {
553
- case 0xF9: // Graphic Control
554
- $b = ord($data[1]);
555
- $this->m_disp = ($b & 0x1C) >> 2;
556
- $this->m_bUser = ($b & 0x02) ? true : false;
557
- $this->m_bTrans = ($b & 0x01) ? true : false;
558
- $this->m_nDelay = $this->w2i(substr($data, 2, 2));
559
- $this->m_nTrans = ord($data[4]);
560
- break;
561
-
562
- case 0xFE: // Comment
563
- $this->m_lpComm = substr($data, 1, ord($data[0]));
564
- break;
565
-
566
- case 0x01: // Plain text
567
- break;
568
-
569
- case 0xFF: // Application
570
- break;
571
- }
572
-
573
- // SKIP DEFAULT AS DEFS MAY CHANGE
574
- $b = ord($data[0]);
575
- $data = substr($data, 1);
576
- $extLen++;
577
- while($b > 0) {
578
- $data = substr($data, $b);
579
- $extLen += $b;
580
- $b = ord($data[0]);
581
- $data = substr($data, 1);
582
- $extLen++;
583
- }
584
- return true;
585
- }
586
-
587
- ///////////////////////////////////////////////////////////////////////////
588
-
589
- function w2i($str)
590
- {
591
- return ord(substr($str, 0, 1)) + (ord(substr($str, 1, 1)) << 8);
592
- }
593
-
594
- ///////////////////////////////////////////////////////////////////////////
595
-
596
- function deInterlace()
597
- {
598
- $data = $this->m_data;
599
-
600
- for($i = 0; $i < 4; $i++) {
601
- switch($i) {
602
- case 0:
603
- $s = 8;
604
- $y = 0;
605
- break;
606
-
607
- case 1:
608
- $s = 8;
609
- $y = 4;
610
- break;
611
-
612
- case 2:
613
- $s = 4;
614
- $y = 2;
615
- break;
616
-
617
- case 3:
618
- $s = 2;
619
- $y = 1;
620
- break;
621
- }
622
-
623
- for(; $y < $this->m_gih->m_nHeight; $y += $s) {
624
- $lne = substr($this->m_data, 0, $this->m_gih->m_nWidth);
625
- $this->m_data = substr($this->m_data, $this->m_gih->m_nWidth);
626
-
627
- $data =
628
- substr($data, 0, $y * $this->m_gih->m_nWidth) .
629
- $lne .
630
- substr($data, ($y + 1) * $this->m_gih->m_nWidth);
631
- }
632
- }
633
-
634
- $this->m_data = $data;
635
- }
636
- }
637
-
638
- ///////////////////////////////////////////////////////////////////////////////////////////////////
639
-
640
- class CGIF
641
- {
642
- var $m_gfh;
643
- var $m_lpData;
644
- var $m_img;
645
- var $m_bLoaded;
646
-
647
- ///////////////////////////////////////////////////////////////////////////
648
-
649
- // CONSTRUCTOR
650
- function CGIF()
651
- {
652
- $this->m_gfh = new CGIFFILEHEADER();
653
- $this->m_img = new CGIFIMAGE();
654
- $this->m_lpData = "";
655
- $this->m_bLoaded = false;
656
- }
657
-
658
- ///////////////////////////////////////////////////////////////////////////
659
- function ClearData() {
660
- $this->m_lpData = '';
661
- unSet($this->m_img->m_data);
662
- unSet($this->m_img->m_lzw->Next);
663
- unSet($this->m_img->m_lzw->Vals);
664
- unSet($this->m_img->m_lzw->Stack);
665
- unSet($this->m_img->m_lzw->Buf);
666
- }
667
-
668
- function loadFile(&$data, $iIndex)
669
- {
670
- if($iIndex < 0) {
671
- return false;
672
- }
673
- $this->m_lpData = $data;
674
-
675
- // GET FILE HEADER
676
- $len = 0;
677
- if(!$this->m_gfh->load($this->m_lpData, $len)) {
678
- return false;
679
- }
680
-
681
- $this->m_lpData = substr($this->m_lpData, $len);
682
-
683
- do {
684
- $imgLen = 0;
685
- if(!$this->m_img->load($this->m_lpData, $imgLen)) {
686
- return false;
687
- }
688
- $this->m_lpData = substr($this->m_lpData, $imgLen);
689
- }
690
- while($iIndex-- > 0);
691
-
692
- $this->m_bLoaded = true;
693
- return true;
694
- }
695
-
696
- }
697
-
698
- ///////////////////////////////////////////////////////////////////////////////////////////////////
699
-
700
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/mpdf/classes/grad.php DELETED
@@ -1,724 +0,0 @@
1
- <?php
2
-
3
- class grad {
4
-
5
- var $mpdf = null;
6
-
7
- function grad(&$mpdf) {
8
- $this->mpdf = $mpdf;
9
- }
10
-
11
- // mPDF 5.3.A1
12
- function CoonsPatchMesh($x, $y, $w, $h, $patch_array=array(), $x_min=0, $x_max=1, $y_min=0, $y_max=1, $colspace='RGB', $return=false){
13
- $s=' q ';
14
- $s.=sprintf(' %.3F %.3F %.3F %.3F re W n ', $x*_MPDFK, ($this->mpdf->h-$y)*_MPDFK, $w*_MPDFK, -$h*_MPDFK);
15
- $s.=sprintf(' %.3F 0 0 %.3F %.3F %.3F cm ', $w*_MPDFK, $h*_MPDFK, $x*_MPDFK, ($this->mpdf->h-($y+$h))*_MPDFK);
16
- $n = count($this->mpdf->gradients)+1;
17
- $this->mpdf->gradients[$n]['type'] = 6; //coons patch mesh
18
- $this->mpdf->gradients[$n]['colorspace'] = $colspace; //coons patch mesh
19
- $bpcd=65535; //16 BitsPerCoordinate
20
- $trans = false;
21
- $this->mpdf->gradients[$n]['stream']='';
22
- for($i=0;$i<count($patch_array);$i++){
23
- $this->mpdf->gradients[$n]['stream'].=chr($patch_array[$i]['f']); //start with the edge flag as 8 bit
24
- for($j=0;$j<count($patch_array[$i]['points']);$j++){
25
- //each point as 16 bit
26
- if (($j % 2) == 1) { // Y coordinate (adjusted as input is From top left)
27
- $patch_array[$i]['points'][$j]=(($patch_array[$i]['points'][$j]-$y_min)/($y_max-$y_min))*$bpcd;
28
- $patch_array[$i]['points'][$j]=$bpcd-$patch_array[$i]['points'][$j];
29
- }
30
- else {
31
- $patch_array[$i]['points'][$j]=(($patch_array[$i]['points'][$j]-$x_min)/($x_max-$x_min))*$bpcd;
32
- }
33
- if($patch_array[$i]['points'][$j]<0) $patch_array[$i]['points'][$j]=0;
34
- if($patch_array[$i]['points'][$j]>$bpcd) $patch_array[$i]['points'][$j]=$bpcd;
35
- $this->mpdf->gradients[$n]['stream'].=chr(floor($patch_array[$i]['points'][$j]/256));
36
- $this->mpdf->gradients[$n]['stream'].=chr(floor($patch_array[$i]['points'][$j]%256));
37
- }
38
- for($j=0;$j<count($patch_array[$i]['colors']);$j++){
39
- //each color component as 8 bit
40
- if ($colspace=='RGB') {
41
- $this->mpdf->gradients[$n]['stream'].=($patch_array[$i]['colors'][$j][1]);
42
- $this->mpdf->gradients[$n]['stream'].=($patch_array[$i]['colors'][$j][2]);
43
- $this->mpdf->gradients[$n]['stream'].=($patch_array[$i]['colors'][$j][3]);
44
- if (isset($patch_array[$i]['colors'][$j][4]) && ord($patch_array[$i]['colors'][$j][4])<100) { $trans = true; }
45
- }
46
- else if ($colspace=='CMYK') {
47
- $this->mpdf->gradients[$n]['stream'].=chr(ord($patch_array[$i]['colors'][$j][1])*2.55);
48
- $this->mpdf->gradients[$n]['stream'].=chr(ord($patch_array[$i]['colors'][$j][2])*2.55);
49
- $this->mpdf->gradients[$n]['stream'].=chr(ord($patch_array[$i]['colors'][$j][3])*2.55);
50
- $this->mpdf->gradients[$n]['stream'].=chr(ord($patch_array[$i]['colors'][$j][4])*2.55);
51
- if (isset($patch_array[$i]['colors'][$j][5]) && ord($patch_array[$i]['colors'][$j][5])<100) { $trans = true; }
52
- }
53
- else if ($colspace=='Gray') {
54
- $this->mpdf->gradients[$n]['stream'].=($patch_array[$i]['colors'][$j][1]);
55
- if ($patch_array[$i]['colors'][$j][2]==1) { $trans = true; } // transparency converted from rgba or cmyka()
56
- }
57
- }
58
- }
59
- // TRANSPARENCY
60
- if ($trans) {
61
- $this->mpdf->gradients[$n]['stream_trans']='';
62
- for($i=0;$i<count($patch_array);$i++){
63
- $this->mpdf->gradients[$n]['stream_trans'].=chr($patch_array[$i]['f']);
64
- for($j=0;$j<count($patch_array[$i]['points']);$j++){
65
- //each point as 16 bit
66
- $this->mpdf->gradients[$n]['stream_trans'].=chr(floor($patch_array[$i]['points'][$j]/256));
67
- $this->mpdf->gradients[$n]['stream_trans'].=chr(floor($patch_array[$i]['points'][$j]%256));
68
- }
69
- for($j=0;$j<count($patch_array[$i]['colors']);$j++){
70
- //each color component as 8 bit // OPACITY
71
- if ($colspace=='RGB') {
72
- $this->mpdf->gradients[$n]['stream_trans'].=chr(intval(ord($patch_array[$i]['colors'][$j][4])*2.55));
73
- }
74
- else if ($colspace=='CMYK') {
75
- $this->mpdf->gradients[$n]['stream_trans'].=chr(intval(ord($patch_array[$i]['colors'][$j][5])*2.55));
76
- }
77
- else if ($colspace=='Gray') {
78
- $this->mpdf->gradients[$n]['stream_trans'].=chr(intval(ord($patch_array[$i]['colors'][$j][3])*2.55));
79
- }
80
- }
81
- }
82
- $this->mpdf->gradients[$n]['trans'] = true;
83
- $s .= ' /TGS'.$n.' gs ';
84
- }
85
- //paint the gradient
86
- $s .= '/Sh'.$n.' sh'."\n";
87
- //restore previous Graphic State
88
- $s .= 'Q'."\n";
89
- if ($return) { return $s; }
90
- else { $this->mpdf->_out($s); }
91
- }
92
-
93
-
94
- // type = linear:2; radial: 3;
95
- // Linear: $coords - array of the form (x1, y1, x2, y2) which defines the gradient vector (see linear_gradient_coords.jpg).
96
- // The default value is from left to right (x1=0, y1=0, x2=1, y2=0).
97
- // Radial: $coords - array of the form (fx, fy, cx, cy, r) where (fx, fy) is the starting point of the gradient with color1,
98
- // (cx, cy) is the center of the circle with color2, and r is the radius of the circle (see radial_gradient_coords.jpg).
99
- // (fx, fy) should be inside the circle, otherwise some areas will not be defined
100
- // $col = array(R,G,B/255); or array(G/255); or array(C,M,Y,K/100)
101
- // $stops = array('col'=>$col [, 'opacity'=>0-1] [, 'offset'=>0-1])
102
- function Gradient($x, $y, $w, $h, $type, $stops=array(), $colorspace='RGB', $coords='', $extend='', $return=false, $is_mask=false) {
103
- if (strtoupper(substr($type,0,1)) == 'L') { $type = 2; } // linear
104
- else if (strtoupper(substr($type,0,1)) == 'R') { $type = 3; } // radial
105
- if ($colorspace != 'CMYK' && $colorspace != 'Gray') {
106
- $colorspace = 'RGB';
107
- }
108
- $bboxw = $w;
109
- $bboxh = $h;
110
- $usex = $x;
111
- $usey = $y;
112
- $usew = $bboxw;
113
- $useh = $bboxh;
114
-
115
- if ($type < 1) { $type = 2; }
116
- if ($coords[0]!==false && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$coords[0],$m)) {
117
- $tmp = $this->mpdf->ConvertSize($m[1],$this->mpdf->w,$this->mpdf->FontSize,false);
118
- if ($tmp) { $coords[0] = $tmp/$w; }
119
- }
120
- if ($coords[1]!==false && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$coords[1],$m)) {
121
- $tmp = $this->mpdf->ConvertSize($m[1],$this->mpdf->w,$this->mpdf->FontSize,false);
122
- if ($tmp) { $coords[1] = 1-($tmp/$h); }
123
- }
124
- // LINEAR
125
- if ($type == 2) {
126
- $angle = (isset($coords[4]) ? $coords[4] : false);
127
- $repeat = (isset($coords[5]) ? $coords[5] : false);
128
- // ALL POINTS SET (default for custom mPDF linear gradient) - no -moz
129
- if ($coords[0]!==false && $coords[1]!==false && $coords[2]!==false && $coords[3]!==false) {
130
- // do nothing - coords used as they are
131
- }
132
-
133
- // If both a <point> and <angle> are defined, the gradient axis starts from the point and runs along the angle. The end point is
134
- // defined as before - in this case start points may not be in corners, and axis may not correctly fall in the right quadrant.
135
- // NO end points (Angle defined & Start points)
136
- else if ($angle!==false && $coords[0]!==false && $coords[1]!==false && $coords[2]===false && $coords[3]===false) {
137
- if ($angle==0 || $angle==360) { $coords[3]=$coords[1]; if ($coords[0]==1) $coords[2]=2; else $coords[2]=1; }
138
- else if ($angle==90) { $coords[2]=$coords[0]; $coords[3]=1; if ($coords[1]==1) $coords[3]=2; else $coords[3]=1; }
139
- else if ($angle==180) { if ($coords[4]==0) $coords[2]=-1; else $coords[2]=0; $coords[3]=$coords[1]; }
140
- else if ($angle==270) { $coords[2]=$coords[0]; if ($coords[1]==0) $coords[3]=-1; else $coords[3]=0; }
141
- else {
142
- $endx=1; $endy=1;
143
- if ($angle <=90) {
144
- if ($angle <=45) { $endy=tan(deg2rad($angle)); }
145
- else { $endx=tan(deg2rad(90-$angle)); }
146
- $b = atan2(($endy*$bboxh), ($endx*$bboxw));
147
- $ny = 1 - $coords[1] - (tan($b) * (1-$coords[0]));
148
- $tx = sin($b) * cos($b) * $ny;
149
- $ty = cos($b) * cos($b) * $ny;
150
- $coords[2] = 1+$tx; $coords[3] = 1-$ty;
151
- }
152
- else if ($angle <=180) {
153
- if ($angle <=135) { $endx=tan(deg2rad($angle-90)); }
154
- else { $endy=tan(deg2rad(180-$angle)); }
155
- $b = atan2(($endy*$bboxh), ($endx*$bboxw));
156
- $ny = 1 - $coords[1] - (tan($b) * ($coords[0]));
157
- $tx = sin($b) * cos($b) * $ny;
158
- $ty = cos($b) * cos($b) * $ny;
159
- $coords[2] = -$tx; $coords[3] = 1-$ty;
160
- }
161
- else if ($angle <=270) {
162
- if ($angle <=225) { $endy=tan(deg2rad($angle-180)); }
163
- else { $endx=tan(deg2rad(270-$angle)); }
164
- $b = atan2(($endy*$bboxh), ($endx*$bboxw));
165
- $ny = $coords[1] - (tan($b) * ($coords[0]));
166
- $tx = sin($b) * cos($b) * $ny;
167
- $ty = cos($b) * cos($b) * $ny;
168
- $coords[2] = -$tx; $coords[3] = $ty;
169
- }
170
- else {
171
- if ($angle <=315) { $endx=tan(deg2rad($angle-270)); }
172
- else { $endy=tan(deg2rad(360-$angle)); }
173
- $b = atan2(($endy*$bboxh), ($endx*$bboxw));
174
- $ny = $coords[1] - (tan($b) * (1-$coords[0]));
175
- $tx = sin($b) * cos($b) * $ny;
176
- $ty = cos($b) * cos($b) * $ny;
177
- $coords[2] = 1+$tx; $coords[3] = $ty;
178
-
179
- }
180
- }
181
- }
182
-
183
- // -moz If the first parameter is only an <angle>, the gradient axis starts from the box's corner that would ensure the
184
- // axis goes through the box. The axis runs along the specified angle. The end point of the axis is defined such that the
185
- // farthest corner of the box from the starting point is perpendicular to the gradient axis at that point.
186
- // NO end points or Start points (Angle defined)
187
- else if ($angle!==false && $coords[0]===false && $coords[1]===false) {
188
- if ($angle==0 || $angle==360) { $coords[0]=0; $coords[1]=0; $coords[2]=1; $coords[3]=0; }
189
- else if ($angle==90) { $coords[0]=0; $coords[1]=0; $coords[2]=0; $coords[3]=1; }
190
- else if ($angle==180) { $coords[0]=1; $coords[1]=0; $coords[2]=0; $coords[3]=0; }
191
- else if ($angle==270) { $coords[0]=0; $coords[1]=1; $coords[2]=0; $coords[3]=0; }
192
- else {
193
- if ($angle <=90) {
194
- $coords[0]=0; $coords[1]=0;
195
- if ($angle <=45) { $endx=1; $endy=tan(deg2rad($angle)); }
196
- else { $endx=tan(deg2rad(90-$angle)); $endy=1; }
197
- }
198
- else if ($angle <=180) {
199
- $coords[0]=1; $coords[1]=0;
200
- if ($angle <=135) { $endx=tan(deg2rad($angle-90)); $endy=1; }
201
- else { $endx=1; $endy=tan(deg2rad(180-$angle)); }
202
- }
203
- else if ($angle <=270) {
204
- $coords[0]=1; $coords[1]=1;
205
- if ($angle <=225) { $endx=1; $endy=tan(deg2rad($angle-180)); }
206
- else { $endx=tan(deg2rad(270-$angle)); $endy=1; }
207
- }
208
- else {
209
- $coords[0]=0; $coords[1]=1;
210
- if ($angle <=315) { $endx=tan(deg2rad($angle-270)); $endy=1; }
211
- else { $endx=1; $endy=tan(deg2rad(360-$angle)); }
212
- }
213
- $b = atan2(($endy*$bboxh), ($endx*$bboxw));
214
- $h2 = $bboxh - ($bboxh * tan($b));
215
- $px = $bboxh + ($h2 * sin($b) * cos($b));
216
- $py = ($bboxh * tan($b)) + ($h2 * sin($b) * sin($b));
217
- $x1 = $px / $bboxh;
218
- $y1 = $py / $bboxh;
219
- if ($angle <=90) { $coords[2] = $x1; $coords[3] = $y1; }
220
- else if ($angle <=180) { $coords[2] = 1-$x1; $coords[3] = $y1; }
221
- else if ($angle <=270) { $coords[2] = 1-$x1; $coords[3] = 1-$y1; }
222
- else { $coords[2] = $x1; $coords[3] = 1-$y1; }
223
- }
224
- }
225
- // -moz If the first parameter to the gradient function is only a <point>, the gradient axis starts from the specified point,
226
- // and ends at the point you would get if you rotated the starting point by 180 degrees about the center of the box that the
227
- // gradient is to be applied to.
228
- // NO angle and NO end points (Start points defined)
229
- else if ((!isset($angle) || $angle===false) && $coords[0]!==false && $coords[1]!==false) { // should have start and end defined
230
- $coords[2] = 1-$coords[0]; $coords[3] = 1-$coords[1];
231
- $angle = rad2deg(atan2($coords[3]-$coords[1],$coords[2]-$coords[0]));
232
- if ($angle < 0) { $angle += 360; }
233
- else if ($angle > 360) { $angle -= 360; }
234
- if ($angle!=0 && $angle!=360 && $angle!=90 && $angle!=180 && $angle!=270) {
235
- if ($w >= $h) {
236
- $coords[1] *= $h/$w ;
237
- $coords[3] *= $h/$w ;
238
- $usew = $useh = $bboxw;
239
- $usey -= ($w-$h);
240
- }
241
- else {
242
- $coords[0] *= $w/$h ;
243
- $coords[2] *= $w/$h ;
244
- $usew = $useh = $bboxh;
245
- }
246
- }
247
- }
248
-
249
- // -moz If neither a <point> or <angle> is specified, i.e. the entire function consists of only <stop> values, the gradient
250
- // axis starts from the top of the box and runs vertically downwards, ending at the bottom of the box.
251
- else { // default values T2B
252
- // All values are set in parseMozGradient - so won't appear here
253
- $coords = array(0,0,1,0); // default for original linear gradient (L2R)
254
- }
255
- $s = ' q';
256
- $s .= sprintf(' %.3F %.3F %.3F %.3F re W n', $x*_MPDFK, ($this->mpdf->h-$y)*_MPDFK, $w*_MPDFK, -$h*_MPDFK)."\n";
257
- $s .= sprintf(' %.3F 0 0 %.3F %.3F %.3F cm', $usew*_MPDFK, $useh*_MPDFK, $usex*_MPDFK, ($this->mpdf->h-($usey+$useh))*_MPDFK)."\n";
258
- }
259
-
260
- // RADIAL
261
- else if ($type == 3) {
262
- $radius = (isset($coords[4]) ? $coords[4] : false);
263
- $angle = (isset($coords[5]) ? $coords[5] : false); // ?? no effect
264
- $shape = (isset($coords[6]) ? $coords[6] : false);
265
- $size = (isset($coords[7]) ? $coords[7] : false);
266
- $repeat = (isset($coords[8]) ? $coords[8] : false);
267
- // ALL POINTS AND RADIUS SET (default for custom mPDF radial gradient) - no -moz
268
- if ($coords[0]!==false && $coords[1]!==false && $coords[2]!==false && $coords[3]!==false && $coords[4]!==false) {
269
- // do nothing - coords used as they are
270
- }
271
- // If a <point> is defined
272
- else if ($shape!==false && $size!==false) {
273
- if ($coords[2]==false) { $coords[2] = $coords[0]; }
274
- if ($coords[3]==false) { $coords[3] = $coords[1]; }
275
- // ELLIPSE
276
- if ($shape=='ellipse') {
277
- $corner1 = sqrt(pow($coords[0],2) + pow($coords[1],2));
278
- $corner2 = sqrt(pow($coords[0],2) + pow((1-$coords[1]),2));
279
- $corner3 = sqrt(pow((1-$coords[0]),2) + pow($coords[1],2));
280
- $corner4 = sqrt(pow((1-$coords[0]),2) + pow((1-$coords[1]),2));
281
- if ($size=='closest-side') { $radius = min($coords[0], $coords[1], (1-$coords[0]), (1-$coords[1])); }
282
- else if ($size=='closest-corner') { $radius = min($corner1, $corner2, $corner3, $corner4); }
283
- else if ($size=='farthest-side') { $radius = max($coords[0], $coords[1], (1-$coords[0]), (1-$coords[1])); }
284
- else { $radius = max($corner1, $corner2, $corner3, $corner4); } // farthest corner (default)
285
- }
286
- // CIRCLE
287
- else if ($shape=='circle') {
288
- if ($w >= $h) {
289
- $coords[1] = $coords[3] = ($coords[1] * $h/$w) ;
290
- $corner1 = sqrt(pow($coords[0],2) + pow($coords[1],2));
291
- $corner2 = sqrt(pow($coords[0],2) + pow((($h/$w)-$coords[1]),2));
292
- $corner3 = sqrt(pow((1-$coords[0]),2) + pow($coords[1],2));
293
- $corner4 = sqrt(pow((1-$coords[0]),2) + pow((($h/$w)-$coords[1]),2));
294
- if ($size=='closest-side') { $radius = min($coords[0], $coords[1], (1-$coords[0]), (($h/$w)-$coords[1])); }
295
- else if ($size=='closest-corner') { $radius = min($corner1, $corner2, $corner3, $corner4); }
296
- else if ($size=='farthest-side') { $radius = max($coords[0], $coords[1], (1-$coords[0]), (($h/$w)-$coords[1])); }
297
- else if ($size=='farthest-corner') { $radius = max($corner1, $corner2, $corner3, $corner4); } // farthest corner (default)
298
- $usew = $useh = $bboxw;
299
- $usey -= ($w-$h);
300
- }
301
- else {
302
- $coords[0] = $coords[2] = ($coords[0] * $w/$h) ;
303
- $corner1 = sqrt(pow($coords[0],2) + pow($coords[1],2));
304
- $corner2 = sqrt(pow($coords[0],2) + pow((1-$coords[1]),2));
305
- $corner3 = sqrt(pow((($w/$h)-$coords[0]),2) + pow($coords[1],2));
306
- $corner4 = sqrt(pow((($w/$h)-$coords[0]),2) + pow((1-$coords[1]),2));
307
- if ($size=='closest-side') { $radius = min($coords[0], $coords[1], (($w/$h)-$coords[0]), (1-$coords[1])); }
308
- else if ($size=='closest-corner') { $radius = min($corner1, $corner2, $corner3, $corner4); }
309
- else if ($size=='farthest-side') { $radius = max($coords[0], $coords[1], (($w/$h)-$coords[0]), (1-$coords[1])); }
310
- else if ($size=='farthest-corner') { $radius = max($corner1, $corner2, $corner3, $corner4); } // farthest corner (default)
311
- $usew = $useh = $bboxh;
312
- }
313
- }
314
- if ($radius==0) { $radius=0.001; } // to prevent error
315
- $coords[4] = $radius;
316
- }
317
-
318
- // -moz If entire function consists of only <stop> values
319
- else { // default values
320
- // All values are set in parseMozGradient - so won't appear here
321
- $coords = array(0.5,0.5,0.5,0.5); // default for radial gradient (centred)
322
- }
323
- $s = ' q';
324
- $s .= sprintf(' %.3F %.3F %.3F %.3F re W n', $x*_MPDFK, ($this->mpdf->h-$y)*_MPDFK, $w*_MPDFK, -$h*_MPDFK)."\n";
325
- $s .= sprintf(' %.3F 0 0 %.3F %.3F %.3F cm', $usew*_MPDFK, $useh*_MPDFK, $usex*_MPDFK, ($this->mpdf->h-($usey+$useh))*_MPDFK)."\n";
326
- }
327
-
328
- $n = count($this->mpdf->gradients) + 1;
329
- $this->mpdf->gradients[$n]['type'] = $type;
330
- $this->mpdf->gradients[$n]['colorspace'] = $colorspace;
331
- $trans = false;
332
- $this->mpdf->gradients[$n]['is_mask'] = $is_mask;
333
- if ($is_mask) { $trans = true; }
334
- if (count($stops) == 1) { $stops[1] = $stops[0]; }
335
- if (!isset($stops[0]['offset'])) { $stops[0]['offset'] = 0; }
336
- if (!isset($stops[(count($stops)-1)]['offset'])) { $stops[(count($stops)-1)]['offset'] = 1; }
337
-
338
- // Fix stop-offsets set as absolute lengths
339
- if ($type==2) {
340
- $axisx = ($coords[2]-$coords[0])*$usew;
341
- $axisy = ($coords[3]-$coords[1])*$useh;
342
- $axis_length = sqrt(pow($axisx,2) + pow($axisy,2));
343
- }
344
- else { $axis_length = $coords[4]*$usew; } // Absolute lengths are meaningless for an ellipse - Firefox uses Width as reference
345
-
346
- for($i=0;$i<count($stops);$i++) {
347
- if (isset($stops[$i]['offset']) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$stops[$i]['offset'],$m)) {
348
- $tmp = $this->mpdf->ConvertSize($m[1],$this->mpdf->w,$this->mpdf->FontSize,false);
349
- $stops[$i]['offset'] = $tmp/$axis_length;
350
- }
351
- }
352
-
353
-
354
- if (isset($stops[0]['offset']) && $stops[0]['offset']>0) {
355
- $firststop = $stops[0];
356
- $firststop['offset'] = 0;
357
- array_unshift($stops, $firststop);
358
- }
359
- if (!$repeat && isset($stops[(count($stops)-1)]['offset']) && $stops[(count($stops)-1)]['offset']<1) {
360
- $endstop = $stops[(count($stops)-1)];
361
- $endstop['offset'] = 1;
362
- $stops[] = $endstop;
363
- }
364
- if ($stops[0]['offset'] > $stops[(count($stops)-1)]['offset']) {
365
- $stops[0]['offset'] = 0;
366
- $stops[(count($stops)-1)]['offset'] = 1;
367
- }
368
-
369
- for($i=0;$i<count($stops);$i++) {
370
- // mPDF 5.3.74
371
- if ($colorspace == 'CMYK') {
372
- $this->mpdf->gradients[$n]['stops'][$i]['col'] = sprintf('%.3F %.3F %.3F %.3F', (ord($stops[$i]['col']{1})/100), (ord($stops[$i]['col']{2})/100), (ord($stops[$i]['col']{3})/100), (ord($stops[$i]['col']{4})/100));
373
- }
374
- else if ($colorspace == 'Gray') {
375
- $this->mpdf->gradients[$n]['stops'][$i]['col'] = sprintf('%.3F', (ord($stops[$i]['col']{1})/255));
376
- }
377
- else {
378
- $this->mpdf->gradients[$n]['stops'][$i]['col'] = sprintf('%.3F %.3F %.3F', (ord($stops[$i]['col']{1})/255), (ord($stops[$i]['col']{2})/255), (ord($stops[$i]['col']{3})/255));
379
- }
380
- if (!isset($stops[$i]['opacity'])) { $stops[$i]['opacity'] = 1; }
381
- else if ($stops[$i]['opacity'] > 1 || $stops[$i]['opacity'] < 0) { $stops[$i]['opacity'] = 1; }
382
- else if ($stops[$i]['opacity'] < 1) {
383
- $trans = true;
384
- }
385
- $this->mpdf->gradients[$n]['stops'][$i]['opacity'] = $stops[$i]['opacity'];
386
- // OFFSET
387
- if ($i>0 && $i<(count($stops)-1)) {
388
- if (!isset($stops[$i]['offset']) || (isset($stops[$i+1]['offset']) && $stops[$i]['offset']>$stops[$i+1]['offset']) || $stops[$i]['offset']<$stops[$i-1]['offset']) {
389
- if (isset($stops[$i-1]['offset']) && isset($stops[$i+1]['offset'])) {
390
- $stops[$i]['offset'] = ($stops[$i-1]['offset']+$stops[$i+1]['offset'])/2;
391
- }
392
- else {
393
- for($j=($i+1);$j<count($stops);$j++) {
394
- if(isset($stops[$j]['offset'])) { break; }
395
- }
396
- $int = ($stops[$j]['offset'] - $stops[($i-1)]['offset'])/($j-$i+1);
397
- for($f=0;$f<($j-$i-1);$f++) {
398
- $stops[($i+$f)]['offset'] = $stops[($i+$f-1)]['offset'] + ($int);
399
- }
400
- }
401
- }
402
- }
403
- $this->mpdf->gradients[$n]['stops'][$i]['offset'] = $stops[$i]['offset'];
404
- $this->mpdf->gradients[$n]['stops'][$i]['offset'] = $stops[$i]['offset'];
405
- }
406
-
407
- if ($repeat) {
408
- $ns = count($this->mpdf->gradients[$n]['stops']);
409
- $offs = array();
410
- for($i=0;$i<$ns;$i++) {
411
- $offs[$i] = $this->mpdf->gradients[$n]['stops'][$i]['offset'];
412
- }
413
- $gp = 0;
414
- $inside=true;
415
- while($inside) {
416
- $gp++;
417
- for($i=0;$i<$ns;$i++) {
418
- $this->mpdf->gradients[$n]['stops'][(($ns*$gp)+$i)] = $this->mpdf->gradients[$n]['stops'][(($ns*($gp-1))+$i)];
419
- $tmp = $this->mpdf->gradients[$n]['stops'][(($ns*($gp-1))+($ns-1))]['offset']+$offs[$i] ;
420
- if ($tmp < 1) { $this->mpdf->gradients[$n]['stops'][(($ns*$gp)+$i)]['offset'] = $tmp; }
421
- else {
422
- $this->mpdf->gradients[$n]['stops'][(($ns*$gp)+$i)]['offset'] = 1;
423
- $inside = false;
424
- break(2);
425
- }
426
- }
427
- }
428
- }
429
-
430
- if ($trans) {
431
- $this->mpdf->gradients[$n]['trans'] = true;
432
- $s .= ' /TGS'.$n.' gs ';
433
- }
434
- if (!is_array($extend) || count($extend) <1) {
435
- $extend=array('true', 'true'); // These are supposed to be quoted - appear in PDF file as text
436
- }
437
- $this->mpdf->gradients[$n]['coords'] = $coords;
438
- $this->mpdf->gradients[$n]['extend'] = $extend;
439
- //paint the gradient
440
- $s .= '/Sh'.$n.' sh '."\n";
441
- //restore previous Graphic State
442
- $s .= ' Q '."\n";
443
- if ($return) { return $s; }
444
- else { $this->mpdf->_out($s); }
445
- }
446
-
447
-
448
- function parseMozGradient($bg) {
449
- // background[-image]: -moz-linear-gradient(left, #c7Fdde 20%, #FF0000 );
450
- // background[-image]: linear-gradient(left, #c7Fdde 20%, #FF0000 ); // CSS3
451
- if (preg_match('/repeating-/',$bg)) { $repeat = true; }
452
- else { $repeat = false; }
453
- if (preg_match('/linear-gradient\((.*)\)/',$bg,$m)) {
454
- $g = array();
455
- $g['type'] = 2;
456
- $g['colorspace'] = 'RGB';
457
- $g['extend'] = array('true','true');
458
- $v = trim($m[1]);
459
- // Change commas inside e.g. rgb(x,x,x)
460
- while(preg_match('/(\([^\)]*?),/',$v)) { $v = preg_replace('/(\([^\)]*?),/','\\1@',$v); }
461
- // Remove spaces inside e.g. rgb(x, x, x)
462
- while(preg_match('/(\([^\)]*?)[ ]/',$v)) { $v = preg_replace('/(\([^\)]*?)[ ]/','\\1',$v); }
463
- $bgr = preg_split('/\s*,\s*/',$v);
464
- for($i=0;$i<count($bgr);$i++) { $bgr[$i] = preg_replace('/@/', ',', $bgr[$i]); }
465
- // Is first part $bgr[0] a valid point/angle?
466
- $first = preg_split('/\s+/',trim($bgr[0]));
467
- if (preg_match('/(left|center|right|bottom|top|deg|grad|rad)/i',$bgr[0]) && !preg_match('/(<#|rgb|rgba|hsl|hsla)/i',$bgr[0])) {
468
- $startStops = 1;
469
- }
470
- else if (trim($first[(count($first)-1)]) === "0") {
471
- $startStops = 1;
472
- }
473
- else {
474
- $check = $this->mpdf->ConvertColor($first[0]);
475
- if ($check) $startStops = 0;
476
- else $startStops = 1;
477
- }
478
- // first part a valid point/angle?
479
- if ($startStops == 1) { // default values
480
- // [<point> || <angle>,] = [<% em px left center right bottom top> || <deg grad rad 0>,]
481
- if (preg_match('/([\-]*[0-9\.]+)(deg|grad|rad)/i',$bgr[0],$m)) {
482
- $angle = $m[1] + 0;
483
- if (strtolower($m[2])=='deg') { $angle = $angle; }
484
- else if (strtolower($m[2])=='grad') { $angle *= (360/400); }
485
- else if (strtolower($m[2])=='rad') { $angle = rad2deg($angle); }
486
- while($angle < 0) { $angle += 360; }
487
- $angle = ($angle % 360);
488
- }
489
- else if (trim($first[(count($first)-1)]) === "0") { $angle = 0; }
490
- if (preg_match('/left/i',$bgr[0])) { $startx = 0; }
491
- else if (preg_match('/right/i',$bgr[0])) { $startx = 1; }
492
- if (preg_match('/top/i',$bgr[0])) { $starty = 1; }
493
- else if (preg_match('/bottom/i',$bgr[0])) { $starty = 0; }
494
- // Check for %? ?% or %%
495
- if (preg_match('/(\d+)[%]/i',$first[0],$m)) { $startx = $m[1]/100; }
496
- else if (!isset($startx) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$first[0],$m)) {
497
- $tmp = $this->mpdf->ConvertSize($m[1],$this->mpdf->w,$this->mpdf->FontSize,false);
498
- if ($tmp) { $startx = $m[1]; }
499
- }
500
- if (isset($first[1]) && preg_match('/(\d+)[%]/i',$first[1],$m)) { $starty = 1 - ($m[1]/100); }
501
- else if (!isset($starty) && isset($first[1]) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$first[1],$m)) {
502
- $tmp = $this->mpdf->ConvertSize($m[1],$this->mpdf->w,$this->mpdf->FontSize,false);
503
- if ($tmp) { $starty = $m[1]; }
504
- }
505
- if (isset($startx) && !isset($starty)) { $starty = 0.5; }
506
- if (!isset($startx) && isset($starty)) { $startx = 0.5; }
507
-
508
- }
509
- // If neither a <point> or <angle> is specified, i.e. the entire function consists of only <stop> values, the gradient axis starts from the top of the box and runs vertically downwards, ending at the bottom of the box.
510
- else { // default values T2B
511
- $starty = 1; $startx = 0.5;
512
- $endy = 0; $endx = 0.5;
513
- }
514
- $coords = array();
515
- if (!isset($startx)) { $startx = false; }
516
- if (!isset($starty)) { $starty = false; }
517
- if (!isset($endx)) { $endx = false; }
518
- if (!isset($endy)) { $endy = false; }
519
- if (!isset($angle)) { $angle = false; }
520
- $g['coords'] = array($startx ,$starty ,$endx ,$endy, $angle, $repeat );
521
- $g['stops'] = array();
522
- for($i=$startStops;$i<count($bgr);$i++) {
523
- $stop = array();
524
- // parse stops
525
- $el = preg_split('/\s+/',trim($bgr[$i]));
526
- // mPDF 5.3.74
527
- $col = $this->mpdf->ConvertColor($el[0]);
528
- if ($col) { $stop['col'] = $col; }
529
- else { $stop['col'] = $col = $this->mpdf->ConvertColor(255); }
530
- if ($col{0}==1) $g['colorspace'] = 'Gray';
531
- else if ($col{0}==4 || $col{0}==6) $g['colorspace'] = 'CMYK';
532
- if ($col{0}==5) { $stop['opacity'] = ord($col{4})/100; } // transparency from rgba()
533
- else if ($col{0}==6) { $stop['opacity'] = ord($col{5})/100; } // transparency from cmyka()
534
- else if ($col{0}==1 && $col{2}==1) { $stop['opacity'] = ord($col{3})/100; } // transparency converted from rgba or cmyka()
535
-
536
- if (isset($el[1]) && preg_match('/(\d+)[%]/',$el[1],$m)) {
537
- $stop['offset'] = $m[1]/100;
538
- if ($stop['offset']>1) { unset($stop['offset']); }
539
- }
540
- else if (isset($el[1]) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$el[1],$m)) {
541
- $tmp = $this->mpdf->ConvertSize($m[1],$this->mpdf->w,$this->mpdf->FontSize,false);
542
- if ($tmp) { $stop['offset'] = $m[1]; }
543
- }
544
- $g['stops'][] = $stop;
545
- }
546
- if (count($g['stops'] )) { return $g; }
547
- }
548
- else if (preg_match('/radial-gradient\((.*)\)/',$bg,$m)) {
549
- $g = array();
550
- $g['type'] = 3;
551
- $g['colorspace'] = 'RGB';
552
- $g['extend'] = array('true','true');
553
- $v = trim($m[1]);
554
- // Change commas inside e.g. rgb(x,x,x)
555
- while(preg_match('/(\([^\)]*?),/',$v)) { $v = preg_replace('/(\([^\)]*?),/','\\1@',$v); }
556
- // Remove spaces inside e.g. rgb(x, x, x)
557
- while(preg_match('/(\([^\)]*?)[ ]/',$v)) { $v = preg_replace('/(\([^\)]*?)[ ]/','\\1',$v); }
558
- $bgr = preg_split('/\s*,\s*/',$v);
559
- for($i=0;$i<count($bgr);$i++) { $bgr[$i] = preg_replace('/@/', ',', $bgr[$i]); }
560
-
561
- // Is first part $bgr[0] a valid point/angle?
562
- $startStops = 0;
563
- $pos_angle = false;
564
- $shape_size = false;
565
- $first = preg_split('/\s+/',trim($bgr[0]));
566
- $checkCol = $this->mpdf->ConvertColor($first[0]);
567
- if (preg_match('/(left|center|right|bottom|top|deg|grad|rad)/i',$bgr[0]) && !preg_match('/(<#|rgb|rgba|hsl|hsla)/i',$bgr[0])) {
568
- $startStops=1;
569
- $pos_angle = $bgr[0];
570
- }
571
- else if (trim($first[(count($first)-1)]) === "0") {
572
- $startStops=1;
573
- $pos_angle = $bgr[0];
574
- }
575
- else if (preg_match('/(circle|ellipse|closest-side|closest-corner|farthest-side|farthest-corner|contain|cover)/i',$bgr[0])) {
576
- $startStops=1;
577
- $shape_size = $bgr[0];
578
- }
579
- else if (!$checkCol) {
580
- $startStops=1;
581
- $pos_angle = $bgr[0];
582
- }
583
- if (preg_match('/(circle|ellipse|closest-side|closest-corner|farthest-side|farthest-corner|contain|cover)/i',$bgr[1])) {
584
- $startStops=2;
585
- $shape_size = $bgr[1];
586
- }
587
-
588
- // If valid point/angle?
589
- if ($pos_angle) { // default values
590
- // [<point> || <angle>,] = [<% em px left center right bottom top> || <deg grad rad 0>,]
591
- if (preg_match('/left/i',$pos_angle)) { $startx = 0; }
592
- else if (preg_match('/right/i',$pos_angle)) { $startx = 1; }
593
- if (preg_match('/top/i',$pos_angle)) { $starty = 1; }
594
- else if (preg_match('/bottom/i',$pos_angle)) { $starty = 0; }
595
- // Check for %? ?% or %%
596
- if (preg_match('/(\d+)[%]/i',$first[0],$m)) { $startx = $m[1]/100; }
597
- else if (!isset($startx) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$first[0],$m)) {
598
- $tmp = $this->mpdf->ConvertSize($m[1],$this->mpdf->w,$this->mpdf->FontSize,false);
599
- if ($tmp) { $startx = $m[1]; }
600
- }
601
- if (isset($first[1]) && preg_match('/(\d+)[%]/i',$first[1],$m)) { $starty = 1 - ($m[1]/100); }
602
- else if (!isset($starty) && isset($first[1]) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$first[1],$m)) {
603
- $tmp = $this->mpdf->ConvertSize($m[1],$this->mpdf->w,$this->mpdf->FontSize,false);
604
- if ($tmp) { $starty = $m[1]; }
605
- }
606
-
607
- /*
608
- // ?? Angle has no effect in radial gradient (does not exist in CSS3 spec.)
609
- if (preg_match('/([\-]*[0-9\.]+)(deg|grad|rad)/i',$pos_angle,$m)) {
610
- $angle = $m[1] + 0;
611
- if (strtolower($m[2])=='deg') { $angle = $angle; }
612
- else if (strtolower($m[2])=='grad') { $angle *= (360/400); }
613
- else if (strtolower($m[2])=='rad') { $angle = rad2deg($angle); }
614
- while($angle < 0) { $angle += 360; }
615
- $angle = ($angle % 360);
616
- }
617
- */
618
- if (!isset($starty)) { $starty = 0.5; }
619
- if (!isset($startx)) { $startx = 0.5; }
620
-
621
- }
622
- // If neither a <point> or <angle> is specified, i.e. the entire function consists of only <stop> values, the gradient axis starts from the top of the box and runs vertically downwards, ending at the bottom of the box.
623
- else { // default values Center
624
- $starty = 0.5; $startx = 0.5;
625
- $endy = 0.5; $endx = 0.5;
626
- }
627
-
628
- // If valid shape/size?
629
- $shape = 'ellipse'; // default
630
- $size = 'farthest-corner'; // default
631
- if ($shape_size) { // default values
632
- if (preg_match('/(circle|ellipse)/i',$shape_size, $m)) {
633
- $shape = $m[1];
634
- }
635
- if (preg_match('/(closest-side|closest-corner|farthest-side|farthest-corner|contain|cover)/i',$shape_size, $m)) {
636
- $size = $m[1];
637
- if ($size=='contain') { $size = 'closest-side'; }
638
- else if ($size=='cover') { $size = 'farthest-corner'; }
639
- }
640
- }
641
-
642
- $coords = array();
643
- if (!isset($startx)) { $startx = false; }
644
- if (!isset($starty)) { $starty = false; }
645
- if (!isset($endx)) { $endx = false; }
646
- if (!isset($endy)) { $endy = false; }
647
- if (!isset($radius)) { $radius = false; }
648
- if (!isset($angle)) { $angle = 0; }
649
- $g['coords'] = array($startx ,$starty ,$endx ,$endy, $radius, $angle, $shape, $size, $repeat );
650
-
651
- $g['stops'] = array();
652
- for($i=$startStops;$i<count($bgr);$i++) {
653
- $stop = array();
654
- // parse stops
655
- $el = preg_split('/\s+/',trim($bgr[$i]));
656
- // mPDF 5.3.74
657
- $col = $this->mpdf->ConvertColor($el[0]);
658
- if ($col) { $stop['col'] = $col; }
659
- else { $stop['col'] = $col = $this->mpdf->ConvertColor(255); }
660
- if ($col{0}==1) $g['colorspace'] = 'Gray';
661
- else if ($col{0}==4 || $col{0}==6) $g['colorspace'] = 'CMYK';
662
- if ($col{0}==5) { $stop['opacity'] = ord($col{4})/100; } // transparency from rgba()
663
- else if ($col{0}==6) { $stop['opacity'] = ord($col{5})/100; } // transparency from cmyka()
664
- else if ($col{0}==1 && $col{2}==1) { $stop['opacity'] = ord($col{3})/100; } // transparency converted from rgba or cmyka()
665
-
666
- if (isset($el[1]) && preg_match('/(\d+)[%]/',$el[1],$m)) {
667
- $stop['offset'] = $m[1]/100;
668
- if ($stop['offset']>1) { unset($stop['offset']); }
669
- }
670
- else if (isset($el[1]) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$el[1],$m)) {
671
- $tmp = $this->mpdf->ConvertSize($m[1],$this->mpdf->w,$this->mpdf->FontSize,false);
672
- $stop['offset'] = $el[1];
673
- }
674
- $g['stops'][] = $stop;
675
- }
676
- if (count($g['stops'] )) { return $g; }
677
- }
678
- return array();
679
- }
680
-
681
- function parseBackgroundGradient($bg) {
682
- // background-gradient: linear #00FFFF #FFFF00 0 0.5 1 0.5; or
683
- // background-gradient: radial #00FFFF #FFFF00 0.5 0.5 1 1 1.2;
684
-
685
- $v = trim($bg);
686
- $bgr = preg_split('/\s+/',$v);
687
- $g = array();
688
- if (count($bgr)> 6) {
689
- if (strtoupper(substr($bgr[0],0,1)) == 'L' && count($bgr)==7) { // linear
690
- $g['type'] = 2;
691
- //$coords = array(0,0,1,1 ); // 0 0 1 0 or 0 1 1 1 is L 2 R; 1,1,0,1 is R2L; 1,1,1,0 is T2B; 1,0,1,1 is B2T
692
- // Linear: $coords - array of the form (x1, y1, x2, y2) which defines the gradient vector (see linear_gradient_coords.jpg).
693
- // The default value is from left to right (x1=0, y1=0, x2=1, y2=0).
694
- $g['coords'] = array($bgr[3], $bgr[4], $bgr[5], $bgr[6]);
695
- }
696
- else if (count($bgr)==8) { // radial
697
- $g['type'] = 3;
698
- // Radial: $coords - array of the form (fx, fy, cx, cy, r) where (fx, fy) is the starting point of the gradient with color1,
699
- // (cx, cy) is the center of the circle with color2, and r is the radius of the circle (see radial_gradient_coords.jpg).
700
- // (fx, fy) should be inside the circle, otherwise some areas will not be defined
701
- $g['coords'] = array($bgr[3], $bgr[4], $bgr[5], $bgr[6], $bgr[7]);
702
- }
703
- $g['colorspace'] = 'RGB';
704
- // mPDF 5.3.74
705
- $cor = $this->mpdf->ConvertColor($bgr[1]);
706
- if ($cor{0}==1) $g['colorspace'] = 'Gray';
707
- else if ($cor{0}==4 || $cor{0}==6) $g['colorspace'] = 'CMYK';
708
- if ($cor) { $g['col'] = $cor; }
709
- else { $g['col'] = $this->mpdf->ConvertColor(255); }
710
- $cor = $this->mpdf->ConvertColor($bgr[2]);
711
- if ($cor) { $g['col2'] = $cor; }
712
- else { $g['col2'] = $this->mpdf->ConvertColor(255); }
713
- $g['extend'] = array('true','true');
714
- $g['stops'] = array(array('col'=>$g['col'], 'opacity'=>1, 'offset'=>0), array('col'=>$g['col2'], 'opacity'=>1, 'offset'=>1));
715
- return $g;
716
- }
717
- return false;
718
- }
719
-
720
-
721
-
722
- }
723
-
724
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/mpdf/classes/indic.php DELETED
@@ -1,1714 +0,0 @@
1
- <?php
2
-
3
-
4
- class INDIC {
5
-
6
- /* FROM hb-ot-shape-complex-indic-private.hh */
7
- // indic_category
8
- const OT_X = 0;
9
- const OT_C = 1;
10
- const OT_V = 2;
11
- const OT_N = 3;
12
- const OT_H = 4;
13
- const OT_ZWNJ = 5;
14
- const OT_ZWJ = 6;
15
- const OT_M = 7; /* Matra or Dependent Vowel */
16
- const OT_SM = 8;
17
- const OT_VD = 9;
18
- const OT_A = 10;
19
- const OT_NBSP = 11;
20
- const OT_DOTTEDCIRCLE = 12; /* Not in the spec, but special in Uniscribe. /Very very/ special! */
21
- const OT_RS = 13; /* Register Shifter, used in Khmer OT spec */
22
- const OT_Coeng = 14;
23
- const OT_Repha = 15;
24
- const OT_Ra = 16; /* Not explicitly listed in the OT spec, but used in the grammar. */
25
- const OT_CM = 17;
26
-
27
-
28
- // Based on indic_category used to make string to find syllables
29
- // OT_ to string character (using e.g. OT_C from INDIC) hb-ot-shape-complex-indic-private.hh
30
- public static $indic_category_char = array(
31
- 'x',
32
- 'C',
33
- 'V',
34
- 'N',
35
- 'H',
36
- 'Z',
37
- 'J',
38
- 'M',
39
- 'S',
40
- 'v',
41
- 'A', /* Spec gives Andutta U+0952 as OT_A. However, testing shows that Uniscribe
42
- * treats U+0951..U+0952 all as OT_VD - see set_indic_properties */
43
- 's',
44
- 'D',
45
- 'F', /* Register shift Khmer only */
46
- 'G', /* Khmer only */
47
- 'r', /* 0D4E (dot reph) only one in Malayalam */
48
- 'R',
49
- 'm', /* Consonant medial only used in Indic 0A75 in Gurmukhi (0A00..0A7F) : also in Lao, Myanmar, Tai Tham, Javanese & Cham */
50
- );
51
-
52
-
53
- /* Visual positions in a syllable from left to right. */
54
- /* FROM hb-ot-shape-complex-indic-private.hh */
55
- // indic_position
56
- const POS_START = 0;
57
-
58
- const POS_RA_TO_BECOME_REPH = 1;
59
- const POS_PRE_M = 2;
60
- const POS_PRE_C = 3;
61
-
62
- const POS_BASE_C = 4;
63
- const POS_AFTER_MAIN = 5;
64
-
65
- const POS_ABOVE_C = 6;
66
-
67
- const POS_BEFORE_SUB = 7;
68
- const POS_BELOW_C = 8;
69
- const POS_AFTER_SUB = 9;
70
-
71
- const POS_BEFORE_POST = 10;
72
- const POS_POST_C = 11;
73
- const POS_AFTER_POST = 12;
74
-
75
- const POS_FINAL_C = 13;
76
- const POS_SMVD = 14;
77
-
78
- const POS_END = 15;
79
-
80
- /*
81
- * Basic features.
82
- * These features are applied in order, one at a time, after initial_reordering.
83
- */
84
- /*
85
- * Must be in the same order as the indic_features array. Ones starting with _ are F_GLOBAL
86
- * Ones without the _ are only applied where the mask says!
87
- */
88
- const _NUKT = 0;
89
- const _AKHN = 1;
90
- const RPHF = 2;
91
- const _RKRF = 3;
92
- const PREF = 4;
93
- const BLWF = 5;
94
- const HALF = 6;
95
- const ABVF = 7;
96
- const PSTF = 8;
97
- const CFAR = 9; // Khmer only
98
- const _VATU = 10;
99
- const _CJCT = 11;
100
- const INIT = 12;
101
-
102
-
103
- public static function set_indic_properties(&$info, $scriptblock ) {
104
- $u = $info['uni'];
105
- $type = self::indic_get_categories($u);
106
- $cat = ($type & 0x7F);
107
- $pos = ($type >> 8);
108
-
109
- /*
110
- * Re-assign category
111
- */
112
-
113
- if ($u == 0x17D1) $cat = self::OT_X;
114
-
115
- if ($cat == self::OT_X && self::in_range($u, 0x17CB, 0x17D3)) { /* Khmer Various signs */
116
- /* These are like Top Matras. */
117
- $cat = self::OT_M;
118
- $pos = self::POS_ABOVE_C;
119
- }
120
-
121
- if ($u == 0x17C6) $cat = self::OT_N; /* Khmer Bindu doesn't like to be repositioned. */
122
-
123
- if ($u == 0x17D2) $cat = self::OT_Coeng; /* Khmer coeng */
124
-
125
- /* The spec says U+0952 is OT_A. However, testing shows that Uniscribe
126
- * treats U+0951..U+0952 all as OT_VD.
127
- * TESTS:
128
- * U+092E,U+0947,U+0952
129
- * U+092E,U+0952,U+0947
130
- * U+092E,U+0947,U+0951
131
- * U+092E,U+0951,U+0947
132
- * */
133
- //if ($u == 0x0952) $cat = self::OT_A;
134
- if (self::in_range($u, 0x0951, 0x0954))
135
- $cat = self::OT_VD;
136
-
137
- if ($u == 0x200C) $cat = self::OT_ZWNJ;
138
- else if ($u == 0x200D) $cat = self::OT_ZWJ;
139
- else if ($u == 0x25CC) $cat = self::OT_DOTTEDCIRCLE;
140
- else if ($u == 0x0A71) $cat = self::OT_SM; /* GURMUKHI ADDAK. More like consonant medial. like 0A75. */
141
-
142
- if ($cat == self::OT_Repha) {
143
- /* There are two kinds of characters marked as Repha:
144
- * - The ones that are GenCat=Mn are already positioned visually, ie. after base. (eg. Khmer)
145
- * - The ones that are GenCat=Lo is encoded logically, ie. beginning of syllable. (eg. Malayalam)
146
- *
147
- * We recategorize the first kind to look like a Nukta and attached to the base directly.
148
- */
149
- if ($info['general_category'] == UCDN::UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)
150
- $cat = self::OT_N;
151
- }
152
-
153
- /*
154
- * Re-assign position.
155
- */
156
-
157
- if ((self::FLAG($cat) & (self::FLAG(self::OT_C) | self::FLAG(self::OT_CM) | self::FLAG(self::OT_Ra) | self::FLAG(self::OT_V) | self::FLAG(self::OT_NBSP) | self::FLAG(self::OT_DOTTEDCIRCLE)))) { // = CONSONANT_FLAGS like is_consonant
158
- if ($scriptblock == UCDN::SCRIPT_KHMER) $pos = self::POS_BELOW_C; /* Khmer differs from Indic here. */
159
- else $pos = self::POS_BASE_C; /* Will recategorize later based on font lookups. */
160
-
161
- if (self::is_ra ($u))
162
- $cat = self::OT_Ra;
163
- }
164
- else if ($cat == self::OT_M) {
165
- $pos = self::matra_position($u, $pos);
166
- }
167
- else if ($cat == self::OT_SM || $cat == self::OT_VD) {
168
- $pos = self::POS_SMVD;
169
- }
170
-
171
- if ($u == 0x0B01) $pos = self::POS_BEFORE_SUB; /* Oriya Bindu is BeforeSub in the spec. */
172
-
173
- $info['indic_category'] = $cat;
174
- $info['indic_position'] = $pos;
175
- }
176
-
177
- // syllable_type
178
- const CONSONANT_SYLLABLE = 0;
179
- const VOWEL_SYLLABLE = 1;
180
- const STANDALONE_CLUSTER = 2;
181
- const BROKEN_CLUSTER = 3;
182
- const NON_INDIC_CLUSTER = 4;
183
-
184
- public static function set_syllables(&$o, $s, &$broken_syllables) {
185
- $ptr = 0;
186
- $syllable_serial = 1;
187
- $broken_syllables = false;
188
-
189
- while($ptr < strlen($s)) {
190
- $match = '';
191
- $syllable_length = 1;
192
- $syllable_type = self::NON_INDIC_CLUSTER ;
193
- // CONSONANT_SYLLABLE Consonant syllable
194
- // From OT spec:
195
- if (preg_match('/^([CR]m*[N]?(H[ZJ]?|[ZJ]H))*[CR]m*[N]?[A]?(H[ZJ]?|[M]*[N]?[H]?)?[S]?[v]{0,2}/', substr($s,$ptr), $ma)) {
196
- // From HarfBuzz:
197
- //if (preg_match('/^r?([CR]J?(Z?[N]{0,2})?[ZJ]?H(J[N]?)?){0,4}[CR]J?(Z?[N]{0,2})?A?((([ZJ]?H(J[N]?)?)|HZ)|(HJ)?([ZJ]{0,3}M[N]?(H|JHJR)?){0,4})?(S[Z]?)?[v]{0,2}/', substr($s,$ptr), $ma)) {
198
- $syllable_length = strlen($ma[0]);
199
- $syllable_type = self::CONSONANT_SYLLABLE ;
200
- }
201
- // VOWEL_SYLLABLE Vowel-based syllable
202
- // From OT spec:
203
- else if (preg_match('/^(RH|r)?V[N]?([ZJ]?H[CR]m*|J[CR]m*)?([M]*[N]?[H]?)?[S]?[v]{0,2}/', substr($s,$ptr), $ma)) {
204
- // From HarfBuzz:
205
- //else if (preg_match('/^(RH|r)?V(Z?[N]{0,2})?(J|([ZJ]?H(J[N]?)?[CR]J?(Z?[N]{0,2})?){0,4}((([ZJ]?H(J[N]?)?)|HZ)|(HJ)?([ZJ]{0,3}M[N]?(H|JHJR)?){0,4})?(S[Z]?)?[v]{0,2})/', substr($s,$ptr), $ma)) {
206
- $syllable_length = strlen($ma[0]);
207
- $syllable_type = self::VOWEL_SYLLABLE ;
208
- }
209
-
210
- /* Apply only if it's a word start. */
211
- // STANDALONE_CLUSTER Stand Alone syllable at start of word
212
- // From OT spec:
213
- else if (($ptr==0 ||
214
- $o[$ptr - 1]['general_category'] < UCDN::UNICODE_GENERAL_CATEGORY_LOWERCASE_LETTER ||
215
- $o[$ptr - 1]['general_category'] > UCDN::UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK
216
- )
217
-
218
- && (preg_match('/^(RH|r)?[sD][N]?([ZJ]?H[CR]m*)?([M]*[N]?[H]?)?[S]?[v]{0,2}/', substr($s,$ptr), $ma))) {
219
- // From HarfBuzz:
220
- // && (preg_match('/^(RH|r)?[sD](Z?[N]{0,2})?(([ZJ]?H(J[N]?)?)[CR]J?(Z?[N]{0,2})?){0,4}((([ZJ]?H(J[N]?)?)|HZ)|(HJ)?([ZJ]{0,3}M[N]?(H|JHJR)?){0,4})?(S[Z]?)?[v]{0,2}/', substr($s,$ptr), $ma)) {
221
- $syllable_length = strlen($ma[0]);
222
- $syllable_type = self::STANDALONE_CLUSTER ;
223
- }
224
-
225
- // BROKEN_CLUSTER syllable
226
- else if (preg_match('/^(RH|r)?[N]?([ZJ]?H[CR])?([M]*[N]?[H]?)?[S]?[v]{0,2}/', substr($s,$ptr), $ma)) {
227
- // From HarfBuzz:
228
- //else if (preg_match('/^(RH|r)?(Z?[N]{0,2})?(([ZJ]?H(J[N]?)?)[CR]J?(Z?[N]{0,2})?){0,4}((([ZJ]?H(J[N]?)?)|HZ)|(HJ)?([ZJ]{0,3}M[N]?(H|JHJR)?){0,4})(S[Z]?)?[v]{0,2}/', substr($s,$ptr), $ma)) {
229
- if (strlen($ma[0])) { // May match blank
230
- $syllable_length = strlen($ma[0]);
231
- $syllable_type = self::BROKEN_CLUSTER ;
232
- $broken_syllables = true;
233
- }
234
- }
235
-
236
- for ($i = $ptr; $i < $ptr+$syllable_length; $i++) { $o[$i]['syllable'] = ($syllable_serial << 4) | $syllable_type; }
237
- $ptr += $syllable_length ;
238
- $syllable_serial++;
239
- if ($syllable_serial == 16) $syllable_serial = 1;
240
- }
241
- }
242
-
243
-
244
- public static function set_syllables_sinhala(&$o, $s, &$broken_syllables) {
245
- $ptr = 0;
246
- $syllable_serial = 1;
247
- $broken_syllables = false;
248
-
249
- while($ptr < strlen($s)) {
250
- $match = '';
251
- $syllable_length = 1;
252
- $syllable_type = self::NON_INDIC_CLUSTER ;
253
- // CONSONANT_SYLLABLE Consonant syllable
254
- // From OT spec:
255
- if (preg_match('/^([CR]HJ|[CR]JH){0,8}[CR][HM]{0,3}[S]{0,1}/', substr($s,$ptr), $ma)) {
256
- $syllable_length = strlen($ma[0]);
257
- $syllable_type = self::CONSONANT_SYLLABLE ;
258
- }
259
- // VOWEL_SYLLABLE Vowel-based syllable
260
- // From OT spec:
261
- else if (preg_match('/^V[S]{0,1}/', substr($s,$ptr), $ma)) {
262
- $syllable_length = strlen($ma[0]);
263
- $syllable_type = self::VOWEL_SYLLABLE ;
264
- }
265
-
266
- for ($i = $ptr; $i < $ptr+$syllable_length; $i++) { $o[$i]['syllable'] = ($syllable_serial << 4) | $syllable_type; }
267
- $ptr += $syllable_length ;
268
- $syllable_serial++;
269
- if ($syllable_serial == 16) $syllable_serial = 1;
270
- }
271
- }
272
-
273
- public static function set_syllables_khmer(&$o, $s, &$broken_syllables) {
274
- $ptr = 0;
275
- $syllable_serial = 1;
276
- $broken_syllables = false;
277
-
278
- while($ptr < strlen($s)) {
279
- $match = '';
280
- $syllable_length = 1;
281
- $syllable_type = self::NON_INDIC_CLUSTER ;
282
- // CONSONANT_SYLLABLE Consonant syllable
283
- if (preg_match('/^r?([CR]J?((Z?F)?[N]{0,2})?[ZJ]?G(JN?)?){0,4}[CR]J?((Z?F)?[N]{0,2})?A?((([ZJ]?G(JN?)?)|GZ)|(GJ)?([ZJ]{0,3}MN?(H|JHJR)?){0,4})?(G([CR]J?((Z?F)?[N]{0,2})?|V))?(SZ?)?[v]{0,2}/', substr($s,$ptr), $ma)) {
284
- $syllable_length = strlen($ma[0]);
285
- $syllable_type = self::CONSONANT_SYLLABLE ;
286
- }
287
- // VOWEL_SYLLABLE Vowel-based syllable
288
- else if (preg_match('/^(RH|r)?V((Z?F)?[N]{0,2})?(J|([ZJ]?G(JN?)?[CR]J?((Z?F)?[N]{0,2})?){0,4}((([ZJ]?G(JN?)?)|GZ)|(GJ)?([ZJ]{0,3}MN?(H|JHJR)?){0,4})?(G([CR]J?((Z?F)?[N]{0,2})?|V))?(SZ?)?[v]{0,2})/', substr($s,$ptr), $ma)) {
289
- $syllable_length = strlen($ma[0]);
290
- $syllable_type = self::VOWEL_SYLLABLE ;
291
- }
292
-
293
-
294
- // BROKEN_CLUSTER syllable
295
- else if (preg_match('/^(RH|r)?((Z?F)?[N]{0,2})?(([ZJ]?G(JN?)?)[CR]J?((Z?F)?[N]{0,2})?){0,4}((([ZJ]?G(JN?)?)|GZ)|(GJ)?([ZJ]{0,3}MN?(H|JHJR)?){0,4})(G([CR]J?((Z?F)?[N]{0,2})?|V))?(SZ?)?[v]{0,2}/', substr($s,$ptr), $ma)) {
296
- if (strlen($ma[0])) { // May match blank
297
- $syllable_length = strlen($ma[0]);
298
- $syllable_type = self::BROKEN_CLUSTER ;
299
- $broken_syllables = true;
300
- }
301
- }
302
-
303
- for ($i = $ptr; $i < $ptr+$syllable_length; $i++) { $o[$i]['syllable'] = ($syllable_serial << 4) | $syllable_type; }
304
- $ptr += $syllable_length ;
305
- $syllable_serial++;
306
- if ($syllable_serial == 16) $syllable_serial = 1;
307
- }
308
- }
309
-
310
- public static function initial_reordering(&$info, $GSUBdata, $broken_syllables, $indic_config, $scriptblock, $is_old_spec, $dottedcircle) {
311
-
312
- self::update_consonant_positions ($info, $GSUBdata);
313
-
314
- if ($broken_syllables && $dottedcircle) { self::insert_dotted_circles ($info, $dottedcircle); }
315
-
316
- $count = count($info);
317
- if (!$count) return;
318
- $last = 0;
319
- $last_syllable = $info[0]['syllable'];
320
- for ($i = 1; $i < $count; $i++) {
321
- if ($last_syllable != $info[$i]['syllable']) {
322
- self::initial_reordering_syllable ($info, $GSUBdata, $indic_config, $scriptblock, $is_old_spec, $last, $i);
323
- $last = $i;
324
- $last_syllable = $info[$last]['syllable'];
325
- }
326
- }
327
- self::initial_reordering_syllable($info, $GSUBdata, $indic_config, $scriptblock, $is_old_spec, $last, $count);
328
- }
329
-
330
- public static function update_consonant_positions(&$info, $GSUBdata) {
331
- $count = count($info);
332
- for ($i = 0; $i < $count; $i++) {
333
- if ($info[$i]['indic_position'] == self::POS_BASE_C) {
334
- $c = $info[$i]['uni'];
335
- // If would substitute...
336
- if (isset($GSUBdata['pref'][$c])) { $info[$i]['indic_position'] = self::POS_POST_C; }
337
- else if (isset($GSUBdata['blwf'][$c])) { $info[$i]['indic_position'] = self::POS_BELOW_C; }
338
- else if (isset($GSUBdata['pstf'][$c])) { $info[$i]['indic_position'] = self::POS_POST_C; }
339
- }
340
- }
341
- }
342
-
343
- public static function insert_dotted_circles(&$info, $dottedcircle) {
344
- $idx = 0;
345
- $last_syllable = 0;
346
- while ($idx < count($info)) {
347
- $syllable = $info[$idx]['syllable'];
348
- $syllable_type = ($syllable & 0x0F);
349
- if ($last_syllable != $syllable && $syllable_type == self::BROKEN_CLUSTER) {
350
- $last_syllable = $syllable;
351
-
352
- $dottedcircle[0]['syllable'] = $info[$idx]['syllable'];
353
-
354
- /* Insert dottedcircle after possible Repha. */
355
- while ($idx < count($info) && $last_syllable == $info[$idx]['syllable'] && $info[$idx]['indic_category'] == self::OT_Repha)
356
- $idx++;
357
- array_splice($info, $idx, 0, $dottedcircle);
358
- }
359
- else
360
- $idx++;
361
- }
362
- // I am not sue how this code below got in here, since $idx should now be > count($info) and thus invalid.
363
- // In case I am missing something(!) I'll leave a warning here for now:
364
- if (isset($info[$idx])) { die("This shouldn't happen (in otl.php)"); exit; }
365
- // In case of final bloken cluster...
366
- //$syllable = $info[$idx]['syllable'];
367
- //$syllable_type = ($syllable & 0x0F);
368
- //if ($last_syllable != $syllable && $syllable_type == self::BROKEN_CLUSTER) {
369
- // $dottedcircle[0]['syllable'] = $info[$idx]['syllable'];
370
- // array_splice($info, $idx, 0, $dottedcircle);
371
- //}
372
- }
373
-
374
-
375
-
376
- /* Rules from:
377
- * https://www.microsoft.com/typography/otfntdev/devanot/shaping.aspx */
378
-
379
- public static function initial_reordering_syllable (&$info, $GSUBdata, $indic_config, $scriptblock, $is_old_spec, $start, $end) {
380
- /* vowel_syllable: We made the vowels look like consonants. So uses the consonant logic! */
381
- /* broken_cluster: We already inserted dotted-circles, so just call the standalone_cluster. */
382
- /* standalone_cluster: We treat NBSP/dotted-circle as if they are consonants, so we should just chain. */
383
-
384
- $syllable_type = ($info[$start]['syllable'] & 0x0F);
385
- if ($syllable_type==self::NON_INDIC_CLUSTER ) { return; }
386
- if ($syllable_type==self::BROKEN_CLUSTER || $syllable_type==self::STANDALONE_CLUSTER ) {
387
- //if ($uniscribe_bug_compatible) {
388
- /* For dotted-circle, this is what Uniscribe does:
389
- * If dotted-circle is the last glyph, it just does nothing.
390
- * i.e. It doesn't form Reph. */
391
- if ($info[$end - 1]['indic_category'] == self::OT_DOTTEDCIRCLE) {
392
- return;
393
- }
394
- }
395
-
396
- /* 1. Find base consonant:
397
- *
398
- * The shaping engine finds the base consonant of the syllable, using the
399
- * following algorithm: starting from the end of the syllable, move backwards
400
- * until a consonant is found that does not have a below-base or post-base
401
- * form (post-base forms have to follow below-base forms), or that is not a
402
- * pre-base reordering Ra, or arrive at the first consonant. The consonant
403
- * stopped at will be the base.
404
- *
405
- * o If the syllable starts with Ra + Halant (in a script that has Reph)
406
- * and has more than one consonant, Ra is excluded from candidates for
407
- * base consonants.
408
- */
409
-
410
- $base = $end;
411
- $has_reph = false;
412
- $limit = $start;
413
-
414
- if ($scriptblock != UCDN::SCRIPT_KHMER) {
415
- /* -> If the syllable starts with Ra + Halant (in a script that has Reph)
416
- * and has more than one consonant, Ra is excluded from candidates for
417
- * base consonants. */
418
- if (count($GSUBdata['rphf']) /* ?? $indic_plan->mask_array[RPHF] */ && $start + 3 <= $end &&
419
- (
420
- ($indic_config[4] == self::REPH_MODE_IMPLICIT && !self::is_joiner($info[$start + 2])) ||
421
- ($indic_config[4] == self::REPH_MODE_EXPLICIT && $info[$start + 2]['indic_category'] == self::OT_ZWJ)
422
- )) {
423
- /* See if it matches the 'rphf' feature. */
424
- //$glyphs = array($info[$start]['uni'], $info[$start + 1]['uni']);
425
- //if ($indic_plan->rphf->would_substitute ($glyphs, count($glyphs), true, face)) {
426
- if (isset($GSUBdata['rphf'][$info[$start]['uni']]) && self::is_halant_or_coeng($info[$start + 1]) ) {
427
- $limit += 2;
428
- while ($limit < $end && self::is_joiner($info[$limit]))
429
- $limit++;
430
- $base = $start;
431
- $has_reph = true;
432
- }
433
- }
434
- else if ($indic_config[4] == self::REPH_MODE_LOG_REPHA && $info[$start]['indic_category'] == self::OT_Repha) {
435
- $limit += 1;
436
- while ($limit < $end && self::is_joiner($info[$limit]))
437
- $limit++;
438
- $base = $start;
439
- $has_reph = true;
440
- }
441
- }
442
-
443
- switch ($indic_config[2]) { // base_pos
444
- case self::BASE_POS_LAST:
445
- /* -> starting from the end of the syllable, move backwards */
446
- $i = $end;
447
- $seen_below = false;
448
- do {
449
- $i--;
450
- /* -> until a consonant is found */
451
- if (self::is_consonant($info[$i])) {
452
- /* -> that does not have a below-base or post-base form
453
- * (post-base forms have to follow below-base forms), */
454
- if ($info[$i]['indic_position'] != self::POS_BELOW_C && ($info[$i]['indic_position'] != self::POS_POST_C || $seen_below)) {
455
- $base = $i;
456
- break;
457
- }
458
- if ($info[$i]['indic_position'] == self::POS_BELOW_C)
459
- $seen_below = true;
460
-
461
- /* -> or that is not a pre-base reordering Ra,
462
- *
463
- * IMPLEMENTATION NOTES:
464
- *
465
- * Our pre-base reordering Ra's are marked POS_POST_C, so will be skipped
466
- * by the logic above already.
467
- */
468
-
469
- /* -> or arrive at the first consonant. The consonant stopped at will
470
- * be the base. */
471
- $base = $i;
472
- }
473
- else {
474
- /* A ZWJ after a Halant stops the base search, and requests an explicit
475
- * half form.
476
- * [A ZWJ before a Halant, requests a subjoined form instead, and hence
477
- * search continues. This is particularly important for Bengali
478
- * sequence Ra,H,Ya that should form Ya-Phalaa by subjoining Ya] */
479
- if ($start < $i && $info[$i]['indic_category'] == self::OT_ZWJ && $info[$i - 1]['indic_category'] == self::OT_H) {
480
- if (!defined("OMIT_INDIC_FIX_1") || OMIT_INDIC_FIX_1!=1) { $base = $i; } // INDIC_FIX_1
481
- break;
482
- }
483
- // ZKI8
484
- if ($start < $i && $info[$i]['indic_category'] == self::OT_ZWNJ) {
485
- break;
486
- }
487
- }
488
- } while ($i > $limit);
489
- break;
490
-
491
- case self::BASE_POS_FIRST:
492
- /* In scripts without half forms (eg. Khmer), the first consonant is always the base. */
493
-
494
- if (!$has_reph)
495
- $base = $limit;
496
-
497
- /* Find the last base consonant that is not blocked by ZWJ. If there is
498
- * a ZWJ right before a base consonant, that would request a subjoined form. */
499
- for ($i = $limit; $i < $end; $i++) {
500
- if (self::is_consonant($info[$i]) && $info[$i]['indic_position'] == self::POS_BASE_C) {
501
- if ($limit < $i && $info[$i - 1]['indic_category'] == self::OT_ZWJ)
502
- break;
503
- else
504
- $base = $i;
505
- }
506
- }
507
-
508
- /* Mark all subsequent consonants as below. */
509
- for ($i = $base + 1; $i < $end; $i++) {
510
- if (self::is_consonant ($info[$i]) && $info[$i]['indic_position'] == self::POS_BASE_C)
511
- $info[$i]['indic_position'] = self::POS_BELOW_C;
512
- }
513
- break;
514
- //default:
515
- //assert (false);
516
- /* fallthrough */
517
- }
518
-
519
- /* -> If the syllable starts with Ra + Halant (in a script that has Reph)
520
- * and has more than one consonant, Ra is excluded from candidates for
521
- * base consonants.
522
- *
523
- * Only do this for unforced Reph. (ie. not for Ra,H,ZWJ. */
524
- if ($scriptblock != UCDN::SCRIPT_KHMER) {
525
- if ($has_reph && $base == $start && $limit - $base <= 2) {
526
- /* Have no other consonant, so Reph is not formed and Ra becomes base. */
527
- $has_reph = false;
528
- }
529
- }
530
-
531
- /* 2. Decompose and reorder Matras:
532
- *
533
- * Each matra and any syllable modifier sign in the cluster are moved to the
534
- * appropriate position relative to the consonant(s) in the cluster. The
535
- * shaping engine decomposes two- or three-part matras into their constituent
536
- * parts before any repositioning. Matra characters are classified by which
537
- * consonant in a conjunct they have affinity for and are reordered to the
538
- * following positions:
539
- *
540
- * o Before first half form in the syllable
541
- * o After subjoined consonants
542
- * o After post-form consonant
543
- * o After main consonant (for above marks)
544
- *
545
- * IMPLEMENTATION NOTES:
546
- *
547
- * The normalize() routine has already decomposed matras for us, so we don't
548
- * need to worry about that.
549
- */
550
-
551
-
552
- /* 3. Reorder marks to canonical order:
553
- *
554
- * Adjacent nukta and halant or nukta and vedic sign are always repositioned
555
- * if necessary, so that the nukta is first.
556
- *
557
- * IMPLEMENTATION NOTES:
558
- *
559
- * Use the combining Class from Unicode categories? to bubble_sort.
560
- */
561
-
562
- /* Reorder characters */
563
-
564
- for ($i = $start; $i < $base; $i++)
565
- $info[$i]['indic_position'] = min(self::POS_PRE_C, $info[$i]['indic_position']);
566
-
567
- if ($base < $end)
568
- $info[$base]['indic_position'] = self::POS_BASE_C;
569
-
570
- /* Mark final consonants. A final consonant is one appearing after a matra,
571
- * ? only in Khmer. */
572
- for ($i = $base + 1; $i < $end; $i++)
573
- if ($info[$i]['indic_category'] == self::OT_M) {
574
- for ($j = $i + 1; $j < $end; $j++)
575
- if (self::is_consonant ($info[$j])) {
576
- $info[$j]['indic_position'] = self::POS_FINAL_C;
577
- break;
578
- }
579
- break;
580
- }
581
-
582
- /* Handle beginning Ra */
583
- if ($scriptblock != UCDN::SCRIPT_KHMER) {
584
- if ($has_reph)
585
- $info[$start]['indic_position'] = self::POS_RA_TO_BECOME_REPH;
586
- }
587
-
588
-
589
- /* For old-style Indic script tags, move the first post-base Halant after
590
- * last consonant. Only do this if there is *not* a Halant after last
591
- * consonant. Otherwise it becomes messy. */
592
- if ($is_old_spec) {
593
- for ($i = $base + 1; $i < $end; $i++) {
594
- if ($info[$i]['indic_category'] == self::OT_H) {
595
- for ($j = $end - 1; $j > $i; $j--) {
596
- if (self::is_consonant($info[$j]) || $info[$j]['indic_category'] == self::OT_H) { break; }
597
- }
598
- if ($info[$j]['indic_category'] != self::OT_H && $j > $i) {
599
- /* Move Halant to after last consonant. */
600
- self::_move_info_pos($info, $i, $j+1);
601
- }
602
- break;
603
- }
604
- }
605
- }
606
-
607
- /* Attach misc marks to previous char to move with them. */
608
- $last_pos = self::POS_START;
609
- for ($i = $start; $i < $end; $i++) {
610
- if ((self::FLAG($info[$i]['indic_category']) & (self::FLAG(self::OT_ZWJ)| self::FLAG(self::OT_ZWNJ) | self::FLAG(self::OT_N) | self::FLAG (self::OT_RS) | self::FLAG (self::OT_H) | self::FLAG (self::OT_Coeng) ))) {
611
- $info[$i]['indic_position'] = $last_pos;
612
- if ($info[$i]['indic_category'] == self::OT_H && $info[$i]['indic_position'] == self::POS_PRE_M) {
613
- /*
614
- * Uniscribe doesn't move the Halant with Left Matra.
615
- * TEST: U+092B,U+093F,U+094DE
616
- * We follow. This is important for the Sinhala
617
- * U+0DDA split matra since it decomposes to U+0DD9,U+0DCA
618
- * where U+0DD9 is a left matra and U+0DCA is the virama.
619
- * We don't want to move the virama with the left matra.
620
- * TEST: U+0D9A,U+0DDA
621
- */
622
- for ($j = $i; $j > $start; $j--)
623
- if ($info[$j - 1]['indic_position'] != self::POS_PRE_M) {
624
- $info[$i]['indic_position'] = $info[$j - 1]['indic_position'];
625
- break;
626
- }
627
- }
628
- }
629
- else if ($info[$i]['indic_position'] != self::POS_SMVD) {
630
- $last_pos = $info[$i]['indic_position'];
631
- }
632
- }
633
-
634
- /* Re-attach ZWJ, ZWNJ, and halant to next char, for after-base consonants. */
635
- $last_halant = $end;
636
- for ($i = $base + 1; $i < $end; $i++) {
637
- if (self::is_halant_or_coeng($info[$i]))
638
- $last_halant = $i;
639
- else if (self::is_consonant($info[$i])) {
640
- for ($j = $last_halant; $j < $i; $j++)
641
- if ($info[$j]['indic_position'] != self::POS_SMVD)
642
- $info[$j]['indic_position'] = $info[$i]['indic_position'];
643
- }
644
- }
645
-
646
-
647
- if ($scriptblock == UCDN::SCRIPT_KHMER) {
648
- /* KHMER_FIX_2 */
649
- /* Move Coeng+RO (Halant,Ra) sequence before base consonant. */
650
- for ($i = $base + 1; $i < $end; $i++) {
651
- if (self::is_halant_or_coeng($info[$i]) && self::is_ra($info[$i + 1]['uni'])) {
652
- $info[$i]['indic_position'] = self::POS_PRE_C;
653
- $info[$i + 1]['indic_position'] = self::POS_PRE_C;
654
- break;
655
- }
656
- }
657
- }
658
-
659
-
660
- /*
661
- if (!defined("OMIT_INDIC_FIX_2") || OMIT_INDIC_FIX_2 != 1) {
662
- // INDIC_FIX_2
663
- $ZWNJ_found = false;
664
- $POST_ZWNJ_c_found = false;
665
- for ($i = $base + 1; $i < $end; $i++) {
666
- if ($info[$i]['indic_category'] == self::OT_ZWNJ) { $ZWNJ_found = true; }
667
- else if ($ZWNJ_found && $info[$i]['indic_category'] == self::OT_C) { $POST_ZWNJ_c_found = true; }
668
- else if ($POST_ZWNJ_c_found && $info[$i]['indic_position'] == self::POS_BEFORE_SUB) { $info[$i]['indic_position'] = self::POS_AFTER_SUB; }
669
- }
670
- }
671
- */
672
-
673
- /* Setup masks now */
674
- for ($i = $start; $i < $end; $i++) {
675
- $info[$i]['mask'] = 0;
676
- }
677
-
678
-
679
- if ($scriptblock == UCDN::SCRIPT_KHMER) {
680
- /* Find a Coeng+RO (Halant,Ra) sequence and mark it for pre-base processing. */
681
- $mask = self::FLAG(self::PREF);
682
- for ($i = $base; $i < $end-1; $i++) { /* KHMER_FIX_1 From $start (not base) */
683
- if (self::is_halant_or_coeng($info[$i]) && self::is_ra($info[$i + 1]['uni']) ) {
684
-
685
- $info[$i]['mask'] |= self::FLAG(self::PREF);
686
- $info[$i + 1]['mask'] |= self::FLAG(self::PREF);
687
-
688
- /* Mark the subsequent stuff with 'cfar'. Used in Khmer.
689
- * Read the feature spec.
690
- * This allows distinguishing the following cases with MS Khmer fonts:
691
- * U+1784,U+17D2,U+179A,U+17D2,U+1782 [C+Coeng+RO+Coeng+C] => Should activate CFAR
692
- * U+1784,U+17D2,U+1782,U+17D2,U+179A [C+Coeng+C+Coeng+RO] => Should NOT activate CFAR
693
- */
694
- for ($j=($i+2); $j < $end; $j++)
695
- $info[$j]['mask'] |= self::FLAG(self::CFAR);
696
-
697
- break;
698
- }
699
- }
700
- }
701
-
702
-
703
-
704
- /* Sit tight, rock 'n roll! */
705
- self::bubble_sort ($info, $start, $end - $start);
706
-
707
- /* Find base again */
708
- $base = $end;
709
- for ($i = $start; $i < $end; $i++) {
710
- if ($info[$i]['indic_position'] == self::POS_BASE_C) {
711
- $base = $i;
712
- break;
713
- }
714
- }
715
-
716
- if ($scriptblock != UCDN::SCRIPT_KHMER) {
717
- /* Reph */
718
- for ($i = $start; $i < $end; $i++) {
719
- if ($info[$i]['indic_position'] == self::POS_RA_TO_BECOME_REPH) {
720
- $info[$i]['mask'] |= self::FLAG(self::RPHF);
721
- }
722
- }
723
-
724
- /* Pre-base */
725
- $mask = self::FLAG(self::HALF);
726
- for ($i = $start; $i < $base; $i++) {
727
- $info[$i]['mask'] |= $mask;
728
- }
729
- }
730
-
731
- /* Post-base */
732
- $mask = (self::FLAG(self::BLWF) | self::FLAG(self::ABVF) | self::FLAG(self::PSTF));
733
- for ($i = $base + 1; $i < $end; $i++) {
734
- $info[$i]['mask'] |= $mask;
735
- }
736
-
737
-
738
- if ($scriptblock != UCDN::SCRIPT_KHMER) {
739
- if (!defined("OMIT_INDIC_FIX_3") || OMIT_INDIC_FIX_3 != 1) {
740
- /* INDIC_FIX_3 */
741
- /* Find a (pre-base) Consonant, Halant,Ra sequence and mark Halant|Ra for below-base BLWF processing. */
742
- // TEST CASE &#x995;&#x9cd;&#x9b0;&#x9cd;&#x995; in FreeSans versus Vrinda
743
- if (($base - $start) >= 3) {
744
- for ($i = $start; $i < ($base-2); $i++) {
745
- if (self::is_consonant($info[$i])) {
746
- if (self::is_halant_or_coeng($info[$i + 1]) && self::is_ra($info[$i + 2]['uni'])) {
747
- // If would substitute Halant+Ra...BLWF
748
- if (isset($GSUBdata['blwf'][$info[$i+2]['uni']])) {
749
- $info[$i + 1]['mask'] |= self::FLAG(self::BLWF);
750
- $info[$i + 2]['mask'] |= self::FLAG(self::BLWF);
751
- }
752
- /* If would not substitute as blwf, mark Ra+Halant for RPHF using following Halant (if present) */
753
- else if (self::is_halant_or_coeng($info[$i + 3])) {
754
- $info[$i + 2]['mask'] |= self::FLAG(self::RPHF);
755
- $info[$i + 3]['mask'] |= self::FLAG(self::RPHF);
756
- }
757
- break;
758
- }
759
- }
760
- }
761
- }
762
- }
763
- }
764
-
765
-
766
-
767
- if ($is_old_spec && $scriptblock == UCDN::SCRIPT_DEVANAGARI) {
768
- /* Old-spec eye-lash Ra needs special handling. From the spec:
769
- * "The feature 'below-base form' is applied to consonants
770
- * having below-base forms and following the base consonant.
771
- * The exception is vattu, which may appear below half forms
772
- * as well as below the base glyph. The feature 'below-base
773
- * form' will be applied to all such occurrences of Ra as well."
774
- *
775
- * Test case: U+0924,U+094D,U+0930,U+094d,U+0915
776
- * with Sanskrit 2003 font.
777
- *
778
- * However, note that Ra,Halant,ZWJ is the correct way to
779
- * request eyelash form of Ra, so we wouldbn't inhibit it
780
- * in that sequence.
781
- *
782
- * Test case: U+0924,U+094D,U+0930,U+094d,U+200D,U+0915
783
- */
784
- for ($i = $start; ($i + 1) < $base; $i++) {
785
- if ($info[$i]['indic_category'] == self::OT_Ra && $info[$i+1]['indic_category'] == self::OT_H &&
786
- ($i + 2 == $base || $info[$i+2]['indic_category'] != self::OT_ZWJ)) {
787
- $info[$i]['mask'] |= self::FLAG(self::BLWF);
788
- $info[$i+1]['mask'] |= self::FLAG(self::BLWF);
789
- }
790
- }
791
- }
792
-
793
- if ($scriptblock != UCDN::SCRIPT_KHMER) {
794
- if (count($GSUBdata['pref']) && $base + 2 < $end) {
795
- /* Find a Halant,Ra sequence and mark it for pre-base processing. */
796
- for ($i = $base + 1; $i + 1 < $end; $i++) {
797
- // If old_spec find Ra-Halant...
798
- if ((isset($GSUBdata['pref'][$info[$i + 1]['uni']]) && self::is_halant_or_coeng($info[$i]) && self::is_ra($info[$i + 1]['uni']) ) ||
799
- ($is_old_spec && isset($GSUBdata['pref'][$info[$i]['uni']]) && self::is_halant_or_coeng($info[$i + 1]) && self::is_ra($info[$i]['uni']) )
800
- ) {
801
- $info[$i++]['mask'] |= self::FLAG(self::PREF);
802
- $info[$i++]['mask'] |= self::FLAG(self::PREF);
803
- break;
804
- }
805
- }
806
- }
807
- }
808
-
809
-
810
- /* Apply ZWJ/ZWNJ effects */
811
- for ($i = $start + 1; $i < $end; $i++) {
812
- if (self::is_joiner ($info[$i])) {
813
- $non_joiner = ($info[$i]['indic_category'] == self::OT_ZWNJ);
814
- $j = $i;
815
- while ($j > $start) {
816
- if (defined("OMIT_INDIC_FIX_4") && OMIT_INDIC_FIX_4 == 1) {
817
- // INDIC_FIX_4 = do nothing - carry on //
818
- // ZWNJ should block H C from forming blwf post-base - need to unmask backwards beyond first consonant arrived at //
819
- if (!self::is_consonant($info[$j])) { break; }
820
- }
821
- $j--;
822
-
823
- /* ZWJ/ZWNJ should disable CJCT. They do that by simply
824
- * being there, since we don't skip them for the CJCT
825
- * feature (ie. F_MANUAL_ZWJ) */
826
-
827
- /* A ZWNJ disables HALF. */
828
- if ($non_joiner) {
829
- $info[$j]['mask'] &= ~(self::FLAG(self::HALF) | self::FLAG(self::BLWF));
830
- }
831
-
832
- }
833
- }
834
- }
835
- }
836
-
837
- public static function final_reordering (&$info, $GSUBdata, $indic_config, $scriptblock, $is_old_spec) {
838
- $count = count($info);
839
- if (!$count) return;
840
- $last = 0;
841
- $last_syllable = $info[0]['syllable'];
842
- for ($i = 1; $i < $count; $i++) {
843
- if ($last_syllable != $info[$i]['syllable']) {
844
- self::final_reordering_syllable ($info, $GSUBdata, $indic_config, $scriptblock, $is_old_spec, $last, $i);
845
- $last = $i;
846
- $last_syllable = $info[$last]['syllable'];
847
- }
848
- }
849
- self::final_reordering_syllable ($info, $GSUBdata, $indic_config, $scriptblock, $is_old_spec, $last, $count);
850
-
851
- }
852
-
853
- public static function final_reordering_syllable (&$info, $GSUBdata, $indic_config, $scriptblock, $is_old_spec, $start, $end) {
854
-
855
- /* 4. Final reordering:
856
- *
857
- * After the localized forms and basic shaping forms GSUB features have been
858
- * applied (see below), the shaping engine performs some final glyph
859
- * reordering before applying all the remaining font features to the entire
860
- * cluster.
861
- */
862
-
863
- /* Find base again */
864
- for ($base = $start; $base < $end; $base++)
865
- if ($info[$base]['indic_position'] >= self::POS_BASE_C) {
866
- if ($start < $base && $info[$base]['indic_position'] > self::POS_BASE_C)
867
- $base--;
868
- break;
869
- }
870
- if ($base == $end && $start < $base && $info[$base - 1]['indic_category'] != self::OT_ZWJ)
871
- $base--;
872
- while ($start < $base && isset($info[$base]) && ($info[$base]['indic_category'] == self::OT_H || $info[$base]['indic_category'] == self::OT_N))
873
- $base--;
874
-
875
-
876
- /* o Reorder matras:
877
- *
878
- * If a pre-base matra character had been reordered before applying basic
879
- * features, the glyph can be moved closer to the main consonant based on
880
- * whether half-forms had been formed. Actual position for the matra is
881
- * defined as "after last standalone halant glyph, after initial matra
882
- * position and before the main consonant". If ZWJ or ZWNJ follow this
883
- * halant, position is moved after it.
884
- */
885
-
886
-
887
- if ($start + 1 < $end && $start < $base) { /* Otherwise there can't be any pre-base matra characters. */
888
- /* If we lost track of base, alas, position before last thingy. */
889
- $new_pos = ($base == $end) ? $base - 2 : $base - 1;
890
-
891
- /* Malayalam / Tamil do not have "half" forms or explicit virama forms.
892
- * The glyphs formed by 'half' are Chillus or ligated explicit viramas.
893
- * We want to position matra after them.
894
- */
895
- if ($scriptblock != UCDN::SCRIPT_MALAYALAM && $scriptblock != UCDN::SCRIPT_TAMIL) {
896
- while ($new_pos > $start && !(self::is_one_of ($info[$new_pos], (self::FLAG(self::OT_M) | self::FLAG(self::OT_H) | self::FLAG(self::OT_Coeng)))))
897
- $new_pos--;
898
-
899
- /* If we found no Halant we are done.
900
- * Otherwise only proceed if the Halant does
901
- * not belong to the Matra itself! */
902
- if (self::is_halant_or_coeng($info[$new_pos]) && $info[$new_pos]['indic_position'] != self::POS_PRE_M) {
903
- /* -> If ZWJ or ZWNJ follow this halant, position is moved after it. */
904
- if ($new_pos + 1 < $end && self::is_joiner($info[$new_pos + 1]))
905
- $new_pos++;
906
- }
907
- else
908
- $new_pos = $start; /* No move. */
909
- }
910
-
911
- if ($start < $new_pos && $info[$new_pos]['indic_position'] != self::POS_PRE_M) {
912
- /* Now go see if there's actually any matras... */
913
- for ($i = $new_pos; $i > $start; $i--)
914
- if ($info[$i - 1]['indic_position'] == self::POS_PRE_M) {
915
- $old_pos = $i - 1;
916
- //memmove (&info[$old_pos], &info[$old_pos + 1], ($new_pos - $old_pos) * sizeof ($info[0]));
917
- self::_move_info_pos($info, $old_pos, $new_pos+1);
918
-
919
- if ($old_pos < $base && $base <= $new_pos) /* Shouldn't actually happen. */
920
- $base--;
921
- $new_pos--;
922
- }
923
- }
924
- }
925
-
926
-
927
- /* o Reorder reph:
928
- *
929
- * Reph's original position is always at the beginning of the syllable,
930
- * (i.e. it is not reordered at the character reordering stage). However,
931
- * it will be reordered according to the basic-forms shaping results.
932
- * Possible positions for reph, depending on the script, are; after main,
933
- * before post-base consonant forms, and after post-base consonant forms.
934
- */
935
-
936
- /* If there's anything after the Ra that has the REPH pos, it ought to be halant.
937
- * Which means that the font has failed to ligate the Reph. In which case, we
938
- * shouldn't move. */
939
- if ($start + 1 < $end &&
940
- $info[$start]['indic_position'] == self::POS_RA_TO_BECOME_REPH && $info[$start + 1]['indic_position'] != self::POS_RA_TO_BECOME_REPH) {
941
- $reph_pos = $indic_config[3];
942
- $skip_to_reph_step_5 = false;
943
- $skip_to_reph_move = false;
944
-
945
- /* 1. If reph should be positioned after post-base consonant forms,
946
- * proceed to step 5.
947
- */
948
- if ($reph_pos == self::REPH_POS_AFTER_POST) {
949
- $skip_to_reph_step_5 = true;
950
- }
951
-
952
- /* 2. If the reph repositioning class is not after post-base: target
953
- * position is after the first explicit halant glyph between the
954
- * first post-reph consonant and last main consonant. If ZWJ or ZWNJ
955
- * are following this halant, position is moved after it. If such
956
- * position is found, this is the target position. Otherwise,
957
- * proceed to the next step.
958
- *
959
- * Note: in old-implementation fonts, where classifications were
960
- * fixed in shaping engine, there was no case where reph position
961
- * will be found on this step.
962
- */
963
-
964
- if (!$skip_to_reph_step_5) {
965
-
966
- $new_reph_pos = $start + 1;
967
-
968
- while ($new_reph_pos < $base && !self::is_halant_or_coeng($info[$new_reph_pos]))
969
- $new_reph_pos++;
970
-
971
- if ($new_reph_pos < $base && self::is_halant_or_coeng($info[$new_reph_pos])) {
972
- /* ->If ZWJ or ZWNJ are following this halant, position is moved after it. */
973
- if ($new_reph_pos + 1 < $base && self::is_joiner ($info[$new_reph_pos + 1]))
974
- $new_reph_pos++;
975
- $skip_to_reph_move =true;
976
- }
977
- }
978
-
979
- /* 3. If reph should be repositioned after the main consonant: find the
980
- * first consonant not ligated with main, or find the first
981
- * consonant that is not a potential pre-base reordering Ra.
982
- */
983
- if ($reph_pos == self::REPH_POS_AFTER_MAIN && !$skip_to_reph_move && !$skip_to_reph_step_5) {
984
- $new_reph_pos = $base;
985
- /* XXX Skip potential pre-base reordering Ra. */
986
- while ($new_reph_pos + 1 < $end && $info[$new_reph_pos + 1]['indic_position'] <= self::POS_AFTER_MAIN)
987
- $new_reph_pos++;
988
- if ($new_reph_pos < $end)
989
- $skip_to_reph_move =true;
990
- }
991
-
992
- /* 4. If reph should be positioned before post-base consonant, find
993
- * first post-base classified consonant not ligated with main. If no
994
- * consonant is found, the target position should be before the
995
- * first matra, syllable modifier sign or vedic sign.
996
- */
997
- /* This is our take on what step 4 is trying to say (and failing, BADLY). */
998
- if ($reph_pos == self::REPH_POS_AFTER_SUB && !$skip_to_reph_move && !$skip_to_reph_step_5) {
999
- $new_reph_pos = $base;
1000
- while ($new_reph_pos < $end && isset($info[$new_reph_pos + 1]['indic_position']) &&
1001
- !( self::FLAG($info[$new_reph_pos + 1]['indic_position']) & (self::FLAG(self::POS_POST_C) | self::FLAG(self::POS_AFTER_POST) | self::FLAG(self::POS_SMVD)))) {
1002
- $new_reph_pos++;
1003
- }
1004
- if ($new_reph_pos < $end) { $skip_to_reph_move =true; }
1005
- }
1006
-
1007
- /* 5. If no consonant is found in steps 3 or 4, move reph to a position
1008
- * immediately before the first post-base matra, syllable modifier
1009
- * sign or vedic sign that has a reordering class after the intended
1010
- * reph position. For example, if the reordering position for reph
1011
- * is post-main, it will skip above-base matras that also have a
1012
- * post-main position.
1013
- */
1014
- if (!$skip_to_reph_move) {
1015
- /* Copied from step 2. */
1016
- $new_reph_pos = $start + 1;
1017
- while ($new_reph_pos < $base && !self::is_halant_or_coeng($info[$new_reph_pos]))
1018
- $new_reph_pos++;
1019
-
1020
- if ($new_reph_pos < $base && self::is_halant_or_coeng($info[$new_reph_pos])) {
1021
- /* ->If ZWJ or ZWNJ are following this halant, position is moved after it. */
1022
- if ($new_reph_pos + 1 < $base && self::is_joiner($info[$new_reph_pos + 1]))
1023
- $new_reph_pos++;
1024
- $skip_to_reph_move =true;
1025
- }
1026
- }
1027
-
1028
-
1029
- /* 6. Otherwise, reorder reph to the end of the syllable.
1030
- */
1031
- if (!$skip_to_reph_move) {
1032
- $new_reph_pos = $end - 1;
1033
- while ($new_reph_pos > $start && $info[$new_reph_pos]['indic_position'] == self::POS_SMVD)
1034
- $new_reph_pos--;
1035
-
1036
- /*
1037
- * If the Reph is to be ending up after a Matra,Halant sequence,
1038
- * position it before that Halant so it can interact with the Matra.
1039
- * However, if it's a plain Consonant,Halant we shouldn't do that.
1040
- * Uniscribe doesn't do this.
1041
- * TEST: U+0930,U+094D,U+0915,U+094B,U+094D
1042
- */
1043
- //if (!$hb_options.uniscribe_bug_compatible && self::is_halant_or_coeng($info[$new_reph_pos])) {
1044
- if (self::is_halant_or_coeng($info[$new_reph_pos])) {
1045
- for ($i = $base + 1; $i < $new_reph_pos; $i++)
1046
- if ($info[$i]['indic_category'] == self::OT_M) {
1047
- /* Ok, got it. */
1048
- $new_reph_pos--;
1049
- }
1050
- }
1051
- }
1052
-
1053
-
1054
- /* Move */
1055
- self::_move_info_pos($info, $start, $new_reph_pos+1);
1056
-
1057
- if ($start < $base && $base <= $new_reph_pos) {
1058
- $base--;
1059
- }
1060
- }
1061
-
1062
-
1063
- /* o Reorder pre-base reordering consonants:
1064
- *
1065
- * If a pre-base reordering consonant is found, reorder it according to
1066
- * the following rules:
1067
- */
1068
-
1069
-
1070
- if (count($GSUBdata['pref']) && $base + 1 < $end) { /* Otherwise there can't be any pre-base reordering Ra. */
1071
- for ($i = $base + 1; $i < $end; $i++) {
1072
- if ($info[$i]['mask'] & self::FLAG(self::PREF)) {
1073
- /* 1. Only reorder a glyph produced by substitution during application
1074
- * of the <pref> feature. (Note that a font may shape a Ra consonant with
1075
- * the feature generally but block it in certain contexts.)
1076
- */
1077
- // ??? Need to TEST if actual substitution has occurred
1078
- if ($i + 1 == $end || ($info[$i + 1]['mask'] & self::FLAG(self::PREF)) == 0) {
1079
- /*
1080
- * 2. Try to find a target position the same way as for pre-base matra.
1081
- * If it is found, reorder pre-base consonant glyph.
1082
- *
1083
- * 3. If position is not found, reorder immediately before main
1084
- * consonant.
1085
- */
1086
- $new_pos = $base;
1087
- /* Malayalam / Tamil do not have "half" forms or explicit virama forms.
1088
- * The glyphs formed by 'half' are Chillus or ligated explicit viramas.
1089
- * We want to position matra after them.
1090
- */
1091
- if ($scriptblock != UCDN::SCRIPT_MALAYALAM && $scriptblock != UCDN::SCRIPT_TAMIL) {
1092
- while ($new_pos > $start &&
1093
- !(self::is_one_of($info[$new_pos - 1], self::FLAG(self::OT_M) | self::FLAG(self::OT_H) | self::FLAG(self::OT_Coeng))))
1094
- $new_pos--;
1095
-
1096
- /* In Khmer coeng model, a V,Ra can go *after* matras. If it goes after a
1097
- * split matra, it should be reordered to *before* the left part of such matra. */
1098
- if ($new_pos > $start && $info[$new_pos - 1]['indic_category'] == self::OT_M) {
1099
- $old_pos = i;
1100
- for ($i = $base + 1; $i < $old_pos; $i++)
1101
- if ($info[$i]['indic_category'] == self::OT_M) {
1102
- $new_pos--;
1103
- break;
1104
- }
1105
- }
1106
- }
1107
-
1108
- if ($new_pos > $start && self::is_halant_or_coeng($info[$new_pos - 1])) {
1109
- /* -> If ZWJ or ZWNJ follow this halant, position is moved after it. */
1110
- if ($new_pos < $end && self::is_joiner($info[$new_pos]))
1111
- $new_pos++;
1112
- }
1113
-
1114
- $old_pos = $i;
1115
- self::_move_info_pos($info, $old_pos, $new_pos);
1116
-
1117
- if ($new_pos <= $base && $base < $old_pos)
1118
- $base++;
1119
- }
1120
-
1121
- break;
1122
- }
1123
- }
1124
- }
1125
-
1126
-
1127
- /* Apply 'init' to the Left Matra if it's a word start. */
1128
- if ($info[$start]['indic_position'] == self::POS_PRE_M &&
1129
- ($start==0 ||
1130
- ($info[$start - 1]['general_category'] < UCDN::UNICODE_GENERAL_CATEGORY_FORMAT || $info[$start - 1]['general_category'] > UCDN::UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)
1131
- )) {
1132
- $info[$start]['mask'] |= self::FLAG(self::INIT);
1133
- }
1134
-
1135
-
1136
- /*
1137
- * Finish off and go home!
1138
- */
1139
-
1140
- }
1141
-
1142
- function _move_info_pos(&$info, $from, $to) {
1143
- $t = array();
1144
- $t[0] = $info[$from];
1145
- if ($from > $to) {
1146
- array_splice($info, $from, 1);
1147
- array_splice($info, $to, 0, $t);
1148
- }
1149
- else {
1150
- array_splice($info, $to, 0, $t);
1151
- array_splice($info, $from, 1);
1152
- }
1153
- }
1154
-
1155
-
1156
- public static $ra_chars = array(
1157
- 0x0930 => 1, /* Devanagari */
1158
- 0x09B0 => 1, /* Bengali */
1159
- 0x09F0 => 1, /* Bengali (Assamese) */
1160
- 0x0A30 => 1, /* Gurmukhi */ /* No Reph */
1161
- 0x0AB0 => 1, /* Gujarati */
1162
- 0x0B30 => 1, /* Oriya */
1163
- 0x0BB0 => 1, /* Tamil */ /* No Reph */
1164
- 0x0C30 => 1, /* Telugu */ /* Reph formed only with ZWJ */
1165
- 0x0CB0 => 1, /* Kannada */
1166
- 0x0D30 => 1, /* Malayalam */ /* No Reph, Logical Repha */
1167
-
1168
- 0x0DBB => 1, /* Sinhala */ /* Reph formed only with ZWJ */
1169
- 0x179A => 1, /* Khmer */ /* No Reph, Visual Repha */
1170
- );
1171
-
1172
- public static function is_ra ($u) {
1173
- if (isset(self::$ra_chars[$u])) return true;
1174
- return false;
1175
- }
1176
-
1177
- public static function is_one_of ($info, $flags) {
1178
- if (isset($info['is_ligature']) && $info['is_ligature']) return false; /* If it ligated, all bets are off. */
1179
- return !!(self::FLAG($info['indic_category']) & $flags);
1180
- }
1181
-
1182
- public static function is_joiner($info) {
1183
- return self::is_one_of ($info, (self::FLAG(self::OT_ZWJ) | self::FLAG(self::OT_ZWNJ)));
1184
- }
1185
-
1186
-
1187
- /* Vowels and placeholders treated as if they were consonants. */
1188
- public static function is_consonant($info) {
1189
- return self::is_one_of($info, (self::FLAG(self::OT_C) | self::FLAG(self::OT_CM) | self::FLAG(self::OT_Ra) | self::FLAG(self::OT_V) | self::FLAG(self::OT_NBSP) | self::FLAG(self::OT_DOTTEDCIRCLE)));
1190
- }
1191
-
1192
-
1193
- public static function is_halant_or_coeng($info) {
1194
- return self::is_one_of($info, (self::FLAG(self::OT_H) | self::FLAG(self::OT_Coeng)));
1195
- }
1196
-
1197
-
1198
-
1199
- // From hb-private.hh
1200
- public static function in_range ($u, $lo, $hi) {
1201
- if ( (($lo^$hi) & $lo) == 0 && (($lo^$hi) & $hi) == ($lo^$hi) && (($lo^$hi) & (($lo^$hi) + 1)) == 0 )
1202
- return ($u & ~($lo^$hi)) == $lo;
1203
- else
1204
- return $lo <= $u && $u <= $hi;
1205
- }
1206
- // From hb-private.hh
1207
- public static function FLAG($x) { return (1<<($x)); }
1208
-
1209
-
1210
- // BELOW from hb-ot-shape-complex-indic.cc
1211
-
1212
- /*
1213
- * Indic configurations.
1214
- */
1215
-
1216
- // base_position
1217
- const BASE_POS_FIRST = 0;
1218
- const BASE_POS_LAST = 1;
1219
-
1220
- // reph_position
1221
- const REPH_POS_DEFAULT = 10; // POS_BEFORE_POST,
1222
-
1223
- const REPH_POS_AFTER_MAIN = 5; // POS_AFTER_MAIN,
1224
- const REPH_POS_BEFORE_SUB = 7; // POS_BEFORE_SUB,
1225
- const REPH_POS_AFTER_SUB = 9; // POS_AFTER_SUB,
1226
- const REPH_POS_BEFORE_POST = 10; // POS_BEFORE_POST,
1227
- const REPH_POS_AFTER_POST = 12; // POS_AFTER_POST
1228
-
1229
- // reph_mode
1230
- const REPH_MODE_IMPLICIT = 0; /* Reph formed out of initial Ra,H sequence. */
1231
- const REPH_MODE_EXPLICIT = 1; /* Reph formed out of initial Ra,H,ZWJ sequence. */
1232
- const REPH_MODE_VIS_REPHA = 2; /* Encoded Repha character, no reordering needed. */
1233
- const REPH_MODE_LOG_REPHA = 3; /* Encoded Repha character, needs reordering. */
1234
-
1235
-
1236
-
1237
- /*
1238
- struct of indic_configs{
1239
- KEY - script;
1240
- 0 - has_old_spec;
1241
- 1 - virama;
1242
- 2 - base_pos;
1243
- 3 - reph_pos;
1244
- 4 - reph_mode;
1245
- };
1246
- */
1247
-
1248
- public static $indic_configs = array( /* index is SCRIPT_number from UCDN */
1249
- 9 => array(true, 0x094D, 1, 10, 0),
1250
- 10 => array(true, 0x09CD, 1, 9, 0),
1251
- 11 => array(true, 0x0A4D, 1, 7, 0),
1252
- 12 => array(true, 0x0ACD, 1, 10, 0),
1253
- 13 => array(true, 0x0B4D, 1, 5, 0),
1254
- 14 => array(true, 0x0BCD, 1, 12, 0),
1255
- 15 => array(true, 0x0C4D, 1, 12, 1),
1256
- 16 => array(true, 0x0CCD, 1, 12, 0),
1257
- 17 => array(true, 0x0D4D, 1, 5, 3),
1258
- 18 => array(false, 0x0DCA, 0, 5, 1), /* Sinhala */
1259
- 30 => array(false, 0x17D2, 0, 10, 2), /* Khmer */
1260
- 84 => array(false, 0xA9C0, 1, 10, 0), /* Javanese */
1261
-
1262
- );
1263
-
1264
-
1265
-
1266
- /*
1267
-
1268
- // from "hb-ot-shape-complex-indic-table.cc"
1269
-
1270
-
1271
- const ISC_A = 0; // INDIC_SYLLABIC_CATEGORY_AVAGRAHA Avagraha
1272
- const ISC_Bi = 8; // INDIC_SYLLABIC_CATEGORY_BINDU Bindu
1273
- const ISC_C = 1; // INDIC_SYLLABIC_CATEGORY_CONSONANT Consonant
1274
- const ISC_CD = 1; // INDIC_SYLLABIC_CATEGORY_CONSONANT_DEAD Consonant_Dead
1275
- const ISC_CF = 17; // INDIC_SYLLABIC_CATEGORY_CONSONANT_FINAL Consonant_Final
1276
- const ISC_CHL = 1; // INDIC_SYLLABIC_CATEGORY_CONSONANT_HEAD_LETTER Consonant_Head_Letter
1277
- const ISC_CM = 17; // INDIC_SYLLABIC_CATEGORY_CONSONANT_MEDIAL Consonant_Medial
1278
- const ISC_CP = 11; // INDIC_SYLLABIC_CATEGORY_CONSONANT_PLACEHOLDER Consonant_Placeholder
1279
- const ISC_CR = 15; // INDIC_SYLLABIC_CATEGORY_CONSONANT_REPHA Consonant_Repha
1280
- const ISC_CS = 1; // INDIC_SYLLABIC_CATEGORY_CONSONANT_SUBJOINED Consonant_Subjoined
1281
- const ISC_ML = 0; // INDIC_SYLLABIC_CATEGORY_MODIFYING_LETTER Modifying_Letter
1282
- const ISC_N = 3; // INDIC_SYLLABIC_CATEGORY_NUKTA Nukta
1283
- const ISC_x = 0; // INDIC_SYLLABIC_CATEGORY_OTHER Other
1284
- const ISC_RS = 13; // INDIC_SYLLABIC_CATEGORY_REGISTER_SHIFTER Register_Shifter
1285
- const ISC_TL = 0; // INDIC_SYLLABIC_CATEGORY_TONE_LETTER Tone_Letter
1286
- const ISC_TM = 3; // INDIC_SYLLABIC_CATEGORY_TONE_MARK Tone_Mark
1287
- const ISC_V = 4; // INDIC_SYLLABIC_CATEGORY_VIRAMA Virama
1288
- const ISC_Vs = 8; // INDIC_SYLLABIC_CATEGORY_VISARGA Visarga
1289
- const ISC_Vo = 2; // INDIC_SYLLABIC_CATEGORY_VOWEL Vowel
1290
- const ISC_M = 7; // INDIC_SYLLABIC_CATEGORY_VOWEL_DEPENDENT Vowel_Dependent
1291
- const ISC_VI = 2; // INDIC_SYLLABIC_CATEGORY_VOWEL_INDEPENDENT Vowel_Independent
1292
-
1293
- const IMC_B = 8; // INDIC_MATRA_CATEGORY_BOTTOM Bottom
1294
- const IMC_BR = 11; // INDIC_MATRA_CATEGORY_BOTTOM_AND_RIGHT Bottom_And_Right
1295
- const IMC_I = 15; // INDIC_MATRA_CATEGORY_INVISIBLE Invisible
1296
- const IMC_L = 3; // INDIC_MATRA_CATEGORY_LEFT Left
1297
- const IMC_LR = 11; // INDIC_MATRA_CATEGORY_LEFT_AND_RIGHT Left_And_Right
1298
- const IMC_x = 15; // INDIC_MATRA_CATEGORY_NOT_APPLICABLE Not_Applicable
1299
- const IMC_O = 5; // INDIC_MATRA_CATEGORY_OVERSTRUCK Overstruck
1300
- const IMC_R = 11; // INDIC_MATRA_CATEGORY_RIGHT Right
1301
- const IMC_T = 6; // INDIC_MATRA_CATEGORY_TOP Top
1302
- const IMC_TB = 8; // INDIC_MATRA_CATEGORY_TOP_AND_BOTTOM Top_And_Bottom
1303
- const IMC_TBR = 11; // INDIC_MATRA_CATEGORY_TOP_AND_BOTTOM_AND_RIGHT Top_And_Bottom_And_Right
1304
- const IMC_TL = 6; // INDIC_MATRA_CATEGORY_TOP_AND_LEFT Top_And_Left
1305
- const IMC_TLR = 11; // INDIC_MATRA_CATEGORY_TOP_AND_LEFT_AND_RIGHT Top_And_Left_And_Right
1306
- const IMC_TR = 11; // INDIC_MATRA_CATEGORY_TOP_AND_RIGHT Top_And_Right
1307
- const IMC_VOL = 2; // INDIC_MATRA_CATEGORY_VISUAL_ORDER_LEFT Visual_Order_Left
1308
-
1309
- If in original table = _(C,x), that = ISC_C,IMC_x
1310
- Value is IMC_x << 8 (or IMC_x * 256) = 3840
1311
- plus ISC_C = 1, so = 3841
1312
-
1313
- */
1314
-
1315
-
1316
-
1317
- public static $indic_table = array(
1318
-
1319
- /* Devanagari (0900..097F) */
1320
-
1321
- /* 0900 */ 3848,3848,3848,3848,3842,3842,3842,3842,
1322
- /* 0908 */ 3842,3842,3842,3842,3842,3842,3842,3842,
1323
- /* 0910 */ 3842,3842,3842,3842,3842, 3841, 3841, 3841,
1324
- /* 0918 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1325
- /* 0920 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1326
- /* 0928 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1327
- /* 0930 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1328
- /* 0938 */ 3841, 3841, 1543, 2823, 3843, 3840, 2823, 775,
1329
- /* 0940 */ 2823, 2055, 2055, 2055, 2055, 1543, 1543, 1543,
1330
- /* 0948 */ 1543, 2823, 2823, 2823, 2823, 2052, 775, 2823,
1331
- /* 0950 */ 3840, 3840, 3840, 3840, 3840, 1543, 2055, 2055,
1332
- /* 0958 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1333
- /* 0960 */ 3842,3842, 2055, 2055, 3840, 3840, 3840, 3840,
1334
- /* 0968 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1335
- /* 0970 */ 3840, 3840,3842,3842,3842,3842,3842,3842,
1336
- /* 0978 */ 3840, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1337
-
1338
- /* Bengali (0980..09FF) */
1339
-
1340
- /* 0980 */ 3840,3848,3848,3848, 3840,3842,3842,3842,
1341
- /* 0988 */ 3842,3842,3842,3842,3842, 3840, 3840,3842,
1342
- /* 0990 */ 3842, 3840, 3840,3842,3842, 3841, 3841, 3841,
1343
- /* 0998 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1344
- /* 09A0 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1345
- /* 09A8 */ 3841, 3840, 3841, 3841, 3841, 3841, 3841, 3841,
1346
- /* 09B0 */ 3841, 3840, 3841, 3840, 3840, 3840, 3841, 3841,
1347
- /* 09B8 */ 3841, 3841, 3840, 3840, 3843, 3840, 2823, 775,
1348
- /* 09C0 */ 2823, 2055, 2055, 2055, 2055, 3840, 3840, 775,
1349
- /* 09C8 */ 775, 3840, 3840,2823,2823, 2052,3841, 3840,
1350
- /* 09D0 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 2823,
1351
- /* 09D8 */ 3840, 3840, 3840, 3840, 3841, 3841, 3840, 3841,
1352
- /* 09E0 */ 3842,3842, 2055, 2055, 3840, 3840, 3840, 3840,
1353
- /* 09E8 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1354
- /* 09F0 */ 3841, 3841, 3840, 3840, 3840, 3840, 3840, 3840,
1355
- /* 09F8 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1356
-
1357
- /* Gurmukhi (0A00..0A7F) */
1358
-
1359
- /* 0A00 */ 3840,3848,3848,3848, 3840,3842,3842,3842,
1360
- /* 0A08 */ 3842,3842,3842, 3840, 3840, 3840, 3840,3842,
1361
- /* 0A10 */ 3842, 3840, 3840,3842,3842, 3841, 3841, 3841,
1362
- /* 0A18 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1363
- /* 0A20 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1364
- /* 0A28 */ 3841, 3840, 3841, 3841, 3841, 3841, 3841, 3841,
1365
- /* 0A30 */ 3841, 3840, 3841, 3841, 3840, 3841, 3841, 3840,
1366
- /* 0A38 */ 3841, 3841, 3840, 3840, 3843, 3840, 2823, 775,
1367
- /* 0A40 */ 2823, 2055, 2055, 3840, 3840, 3840, 3840, 1543,
1368
- /* 0A48 */ 1543, 3840, 3840, 1543, 1543, 2052, 3840, 3840,
1369
- /* 0A50 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1370
- /* 0A58 */ 3840, 3841, 3841, 3841, 3841, 3840, 3841, 3840,
1371
- /* 0A60 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1372
- /* 0A68 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1373
- /* 0A70 */ 3848, 3840,13841,13841, 3840, 3857, 3840, 3840,
1374
- /* 0A78 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1375
-
1376
- /* Gujarati (0A80..0AFF) */
1377
-
1378
- /* 0A80 */ 3840,3848,3848,3848, 3840,3842,3842,3842,
1379
- /* 0A88 */ 3842,3842,3842,3842,3842,3842, 3840,3842,
1380
- /* 0A90 */ 3842,3842, 3840,3842,3842, 3841, 3841, 3841,
1381
- /* 0A98 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1382
- /* 0AA0 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1383
- /* 0AA8 */ 3841, 3840, 3841, 3841, 3841, 3841, 3841, 3841,
1384
- /* 0AB0 */ 3841, 3840, 3841, 3841, 3840, 3841, 3841, 3841,
1385
- /* 0AB8 */ 3841, 3841, 3840, 3840, 3843, 3840, 2823, 775,
1386
- /* 0AC0 */ 2823, 2055, 2055, 2055, 2055, 1543, 3840, 1543,
1387
- /* 0AC8 */ 1543,2823, 3840, 2823, 2823, 2052, 3840, 3840,
1388
- /* 0AD0 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1389
- /* 0AD8 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1390
- /* 0AE0 */ 3842,3842, 2055, 2055, 3840, 3840, 3840, 3840,
1391
- /* 0AE8 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1392
- /* 0AF0 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1393
- /* 0AF8 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1394
-
1395
- /* Oriya (0B00..0B7F) */
1396
-
1397
- /* 0B00 */ 3840,3848,3848,3848, 3840,3842,3842,3842,
1398
- /* 0B08 */ 3842,3842,3842,3842,3842, 3840, 3840,3842,
1399
- /* 0B10 */ 3842, 3840, 3840,3842,3842, 3841, 3841, 3841,
1400
- /* 0B18 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1401
- /* 0B20 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1402
- /* 0B28 */ 3841, 3840, 3841, 3841, 3841, 3841, 3841, 3841,
1403
- /* 0B30 */ 3841, 3840, 3841, 3841, 3840, 3841, 3841, 3841,
1404
- /* 0B38 */ 3841, 3841, 3840, 3840, 3843, 3840, 2823, 1543,
1405
- /* 0B40 */ 2823, 2055, 2055, 2055, 2055, 3840, 3840, 775,
1406
- /* 0B48 */ 1543, 3840, 3840,2823,2823,2052, 3840, 3840,
1407
- /* 0B50 */ 3840, 3840, 3840, 3840, 3840, 3840, 1543,2823,
1408
- /* 0B58 */ 3840, 3840, 3840, 3840, 3841, 3841, 3840, 3841,
1409
- /* 0B60 */ 3842,3842, 2055, 2055, 3840, 3840, 3840, 3840,
1410
- /* 0B68 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1411
- /* 0B70 */ 3840, 3841, 3840, 3840, 3840, 3840, 3840, 3840,
1412
- /* 0B78 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1413
-
1414
- /* Tamil (0B80..0BFF) */
1415
-
1416
- /* 0B80 */ 3840, 3840, 3848, 3840, 3840, 3842, 3842, 3842,
1417
- /* 0B88 */ 3842, 3842, 3842, 3840, 3840, 3840, 3842,3842,
1418
- /* 0B90 */ 3842, 3840, 3842, 3842, 3842, 3841, 3840, 3840,
1419
- /* 0B98 */ 3840, 3841, 3841, 3840, 3841, 3840, 3841, 3841,
1420
- /* 0BA0 */ 3840, 3840, 3840, 3841, 3841, 3840, 3840, 3840,
1421
- /* 0BA8 */ 3841, 3841, 3841, 3840, 3840, 3840, 3841, 3841,
1422
- /* 0BB0 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1423
- /* 0BB8 */ 3841, 3841, 3840, 3840, 3840, 3840, 2823, 2823,
1424
- /* 0BC0 */ 1543, 2055, 2055, 3840, 3840, 3840, 775, 775,
1425
- /* 0BC8 */ 775, 3840, 2823, 2823, 2823, 1540, 3840, 3840,
1426
- /* 0BD0 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 2823,
1427
- /* 0BD8 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1428
- /* 0BE0 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1429
- /* 0BE8 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1430
- /* 0BF0 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1431
- /* 0BF8 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1432
-
1433
- /* Telugu (0C00..0C7F) */
1434
-
1435
- /* 0C00 */ 3840,3848,3848,3848, 3840,3842,3842,3842,
1436
- /* 0C08 */ 3842,3842,3842,3842,3842, 3840,3842,3842,
1437
- /* 0C10 */ 3842, 3840,3842,3842,3842, 3841, 3841, 3841,
1438
- /* 0C18 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1439
- /* 0C20 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1440
- /* 0C28 */ 3841, 3840, 3841, 3841, 3841, 3841, 3841, 3841,
1441
- /* 0C30 */ 3841, 3841, 3841, 3841, 3840, 3841, 3841, 3841,
1442
- /* 0C38 */ 3841, 3841, 3840, 3840, 3840, 3840, 1543, 1543,
1443
- /* 0C40 */ 1543, 2823, 2823, 2823, 2823, 3840, 1543, 1543,
1444
- /* 0C48 */ 2055, 3840, 1543, 1543, 1543, 1540, 3840, 3840,
1445
- /* 0C50 */ 3840, 3840, 3840, 3840, 3840, 1543, 2055, 3840,
1446
- /* 0C58 */ 3841, 3841, 3840, 3840, 3840, 3840, 3840, 3840,
1447
- /* 0C60 */ 3842,3842, 2055, 2055, 3840, 3840, 3840, 3840,
1448
- /* 0C68 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1449
- /* 0C70 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1450
- /* 0C78 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1451
-
1452
- /* Kannada (0C80..0CFF) */
1453
-
1454
- /* 0C80 */ 3840, 3840,3848,3848, 3840,3842,3842,3842,
1455
- /* 0C88 */ 3842,3842,3842,3842,3842, 3840,3842,3842,
1456
- /* 0C90 */ 3842, 3840,3842,3842,3842, 3841, 3841, 3841,
1457
- /* 0C98 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1458
- /* 0CA0 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1459
- /* 0CA8 */ 3841, 3840, 3841, 3841, 3841, 3841, 3841, 3841,
1460
- /* 0CB0 */ 3841, 3841, 3841, 3841, 3840, 3841, 3841, 3841,
1461
- /* 0CB8 */ 3841, 3841, 3840, 3840, 3843, 3840, 2823, 1543,
1462
- /* 0CC0 */ 2823, 2823, 2823, 2823, 2823, 3840, 1543,2823,
1463
- /* 0CC8 */ 2823, 3840,2823,2823, 1543, 1540, 3840, 3840,
1464
- /* 0CD0 */ 3840, 3840, 3840, 3840, 3840, 2823, 2823, 3840,
1465
- /* 0CD8 */ 3840, 3840, 3840, 3840, 3840, 3840, 3841, 3840,
1466
- /* 0CE0 */ 3842,3842, 2055, 2055, 3840, 3840, 3840, 3840,
1467
- /* 0CE8 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1468
- /* 0CF0 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1469
- /* 0CF8 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1470
-
1471
- /* Malayalam (0D00..0D7F) */
1472
-
1473
- /* 0D00 */ 3840, 3840,3848,3848, 3840,3842,3842,3842,
1474
- /* 0D08 */ 3842,3842,3842,3842,3842, 3840,3842,3842,
1475
- /* 0D10 */ 3842, 3840,3842,3842,3842, 3841, 3841, 3841,
1476
- /* 0D18 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1477
- /* 0D20 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1478
- /* 0D28 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1479
- /* 0D30 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1480
- /* 0D38 */ 3841, 3841, 3841, 3840, 3840, 3840, 2823, 2823,
1481
- /* 0D40 */ 2823, 2823, 2823, 2055, 2055, 3840, 775, 775,
1482
- /* 0D48 */ 775, 3840,2823,2823,2823, 1540, 3855, 3840,
1483
- /* 0D50 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 2823,
1484
- /* 0D58 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1485
- /* 0D60 */ 3842,3842, 2055, 2055, 3840, 3840, 3840, 3840,
1486
- /* 0D68 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1487
- /* 0D70 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1488
- /* 0D78 */ 3840, 3840,3841,3841,3841,3841,3841,3841,
1489
-
1490
- /* Sinhala (0D80..0DFF) */
1491
-
1492
- /* 0D80 */ 3840, 3840, 3848, 3848, 3840, 3842, 3842, 3842,
1493
- /* 0D88 */ 3842, 3842, 3842, 3842, 3842, 3842, 3842, 3842,
1494
- /* 0D90 */ 3842, 3842, 3842, 3842, 3842, 3842, 3842, 3840,
1495
- /* 0D98 */ 3840, 3840, 3841, 3841, 3841, 3841, 3841, 3841,
1496
- /* 0DA0 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1497
- /* 0DA8 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1498
- /* 0DB0 */ 3841, 3841, 3840, 3841, 3841, 3841, 3841, 3841,
1499
- /* 0DB8 */ 3841, 3841, 3841, 3841, 3840, 3841, 3840, 3840,
1500
- /* 0DC0 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3840,
1501
- /* 0DC8 */ 3840, 3840, 1540, 3840, 3840, 3840, 3840, 2823,
1502
- /* 0DD0 */ 2823, 2823, 1543, 1543, 2055, 3840, 2055, 3840,
1503
- /* 0DD8 */ 2823, 775, 1543, 775, 2823, 2823, 2823, 2823,
1504
- /* 0DE0 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1505
- /* 0DE8 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1506
- /* 0DF0 */ 3840, 3840, 2823, 2823, 3840, 3840, 3840, 3840,
1507
- /* 0DF8 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1508
-
1509
-
1510
- /* Vedic Extensions (1CD0..1CFF) */
1511
-
1512
- /* 1CD0 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1513
- /* 1CD8 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1514
- /* 1CE0 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1515
- /* 1CE8 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1516
- /* 1CF0 */ 3840, 3840,3848,3848, 3840, 3840, 3840, 3840,
1517
- /* 1CF8 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1518
-
1519
-
1520
- );
1521
-
1522
- public static $khmer_table = array(
1523
-
1524
- /* Khmer (1780..17FF) */
1525
-
1526
- /* 1780 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1527
- /* 1788 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1528
- /* 1790 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1529
- /* 1798 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
1530
- /* 17A0 */ 3841, 3841, 3841, 3842, 3842, 3842, 3842, 3842,
1531
- /* 17A8 */ 3842, 3842, 3842, 3842, 3842, 3842, 3842, 3842,
1532
- /* 17B0 */ 3842, 3842, 3842, 3842, 3840, 3840, 2823, 1543,
1533
- /* 17B8 */ 1543, 1543, 1543, 2055, 2055, 2055, 1543,2823,
1534
- /* 17C0 */ 2823, 775, 775, 775, 2823, 2823, 3848, 3848,
1535
- /* 17C8 */ 2823, 3853, 3853, 3840, 3855, 3840, 3840, 3840,
1536
- /* 17D0 */ 3840, 1540, 3844, 3840, 3840, 3840, 3840, 3840,
1537
- /* 17D8 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1538
- /* 17E0 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1539
- /* 17E8 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1540
- /* 17F0 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1541
- /* 17F8 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
1542
-
1543
-
1544
- );
1545
-
1546
-
1547
-
1548
- // from "hb-ot-shape-complex-indic-table.cc"
1549
- public static function indic_get_categories ($u) {
1550
- if (0x0900 <= $u && $u <= 0x0DFF) return self::$indic_table[$u - 0x0900 + 0]; // offset 0 for Most "indic"
1551
- if (0x1CD0 <= $u && $u <= 0x1D00) return self::$indic_table[$u - 0x1CD0 + 1152]; // offset for Vedic extensions
1552
- if (0x1780 <= $u && $u <= 0x17FF) return self::$khmer_table[$u - 0x1780]; // Khmer
1553
- if ($u == 0x00A0) return 3851; // (ISC_CP | (IMC_x << 8))
1554
- if ($u == 0x25CC) return 3851; // (ISC_CP | (IMC_x << 8))
1555
- return 3840; // (ISC_x | (IMC_x << 8))
1556
- }
1557
-
1558
- // BELOW from hb-ot-shape-complex-indic.cc
1559
- /*
1560
- * Indic shaper.
1561
- */
1562
-
1563
- public static function IN_HALF_BLOCK($u, $Base) { return (($u & ~0x7F) == $Base); }
1564
-
1565
- public static function IS_DEVA($u) { return self::IN_HALF_BLOCK ($u, 0x0900); }
1566
- public static function IS_BENG($u) { return self::IN_HALF_BLOCK ($u, 0x0980); }
1567
- public static function IS_GURU($u) { return self::IN_HALF_BLOCK ($u, 0x0A00); }
1568
- public static function IS_GUJR($u) { return self::IN_HALF_BLOCK ($u, 0x0A80); }
1569
- public static function IS_ORYA($u) { return self::IN_HALF_BLOCK ($u, 0x0B00); }
1570
- public static function IS_TAML($u) { return self::IN_HALF_BLOCK ($u, 0x0B80); }
1571
- public static function IS_TELU($u) { return self::IN_HALF_BLOCK ($u, 0x0C00); }
1572
- public static function IS_KNDA($u) { return self::IN_HALF_BLOCK ($u, 0x0C80); }
1573
- public static function IS_MLYM($u) { return self::IN_HALF_BLOCK ($u, 0x0D00); }
1574
- public static function IS_SINH($u) { return self::IN_HALF_BLOCK ($u, 0x0D80); }
1575
- public static function IS_KHMR($u) { return self::IN_HALF_BLOCK ($u, 0x1780); }
1576
-
1577
-
1578
- public static function MATRA_POS_LEFT($u) { return self::POS_PRE_M; }
1579
- public static function MATRA_POS_RIGHT($u) { return
1580
- (self::IS_DEVA($u) ? self::POS_AFTER_SUB :
1581
- (self::IS_BENG($u) ? self::POS_AFTER_POST :
1582
- (self::IS_GURU($u) ? self::POS_AFTER_POST :
1583
- (self::IS_GUJR($u) ? self::POS_AFTER_POST :
1584
- (self::IS_ORYA($u) ? self::POS_AFTER_POST :
1585
- (self::IS_TAML($u) ? self::POS_AFTER_POST :
1586
- (self::IS_TELU($u) ? ($u <= 0x0C42 ? self::POS_BEFORE_SUB : self::POS_AFTER_SUB) :
1587
- (self::IS_KNDA($u) ? ($u < 0x0CC3 || $u > 0xCD6 ? self::POS_BEFORE_SUB : self::POS_AFTER_SUB) :
1588
- (self::IS_MLYM($u) ? self::POS_AFTER_POST :
1589
- (self::IS_SINH($u) ? self::POS_AFTER_SUB :
1590
- (self::IS_KHMR($u) ? self::POS_AFTER_POST :
1591
- self::POS_AFTER_SUB))))))))))); /*default*/
1592
- }
1593
- public static function MATRA_POS_TOP($u) { return /* BENG and MLYM don't have top matras. */
1594
- (self::IS_DEVA($u) ? self::POS_AFTER_SUB :
1595
- (self::IS_GURU($u) ? self::POS_AFTER_POST : /* Deviate from spec */
1596
- (self::IS_GUJR($u) ? self::POS_AFTER_SUB :
1597
- (self::IS_ORYA($u) ? self::POS_AFTER_MAIN :
1598
- (self::IS_TAML($u) ? self::POS_AFTER_SUB :
1599
- (self::IS_TELU($u) ? self::POS_BEFORE_SUB :
1600
- (self::IS_KNDA($u) ? self::POS_BEFORE_SUB :
1601
- (self::IS_SINH($u) ? self::POS_AFTER_SUB :
1602
- (self::IS_KHMR($u) ? self::POS_AFTER_POST :
1603
- self::POS_AFTER_SUB))))))))); /*default*/
1604
- }
1605
- public static function MATRA_POS_BOTTOM($u) { return
1606
- (self::IS_DEVA($u) ? self::POS_AFTER_SUB :
1607
- (self::IS_BENG($u) ? self::POS_AFTER_SUB :
1608
- (self::IS_GURU($u) ? self::POS_AFTER_POST :
1609
- (self::IS_GUJR($u) ? self::POS_AFTER_POST :
1610
- (self::IS_ORYA($u) ? self::POS_AFTER_SUB :
1611
- (self::IS_TAML($u) ? self::POS_AFTER_POST :
1612
- (self::IS_TELU($u) ? self::POS_BEFORE_SUB :
1613
- (self::IS_KNDA($u) ? self::POS_BEFORE_SUB :
1614
- (self::IS_MLYM($u) ? self::POS_AFTER_POST :
1615
- (self::IS_SINH($u) ? self::POS_AFTER_SUB :
1616
- (self::IS_KHMR($u) ? self::POS_AFTER_POST :
1617
- self::POS_AFTER_SUB))))))))))); /*default*/
1618
- }
1619
-
1620
- public static function matra_position ($u, $side) {
1621
- switch ($side) {
1622
- case self::POS_PRE_C: return self::MATRA_POS_LEFT($u);
1623
- case self::POS_POST_C: return self::MATRA_POS_RIGHT($u);
1624
- case self::POS_ABOVE_C: return self::MATRA_POS_TOP($u);
1625
- case self::POS_BELOW_C: return self::MATRA_POS_BOTTOM($u);
1626
- }
1627
- return $side;
1628
- }
1629
-
1630
- // vowel matras that have to be split into two parts.
1631
- // From Harfbuzz (old)
1632
- // New HarfBuzz uses /src/hb-ucdn/ucdn.c and unicodedata_db.h for full method of decomposition for all characters
1633
- // Should always fully decompose and then recompose back, but we will just do the split matras
1634
- public static function decompose_indic($ab) {
1635
- $sub = array();
1636
- switch ($ab) {
1637
- /*
1638
- * Decompose split matras.
1639
- */
1640
- /* bengali */
1641
- case 0x9cb : $sub[0] = 0x9c7; $sub[1]= 0x9be; return $sub;
1642
- case 0x9cc : $sub[0] = 0x9c7; $sub[1]= 0x9d7; return $sub;
1643
- /* oriya */
1644
- case 0xb48 : $sub[0] = 0xb47; $sub[1]= 0xb56; return $sub;
1645
- case 0xb4b : $sub[0] = 0xb47; $sub[1]= 0xb3e; return $sub;
1646
- case 0xb4c : $sub[0] = 0xb47; $sub[1]= 0xb57; return $sub;
1647
- /* tamil */
1648
- case 0xbca : $sub[0] = 0xbc6; $sub[1]= 0xbbe; return $sub;
1649
- case 0xbcb : $sub[0] = 0xbc7; $sub[1]= 0xbbe; return $sub;
1650
- case 0xbcc : $sub[0] = 0xbc6; $sub[1]= 0xbd7; return $sub;
1651
- /* telugu */
1652
- case 0xc48 : $sub[0] = 0xc46; $sub[1]= 0xc56; return $sub;
1653
- /* kannada */
1654
- case 0xcc0 : $sub[0] = 0xcbf; $sub[1]= 0xcd5; return $sub;
1655
- case 0xcc7 : $sub[0] = 0xcc6; $sub[1]= 0xcd5; return $sub;
1656
- case 0xcc8 : $sub[0] = 0xcc6; $sub[1]= 0xcd6; return $sub;
1657
- case 0xcca : $sub[0] = 0xcc6; $sub[1]= 0xcc2; return $sub;
1658
- case 0xccb : $sub[0] = 0xcc6; $sub[1]= 0xcc2; $sub[2]= 0xcd5; return $sub;
1659
- /* malayalam */
1660
- case 0xd4a : $sub[0] = 0xd46; $sub[1]= 0xd3e; return $sub;
1661
- case 0xd4b : $sub[0] = 0xd47; $sub[1]= 0xd3e; return $sub;
1662
- case 0xd4c : $sub[0] = 0xd46; $sub[1]= 0xd57; return $sub;
1663
- /* sinhala */
1664
- // NB Some fonts break with these Sinhala decomps (although this is Uniscribe spec)
1665
- // Can check if character would be substituted by pstf and only decompose if true
1666
- // e.g. if (isset($GSUBdata['pstf'][$ab])) - would need to pass $GSUBdata as parameter to this function
1667
- case 0xdda : $sub[0] = 0xdd9; $sub[1]= 0xdca; return $sub;
1668
- case 0xddc : $sub[0] = 0xdd9; $sub[1]= 0xdcf; return $sub;
1669
- case 0xddd : $sub[0] = 0xdd9; $sub[1]= 0xdcf; $sub[2]= 0xdca; return $sub;
1670
- case 0xdde : $sub[0] = 0xdd9; $sub[1]= 0xddf; return $sub;
1671
- /* khmer */
1672
- case 0x17be : $sub[0] = 0x17c1; $sub[1]= 0x17be; return $sub;
1673
- case 0x17bf : $sub[0] = 0x17c1; $sub[1]= 0x17bf; return $sub;
1674
- case 0x17c0 : $sub[0] = 0x17c1; $sub[1]= 0x17c0; return $sub;
1675
-
1676
- case 0x17c4 : $sub[0] = 0x17c1; $sub[1]= 0x17c4; return $sub;
1677
- case 0x17c5 : $sub[0] = 0x17c1; $sub[1]= 0x17c5; return $sub;
1678
- /* tibetan - included here although does not use Inidc shaper in other ways */
1679
- case 0xf73 : $sub[0] = 0xf71; $sub[1]= 0xf72; return $sub;
1680
- case 0xf75 : $sub[0] = 0xf71; $sub[1]= 0xf74; return $sub;
1681
- case 0xf76 : $sub[0] = 0xfb2; $sub[1]= 0xf80; return $sub;
1682
- case 0xf77 : $sub[0] = 0xfb2; $sub[1]= 0xf81; return $sub;
1683
- case 0xf78 : $sub[0] = 0xfb3; $sub[1]= 0xf80; return $sub;
1684
- case 0xf79 : $sub[0] = 0xfb3; $sub[1]= 0xf71; $sub[2]= 0xf80; return $sub;
1685
- case 0xf81 : $sub[0] = 0xf71; $sub[1]= 0xf80; return $sub;
1686
- }
1687
- return false;
1688
- }
1689
-
1690
-
1691
-
1692
-
1693
-
1694
- public static function bubble_sort(&$arr, $start, $len) {
1695
- if ($len<2) { return;}
1696
- $k = $start+$len-2;
1697
- while ($k >= $start) {
1698
- for ($j=$start; $j<=$k; $j++) {
1699
- if ($arr[$j]['indic_position'] > $arr[$j + 1]['indic_position']) {
1700
- $t = $arr[$j];
1701
- $arr[$j] = $arr[$j + 1];
1702
- $arr[$j + 1] = $t;
1703
- }
1704
- }
1705
- $k--;
1706
- }
1707
- }
1708
-
1709
-
1710
-
1711
-
1712
- } // end Class
1713
-
1714
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/mpdf/classes/meter.php DELETED
@@ -1,282 +0,0 @@
1
- <?php
2
-
3
- class meter {
4
-
5
-
6
- function __construct() {
7
-
8
- }
9
-
10
- function makeSVG($tag, $type, $value, $max, $min, $optimum, $low, $high) {
11
- $svg = '';
12
- if ($tag == 'meter') {
13
-
14
- if ($type=='2') {
15
- /////////////////////////////////////////////////////////////////////////////////////
16
- ///////// CUSTOM <meter type="2">
17
- /////////////////////////////////////////////////////////////////////////////////////
18
- $h = 10;
19
- $w = 160;
20
- $border_radius = 0.143; // Factor of Height
21
-
22
- $svg = '<?xml version="1.0" encoding="UTF-8"?>
23
- <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
24
- <svg width="'.$w.'px" height="'.$h.'px" viewBox="0 0 '.$w.' '.$h.'" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ><g>
25
-
26
-
27
- <defs>
28
- <linearGradient id="GrGRAY" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox">
29
- <stop offset="0%" stop-color="rgb(222, 222, 222)" />
30
- <stop offset="20%" stop-color="rgb(232, 232, 232)" />
31
- <stop offset="25%" stop-color="rgb(232, 232, 232)" />
32
- <stop offset="100%" stop-color="rgb(182, 182, 182)" />
33
- </linearGradient>
34
-
35
- </defs>
36
- ';
37
- $svg .= '<rect x="0" y="0" width="'.$w.'" height="'.$h.'" fill="#f4f4f4" stroke="none" />';
38
-
39
- // LOW to HIGH region
40
- //if ($low && $high && ($low != $min || $high != $max)) {
41
- if ($low && $high) {
42
- $barx = (($low-$min) / ($max-$min) ) * $w;
43
- $barw = (($high-$low) / ($max-$min) ) * $w;
44
- $svg .= '<rect x="'.$barx.'" y="0" width="'.$barw.'" height="'.$h.'" fill="url(#GrGRAY)" stroke="#888888" stroke-width="0.5px" />';
45
- }
46
-
47
- // OPTIMUM Marker (? AVERAGE)
48
- if ($optimum) {
49
- $barx = (($optimum-$min) / ($max-$min) ) * $w;
50
- $barw = $h/2;
51
- $barcol = '#888888';
52
- $svg .= '<rect x="'.$barx.'" y="0" rx="'.($h*$border_radius).'px" ry="'.($h*$border_radius).'px" width="'.$barw.'" height="'.$h.'" fill="'.$barcol.'" stroke="none" />';
53
- }
54
-
55
- // VALUE Marker
56
- if ($value) {
57
- if ($min != $low && $value < $low) { $col = 'orange'; }
58
- else if ($max != $high && $value > $high) { $col = 'orange'; }
59
- else { $col = '#008800'; }
60
- $cx = (($value-$min) / ($max-$min) ) * $w;
61
- $cy = $h/2;
62
- $rx = $h/3.5;
63
- $ry = $h/2.2;
64
- $svg .= '<ellipse fill="'.$col.'" stroke="#000000" stroke-width="0.5px" cx="'.$cx.'" cy="'.$cy.'" rx="'.$rx.'" ry="'.$ry.'"/>';
65
- }
66
-
67
- // BoRDER
68
- $svg .= '<rect x="0" y="0" width="'.$w.'" height="'.$h.'" fill="none" stroke="#888888" stroke-width="0.5px" />';
69
-
70
- $svg .= '</g></svg>';
71
- }
72
- else if ($type=='3') {
73
- /////////////////////////////////////////////////////////////////////////////////////
74
- ///////// CUSTOM <meter type="2">
75
- /////////////////////////////////////////////////////////////////////////////////////
76
- $h = 10;
77
- $w = 100;
78
- $border_radius = 0.143; // Factor of Height
79
-
80
- $svg = '<?xml version="1.0" encoding="UTF-8"?>
81
- <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
82
- <svg width="'.$w.'px" height="'.$h.'px" viewBox="0 0 '.$w.' '.$h.'" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ><g>
83
-
84
-
85
- <defs>
86
- <linearGradient id="GrGRAY" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox">
87
- <stop offset="0%" stop-color="rgb(222, 222, 222)" />
88
- <stop offset="20%" stop-color="rgb(232, 232, 232)" />
89
- <stop offset="25%" stop-color="rgb(232, 232, 232)" />
90
- <stop offset="100%" stop-color="rgb(182, 182, 182)" />
91
- </linearGradient>
92
-
93
- </defs>
94
- ';
95
- $svg .= '<rect x="0" y="0" width="'.$w.'" height="'.$h.'" fill="#f4f4f4" stroke="none" />';
96
-
97
- // LOW to HIGH region
98
- if ($low && $high && ($low != $min || $high != $max)) {
99
- //if ($low && $high) {
100
- $barx = (($low-$min) / ($max-$min) ) * $w;
101
- $barw = (($high-$low) / ($max-$min) ) * $w;
102
- $svg .= '<rect x="'.$barx.'" y="0" width="'.$barw.'" height="'.$h.'" fill="url(#GrGRAY)" stroke="#888888" stroke-width="0.5px" />';
103
- }
104
-
105
- // OPTIMUM Marker (? AVERAGE)
106
- if ($optimum) {
107
- $barx = (($optimum-$min) / ($max-$min) ) * $w;
108
- $barw = $h/2;
109
- $barcol = '#888888';
110
- $svg .= '<rect x="'.$barx.'" y="0" rx="'.($h*$border_radius).'px" ry="'.($h*$border_radius).'px" width="'.$barw.'" height="'.$h.'" fill="'.$barcol.'" stroke="none" />';
111
- }
112
-
113
- // VALUE Marker
114
- if ($value) {
115
- if ($min != $low && $value < $low) { $col = 'orange'; }
116
- else if ($max != $high && $value > $high) { $col = 'orange'; }
117
- else { $col = 'orange'; }
118
- $cx = (($value-$min) / ($max-$min) ) * $w;
119
- $cy = $h/2;
120
- $rx = $h/2.2;
121
- $ry = $h/2.2;
122
- $svg .= '<ellipse fill="'.$col.'" stroke="#000000" stroke-width="0.5px" cx="'.$cx.'" cy="'.$cy.'" rx="'.$rx.'" ry="'.$ry.'"/>';
123
- }
124
-
125
- // BoRDER
126
- $svg .= '<rect x="0" y="0" width="'.$w.'" height="'.$h.'" fill="none" stroke="#888888" stroke-width="0.5px" />';
127
-
128
- $svg .= '</g></svg>';
129
- }
130
- else {
131
- /////////////////////////////////////////////////////////////////////////////////////
132
- ///////// DEFAULT <meter>
133
- /////////////////////////////////////////////////////////////////////////////////////
134
- $h = 10;
135
- $w = 50;
136
- $border_radius = 0.143; // Factor of Height
137
-
138
- $svg = '<?xml version="1.0" encoding="UTF-8"?>
139
- <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
140
- <svg width="'.$w.'px" height="'.$h.'px" viewBox="0 0 '.$w.' '.$h.'" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ><g>
141
-
142
- <defs>
143
- <linearGradient id="GrGRAY" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox">
144
- <stop offset="0%" stop-color="rgb(222, 222, 222)" />
145
- <stop offset="20%" stop-color="rgb(232, 232, 232)" />
146
- <stop offset="25%" stop-color="rgb(232, 232, 232)" />
147
- <stop offset="100%" stop-color="rgb(182, 182, 182)" />
148
- </linearGradient>
149
-
150
- <linearGradient id="GrRED" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox">
151
- <stop offset="0%" stop-color="rgb(255, 162, 162)" />
152
- <stop offset="20%" stop-color="rgb(255, 218, 218)" />
153
- <stop offset="25%" stop-color="rgb(255, 218, 218)" />
154
- <stop offset="100%" stop-color="rgb(255, 0, 0)" />
155
- </linearGradient>
156
-
157
- <linearGradient id="GrGREEN" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox">
158
- <stop offset="0%" stop-color="rgb(102, 230, 102)" />
159
- <stop offset="20%" stop-color="rgb(218, 255, 218)" />
160
- <stop offset="25%" stop-color="rgb(218, 255, 218)" />
161
- <stop offset="100%" stop-color="rgb(0, 148, 0)" />
162
- </linearGradient>
163
-
164
- <linearGradient id="GrBLUE" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox">
165
- <stop offset="0%" stop-color="rgb(102, 102, 230)" />
166
- <stop offset="20%" stop-color="rgb(238, 238, 238)" />
167
- <stop offset="25%" stop-color="rgb(238, 238, 238)" />
168
- <stop offset="100%" stop-color="rgb(0, 0, 128)" />
169
- </linearGradient>
170
-
171
- <linearGradient id="GrORANGE" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox">
172
- <stop offset="0%" stop-color="rgb(255, 186, 0)" />
173
- <stop offset="20%" stop-color="rgb(255, 238, 168)" />
174
- <stop offset="25%" stop-color="rgb(255, 238, 168)" />
175
- <stop offset="100%" stop-color="rgb(255, 155, 0)" />
176
- </linearGradient>
177
- </defs>
178
-
179
- <rect x="0" y="0" rx="'.($h*$border_radius).'px" ry="'.($h*$border_radius).'px" width="'.$w.'" height="'.$h.'" fill="url(#GrGRAY)" stroke="none" />
180
- ';
181
-
182
- if ($value) {
183
- $barw = (($value-$min) / ($max-$min) ) * $w;
184
- if ($optimum < $low) {
185
- if ($value < $low) { $barcol = 'url(#GrGREEN)'; }
186
- else if ($value > $high) { $barcol = 'url(#GrRED)'; }
187
- else { $barcol = 'url(#GrORANGE)'; }
188
- }
189
- else if ($optimum > $high) {
190
- if ($value < $low) { $barcol = 'url(#GrRED)'; }
191
- else if ($value > $high) { $barcol = 'url(#GrGREEN)'; }
192
- else { $barcol = 'url(#GrORANGE)'; }
193
- }
194
- else {
195
- if ($value < $low) { $barcol = 'url(#GrORANGE)'; }
196
- else if ($value > $high) { $barcol = 'url(#GrORANGE)'; }
197
- else { $barcol = 'url(#GrGREEN)'; }
198
- }
199
- $svg .= '<rect x="0" y="0" rx="'.($h*$border_radius).'px" ry="'.($h*$border_radius).'px" width="'.$barw.'" height="'.$h.'" fill="'.$barcol.'" stroke="none" />';
200
- }
201
-
202
-
203
- // Borders
204
- //$svg .= '<rect x="0" y="0" rx="'.($h*$border_radius).'px" ry="'.($h*$border_radius).'px" width="'.$w.'" height="'.$h.'" fill="none" stroke="#888888" stroke-width="0.5px" />';
205
- if ($value) {
206
- // $svg .= '<rect x="0" y="0" rx="'.($h*$border_radius).'px" ry="'.($h*$border_radius).'px" width="'.$barw.'" height="'.$h.'" fill="none" stroke="#888888" stroke-width="0.5px" />';
207
- }
208
-
209
-
210
- $svg .= '</g></svg>';
211
- }
212
- }
213
- else { // $tag == 'progress'
214
-
215
- if ($type=='2') {
216
- /////////////////////////////////////////////////////////////////////////////////////
217
- ///////// CUSTOM <progress type="2">
218
- /////////////////////////////////////////////////////////////////////////////////////
219
- }
220
- else {
221
- /////////////////////////////////////////////////////////////////////////////////////
222
- ///////// DEFAULT <progress>
223
- /////////////////////////////////////////////////////////////////////////////////////
224
- $h = 10;
225
- $w = 100;
226
- $border_radius = 0.143; // Factor of Height
227
-
228
- if ($value or $value==='0') {
229
- $fill = 'url(#GrGRAY)';
230
- }
231
- else {
232
- $fill = '#f8f8f8';
233
- }
234
-
235
- $svg = '<svg width="'.$w.'px" height="'.$h.'px" viewBox="0 0 '.$w.' '.$h.'"><g>
236
-
237
- <defs>
238
- <linearGradient id="GrGRAY" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox">
239
- <stop offset="0%" stop-color="rgb(222, 222, 222)" />
240
- <stop offset="20%" stop-color="rgb(232, 232, 232)" />
241
- <stop offset="25%" stop-color="rgb(232, 232, 232)" />
242
- <stop offset="100%" stop-color="rgb(182, 182, 182)" />
243
- </linearGradient>
244
-
245
- <linearGradient id="GrGREEN" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox">
246
- <stop offset="0%" stop-color="rgb(102, 230, 102)" />
247
- <stop offset="20%" stop-color="rgb(218, 255, 218)" />
248
- <stop offset="25%" stop-color="rgb(218, 255, 218)" />
249
- <stop offset="100%" stop-color="rgb(0, 148, 0)" />
250
- </linearGradient>
251
-
252
- </defs>
253
-
254
- <rect x="0" y="0" rx="'.($h*$border_radius).'px" ry="'.($h*$border_radius).'px" width="'.$w.'" height="'.$h.'" fill="'.$fill.'" stroke="none" />
255
- ';
256
-
257
- if ($value) {
258
- $barw = (($value-$min) / ($max-$min) ) * $w;
259
- $barcol = 'url(#GrGREEN)';
260
- $svg .= '<rect x="0" y="0" rx="'.($h*$border_radius).'px" ry="'.($h*$border_radius).'px" width="'.$barw.'" height="'.$h.'" fill="'.$barcol.'" stroke="none" />';
261
- }
262
-
263
-
264
- // Borders
265
- $svg .= '<rect x="0" y="0" rx="'.($h*$border_radius).'px" ry="'.($h*$border_radius).'px" width="'.$w.'" height="'.$h.'" fill="none" stroke="#888888" stroke-width="0.5px" />';
266
- if ($value) {
267
- // $svg .= '<rect x="0" y="0" rx="'.($h*$border_radius).'px" ry="'.($h*$border_radius).'px" width="'.$barw.'" height="'.$h.'" fill="none" stroke="#888888" stroke-width="0.5px" />';
268
- }
269
-
270
-
271
- $svg .= '</g></svg>';
272
-
273
- }
274
- }
275
-
276
- return $svg;
277
- }
278
-
279
-
280
- } // end of class
281
-
282
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/mpdf/classes/mpdfform.php DELETED
@@ -1,1550 +0,0 @@
1
- <?php
2
-
3
- class mpdfform {
4
-
5
- var $mpdf = null;
6
-
7
- var $forms;
8
- var $formn;
9
-
10
- //Active Forms
11
- var $formSubmitNoValueFields;
12
- var $formExportType;
13
- var $formSelectDefaultOption;
14
- var $formUseZapD;
15
- /* Form Styles */
16
- var $form_border_color;
17
- var $form_background_color;
18
- var $form_border_width;
19
- var $form_border_style;
20
- var $form_button_border_color;
21
- var $form_button_background_color;
22
- var $form_button_border_width;
23
- var $form_button_border_style;
24
- var $form_radio_color;
25
- var $form_radio_background_color;
26
-
27
- var $form_element_spacing;
28
-
29
- // Active forms
30
- var $formMethod;
31
- var $formAction;
32
- var $form_fonts;
33
- var $form_radio_groups;
34
- var $form_checkboxes;
35
- var $pdf_acro_array;
36
-
37
- var $pdf_array_co;
38
- var $array_form_button_js;
39
- var $array_form_choice_js;
40
- var $array_form_text_js;
41
-
42
- /* Button Text */
43
- var $form_button_text;
44
- var $form_button_text_over;
45
- var $form_button_text_click;
46
- var $form_button_icon;
47
-
48
-
49
- // FORMS
50
- var $textarea_lineheight;
51
-
52
- function mpdfform(&$mpdf) {
53
- $this->mpdf = $mpdf;
54
-
55
- // ACTIVE FORMS
56
- $this->formExportType = 'xfdf'; // 'xfdf' or 'html'
57
- $this->formSubmitNoValueFields = true; // Whether to include blank fields when submitting data
58
- $this->formSelectDefaultOption = true; // for Select drop down box; if no option is explicitly maked as selected,
59
- // this determines whether to select 1st option (as per browser)
60
- // - affects whether "required" attribute is relevant
61
- $this->formUseZapD = true; // Determine whether to use ZapfDingbat icons for radio/checkboxes
62
-
63
- // FORM STYLES
64
- // These can alternatively use a 4 number string to represent CMYK colours
65
- $this->form_border_color = '0.6 0.6 0.72'; // RGB
66
- $this->form_background_color = '0.975 0.975 0.975'; // RGB
67
- $this->form_border_width = '1'; // 0 doesn't seem to work as it should
68
- $this->form_border_style = 'S'; // B - Bevelled; D - Double
69
- $this->form_button_border_color = '0.2 0.2 0.55';
70
- $this->form_button_background_color = '0.941 0.941 0.941';
71
- $this->form_button_border_width = '1';
72
- $this->form_button_border_style = 'S';
73
- $this->form_radio_color = '0.0 0.0 0.4'; // radio and checkbox
74
- $this->form_radio_background_color = '0.9 0.9 0.9';
75
-
76
- // FORMS
77
- $this->textarea_lineheight = 1.25;
78
-
79
- // FORM ELEMENT SPACING
80
- $this->form_element_spacing['select']['outer']['h'] = 0.5; // Horizontal spacing around SELECT
81
- $this->form_element_spacing['select']['outer']['v'] = 0.5; // Vertical spacing around SELECT
82
- $this->form_element_spacing['select']['inner']['h'] = 0.7; // Horizontal padding around SELECT
83
- $this->form_element_spacing['select']['inner']['v'] = 0.7; // Vertical padding around SELECT
84
- $this->form_element_spacing['input']['outer']['h'] = 0.5;
85
- $this->form_element_spacing['input']['outer']['v'] = 0.5;
86
- $this->form_element_spacing['input']['inner']['h'] = 0.7;
87
- $this->form_element_spacing['input']['inner']['v'] = 0.7;
88
- $this->form_element_spacing['textarea']['outer']['h'] = 0.5;
89
- $this->form_element_spacing['textarea']['outer']['v'] = 0.5;
90
- $this->form_element_spacing['textarea']['inner']['h'] = 1;
91
- $this->form_element_spacing['textarea']['inner']['v'] = 0.5;
92
- $this->form_element_spacing['button']['outer']['h'] = 0.5;
93
- $this->form_element_spacing['button']['outer']['v'] = 0.5;
94
- $this->form_element_spacing['button']['inner']['h'] = 2;
95
- $this->form_element_spacing['button']['inner']['v'] = 1;
96
-
97
- // INITIALISE non-configurable
98
- $this->formMethod = 'POST';
99
- $this->formAction = '';
100
- $this->form_fonts = array();
101
- $this->form_radio_groups = array();
102
- $this->form_checkboxes = false;
103
- $this->forms = array();
104
- $this->pdf_array_co = '';
105
-
106
-
107
- }
108
-
109
-
110
- function print_ob_text($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir) {
111
- // TEXT/PASSWORD INPUT
112
- if ($this->mpdf->useActiveForms) {
113
- // Flags: 1 - Readonly; 2 - Required; 3 - No export; 13 - textarea; 14 - Password
114
- $flags = array();
115
- if ((isset($objattr['disabled']) && $objattr['disabled']) || (isset($objattr['readonly']) && $objattr['readonly'])) { $flags[] = 1; } // readonly
116
- if (isset($objattr['disabled']) && $objattr['disabled']) {
117
- $flags[] = 3; // no export
118
- $objattr['color'] = array(3,128,128,128); // gray out disabled
119
- }
120
- if (isset($objattr['required']) && $objattr['required']) { $flags[] = 2; } // required
121
- if (!isset($objattr['spellcheck']) || !$objattr['spellcheck']) { $flags[] = 23; } // DoNotSpellCheck
122
- if (isset($objattr['subtype']) && $objattr['subtype']=='PASSWORD') {
123
- $flags[] = 14;
124
- $val = $objattr['value'];
125
- }
126
- if (isset($objattr['color'])) {
127
- $this->mpdf->SetTColor($objattr['color']);
128
- }
129
- else {
130
- $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
131
- }
132
- $fieldalign = $rtlalign;
133
- if (isset($objattr['text_align']) && $objattr['text_align']) { $fieldalign = $objattr['text_align']; }
134
- else { $val = $objattr['text']; }
135
- // mPDF 5.3.25
136
- $js = array();
137
- if (isset($objattr['onCalculate']) && $objattr['onCalculate']) { $js[] = array('C', $objattr['onCalculate']); }
138
- if (isset($objattr['onValidate']) && $objattr['onValidate']) { $js[] = array('V', $objattr['onValidate']); }
139
- if (isset($objattr['onFormat']) && $objattr['onFormat']) { $js[] = array('F', $objattr['onFormat']); }
140
- if (isset($objattr['onKeystroke']) && $objattr['onKeystroke']) { $js[] = array('K', $objattr['onKeystroke']); }
141
- $this->SetFormText( $w, $h, $objattr['fieldname'], $val, $val, $objattr['title'], $flags, $fieldalign, false, (isset($objattr['maxlength']) ? $objattr['maxlength'] : false), $js, (isset($objattr['background-col']) ? $objattr['background-col'] : false), (isset($objattr['border-col']) ? $objattr['border-col'] : false) );
142
- $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
143
- }
144
- else {
145
- $w -= $this->form_element_spacing['input']['outer']['h']*2 /$k;
146
- $h -= $this->form_element_spacing['input']['outer']['v']*2 /$k;
147
- $this->mpdf->x += $this->form_element_spacing['input']['outer']['h'] /$k;
148
- $this->mpdf->y += $this->form_element_spacing['input']['outer']['v'] /$k;
149
- // Chop texto to max length $w-inner-padding
150
- while ($this->mpdf->GetStringWidth($texto) > $w-($this->form_element_spacing['input']['inner']['h']*2)) {
151
- $texto = mb_substr($texto,0,mb_strlen($texto,$this->mpdf->mb_enc)-1,$this->mpdf->mb_enc);
152
- }
153
-
154
- // DIRECTIONALITY
155
- if (preg_match("/([".$this->mpdf->pregRTLchars."])/u", $texto)) { $this->mpdf->biDirectional = true; } // *RTL*
156
-
157
- // Use OTL OpenType Table Layout - GSUB & GPOS
158
- if (isset($this->mpdf->CurrentFont['useOTL']) && $this->mpdf->CurrentFont['useOTL']) {
159
- $texto = $this->mpdf->otl->applyOTL($texto, $this->mpdf->CurrentFont['useOTL']);
160
- $OTLdata = $this->mpdf->otl->OTLdata;
161
- }
162
-
163
- $this->mpdf->magic_reverse_dir($texto, $this->mpdf->directionality, $OTLdata);
164
-
165
- $this->mpdf->SetLineWidth(0.2 /$k );
166
- if (isset($objattr['disabled']) && $objattr['disabled']) {
167
- $this->mpdf->SetFColor($this->mpdf->ConvertColor(225));
168
- $this->mpdf->SetTColor($this->mpdf->ConvertColor(127));
169
- }
170
- else if (isset($objattr['readonly']) && $objattr['readonly']) {
171
- $this->mpdf->SetFColor($this->mpdf->ConvertColor(225));
172
- $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
173
- }
174
- else {
175
- $this->mpdf->SetFColor($this->mpdf->ConvertColor(250));
176
- $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
177
- }
178
- $this->mpdf->Cell($w,$h,$texto,1,0,$rtlalign,1,'',0,$this->form_element_spacing['input']['inner']['h'] /$k ,$this->form_element_spacing['input']['inner']['h'] /$k , 'M', 0, false, $OTLdata);
179
- $this->mpdf->SetFColor($this->mpdf->ConvertColor(255));
180
- $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
181
- }
182
- }
183
-
184
- function print_ob_textarea($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir) {
185
- // TEXTAREA
186
- if ($this->mpdf->useActiveForms) {
187
- // Flags: 1 - Readonly; 2 - Required; 3 - No export; 13 - textarea; 14 - Password
188
- $flags = array();
189
- $flags = array(13); // textarea
190
- if ((isset($objattr['disabled']) && $objattr['disabled']) || (isset($objattr['readonly']) && $objattr['readonly'])) { $flags[] = 1; } // readonly
191
- if (isset($objattr['disabled']) && $objattr['disabled']) {
192
- $flags[] = 3; // no export
193
- $objattr['color'] = array(3,128,128,128); // gray out disabled
194
- }
195
- if (isset($objattr['required']) && $objattr['required']) { $flags[] = 2; } // required
196
- if (!isset($objattr['spellcheck']) || !$objattr['spellcheck']) { $flags[] = 23; } // DoNotSpellCheck
197
- if (isset($objattr['donotscroll']) && $objattr['donotscroll']) { $flags[] = 24; } // DoNotScroll
198
- if (isset($objattr['color'])) {
199
- $this->mpdf->SetTColor($objattr['color']);
200
- }
201
- else {
202
- $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
203
- }
204
- $fieldalign = $rtlalign;
205
- if ($texto == ' ') { $texto = ''; } // mPDF 5.3.24
206
- if (isset($objattr['text_align']) && $objattr['text_align']) { $fieldalign = $objattr['text_align']; }
207
- // mPDF 5.3.25
208
- $js = array();
209
- if (isset($objattr['onCalculate']) && $objattr['onCalculate']) { $js[] = array('C', $objattr['onCalculate']); }
210
- if (isset($objattr['onValidate']) && $objattr['onValidate']) { $js[] = array('V', $objattr['onValidate']); }
211
- if (isset($objattr['onFormat']) && $objattr['onFormat']) { $js[] = array('F', $objattr['onFormat']); }
212
- if (isset($objattr['onKeystroke']) && $objattr['onKeystroke']) { $js[] = array('K', $objattr['onKeystroke']); }
213
- $this->SetFormText( $w, $h, $objattr['fieldname'], $texto, $texto, (isset($objattr['title']) ? $objattr['title'] : ''), $flags, $fieldalign , false, -1, $js, (isset($objattr['background-col']) ? $objattr['background-col'] : false), (isset($objattr['border-col']) ? $objattr['border-col'] : false));
214
- $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
215
- }
216
- else {
217
- $w -= $this->form_element_spacing['textarea']['outer']['h']*2 /$k ;
218
- $h -= $this->form_element_spacing['textarea']['outer']['v']*2 /$k ;
219
- $this->mpdf->x += $this->form_element_spacing['textarea']['outer']['h'] /$k ;
220
- $this->mpdf->y += $this->form_element_spacing['textarea']['outer']['v'] /$k ;
221
- $this->mpdf->SetLineWidth(0.2 /$k );
222
- if (isset($objattr['disabled']) && $objattr['disabled']) {
223
- $this->mpdf->SetFColor($this->mpdf->ConvertColor(225));
224
- $this->mpdf->SetTColor($this->mpdf->ConvertColor(127));
225
- }
226
- else if (isset($objattr['readonly']) && $objattr['readonly']) {
227
- $this->mpdf->SetFColor($this->mpdf->ConvertColor(225));
228
- $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
229
- }
230
- else {
231
- $this->mpdf->SetFColor($this->mpdf->ConvertColor(250));
232
- $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
233
- }
234
- $this->mpdf->Rect($this->mpdf->x,$this->mpdf->y,$w,$h,'DF');
235
- $ClipPath = sprintf('q %.3F %.3F %.3F %.3F re W n ',$this->mpdf->x*_MPDFK,($this->mpdf->h-$this->mpdf->y)*_MPDFK,$w*_MPDFK,-$h*_MPDFK);
236
- $this->mpdf->_out($ClipPath);
237
-
238
- $w -= $this->form_element_spacing['textarea']['inner']['h']*2 /$k ;
239
- $this->mpdf->x += $this->form_element_spacing['textarea']['inner']['h'] /$k ;
240
- $this->mpdf->y += $this->form_element_spacing['textarea']['inner']['v'] /$k ;
241
-
242
- if ($texto != '') $this->mpdf->MultiCell($w,$this->mpdf->FontSize*$this->textarea_lineheight,$texto,0,'',0,'',$blockdir,true,$objattr['OTLdata'], $objattr['rows']);
243
- $this->mpdf->_out('Q');
244
- $this->mpdf->SetFColor($this->mpdf->ConvertColor(255));
245
- $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
246
- }
247
- }
248
-
249
- function print_ob_select($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir) {
250
- // SELECT
251
- if ($this->mpdf->useActiveForms) {
252
- // Flags: 1 - Readonly; 2 - Required; 3 - No export; 19 - edit (only if combo)
253
- $flags = array();
254
- if (isset($objattr['disabled']) && $objattr['disabled']) {
255
- $flags[] = 1; // readonly
256
- $flags[] = 3; // no export
257
- $objattr['color'] = array(3,128,128,128); // gray out disabled
258
- }
259
- if (isset($objattr['required']) && $objattr['required']) { $flags[] = 2; } // required
260
- if (isset($objattr['multiple']) && $objattr['multiple'] && isset($objattr['size']) && $objattr['size']>1) { $flags[] = 22; } //flag 22 = multiselect (listbox)
261
- if (isset($objattr['size']) && $objattr['size']<2) {
262
- $flags[] = 18; //flag 18 = combobox (else a listbox)
263
- if (isset($objattr['editable']) && $objattr['editable']) { $flags[] = 19; } // editable
264
- }
265
- // only allow spellcheck if combo and editable
266
- if ((!isset($objattr['spellcheck']) || !$objattr['spellcheck']) || (isset($objattr['size']) && $objattr['size']>1) || (!isset($objattr['editable']) || !$objattr['editable'])) { $flags[] = 23; } // DoNotSpellCheck
267
- if (isset($objattr['subtype']) && $objattr['subtype']=='PASSWORD') { $flags[] = 14; }
268
- if (isset($objattr['onChange']) && $objattr['onChange']) { $js = $objattr['onChange']; }
269
- else { $js = ''; } // mPDF 5.3.37
270
- $data = array('VAL' => array(), 'OPT' => array(), 'SEL' => array(), );
271
- if (isset($objattr['items'])) {
272
- for($i=0; $i<count($objattr['items']); $i++) {
273
- $item = $objattr['items'][$i];
274
- $data['VAL'][] = (isset($item['exportValue']) ? $item['exportValue'] : '');
275
- $data['OPT'][] = (isset($item['content']) ? $item['content'] : '');
276
- if (isset($item['selected']) && $item['selected']) { $data['SEL'][] = $i; }
277
- }
278
- }
279
- if (count($data['SEL'])==0 && $this->formSelectDefaultOption) {$data['SEL'][] = 0; }
280
- if (isset($objattr['color'])) {
281
- $this->mpdf->SetTColor($objattr['color']);
282
- }
283
- else {
284
- $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
285
- }
286
- $this->SetFormChoice( $w, $h, $objattr['fieldname'], $flags, $data, $rtlalign, $js );
287
- $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
288
- }
289
- else {
290
- $this->mpdf->SetLineWidth(0.2 /$k );
291
- if (isset($objattr['disabled']) && $objattr['disabled']) {
292
- $this->mpdf->SetFColor($this->mpdf->ConvertColor(225));
293
- $this->mpdf->SetTColor($this->mpdf->ConvertColor(127));
294
- }
295
- else {
296
- $this->mpdf->SetFColor($this->mpdf->ConvertColor(250));
297
- $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
298
- }
299
- $w -= $this->form_element_spacing['select']['outer']['h']*2 /$k ;
300
- $h -= $this->form_element_spacing['select']['outer']['v']*2 /$k ;
301
- $this->mpdf->x += $this->form_element_spacing['select']['outer']['h'] /$k ;
302
- $this->mpdf->y += $this->form_element_spacing['select']['outer']['v'] /$k ;
303
-
304
- // DIRECTIONALITY
305
- if (preg_match("/([".$this->mpdf->pregRTLchars."])/u", $texto)) { $this->mpdf->biDirectional = true; } // *RTL*
306
-
307
- $this->mpdf->magic_reverse_dir($texto, $this->mpdf->directionality, $objattr['OTLdata']);
308
-
309
- $this->mpdf->Cell($w-($this->mpdf->FontSize*1.4),$h,$texto,1,0,$rtlalign,1,'',0,$this->form_element_spacing['select']['inner']['h'] /$k,$this->form_element_spacing['select']['inner']['h'] /$k , 'M', 0, false, $objattr['OTLdata']) ;
310
- $this->mpdf->SetFColor($this->mpdf->ConvertColor(190));
311
- $save_font = $this->mpdf->FontFamily;
312
- $save_currentfont = $this->mpdf->currentfontfamily;
313
- if ($this->mpdf->PDFA || $this->mpdf->PDFX) {
314
- if (($this->mpdf->PDFA && !$this->mpdf->PDFAauto) || ($this->mpdf->PDFX && !$this->mpdf->PDFXauto)) { $this->mpdf->PDFAXwarnings[] = "Core Adobe font Zapfdingbats cannot be embedded in mPDF - used in Form element: Select - which is required for PDFA1-b or PDFX/1-a. (Different character/font will be substituted.)"; }
315
- $this->mpdf->SetFont('sans');
316
- if ($this->mpdf->_charDefined($this->mpdf->CurrentFont['cw'], 9660)) { $down = "\xe2\x96\xbc"; }
317
- else { $down = '='; }
318
- $this->mpdf->Cell(($this->mpdf->FontSize*1.4),$h,$down,1,0,'C',1,'',0,0,0, 'M') ;
319
- }
320
- else {
321
- $this->mpdf->SetFont('czapfdingbats','',0);
322
- $this->mpdf->Cell(($this->mpdf->FontSize*1.4),$h,chr(116),1,0,'C',1,'',0,0,0, 'M') ;
323
- }
324
- $this->mpdf->SetFont($save_font,'',0);
325
- $this->mpdf->currentfontfamily = $save_currentfont;
326
- $this->mpdf->SetFColor($this->mpdf->ConvertColor(255));
327
- $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
328
- }
329
- }
330
-
331
- function print_ob_imageinput($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir) {
332
- // INPUT/BUTTON as IMAGE
333
- if ($this->mpdf->useActiveForms) {
334
- // Flags: 1 - Readonly; 3 - No export;
335
- $flags = array();
336
- if (isset($objattr['disabled']) && $objattr['disabled']) {
337
- $flags[] = 1; // readonly
338
- $flags[] = 3; // no export
339
- }
340
- if (isset($objattr['onClick']) && $objattr['onClick']) { $js = $objattr['onClick']; }
341
- else { $js = ''; }
342
- $this->SetJSButton( $w, $h, $objattr['fieldname'], (isset($objattr['value']) ? $objattr['value'] : ''), $js, $objattr['ID'], $objattr['title'], $flags, (isset($objattr['Indexed']) ? $objattr['Indexed'] : false));
343
- }
344
- else {
345
- $this->mpdf->y = $objattr['INNER-Y'];
346
- $this->mpdf->_out( sprintf("q %.3F 0 0 %.3F %.3F %.3F cm /I%d Do Q",$objattr['INNER-WIDTH'] *_MPDFK,$objattr['INNER-HEIGHT'] *_MPDFK,$objattr['INNER-X'] *_MPDFK,($this->mpdf->h-($objattr['INNER-Y'] +$objattr['INNER-HEIGHT'] ))*_MPDFK,$objattr['ID'] ) );
347
- if (isset($objattr['BORDER-WIDTH']) && $objattr['BORDER-WIDTH']) { $this->mpdf->PaintImgBorder($objattr,$is_table); }
348
- }
349
- }
350
-
351
- function print_ob_button($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir) {
352
- // BUTTON
353
- if ($this->mpdf->useActiveForms) {
354
- // Flags: 1 - Readonly; 3 - No export;
355
- $flags = array();
356
- if (isset($objattr['disabled']) && $objattr['disabled']) {
357
- $flags[] = 1; // readonly
358
- $flags[] = 3; // no export
359
- $objattr['color'] = array(3,128,128,128);
360
- }
361
- if (isset($objattr['color'])) {
362
- $this->mpdf->SetTColor($objattr['color']);
363
- }
364
- else {
365
- $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
366
- }
367
- if (isset($objattr['subtype']) && $objattr['subtype'] == 'RESET') {
368
- $this->SetFormButtonText( $objattr['value'] );
369
- $this->SetFormReset( $w, $h, $objattr['fieldname'], $objattr['value'], $objattr['title'], $flags, (isset($objattr['background-col']) ? $objattr['background-col'] : false), (isset($objattr['border-col']) ? $objattr['border-col'] : false), (isset($objattr['noprint']) ? $objattr['noprint'] : false) );
370
- }
371
- else if (isset($objattr['subtype']) && $objattr['subtype'] == 'SUBMIT') {
372
- $url = $this->formAction;
373
- $type = $this->formExportType;
374
- $method = $this->formMethod;
375
- $this->SetFormButtonText( $objattr['value'] );
376
- $this->SetFormSubmit( $w, $h, $objattr['fieldname'], $objattr['value'], $url, $objattr['title'], $type, $method, $flags, (isset($objattr['background-col']) ? $objattr['background-col'] : false), (isset($objattr['border-col']) ? $objattr['border-col'] : false), (isset($objattr['noprint']) ? $objattr['noprint'] : false) );
377
- }
378
- else if (isset($objattr['subtype']) && $objattr['subtype'] == 'BUTTON') {
379
- $this->SetFormButtonText( $objattr['value'] );
380
- if (isset($objattr['onClick']) && $objattr['onClick']) { $js = $objattr['onClick']; }
381
- else { $js = ''; }
382
- $this->SetJSButton( $w, $h, $objattr['fieldname'], $objattr['value'], $js, 0, $objattr['title'], $flags, false, (isset($objattr['background-col']) ? $objattr['background-col'] : false), (isset($objattr['border-col']) ? $objattr['border-col'] : false), (isset($objattr['noprint']) ? $objattr['noprint'] : false) );
383
- }
384
- $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
385
- }
386
- else {
387
- $this->mpdf->SetLineWidth(0.2 /$k );
388
- $this->mpdf->SetFColor($this->mpdf->ConvertColor(190));
389
- $w -= $this->form_element_spacing['button']['outer']['h']*2 /$k ;
390
- $h -= $this->form_element_spacing['button']['outer']['v']*2 /$k ;
391
- $this->mpdf->x += $this->form_element_spacing['button']['outer']['h'] /$k ;
392
- $this->mpdf->y += $this->form_element_spacing['button']['outer']['v'] /$k ;
393
- $this->mpdf->RoundedRect($this->mpdf->x, $this->mpdf->y, $w, $h, 0.5 /$k , 'DF');
394
- $w -= $this->form_element_spacing['button']['inner']['h']*2 /$k ;
395
- $h -= $this->form_element_spacing['button']['inner']['v']*2 /$k ;
396
- $this->mpdf->x += $this->form_element_spacing['button']['inner']['h'] /$k ;
397
- $this->mpdf->y += $this->form_element_spacing['button']['inner']['v'] /$k ;
398
-
399
- // DIRECTIONALITY
400
- if (preg_match("/([".$this->mpdf->pregRTLchars."])/u", $texto)) { $this->mpdf->biDirectional = true; } // *RTL*
401
-
402
- // Use OTL OpenType Table Layout - GSUB & GPOS
403
- if (isset($this->mpdf->CurrentFont['useOTL']) && $this->mpdf->CurrentFont['useOTL']) {
404
- $texto = $this->mpdf->otl->applyOTL($texto, $this->mpdf->CurrentFont['useOTL']);
405
- $OTLdata = $this->mpdf->otl->OTLdata;
406
- }
407
-
408
- $this->mpdf->magic_reverse_dir($texto, $this->mpdf->directionality, $OTLdata);
409
-
410
- $this->mpdf->Cell($w,$h,$texto,'',0,'C',0,'',0,0,0, 'M', 0, false, $OTLdata ) ;
411
- $this->mpdf->SetFColor($this->mpdf->ConvertColor(0));
412
- }
413
- }
414
-
415
- function print_ob_checkbox($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir,$x,$y) {
416
- // CHECKBOX
417
- if ($this->mpdf->useActiveForms) {
418
- // Flags: 1 - Readonly; 2 - Required; 3 - No export;
419
- $flags = array();
420
- if (isset($objattr['disabled']) && $objattr['disabled']) {
421
- $flags[] = 1; // readonly
422
- $flags[] = 3; // no export
423
- }
424
- $checked = false;
425
- if (isset($objattr['checked']) && $objattr['checked']) { $checked = true; }
426
- if ($this->formUseZapD) {
427
- $save_font = $this->mpdf->FontFamily;
428
- $save_currentfont = $this->mpdf->currentfontfamily;
429
- $this->mpdf->SetFont('czapfdingbats','',0);
430
- }
431
- $this->SetCheckBox( $w, $h, $objattr['fieldname'], $objattr['value'], $objattr['title'], $checked, $flags, (isset($objattr['disabled']) ? $objattr['disabled'] : false));
432
- if ($this->formUseZapD) {
433
- $this->mpdf->SetFont($save_font,'',0);
434
- $this->mpdf->currentfontfamily = $save_currentfont;
435
- }
436
- }
437
- else {
438
- $iw = $w * 0.7;
439
- $ih = $h * 0.7;
440
- $lx = $x + (($w-$iw)/2);
441
- $ty = $y + (($h-$ih)/2);
442
- $rx = $lx + $iw;
443
- $by = $ty + $ih;
444
- $this->mpdf->SetLineWidth(0.2 /$k );
445
- if (isset($objattr['disabled']) && $objattr['disabled']) {
446
- $this->mpdf->SetFColor($this->mpdf->ConvertColor(225));
447
- $this->mpdf->SetDColor($this->mpdf->ConvertColor(127));
448
- }
449
- else {
450
- $this->mpdf->SetFColor($this->mpdf->ConvertColor(250));
451
- $this->mpdf->SetDColor($this->mpdf->ConvertColor(0));
452
- }
453
- $this->mpdf->Rect($lx,$ty,$iw,$ih,'DF');
454
- if (isset($objattr['checked']) && $objattr['checked']) {
455
- //Round join and cap
456
- $this->mpdf->SetLineCap(1);
457
- $this->mpdf->Line($lx,$ty,$rx,$by);
458
- $this->mpdf->Line($lx,$by,$rx,$ty);
459
- //Set line cap style back to square
460
- $this->mpdf->SetLineCap(2);
461
- }
462
- $this->mpdf->SetFColor($this->mpdf->ConvertColor(255));
463
- $this->mpdf->SetDColor($this->mpdf->ConvertColor(0));
464
- }
465
- }
466
-
467
- function print_ob_radio($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir,$x,$y) {
468
- // RADIO
469
- if ($this->mpdf->useActiveForms) {
470
- // Flags: 1 - Readonly; 2 - Required; 3 - No export;
471
- $flags = array();
472
- if (isset($objattr['disabled']) && $objattr['disabled']) {
473
- $flags[] = 1; // readonly
474
- $flags[] = 3; // no export
475
- }
476
- $checked = false;
477
- if (isset($objattr['checked']) && $objattr['checked']) { $checked = true; }
478
- if ($this->formUseZapD) {
479
- $save_font = $this->mpdf->FontFamily;
480
- $save_currentfont = $this->mpdf->currentfontfamily;
481
- $this->mpdf->SetFont('czapfdingbats','',0);
482
- }
483
- $this->SetRadio( $w, $h, $objattr['fieldname'], $objattr['value'], (isset($objattr['title']) ? $objattr['title'] : ''), $checked, $flags, (isset($objattr['disabled']) ? $objattr['disabled'] : false) );
484
- if ($this->formUseZapD) {
485
- $this->mpdf->SetFont($save_font,'',0);
486
- $this->mpdf->currentfontfamily = $save_currentfont;
487
- }
488
- }
489
- else {
490
- $this->mpdf->SetLineWidth(0.2 /$k );
491
- $radius = $this->mpdf->FontSize *0.35;
492
- $cx = $x + ($w/2);
493
- $cy = $y + ($h/2);
494
- if (isset($objattr['disabled']) && $objattr['disabled']) {
495
- $this->mpdf->SetFColor($this->mpdf->ConvertColor(127));
496
- $this->mpdf->SetDColor($this->mpdf->ConvertColor(127));
497
- }
498
- else {
499
- $this->mpdf->SetFColor($this->mpdf->ConvertColor(0));
500
- $this->mpdf->SetDColor($this->mpdf->ConvertColor(0));
501
- }
502
- $this->mpdf->Circle($cx,$cy,$radius,'D');
503
- if (isset($objattr['checked']) && $objattr['checked']) {
504
- $this->mpdf->Circle($cx,$cy,$radius*0.4,'DF');
505
- }
506
- $this->mpdf->SetFColor($this->mpdf->ConvertColor(255));
507
- $this->mpdf->SetDColor($this->mpdf->ConvertColor(0));
508
-
509
- }
510
- }
511
-
512
-
513
-
514
- // In _putpages
515
- function countPageForms($n, &$totaladdnum) {
516
- foreach( $this->forms as $form ) {
517
- if ( $form['page'] == $n ) {
518
- $totaladdnum++;
519
- if ( $form['typ'] == 'Tx' ) {
520
- if ( isset($this->array_form_text_js[$form['T']]) ) {
521
- if ( isset($this->array_form_text_js[$form['T']]['F']) ) { $totaladdnum++; }
522
- if ( isset($this->array_form_text_js[$form['T']]['K']) ) { $totaladdnum++; }
523
- if ( isset($this->array_form_text_js[$form['T']]['V']) ) { $totaladdnum++; }
524
- if ( isset($this->array_form_text_js[$form['T']]['C']) ) { $totaladdnum++; }
525
- }
526
- }
527
- if ( $form['typ'] == 'Bt' ) {
528
- if ( isset($this->array_form_button_js[$form['T']]) ) { $totaladdnum++; }
529
- if ( isset($this->form_button_icon[$form['T']]) ) {
530
- $totaladdnum++;
531
- if ( $this->form_button_icon[$form['T']]['Indexed'] ) { $totaladdnum++; }
532
- }
533
- if ( $form['subtype'] == 'radio' ) { $totaladdnum+=2; }
534
- else if ( $form['subtype'] == 'checkbox' && $this->formUseZapD ) { $totaladdnum++; }
535
- else if ( $form['subtype'] == 'checkbox' && !$this->formUseZapD ) { $totaladdnum+=2; }
536
- }
537
- if ( $form['typ'] == 'Ch' ) {
538
- if ( isset($this->array_form_choice_js[$form['T']]) ) { $totaladdnum++; }
539
- }
540
- }
541
- }
542
- }
543
-
544
- // In _putpages
545
- function addFormIds($n, &$s, &$annotid) {
546
- foreach( $this->forms as $form ) {
547
- if ( $form['page'] == $n ) {
548
- $s .= ($annotid) . ' 0 R ';
549
- $annotid++;
550
- if ( $form['typ'] == 'Tx' ) {
551
- if ( isset($this->array_form_text_js[$form['T']]) ) {
552
- if ( isset($this->array_form_text_js[$form['T']]['F']) ) { $annotid++; }
553
- if ( isset($this->array_form_text_js[$form['T']]['K']) ) { $annotid++; }
554
- if ( isset($this->array_form_text_js[$form['T']]['V']) ) { $annotid++; }
555
- if ( isset($this->array_form_text_js[$form['T']]['C']) ) { $annotid++; }
556
- }
557
- }
558
- if ( $form['typ'] == 'Bt' ) {
559
- if ( isset($this->array_form_button_js[$form['T']]) ) { $annotid++; }
560
- if ( isset($this->form_button_icon[$form['T']]) ) {
561
- $annotid++;
562
- if ( $this->form_button_icon[$form['T']]['Indexed'] ) { $annotid++; }
563
- }
564
- if ( $form['subtype'] == 'radio' ) { $annotid+=2; }
565
- else if ( $form['subtype'] == 'checkbox' && $this->formUseZapD ) { $annotid++; }
566
- else if ( $form['subtype'] == 'checkbox' && !$this->formUseZapD ) { $annotid+=2; }
567
- }
568
- if ( $form['typ'] == 'Ch' ) {
569
- if ( isset($this->array_form_choice_js[$form['T']]) ) { $annotid++; }
570
- }
571
- }
572
- }
573
- }
574
-
575
- // In _putannots
576
- function _putFormItems($n, $hPt) {
577
- foreach( $this->forms as $val) {
578
- if ( $val['page'] == $n ) {
579
- if ( $val['typ'] == 'Tx' ) $this->_putform_tx( $val, $hPt );
580
- if ( $val['typ'] == 'Ch' ) $this->_putform_ch( $val, $hPt );
581
- if ( $val['typ'] == 'Bt' ) $this->_putform_bt( $val, $hPt );
582
- }
583
- }
584
- }
585
-
586
- // In _putannots
587
- function _putRadioItems($n) {
588
- // Output Radio Groups
589
- $key = 1;
590
- foreach($this->form_radio_groups AS $name=>$frg) {
591
- $this->mpdf->_newobj();
592
- $this->pdf_acro_array .= $this->mpdf->n.' 0 R ';
593
- $this->mpdf->_out('<<');
594
- $this->mpdf->_out('/Type /Annot ');
595
- $this->mpdf->_out('/Subtype /Widget');
596
- $this->mpdf->_out('/NM '.$this->mpdf->_textstring(sprintf('%04u-%04u', $n, (3000 + $key++))));
597
- $this->mpdf->_out('/M '.$this->mpdf->_textstring('D:'.date('YmdHis')));
598
- $this->mpdf->_out('/Rect [0 0 0 0] ');
599
- $this->mpdf->_out('/FT /Btn ');
600
- if (isset($frg['disabled']) && $frg['disabled']) { $flags=array(1,3,15,16); } // NoExport and readonly
601
- else { $flags=array(15,16); } // Flags for Radiobutton, and NoToggleToOff
602
- $this->mpdf->_out('/Ff '.$this->_setflag($flags) );
603
- $kstr = '';
604
- $optstr = '';
605
- foreach($frg['kids'] AS $kid) {
606
- $kstr .= $this->forms[$kid['n']]['obj'].' 0 R ';
607
- // $optstr .= ' '.$this->mpdf->_textstring($kid['OPT']).' ';
608
- }
609
- $this->mpdf->_out('/Kids [ '.$kstr.' ] '); // 11 0 R 12 0 R etc.
610
- // $this->mpdf->_out('/Opt [ '.$optstr.' ] ');
611
-
612
- //V entry holds index corresponding to the appearance state of
613
- //whichever child field is currently in the on state = or Off
614
- if (isset($frg['on'])) { $state = $frg['on']; }
615
- else { $state = 'Off'; }
616
- $this->mpdf->_out('/V /'.$state.' ');
617
- $this->mpdf->_out('/DV /'.$state.' ');
618
- $this->mpdf->_out('/T '.$this->mpdf->_textstring($name).' ');
619
- $this->mpdf->_out('>>');
620
- $this->mpdf->_out('endobj');
621
- }
622
- }
623
-
624
- function _putFormsCatalog() {
625
- if (isset($this->pdf_acro_array) ) {
626
- $this->mpdf->_out('/AcroForm << /DA (/F1 0 Tf 0 g )');
627
- $this->mpdf->_out('/Q 0');
628
- $this->mpdf->_out('/Fields ['.$this->pdf_acro_array.']');
629
- $f = '';
630
- foreach($this->form_fonts AS $fn) {
631
- if (is_array($this->mpdf->fonts[$fn]['n'])) { $this->mpdf->Error("Cannot use fonts with SMP or SIP characters for interactive Form elements"); }
632
- $f .= '/F'.$this->mpdf->fonts[$fn]['i'].' '.$this->mpdf->fonts[$fn]['n'].' 0 R ';
633
- }
634
- $this->mpdf->_out('/DR << /Font << '.$f.' >> >>');
635
- // CO Calculation Order
636
- if ( $this->pdf_array_co ) {
637
- $this->mpdf->_out('/CO ['.$this->pdf_array_co.']');
638
- }
639
- $this->mpdf->_out('/NeedAppearances true');
640
- $this->mpdf->_out('>>');
641
- }
642
- }
643
-
644
-
645
-
646
- function SetFormButtonJS( $name, $js ) {
647
- $js = str_replace("\t",' ', trim($js) );
648
- if ( isset($name) && isset($js) ) {
649
- $this->array_form_button_js[$this->mpdf->_escape($name)] = array(
650
- 'js' => $js
651
- );
652
- }
653
- }
654
-
655
- function SetFormChoiceJS( $name, $js ) {
656
- $js = str_replace("\t",' ', trim($js) );
657
- if ( isset($name) && isset($js) ) {
658
- $this->array_form_choice_js[$this->mpdf->_escape($name)] = array(
659
- 'js' => $js
660
- );
661
- }
662
- }
663
-
664
- function SetFormTextJS( $name, $js) {
665
- for ($i=0; $i<count($js); $i++) {
666
- $j = str_replace("\t",' ', trim($js[$i][1]) );
667
- $format = $js[$i][0];
668
- if ($name) {
669
- $this->array_form_text_js[$this->mpdf->_escape($name)][$format] = array('js' => $j);
670
- }
671
- }
672
- }
673
-
674
-
675
- function Win1252ToPDFDocEncoding($txt) {
676
- $Win1252ToPDFDocEncoding = array(
677
- chr(0200) => chr(0240), chr(0214) => chr(0226), chr(0212) => chr(0227), chr(0237) => chr(0230),
678
- chr(0225) => chr(0200), chr(0210) => chr(0032), chr(0206) => chr(0201), chr(0207) => chr(0202),
679
- chr(0205) => chr(0203), chr(0227) => chr(0204), chr(0226) => chr(0205), chr(0203) => chr(0206),
680
- chr(0213) => chr(0210), chr(0233) => chr(0211), chr(0211) => chr(0213), chr(0204) => chr(0214),
681
- chr(0223) => chr(0215), chr(0224) => chr(0216), chr(0221) => chr(0217), chr(0222) => chr(0220),
682
- chr(0202) => chr(0221), chr(0232) => chr(0235), chr(0230) => chr(0037), chr(0231) => chr(0222),
683
- chr(0216) => chr(0231), chr(0240) => chr(0040)
684
- ); // mPDF 5.3.46
685
- return strtr($txt, $Win1252ToPDFDocEncoding );
686
- }
687
-
688
-
689
- function SetFormText( $w, $h, $name, $value = '', $default = '', $title = '', $flags = array(), $align='L', $hidden = false, $maxlen=-1, $js='', $background_col=false, $border_col=false ) {
690
- // Flags: 1 - Readonly; 2 - Required; 3 - No export; 13 - textarea; 14 - Password
691
- $this->formn++;
692
- if( $align == 'C' ) { $align = '1'; }
693
- else if( $align == 'R' ) { $align = '2'; }
694
- else { $align = '0'; }
695
- if ($maxlen < 1) { $maxlen = false; }
696
- if (!preg_match('/^[a-zA-Z0-9_:\-]+$/', $name)) {
697
- $this->mpdf->Error("Field [".$name."] must have a name attribute, which can only contain letters, numbers, colon(:), undersore(_) or hyphen(-)");
698
- }
699
- if ($this->mpdf->onlyCoreFonts) {
700
- $value = $this->Win1252ToPDFDocEncoding($value);
701
- $default = $this->Win1252ToPDFDocEncoding($default);
702
- $title = $this->Win1252ToPDFDocEncoding($title);
703
- }
704
- else {
705
- if (isset($this->mpdf->CurrentFont['subset'])) {
706
- $this->mpdf->UTF8StringToArray($value, true); // Add characters to font subset
707
- $this->mpdf->UTF8StringToArray($default, true); // Add characters to font subset
708
- $this->mpdf->UTF8StringToArray($title, true); // Add characters to font subset
709
- }
710
- if ($value) $value = $this->mpdf->UTF8ToUTF16BE($value, true);
711
- if ($default ) $default = $this->mpdf->UTF8ToUTF16BE($default, true);
712
- $title = $this->mpdf->UTF8ToUTF16BE($title, true);
713
- }
714
- if ($background_col) { $bg_c = $this->mpdf->SetColor($background_col, 'CodeOnly'); }
715
- else { $bg_c = $this->form_background_color; }
716
- if ($border_col) { $bc_c = $this->mpdf->SetColor($border_col, 'CodeOnly'); }
717
- else { $bc_c = $this->form_border_color; }
718
- $f = array( 'n' => $this->formn,
719
- 'typ' => 'Tx',
720
- 'page' => $this->mpdf->page,
721
- 'x' => $this->mpdf->x,
722
- 'y' => $this->mpdf->y,
723
- 'w' => $w,
724
- 'h' => $h,
725
- 'T' => $name,
726
- 'FF' => $flags,
727
- 'V' => $value,
728
- 'DV' => $default,
729
- 'TU' => $title,
730
- 'hidden' => $hidden,
731
- 'Q' => $align,
732
- 'maxlen' => $maxlen,
733
- 'BS_W' => $this->form_border_width,
734
- 'BS_S' => $this->form_border_style,
735
- 'BC_C' => $bc_c,
736
- 'BG_C' => $bg_c,
737
- 'style' => array(
738
- 'font' => $this->mpdf->FontFamily,
739
- 'fontsize' => $this->mpdf->FontSizePt,
740
- 'fontcolor' => $this->mpdf->TextColor,
741
- )
742
- );
743
- if (is_array($js) && count($js)>0) { $this->SetFormTextJS( $name, $js); } // mPDF 5.3.25
744
- if ($this->mpdf->keep_block_together) { $this->mpdf->ktForms[]= $f; }
745
- else if ($this->mpdf->writingHTMLheader || $this->mpdf->writingHTMLfooter) { $this->mpdf->HTMLheaderPageForms[]= $f; }
746
- else {
747
- if ($this->mpdf->ColActive) {
748
- $this->mpdf->columnbuffer[] = array('s' => 'ACROFORM', 'col' => $this->mpdf->CurrCol, 'x' => $this->mpdf->x, 'y' => $this->mpdf->y,
749
- 'h' => $h);
750
- $this->mpdf->columnForms[$this->mpdf->CurrCol][INTVAL($this->mpdf->x)][INTVAL($this->mpdf->y)] = $this->formn;
751
- }
752
- $this->forms[$this->formn] = $f;
753
- }
754
- if (!in_array($this->mpdf->FontFamily, $this->form_fonts)) {
755
- $this->form_fonts[] = $this->mpdf->FontFamily;
756
- $this->mpdf->fonts[$this->mpdf->FontFamily]['used'] = true;
757
- }
758
- if ( !$hidden ) $this->mpdf->x += $w;
759
-
760
- }
761
-
762
-
763
- function SetFormChoice( $w, $h, $name, $flags, $array, $align='L', $js = '' ) {
764
- $this->formn++;
765
- if( $this->mpdf->blk[$this->mpdf->blklvl]['direction'] == 'rtl' ) { $align = '2'; }
766
- else { $align = '0'; }
767
- if (!preg_match('/^[a-zA-Z0-9_:\-]+$/', $name)) {
768
- $this->mpdf->Error("Field [".$name."] must have a name attribute, which can only contain letters, numbers, colon(:), undersore(_) or hyphen(-)");
769
- }
770
- if ($this->mpdf->onlyCoreFonts) {
771
- for($i=0;$i<count($array['VAL']);$i++) {
772
- $array['VAL'][$i] = $this->Win1252ToPDFDocEncoding($array['VAL'][$i]);
773
- $array['OPT'][$i] = $this->Win1252ToPDFDocEncoding($array['OPT'][$i]);
774
- }
775
- }
776
- else {
777
- for($i=0;$i<count($array['VAL']);$i++) {
778
- if (isset($this->mpdf->CurrentFont['subset'])) {
779
- $this->mpdf->UTF8StringToArray($array['VAL'][$i], true); // Add characters to font subset
780
- $this->mpdf->UTF8StringToArray($array['OPT'][$i], true); // Add characters to font subset
781
- }
782
- if ($array['VAL'][$i] ) $array['VAL'][$i] = $this->mpdf->UTF8ToUTF16BE($array['VAL'][$i], true);
783
- if ($array['OPT'][$i] ) $array['OPT'][$i] = $this->mpdf->UTF8ToUTF16BE($array['OPT'][$i], true);
784
- }
785
- }
786
- $f = array( 'n' => $this->formn,
787
- 'typ' => 'Ch',
788
- 'page' => $this->mpdf->page,
789
- 'x' => $this->mpdf->x,
790
- 'y' => $this->mpdf->y,
791
- 'w' => $w,
792
- 'h' => $h,
793
- 'T' => $name,
794
- 'OPT' => $array,
795
- 'FF' => $flags,
796
- 'Q' => $align,
797
- 'BS_W' => $this->form_border_width,
798
- 'BS_S' => $this->form_border_style,
799
- 'BC_C' => $this->form_border_color,
800
- 'BG_C' => $this->form_background_color,
801
- 'style' => array(
802
- 'font' => $this->mpdf->FontFamily,
803
- 'fontsize' => $this->mpdf->FontSizePt,
804
- 'fontcolor' => $this->mpdf->TextColor,
805
- )
806
- );
807
- if ($js) { $this->SetFormChoiceJS( $name, $js ); }
808
- if ($this->mpdf->keep_block_together) { $this->mpdf->ktForms[]= $f; }
809
- else if ($this->mpdf->writingHTMLheader || $this->mpdf->writingHTMLfooter) { $this->mpdf->HTMLheaderPageForms[]= $f; }
810
- else {
811
- if ($this->mpdf->ColActive) {
812
- $this->mpdf->columnbuffer[] = array('s' => 'ACROFORM', 'col' => $this->mpdf->CurrCol, 'x' => $this->mpdf->x, 'y' => $this->mpdf->y,
813
- 'h' => $h);
814
- $this->mpdf->columnForms[$this->mpdf->CurrCol][INTVAL($this->mpdf->x)][INTVAL($this->mpdf->y)] = $this->formn;
815
- }
816
- $this->forms[$this->formn] = $f;
817
- }
818
- if (!in_array($this->mpdf->FontFamily, $this->form_fonts)) {
819
- $this->form_fonts[] = $this->mpdf->FontFamily;
820
- $this->mpdf->fonts[$this->mpdf->FontFamily]['used'] = true;
821
- }
822
- $this->mpdf->x += $w;
823
- }
824
-
825
- // CHECKBOX
826
- function SetCheckBox( $w, $h, $name, $value, $title = '', $checked = false, $flags = array(), $disabled=false ) {
827
- $this->SetFormButton( $w, $h, $name, $value, 'checkbox', $title, $flags, $checked, $disabled );
828
- $this->mpdf->x += $w;
829
- }
830
-
831
-
832
- // RADIO
833
- function SetRadio( $w, $h, $name, $value, $title = '', $checked = false, $flags = array(), $disabled=false ) {
834
- $this->SetFormButton( $w, $h, $name, $value, 'radio', $title, $flags, $checked, $disabled );
835
- $this->mpdf->x += $w;
836
- }
837
-
838
-
839
- function SetFormReset( $w, $h, $name, $value = 'Reset', $title = '', $flags = array(), $background_col=false, $border_col=false, $noprint=false ) {
840
- if (!$name) { $name = 'Reset'; }
841
- $this->SetFormButton( $w, $h, $name, $value, 'reset', $title, $flags, false, false, $background_col, $border_col, $noprint);
842
- $this->mpdf->x += $w;
843
- }
844
-
845
-
846
- function SetJSButton( $w, $h, $name, $value, $js, $image_id = 0, $title = '', $flags = array(), $indexed=false , $background_col=false, $border_col=false, $noprint=false ) {
847
- $this->SetFormButton( $w, $h, $name, $value, 'js_button', $title, $flags, false, false, $background_col, $border_col, $noprint);
848
- // pos => 1 = no caption, icon only; 0 = caption only
849
- if ($image_id) {
850
- $this->form_button_icon[$this->mpdf->_escape($name)] = array(
851
- 'pos' => 1,
852
- 'image_id' => $image_id,
853
- 'Indexed' => $indexed,
854
- );
855
- }
856
- if ($js) { $this->SetFormButtonJS( $name, $js ); }
857
- $this->mpdf->x += $w;
858
- }
859
-
860
-
861
- function SetFormSubmit( $w, $h, $name, $value = 'Submit', $url, $title = '', $typ = 'html', $method = 'POST', $flags = array(), $background_col=false, $border_col=false, $noprint=false) {
862
- if (!$name) { $name = 'Submit'; }
863
- $this->SetFormButton( $w, $h, $name, $value, 'submit', $title, $flags, false, false, $background_col, $border_col, $noprint);
864
- $this->forms[$this->formn]['URL'] = $url;
865
- $this->forms[$this->formn]['method'] = $method;
866
- $this->forms[$this->formn]['exporttype'] = $typ;
867
- $this->mpdf->x += $w;
868
- }
869
-
870
-
871
- function SetFormButtonText( $ca, $rc = '', $ac = '' ) {
872
- if ($this->mpdf->onlyCoreFonts) {
873
- $ca = $this->Win1252ToPDFDocEncoding($ca);
874
- if ($rc) $rc = $this->Win1252ToPDFDocEncoding($rc);
875
- if ($ac) $ac = $this->Win1252ToPDFDocEncoding($ac);
876
- }
877
- else {
878
- if (isset($this->mpdf->CurrentFont['subset'])) {
879
- $this->mpdf->UTF8StringToArray($ca, true); // Add characters to font subset
880
- }
881
- $ca = $this->mpdf->UTF8ToUTF16BE($ca, true);
882
- if ($rc) {
883
- if (isset($this->mpdf->CurrentFont['subset'])) { $this->mpdf->UTF8StringToArray($rc, true); }
884
- $rc = $this->mpdf->UTF8ToUTF16BE($rc, true);
885
- }
886
- if ($ac) {
887
- if (isset($this->mpdf->CurrentFont['subset'])) { $this->mpdf->UTF8StringToArray($ac, true); }
888
- $ac = $this->mpdf->UTF8ToUTF16BE($ac, true);
889
- }
890
- }
891
- $this->form_button_text = $ca;
892
- $this->form_button_text_over = $rc ? $rc : $ca;
893
- $this->form_button_text_click = $ac ? $ac : $ca;
894
- }
895
-
896
-
897
- function SetFormButton( $bb, $hh, $name, $value, $type, $title = '', $flags = array(), $checked=false, $disabled=false, $background_col=false, $border_col=false, $noprint=false ) {
898
- $this->formn++;
899
- if (!preg_match('/^[a-zA-Z0-9_:\-]+$/', $name)) {
900
- $this->mpdf->Error("Field [".$name."] must have a name attribute, which can only contain letters, numbers, colon(:), undersore(_) or hyphen(-)");
901
- }
902
- if (!$this->mpdf->onlyCoreFonts) {
903
- if (isset($this->mpdf->CurrentFont['subset'])) {
904
- $this->mpdf->UTF8StringToArray($title, true); // Add characters to font subset
905
- $this->mpdf->UTF8StringToArray($value, true); // Add characters to font subset
906
- }
907
- $title = $this->mpdf->UTF8ToUTF16BE($title, true);
908
- if ($type == 'checkbox') {
909
- $uvalue = $this->mpdf->UTF8ToUTF16BE($value, true);
910
- }
911
- else if ($type == 'radio') {
912
- $uvalue = $this->mpdf->UTF8ToUTF16BE($value, true);
913
- $value = mb_convert_encoding($value, 'Windows-1252', 'UTF-8');
914
- }
915
- else {
916
- $value = $this->mpdf->UTF8ToUTF16BE($value, true);
917
- $uvalue = $value;
918
- }
919
- }
920
- else {
921
- $title = $this->Win1252ToPDFDocEncoding($title);
922
- $value = $this->Win1252ToPDFDocEncoding($value); //// ??? not needed
923
- $uvalue = mb_convert_encoding($value, 'UTF-8', 'Windows-1252');
924
- $uvalue = $this->mpdf->UTF8ToUTF16BE($uvalue, true);
925
- }
926
- if ($type == 'radio' || $type == 'checkbox') {
927
- if (!preg_match('/^[a-zA-Z0-9_:\-\.]+$/', $value)) {
928
- $this->mpdf->Error("Field '".$name."' must have a value, which can only contain letters, numbers, colon(:), undersore(_), hyphen(-) or period(.)");
929
- }
930
- }
931
- if ($type == 'radio') {
932
- if (!isset($this->form_radio_groups[$name])) {
933
- $this->form_radio_groups[$name] = array(
934
- 'page' => $this->mpdf->page,
935
- 'kids' => array(),
936
- );
937
- }
938
- $this->form_radio_groups[$name]['kids'][] = array(
939
- 'n' => $this->formn, 'V'=> $value, 'OPT'=>$uvalue, 'disabled'=>$disabled
940
- );
941
- if ( $checked ) { $this->form_radio_groups[$name]['on'] = $value; }
942
- // Disable the whole radio group if one is disabled, because of inconsistency in PDF readers
943
- if ( $disabled ) { $this->form_radio_groups[$name]['disabled'] = true; }
944
- }
945
- if ($type == 'checkbox') {
946
- $this->form_checkboxes = true;
947
- }
948
- if ( $checked ) { $activ = 1; }
949
- else { $activ = 0; }
950
- if ($background_col) { $bg_c = $this->mpdf->SetColor($background_col, 'CodeOnly'); }
951
- else { $bg_c = $this->form_button_background_color; }
952
- if ($border_col) { $bc_c = $this->mpdf->SetColor($border_col, 'CodeOnly'); }
953
- else { $bc_c = $this->form_button_border_color; }
954
- $f = array( 'n' => $this->formn,
955
- 'typ' => 'Bt',
956
- 'page' => $this->mpdf->page,
957
- 'subtype' => $type,
958
- 'x' => $this->mpdf->x,
959
- 'y' => $this->mpdf->y,
960
- 'w' => $bb,
961
- 'h' => $hh,
962
- 'T' => $name,
963
- 'V' => $value,
964
- 'OPT' => $uvalue,
965
- 'TU' => $title,
966
- 'FF' => $flags,
967
- 'CA' => $this->form_button_text,
968
- 'RC' => $this->form_button_text_over,
969
- 'AC' => $this->form_button_text_click,
970
- 'BS_W' => $this->form_button_border_width,
971
- 'BS_S' => $this->form_button_border_style,
972
- 'BC_C' => $bc_c,
973
- 'BG_C' => $bg_c,
974
- 'activ' => $activ,
975
- 'disabled' => $disabled,
976
- 'noprint' => $noprint,
977
- 'style' => array(
978
- 'font' => $this->mpdf->FontFamily,
979
- 'fontsize' => $this->mpdf->FontSizePt,
980
- 'fontcolor' => $this->mpdf->TextColor,
981
- )
982
- );
983
- if ($this->mpdf->keep_block_together) { $this->mpdf->ktForms[]= $f; }
984
- else if ($this->mpdf->writingHTMLheader || $this->mpdf->writingHTMLfooter) { $this->mpdf->HTMLheaderPageForms[]= $f; }
985
- else {
986
- if ($this->mpdf->ColActive) {
987
- $this->mpdf->columnbuffer[] = array('s' => 'ACROFORM', 'col' => $this->mpdf->CurrCol, 'x' => $this->mpdf->x, 'y' => $this->mpdf->y,
988
- 'h' => $hh);
989
- $this->mpdf->columnForms[$this->mpdf->CurrCol][INTVAL($this->mpdf->x)][INTVAL($this->mpdf->y)] = $this->formn;
990
- }
991
- $this->forms[$this->formn] = $f;
992
- }
993
- if (!in_array($this->mpdf->FontFamily, $this->form_fonts)) {
994
- $this->form_fonts[] = $this->mpdf->FontFamily;
995
- $this->mpdf->fonts[$this->mpdf->FontFamily]['used'] = true;
996
- }
997
-
998
- $this->form_button_text = NULL;
999
- $this->form_button_text_over = NULL;
1000
- $this->form_button_text_click = NULL;
1001
- }
1002
-
1003
-
1004
-
1005
- function SetFormBorderWidth ( $string ) {
1006
- switch( $string ) {
1007
- case 'S': $this->form_border_width = '1';
1008
- break;
1009
- case 'M': $this->form_border_width = '2';
1010
- break;
1011
- case 'B': $this->form_border_width = '3';
1012
- break;
1013
- case '0': $this->form_border_width = '0';
1014
- break;
1015
- default: $this->form_border_width = '0';
1016
- break;
1017
- }
1018
- }
1019
-
1020
-
1021
- function SetFormBorderStyle ( $string ) {
1022
- switch( $string ) {
1023
- case 'S': $this->form_border_style = 'S';
1024
- break;
1025
- case 'D': $this->form_border_style = 'D /D [3]';
1026
- break;
1027
- case 'B': $this->form_border_style = 'B';
1028
- break;
1029
- case 'I': $this->form_border_style = 'I';
1030
- break;
1031
- case 'U': $this->form_border_style = 'U';
1032
- break;
1033
- default: $this->form_border_style = 'B';
1034
- break;
1035
- }
1036
- }
1037
-
1038
- function SetFormBorderColor ( $r, $g=-1, $b=-1 ) {
1039
- if ( ($r==0 and $g==0 and $b==0) || $g==-1 )
1040
- $this->form_border_color = sprintf('%.3F', $r/255);
1041
- else
1042
- $this->form_border_color = sprintf('%.3F %.3F %.3F', $r/255, $g/255, $b/255);
1043
- }
1044
-
1045
- function SetFormBackgroundColor ( $r, $g=-1, $b=-1 ) {
1046
- if ( ($r==0 and $g==0 and $b==0) || $g==-1 )
1047
- $this->form_background_color = sprintf('%.3F', $r/255);
1048
- else
1049
- $this->form_background_color = sprintf('%.3F %.3F %.3F', $r/255, $g/255, $b/255);
1050
- }
1051
-
1052
- function SetFormD ( $W, $S, $BC, $BG ) {
1053
- $this->SetFormBorderWidth ( $W );
1054
- $this->SetFormBorderStyle ( $S );
1055
- $this->SetFormBorderColor ( $BC );
1056
- $this->SetFormBackgroundColor ( $BG );
1057
- }
1058
-
1059
- function _setflag( $array ) {
1060
- $flag = 0;
1061
- foreach($array as $val) { $flag += 1 << ($val-1); }
1062
- return $flag;
1063
- }
1064
-
1065
- function _form_rect( $x, $y, $w, $h, $hPt ) {
1066
- $x = $x * _MPDFK;
1067
- $y = $hPt - ($y * _MPDFK);
1068
- $x2 = $x + ($w * _MPDFK);
1069
- $y2 = $y - ($h * _MPDFK);
1070
- $rect = sprintf('%.3F %.3F %.3F %.3F', $x, $y2, $x2, $y );
1071
- return $rect;
1072
- }
1073
-
1074
-
1075
- function _put_button_icon( $array , $w, $h ) {
1076
- if (isset($array['image_id'])) {
1077
- $info = false;
1078
- foreach($this->mpdf->images AS $iid=>$img) {
1079
- if ($img['i'] == $array['image_id']) {
1080
- $info = $this->mpdf->images[$iid];
1081
- break;
1082
- }
1083
- }
1084
- }
1085
- if (!$info) { die("Cannot find Button image"); }
1086
- $this->mpdf->_newobj();
1087
- $this->mpdf->_out('<<');
1088
- $this->mpdf->_out('/Type /XObject');
1089
- $this->mpdf->_out('/Subtype /Image');
1090
- $this->mpdf->_out('/BBox [0 0 1 1]');
1091
- $this->mpdf->_out('/Length '.strlen($info['data']));
1092
- $this->mpdf->_out('/BitsPerComponent '.$info['bpc']);
1093
- if ($info['cs']=='Indexed') {
1094
- $this->mpdf->_out('/ColorSpace [/Indexed /DeviceRGB '.(strlen($info['pal'])/3-1).' '.($this->mpdf->n+1).' 0 R]');
1095
- }
1096
- else {
1097
- $this->mpdf->_out('/ColorSpace /'.$info['cs']);
1098
- if ($info['cs']=='DeviceCMYK')
1099
- if($info['type']=='jpg') { $this->mpdf->_out('/Decode [1 0 1 0 1 0 1 0]'); }
1100
- }
1101
- if ( isset($info['f']) )
1102
- $this->mpdf->_out('/Filter /'.$info['f']);
1103
- if ( isset($info['parms']) )
1104
- $this->mpdf->_out($info['parms']);
1105
- $this->mpdf->_out('/Width '.$info['w']);
1106
- $this->mpdf->_out('/Height '.$info['h']);
1107
- $this->mpdf->_out('>>');
1108
- $this->mpdf->_putstream($info['data']);
1109
- $this->mpdf->_out('endobj');
1110
- unset($array);
1111
- //Palette
1112
- if($info['cs']=='Indexed') {
1113
- $filter=($this->mpdf->compress) ? '/Filter /FlateDecode ' : '';
1114
- $this->mpdf->_newobj();
1115
- $pal=($this->mpdf->compress) ? gzcompress($info['pal']) : $info['pal'];
1116
- $this->mpdf->_out('<<'.$filter.'/Length '.strlen($pal).'>>');
1117
- $this->mpdf->_putstream($pal);
1118
- $this->mpdf->_out('endobj');
1119
- }
1120
-
1121
- }
1122
-
1123
-
1124
- function _putform_bt( $form, $hPt ) {
1125
- $cc = 0;
1126
- $put_xobject = 0;
1127
- $put_js = 0;
1128
- $put_icon = 0;
1129
- $this->mpdf->_newobj();
1130
- $n = $this->mpdf->n;
1131
- if ($form['subtype'] != 'radio') $this->pdf_acro_array .= $n.' 0 R '; // Add to /Field element
1132
- $this->forms[ $form['n'] ]['obj'] = $n;
1133
- $this->mpdf->_out('<<');
1134
- $this->mpdf->_out('/Type /Annot ');
1135
- $this->mpdf->_out('/Subtype /Widget');
1136
- $this->mpdf->_out('/NM '.$this->mpdf->_textstring(sprintf('%04u-%04u', $n, (7000 + $form['n']))));
1137
- $this->mpdf->_out('/M '.$this->mpdf->_textstring('D:'.date('YmdHis')));
1138
- $this->mpdf->_out('/Rect [ '.$this->_form_rect($form['x'],$form['y'],$form['w'],$form['h'], $hPt).' ]');
1139
- $form['noprint'] ? $this->mpdf->_out('/F 0 ') : $this->mpdf->_out('/F 4 ');
1140
- $this->mpdf->_out('/FT /Btn ');
1141
- $this->mpdf->_out('/H /P ');
1142
- if ( $form['subtype'] != 'radio' ) // mPDF 5.3.23
1143
- $this->mpdf->_out('/T '.$this->mpdf->_textstring($form['T']) );
1144
- $this->mpdf->_out('/TU '.$this->mpdf->_textstring($form['TU']) );
1145
- if ( isset( $this->form_button_icon[ $form['T'] ] ) ) { $form['BS_W'] = 0; }
1146
- if ($form['BS_W'] == 0) { $form['BC_C'] = $form['BG_C']; }
1147
- $bstemp = '';
1148
- $bstemp .= '/W '.$form['BS_W'].' ';
1149
- $bstemp .= '/S /'.$form['BS_S'].' ';
1150
- $temp = '';
1151
- $temp .= '/BC [ '.$form['BC_C']." ] ";
1152
- $temp .= '/BG [ '.$form['BG_C']." ] ";
1153
- if ( $form['subtype'] == 'checkbox' ) {
1154
- if ($form['disabled']) {
1155
- $radio_color = '0.5 0.5 0.5';
1156
- $radio_background_color = '0.9 0.9 0.9';
1157
- }
1158
- else {
1159
- $radio_color = $this->form_radio_color;
1160
- $radio_background_color = $this->form_radio_background_color;
1161
- }
1162
- $temp = '';
1163
- $temp .= '/BC [ '.$radio_color." ] ";
1164
- $temp .= '/BG [ '.$radio_background_color." ] ";
1165
- $this->mpdf->_out("/BS << /W 1 /S /S >>");
1166
- $this->mpdf->_out("/MK << $temp >>");
1167
- $this->mpdf->_out('/Ff '.$this->_setflag($form['FF']) );
1168
- if ( $form['activ'] ) {
1169
- $this->mpdf->_out('/V /'.$this->mpdf->_escape($form['V']).' ');
1170
- $this->mpdf->_out('/DV /'.$this->mpdf->_escape($form['V']).' ');
1171
- $this->mpdf->_out('/AS /'.$this->mpdf->_escape($form['V']).' ');
1172
- } else {
1173
- $this->mpdf->_out('/AS /Off ');
1174
- }
1175
- if ($this->formUseZapD) {
1176
- $this->mpdf->_out('/DA (/F'.$this->mpdf->fonts['czapfdingbats']['i'].' 0 Tf '.$radio_color.' rg)');
1177
- $this->mpdf->_out("/AP << /N << /".$this->mpdf->_escape($form['V'])." ".($this->mpdf->n+1)." 0 R /Off /Off >> >>");
1178
- }
1179
- else {
1180
- $this->mpdf->_out('/DA (/F'.$this->mpdf->fonts[$this->mpdf->CurrentFont['fontkey']]['i'].' 0 Tf '.$radio_color.' rg)');
1181
- $this->mpdf->_out("/AP << /N << /".$this->mpdf->_escape($form['V'])." ".($this->mpdf->n+1)." 0 R /Off ".($this->mpdf->n+2)." 0 R >> >>");
1182
- }
1183
- $this->mpdf->_out('/Opt [ '.$this->mpdf->_textstring($form['OPT']).' '.$this->mpdf->_textstring($form['OPT']).' ]');
1184
- }
1185
-
1186
-
1187
- if ( $form['subtype'] == 'radio' ) {
1188
- if ((isset($form['disabled']) && $form['disabled']) || (isset($this->form_radio_groups[$form['T']]['disabled']) && $this->form_radio_groups[$form['T']]['disabled'])) {
1189
- $radio_color = '0.5 0.5 0.5';
1190
- $radio_background_color = '0.9 0.9 0.9';
1191
- }
1192
- else {
1193
- $radio_color = $this->form_radio_color;
1194
- $radio_background_color = $this->form_radio_background_color;
1195
- }
1196
- $this->mpdf->_out('/Parent '.$this->form_radio_groups[$form['T']]['obj_id'].' 0 R ');
1197
- $temp = '';
1198
- $temp .= '/BC [ '.$radio_color." ] ";
1199
- $temp .= '/BG [ '.$radio_background_color." ] ";
1200
- $this->mpdf->_out("/BS << /W 1 /S /S >>");
1201
- $this->mpdf->_out('/MK << '.$temp.' >> ');
1202
- $form['FF'][] = 16; // Radiobutton
1203
- $form['FF'][] = 15; // NoToggleOff - must be same as radio button group setting?
1204
- $this->mpdf->_out('/Ff '.$this->_setflag($form['FF']) );
1205
- if ($this->formUseZapD)
1206
- $this->mpdf->_out('/DA (/F'.$this->mpdf->fonts['czapfdingbats']['i'].' 0 Tf '.$radio_color.' rg)');
1207
- else
1208
- $this->mpdf->_out('/DA (/F'.$this->mpdf->fonts[$this->mpdf->CurrentFont['fontkey']]['i'].' 0 Tf '.$radio_color.' rg)');
1209
- $this->mpdf->_out("/AP << /N << /".$this->mpdf->_escape($form['V'])." ".($this->mpdf->n+1)." 0 R /Off ".($this->mpdf->n+2)." 0 R >> >>");
1210
- if ( $form['activ'] ) {
1211
- $this->mpdf->_out('/V /'.$this->mpdf->_escape($form['V']).' ');
1212
- $this->mpdf->_out('/DV /'.$this->mpdf->_escape($form['V']).' ');
1213
- $this->mpdf->_out('/AS /'.$this->mpdf->_escape($form['V']).' ');
1214
- }
1215
- else {
1216
- $this->mpdf->_out('/AS /Off ');
1217
- }
1218
- $this->mpdf->_out("/AP << /N << /".$this->mpdf->_escape($form['V'])." ".($this->mpdf->n+1)." 0 R /Off ".($this->mpdf->n+2)." 0 R >> >>");
1219
- // $this->mpdf->_out('/Opt [ '.$this->mpdf->_textstring($form['OPT']).' '.$this->mpdf->_textstring($form['OPT']).' ]');
1220
- }
1221
-
1222
- if ( $form['subtype'] == 'reset' ) {
1223
- $temp .= $form['CA'] ? '/CA '.$this->mpdf->_textstring($form['CA']).' ' : '/CA '.$this->mpdf->_textstring($form['T']).' ';
1224
- $temp .= $form['RC'] ? '/RC '.$this->mpdf->_textstring($form['RC']).' ' : '/RC '.$this->mpdf->_textstring($form['T']).' ';
1225
- $temp .= $form['AC'] ? '/AC '.$this->mpdf->_textstring($form['AC']).' ' : '/AC '.$this->mpdf->_textstring($form['T']).' ';
1226
- $this->mpdf->_out("/BS << $bstemp >>");
1227
- $this->mpdf->_out('/MK << '.$temp.' >>');
1228
- $this->mpdf->_out('/DA (/F'.$this->mpdf->fonts[$form['style']['font']]['i'].' '.$form['style']['fontsize'].' Tf '.$form['style']['fontcolor'].')');
1229
- $this->mpdf->_out('/AA << /D << /S /ResetForm /Flags 1 >> >>');
1230
- $form['FF'][] = 17;
1231
- $this->mpdf->_out('/Ff '.$this->_setflag($form['FF']) );
1232
- }
1233
-
1234
-
1235
- if ( $form['subtype'] == 'submit' ) {
1236
- $temp .= $form['CA'] ? '/CA '.$this->mpdf->_textstring($form['CA']).' ' : '/CA '.$this->mpdf->_textstring($form['T']).' ';
1237
- $temp .= $form['RC'] ? '/RC '.$this->mpdf->_textstring($form['RC']).' ' : '/RC '.$this->mpdf->_textstring($form['T']).' ';
1238
- $temp .= $form['AC'] ? '/AC '.$this->mpdf->_textstring($form['AC']).' ' : '/AC '.$this->mpdf->_textstring($form['T']).' ';
1239
- $this->mpdf->_out("/BS << $bstemp >>");
1240
- $this->mpdf->_out("/MK << $temp >>");
1241
- $this->mpdf->_out('/DA (/F'.$this->mpdf->fonts[$form['style']['font']]['i'].' '.$form['style']['fontsize'].' Tf '.$form['style']['fontcolor'].')');
1242
- // Bit 4 (8) = useGETmethod else use POST
1243
- // Bit 3 (4) = HTML export format (charset chosen by Adobe)--- OR ---
1244
- // Bit 6 (32) = XFDF export format (form of XML in UTF-8)
1245
- if ($form['exporttype'] == 'xfdf') { $flag = 32; } // 'xfdf' or 'html'
1246
- else {
1247
- if ($form['method'] == 'GET') { $flag = 12; }
1248
- else { $flag = 4; }
1249
- }
1250
- // Bit 2 (2) = IncludeNoValueFields
1251
- if ($this->formSubmitNoValueFields) $flag += 2;
1252
- // To submit a value, needs to be in /AP dictionary, AND this object must contain a /Fields entry
1253
- // listing all fields to output
1254
- $this->mpdf->_out('/AA << /D << /S /SubmitForm /F ('.$form['URL'].') /Flags '.$flag.' >> >>');
1255
- $form['FF'][] = 17;
1256
- $this->mpdf->_out('/Ff '.$this->_setflag($form['FF']) );
1257
- }
1258
-
1259
- if ( $form['subtype'] == 'js_button' ) {
1260
- // Icon / image
1261
- if ( isset( $this->form_button_icon[ $form['T'] ] ) ) {
1262
- $cc++;
1263
- $temp .= '/TP '.$this->form_button_icon[$form['T']]['pos'].' ';
1264
- $temp .= '/I '.($cc + $this->mpdf->n).' 0 R '; // Normal icon
1265
- $temp .= '/RI '.($cc + $this->mpdf->n).' 0 R '; // onMouseOver
1266
- $temp .= '/IX '.($cc + $this->mpdf->n).' 0 R '; // onClick / onMouseDown
1267
- $temp .= '/IF << /SW /A /S /A /A [0.0 0.0] >> '; // Icon fit dictionary
1268
- if ($this->form_button_icon[ $form['T'] ]['Indexed']) { $cc++; }
1269
- $put_icon = 1;
1270
- }
1271
- $temp .= $form['CA'] ? '/CA '.$this->mpdf->_textstring($form['CA']).' ' : '/CA '.$this->mpdf->_textstring($form['T']).' ';
1272
- $temp .= $form['RC'] ? '/RC '.$this->mpdf->_textstring($form['RC']).' ' : '/RC '.$this->mpdf->_textstring($form['T']).' ';
1273
- $temp .= $form['AC'] ? '/AC '.$this->mpdf->_textstring($form['AC']).' ' : '/AC '.$this->mpdf->_textstring($form['T']).' ';
1274
- $this->mpdf->_out("/BS << $bstemp >>");
1275
- $this->mpdf->_out("/MK << $temp >>");
1276
- $this->mpdf->_out('/DA (/F'.$this->mpdf->fonts[$form['style']['font']]['i'].' '.$form['style']['fontsize'].' Tf '.$form['style']['fontcolor'].')');
1277
- $form['FF'][] = 17;
1278
- $this->mpdf->_out('/Ff '.$this->_setflag($form['FF']) );
1279
- // Javascript
1280
- if ( isset($this->array_form_button_js[$form['T']]) ) {
1281
- $cc++;
1282
- $this->mpdf->_out("/AA << /D ".($cc + $this->mpdf->n)." 0 R >>");
1283
- $put_js = 1;
1284
- }
1285
- }
1286
-
1287
- $this->mpdf->_out('>>');
1288
- $this->mpdf->_out('endobj');
1289
-
1290
- // additional objects
1291
- // obj icon
1292
- if ( $put_icon == 1 ) {
1293
- $this->_put_button_icon( $this->form_button_icon[ $form['T'] ], $form['w'], $form['h'] );
1294
- $put_icon = NULL;
1295
- }
1296
- // obj + 1
1297
- if ( $put_js == 1 ) {
1298
- $this->mpdf->_set_object_javascript( $this->array_form_button_js[$form['T']]['js'] );
1299
- unset( $this->array_form_button_js[$form['T']] );
1300
- $put_js = NULL;
1301
- }
1302
-
1303
- // RADIO and CHECK BOX appearance streams
1304
- $filter=($this->mpdf->compress) ? '/Filter /FlateDecode ' : '';
1305
- if ( $form['subtype'] == 'radio' ) {
1306
- // output 2 appearance streams for radio buttons on/off
1307
- if ($this->formUseZapD) {
1308
- $fs = sprintf('%.3F', $form['style']['fontsize']*1.25);
1309
- $fi = 'czapfdingbats';
1310
- $r_on = 'q '.$radio_color .' rg BT /F'.$this->mpdf->fonts[$fi]['i'].' '.$fs.' Tf 0 0 Td (4) Tj ET Q';
1311
- $r_off = 'q '.$radio_color .' rg BT /F'.$this->mpdf->fonts[$fi]['i'].' '.$fs.' Tf 0 0 Td (8) Tj ET Q';
1312
- }
1313
- else {
1314
- $matrix = sprintf('%.3F 0 0 %.3F 0 %.3F', $form['style']['fontsize']*1.33/10, $form['style']['fontsize']*1.25/10, $form['style']['fontsize']);
1315
- $fill = $radio_background_color.' rg 3.778 -7.410 m 2.800 -7.410 1.947 -7.047 1.225 -6.322 c 0.500 -5.600 0.138 -4.747 0.138 -3.769 c 0.138 -2.788 0.500 -1.938 1.225 -1.213 c 1.947 -0.491 2.800 -0.128 3.778 -0.128 c 4.757 -0.128 5.610 -0.491 6.334 -1.213 c 7.056 -1.938 7.419 -2.788 7.419 -3.769 c 7.419 -4.747 7.056 -5.600 6.334 -6.322 c 5.610 -7.047 4.757 -7.410 3.778 -7.410 c h f ';
1316
- $circle = '3.778 -6.963 m 4.631 -6.963 5.375 -6.641 6.013 -6.004 c 6.653 -5.366 6.972 -4.619 6.972 -3.769 c 6.972 -2.916 6.653 -2.172 6.013 -1.532 c 5.375 -0.894 4.631 -0.576 3.778 -0.576 c 2.928 -0.576 2.182 -0.894 1.544 -1.532 c 0.904 -2.172 0.585 -2.916 0.585 -3.769 c 0.585 -4.619 0.904 -5.366 1.544 -6.004 c 2.182 -6.641 2.928 -6.963 3.778 -6.963 c h 3.778 -7.410 m 2.800 -7.410 1.947 -7.047 1.225 -6.322 c 0.500 -5.600 0.138 -4.747 0.138 -3.769 c 0.138 -2.788 0.500 -1.938 1.225 -1.213 c 1.947 -0.491 2.800 -0.128 3.778 -0.128 c 4.757 -0.128 5.610 -0.491 6.334 -1.213 c 7.056 -1.938 7.419 -2.788 7.419 -3.769 c 7.419 -4.747 7.056 -5.600 6.334 -6.322 c 5.610 -7.047 4.757 -7.410 3.778 -7.410 c h f ';
1317
- $r_on = 'q '.$matrix.' cm '.$fill .$radio_color.' rg '.$circle.' '.$radio_color.' rg
1318
- 5.184 -5.110 m 4.800 -5.494 4.354 -5.685 3.841 -5.685 c 3.331 -5.685 2.885 -5.494 2.501 -5.110 c 2.119 -4.725 1.925 -4.279 1.925 -3.769 c 1.925 -3.257 2.119 -2.810 2.501 -2.429 c 2.885 -2.044 3.331 -1.853 3.841 -1.853 c 4.354 -1.853 4.800 -2.044 5.184 -2.429 c 5.566 -2.810 5.760 -3.257 5.760 -3.769 c 5.760 -4.279 5.566 -4.725 5.184 -5.110 c h
1319
- f Q ';
1320
- $r_off = 'q '.$matrix.' cm '.$fill .$radio_color.' rg '.$circle.' Q ';
1321
- }
1322
-
1323
- $this->mpdf->_newobj();
1324
- $p=($this->mpdf->compress) ? gzcompress($r_on) : $r_on;
1325
- $this->mpdf->_out('<<'.$filter.'/Length '.strlen($p).' /Resources 2 0 R>>');
1326
- $this->mpdf->_putstream($p);
1327
- $this->mpdf->_out('endobj');
1328
-
1329
- $this->mpdf->_newobj();
1330
- $p=($this->mpdf->compress) ? gzcompress($r_off) : $r_off;
1331
- $this->mpdf->_out('<<'.$filter.'/Length '.strlen($p).' /Resources 2 0 R>>');
1332
- $this->mpdf->_putstream($p);
1333
- $this->mpdf->_out('endobj');
1334
- }
1335
- if ( $form['subtype'] == 'checkbox' ) {
1336
- // First output appearance stream for check box on
1337
- if ($this->formUseZapD) {
1338
- $fs = sprintf('%.3F', $form['style']['fontsize']*1.25);
1339
- $fi = 'czapfdingbats';
1340
- $cb_on = 'q '.$radio_color .' rg BT /F'.$this->mpdf->fonts[$fi]['i'].' '.$fs.' Tf 0 0 Td (4) Tj ET Q';
1341
- $cb_off = 'q '.$radio_color .' rg BT /F'.$this->mpdf->fonts[$fi]['i'].' '.$fs.' Tf 0 0 Td (8) Tj ET Q';
1342
- }
1343
- else {
1344
- $matrix = sprintf('%.3F 0 0 %.3F 0 %.3F', $form['style']['fontsize']*1.33/10, $form['style']['fontsize']*1.25/10, $form['style']['fontsize']);
1345
- $fill = $radio_background_color.' rg 7.395 -0.070 m 7.395 -7.344 l 0.121 -7.344 l 0.121 -0.070 l 7.395 -0.070 l h f ';
1346
- $square = '0.508 -6.880 m 6.969 -6.880 l 6.969 -0.534 l 0.508 -0.534 l 0.508 -6.880 l h 7.395 -0.070 m 7.395 -7.344 l 0.121 -7.344 l 0.121 -0.070 l 7.395 -0.070 l h ';
1347
- $cb_on = 'q '.$matrix.' cm '.$fill. $radio_color.' rg '.$square.' f '.$radio_color.' rg
1348
- 6.321 -1.352 m 5.669 -2.075 5.070 -2.801 4.525 -3.532 c 3.979 -4.262 3.508 -4.967 3.112 -5.649 c 3.080 -5.706 3.039 -5.779 2.993 -5.868 c 2.858 -6.118 2.638 -6.243 2.334 -6.243 c 2.194 -6.243 2.100 -6.231 2.052 -6.205 c 2.003 -6.180 1.954 -6.118 1.904 -6.020 c 1.787 -5.788 1.688 -5.523 1.604 -5.226 c 1.521 -4.930 1.480 -4.721 1.480 -4.600 c 1.480 -4.535 1.491 -4.484 1.512 -4.447 c 1.535 -4.410 1.579 -4.367 1.647 -4.319 c 1.733 -4.259 1.828 -4.210 1.935 -4.172 c 2.040 -4.134 2.131 -4.115 2.205 -4.115 c 2.267 -4.115 2.341 -4.232 2.429 -4.469 c 2.437 -4.494 2.444 -4.511 2.448 -4.522 c 2.451 -4.531 2.456 -4.546 2.465 -4.568 c 2.546 -4.795 2.614 -4.910 2.668 -4.910 c 2.714 -4.910 2.898 -4.652 3.219 -4.136 c 3.539 -3.620 3.866 -3.136 4.197 -2.683 c 4.426 -2.367 4.633 -2.103 4.816 -1.889 c 4.998 -1.676 5.131 -1.544 5.211 -1.493 c 5.329 -1.426 5.483 -1.368 5.670 -1.319 c 5.856 -1.271 6.066 -1.238 6.296 -1.217 c 6.321 -1.352 l h f Q ';
1349
- $cb_off = 'q '.$matrix.' cm '.$fill. $radio_color.' rg '.$square.' f Q ';
1350
-
1351
- }
1352
- $this->mpdf->_newobj();
1353
- $p=($this->mpdf->compress) ? gzcompress($cb_on) : $cb_on;
1354
- $this->mpdf->_out('<<'.$filter.'/Length '.strlen($p).' /Resources 2 0 R>>');
1355
- $this->mpdf->_putstream($p);
1356
- $this->mpdf->_out('endobj');
1357
-
1358
- // output appearance stream for check box off (only if not using ZapfDingbats)
1359
- if (!$this->formUseZapD) {
1360
- $this->mpdf->_newobj();
1361
- $p=($this->mpdf->compress) ? gzcompress($cb_off) : $cb_off;
1362
- $this->mpdf->_out('<<'.$filter.'/Length '.strlen($p).' /Resources 2 0 R>>');
1363
- $this->mpdf->_putstream($p);
1364
- $this->mpdf->_out('endobj');
1365
- }
1366
-
1367
- }
1368
- return $n;
1369
- }
1370
-
1371
-
1372
- function _putform_ch( $form, $hPt ) {
1373
- $put_js = 0;
1374
- $this->mpdf->_newobj();
1375
- $n = $this->mpdf->n;
1376
- $this->pdf_acro_array .= $n.' 0 R ';
1377
- $this->forms[ $form['n'] ]['obj'] = $n;
1378
-
1379
- $this->mpdf->_out('<<');
1380
- $this->mpdf->_out('/Type /Annot ');
1381
- $this->mpdf->_out('/Subtype /Widget');
1382
- $this->mpdf->_out('/Rect [ '.$this->_form_rect($form['x'],$form['y'],$form['w'],$form['h'], $hPt).' ]');
1383
- $this->mpdf->_out('/F 4');
1384
- $this->mpdf->_out('/FT /Ch');
1385
- if ($form['Q']) $this->mpdf->_out('/Q '.$form['Q'].'');
1386
- $temp = '';
1387
- $temp .= '/W '.$form['BS_W'].' ';
1388
- $temp .= '/S /'.$form['BS_S'].' ';
1389
- $this->mpdf->_out("/BS << $temp >>");
1390
-
1391
- $temp = '';
1392
- $temp .= '/BC [ '.$form['BC_C']." ] ";
1393
- $temp .= '/BG [ '.$form['BG_C']." ] ";
1394
- $this->mpdf->_out('/MK << '.$temp.' >>');
1395
-
1396
- $this->mpdf->_out('/NM '.$this->mpdf->_textstring(sprintf('%04u-%04u', $n, (6000 + $form['n']))));
1397
- $this->mpdf->_out('/M '.$this->mpdf->_textstring('D:'.date('YmdHis')));
1398
-
1399
- $this->mpdf->_out('/T '.$this->mpdf->_textstring($form['T']) );
1400
- $this->mpdf->_out('/DA (/F'.$this->mpdf->fonts[$form['style']['font']]['i'].' '.$form['style']['fontsize'].' Tf '.$form['style']['fontcolor'].')');
1401
-
1402
- $opt = '';
1403
- for( $i = 0; $i < count($form['OPT']['VAL']) ; $i++ ) {
1404
- $opt .= '[ '.$this->mpdf->_textstring($form['OPT']['VAL'][$i]).' '.$this->mpdf->_textstring($form['OPT']['OPT'][$i]).' ] ';
1405
- }
1406
- $this->mpdf->_out('/Opt [ '.$opt.']');
1407
-
1408
- // selected
1409
- $selectItem = false;
1410
- $selectIndex = false;
1411
- foreach ( $form['OPT']['SEL'] as $selectKey => $selectVal ) {
1412
- $selectName = $this->mpdf->_textstring($form['OPT']['VAL'][$selectVal]);
1413
- $selectItem .= ' '.$selectName.' ';
1414
- $selectIndex .= ' '.$selectVal.' ';
1415
- }
1416
- if ( $selectItem ) {
1417
- if (count($form['OPT']['SEL']) < 2) {
1418
- $this->mpdf->_out('/V '.$selectItem.' ');
1419
- $this->mpdf->_out('/DV '.$selectItem.' ');
1420
- }
1421
- else {
1422
- $this->mpdf->_out('/V ['.$selectItem.'] ');
1423
- $this->mpdf->_out('/DV ['.$selectItem.'] ');
1424
- }
1425
- $this->mpdf->_out('/I ['.$selectIndex.'] ');
1426
- }
1427
-
1428
- if ( is_array($form['FF']) && count($form['FF'])>0 ) {
1429
- $this->mpdf->_out('/Ff '.$this->_setflag($form['FF']).' ');
1430
- }
1431
- // Javascript
1432
- if ( isset($this->array_form_choice_js[$form['T']]) ) {
1433
- $this->mpdf->_out("/AA << /V ".($this->mpdf->n+1)." 0 R >>");
1434
- $put_js = 1;
1435
- }
1436
-
1437
- $this->mpdf->_out('>>');
1438
- $this->mpdf->_out('endobj');
1439
- // obj + 1
1440
- if ( $put_js == 1 ) {
1441
- $this->mpdf->_set_object_javascript( $this->array_form_choice_js[$form['T']]['js'] );
1442
- unset( $this->array_form_choice_js[$form['T']] );
1443
- $put_js = NULL;
1444
- }
1445
-
1446
- return $n;
1447
- }
1448
-
1449
-
1450
- function _putform_tx( $form, $hPt ) {
1451
- $put_js = 0;
1452
- $this->mpdf->_newobj();
1453
- $n = $this->mpdf->n;
1454
- $this->pdf_acro_array .= $n.' 0 R ';
1455
- $this->forms[ $form['n'] ]['obj'] = $n;
1456
-
1457
- $this->mpdf->_out('<<');
1458
- $this->mpdf->_out('/Type /Annot ');
1459
- $this->mpdf->_out('/Subtype /Widget ');
1460
-
1461
- $this->mpdf->_out('/Rect [ '.$this->_form_rect($form['x'],$form['y'],$form['w'],$form['h'], $hPt).' ] ');
1462
- $form['hidden'] ? $this->mpdf->_out('/F 2 ') : $this->mpdf->_out('/F 4 ');
1463
- $this->mpdf->_out('/FT /Tx ');
1464
-
1465
- $this->mpdf->_out('/H /N ');
1466
- $this->mpdf->_out('/R 0 ');
1467
-
1468
- if ( is_array($form['FF']) && count($form['FF'])>0 ) {
1469
- $this->mpdf->_out('/Ff '.$this->_setflag($form['FF']).' ');
1470
- }
1471
- if ( isset($form['maxlen']) && $form['maxlen']>0 ) {
1472
- $this->mpdf->_out('/MaxLen '.$form['maxlen']);
1473
- }
1474
-
1475
- $temp = '';
1476
- $temp .= '/W '.$form['BS_W'].' ';
1477
- $temp .= '/S /'.$form['BS_S'].' ';
1478
- $this->mpdf->_out("/BS << $temp >>");
1479
-
1480
- $temp = '';
1481
- $temp .= '/BC [ '.$form['BC_C']." ] ";
1482
- $temp .= '/BG [ '.$form['BG_C']." ] ";
1483
- $this->mpdf->_out('/MK <<'.$temp.' >>');
1484
-
1485
- $this->mpdf->_out('/T '.$this->mpdf->_textstring($form['T']) );
1486
- $this->mpdf->_out('/TU '.$this->mpdf->_textstring($form['TU']) );
1487
- if ($form['V'] || $form['V']==='0')
1488
- $this->mpdf->_out('/V '.$this->mpdf->_textstring($form['V']) );
1489
- $this->mpdf->_out('/DV '.$this->mpdf->_textstring($form['DV']) );
1490
- $this->mpdf->_out('/DA (/F'.$this->mpdf->fonts[$form['style']['font']]['i'].' '.$form['style']['fontsize'].' Tf '.$form['style']['fontcolor'].')');
1491
- if ( $form['Q'] ) $this->mpdf->_out('/Q '.$form['Q'].'');
1492
-
1493
- $this->mpdf->_out('/NM '.$this->mpdf->_textstring(sprintf('%04u-%04u', $n, (5000 + $form['n']))));
1494
- $this->mpdf->_out('/M '.$this->mpdf->_textstring('D:'.date('YmdHis')));
1495
-
1496
-
1497
- if ( isset($this->array_form_text_js[$form['T']]) ) {
1498
- $put_js = 1;
1499
- $cc = 0;
1500
- $js_str = '';
1501
-
1502
- if ( isset($this->array_form_text_js[$form['T']]['F']) ) {
1503
- $cc++;
1504
- $js_str .= '/F '.($cc + $this->mpdf->n).' 0 R ';
1505
- }
1506
- if ( isset($this->array_form_text_js[$form['T']]['K']) ) {
1507
- $cc++;
1508
- $js_str .= '/K '.($cc + $this->mpdf->n).' 0 R ';
1509
- }
1510
- if ( isset($this->array_form_text_js[$form['T']]['V']) ) {
1511
- $cc++;
1512
- $js_str .= '/V '.($cc + $this->mpdf->n).' 0 R ';
1513
- }
1514
- if ( isset($this->array_form_text_js[$form['T']]['C']) ) {
1515
- $cc++;
1516
- $js_str .= '/C '.($cc + $this->mpdf->n).' 0 R ';
1517
- $this->pdf_array_co .= $this->mpdf->n.' 0 R ';
1518
- }
1519
- $this->mpdf->_out('/AA << '.$js_str.' >>');
1520
- }
1521
-
1522
- $this->mpdf->_out('>>');
1523
- $this->mpdf->_out('endobj');
1524
-
1525
- if ( $put_js == 1 ) {
1526
- if ( isset($this->array_form_text_js[$form['T']]['F']) ) {
1527
- $this->mpdf->_set_object_javascript( $this->array_form_text_js[$form['T']]['F']['js'] );
1528
- unset( $this->array_form_text_js[$form['T']]['F'] );
1529
- }
1530
- if ( isset($this->array_form_text_js[$form['T']]['K']) ) {
1531
- $this->mpdf->_set_object_javascript( $this->array_form_text_js[$form['T']]['K']['js'] );
1532
- unset( $this->array_form_text_js[$form['T']]['K'] );
1533
- }
1534
- if ( isset($this->array_form_text_js[$form['T']]['V']) ) {
1535
- $this->mpdf->_set_object_javascript( $this->array_form_text_js[$form['T']]['V']['js'] );
1536
- unset( $this->array_form_text_js[$form['T']]['V'] );
1537
- }
1538
- if ( isset($this->array_form_text_js[$form['T']]['C']) ) {
1539
- $this->mpdf->_set_object_javascript( $this->array_form_text_js[$form['T']]['C']['js'] );
1540
- unset( $this->array_form_text_js[$form['T']]['C'] );
1541
- }
1542
- }
1543
- return $n;
1544
- }
1545
-
1546
-
1547
-
1548
- }
1549
-
1550
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/mpdf/classes/myanmar.php DELETED
@@ -1,481 +0,0 @@
1
- <?php
2
-
3
-
4
- class MYANMAR {
5
-
6
- /* FROM hb-ot-shape-complex-indic-private.hh */
7
- // indic_category
8
- const OT_X = 0;
9
- const OT_C = 1;
10
- const OT_V = 2;
11
- const OT_N = 3;
12
- const OT_H = 4;
13
- const OT_ZWNJ = 5;
14
- const OT_ZWJ = 6;
15
- const OT_M = 7; /* Matra or Dependent Vowel */
16
- const OT_SM = 8;
17
- const OT_VD = 9;
18
- const OT_A = 10;
19
- const OT_NBSP = 11;
20
- const OT_DOTTEDCIRCLE = 12; /* Not in the spec, but special in Uniscribe. /Very very/ special! */
21
- const OT_RS = 13; /* Register Shifter, used in Khmer OT spec */
22
- const OT_Coeng = 14;
23
- const OT_Repha = 15;
24
- const OT_Ra = 16; /* Not explicitly listed in the OT spec, but used in the grammar. */
25
- const OT_CM = 17;
26
-
27
- /* FROM hb-ot-shape-complex-myanmar.hh */
28
- // myanmar_category
29
- const OT_DB = 3; // same as INDIC::OT_N; /* Dot below */
30
- const OT_GB = 12; // same as INDIC::OT_DOTTEDCIRCLE;
31
-
32
- const OT_As = 18; /* Asat */
33
- const OT_D = 19; /* Digits except zero */
34
- const OT_D0 = 20; /* Digit zero */
35
- const OT_MH = 21; /* Various consonant medial types */
36
- const OT_MR = 22; /* Various consonant medial types */
37
- const OT_MW = 23; /* Various consonant medial types */
38
- const OT_MY = 24; /* Various consonant medial types */
39
- const OT_PT = 25; /* Pwo and other tones */
40
- const OT_VAbv = 26;
41
- const OT_VBlw = 27;
42
- const OT_VPre = 28;
43
- const OT_VPst = 29;
44
- const OT_VS = 30; /* Variation selectors */
45
-
46
-
47
- // Based on myanmar_category used to make string to find syllables
48
- // OT_ to string character (using e.g. OT_C from MYANMAR) hb-ot-shape-complex-myanmar-private.hh
49
- public static $myanmar_category_char = array(
50
- 'x',
51
- 'C',
52
- 'V',
53
- 'N',
54
- 'H',
55
- 'Z',
56
- 'J',
57
- 'x',
58
- 'S',
59
- 'x',
60
- 'A',
61
- 'x',
62
- 'D',
63
- 'x',
64
- 'x',
65
- 'x',
66
- 'R',
67
- 'x',
68
-
69
-
70
- 'a', /* As Asat */
71
- 'd', /* Digits except zero */
72
- 'o', /* Digit zero */
73
- 'k', /* Medial types */
74
- 'l', /* Medial types */
75
- 'm', /* Medial types */
76
- 'n', /* Medial types */
77
- 'p', /* Pwo and other tones */
78
- 'v', /* Vowel aboVe */
79
- 'b', /* Vowel Below */
80
- 'e', /* Vowel prE */
81
- 't', /* Vowel posT */
82
- 's', /* variation Selector */
83
-
84
- );
85
-
86
-
87
- /* Visual positions in a syllable from left to right. */
88
- /* FROM hb-ot-shape-complex-myanmar-private.hh */
89
- // myanmar_position
90
- const POS_START = 0;
91
-
92
- const POS_RA_TO_BECOME_REPH = 1;
93
- const POS_PRE_M = 2;
94
- const POS_PRE_C = 3;
95
-
96
- const POS_BASE_C = 4;
97
- const POS_AFTER_MAIN = 5;
98
-
99
- const POS_ABOVE_C = 6;
100
-
101
- const POS_BEFORE_SUB = 7;
102
- const POS_BELOW_C = 8;
103
- const POS_AFTER_SUB = 9;
104
-
105
- const POS_BEFORE_POST = 10;
106
- const POS_POST_C = 11;
107
- const POS_AFTER_POST = 12;
108
-
109
- const POS_FINAL_C = 13;
110
- const POS_SMVD = 14;
111
-
112
- const POS_END = 15;
113
-
114
-
115
-
116
- public static function set_myanmar_properties(&$info) {
117
- $u = $info['uni'];
118
- $type = self::myanmar_get_categories($u);
119
- $cat = ($type & 0x7F);
120
- $pos = ($type >> 8);
121
- /*
122
- * Re-assign category
123
- * http://www.microsoft.com/typography/OpenTypeDev/myanmar/intro.htm#analyze
124
- */
125
- if (self::in_range($u, 0xFE00, 0xFE0F))
126
- $cat = self::OT_VS;
127
- else if ($u == 0x200C) $cat = self::OT_ZWNJ;
128
- else if ($u == 0x200D) $cat = self::OT_ZWJ;
129
-
130
- switch ($u) {
131
- case 0x002D: case 0x00A0: case 0x00D7: case 0x2012:
132
- case 0x2013: case 0x2014: case 0x2015: case 0x2022:
133
- case 0x25CC: case 0x25FB: case 0x25FC: case 0x25FD:
134
- case 0x25FE:
135
- $cat = self::OT_GB;
136
- break;
137
-
138
- case 0x1004: case 0x101B: case 0x105A:
139
- $cat = self::OT_Ra;
140
- break;
141
-
142
- case 0x1032: case 0x1036:
143
- $cat = self::OT_A;
144
- break;
145
-
146
- case 0x103A:
147
- $cat = self::OT_As;
148
- break;
149
-
150
- case 0x1041: case 0x1042: case 0x1043: case 0x1044:
151
- case 0x1045: case 0x1046: case 0x1047: case 0x1048:
152
- case 0x1049: case 0x1090: case 0x1091: case 0x1092:
153
- case 0x1093: case 0x1094: case 0x1095: case 0x1096:
154
- case 0x1097: case 0x1098: case 0x1099:
155
- $cat = self::OT_D;
156
- break;
157
-
158
- case 0x1040:
159
- $cat = self::OT_D; /* XXX The spec says D0, but Uniscribe doesn't seem to do. */
160
- break;
161
-
162
- case 0x103E: case 0x1060:
163
- $cat = self::OT_MH;
164
- break;
165
-
166
- case 0x103C:
167
- $cat = self::OT_MR;
168
- break;
169
-
170
- case 0x103D: case 0x1082:
171
- $cat = self::OT_MW;
172
- break;
173
-
174
- case 0x103B: case 0x105E: case 0x105F:
175
- $cat = self::OT_MY;
176
- break;
177
-
178
- case 0x1063: case 0x1064: case 0x1069: case 0x106A:
179
- case 0x106B: case 0x106C: case 0x106D: case 0xAA7B:
180
- $cat = self::OT_PT;
181
- break;
182
-
183
- case 0x1038: case 0x1087: case 0x1088: case 0x1089:
184
- case 0x108A: case 0x108B: case 0x108C: case 0x108D:
185
- case 0x108F: case 0x109A: case 0x109B: case 0x109C:
186
- $cat = self::OT_SM;
187
- break;
188
- }
189
-
190
- if ($cat == self::OT_M) {
191
- switch ($pos) {
192
- case self::POS_PRE_C:
193
- $cat = self::OT_VPre;
194
- $pos = self::POS_PRE_M;
195
- break;
196
- case self::POS_ABOVE_C: $cat = self::OT_VAbv; break;
197
- case self::POS_BELOW_C: $cat = self::OT_VBlw; break;
198
- case self::POS_POST_C: $cat = self::OT_VPst; break;
199
- }
200
- }
201
- $info['myanmar_category'] = $cat;
202
- $info['myanmar_position'] = $pos;
203
- }
204
-
205
- // syllable_type
206
- const CONSONANT_SYLLABLE = 0;
207
- const BROKEN_CLUSTER = 3;
208
- const NON_MYANMAR_CLUSTER = 4;
209
-
210
-
211
-
212
- public static function set_syllables(&$o, $s, &$broken_syllables) {
213
- $ptr = 0;
214
- $syllable_serial = 1;
215
- $broken_syllables = false;
216
-
217
- while($ptr < strlen($s)) {
218
- $match = '';
219
- $syllable_length = 1;
220
- $syllable_type = self::NON_MYANMAR_CLUSTER ;
221
- // CONSONANT_SYLLABLE Consonant syllable
222
- // From OT spec:
223
- if (preg_match('/^(RaH)?([C|R]|V|d|D)[s]?(H([C|R|V])[s]?)*(H|[a]*[n]?[l]?((m[k]?|k)[a]?)?[e]*[v]*[b]*[A]*(N[a]?)?(t[k]?[a]*[v]*[A]*(N[a]?)?)*(p[A]*(N[a]?)?)*S*[J|Z]?)/', substr($s,$ptr), $ma)) {
224
- $syllable_length = strlen($ma[0]);
225
- $syllable_type = self::CONSONANT_SYLLABLE ;
226
- }
227
-
228
- // BROKEN_CLUSTER syllable
229
- else if (preg_match('/^(RaH)?s?(H|[a]*[n]?[l]?((m[k]?|k)[a]?)?[e]*[v]*[b]*[A]*(N[a]?)?(t[k]?[a]*[v]*[A]*(N[a]?)?)*(p[A]*(N[a]?)?)*S*[J|Z]?)/', substr($s,$ptr), $ma)) {
230
- if (strlen($ma[0])) { // May match blank
231
- $syllable_length = strlen($ma[0]);
232
- $syllable_type = self::BROKEN_CLUSTER ;
233
- $broken_syllables = true;
234
- }
235
- }
236
- for ($i = $ptr; $i < $ptr+$syllable_length; $i++) { $o[$i]['syllable'] = ($syllable_serial << 4) | $syllable_type; }
237
- $ptr += $syllable_length ;
238
- $syllable_serial++;
239
- if ($syllable_serial == 16) $syllable_serial = 1;
240
- }
241
- }
242
-
243
-
244
-
245
- public static function reordering(&$info, $GSUBdata, $broken_syllables, $dottedcircle) {
246
- if ($broken_syllables && $dottedcircle) { self::insert_dotted_circles ($info, $dottedcircle); }
247
- $count = count($info);
248
- if (!$count) return;
249
- $last = 0;
250
- $last_syllable = $info[0]['syllable'];
251
- for ($i = 1; $i < $count; $i++) {
252
- if ($last_syllable != $info[$i]['syllable']) {
253
- self::reordering_syllable ($info, $GSUBdata, $last, $i);
254
- $last = $i;
255
- $last_syllable = $info[$last]['syllable'];
256
- }
257
- }
258
- self::reordering_syllable($info, $GSUBdata, $last, $count);
259
- }
260
-
261
- public static function insert_dotted_circles(&$info, $dottedcircle) {
262
- $idx = 0;
263
- $last_syllable = 0;
264
- while ($idx < count($info)) {
265
- $syllable = $info[$idx]['syllable'];
266
- $syllable_type = ($syllable & 0x0F);
267
- if ($last_syllable != $syllable && $syllable_type == self::BROKEN_CLUSTER) {
268
- $last_syllable = $syllable;
269
- $dottedcircle[0]['syllable'] = $info[$idx]['syllable'];
270
- array_splice($info, $idx, 0, $dottedcircle);
271
- }
272
- else
273
- $idx++;
274
- }
275
- // In case of final bloken cluster...
276
- $syllable = $info[$idx]['syllable'];
277
- $syllable_type = ($syllable & 0x0F);
278
- if ($last_syllable != $syllable && $syllable_type == self::BROKEN_CLUSTER) {
279
- $dottedcircle[0]['syllable'] = $info[$idx]['syllable'];
280
- array_splice($info, $idx, 0, $dottedcircle);
281
- }
282
- }
283
-
284
-
285
-
286
- /* Rules from:
287
- * https://www.microsoft.com/typography/otfntdev/devanot/shaping.aspx */
288
-
289
- public static function reordering_syllable (&$info, $GSUBdata, $start, $end) {
290
- /* vowel_syllable: We made the vowels look like consonants. So uses the consonant logic! */
291
- /* broken_cluster: We already inserted dotted-circles, so just call the standalone_cluster. */
292
-
293
- $syllable_type = ($info[$start]['syllable'] & 0x0F);
294
- if ($syllable_type==self::NON_MYANMAR_CLUSTER ) { return; }
295
- if ($syllable_type==self::BROKEN_CLUSTER) {
296
- //if ($uniscribe_bug_compatible) {
297
- /* For dotted-circle, this is what Uniscribe does:
298
- * If dotted-circle is the last glyph, it just does nothing.
299
- * i.e. It doesn't form Reph. */
300
- if ($info[$end - 1]['myanmar_category'] == self::OT_DOTTEDCIRCLE) {
301
- return;
302
- }
303
- }
304
-
305
- $base = $end;
306
- $has_reph = false;
307
- $limit = $start;
308
-
309
- if (($start + 3 <= $end) &&
310
- $info[$start]['myanmar_category'] == self::OT_Ra &&
311
- $info[$start+1]['myanmar_category'] == self::OT_As &&
312
- $info[$start+2]['myanmar_category'] == self::OT_H ) {
313
- $limit += 3;
314
- $base = $start;
315
- $has_reph = true;
316
- }
317
-
318
- if (!$has_reph)
319
- $base = $limit;
320
-
321
- for ($i = $limit; $i < $end; $i++) {
322
- if (self::is_consonant($info[$i])) {
323
- $base = $i;
324
- break;
325
- }
326
- }
327
-
328
-
329
- /* Reorder! */
330
- $i = $start;
331
- for (; $i < $start + ($has_reph ? 3 : 0); $i++)
332
- $info[$i]['myanmar_position'] = self::POS_AFTER_MAIN;
333
- for (; $i < $base; $i++)
334
- $info[$i]['myanmar_position'] = self::POS_PRE_C;
335
- if ($i < $end) {
336
- $info[$i]['myanmar_position'] = self::POS_BASE_C;
337
- $i++;
338
- }
339
- $pos = self::POS_AFTER_MAIN;
340
- /* The following loop may be ugly, but it implements all of
341
- * Myanmar reordering! */
342
- for (; $i < $end; $i++) {
343
- if ($info[$i]['myanmar_category'] == self::OT_MR) /* Pre-base reordering */
344
- {
345
- $info[$i]['myanmar_position'] = self::POS_PRE_C;
346
- continue;
347
- }
348
- if ($info[$i]['myanmar_position'] < self::POS_BASE_C) /* Left matra */
349
- {
350
- continue;
351
- }
352
-
353
- if ($pos == self::POS_AFTER_MAIN && $info[$i]['myanmar_category'] == self::OT_VBlw)
354
- {
355
- $pos = self::POS_BELOW_C;
356
- $info[$i]['myanmar_position'] = $pos;
357
- continue;
358
- }
359
-
360
- if ($pos == self::POS_BELOW_C && $info[$i]['myanmar_category'] == self::OT_A)
361
- {
362
- $info[$i]['myanmar_position'] = self::POS_BEFORE_SUB;
363
- continue;
364
- }
365
- if ($pos == self::POS_BELOW_C && $info[$i]['myanmar_category'] == self::OT_VBlw)
366
- {
367
- $info[$i]['myanmar_position'] = $pos;
368
- continue;
369
- }
370
- if ($pos == self::POS_BELOW_C && $info[$i]['myanmar_category'] != self::OT_A)
371
- {
372
- $pos = self::POS_AFTER_SUB;
373
- $info[$i]['myanmar_position'] = $pos;
374
- continue;
375
- }
376
- $info[$i]['myanmar_position'] = $pos;
377
- }
378
-
379
-
380
- /* Sit tight, rock 'n roll! */
381
- self::bubble_sort ($info, $start, $end - $start);
382
-
383
- }
384
-
385
-
386
- public static function is_one_of ($info, $flags) {
387
- if (isset($info['is_ligature']) && $info['is_ligature']) return false; /* If it ligated, all bets are off. */
388
- return !!(self::FLAG($info['myanmar_category']) & $flags);
389
- }
390
-
391
- /* Vowels and placeholders treated as if they were consonants. */
392
- public static function is_consonant($info) {
393
- return self::is_one_of($info, (self::FLAG(self::OT_C) | self::FLAG(self::OT_CM) | self::FLAG(self::OT_Ra) | self::FLAG(self::OT_V) | self::FLAG(self::OT_NBSP) | self::FLAG(self::OT_GB)));
394
- }
395
-
396
-
397
-
398
- // From hb-private.hh
399
- public static function in_range ($u, $lo, $hi) {
400
- if ( (($lo^$hi) & $lo) == 0 && (($lo^$hi) & $hi) == ($lo^$hi) && (($lo^$hi) & (($lo^$hi) + 1)) == 0 )
401
- return ($u & ~($lo^$hi)) == $lo;
402
- else
403
- return $lo <= $u && $u <= $hi;
404
- }
405
-
406
- // From hb-private.hh
407
- public static function FLAG($x) { return (1<<($x)); }
408
-
409
- public static function FLAG_RANGE($x,$y) { self::FLAG(y+1) - self::FLAG(x); }
410
-
411
-
412
-
413
- // BELOW from hb-ot-shape-complex-indic.cc
414
- // see INDIC for details
415
-
416
- public static $myanmar_table = array(
417
-
418
- /* Myanmar (1000..109F) */
419
-
420
- /* 1000 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
421
- /* 1008 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
422
- /* 1010 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
423
- /* 1018 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
424
- /* 1020 */ 3841, 3842, 3842, 3842, 3842, 3842, 3842, 3842,
425
- /* 1028 */ 3842, 3842, 3842, 2823, 2823, 1543, 1543, 2055,
426
- /* 1030 */ 2055, 775, 1543, 1543, 1543, 1543, 3848, 3843,
427
- /* 1038 */ 3848, 3844, 1540, 3857, 3857, 3857, 3857, 3841,
428
- /* 1040 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
429
- /* 1048 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
430
- /* 1050 */ 3841, 3841, 3842, 3842, 3842, 3842, 2823, 2823,
431
- /* 1058 */ 2055, 2055, 3841, 3841, 3841, 3841, 3857, 3857,
432
- /* 1060 */ 3857, 3841, 2823, 3843, 3843, 3841, 3841, 2823,
433
- /* 1068 */ 2823, 3843, 3843, 3843, 3843, 3843, 3841, 3841,
434
- /* 1070 */ 3841, 1543, 1543, 1543, 1543, 3841, 3841, 3841,
435
- /* 1078 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
436
- /* 1080 */ 3841, 3841, 3857, 2823, 775, 1543, 1543, 3843,
437
- /* 1088 */ 3843, 3843, 3843, 3843, 3843, 3843, 3841, 3843,
438
- /* 1090 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
439
- /* 1098 */ 3840, 3840, 3843, 3843, 2823, 1543, 3840, 3840,
440
-
441
- /* Myanmar Extended-A (AA60..AA7F) */
442
-
443
- /* AA60 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
444
- /* AA68 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
445
- /* AA70 */ 3840, 3841, 3841, 3841, 3840, 3840, 3840, 3840,
446
- /* AA78 */ 3840, 3840, 3841, 3843, 3840, 3840, 3840, 3840,
447
-
448
-
449
- );
450
-
451
- // from "hb-ot-shape-complex-indic-table.cc"
452
- public static function myanmar_get_categories ($u) {
453
- if (0x1000 <= $u && $u <= 0x109F) return self::$myanmar_table[$u - 0x1000 + 0]; // offset 0 for Most "myanmar"
454
- if (0xAA60 <= $u && $u <= 0xAA7F) return self::$myanmar_table[$u - 0xAA60 + 160]; // offset for extensions
455
- if ($u == 0x00A0) return 3851; // (ISC_CP | (IMC_x << 8))
456
- if ($u == 0x25CC) return 3851; // (ISC_CP | (IMC_x << 8))
457
- return 3840; // (ISC_x | (IMC_x << 8))
458
- }
459
-
460
-
461
- public static function bubble_sort(&$arr, $start, $len) {
462
- if ($len<2) { return;}
463
- $k = $start+$len-2;
464
- while ($k >= $start) {
465
- for ($j=$start; $j<=$k; $j++) {
466
- if ($arr[$j]['myanmar_position'] > $arr[$j + 1]['myanmar_position']) {
467
- $t = $arr[$j];
468
- $arr[$j] = $arr[$j + 1];
469
- $arr[$j + 1] = $t;
470
- }
471
- }
472
- $k--;
473
- }
474
- }
475
-
476
-
477
-
478
-
479
- } // end Class
480
-
481
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/mpdf/classes/otl.php DELETED
@@ -1,5719 +0,0 @@
1
- <?php
2
-
3
- define("_OTL_OLD_SPEC_COMPAT_1", true);
4
-
5
- define("_DICT_NODE_TYPE_SPLIT", 0x01);
6
- define("_DICT_NODE_TYPE_LINEAR", 0x02);
7
- define("_DICT_INTERMEDIATE_MATCH", 0x03);
8
- define("_DICT_FINAL_MATCH", 0x04);
9
-
10
-
11
-
12
- class otl {
13
-
14
- var $mpdf;
15
- var $arabLeftJoining;
16
- var $arabRightJoining;
17
- var $arabTransparentJoin;
18
- var $arabTransparent;
19
- var $GSUBdata;
20
- var $GPOSdata;
21
- var $GSUBfont;
22
- var $fontkey;
23
- var $ttfOTLdata;
24
- var $glyphIDtoUni;
25
- var $_pos;
26
- var $GSUB_offset;
27
- var $GPOS_offset;
28
- var $MarkAttachmentType;
29
- var $MarkGlyphSets;
30
- var $GlyphClassMarks;
31
- var $GlyphClassLigatures;
32
- var $GlyphClassBases;
33
- var $GlyphClassComponents;
34
- var $Ignores;
35
- var $LuCoverage;
36
- var $OTLdata;
37
- var $assocLigs;
38
- var $assocMarks;
39
- var $shaper;
40
- var $restrictToSyllable;
41
- var $lbdicts; // Line-breaking dictionaries
42
- var $LuDataCache;
43
-
44
- var $debugOTL = false;
45
-
46
- function otl(&$mpdf) {
47
- $this->mpdf = $mpdf;
48
-
49
- $this->arabic_initialise();
50
- $this->current_fh = '';
51
-
52
- $this->lbdicts = array();
53
- $this->LuDataCache = array();
54
- }
55
-
56
- ////////////////////////////////////////////////////////////////
57
- ////////////////////////////////////////////////////////////////
58
- ////////// APPLY OTL ////////////////////////////
59
- ////////////////////////////////////////////////////////////////
60
- ////////////////////////////////////////////////////////////////
61
-
62
- function applyOTL($str, $useOTL) {
63
- $this->OTLdata = array();
64
- if (trim($str)=='') { return $str; }
65
- if (!$useOTL) { return $str; }
66
-
67
- // 1. Load GDEF data
68
- //==============================
69
- $this->fontkey = $this->mpdf->CurrentFont['fontkey'];
70
- $this->glyphIDtoUni = $this->mpdf->CurrentFont['glyphIDtoUni'];
71
- if (!isset($this->GDEFdata[$this->fontkey])) {
72
- include(_MPDF_TTFONTDATAPATH.$this->fontkey.'.GDEFdata.php');
73
- $this->GSUB_offset = $this->GDEFdata[$this->fontkey]['GSUB_offset'] = $GSUB_offset;
74
- $this->GPOS_offset = $this->GDEFdata[$this->fontkey]['GPOS_offset'] = $GPOS_offset;
75
- $this->GSUB_length = $this->GDEFdata[$this->fontkey]['GSUB_length'] = $GSUB_length;
76
- $this->MarkAttachmentType = $this->GDEFdata[$this->fontkey]['MarkAttachmentType'] = $MarkAttachmentType;
77
- $this->MarkGlyphSets = $this->GDEFdata[$this->fontkey]['MarkGlyphSets'] = $MarkGlyphSets;
78
- $this->GlyphClassMarks = $this->GDEFdata[$this->fontkey]['GlyphClassMarks'] = $GlyphClassMarks;
79
- $this->GlyphClassLigatures = $this->GDEFdata[$this->fontkey]['GlyphClassLigatures'] = $GlyphClassLigatures;
80
- $this->GlyphClassComponents = $this->GDEFdata[$this->fontkey]['GlyphClassComponents'] = $GlyphClassComponents;
81
- $this->GlyphClassBases = $this->GDEFdata[$this->fontkey]['GlyphClassBases'] = $GlyphClassBases;
82
- }
83
- else {
84
- $this->GSUB_offset = $this->GDEFdata[$this->fontkey]['GSUB_offset'];
85
- $this->GPOS_offset = $this->GDEFdata[$this->fontkey]['GPOS_offset'];
86
- $this->GSUB_length = $this->GDEFdata[$this->fontkey]['GSUB_length'];
87
- $this->MarkAttachmentType = $this->GDEFdata[$this->fontkey]['MarkAttachmentType'];
88
- $this->MarkGlyphSets = $this->GDEFdata[$this->fontkey]['MarkGlyphSets'];
89
- $this->GlyphClassMarks = $this->GDEFdata[$this->fontkey]['GlyphClassMarks'];
90
- $this->GlyphClassLigatures = $this->GDEFdata[$this->fontkey]['GlyphClassLigatures'];
91
- $this->GlyphClassComponents = $this->GDEFdata[$this->fontkey]['GlyphClassComponents'];
92
- $this->GlyphClassBases = $this->GDEFdata[$this->fontkey]['GlyphClassBases'];
93
- }
94
-
95
- // 2. Prepare string as HEX string and Analyse character properties
96
- //=================================================================
97
- $earr = $this->mpdf->UTF8StringToArray($str, false);
98
-
99
- $scriptblock = 0;
100
- $scriptblocks = array();
101
- $scriptblocks[0] = 0;
102
- $vstr = '';
103
- $OTLdata = array();
104
- $subchunk = 0;
105
- $charctr = 0;
106
- foreach($earr as $char) {
107
- $ucd_record = UCDN::get_ucd_record($char);
108
- $sbl = $ucd_record[6];
109
-
110
- // Special case - Arabic End of Ayah
111
- if ($char==1757) { $sbl = UCDN::SCRIPT_ARABIC; }
112
-
113
- if ($sbl && $sbl != 40 && $sbl != 102) {
114
- if ($scriptblock == 0) { $scriptblock = $sbl; $scriptblocks[$subchunk] = $scriptblock; }
115
- else if ($scriptblock > 0 && $scriptblock != $sbl) {
116
- // *************************************************
117
- // NEW (non-common) Script encountered in this chunk. Start a new subchunk
118
- $subchunk++;
119
- $scriptblock = $sbl;
120
- $charctr = 0;
121
- $scriptblocks[$subchunk] = $scriptblock;
122
- }
123
- }
124
-
125
- $OTLdata[$subchunk][$charctr]['general_category'] = $ucd_record[0];
126
- $OTLdata[$subchunk][$charctr]['bidi_type'] = $ucd_record[2];
127
-
128
- //$OTLdata[$subchunk][$charctr]['combining_class'] = $ucd_record[1];
129
- //$OTLdata[$subchunk][$charctr]['bidi_type'] = $ucd_record[2];
130
- //$OTLdata[$subchunk][$charctr]['mirrored'] = $ucd_record[3];
131
- //$OTLdata[$subchunk][$charctr]['east_asian_width'] = $ucd_record[4];
132
- //$OTLdata[$subchunk][$charctr]['normalization_check'] = $ucd_record[5];
133
- //$OTLdata[$subchunk][$charctr]['script'] = $ucd_record[6];
134
-
135
- $charasstr = $this->unicode_hex($char);
136
-
137
- if (strpos($this->GlyphClassMarks, $charasstr)!==false) { $OTLdata[$subchunk][$charctr]['group'] = 'M'; }
138
- else if ($char == 32 || $char == 12288) { $OTLdata[$subchunk][$charctr]['group'] = 'S'; } // 12288 = 0x3000 = CJK space
139
- else { $OTLdata[$subchunk][$charctr]['group'] = 'C'; }
140
-
141
- $OTLdata[$subchunk][$charctr]['uni'] = $char;
142
- $OTLdata[$subchunk][$charctr]['hex'] = $charasstr;
143
- $charctr++;
144
- }
145
-
146
- /* PROCESS EACH SUBCHUNK WITH DIFFERENT SCRIPTS */
147
- for($sch=0;$sch<=$subchunk;$sch++) {
148
- $this->OTLdata = $OTLdata[$sch];
149
- $scriptblock = $scriptblocks[$sch];
150
-
151
- // 3. Get Appropriate Scripts, and Shaper engine from analysing text and list of available scripts/langsys in font
152
- //==============================
153
- // Based on actual script block of text, select shaper (and line-breaking dictionaries)
154
- if (UCDN::SCRIPT_DEVANAGARI <= $scriptblock && $scriptblock <= UCDN::SCRIPT_MALAYALAM) { $this->shaper = "I"; } // INDIC shaper
155
- else if ($scriptblock == UCDN::SCRIPT_ARABIC || $scriptblock == UCDN::SCRIPT_SYRIAC) { $this->shaper = "A"; } // ARABIC shaper
156
- else if ($scriptblock == UCDN::SCRIPT_NKO || $scriptblock == UCDN::SCRIPT_MANDAIC) { $this->shaper = "A"; } // ARABIC shaper
157
- else if ($scriptblock == UCDN::SCRIPT_KHMER) { $this->shaper = "K"; } // KHMER shaper
158
- else if ($scriptblock == UCDN::SCRIPT_THAI) { $this->shaper = "T"; } // THAI shaper
159
- else if ($scriptblock == UCDN::SCRIPT_LAO) { $this->shaper = "L"; } // LAO shaper
160
- else if ($scriptblock == UCDN::SCRIPT_SINHALA) { $this->shaper = "S"; } // SINHALA shaper
161
- else if ($scriptblock == UCDN::SCRIPT_MYANMAR) { $this->shaper = "M"; } // MYANMAR shaper
162
- else if ($scriptblock == UCDN::SCRIPT_NEW_TAI_LUE) { $this->shaper = "E"; } // SEA South East Asian shaper
163
- else if ($scriptblock == UCDN::SCRIPT_CHAM) { $this->shaper = "E"; } // SEA South East Asian shaper
164
- else if ($scriptblock == UCDN::SCRIPT_TAI_THAM) { $this->shaper = "E"; } // SEA South East Asian shaper
165
- else $this->shaper = "";
166
- // Get scripttag based on actual text script
167
- $scripttag = UCDN::$uni_scriptblock[$scriptblock];
168
-
169
- $GSUBscriptTag = '';
170
- $GSUBlangsys = '';
171
- $GPOSscriptTag = '';
172
- $GPOSlangsys = '';
173
- $is_old_spec = false;
174
-
175
- $ScriptLang = $this->mpdf->CurrentFont['GSUBScriptLang'];
176
- if (count($ScriptLang)) {
177
- list($GSUBscriptTag,$is_old_spec) = $this->_getOTLscriptTag($ScriptLang, $scripttag, $scriptblock, $this->shaper, $useOTL, 'GSUB');
178
- if ($this->mpdf->fontLanguageOverride && strpos($ScriptLang[$GSUBscriptTag], $this->mpdf->fontLanguageOverride)!==false) {
179
- $GSUBlangsys = str_pad($this->mpdf->fontLanguageOverride,4);
180
- }
181
- else if ($GSUBscriptTag && isset($ScriptLang[$GSUBscriptTag]) && $ScriptLang[$GSUBscriptTag]!='') {
182
- $GSUBlangsys = $this->_getOTLLangTag($this->mpdf->currentLang, $ScriptLang[$GSUBscriptTag]);
183
- }
184
- }
185
- $ScriptLang = $this->mpdf->CurrentFont['GPOSScriptLang'];
186
-
187
- // NB If after GSUB, the same script/lang exist for GPOS, just use these...
188
- if ($GSUBscriptTag && $GSUBlangsys && isset($ScriptLang[$GSUBscriptTag]) && strpos($ScriptLang[$GSUBscriptTag], $GSUBlangsys)!==false) {
189
- $GPOSlangsys = $GSUBlangsys;
190
- $GPOSscriptTag = $GSUBscriptTag;
191
- }
192
-
193
- // else repeat for GPOS
194
- // [Font XBRiyaz has GSUB tables for latn, but not GPOS for latn]
195
- else if (count($ScriptLang)) {
196
- list($GPOSscriptTag,$dummy) = $this->_getOTLscriptTag($ScriptLang, $scripttag, $scriptblock, $this->shaper, $useOTL, 'GPOS');
197
- if ($GPOSscriptTag && $this->mpdf->fontLanguageOverride && strpos($ScriptLang[$GPOSscriptTag], $this->mpdf->fontLanguageOverride)!==false) {
198
- $GPOSlangsys = str_pad($this->mpdf->fontLanguageOverride,4);
199
- }
200
- else if ($GPOSscriptTag && isset($ScriptLang[$GPOSscriptTag]) && $ScriptLang[$GPOSscriptTag]!='') {
201
- $GPOSlangsys = $this->_getOTLLangTag($this->mpdf->currentLang, $ScriptLang[$GPOSscriptTag]);
202
- }
203
- }
204
-
205
- ////////////////////////////////////////////////////////////////
206
- // This is just for the font_dump_OTL utility to set script and langsys override
207
- if (isset($this->mpdf->overrideOTLsettings) && isset($this->mpdf->overrideOTLsettings[$this->fontkey])) {
208
- $GSUBscriptTag = $GPOSscriptTag = $this->mpdf->overrideOTLsettings[$this->fontkey]['script'];
209
- $GSUBlangsys = $GPOSlangsys = $this->mpdf->overrideOTLsettings[$this->fontkey]['lang'];
210
- }
211
- ////////////////////////////////////////////////////////////////
212
-
213
- if (!$GSUBscriptTag && !$GSUBlangsys && !$GPOSscriptTag && !$GPOSlangsys) {
214
- // Remove ZWJ and ZWNJ
215
- for ($i=0;$i<count($this->OTLdata);$i++) {
216
- if ($this->OTLdata[$i]['uni']==8204 || $this->OTLdata[$i]['uni']==8205) {
217
- array_splice($this->OTLdata, $i, 1);
218
- }
219
- }
220
- $this->schOTLdata[$sch] = $this->OTLdata;
221
- $this->OTLdata = array();
222
- continue;
223
- }
224
-
225
- // Don't use MYANMAR shaper unless using v2 scripttag
226
- if ($this->shaper == 'M' && $GSUBscriptTag != 'mym2') { $this->shaper = ''; }
227
-
228
- $GSUBFeatures = (isset($this->mpdf->CurrentFont['GSUBFeatures'][$GSUBscriptTag][$GSUBlangsys]) ? $this->mpdf->CurrentFont['GSUBFeatures'][$GSUBscriptTag][$GSUBlangsys] : false);
229
- $GPOSFeatures = (isset($this->mpdf->CurrentFont['GPOSFeatures'][$GPOSscriptTag][$GPOSlangsys]) ? $this->mpdf->CurrentFont['GPOSFeatures'][$GPOSscriptTag][$GPOSlangsys] : false);
230
-
231
- $this->assocLigs = array(); // Ligatures[$posarr lpos] => nc
232
- $this->assocMarks = array(); // assocMarks[$posarr mpos] => array(compID, ligPos)
233
-
234
- if (!isset($this->GDEFdata[$this->fontkey]['GSUBGPOStables'])) {
235
- $this->ttfOTLdata = $this->GDEFdata[$this->fontkey]['GSUBGPOStables'] = file_get_contents(_MPDF_TTFONTDATAPATH.$this->fontkey.'.GSUBGPOStables.dat','rb') or die('Can\'t open file ' . _MPDF_TTFONTDATAPATH.$this->fontkey.'.GSUBGPOStables.dat');
236
- }
237
- else {
238
- $this->ttfOTLdata = $this->GDEFdata[$this->fontkey]['GSUBGPOStables'];
239
- }
240
-
241
-
242
- if ($this->debugOTL) { $this->_dumpproc('BEGIN', '-', '-', '-', '-', -1, '-', 0); }
243
-
244
-
245
- ////////////////////////////////////////////////////////////////
246
- ////////////////////////////////////////////////////////////////
247
- ///////// LINE BREAKING FOR KHMER, THAI + LAO /////////////////
248
- ////////////////////////////////////////////////////////////////
249
- ////////////////////////////////////////////////////////////////
250
- // Insert U+200B at word boundaries using dictionaries
251
- if ($this->mpdf->useDictionaryLBR && ($this->shaper == "K" || $this->shaper == "T" || $this->shaper == "L")) {
252
- // Sets $this->OTLdata[$i]['wordend']=true at possible end of word boundaries
253
- $this->SEAlineBreaking();
254
- }
255
- // Insert U+200B at word boundaries for Tibetan
256
- else if ($this->mpdf->useTibetanLBR && $scriptblock == UCDN::SCRIPT_TIBETAN ) {
257
- // Sets $this->OTLdata[$i]['wordend']=true at possible end of word boundaries
258
- $this->TibetanlineBreaking();
259
- }
260
- ////////////////////////////////////////////////////////////////
261
- ////////////////////////////////////////////////////////////////
262
- ////////// GSUB /////////////////////////////////
263
- ////////////////////////////////////////////////////////////////
264
- ////////////////////////////////////////////////////////////////
265
- if (($useOTL & 0xFF) && $GSUBscriptTag && $GSUBlangsys && $GSUBFeatures) {
266
-
267
- // 4. Load GSUB data, Coverage & Lookups
268
- //=================================================================
269
-
270
- $this->GSUBfont = $this->fontkey.'.GSUB.'.$GSUBscriptTag.'.'.$GSUBlangsys;
271
-
272
- if (!isset($this->GSUBdata[$this->GSUBfont])) {
273
- if (file_exists(_MPDF_TTFONTDATAPATH.$this->mpdf->CurrentFont['fontkey'].'.GSUB.'.$GSUBscriptTag.'.'.$GSUBlangsys.'.php')) {
274
- include_once(_MPDF_TTFONTDATAPATH.$this->mpdf->CurrentFont['fontkey'].'.GSUB.'.$GSUBscriptTag.'.'.$GSUBlangsys.'.php');
275
- $this->GSUBdata[$this->GSUBfont]['rtlSUB'] = $rtlSUB;
276
- $this->GSUBdata[$this->GSUBfont]['finals'] = $finals;
277
- if ($this->shaper=='I') {
278
- $this->GSUBdata[$this->GSUBfont]['rphf'] = $rphf;
279
- $this->GSUBdata[$this->GSUBfont]['half'] = $half;
280
- $this->GSUBdata[$this->GSUBfont]['pref'] = $pref;
281
- $this->GSUBdata[$this->GSUBfont]['blwf'] = $blwf;
282
- $this->GSUBdata[$this->GSUBfont]['pstf'] = $pstf;
283
- }
284
- }
285
- else { $this->GSUBdata[$this->GSUBfont] = array('rtlSUB'=>array(), 'rphf'=>array(), 'rphf'=>array(),
286
- 'pref'=>array(), 'blwf'=>array(), 'pstf'=>array(), 'finals'=>''
287
- );
288
- }
289
- }
290
-
291
- if (!isset($this->GSUBdata[$this->fontkey])) {
292
- include(_MPDF_TTFONTDATAPATH.$this->fontkey.'.GSUBdata.php');
293
- $this->GSLuCoverage = $this->GSUBdata[$this->fontkey]['GSLuCoverage'] = $GSLuCoverage;
294
- }
295
- else {
296
- $this->GSLuCoverage = $this->GSUBdata[$this->fontkey]['GSLuCoverage'];
297
- }
298
-
299
- $this->GSUBLookups = $this->mpdf->CurrentFont['GSUBLookups'];
300
-
301
-
302
- // 5(A). GSUB - Shaper - ARABIC
303
- //==============================
304
- if ($this->shaper == 'A') {
305
- //-----------------------------------------------------------------------------------
306
- // a. Apply initial GSUB Lookups (in order specified in lookup list but only selecting from certain tags)
307
- //-----------------------------------------------------------------------------------
308
- $tags = 'locl ccmp';
309
- $omittags = '';
310
- $usetags = $tags;
311
- if(!empty($this->mpdf->OTLtags)) {
312
- $usetags = $this->_applyTagSettings($tags, $GSUBFeatures, $omittags, true) ;
313
- }
314
- $this->_applyGSUBrules($usetags, $GSUBscriptTag, $GSUBlangsys);
315
-
316
- //-----------------------------------------------------------------------------------
317
- // b. Apply context-specific forms GSUB Lookups (initial, isolated, medial, final)
318
- //-----------------------------------------------------------------------------------
319
- // Arab and Syriac are the only scripts requiring the special joining - which takes the place of
320
- // isol fina medi init rules in GSUB (+ fin2 fin3 med2 in Syriac syrc)
321
- $tags = 'isol fina fin2 fin3 medi med2 init';
322
- $omittags = '';
323
- $usetags = $tags;
324
- if(!empty($this->mpdf->OTLtags)) {
325
- $usetags = $this->_applyTagSettings($tags, $GSUBFeatures, $omittags, true) ;
326
- }
327
-
328
- $this->arabGlyphs = $this->GSUBdata[$this->GSUBfont]['rtlSUB'];
329
-
330
- $gcms = explode("| ",$this->GlyphClassMarks);
331
- $gcm = array();
332
- foreach($gcms AS $g) { $gcm[hexdec($g)] = 1; }
333
- $this->arabTransparentJoin = $this->arabTransparent + $gcm;
334
- $this->arabic_shaper($usetags, $GSUBscriptTag);
335
-
336
- //-----------------------------------------------------------------------------------
337
- // c. Set Kashida points (after joining occurred - medi, fina, init) but before other substitutions
338
- //-----------------------------------------------------------------------------------
339
- //if ($scriptblock == UCDN::SCRIPT_ARABIC ) {
340
- for ($i=0;$i<count($this->OTLdata);$i++) {
341
- // Put the kashida marker on the character BEFORE which is inserted the kashida
342
- // Kashida marker is inverse of priority i.e. Priority 1 => 7, Priority 7 => 1.
343
-
344
- // Priority 1 User-inserted Kashida 0640 = Tatweel
345
- // The user entered a Kashida in a position
346
- // Position: Before the user-inserted kashida
347
- if ($this->OTLdata[$i]['uni']==0x0640) {
348
- $this->OTLdata[$i]['GPOSinfo']['kashida'] = 8; // Put before the next character
349
- }
350
-
351
- // Priority 2 Seen (0633) FEB3, FEB4; Sad (0635) FEBB, FEBC
352
- // Initial or medial form
353
- // Connecting to the next character
354
- // Position: After the character
355
- else if ($this->OTLdata[$i]['uni']==0xFEB3 || $this->OTLdata[$i]['uni']==0xFEB4 || $this->OTLdata[$i]['uni']==0xFEBB || $this->OTLdata[$i]['uni']==0xFEBC) {
356
- $checkpos = $i+1;
357
- while (isset($this->OTLdata[$checkpos]) && strpos($this->GlyphClassMarks, $this->OTLdata[$checkpos]['hex'])!==false) {
358
- $checkpos++;
359
- }
360
- if (isset($this->OTLdata[$checkpos])) {
361
- $this->OTLdata[$checkpos]['GPOSinfo']['kashida'] = 7; // Put after marks on next character
362
- }
363
- }
364
-
365
- // Priority 3 Taa Marbutah (0629) FE94; Haa (062D) FEA2; Dal (062F) FEAA
366
- // Final form
367
- // Connecting to previous character
368
- // Position: Before the character
369
- else if ($this->OTLdata[$i]['uni']==0xFE94 || $this->OTLdata[$i]['uni']==0xFEA2 || $this->OTLdata[$i]['uni']==0xFEAA) {
370
- $this->OTLdata[$i]['GPOSinfo']['kashida'] = 6;
371
- }
372
-
373
- // Priority 4 Alef (0627) FE8E; Tah (0637) FEC2; Lam (0644) FEDE; Kaf (0643) FEDA; Gaf (06AF) FB93
374
- // Final form
375
- // Connecting to previous character
376
- // Position: Before the character
377
- else if ($this->OTLdata[$i]['uni']==0xFE8E || $this->OTLdata[$i]['uni']==0xFEC2 || $this->OTLdata[$i]['uni']==0xFEDE || $this->OTLdata[$i]['uni']==0xFEDA || $this->OTLdata[$i]['uni']==0xFB93) {
378
- $this->OTLdata[$i]['GPOSinfo']['kashida'] = 5;
379
- }
380
-
381
- // Priority 5 RA (0631) FEAE; Ya (064A) FEF2 FEF4; Alef Maqsurah (0649) FEF0 FBE9
382
- // Final or Medial form
383
- // Connected to preceding medial BAA (0628) = FE92
384
- // Position: Before preceding medial Baa
385
- // Although not mentioned in spec, added Farsi Yeh (06CC) FBFD FBFF; equivalent to 064A or 0649
386
- else if ($this->OTLdata[$i]['uni']==0xFEAE || $this->OTLdata[$i]['uni']==0xFEF2 || $this->OTLdata[$i]['uni']==0xFEF0
387
- || $this->OTLdata[$i]['uni']==0xFEF4 || $this->OTLdata[$i]['uni']==0xFBE9
388
- || $this->OTLdata[$i]['uni']==0xFBFD || $this->OTLdata[$i]['uni']==0xFBFF
389
- ) {
390
- $checkpos = $i-1;
391
- while (isset($this->OTLdata[$checkpos]) && strpos($this->GlyphClassMarks, $this->OTLdata[$checkpos]['hex'])!==false) {
392
- $checkpos--;
393
- }
394
- if (isset($this->OTLdata[$checkpos]) && $this->OTLdata[$checkpos]['uni']==0xFE92) {
395
- $this->OTLdata[$checkpos]['GPOSinfo']['kashida'] = 4; // ******* Before preceding BAA
396
- }
397
- }
398
-
399
- // Priority 6 WAW (0648) FEEE; Ain (0639) FECA; Qaf (0642) FED6; Fa (0641) FED2
400
- // Final form
401
- // Connecting to previous character
402
- // Position: Before the character
403
- else if ($this->OTLdata[$i]['uni']==0xFEEE || $this->OTLdata[$i]['uni']==0xFECA || $this->OTLdata[$i]['uni']==0xFED6 || $this->OTLdata[$i]['uni']==0xFED2) {
404
- $this->OTLdata[$i]['GPOSinfo']['kashida'] = 3;
405
- }
406
-
407
- // Priority 7 Other connecting characters
408
- // Final form
409
- // Connecting to previous character
410
- // Position: Before the character
411
- /* This isn't in the spec, but using MS WORD as a basis, give a lower priority to the 3 characters already checked
412
- in (5) above. Test case:
413
- &#x62e;&#x652;&#x631;&#x64e;&#x649;&#x670;
414
- &#x641;&#x64e;&#x62a;&#x64f;&#x630;&#x64e;&#x643;&#x651;&#x650;&#x631;
415
- */
416
-
417
- if (!isset($this->OTLdata[$i]['GPOSinfo']['kashida'])) {
418
- if (strpos($this->GSUBdata[$this->GSUBfont]['finals'], $this->OTLdata[$i]['hex'])!==false) { // ANY OTHER FINAL FORM
419
- $this->OTLdata[$i]['GPOSinfo']['kashida'] = 2;
420
- }
421
- else if (strpos('0FEAE 0FEF0 0FEF2',$this->OTLdata[$i]['hex'])!==false) { // not already included in 5 above
422
- $this->OTLdata[$i]['GPOSinfo']['kashida'] = 1;
423
- }
424
- }
425
- }
426
-
427
- //-----------------------------------------------------------------------------------
428
- // d. Apply Presentation Forms GSUB Lookups (+ any discretionary) - Apply one at a time in Feature order
429
- //-----------------------------------------------------------------------------------
430
- $tags = 'rlig calt liga clig mset';
431
-
432
- $omittags = 'locl ccmp nukt akhn rphf rkrf pref blwf abvf half pstf cfar vatu cjct init medi fina isol med2 fin2 fin3 ljmo vjmo tjmo';
433
- $usetags = $tags;
434
- if(!empty($this->mpdf->OTLtags)) {
435
- $usetags = $this->_applyTagSettings($tags, $GSUBFeatures, $omittags, false) ;
436
- }
437
-
438
- $ts = explode(' ',$usetags);
439
- foreach($ts AS $ut) { // - Apply one at a time in Feature order
440
- $this->_applyGSUBrules($ut, $GSUBscriptTag, $GSUBlangsys);
441
- }
442
- //-----------------------------------------------------------------------------------
443
- // e. NOT IN SPEC
444
- // If space precedes a mark -> substitute a &nbsp; before the Mark, to prevent line breaking Test:
445
- //-----------------------------------------------------------------------------------
446
- for($ptr=1; $ptr<count($this->OTLdata); $ptr++) {
447
- if ($this->OTLdata[$ptr]['general_category'] == UCDN::UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK && $this->OTLdata[$ptr-1]['uni'] == 32) {
448
- $this->OTLdata[$ptr-1]['uni'] = 0xa0;
449
- $this->OTLdata[$ptr-1]['hex'] = '000A0';
450
- }
451
- }
452
- }
453
-
454
- // 5(I). GSUB - Shaper - INDIC and SINHALA and KHMER
455
- //===================================
456
- else if ($this->shaper == 'I' || $this->shaper == 'K' || $this->shaper == 'S') {
457
- $this->restrictToSyllable = true;
458
- //-----------------------------------------------------------------------------------
459
- // a. First decompose/compose split mattras
460
- // (normalize) ??????? Nukta/Halant order etc ??????????????????????????????????????????????????????????????????????????
461
- //-----------------------------------------------------------------------------------
462
- for($ptr=0; $ptr<count($this->OTLdata); $ptr++) {
463
- $char = $this->OTLdata[$ptr]['uni'];
464
- $sub = INDIC::decompose_indic($char);
465
- if ($sub) {
466
- $newinfo = array();
467
- for($i=0;$i<count($sub);$i++) {
468
- $newinfo[$i] = array();
469
- $ucd_record = UCDN::get_ucd_record($sub[$i]);
470
- $newinfo[$i]['general_category'] = $ucd_record[0];
471
- $newinfo[$i]['bidi_type'] = $ucd_record[2];
472
- $charasstr = $this->unicode_hex($sub[$i]);
473
- if (strpos($this->GlyphClassMarks, $charasstr)!==false) { $newinfo[$i]['group'] = 'M'; }
474
- else { $newinfo[$i]['group'] = 'C'; }
475
- $newinfo[$i]['uni'] = $sub[$i];
476
- $newinfo[$i]['hex'] = $charasstr;
477
- }
478
- array_splice($this->OTLdata, $ptr, 1, $newinfo);
479
- $ptr += count($sub)-1;
480
- }
481
- /* Only Composition-exclusion exceptions that we want to recompose. */
482
- if ($this->shaper == 'I') {
483
- if ($char == 0x09AF && isset($this->OTLdata[$ptr + 1]) && $this->OTLdata[$ptr + 1]['uni'] == 0x09BC) {
484
- $sub = 0x09DF;
485
- $newinfo = array();
486
- $newinfo[0] = array();
487
- $ucd_record = UCDN::get_ucd_record($sub);
488
- $newinfo[0]['general_category'] = $ucd_record[0];
489
- $newinfo[0]['bidi_type'] = $ucd_record[2];
490
- $newinfo[0]['group'] = 'C';
491
- $newinfo[0]['uni'] = $sub;
492
- $newinfo[0]['hex'] = $this->unicode_hex($sub);
493
- array_splice($this->OTLdata, $ptr, 2, $newinfo);
494
- }
495
- }
496
- }
497
- //-----------------------------------------------------------------------------------
498
- // b. Analyse characters - group as syllables/clusters (Indic); invalid diacritics; add dotted circle
499
- //-----------------------------------------------------------------------------------
500
- $indic_category_string = '';
501
- foreach($this->OTLdata AS $eid=>$c) {
502
- INDIC::set_indic_properties($this->OTLdata[$eid], $scriptblock ); // sets ['indic_category'] and ['indic_position']
503
- //$c['general_category']
504
- //$c['combining_class']
505
- //$c['uni'] = $char;
506
-
507
- $indic_category_string .= INDIC::$indic_category_char[$this->OTLdata[$eid]['indic_category']];
508
- }
509
-
510
- $broken_syllables = false;
511
- if ($this->shaper == 'I') {
512
- INDIC::set_syllables($this->OTLdata, $indic_category_string, $broken_syllables);
513
- }
514
- else if ($this->shaper == 'S') {
515
- INDIC::set_syllables_sinhala($this->OTLdata, $indic_category_string, $broken_syllables);
516
- }
517
- else if ($this->shaper == 'K') {
518
- INDIC::set_syllables_khmer($this->OTLdata, $indic_category_string, $broken_syllables);
519
- }
520
- $indic_category_string = '';
521
-
522
- //-----------------------------------------------------------------------------------
523
- // c. Initial Re-ordering (Indic / Khmer / Sinhala)
524
- //-----------------------------------------------------------------------------------
525
- // Find base consonant
526
- // Decompose/compose and reorder Matras
527
- // Reorder marks to canonical order
528
-
529
- $indic_config = INDIC::$indic_configs[$scriptblock];
530
- $dottedcircle = false;
531
- if ($broken_syllables) {
532
- if ($this->mpdf->_charDefined($this->mpdf->fonts[$this->fontkey]['cw'],0x25CC) ) {
533
- $dottedcircle = array();
534
- $ucd_record = UCDN::get_ucd_record(0x25CC);
535
- $dottedcircle[0]['general_category'] = $ucd_record[0];
536
- $dottedcircle[0]['bidi_type'] = $ucd_record[2];
537
- $dottedcircle[0]['group'] = 'C';
538
- $dottedcircle[0]['uni'] = 0x25CC;
539
- $dottedcircle[0]['indic_category'] = INDIC::OT_DOTTEDCIRCLE;
540
- $dottedcircle[0]['indic_position'] = INDIC::POS_BASE_C;
541
-
542
- $dottedcircle[0]['hex'] = '025CC'; // TEMPORARY *****
543
- }
544
- }
545
- INDIC::initial_reordering($this->OTLdata, $this->GSUBdata[$this->GSUBfont], $broken_syllables, $indic_config, $scriptblock, $is_old_spec, $dottedcircle);
546
-
547
- //-----------------------------------------------------------------------------------
548
- // d. Apply initial and basic shaping forms GSUB Lookups (one at a time)
549
- //-----------------------------------------------------------------------------------
550
- if ($this->shaper == 'I' || $this->shaper == 'S') {
551
- $tags = 'locl ccmp nukt akhn rphf rkrf pref blwf half pstf vatu cjct';
552
- }
553
- else if ($this->shaper == 'K') {
554
- $tags = 'locl ccmp pref blwf abvf pstf cfar';
555
- }
556
- $this->_applyGSUBrulesIndic($tags, $GSUBscriptTag, $GSUBlangsys, $is_old_spec);
557
-
558
- //-----------------------------------------------------------------------------------
559
- // e. Final Re-ordering (Indic / Khmer / Sinhala)
560
- //-----------------------------------------------------------------------------------
561
- // Reorder matras
562
- // Reorder reph
563
- // Reorder pre-base reordering consonants:
564
-
565
- INDIC::final_reordering($this->OTLdata, $this->GSUBdata[$this->GSUBfont], $indic_config, $scriptblock, $is_old_spec);
566
-
567
- //-----------------------------------------------------------------------------------
568
- // f. Apply 'init' feature to first syllable in word (indicated by ['mask']) INDIC::FLAG(INDIC::INIT);
569
- //-----------------------------------------------------------------------------------
570
- if ($this->shaper == 'I' || $this->shaper == 'S') {
571
- $tags = 'init';
572
- $this->_applyGSUBrulesIndic($tags, $GSUBscriptTag, $GSUBlangsys, $is_old_spec);
573
- }
574
-
575
- //-----------------------------------------------------------------------------------
576
- // g. Apply Presentation Forms GSUB Lookups (+ any discretionary)
577
- //-----------------------------------------------------------------------------------
578
- $tags = 'pres abvs blws psts haln rlig calt liga clig mset';
579
-
580
- $omittags = 'locl ccmp nukt akhn rphf rkrf pref blwf abvf half pstf cfar vatu cjct init medi fina isol med2 fin2 fin3 ljmo vjmo tjmo';
581
- $usetags = $tags;
582
- if(!empty($this->mpdf->OTLtags)) {
583
- $usetags = $this->_applyTagSettings($tags, $GSUBFeatures, $omittags, false) ;
584
- }
585
- if ($this->shaper == 'K') { // Features are applied one at a time, working through each codepoint
586
- $this->_applyGSUBrulesSingly($usetags, $GSUBscriptTag, $GSUBlangsys);
587
- }
588
- else {
589
- $this->_applyGSUBrules($usetags, $GSUBscriptTag, $GSUBlangsys);
590
- }
591
- $this->restrictToSyllable = false;
592
- }
593
-
594
-
595
- // 5(M). GSUB - Shaper - MYANMAR (ONLY mym2)
596
- //==============================
597
- // NB Old style 'mymr' is left to go through the default shaper
598
- else if ($this->shaper == 'M') {
599
- $this->restrictToSyllable = true;
600
- //-----------------------------------------------------------------------------------
601
- // a. Analyse characters - group as syllables/clusters (Myanmar); invalid diacritics; add dotted circle
602
- //-----------------------------------------------------------------------------------
603
- $myanmar_category_string = '';
604
- foreach($this->OTLdata AS $eid=>$c) {
605
- MYANMAR::set_myanmar_properties($this->OTLdata[$eid]); // sets ['myanmar_category'] and ['myanmar_position']
606
- $myanmar_category_string .= MYANMAR::$myanmar_category_char[$this->OTLdata[$eid]['myanmar_category']];
607
- }
608
- $broken_syllables = false;
609
- MYANMAR::set_syllables($this->OTLdata, $myanmar_category_string, $broken_syllables);
610
- $myanmar_category_string = '';
611
-
612
- //-----------------------------------------------------------------------------------
613
- // b. Re-ordering (Myanmar mym2)
614
- //-----------------------------------------------------------------------------------
615
- $dottedcircle = false;
616
- if ($broken_syllables) {
617
- if ($this->mpdf->_charDefined($this->mpdf->fonts[$this->fontkey]['cw'],0x25CC) ) {
618
- $dottedcircle = array();
619
- $ucd_record = UCDN::get_ucd_record(0x25CC);
620
- $dottedcircle[0]['general_category'] = $ucd_record[0];
621
- $dottedcircle[0]['bidi_type'] = $ucd_record[2];
622
- $dottedcircle[0]['group'] = 'C';
623
- $dottedcircle[0]['uni'] = 0x25CC;
624
- $dottedcircle[0]['myanmar_category'] = MYANMAR::OT_DOTTEDCIRCLE;
625
- $dottedcircle[0]['myanmar_position'] = MYANMAR::POS_BASE_C;
626
- $dottedcircle[0]['hex'] = '025CC';
627
- }
628
- }
629
- MYANMAR::reordering($this->OTLdata, $this->GSUBdata[$this->GSUBfont], $broken_syllables, $dottedcircle);
630
-
631
- //-----------------------------------------------------------------------------------
632
- // c. Apply initial and basic shaping forms GSUB Lookups (one at a time)
633
- //-----------------------------------------------------------------------------------
634
-
635
- $tags = 'locl ccmp rphf pref blwf pstf';
636
- $this->_applyGSUBrulesMyanmar($tags, $GSUBscriptTag, $GSUBlangsys);
637
-
638
- //-----------------------------------------------------------------------------------
639
- // d. Apply Presentation Forms GSUB Lookups (+ any discretionary)
640
- //-----------------------------------------------------------------------------------
641
- $tags = 'pres abvs blws psts haln rlig calt liga clig mset';
642
- $omittags = 'locl ccmp nukt akhn rphf rkrf pref blwf abvf half pstf cfar vatu cjct init medi fina isol med2 fin2 fin3 ljmo vjmo tjmo';
643
- $usetags = $tags;
644
- if(!empty($this->mpdf->OTLtags)) {
645
- $usetags = $this->_applyTagSettings($tags, $GSUBFeatures, $omittags, false) ;
646
- }
647
- $this->_applyGSUBrules($usetags, $GSUBscriptTag, $GSUBlangsys);
648
- $this->restrictToSyllable = false;
649
- }
650
-
651
-
652
- // 5(E). GSUB - Shaper - SEA South East Asian (New Tai Lue, Cham, Tai Tam)
653
- //==============================
654
- else if ($this->shaper == 'E') {
655
- /* HarfBuzz says: If the designer designed the font for the 'DFLT' script,
656
- * use the default shaper. Otherwise, use the SEA shaper.
657
- * Note that for some simple scripts, there may not be *any*
658
- * GSUB/GPOS needed, so there may be no scripts found! */
659
-
660
- $this->restrictToSyllable = true;
661
- //-----------------------------------------------------------------------------------
662
- // a. Analyse characters - group as syllables/clusters (Indic); invalid diacritics; add dotted circle
663
- //-----------------------------------------------------------------------------------
664
- $sea_category_string = '';
665
- foreach($this->OTLdata AS $eid=>$c) {
666
- SEA::set_sea_properties($this->OTLdata[$eid], $scriptblock ); // sets ['sea_category'] and ['sea_position']
667
- //$c['general_category']
668
- //$c['combining_class']
669
- //$c['uni'] = $char;
670
-
671
- $sea_category_string .= SEA::$sea_category_char[$this->OTLdata[$eid]['sea_category']];
672
- }
673
-
674
- $broken_syllables = false;
675
- SEA::set_syllables($this->OTLdata, $sea_category_string, $broken_syllables);
676
- $sea_category_string = '';
677
-
678
- //-----------------------------------------------------------------------------------
679
- // b. Apply locl and ccmp shaping forms - before initial re-ordering; GSUB Lookups (one at a time)
680
- //-----------------------------------------------------------------------------------
681
- $tags = 'locl ccmp';
682
- $this->_applyGSUBrulesSingly($tags, $GSUBscriptTag, $GSUBlangsys);
683
-
684
- //-----------------------------------------------------------------------------------
685
- // c. Initial Re-ordering
686
- //-----------------------------------------------------------------------------------
687
- // Find base consonant
688
- // Decompose/compose and reorder Matras
689
- // Reorder marks to canonical order
690
-
691
- $dottedcircle = false;
692
- if ($broken_syllables) {
693
- if ($this->mpdf->_charDefined($this->mpdf->fonts[$this->fontkey]['cw'],0x25CC) ) {
694
- $dottedcircle = array();
695
- $ucd_record = UCDN::get_ucd_record(0x25CC);
696
- $dottedcircle[0]['general_category'] = $ucd_record[0];
697
- $dottedcircle[0]['bidi_type'] = $ucd_record[2];
698
- $dottedcircle[0]['group'] = 'C';
699
- $dottedcircle[0]['uni'] = 0x25CC;
700
- $dottedcircle[0]['sea_category'] = SEA::OT_GB;
701
- $dottedcircle[0]['sea_position'] = SEA::POS_BASE_C;
702
-
703
- $dottedcircle[0]['hex'] = '025CC'; // TEMPORARY *****
704
- }
705
- }
706
- SEA::initial_reordering($this->OTLdata, $this->GSUBdata[$this->GSUBfont], $broken_syllables, $scriptblock, $dottedcircle);
707
-
708
- //-----------------------------------------------------------------------------------
709
- // d. Apply basic shaping forms GSUB Lookups (one at a time)
710
- //-----------------------------------------------------------------------------------
711
- $tags = 'pref abvf blwf pstf';
712
- $this->_applyGSUBrulesSingly($tags, $GSUBscriptTag, $GSUBlangsys);
713
-
714
- //-----------------------------------------------------------------------------------
715
- // e. Final Re-ordering
716
- //-----------------------------------------------------------------------------------
717
-
718
- SEA::final_reordering($this->OTLdata, $this->GSUBdata[$this->GSUBfont], $scriptblock);
719
-
720
- //-----------------------------------------------------------------------------------
721
- // f. Apply Presentation Forms GSUB Lookups (+ any discretionary)
722
- //-----------------------------------------------------------------------------------
723
- $tags = 'pres abvs blws psts';
724
-
725
- $omittags = 'locl ccmp nukt akhn rphf rkrf pref blwf abvf half pstf cfar vatu cjct init medi fina isol med2 fin2 fin3 ljmo vjmo tjmo';
726
- $usetags = $tags;
727
- if(!empty($this->mpdf->OTLtags)) {
728
- $usetags = $this->_applyTagSettings($tags, $GSUBFeatures, $omittags, false) ;
729
- }
730
- $this->_applyGSUBrules($usetags, $GSUBscriptTag, $GSUBlangsys);
731
- $this->restrictToSyllable = false;
732
- }
733
-
734
-
735
- // 5(D). GSUB - Shaper - DEFAULT (including THAI and LAO and MYANMAR v1 [mymr] and TIBETAN)
736
- //==============================
737
- else { // DEFAULT
738
- //-----------------------------------------------------------------------------------
739
- // a. First decompose/compose in Thai / Lao - Tibetan
740
- //-----------------------------------------------------------------------------------
741
- // Decomposition for THAI or LAO
742
- /* This function implements the shaping logic documented here:
743
- *
744
- * http://linux.thai.net/~thep/th-otf/shaping.html
745
- *
746
- * The first shaping rule listed there is needed even if the font has Thai
747
- * OpenType tables.
748
- *
749
- *
750
- * The following is NOT specified in the MS OT Thai spec, however, it seems
751
- * to be what Uniscribe and other engines implement. According to Eric Muller:
752
- *
753
- * When you have a SARA AM, decompose it in NIKHAHIT + SARA AA, *and* move the
754
- * NIKHAHIT backwards over any tone mark (0E48-0E4B).
755
- *
756
- * <0E14, 0E4B, 0E33> -> <0E14, 0E4D, 0E4B, 0E32>
757
- *
758
- * This reordering is legit only when the NIKHAHIT comes from a SARA AM, not
759
- * when it's there to start with. The string <0E14, 0E4B, 0E4D> is probably
760
- * not what a user wanted, but the rendering is nevertheless nikhahit above
761
- * chattawa.
762
- *
763
- * Same for Lao.
764
- *
765
- * Thai Lao
766
- * SARA AM: U+0E33 U+0EB3
767
- * SARA AA: U+0E32 U+0EB2
768
- * Nikhahit: U+0E4D U+0ECD
769
- *
770
- * Testing shows that Uniscribe reorder the following marks:
771
- * Thai: <0E31,0E34..0E37,0E47..0E4E>
772
- * Lao: <0EB1,0EB4..0EB7,0EC7..0ECE>
773
- *
774
- * Lao versions are the same as Thai + 0x80.
775
- */
776
- if ($this->shaper == 'T' || $this->shaper == 'L') {
777
- for($ptr=0; $ptr<count($this->OTLdata); $ptr++) {
778
- $char = $this->OTLdata[$ptr]['uni'];
779
- if (($char & ~0x0080) == 0x0E33) { // if SARA_AM (U+0E33 or U+0EB3)
780
-
781
- $NIKHAHIT = $char + 0x1A;
782
- $SARA_AA = $char - 1;
783
- $sub = array($SARA_AA, $NIKHAHIT);
784
-
785
- $newinfo = array();
786
- $ucd_record = UCDN::get_ucd_record($sub[0]);
787
- $newinfo[0]['general_category'] = $ucd_record[0];
788
- $newinfo[0]['bidi_type'] = $ucd_record[2];
789
- $charasstr = $this->unicode_hex($sub[0]);
790
- if (strpos($this->GlyphClassMarks, $charasstr)!==false) { $newinfo[0]['group'] = 'M'; }
791
- else { $newinfo[0]['group'] = 'C'; }
792
- $newinfo[0]['uni'] = $sub[0];
793
- $newinfo[0]['hex'] = $charasstr;
794
- $this->OTLdata[$ptr] = $newinfo[0]; // Substitute SARA_AM => SARA_AA
795
-
796
- $ntones = 0; // number of (preceding) tone marks
797
- // IS_TONE_MARK ((x) & ~0x0080, 0x0E34 - 0x0E37, 0x0E47 - 0x0E4E, 0x0E31)
798
- while (isset($this->OTLdata[$ptr - 1 - $ntones])
799
- && (
800
- ($this->OTLdata[$ptr - 1 - $ntones]['uni'] & ~0x0080) == 0x0E31 ||
801
-
802
- (($this->OTLdata[$ptr - 1 - $ntones]['uni'] & ~0x0080) >= 0x0E34 &&
803
- ($this->OTLdata[$ptr - 1 - $ntones]['uni'] & ~0x0080) <= 0x0E37) ||
804
-
805
- (($this->OTLdata[$ptr - 1 - $ntones]['uni'] & ~0x0080) >= 0x0E47 &&
806
- ($this->OTLdata[$ptr - 1 - $ntones]['uni'] & ~0x0080) <= 0x0E4E)
807
- )
808
- ) { $ntones++; }
809
-
810
- $newinfo = array();
811
- $ucd_record = UCDN::get_ucd_record($sub[1]);
812
- $newinfo[0]['general_category'] = $ucd_record[0];
813
- $newinfo[0]['bidi_type'] = $ucd_record[2];
814
- $charasstr = $this->unicode_hex($sub[1]);
815
- if (strpos($this->GlyphClassMarks, $charasstr)!==false) { $newinfo[0]['group'] = 'M'; }
816
- else { $newinfo[0]['group'] = 'C'; }
817
- $newinfo[0]['uni'] = $sub[1];
818
- $newinfo[0]['hex'] = $charasstr;
819
- // Insert NIKAHIT
820
- array_splice($this->OTLdata, $ptr - $ntones, 0, $newinfo);
821
-
822
- $ptr++;
823
- }
824
- }
825
- }
826
-
827
- if ($scriptblock == UCDN::SCRIPT_TIBETAN) {
828
- // =========================
829
- // Reordering TIBETAN
830
- // =========================
831
- // Tibetan does not need to need a shaper generally, as long as characters are presented in the correct order
832
- // so we will do one minor change here:
833
- // From ICU: If the present character is a number, and the next character is a pre-number combining mark
834
- // then the two characters are reordered
835
- // From MS OTL spec the following are Digit modifiers (Md): 0F18�0F19, 0F3E�0F3F
836
- // Digits: 0F20�0F33
837
- // On testing only 0x0F3F (pre-based mark) seems to need re-ordering
838
- for($ptr=0; $ptr<count($this->OTLdata)-1; $ptr++) {
839
- if (INDIC::in_range($this->OTLdata[$ptr]['uni'], 0x0F20, 0x0F33) && $this->OTLdata[$ptr+1]['uni'] == 0x0F3F ) {
840
- $tmp = $this->OTLdata[$ptr+1];
841
- $this->OTLdata[$ptr+1] = $this->OTLdata[$ptr];
842
- $this->OTLdata[$ptr] = $tmp;
843
- }
844
- }
845
-
846
-
847
- // =========================
848
- // Decomposition for TIBETAN
849
- // =========================
850
- /* Recommended, but does not seem to change anything...
851
- for($ptr=0; $ptr<count($this->OTLdata); $ptr++) {
852
- $char = $this->OTLdata[$ptr]['uni'];
853
- $sub = INDIC::decompose_indic($char);
854
- if ($sub) {
855
- $newinfo = array();
856
- for($i=0;$i<count($sub);$i++) {
857
- $newinfo[$i] = array();
858
- $ucd_record = UCDN::get_ucd_record($sub[$i]);
859
- $newinfo[$i]['general_category'] = $ucd_record[0];
860
- $newinfo[$i]['bidi_type'] = $ucd_record[2];
861
- $charasstr = $this->unicode_hex($sub[$i]);
862
- if (strpos($this->GlyphClassMarks, $charasstr)!==false) { $newinfo[$i]['group'] = 'M'; }
863
- else { $newinfo[$i]['group'] = 'C'; }
864
- $newinfo[$i]['uni'] = $sub[$i];
865
- $newinfo[$i]['hex'] = $charasstr;
866
- }
867
- array_splice($this->OTLdata, $ptr, 1, $newinfo);
868
- $ptr += count($sub)-1;
869
- }
870
- }
871
- */
872
-
873
- }
874
-
875
-
876
- //-----------------------------------------------------------------------------------
877
- // b. Apply all GSUB Lookups (in order specified in lookup list)
878
- //-----------------------------------------------------------------------------------
879
- $tags = 'locl ccmp pref blwf abvf pstf pres abvs blws psts haln rlig calt liga clig mset RQD';
880
- // pref blwf abvf pstf required for Tibetan
881
- // " RQD" is a non-standard tag in Garuda font - presumably intended to be used by default ? "ReQuireD"
882
- // Being a 3 letter tag is non-standard, and does not allow it to be set by font-feature-settings
883
-
884
-
885
- /* ?Add these until shapers witten?
886
- Hangul: ljmo vjmo tjmo
887
- */
888
-
889
- $omittags = '';
890
- $useGSUBtags = $tags;
891
- if(!empty($this->mpdf->OTLtags)) {
892
- $useGSUBtags = $this->_applyTagSettings($tags, $GSUBFeatures, $omittags, false) ;
893
- }
894
- // APPLY GSUB rules (as long as not Latin + SmallCaps - but not OTL smcp)
895
- if (!(($this->mpdf->textvar & FC_SMALLCAPS) && $scriptblock == UCDN::SCRIPT_LATIN && strpos($useGSUBtags, 'smcp')===false)) {
896
- $this->_applyGSUBrules($useGSUBtags, $GSUBscriptTag, $GSUBlangsys);
897
- }
898
- }
899
-
900
-
901
- }
902
-
903
- // Shapers - KHMER & THAI & LAO - Replace Word boundary marker with U+200B
904
- // Also TIBETAN (no shaper)
905
- //=======================================================
906
- if (($this->shaper == "K" || $this->shaper == "T" || $this->shaper == "L") || $scriptblock == UCDN::SCRIPT_TIBETAN ) {
907
- // Set up properties to insert a U+200B character
908
- $newinfo = array();
909
- //$newinfo[0] = array('general_category' => 1, 'bidi_type' => 14, 'group' => 'S', 'uni' => 0x200B, 'hex' => '0200B');
910
- $newinfo[0] = array(
911
- 'general_category' => UCDN::UNICODE_GENERAL_CATEGORY_FORMAT,
912
- 'bidi_type' => UCDN::BIDI_CLASS_BN,
913
- 'group' => 'S', 'uni' => 0x200B, 'hex' => '0200B');
914
- // Then insert U+200B at (after) all word end boundaries
915
- for ($i=count($this->OTLdata)-1;$i>0;$i--) {
916
- // Make sure after GSUB that wordend has not been moved - check next char is not in the same syllable
917
- if (isset($this->OTLdata[$i]['wordend']) && $this->OTLdata[$i]['wordend'] &&
918
- isset($this->OTLdata[$i+1]['uni']) && (!isset($this->OTLdata[$i+1]['syllable']) || !isset($this->OTLdata[$i+1]['syllable']) || $this->OTLdata[$i+1]['syllable']!=$this->OTLdata[$i]['syllable'])) {
919
- array_splice($this->OTLdata, $i+1, 0, $newinfo);
920
- $this->_updateLigatureMarks($i, 1);
921
- }
922
- else if ($this->OTLdata[$i]['uni']==0x2e) { // Word end if Full-stop.
923
- array_splice($this->OTLdata, $i+1, 0, $newinfo);
924
- $this->_updateLigatureMarks($i, 1);
925
- }
926
- }
927
- }
928
-
929
-
930
- // Shapers - INDIC & ARABIC & KHMER & SINHALA & MYANMAR - Remove ZWJ and ZWNJ
931
- //=======================================================
932
- if ($this->shaper == 'I' || $this->shaper == 'S' || $this->shaper == 'A' || $this->shaper == 'K' || $this->shaper == 'M') {
933
- // Remove ZWJ and ZWNJ
934
- for ($i=0;$i<count($this->OTLdata);$i++) {
935
- if ($this->OTLdata[$i]['uni']==8204 || $this->OTLdata[$i]['uni']==8205) {
936
- array_splice($this->OTLdata, $i, 1);
937
- $this->_updateLigatureMarks($i, -1);
938
- }
939
- }
940
- }
941
-
942
- //print_r($this->OTLdata); echo '<br />';
943
- //print_r($this->assocMarks); echo '<br />';
944
- //print_r($this->assocLigs); exit;
945
-
946
- ////////////////////////////////////////////////////////////////
947
- ////////////////////////////////////////////////////////////////
948
- ////////// GPOS /////////////////////////////////
949
- ////////////////////////////////////////////////////////////////
950
- ////////////////////////////////////////////////////////////////
951
-
952
- if (($useOTL & 0xFF) && $GPOSscriptTag && $GPOSlangsys && $GPOSFeatures) {
953
- $this->Entry = array();
954
- $this->Exit = array();
955
-
956
- // 6. Load GPOS data, Coverage & Lookups
957
- //=================================================================
958
- if (!isset($this->GPOSdata[$this->fontkey])) {
959
- include(_MPDF_TTFONTDATAPATH.$this->mpdf->CurrentFont['fontkey'].'.GPOSdata.php');
960
- $this->LuCoverage = $this->GPOSdata[$this->fontkey]['LuCoverage'] = $LuCoverage;
961
- }
962
- else {
963
- $this->LuCoverage = $this->GPOSdata[$this->fontkey]['LuCoverage'];
964
- }
965
-
966
- $this->GPOSLookups = $this->mpdf->CurrentFont['GPOSLookups'];
967
-
968
-
969
- // 7. Select Feature tags to use (incl optional)
970
- //==============================
971
- $tags = 'abvm blwm mark mkmk curs cpsp dist requ'; // Default set
972
- /* 'requ' is not listed in the Microsoft registry of Feature tags
973
- Found in Arial Unicode MS, it repositions the baseline for punctuation in Kannada script */
974
-
975
- // ZZZ96
976
- // Set kern to be included by default in non-Latin script (? just when shapers used)
977
- // Kern is used in some fonts to reposition marks etc. and is essential for correct display
978
- //if ($this->shaper) {$tags .= ' kern'; }
979
- if ($scriptblock != UCDN::SCRIPT_LATIN) { $tags .= ' kern'; }
980
-
981
- $omittags = '';
982
- $usetags = $tags;
983
- if(!empty($this->mpdf->OTLtags)) {
984
- $usetags = $this->_applyTagSettings($tags, $GPOSFeatures, $omittags, false) ;
985
- }
986
-
987
-
988
-
989
- // 8. Get GPOS LookupList from Feature tags
990
- //==============================
991
- $LookupList = array();
992
- foreach($GPOSFeatures AS $tag=>$arr) {
993
- if (strpos($usetags, $tag)!==false) {
994
- foreach($arr AS $lu) { $LookupList[$lu] = $tag; }
995
- }
996
- }
997
- ksort($LookupList);
998
-
999
-
1000
- // 9. Apply GPOS Lookups (in order specified in lookup list but selecting from specified tags)
1001
- //==============================
1002
-
1003
- // APPLY THE GPOS RULES (as long as not Latin + SmallCaps - but not OTL smcp)
1004
- if (!(($this->mpdf->textvar & FC_SMALLCAPS) && $scriptblock == UCDN::SCRIPT_LATIN && strpos($useGSUBtags, 'smcp')===false)) {
1005
- $this->_applyGPOSrules($LookupList, $is_old_spec);
1006
- // (sets: $this->OTLdata[n]['GPOSinfo'] XPlacement YPlacement XAdvance Entry Exit )
1007
- }
1008
-
1009
- // 10. Process cursive text
1010
- //==============================
1011
- if (count($this->Entry) || count($this->Exit)) {
1012
- // RTL
1013
- $incurs = false;
1014
- for ($i=(count($this->OTLdata)-1);$i>=0;$i--) {
1015
- if (isset($this->Entry[$i]) && isset($this->Entry[$i]['Y']) && $this->Entry[$i]['dir']=='RTL') {
1016
- $nextbase = $i-1; // Set as next base ignoring marks (next base reading RTL in logical oder
1017
- while(isset($this->OTLdata[$nextbase]['hex']) && strpos($this->GlyphClassMarks, $this->OTLdata[$nextbase]['hex'])!==false) { $nextbase--; }
1018
- if (isset($this->Exit[$nextbase]) && isset($this->Exit[$nextbase]['Y']) ) {
1019
- $diff = $this->Entry[$i]['Y'] - $this->Exit[$nextbase]['Y'];
1020
- if ($incurs===false) { $incurs = $diff; }
1021
- else { $incurs += $diff; }
1022
- for ($j=($i-1);$j>=$nextbase;$j--) {
1023
- if (isset($this->OTLdata[$j]['GPOSinfo']['YPlacement'])) { $this->OTLdata[$j]['GPOSinfo']['YPlacement'] += $incurs; }
1024
- else { $this->OTLdata[$j]['GPOSinfo']['YPlacement'] = $incurs; }
1025
- }
1026
- if (isset($this->Exit[$i]['X']) && isset($this->Entry[$nextbase]['X']) ) {
1027
- $adj = -($this->Entry[$i]['X'] - $this->Exit[$nextbase]['X']);
1028
- // If XAdvance is aplied - in order for PDF to position the Advance correctly need to place it on:
1029
- // in RTL - the current glyph or the last of any associated marks
1030
- if (isset($this->OTLdata[$nextbase+1]['GPOSinfo']['XAdvance'])) { $this->OTLdata[$nextbase+1]['GPOSinfo']['XAdvance'] += $adj; }
1031
- else { $this->OTLdata[$nextbase+1]['GPOSinfo']['XAdvance'] = $adj; }
1032
- }
1033
- }
1034
- else { $incurs = false; }
1035
- }
1036
- else if (strpos($this->GlyphClassMarks, $this->OTLdata[$i]['hex'])!==false) { continue; } // ignore Marks
1037
- else { $incurs = false; }
1038
- }
1039
- // LTR
1040
- $incurs = false;
1041
- for ($i=0;$i<count($this->OTLdata);$i++) {
1042
- if (isset($this->Exit[$i]) && isset($this->Exit[$i]['Y']) && $this->Exit[$i]['dir']=='LTR') {
1043
- $nextbase = $i+1; // Set as next base ignoring marks
1044
- while(strpos($this->GlyphClassMarks, $this->OTLdata[$nextbase]['hex'])!==false) { $nextbase++; }
1045
- if (isset($this->Entry[$nextbase]) && isset($this->Entry[$nextbase]['Y']) ) {
1046
-
1047
- $diff = $this->Exit[$i]['Y'] - $this->Entry[$nextbase]['Y'];
1048
- if ($incurs===false) { $incurs = $diff; }
1049
- else { $incurs += $diff; }
1050
- for ($j=($i+1);$j<=$nextbase;$j++) {
1051
- if (isset($this->OTLdata[$j]['GPOSinfo']['YPlacement'])) { $this->OTLdata[$j]['GPOSinfo']['YPlacement'] += $incurs; }
1052
- else { $this->OTLdata[$j]['GPOSinfo']['YPlacement'] = $incurs; }
1053
- }
1054
- if (isset($this->Exit[$i]['X']) && isset($this->Entry[$nextbase]['X']) ) {
1055
- $adj = -($this->Exit[$i]['X'] - $this->Entry[$nextbase]['X']);
1056
- // If XAdvance is aplied - in order for PDF to position the Advance correctly need to place it on:
1057
- // in LTR - the next glyph, ignoring marks
1058
- if (isset($this->OTLdata[$nextbase]['GPOSinfo']['XAdvance'])) { $this->OTLdata[$nextbase]['GPOSinfo']['XAdvance'] += $adj; }
1059
- else { $this->OTLdata[$nextbase]['GPOSinfo']['XAdvance'] = $adj; }
1060
- }
1061
- }
1062
- else { $incurs = false; }
1063
- }
1064
- else if (strpos($this->GlyphClassMarks, $this->OTLdata[$i]['hex'])!==false) { continue; } // ignore Marks
1065
- else { $incurs = false; }
1066
- }
1067
- }
1068
-
1069
-
1070
-
1071
-
1072
- } // end GPOS
1073
-
1074
- if ($this->debugOTL) { $this->_dumpproc('END', '-', '-', '-', '-', 0, '-', 0); exit; }
1075
-
1076
- $this->schOTLdata[$sch] = $this->OTLdata;
1077
- $this->OTLdata = array();
1078
- } // END foreach subchunk
1079
-
1080
-
1081
- // 11. Re-assemble and return text string
1082
- //==============================
1083
- $newGPOSinfo = array();
1084
- $newOTLdata = array();
1085
- $newchar_data = array();
1086
- $newgroup = '';
1087
- $e = '';
1088
- $ectr = 0;
1089
-
1090
- for($sch=0;$sch<=$subchunk;$sch++) {
1091
- for ($i=0;$i<count($this->schOTLdata[$sch]);$i++) {
1092
- if (isset($this->schOTLdata[$sch][$i]['GPOSinfo'])) {
1093
- $newGPOSinfo[$ectr] = $this->schOTLdata[$sch][$i]['GPOSinfo'];
1094
- }
1095
- $newchar_data[$ectr] = array('bidi_class' => $this->schOTLdata[$sch][$i]['bidi_type'], 'uni' => $this->schOTLdata[$sch][$i]['uni']);
1096
- $newgroup .= $this->schOTLdata[$sch][$i]['group'];
1097
- $e.=code2utf($this->schOTLdata[$sch][$i]['uni']);
1098
- if (isset($this->mpdf->CurrentFont['subset'])) {
1099
- $this->mpdf->CurrentFont['subset'][$this->schOTLdata[$sch][$i]['uni']] = $this->schOTLdata[$sch][$i]['uni'];
1100
- }
1101
- $ectr++;
1102
- }
1103
-
1104
- }
1105
- $this->OTLdata['GPOSinfo'] = $newGPOSinfo;
1106
- $this->OTLdata['char_data'] = $newchar_data ;
1107
- $this->OTLdata['group'] = $newgroup ;
1108
-
1109
-
1110
- // This leaves OTLdata::GPOSinfo, ::bidi_type, & ::group
1111
-
1112
- return $e;
1113
-
1114
- }
1115
-
1116
- function _applyTagSettings($tags, $Features, $omittags='', $onlytags=false) {
1117
- if (empty($this->mpdf->OTLtags['Plus']) && empty($this->mpdf->OTLtags['Minus']) && empty($this->mpdf->OTLtags['FFPlus']) && empty($this->mpdf->OTLtags['FFMinus'])) { return $tags; }
1118
-
1119
- // Use $tags as starting point
1120
- $usetags = $tags;
1121
-
1122
- // Only set / unset tags which are in the font
1123
- // Ignore tags which are in $omittags
1124
- // If $onlytags, then just unset tags which are already in the Tag list
1125
-
1126
- $fp = $fm = $ffp = $ffm = '';
1127
-
1128
- // Font features to enable - set by font-variant-xx
1129
- if (isset($this->mpdf->OTLtags['Plus'])) $fp = $this->mpdf->OTLtags['Plus'];
1130
- preg_match_all('/([a-zA-Z0-9]{4})/',$fp,$m);
1131
- for($i=0;$i<count($m[0]);$i++) {
1132
- $t = $m[1][$i];
1133
- // Is it a valid tag?
1134
- if(isset($Features[$t]) && strpos($omittags,$t)===false && (!$onlytags || strpos($tags,$t)!==false )) {
1135
- $usetags .= ' '.$t;
1136
- }
1137
- }
1138
-
1139
- // Font features to disable - set by font-variant-xx
1140
- if (isset($this->mpdf->OTLtags['Minus'])) $fm = $this->mpdf->OTLtags['Minus'];
1141
- preg_match_all('/([a-zA-Z0-9]{4})/',$fm,$m);
1142
- for($i=0;$i<count($m[0]);$i++) {
1143
- $t = $m[1][$i];
1144
- // Is it a valid tag?
1145
- if(isset($Features[$t]) && strpos($omittags,$t)===false && (!$onlytags || strpos($tags,$t)!==false )) {
1146
- $usetags = str_replace($t,'',$usetags);
1147
- }
1148
- }
1149
-
1150
- // Font features to enable - set by font-feature-settings
1151
- if (isset($this->mpdf->OTLtags['FFPlus'])) $ffp = $this->mpdf->OTLtags['FFPlus']; // Font Features - may include integer: salt4
1152
- preg_match_all('/([a-zA-Z0-9]{4})([\d+]*)/',$ffp,$m);
1153
- for($i=0;$i<count($m[0]);$i++) {
1154
- $t = $m[1][$i];
1155
- // Is it a valid tag?
1156
- if(isset($Features[$t]) && strpos($omittags,$t)===false && (!$onlytags || strpos($tags,$t)!==false )) {
1157
- $usetags .= ' '.$m[0][$i]; // - may include integer: salt4
1158
- }
1159
- }
1160
-
1161
- // Font features to disable - set by font-feature-settings
1162
- if (isset($this->mpdf->OTLtags['FFMinus'])) $ffm = $this->mpdf->OTLtags['FFMinus'];
1163
- preg_match_all('/([a-zA-Z0-9]{4})/',$ffm,$m);
1164
- for($i=0;$i<count($m[0]);$i++) {
1165
- $t = $m[1][$i];
1166
- // Is it a valid tag?
1167
- if(isset($Features[$t]) && strpos($omittags,$t)===false && (!$onlytags || strpos($tags,$t)!==false )) {
1168
- $usetags = str_replace($t,'',$usetags);
1169
- }
1170
- }
1171
- return $usetags;
1172
- }
1173
-
1174
- function _applyGSUBrules($usetags, $scriptTag, $langsys) {
1175
- // Features from all Tags are applied together, in Lookup List order.
1176
- // For Indic - should be applied one syllable at a time
1177
- // - Implemented in functions checkContextMatch and checkContextMatchMultiple by failing to match if outside scope of current 'syllable'
1178
- // if $this->restrictToSyllable is true
1179
-
1180
- $GSUBFeatures = $this->mpdf->CurrentFont['GSUBFeatures'][$scriptTag][$langsys];
1181
- $LookupList = array();
1182
- foreach($GSUBFeatures AS $tag=>$arr) {
1183
- if (strpos($usetags, $tag)!==false) {
1184
- foreach($arr AS $lu) { $LookupList[$lu] = $tag; }
1185
- }
1186
- }
1187
- ksort($LookupList);
1188
-
1189
- foreach($LookupList AS $lu=>$tag) {
1190
- $Type = $this->GSUBLookups[$lu]['Type'];
1191
- $Flag = $this->GSUBLookups[$lu]['Flag'];
1192
- $MarkFilteringSet = $this->GSUBLookups[$lu]['MarkFilteringSet'];
1193
- $tagInt = 1;
1194
- if (preg_match('/'.$tag.'([0-9]{1,2})/', $usetags, $m)) {
1195
- $tagInt = $m[1];
1196
- }
1197
- $ptr = 0;
1198
- // Test each glyph sequentially
1199
- while($ptr < (count($this->OTLdata))) { // whilst there is another glyph ..0064
1200
- $currGlyph = $this->OTLdata[$ptr]['hex'];
1201
- $currGID = $this->OTLdata[$ptr]['uni'];
1202
- $shift = 1;
1203
- foreach($this->GSUBLookups[$lu]['Subtables'] AS $c=>$subtable_offset) {
1204
- // NB Coverage only looks at glyphs for position 1 (esp. 7.3 and 8.3)
1205
- if (isset($this->GSLuCoverage[$lu][$c][$currGID])) {
1206
- // Get rules from font GSUB subtable
1207
- $shift = $this->_applyGSUBsubtable($lu, $c, $ptr, $currGlyph, $currGID, ($subtable_offset - $this->GSUB_offset), $Type, $Flag, $MarkFilteringSet, $this->GSLuCoverage[$lu][$c], 0, $tag, 0, $tagInt);
1208
-
1209
- if ($shift) { break; }
1210
- }
1211
- }
1212
- if ($shift == 0) { $shift = 1; }
1213
- $ptr += $shift;
1214
-
1215
- }
1216
- }
1217
- }
1218
-
1219
- function _applyGSUBrulesSingly($usetags, $scriptTag, $langsys) {
1220
- // Features are applied one at a time, working through each codepoint
1221
-
1222
- $GSUBFeatures = $this->mpdf->CurrentFont['GSUBFeatures'][$scriptTag][$langsys];
1223
-
1224
- $tags = explode(' ',$usetags);
1225
- foreach($tags AS $usetag) {
1226
- $LookupList = array();
1227
- foreach($GSUBFeatures AS $tag=>$arr) {
1228
- if (strpos($usetags, $tag)!==false) {
1229
- foreach($arr AS $lu) { $LookupList[$lu] = $tag; }
1230
- }
1231
- }
1232
- ksort($LookupList);
1233
-
1234
- $ptr = 0;
1235
- // Test each glyph sequentially
1236
- while($ptr < (count($this->OTLdata))) { // whilst there is another glyph ..0064
1237
- $currGlyph = $this->OTLdata[$ptr]['hex'];
1238
- $currGID = $this->OTLdata[$ptr]['uni'];
1239
- $shift = 1;
1240
-
1241
- foreach($LookupList AS $lu=>$tag) {
1242
- $Type = $this->GSUBLookups[$lu]['Type'];
1243
- $Flag = $this->GSUBLookups[$lu]['Flag'];
1244
- $MarkFilteringSet = $this->GSUBLookups[$lu]['MarkFilteringSet'];
1245
- $tagInt = 1;
1246
- if (preg_match('/'.$tag.'([0-9]{1,2})/', $usetags, $m)) {
1247
- $tagInt = $m[1];
1248
- }
1249
-
1250
- foreach($this->GSUBLookups[$lu]['Subtables'] AS $c=>$subtable_offset) {
1251
- // NB Coverage only looks at glyphs for position 1 (esp. 7.3 and 8.3)
1252
- if (isset($this->GSLuCoverage[$lu][$c][$currGID])) {
1253
- // Get rules from font GSUB subtable
1254
- $shift = $this->_applyGSUBsubtable($lu, $c, $ptr, $currGlyph, $currGID, ($subtable_offset - $this->GSUB_offset), $Type, $Flag, $MarkFilteringSet, $this->GSLuCoverage[$lu][$c], 0, $tag, 0, $tagInt);
1255
-
1256
- if ($shift) { break 2; }
1257
- }
1258
- }
1259
- }
1260
- if ($shift == 0) { $shift = 1; }
1261
- $ptr += $shift;
1262
-
1263
- }
1264
- }
1265
- }
1266
-
1267
- function _applyGSUBrulesMyanmar($usetags, $scriptTag, $langsys) {
1268
- // $usetags = locl ccmp rphf pref blwf pstf';
1269
- // applied to all characters
1270
-
1271
- $GSUBFeatures = $this->mpdf->CurrentFont['GSUBFeatures'][$scriptTag][$langsys];
1272
-
1273
- // ALL should be applied one syllable at a time
1274
- // Implemented in functions checkContextMatch and checkContextMatchMultiple by failing to match if outside scope of current 'syllable'
1275
- $tags = explode(' ',$usetags);
1276
- foreach($tags AS $usetag) {
1277
-
1278
- $LookupList = array();
1279
- foreach($GSUBFeatures AS $tag=>$arr) {
1280
- if ($tag==$usetag) {
1281
- foreach($arr AS $lu) { $LookupList[$lu] = $tag; }
1282
- }
1283
- }
1284
- ksort($LookupList);
1285
-
1286
- foreach($LookupList AS $lu=>$tag) {
1287
-
1288
- $Type = $this->GSUBLookups[$lu]['Type'];
1289
- $Flag = $this->GSUBLookups[$lu]['Flag'];
1290
- $MarkFilteringSet = $this->GSUBLookups[$lu]['MarkFilteringSet'];
1291
- $tagInt = 1;
1292
- if (preg_match('/'.$tag.'([0-9]{1,2})/', $usetags, $m)) {
1293
- $tagInt = $m[1];
1294
- }
1295
-
1296
- $ptr = 0;
1297
- // Test each glyph sequentially
1298
- while($ptr < (count($this->OTLdata))) { // whilst there is another glyph ..0064
1299
- $currGlyph = $this->OTLdata[$ptr]['hex'];
1300
- $currGID = $this->OTLdata[$ptr]['uni'];
1301
- $shift = 1;
1302
- foreach($this->GSUBLookups[$lu]['Subtables'] AS $c=>$subtable_offset) {
1303
- // NB Coverage only looks at glyphs for position 1 (esp. 7.3 and 8.3)
1304
- if (isset($this->GSLuCoverage[$lu][$c][$currGID])) {
1305
- // Get rules from font GSUB subtable
1306
- $shift = $this->_applyGSUBsubtable($lu, $c, $ptr, $currGlyph, $currGID, ($subtable_offset - $this->GSUB_offset), $Type, $Flag, $MarkFilteringSet, $this->GSLuCoverage[$lu][$c], 0, $usetag, 0, $tagInt);
1307
-
1308
- if ($shift) { break; }
1309
- }
1310
- }
1311
- if ($shift == 0) { $shift = 1; }
1312
- $ptr += $shift;
1313
-
1314
- }
1315
- }
1316
- }
1317
- }
1318
-
1319
- function _applyGSUBrulesIndic($usetags, $scriptTag, $langsys, $is_old_spec) {
1320
- // $usetags = 'locl ccmp nukt akhn rphf rkrf pref blwf half pstf vatu cjct'; then later - init
1321
- // rphf, pref, blwf, half, abvf, pstf, and init are only applied where ['mask'] indicates: INDIC::FLAG(INDIC::RPHF);
1322
- // The rest are applied to all characters
1323
-
1324
- $GSUBFeatures = $this->mpdf->CurrentFont['GSUBFeatures'][$scriptTag][$langsys];
1325
-
1326
- // ALL should be applied one syllable at a time
1327
- // Implemented in functions checkContextMatch and checkContextMatchMultiple by failing to match if outside scope of current 'syllable'
1328
- $tags = explode(' ',$usetags);
1329
- foreach($tags AS $usetag) {
1330
-
1331
- $LookupList = array();
1332
- foreach($GSUBFeatures AS $tag=>$arr) {
1333
- if ($tag==$usetag) {
1334
- foreach($arr AS $lu) { $LookupList[$lu] = $tag; }
1335
- }
1336
- }
1337
- ksort($LookupList);
1338
-
1339
- foreach($LookupList AS $lu=>$tag) {
1340
-
1341
- $Type = $this->GSUBLookups[$lu]['Type'];
1342
- $Flag = $this->GSUBLookups[$lu]['Flag'];
1343
- $MarkFilteringSet = $this->GSUBLookups[$lu]['MarkFilteringSet'];
1344
- $tagInt = 1;
1345
- if (preg_match('/'.$tag.'([0-9]{1,2})/', $usetags, $m)) {
1346
- $tagInt = $m[1];
1347
- }
1348
-
1349
- $ptr = 0;
1350
- // Test each glyph sequentially
1351
- while($ptr < (count($this->OTLdata))) { // whilst there is another glyph ..0064
1352
- $currGlyph = $this->OTLdata[$ptr]['hex'];
1353
- $currGID = $this->OTLdata[$ptr]['uni'];
1354
- $shift = 1;
1355
- foreach($this->GSUBLookups[$lu]['Subtables'] AS $c=>$subtable_offset) {
1356
- // NB Coverage only looks at glyphs for position 1 (esp. 7.3 and 8.3)
1357
- if (isset($this->GSLuCoverage[$lu][$c][$currGID])) {
1358
- if (strpos('rphf pref blwf half pstf cfar init' , $usetag)!==false) { // only apply when mask indicates
1359
- $mask = 0;
1360
- switch ($usetag) {
1361
- case 'rphf': $mask = (1<<(INDIC::RPHF)); break;
1362
- case 'pref': $mask = (1<<(INDIC::PREF)); break;
1363
- case 'blwf': $mask = (1<<(INDIC::BLWF)); break;
1364
- case 'half': $mask = (1<<(INDIC::HALF)); break;
1365
- case 'pstf': $mask = (1<<(INDIC::PSTF)); break;
1366
- case 'cfar': $mask = (1<<(INDIC::CFAR)); break;
1367
- case 'init': $mask = (1<<(INDIC::INIT)); break;
1368
- }
1369
- if (!($this->OTLdata[$ptr]['mask'] & $mask)) { continue; }
1370
- }
1371
- // Get rules from font GSUB subtable
1372
- $shift = $this->_applyGSUBsubtable($lu, $c, $ptr, $currGlyph, $currGID, ($subtable_offset - $this->GSUB_offset), $Type, $Flag, $MarkFilteringSet, $this->GSLuCoverage[$lu][$c], 0, $usetag, $is_old_spec, $tagInt);
1373
-
1374
- if ($shift) { break; }
1375
- }
1376
-
1377
- // Special case for Indic ZZZ99S
1378
- // Check to substitute Halant-Consonant in PREF, BLWF or PSTF
1379
- // i.e. new spec but GSUB tables have Consonant-Halant in Lookups e.g. FreeSerif, which
1380
- // incorrectly just moved old spec tables to new spec. Uniscribe seems to cope with this
1381
- // See also ttffontsuni.php
1382
- // First check if current glyph is a Halant/Virama
1383
- else if (_OTL_OLD_SPEC_COMPAT_1 && $Type==4 && !$is_old_spec && strpos('0094D 009CD 00A4D 00ACD 00B4D 00BCD 00C4D 00CCD 00D4D',$currGlyph)!== false) {
1384
- // only apply when 'pref blwf pstf' tags, and when mask indicates
1385
- if (strpos('pref blwf pstf' , $usetag)!==false) {
1386
- $mask = 0;
1387
- switch ($usetag) {
1388
- case 'pref': $mask = (1<<(INDIC::PREF)); break;
1389
- case 'blwf': $mask = (1<<(INDIC::BLWF)); break;
1390
- case 'pstf': $mask = (1<<(INDIC::PSTF)); break;
1391
- }
1392
- if (!($this->OTLdata[$ptr]['mask'] & $mask)) { continue; }
1393
-
1394
- $nextGlyph = $this->OTLdata[$ptr+1]['hex'];
1395
- $nextGID = $this->OTLdata[$ptr+1]['uni'];
1396
- if (isset($this->GSLuCoverage[$lu][$c][$nextGID])) {
1397
-
1398
- // Get rules from font GSUB subtable
1399
- $shift = $this->_applyGSUBsubtableSpecial($lu, $c, $ptr, $currGlyph, $currGID, $nextGlyph, $nextGID, ($subtable_offset - $this->GSUB_offset), $Type, $this->GSLuCoverage[$lu][$c]);
1400
-
1401
- if ($shift) { break; }
1402
- }
1403
- }
1404
- }
1405
-
1406
-
1407
- }
1408
- if ($shift == 0) { $shift = 1; }
1409
- $ptr += $shift;
1410
-
1411
- }
1412
- }
1413
- }
1414
- }
1415
-
1416
-
1417
- function _applyGSUBsubtableSpecial($lookupID, $subtable, $ptr, $currGlyph, $currGID, $nextGlyph, $nextGID, $subtable_offset, $Type, $LuCoverage) {
1418
-
1419
- // Special case for Indic
1420
- // Check to substitute Halant-Consonant in PREF, BLWF or PSTF
1421
- // i.e. new spec but GSUB tables have Consonant-Halant in Lookups e.g. FreeSerif, which
1422
- // incorrectly just moved old spec tables to new spec. Uniscribe seems to cope with this
1423
- // See also ttffontsuni.php
1424
-
1425
- $this->seek($subtable_offset);
1426
- $SubstFormat= $this->read_ushort();
1427
-
1428
- // Subtable contains Consonant - Halant
1429
- // Text string contains Halant ($CurrGlyph) - Consonant ($nextGlyph)
1430
- // Halant has already been matched, and already checked that $nextGID is in Coverage table
1431
-
1432
- ////////////////////////////////////////////////////////////////////////////////
1433
- // Only does: LookupType 4: Ligature Substitution Subtable : n to 1
1434
- ////////////////////////////////////////////////////////////////////////////////
1435
- $Coverage = $subtable_offset + $this->read_ushort();
1436
- $NextGlyphPos = $LuCoverage[$nextGID];
1437
- $LigSetCount = $this->read_short();
1438
-
1439
- $this->skip($NextGlyphPos * 2);
1440
- $LigSet = $subtable_offset + $this->read_short();
1441
-
1442
- $this->seek($LigSet);
1443
- $LigCount = $this->read_short();
1444
- // LigatureSet i.e. all starting with the same Glyph $nextGlyph [Consonant]
1445
- $LigatureOffset = array();
1446
- for ($g=0;$g<$LigCount;$g++) {
1447
- $LigatureOffset[$g] = $LigSet + $this->read_ushort();
1448
- }
1449
- for ($g=0;$g<$LigCount;$g++) {
1450
- // Ligature tables
1451
- $this->seek($LigatureOffset[$g]);
1452
- $LigGlyph = $this->read_ushort();
1453
- $substitute = $this->glyphToChar($LigGlyph);
1454
- $CompCount = $this->read_ushort();
1455
-
1456
- if ($CompCount != 2) { return 0; } // Only expecting to work with 2:1 (and no ignore characters in between)
1457
-
1458
-
1459
- $gid = $this->read_ushort();
1460
- $checkGlyph = $this->glyphToChar($gid); // Other component/input Glyphs starting at position 2 (arrayindex 1)
1461
-
1462
- if ($currGID == $checkGlyph) { $match = true; }
1463
- else { $match = false; break; }
1464
-
1465
- $GlyphPos = array();
1466
- $GlyphPos[] = $ptr;
1467
- $GlyphPos[] = $ptr+1;
1468
-
1469
-
1470
- if ($match) {
1471
- $shift = $this->GSUBsubstitute($ptr, $substitute, 4, $GlyphPos ); // GlyphPos contains positions to set null
1472
- if ($shift) return 1;
1473
- }
1474
-
1475
- }
1476
- return 0;
1477
- }
1478
-
1479
- function _applyGSUBsubtable($lookupID, $subtable, $ptr, $currGlyph, $currGID, $subtable_offset, $Type, $Flag, $MarkFilteringSet, $LuCoverage, $level=0, $currentTag, $is_old_spec, $tagInt) {
1480
- $ignore = $this->_getGCOMignoreString($Flag, $MarkFilteringSet);
1481
-
1482
- // Lets start
1483
- $this->seek($subtable_offset);
1484
- $SubstFormat= $this->read_ushort();
1485
-
1486
- ////////////////////////////////////////////////////////////////////////////////
1487
- // LookupType 1: Single Substitution Subtable : 1 to 1
1488
- ////////////////////////////////////////////////////////////////////////////////
1489
- if ($Type == 1) {
1490
- // Flag = Ignore
1491
- if ($this->_checkGCOMignore($Flag, $currGlyph, $MarkFilteringSet)) { return 0; }
1492
- $CoverageOffset = $subtable_offset + $this->read_ushort();
1493
- $GlyphPos = $LuCoverage[$currGID];
1494
- //===========
1495
- // Format 1:
1496
- //===========
1497
- if ($SubstFormat==1) { // Calculated output glyph indices
1498
- $DeltaGlyphID = $this->read_short();
1499
- $this->seek($CoverageOffset);
1500
- $glyphs = $this->_getCoverageGID();
1501
- $GlyphID = $glyphs[$GlyphPos] + $DeltaGlyphID;
1502
- }
1503
- //===========
1504
- // Format 2:
1505
- //===========
1506
- else if ($SubstFormat==2) { // Specified output glyph indices
1507
- $GlyphCount = $this->read_ushort();
1508
- $this->skip($GlyphPos * 2 );
1509
- $GlyphID = $this->read_ushort();
1510
- }
1511
-
1512
- $substitute = $this->glyphToChar($GlyphID);
1513
- $shift = $this->GSUBsubstitute($ptr, $substitute, $Type );
1514
- if ($this->debugOTL && $shift) { $this->_dumpproc('GSUB', $lookupID, $subtable, $Type, $SubstFormat, $ptr, $currGlyph, $level); }
1515
- if ($shift) return 1;
1516
- return 0;
1517
- }
1518
-
1519
- ////////////////////////////////////////////////////////////////////////////////
1520
- // LookupType 2: Multiple Substitution Subtable : 1 to n
1521
- ////////////////////////////////////////////////////////////////////////////////
1522
- else if ($Type == 2) {
1523
- // Flag = Ignore
1524
- if ($this->_checkGCOMignore($Flag, $currGlyph, $MarkFilteringSet)) { return 0; }
1525
- $Coverage = $subtable_offset + $this->read_ushort();
1526
- $GlyphPos = $LuCoverage[$currGID];
1527
- $this->skip(2);
1528
- $this->skip($GlyphPos * 2);
1529
- $Sequences = $subtable_offset + $this->read_short();
1530
-
1531
- $this->seek($Sequences);
1532
- $GlyphCount = $this->read_short();
1533
- $SubstituteGlyphs = array();
1534
- for ($g=0;$g<$GlyphCount;$g++) {
1535
- $sgid = $this->read_ushort();
1536
- $SubstituteGlyphs[] = $this->glyphToChar($sgid);
1537
- }
1538
-
1539
- $shift = $this->GSUBsubstitute($ptr, $SubstituteGlyphs, $Type );
1540
- if ($this->debugOTL && $shift) { $this->_dumpproc('GSUB', $lookupID, $subtable, $Type, $SubstFormat, $ptr, $currGlyph, $level); }
1541
- if ($shift) return $shift;
1542
- return 0;
1543
- }
1544
- ////////////////////////////////////////////////////////////////////////////////
1545
- // LookupType 3: Alternate Forms : 1 to 1(n)
1546
- ////////////////////////////////////////////////////////////////////////////////
1547
- else if ($Type == 3) {
1548
- // Flag = Ignore
1549
- if ($this->_checkGCOMignore($Flag, $currGlyph, $MarkFilteringSet)) { return 0; }
1550
- $Coverage = $subtable_offset + $this->read_ushort();
1551
- $AlternateSetCount = $this->read_short();
1552
- ///////////////////////////////////////////////////////////////////////////////!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1553
- // Need to set alternate IF set by CSS3 font-feature for a tag
1554
- // i.e. if this is 'salt' alternate may be set to 2
1555
- // default value will be $alt=1 ( === index of 0 in list of alternates)
1556
- $alt = 1; // $alt=1 points to Alternative[0]
1557
- if ($tagInt>1) { $alt = $tagInt; }
1558
- ///////////////////////////////////////////////////////////////////////////////!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1559
- if ($alt == 0) { return 0; } // If specified alternate not present, cancel [ or could default $alt = 1 ?]
1560
-
1561
- $GlyphPos = $LuCoverage[$currGID];
1562
- $this->skip($GlyphPos * 2);
1563
-
1564
- $AlternateSets = $subtable_offset + $this->read_short();
1565
- $this->seek($AlternateSets );
1566
-
1567
- $AlternateGlyphCount = $this->read_short();
1568
- if ($alt > $AlternateGlyphCount) { return 0; } // If specified alternate not present, cancel [ or could default $alt = 1 ?]
1569
-
1570
- $this->skip(($alt-1) * 2);
1571
- $GlyphID = $this->read_ushort();
1572
-
1573
- $substitute = $this->glyphToChar($GlyphID);
1574
- $shift = $this->GSUBsubstitute($ptr, $substitute, $Type );
1575
- if ($this->debugOTL && $shift) { $this->_dumpproc('GSUB', $lookupID, $subtable, $Type, $SubstFormat, $ptr, $currGlyph, $level); }
1576
- if ($shift) return 1;
1577
- return 0;
1578
- }
1579
- ////////////////////////////////////////////////////////////////////////////////
1580
- // LookupType 4: Ligature Substitution Subtable : n to 1
1581
- ////////////////////////////////////////////////////////////////////////////////
1582
- else if ($Type == 4) {
1583
- // Flag = Ignore
1584
- if ($this->_checkGCOMignore($Flag, $currGlyph, $MarkFilteringSet)) { return 0; }
1585
- $Coverage = $subtable_offset + $this->read_ushort();
1586
- $FirstGlyphPos = $LuCoverage[$currGID];
1587
-
1588
- $LigSetCount = $this->read_short();
1589
-
1590
- $this->skip($FirstGlyphPos * 2);
1591
- $LigSet = $subtable_offset + $this->read_short();
1592
-
1593
- $this->seek($LigSet);
1594
- $LigCount = $this->read_short();
1595
- // LigatureSet i.e. all starting with the same first Glyph $currGlyph
1596
- $LigatureOffset = array();
1597
- for ($g=0;$g<$LigCount;$g++) {
1598
- $LigatureOffset[$g] = $LigSet + $this->read_ushort();
1599
- }
1600
- for ($g=0;$g<$LigCount;$g++) {
1601
- // Ligature tables
1602
- $this->seek($LigatureOffset[$g]);
1603
- $LigGlyph = $this->read_ushort(); // Output Ligature GlyphID
1604
- $substitute = $this->glyphToChar($LigGlyph);
1605
- $CompCount = $this->read_ushort();
1606
-
1607
- $spos = $ptr;
1608
- $match = true;
1609
- $GlyphPos = array();
1610
- $GlyphPos[] = $spos;
1611
- for ($l=1;$l<$CompCount;$l++) {
1612
- $gid = $this->read_ushort();
1613
- $checkGlyph = $this->glyphToChar($gid); // Other component/input Glyphs starting at position 2 (arrayindex 1)
1614
-
1615
- $spos++;
1616
- //while $this->OTLdata[$spos]['uni'] is an "ignore" => spos++
1617
- while (isset($this->OTLdata[$spos]) && strpos($ignore, $this->OTLdata[$spos]['hex'])!==false) { $spos++; }
1618
-
1619
- if (isset($this->OTLdata[$spos]) && $this->OTLdata[$spos]['uni'] == $checkGlyph) {
1620
- $GlyphPos[] = $spos;
1621
- }
1622
- else { $match = false; break; }
1623
-
1624
- }
1625
-
1626
-
1627
- if ($match) {
1628
- $shift = $this->GSUBsubstitute($ptr, $substitute, $Type, $GlyphPos ); // GlyphPos contains positions to set null
1629
- if ($this->debugOTL && $shift) { $this->_dumpproc('GSUB', $lookupID, $subtable, $Type, $SubstFormat, $ptr, $currGlyph, $level); }
1630
- if ($shift) return ($spos-$ptr+1-($CompCount-1));
1631
- }
1632
-
1633
- }
1634
- return 0;
1635
- }
1636
-
1637
- ////////////////////////////////////////////////////////////////////////////////
1638
- // LookupType 5: Contextual Substitution Subtable
1639
- ////////////////////////////////////////////////////////////////////////////////
1640
- else if ($Type == 5) {
1641
- //===========
1642
- // Format 1: Simple Context Glyph Substitution
1643
- //===========
1644
- if ($SubstFormat==1) {
1645
- $CoverageTableOffset = $subtable_offset + $this->read_ushort();
1646
- $SubRuleSetCount = $this->read_ushort();
1647
- $SubRuleSetOffset = array();
1648
- for ($b=0;$b<$SubRuleSetCount;$b++) {
1649
- $offset = $this->read_ushort();
1650
- if ($offset==0x0000) {
1651
- $SubRuleSetOffset[] = $offset;
1652
- }
1653
- else {
1654
- $SubRuleSetOffset[] = $subtable_offset + $offset;
1655
- }
1656
- }
1657
-
1658
- // SubRuleSet tables: All contexts beginning with the same glyph
1659
- // Select the SubRuleSet required using the position of the glyph in the coverage table
1660
- $GlyphPos = $LuCoverage[$currGID];
1661
- if ($SubRuleSetOffset[$GlyphPos]>0) {
1662
- $this->seek($SubRuleSetOffset[$GlyphPos]);
1663
- $SubRuleCnt = $this->read_ushort();
1664
- $SubRule = array();
1665
- for($b=0;$b<$SubRuleCnt;$b++) {
1666
- $SubRule[$b] = $SubRuleSetOffset[$GlyphPos]+$this->read_ushort();
1667
- }
1668
- for($b=0;$b<$SubRuleCnt;$b++) { // EACH RULE
1669
- $this->seek($SubRule[$b]);
1670
- $InputGlyphCount = $this->read_ushort();
1671
- $SubstCount = $this->read_ushort();
1672
-
1673
- $Backtrack = array();
1674
- $Lookahead = array();
1675
- $Input = array();
1676
- $Input[0] = $this->OTLdata[$ptr]['uni'];
1677
- for ($r=1;$r<$InputGlyphCount;$r++) {
1678
- $gid = $this->read_ushort();
1679
- $Input[$r] = $this->glyphToChar($gid);
1680
- }
1681
- $matched = $this->checkContextMatch($Input, $Backtrack, $Lookahead, $ignore, $ptr);
1682
- if ($matched) {
1683
- if ($this->debugOTL) { $this->_dumpproc('GSUB', $lookupID, $subtable, $Type, $SubstFormat, $ptr, $currGlyph, $level); }
1684
- for ($p=0;$p<$SubstCount;$p++) { // EACH LOOKUP
1685
- $SequenceIndex[$p] = $this->read_ushort();
1686
- $LookupListIndex[$p] = $this->read_ushort();
1687
- }
1688
-
1689
- for ($p=0;$p<$SubstCount;$p++) {
1690
- // Apply $LookupListIndex at $SequenceIndex
1691
- if ($SequenceIndex[$p] >= $InputGlyphCount) { continue; }
1692
- $lu = $LookupListIndex[$p];
1693
- $luType = $this->GSUBLookups[$lu]['Type'];
1694
- $luFlag = $this->GSUBLookups[$lu]['Flag'];
1695
- $luMarkFilteringSet = $this->GSUBLookups[$lu]['MarkFilteringSet'];
1696
-
1697
- $luptr = $matched[$SequenceIndex[$p]];
1698
- $lucurrGlyph = $this->OTLdata[$luptr]['hex'];
1699
- $lucurrGID = $this->OTLdata[$luptr]['uni'];
1700
-
1701
- foreach($this->GSUBLookups[$lu]['Subtables'] AS $luc=>$lusubtable_offset) {
1702
- $shift = $this->_applyGSUBsubtable($lu, $luc, $luptr, $lucurrGlyph, $lucurrGID, ($lusubtable_offset - $this->GSUB_offset) , $luType, $luFlag, $luMarkFilteringSet, $this->GSLuCoverage[$lu][$luc], 1, $currentTag, $is_old_spec, $tagInt);
1703
- if ($shift) { break; }
1704
- }
1705
- }
1706
-
1707
- if (!defined("OMIT_OTL_FIX_3") || OMIT_OTL_FIX_3 != 1) { return $shift ; } /* OTL_FIX_3 */
1708
- else return $InputGlyphCount ; // should be + matched ignores in Input Sequence
1709
-
1710
- }
1711
- }
1712
-
1713
- }
1714
- return 0;
1715
- }
1716
-
1717
- //===========
1718
- // Format 2:
1719
- //===========
1720
- // Format 2: Class-based Context Glyph Substitution
1721
- else if ($SubstFormat==2) {
1722
-
1723
- $CoverageTableOffset = $subtable_offset + $this->read_ushort();
1724
- $InputClassDefOffset = $subtable_offset + $this->read_ushort();
1725
- $SubClassSetCnt = $this->read_ushort();
1726
- $SubClassSetOffset = array();
1727
- for ($b=0;$b<$SubClassSetCnt;$b++) {
1728
- $offset = $this->read_ushort();
1729
- if ($offset==0x0000) {
1730
- $SubClassSetOffset[] = $offset;
1731
- }
1732
- else {
1733
- $SubClassSetOffset[] = $subtable_offset + $offset;
1734
- }
1735
- }
1736
-
1737
- $InputClasses = $this->_getClasses($InputClassDefOffset);
1738
-
1739
- for ($s=0;$s<$SubClassSetCnt;$s++) { // $SubClassSet is ordered by input class-may be NULL
1740
- // Select $SubClassSet if currGlyph is in First Input Class
1741
- if ($SubClassSetOffset[$s]>0 && isset($InputClasses[$s][$currGID])) {
1742
- $this->seek($SubClassSetOffset[$s]);
1743
- $SubClassRuleCnt = $this->read_ushort();
1744
- $SubClassRule = array();
1745
- for($b=0;$b<$SubClassRuleCnt;$b++) {
1746
- $SubClassRule[$b] = $SubClassSetOffset[$s]+$this->read_ushort();
1747
- }
1748
-
1749
- for($b=0;$b<$SubClassRuleCnt;$b++) { // EACH RULE
1750
- $this->seek($SubClassRule[$b]);
1751
- $InputGlyphCount = $this->read_ushort();
1752
- $SubstCount = $this->read_ushort();
1753
- $Input = array();
1754
- for ($r=1;$r<$InputGlyphCount;$r++) {
1755
- $Input[$r] = $this->read_ushort();
1756
- }
1757
-
1758
- $inputClass = $s;
1759
-
1760
- $inputGlyphs = array();
1761
- $inputGlyphs[0] = $InputClasses[$inputClass];
1762
-
1763
- if ($InputGlyphCount>1) {
1764
- // NB starts at 1
1765
- for ($gcl=1;$gcl<$InputGlyphCount;$gcl++) {
1766
- $classindex = $Input[$gcl];
1767
- if (isset($InputClasses[$classindex])) { $inputGlyphs[$gcl] = $InputClasses[$classindex]; }
1768
- else { $inputGlyphs[$gcl] = ''; }
1769
- }
1770
- }
1771
-
1772
- // Class 0 contains all the glyphs NOT in the other classes
1773
- $class0excl = array();
1774
- for ($gc=1;$gc<=count($InputClasses);$gc++) {
1775
- if (is_array($InputClasses[$gc])) $class0excl = $class0excl + $InputClasses[$gc];
1776
- }
1777
-
1778
- $backtrackGlyphs = array();
1779
- $lookaheadGlyphs = array();
1780
-
1781
- $matched = $this->checkContextMatchMultipleUni($inputGlyphs, $backtrackGlyphs, $lookaheadGlyphs, $ignore, $ptr, $class0excl);
1782
- if ($matched) {
1783
- if ($this->debugOTL) { $this->_dumpproc('GSUB', $lookupID, $subtable, $Type, $SubstFormat, $ptr, $currGlyph, $level); }
1784
- for ($p=0;$p<$SubstCount;$p++) { // EACH LOOKUP
1785
- $SequenceIndex[$p] = $this->read_ushort();
1786
- $LookupListIndex[$p] = $this->read_ushort();
1787
- }
1788
-
1789
- for ($p=0;$p<$SubstCount;$p++) {
1790
- // Apply $LookupListIndex at $SequenceIndex
1791
- if ($SequenceIndex[$p] >= $InputGlyphCount) { continue; }
1792
- $lu = $LookupListIndex[$p];
1793
- $luType = $this->GSUBLookups[$lu]['Type'];
1794
- $luFlag = $this->GSUBLookups[$lu]['Flag'];
1795
- $luMarkFilteringSet = $this->GSUBLookups[$lu]['MarkFilteringSet'];
1796
-
1797
- $luptr = $matched[$SequenceIndex[$p]];
1798
- $lucurrGlyph = $this->OTLdata[$luptr]['hex'];
1799
- $lucurrGID = $this->OTLdata[$luptr]['uni'];
1800
-
1801
- foreach($this->GSUBLookups[$lu]['Subtables'] AS $luc=>$lusubtable_offset) {
1802
- $shift = $this->_applyGSUBsubtable($lu, $luc, $luptr, $lucurrGlyph, $lucurrGID, ($lusubtable_offset - $this->GSUB_offset) , $luType, $luFlag, $luMarkFilteringSet, $this->GSLuCoverage[$lu][$luc], 1, $currentTag, $is_old_spec, $tagInt);
1803
- if ($shift) { break; }
1804
- }
1805
- }
1806
-
1807
- if (!defined("OMIT_OTL_FIX_3") || OMIT_OTL_FIX_3 != 1) { return $shift ; } /* OTL_FIX_3 */
1808
- else return $InputGlyphCount ; // should be + matched ignores in Input Sequence
1809
-
1810
- }
1811
-
1812
- }
1813
-
1814
- }
1815
- }
1816
-
1817
- return 0;
1818
- }
1819
-
1820
- //===========
1821
- // Format 3:
1822
- //===========
1823
- // Format 3: Coverage-based Context Glyph Substitution
1824
- else if ($SubstFormat==3) {
1825
- die("GSUB Lookup Type ".$Type." Format ".$SubstFormat." not TESTED YET.");
1826
- return 0;
1827
- }
1828
-
1829
- }
1830
-
1831
- ////////////////////////////////////////////////////////////////////////////////
1832
- // LookupType 6: Chaining Contextual Substitution Subtable
1833
- ////////////////////////////////////////////////////////////////////////////////
1834
- else if ($Type == 6) {
1835
-
1836
- //===========
1837
- // Format 1:
1838
- //===========
1839
- // Format 1: Simple Chaining Context Glyph Substitution
1840
- if ($SubstFormat==1) {
1841
- $Coverage = $subtable_offset + $this->read_ushort();
1842
- $GlyphPos = $LuCoverage[$currGID];
1843
- $ChainSubRuleSetCount = $this->read_ushort();
1844
- // All of the ChainSubRule tables defining contexts that begin with the same first glyph are grouped together and defined in a ChainSubRuleSet table
1845
- $this->skip($GlyphPos * 2);
1846
- $ChainSubRuleSet= $subtable_offset + $this->read_ushort();
1847
- $this->seek($ChainSubRuleSet);
1848
- $ChainSubRuleCount = $this->read_ushort();
1849
-
1850
- for($s=0;$s<$ChainSubRuleCount;$s++) {
1851
- $ChainSubRule[$s] = $ChainSubRuleSet + $this->read_ushort();
1852
- }
1853
-
1854
- for($s=0;$s<$ChainSubRuleCount;$s++) {
1855
- $this->seek($ChainSubRule[$s]);
1856
-
1857
- $BacktrackGlyphCount = $this->read_ushort();
1858
- $Backtrack = array();
1859
- for ($b=0;$b<$BacktrackGlyphCount;$b++) {
1860
- $gid = $this->read_ushort();
1861
- $Backtrack[] = $this->glyphToChar($gid);
1862
- }
1863
- $Input = array();
1864
- $Input[0] = $this->OTLdata[$ptr]['uni'];
1865
- $InputGlyphCount = $this->read_ushort();
1866
- for ($b=1;$b<$InputGlyphCount;$b++) {
1867
- $gid = $this->read_ushort();
1868
- $Input[$b] = $this->glyphToChar($gid);
1869
- }
1870
- $LookaheadGlyphCount = $this->read_ushort();
1871
- $Lookahead = array();
1872
- for ($b=0;$b<$LookaheadGlyphCount;$b++) {
1873
- $gid = $this->read_ushort();
1874
- $Lookahead[] = $this->glyphToChar($gid);
1875
- }
1876
-
1877
- $matched = $this->checkContextMatch($Input, $Backtrack, $Lookahead, $ignore, $ptr);
1878
- if ($matched) {
1879
- if ($this->debugOTL) { $this->_dumpproc('GSUB', $lookupID, $subtable, $Type, $SubstFormat, $ptr, $currGlyph, $level); }
1880
- $SubstCount = $this->read_ushort();
1881
- for ($p=0;$p<$SubstCount;$p++) {
1882
- // SubstLookupRecord
1883
- $SubstLookupRecord[$p]['SequenceIndex'] = $this->read_ushort();
1884
- $SubstLookupRecord[$p]['LookupListIndex'] = $this->read_ushort();
1885
- }
1886
- for ($p=0;$p<$SubstCount;$p++) {
1887
- // Apply $SubstLookupRecord[$p]['LookupListIndex'] at $SubstLookupRecord[$p]['SequenceIndex']
1888
- if ($SubstLookupRecord[$p]['SequenceIndex'] >= $InputGlyphCount) { continue; }
1889
- $lu = $SubstLookupRecord[$p]['LookupListIndex'];
1890
- $luType = $this->GSUBLookups[$lu]['Type'];
1891
- $luFlag = $this->GSUBLookups[$lu]['Flag'];
1892
- $luMarkFilteringSet = $this->GSUBLookups[$lu]['MarkFilteringSet'];
1893
-
1894
- $luptr = $matched[$SubstLookupRecord[$p]['SequenceIndex']];
1895
- $lucurrGlyph = $this->OTLdata[$luptr]['hex'];
1896
- $lucurrGID = $this->OTLdata[$luptr]['uni'];
1897
-
1898
- foreach($this->GSUBLookups[$lu]['Subtables'] AS $luc=>$lusubtable_offset) {
1899
- $shift = $this->_applyGSUBsubtable($lu, $luc, $luptr, $lucurrGlyph, $lucurrGID, ($lusubtable_offset - $this->GSUB_offset), $luType, $luFlag, $luMarkFilteringSet, $this->GSLuCoverage[$lu][$luc], 1, $currentTag, $is_old_spec, $tagInt);
1900
- if ($shift) { break; }
1901
- }
1902
- }
1903
- if (!defined("OMIT_OTL_FIX_3") || OMIT_OTL_FIX_3 != 1) { return $shift ; } /* OTL_FIX_3 */
1904
- else return $InputGlyphCount ; // should be + matched ignores in Input Sequence
1905
- }
1906
-
1907
-
1908
-
1909
-
1910
- }
1911
- return 0;
1912
- }
1913
-
1914
- //===========
1915
- // Format 2:
1916
- //===========
1917
- // Format 2: Class-based Chaining Context Glyph Substitution p257
1918
- else if ($SubstFormat==2) {
1919
-
1920
- // NB Format 2 specifies fixed class assignments (identical for each position in the backtrack, input, or lookahead sequence) and exclusive classes (a glyph cannot be in more than one class at a time)
1921
-
1922
- $CoverageTableOffset = $subtable_offset + $this->read_ushort();
1923
- $BacktrackClassDefOffset = $subtable_offset + $this->read_ushort();
1924
- $InputClassDefOffset = $subtable_offset + $this->read_ushort();
1925
- $LookaheadClassDefOffset = $subtable_offset + $this->read_ushort();
1926
- $ChainSubClassSetCnt = $this->read_ushort();
1927
- $ChainSubClassSetOffset = array();
1928
- for ($b=0;$b<$ChainSubClassSetCnt;$b++) {
1929
- $offset = $this->read_ushort();
1930
- if ($offset==0x0000) {
1931
- $ChainSubClassSetOffset[] = $offset;
1932
- }
1933
- else {
1934
- $ChainSubClassSetOffset[] = $subtable_offset + $offset;
1935
- }
1936
- }
1937
-
1938
- $BacktrackClasses = $this->_getClasses($BacktrackClassDefOffset);
1939
- $InputClasses = $this->_getClasses($InputClassDefOffset);
1940
- $LookaheadClasses = $this->_getClasses($LookaheadClassDefOffset);
1941
-
1942
- for ($s=0;$s<$ChainSubClassSetCnt;$s++) { // $ChainSubClassSet is ordered by input class-may be NULL
1943
- // Select $ChainSubClassSet if currGlyph is in First Input Class
1944
- if ($ChainSubClassSetOffset[$s]>0 && isset($InputClasses[$s][$currGID])) {
1945
- $this->seek($ChainSubClassSetOffset[$s]);
1946
- $ChainSubClassRuleCnt = $this->read_ushort();
1947
- $ChainSubClassRule = array();
1948
- for($b=0;$b<$ChainSubClassRuleCnt;$b++) {
1949
- $ChainSubClassRule[$b] = $ChainSubClassSetOffset[$s]+$this->read_ushort();
1950
- }
1951
-
1952
- for($b=0;$b<$ChainSubClassRuleCnt;$b++) { // EACH RULE
1953
- $this->seek($ChainSubClassRule[$b]);
1954
- $BacktrackGlyphCount = $this->read_ushort();
1955
- for ($r=0;$r<$BacktrackGlyphCount;$r++) {
1956
- $Backtrack[$r] = $this->read_ushort();
1957
- }
1958
- $InputGlyphCount = $this->read_ushort();
1959
- for ($r=1;$r<$InputGlyphCount;$r++) {
1960
- $Input[$r] = $this->read_ushort();
1961
- }
1962
- $LookaheadGlyphCount = $this->read_ushort();
1963
- for ($r=0;$r<$LookaheadGlyphCount;$r++) {
1964
- $Lookahead[$r] = $this->read_ushort();
1965
- }
1966
-
1967
-
1968
- // These contain classes of glyphs as arrays
1969
- // $InputClasses[(class)] e.g. 0x02E6,0x02E7,0x02E8
1970
- // $LookaheadClasses[(class)]
1971
- // $BacktrackClasses[(class)]
1972
-
1973
- // These contain arrays of classIndexes
1974
- // [Backtrack] [Lookahead] and [Input] (Input is from the second position only)
1975
-
1976
-
1977
- $inputClass = $s; //???
1978
-
1979
- $inputGlyphs = array();
1980
- $inputGlyphs[0] = $InputClasses[$inputClass];
1981
-
1982
- if ($InputGlyphCount>1) {
1983
- // NB starts at 1
1984
- for ($gcl=1;$gcl<$InputGlyphCount;$gcl++) {
1985
- $classindex = $Input[$gcl];
1986
- if (isset($InputClasses[$classindex])) { $inputGlyphs[$gcl] = $InputClasses[$classindex]; }
1987
- else { $inputGlyphs[$gcl] = ''; }
1988
- }
1989
- }
1990
-
1991
- // Class 0 contains all the glyphs NOT in the other classes
1992
- $class0excl = array();
1993
- for ($gc=1;$gc<=count($InputClasses);$gc++) {
1994
- if (isset($InputClasses[$gc])) $class0excl = $class0excl + $InputClasses[$gc];
1995
- }
1996
-
1997
- if ($BacktrackGlyphCount) {
1998
- for ($gcl=0;$gcl<$BacktrackGlyphCount;$gcl++) {
1999
- $classindex = $Backtrack[$gcl];
2000
- if (isset($BacktrackClasses[$classindex])) { $backtrackGlyphs[$gcl] = $BacktrackClasses[$classindex]; }
2001
- else { $backtrackGlyphs[$gcl] = ''; }
2002
- }
2003
- }
2004
- else { $backtrackGlyphs = array(); }
2005
-
2006
- // Class 0 contains all the glyphs NOT in the other classes
2007
- $bclass0excl = array();
2008
- for ($gc=1;$gc<=count($BacktrackClasses);$gc++) {
2009
- if (isset($BacktrackClasses[$gc])) $bclass0excl = $bclass0excl + $BacktrackClasses[$gc];
2010
- }
2011
-
2012
-
2013
- if ($LookaheadGlyphCount) {
2014
- for ($gcl=0;$gcl<$LookaheadGlyphCount;$gcl++) {
2015
- $classindex = $Lookahead[$gcl];
2016
- if (isset($LookaheadClasses[$classindex])) { $lookaheadGlyphs[$gcl] = $LookaheadClasses[$classindex]; }
2017
- else { $lookaheadGlyphs[$gcl] = ''; }
2018
- }
2019
- }
2020
- else { $lookaheadGlyphs = array(); }
2021
-
2022
- // Class 0 contains all the glyphs NOT in the other classes
2023
- $lclass0excl = array();
2024
- for ($gc=1;$gc<=count($LookaheadClasses);$gc++) {
2025
- if (isset($LookaheadClasses[$gc])) $lclass0excl = $lclass0excl + $LookaheadClasses[$gc];
2026
- }
2027
-
2028
-
2029
- $matched = $this->checkContextMatchMultipleUni($inputGlyphs, $backtrackGlyphs, $lookaheadGlyphs, $ignore, $ptr, $class0excl, $bclass0excl, $lclass0excl );
2030
- if ($matched) {
2031
- if ($this->debugOTL) { $this->_dumpproc('GSUB', $lookupID, $subtable, $Type, $SubstFormat, $ptr, $currGlyph, $level); }
2032
- $SubstCount = $this->read_ushort();
2033
- for ($p=0;$p<$SubstCount;$p++) { // EACH LOOKUP
2034
- $SequenceIndex[$p] = $this->read_ushort();
2035
- $LookupListIndex[$p] = $this->read_ushort();
2036
- }
2037
-
2038
- for ($p=0;$p<$SubstCount;$p++) {
2039
- // Apply $LookupListIndex at $SequenceIndex
2040
- if ($SequenceIndex[$p] >= $InputGlyphCount) { continue; }
2041
- $lu = $LookupListIndex[$p];
2042
- $luType = $this->GSUBLookups[$lu]['Type'];
2043
- $luFlag = $this->GSUBLookups[$lu]['Flag'];
2044
- $luMarkFilteringSet = $this->GSUBLookups[$lu]['MarkFilteringSet'];
2045
-
2046
- $luptr = $matched[$SequenceIndex[$p]];
2047
- $lucurrGlyph = $this->OTLdata[$luptr]['hex'];
2048
- $lucurrGID = $this->OTLdata[$luptr]['uni'];
2049
-
2050
- foreach($this->GSUBLookups[$lu]['Subtables'] AS $luc=>$lusubtable_offset) {
2051
- $shift = $this->_applyGSUBsubtable($lu, $luc, $luptr, $lucurrGlyph, $lucurrGID, ($lusubtable_offset - $this->GSUB_offset) , $luType, $luFlag, $luMarkFilteringSet, $this->GSLuCoverage[$lu][$luc], 1, $currentTag, $is_old_spec, $tagInt);
2052
- if ($shift) { break; }
2053
- }
2054
- }
2055
-
2056
- if (!defined("OMIT_OTL_FIX_3") || OMIT_OTL_FIX_3 != 1) { return $shift ; } /* OTL_FIX_3 */
2057
- else return $InputGlyphCount ; // should be + matched ignores in Input Sequence
2058
-
2059
- }
2060
-
2061
- }
2062
-
2063
- }
2064
- }
2065
-
2066
- return 0;
2067
- }
2068
-
2069
- //===========
2070
- // Format 3:
2071
- //===========
2072
- // Format 3: Coverage-based Chaining Context Glyph Substitution p259
2073
- else if ($SubstFormat==3) {
2074
-
2075
- $BacktrackGlyphCount = $this->read_ushort();
2076
- for ($b=0;$b<$BacktrackGlyphCount;$b++) {
2077
- $CoverageBacktrackOffset[] = $subtable_offset + $this->read_ushort(); // in glyph sequence order
2078
- }
2079
- $InputGlyphCount = $this->read_ushort();
2080
- for ($b=0;$b<$InputGlyphCount;$b++) {
2081
- $CoverageInputOffset[] = $subtable_offset + $this->read_ushort(); // in glyph sequence order
2082
- }
2083
- $LookaheadGlyphCount = $this->read_ushort();
2084
- for ($b=0;$b<$LookaheadGlyphCount;$b++) {
2085
- $CoverageLookaheadOffset[] = $subtable_offset + $this->read_ushort(); // in glyph sequence order
2086
- }
2087
- $SubstCount = $this->read_ushort();
2088
- $save_pos = $this->_pos; // Save the point just after PosCount
2089
-
2090
- $CoverageBacktrackGlyphs = array();
2091
- for ($b=0;$b<$BacktrackGlyphCount;$b++) {
2092
- $this->seek($CoverageBacktrackOffset[$b]);
2093
- $glyphs = $this->_getCoverage();
2094
- $CoverageBacktrackGlyphs[$b] = implode("|",$glyphs);
2095
- }
2096
- $CoverageInputGlyphs = array();
2097
- for ($b=0;$b<$InputGlyphCount;$b++) {
2098
- $this->seek($CoverageInputOffset[$b]);
2099
- $glyphs = $this->_getCoverage();
2100
- $CoverageInputGlyphs[$b] = implode("|",$glyphs);
2101
- }
2102
- $CoverageLookaheadGlyphs = array();
2103
- for ($b=0;$b<$LookaheadGlyphCount;$b++) {
2104
- $this->seek($CoverageLookaheadOffset[$b]);
2105
- $glyphs = $this->_getCoverage();
2106
- $CoverageLookaheadGlyphs[$b] = implode("|",$glyphs);
2107
- }
2108
-
2109
- $matched = $this->checkContextMatchMultiple($CoverageInputGlyphs, $CoverageBacktrackGlyphs, $CoverageLookaheadGlyphs , $ignore, $ptr);
2110
- if ($matched) {
2111
- if ($this->debugOTL) { $this->_dumpproc('GSUB', $lookupID, $subtable, $Type, $SubstFormat, $ptr, $currGlyph, $level); }
2112
-
2113
- $this->seek($save_pos); // Return to just after PosCount
2114
- for ($p=0;$p<$SubstCount;$p++) {
2115
- // SubstLookupRecord
2116
- $SubstLookupRecord[$p]['SequenceIndex'] = $this->read_ushort();
2117
- $SubstLookupRecord[$p]['LookupListIndex'] = $this->read_ushort();
2118
- }
2119
- for ($p=0;$p<$SubstCount;$p++) {
2120
- // Apply $SubstLookupRecord[$p]['LookupListIndex'] at $SubstLookupRecord[$p]['SequenceIndex']
2121
- if ($SubstLookupRecord[$p]['SequenceIndex'] >= $InputGlyphCount) { continue; }
2122
- $lu = $SubstLookupRecord[$p]['LookupListIndex'];
2123
- $luType = $this->GSUBLookups[$lu]['Type'];
2124
- $luFlag = $this->GSUBLookups[$lu]['Flag'];
2125
- $luMarkFilteringSet = $this->GSUBLookups[$lu]['MarkFilteringSet'];
2126
-
2127
- $luptr = $matched[$SubstLookupRecord[$p]['SequenceIndex']];
2128
- $lucurrGlyph = $this->OTLdata[$luptr]['hex'];
2129
- $lucurrGID = $this->OTLdata[$luptr]['uni'];
2130
-
2131
- foreach($this->GSUBLookups[$lu]['Subtables'] AS $luc=>$lusubtable_offset) {
2132
- $shift = $this->_applyGSUBsubtable($lu, $luc, $luptr, $lucurrGlyph, $lucurrGID, ($lusubtable_offset - $this->GSUB_offset), $luType, $luFlag, $luMarkFilteringSet, $this->GSLuCoverage[$lu][$luc], 1, $currentTag, $is_old_spec, $tagInt);
2133
- if ($shift) { break; }
2134
- }
2135
- }
2136
- if (!defined("OMIT_OTL_FIX_3") || OMIT_OTL_FIX_3 != 1) { return (isset($shift) ? $shift : 0) ; } /* OTL_FIX_3 */
2137
- else return $InputGlyphCount ; // should be + matched ignores in Input Sequence
2138
- }
2139
-
2140
- return 0;
2141
-
2142
- }
2143
- }
2144
-
2145
- else { die("GSUB Lookup Type ".$Type." not supported."); }
2146
-
2147
- }
2148
-
2149
- function _updateLigatureMarks($pos, $n) {
2150
- if ($n > 0) {
2151
- // Update position of Ligatures and associated Marks
2152
- // Foreach lig/assocMarks
2153
- // Any position lpos or mpos > $pos + count($substitute)
2154
- // $this->assocMarks = array(); // assocMarks[$pos mpos] => array(compID, ligPos)
2155
- // $this->assocLigs = array(); // Ligatures[$pos lpos] => nc
2156
- for ($p=count($this->OTLdata)-1;$p>=($pos+$n);$p--) {
2157
- if (isset($this->assocLigs[$p])) {
2158
- $tmp = $this->assocLigs[$p];
2159
- unset($this->assocLigs[$p]);
2160
- $this->assocLigs[($p + $n)] = $tmp;
2161
- }
2162
- }
2163
- for ($p=count($this->OTLdata)-1;$p>=0;$p--) {
2164
- if (isset($this->assocMarks[$p])) {
2165
- if ($this->assocMarks[$p]['ligPos'] >=($pos+$n)) { $this->assocMarks[$p]['ligPos'] += $n; }
2166
- if ($p>=($pos+$n)) {
2167
- $tmp = $this->assocMarks[$p];
2168
- unset($this->assocMarks[$p]);
2169
- $this->assocMarks[($p + $n)] = $tmp;
2170
- }
2171
- }
2172
- }
2173
- }
2174
-
2175
- else if ($n<1) { // glyphs removed
2176
- $nrem = -$n;
2177
- // Update position of pre-existing Ligatures and associated Marks
2178
- for ($p=($pos+1);$p<count($this->OTLdata);$p++) {
2179
- if (isset($this->assocLigs[$p])) {
2180
- $tmp = $this->assocLigs[$p];
2181
- unset($this->assocLigs[$p]);
2182
- $this->assocLigs[($p - $nrem)] = $tmp;
2183
- }
2184
- }
2185
- for ($p=0;$p<count($this->OTLdata);$p++) {
2186
- if (isset($this->assocMarks[$p])) {
2187
- if ($this->assocMarks[$p]['ligPos'] >=($pos)) { $this->assocMarks[$p]['ligPos'] -= $nrem; }
2188
- if ($p>$pos) {
2189
- $tmp = $this->assocMarks[$p];
2190
- unset($this->assocMarks[$p]);
2191
- $this->assocMarks[($p - $nrem)] = $tmp;
2192
- }
2193
- }
2194
- }
2195
- }
2196
- }
2197
-
2198
- function GSUBsubstitute($pos, $substitute, $Type, $GlyphPos=NULL ) {
2199
-
2200
- // LookupType 1: Simple Substitution Subtable : 1 to 1
2201
- // LookupType 3: Alternate Forms : 1 to 1(n)
2202
- if ($Type == 1 || $Type == 3) {
2203
- $this->OTLdata[$pos]['uni'] = $substitute;
2204
- $this->OTLdata[$pos]['hex'] = $this->unicode_hex($substitute);
2205
- return 1;
2206
- }
2207
- // LookupType 2: Multiple Substitution Subtable : 1 to n
2208
- else if ($Type == 2) {
2209
- for($i=0;$i<count($substitute);$i++) {
2210
- $uni = $substitute[$i];
2211
- $newOTLdata[$i] = array();
2212
- $newOTLdata[$i]['uni'] = $uni;
2213
- $newOTLdata[$i]['hex'] = $this->unicode_hex($uni);
2214
-
2215
-
2216
- // Get types of new inserted chars - or replicate type of char being replaced
2217
- // $bt = UCDN::get_bidi_class($uni);
2218
- // if (!$bt) {
2219
- $bt = $this->OTLdata[$pos]['bidi_type'];
2220
- // }
2221
-
2222
- if (strpos($this->GlyphClassMarks, $newOTLdata[$i]['hex'] )!==false) { $gp = 'M'; }
2223
- else if ($uni == 32) { $gp = 'S'; }
2224
- else { $gp = 'C'; }
2225
-
2226
- // Need to update matra_type ??? of new glyphs inserted ???????????????????????????????????????
2227
-
2228
- $newOTLdata[$i]['bidi_type'] = $bt;
2229
- $newOTLdata[$i]['group'] = $gp;
2230
-
2231
- // Need to update details of new glyphs inserted
2232
- $newOTLdata[$i]['general_category'] = $this->OTLdata[$pos]['general_category'];
2233
-
2234
- if ($this->shaper=='I' || $this->shaper=='K' || $this->shaper=='S') {
2235
- $newOTLdata[$i]['indic_category'] = $this->OTLdata[$pos]['indic_category'];
2236
- $newOTLdata[$i]['indic_position'] = $this->OTLdata[$pos]['indic_position'];
2237
- }
2238
- else if ($this->shaper=='M') {
2239
- $newOTLdata[$i]['myanmar_category'] = $this->OTLdata[$pos]['myanmar_category'];
2240
- $newOTLdata[$i]['myanmar_position'] = $this->OTLdata[$pos]['myanmar_position'];
2241
- }
2242
- if (isset($this->OTLdata[$pos]['mask'])) { $newOTLdata[$i]['mask'] = $this->OTLdata[$pos]['mask']; }
2243
- if (isset($this->OTLdata[$pos]['syllable'])) { $newOTLdata[$i]['syllable'] = $this->OTLdata[$pos]['syllable']; }
2244
-
2245
- }
2246
- if ($this->shaper=='K' || $this->shaper=='T' || $this->shaper=='L') {
2247
- if ($this->OTLdata[$pos]['wordend']) { $newOTLdata[count($substitute)-1]['wordend'] = true; }
2248
- }
2249
-
2250
- array_splice($this->OTLdata, $pos, 1, $newOTLdata); // Replace 1 with n
2251
- // Update position of Ligatures and associated Marks
2252
- // count($substitute)-1 is the number of glyphs added
2253
- $nadd = count($substitute)-1;
2254
- $this->_updateLigatureMarks($pos, $nadd);
2255
- return count($substitute);
2256
- }
2257
- // LookupType 4: Ligature Substitution Subtable : n to 1
2258
- else if ($Type == 4) {
2259
- // Create Ligatures and associated Marks
2260
- $firstGlyph = $this->OTLdata[$pos]['hex'];
2261
-
2262
- // If all components of the ligature are marks (and in the same syllable), we call this a mark ligature.
2263
- $contains_marks = false;
2264
- $contains_nonmarks = false;
2265
- if (isset($this->OTLdata[$pos]['syllable'])) { $current_syllable = $this->OTLdata[$pos]['syllable']; }
2266
- else { $current_syllable = 0; }
2267
- for($i=0;$i<count($GlyphPos);$i++) {
2268
- // If subsequent components are not Marks as well - don't ligate
2269
- $unistr = $this->OTLdata[$GlyphPos[$i]]['hex'];
2270
- if ($this->restrictToSyllable && isset($this->OTLdata[$GlyphPos[$i]]['syllable']) && $this->OTLdata[$GlyphPos[$i]]['syllable'] != $current_syllable) {
2271
- return 0;
2272
- }
2273
- if (strpos($this->GlyphClassMarks, $unistr )!==false) { $contains_marks = true; }
2274
- else { $contains_nonmarks = true; }
2275
- }
2276
- if ($contains_marks && !$contains_nonmarks) {
2277
- // Mark Ligature (all components are Marks)
2278
- $firstMarkAssoc = '';
2279
- if (isset($this->assocMarks[$pos])) {
2280
- $firstMarkAssoc = $this->assocMarks[$pos];
2281
- }
2282
- // If all components of the ligature are marks, we call this a mark ligature.
2283
- for($i=1;$i<count($GlyphPos);$i++) {
2284
-
2285
- // If subsequent components are not Marks as well - don't ligate
2286
- // $unistr = $this->OTLdata[$GlyphPos[$i]]['hex'];
2287
- // if (strpos($this->GlyphClassMarks, $unistr )===false) { return; }
2288
-
2289
- $nextMarkAssoc = '';
2290
- if (isset($this->assocMarks[$GlyphPos[$i]])) {
2291
- $nextMarkAssoc = $this->assocMarks[$GlyphPos[$i]];
2292
- }
2293
- // If first component was attached to a previous ligature component,
2294
- // all subsequent components should be attached to the same ligature
2295
- // component, otherwise we shouldn't ligate them.
2296
- // If first component was NOT attached to a previous ligature component,
2297
- // all subsequent components should also NOT be attached to any ligature component,
2298
- if ($firstMarkAssoc != $nextMarkAssoc ) {
2299
- // unless they are attached to the first component itself!
2300
- // if (!is_array($nextMarkAssoc) || $nextMarkAssoc['ligPos']!= $pos) { return; }
2301
-
2302
- // Update/Edit - In test with myanmartext font
2303
- // &#x1004;&#x103a;&#x1039;&#x1000;&#x1039;&#x1000;&#x103b;&#x103c;&#x103d;&#x1031;&#x102d;
2304
- // => Lookup 17 E003 E066B E05A 102D
2305
- // E003 and 102D should form a mark ligature, but 102D is already associated with (non-mark) ligature E05A
2306
- // So instead of disallowing the mark ligature to form, just dissociate...
2307
- if (!is_array($nextMarkAssoc) || $nextMarkAssoc['ligPos']!= $pos) { unset($this->assocMarks[$GlyphPos[$i]]); }
2308
- }
2309
- }
2310
-
2311
- /*
2312
- * - If it *is* a mark ligature, we don't allocate a new ligature id, and leave
2313
- * the ligature to keep its old ligature id. This will allow it to attach to
2314
- * a base ligature in GPOS. Eg. if the sequence is: LAM,LAM,SHADDA,FATHA,HEH,
2315
- * and LAM,LAM,HEH form a ligature, they will leave SHADDA and FATHA wit a
2316
- * ligature id and component value of 2. Then if SHADDA,FATHA form a ligature
2317
- * later, we don't want them to lose their ligature id/component, otherwise
2318
- * GPOS will fail to correctly position the mark ligature on top of the
2319
- * LAM,LAM,HEH ligature.
2320
- */
2321
- // So if is_array($firstMarkAssoc) - the new (Mark) ligature should keep this association
2322
-
2323
- $lastPos = $GlyphPos[(count($GlyphPos)-1)];
2324
- }
2325
- else {
2326
- /*
2327
- * - Ligatures cannot be formed across glyphs attached to different components
2328
- * of previous ligatures. Eg. the sequence is LAM,SHADDA,LAM,FATHA,HEH, and
2329
- * LAM,LAM,HEH form a ligature, leaving SHADDA,FATHA next to eachother.
2330
- * However, it would be wrong to ligate that SHADDA,FATHA sequence.
2331
- * There is an exception to this: If a ligature tries ligating with marks that
2332
- * belong to it itself, go ahead, assuming that the font designer knows what
2333
- * they are doing (otherwise it can break Indic stuff when a matra wants to
2334
- * ligate with a conjunct...)
2335
- */
2336
-
2337
- /*
2338
- * - If a ligature is formed of components that some of which are also ligatures
2339
- * themselves, and those ligature components had marks attached to *their*
2340
- * components, we have to attach the marks to the new ligature component
2341
- * positions! Now *that*'s tricky! And these marks may be following the
2342
- * last component of the whole sequence, so we should loop forward looking
2343
- * for them and update them.
2344
- *
2345
- * Eg. the sequence is LAM,LAM,SHADDA,FATHA,HEH, and the font first forms a
2346
- * 'calt' ligature of LAM,HEH, leaving the SHADDA and FATHA with a ligature
2347
- * id and component == 1. Now, during 'liga', the LAM and the LAM-HEH ligature
2348
- * form a LAM-LAM-HEH ligature. We need to reassign the SHADDA and FATHA to
2349
- * the new ligature with a component value of 2.
2350
- *
2351
- * This in fact happened to a font... See:
2352
- * https://bugzilla.gnome.org/show_bug.cgi?id=437633
2353
- */
2354
-
2355
- $currComp = 0;
2356
- for($i=0;$i<count($GlyphPos);$i++) {
2357
- if ($i>0 && isset($this->assocLigs[$GlyphPos[$i]])) { // One of the other components is already a ligature
2358
- $nc = $this->assocLigs[$GlyphPos[$i]];
2359
- }
2360
- else { $nc = 1; }
2361
- // While next char to right is a mark (but not the next matched glyph)
2362
- // ?? + also include a Mark Ligature here
2363
- $ic = 1;
2364
- while((($i==count($GlyphPos)-1) || (isset($GlyphPos[$i+1]) && ($GlyphPos[$i]+$ic) < $GlyphPos[$i+1])) && isset($this->OTLdata[($GlyphPos[$i]+$ic)]) && strpos($this->GlyphClassMarks, $this->OTLdata[($GlyphPos[$i]+$ic)]['hex'])!== false) {
2365
- $newComp = $currComp;
2366
- if (isset($this->assocMarks[$GlyphPos[$i]+$ic])) { // One of the inbetween Marks is already associated with a Lig
2367
- // OK as long as it is associated with the current Lig
2368
- // if ($this->assocMarks[($GlyphPos[$i]+$ic)]['ligPos'] != ($GlyphPos[$i]+$ic)) { die("Problem #1"); }
2369
- $newComp += $this->assocMarks[($GlyphPos[$i]+$ic)]['compID'];
2370
- }
2371
- $this->assocMarks[($GlyphPos[$i]+$ic)] = array('compID'=>$newComp, 'ligPos'=>$pos);
2372
- $ic++;
2373
- }
2374
- $currComp += $nc;
2375
- }
2376
- $lastPos = $GlyphPos[(count($GlyphPos)-1)]+$ic-1;
2377
- $this->assocLigs[$pos] = $currComp ; // Number of components in new Ligature
2378
- }
2379
-
2380
- // Now remove the unwanted glyphs and associated metadata
2381
- $newOTLdata[0] = array();
2382
-
2383
- // Get types of new inserted chars - or replicate type of char being replaced
2384
- // $bt = UCDN::get_bidi_class($substitute);
2385
- // if (!$bt) {
2386
- $bt = $this->OTLdata[$pos]['bidi_type'];
2387
- // }
2388
-
2389
- if (strpos($this->GlyphClassMarks, $this->unicode_hex($substitute))!==false) { $gp = 'M'; }
2390
- else if ($substitute == 32) { $gp = 'S'; }
2391
- else { $gp = 'C'; }
2392
-
2393
- // Need to update details of new glyphs inserted
2394
- $newOTLdata[0]['general_category'] = $this->OTLdata[$pos]['general_category'];
2395
-
2396
- $newOTLdata[0]['bidi_type'] = $bt;
2397
- $newOTLdata[0]['group'] = $gp;
2398
-
2399
- // KASHIDA: If forming a ligature when the last component was identified as a kashida point (final form)
2400
- // If previous/first component of ligature is a medial form, then keep this as a kashida point
2401
- // TEST (Arabic Typesetting) &#x64a;&#x64e;&#x646;&#x62a;&#x64f;&#x645;
2402
- $ka = 0;
2403
- if (isset($this->OTLdata[$GlyphPos[(count($GlyphPos)-1)]]['GPOSinfo']['kashida'])) {
2404
- $ka = $this->OTLdata[$GlyphPos[(count($GlyphPos)-1)]]['GPOSinfo']['kashida'];
2405
- }
2406
- if ($ka==1 && isset($this->OTLdata[$pos]['form']) && $this->OTLdata[$pos]['form']==3) { $newOTLdata[0]['GPOSinfo']['kashida'] = $ka; }
2407
-
2408
- $newOTLdata[0]['uni'] = $substitute;
2409
- $newOTLdata[0]['hex'] = $this->unicode_hex($substitute);
2410
-
2411
- if ($this->shaper=='I' || $this->shaper=='K' || $this->shaper=='S') {
2412
- $newOTLdata[0]['indic_category'] = $this->OTLdata[$pos]['indic_category'];
2413
- $newOTLdata[0]['indic_position'] = $this->OTLdata[$pos]['indic_position'];
2414
- }
2415
- else if ($this->shaper=='M') {
2416
- $newOTLdata[0]['myanmar_category'] = $this->OTLdata[$pos]['myanmar_category'];
2417
- $newOTLdata[0]['myanmar_position'] = $this->OTLdata[$pos]['myanmar_position'];
2418
- }
2419
- if (isset($this->OTLdata[$pos]['mask'])) {$newOTLdata[0]['mask'] = $this->OTLdata[$pos]['mask']; }
2420
- if (isset($this->OTLdata[$pos]['syllable'])) {$newOTLdata[0]['syllable'] = $this->OTLdata[$pos]['syllable']; }
2421
-
2422
- $newOTLdata[0]['is_ligature'] = true;
2423
-
2424
-
2425
- array_splice($this->OTLdata, $pos, 1, $newOTLdata);
2426
-
2427
- // GlyphPos contains array of arr_pos to set null - not necessarily contiguous
2428
-
2429
- // +- Remove any assocMarks or assocLigs from the main components (the ones that are deleted)
2430
- for($i=count($GlyphPos)-1;$i>0;$i--) {
2431
- $gpos = $GlyphPos[$i];
2432
- array_splice($this->OTLdata, $gpos, 1);
2433
- unset($this->assocLigs[$gpos]);
2434
- unset($this->assocMarks[$gpos]);
2435
- }
2436
- // $this->assocLigs = array(); // Ligatures[$posarr lpos] => nc
2437
- // $this->assocMarks = array(); // assocMarks[$posarr mpos] => array(compID, ligPos)
2438
-
2439
- // Update position of pre-existing Ligatures and associated Marks
2440
- // Start after first GlyphPos
2441
- // count($GlyphPos)-1 is the number of glyphs removed from string
2442
- for($p=($GlyphPos[0]+1);$p<(count($this->OTLdata)+count($GlyphPos)-1) ;$p++ ) {
2443
- $nrem = 0; // Number of Glyphs removed at this point in the string
2444
- for($i=0;$i<count($GlyphPos);$i++) {
2445
- if ($i>0 && $p > $GlyphPos[$i]) { $nrem++; }
2446
- }
2447
- if (isset($this->assocLigs[$p])) {
2448
- $tmp = $this->assocLigs[$p];
2449
- unset($this->assocLigs[$p]);
2450
- $this->assocLigs[($p - $nrem)] = $tmp;
2451
- }
2452
- if (isset($this->assocMarks[$p])) {
2453
- $tmp = $this->assocMarks[$p];
2454
- unset($this->assocMarks[$p]);
2455
- if ($tmp['ligPos'] > $GlyphPos[0]) { $tmp['ligPos'] -= $nrem; }
2456
- $this->assocMarks[($p - $nrem)] = $tmp;
2457
- }
2458
- }
2459
- return 1;
2460
- }
2461
- else { return 0; }
2462
- }
2463
-
2464
-
2465
-
2466
- ////////////////////////////////////////////////////////////////
2467
- ////////////////////////////////////////////////////////////////
2468
- ////////// ARABIC /////////////////////////////////
2469
- ////////////////////////////////////////////////////////////////
2470
- ////////////////////////////////////////////////////////////////
2471
-
2472
- function arabic_initialise() {
2473
- // cf. http://unicode.org/Public/UNIDATA/ArabicShaping.txt
2474
- // http://unicode.org/Public/UNIDATA/extracted/DerivedJoiningType.txt
2475
- // JOIN TO FOLLOWING LETTER IN LOGICAL ORDER (i.e. AS INITIAL/MEDIAL FORM) = Unicode Left-Joining (+ Dual-Joining + Join_Causing 00640)
2476
- $this->arabLeftJoining = array(
2477
- 0x0620=>1, 0x0626=>1, 0x0628=>1, 0x062A=>1, 0x062B=>1, 0x062C=>1, 0x062D=>1, 0x062E=>1,
2478
- 0x0633=>1, 0x0634=>1, 0x0635=>1, 0x0636=>1, 0x0637=>1, 0x0638=>1, 0x0639=>1, 0x063A=>1,
2479
- 0x063B=>1, 0x063C=>1, 0x063D=>1, 0x063E=>1, 0x063F=>1, 0x0640=>1, 0x0641=>1, 0x0642=>1,
2480
- 0x0643=>1, 0x0644=>1, 0x0645=>1, 0x0646=>1, 0x0647=>1, 0x0649=>1, 0x064A=>1, 0x066E=>1,
2481
- 0x066F=>1, 0x0678=>1, 0x0679=>1, 0x067A=>1, 0x067B=>1, 0x067C=>1, 0x067D=>1, 0x067E=>1,
2482
- 0x067F=>1, 0x0680=>1, 0x0681=>1, 0x0682=>1, 0x0683=>1, 0x0684=>1, 0x0685=>1, 0x0686=>1,
2483
- 0x0687=>1, 0x069A=>1, 0x069B=>1, 0x069C=>1, 0x069D=>1, 0x069E=>1, 0x069F=>1, 0x06A0=>1,
2484
- 0x06A1=>1, 0x06A2=>1, 0x06A3=>1, 0x06A4=>1, 0x06A5=>1, 0x06A6=>1, 0x06A7=>1, 0x06A8=>1,
2485
- 0x06A9=>1, 0x06AA=>1, 0x06AB=>1, 0x06AC=>1, 0x06AD=>1, 0x06AE=>1, 0x06AF=>1, 0x06B0=>1,
2486
- 0x06B1=>1, 0x06B2=>1, 0x06B3=>1, 0x06B4=>1, 0x06B5=>1, 0x06B6=>1, 0x06B7=>1, 0x06B8=>1,
2487
- 0x06B9=>1, 0x06BA=>1, 0x06BB=>1, 0x06BC=>1, 0x06BD=>1, 0x06BE=>1, 0x06BF=>1, 0x06C1=>1,
2488
- 0x06C2=>1, 0x06CC=>1, 0x06CE=>1, 0x06D0=>1, 0x06D1=>1, 0x06FA=>1, 0x06FB=>1, 0x06FC=>1,
2489
- 0x06FF=>1,
2490
- /* Arabic Supplement */
2491
- 0x0750=>1, 0x0751=>1, 0x0752=>1, 0x0753=>1, 0x0754=>1, 0x0755=>1, 0x0756=>1, 0x0757=>1,
2492
- 0x0758=>1, 0x075C=>1, 0x075D=>1, 0x075E=>1, 0x075F=>1, 0x0760=>1, 0x0761=>1, 0x0762=>1,
2493
- 0x0763=>1, 0x0764=>1, 0x0765=>1, 0x0766=>1, 0x0767=>1, 0x0768=>1, 0x0769=>1, 0x076A=>1,
2494
- 0x076D=>1, 0x076E=>1, 0x076F=>1, 0x0770=>1, 0x0772=>1, 0x0775=>1, 0x0776=>1, 0x0777=>1,
2495
- 0x077A=>1, 0x077B=>1, 0x077C=>1, 0x077D=>1, 0x077E=>1, 0x077F=>1,
2496
- /* Extended Arabic */
2497
- 0x08A0=>1, 0x08A2=>1, 0x08A3=>1, 0x08A4=>1, 0x08A5=>1, 0x08A6=>1, 0x08A7=>1, 0x08A8=>1,
2498
- 0x08A9=>1,
2499
- /* 'syrc' Syriac */
2500
- 0x0712=>1, 0x0713=>1, 0x0714=>1, 0x071A=>1, 0x071B=>1, 0x071C=>1, 0x071D=>1, 0x071F=>1,
2501
- 0x0720=>1, 0x0721=>1, 0x0722=>1, 0x0723=>1, 0x0724=>1, 0x0725=>1, 0x0726=>1, 0x0727=>1,
2502
- 0x0729=>1, 0x072B=>1, 0x072D=>1, 0x072E=>1, 0x074E=>1, 0x074F=>1,
2503
- /* N'Ko */
2504
- 0x07CA=>1, 0x07CB=>1, 0x07CC=>1, 0x07CD=>1, 0x07CE=>1, 0x07CF=>1, 0x07D0=>1, 0x07D1=>1,
2505
- 0x07D2=>1, 0x07D3=>1, 0x07D4=>1, 0x07D5=>1, 0x07D6=>1, 0x07D7=>1, 0x07D8=>1, 0x07D9=>1,
2506
- 0x07DA=>1, 0x07DB=>1, 0x07DC=>1, 0x07DD=>1, 0x07DE=>1, 0x07DF=>1, 0x07E0=>1, 0x07E1=>1,
2507
- 0x07E2=>1, 0x07E3=>1, 0x07E4=>1, 0x07E5=>1, 0x07E6=>1, 0x07E7=>1, 0x07E8=>1, 0x07E9=>1,
2508
- 0x07EA=>1, 0x07FA=>1,
2509
- /* Mandaic */
2510
- 0x0841=>1, 0x0842=>1, 0x0843=>1, 0x0844=>1, 0x0845=>1, 0x0847=>1, 0x0848=>1, 0x084A=>1,
2511
- 0x084B=>1, 0x084C=>1, 0x084D=>1, 0x084E=>1, 0x0850=>1, 0x0851=>1, 0x0852=>1, 0x0853=>1,
2512
- 0x0855=>1,
2513
- /* ZWJ U+200D */
2514
- 0x0200D=>1);
2515
-
2516
- /* JOIN TO PREVIOUS LETTER IN LOGICAL ORDER (i.e. AS FINAL/MEDIAL FORM) = Unicode Right-Joining (+ Dual-Joining + Join_Causing) */
2517
- $this->arabRightJoining = array(
2518
- 0x0620=>1, 0x0622=>1, 0x0623=>1, 0x0624=>1, 0x0625=>1, 0x0626=>1, 0x0627=>1, 0x0628=>1,
2519
- 0x0629=>1, 0x062A=>1, 0x062B=>1, 0x062C=>1, 0x062D=>1, 0x062E=>1, 0x062F=>1, 0x0630=>1,
2520
- 0x0631=>1, 0x0632=>1, 0x0633=>1, 0x0634=>1, 0x0635=>1, 0x0636=>1, 0x0637=>1, 0x0638=>1,
2521
- 0x0639=>1, 0x063A=>1, 0x063B=>1, 0x063C=>1, 0x063D=>1, 0x063E=>1, 0x063F=>1, 0x0640=>1,
2522
- 0x0641=>1, 0x0642=>1, 0x0643=>1, 0x0644=>1, 0x0645=>1, 0x0646=>1, 0x0647=>1, 0x0648=>1,
2523
- 0x0649=>1, 0x064A=>1, 0x066E=>1, 0x066F=>1, 0x0671=>1, 0x0672=>1, 0x0673=>1, 0x0675=>1,
2524
- 0x0676=>1, 0x0677=>1, 0x0678=>1, 0x0679=>1, 0x067A=>1, 0x067B=>1, 0x067C=>1, 0x067D=>1,
2525
- 0x067E=>1, 0x067F=>1, 0x0680=>1, 0x0681=>1, 0x0682=>1, 0x0683=>1, 0x0684=>1, 0x0685=>1,
2526
- 0x0686=>1, 0x0687=>1, 0x0688=>1, 0x0689=>1, 0x068A=>1, 0x068B=>1, 0x068C=>1, 0x068D=>1,
2527
- 0x068E=>1, 0x068F=>1, 0x0690=>1, 0x0691=>1, 0x0692=>1, 0x0693=>1, 0x0694=>1, 0x0695=>1,
2528
- 0x0696=>1, 0x0697=>1, 0x0698=>1, 0x0699=>1, 0x069A=>1, 0x069B=>1, 0x069C=>1, 0x069D=>1,
2529
- 0x069E=>1, 0x069F=>1, 0x06A0=>1, 0x06A1=>1, 0x06A2=>1, 0x06A3=>1, 0x06A4=>1, 0x06A5=>1,
2530
- 0x06A6=>1, 0x06A7=>1, 0x06A8=>1, 0x06A9=>1, 0x06AA=>1, 0x06AB=>1, 0x06AC=>1, 0x06AD=>1,
2531
- 0x06AE=>1, 0x06AF=>1, 0x06B0=>1, 0x06B1=>1, 0x06B2=>1, 0x06B3=>1, 0x06B4=>1, 0x06B5=>1,
2532
- 0x06B6=>1, 0x06B7=>1, 0x06B8=>1, 0x06B9=>1, 0x06BA=>1, 0x06BB=>1, 0x06BC=>1, 0x06BD=>1,
2533
- 0x06BE=>1, 0x06BF=>1, 0x06C0=>1, 0x06C1=>1, 0x06C2=>1, 0x06C3=>1, 0x06C4=>1, 0x06C5=>1,
2534
- 0x06C6=>1, 0x06C7=>1, 0x06C8=>1, 0x06C9=>1, 0x06CA=>1, 0x06CB=>1, 0x06CC=>1, 0x06CD=>1,
2535
- 0x06CE=>1, 0x06CF=>1, 0x06D0=>1, 0x06D1=>1, 0x06D2=>1, 0x06D3=>1, 0x06D5=>1, 0x06EE=>1,
2536
- 0x06EF=>1, 0x06FA=>1, 0x06FB=>1, 0x06FC=>1, 0x06FF=>1,
2537
- /* Arabic Supplement */
2538
- 0x0750=>1, 0x0751=>1, 0x0752=>1, 0x0753=>1, 0x0754=>1, 0x0755=>1, 0x0756=>1, 0x0757=>1,
2539
- 0x0758=>1, 0x0759=>1, 0x075A=>1, 0x075B=>1, 0x075C=>1, 0x075D=>1, 0x075E=>1, 0x075F=>1,
2540
- 0x0760=>1, 0x0761=>1, 0x0762=>1, 0x0763=>1, 0x0764=>1, 0x0765=>1, 0x0766=>1, 0x0767=>1,
2541
- 0x0768=>1, 0x0769=>1, 0x076A=>1, 0x076B=>1, 0x076C=>1, 0x076D=>1, 0x076E=>1, 0x076F=>1,
2542
- 0x0770=>1, 0x0771=>1, 0x0772=>1, 0x0773=>1, 0x0774=>1, 0x0775=>1, 0x0776=>1, 0x0777=>1,
2543
- 0x0778=>1, 0x0779=>1, 0x077A=>1, 0x077B=>1, 0x077C=>1, 0x077D=>1, 0x077E=>1, 0x077F=>1,
2544
- /* Extended Arabic */
2545
- 0x08A0=>1, 0x08A2=>1, 0x08A3=>1, 0x08A4=>1, 0x08A5=>1, 0x08A6=>1, 0x08A7=>1, 0x08A8=>1,
2546
- 0x08A9=>1, 0x08AA=>1, 0x08AB=>1, 0x08AC=>1,
2547
- /* 'syrc' Syriac */
2548
- 0x0710=>1, 0x0712=>1, 0x0713=>1, 0x0714=>1, 0x0715=>1, 0x0716=>1, 0x0717=>1, 0x0718=>1,
2549
- 0x0719=>1, 0x071A=>1, 0x071B=>1, 0x071C=>1, 0x071D=>1, 0x071E=>1, 0x071F=>1, 0x0720=>1,
2550
- 0x0721=>1, 0x0722=>1, 0x0723=>1, 0x0724=>1, 0x0725=>1, 0x0726=>1, 0x0727=>1, 0x0728=>1,
2551
- 0x0729=>1, 0x072A=>1, 0x072B=>1, 0x072C=>1, 0x072D=>1, 0x072E=>1, 0x072F=>1, 0x074D=>1,
2552
- 0x074E=>1, 0x074F,
2553
- /* N'Ko */
2554
- 0x07CA=>1, 0x07CB=>1, 0x07CC=>1, 0x07CD=>1, 0x07CE=>1, 0x07CF=>1, 0x07D0=>1, 0x07D1=>1,
2555
- 0x07D2=>1, 0x07D3=>1, 0x07D4=>1, 0x07D5=>1, 0x07D6=>1, 0x07D7=>1, 0x07D8=>1, 0x07D9=>1,
2556
- 0x07DA=>1, 0x07DB=>1, 0x07DC=>1, 0x07DD=>1, 0x07DE=>1, 0x07DF=>1, 0x07E0=>1, 0x07E1=>1,
2557
- 0x07E2=>1, 0x07E3=>1, 0x07E4=>1, 0x07E5=>1, 0x07E6=>1, 0x07E7=>1, 0x07E8=>1, 0x07E9=>1,
2558
- 0x07EA=>1, 0x07FA=>1,
2559
- /* Mandaic */
2560
- 0x0841=>1, 0x0842=>1, 0x0843=>1, 0x0844=>1, 0x0845=>1, 0x0847=>1, 0x0848=>1, 0x084A=>1,
2561
- 0x084B=>1, 0x084C=>1, 0x084D=>1, 0x084E=>1, 0x0850=>1, 0x0851=>1, 0x0852=>1, 0x0853=>1,
2562
- 0x0855=>1,
2563
- 0x0840=>1, 0x0846=>1, 0x0849=>1, 0x084F=>1, 0x0854=>1, /* Right joining */
2564
- /* ZWJ U+200D */
2565
- 0x0200D=>1);
2566
-
2567
-
2568
- /* VOWELS = TRANSPARENT-JOINING = Unicode Transparent-Joining type (not just vowels) */
2569
- $this->arabTransparent = array(
2570
- 0x0610=>1, 0x0611=>1, 0x0612=>1, 0x0613=>1, 0x0614=>1, 0x0615=>1, 0x0616=>1, 0x0617=>1,
2571
- 0x0618=>1, 0x0619=>1, 0x061A=>1, 0x064B=>1, 0x064C=>1, 0x064D=>1, 0x064E=>1, 0x064F=>1,
2572
- 0x0650=>1, 0x0651=>1, 0x0652=>1, 0x0653=>1, 0x0654=>1, 0x0655=>1, 0x0656=>1, 0x0657=>1,
2573
- 0x0658=>1, 0x0659=>1, 0x065A=>1, 0x065B=>1, 0x065C=>1, 0x065D=>1, 0x065E=>1, 0x065F=>1,
2574
- 0x0670=>1, 0x06D6=>1, 0x06D7=>1, 0x06D8=>1, 0x06D9=>1, 0x06DA=>1, 0x06DB=>1, 0x06DC=>1,
2575
- 0x06DF=>1, 0x06E0=>1, 0x06E1=>1, 0x06E2=>1, 0x06E3=>1, 0x06E4=>1, 0x06E7=>1, 0x06E8=>1,
2576
- 0x06EA=>1, 0x06EB=>1, 0x06EC=>1, 0x06ED=>1,
2577
- /* Extended Arabic */
2578
- 0x08E4=>1, 0x08E5=>1, 0x08E6=>1, 0x08E7=>1, 0x08E8=>1, 0x08E9=>1, 0x08EA=>1, 0x08EB=>1,
2579
- 0x08EC=>1, 0x08ED=>1, 0x08EE=>1, 0x08EF=>1, 0x08F0=>1, 0x08F1=>1, 0x08F2=>1, 0x08F3=>1,
2580
- 0x08F4=>1, 0x08F5=>1, 0x08F6=>1, 0x08F7=>1, 0x08F8=>1, 0x08F9=>1, 0x08FA=>1, 0x08FB=>1,
2581
- 0x08FC=>1, 0x08FD=>1, 0x08FE=>1,
2582
- /* Arabic ligatures in presentation form (converted in 'ccmp' in e.g. Arial and Times ? need to add others in this range) */
2583
- 0xFC5E=>1, 0xFC5F=>1, 0xFC60=>1, 0xFC61=>1, 0xFC62=>1,
2584
- /* 'syrc' Syriac */
2585
- 0x070F=>1, 0x0711=>1, 0x0730=>1, 0x0731=>1, 0x0732=>1, 0x0733=>1, 0x0734=>1, 0x0735=>1,
2586
- 0x0736=>1, 0x0737=>1, 0x0738=>1, 0x0739=>1, 0x073A=>1, 0x073B=>1, 0x073C=>1, 0x073D=>1,
2587
- 0x073E=>1, 0x073F=>1, 0x0740=>1, 0x0741=>1, 0x0742=>1, 0x0743=>1, 0x0744=>1, 0x0745=>1,
2588
- 0x0746=>1, 0x0747=>1, 0x0748=>1, 0x0749=>1, 0x074A=>1,
2589
- /* N'Ko */
2590
- 0x07EB=>1, 0x07EC=>1, 0x07ED=>1, 0x07EE=>1, 0x07EF=>1, 0x07F0=>1, 0x07F1=>1, 0x07F2=>1,
2591
- 0x07F3=>1,
2592
- /* Mandaic */
2593
- 0x0859=>1, 0x085A=>1, 0x085B=>1,
2594
- );
2595
-
2596
- }
2597
-
2598
-
2599
- function arabic_shaper($usetags, $scriptTag) {
2600
- $chars = array();
2601
- for($i=0;$i<count($this->OTLdata);$i++) {
2602
- $chars[] = $this->OTLdata[$i]['hex'];
2603
- }
2604
- $crntChar = null;
2605
- $prevChar = null;
2606
- $nextChar = null;
2607
- $output = array();
2608
- $max = count($chars);
2609
- for ($i = $max - 1; $i >= 0; $i--) {
2610
- $crntChar = $chars[$i];
2611
- if ($i > 0){ $prevChar = hexdec($chars[$i - 1]); }
2612
- else{ $prevChar = NULL; }
2613
- if ($prevChar && isset($this->arabTransparentJoin[$prevChar]) && isset($chars[$i - 2]) ) {
2614
- $prevChar = hexdec($chars[$i - 2]);
2615
- if ($prevChar && isset($this->arabTransparentJoin[$prevChar]) && isset($chars[$i - 3])) {
2616
- $prevChar = hexdec($chars[$i - 3]);
2617
- if ($prevChar && isset($this->arabTransparentJoin[$prevChar]) && isset($chars[$i - 4])) {
2618
- $prevChar = hexdec($chars[$i - 4]);
2619
- }
2620
- }
2621
- }
2622
- if ($crntChar && isset($this->arabTransparentJoin[ hexdec($crntChar)]) ) {
2623
- // If next_char = RightJoining && prev_char = LeftJoining:
2624
- if (isset($chars[$i + 1]) && $chars[$i + 1] && isset($this->arabRightJoining[ hexdec($chars[$i + 1]) ]) && $prevChar && isset($this->arabLeftJoining[$prevChar])) {
2625
- $output[] = $this->get_arab_glyphs($crntChar, 1, $chars, $i, $scriptTag, $usetags); // <final> form
2626
- }
2627
- else {
2628
- $output[] = $this->get_arab_glyphs($crntChar, 0, $chars, $i, $scriptTag, $usetags); // <isolated> form
2629
- }
2630
- continue;
2631
- }
2632
- if (hexdec($crntChar) < 128) {
2633
- $output[] = array($crntChar,0);
2634
- $nextChar = $crntChar;
2635
- continue;
2636
- }
2637
- // 0=ISOLATED FORM :: 1=FINAL :: 2=INITIAL :: 3=MEDIAL
2638
- $form = 0;
2639
- if ($prevChar && isset($this->arabLeftJoining[$prevChar])) {
2640
- $form++;
2641
- }
2642
- if ($nextChar && isset($this->arabRightJoining[ hexdec($nextChar) ])) {
2643
- $form += 2;
2644
- }
2645
- $output[] = $this->get_arab_glyphs($crntChar, $form, $chars, $i, $scriptTag, $usetags) ;
2646
- $nextChar = $crntChar;
2647
- }
2648
- $ra = array_reverse($output);
2649
- for($i=0;$i<count($this->OTLdata);$i++) {
2650
- $this->OTLdata[$i]['uni'] = hexdec($ra[$i][0]);
2651
- $this->OTLdata[$i]['hex'] = $ra[$i][0];
2652
- $this->OTLdata[$i]['form'] = $ra[$i][1]; // Actaul form substituted 0=ISOLATED FORM :: 1=FINAL :: 2=INITIAL :: 3=MEDIAL
2653
- }
2654
- }
2655
-
2656
-
2657
- function get_arab_glyphs($char, $type, &$chars, $i, $scriptTag, $usetags) {
2658
-
2659
- // Optional Feature settings // doesn't control Syriac at present
2660
- if (($type===0 && strpos($usetags, 'isol')===false) || ($type===1 && strpos($usetags, 'fina')===false) || ($type===2 && strpos($usetags, 'init')===false) || ($type===3 && strpos($usetags, 'medi')===false)) {
2661
- return array($char,0);
2662
- }
2663
-
2664
- // 0=ISOLATED FORM :: 1=FINAL :: 2=INITIAL :: 3=MEDIAL (:: 4=MED2 :: 5=FIN2 :: 6=FIN3)
2665
- $retk = -1;
2666
- // Alaph 00710 in Syriac
2667
- if ($scriptTag=='syrc' && $char=='00710') {
2668
- // if there is a preceding (base?) character *** should search back to previous base - ignoring vowels and change $n
2669
- // set $n as the position of the last base; for now we'll just do this:
2670
- $n = $i-1;
2671
- // if the preceding (base) character cannot be joined to
2672
- // not in $this->arabLeftJoining i.e. not a char which can join to the next one
2673
- if (isset($chars[$n]) && isset($this->arabLeftJoining[hexdec($chars[$n])])) {
2674
- // if in the middle of Syriac words
2675
- if (isset($chars[$i+1]) && preg_match('/[\x{0700}-\x{0745}]/u',code2utf(hexdec($chars[$n]))) && preg_match('/[\x{0700}-\x{0745}]/u',code2utf(hexdec($chars[$i+1]))) && isset($this->arabGlyphs[$char][4])) { $retk = 4; }
2676
- // if at the end of Syriac words
2677
- else if(!isset($chars[$i+1]) || !preg_match('/[\x{0700}-\x{0745}]/u',code2utf(hexdec($chars[$i+1])))) {
2678
- // if preceding base character IS (00715|00716|0072A)
2679
- if (strpos('0715|0716|072A',$chars[$n])!==false && isset($this->arabGlyphs[$char][6])) { $retk = 6; }
2680
-
2681
- // else if preceding base character is NOT (00715|00716|0072A)
2682
- else if (isset($this->arabGlyphs[$char][5])) { $retk = 5; }
2683
- }
2684
- }
2685
- if ($retk != -1) {
2686
- return array($this->arabGlyphs[$char][$retk],$retk);
2687
- }
2688
- else { return array($char,0); }
2689
- }
2690
-
2691
- if (($type>0 || $type===0) && isset($this->arabGlyphs[$char][$type])) {
2692
- $retk = $type;
2693
- }
2694
- else if ($type==3 && isset($this->arabGlyphs[$char][1])) { // if <medial> not defined, but <final>, return <final>
2695
- $retk = 1;
2696
- }
2697
- else if ($type==2 && isset($this->arabGlyphs[$char][0])) { // if <initial> not defined, but <isolated>, return <isolated>
2698
- $retk = 0;
2699
- }
2700
- if ($retk != -1) {
2701
- $match = true;
2702
- // If GSUB includes a Backtrack or Lookahead condition (e.g. font ArabicTypesetting)
2703
- if (isset($this->arabGlyphs[$char]['prel'][$retk]) && $this->arabGlyphs[$char]['prel'][$retk]) {
2704
- $ig = 1;
2705
- foreach($this->arabGlyphs[$char]['prel'][$retk] AS $k=>$v) { // $k starts 0, 1...
2706
- if (!isset($chars[$i-$ig-$k])) { $match = false; }
2707
- else if (strpos($v,$chars[$i-$ig-$k])===false) {
2708
- while (strpos($this->arabGlyphs[$char]['ignore'][$retk],$chars[$i-$ig-$k])!==false) { // ignore
2709
- $ig++;
2710
- }
2711
- if (!isset($chars[$i-$ig-$k])) { $match = false; }
2712
- else if (strpos($v,$chars[$i-$ig-$k])===false) { $match = false; }
2713
- }
2714
- }
2715
- }
2716
- if (isset($this->arabGlyphs[$char]['postl'][$retk]) && $this->arabGlyphs[$char]['postl'][$retk]) {
2717
- $ig = 1;
2718
- foreach($this->arabGlyphs[$char]['postl'][$retk] AS $k=>$v) { // $k starts 0, 1...
2719
- if (!isset($chars[$i+$ig+$k])) { $match = false; }
2720
- else if (strpos($v,$chars[$i+$ig+$k])===false) {
2721
- while (strpos($this->arabGlyphs[$char]['ignore'][$retk],$chars[$i+$ig+$k])!==false) { // ignore
2722
- $ig++;
2723
- }
2724
- if (!isset($chars[$i+$ig+$k])) { $match = false; }
2725
- else if (strpos($v,$chars[$i+$ig+$k])===false) { $match = false; }
2726
- }
2727
- }
2728
- }
2729
- if ($match) {
2730
- return array($this->arabGlyphs[$char][$retk],$retk);
2731
- }
2732
- else { return array($char,0); }
2733
- }
2734
- else { return array($char,0); }
2735
- }
2736
-
2737
-
2738
- ////////////////////////////////////////////////////////////////
2739
- ////////////////////////////////////////////////////////////////
2740
- ///////////////// LINE BREAKING ///////////////////////
2741
- ////////////////////////////////////////////////////////////////
2742
- ////////////////////////////////////////////////////////////////
2743
-
2744
- ////////////////////////////////////////////////////////////////
2745
- ///////////// TIBETAN LINE BREAKING ///////////////////
2746
- ////////////////////////////////////////////////////////////////
2747
- // Sets $this->OTLdata[$i]['wordend']=true at possible end of word boundaries
2748
- function TibetanlineBreaking() {
2749
- for ($ptr=0; $ptr<count($this->OTLdata);$ptr++) {
2750
- // Break opportunities at U+0F0B Tsheg or U=0F0D
2751
- if (isset($this->OTLdata[$ptr]['uni']) && ($this->OTLdata[$ptr]['uni']==0x0F0B || $this->OTLdata[$ptr]['uni']==0x0F0D)) {
2752
- if (isset($this->OTLdata[$ptr+1]['uni']) && ($this->OTLdata[$ptr+1]['uni']==0x0F0D || $this->OTLdata[$ptr+1]['uni']==0xF0E)) { continue; }
2753
- // Set end of word marker in OTLdata at matchpos
2754
- $this->OTLdata[$ptr]['wordend'] = true;
2755
- }
2756
- }
2757
-
2758
- }
2759
-
2760
- ////////////////////////////////////////////////////////////////
2761
- ////////// SOUTH EAST ASIAN LINE BREAKING /////////////
2762
- ////////////////////////////////////////////////////////////////
2763
- // South East Asian Linebreaking (Thai, Khmer and Lao) using dictionary of words
2764
- // Sets $this->OTLdata[$i]['wordend']=true at possible end of word boundaries
2765
- function SEAlineBreaking() {
2766
- // Load Line-breaking dictionary
2767
- if (!isset($this->lbdicts[$this->shaper]) && file_exists(_MPDF_PATH.'includes/linebrdict'.$this->shaper.'.dat')) { $this->lbdicts[$this->shaper] = file_get_contents(_MPDF_PATH.'includes/linebrdict'.$this->shaper.'.dat'); }
2768
-
2769
- $dict =&$this->lbdicts[$this->shaper];
2770
-
2771
- // Find all word boundaries and mark end of word $this->OTLdata[$i]['wordend']=true on last character
2772
- // If Thai, allow for possible suffixes (not in Lao or Khmer)
2773
-
2774
- // repeater/ellision characters
2775
- // (0x0E2F); // Ellision character THAI_PAIYANNOI 0x0E2F UTF-8 0xE0 0xB8 0xAF
2776
- // (0x0E46); // Repeat character THAI_MAIYAMOK 0x0E46 UTF-8 0xE0 0xB9 0x86
2777
- // (0x0EC6); // Repeat character LAO UTF-8 0xE0 0xBB 0x86
2778
-
2779
- $rollover = array();
2780
- $ptr = 0;
2781
- while ($ptr<count($this->OTLdata)-3) {
2782
- if (count($rollover)) {
2783
- $matches = $rollover;
2784
- $rollover = array();
2785
- }
2786
- else {
2787
- $matches = $this->checkwordmatch($dict, $ptr);
2788
- }
2789
- if (count($matches)==1) {
2790
- $matchpos = $matches[0];
2791
- // Check for repeaters - if so $matchpos++
2792
- if (isset($this->OTLdata[$matchpos+1]['uni']) && ($this->OTLdata[$matchpos+1]['uni']==0x0E2F || $this->OTLdata[$matchpos+1]['uni']==0x0E46 || $this->OTLdata[$matchpos+1]['uni']==0x0EC6)) { $matchpos++; }
2793
- // Set end of word marker in OTLdata at matchpos
2794
- $this->OTLdata[$matchpos]['wordend'] = true;
2795
- $ptr = $matchpos + 1;
2796
- }
2797
- else if (empty($matches)) {
2798
- $ptr++;
2799
- // Move past any ASCII characters
2800
- while (isset($this->OTLdata[$ptr]['uni']) && ($this->OTLdata[$ptr]['uni'] >> 8) == 0) { $ptr++; }
2801
- }
2802
- else { // Multiple matches
2803
- $secondmatch = false;
2804
- for ($m=count($matches)-1;$m>=0;$m--) {
2805
- //for ($m=0;$m<count($matches);$m++) {
2806
- $firstmatch = $matches[$m];
2807
- $matches2 = $this->checkwordmatch($dict, $firstmatch+1);
2808
- if (count($matches2)) {
2809
- // Set end of word marker in OTLdata at matchpos
2810
- $this->OTLdata[$firstmatch]['wordend'] = true;
2811
- $ptr = $firstmatch + 1;
2812
- $rollover = $matches2;
2813
- $secondmatch = true;
2814
- break;
2815
- }
2816
- }
2817
- if (!$secondmatch) {
2818
- // Set end of word marker in OTLdata at end of longest first match
2819
- $this->OTLdata[$matches[count($matches)-1]]['wordend'] = true;
2820
- $ptr = $matches[count($matches)-1] + 1;
2821
- // Move past any ASCII characters
2822
- while (isset($this->OTLdata[$ptr]['uni']) && ($this->OTLdata[$ptr]['uni'] >> 8) == 0) { $ptr++; }
2823
- }
2824
- }
2825
-
2826
- }
2827
-
2828
- }
2829
-
2830
- function checkwordmatch(&$dict, $ptr) {
2831
- /*
2832
- define("_DICT_NODE_TYPE_SPLIT", 0x01);
2833
- define("_DICT_NODE_TYPE_LINEAR", 0x02);
2834
- define("_DICT_INTERMEDIATE_MATCH", 0x03);
2835
- define("_DICT_FINAL_MATCH", 0x04);
2836
-
2837
- Node type: Split.
2838
- Divide at < 98 >= 98
2839
- Offset for >= 98 == 79 (long 4-byte unsigned)
2840
-
2841
- Node type: Linear match.
2842
- Char = 97
2843
-
2844
- Intermediate match
2845
-
2846
- Final match
2847
- */
2848
-
2849
- $dictptr = 0;
2850
- $ok = true;
2851
- $matches = array();
2852
- while ($ok) {
2853
- $x = ord($dict{$dictptr});
2854
- $c = $this->OTLdata[$ptr]['uni'] & 0xFF;
2855
- if ($x==_DICT_INTERMEDIATE_MATCH) {
2856
- //echo "DICT_INTERMEDIATE_MATCH: ".dechex($c).'<br />';
2857
- // Do not match if next character in text is a Mark
2858
- if (isset($this->OTLdata[$ptr]['uni']) && strpos($this->GlyphClassMarks, $this->OTLdata[$ptr]['hex'])===false) {
2859
- $matches[] = $ptr - 1;
2860
- }
2861
- $dictptr++;
2862
- }
2863
- else if ($x==_DICT_FINAL_MATCH) {
2864
- //echo "DICT_FINAL_MATCH: ".dechex($c).'<br />';
2865
- // Do not match if next character in text is a Mark
2866
- if (isset($this->OTLdata[$ptr]['uni']) && strpos($this->GlyphClassMarks, $this->OTLdata[$ptr]['hex'])===false) {
2867
- $matches[] = $ptr - 1;
2868
- }
2869
- return $matches;
2870
- }
2871
- else if ($x==_DICT_NODE_TYPE_LINEAR) {
2872
- //echo "DICT_NODE_TYPE_LINEAR: ".dechex($c).'<br />';
2873
- $dictptr++;
2874
- $m = ord($dict{$dictptr});
2875
- if ($c == $m) {
2876
- $ptr++;
2877
- if ($ptr > count($this->OTLdata)-1) {
2878
- $next = ord($dict{$dictptr+1});
2879
- if ($next==_DICT_INTERMEDIATE_MATCH || $next==_DICT_FINAL_MATCH) {
2880
- // Do not match if next character in text is a Mark
2881
- if (isset($this->OTLdata[$ptr]['uni']) && strpos($this->GlyphClassMarks, $this->OTLdata[$ptr]['hex'])===false) {
2882
- $matches[] = $ptr - 1;
2883
- }
2884
- }
2885
- return $matches;
2886
- }
2887
- $dictptr++;
2888
- continue;
2889
- }
2890
- else {
2891
- //echo "DICT_NODE_TYPE_LINEAR NOT: ".dechex($c).'<br />';
2892
- return $matches;
2893
- }
2894
- }
2895
- else if ($x==_DICT_NODE_TYPE_SPLIT) {
2896
- //echo "DICT_NODE_TYPE_SPLIT ON ".dechex($d).": ".dechex($c).'<br />';
2897
- $dictptr++;
2898
- $d = ord($dict{$dictptr});
2899
- if ($c < $d) {
2900
- $dictptr += 5;
2901
- }
2902
- else {
2903
- $dictptr++;
2904
- // Unsigned long 32-bit offset
2905
- $offset = (ord($dict{$dictptr})*16777216) + (ord($dict{$dictptr+1})<<16) + (ord($dict{$dictptr+2})<<8) + ord($dict{$dictptr+3});
2906
- $dictptr = $offset;
2907
- }
2908
- }
2909
- else {
2910
- //echo "PROBLEM: ".($x).'<br />';
2911
- $ok = false; // Something has gone wrong
2912
- }
2913
- }
2914
-
2915
- return $matches;
2916
- }
2917
-
2918
-
2919
-
2920
- ////////////////////////////////////////////////////////////////
2921
- ////////////////////////////////////////////////////////////////
2922
- ////////// GPOS ///////////////////////////////////////
2923
- ////////////////////////////////////////////////////////////////
2924
- ////////////////////////////////////////////////////////////////
2925
-
2926
- function _applyGPOSrules($LookupList, $is_old_spec=false) {
2927
- foreach($LookupList AS $lu=>$tag) {
2928
- $Type = $this->GPOSLookups[$lu]['Type'];
2929
- $Flag = $this->GPOSLookups[$lu]['Flag'];
2930
- $MarkFilteringSet = '';
2931
- if (isset($this->GPOSLookups[$lu]['MarkFilteringSet']))
2932
- $MarkFilteringSet = $this->GPOSLookups[$lu]['MarkFilteringSet'];
2933
- $ptr = 0;
2934
- // Test each glyph sequentially
2935
- while($ptr < (count($this->OTLdata))) { // whilst there is another glyph ..0064
2936
- $currGlyph = $this->OTLdata[$ptr]['hex'];
2937
- $currGID = $this->OTLdata[$ptr]['uni'];
2938
- $shift = 1;
2939
- foreach($this->GPOSLookups[$lu]['Subtables'] AS $c=>$subtable_offset) {
2940
- // NB Coverage only looks at glyphs for position 1 (esp. 7.3 and 8.3)
2941
- if (isset($this->LuCoverage[$lu][$c][$currGID])) {
2942
- // Get rules from font GPOS subtable
2943
- if (isset($this->OTLdata[$ptr]['bidi_type'])) { // No need to check bidi_type - just a check that it exists
2944
- $shift = $this->_applyGPOSsubtable($lu, $c, $ptr, $currGlyph, $currGID, ($subtable_offset - $this->GPOS_offset + $this->GSUB_length), $Type, $Flag, $MarkFilteringSet, $this->LuCoverage[$lu][$c], $tag, 0, $is_old_spec);
2945
- if ($shift) { break; }
2946
- }
2947
- }
2948
- }
2949
- if ($shift == 0) { $shift = 1; }
2950
- $ptr += $shift;
2951
-
2952
- }
2953
- }
2954
- }
2955
-
2956
- //////////////////////////////////////////////////////////////////////////////////
2957
- // GPOS Types
2958
- // Lookup Type 1: Single Adjustment Positioning Subtable Adjust position of a single glyph
2959
- // Lookup Type 2: Pair Adjustment Positioning Subtable Adjust position of a pair of glyphs
2960
- // Lookup Type 3: Cursive Attachment Positioning Subtable Attach cursive glyphs
2961
- // Lookup Type 4: MarkToBase Attachment Positioning Subtable Attach a combining mark to a base glyph
2962
- // Lookup Type 5: MarkToLigature Attachment Positioning Subtable Attach a combining mark to a ligature
2963
- // Lookup Type 6: MarkToMark Attachment Positioning Subtable Attach a combining mark to another mark
2964
- // Lookup Type 7: Contextual Positioning Subtables Position one or more glyphs in context
2965
- // Lookup Type 8: Chaining Contextual Positioning Subtable Position one or more glyphs in chained context
2966
- // Lookup Type 9: Extension positioning
2967
- //////////////////////////////////////////////////////////////////////////////////
2968
- function _applyGPOSvaluerecord($basepos,$Value) {
2969
-
2970
- // If current glyph is a mark with a defined width, any XAdvance is considered to REPLACE the character Advance Width
2971
- // Test case <div style="font-family:myanmartext">&#x1004;&#x103a;&#x1039;&#x1000;&#x1039;&#x1000;&#x103b;&#x103c;&#x103d;&#x1031;&#x102d;</div>
2972
- if (strpos($this->GlyphClassMarks, $this->OTLdata[$basepos]['hex'])!==false) {
2973
- $cw = round($this->mpdf->_getCharWidth($this->mpdf->CurrentFont['cw'], $this->OTLdata[$basepos]['uni']) * $this->mpdf->CurrentFont['unitsPerEm'] / 1000); // convert back to font design units
2974
- }
2975
- else {
2976
- $cw = 0;
2977
- }
2978
-
2979
- $apos = $this->_getXAdvancePos($basepos);
2980
-
2981
- if (isset($Value['XAdvance']) && ($Value['XAdvance']-$cw) != 0) {
2982
- // However DON'T REPLACE the character Advance Width if Advance Width is negative
2983
- // Test case <div style="font-family: dejavusansmono">&#x440;&#x443;&#x301;&#x441;&#x441;&#x43a;&#x438;&#x439;</div>
2984
- if ($Value['XAdvance'] < 0) { $cw = 0; }
2985
-
2986
- // For LTR apply XAdvanceL to the last mark following the base = at $apos
2987
- // For RTL apply XAdvanceR to base = at $basepos
2988
- if (isset($this->OTLdata[$apos]['GPOSinfo']['XAdvanceL'])) { $this->OTLdata[$apos]['GPOSinfo']['XAdvanceL'] += $Value['XAdvance']-$cw; }
2989
- else { $this->OTLdata[$apos]['GPOSinfo']['XAdvanceL'] = $Value['XAdvance']-$cw; }
2990
- if (isset($this->OTLdata[$basepos]['GPOSinfo']['XAdvanceR'])) { $this->OTLdata[$basepos]['GPOSinfo']['XAdvanceR'] += $Value['XAdvance']-$cw; }
2991
- else { $this->OTLdata[$basepos]['GPOSinfo']['XAdvanceR'] = $Value['XAdvance']-$cw; }
2992
- }
2993
-
2994
- // Any XPlacement (? and Y Placement) apply to base and marks (from basepos to apos)
2995
- for ($a=$basepos;$a<=$apos;$a++) {
2996
- if (isset($Value['XPlacement'])) {
2997
- if (isset($this->OTLdata[$a]['GPOSinfo']['XPlacement'])) { $this->OTLdata[$a]['GPOSinfo']['XPlacement'] += $Value['XPlacement']; }
2998
- else { $this->OTLdata[$a]['GPOSinfo']['XPlacement'] = $Value['XPlacement']; }
2999
- }
3000
- if (isset($Value['YPlacement'])) {
3001
- if (isset($this->OTLdata[$a]['GPOSinfo']['YPlacement'])) { $this->OTLdata[$a]['GPOSinfo']['YPlacement'] += $Value['YPlacement']; }
3002
- else { $this->OTLdata[$a]['GPOSinfo']['YPlacement'] = $Value['YPlacement']; }
3003
- }
3004
- }
3005
- }
3006
-
3007
-
3008
-
3009
- // If XAdvance is aplied to $ptr - in order for PDF to position the Advance correctly need to place it on
3010
- // the last of any Marks which immediately follow the current glyph
3011
- function _getXAdvancePos($pos) {
3012
- // NB Not all fonts have all marks specified in GlyphClassMarks
3013
-
3014
- // If the current glyph is not a base (but a mark) then ignore this, and apply to the current position
3015
- if (strpos($this->GlyphClassMarks, $this->OTLdata[$pos]['hex'])!==false) { return $pos; }
3016
-
3017
- while(isset($this->OTLdata[$pos+1]['hex']) && strpos($this->GlyphClassMarks, $this->OTLdata[$pos+1]['hex'])!==false) { $pos++; }
3018
- return $pos ;
3019
- }
3020
-
3021
-
3022
-
3023
-
3024
- function _applyGPOSsubtable($lookupID, $subtable, $ptr, $currGlyph, $currGID, $subtable_offset, $Type, $Flag, $MarkFilteringSet, $LuCoverage, $tag, $level=0, $is_old_spec) {
3025
- if (($Flag & 0x0001) == 1) { $dir = 'RTL'; } // only used for Type 3
3026
- else { $dir = 'LTR'; }
3027
- $ignore = $this->_getGCOMignoreString($Flag, $MarkFilteringSet);
3028
-
3029
- // Lets start
3030
- $this->seek($subtable_offset);
3031
- $PosFormat = $this->read_ushort();
3032
-
3033
- ////////////////////////////////////////////////////////////////////////////////
3034
- // LookupType 1: Single adjustment Adjust position of a single glyph (e.g. SmallCaps/Sups/Subs)
3035
- ////////////////////////////////////////////////////////////////////////////////
3036
- if ($Type == 1) {
3037
- //===========
3038
- // Format 1:
3039
- //===========
3040
- if ($PosFormat==1) {
3041
- $Coverage = $subtable_offset + $this->read_ushort();
3042
- $ValueFormat = $this->read_ushort();
3043
- $Value = $this->_getValueRecord($ValueFormat);
3044
- }
3045
- //===========
3046
- // Format 2:
3047
- //===========
3048
- else if ($PosFormat==2) {
3049
- $Coverage = $subtable_offset + $this->read_ushort();
3050
- $ValueFormat = $this->read_ushort();
3051
- $ValueCount = $this->read_ushort();
3052
- $GlyphPos = $LuCoverage[$currGID];
3053
- $this->skip($GlyphPos * 2 * $this->count_bits($ValueFormat) );
3054
- $Value = $this->_getValueRecord($ValueFormat);
3055
- }
3056
- $this->_applyGPOSvaluerecord($ptr,$Value);
3057
- if ($this->debugOTL) { $this->_dumpproc('GPOS', $lookupID, $subtable, $Type, $PosFormat, $ptr, $currGlyph, $level); }
3058
- return 1;
3059
- }
3060
-
3061
- ////////////////////////////////////////////////////////////////////////////////
3062
- // LookupType 2: Pair adjustment Adjust position of a pair of glyphs (Kerning)
3063
- ////////////////////////////////////////////////////////////////////////////////
3064
- else if ($Type == 2) {
3065
- $Coverage = $subtable_offset + $this->read_ushort();
3066
- $ValueFormat1 = $this->read_ushort();
3067
- $ValueFormat2 = $this->read_ushort();
3068
- $sizeOfPair = ( 2*$this->count_bits($ValueFormat1) ) + ( 2*$this->count_bits($ValueFormat2) );
3069
- //===========
3070
- // Format 1:
3071
- //===========
3072
- if ($PosFormat==1) {
3073
- $PairSetCount = $this->read_ushort();
3074
- $PairSetOffset = array();
3075
- for($p=0;$p<$PairSetCount;$p++) {
3076
- $PairSetOffset[] = $subtable_offset + $this->read_ushort();
3077
- }
3078
- for($p=0;$p<$PairSetCount;$p++) {
3079
- if (isset($LuCoverage[$currGID]) && $LuCoverage[$currGID]==$p) {
3080
- $this->seek($PairSetOffset[$p]);
3081
- //PairSet table
3082
- $PairValueCount = $this->read_ushort();
3083
- for($pv=0;$pv<$PairValueCount;$pv++) {
3084
- //PairValueRecord
3085
- $gid = $this->read_ushort();
3086
- $SecondGlyph = $this->glyphToChar($gid);
3087
- $FirstGlyph = $this->OTLdata[$ptr]['uni'];
3088
-
3089
- $checkpos = $ptr;
3090
- $checkpos++;
3091
- while (isset($this->OTLdata[$checkpos]) && strpos($ignore, $this->OTLdata[$checkpos]['hex'])!==false) {
3092
- $checkpos++;
3093
- }
3094
- if (isset($this->OTLdata[$checkpos]) && $this->OTLdata[$checkpos]['uni']==$SecondGlyph) {
3095
- $matchedpos = $checkpos;
3096
- }
3097
- else { $matchedpos = false; }
3098
-
3099
- if ($matchedpos !== false) {
3100
- $Value1 = $this->_getValueRecord($ValueFormat1);
3101
- $Value2 = $this->_getValueRecord($ValueFormat2);
3102
- if($ValueFormat1) {
3103
- $this->_applyGPOSvaluerecord($ptr,$Value1);
3104
- }
3105
- if($ValueFormat2) {
3106
- $this->_applyGPOSvaluerecord($matchedpos,$Value2);
3107
- if ($this->debugOTL) { $this->_dumpproc('GPOS', $lookupID, $subtable, $Type, $PosFormat, $ptr, $currGlyph, $level); }
3108
- return $matchedpos - $ptr +1;
3109
- }
3110
- if ($this->debugOTL) { $this->_dumpproc('GPOS', $lookupID, $subtable, $Type, $PosFormat, $ptr, $currGlyph, $level); }
3111
- return $matchedpos - $ptr;
3112
- }
3113
- else {
3114
- $this->skip($sizeOfPair);
3115
- }
3116
- }
3117
- }
3118
- }
3119
- return 0;
3120
- }
3121
- //===========
3122
- // Format 2:
3123
- //===========
3124
- else if ($PosFormat==2) {
3125
- $ClassDef1 = $subtable_offset + $this->read_ushort();
3126
- $ClassDef2 = $subtable_offset + $this->read_ushort();
3127
- $Class1Count = $this->read_ushort();
3128
- $Class2Count = $this->read_ushort();
3129
-
3130
- $sizeOfValueRecords = $Class1Count * $Class2Count * $sizeOfPair;
3131
-
3132
- //$this->skip($sizeOfValueRecords ); ???? NOT NEEDED
3133
-
3134
- // NB Class1Count includes Class 0 even though it is not defined by $ClassDef1
3135
- // i.e. Class1Count = 5; Class1 will contain array(indices 1-4);
3136
- $Class1 = $this->_getClassDefinitionTable($ClassDef1);
3137
- $Class2 = $this->_getClassDefinitionTable($ClassDef2);
3138
- $FirstGlyph = $this->OTLdata[$ptr]['uni'];
3139
- $checkpos = $ptr;
3140
- $checkpos++;
3141
- while (isset($this->OTLdata[$checkpos]) && strpos($ignore, $this->OTLdata[$checkpos]['hex'])!==false) {
3142
- $checkpos++;
3143
- }
3144
- if (isset($this->OTLdata[$checkpos])) { $matchedpos = $checkpos; }
3145
- else { return 0; }
3146
-
3147
- $SecondGlyph = $this->OTLdata[$matchedpos]['uni'];
3148
- for($i=0;$i<$Class1Count;$i++) {
3149
- if (isset($Class1[$i]) && count($Class1[$i])) {
3150
- $FirstClassPos = array_search($FirstGlyph, $Class1[$i]);
3151
- if ($FirstClassPos === false) { continue; }
3152
- else {
3153
- for($j=0;$j<$Class2Count;$j++) {
3154
- if (isset($Class2[$j]) && count($Class2[$j])) {
3155
-
3156
- $SecondClassPos = array_search($SecondGlyph, $Class2[$j]);
3157
- if ($SecondClassPos === false) { continue; }
3158
-
3159
- // Get ValueRecord[$i][$j]
3160
- $offs = ($i*$Class2Count*$sizeOfPair) + ($j*$sizeOfPair);
3161
- $this->seek($subtable_offset + 16 + $offs);
3162
-
3163
- $Value1 = $this->_getValueRecord($ValueFormat1);
3164
- $Value2 = $this->_getValueRecord($ValueFormat2);
3165
- if($ValueFormat1) {
3166
- $this->_applyGPOSvaluerecord($ptr,$Value1);
3167
- }
3168
- if($ValueFormat2) {
3169
- $this->_applyGPOSvaluerecord($matchedpos,$Value2);
3170
- if ($this->debugOTL) { $this->_dumpproc('GPOS', $lookupID, $subtable, $Type, $PosFormat, $ptr, $currGlyph, $level); }
3171
- return $matchedpos - $ptr +1;
3172
- }
3173
- if ($this->debugOTL) { $this->_dumpproc('GPOS', $lookupID, $subtable, $Type, $PosFormat, $ptr, $currGlyph, $level); }
3174
- return $matchedpos - $ptr;
3175
- }
3176
- }
3177
- }
3178
-
3179
- }
3180
- }
3181
- return 0;
3182
- }
3183
- }
3184
-
3185
- ////////////////////////////////////////////////////////////////////////////////
3186
- // LookupType 3: Cursive attachment Attach cursive glyphs
3187
- ////////////////////////////////////////////////////////////////////////////////
3188
- else if ($Type == 3) {
3189
- $this->skip(4);
3190
- // Need default XAdvance for glyph
3191
- $pdfWidth = $this->mpdf->_getCharWidth($this->mpdf->CurrentFont['cw'], hexdec($currGlyph)); // DON'T convert back to design units
3192
-
3193
- $CPos = $LuCoverage[$currGID];
3194
- $this->skip($CPos * 4);
3195
- $EntryAnchor = $this->read_ushort();
3196
- $ExitAnchor = $this->read_ushort();
3197
- if ($EntryAnchor != 0) {
3198
- $EntryAnchor += $subtable_offset;
3199
- list($x,$y) = $this->_getAnchorTable($EntryAnchor);
3200
- if ($dir == 'RTL') {
3201
- if (round($pdfWidth) == round($x * 1000/ $this->mpdf->CurrentFont['unitsPerEm']) ) {
3202
- $x = 0;
3203
- }
3204
- else { $x = $x - ($pdfWidth * $this->mpdf->CurrentFont['unitsPerEm']/1000); }
3205
- }
3206
-
3207
- $this->Entry[$ptr] = array('X'=>$x, 'Y'=>$y, 'dir'=>$dir);
3208
- }
3209
- if ($ExitAnchor != 0) {
3210
- $ExitAnchor += $subtable_offset;
3211
- list($x,$y) = $this->_getAnchorTable($ExitAnchor);
3212
- if ($dir == 'LTR') {
3213
- if (round($pdfWidth) == round($x * 1000/ $this->mpdf->CurrentFont['unitsPerEm']) ) {
3214
- $x = 0;
3215
- }
3216
- else { $x = $x - ($pdfWidth * $this->mpdf->CurrentFont['unitsPerEm']/1000); }
3217
- }
3218
- $this->Exit[$ptr] = array('X'=>$x, 'Y'=>$y, 'dir'=>$dir);
3219
- }
3220
- if ($this->debugOTL) { $this->_dumpproc('GPOS', $lookupID, $subtable, $Type, $PosFormat, $ptr, $currGlyph, $level); }
3221
- return 1;
3222
- }
3223
-
3224
- ////////////////////////////////////////////////////////////////////////////////
3225
- // LookupType 4: MarkToBase attachment Attach a combining mark to a base glyph
3226
- ////////////////////////////////////////////////////////////////////////////////
3227
- else if ($Type == 4) {
3228
- $MarkCoverage = $subtable_offset + $this->read_ushort();
3229
- //$MarkCoverage is already set in $LuCoverage 00065|00073 etc
3230
- $BaseCoverage = $subtable_offset + $this->read_ushort();
3231
- $ClassCount = $this->read_ushort(); // Number of classes defined for marks = Number of mark glyphs in the MarkCoverage table
3232
- $MarkArray = $subtable_offset + $this->read_ushort(); // Offset to MarkArray table
3233
- $BaseArray = $subtable_offset + $this->read_ushort(); // Offset to BaseArray table
3234
-
3235
- $this->seek($BaseCoverage);
3236
- $BaseGlyphs = implode('|',$this->_getCoverage());
3237
-
3238
- $checkpos = $ptr;
3239
- $checkpos--;
3240
-
3241
- // ZZZ93
3242
- // In Lohit-Kannada font (old-spec), rules specify a Type 4 GPOS to attach below-forms to base glyph
3243
- // the repositioning does not happen in MS Word, and shouldn't happen comparing with other fonts
3244
- // ?Why not
3245
- // This Fix blocks the GPOS rule if the "mark" is not actually classified as a mark in the GlyphClasses of GDEF
3246
- // but only in Indic old-spec.
3247
- // Test cases: &#xca8;&#xccd;&#xca8;&#xcc1; and &#xc95;&#xccd;&#xcb0;&#xccc;
3248
- if ($this->shaper=='I' && $is_old_spec && strpos($this->GlyphClassMarks, $this->OTLdata[$ptr]['hex'])===false) { return; }
3249
-
3250
-
3251
- // "To identify the base glyph that combines with a mark, the text-processing client must look backward in the glyph string from the mark to the preceding base glyph."
3252
- while (isset($this->OTLdata[$checkpos]) && strpos($this->GlyphClassMarks, $this->OTLdata[$checkpos]['hex'])!==false) {
3253
- $checkpos--;
3254
- }
3255
-
3256
- if (isset($this->OTLdata[$checkpos]) && strpos($BaseGlyphs, $this->OTLdata[$checkpos]['hex'])!==false) {
3257
- $matchedpos = $checkpos;
3258
- }
3259
- else { $matchedpos = false; }
3260
-
3261
- if ($matchedpos !== false) {
3262
-
3263
- // Get the relevant MarkRecord
3264
- $MarkPos = $LuCoverage[$currGID];
3265
- $MarkRecord = $this->_getMarkRecord($MarkArray, $MarkPos); // e.g. Array ( [Class] => 0 [AnchorX] => -549 [AnchorY] => 1548 )
3266
- //Mark Class is = $MarkRecord['Class']
3267
-
3268
- // Get the relevant BaseRecord
3269
- $this->seek($BaseArray);
3270
- $BaseCount = $this->read_ushort();
3271
- $BasePos = strpos($BaseGlyphs, $this->OTLdata[$matchedpos]['hex'])/6;
3272
-
3273
- // Move to the BaseRecord we want
3274
- $nSkip = (2 * $BasePos * $ClassCount );
3275
- $this->skip($nSkip);
3276
-
3277
- // Read BaseRecord we want for appropriate Class
3278
- $nSkip = 2*$MarkRecord['Class'];
3279
- $this->skip($nSkip);
3280
- $BaseRecordOffset = $BaseArray + $this->read_ushort();
3281
- list($x,$y) = $this->_getAnchorTable($BaseRecordOffset);
3282
- $BaseRecord = array('AnchorX'=>$x, 'AnchorY'=>$y); // e.g. Array ( [AnchorX] => 660 [AnchorY] => 1556 )
3283
-
3284
- // Need default XAdvance for Base glyph
3285
- $BaseWidth = $this->mpdf->_getCharWidth($this->mpdf->CurrentFont['cw'], $this->OTLdata[$matchedpos]['uni']) * $this->mpdf->CurrentFont['unitsPerEm'] / 1000; // convert back to font design units
3286
- $this->OTLdata[$ptr]['GPOSinfo']['BaseWidth'] = $BaseWidth;
3287
- // And any intervening (ignored) characters
3288
- if (($ptr - $matchedpos) > 1) {
3289
- for ($i=$matchedpos+1; $i<$ptr; $i++) {
3290
- $BaseWidthExtra = $this->mpdf->_getCharWidth($this->mpdf->CurrentFont['cw'], $this->OTLdata[$i]['uni']) * $this->mpdf->CurrentFont['unitsPerEm'] / 1000; // convert back to font design units
3291
- $this->OTLdata[$ptr]['GPOSinfo']['BaseWidth'] += $BaseWidthExtra;
3292
-
3293
- }
3294
- }
3295
-
3296
- // Align to previous Glyph by attachment - so need to add to previous placement values
3297
- $prevXPlacement = (isset($this->OTLdata[$matchedpos]['GPOSinfo']['XPlacement']) ? $this->OTLdata[$matchedpos]['GPOSinfo']['XPlacement'] : 0);
3298
- $prevYPlacement = (isset($this->OTLdata[$matchedpos]['GPOSinfo']['YPlacement']) ? $this->OTLdata[$matchedpos]['GPOSinfo']['YPlacement'] : 0);
3299
-
3300
- $this->OTLdata[$ptr]['GPOSinfo']['XPlacement'] = $prevXPlacement + $BaseRecord['AnchorX'] - $MarkRecord['AnchorX'];
3301
- $this->OTLdata[$ptr]['GPOSinfo']['YPlacement'] = $prevYPlacement + $BaseRecord['AnchorY'] - $MarkRecord['AnchorY'];
3302
- if ($this->debugOTL) { $this->_dumpproc('GPOS', $lookupID, $subtable, $Type, $PosFormat, $ptr, $currGlyph, $level); }
3303
- return 1;
3304
-
3305
- }
3306
- return 0;
3307
- }
3308
-
3309
- ////////////////////////////////////////////////////////////////////////////////
3310
- // LookupType 5: MarkToLigature attachment Attach a combining mark to a ligature
3311
- ////////////////////////////////////////////////////////////////////////////////
3312
- else if ($Type == 5) {
3313
- $MarkCoverage = $subtable_offset + $this->read_ushort();
3314
- //$MarkCoverage is already set in $LuCoverage 00065|00073 etc
3315
- $LigatureCoverage = $subtable_offset + $this->read_ushort();
3316
- $ClassCount = $this->read_ushort(); // Number of classes defined for marks = Number of mark glyphs in the MarkCoverage table
3317
- $MarkArray = $subtable_offset + $this->read_ushort(); // Offset to MarkArray table
3318
- $LigatureArray = $subtable_offset + $this->read_ushort(); // Offset to LigatureArray table
3319
-
3320
- $this->seek($LigatureCoverage);
3321
- $LigatureGlyphs = implode('|',$this->_getCoverage());
3322
-
3323
-
3324
- $checkpos = $ptr;
3325
- $checkpos--;
3326
-
3327
- // "To position a combining mark using a MarkToLigature attachment subtable, the text-processing client must work backward from the mark to the preceding ligature glyph."
3328
- while (isset($this->OTLdata[$checkpos]) && strpos($this->GlyphClassMarks, $this->OTLdata[$checkpos]['hex'])!==false) {
3329
- $checkpos--;
3330
- }
3331
-
3332
- if (isset($this->OTLdata[$checkpos]) && strpos($LigatureGlyphs, $this->OTLdata[$checkpos]['hex'])!==false) {
3333
- $matchedpos = $checkpos;
3334
- }
3335
- else { $matchedpos = false; }
3336
-
3337
- if ($matchedpos !== false) {
3338
-
3339
- // Get the relevant MarkRecord
3340
- $MarkPos = $LuCoverage[$currGID];
3341
- $MarkRecord = $this->_getMarkRecord($MarkArray, $MarkPos); // e.g. Array ( [Class] => 0 [AnchorX] => -549 [AnchorY] => 1548 )
3342
- //Mark Class is = $MarkRecord['Class']
3343
-
3344
-
3345
- // Get the relevant LigatureRecord
3346
- $this->seek($LigatureArray);
3347
- $LigatureCount = $this->read_ushort();
3348
- $LigaturePos = strpos($LigatureGlyphs, $this->OTLdata[$matchedpos]['hex'])/6;
3349
-
3350
- // Move to the LigatureAttach table Record we want
3351
- $nSkip = (2 * $LigaturePos);
3352
- $this->skip($nSkip);
3353
- $LigatureAttachOffset = $LigatureArray + $this->read_ushort();
3354
- $this->seek($LigatureAttachOffset);
3355
- $ComponentCount = $this->read_ushort();
3356
- $offsets = array();
3357
- for ($comp=0;$comp<$ComponentCount;$comp++) {
3358
- // ComponentRecords
3359
- for ($class=0;$class<$ClassCount;$class++) {
3360
- $offsets[$comp][$class] = $this->read_ushort();
3361
- }
3362
- }
3363
-
3364
- // Get the specific component for this mark attachment
3365
- if (isset($this->assocLigs[$matchedpos]) && isset($this->assocMarks[$ptr]['ligPos']) && $this->assocMarks[$ptr]['ligPos']==$matchedpos) {
3366
- $component = $this->assocMarks[$ptr]['compID'] ;
3367
- }
3368
- else { $component = $ComponentCount-1; }
3369
-
3370
- $offset = $offsets[$component][$MarkRecord['Class']];
3371
- if ($offset!=0) {
3372
- $LigatureRecordOffset = $offset + $LigatureAttachOffset;
3373
- list($x,$y) = $this->_getAnchorTable($LigatureRecordOffset);
3374
- $LigatureRecord = array('AnchorX'=>$x, 'AnchorY'=>$y);
3375
-
3376
- // Need default XAdvance for Ligature glyph
3377
- $LigatureWidth = $this->mpdf->_getCharWidth($this->mpdf->CurrentFont['cw'], $this->OTLdata[$matchedpos]['uni']) * $this->mpdf->CurrentFont['unitsPerEm'] / 1000; // convert back to font design units
3378
- $this->OTLdata[$ptr]['GPOSinfo']['BaseWidth'] = $LigatureWidth;
3379
- // And any intervening (ignored)characters
3380
- if (($ptr - $matchedpos) > 1) {
3381
- for ($i=$matchedpos+1; $i<$ptr; $i++) {
3382
- $LigatureWidthExtra = $this->mpdf->_getCharWidth($this->mpdf->CurrentFont['cw'], $this->OTLdata[$i]['uni']) * $this->mpdf->CurrentFont['unitsPerEm'] / 1000; // convert back to font design units
3383
- $this->OTLdata[$ptr]['GPOSinfo']['BaseWidth'] += $LigatureWidthExtra;
3384
-
3385
- }
3386
- }
3387
-
3388
- // Align to previous Ligature by attachment - so need to add to previous placement values
3389
- if (isset($this->OTLdata[$matchedpos]['GPOSinfo']['XPlacement'])) $prevXPlacement = $this->OTLdata[$matchedpos]['GPOSinfo']['XPlacement'];
3390
- else { $prevXPlacement = 0; }
3391
- if (isset($this->OTLdata[$matchedpos]['GPOSinfo']['YPlacement'])) { $prevYPlacement = $this->OTLdata[$matchedpos]['GPOSinfo']['YPlacement']; }
3392
- else { $prevYPlacement = 0; }
3393
-
3394
- $this->OTLdata[$ptr]['GPOSinfo']['XPlacement'] = $prevXPlacement + $LigatureRecord['AnchorX'] - $MarkRecord['AnchorX'];
3395
- $this->OTLdata[$ptr]['GPOSinfo']['YPlacement'] = $prevYPlacement + $LigatureRecord['AnchorY'] - $MarkRecord['AnchorY'];
3396
- if ($this->debugOTL) { $this->_dumpproc('GPOS', $lookupID, $subtable, $Type, $PosFormat, $ptr, $currGlyph, $level); }
3397
- return 1;
3398
-
3399
- }
3400
- }
3401
- return 0;
3402
- }
3403
-
3404
- ////////////////////////////////////////////////////////////////////////////////
3405
- // LookupType 6: MarkToMark attachment Attach a combining mark to another mark
3406
- ////////////////////////////////////////////////////////////////////////////////
3407
- else if ($Type == 6) {
3408
- $Mark1Coverage = $subtable_offset + $this->read_ushort(); // Combining Mark
3409
- //$Mark1Coverage is already set in $LuCoverage 0065|0073 etc
3410
- $Mark2Coverage = $subtable_offset + $this->read_ushort(); // Base Mark
3411
- $ClassCount = $this->read_ushort(); // Number of classes defined for marks = No. of Combining mark1 glyphs in the MarkCoverage table
3412
- $Mark1Array = $subtable_offset + $this->read_ushort(); // Offset to MarkArray table
3413
- $Mark2Array = $subtable_offset + $this->read_ushort(); // Offset to Mark2Array table
3414
- $this->seek($Mark2Coverage);
3415
- $Mark2Glyphs = implode('|',$this->_getCoverage());
3416
- $checkpos = $ptr;
3417
- $checkpos--;
3418
- while (isset($this->OTLdata[$checkpos]) && strpos($ignore, $this->OTLdata[$checkpos]['hex'])!==false) {
3419
- $checkpos--;
3420
- }
3421
- if (isset($this->OTLdata[$checkpos]) && strpos($Mark2Glyphs, $this->OTLdata[$checkpos]['hex'])!==false) {
3422
- $matchedpos = $checkpos;
3423
- }
3424
- else { $matchedpos = false; }
3425
-
3426
- if ($matchedpos !== false) {
3427
-
3428
- // Get the relevant MarkRecord
3429
- $Mark1Pos = $LuCoverage[$currGID];
3430
- $Mark1Record = $this->_getMarkRecord($Mark1Array, $Mark1Pos); // e.g. Array ( [Class] => 0 [AnchorX] => -549 [AnchorY] => 1548 )
3431
- //Mark Class is = $Mark1Record['Class']
3432
-
3433
- // Get the relevant Mark2Record
3434
- $this->seek($Mark2Array);
3435
- $Mark2Count = $this->read_ushort();
3436
- $Mark2Pos = strpos($Mark2Glyphs, $this->OTLdata[$matchedpos]['hex'])/6;
3437
-
3438
- // Move to the Mark2Record we want
3439
- $nSkip = (2 * $Mark2Pos * $ClassCount );
3440
- $this->skip($nSkip);
3441
-
3442
- // Read Mark2Record we want for appropriate Class
3443
- $nSkip = 2*$Mark1Record['Class'];
3444
- $this->skip($nSkip);
3445
- $Mark2RecordOffset = $Mark2Array + $this->read_ushort();
3446
- list($x,$y) = $this->_getAnchorTable($Mark2RecordOffset);
3447
- $Mark2Record = array('AnchorX'=>$x, 'AnchorY'=>$y); // e.g. Array ( [AnchorX] => 660 [AnchorY] => 1556 )
3448
-
3449
- // Need default XAdvance for Mark2 glyph
3450
- $Mark2Width = $this->mpdf->_getCharWidth($this->mpdf->CurrentFont['cw'], $this->OTLdata[$matchedpos]['uni']) * $this->mpdf->CurrentFont['unitsPerEm'] / 1000; // convert back to font design units
3451
-
3452
-
3453
- // IF combining marks are set on different components of a ligature glyph, do not apply this rule
3454
- // Test: arabictypesetting: &#x625;&#x650;&#x644;&#x64e;&#x649;&#x670;&#x653;
3455
- // Test: arabictypesetting: &#x628;&#x651;&#x64e;&#x64a;&#x652;&#x646;&#x64e;&#x643;&#x64f;&#x645;&#x652;
3456
- $prevLig = -1;
3457
- $thisLig = -1;
3458
- $prevComp = -1;
3459
- $thisComp = -1;
3460
- if (isset($this->assocMarks[$matchedpos])) {
3461
- $prevLig = $this->assocMarks[$matchedpos]['ligPos'];
3462
- $prevComp = $this->assocMarks[$matchedpos]['compID'];
3463
- }
3464
- if (isset($this->assocMarks[$ptr])) {
3465
- $thisLig = $this->assocMarks[$ptr]['ligPos'];
3466
- $thisComp = $this->assocMarks[$ptr]['compID'];
3467
- }
3468
-
3469
- // However IF Mark2 (first in logical order, i.e. being attached to) is not associated with a base, carry on
3470
- // This happens in Indic when the Mark being attached to e.g. [Halant Ma lig] -> MatraU, [U+0B4D + U+B2E as E0F5]-> U+0B41 become E135
3471
- if (!defined("OMIT_OTL_FIX_1") || OMIT_OTL_FIX_1 != 1) {
3472
- /* OTL_FIX_1 */
3473
- if (isset($this->assocMarks[$matchedpos]) && ($prevLig != $thisLig || $prevComp != $thisComp )) { return 0; }
3474
- }
3475
- else {
3476
- /* Original code */
3477
- if ($prevLig != $thisLig || $prevComp != $thisComp ) { return 0; }
3478
- }
3479
-
3480
-
3481
- if (!defined("OMIT_OTL_FIX_2") || OMIT_OTL_FIX_2 != 1) {
3482
- /* OTL_FIX_2 */
3483
- if (!isset($this->OTLdata[$matchedpos]['GPOSinfo']['BaseWidth']) || !$this->OTLdata[$matchedpos]['GPOSinfo']['BaseWidth']) { $this->OTLdata[$ptr]['GPOSinfo']['BaseWidth'] = $Mark2Width; }
3484
- }
3485
-
3486
- // ZZZ99Q - Test Case font-family: garuda &#xe19;&#xe49;&#xe33;
3487
- if (isset($this->OTLdata[$matchedpos]['GPOSinfo']['BaseWidth']) && $this->OTLdata[$matchedpos]['GPOSinfo']['BaseWidth']) { $this->OTLdata[$ptr]['GPOSinfo']['BaseWidth'] = $this->OTLdata[$matchedpos]['GPOSinfo']['BaseWidth']; }
3488
-
3489
- // Align to previous Mark by attachment - so need to add the previous placement values
3490
- $prevXPlacement = (isset($this->OTLdata[$matchedpos]['GPOSinfo']['XPlacement']) ? $this->OTLdata[$matchedpos]['GPOSinfo']['XPlacement'] : 0);
3491
- $prevYPlacement = (isset($this->OTLdata[$matchedpos]['GPOSinfo']['YPlacement']) ? $this->OTLdata[$matchedpos]['GPOSinfo']['YPlacement'] : 0);
3492
- $this->OTLdata[$ptr]['GPOSinfo']['XPlacement'] = $prevXPlacement + $Mark2Record['AnchorX'] - $Mark1Record['AnchorX'];
3493
- $this->OTLdata[$ptr]['GPOSinfo']['YPlacement'] = $prevYPlacement + $Mark2Record['AnchorY'] - $Mark1Record['AnchorY'];
3494
- if ($this->debugOTL) { $this->_dumpproc('GPOS', $lookupID, $subtable, $Type, $PosFormat, $ptr, $currGlyph, $level); }
3495
- return 1;
3496
-
3497
- }
3498
- return 0;
3499
- }
3500
-
3501
- ////////////////////////////////////////////////////////////////////////////////
3502
- // LookupType 7: Context positioning Position one or more glyphs in context
3503
- ////////////////////////////////////////////////////////////////////////////////
3504
- else if ($Type == 7) {
3505
- //===========
3506
- // Format 1:
3507
- //===========
3508
- if ($PosFormat==1) {
3509
- die("GPOS Lookup Type ".$Type." Format ".$PosFormat." not TESTED YET.");
3510
- return 0;
3511
- }
3512
- //===========
3513
- // Format 2:
3514
- //===========
3515
- else if ($PosFormat==2) {
3516
- $CoverageTableOffset = $subtable_offset + $this->read_ushort();
3517
- $InputClassDefOffset = $subtable_offset + $this->read_ushort();
3518
- $PosClassSetCnt = $this->read_ushort();
3519
- $PosClassSetOffset = array();
3520
- for ($b=0;$b<$PosClassSetCnt;$b++) {
3521
- $offset = $this->read_ushort();
3522
- if ($offset==0x0000) {
3523
- $PosClassSetOffset[] = $offset;
3524
- }
3525
- else {
3526
- $PosClassSetOffset[] = $subtable_offset + $offset;
3527
- }
3528
- }
3529
-
3530
- $InputClasses = $this->_getClasses($InputClassDefOffset);
3531
-
3532
- for ($s=0;$s<$PosClassSetCnt;$s++) { // $ChainPosClassSet is ordered by input class-may be NULL
3533
- // Select $PosClassSet if currGlyph is in First Input Class
3534
- if ($PosClassSetOffset[$s]>0 && isset($InputClasses[$s][$currGID])) {
3535
- $this->seek($PosClassSetOffset[$s]);
3536
- $PosClassRuleCnt = $this->read_ushort();
3537
- $PosClassRule = array();
3538
- for($b=0;$b<$PosClassRuleCnt;$b++) {
3539
- $PosClassRule[$b] = $PosClassSetOffset[$s]+$this->read_ushort();
3540
- }
3541
-
3542
- for($b=0;$b<$PosClassRuleCnt;$b++) { // EACH RULE
3543
- $this->seek($PosClassRule[$b]);
3544
- $InputGlyphCount = $this->read_ushort();
3545
- $PosCount = $this->read_ushort();
3546
-
3547
- $Input = array();
3548
- for ($r=1;$r<$InputGlyphCount;$r++) {
3549
- $Input[$r] = $this->read_ushort();
3550
- }
3551
- $inputClass = $s;
3552
-
3553
- $inputGlyphs = array();
3554
- $inputGlyphs[0] = $InputClasses[$inputClass];
3555
-
3556
- if ($InputGlyphCount>1) {
3557
- // NB starts at 1
3558
- for ($gcl=1;$gcl<$InputGlyphCount;$gcl++) {
3559
- $classindex = $Input[$gcl];
3560
- if (isset($InputClasses[$classindex])) { $inputGlyphs[$gcl] = $InputClasses[$classindex]; }
3561
- else { $inputGlyphs[$gcl] = ''; }
3562
- }
3563
- }
3564
-
3565
- // Class 0 contains all the glyphs NOT in the other classes
3566
- $class0excl = array();
3567
- for ($gc=1;$gc<=count($InputClasses);$gc++) {
3568
- if (is_array($InputClasses[$gc])) $class0excl = $class0excl + $InputClasses[$gc];
3569
- }
3570
-
3571
- $backtrackGlyphs = array();
3572
- $lookaheadGlyphs = array();
3573
-
3574
- $matched = $this->checkContextMatchMultipleUni($inputGlyphs, $backtrackGlyphs, $lookaheadGlyphs, $ignore, $ptr, $class0excl );
3575
- if ($matched) {
3576
- for ($p=0;$p<$PosCount;$p++) { // EACH LOOKUP
3577
- $SequenceIndex[$p] = $this->read_ushort();
3578
- $LookupListIndex[$p] = $this->read_ushort();
3579
- }
3580
-
3581
- for ($p=0;$p<$PosCount;$p++) {
3582
- // Apply $LookupListIndex at $SequenceIndex
3583
- if ($SequenceIndex[$p] >= $InputGlyphCount) { continue; }
3584
- $lu = $LookupListIndex[$p];
3585
- $luType = $this->GPOSLookups[$lu]['Type'];
3586
- $luFlag = $this->GPOSLookups[$lu]['Flag'];
3587
- $luMarkFilteringSet = $this->GPOSLookups[$lu]['MarkFilteringSet'];
3588
-
3589
- $luptr = $matched[$SequenceIndex[$p]];
3590
- $lucurrGlyph = $this->OTLdata[$luptr]['hex'];
3591
- $lucurrGID = $this->OTLdata[$luptr]['uni'];
3592
-
3593
- foreach($this->GPOSLookups[$lu]['Subtables'] AS $luc=>$lusubtable_offset) {
3594
- $shift = $this->_applyGPOSsubtable($lu, $luc, $luptr, $lucurrGlyph, $lucurrGID, ($lusubtable_offset - $this->GPOS_offset + $this->GSUB_length), $luType, $luFlag, $luMarkFilteringSet, $this->LuCoverage[$lu][$luc], $tag, 1, $is_old_spec);
3595
- if ($this->debugOTL && $shift) { $this->_dumpproc('GPOS', $lookupID, $subtable, $Type, $PosFormat, $ptr, $currGlyph, $level); }
3596
- if ($shift) { break; }
3597
- }
3598
- }
3599
-
3600
- if (!defined("OMIT_OTL_FIX_3") || OMIT_OTL_FIX_3 != 1) { return $shift ; } /* OTL_FIX_3 */
3601
- else return $InputGlyphCount ; // should be + matched ignores in Input Sequence
3602
-
3603
- }
3604
- }
3605
-
3606
- }
3607
- }
3608
-
3609
- return 0;
3610
- }
3611
- //===========
3612
- // Format 3:
3613
- //===========
3614
- else if ($PosFormat==3) {
3615
- die("GPOS Lookup Type ".$Type." Format ".$PosFormat." not TESTED YET.");
3616
- return 0;
3617
- }
3618
- else { die("GPOS Lookup Type ".$Type.", Format ".$PosFormat." not supported."); }
3619
- }
3620
-
3621
- ////////////////////////////////////////////////////////////////////////////////
3622
- // LookupType 8: Chained Context positioning Position one or more glyphs in chained context
3623
- ////////////////////////////////////////////////////////////////////////////////
3624
- else if ($Type == 8) {
3625
- //===========
3626
- // Format 1:
3627
- //===========
3628
- if ($PosFormat==1) {
3629
- die("GPOS Lookup Type ".$Type." Format ".$PosFormat." not TESTED YET.");
3630
- return 0;
3631
- }
3632
- //===========
3633
- // Format 2:
3634
- //===========
3635
- else if ($PosFormat==2) {
3636
-
3637
- $CoverageTableOffset = $subtable_offset + $this->read_ushort();
3638
- $BacktrackClassDefOffset = $subtable_offset + $this->read_ushort();
3639
- $InputClassDefOffset = $subtable_offset + $this->read_ushort();
3640
- $LookaheadClassDefOffset = $subtable_offset + $this->read_ushort();
3641
- $ChainPosClassSetCnt = $this->read_ushort();
3642
- $ChainPosClassSetOffset = array();
3643
- for ($b=0;$b<$ChainPosClassSetCnt;$b++) {
3644
- $offset = $this->read_ushort();
3645
- if ($offset==0x0000) {
3646
- $ChainPosClassSetOffset[] = $offset;
3647
- }
3648
- else {
3649
- $ChainPosClassSetOffset[] = $subtable_offset + $offset;
3650
- }
3651
- }
3652
-
3653
- $BacktrackClasses = $this->_getClasses($BacktrackClassDefOffset);
3654
- $InputClasses = $this->_getClasses($InputClassDefOffset);
3655
- $LookaheadClasses = $this->_getClasses($LookaheadClassDefOffset);
3656
-
3657
- for ($s=0;$s<$ChainPosClassSetCnt;$s++) { // $ChainPosClassSet is ordered by input class-may be NULL
3658
- // Select $ChainPosClassSet if currGlyph is in First Input Class
3659
- if ($ChainPosClassSetOffset[$s]>0 && isset($InputClasses[$s][$currGID])) {
3660
- $this->seek($ChainPosClassSetOffset[$s]);
3661
- $ChainPosClassRuleCnt = $this->read_ushort();
3662
- $ChainPosClassRule = array();
3663
- for($b=0;$b<$ChainPosClassRuleCnt;$b++) {
3664
- $ChainPosClassRule[$b] = $ChainPosClassSetOffset[$s]+$this->read_ushort();
3665
- }
3666
-
3667
- for($b=0;$b<$ChainPosClassRuleCnt;$b++) { // EACH RULE
3668
- $this->seek($ChainPosClassRule[$b]);
3669
- $BacktrackGlyphCount = $this->read_ushort();
3670
- $Backtrack = array();
3671
- for ($r=0;$r<$BacktrackGlyphCount;$r++) {
3672
- $Backtrack[$r] = $this->read_ushort();
3673
- }
3674
- $InputGlyphCount = $this->read_ushort();
3675
- $Input = array();
3676
- for ($r=1;$r<$InputGlyphCount;$r++) {
3677
- $Input[$r] = $this->read_ushort();
3678
- }
3679
- $LookaheadGlyphCount = $this->read_ushort();
3680
- $Lookahead = array();
3681
- for ($r=0;$r<$LookaheadGlyphCount;$r++) {
3682
- $Lookahead[$r] = $this->read_ushort();
3683
- }
3684
-
3685
- $inputClass = $s; //???
3686
-
3687
- $inputGlyphs = array();
3688
- $inputGlyphs[0] = $InputClasses[$inputClass];
3689
-
3690
- if ($InputGlyphCount>1) {
3691
- // NB starts at 1
3692
- for ($gcl=1;$gcl<$InputGlyphCount;$gcl++) {
3693
- $classindex = $Input[$gcl];
3694
- if (isset($InputClasses[$classindex])) { $inputGlyphs[$gcl] = $InputClasses[$classindex]; }
3695
- else { $inputGlyphs[$gcl] = ''; }
3696
- }
3697
- }
3698
-
3699
- // Class 0 contains all the glyphs NOT in the other classes
3700
- $class0excl = array();
3701
- for ($gc=1;$gc<=count($InputClasses);$gc++) {
3702
- if (isset($InputClasses[$gc]) && is_array($InputClasses[$gc])) $class0excl = $class0excl + $InputClasses[$gc];
3703
- }
3704
-
3705
- if ($BacktrackGlyphCount) {
3706
- $backtrackGlyphs = array();
3707
- for ($gcl=0;$gcl<$BacktrackGlyphCount;$gcl++) {
3708
- $classindex = $Backtrack[$gcl];
3709
- if (isset($BacktrackClasses[$classindex])) { $backtrackGlyphs[$gcl] = $BacktrackClasses[$classindex]; }
3710
- else { $backtrackGlyphs[$gcl] = ''; }
3711
- }
3712
- }
3713
- else { $backtrackGlyphs = array(); }
3714
-
3715
- // Class 0 contains all the glyphs NOT in the other classes
3716
- $bclass0excl = array();
3717
- for ($gc=1;$gc<=count($BacktrackClasses);$gc++) {
3718
- if (isset($BacktrackClasses[$gc]) && is_array($BacktrackClasses[$gc])) $bclass0excl = $bclass0excl + $BacktrackClasses[$gc];
3719
- }
3720
-
3721
- if ($LookaheadGlyphCount) {
3722
- $lookaheadGlyphs = array();
3723
- for ($gcl=0;$gcl<$LookaheadGlyphCount;$gcl++) {
3724
- $classindex = $Lookahead[$gcl];
3725
- if (isset($LookaheadClasses[$classindex])) { $lookaheadGlyphs[$gcl] = $LookaheadClasses[$classindex]; }
3726
- else { $lookaheadGlyphs[$gcl] = ''; }
3727
- }
3728
- }
3729
- else { $lookaheadGlyphs = array(); }
3730
-
3731
- // Class 0 contains all the glyphs NOT in the other classes
3732
- $lclass0excl = array();
3733
- for ($gc=1;$gc<=count($LookaheadClasses);$gc++) {
3734
- if (isset($LookaheadClasses[$gc]) && is_array($LookaheadClasses[$gc])) $lclass0excl = $lclass0excl + $LookaheadClasses[$gc];
3735
- }
3736
-
3737
- $matched = $this->checkContextMatchMultipleUni($inputGlyphs, $backtrackGlyphs, $lookaheadGlyphs, $ignore, $ptr, $class0excl, $bclass0excl, $lclass0excl );
3738
- if ($matched) {
3739
- $PosCount = $this->read_ushort();
3740
- $SequenceIndex = array();
3741
- $LookupListIndex = array();
3742
- for ($p=0;$p<$PosCount;$p++) { // EACH LOOKUP
3743
- $SequenceIndex[$p] = $this->read_ushort();
3744
- $LookupListIndex[$p] = $this->read_ushort();
3745
- }
3746
-
3747
- for ($p=0;$p<$PosCount;$p++) {
3748
- // Apply $LookupListIndex at $SequenceIndex
3749
- if ($SequenceIndex[$p] >= $InputGlyphCount) { continue; }
3750
- $lu = $LookupListIndex[$p];
3751
- $luType = $this->GPOSLookups[$lu]['Type'];
3752
- $luFlag = $this->GPOSLookups[$lu]['Flag'];
3753
- $luMarkFilteringSet = $this->GPOSLookups[$lu]['MarkFilteringSet'];
3754
-
3755
- $luptr = $matched[$SequenceIndex[$p]];
3756
- $lucurrGlyph = $this->OTLdata[$luptr]['hex'];
3757
- $lucurrGID = $this->OTLdata[$luptr]['uni'];
3758
-
3759
- foreach($this->GPOSLookups[$lu]['Subtables'] AS $luc=>$lusubtable_offset) {
3760
- $shift = $this->_applyGPOSsubtable($lu, $luc, $luptr, $lucurrGlyph, $lucurrGID, ($lusubtable_offset - $this->GPOS_offset + $this->GSUB_length), $luType, $luFlag, $luMarkFilteringSet, $this->LuCoverage[$lu][$luc], $tag, 1, $is_old_spec);
3761
- if ($this->debugOTL && $shift) { $this->_dumpproc('GPOS', $lookupID, $subtable, $Type, $PosFormat, $ptr, $currGlyph, $level); }
3762
- if ($shift) { break; }
3763
- }
3764
- }
3765
-
3766
- if (!defined("OMIT_OTL_FIX_3") || OMIT_OTL_FIX_3 != 1) { return $shift ; } /* OTL_FIX_3 */
3767
- else return $InputGlyphCount ; // should be + matched ignores in Input Sequence
3768
-
3769
- }
3770
- }
3771
-
3772
- }
3773
- }
3774
-
3775
- return 0;
3776
- }
3777
- //===========
3778
- // Format 3:
3779
- //===========
3780
- else if ($PosFormat==3) {
3781
- $BacktrackGlyphCount = $this->read_ushort();
3782
- for ($b=0;$b<$BacktrackGlyphCount;$b++) {
3783
- $CoverageBacktrackOffset[] = $subtable_offset + $this->read_ushort(); // in glyph sequence order
3784
- }
3785
- $InputGlyphCount = $this->read_ushort();
3786
- for ($b=0;$b<$InputGlyphCount;$b++) {
3787
- $CoverageInputOffset[] = $subtable_offset + $this->read_ushort(); // in glyph sequence order
3788
- }
3789
- $LookaheadGlyphCount = $this->read_ushort();
3790
- for ($b=0;$b<$LookaheadGlyphCount;$b++) {
3791
- $CoverageLookaheadOffset[] = $subtable_offset + $this->read_ushort(); // in glyph sequence order
3792
- }
3793
- $PosCount = $this->read_ushort();
3794
- $save_pos = $this->_pos; // Save the point just after PosCount
3795
-
3796
- $CoverageBacktrackGlyphs = array();
3797
- for ($b=0;$b<$BacktrackGlyphCount;$b++) {
3798
- $this->seek($CoverageBacktrackOffset[$b]);
3799
- $glyphs = $this->_getCoverage();
3800
- $CoverageBacktrackGlyphs[$b] = implode("|",$glyphs);
3801
- }
3802
- $CoverageInputGlyphs = array();
3803
- for ($b=0;$b<$InputGlyphCount;$b++) {
3804
- $this->seek($CoverageInputOffset[$b]);
3805
- $glyphs = $this->_getCoverage();
3806
- $CoverageInputGlyphs[$b] = implode("|",$glyphs);
3807
- }
3808
- $CoverageLookaheadGlyphs = array();
3809
- for ($b=0;$b<$LookaheadGlyphCount;$b++) {
3810
- $this->seek($CoverageLookaheadOffset[$b]);
3811
- $glyphs = $this->_getCoverage();
3812
- $CoverageLookaheadGlyphs[$b] = implode("|",$glyphs);
3813
- }
3814
- $matched = $this->checkContextMatchMultiple($CoverageInputGlyphs, $CoverageBacktrackGlyphs, $CoverageLookaheadGlyphs , $ignore, $ptr);
3815
- if ($matched) {
3816
-
3817
- $this->seek($save_pos); // Return to just after PosCount
3818
- for ($p=0;$p<$PosCount;$p++) {
3819
- // PosLookupRecord
3820
- $PosLookupRecord[$p]['SequenceIndex'] = $this->read_ushort();
3821
- $PosLookupRecord[$p]['LookupListIndex'] = $this->read_ushort();
3822
- }
3823
- for ($p=0;$p<$PosCount;$p++) {
3824
- // Apply $PosLookupRecord[$p]['LookupListIndex'] at $PosLookupRecord[$p]['SequenceIndex']
3825
- if ($PosLookupRecord[$p]['SequenceIndex'] >= $InputGlyphCount) { continue; }
3826
- $lu = $PosLookupRecord[$p]['LookupListIndex'];
3827
- $luType = $this->GPOSLookups[$lu]['Type'];
3828
- $luFlag = $this->GPOSLookups[$lu]['Flag'];
3829
- if (isset($this->GPOSLookups[$lu]['MarkFilteringSet'])) { $luMarkFilteringSet = $this->GPOSLookups[$lu]['MarkFilteringSet']; }
3830
- else { $luMarkFilteringSet = ''; }
3831
-
3832
- $luptr = $matched[$PosLookupRecord[$p]['SequenceIndex']];
3833
- $lucurrGlyph = $this->OTLdata[$luptr]['hex'];
3834
- $lucurrGID = $this->OTLdata[$luptr]['uni'];
3835
-
3836
- foreach($this->GPOSLookups[$lu]['Subtables'] AS $luc=>$lusubtable_offset) {
3837
- $shift = $this->_applyGPOSsubtable($lu, $luc, $luptr, $lucurrGlyph, $lucurrGID, ($lusubtable_offset - $this->GPOS_offset + $this->GSUB_length), $luType, $luFlag, $luMarkFilteringSet, $this->LuCoverage[$lu][$luc], $tag, 1, $is_old_spec);
3838
- if ($this->debugOTL && $shift) { $this->_dumpproc('GPOS', $lookupID, $subtable, $Type, $PosFormat, $ptr, $currGlyph, $level); }
3839
- if ($shift) { break; }
3840
- }
3841
- }
3842
- }
3843
-
3844
-
3845
- }
3846
- else { die("GPOS Lookup Type ".$Type.", Format ".$PosFormat." not supported."); }
3847
- }
3848
-
3849
- else { die("GPOS Lookup Type ".$Type." not supported."); }
3850
- }
3851
-
3852
- //////////////////////////////////////////////////////////////////////////////////
3853
- //////////////////////////////////////////////////////////////////////////////////
3854
- // GPOS / GSUB / GCOM (common) functions
3855
- //////////////////////////////////////////////////////////////////////////////////
3856
- //////////////////////////////////////////////////////////////////////////////////
3857
-
3858
- function checkContextMatch($Input, $Backtrack, $Lookahead, $ignore, $ptr) {
3859
- // Input etc are single numbers - GSUB Format 6.1
3860
- // Input starts with (1=>xxx)
3861
- // return false if no match, else an array of ptr for matches (0=>0, 1=>3,...)
3862
-
3863
- $current_syllable = (isset($this->OTLdata[$ptr]['syllable']) ? $this->OTLdata[$ptr]['syllable'] : 0);
3864
-
3865
- // BACKTRACK
3866
- $checkpos = $ptr;
3867
- for ($i=0;$i<count($Backtrack);$i++) {
3868
- $checkpos--;
3869
- while (isset($this->OTLdata[$checkpos]) && strpos($ignore, $this->OTLdata[$checkpos]['hex'])!==false) { $checkpos--; }
3870
- // If outside scope of current syllable - return no match
3871
- if ($this->restrictToSyllable && isset($this->OTLdata[$checkpos]['syllable']) && $this->OTLdata[$checkpos]['syllable'] != $current_syllable) {
3872
- return false;
3873
- }
3874
- else if (!isset($this->OTLdata[$checkpos]) || $this->OTLdata[$checkpos]['uni'] != $Backtrack[$i]) {
3875
- return false;
3876
- }
3877
- }
3878
-
3879
- // INPUT
3880
- $matched = array(0=>$ptr);
3881
- $checkpos = $ptr;
3882
- for ($i=1;$i<count($Input);$i++) {
3883
- $checkpos++;
3884
- while (isset($this->OTLdata[$checkpos]) && strpos($ignore, $this->OTLdata[$checkpos]['hex'])!==false) { $checkpos++; }
3885
- // If outside scope of current syllable - return no match
3886
- if ($this->restrictToSyllable && isset($this->OTLdata[$checkpos]['syllable']) && $this->OTLdata[$checkpos]['syllable'] != $current_syllable) {
3887
- return false;
3888
- }
3889
- else if (isset($this->OTLdata[$checkpos]) && $this->OTLdata[$checkpos]['uni'] == $Input[$i]) {
3890
- $matched[] = $checkpos;
3891
- }
3892
- else { return false; }
3893
- }
3894
-
3895
- // LOOKAHEAD
3896
- for ($i=0;$i<count($Lookahead);$i++) {
3897
- $checkpos++;
3898
- while (isset($this->OTLdata[$checkpos]) && strpos($ignore, $this->OTLdata[$checkpos]['hex'])!==false) { $checkpos++; }
3899
- // If outside scope of current syllable - return no match
3900
- if ($this->restrictToSyllable && isset($this->OTLdata[$checkpos]['syllable']) && $this->OTLdata[$checkpos]['syllable'] != $current_syllable) {
3901
- return false;
3902
- }
3903
- else if (!isset($this->OTLdata[$checkpos]) || $this->OTLdata[$checkpos]['uni'] != $Lookahead[$i]) {
3904
- return false;
3905
- }
3906
- }
3907
-
3908
- return $matched;
3909
- }
3910
-
3911
-
3912
- function checkContextMatchMultiple($Input, $Backtrack, $Lookahead, $ignore, $ptr, $class0excl='', $bclass0excl='', $lclass0excl='') {
3913
- // Input etc are string/array of glyph strings - GSUB Format 5.2, 5.3, 6.2, 6.3, GPOS Format 7.2, 7.3, 8.2, 8.3
3914
- // Input starts with (1=>xxx)
3915
- // return false if no match, else an array of ptr for matches (0=>0, 1=>3,...)
3916
- // $class0excl is the string of glyphs in all classes except Class 0 (GSUB 5.2, 6.2, GPOS 7.2, 8.2)
3917
- // $bclass0excl & $lclass0excl are the same for lookahead and backtrack (GSUB 6.2, GPOS 8.2)
3918
-
3919
- $current_syllable = (isset($this->OTLdata[$ptr]['syllable']) ? $this->OTLdata[$ptr]['syllable'] : 0);
3920
-
3921
- // BACKTRACK
3922
- $checkpos = $ptr;
3923
- for ($i=0;$i<count($Backtrack);$i++) {
3924
- $checkpos--;
3925
- while (isset($this->OTLdata[$checkpos]) && strpos($ignore, $this->OTLdata[$checkpos]['hex'])!==false) { $checkpos--; }
3926
- // If outside scope of current syllable - return no match
3927
- if ($this->restrictToSyllable && isset($this->OTLdata[$checkpos]['syllable']) && $this->OTLdata[$checkpos]['syllable'] != $current_syllable) {
3928
- return false;
3929
- }
3930
- // If Class 0 specified, matches anything NOT in $bclass0excl
3931
- else if (!$Backtrack[$i] && isset($this->OTLdata[$checkpos]) && strpos($bclass0excl,$this->OTLdata[$checkpos]['hex'])!==false) {
3932
- return false;
3933
- }
3934
- else if (!isset($this->OTLdata[$checkpos]) || strpos($Backtrack[$i], $this->OTLdata[$checkpos]['hex'])===false) {
3935
- return false;
3936
- }
3937
- }
3938
-
3939
- // INPUT
3940
- $matched = array(0=>$ptr);
3941
- $checkpos = $ptr;
3942
- for ($i=1;$i<count($Input);$i++) { // Start at 1 - already matched the first InputGlyph
3943
- $checkpos++;
3944
- while (isset($this->OTLdata[$checkpos]) && strpos($ignore, $this->OTLdata[$checkpos]['hex'])!==false) { $checkpos++; }
3945
- // If outside scope of current syllable - return no match
3946
- if ($this->restrictToSyllable && isset($this->OTLdata[$checkpos]['syllable']) && $this->OTLdata[$checkpos]['syllable'] != $current_syllable) {
3947
- return false;
3948
- }
3949
- // If Input Class 0 specified, matches anything NOT in $class0excl
3950
- else if (!$Input[$i] && isset($this->OTLdata[$checkpos]) && strpos($class0excl,$this->OTLdata[$checkpos]['hex'])===false) {
3951
- $matched[] = $checkpos;
3952
- }
3953
- else if (isset($this->OTLdata[$checkpos]) && strpos($Input[$i],$this->OTLdata[$checkpos]['hex'])!==false) {
3954
- $matched[] = $checkpos;
3955
- }
3956
- else { return false; }
3957
- }
3958
-
3959
- // LOOKAHEAD
3960
- for ($i=0;$i<count($Lookahead);$i++) {
3961
- $checkpos++;
3962
- while (isset($this->OTLdata[$checkpos]) && strpos($ignore, $this->OTLdata[$checkpos]['hex'])!==false) { $checkpos++; }
3963
- // If outside scope of current syllable - return no match
3964
- if ($this->restrictToSyllable && isset($this->OTLdata[$checkpos]['syllable']) && $this->OTLdata[$checkpos]['syllable'] != $current_syllable) {
3965
- return false;
3966
- }
3967
- // If Class 0 specified, matches anything NOT in $lclass0excl
3968
- else if (!$Lookahead[$i] && isset($this->OTLdata[$checkpos]) && strpos($lclass0excl,$this->OTLdata[$checkpos]['hex'])!==false) {
3969
- return false;
3970
- }
3971
- else if (!isset($this->OTLdata[$checkpos]) || strpos($Lookahead[$i],$this->OTLdata[$checkpos]['hex'])===false) {
3972
- return false;
3973
- }
3974
- }
3975
- return $matched;
3976
- }
3977
-
3978
- function checkContextMatchMultipleUni($Input, $Backtrack, $Lookahead, $ignore, $ptr, $class0excl=array(), $bclass0excl=array(), $lclass0excl=array()) {
3979
- // Input etc are array of glyphs - GSUB Format 5.2, 5.3, 6.2, 6.3, GPOS Format 7.2, 7.3, 8.2, 8.3
3980
- // Input starts with (1=>xxx)
3981
- // return false if no match, else an array of ptr for matches (0=>0, 1=>3,...)
3982
- // $class0excl is array of glyphs in all classes except Class 0 (GSUB 5.2, 6.2, GPOS 7.2, 8.2)
3983
- // $bclass0excl & $lclass0excl are the same for lookahead and backtrack (GSUB 6.2, GPOS 8.2)
3984
-
3985
- $current_syllable = (isset($this->OTLdata[$ptr]['syllable']) ? $this->OTLdata[$ptr]['syllable'] : 0);
3986
-
3987
- // BACKTRACK
3988
- $checkpos = $ptr;
3989
- for ($i=0;$i<count($Backtrack);$i++) {
3990
- $checkpos--;
3991
- while (isset($this->OTLdata[$checkpos]) && strpos($ignore, $this->OTLdata[$checkpos]['hex'])!==false) { $checkpos--; }
3992
- // If outside scope of current syllable - return no match
3993
- if ($this->restrictToSyllable && isset($this->OTLdata[$checkpos]['syllable']) && $this->OTLdata[$checkpos]['syllable'] != $current_syllable) {
3994
- return false;
3995
- }
3996
- // If Class 0 specified, matches anything NOT in $bclass0excl
3997
- else if (!$Backtrack[$i] && isset($this->OTLdata[$checkpos]) && isset($bclass0excl[$this->OTLdata[$checkpos]['uni']]) ) {
3998
- return false;
3999
- }
4000
- else if (!isset($this->OTLdata[$checkpos]) || !isset($Backtrack[$i][$this->OTLdata[$checkpos]['uni']])) {
4001
- return false;
4002
- }
4003
- }
4004
-
4005
- // INPUT
4006
- $matched = array(0=>$ptr);
4007
- $checkpos = $ptr;
4008
- for ($i=1;$i<count($Input);$i++) { // Start at 1 - already matched the first InputGlyph
4009
- $checkpos++;
4010
- while (isset($this->OTLdata[$checkpos]) && strpos($ignore, $this->OTLdata[$checkpos]['hex'])!==false) { $checkpos++; }
4011
- // If outside scope of current syllable - return no match
4012
- if ($this->restrictToSyllable && isset($this->OTLdata[$checkpos]['syllable']) && $this->OTLdata[$checkpos]['syllable'] != $current_syllable) {
4013
- return false;
4014
- }
4015
- // If Input Class 0 specified, matches anything NOT in $class0excl
4016
- else if (!$Input[$i] && isset($this->OTLdata[$checkpos]) && !isset($class0excl[$this->OTLdata[$checkpos]['uni']]) ) {
4017
- $matched[] = $checkpos;
4018
- }
4019
- else if (isset($this->OTLdata[$checkpos]) && isset($Input[$i][$this->OTLdata[$checkpos]['uni']])) {
4020
- $matched[] = $checkpos;
4021
- }
4022
- else { return false; }
4023
- }
4024
-
4025
- // LOOKAHEAD
4026
- for ($i=0;$i<count($Lookahead);$i++) {
4027
- $checkpos++;
4028
- while (isset($this->OTLdata[$checkpos]) && strpos($ignore, $this->OTLdata[$checkpos]['hex'])!==false) { $checkpos++; }
4029
- // If outside scope of current syllable - return no match
4030
- if ($this->restrictToSyllable && isset($this->OTLdata[$checkpos]['syllable']) && $this->OTLdata[$checkpos]['syllable'] != $current_syllable) {
4031
- return false;
4032
- }
4033
- // If Class 0 specified, matches anything NOT in $lclass0excl
4034
- else if (!$Lookahead[$i] && isset($this->OTLdata[$checkpos]) && isset($lclass0excl[$this->OTLdata[$checkpos]['uni']]) ) {
4035
- return false;
4036
- }
4037
- else if (!isset($this->OTLdata[$checkpos]) || !isset($Lookahead[$i][$this->OTLdata[$checkpos]['uni']])) {
4038
- return false;
4039
- }
4040
- }
4041
- return $matched;
4042
- }
4043
-
4044
-
4045
-
4046
-
4047
-
4048
- function _getClassDefinitionTable($offset) {
4049
- if (isset($this->LuDataCache[$this->fontkey][$offset])) {
4050
- $GlyphByClass = $this->LuDataCache[$this->fontkey][$offset];
4051
- }
4052
- else {
4053
- $this->seek($offset);
4054
- $ClassFormat = $this->read_ushort();
4055
- $GlyphClass = array();
4056
- // $GlyphByClass = array(0=>array()); // NB This forces an index[0]
4057
- if ($ClassFormat == 1) {
4058
- $StartGlyph = $this->read_ushort();
4059
- $GlyphCount = $this->read_ushort();
4060
- for ($i=0;$i<$GlyphCount;$i++) {
4061
- $GlyphClass[$i]['startGlyphID'] = $StartGlyph + $i;
4062
- $GlyphClass[$i]['endGlyphID'] = $StartGlyph + $i;
4063
- $GlyphClass[$i]['class'] = $this->read_ushort();
4064
- for($g=$GlyphClass[$i]['startGlyphID'];$g<=$GlyphClass[$i]['endGlyphID'];$g++) {
4065
- $GlyphByClass[$GlyphClass[$i]['class']][] = $this->glyphToChar($g);
4066
- }
4067
- }
4068
- }
4069
- else if ($ClassFormat == 2) {
4070
- $tableCount = $this->read_ushort();
4071
- for ($i=0;$i<$tableCount;$i++) {
4072
- $GlyphClass[$i]['startGlyphID'] = $this->read_ushort();
4073
- $GlyphClass[$i]['endGlyphID'] = $this->read_ushort();
4074
- $GlyphClass[$i]['class'] = $this->read_ushort();
4075
- for($g=$GlyphClass[$i]['startGlyphID'];$g<=$GlyphClass[$i]['endGlyphID'];$g++) {
4076
- $GlyphByClass[$GlyphClass[$i]['class']][] = $this->glyphToChar($g);
4077
- }
4078
- }
4079
- }
4080
- ksort($GlyphByClass);
4081
- $this->LuDataCache[$this->fontkey][$offset] = $GlyphByClass;
4082
- }
4083
- return $GlyphByClass;
4084
- }
4085
-
4086
- function count_bits($n) {
4087
- for ($c=0; $n; $c++) {
4088
- $n &= $n - 1; // clear the least significant bit set
4089
- }
4090
- return $c;
4091
- }
4092
-
4093
- function _getValueRecord($ValueFormat) { // Common ValueRecord for GPOS
4094
- // Only returns 3 possible: $vra['XPlacement'] $vra['YPlacement'] $vra['XAdvance']
4095
- $vra = array();
4096
- // Horizontal adjustment for placement - in design units
4097
- if (($ValueFormat & 0x0001) == 0x0001) { $vra['XPlacement'] = $this->read_short(); }
4098
- // Vertical adjustment for placement - in design units
4099
- if (($ValueFormat & 0x0002) == 0x0002) { $vra['YPlacement'] = $this->read_short(); }
4100
- // Horizontal adjustment for advance - in design units (only used for horizontal writing)
4101
- if (($ValueFormat & 0x0004) == 0x0004) { $vra['XAdvance'] = $this->read_short(); }
4102
- // Vertical adjustment for advance - in design units (only used for vertical writing)
4103
- if (($ValueFormat & 0x0008) == 0x0008) { $this->read_short(); }
4104
- // Offset to Device table for horizontal placement-measured from beginning of PosTable (may be NULL)
4105
- if (($ValueFormat & 0x0010) == 0x0010) { $this->read_ushort(); }
4106
- // Offset to Device table for vertical placement-measured from beginning of PosTable (may be NULL)
4107
- if (($ValueFormat & 0x0020) == 0x0020) { $this->read_ushort(); }
4108
- // Offset to Device table for horizontal advance-measured from beginning of PosTable (may be NULL)
4109
- if (($ValueFormat & 0x0040) == 0x0040) { $this->read_ushort(); }
4110
- // Offset to Device table for vertical advance-measured from beginning of PosTable (may be NULL)
4111
- if (($ValueFormat & 0x0080) == 0x0080) { $this->read_ushort(); }
4112
- return $vra;
4113
- }
4114
-
4115
- function _getAnchorTable($offset=0) {
4116
- if ($offset) { $this->seek($offset); }
4117
- $AnchorFormat = $this->read_ushort();
4118
- $XCoordinate = $this->read_short();
4119
- $YCoordinate = $this->read_short();
4120
- // Format 2 specifies additional link to contour point; Format 3 additional Device table
4121
- return array($XCoordinate, $YCoordinate);
4122
- }
4123
-
4124
- function _getMarkRecord($offset, $MarkPos) {
4125
- $this->seek($offset);
4126
- $MarkCount = $this->read_ushort();
4127
- $this->skip($MarkPos*4);
4128
- $Class = $this->read_ushort();
4129
- $MarkAnchor = $offset + $this->read_ushort(); // = Offset to anchor table
4130
- list($x,$y) = $this->_getAnchorTable($MarkAnchor );
4131
- $MarkRecord = array('Class'=>$Class, 'AnchorX'=>$x, 'AnchorY'=>$y);
4132
- return $MarkRecord;
4133
- }
4134
-
4135
- function _getGCOMignoreString($flag, $MarkFilteringSet) {
4136
- // If ignoreFlag set, combine all ignore glyphs into -> "(?:( 0FBA1| 0FBA2| 0FBA3)*)"
4137
- // else "()"
4138
- // for Input - set on secondary Lookup table if in Context, and set Backtrack and Lookahead on Context Lookup
4139
- $str = "";
4140
- $ignoreflag = 0;
4141
-
4142
- // Flag & 0xFF?? = MarkAttachmentType
4143
- if ($flag & 0xFF00) {
4144
- // "a lookup must ignore any mark glyphs that are not in the specified mark attachment class"
4145
- // $this->MarkAttachmentType is already adjusted for this i.e. contains all Marks except those in the MarkAttachmentClassDef table
4146
- $MarkAttachmentType = $flag >> 8;
4147
- $ignoreflag = $flag;
4148
- $str = $this->MarkAttachmentType[$MarkAttachmentType];
4149
- }
4150
-
4151
- // Flag & 0x0010 = UseMarkFilteringSet
4152
- if ($flag & 0x0010) {
4153
- die("This font [".$this->fontkey."] contains MarkGlyphSets - Not tested yet");
4154
- // Change also in ttfontsuni.php
4155
- if ($MarkFilteringSet=='') die("This font [".$this->fontkey."] contains MarkGlyphSets - but MarkFilteringSet not set");
4156
- $str = $this->MarkGlyphSets[$MarkFilteringSet];
4157
- }
4158
-
4159
- // If Ignore Marks set, supercedes any above
4160
- // Flag & 0x0008 = Ignore Marks - (unless already done with MarkAttachmentType)
4161
- if (($flag & 0x0008) == 0x0008 && ($flag & 0xFF00) == 0) {
4162
- $ignoreflag = 8;
4163
- $str = $this->GlyphClassMarks;
4164
- }
4165
-
4166
- // Flag & 0x0004 = Ignore Ligatures
4167
- if (($flag & 0x0004) == 0x0004) {
4168
- $ignoreflag += 4;
4169
- if ($str) { $str .= "|"; }
4170
- $str .= $this->GlyphClassLigatures;
4171
- }
4172
- // Flag & 0x0002 = Ignore BaseGlyphs
4173
- if (($flag & 0x0002) == 0x0002) {
4174
- $ignoreflag += 2;
4175
- if ($str) { $str .= "|"; }
4176
- $str .= $this->GlyphClassBases;
4177
- }
4178
- if ($str) { return "((?:(?:" . $str . "))*)"; }
4179
- else return "()";
4180
- }
4181
-
4182
- function _checkGCOMignore($flag, $glyph, $MarkFilteringSet) {
4183
- $ignore = false;
4184
- // Flag & 0x0008 = Ignore Marks - (unless already done with MarkAttachmentType)
4185
- if (($flag & 0x0008 && ($flag & 0xFF00) == 0) && strpos($this->GlyphClassMarks,$glyph)) { $ignore = true; }
4186
- if (($flag & 0x0004) && strpos($this->GlyphClassLigatures,$glyph)) { $ignore = true; }
4187
- if (($flag & 0x0002) && strpos($this->GlyphClassBases,$glyph)) { $ignore = true; }
4188
- // Flag & 0xFF?? = MarkAttachmentType
4189
- if ($flag & 0xFF00) {
4190
- // "a lookup must ignore any mark glyphs that are not in the specified mark attachment class"
4191
- // $this->MarkAttachmentType is already adjusted for this i.e. contains all Marks except those in the MarkAttachmentClassDef table
4192
- if (strpos($this->MarkAttachmentType[($flag >> 8)],$glyph)) { $ignore = true; }
4193
- }
4194
- // Flag & 0x0010 = UseMarkFilteringSet
4195
- if (($flag & 0x0010) && strpos($this->MarkGlyphSets[$MarkFilteringSet],$glyph)) { $ignore = true; }
4196
- return $ignore;
4197
- }
4198
-
4199
- ////////////////////////////////////////////////////////////////
4200
- ////////////////////////////////////////////////////////////////
4201
- ////////// BIDI ALGORITHM ////////////////////////
4202
- ////////////////////////////////////////////////////////////////
4203
- ////////////////////////////////////////////////////////////////
4204
- ////////////////////////////////////////////////////////////////
4205
- ////////////////////////////////////////////////////////////////
4206
- // These functions are called from mpdf after GSUB/GPOS has taken place
4207
- // At this stage the bidi-type is in string form
4208
- ////////////////////////////////////////////////////////////////
4209
- ////////////////////////////////////////////////////////////////
4210
- /*
4211
- Bidirectional Character Types
4212
- =============================
4213
- Type Description General Scope
4214
- Strong
4215
- L Left-to-Right LRM, most alphabetic, syllabic, Han ideographs, non-European or non-Arabic digits, ...
4216
- LRE Left-to-Right Embedding LRE
4217
- LRO Left-to-Right Override LRO
4218
- R Right-to-Left RLM, Hebrew alphabet, and related punctuation
4219
- AL Right-to-Left Arabic Arabic, Thaana, and Syriac alphabets, most punctuation specific to those scripts, ...
4220
- RLE Right-to-Left Embedding RLE
4221
- RLO Right-to-Left Override RLO
4222
- Weak
4223
- PDF Pop Directional Format PDF
4224
- EN European Number European digits, Eastern Arabic-Indic digits, ...
4225
- ES European Number Separator Plus sign, minus sign
4226
- ET European Number Terminator Degree sign, currency symbols, ...
4227
- AN Arabic Number Arabic-Indic digits, Arabic decimal and thousands separators, ...
4228
- CS Common Number Separator Colon, comma, full stop (period), No-break space, ...
4229
- NSM Nonspacing Mark Characters marked Mn (Nonspacing_Mark) and Me (Enclosing_Mark) in the Unicode Character Database
4230
- BN Boundary Neutral Default ignorables, non-characters, and control characters, other than those explicitly given other types.
4231
- Neutral
4232
- B Paragraph Separator Paragraph separator, appropriate Newline Functions, higher-level protocol paragraph determination
4233
- S Segment Separator Tab
4234
- WS Whitespace Space, figure space, line separator, form feed, General Punctuation spaces, ...
4235
- ON Other Neutrals All other characters, including OBJECT REPLACEMENT CHARACTER
4236
- */
4237
-
4238
- function _bidiSort($ta, $str='', $dir, &$chunkOTLdata, $useGPOS) {
4239
-
4240
- $pel = 0; // paragraph embedding level
4241
- $maxlevel = 0;
4242
- $numchars = count($chunkOTLdata['char_data']);
4243
-
4244
- // Set the initial paragraph embedding level
4245
- if ($dir == 'rtl') { $pel = 1; }
4246
- else { $pel = 0; }
4247
-
4248
-
4249
- // X1. Begin by setting the current embedding level to the paragraph embedding level. Set the directional override status to neutral.
4250
- // Current Embedding Level
4251
- $cel = $pel;
4252
- // directional override status (-1 is Neutral)
4253
- $dos = -1;
4254
- $remember = array();
4255
-
4256
- // Array of characters data
4257
- $chardata = Array();
4258
-
4259
- // Process each character iteratively, applying rules X2 through X9. Only embedding levels from 0 to 61 are valid in this phase.
4260
- // In the resolution of levels in rules I1 and I2, the maximum embedding level of 62 can be reached.
4261
- for ($i=0; $i < $numchars; ++$i) {
4262
- if ($chunkOTLdata['char_data'][$i]['uni'] == 8235) { // RLE
4263
- // X2. With each RLE, compute the least greater odd embedding level.
4264
- // a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to neutral.
4265
- // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
4266
- $next_level = $cel + ($cel % 2) + 1;
4267
- if ($next_level < 62) {
4268
- $remember[] = array('num' => 8235, 'cel' => $cel, 'dos' => $dos);
4269
- $cel = $next_level;
4270
- $dos = -1;
4271
- }
4272
- }
4273
- else if ($chunkOTLdata['char_data'][$i]['uni'] == 8234) { // LRE
4274
- // X3. With each LRE, compute the least greater even embedding level.
4275
- // a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to neutral.
4276
- // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
4277
- $next_level = $cel + 2 - ($cel % 2);
4278
- if ( $next_level < 62 ) {
4279
- $remember[] = array('num' => 8234, 'cel' => $cel, 'dos' => $dos);
4280
- $cel = $next_level;
4281
- $dos = -1;
4282
- }
4283
- }
4284
- else if ($chunkOTLdata['char_data'][$i]['uni'] == 8238) { // RLO
4285
- // X4. With each RLO, compute the least greater odd embedding level.
4286
- // a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to right-to-left.
4287
- // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
4288
- $next_level = $cel + ($cel % 2) + 1;
4289
- if ($next_level < 62) {
4290
- $remember[] = array('num' => 8238, 'cel' => $cel, 'dos' => $dos);
4291
- $cel = $next_level;
4292
- $dos = UCDN::BIDI_CLASS_R;
4293
- }
4294
- }
4295
- else if ($chunkOTLdata['char_data'][$i]['uni'] == 8237) { // LRO
4296
- // X5. With each LRO, compute the least greater even embedding level.
4297
- // a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to left-to-right.
4298
- // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
4299
- $next_level = $cel + 2 - ($cel % 2);
4300
- if ( $next_level < 62 ) {
4301
- $remember[] = array('num' => 8237, 'cel' => $cel, 'dos' => $dos);
4302
- $cel = $next_level;
4303
- $dos = UCDN::BIDI_CLASS_L;
4304
- }
4305
- }
4306
- else if ($chunkOTLdata['char_data'][$i]['uni'] == 8236) { // PDF
4307
- // X7. With each PDF, determine the matching embedding or override code. If there was a valid matching code, restore (pop) the last remembered (pushed) embedding level and directional override.
4308
- if (count($remember)) {
4309
- $last = count($remember ) - 1;
4310
- if (($remember[$last]['num'] == 8235) || ($remember[$last]['num'] == 8234) || ($remember[$last]['num'] == 8238) ||
4311
- ($remember[$last]['num'] == 8237)) {
4312
- $match = array_pop($remember);
4313
- $cel = $match['cel'];
4314
- $dos = $match['dos'];
4315
- }
4316
- }
4317
- }
4318
- else if ($chunkOTLdata['char_data'][$i]['uni'] == 10) { // NEW LINE
4319
- // Reset to start values
4320
- $cel = $pel;
4321
- $dos = -1;
4322
- $remember = array();
4323
- }
4324
- else {
4325
- // X6. For all types besides RLE, LRE, RLO, LRO, and PDF:
4326
- // a. Set the level of the current character to the current embedding level.
4327
- // b. When the directional override status is not neutral, reset the current character type to directional override status.
4328
- if ($dos != -1) { $chardir = $dos; }
4329
- else {
4330
- $chardir = $chunkOTLdata['char_data'][$i]['bidi_class'];
4331
- }
4332
- // stores string characters and other information
4333
- if (isset($chunkOTLdata['GPOSinfo'][$i])) { $gpos = $chunkOTLdata['GPOSinfo'][$i]; }
4334
- else $gpos = '';
4335
- $chardata[] = array('char' => $chunkOTLdata['char_data'][$i]['uni'], 'level' => $cel, 'type' => $chardir, 'group' => $chunkOTLdata['group']{$i}, 'GPOSinfo' => $gpos);
4336
- }
4337
- }
4338
-
4339
- $numchars = count($chardata);
4340
-
4341
- // X8. All explicit directional embeddings and overrides are completely terminated at the end of each paragraph.
4342
- // Paragraph separators are not included in the embedding.
4343
- // X9. Remove all RLE, LRE, RLO, LRO, and PDF codes.
4344
- // This is effectively done by only saving other codes to chardata
4345
-
4346
- // X10. Determine the start-of-sequence (sor) and end-of-sequence (eor) types, either L or R, for each isolating run sequence. These depend on the higher of the two levels on either side of the sequence boundary:
4347
- // For sor, compare the level of the first character in the sequence with the level of the character preceding it in the paragraph or if there is none, with the paragraph embedding level.
4348
- // For eor, compare the level of the last character in the sequence with the level of the character following it in the paragraph or if there is none, with the paragraph embedding level.
4349
- // If the higher level is odd, the sor or eor is R; otherwise, it is L.
4350
-
4351
- $prelevel = $pel;
4352
- $postlevel = $pel;
4353
- $cel = $prelevel; // current embedding level
4354
- for ($i=0; $i < $numchars; ++$i) {
4355
- $level = $chardata[$i]['level'];
4356
- if ($i==0) { $left = $prelevel; }
4357
- else { $left = $chardata[$i-1]['level']; }
4358
- if ($i==($numchars-1)) { $right = $postlevel; }
4359
- else { $right = $chardata[$i+1]['level']; }
4360
- $chardata[$i]['sor'] = max($left, $level) % 2 ? UCDN::BIDI_CLASS_R : UCDN::BIDI_CLASS_L;
4361
- $chardata[$i]['eor'] = max($right, $level) % 2 ? UCDN::BIDI_CLASS_R : UCDN::BIDI_CLASS_L;
4362
- }
4363
-
4364
-
4365
-
4366
- // 3.3.3 Resolving Weak Types
4367
- // Weak types are now resolved one level run at a time. At level run boundaries where the type of the character on the other side of the boundary is required, the type assigned to sor or eor is used.
4368
- // Nonspacing marks are now resolved based on the previous characters.
4369
-
4370
- // W1. Examine each nonspacing mark (NSM) in the level run, and change the type of the NSM to the type of the previous character. If the NSM is at the start of the level run, it will get the type of sor.
4371
- for ($i=0; $i < $numchars; ++$i) {
4372
- if ($chardata[$i]['type'] == UCDN::BIDI_CLASS_NSM) {
4373
- if ($i==0 || $chardata[$i]['level']!=$chardata[$i-1]['level']) {
4374
- $chardata[$i]['type'] = $chardata[$i]['sor'];
4375
- }
4376
- else {
4377
- $chardata[$i]['type'] = $chardata[($i-1)]['type'];
4378
- }
4379
- }
4380
- }
4381
-
4382
- // W2. Search backward from each instance of a European number until the first strong type (R, L, AL, or sor) is found. If an AL is found, change the type of the European number to Arabic number.
4383
- $prevlevel = -1;
4384
- $levcount = 0;
4385
- for ($i=0; $i < $numchars; ++$i) {
4386
- if ($chardata[$i]['type'] == UCDN::BIDI_CLASS_EN) {
4387
- $found = false;
4388
- for ($j=$levcount; $j >= 0; $j--) {
4389
- if ($chardata[$j]['type'] == UCDN::BIDI_CLASS_AL) { $chardata[$i]['type'] = UCDN::BIDI_CLASS_AN; $found = true; break; }
4390
- else if (($chardata[$j]['type'] == UCDN::BIDI_CLASS_L) || ($chardata[$j]['type'] == UCDN::BIDI_CLASS_R)) { $found = true; break; }
4391
- }
4392
- }
4393
- if ($chardata[$i]['level'] != $prevlevel) { $levcount = 0; }
4394
- else { ++$levcount; }
4395
- $prevlevel = $chardata[$i]['level'];
4396
- }
4397
-
4398
- // W3. Change all ALs to R.
4399
- for ($i=0; $i < $numchars; ++$i) {
4400
- if ($chardata[$i]['type'] == UCDN::BIDI_CLASS_AL) { $chardata[$i]['type'] = UCDN::BIDI_CLASS_R; }
4401
- }
4402
-
4403
- // W4. A single European separator between two European numbers changes to a European number. A single common separator between two numbers of the same type changes to that type.
4404
- for ($i=1; $i < $numchars; ++$i) {
4405
- if ( ($i+1) < $numchars && $chardata[($i)]['level'] == $chardata[($i+1)]['level'] && $chardata[($i)]['level'] == $chardata[($i-1)]['level']) {
4406
- if ($chardata[$i]['type'] == UCDN::BIDI_CLASS_ES && $chardata[($i-1)]['type'] == UCDN::BIDI_CLASS_EN && $chardata[($i+1)]['type'] == UCDN::BIDI_CLASS_EN) {
4407
- $chardata[$i]['type'] = UCDN::BIDI_CLASS_EN;
4408
- }
4409
- else if ($chardata[$i]['type'] == UCDN::BIDI_CLASS_CS && $chardata[($i-1)]['type'] == UCDN::BIDI_CLASS_EN && $chardata[($i+1)]['type'] == UCDN::BIDI_CLASS_EN) {
4410
- $chardata[$i]['type'] = UCDN::BIDI_CLASS_EN;
4411
- }
4412
- else if ($chardata[$i]['type'] == UCDN::BIDI_CLASS_CS && $chardata[($i-1)]['type'] == UCDN::BIDI_CLASS_AN && $chardata[($i+1)]['type'] == UCDN::BIDI_CLASS_AN) {
4413
- $chardata[$i]['type'] = UCDN::BIDI_CLASS_AN;
4414
- }
4415
- }
4416
- }
4417
-
4418
- // W5. A sequence of European terminators adjacent to European numbers changes to all European numbers.
4419
- for ($i=0; $i < $numchars; ++$i) {
4420
- if ($chardata[$i]['type'] == UCDN::BIDI_CLASS_ET) {
4421
- if ($i > 0 && $chardata[($i-1)]['type'] == UCDN::BIDI_CLASS_EN && $chardata[($i)]['level'] == $chardata[($i-1)]['level']) {
4422
- $chardata[$i]['type'] = UCDN::BIDI_CLASS_EN;
4423
- }
4424
- else {
4425
- $j = $i+1;
4426
- while ($j < $numchars && $chardata[$j]['level'] == $chardata[$i]['level'] ) {
4427
- if ($chardata[$j]['type'] == UCDN::BIDI_CLASS_EN) {
4428
- $chardata[$i]['type'] = UCDN::BIDI_CLASS_EN;
4429
- break;
4430
- }
4431
- else if ($chardata[$j]['type'] != UCDN::BIDI_CLASS_ET) { break; }
4432
- ++$j;
4433
- }
4434
- }
4435
- }
4436
- }
4437
-
4438
- // W6. Otherwise, separators and terminators change to Other Neutral.
4439
- for ($i=0; $i < $numchars; ++$i) {
4440
- if (($chardata[$i]['type'] == UCDN::BIDI_CLASS_ET) || ($chardata[$i]['type'] == UCDN::BIDI_CLASS_ES) || ($chardata[$i]['type'] == UCDN::BIDI_CLASS_CS)) {
4441
- $chardata[$i]['type'] = UCDN::BIDI_CLASS_ON;
4442
- }
4443
- }
4444
-
4445
- //W7. Search backward from each instance of a European number until the first strong type (R, L, or sor) is found. If an L is found, then change the type of the European number to L.
4446
- for ($i=0; $i < $numchars; ++$i) {
4447
- if ($chardata[$i]['type'] == UCDN::BIDI_CLASS_EN) {
4448
- if ($i==0) { // Start of Level run
4449
- if ($chardata[$i]['sor']==UCDN::BIDI_CLASS_L) $chardata[$i]['type'] = $chardata[$i]['sor'];
4450
- }
4451
- else {
4452
- for ($j=$i-1; $j >= 0; $j--) {
4453
- if ($chardata[$j]['level'] != $chardata[$i]['level']) { // Level run boundary
4454
- if ($chardata[$j+1]['sor']==UCDN::BIDI_CLASS_L) $chardata[$i]['type'] = $chardata[$j+1]['sor'];
4455
- break;
4456
- }
4457
- else if ($chardata[$j]['type'] == UCDN::BIDI_CLASS_L) {
4458
- $chardata[$i]['type'] = UCDN::BIDI_CLASS_L;
4459
- break;
4460
- }
4461
- else if ($chardata[$j]['type'] == UCDN::BIDI_CLASS_R) {
4462
- break;
4463
- }
4464
- }
4465
- }
4466
- }
4467
- }
4468
-
4469
- // N1. A sequence of neutrals takes the direction of the surrounding strong text if the text on both sides has the same direction. European and Arabic numbers act as if they were R in terms of their influence on neutrals. Start-of-level-run (sor) and end-of-level-run (eor) are used at level run boundaries.
4470
- for ($i=0; $i < $numchars; ++$i) {
4471
- if ($chardata[$i]['type'] == UCDN::BIDI_CLASS_ON || $chardata[$i]['type'] == UCDN::BIDI_CLASS_WS) {
4472
- $left = -1;
4473
- // LEFT
4474
- if ($i==0) { // first char
4475
- $left = $chardata[($i)]['sor'];
4476
- }
4477
- else if ($chardata[($i-1)]['level'] != $chardata[($i)]['level']) { // run boundary
4478
- $left = $chardata[($i)]['sor'];
4479
- }
4480
- else if ($chardata[($i-1)]['type'] == UCDN::BIDI_CLASS_L) {
4481
- $left = UCDN::BIDI_CLASS_L;
4482
- }
4483
- else if ($chardata[($i-1)]['type'] == UCDN::BIDI_CLASS_R || $chardata[($i-1)]['type'] == UCDN::BIDI_CLASS_EN || $chardata[($i-1)]['type'] == UCDN::BIDI_CLASS_AN) {
4484
- $left = UCDN::BIDI_CLASS_R;
4485
- }
4486
- // RIGHT
4487
- $right = -1;
4488
- $j=$i;
4489
- // move to the right of any following neutrals OR hit a run boundary
4490
- while(($chardata[$j]['type'] == UCDN::BIDI_CLASS_ON || $chardata[$j]['type'] == UCDN::BIDI_CLASS_WS) && $j<=($numchars-1)) {
4491
- if ($j==($numchars-1)) { // last char
4492
- $right = $chardata[($j)]['eor'];
4493
- break;
4494
- }
4495
- else if ($chardata[($j+1)]['level'] != $chardata[($j)]['level']) { // run boundary
4496
- $right = $chardata[($j)]['eor'];
4497
- break;
4498
- }
4499
- else if ($chardata[($j+1)]['type'] == UCDN::BIDI_CLASS_L) {
4500
- $right = UCDN::BIDI_CLASS_L;
4501
- break;
4502
- }
4503
- else if ($chardata[($j+1)]['type'] == UCDN::BIDI_CLASS_R || $chardata[($j+1)]['type'] == UCDN::BIDI_CLASS_EN || $chardata[($j+1)]['type'] == UCDN::BIDI_CLASS_AN) {
4504
- $right = UCDN::BIDI_CLASS_R;
4505
- break;
4506
- }
4507
- $j++;
4508
- }
4509
- if ($left > -1 && $left==$right) {
4510
- $chardata[$i]['orig_type'] = $chardata[$i]['type']; // Need to store the original 'WS' for reference in L1 below
4511
- $chardata[$i]['type'] = $left;
4512
- }
4513
- }
4514
- }
4515
-
4516
- // N2. Any remaining neutrals take the embedding direction
4517
- for ($i=0; $i < $numchars; ++$i) {
4518
- if ($chardata[$i]['type'] == UCDN::BIDI_CLASS_ON || $chardata[$i]['type'] == UCDN::BIDI_CLASS_WS) {
4519
- $chardata[$i]['type'] = ($chardata[$i]['level'] % 2) ? UCDN::BIDI_CLASS_R : UCDN::BIDI_CLASS_L;
4520
- $chardata[$i]['orig_type'] = $chardata[$i]['type']; // Need to store the original 'WS' for reference in L1 below
4521
- }
4522
- }
4523
-
4524
- // I1. For all characters with an even (left-to-right) embedding direction, those of type R go up one level and those of type AN or EN go up two levels.
4525
- // I2. For all characters with an odd (right-to-left) embedding direction, those of type L, EN or AN go up one level.
4526
- for ($i=0; $i < $numchars; ++$i) {
4527
- $odd = $chardata[$i]['level'] % 2;
4528
- if ($odd) {
4529
- if (($chardata[$i]['type'] == UCDN::BIDI_CLASS_L) || ($chardata[$i]['type'] == UCDN::BIDI_CLASS_AN) || ($chardata[$i]['type'] == UCDN::BIDI_CLASS_EN)) {
4530
- $chardata[$i]['level'] += 1;
4531
- }
4532
- }
4533
- else {
4534
- if ($chardata[$i]['type'] == UCDN::BIDI_CLASS_R) { $chardata[$i]['level'] += 1; }
4535
- else if (($chardata[$i]['type'] == UCDN::BIDI_CLASS_AN) || ($chardata[$i]['type'] == UCDN::BIDI_CLASS_EN)) { $chardata[$i]['level'] += 2; }
4536
- }
4537
- $maxlevel = max($chardata[$i]['level'],$maxlevel);
4538
- }
4539
-
4540
- // NB
4541
- // Separate into lines at this point************
4542
- //
4543
-
4544
- // L1. On each line, reset the embedding level of the following characters to the paragraph embedding level:
4545
- // 1. Segment separators (Tab) 'S',
4546
- // 2. Paragraph separators 'B',
4547
- // 3. Any sequence of whitespace characters 'WS' preceding a segment separator or paragraph separator, and
4548
- // 4. Any sequence of whitespace characters 'WS' at the end of the line.
4549
- // The types of characters used here are the original types, not those modified by the previous phase cf N1 and N2*******
4550
- // Because a Paragraph Separator breaks lines, there will be at most one per line, at the end of that line.
4551
-
4552
- for ($i=($numchars-1); $i>0; $i--) {
4553
- if ($chardata[$i]['type'] == UCDN::BIDI_CLASS_WS || (isset($chardata[$i]['orig_type']) && $chardata[$i]['orig_type'] == UCDN::BIDI_CLASS_WS)) {
4554
- $chardata[$i]['level'] = $pel;
4555
- }
4556
- else { break; }
4557
- }
4558
-
4559
-
4560
- // L2. From the highest level found in the text to the lowest odd level on each line, including intermediate levels not actually present in the text, reverse any contiguous sequence of characters that are at that level or higher.
4561
- for ($j=$maxlevel; $j > 0; $j--) {
4562
- $ordarray = array();
4563
- $revarr = array();
4564
- $onlevel = false;
4565
- for ($i=0; $i < $numchars; ++$i) {
4566
- if ($chardata[$i]['level'] >= $j) {
4567
- $onlevel = true;
4568
-
4569
- // L4. A character is depicted by a mirrored glyph if and only if (a) the resolved directionality of that character is R, and (b) the Bidi_Mirrored property value of that character is true.
4570
- if (isset(UCDN::$mirror_pairs[$chardata[$i]['char']]) && $chardata[$i]['type']==UCDN::BIDI_CLASS_R) {
4571
- $chardata[$i]['char'] = UCDN::$mirror_pairs[$chardata[$i]['char']];
4572
- }
4573
-
4574
- $revarr[] = $chardata[$i];
4575
- }
4576
- else {
4577
- if ($onlevel) {
4578
- $revarr = array_reverse($revarr);
4579
- $ordarray = array_merge($ordarray, $revarr);
4580
- $revarr = Array();
4581
- $onlevel = false;
4582
- }
4583
- $ordarray[] = $chardata[$i];
4584
- }
4585
- }
4586
- if ($onlevel) {
4587
- $revarr = array_reverse($revarr);
4588
- $ordarray = array_merge($ordarray, $revarr);
4589
- }
4590
- $chardata = $ordarray;
4591
- }
4592
-
4593
- $group = '';
4594
- $e = '';
4595
- $GPOS = array();
4596
- $cctr = 0;
4597
- $rtl_content = 0x0;
4598
- foreach ($chardata as $cd) {
4599
- $e.=code2utf($cd['char']);
4600
- $group .= $cd['group'];
4601
- if ($useGPOS && is_array($cd['GPOSinfo'])) {
4602
- $GPOS[$cctr] = $cd['GPOSinfo'];
4603
- $GPOS[$cctr]['wDir'] = ($cd['level'] % 2) ? 'RTL' : 'LTR';
4604
- }
4605
- if($cd['type']==UCDN::BIDI_CLASS_L) { $rtl_content |= 1; }
4606
- else if($cd['type']==UCDN::BIDI_CLASS_R) { $rtl_content |= 2; }
4607
- $cctr++;
4608
- }
4609
-
4610
-
4611
- $chunkOTLdata['group'] = $group ;
4612
- if ($useGPOS) {
4613
- $chunkOTLdata['GPOSinfo'] = $GPOS;
4614
- }
4615
-
4616
- return array($e,$rtl_content);
4617
- }
4618
-
4619
- // **********************************************************************************************
4620
- // The following versions for BidiSort work on amalgamated chunks to process the whole paragraph
4621
- // Firstly set the level in the OTLdata - called from fn printbuffer() [_bidiPrepare]
4622
- // Secondly re-order - called from fn writeFlowingBlock and FinishFlowingBlock, when already divided into lines. [_bidiReorder]
4623
- // **********************************************************************************************
4624
-
4625
- function _bidiPrepare(&$para, $dir) {
4626
-
4627
- // Set the initial paragraph embedding level
4628
- $pel = 0; // paragraph embedding level
4629
- if ($dir == 'rtl') { $pel = 1; }
4630
-
4631
- // X1. Begin by setting the current embedding level to the paragraph embedding level. Set the directional override status to neutral.
4632
- // Current Embedding Level
4633
- $cel = $pel;
4634
- // directional override status (-1 is Neutral)
4635
- $dos = -1;
4636
- $remember = array();
4637
- $controlchars = false;
4638
- $strongrtl = false;
4639
- $diid = 0; // direction isolate ID
4640
- $dictr = 0; // direction isolate counter
4641
-
4642
- // Process each character iteratively, applying rules X2 through X9. Only embedding levels from 0 to 61 are valid in this phase.
4643
- // In the resolution of levels in rules I1 and I2, the maximum embedding level of 62 can be reached.
4644
- $numchunks = count($para);
4645
- for ($nc=0;$nc<$numchunks;$nc++) {
4646
- $chunkOTLdata =& $para[$nc][18];
4647
-
4648
- $numchars = count($chunkOTLdata['char_data']);
4649
- for ($i=0; $i < $numchars; ++$i) {
4650
- if ($chunkOTLdata['char_data'][$i]['uni'] == 8235) { // RLE
4651
- // X2. With each RLE, compute the least greater odd embedding level.
4652
- // a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to neutral.
4653
- // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
4654
- $next_level = $cel + ($cel % 2) + 1;
4655
- if ($next_level < 62) {
4656
- $remember[] = array('num' => 8235, 'cel' => $cel, 'dos' => $dos);
4657
- $cel = $next_level;
4658
- $dos = -1;
4659
- $controlchars = true;
4660
- }
4661
- }
4662
- else if ($chunkOTLdata['char_data'][$i]['uni'] == 8234) { // LRE
4663
- // X3. With each LRE, compute the least greater even embedding level.
4664
- // a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to neutral.
4665
- // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
4666
- $next_level = $cel + 2 - ($cel % 2);
4667
- if ( $next_level < 62 ) {
4668
- $remember[] = array('num' => 8234, 'cel' => $cel, 'dos' => $dos);
4669
- $cel = $next_level;
4670
- $dos = -1;
4671
- $controlchars = true;
4672
- }
4673
- }
4674
- else if ($chunkOTLdata['char_data'][$i]['uni'] == 8238) { // RLO
4675
- // X4. With each RLO, compute the least greater odd embedding level.
4676
- // a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to right-to-left.
4677
- // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
4678
- $next_level = $cel + ($cel % 2) + 1;
4679
- if ($next_level < 62) {
4680
- $remember[] = array('num' => 8238, 'cel' => $cel, 'dos' => $dos);
4681
- $cel = $next_level;
4682
- $dos = UCDN::BIDI_CLASS_R;
4683
- $controlchars = true;
4684
- }
4685
- }
4686
- else if ($chunkOTLdata['char_data'][$i]['uni'] == 8237) { // LRO
4687
- // X5. With each LRO, compute the least greater even embedding level.
4688
- // a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to left-to-right.
4689
- // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
4690
- $next_level = $cel + 2 - ($cel % 2);
4691
- if ( $next_level < 62 ) {
4692
- $remember[] = array('num' => 8237, 'cel' => $cel, 'dos' => $dos);
4693
- $cel = $next_level;
4694
- $dos = UCDN::BIDI_CLASS_L;
4695
- $controlchars = true;
4696
- }
4697
- }
4698
- else if ($chunkOTLdata['char_data'][$i]['uni'] == 8236) { // PDF
4699
- // X7. With each PDF, determine the matching embedding or override code. If there was a valid matching code, restore (pop) the last remembered (pushed) embedding level and directional override.
4700
- if (count($remember)) {
4701
- $last = count($remember ) - 1;
4702
- if (($remember[$last]['num'] == 8235) || ($remember[$last]['num'] == 8234) || ($remember[$last]['num'] == 8238) ||
4703
- ($remember[$last]['num'] == 8237)) {
4704
- $match = array_pop($remember);
4705
- $cel = $match['cel'];
4706
- $dos = $match['dos'];
4707
- }
4708
- }
4709
- }
4710
- else if ($chunkOTLdata['char_data'][$i]['uni'] == 8294 || $chunkOTLdata['char_data'][$i]['uni'] == 8295 ||
4711
- $chunkOTLdata['char_data'][$i]['uni'] == 8296) { // LRI // RLI // FSI
4712
- // X5a. With each RLI:
4713
- // X5b. With each LRI:
4714
- // X5c. With each FSI, apply rules P2 and P3 for First Strong character
4715
- // Set the RLI/LRI/FSI embedding level to the embedding level of the last entry on the directional status stack.
4716
- if ($dos != -1) { $chardir = $dos; }
4717
- else { $chardir = $chunkOTLdata['char_data'][$i]['bidi_class']; }
4718
- $chunkOTLdata['char_data'][$i]['level'] = $cel;
4719
- $chunkOTLdata['char_data'][$i]['type'] = $chardir;
4720
- $chunkOTLdata['char_data'][$i]['diid'] = $diid;
4721
-
4722
- $fsi = '';
4723
- // X5c. With each FSI, apply rules P2 and P3 within the isolate run for First Strong character
4724
- if ($chunkOTLdata['char_data'][$i]['uni'] == 8296) { // FSI
4725
- $lvl = 0;
4726
- $nc2 = $nc;
4727
- $i2 = $i;
4728
- while (!($nc2==($numchunks-1) && $i2==((count($para[$nc2][18]['char_data']))-1))) { // while not at end of last chunk
4729
- $i2++;
4730
- if ($i2 >= count($para[$nc2][18]['char_data'])) {
4731
- $nc2++;
4732
- $i2 = 0;
4733
- }
4734
- if ($lvl > 0) { continue; }
4735
- if ($para[$nc2][18]['char_data'][$i2]['uni'] == 8294 || $para[$nc2][18]['char_data'][$i2]['uni'] == 8295 || $para[$nc2][18]['char_data'][$i2]['uni'] == 8296) {
4736
- $lvl++;
4737
- continue;
4738
- }
4739
- if ($para[$nc2][18]['char_data'][$i2]['uni'] == 8297) {
4740
- $lvl--;
4741
- if ($lvl < 0) { break; }
4742
- }
4743
- if ($para[$nc2][18]['char_data'][$i2]['bidi_class'] === UCDN::BIDI_CLASS_L || $para[$nc2][18]['char_data'][$i2]['bidi_class'] == UCDN::BIDI_CLASS_AL || $para[$nc2][18]['char_data'][$i2]['bidi_class'] === UCDN::BIDI_CLASS_R) {
4744
- $fsi = $para[$nc2][18]['char_data'][$i2]['bidi_class'];
4745
- break;
4746
- }
4747
- }
4748
- // if fsi not found, fsi is same as paragraph embedding level
4749
- if (!$fsi && $fsi!==0) {
4750
- if ($pel==1) { $fsi = UCDN::BIDI_CLASS_R ; }
4751
- else { $fsi = UCDN::BIDI_CLASS_L ; }
4752
- }
4753
- }
4754
-
4755
- if ($chunkOTLdata['char_data'][$i]['uni'] == 8294 || $fsi === UCDN::BIDI_CLASS_L ) { // LRI or FSI-L
4756
- // Compute the least even embedding level greater than the embedding level of the last entry on the directional status stack.
4757
- $next_level = $cel + 2 - ($cel % 2);
4758
- }
4759
- else if ($chunkOTLdata['char_data'][$i]['uni'] == 8295 || $fsi == UCDN::BIDI_CLASS_R || $fsi == UCDN::BIDI_CLASS_AL ) { // RLI or FSI-R
4760
- // Compute the least odd embedding level greater than the embedding level of the last entry on the directional status stack.
4761
- $next_level = $cel + ($cel % 2) + 1;
4762
- }
4763
-
4764
-
4765
- // Increment the isolate count by one, and push an entry consisting of the new embedding level,
4766
- // neutral directional override status, and true directional isolate status onto the directional status stack.
4767
- $remember[] = array('num' => $chunkOTLdata['char_data'][$i]['uni'], 'cel' => $cel, 'dos' => $dos, 'diid' => $diid);
4768
- $cel = $next_level;
4769
- $dos = -1;
4770
- $diid = ++$dictr; // Set new direction isolate ID after incrementing direction isolate counter
4771
-
4772
- $controlchars = true;
4773
- }
4774
- else if ($chunkOTLdata['char_data'][$i]['uni'] == 8297) { // PDI
4775
- // X6a. With each PDI, perform the following steps:
4776
- // Pop the last entry from the directional status stack and decrement the isolate count by one.
4777
- while (count($remember)) {
4778
- $last = count($remember ) - 1;
4779
- if (($remember[$last]['num'] == 8294) || ($remember[$last]['num'] == 8295) || ($remember[$last]['num'] == 8296)) {
4780
- $match = array_pop($remember);
4781
- $cel = $match['cel'];
4782
- $dos = $match['dos'];
4783
- $diid = $match['diid'];
4784
- break;
4785
- }
4786
- // End/close any open embedding states not explicitly closed during the isolate
4787
- else if (($remember[$last]['num'] == 8235) || ($remember[$last]['num'] == 8234) || ($remember[$last]['num'] == 8238) ||
4788
- ($remember[$last]['num'] == 8237)) {
4789
- $match = array_pop($remember);
4790
- }
4791
- }
4792
- // In all cases, set the PDI�s level to the embedding level of the last entry on the directional status stack left after the steps above.
4793
- // NB The level assigned to an isolate initiator is always the same as that assigned to the matching PDI.
4794
- if ($dos != -1) { $chardir = $dos; }
4795
- else { $chardir = $chunkOTLdata['char_data'][$i]['bidi_class']; }
4796
- $chunkOTLdata['char_data'][$i]['level'] = $cel;
4797
- $chunkOTLdata['char_data'][$i]['type'] = $chardir;
4798
- $chunkOTLdata['char_data'][$i]['diid'] = $diid;
4799
- $controlchars = true;
4800
- }
4801
- else if ($chunkOTLdata['char_data'][$i]['uni'] == 10) { // NEW LINE
4802
- // Reset to start values
4803
- $cel = $pel;
4804
- $dos = -1;
4805
- $remember = array();
4806
- }
4807
- else {
4808
- // X6. For all types besides RLE, LRE, RLO, LRO, and PDF:
4809
- // a. Set the level of the current character to the current embedding level.
4810
- // b. When the directional override status is not neutral, reset the current character type to directional override status.
4811
- if ($dos != -1) { $chardir = $dos; }
4812
- else {
4813
- $chardir = $chunkOTLdata['char_data'][$i]['bidi_class'];
4814
- if ($chardir == UCDN::BIDI_CLASS_R || $chardir == UCDN::BIDI_CLASS_AL) { $strongrtl = true; }
4815
- }
4816
- $chunkOTLdata['char_data'][$i]['level'] = $cel;
4817
- $chunkOTLdata['char_data'][$i]['type'] = $chardir;
4818
- $chunkOTLdata['char_data'][$i]['diid'] = $diid;
4819
- }
4820
- }
4821
- // X8. All explicit directional embeddings and overrides are completely terminated at the end of each paragraph.
4822
- // Paragraph separators are not included in the embedding.
4823
- // X9. Remove all RLE, LRE, RLO, LRO, and PDF codes.
4824
- if ($controlchars) {
4825
- $this->removeChar($para[$nc][0], $para[$nc][18], "\xe2\x80\xaa");
4826
- $this->removeChar($para[$nc][0], $para[$nc][18], "\xe2\x80\xab");
4827
- $this->removeChar($para[$nc][0], $para[$nc][18], "\xe2\x80\xac");
4828
- $this->removeChar($para[$nc][0], $para[$nc][18], "\xe2\x80\xad");
4829
- $this->removeChar($para[$nc][0], $para[$nc][18], "\xe2\x80\xae");
4830
- preg_replace("/\x{202a}-\x{202e}/u", '', $para[$nc][0]);
4831
- }
4832
- }
4833
-
4834
- // Remove any blank chunks made by removing directional codes
4835
- $numchunks = count($para);
4836
- for ($nc=($numchunks-1);$nc>=0;$nc--) {
4837
- if (count($para[$nc][18]['char_data'])==0) { array_splice($para, $nc, 1); }
4838
- }
4839
- if ($dir != 'rtl' && !$strongrtl && !$controlchars) { return; }
4840
-
4841
- $numchunks = count($para);
4842
-
4843
- // X10. Determine the start-of-sequence (sor) and end-of-sequence (eor) types, either L or R, for each isolating run sequence. These depend on the higher of the two levels on either side of the sequence boundary:
4844
- // For sor, compare the level of the first character in the sequence with the level of the character preceding it in the paragraph or if there is none, with the paragraph embedding level.
4845
- // For eor, compare the level of the last character in the sequence with the level of the character following it in the paragraph or if there is none, with the paragraph embedding level.
4846
- // If the higher level is odd, the sor or eor is R; otherwise, it is L.
4847
-
4848
- for ($ir=0; $ir<=$dictr;$ir++) {
4849
- $prelevel = $pel;
4850
- $postlevel = $pel;
4851
- $firstchar = true;
4852
- for ($nc=0;$nc<$numchunks;$nc++) {
4853
- $chardata =& $para[$nc][18]['char_data'];
4854
- $numchars = count($chardata);
4855
- for ($i=0; $i < $numchars; ++$i) {
4856
- if (!isset($chardata[$i]['diid']) || $chardata[$i]['diid']!=$ir) { continue; } // Ignore characters in a different isolate run
4857
- $right = $postlevel;
4858
- $nc2 = $nc;
4859
- $i2 = $i;
4860
- while (!($nc2==($numchunks-1) && $i2==((count($para[$nc2][18]['char_data']))-1))) { // while not at end of last chunk
4861
- $i2++;
4862
- if ($i2 >= count($para[$nc2][18]['char_data'])) {
4863
- $nc2++;
4864
- $i2 = 0;
4865
- }
4866
-
4867
- if (isset($para[$nc2][18]['char_data'][$i2]['diid']) && $para[$nc2][18]['char_data'][$i2]['diid']==$ir) { $right = $para[$nc2][18]['char_data'][$i2]['level']; break; }
4868
- }
4869
-
4870
- $level = $chardata[$i]['level'];
4871
- if ($firstchar || $level!=$prelevel) {
4872
- $chardata[$i]['sor'] = max($prelevel, $level) % 2 ? UCDN::BIDI_CLASS_R : UCDN::BIDI_CLASS_L;
4873
- }
4874
- if (($nc==($numchunks-1) && $i==($numchars-1)) || $level != $right) {
4875
- $chardata[$i]['eor'] = max($right, $level) % 2 ? UCDN::BIDI_CLASS_R : UCDN::BIDI_CLASS_L;
4876
- }
4877
- $prelevel = $level;
4878
- $firstchar = false;
4879
- }
4880
- }
4881
- }
4882
-
4883
-
4884
- // 3.3.3 Resolving Weak Types
4885
- // Weak types are now resolved one level run at a time. At level run boundaries where the type of the character on the other side of the boundary is required, the type assigned to sor or eor is used.
4886
- // Nonspacing marks are now resolved based on the previous characters.
4887
-
4888
- // W1. Examine each nonspacing mark (NSM) in the level run, and change the type of the NSM to the type of the previous character. If the NSM is at the start of the level run, it will get the type of sor.
4889
- for ($ir=0; $ir<=$dictr;$ir++) {
4890
- $prevtype = 0;
4891
- for ($nc=0;$nc<$numchunks;$nc++) {
4892
- $chardata =& $para[$nc][18]['char_data'];
4893
- $numchars = count($chardata);
4894
- for ($i=0; $i < $numchars; ++$i) {
4895
- if (!isset($chardata[$i]['diid']) || $chardata[$i]['diid']!=$ir) { continue; } // Ignore characters in a different isolate run
4896
- if ($chardata[$i]['type'] == UCDN::BIDI_CLASS_NSM) {
4897
- if (isset($chardata[$i]['sor'])) {
4898
- $chardata[$i]['type'] = $chardata[$i]['sor'];
4899
- }
4900
- else {
4901
- $chardata[$i]['type'] = $prevtype;
4902
- }
4903
- }
4904
- $prevtype = $chardata[$i]['type'];
4905
- }
4906
- }
4907
- }
4908
-
4909
- // W2. Search backward from each instance of a European number until the first strong type (R, L, AL or sor) is found. If an AL is found, change the type of the European number to Arabic number.
4910
- for ($ir=0; $ir<=$dictr;$ir++) {
4911
- $laststrongtype = -1;
4912
- for ($nc=0;$nc<$numchunks;$nc++) {
4913
- $chardata =& $para[$nc][18]['char_data'];
4914
- $numchars = count($chardata);
4915
- for ($i=0; $i < $numchars; ++$i) {
4916
- if (!isset($chardata[$i]['diid']) || $chardata[$i]['diid']!=$ir) { continue; } // Ignore characters in a different isolate run
4917
- if (isset($chardata[$i]['sor'])) { $laststrongtype = $chardata[$i]['sor']; }
4918
- if ($chardata[$i]['type'] == UCDN::BIDI_CLASS_EN && $laststrongtype == UCDN::BIDI_CLASS_AL ) {
4919
- $chardata[$i]['type'] = UCDN::BIDI_CLASS_AN;
4920
- }
4921
- if ($chardata[$i]['type'] == UCDN::BIDI_CLASS_L || $chardata[$i]['type'] == UCDN::BIDI_CLASS_R || $chardata[$i]['type'] == UCDN::BIDI_CLASS_AL) {
4922
- $laststrongtype = $chardata[$i]['type'];
4923
- }
4924
- }
4925
- }
4926
- }
4927
-
4928
-
4929
- // W3. Change all ALs to R.
4930
- for ($nc=0;$nc<$numchunks;$nc++) {
4931
- $chardata =& $para[$nc][18]['char_data'];
4932
- $numchars = count($chardata);
4933
- for ($i=0; $i < $numchars; ++$i) {
4934
- if (isset($chardata[$i]['type']) && $chardata[$i]['type'] == UCDN::BIDI_CLASS_AL) { $chardata[$i]['type'] = UCDN::BIDI_CLASS_R; }
4935
- }
4936
- }
4937
-
4938
-
4939
- // W4. A single European separator between two European numbers changes to a European number. A single common separator between two numbers of the same type changes to that type.
4940
- for ($ir=0; $ir<=$dictr;$ir++) {
4941
- $prevtype = -1;
4942
- $nexttype = -1;
4943
- for ($nc=0;$nc<$numchunks;$nc++) {
4944
- $chardata =& $para[$nc][18]['char_data'];
4945
- $numchars = count($chardata);
4946
- for ($i=0; $i < $numchars; ++$i) {
4947
- if (!isset($chardata[$i]['diid']) || $chardata[$i]['diid']!=$ir) { continue; } // Ignore characters in a different isolate run
4948
-
4949
- // Get next type
4950
- $nexttype = -1;
4951
- $nc2 = $nc;
4952
- $i2 = $i;
4953
- while (!($nc2==($numchunks-1) && $i2==((count($para[$nc2][18]['char_data']))-1))) { // while not at end of last chunk
4954
- $i2++;
4955
- if ($i2 >= count($para[$nc2][18]['char_data'])) {
4956
- $nc2++;
4957
- $i2 = 0;
4958
- }
4959
-
4960
- if (isset($para[$nc2][18]['char_data'][$i2]['diid']) && $para[$nc2][18]['char_data'][$i2]['diid']==$ir) { $nexttype = $para[$nc2][18]['char_data'][$i2]['type']; break; }
4961
- }
4962
-
4963
- if (!isset($chardata[$i]['sor']) && !isset($chardata[$i]['eor'])) {
4964
- if ($chardata[$i]['type'] == UCDN::BIDI_CLASS_ES && $prevtype == UCDN::BIDI_CLASS_EN && $nexttype == UCDN::BIDI_CLASS_EN) {
4965
- $chardata[$i]['type'] = UCDN::BIDI_CLASS_EN;
4966
- }
4967
- else if ($chardata[$i]['type'] == UCDN::BIDI_CLASS_CS && $prevtype == UCDN::BIDI_CLASS_EN && $nexttype == UCDN::BIDI_CLASS_EN) {
4968
- $chardata[$i]['type'] = UCDN::BIDI_CLASS_EN;
4969
- }
4970
- else if ($chardata[$i]['type'] == UCDN::BIDI_CLASS_CS && $prevtype == UCDN::BIDI_CLASS_AN && $nexttype == UCDN::BIDI_CLASS_AN) {
4971
- $chardata[$i]['type'] = UCDN::BIDI_CLASS_AN;
4972
- }
4973
- }
4974
- $prevtype = $chardata[$i]['type'];
4975
- }
4976
- }
4977
- }
4978
-
4979
- // W5. A sequence of European terminators adjacent to European numbers changes to all European numbers.
4980
- for ($ir=0; $ir<=$dictr;$ir++) {
4981
- $prevtype = -1;
4982
- $nexttype = -1;
4983
- for ($nc=0;$nc<$numchunks;$nc++) {
4984
- $chardata =& $para[$nc][18]['char_data'];
4985
- $numchars = count($chardata);
4986
- for ($i=0; $i < $numchars; ++$i) {
4987
- if (!isset($chardata[$i]['diid']) || $chardata[$i]['diid']!=$ir) { continue; } // Ignore characters in a different isolate run
4988
- if (isset($chardata[$i]['sor'])) { $prevtype = $chardata[$i]['sor']; }
4989
-
4990
- if ($chardata[$i]['type'] == UCDN::BIDI_CLASS_ET) {
4991
- if ($prevtype == UCDN::BIDI_CLASS_EN) {
4992
- $chardata[$i]['type'] = UCDN::BIDI_CLASS_EN;
4993
- }
4994
- else if (!isset($chardata[$i]['eor'])) {
4995
- $nexttype = -1;
4996
- $nc2 = $nc;
4997
- $i2 = $i;
4998
- while (!($nc2==($numchunks-1) && $i2==((count($para[$nc2][18]['char_data']))-1))) { // while not at end of last chunk
4999
- $i2++;
5000
- if ($i2 >= count($para[$nc2][18]['char_data'])) {
5001
- $nc2++;
5002
- $i2 = 0;
5003
- }
5004
- if ($para[$nc2][18]['char_data'][$i2]['diid']!=$ir) { continue; }
5005
- $nexttype = $para[$nc2][18]['char_data'][$i2]['type'];
5006
- if (isset($para[$nc2][18]['char_data'][$i2]['sor'])) { break; }
5007
- if ($nexttype == UCDN::BIDI_CLASS_EN) {
5008
- $chardata[$i]['type'] = UCDN::BIDI_CLASS_EN;
5009
- break;
5010
- }
5011
- else if ($nexttype != UCDN::BIDI_CLASS_ET) { break; }
5012
- }
5013
- }
5014
- }
5015
- $prevtype = $chardata[$i]['type'];
5016
- }
5017
- }
5018
- }
5019
-
5020
- // W6. Otherwise, separators and terminators change to Other Neutral.
5021
- for ($nc=0;$nc<$numchunks;$nc++) {
5022
- $chardata =& $para[$nc][18]['char_data'];
5023
- $numchars = count($chardata);
5024
- for ($i=0; $i < $numchars; ++$i) {
5025
- if (isset($chardata[$i]['type']) && (($chardata[$i]['type'] == UCDN::BIDI_CLASS_ET) || ($chardata[$i]['type'] == UCDN::BIDI_CLASS_ES) || ($chardata[$i]['type'] == UCDN::BIDI_CLASS_CS))) {
5026
- $chardata[$i]['type'] = UCDN::BIDI_CLASS_ON;
5027
- }
5028
- }
5029
- }
5030
-
5031
- //W7. Search backward from each instance of a European number until the first strong type (R, L, or sor) is found. If an L is found, then change the type of the European number to L.
5032
- for ($ir=0; $ir<=$dictr;$ir++) {
5033
- $laststrongtype = -1;
5034
- for ($nc=0;$nc<$numchunks;$nc++) {
5035
- $chardata =& $para[$nc][18]['char_data'];
5036
- $numchars = count($chardata);
5037
- for ($i=0; $i < $numchars; ++$i) {
5038
- if (!isset($chardata[$i]['diid']) || $chardata[$i]['diid']!=$ir) { continue; } // Ignore characters in a different isolate run
5039
- if (isset($chardata[$i]['sor'])) { $laststrongtype = $chardata[$i]['sor']; }
5040
- if (isset($chardata[$i]['type']) && $chardata[$i]['type'] == UCDN::BIDI_CLASS_EN && $laststrongtype == UCDN::BIDI_CLASS_L ) {
5041
- $chardata[$i]['type'] = UCDN::BIDI_CLASS_L;
5042
- }
5043
- if (isset($chardata[$i]['type']) && ($chardata[$i]['type'] == UCDN::BIDI_CLASS_L || $chardata[$i]['type'] == UCDN::BIDI_CLASS_R || $chardata[$i]['type'] == UCDN::BIDI_CLASS_AL)) {
5044
- $laststrongtype = $chardata[$i]['type'];
5045
- }
5046
- }
5047
- }
5048
- }
5049
-
5050
- // N1. A sequence of neutrals takes the direction of the surrounding strong text if the text on both sides has the same direction. European and Arabic numbers act as if they were R in terms of their influence on neutrals. Start-of-level-run (sor) and end-of-level-run (eor) are used at level run boundaries.
5051
- for ($ir=0; $ir<=$dictr;$ir++) {
5052
- $laststrongtype = -1;
5053
- for ($nc=0;$nc<$numchunks;$nc++) {
5054
- $chardata =& $para[$nc][18]['char_data'];
5055
- $numchars = count($chardata);
5056
- for ($i=0; $i < $numchars; ++$i) {
5057
- if (!isset($chardata[$i]['diid']) || $chardata[$i]['diid']!=$ir) { continue; } // Ignore characters in a different isolate run
5058
- if (isset($chardata[$i]['sor'])) { $laststrongtype = $chardata[$i]['sor']; }
5059
- if ($chardata[$i]['type'] == UCDN::BIDI_CLASS_ON || $chardata[$i]['type'] == UCDN::BIDI_CLASS_WS) {
5060
- $left = -1;
5061
- // LEFT
5062
- if ($laststrongtype == UCDN::BIDI_CLASS_R || $laststrongtype == UCDN::BIDI_CLASS_EN || $laststrongtype == UCDN::BIDI_CLASS_AN) {
5063
- $left = UCDN::BIDI_CLASS_R;
5064
- }
5065
- else if ($laststrongtype == UCDN::BIDI_CLASS_L) {
5066
- $left = UCDN::BIDI_CLASS_L;
5067
- }
5068
- // RIGHT
5069
- $right = -1;
5070
- // move to the right of any following neutrals OR hit a run boundary
5071
-
5072
- if (isset($chardata[$i]['eor'])) {
5073
- $right = $chardata[$i]['eor'];
5074
- }
5075
- else {
5076
- $nexttype = -1;
5077
- $nc2 = $nc;
5078
- $i2 = $i;
5079
- while (!($nc2==($numchunks-1) && $i2==((count($para[$nc2][18]['char_data']))-1))) { // while not at end of last chunk
5080
- $i2++;
5081
- if ($i2 >= count($para[$nc2][18]['char_data'])) {
5082
- $nc2++;
5083
- $i2 = 0;
5084
- }
5085
- if (!isset($para[$nc2][18]['char_data'][$i2]['diid']) || $para[$nc2][18]['char_data'][$i2]['diid']!=$ir) { continue; }
5086
- $nexttype = $para[$nc2][18]['char_data'][$i2]['type'];
5087
- if ($nexttype == UCDN::BIDI_CLASS_R || $nexttype == UCDN::BIDI_CLASS_EN || $nexttype == UCDN::BIDI_CLASS_AN) {
5088
- $right = UCDN::BIDI_CLASS_R;
5089
- break;
5090
- }
5091
- else if ($nexttype == UCDN::BIDI_CLASS_L) {
5092
- $right = UCDN::BIDI_CLASS_L;
5093
- break;
5094
- }
5095
- else if (isset($para[$nc2][18]['char_data'][$i2]['eor'])) {
5096
- $right = $para[$nc2][18]['char_data'][$i2]['eor'];
5097
- break;
5098
- }
5099
- }
5100
- }
5101
-
5102
- if ($left > -1 && $left==$right) {
5103
- $chardata[$i]['orig_type'] = $chardata[$i]['type']; // Need to store the original 'WS' for reference in L1 below
5104
- $chardata[$i]['type'] = $left;
5105
- }
5106
- }
5107
- else if ($chardata[$i]['type'] == UCDN::BIDI_CLASS_L || $chardata[$i]['type'] == UCDN::BIDI_CLASS_R || $chardata[$i]['type'] == UCDN::BIDI_CLASS_EN || $chardata[$i]['type'] == UCDN::BIDI_CLASS_AN) {
5108
- $laststrongtype = $chardata[$i]['type'];
5109
- }
5110
- }
5111
- }
5112
- }
5113
-
5114
- // N2. Any remaining neutrals take the embedding direction
5115
- for ($nc=0;$nc<$numchunks;$nc++) {
5116
- $chardata =& $para[$nc][18]['char_data'];
5117
- $numchars = count($chardata);
5118
- for ($i=0; $i < $numchars; ++$i) {
5119
- if (isset($chardata[$i]['type']) && ($chardata[$i]['type'] == UCDN::BIDI_CLASS_ON || $chardata[$i]['type'] == UCDN::BIDI_CLASS_WS)) {
5120
- $chardata[$i]['orig_type'] = $chardata[$i]['type']; // Need to store the original 'WS' for reference in L1 below
5121
- $chardata[$i]['type'] = ($chardata[$i]['level'] % 2) ? UCDN::BIDI_CLASS_R : UCDN::BIDI_CLASS_L;
5122
- }
5123
- }
5124
- }
5125
-
5126
- // I1. For all characters with an even (left-to-right) embedding direction, those of type R go up one level and those of type AN or EN go up two levels.
5127
- // I2. For all characters with an odd (right-to-left) embedding direction, those of type L, EN or AN go up one level.
5128
- for ($nc=0;$nc<$numchunks;$nc++) {
5129
- $chardata =& $para[$nc][18]['char_data'];
5130
- $numchars = count($chardata);
5131
- for ($i=0; $i < $numchars; ++$i) {
5132
- if (isset($chardata[$i]['level'])) {
5133
- $odd = $chardata[$i]['level'] % 2;
5134
- if ($odd) {
5135
- if (($chardata[$i]['type'] == UCDN::BIDI_CLASS_L) || ($chardata[$i]['type'] == UCDN::BIDI_CLASS_AN) || ($chardata[$i]['type'] == UCDN::BIDI_CLASS_EN)) {
5136
- $chardata[$i]['level'] += 1;
5137
- }
5138
- }
5139
- else {
5140
- if ($chardata[$i]['type'] == UCDN::BIDI_CLASS_R) { $chardata[$i]['level'] += 1; }
5141
- else if (($chardata[$i]['type'] == UCDN::BIDI_CLASS_AN) || ($chardata[$i]['type'] == UCDN::BIDI_CLASS_EN)) { $chardata[$i]['level'] += 2; }
5142
- }
5143
- }
5144
- }
5145
- }
5146
-
5147
- // Remove Isolate formatters
5148
- $numchunks = count($para);
5149
- if ($controlchars) {
5150
- for ($nc=0;$nc<$numchunks;$nc++) {
5151
- $this->removeChar($para[$nc][0], $para[$nc][18], "\xe2\x81\xa6");
5152
- $this->removeChar($para[$nc][0], $para[$nc][18], "\xe2\x81\xa7");
5153
- $this->removeChar($para[$nc][0], $para[$nc][18], "\xe2\x81\xa8");
5154
- $this->removeChar($para[$nc][0], $para[$nc][18], "\xe2\x81\xa9");
5155
- preg_replace("/\x{2066}-\x{2069}/u", '', $para[$nc][0]);
5156
- }
5157
- // Remove any blank chunks made by removing directional codes
5158
- for ($nc=($numchunks-1);$nc>=0;$nc--) {
5159
- if (count($para[$nc][18]['char_data'])==0) { array_splice($para, $nc, 1); }
5160
- }
5161
- }
5162
-
5163
- }
5164
-
5165
-
5166
-
5167
- // Reorder, once divided into lines
5168
-
5169
- function _bidiReorder(&$chunkorder, &$content, &$cOTLdata, $blockdir) {
5170
-
5171
- $bidiData = array();
5172
-
5173
- // First combine into one array (and get the highest level in use)
5174
- $numchunks = count($content);
5175
- $maxlevel = 0;
5176
- for ($nc=0;$nc<$numchunks;$nc++) {
5177
- $numchars = count($cOTLdata[$nc]['char_data']);
5178
- for ($i=0; $i < $numchars; ++$i) {
5179
-
5180
- $carac = array();
5181
- if (isset($cOTLdata[$nc]['GPOSinfo'][$i])) {$carac['GPOSinfo'] = $cOTLdata[$nc]['GPOSinfo'][$i]; }
5182
- $carac['uni'] = $cOTLdata[$nc]['char_data'][$i]['uni'];
5183
- if (isset($cOTLdata[$nc]['char_data'][$i]['type'])) $carac['type'] = $cOTLdata[$nc]['char_data'][$i]['type'];
5184
- if (isset($cOTLdata[$nc]['char_data'][$i]['level'])) $carac['level'] = $cOTLdata[$nc]['char_data'][$i]['level'];
5185
- if (isset($cOTLdata[$nc]['char_data'][$i]['orig_type'])) { $carac['orig_type'] = $cOTLdata[$nc]['char_data'][$i]['orig_type']; }
5186
- $carac['group'] = $cOTLdata[$nc]['group']{$i};
5187
- $carac['chunkid'] = $chunkorder[$nc]; // gives font id and/or object ID
5188
-
5189
- $maxlevel = max((isset($carac['level']) ? $carac['level'] : 0),$maxlevel);
5190
- $bidiData[] = $carac;
5191
- }
5192
- }
5193
- if ($maxlevel==0) { return; }
5194
-
5195
- $numchars = count($bidiData);
5196
-
5197
- // L1. On each line, reset the embedding level of the following characters to the paragraph embedding level:
5198
- // 1. Segment separators (Tab) 'S',
5199
- // 2. Paragraph separators 'B',
5200
- // 3. Any sequence of whitespace characters 'WS' preceding a segment separator or paragraph separator, and
5201
- // 4. Any sequence of whitespace characters 'WS' at the end of the line.
5202
- // The types of characters used here are the original types, not those modified by the previous phase cf N1 and N2*******
5203
- // Because a Paragraph Separator breaks lines, there will be at most one per line, at the end of that line.
5204
-
5205
- // Set the initial paragraph embedding level
5206
- if ($blockdir == 'rtl') { $pel = 1; }
5207
- else { $pel = 0; }
5208
-
5209
- for ($i=($numchars-1); $i>0; $i--) {
5210
- if ($bidiData[$i]['type'] == UCDN::BIDI_CLASS_WS || (isset($bidiData[$i]['orig_type']) && $bidiData[$i]['orig_type'] == UCDN::BIDI_CLASS_WS)) {
5211
- $bidiData[$i]['level'] = $pel;
5212
- }
5213
- else { break; }
5214
- }
5215
-
5216
-
5217
- // L2. From the highest level found in the text to the lowest odd level on each line, including intermediate levels not actually present in the text, reverse any contiguous sequence of characters that are at that level or higher.
5218
- for ($j=$maxlevel; $j > 0; $j--) {
5219
- $ordarray = array();
5220
- $revarr = array();
5221
- $onlevel = false;
5222
- for ($i=0; $i < $numchars; ++$i) {
5223
- if ($bidiData[$i]['level'] >= $j) {
5224
- $onlevel = true;
5225
- // L4. A character is depicted by a mirrored glyph if and only if (a) the resolved directionality of that character is R, and (b) the Bidi_Mirrored property value of that character is true.
5226
- if (isset(UCDN::$mirror_pairs[$bidiData[$i]['uni']]) && $bidiData[$i]['type']==UCDN::BIDI_CLASS_R) {
5227
- $bidiData[$i]['uni'] = UCDN::$mirror_pairs[$bidiData[$i]['uni']];
5228
- }
5229
-
5230
- $revarr[] = $bidiData[$i];
5231
- }
5232
- else {
5233
- if ($onlevel) {
5234
- $revarr = array_reverse($revarr);
5235
- $ordarray = array_merge($ordarray, $revarr);
5236
- $revarr = Array();
5237
- $onlevel = false;
5238
- }
5239
- $ordarray[] = $bidiData[$i];
5240
- }
5241
- }
5242
- if ($onlevel) {
5243
- $revarr = array_reverse($revarr);
5244
- $ordarray = array_merge($ordarray, $revarr);
5245
- }
5246
- $bidiData = $ordarray;
5247
- }
5248
-
5249
- $content = array();
5250
- $cOTLdata = array();
5251
- $chunkorder = array();
5252
-
5253
-
5254
-
5255
- $nc = -1; // New chunk order ID
5256
- $chunkid = -1;
5257
-
5258
- foreach ($bidiData as $carac) {
5259
- if ($carac['chunkid'] != $chunkid) {
5260
- $nc++;
5261
- $chunkorder[$nc] = $carac['chunkid'];
5262
- $cctr = 0;
5263
- $content[$nc] = '';
5264
- $cOTLdata[$nc]['group'] = '';
5265
- }
5266
- if ($carac['uni'] != 0xFFFC) { // Object replacement character (65532)
5267
- $content[$nc] .= code2utf($carac['uni']);
5268
- $cOTLdata[$nc]['group'] .= $carac['group'];
5269
- if (!empty($carac['GPOSinfo'])) {
5270
- if (isset($carac['GPOSinfo'])) { $cOTLdata[$nc]['GPOSinfo'][$cctr] = $carac['GPOSinfo']; }
5271
- $cOTLdata[$nc]['GPOSinfo'][$cctr]['wDir'] = ($carac['level'] % 2) ? 'RTL' : 'LTR';
5272
- }
5273
- }
5274
- $chunkid = $carac['chunkid'];
5275
- $cctr++;
5276
- }
5277
-
5278
- }
5279
-
5280
-
5281
-
5282
-
5283
-
5284
-
5285
- ////////////////////////////////////////////////////////////////
5286
- ////////////////////////////////////////////////////////////////
5287
- // These functions are called from mpdf after GSUB/GPOS has taken place
5288
- // At this stage the bidi-type is in string form
5289
- ////////////////////////////////////////////////////////////////
5290
- ////////////////////////////////////////////////////////////////
5291
- function splitOTLdata(&$cOTLdata, $OTLcutoffpos, $OTLrestartpos='') {
5292
- if (!$OTLrestartpos) { $OTLrestartpos = $OTLcutoffpos; }
5293
- $newOTLdata = array('GPOSinfo' => array(), 'char_data' => array());
5294
- $newOTLdata['group'] = substr($cOTLdata['group'],$OTLrestartpos);
5295
- $cOTLdata['group'] = substr($cOTLdata['group'],0,$OTLcutoffpos);
5296
-
5297
- if (isset($cOTLdata['GPOSinfo']) && $cOTLdata['GPOSinfo']) {
5298
- foreach($cOTLdata['GPOSinfo'] AS $k => $val) {
5299
- if ($k >= $OTLrestartpos) {
5300
- $newOTLdata['GPOSinfo'][($k - $OTLrestartpos)] = $val;
5301
- }
5302
- if ($k >= $OTLcutoffpos) {
5303
- unset($cOTLdata['GPOSinfo'][$k]);
5304
- //$cOTLdata['GPOSinfo'][$k] = array();
5305
- }
5306
- }
5307
- }
5308
- if (isset($cOTLdata['char_data'])) {
5309
- $newOTLdata['char_data'] = array_slice($cOTLdata['char_data'], $OTLrestartpos);
5310
- array_splice($cOTLdata['char_data'], $OTLcutoffpos);
5311
- }
5312
-
5313
- // Not necessary - easier to debug
5314
- if (isset($cOTLdata['GPOSinfo'])) ksort($cOTLdata['GPOSinfo']);
5315
- if (isset($newOTLdata['GPOSinfo'])) ksort($newOTLdata['GPOSinfo']);
5316
-
5317
- return $newOTLdata;
5318
- }
5319
-
5320
- function sliceOTLdata($OTLdata, $pos, $len) {
5321
- $newOTLdata = array('GPOSinfo' => array(), 'char_data' => array());
5322
- $newOTLdata['group'] = substr($OTLdata['group'],$pos,$len);
5323
-
5324
- if ($OTLdata['GPOSinfo']) {
5325
- foreach($OTLdata['GPOSinfo'] AS $k => $val) {
5326
- if ($k >= $pos && $k <($pos+$len)) {
5327
- $newOTLdata['GPOSinfo'][($k - $pos)] = $val;
5328
- }
5329
- }
5330
- }
5331
-
5332
- if (isset($OTLdata['char_data'])) { $newOTLdata['char_data'] = array_slice($OTLdata['char_data'], $pos, $len); }
5333
-
5334
- // Not necessary - easier to debug
5335
- if ($newOTLdata['GPOSinfo']) ksort($newOTLdata['GPOSinfo']);
5336
-
5337
- return $newOTLdata;
5338
- }
5339
-
5340
- // Remove one or more occurrences of $char (single character) from $txt and adjust OTLdata
5341
- function removeChar(&$txt, &$cOTLdata, $char) {
5342
- while(mb_strpos($txt, $char, 0, $this->mpdf->mb_enc )!== false) {
5343
- $pos = mb_strpos($txt, $char, 0, $this->mpdf->mb_enc );
5344
- $newGPOSinfo = array();
5345
- $cOTLdata['group'] = substr_replace($cOTLdata['group'], '', $pos, 1);
5346
- if ($cOTLdata['GPOSinfo']) {
5347
- foreach($cOTLdata['GPOSinfo'] AS $k => $val) {
5348
- if ($k > $pos) {
5349
- $newGPOSinfo[($k - 1)] = $val;
5350
- }
5351
- else if ($k!=$pos) {
5352
- $newGPOSinfo[$k] = $val;
5353
- }
5354
- }
5355
- $cOTLdata['GPOSinfo'] = $newGPOSinfo;
5356
- }
5357
- if (isset($cOTLdata['char_data'])) { array_splice($cOTLdata['char_data'], $pos, 1); }
5358
-
5359
- $txt = preg_replace("/".$char."/",'',$txt, 1);
5360
- }
5361
- }
5362
-
5363
- // Remove one or more occurrences of $char (single character) from $txt and adjust OTLdata
5364
- function replaceSpace(&$txt, &$cOTLdata) {
5365
- $char = chr(194).chr(160); // NBSP
5366
- while(mb_strpos($txt, $char, 0, $this->mpdf->mb_enc )!== false) {
5367
- $pos = mb_strpos($txt, $char, 0, $this->mpdf->mb_enc );
5368
- if ($cOTLdata['char_data'][$pos]['uni'] == 160) {
5369
- $cOTLdata['char_data'][$pos]['uni'] = 32;
5370
- }
5371
- $txt = preg_replace("/".$char."/",' ',$txt, 1);
5372
- }
5373
- }
5374
-
5375
- function trimOTLdata(&$cOTLdata, $Left=true, $Right=true) {
5376
-
5377
- $len = count($cOTLdata['char_data']);
5378
- $nLeft = 0;
5379
- $nRight = 0;
5380
- for($i=0;$i<$len;$i++) {
5381
- if($cOTLdata['char_data'][$i]['uni']==32 || $cOTLdata['char_data'][$i]['uni']==12288) { $nLeft++; } // 12288 = 0x3000 = CJK space
5382
- else { break; }
5383
- }
5384
- for($i=($len-1);$i>=0;$i--) {
5385
- if($cOTLdata['char_data'][$i]['uni']==32 || $cOTLdata['char_data'][$i]['uni']==12288) { $nRight++; } // 12288 = 0x3000 = CJK space
5386
- else { break; }
5387
- }
5388
-
5389
- // Trim Right
5390
- if ($Right && $nRight) {
5391
- $cOTLdata['group'] = substr($cOTLdata['group'],0,strlen($cOTLdata['group'])-$nRight);
5392
- if ($cOTLdata['GPOSinfo']) {
5393
- foreach($cOTLdata['GPOSinfo'] AS $k => $val) {
5394
- if ($k >= $len-$nRight) {
5395
- unset($cOTLdata['GPOSinfo'][$k]);
5396
- }
5397
- }
5398
- }
5399
- if (isset($cOTLdata['char_data'])) {
5400
- for($i=0;$i<$nRight;$i++) {
5401
- array_pop($cOTLdata['char_data']);
5402
- }
5403
- }
5404
- }
5405
- // Trim Left
5406
- if ($Left && $nLeft) {
5407
- $cOTLdata['group'] = substr($cOTLdata['group'],$nLeft);
5408
- if ($cOTLdata['GPOSinfo']) {
5409
- $newPOSinfo = array();
5410
- foreach($cOTLdata['GPOSinfo'] AS $k => $val) {
5411
- if ($k >= $nLeft) {
5412
- $newPOSinfo[$k-$nLeft] = $cOTLdata['GPOSinfo'][$k];
5413
- }
5414
- }
5415
- $cOTLdata['GPOSinfo'] = $newPOSinfo;
5416
- }
5417
- if (isset($cOTLdata['char_data'])) {
5418
- for($i=0;$i<$nLeft;$i++) {
5419
- array_shift($cOTLdata['char_data']);
5420
- }
5421
- }
5422
- }
5423
- }
5424
-
5425
-
5426
- ////////////////////////////////////////////////////////////////
5427
- ////////////////////////////////////////////////////////////////
5428
- ////////// GENERAL OTL FUNCTIONS /////////////////
5429
- ////////////////////////////////////////////////////////////////
5430
- ////////////////////////////////////////////////////////////////
5431
-
5432
-
5433
- function glyphToChar($gid) {
5434
- return (ord($this->glyphIDtoUni[$gid*3]) << 16) + (ord($this->glyphIDtoUni[$gid*3+1]) << 8) + ord($this->glyphIDtoUni[$gid*3+2]);
5435
- }
5436
-
5437
- function unicode_hex($unicode_dec) {
5438
- return (str_pad(strtoupper(dechex($unicode_dec)),5,'0',STR_PAD_LEFT));
5439
- }
5440
-
5441
- function seek($pos) {
5442
- $this->_pos = $pos;
5443
- }
5444
-
5445
- function skip($delta) {
5446
- $this->_pos += $delta;
5447
- }
5448
- function read_short() {
5449
- $a = (ord($this->ttfOTLdata[$this->_pos])<<8) + ord($this->ttfOTLdata[$this->_pos+1]);
5450
- if ($a & (1 << 15) ) {
5451
- $a = ($a - (1 << 16));
5452
- }
5453
- $this->_pos += 2;
5454
- return $a;
5455
- }
5456
-
5457
- function read_ushort() {
5458
- $a = (ord($this->ttfOTLdata[$this->_pos])<<8) + ord($this->ttfOTLdata[$this->_pos+1]);
5459
- $this->_pos += 2;
5460
- return $a;
5461
- }
5462
-
5463
-
5464
- function _getCoverageGID() {
5465
- // Called from Lookup Type 1, Format 1 - returns glyphIDs rather than hexstrings
5466
- // Need to do this separately to cache separately
5467
- // Otherwise the same as fn below _getCoverage
5468
- $offset = $this->_pos;
5469
- if (isset($this->LuDataCache[$this->fontkey]['GID'][$offset])) {
5470
- $g = $this->LuDataCache[$this->fontkey]['GID'][$offset];
5471
- }
5472
- else {
5473
- $g = array();
5474
- $CoverageFormat= $this->read_ushort();
5475
- if ($CoverageFormat == 1) {
5476
- $CoverageGlyphCount= $this->read_ushort();
5477
- for ($gid=0;$gid<$CoverageGlyphCount;$gid++) {
5478
- $glyphID = $this->read_ushort();
5479
- $g[] = $glyphID;
5480
- }
5481
- }
5482
- if ($CoverageFormat == 2) {
5483
- $RangeCount= $this->read_ushort();
5484
- for ($r=0;$r<$RangeCount;$r++) {
5485
- $start = $this->read_ushort();
5486
- $end = $this->read_ushort();
5487
- $StartCoverageIndex = $this->read_ushort(); // n/a
5488
- for ($glyphID=$start;$glyphID<=$end;$glyphID++) {
5489
- $g[] = $glyphID;
5490
- }
5491
- }
5492
- }
5493
- $this->LuDataCache[$this->fontkey]['GID'][$offset] = $g;
5494
- }
5495
- return $g;
5496
- }
5497
-
5498
-
5499
- function _getCoverage() {
5500
- $offset = $this->_pos;
5501
- if (isset($this->LuDataCache[$this->fontkey][$offset])) {
5502
- $g = $this->LuDataCache[$this->fontkey][$offset];
5503
- }
5504
- else {
5505
- $g = array();
5506
- $CoverageFormat= $this->read_ushort();
5507
- if ($CoverageFormat == 1) {
5508
- $CoverageGlyphCount= $this->read_ushort();
5509
- for ($gid=0;$gid<$CoverageGlyphCount;$gid++) {
5510
- $glyphID = $this->read_ushort();
5511
- $g[] = $this->unicode_hex($this->glyphToChar($glyphID));
5512
- }
5513
- }
5514
- if ($CoverageFormat == 2) {
5515
- $RangeCount= $this->read_ushort();
5516
- for ($r=0;$r<$RangeCount;$r++) {
5517
- $start = $this->read_ushort();
5518
- $end = $this->read_ushort();
5519
- $StartCoverageIndex = $this->read_ushort(); // n/a
5520
- for ($glyphID=$start;$glyphID<=$end;$glyphID++) {
5521
- $g[] = $this->unicode_hex($this->glyphToChar($glyphID));
5522
- }
5523
- }
5524
- }
5525
- $this->LuDataCache[$this->fontkey][$offset] = $g;
5526
- }
5527
- return $g;
5528
- }
5529
-
5530
- function _getClasses($offset) {
5531
- if (isset($this->LuDataCache[$this->fontkey][$offset])) {
5532
- $GlyphByClass = $this->LuDataCache[$this->fontkey][$offset];
5533
- }
5534
- else {
5535
- $this->seek($offset);
5536
- $ClassFormat = $this->read_ushort();
5537
- $GlyphByClass = array();
5538
- if ($ClassFormat == 1) {
5539
- $StartGlyph = $this->read_ushort();
5540
- $GlyphCount = $this->read_ushort();
5541
- for ($i=0;$i<$GlyphCount;$i++) {
5542
- $startGlyphID = $StartGlyph + $i;
5543
- $endGlyphID = $StartGlyph + $i;
5544
- $class = $this->read_ushort();
5545
- // Note: Font FreeSerif , tag "blws"
5546
- // $BacktrackClasses[0] is defined ? a mistake in the font ???
5547
- // Let's ignore for now
5548
- if ($class > 0) {
5549
- for($g=$startGlyphID;$g<=$endGlyphID;$g++) {
5550
- if ($this->glyphToChar($g)) {
5551
- $GlyphByClass[$class][$this->glyphToChar($g)] = 1;
5552
- }
5553
- }
5554
- }
5555
- }
5556
- }
5557
- else if ($ClassFormat == 2) {
5558
- $tableCount = $this->read_ushort();
5559
- for ($i=0;$i<$tableCount;$i++) {
5560
- $startGlyphID = $this->read_ushort();
5561
- $endGlyphID = $this->read_ushort();
5562
- $class = $this->read_ushort();
5563
- // Note: Font FreeSerif , tag "blws"
5564
- // $BacktrackClasses[0] is defined ? a mistake in the font ???
5565
- // Let's ignore for now
5566
- if ($class > 0) {
5567
- for($g=$startGlyphID;$g<=$endGlyphID;$g++) {
5568
- if ($this->glyphToChar($g)) {
5569
- $GlyphByClass[$class][$this->glyphToChar($g)] = 1;
5570
- }
5571
- }
5572
- }
5573
- }
5574
- }
5575
- $this->LuDataCache[$this->fontkey][$offset] = $GlyphByClass;
5576
- }
5577
- return $GlyphByClass;
5578
- }
5579
-
5580
-
5581
- function _getOTLscriptTag($ScriptLang, $scripttag, $scriptblock, $shaper, $useOTL, $mode) {
5582
- // ScriptLang is the array of available script/lang tags supported by the font
5583
- // $scriptblock is the (number/code) for the script of the actual text string based on Unicode properties (UCDN::$uni_scriptblock)
5584
- // $scripttag is the default tag derived from $scriptblock
5585
- /*
5586
- http://www.microsoft.com/typography/otspec/ttoreg.htm
5587
- http://www.microsoft.com/typography/otspec/scripttags.htm
5588
-
5589
- Values for useOTL
5590
-
5591
- Bit dn hn Value
5592
- 1 1 0x0001 GSUB/GPOS - Latin scripts
5593
- 2 2 0x0002 GSUB/GPOS - Cyrillic scripts
5594
- 3 4 0x0004 GSUB/GPOS - Greek scripts
5595
- 4 8 0x0008 GSUB/GPOS - CJK scripts (excluding Hangul-Jamo)
5596
- 5 16 0x0010 (Reserved)
5597
- 6 32 0x0020 (Reserved)
5598
- 7 64 0x0040 (Reserved)
5599
- 8 128 0x0080 GSUB/GPOS - All other scripts (including all RTL scripts, complex scripts with shapers etc)
5600
-
5601
- NB If change for RTL - cf. function magic_reverse_dir in mpdf.php to update
5602
-
5603
- */
5604
-
5605
-
5606
- if ($scriptblock == UCDN::SCRIPT_LATIN) {
5607
- if (!($useOTL & 0x01)) { return array('',false); }
5608
- }
5609
- else if ($scriptblock == UCDN::SCRIPT_CYRILLIC) {
5610
- if (!($useOTL & 0x02)) { return array('',false); }
5611
- }
5612
- else if ($scriptblock == UCDN::SCRIPT_GREEK) {
5613
- if (!($useOTL & 0x04)) { return array('',false); }
5614
- }
5615
- else if ($scriptblock >= UCDN::SCRIPT_HIRAGANA && $scriptblock <= UCDN::SCRIPT_YI ) {
5616
- if (!($useOTL & 0x08)) { return array('',false); }
5617
- }
5618
- else {
5619
- if (!($useOTL & 0x80)) { return array('',false); }
5620
- }
5621
-
5622
- // If availabletags includes scripttag - choose
5623
- if (isset($ScriptLang[$scripttag])) { return array($scripttag, false); }
5624
-
5625
- // If INDIC (or Myanmar) and available tag not includes new version, check if includes old version & choose old version
5626
- if ($shaper) {
5627
- switch($scripttag) {
5628
- CASE 'bng2': if (isset($ScriptLang['beng'])) return array('beng',true);
5629
- CASE 'dev2': if (isset($ScriptLang['deva'])) return array('deva',true);
5630
- CASE 'gjr2': if (isset($ScriptLang['gujr'])) return array('gujr',true);
5631
- CASE 'gur2': if (isset($ScriptLang['guru'])) return array('guru',true);
5632
- CASE 'knd2': if (isset($ScriptLang['knda'])) return array('knda',true);
5633
- CASE 'mlm2': if (isset($ScriptLang['mlym'])) return array('mlym',true);
5634
- CASE 'ory2': if (isset($ScriptLang['orya'])) return array('orya',true);
5635
- CASE 'tml2': if (isset($ScriptLang['taml'])) return array('taml',true);
5636
- CASE 'tel2': if (isset($ScriptLang['telu'])) return array('telu',true);
5637
- CASE 'mym2': if (isset($ScriptLang['mymr'])) return array('mymr',true);
5638
- }
5639
- }
5640
-
5641
- // choose DFLT if present
5642
- if (isset($ScriptLang['DFLT'])) { return array('DFLT', false); }
5643
- // else choose dflt if present
5644
- if (isset($ScriptLang['dflt'])) { return array('dflt', false); }
5645
- // else return no scriptTag
5646
- if (isset($ScriptLang['latn'])) { return array('latn', false); }
5647
- // else return no scriptTag
5648
- return array('',false);
5649
-
5650
- }
5651
-
5652
-
5653
-
5654
- // LangSys tags
5655
- function _getOTLLangTag($ietf, $available) {
5656
- // http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
5657
- // http://www.microsoft.com/typography/otspec/languagetags.htm
5658
- // IETF tag = e.g. en-US, und-Arab, sr-Cyrl cf. config_lang2fonts.php
5659
- if ($available=='') { return ''; }
5660
- $tags = preg_split('/-/',$ietf);
5661
- $lang = '';
5662
- $country = '';
5663
- $script = '';
5664
- $lang = strtolower($tags[0]);
5665
- if (isset($tags[1]) && $tags[1]) {
5666
- if (strlen($tags[1]) == 2) { $country = strtolower($tags[1]); }
5667
- }
5668
- if (isset($tags[2]) && $tags[2]) { $country = strtolower($tags[2]); }
5669
-
5670
- if ($lang!='' && isset(UCDN::$ot_languages[$lang])) { $langsys = UCDN::$ot_languages[$lang]; }
5671
- else if ($lang!='' && $country !='' && isset(UCDN::$ot_languages[$lang.''.$country])) {
5672
- $langsys = UCDN::$ot_languages[$lang.''.$country];
5673
- }
5674
- else { $langsys = "DFLT"; }
5675
- if (strpos($available, $langsys)===false) {
5676
- if (strpos($available, "DFLT")!==false) { return "DFLT"; }
5677
- else return '';
5678
- }
5679
- return $langsys;
5680
- }
5681
-
5682
- function _dumpproc($GPOSSUB, $lookupID, $subtable, $Type, $Format, $ptr, $currGlyph, $level) {
5683
- echo '<div style="padding-left: '.($level*2).'em;">';
5684
- echo $GPOSSUB .' LookupID #'.$lookupID.' Subtable#'.$subtable .' Type: '.$Type.' Format: '.$Format.'<br />';
5685
- echo '<div style="font-family:monospace">';
5686
- echo 'Glyph position: '.$ptr.' Current Glyph: '.$currGlyph.'<br />';
5687
-
5688
- for ($i=0;$i<count($this->OTLdata);$i++) {
5689
- if ($i==$ptr) { echo '<b>'; }
5690
- echo $this->OTLdata[$i]['hex'] . ' ';
5691
- if ($i==$ptr) { echo '</b>'; }
5692
- }
5693
- echo '<br />';
5694
-
5695
- for ($i=0;$i<count($this->OTLdata);$i++) {
5696
- if ($i==$ptr) { echo '<b>'; }
5697
- echo str_pad($this->OTLdata[$i]['uni'],5) . ' ';
5698
- if ($i==$ptr) { echo '</b>'; }
5699
- }
5700
- echo '<br />';
5701
-
5702
- if ($GPOSSUB == 'GPOS') {
5703
- for ($i=0;$i<count($this->OTLdata);$i++) {
5704
- if (!empty($this->OTLdata[$i]['GPOSinfo'])) {
5705
- echo $this->OTLdata[$i]['hex'] . ' &#x'.$this->OTLdata[$i]['hex'].'; ';
5706
- print_r($this->OTLdata[$i]['GPOSinfo']);
5707
- echo ' ';
5708
- }
5709
- }
5710
- }
5711
-
5712
- echo '</div>';
5713
- echo '</div>';
5714
- }
5715
-
5716
-
5717
- }
5718
-
5719
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/mpdf/classes/otl_dump.php DELETED
@@ -1,3897 +0,0 @@
1
- <?php
2
-
3
- /*******************************************************************************
4
- * otl_dump class *
5
- *******************************************************************************/
6
-
7
- // Define the value used in the "head" table of a created TTF file
8
- // 0x74727565 "true" for Mac
9
- // 0x00010000 for Windows
10
- // Either seems to work for a font embedded in a PDF file
11
- // when read by Adobe Reader on a Windows PC(!)
12
- if (!defined('_TTF_MAC_HEADER')) define("_TTF_MAC_HEADER", false);
13
-
14
- // Recalculate correct metadata/profiles when making subset fonts (not SIP/SMP)
15
- // e.g. xMin, xMax, maxNContours
16
- if (!defined('_RECALC_PROFILE')) define("_RECALC_PROFILE", false);
17
-
18
- // TrueType Font Glyph operators
19
- define("GF_WORDS",(1 << 0));
20
- define("GF_SCALE",(1 << 3));
21
- define("GF_MORE",(1 << 5));
22
- define("GF_XYSCALE",(1 << 6));
23
- define("GF_TWOBYTWO",(1 << 7));
24
-
25
- // mPDF 5.7.1
26
- if(!function_exists('unicode_hex')){
27
- function unicode_hex($unicode_dec) {
28
- return (sprintf("%05s", strtoupper(dechex($unicode_dec))));
29
- }
30
- }
31
- class OTLdump {
32
-
33
- var $GPOSFeatures; // mPDF 5.7.1
34
- var $GPOSLookups; // mPDF 5.7.1
35
- var $GPOSScriptLang; // mPDF 5.7.1
36
- var $ignoreStrings; // mPDF 5.7.1
37
- var $MarkAttachmentType; // mPDF 5.7.1
38
- var $MarkGlyphSets; // mPDF 7.5.1
39
- var $GlyphClassMarks; // mPDF 5.7.1
40
- var $GlyphClassLigatures; // mPDF 5.7.1
41
- var $GlyphClassBases; // mPDF 5.7.1
42
- var $GlyphClassComponents; // mPDF 5.7.1
43
- var $GSUBScriptLang; // mPDF 5.7.1
44
- var $rtlPUAstr; // mPDF 5.7.1
45
- var $rtlPUAarr; // mPDF 5.7.1
46
- var $fontkey; // mPDF 5.7.1
47
- var $useOTL; // mPDF 5.7.1
48
- var $panose;
49
- var $maxUni;
50
- var $sFamilyClass;
51
- var $sFamilySubClass;
52
- var $sipset;
53
- var $smpset;
54
- var $_pos;
55
- var $numTables;
56
- var $searchRange;
57
- var $entrySelector;
58
- var $rangeShift;
59
- var $tables;
60
- var $otables;
61
- var $filename;
62
- var $fh;
63
- var $glyphPos;
64
- var $charToGlyph;
65
- var $ascent;
66
- var $descent;
67
- var $name;
68
- var $familyName;
69
- var $styleName;
70
- var $fullName;
71
- var $uniqueFontID;
72
- var $unitsPerEm;
73
- var $bbox;
74
- var $capHeight;
75
- var $stemV;
76
- var $italicAngle;
77
- var $flags;
78
- var $underlinePosition;
79
- var $underlineThickness;
80
- var $charWidths;
81
- var $defaultWidth;
82
- var $maxStrLenRead;
83
- var $numTTCFonts;
84
- var $TTCFonts;
85
- var $maxUniChar;
86
- var $kerninfo;
87
-
88
- function OTLdump(&$mpdf) {
89
- $this->mpdf = $mpdf;
90
- $this->maxStrLenRead = 200000; // Maximum size of glyf table to read in as string (otherwise reads each glyph from file)
91
- }
92
-
93
-
94
- function getMetrics($file, $fontkey, $TTCfontID=0, $debug=false, $BMPonly=false, $kerninfo=false, $useOTL=0, $mode) { // mPDF 5.7.1
95
- $this->mode = $mode;
96
- $this->useOTL = $useOTL; // mPDF 5.7.1
97
- $this->fontkey = $fontkey; // mPDF 5.7.1
98
- $this->filename = $file;
99
- $this->fh = fopen($file,'rb') or die('Can\'t open file ' . $file);
100
- $this->_pos = 0;
101
- $this->charWidths = '';
102
- $this->glyphPos = array();
103
- $this->charToGlyph = array();
104
- $this->tables = array();
105
- $this->otables = array();
106
- $this->kerninfo = array();
107
- $this->ascent = 0;
108
- $this->descent = 0;
109
- $this->numTTCFonts = 0;
110
- $this->TTCFonts = array();
111
- $this->version = $version = $this->read_ulong();
112
- $this->panose = array();
113
- if ($version==0x4F54544F)
114
- die("Postscript outlines are not supported");
115
- if ($version==0x74746366 && !$TTCfontID)
116
- die("ERROR - You must define the TTCfontID for a TrueType Collection in config_fonts.php (". $file.")");
117
- if (!in_array($version, array(0x00010000,0x74727565)) && !$TTCfontID)
118
- die("Not a TrueType font: version=".$version);
119
- if ($TTCfontID > 0) {
120
- $this->version = $version = $this->read_ulong(); // TTC Header version now
121
- if (!in_array($version, array(0x00010000,0x00020000)))
122
- die("ERROR - Error parsing TrueType Collection: version=".$version." - " . $file);
123
- $this->numTTCFonts = $this->read_ulong();
124
- for ($i=1; $i<=$this->numTTCFonts; $i++) {
125
- $this->TTCFonts[$i]['offset'] = $this->read_ulong();
126
- }
127
- $this->seek($this->TTCFonts[$TTCfontID]['offset']);
128
- $this->version = $version = $this->read_ulong(); // TTFont version again now
129
- }
130
- $this->readTableDirectory($debug);
131
- $this->extractInfo($debug, $BMPonly, $kerninfo, $useOTL);
132
- fclose($this->fh);
133
- }
134
-
135
-
136
- function readTableDirectory($debug=false) {
137
- $this->numTables = $this->read_ushort();
138
- $this->searchRange = $this->read_ushort();
139
- $this->entrySelector = $this->read_ushort();
140
- $this->rangeShift = $this->read_ushort();
141
- $this->tables = array();
142
- for ($i=0;$i<$this->numTables;$i++) {
143
- $record = array();
144
- $record['tag'] = $this->read_tag();
145
- $record['checksum'] = array($this->read_ushort(),$this->read_ushort());
146
- $record['offset'] = $this->read_ulong();
147
- $record['length'] = $this->read_ulong();
148
- $this->tables[$record['tag']] = $record;
149
- }
150
- if ($debug) $this->checksumTables();
151
- }
152
-
153
- function checksumTables() {
154
- // Check the checksums for all tables
155
- foreach($this->tables AS $t) {
156
- if ($t['length'] > 0 && $t['length'] < $this->maxStrLenRead) { // 1.02
157
- $table = $this->get_chunk($t['offset'], $t['length']);
158
- $checksum = $this->calcChecksum($table);
159
- if ($t['tag'] == 'head') {
160
- $up = unpack('n*', substr($table,8,4));
161
- $adjustment[0] = $up[1];
162
- $adjustment[1] = $up[2];
163
- $checksum = $this->sub32($checksum, $adjustment);
164
- }
165
- $xchecksum = $t['checksum'];
166
- if ($xchecksum != $checksum)
167
- die(sprintf('TTF file "%s": invalid checksum %s table: %s (expected %s)', $this->filename,dechex($checksum[0]).dechex($checksum[1]),$t['tag'],dechex($xchecksum[0]).dechex($xchecksum[1])));
168
- }
169
- }
170
- }
171
-
172
- function sub32($x, $y) {
173
- $xlo = $x[1];
174
- $xhi = $x[0];
175
- $ylo = $y[1];
176
- $yhi = $y[0];
177
- if ($ylo > $xlo) { $xlo += 1 << 16; $yhi += 1; }
178
- $reslo = $xlo-$ylo;
179
- if ($yhi > $xhi) { $xhi += 1 << 16; }
180
- $reshi = $xhi-$yhi;
181
- $reshi = $reshi & 0xFFFF;
182
- return array($reshi, $reslo);
183
- }
184
-
185
- function calcChecksum($data) {
186
- if (strlen($data) % 4) { $data .= str_repeat("\0",(4-(strlen($data) % 4))); }
187
- $len = strlen($data);
188
- $hi=0x0000;
189
- $lo=0x0000;
190
- for($i=0;$i<$len;$i+=4) {
191
- $hi += (ord($data[$i])<<8) + ord($data[$i+1]);
192
- $lo += (ord($data[$i+2])<<8) + ord($data[$i+3]);
193
- $hi += ($lo >> 16) & 0xFFFF;
194
- $lo = $lo & 0xFFFF;
195
- }
196
- return array($hi, $lo);
197
- }
198
-
199
- function get_table_pos($tag) {
200
- $offset = $this->tables[$tag]['offset'];
201
- $length = $this->tables[$tag]['length'];
202
- return array($offset, $length);
203
- }
204
-
205
- function seek($pos) {
206
- $this->_pos = $pos;
207
- fseek($this->fh,$this->_pos);
208
- }
209
-
210
- function skip($delta) {
211
- $this->_pos = $this->_pos + $delta;
212
- fseek($this->fh,$delta,SEEK_CUR);
213
- }
214
-
215
- function seek_table($tag, $offset_in_table = 0) {
216
- $tpos = $this->get_table_pos($tag);
217
- $this->_pos = $tpos[0] + $offset_in_table;
218
- fseek($this->fh, $this->_pos);
219
- return $this->_pos;
220
- }
221
-
222
- function read_tag() {
223
- $this->_pos += 4;
224
- return fread($this->fh,4);
225
- }
226
-
227
- function read_short() {
228
- $this->_pos += 2;
229
- $s = fread($this->fh,2);
230
- $a = (ord($s[0])<<8) + ord($s[1]);
231
- if ($a & (1 << 15) ) {
232
- $a = ($a - (1 << 16));
233
- }
234
- return $a;
235
- }
236
-
237
- function unpack_short($s) {
238
- $a = (ord($s[0])<<8) + ord($s[1]);
239
- if ($a & (1 << 15) ) {
240
- $a = ($a - (1 << 16));
241
- }
242
- return $a;
243
- }
244
-
245
- function read_ushort() {
246
- $this->_pos += 2;
247
- $s = fread($this->fh,2);
248
- return (ord($s[0])<<8) + ord($s[1]);
249
- }
250
-
251
- function read_ulong() {
252
- $this->_pos += 4;
253
- $s = fread($this->fh,4);
254
- // if large uInt32 as an integer, PHP converts it to -ve
255
- return (ord($s[0])*16777216) + (ord($s[1])<<16) + (ord($s[2])<<8) + ord($s[3]); // 16777216 = 1<<24
256
- }
257
-
258
- function get_ushort($pos) {
259
- fseek($this->fh,$pos);
260
- $s = fread($this->fh,2);
261
- return (ord($s[0])<<8) + ord($s[1]);
262
- }
263
-
264
- function get_ulong($pos) {
265
- fseek($this->fh,$pos);
266
- $s = fread($this->fh,4);
267
- // iF large uInt32 as an integer, PHP converts it to -ve
268
- return (ord($s[0])*16777216) + (ord($s[1])<<16) + (ord($s[2])<<8) + ord($s[3]); // 16777216 = 1<<24
269
- }
270
-
271
- function pack_short($val) {
272
- if ($val<0) {
273
- $val = abs($val);
274
- $val = ~$val;
275
- $val += 1;
276
- }
277
- return pack("n",$val);
278
- }
279
-
280
- function splice($stream, $offset, $value) {
281
- return substr($stream,0,$offset) . $value . substr($stream,$offset+strlen($value));
282
- }
283
-
284
- function _set_ushort($stream, $offset, $value) {
285
- $up = pack("n", $value);
286
- return $this->splice($stream, $offset, $up);
287
- }
288
-
289
- function _set_short($stream, $offset, $val) {
290
- if ($val<0) {
291
- $val = abs($val);
292
- $val = ~$val;
293
- $val += 1;
294
- }
295
- $up = pack("n",$val);
296
- return $this->splice($stream, $offset, $up);
297
- }
298
-
299
- function get_chunk($pos, $length) {
300
- fseek($this->fh,$pos);
301
- if ($length <1) { return ''; }
302
- return (fread($this->fh,$length));
303
- }
304
-
305
- function get_table($tag) {
306
- list($pos, $length) = $this->get_table_pos($tag);
307
- if ($length == 0) { return ''; }
308
- fseek($this->fh,$pos);
309
- return (fread($this->fh,$length));
310
- }
311
-
312
- function add($tag, $data) {
313
- if ($tag == 'head') {
314
- $data = $this->splice($data, 8, "\0\0\0\0");
315
- }
316
- $this->otables[$tag] = $data;
317
- }
318
-
319
-
320
-
321
-
322
- /////////////////////////////////////////////////////////////////////////////////////////
323
-
324
- /////////////////////////////////////////////////////////////////////////////////////////
325
-
326
- function extractInfo($debug=false, $BMPonly=false, $kerninfo=false, $useOTL=0) {
327
- $this->panose = array();
328
- $this->sFamilyClass = 0;
329
- $this->sFamilySubClass = 0;
330
- ///////////////////////////////////
331
- // name - Naming table
332
- ///////////////////////////////////
333
- $name_offset = $this->seek_table("name");
334
- $format = $this->read_ushort();
335
- if ($format != 0 && $format != 1)
336
- die("Unknown name table format ".$format);
337
- $numRecords = $this->read_ushort();
338
- $string_data_offset = $name_offset + $this->read_ushort();
339
- $names = array(1=>'',2=>'',3=>'',4=>'',6=>'');
340
- $K = array_keys($names);
341
- $nameCount = count($names);
342
- for ($i=0;$i<$numRecords; $i++) {
343
- $platformId = $this->read_ushort();
344
- $encodingId = $this->read_ushort();
345
- $languageId = $this->read_ushort();
346
- $nameId = $this->read_ushort();
347
- $length = $this->read_ushort();
348
- $offset = $this->read_ushort();
349
- if (!in_array($nameId,$K)) continue;
350
- $N = '';
351
- if ($platformId == 3 && $encodingId == 1 && $languageId == 0x409) { // Microsoft, Unicode, US English, PS Name
352
- $opos = $this->_pos;
353
- $this->seek($string_data_offset + $offset);
354
- if ($length % 2 != 0)
355
- die("PostScript name is UTF-16BE string of odd length");
356
- $length /= 2;
357
- $N = '';
358
- while ($length > 0) {
359
- $char = $this->read_ushort();
360
- $N .= (chr($char));
361
- $length -= 1;
362
- }
363
- $this->_pos = $opos;
364
- $this->seek($opos);
365
- }
366
- else if ($platformId == 1 && $encodingId == 0 && $languageId == 0) { // Macintosh, Roman, English, PS Name
367
- $opos = $this->_pos;
368
- $N = $this->get_chunk($string_data_offset + $offset, $length);
369
- $this->_pos = $opos;
370
- $this->seek($opos);
371
- }
372
- if ($N && $names[$nameId]=='') {
373
- $names[$nameId] = $N;
374
- $nameCount -= 1;
375
- if ($nameCount==0) break;
376
- }
377
- }
378
- if ($names[6])
379
- $psName = $names[6];
380
- else if ($names[4])
381
- $psName = preg_replace('/ /','-',$names[4]);
382
- else if ($names[1])
383
- $psName = preg_replace('/ /','-',$names[1]);
384
- else
385
- $psName = '';
386
- if (!$psName)
387
- die("Could not find PostScript font name: ".$this->filename);
388
- if ($debug) {
389
- for ($i=0;$i<count($psName);$i++) {
390
- $c = $psName[$i];
391
- $oc = ord($c);
392
- if ($oc>126 || strpos(' [](){}<>/%',$c)!==false)
393
- die("psName=".$psName." contains invalid character ".$c." ie U+".ord(c));
394
- }
395
- }
396
- $this->name = $psName;
397
- if ($names[1]) { $this->familyName = $names[1]; } else { $this->familyName = $psName; }
398
- if ($names[2]) { $this->styleName = $names[2]; } else { $this->styleName = 'Regular'; }
399
- if ($names[4]) { $this->fullName = $names[4]; } else { $this->fullName = $psName; }
400
- if ($names[3]) { $this->uniqueFontID = $names[3]; } else { $this->uniqueFontID = $psName; }
401
-
402
- if ($names[6]) { $this->fullName = $names[6]; }
403
-
404
- ///////////////////////////////////
405
- // head - Font header table
406
- ///////////////////////////////////
407
- $this->seek_table("head");
408
- if ($debug) {
409
- $ver_maj = $this->read_ushort();
410
- $ver_min = $this->read_ushort();
411
- if ($ver_maj != 1)
412
- die('Unknown head table version '. $ver_maj .'.'. $ver_min);
413
- $this->fontRevision = $this->read_ushort() . $this->read_ushort();
414
-
415
- $this->skip(4);
416
- $magic = $this->read_ulong();
417
- if ($magic != 0x5F0F3CF5)
418
- die('Invalid head table magic ' .$magic);
419
- $this->skip(2);
420
- }
421
- else {
422
- $this->skip(18);
423
- }
424
- $this->unitsPerEm = $unitsPerEm = $this->read_ushort();
425
- $scale = 1000 / $unitsPerEm;
426
- $this->skip(16);
427
- $xMin = $this->read_short();
428
- $yMin = $this->read_short();
429
- $xMax = $this->read_short();
430
- $yMax = $this->read_short();
431
- $this->bbox = array(($xMin*$scale), ($yMin*$scale), ($xMax*$scale), ($yMax*$scale));
432
- $this->skip(3*2);
433
- $indexToLocFormat = $this->read_ushort();
434
- $glyphDataFormat = $this->read_ushort();
435
- if ($glyphDataFormat != 0)
436
- die('Unknown glyph data format '.$glyphDataFormat);
437
-
438
- ///////////////////////////////////
439
- // hhea metrics table
440
- ///////////////////////////////////
441
- // ttf2t1 seems to use this value rather than the one in OS/2 - so put in for compatibility
442
- if (isset($this->tables["hhea"])) {
443
- $this->seek_table("hhea");
444
- $this->skip(4);
445
- $hheaAscender = $this->read_short();
446
- $hheaDescender = $this->read_short();
447
- $this->ascent = ($hheaAscender *$scale);
448
- $this->descent = ($hheaDescender *$scale);
449
- }
450
-
451
- ///////////////////////////////////
452
- // OS/2 - OS/2 and Windows metrics table
453
- ///////////////////////////////////
454
- if (isset($this->tables["OS/2"])) {
455
- $this->seek_table("OS/2");
456
- $version = $this->read_ushort();
457
- $this->skip(2);
458
- $usWeightClass = $this->read_ushort();
459
- $this->skip(2);
460
- $fsType = $this->read_ushort();
461
- if ($fsType == 0x0002 || ($fsType & 0x0300) != 0) {
462
- global $overrideTTFFontRestriction;
463
- if (!$overrideTTFFontRestriction) die('ERROR - Font file '.$this->filename.' cannot be embedded due to copyright restrictions.');
464
- $this->restrictedUse = true;
465
- }
466
- $this->skip(20);
467
- $sF = $this->read_short();
468
- $this->sFamilyClass = ($sF >> 8);
469
- $this->sFamilySubClass = ($sF & 0xFF);
470
- $this->_pos += 10; //PANOSE = 10 byte length
471
- $panose = fread($this->fh,10);
472
- $this->panose = array();
473
- for ($p=0;$p<strlen($panose);$p++) { $this->panose[] = ord($panose[$p]); }
474
- $this->skip(26);
475
- $sTypoAscender = $this->read_short();
476
- $sTypoDescender = $this->read_short();
477
- if (!$this->ascent) $this->ascent = ($sTypoAscender*$scale);
478
- if (!$this->descent) $this->descent = ($sTypoDescender*$scale);
479
- if ($version > 1) {
480
- $this->skip(16);
481
- $sCapHeight = $this->read_short();
482
- $this->capHeight = ($sCapHeight*$scale);
483
- }
484
- else {
485
- $this->capHeight = $this->ascent;
486
- }
487
- }
488
- else {
489
- $usWeightClass = 500;
490
- if (!$this->ascent) $this->ascent = ($yMax*$scale);
491
- if (!$this->descent) $this->descent = ($yMin*$scale);
492
- $this->capHeight = $this->ascent;
493
- }
494
- $this->stemV = 50 + intval(pow(($usWeightClass / 65.0),2));
495
-
496
- ///////////////////////////////////
497
- // post - PostScript table
498
- ///////////////////////////////////
499
- $this->seek_table("post");
500
- if ($debug) {
501
- $ver_maj = $this->read_ushort();
502
- $ver_min = $this->read_ushort();
503
- if ($ver_maj <1 || $ver_maj >4)
504
- die('Unknown post table version '.$ver_maj);
505
- }
506
- else {
507
- $this->skip(4);
508
- }
509
- $this->italicAngle = $this->read_short() + $this->read_ushort() / 65536.0;
510
- $this->underlinePosition = $this->read_short() * $scale;
511
- $this->underlineThickness = $this->read_short() * $scale;
512
- $isFixedPitch = $this->read_ulong();
513
-
514
- $this->flags = 4;
515
-
516
- if ($this->italicAngle!= 0)
517
- $this->flags = $this->flags | 64;
518
- if ($usWeightClass >= 600)
519
- $this->flags = $this->flags | 262144;
520
- if ($isFixedPitch)
521
- $this->flags = $this->flags | 1;
522
-
523
- ///////////////////////////////////
524
- // hhea - Horizontal header table
525
- ///////////////////////////////////
526
- $this->seek_table("hhea");
527
- if ($debug) {
528
- $ver_maj = $this->read_ushort();
529
- $ver_min = $this->read_ushort();
530
- if ($ver_maj != 1)
531
- die('Unknown hhea table version '.$ver_maj);
532
- $this->skip(28);
533
- }
534
- else {
535
- $this->skip(32);
536
- }
537
- $metricDataFormat = $this->read_ushort();
538
- if ($metricDataFormat != 0)
539
- die('Unknown horizontal metric data format '.$metricDataFormat);
540
- $numberOfHMetrics = $this->read_ushort();
541
- if ($numberOfHMetrics == 0)
542
- die('Number of horizontal metrics is 0');
543
-
544
- ///////////////////////////////////
545
- // maxp - Maximum profile table
546
- ///////////////////////////////////
547
- $this->seek_table("maxp");
548
- if ($debug) {
549
- $ver_maj = $this->read_ushort();
550
- $ver_min = $this->read_ushort();
551
- if ($ver_maj != 1)
552
- die('Unknown maxp table version '.$ver_maj);
553
- }
554
- else {
555
- $this->skip(4);
556
- }
557
- $numGlyphs = $this->read_ushort();
558
-
559
-
560
- ///////////////////////////////////
561
- // cmap - Character to glyph index mapping table
562
- ///////////////////////////////////
563
- $cmap_offset = $this->seek_table("cmap");
564
- $this->skip(2);
565
- $cmapTableCount = $this->read_ushort();
566
- $unicode_cmap_offset = 0;
567
- for ($i=0;$i<$cmapTableCount;$i++) {
568
- $platformID = $this->read_ushort();
569
- $encodingID = $this->read_ushort();
570
- $offset = $this->read_ulong();
571
- $save_pos = $this->_pos;
572
- if (($platformID == 3 && $encodingID == 1) || $platformID == 0) { // Microsoft, Unicode
573
- $format = $this->get_ushort($cmap_offset + $offset);
574
- if ($format == 4) {
575
- if (!$unicode_cmap_offset) $unicode_cmap_offset = $cmap_offset + $offset;
576
- if ($BMPonly) break;
577
- }
578
- }
579
- // Microsoft, Unicode Format 12 table HKCS
580
- else if ((($platformID == 3 && $encodingID == 10) || $platformID == 0) && !$BMPonly) {
581
- $format = $this->get_ushort($cmap_offset + $offset);
582
- if ($format == 12) {
583
- $unicode_cmap_offset = $cmap_offset + $offset;
584
- break;
585
- }
586
- }
587
- $this->seek($save_pos );
588
- }
589
-
590
- if (!$unicode_cmap_offset)
591
- die('Font ('.$this->filename .') does not have cmap for Unicode (platform 3, encoding 1, format 4, or platform 0, any encoding, format 4)');
592
-
593
-
594
- $sipset = false;
595
- $smpset = false;
596
-
597
- // mPDF 5.7.1
598
- $this->GSUBScriptLang = array();
599
- $this->rtlPUAstr = '';
600
- $this->rtlPUAarr = array();
601
- $this->GSUBFeatures = array();
602
- $this->GSUBLookups = array();
603
- $this->GPOSScriptLang = array();
604
- $this->GPOSFeatures = array();
605
- $this->GPOSLookups = array();
606
- $this->glyphIDtoUni = '';
607
-
608
- // Format 12 CMAP does characters above Unicode BMP i.e. some HKCS characters U+20000 and above
609
- if ($format == 12 && !$BMPonly) {
610
- $this->maxUniChar = 0;
611
- $this->seek($unicode_cmap_offset + 4);
612
- $length = $this->read_ulong();
613
- $limit = $unicode_cmap_offset + $length;
614
- $this->skip(4);
615
-
616
- $nGroups = $this->read_ulong();
617
-
618
- $glyphToChar = array();
619
- $charToGlyph = array();
620
- for($i=0; $i<$nGroups ; $i++) {
621
- $startCharCode = $this->read_ulong();
622
- $endCharCode = $this->read_ulong();
623
- $startGlyphCode = $this->read_ulong();
624
- if ($endCharCode > 0x20000 && $endCharCode < 0x2FFFF) {
625
- $sipset = true;
626
- }
627
- else if ($endCharCode > 0x10000 && $endCharCode < 0x1FFFF) {
628
- $smpset = true;
629
- }
630
- $offset = 0;
631
- for ($unichar=$startCharCode;$unichar<=$endCharCode;$unichar++) {
632
- $glyph = $startGlyphCode + $offset ;
633
- $offset++;
634
- if ($unichar < 0x30000) {
635
- $charToGlyph[$unichar] = $glyph;
636
- $this->maxUniChar = max($unichar,$this->maxUniChar);
637
- $glyphToChar[$glyph][] = $unichar;
638
- }
639
- }
640
- }
641
- }
642
- else {
643
-
644
- $glyphToChar = array();
645
- $charToGlyph = array();
646
- $this->getCMAP4($unicode_cmap_offset, $glyphToChar, $charToGlyph );
647
-
648
- }
649
- $this->sipset = $sipset ;
650
- $this->smpset = $smpset ;
651
-
652
-
653
- ///////////////////////////////////
654
- // mPDF 5.7.1
655
- // Map Unmapped glyphs - from $numGlyphs
656
- if ($this->useOTL) {
657
- $bctr = 0xE000;
658
- for ($gid=1; $gid<$numGlyphs; $gid++) {
659
- if (!isset($glyphToChar[$gid])) {
660
- while(isset($charToGlyph[$bctr])) { $bctr++; } // Avoid overwriting a glyph already mapped in PUA
661
- if (($bctr > 0xF8FF) && ($bctr < 0x2CEB0)) {
662
- if (!$BMPonly) {
663
- $bctr = 0x2CEB0; // Use unassigned area 0x2CEB0 to 0x2F7FF (space for 10,000 characters)
664
- $this->sipset = $sipset = true; // forces subsetting; also ensure charwidths are saved
665
- while(isset($charToGlyph[$bctr])) { $bctr++; }
666
- }
667
- else { die($names[1]." : WARNING - The font does not have enough space to map all (unmapped) included glyphs into Private Use Area U+E000 - U+F8FF"); }
668
- }
669
- $glyphToChar[$gid][] = $bctr;
670
- $charToGlyph[$bctr] = $gid;
671
- $this->maxUniChar = max($bctr,$this->maxUniChar);
672
- $bctr++;
673
- }
674
- }
675
- }
676
- $this->glyphToChar = $glyphToChar;
677
- $this->charToGlyph = $charToGlyph;
678
- ///////////////////////////////////
679
- // mPDF 5.7.1 OpenType Layout tables
680
- $this->GSUBScriptLang=array(); $this->rtlPUAstr = ''; $this->rtlPUAarr = array();
681
- if ($useOTL) {
682
- $this->_getGDEFtables();
683
- list($this->GSUBScriptLang, $this->GSUBFeatures, $this->GSUBLookups, $this->rtlPUAstr, $this->rtlPUAarr) = $this->_getGSUBtables();
684
- list($this->GPOSScriptLang, $this->GPOSFeatures, $this->GPOSLookups) = $this->_getGPOStables();
685
- $this->glyphIDtoUni = str_pad('', 256*256*3, "\x00");
686
- foreach($glyphToChar AS $gid=>$arr) {
687
- if (isset($glyphToChar[$gid][0])) {
688
- $char = $glyphToChar[$gid][0];
689
- if ($char != 0 && $char != 65535) {
690
- $this->glyphIDtoUni[$gid*3] = chr($char >> 16);
691
- $this->glyphIDtoUni[$gid*3 + 1] = chr(($char >> 8) & 0xFF);
692
- $this->glyphIDtoUni[$gid*3 + 2] = chr($char & 0xFF);
693
- }
694
- }
695
- }
696
- }
697
- ///////////////////////////////////
698
-
699
- ///////////////////////////////////
700
- // hmtx - Horizontal metrics table
701
- ///////////////////////////////////
702
- $this->getHMTX($numberOfHMetrics, $numGlyphs, $glyphToChar, $scale);
703
-
704
- ///////////////////////////////////
705
- // kern - Kerning pair table
706
- ///////////////////////////////////
707
- if ($kerninfo) {
708
- // Recognises old form of Kerning table - as required by Windows - Format 0 only
709
- $kern_offset = $this->seek_table("kern");
710
- $version = $this->read_ushort();
711
- $nTables = $this->read_ushort();
712
- // subtable header
713
- $sversion = $this->read_ushort();
714
- $slength = $this->read_ushort();
715
- $scoverage = $this->read_ushort();
716
- $format = $scoverage >> 8;
717
- if ($kern_offset && $version==0 && $format==0) {
718
- // Format 0
719
- $nPairs = $this->read_ushort();
720
- $this->skip(6);
721
- for ($i=0; $i<$nPairs; $i++) {
722
- $left = $this->read_ushort();
723
- $right = $this->read_ushort();
724
- $val = $this->read_short();
725
- if (count($glyphToChar[$left])==1 && count($glyphToChar[$right])==1) {
726
- if ($left != 32 && $right != 32) {
727
- $this->kerninfo[$glyphToChar[$left][0]][$glyphToChar[$right][0]] = intval($val*$scale);
728
- }
729
- }
730
- }
731
- }
732
- }
733
- }
734
-
735
-
736
- /////////////////////////////////////////////////////////////////////////////////////////
737
- function _getGDEFtables() {
738
- ///////////////////////////////////
739
- // GDEF - Glyph Definition
740
- ///////////////////////////////////
741
- // http://www.microsoft.com/typography/otspec/gdef.htm
742
- if (isset($this->tables["GDEF"])) {
743
- if ($this->mode == 'summary') { $this->mpdf->WriteHTML('<h1>GDEF table</h1>'); }
744
- $gdef_offset = $this->seek_table("GDEF");
745
- // ULONG Version of the GDEF table-currently 0x00010000
746
- $ver_maj = $this->read_ushort();
747
- $ver_min = $this->read_ushort();
748
- // Version 0x00010002 of GDEF header contains additional Offset to a list defining mark glyph set definitions (MarkGlyphSetDef)
749
- $GlyphClassDef_offset = $this->read_ushort();
750
- $AttachList_offset = $this->read_ushort();
751
- $LigCaretList_offset = $this->read_ushort();
752
- $MarkAttachClassDef_offset = $this->read_ushort();
753
- if ($ver_min == 2) {
754
- $MarkGlyphSetsDef_offset = $this->read_ushort();
755
- }
756
-
757
- // GlyphClassDef
758
- $this->seek($gdef_offset+$GlyphClassDef_offset );
759
- /*
760
- 1 Base glyph (single character, spacing glyph)
761
- 2 Ligature glyph (multiple character, spacing glyph)
762
- 3 Mark glyph (non-spacing combining glyph)
763
- 4 Component glyph (part of single character, spacing glyph)
764
- */
765
- $GlyphByClass = $this->_getClassDefinitionTable();
766
-
767
- if ($this->mode == 'summary') {
768
- $this->mpdf->WriteHTML('<h2>Glyph classes</h2>');
769
- }
770
-
771
- if (isset($GlyphByClass[1]) && count($GlyphByClass[1])>0) {
772
- $this->GlyphClassBases = $this->formatClassArr($GlyphByClass[1]);
773
- if ($this->mode == 'summary') {
774
- $this->mpdf->WriteHTML('<h3>Glyph class 1</h3>');
775
- $this->mpdf->WriteHTML('<h5>Base glyph (single character, spacing glyph)</h5>');
776
- $html = '';
777
- $html .= '<div class="glyphs">';
778
- foreach ($GlyphByClass[1] AS $g) {
779
- $html .= '&#x'.$g.'; ';
780
- }
781
- $html .= '</div>';
782
- $this->mpdf->WriteHTML($html);
783
- }
784
- }
785
- else { $this->GlyphClassBases = ''; }
786
- if (isset($GlyphByClass[2]) && count($GlyphByClass[2])>0) {
787
- $this->GlyphClassLigatures = $this->formatClassArr($GlyphByClass[2]);
788
- if ($this->mode == 'summary') {
789
- $this->mpdf->WriteHTML('<h3>Glyph class 2</h3>');
790
- $this->mpdf->WriteHTML('<h5>Ligature glyph (multiple character, spacing glyph)</h5>');
791
- $html = '';
792
- $html .= '<div class="glyphs">';
793
- foreach ($GlyphByClass[2] AS $g) {
794
- $html .= '&#x'.$g.'; ';
795
- }
796
- $html .= '</div>';
797
- $this->mpdf->WriteHTML($html);
798
- }
799
- }
800
- else { $this->GlyphClassLigatures = ''; }
801
- if (isset($GlyphByClass[3]) && count($GlyphByClass[3])>0) {
802
- $this->GlyphClassMarks = $this->formatClassArr($GlyphByClass[3]);
803
- if ($this->mode == 'summary') {
804
- $this->mpdf->WriteHTML('<h3>Glyph class 3</h3>');
805
- $this->mpdf->WriteHTML('<h5>Mark glyph (non-spacing combining glyph)</h5>');
806
- $html = '';
807
- $html .= '<div class="glyphs">';
808
- foreach ($GlyphByClass[3] AS $g) {
809
- $html .= '&#x25cc;&#x'.$g.'; ';
810
- }
811
- $html .= '</div>';
812
- $this->mpdf->WriteHTML($html);
813
- }
814
- }
815
- else { $this->GlyphClassMarks = ''; }
816
- if (isset($GlyphByClass[4]) && count($GlyphByClass[4])>0) {
817
- $this->GlyphClassComponents = $this->formatClassArr($GlyphByClass[4]);
818
- if ($this->mode == 'summary') {
819
- $this->mpdf->WriteHTML('<h3>Glyph class 4</h3>');
820
- $this->mpdf->WriteHTML('<h5>Component glyph (part of single character, spacing glyph)</h5>');
821
- $html = '';
822
- $html .= '<div class="glyphs">';
823
- foreach ($GlyphByClass[4] AS $g) {
824
- $html .= '&#x'.$g.'; ';
825
- }
826
- $html .= '</div>';
827
- $this->mpdf->WriteHTML($html);
828
- }
829
- }
830
- else { $this->GlyphClassComponents = ''; }
831
-
832
- $Marks = $GlyphByClass[3]; // to use for MarkAttachmentType
833
-
834
-
835
- /* Required for GPOS
836
- // Attachment List
837
- if ($AttachList_offset) {
838
- $this->seek($gdef_offset+$AttachList_offset );
839
- }
840
- The Attachment Point List table (AttachmentList) identifies all the attachment points defined in the GPOS table and their associated glyphs so a client can quickly access coordinates for each glyph's attachment points. As a result, the client can cache coordinates for attachment points along with glyph bitmaps and avoid recalculating the attachment points each time it displays a glyph. Without this table, processing speed would be slower because the client would have to decode the GPOS lookups that define attachment points and compile the points in a list.
841
-
842
- The Attachment List table (AttachList) may be used to cache attachment point coordinates along with glyph bitmaps.
843
-
844
- The table consists of an offset to a Coverage table (Coverage) listing all glyphs that define attachment points in the GPOS table, a count of the glyphs with attachment points (GlyphCount), and an array of offsets to AttachPoint tables (AttachPoint). The array lists the AttachPoint tables, one for each glyph in the Coverage table, in the same order as the Coverage Index.
845
- AttachList table
846
- Type Name Description
847
- Offset Coverage Offset to Coverage table - from beginning of AttachList table
848
- uint16 GlyphCount Number of glyphs with attachment points
849
- Offset AttachPoint[GlyphCount] Array of offsets to AttachPoint tables-from beginning of AttachList table-in Coverage Index order
850
-
851
- An AttachPoint table consists of a count of the attachment points on a single glyph (PointCount) and an array of contour indices of those points (PointIndex), listed in increasing numerical order.
852
-
853
- AttachPoint table
854
- Type Name Description
855
- uint16 PointCount Number of attachment points on this glyph
856
- uint16 PointIndex[PointCount] Array of contour point indices -in increasing numerical order
857
-
858
- See Example 3 - http://www.microsoft.com/typography/otspec/gdef.htm
859
- */
860
-
861
-
862
- // Ligature Caret List
863
- // The Ligature Caret List table (LigCaretList) defines caret positions for all the ligatures in a font.
864
- // Not required for mDPF
865
-
866
-
867
- // MarkAttachmentType
868
- if ($MarkAttachClassDef_offset) {
869
- if ($this->mode == 'summary') { $this->mpdf->WriteHTML('<h1>Mark Attachment Types</h1>'); }
870
- $this->seek($gdef_offset+$MarkAttachClassDef_offset );
871
- $MarkAttachmentTypes = $this->_getClassDefinitionTable();
872
- foreach($MarkAttachmentTypes AS $class=>$glyphs) {
873
-
874
- if (is_array($Marks) && count($Marks)) {
875
- $mat = array_diff($Marks, $MarkAttachmentTypes[$class]);
876
- sort($mat, SORT_STRING);
877
- }
878
- else { $mat = array(); }
879
-
880
- $this->MarkAttachmentType[$class] = $this->formatClassArr($mat);
881
-
882
- if ($this->mode == 'summary') {
883
- $this->mpdf->WriteHTML('<h3>Mark Attachment Type: '.$class.'</h3>');
884
- $html = '';
885
- $html .= '<div class="glyphs">';
886
- foreach ($glyphs AS $g) {
887
- $html .= '&#x25cc;&#x'.$g.'; ';
888
- }
889
- $html .= '</div>';
890
- $this->mpdf->WriteHTML($html);
891
- }
892
- }
893
- }
894
- else { $this->MarkAttachmentType = array(); }
895
-
896
-
897
- // MarkGlyphSets only in Version 0x00010002 of GDEF
898
- if ($ver_min == 2 && $MarkGlyphSetsDef_offset) {
899
- if ($this->mode == 'summary') { $this->mpdf->WriteHTML('<h1>Mark Glyph Sets</h1>'); }
900
- $this->seek($gdef_offset+$MarkGlyphSetsDef_offset);
901
- $MarkSetTableFormat = $this->read_ushort();
902
- $MarkSetCount = $this->read_ushort();
903
- $MarkSetOffset = array();
904
- for ($i=0;$i<$MarkSetCount;$i++) {
905
- $MarkSetOffset[] = $this->read_ulong();
906
- }
907
- for ($i=0;$i<$MarkSetCount;$i++) {
908
- $this->seek($MarkSetOffset[$i]);
909
- $glyphs = $this->_getCoverage();
910
- $this->MarkGlyphSets[$i] = $this->formatClassArr($glyphs);
911
- if ($this->mode == 'summary') {
912
- $this->mpdf->WriteHTML('<h3>Mark Glyph Set class: '.$i.'</h3>');
913
- $html = '';
914
- $html .= '<div class="glyphs">';
915
- foreach ($glyphs AS $g) {
916
- $html .= '&#x25cc;&#x'.$g.'; ';
917
- }
918
- $html .= '</div>';
919
- $this->mpdf->WriteHTML($html);
920
- }
921
- }
922
- }
923
- else { $this->MarkGlyphSets = array(); }
924
- }
925
- else { $this->mpdf->WriteHTML('<div>GDEF table not defined</div>'); }
926
-
927
-
928
- //echo $this->GlyphClassMarks ; exit;
929
- //print_r($GlyphClass); exit;
930
- //print_r($GlyphByClass); exit;
931
- }
932
-
933
- function _getClassDefinitionTable($offset=0) {
934
-
935
- if ($offset>0) {
936
- $this->seek($offset);
937
- }
938
-
939
- // NB Any glyph not included in the range of covered GlyphIDs automatically belongs to Class 0. This is not returned by this function
940
- $ClassFormat = $this->read_ushort();
941
- $GlyphByClass = array();
942
- if ($ClassFormat == 1) {
943
- $StartGlyph = $this->read_ushort();
944
- $GlyphCount = $this->read_ushort();
945
- for ($i=0;$i<$GlyphCount;$i++) {
946
- $gid = $StartGlyph + $i;
947
- $class = $this->read_ushort();
948
- $GlyphByClass[$class][] = unicode_hex($this->glyphToChar[$gid][0]);
949
- }
950
- }
951
- else if ($ClassFormat == 2) {
952
- $tableCount = $this->read_ushort();
953
- for ($i=0;$i<$tableCount;$i++) {
954
- $startGlyphID = $this->read_ushort();
955
- $endGlyphID = $this->read_ushort();
956
- $class = $this->read_ushort();
957
- for($gid=$startGlyphID;$gid<=$endGlyphID;$gid++) {
958
- $GlyphByClass[$class][] = unicode_hex($this->glyphToChar[$gid][0]);
959
- }
960
- }
961
- }
962
- ksort($GlyphByClass);
963
- return $GlyphByClass;
964
- }
965
-
966
- function _getGSUBtables() {
967
- ///////////////////////////////////
968
- // GSUB - Glyph Substitution
969
- ///////////////////////////////////
970
- if (isset($this->tables["GSUB"])) {
971
- $this->mpdf->WriteHTML('<h1>GSUB Tables</h1>');
972
- $ffeats = array();
973
- $gsub_offset = $this->seek_table("GSUB");
974
- $this->skip(4);
975
- $ScriptList_offset = $gsub_offset + $this->read_ushort();
976
- $FeatureList_offset = $gsub_offset + $this->read_ushort();
977
- $LookupList_offset = $gsub_offset + $this->read_ushort();
978
-
979
- // ScriptList
980
- $this->seek($ScriptList_offset );
981
- $ScriptCount = $this->read_ushort();
982
- for ($i=0;$i<$ScriptCount;$i++) {
983
- $ScriptTag = $this->read_tag(); // = "beng", "deva" etc.
984
- $ScriptTableOffset = $this->read_ushort();
985
- $ffeats[$ScriptTag] = $ScriptList_offset + $ScriptTableOffset;
986
- }
987
-
988
- // Script Table
989
- foreach($ffeats AS $t=>$o) {
990
- $ls = array();
991
- $this->seek($o);
992
- $DefLangSys_offset = $this->read_ushort();
993
- if ($DefLangSys_offset > 0) {
994
- $ls['DFLT'] = $DefLangSys_offset + $o;
995
- }
996
- $LangSysCount = $this->read_ushort();
997
- for ($i=0;$i<$LangSysCount;$i++) {
998
- $LangTag = $this->read_tag(); // =
999
- $LangTableOffset = $this->read_ushort();
1000
- $ls[$LangTag] = $o + $LangTableOffset;
1001
- }
1002
- $ffeats[$t] = $ls;
1003
- }
1004
- //print_r($ffeats); exit;
1005
-
1006
-
1007
- // Get FeatureIndexList
1008
- // LangSys Table - from first listed langsys
1009
- foreach($ffeats AS $st=>$scripts) {
1010
- foreach($scripts AS $t=>$o) {
1011
- $FeatureIndex = array();
1012
- $langsystable_offset = $o;
1013
- $this->seek($langsystable_offset);
1014
- $LookUpOrder = $this->read_ushort(); //==NULL
1015
- $ReqFeatureIndex = $this->read_ushort();
1016
- if ($ReqFeatureIndex != 0xFFFF) { $FeatureIndex[] = $ReqFeatureIndex; }
1017
- $FeatureCount = $this->read_ushort();
1018
- for ($i=0;$i<$FeatureCount;$i++) {
1019
- $FeatureIndex[] = $this->read_ushort(); // = index of feature
1020
- }
1021
- $ffeats[$st][$t] = $FeatureIndex;
1022
- }
1023
- }
1024
- //print_r($ffeats); exit;
1025
-
1026
-
1027
- // Feauture List => LookupListIndex es
1028
- $this->seek($FeatureList_offset );
1029
- $FeatureCount = $this->read_ushort();
1030
- $Feature = array();
1031
- for ($i=0;$i<$FeatureCount;$i++) {
1032
- $Feature[$i] = array('tag' => $this->read_tag() );
1033
- $Feature[$i]['offset'] = $FeatureList_offset + $this->read_ushort();
1034
- }
1035
- for ($i=0;$i<$FeatureCount;$i++) {
1036
- $this->seek($Feature[$i]['offset']);
1037
- $this->read_ushort(); // null
1038
- $Feature[$i]['LookupCount'] = $Lookupcount = $this->read_ushort();
1039
- $Feature[$i]['LookupListIndex'] = array();
1040
- for ($c=0;$c<$Lookupcount;$c++) {
1041
- $Feature[$i]['LookupListIndex'][] = $this->read_ushort();
1042
- }
1043
- }
1044
-
1045
-
1046
- foreach($ffeats AS $st=>$scripts) {
1047
- foreach($scripts AS $t=>$o) {
1048
- $FeatureIndex = $ffeats[$st][$t];
1049
- foreach($FeatureIndex AS $k=>$fi) {
1050
- $ffeats[$st][$t][$k] = $Feature[$fi];
1051
- }
1052
- }
1053
- }
1054
- //=====================================================================================
1055
- $gsub = array();
1056
- $GSUBScriptLang = array();
1057
- foreach($ffeats AS $st=>$scripts) {
1058
- foreach($scripts AS $t=>$langsys) {
1059
- $lg = array();
1060
- foreach($langsys AS $ft) {
1061
- $lg[$ft['LookupListIndex'][0]] = $ft;
1062
- }
1063
- // list of Lookups in order they need to be run i.e. order listed in Lookup table
1064
- ksort($lg);
1065
- foreach($lg AS $ft) {
1066
- $gsub[$st][$t][$ft['tag']] = $ft['LookupListIndex'];
1067
- }
1068
- if (!isset($GSUBScriptLang[$st])) { $GSUBScriptLang[$st] = ''; }
1069
- $GSUBScriptLang[$st] .= $t.' ';
1070
- }
1071
- }
1072
-
1073
- //print_r($gsub); exit;
1074
-
1075
- if ($this->mode == 'summary') {
1076
- $this->mpdf->WriteHTML('<h3>GSUB Scripts &amp; Languages</h3>');
1077
- $this->mpdf->WriteHTML('<div class="glyphs">');
1078
- $html = '';
1079
- if (count($gsub)) {
1080
- foreach ($gsub AS $st=>$g) {
1081
- $html .= '<h5>'.$st.'</h5>';
1082
- foreach ($g AS $l=>$t) {
1083
- $html .= '<div><a href="font_dump_OTL.php?script='.$st.'&lang='.$l.'">'.$l.'</a></b>: ';
1084
- foreach ($t AS $tag=>$o) {
1085
- $html .= $tag.' ';
1086
- }
1087
- $html .= '</div>';
1088
- }
1089
- }
1090
- }
1091
- else {
1092
- $html .= '<div>No entries in GSUB table.</div>';
1093
- }
1094
- $this->mpdf->WriteHTML($html);
1095
- $this->mpdf->WriteHTML('</div>');
1096
- return 0;
1097
- }
1098
-
1099
-
1100
-
1101
- //=====================================================================================
1102
- // Get metadata and offsets for whole Lookup List table
1103
- $this->seek($LookupList_offset );
1104
- $LookupCount = $this->read_ushort();
1105
- $GSLookup = array();
1106
- $Offsets = array();
1107
- $SubtableCount = array();
1108
- for ($i=0;$i<$LookupCount;$i++) {
1109
- $Offsets[$i] = $LookupList_offset + $this->read_ushort();
1110
- }
1111
- for ($i=0;$i<$LookupCount;$i++) {
1112
- $this->seek($Offsets[$i]);
1113
- $GSLookup[$i]['Type'] = $this->read_ushort();
1114
- $GSLookup[$i]['Flag'] = $flag = $this->read_ushort();
1115
- $GSLookup[$i]['SubtableCount'] = $SubtableCount[$i] = $this->read_ushort();
1116
- for ($c=0;$c<$SubtableCount[$i] ;$c++) {
1117
- $GSLookup[$i]['Subtables'][$c] = $Offsets[$i] + $this->read_ushort();
1118
-
1119
- }
1120
- // MarkFilteringSet = Index (base 0) into GDEF mark glyph sets structure
1121
- if (($flag & 0x0010) == 0x0010) {
1122
- $GSLookup[$i]['MarkFilteringSet'] = $this->read_ushort();
1123
- }
1124
- // else { $GSLookup[$i]['MarkFilteringSet'] = ''; }
1125
-
1126
- // Lookup Type 7: Extension
1127
- if ($GSLookup[$i]['Type'] == 7) {
1128
- // Overwrites new offset (32-bit) for each subtable, and a new lookup Type
1129
- for ($c=0;$c<$SubtableCount[$i] ;$c++) {
1130
- $this->seek($GSLookup[$i]['Subtables'][$c]);
1131
- $ExtensionPosFormat = $this->read_ushort();
1132
- $type = $this->read_ushort();
1133
- $GSLookup[$i]['Subtables'][$c] = $GSLookup[$i]['Subtables'][$c] + $this->read_ulong();
1134
- }
1135
- $GSLookup[$i]['Type'] = $type;
1136
- }
1137
-
1138
- }
1139
-
1140
- //print_r($GSLookup); exit;
1141
- //=====================================================================================
1142
- // Process Whole LookupList - Get LuCoverage = Lookup coverage just for first glyph
1143
- $this->GSLuCoverage = array();
1144
- for ($i=0;$i<$LookupCount;$i++) {
1145
- for ($c=0;$c<$GSLookup[$i]['SubtableCount'] ;$c++) {
1146
-
1147
- $this->seek($GSLookup[$i]['Subtables'][$c]);
1148
- $PosFormat= $this->read_ushort();
1149
-
1150
- if ($GSLookup[$i]['Type']==5 && $PosFormat==3) { $this->skip(4); }
1151
- else if ($GSLookup[$i]['Type']==6 && $PosFormat==3) {
1152
- $BacktrackGlyphCount= $this->read_ushort();
1153
- $this->skip(2*$BacktrackGlyphCount + 2);
1154
- }
1155
- // NB Coverage only looks at glyphs for position 1 (i.e. 5.3 and 6.3) // NEEDS TO READ ALL ********************
1156
- $Coverage = $GSLookup[$i]['Subtables'][$c] + $this->read_ushort();
1157
- $this->seek($Coverage);
1158
- $glyphs = $this->_getCoverage();
1159
- $this->GSLuCoverage[$i][$c] = implode('|',$glyphs);
1160
- }
1161
- }
1162
-
1163
- // $this->GSLuCoverage and $GSLookup
1164
-
1165
- //=====================================================================================
1166
- $s = '<?php
1167
- $GSLuCoverage = '.var_export($this->GSLuCoverage , true).';
1168
- ?>';
1169
-
1170
-
1171
- //=====================================================================================
1172
- $s = '<?php
1173
- $GlyphClassBases = \''.$this->GlyphClassBases.'\';
1174
- $GlyphClassMarks = \''.$this->GlyphClassMarks.'\';
1175
- $GlyphClassLigatures = \''.$this->GlyphClassLigatures.'\';
1176
- $GlyphClassComponents = \''.$this->GlyphClassComponents.'\';
1177
- $MarkGlyphSets = '.var_export($this->MarkGlyphSets , true).';
1178
- $MarkAttachmentType = '.var_export($this->MarkAttachmentType , true).';
1179
- ?>';
1180
-
1181
-
1182
- //=====================================================================================
1183
- //=====================================================================================
1184
- //=====================================================================================
1185
- // Now repeats as original to get Substitution rules
1186
- //=====================================================================================
1187
- //=====================================================================================
1188
- //=====================================================================================
1189
- // Get metadata and offsets for whole Lookup List table
1190
- $this->seek($LookupList_offset );
1191
- $LookupCount = $this->read_ushort();
1192
- $Lookup = array();
1193
- for ($i=0;$i<$LookupCount;$i++) {
1194
- $Lookup[$i]['offset'] = $LookupList_offset + $this->read_ushort();
1195
- }
1196
- for ($i=0;$i<$LookupCount;$i++) {
1197
- $this->seek($Lookup[$i]['offset']);
1198
- $Lookup[$i]['Type'] = $this->read_ushort();
1199
- $Lookup[$i]['Flag'] = $flag = $this->read_ushort();
1200
- $Lookup[$i]['SubtableCount'] = $this->read_ushort();
1201
- for ($c=0;$c<$Lookup[$i]['SubtableCount'] ;$c++) {
1202
- $Lookup[$i]['Subtable'][$c]['Offset'] = $Lookup[$i]['offset'] + $this->read_ushort();
1203
-
1204
- }
1205
- // MarkFilteringSet = Index (base 0) into GDEF mark glyph sets structure
1206
- if (($flag & 0x0010) == 0x0010) {
1207
- $Lookup[$i]['MarkFilteringSet'] = $this->read_ushort();
1208
- }
1209
- else { $Lookup[$i]['MarkFilteringSet'] = ''; }
1210
-
1211
- // Lookup Type 7: Extension
1212
- if ($Lookup[$i]['Type'] == 7) {
1213
- // Overwrites new offset (32-bit) for each subtable, and a new lookup Type
1214
- for ($c=0;$c<$Lookup[$i]['SubtableCount'] ;$c++) {
1215
- $this->seek($Lookup[$i]['Subtable'][$c]['Offset']);
1216
- $ExtensionPosFormat = $this->read_ushort();
1217
- $type = $this->read_ushort();
1218
- $Lookup[$i]['Subtable'][$c]['Offset'] = $Lookup[$i]['Subtable'][$c]['Offset'] + $this->read_ulong();
1219
- }
1220
- $Lookup[$i]['Type'] = $type;
1221
- }
1222
-
1223
- }
1224
-
1225
- //print_r($Lookup); exit;
1226
- //=====================================================================================
1227
- // Process (1) Whole LookupList
1228
- for ($i=0;$i<$LookupCount;$i++) {
1229
- for ($c=0;$c<$Lookup[$i]['SubtableCount'] ;$c++) {
1230
-
1231
- $this->seek($Lookup[$i]['Subtable'][$c]['Offset']);
1232
- $SubstFormat= $this->read_ushort();
1233
- $Lookup[$i]['Subtable'][$c]['Format'] = $SubstFormat;
1234
-
1235
- /*
1236
- Lookup['Type'] Enumeration table for glyph substitution
1237
- Value Type Description
1238
- 1 Single Replace one glyph with one glyph
1239
- 2 Multiple Replace one glyph with more than one glyph
1240
- 3 Alternate Replace one glyph with one of many glyphs
1241
- 4 Ligature Replace multiple glyphs with one glyph
1242
- 5 Context Replace one or more glyphs in context
1243
- 6 Chaining Context Replace one or more glyphs in chained context
1244
- 7 Extension Substitution Extension mechanism for other substitutions (i.e. this excludes the Extension type substitution itself)
1245
- 8 Reverse chaining context single Applied in reverse order, replace single glyph in chaining context
1246
- */
1247
-
1248
- // LookupType 1: Single Substitution Subtable
1249
- if ($Lookup[$i]['Type'] == 1) {
1250
- $Lookup[$i]['Subtable'][$c]['CoverageTableOffset'] = $Lookup[$i]['Subtable'][$c]['Offset'] + $this->read_ushort();
1251
- if ($SubstFormat==1) { // Calculated output glyph indices
1252
- $Lookup[$i]['Subtable'][$c]['DeltaGlyphID'] = $this->read_short();
1253
- }
1254
- else if ($SubstFormat==2) { // Specified output glyph indices
1255
- $GlyphCount = $this->read_ushort();
1256
- for ($g=0;$g<$GlyphCount;$g++) {
1257
- $Lookup[$i]['Subtable'][$c]['Glyphs'][] = $this->read_ushort();
1258
- }
1259
- }
1260
- }
1261
- // LookupType 2: Multiple Substitution Subtable
1262
- else if ($Lookup[$i]['Type'] == 2) {
1263
- $Lookup[$i]['Subtable'][$c]['CoverageTableOffset'] = $Lookup[$i]['Subtable'][$c]['Offset'] + $this->read_ushort();
1264
- $Lookup[$i]['Subtable'][$c]['SequenceCount'] = $SequenceCount = $this->read_short();
1265
- for($s=0;$s<$SequenceCount;$s++) {
1266
- $Lookup[$i]['Subtable'][$c]['Sequences'][$s]['Offset'] = $Lookup[$i]['Subtable'][$c]['Offset'] + $this->read_short();
1267
- }
1268
- for($s=0;$s<$SequenceCount;$s++) {
1269
- // Sequence Tables
1270
- $this->seek($Lookup[$i]['Subtable'][$c]['Sequences'][$s]['Offset']);
1271
- $Lookup[$i]['Subtable'][$c]['Sequences'][$s]['GlyphCount'] = $this->read_short();
1272
- for ($g=0;$g<$Lookup[$i]['Subtable'][$c]['Sequences'][$s]['GlyphCount'];$g++) {
1273
- $Lookup[$i]['Subtable'][$c]['Sequences'][$s]['SubstituteGlyphID'][] = $this->read_ushort();
1274
- }
1275
- }
1276
- }
1277
- // LookupType 3: Alternate Forms
1278
- else if ($Lookup[$i]['Type'] == 3) {
1279
- $Lookup[$i]['Subtable'][$c]['CoverageTableOffset'] = $Lookup[$i]['Subtable'][$c]['Offset'] + $this->read_ushort();
1280
- $Lookup[$i]['Subtable'][$c]['AlternateSetCount'] = $AlternateSetCount = $this->read_short();
1281
- for($s=0;$s<$AlternateSetCount;$s++) {
1282
- $Lookup[$i]['Subtable'][$c]['AlternateSets'][$s]['Offset'] = $Lookup[$i]['Subtable'][$c]['Offset'] + $this->read_short();
1283
- }
1284
-
1285
- for($s=0;$s<$AlternateSetCount;$s++) {
1286
- // AlternateSet Tables
1287
- $this->seek($Lookup[$i]['Subtable'][$c]['AlternateSets'][$s]['Offset']);
1288
- $Lookup[$i]['Subtable'][$c]['AlternateSets'][$s]['GlyphCount'] = $this->read_short();
1289
- for ($g=0;$g<$Lookup[$i]['Subtable'][$c]['AlternateSets'][$s]['GlyphCount'];$g++) {
1290
- $Lookup[$i]['Subtable'][$c]['AlternateSets'][$s]['SubstituteGlyphID'][] = $this->read_ushort();
1291
- }
1292
- }
1293
- }
1294
- // LookupType 4: Ligature Substitution Subtable
1295
- else if ($Lookup[$i]['Type'] == 4) {
1296
- $Lookup[$i]['Subtable'][$c]['CoverageTableOffset'] = $Lookup[$i]['Subtable'][$c]['Offset'] + $this->read_ushort();
1297
- $Lookup[$i]['Subtable'][$c]['LigSetCount'] = $LigSetCount = $this->read_short();
1298
- for($s=0;$s<$LigSetCount;$s++) {
1299
- $Lookup[$i]['Subtable'][$c]['LigSet'][$s]['Offset'] = $Lookup[$i]['Subtable'][$c]['Offset'] + $this->read_short();
1300
- }
1301
- for($s=0;$s<$LigSetCount;$s++) {
1302
- // LigatureSet Tables
1303
- $this->seek($Lookup[$i]['Subtable'][$c]['LigSet'][$s]['Offset']);
1304
- $Lookup[$i]['Subtable'][$c]['LigSet'][$s]['LigCount'] = $this->read_short();
1305
- for ($g=0;$g<$Lookup[$i]['Subtable'][$c]['LigSet'][$s]['LigCount'];$g++) {
1306
- $Lookup[$i]['Subtable'][$c]['LigSet'][$s]['LigatureOffset'][$g] = $Lookup[$i]['Subtable'][$c]['LigSet'][$s]['Offset'] + $this->read_ushort();
1307
- }
1308
- }
1309
- for($s=0;$s<$LigSetCount;$s++) {
1310
- for ($g=0;$g<$Lookup[$i]['Subtable'][$c]['LigSet'][$s]['LigCount'];$g++) {
1311
- // Ligature tables
1312
- $this->seek($Lookup[$i]['Subtable'][$c]['LigSet'][$s]['LigatureOffset'][$g]);
1313
- $Lookup[$i]['Subtable'][$c]['LigSet'][$s]['Ligature'][$g]['LigGlyph'] = $this->read_ushort();
1314
- $Lookup[$i]['Subtable'][$c]['LigSet'][$s]['Ligature'][$g]['CompCount'] = $this->read_ushort();
1315
- for ($l=1;$l<$Lookup[$i]['Subtable'][$c]['LigSet'][$s]['Ligature'][$g]['CompCount'];$l++) {
1316
- $Lookup[$i]['Subtable'][$c]['LigSet'][$s]['Ligature'][$g]['GlyphID'][$l] = $this->read_ushort();
1317
- }
1318
- }
1319
- }
1320
- }
1321
-
1322
- // LookupType 5: Contextual Substitution Subtable
1323
- else if ($Lookup[$i]['Type'] == 5) {
1324
- // Format 1: Context Substitution
1325
- if ($SubstFormat==1) {
1326
- $Lookup[$i]['Subtable'][$c]['CoverageTableOffset'] = $Lookup[$i]['Subtable'][$c]['Offset'] + $this->read_ushort();
1327
- $Lookup[$i]['Subtable'][$c]['SubRuleSetCount'] = $SubRuleSetCount = $this->read_short();
1328
- for($s=0;$s<$SubRuleSetCount;$s++) {
1329
- $Lookup[$i]['Subtable'][$c]['SubRuleSet'][$s]['Offset'] = $Lookup[$i]['Subtable'][$c]['Offset'] + $this->read_short();
1330
- }
1331
- for($s=0;$s<$SubRuleSetCount;$s++) {
1332
- // SubRuleSet Tables
1333
- $this->seek($Lookup[$i]['Subtable'][$c]['SubRuleSet'][$s]['Offset']);
1334
- $Lookup[$i]['Subtable'][$c]['SubRuleSet'][$s]['SubRuleCount'] = $this->read_short();
1335
- for ($g=0;$g<$Lookup[$i]['Subtable'][$c]['SubRuleSet'][$s]['SubRuleCount'];$g++) {
1336
- $Lookup[$i]['Subtable'][$c]['SubRuleSet'][$s]['SubRuleOffset'][$g] = $Lookup[$i]['Subtable'][$c]['SubRuleSet'][$s]['Offset'] + $this->read_ushort();
1337
- }
1338
- }
1339
- for($s=0;$s<$SubRuleSetCount;$s++) {
1340
- // SubRule Tables
1341
- for ($g=0;$g<$Lookup[$i]['Subtable'][$c]['SubRuleSet'][$s]['SubRuleCount'];$g++) {
1342
- // Ligature tables
1343
- $this->seek($Lookup[$i]['Subtable'][$c]['SubRuleSet'][$s]['SubRuleOffset'][$g]);
1344
-
1345
- $Lookup[$i]['Subtable'][$c]['SubRuleSet'][$s]['SubRule'][$g]['GlyphCount'] = $this->read_ushort();
1346
- $Lookup[$i]['Subtable'][$c]['SubRuleSet'][$s]['SubRule'][$g]['SubstCount'] = $this->read_ushort();
1347
- // "Input"::[GlyphCount - 1]::Array of input GlyphIDs-start with second glyph
1348
- for ($l=1;$l<$Lookup[$i]['Subtable'][$c]['SubRuleSet'][$s]['SubRule'][$g]['GlyphCount'];$l++) {
1349
- $Lookup[$i]['Subtable'][$c]['SubRuleSet'][$s]['SubRule'][$g]['Input'][$l] = $this->read_ushort();
1350
- }
1351
- // "SubstLookupRecord"::[SubstCount]::Array of SubstLookupRecords-in design order
1352
- for ($l=0;$l<$Lookup[$i]['Subtable'][$c]['SubRuleSet'][$s]['SubRule'][$g]['SubstCount'];$l++) {
1353
- $Lookup[$i]['Subtable'][$c]['SubRuleSet'][$s]['SubRule'][$g]['SubstLookupRecord'][$l]['SequenceIndex'] = $this->read_ushort();
1354
- $Lookup[$i]['Subtable'][$c]['SubRuleSet'][$s]['SubRule'][$g]['SubstLookupRecord'][$l]['LookupListIndex'] = $this->read_ushort();
1355
- }
1356
-
1357
- }
1358
- }
1359
-
1360
- }
1361
- // Format 2: Class-based Context Glyph Substitution
1362
- else if ($SubstFormat==2) {
1363
- $Lookup[$i]['Subtable'][$c]['CoverageTableOffset'] = $Lookup[$i]['Subtable'][$c]['Offset'] + $this->read_ushort();
1364
- $Lookup[$i]['Subtable'][$c]['ClassDefOffset'] = $Lookup[$i]['Subtable'][$c]['Offset'] + $this->read_ushort();
1365
- $Lookup[$i]['Subtable'][$c]['SubClassSetCnt'] = $this->read_ushort();
1366
- for ($b=0;$b<$Lookup[$i]['Subtable'][$c]['SubClassSetCnt'];$b++) {
1367
- $offset = $this->read_ushort();
1368
- if ($offset==0x0000) {
1369
- $Lookup[$i]['Subtable'][$c]['SubClassSetOffset'][] = 0;
1370
- }
1371
- else {
1372
- $Lookup[$i]['Subtable'][$c]['SubClassSetOffset'][] = $Lookup[$i]['Subtable'][$c]['Offset'] + $offset;
1373
- }
1374
- }
1375
- }
1376
- else { die("GPOS Lookup Type ".$Lookup[$i]['Type'].", Format ".$SubstFormat." not supported (ttfontsuni.php)."); }
1377
- }
1378
-
1379
- // LookupType 6: Chaining Contextual Substitution Subtable
1380
- else if ($Lookup[$i]['Type'] == 6) {
1381
- // Format 1: Simple Chaining Context Glyph Substitution p255
1382
- if ($SubstFormat==1) {
1383
- $Lookup[$i]['Subtable'][$c]['CoverageTableOffset'] = $Lookup[$i]['Subtable'][$c]['Offset'] + $this->read_ushort();
1384
- $Lookup[$i]['Subtable'][$c]['ChainSubRuleSetCount'] = $this->read_ushort();
1385
- for ($b=0;$b<$Lookup[$i]['Subtable'][$c]['ChainSubRuleSetCount'];$b++) {
1386
- $Lookup[$i]['Subtable'][$c]['ChainSubRuleSetOffset'][] = $Lookup[$i]['Subtable'][$c]['Offset'] + $this->read_ushort();
1387
- }
1388
- }
1389
- // Format 2: Class-based Chaining Context Glyph Substitution p257
1390
- else if ($SubstFormat==2) {
1391
- $Lookup[$i]['Subtable'][$c]['CoverageTableOffset'] = $Lookup[$i]['Subtable'][$c]['Offset'] + $this->read_ushort();
1392
- $Lookup[$i]['Subtable'][$c]['BacktrackClassDefOffset'] = $Lookup[$i]['Subtable'][$c]['Offset'] + $this->read_ushort();
1393
- $Lookup[$i]['Subtable'][$c]['InputClassDefOffset'] = $Lookup[$i]['Subtable'][$c]['Offset'] + $this->read_ushort();
1394
- $Lookup[$i]['Subtable'][$c]['LookaheadClassDefOffset'] = $Lookup[$i]['Subtable'][$c]['Offset'] + $this->read_ushort();
1395
- $Lookup[$i]['Subtable'][$c]['ChainSubClassSetCnt'] = $this->read_ushort();
1396
- for ($b=0;$b<$Lookup[$i]['Subtable'][$c]['ChainSubClassSetCnt'];$b++) {
1397
- $offset = $this->read_ushort();
1398
- if ($offset==0x0000) {
1399
- $Lookup[$i]['Subtable'][$c]['ChainSubClassSetOffset'][] = $offset;
1400
- }
1401
- else {
1402
- $Lookup[$i]['Subtable'][$c]['ChainSubClassSetOffset'][] = $Lookup[$i]['Subtable'][$c]['Offset'] + $offset;
1403
- }
1404
- }
1405
- }
1406
- // Format 3: Coverage-based Chaining Context Glyph Substitution p259
1407
- else if ($SubstFormat==3) {
1408
- $Lookup[$i]['Subtable'][$c]['BacktrackGlyphCount'] = $this->read_ushort();
1409
- for ($b=0;$b<$Lookup[$i]['Subtable'][$c]['BacktrackGlyphCount'];$b++) {
1410
- $Lookup[$i]['Subtable'][$c]['CoverageBacktrack'][] = $Lookup[$i]['Subtable'][$c]['Offset'] + $this->read_ushort();
1411
- }
1412
- $Lookup[$i]['Subtable'][$c]['InputGlyphCount'] = $this->read_ushort();
1413
- for ($b=0;$b<$Lookup[$i]['Subtable'][$c]['InputGlyphCount'];$b++) {
1414
- $Lookup[$i]['Subtable'][$c]['CoverageInput'][] = $Lookup[$i]['Subtable'][$c]['Offset'] + $this->read_ushort();
1415
- }
1416
- $Lookup[$i]['Subtable'][$c]['LookaheadGlyphCount'] = $this->read_ushort();
1417
- for ($b=0;$b<$Lookup[$i]['Subtable'][$c]['LookaheadGlyphCount'];$b++) {
1418
- $Lookup[$i]['Subtable'][$c]['CoverageLookahead'][] = $Lookup[$i]['Subtable'][$c]['Offset'] + $this->read_ushort();
1419
- }
1420
- $Lookup[$i]['Subtable'][$c]['SubstCount'] = $this->read_ushort();
1421
- for ($b=0;$b<$Lookup[$i]['Subtable'][$c]['SubstCount'];$b++) {
1422
- $Lookup[$i]['Subtable'][$c]['SubstLookupRecord'][$b]['SequenceIndex'] = $this->read_ushort();
1423
- $Lookup[$i]['Subtable'][$c]['SubstLookupRecord'][$b]['LookupListIndex'] = $this->read_ushort();
1424
- /*
1425
- Substitution Lookup Record
1426
- All contextual substitution subtables specify the substitution data in a Substitution Lookup Record (SubstLookupRecord). Each record contains a SequenceIndex, which indicates the position where the substitution will occur in the glyph sequence. In addition, a LookupListIndex identifies the lookup to be applied at the glyph position specified by the SequenceIndex.
1427
- */
1428
-
1429
- }
1430
- }
1431
- }
1432
- else { die("Lookup Type ".$Lookup[$i]['Type']." not supported."); }
1433
- }
1434
- }
1435
- //print_r($Lookup); exit;
1436
-
1437
-
1438
-
1439
-
1440
- //=====================================================================================
1441
- // Process (2) Whole LookupList
1442
- // Get Coverage tables and prepare preg_replace
1443
- for ($i=0;$i<$LookupCount;$i++) {
1444
- for ($c=0;$c<$Lookup[$i]['SubtableCount'] ;$c++) {
1445
- $SubstFormat= $Lookup[$i]['Subtable'][$c]['Format'] ;
1446
-
1447
- // LookupType 1: Single Substitution Subtable 1 => 1
1448
- if ($Lookup[$i]['Type'] == 1) {
1449
- $this->seek($Lookup[$i]['Subtable'][$c]['CoverageTableOffset']);
1450
- $glyphs = $this->_getCoverage(false);
1451
- for ($g=0;$g<count($glyphs);$g++) {
1452
- $replace = array();
1453
- $substitute = array();
1454
- $replace[] = unicode_hex($this->glyphToChar[$glyphs[$g]][0]);
1455
- // Flag = Ignore
1456
- if ($this->_checkGSUBignore($Lookup[$i]['Flag'], $replace[0], $Lookup[$i]['MarkFilteringSet'])) { continue; }
1457
- if (isset($Lookup[$i]['Subtable'][$c]['DeltaGlyphID'])) { // Format 1
1458
- $substitute[] = unicode_hex($this->glyphToChar[($glyphs[$g]+$Lookup[$i]['Subtable'][$c]['DeltaGlyphID'])][0]);
1459
- }
1460
- else { // Format 2
1461
- $substitute[] = unicode_hex($this->glyphToChar[($Lookup[$i]['Subtable'][$c]['Glyphs'][$g])][0]);
1462
- }
1463
- $Lookup[$i]['Subtable'][$c]['subs'][] = array('Replace'=>$replace, 'substitute'=>$substitute);
1464
- }
1465
- }
1466
-
1467
- // LookupType 2: Multiple Substitution Subtable 1 => n
1468
- else if ($Lookup[$i]['Type'] == 2) {
1469
- $this->seek($Lookup[$i]['Subtable'][$c]['CoverageTableOffset']);
1470
- $glyphs = $this->_getCoverage();
1471
- for ($g=0;$g<count($glyphs);$g++) {
1472
- $replace = array();
1473
- $substitute = array();
1474
- $replace[] = $glyphs[$g];
1475
- // Flag = Ignore
1476
- if ($this->_checkGSUBignore($Lookup[$i]['Flag'], $replace[0], $Lookup[$i]['MarkFilteringSet'])) { continue; }
1477
- if (!isset($Lookup[$i]['Subtable'][$c]['Sequences'][$g]['SubstituteGlyphID']) || count($Lookup[$i]['Subtable'][$c]['Sequences'][$g]['SubstituteGlyphID'])==0) { continue; } // Illegal for GlyphCount to be 0; either error in font, or something has gone wrong - lets carry on for now!
1478
- foreach($Lookup[$i]['Subtable'][$c]['Sequences'][$g]['SubstituteGlyphID'] AS $sub) {
1479
- $substitute[] = unicode_hex($this->glyphToChar[$sub][0]);
1480
- }
1481
- $Lookup[$i]['Subtable'][$c]['subs'][] = array('Replace'=>$replace, 'substitute'=>$substitute);
1482
- }
1483
- }
1484
- // LookupType 3: Alternate Forms 1 => 1 (only first alternate form is used)
1485
- else if ($Lookup[$i]['Type'] == 3) {
1486
- $this->seek($Lookup[$i]['Subtable'][$c]['CoverageTableOffset']);
1487
- $glyphs = $this->_getCoverage();
1488
- for ($g=0;$g<count($glyphs);$g++) {
1489
- $replace = array();
1490
- $substitute = array();
1491
- $replace[] = $glyphs[$g];
1492
- // Flag = Ignore
1493
- if ($this->_checkGSUBignore($Lookup[$i]['Flag'], $replace[0], $Lookup[$i]['MarkFilteringSet'])) { continue; }
1494
-
1495
- for ($gl=0;$gl<$Lookup[$i]['Subtable'][$c]['AlternateSets'][$g]['GlyphCount'];$gl++) {
1496
- $gid = $Lookup[$i]['Subtable'][$c]['AlternateSets'][$g]['SubstituteGlyphID'][$gl];
1497
- $substitute[] = unicode_hex($this->glyphToChar[$gid][0]);
1498
- }
1499
-
1500
- //$gid = $Lookup[$i]['Subtable'][$c]['AlternateSets'][$g]['SubstituteGlyphID'][0];
1501
- //$substitute[] = unicode_hex($this->glyphToChar[$gid][0]);
1502
-
1503
- $Lookup[$i]['Subtable'][$c]['subs'][] = array('Replace'=>$replace, 'substitute'=>$substitute);
1504
- }
1505
- if ($i==166) {
1506
- print_r($Lookup[$i]['Subtable']);
1507
- exit;
1508
- }
1509
- }
1510
- // LookupType 4: Ligature Substitution Subtable n => 1
1511
- else if ($Lookup[$i]['Type'] == 4) {
1512
- $this->seek($Lookup[$i]['Subtable'][$c]['CoverageTableOffset']);
1513
- $glyphs = $this->_getCoverage();
1514
- $LigSetCount = $Lookup[$i]['Subtable'][$c]['LigSetCount'];
1515
- for($s=0;$s<$LigSetCount;$s++) {
1516
- for ($g=0;$g<$Lookup[$i]['Subtable'][$c]['LigSet'][$s]['LigCount'];$g++) {
1517
- $replace = array();
1518
- $substitute = array();
1519
- $replace[] = $glyphs[$s];
1520
- // Flag = Ignore
1521
- if ($this->_checkGSUBignore($Lookup[$i]['Flag'], $replace[0], $Lookup[$i]['MarkFilteringSet'])) { continue; }
1522
- for ($l=1;$l<$Lookup[$i]['Subtable'][$c]['LigSet'][$s]['Ligature'][$g]['CompCount'];$l++) {
1523
- $gid = $Lookup[$i]['Subtable'][$c]['LigSet'][$s]['Ligature'][$g]['GlyphID'][$l];
1524
- $rpl = unicode_hex($this->glyphToChar[$gid][0]);
1525
- // Flag = Ignore
1526
- if ($this->_checkGSUBignore($Lookup[$i]['Flag'], $rpl, $Lookup[$i]['MarkFilteringSet'])) { continue 2; }
1527
- $replace[] = $rpl;
1528
- }
1529
- $gid = $Lookup[$i]['Subtable'][$c]['LigSet'][$s]['Ligature'][$g]['LigGlyph'];
1530
- $substitute[] = unicode_hex($this->glyphToChar[$gid][0]);
1531
- $Lookup[$i]['Subtable'][$c]['subs'][] = array('Replace'=>$replace, 'substitute'=>$substitute, 'CompCount' => $Lookup[$i]['Subtable'][$c]['LigSet'][$s]['Ligature'][$g]['CompCount']);
1532
- }
1533
- }
1534
- }
1535
-
1536
- // LookupType 5: Contextual Substitution Subtable
1537
- else if ($Lookup[$i]['Type'] == 5) {
1538
- // Format 1: Context Substitution
1539
- if ($SubstFormat==1) {
1540
- $this->seek($Lookup[$i]['Subtable'][$c]['CoverageTableOffset']);
1541
- $Lookup[$i]['Subtable'][$c]['CoverageGlyphs'] = $CoverageGlyphs = $this->_getCoverage();
1542
-
1543
- for ($s=0;$s<$Lookup[$i]['Subtable'][$c]['SubRuleSetCount'];$s++) {
1544
- $SubRuleSet = $Lookup[$i]['Subtable'][$c]['SubRuleSet'][$s];
1545
- $Lookup[$i]['Subtable'][$c]['SubRuleSet'][$s]['FirstGlyph'] = $CoverageGlyphs[$s];
1546
- for ($r=0;$r<$Lookup[$i]['Subtable'][$c]['SubRuleSet'][$s]['SubRuleCount'];$r++) {
1547
- $GlyphCount = $Lookup[$i]['Subtable'][$c]['SubRuleSet'][$s]['SubRule'][$r]['GlyphCount'];
1548
- for ($g=1;$g<$GlyphCount;$g++) {
1549
- $glyphID = $Lookup[$i]['Subtable'][$c]['SubRuleSet'][$s]['SubRule'][$r]['Input'][$g];
1550
- $Lookup[$i]['Subtable'][$c]['SubRuleSet'][$s]['SubRule'][$r]['InputGlyphs'][$g] = unicode_hex($this->glyphToChar[$glyphID][0]);
1551
- }
1552
-
1553
- }
1554
- }
1555
- }
1556
- // Format 2: Class-based Context Glyph Substitution
1557
- else if ($SubstFormat==2) {
1558
- $this->seek($Lookup[$i]['Subtable'][$c]['CoverageTableOffset']);
1559
- $Lookup[$i]['Subtable'][$c]['CoverageGlyphs'] = $CoverageGlyphs = $this->_getCoverage();
1560
-
1561
- $InputClasses = $this->_getClasses($Lookup[$i]['Subtable'][$c]['ClassDefOffset']);
1562
- $Lookup[$i]['Subtable'][$c]['InputClasses'] = $InputClasses;
1563
-
1564
- for ($s=0;$s<$Lookup[$i]['Subtable'][$c]['SubClassSetCnt'];$s++) {
1565
- if ($Lookup[$i]['Subtable'][$c]['SubClassSetOffset'][$s]>0) {
1566
- $this->seek($Lookup[$i]['Subtable'][$c]['SubClassSetOffset'][$s]);
1567
- $Lookup[$i]['Subtable'][$c]['SubClassSet'][$s]['SubClassRuleCnt'] = $SubClassRuleCnt = $this->read_ushort();
1568
- $SubClassRule = array();
1569
- for($b=0;$b<$SubClassRuleCnt;$b++) {
1570
- $SubClassRule[$b] = $Lookup[$i]['Subtable'][$c]['SubClassSetOffset'][$s]+$this->read_ushort();
1571
- $Lookup[$i]['Subtable'][$c]['SubClassSet'][$s]['SubClassRule'][$b] = $SubClassRule[$b];
1572
- }
1573
- }
1574
- }
1575
-
1576
- for ($s=0;$s<$Lookup[$i]['Subtable'][$c]['SubClassSetCnt'];$s++) {
1577
- $SubClassRuleCnt = $Lookup[$i]['Subtable'][$c]['SubClassSet'][$s]['SubClassRuleCnt'];
1578
- for($b=0;$b<$SubClassRuleCnt;$b++) {
1579
- if ($Lookup[$i]['Subtable'][$c]['SubClassSetOffset'][$s]>0) {
1580
- $this->seek($Lookup[$i]['Subtable'][$c]['SubClassSet'][$s]['SubClassRule'][$b]);
1581
- $Rule = array();
1582
- $Rule['InputGlyphCount'] = $this->read_ushort();
1583
- $Rule['SubstCount'] = $this->read_ushort();
1584
- for ($r=1;$r<$Rule['InputGlyphCount'];$r++) {
1585
- $Rule['Input'][$r] = $this->read_ushort();
1586
- }
1587
- for ($r=0;$r<$Rule['SubstCount'];$r++) {
1588
- $Rule['SequenceIndex'][$r] = $this->read_ushort();
1589
- $Rule['LookupListIndex'][$r] = $this->read_ushort();
1590
- }
1591
-
1592
- $Lookup[$i]['Subtable'][$c]['SubClassSet'][$s]['SubClassRule'][$b] = $Rule;
1593
- }
1594
- }
1595
- }
1596
- }
1597
- // Format 3: Coverage-based Context Glyph Substitution
1598
- else if ($SubstFormat==3) {
1599
- for ($b=0;$b<$Lookup[$i]['Subtable'][$c]['InputGlyphCount'];$b++) {
1600
- $this->seek($Lookup[$i]['Subtable'][$c]['CoverageInput'][$b]);
1601
- $glyphs = $this->_getCoverage();
1602
- $Lookup[$i]['Subtable'][$c]['CoverageInputGlyphs'][] = implode("|",$glyphs);
1603
- }
1604
- die("Lookup Type 5, SubstFormat 3 not tested. Please report this with the name of font used - ".$this->fontkey);
1605
- }
1606
-
1607
- }
1608
-
1609
- // LookupType 6: Chaining Contextual Substitution Subtable
1610
- else if ($Lookup[$i]['Type'] == 6) {
1611
- // Format 1: Simple Chaining Context Glyph Substitution p255
1612
- if ($SubstFormat==1) {
1613
- $this->seek($Lookup[$i]['Subtable'][$c]['CoverageTableOffset']);
1614
- $Lookup[$i]['Subtable'][$c]['CoverageGlyphs'] = $CoverageGlyphs = $this->_getCoverage();
1615
-
1616
- $ChainSubRuleSetCnt = $Lookup[$i]['Subtable'][$c]['ChainSubRuleSetCount'];
1617
-
1618
- for ($s=0;$s<$ChainSubRuleSetCnt;$s++) {
1619
- $this->seek($Lookup[$i]['Subtable'][$c]['ChainSubRuleSetOffset'][$s]);
1620
- $ChainSubRuleCnt = $Lookup[$i]['Subtable'][$c]['ChainSubRuleSet'][$s]['ChainSubRuleCount'] = $this->read_ushort();
1621
- for ($r=0;$r<$ChainSubRuleCnt;$r++) {
1622
- $Lookup[$i]['Subtable'][$c]['ChainSubRuleSet'][$s]['ChainSubRuleOffset'][$r] = $Lookup[$i]['Subtable'][$c]['ChainSubRuleSetOffset'][$s] + $this->read_ushort();
1623
-
1624
- }
1625
- }
1626
- for ($s=0;$s<$ChainSubRuleSetCnt;$s++) {
1627
- $ChainSubRuleCnt = $Lookup[$i]['Subtable'][$c]['ChainSubRuleSet'][$s]['ChainSubRuleCount'];
1628
- for ($r=0;$r<$ChainSubRuleCnt;$r++) {
1629
- // ChainSubRule
1630
- $this->seek($Lookup[$i]['Subtable'][$c]['ChainSubRuleSet'][$s]['ChainSubRuleOffset'][$r]);
1631
-
1632
- $BacktrackGlyphCount = $Lookup[$i]['Subtable'][$c]['ChainSubRuleSet'][$s]['ChainSubRule'][$r]['BacktrackGlyphCount'] = $this->read_ushort();
1633
- for ($g=0;$g<$BacktrackGlyphCount;$g++) {
1634
- $glyphID = $this->read_ushort();
1635
- $Lookup[$i]['Subtable'][$c]['ChainSubRuleSet'][$s]['ChainSubRule'][$r]['BacktrackGlyphs'][$g] = unicode_hex($this->glyphToChar[$glyphID][0]);
1636
- }
1637
-
1638
- $InputGlyphCount = $Lookup[$i]['Subtable'][$c]['ChainSubRuleSet'][$s]['ChainSubRule'][$r]['InputGlyphCount'] = $this->read_ushort();
1639
- for ($g=1;$g<$InputGlyphCount;$g++) {
1640
- $glyphID = $this->read_ushort();
1641
- $Lookup[$i]['Subtable'][$c]['ChainSubRuleSet'][$s]['ChainSubRule'][$r]['InputGlyphs'][$g] = unicode_hex($this->glyphToChar[$glyphID][0]);
1642
- }
1643
-
1644
-
1645
- $LookaheadGlyphCount = $Lookup[$i]['Subtable'][$c]['ChainSubRuleSet'][$s]['ChainSubRule'][$r]['LookaheadGlyphCount'] = $this->read_ushort();
1646
- for ($g=0;$g<$LookaheadGlyphCount;$g++) {
1647
- $glyphID = $this->read_ushort();
1648
- $Lookup[$i]['Subtable'][$c]['ChainSubRuleSet'][$s]['ChainSubRule'][$r]['LookaheadGlyphs'][$g] = unicode_hex($this->glyphToChar[$glyphID][0]);
1649
- }
1650
-
1651
- $SubstCount = $Lookup[$i]['Subtable'][$c]['ChainSubRuleSet'][$s]['ChainSubRule'][$r]['SubstCount'] = $this->read_ushort();
1652
- for ($lu=0;$lu<$SubstCount;$lu++) {
1653
- $Lookup[$i]['Subtable'][$c]['ChainSubRuleSet'][$s]['ChainSubRule'][$r]['SequenceIndex'][$lu] = $this->read_ushort();
1654
- $Lookup[$i]['Subtable'][$c]['ChainSubRuleSet'][$s]['ChainSubRule'][$r]['LookupListIndex'][$lu] = $this->read_ushort();
1655
- }
1656
- }
1657
- }
1658
-
1659
- }
1660
- // Format 2: Class-based Chaining Context Glyph Substitution p257
1661
- else if ($SubstFormat==2) {
1662
- $this->seek($Lookup[$i]['Subtable'][$c]['CoverageTableOffset']);
1663
- $Lookup[$i]['Subtable'][$c]['CoverageGlyphs'] = $CoverageGlyphs = $this->_getCoverage();
1664
-
1665
- $BacktrackClasses = $this->_getClasses($Lookup[$i]['Subtable'][$c]['BacktrackClassDefOffset']);
1666
- $Lookup[$i]['Subtable'][$c]['BacktrackClasses'] = $BacktrackClasses;
1667
-
1668
- $InputClasses = $this->_getClasses($Lookup[$i]['Subtable'][$c]['InputClassDefOffset']);
1669
- $Lookup[$i]['Subtable'][$c]['InputClasses'] = $InputClasses;
1670
-
1671
- $LookaheadClasses = $this->_getClasses($Lookup[$i]['Subtable'][$c]['LookaheadClassDefOffset']);
1672
- $Lookup[$i]['Subtable'][$c]['LookaheadClasses'] = $LookaheadClasses;
1673
-
1674
- for ($s=0;$s<$Lookup[$i]['Subtable'][$c]['ChainSubClassSetCnt'];$s++) {
1675
- if ($Lookup[$i]['Subtable'][$c]['ChainSubClassSetOffset'][$s]>0) {
1676
- $this->seek($Lookup[$i]['Subtable'][$c]['ChainSubClassSetOffset'][$s]);
1677
- $Lookup[$i]['Subtable'][$c]['ChainSubClassSet'][$s]['ChainSubClassRuleCnt'] = $ChainSubClassRuleCnt = $this->read_ushort();
1678
- $ChainSubClassRule = array();
1679
- for($b=0;$b<$ChainSubClassRuleCnt;$b++) {
1680
- $ChainSubClassRule[$b] = $Lookup[$i]['Subtable'][$c]['ChainSubClassSetOffset'][$s]+$this->read_ushort();
1681
- $Lookup[$i]['Subtable'][$c]['ChainSubClassSet'][$s]['ChainSubClassRule'][$b] = $ChainSubClassRule[$b];
1682
- }
1683
- }
1684
- }
1685
-
1686
- for ($s=0;$s<$Lookup[$i]['Subtable'][$c]['ChainSubClassSetCnt'];$s++) {
1687
- $ChainSubClassRuleCnt = $Lookup[$i]['Subtable'][$c]['ChainSubClassSet'][$s]['ChainSubClassRuleCnt'];
1688
- for($b=0;$b<$ChainSubClassRuleCnt;$b++) {
1689
- if ($Lookup[$i]['Subtable'][$c]['ChainSubClassSetOffset'][$s]>0) {
1690
- $this->seek($Lookup[$i]['Subtable'][$c]['ChainSubClassSet'][$s]['ChainSubClassRule'][$b]);
1691
- $Rule = array();
1692
- $Rule['BacktrackGlyphCount'] = $this->read_ushort();
1693
- for ($r=0;$r<$Rule['BacktrackGlyphCount'];$r++) {
1694
- $Rule['Backtrack'][$r] = $this->read_ushort();
1695
- }
1696
- $Rule['InputGlyphCount'] = $this->read_ushort();
1697
- for ($r=1;$r<$Rule['InputGlyphCount'];$r++) {
1698
- $Rule['Input'][$r] = $this->read_ushort();
1699
- }
1700
- $Rule['LookaheadGlyphCount'] = $this->read_ushort();
1701
- for ($r=0;$r<$Rule['LookaheadGlyphCount'];$r++) {
1702
- $Rule['Lookahead'][$r] = $this->read_ushort();
1703
- }
1704
- $Rule['SubstCount'] = $this->read_ushort();
1705
- for ($r=0;$r<$Rule['SubstCount'];$r++) {
1706
- $Rule['SequenceIndex'][$r] = $this->read_ushort();
1707
- $Rule['LookupListIndex'][$r] = $this->read_ushort();
1708
- }
1709
-
1710
- $Lookup[$i]['Subtable'][$c]['ChainSubClassSet'][$s]['ChainSubClassRule'][$b] = $Rule;
1711
- }
1712
- }
1713
- }
1714
- }
1715
- // Format 3: Coverage-based Chaining Context Glyph Substitution p259
1716
- else if ($SubstFormat==3) {
1717
- for ($b=0;$b<$Lookup[$i]['Subtable'][$c]['BacktrackGlyphCount'];$b++) {
1718
- $this->seek($Lookup[$i]['Subtable'][$c]['CoverageBacktrack'][$b]);
1719
- $glyphs = $this->_getCoverage();
1720
- $Lookup[$i]['Subtable'][$c]['CoverageBacktrackGlyphs'][] = implode("|",$glyphs);
1721
- }
1722
- for ($b=0;$b<$Lookup[$i]['Subtable'][$c]['InputGlyphCount'];$b++) {
1723
- $this->seek($Lookup[$i]['Subtable'][$c]['CoverageInput'][$b]);
1724
- $glyphs = $this->_getCoverage();
1725
- $Lookup[$i]['Subtable'][$c]['CoverageInputGlyphs'][] = implode("|",$glyphs);
1726
- // Don't use above value as these are ordered numerically not as need to process
1727
- }
1728
- for ($b=0;$b<$Lookup[$i]['Subtable'][$c]['LookaheadGlyphCount'];$b++) {
1729
- $this->seek($Lookup[$i]['Subtable'][$c]['CoverageLookahead'][$b]);
1730
- $glyphs = $this->_getCoverage();
1731
- $Lookup[$i]['Subtable'][$c]['CoverageLookaheadGlyphs'][] = implode("|",$glyphs);
1732
- }
1733
-
1734
- }
1735
- }
1736
- }
1737
- }
1738
-
1739
-
1740
- //=====================================================================================
1741
- //=====================================================================================
1742
- //=====================================================================================
1743
-
1744
-
1745
-
1746
- $st = $this->mpdf->OTLscript;
1747
- $t = $this->mpdf->OTLlang;
1748
- $langsys = $gsub[$st][$t];
1749
-
1750
-
1751
- $lul = array(); // array of LookupListIndexes
1752
- $tags = array(); // corresponding array of feature tags e.g. 'ccmp'
1753
- foreach($langsys AS $tag=>$ft) {
1754
- foreach($ft AS $ll) {
1755
- $lul[$ll] = $tag;
1756
- }
1757
- }
1758
- ksort($lul); // Order the Lookups in the order they are in the GUSB table, regardless of Feature order
1759
- $this->_getGSUBarray($Lookup, $lul, $st);
1760
- //print_r($lul); exit;
1761
-
1762
-
1763
-
1764
-
1765
- }
1766
- //print_r($Lookup); exit;
1767
-
1768
- return array($GSUBScriptLang, $gsub, $GSLookup, $rtlPUAstr, $rtlPUAarr);
1769
-
1770
- }
1771
- /////////////////////////////////////////////////////////////////////////////////////////
1772
- // GSUB functions
1773
- function _getGSUBarray(&$Lookup, &$lul, $scripttag, $level=1, $coverage='', $exB='', $exL='') {
1774
- // Process (3) LookupList for specific Script-LangSys
1775
- // Generate preg_replace
1776
- $html = '';
1777
- if ($level==1) { $html .= '<bookmark level="0" content="GSUB features">'; }
1778
- foreach($lul AS $i=>$tag) {
1779
- $html .= '<div class="level'.$level.'">';
1780
- $html .= '<h5 class="level'.$level.'">';
1781
- if ($level==1) { $html .= '<bookmark level="1" content="'.$tag.' [#'.$i.']">'; }
1782
- $html .= 'Lookup #'.$i.' [tag: <span style="color:#000066;">'.$tag.'</span>]</h5>';
1783
- $ignore = $this->_getGSUBignoreString($Lookup[$i]['Flag'], $Lookup[$i]['MarkFilteringSet']);
1784
- if ($ignore) { $html .= '<div class="ignore">Ignoring: '.$ignore.'</div> '; }
1785
-
1786
- $Type = $Lookup[$i]['Type'];
1787
- $Flag = $Lookup[$i]['Flag'];
1788
- if (($Flag & 0x0001) == 1) { $dir = 'RTL'; }
1789
- else { $dir = 'LTR'; }
1790
-
1791
- for ($c=0;$c<$Lookup[$i]['SubtableCount'] ;$c++) {
1792
- $html .= '<div class="subtable">Subtable #'.$c;
1793
- if ($level==1) { $html .= '<bookmark level="2" content="Subtable #'.$c.'">'; }
1794
- $html .= '</div>';
1795
-
1796
- $SubstFormat= $Lookup[$i]['Subtable'][$c]['Format'] ;
1797
-
1798
- // LookupType 1: Single Substitution Subtable
1799
- if ($Lookup[$i]['Type'] == 1) {
1800
- $html .= '<div class="lookuptype">LookupType 1: Single Substitution Subtable</div>';
1801
- for ($s=0;$s<count($Lookup[$i]['Subtable'][$c]['subs']);$s++) {
1802
- $inputGlyphs = $Lookup[$i]['Subtable'][$c]['subs'][$s]['Replace'];
1803
- $substitute = $Lookup[$i]['Subtable'][$c]['subs'][$s]['substitute'][0];
1804
- if ($level==2 && strpos($coverage, $inputGlyphs[0])===false) { continue; }
1805
- $html .= '<div class="substitution">';
1806
- $html .= '<span class="unicode">'.$this->formatUni($inputGlyphs[0]).'&nbsp;</span> ';
1807
- if ($level==2 && $exB) { $html .= $exB; }
1808
- $html .= '<span class="unchanged">&nbsp;'.$this->formatEntity($inputGlyphs[0]).'</span>';
1809
- if ($level==2 && $exL) { $html .= $exL; }
1810
- $html .= '&nbsp; &raquo; &raquo; &nbsp;';
1811
- if ($level==2 && $exB) { $html .= $exB; }
1812
- $html .= '<span class="changed">&nbsp;'.$this->formatEntity($substitute).'</span>';
1813
- if ($level==2 && $exL) { $html .= $exL; }
1814
- $html .= '&nbsp; <span class="unicode">'.$this->formatUni($substitute).'</span> ';
1815
- $html .= '</div>';
1816
- }
1817
- }
1818
- // LookupType 2: Multiple Substitution Subtable
1819
- else if ($Lookup[$i]['Type'] == 2) {
1820
- $html .= '<div class="lookuptype">LookupType 2: Multiple Substitution Subtable</div>';
1821
- for ($s=0;$s<count($Lookup[$i]['Subtable'][$c]['subs']);$s++) {
1822
- $inputGlyphs = $Lookup[$i]['Subtable'][$c]['subs'][$s]['Replace'];
1823
- $substitute = $Lookup[$i]['Subtable'][$c]['subs'][$s]['substitute'];
1824
- if ($level==2 && strpos($coverage, $inputGlyphs[0])===false) { continue; }
1825
- $html .= '<div class="substitution">';
1826
- $html .= '<span class="unicode">'.$this->formatUni($inputGlyphs[0]).'&nbsp;</span> ';
1827
- if ($level==2 && $exB) { $html .= $exB; }
1828
- $html .= '<span class="unchanged">&nbsp;'.$this->formatEntity($inputGlyphs[0]).'</span>';
1829
- if ($level==2 && $exL) { $html .= $exL; }
1830
- $html .= '&nbsp; &raquo; &raquo; &nbsp;';
1831
- if ($level==2 && $exB) { $html .= $exB; }
1832
- $html .= '<span class="changed">&nbsp;'.$this->formatEntityArr($substitute).'</span>';
1833
- if ($level==2 && $exL) { $html .= $exL; }
1834
- $html .= '&nbsp; <span class="unicode">'.$this->formatUniArr($substitute).'</span> ';
1835
- $html .= '</div>';
1836
- }
1837
- }
1838
- // LookupType 3: Alternate Forms
1839
- else if ($Lookup[$i]['Type'] == 3) {
1840
- $html .= '<div class="lookuptype">LookupType 3: Alternate Forms</div>';
1841
- for ($s=0;$s<count($Lookup[$i]['Subtable'][$c]['subs']);$s++) {
1842
- $inputGlyphs = $Lookup[$i]['Subtable'][$c]['subs'][$s]['Replace'];
1843
- $substitute = $Lookup[$i]['Subtable'][$c]['subs'][$s]['substitute'][0];
1844
- if ($level==2 && strpos($coverage, $inputGlyphs[0])===false) { continue; }
1845
- $html .= '<div class="substitution">';
1846
- $html .= '<span class="unicode">'.$this->formatUni($inputGlyphs[0]).'&nbsp;</span> ';
1847
- if ($level==2 && $exB) { $html .= $exB; }
1848
- $html .= '<span class="unchanged">&nbsp;'.$this->formatEntity($inputGlyphs[0]).'</span>';
1849
- if ($level==2 && $exL) { $html .= $exL; }
1850
- $html .= '&nbsp; &raquo; &raquo; &nbsp;';
1851
- if ($level==2 && $exB) { $html .= $exB; }
1852
- $html .= '<span class="changed">&nbsp;'.$this->formatEntity($substitute).'</span>';
1853
- if ($level==2 && $exL) { $html .= $exL; }
1854
- $html .= '&nbsp; <span class="unicode">'.$this->formatUni($substitute).'</span> ';
1855
- if (count($Lookup[$i]['Subtable'][$c]['subs'][$s]['substitute'])>1) {
1856
- for ($alt=1;$alt<count($Lookup[$i]['Subtable'][$c]['subs'][$s]['substitute']);$alt++) {
1857
- $substitute = $Lookup[$i]['Subtable'][$c]['subs'][$s]['substitute'][$alt];
1858
- $html .= '&nbsp; | &nbsp; ALT #'.$alt.' &nbsp; ';
1859
- $html .= '<span class="changed">&nbsp;'.$this->formatEntity($substitute).'</span>';
1860
- $html .= '&nbsp; <span class="unicode">'.$this->formatUni($substitute).'</span> ';
1861
- }
1862
- }
1863
- $html .= '</div>';
1864
- }
1865
- }
1866
- // LookupType 4: Ligature Substitution Subtable
1867
- else if ($Lookup[$i]['Type'] == 4) {
1868
- $html .= '<div class="lookuptype">LookupType 4: Ligature Substitution Subtable</div>';
1869
- for ($s=0;$s<count($Lookup[$i]['Subtable'][$c]['subs']);$s++) {
1870
- $inputGlyphs = $Lookup[$i]['Subtable'][$c]['subs'][$s]['Replace'];
1871
- $substitute = $Lookup[$i]['Subtable'][$c]['subs'][$s]['substitute'][0];
1872
- if ($level==2 && strpos($coverage, $inputGlyphs[0])===false) { continue; }
1873
- $html .= '<div class="substitution">';
1874
- $html .= '<span class="unicode">'.$this->formatUniArr($inputGlyphs).'&nbsp;</span> ';
1875
- if ($level==2 && $exB) { $html .= $exB; }
1876
- $html .= '<span class="unchanged">&nbsp;'.$this->formatEntityArr($inputGlyphs).'</span>';
1877
- if ($level==2 && $exL) { $html .= $exL; }
1878
- $html .= '&nbsp; &raquo; &raquo; &nbsp;';
1879
- if ($level==2 && $exB) { $html .= $exB; }
1880
- $html .= '<span class="changed">&nbsp;'.$this->formatEntity($substitute).'</span>';
1881
- if ($level==2 && $exL) { $html .= $exL; }
1882
- $html .= '&nbsp; <span class="unicode">'.$this->formatUni($substitute).'</span> ';
1883
- $html .= '</div>';
1884
- }
1885
- }
1886
-
1887
- // LookupType 5: Contextual Substitution Subtable
1888
- else if ($Lookup[$i]['Type'] == 5) {
1889
- $html .= '<div class="lookuptype">LookupType 5: Contextual Substitution Subtable</div>';
1890
- // Format 1: Context Substitution
1891
- if ($SubstFormat==1) {
1892
- $html .= '<div class="lookuptypesub">Format 1: Context Substitution</div>';
1893
- for($s=0;$s<$Lookup[$i]['Subtable'][$c]['SubRuleSetCount'];$s++) {
1894
- // SubRuleSet
1895
- $subRule = array();
1896
- $html .= '<div class="rule">Subrule Set: '.$s.'</div>';
1897
- foreach($Lookup[$i]['Subtable'][$c]['SubRuleSet'][$s]['SubRule'] AS $rctr=>$rule) {
1898
- // SubRule
1899
- $html .= '<div class="rule">SubRule: '.$rctr.'</div>';
1900
- $inputGlyphs = array();
1901
- if ($rule['GlyphCount']>1) {
1902
- $inputGlyphs = $rule['InputGlyphs'];
1903
- }
1904
- $inputGlyphs[0] = $Lookup[$i]['Subtable'][$c]['SubRuleSet'][$s]['FirstGlyph'];
1905
- ksort($inputGlyphs);
1906
- $nInput = count($inputGlyphs);
1907
-
1908
-
1909
- $exampleI = array();
1910
- $html .= '<div class="context">CONTEXT: ';
1911
- for ($ff=0;$ff<count($inputGlyphs);$ff++) {
1912
- $html .= '<div>Input #'.$ff.': <span class="unchanged">&nbsp;'.$this->formatEntityStr($inputGlyphs[$ff]).'&nbsp;</span></div>';
1913
- $exampleI[] = $this->formatEntityFirst($inputGlyphs[$ff]);
1914
- }
1915
- $html .= '</div>';
1916
-
1917
-
1918
- for ($b=0;$b<$rule['SubstCount'];$b++) {
1919
- $lup = $rule['SubstLookupRecord'][$b]['LookupListIndex'];
1920
- $seqIndex = $rule['SubstLookupRecord'][$b]['SequenceIndex'];
1921
-
1922
- // GENERATE exampleI[<seqIndex] .... exampleI[>seqIndex]
1923
- $exB = '';
1924
- $exL = '';
1925
- if ($seqIndex>0) {
1926
- $exB .= '<span class="inputother">';
1927
- for($ip=0;$ip<$seqIndex;$ip++) {
1928
- $exB .= $this->formatEntity($inputGlyphs[$ip]).'&#x200d;';
1929
- }
1930
- $exB .= '</span>';
1931
- }
1932
- if (count($inputGlyphs)>($seqIndex+1)) {
1933
- $exL .= '<span class="inputother">';
1934
- for($ip=$seqIndex+1;$ip<count($inputGlyphs);$ip++) {
1935
- $exL .= $this->formatEntity($inputGlyphs[$ip]).'&#x200d;';
1936
- }
1937
- $exL .= '</span>';
1938
- }
1939
- $html .= '<div class="sequenceIndex">Substitution Position: '.$seqIndex.'</div>';
1940
-
1941
- $lul2 = array($lup=>$tag);
1942
-
1943
- // Only apply if the (first) 'Replace' glyph from the
1944
- // Lookup list is in the [inputGlyphs] at ['SequenceIndex']
1945
- // Pass $inputGlyphs[$seqIndex] e.g. 00636|00645|00656
1946
- // to level 2 and only apply if first Replace glyph is in this list
1947
- $html .= $this->_getGSUBarray($Lookup, $lul2, $scripttag, 2, $inputGlyphs[$seqIndex], $exB, $exL);
1948
- }
1949
-
1950
-
1951
- if (count($subRule['rules'])) $volt[] = $subRule;
1952
-
1953
- }
1954
- }
1955
- }
1956
- // Format 2: Class-based Context Glyph Substitution
1957
- else if ($SubstFormat==2) {
1958
- $html .= '<div class="lookuptypesub">Format 2: Class-based Context Glyph Substitution</div>';
1959
- foreach($Lookup[$i]['Subtable'][$c]['SubClassSet'] AS $inputClass=>$cscs) {
1960
- $html .= '<div class="rule">Input Class: '.$inputClass.'</div>';
1961
- for($cscrule=0;$cscrule<$cscs['SubClassRuleCnt'];$cscrule++) {
1962
- $html .= '<div class="rule">Rule: '.$cscrule.'</div>';
1963
- $rule = $cscs['SubClassRule'][$cscrule];
1964
-
1965
- $inputGlyphs = array();
1966
-
1967
- $inputGlyphs[0] = $Lookup[$i]['Subtable'][$c]['InputClasses'][$inputClass];
1968
-
1969
- if ($rule['InputGlyphCount']>1) {
1970
- // NB starts at 1
1971
- for ($gcl=1;$gcl<$rule['InputGlyphCount'];$gcl++) {
1972
- $classindex = $rule['Input'][$gcl];
1973
- $inputGlyphs[$gcl] = $Lookup[$i]['Subtable'][$c]['InputClasses'][$classindex];
1974
- }
1975
- }
1976
-
1977
- // Class 0 contains all the glyphs NOT in the other classes
1978
- $class0excl = implode('|', $Lookup[$i]['Subtable'][$c]['InputClasses']);
1979
-
1980
- $exampleI = array();
1981
- $html .= '<div class="context">CONTEXT: ';
1982
- for ($ff=0;$ff<count($inputGlyphs);$ff++) {
1983
-
1984
- if (!$inputGlyphs[$ff]) {
1985
-
1986
- $html .= '<div>Input #'.$ff.': <span class="unchanged">&nbsp;[NOT '.$this->formatEntityStr($class0excl).']&nbsp;</span></div>';
1987
- $exampleI[] = '[NOT '.$this->formatEntityFirst($class0excl).']';
1988
- }
1989
- else {
1990
- $html .= '<div>Input #'.$ff.': <span class="unchanged">&nbsp;'.$this->formatEntityStr($inputGlyphs[$ff]).'&nbsp;</span></div>';
1991
- $exampleI[] = $this->formatEntityFirst($inputGlyphs[$ff]);
1992
- }
1993
- }
1994
- $html .= '</div>';
1995
-
1996
-
1997
- for ($b=0;$b<$rule['SubstCount'];$b++) {
1998
- $lup = $rule['LookupListIndex'][$b];
1999
- $seqIndex = $rule['SequenceIndex'][$b];
2000
-
2001
- // GENERATE exampleI[<seqIndex] .... exampleI[>seqIndex]
2002
- $exB = '';
2003
- $exL = '';
2004
-
2005
- if ($seqIndex>0) {
2006
- $exB .= '<span class="inputother">';
2007
- for($ip=0;$ip<$seqIndex;$ip++) {
2008
- if (!$inputGlyphs[$ip]) {
2009
- $exB .= '[*]';
2010
- }
2011
- else {
2012
- $exB .= $this->formatEntityFirst($inputGlyphs[$ip]).'&#x200d;';
2013
- }
2014
- }
2015
- $exB .= '</span>';
2016
- }
2017
-
2018
- if (count($inputGlyphs)>($seqIndex+1)) {
2019
- $exL .= '<span class="inputother">';
2020
- for($ip=$seqIndex+1;$ip<count($inputGlyphs);$ip++) {
2021
- if (!$inputGlyphs[$ip]) {
2022
- $exL .= '[*]';
2023
- }
2024
- else {
2025
- $exL .= $this->formatEntityFirst($inputGlyphs[$ip]).'&#x200d;';
2026
- }
2027
- }
2028
- $exL .= '</span>';
2029
- }
2030
-
2031
- $html .= '<div class="sequenceIndex">Substitution Position: '.$seqIndex.'</div>';
2032
-
2033
- $lul2 = array($lup=>$tag);
2034
-
2035
- // Only apply if the (first) 'Replace' glyph from the
2036
- // Lookup list is in the [inputGlyphs] at ['SequenceIndex']
2037
- // Pass $inputGlyphs[$seqIndex] e.g. 00636|00645|00656
2038
- // to level 2 and only apply if first Replace glyph is in this list
2039
- $html .= $this->_getGSUBarray($Lookup, $lul2, $scripttag, 2, $inputGlyphs[$seqIndex], $exB, $exL);
2040
- }
2041
- if (count($subRule['rules'])) $volt[] = $subRule;
2042
-
2043
- }
2044
- }
2045
-
2046
-
2047
-
2048
- }
2049
- // Format 3: Coverage-based Context Glyph Substitution p259
2050
- else if ($SubstFormat==3) {
2051
- $html .= '<div class="lookuptypesub">Format 3: Coverage-based Context Glyph Substitution </div>';
2052
- // IgnoreMarks flag set on main Lookup table
2053
- $inputGlyphs = $Lookup[$i]['Subtable'][$c]['CoverageInputGlyphs'];
2054
- $CoverageInputGlyphs = implode('|', $inputGlyphs);
2055
- $nInput = $Lookup[$i]['Subtable'][$c]['InputGlyphCount'];
2056
-
2057
- $exampleI = array();
2058
- $html .= '<div class="context">CONTEXT: ';
2059
- for ($ff=0;$ff<count($inputGlyphs);$ff++) {
2060
- $html .= '<div>Input #'.$ff.': <span class="unchanged">&nbsp;'.$this->formatEntityStr($inputGlyphs[$ff]).'&nbsp;</span></div>';
2061
- $exampleI[] = $this->formatEntityFirst($inputGlyphs[$ff]);
2062
- }
2063
- $html .= '</div>';
2064
-
2065
-
2066
- for ($b=0;$b<$Lookup[$i]['Subtable'][$c]['SubstCount'];$b++) {
2067
- $lup = $Lookup[$i]['Subtable'][$c]['SubstLookupRecord'][$b]['LookupListIndex'];
2068
- $seqIndex = $Lookup[$i]['Subtable'][$c]['SubstLookupRecord'][$b]['SequenceIndex'];
2069
- // GENERATE exampleI[<seqIndex] .... exampleI[>seqIndex]
2070
- $exB = '';
2071
- $exL = '';
2072
- if ($seqIndex>0) {
2073
- $exB .= '<span class="inputother">';
2074
- for($ip=0;$ip<$seqIndex;$ip++) {
2075
- $exB .= $exampleI[$ip].'&#x200d;';
2076
- }
2077
- $exB .= '</span>';
2078
- }
2079
-
2080
- if (count($inputGlyphs)>($seqIndex+1)) {
2081
- $exL .= '<span class="inputother">';
2082
- for($ip=$seqIndex+1;$ip<count($inputGlyphs);$ip++) {
2083
- $exL .= $exampleI[$ip].'&#x200d;';
2084
- }
2085
- $exL .= '</span>';
2086
- }
2087
-
2088
- $html .= '<div class="sequenceIndex">Substitution Position: '.$seqIndex.'</div>';
2089
-
2090
- $lul2 = array($lup=>$tag);
2091
-
2092
- // Only apply if the (first) 'Replace' glyph from the
2093
- // Lookup list is in the [inputGlyphs] at ['SequenceIndex']
2094
- // Pass $inputGlyphs[$seqIndex] e.g. 00636|00645|00656
2095
- // to level 2 and only apply if first Replace glyph is in this list
2096
- $html .= $this->_getGSUBarray($Lookup, $lul2, $scripttag, 2, $inputGlyphs[$seqIndex], $exB, $exL);
2097
- }
2098
- if (count($subRule['rules'])) $volt[] = $subRule;
2099
- }
2100
-
2101
- //print_r($Lookup[$i]);
2102
- //print_r($volt[(count($volt)-1)]); exit;
2103
- }
2104
- // LookupType 6: Chaining Contextual Substitution Subtable
2105
- else if ($Lookup[$i]['Type'] == 6) {
2106
- $html .= '<div class="lookuptype">LookupType 6: Chaining Contextual Substitution Subtable</div>';
2107
- // Format 1: Simple Chaining Context Glyph Substitution p255
2108
- if ($SubstFormat==1) {
2109
- $html .= '<div class="lookuptypesub">Format 1: Simple Chaining Context Glyph Substitution </div>';
2110
- for($s=0;$s<$Lookup[$i]['Subtable'][$c]['ChainSubRuleSetCount'];$s++) {
2111
- // ChainSubRuleSet
2112
- $subRule = array();
2113
- $html .= '<div class="rule">Subrule Set: '.$s.'</div>';
2114
- $firstInputGlyph = $Lookup[$i]['Subtable'][$c]['CoverageGlyphs'][$s]; // First input gyyph
2115
- foreach($Lookup[$i]['Subtable'][$c]['ChainSubRuleSet'][$s]['ChainSubRule'] AS $rctr=>$rule) {
2116
- $html .= '<div class="rule">SubRule: '.$rctr.'</div>';
2117
- // ChainSubRule
2118
- $inputGlyphs = array();
2119
- if ($rule['InputGlyphCount']>1) {
2120
- $inputGlyphs = $rule['InputGlyphs'];
2121
- }
2122
- $inputGlyphs[0] = $firstInputGlyph;
2123
- ksort($inputGlyphs);
2124
- $nInput = count($inputGlyphs);
2125
-
2126
- if ($rule['BacktrackGlyphCount']) { $backtrackGlyphs = $rule['BacktrackGlyphs']; }
2127
- else { $backtrackGlyphs = array(); }
2128
-
2129
- if ($rule['LookaheadGlyphCount']) { $lookaheadGlyphs = $rule['LookaheadGlyphs']; }
2130
- else { $lookaheadGlyphs = array(); }
2131
-
2132
-
2133
- $exampleB = array();
2134
- $exampleI = array();
2135
- $exampleL = array();
2136
- $html .= '<div class="context">CONTEXT: ';
2137
- for ($ff=count($backtrackGlyphs)-1;$ff>=0;$ff--) {
2138
- $html .= '<div>Backtrack #'.$ff.': <span class="unicode">'.$this->formatUniStr($backtrackGlyphs[$ff]).'</span></div>';
2139
- $exampleB[] = $this->formatEntityFirst($backtrackGlyphs[$ff]);
2140
- }
2141
- for ($ff=0;$ff<count($inputGlyphs);$ff++) {
2142
- $html .= '<div>Input #'.$ff.': <span class="unchanged">&nbsp;'.$this->formatEntityStr($inputGlyphs[$ff]).'&nbsp;</span></div>';
2143
- $exampleI[] = $this->formatEntityFirst($inputGlyphs[$ff]);
2144
- }
2145
- for ($ff=0;$ff<count($lookaheadGlyphs);$ff++) {
2146
- $html .= '<div>Lookahead #'.$ff.': <span class="unicode">'.$this->formatUniStr($lookaheadGlyphs[$ff]).'</span></div>';
2147
- $exampleL[] = $this->formatEntityFirst($lookaheadGlyphs[$ff]);
2148
- }
2149
- $html .= '</div>';
2150
-
2151
-
2152
- for ($b=0;$b<$rule['SubstCount'];$b++) {
2153
- $lup = $rule['LookupListIndex'][$b];
2154
- $seqIndex = $rule['SequenceIndex'][$b];
2155
-
2156
- // GENERATE exampleB[n] exampleI[<seqIndex] .... exampleI[>seqIndex] exampleL[n]
2157
- $exB = '';
2158
- $exL = '';
2159
- if (count($exampleB)) { $exB .= '<span class="backtrack">'.implode('&#x200d;',$exampleB).'</span>'; }
2160
-
2161
- if ($seqIndex>0) {
2162
- $exB .= '<span class="inputother">';
2163
- for($ip=0;$ip<$seqIndex;$ip++) {
2164
- $exB .= $this->formatEntity($inputGlyphs[$ip]).'&#x200d;';
2165
- }
2166
- $exB .= '</span>';
2167
- }
2168
-
2169
- if (count($inputGlyphs)>($seqIndex+1)) {
2170
- $exL .= '<span class="inputother">';
2171
- for($ip=$seqIndex+1;$ip<count($inputGlyphs);$ip++) {
2172
- $exL .= $this->formatEntity($inputGlyphs[$ip]).'&#x200d;';
2173
- }
2174
- $exL .= '</span>';
2175
- }
2176
-
2177
- if (count($exampleL)) { $exL .= '<span class="lookahead">'.implode('&#x200d;',$exampleL).'</span>'; }
2178
-
2179
- $html .= '<div class="sequenceIndex">Substitution Position: '.$seqIndex.'</div>';
2180
-
2181
- $lul2 = array($lup=>$tag);
2182
-
2183
- // Only apply if the (first) 'Replace' glyph from the
2184
- // Lookup list is in the [inputGlyphs] at ['SequenceIndex']
2185
- // Pass $inputGlyphs[$seqIndex] e.g. 00636|00645|00656
2186
- // to level 2 and only apply if first Replace glyph is in this list
2187
- $html .= $this->_getGSUBarray($Lookup, $lul2, $scripttag, 2, $inputGlyphs[$seqIndex], $exB, $exL);
2188
- }
2189
-
2190
-
2191
- if (count($subRule['rules'])) $volt[] = $subRule;
2192
-
2193
-
2194
-
2195
- }
2196
- }
2197
-
2198
- }
2199
- // Format 2: Class-based Chaining Context Glyph Substitution p257
2200
- else if ($SubstFormat==2) {
2201
- $html .= '<div class="lookuptypesub">Format 2: Class-based Chaining Context Glyph Substitution </div>';
2202
- foreach($Lookup[$i]['Subtable'][$c]['ChainSubClassSet'] AS $inputClass=>$cscs) {
2203
- $html .= '<div class="rule">Input Class: '.$inputClass.'</div>';
2204
- for($cscrule=0;$cscrule<$cscs['ChainSubClassRuleCnt'];$cscrule++) {
2205
- $html .= '<div class="rule">Rule: '.$cscrule.'</div>';
2206
- $rule = $cscs['ChainSubClassRule'][$cscrule];
2207
-
2208
- // These contain classes of glyphs as strings
2209
- // $Lookup[$i]['Subtable'][$c]['InputClasses'][(class)] e.g. 02E6|02E7|02E8
2210
- // $Lookup[$i]['Subtable'][$c]['LookaheadClasses'][(class)]
2211
- // $Lookup[$i]['Subtable'][$c]['BacktrackClasses'][(class)]
2212
-
2213
- // These contain arrays of classIndexes
2214
- // [Backtrack] [Lookahead] and [Input] (Input is from the second position only)
2215
-
2216
- $inputGlyphs = array();
2217
-
2218
- $inputGlyphs[0] = $Lookup[$i]['Subtable'][$c]['InputClasses'][$inputClass];
2219
- if ($rule['InputGlyphCount']>1) {
2220
- // NB starts at 1
2221
- for ($gcl=1;$gcl<$rule['InputGlyphCount'];$gcl++) {
2222
- $classindex = $rule['Input'][$gcl];
2223
- $inputGlyphs[$gcl] = $Lookup[$i]['Subtable'][$c]['InputClasses'][$classindex];
2224
- }
2225
- }
2226
- // Class 0 contains all the glyphs NOT in the other classes
2227
- $class0excl = implode('|', $Lookup[$i]['Subtable'][$c]['InputClasses']);
2228
-
2229
- $nInput = $rule['InputGlyphCount'];
2230
-
2231
- if ($rule['BacktrackGlyphCount']) {
2232
- for ($gcl=0;$gcl<$rule['BacktrackGlyphCount'];$gcl++) {
2233
- $classindex = $rule['Backtrack'][$gcl];
2234
- $backtrackGlyphs[$gcl] = $Lookup[$i]['Subtable'][$c]['BacktrackClasses'][$classindex];
2235
- }
2236
- }
2237
- else { $backtrackGlyphs = array(); }
2238
-
2239
- if ($rule['LookaheadGlyphCount']) {
2240
- for ($gcl=0;$gcl<$rule['LookaheadGlyphCount'];$gcl++) {
2241
- $classindex = $rule['Lookahead'][$gcl];
2242
- $lookaheadGlyphs[$gcl] = $Lookup[$i]['Subtable'][$c]['LookaheadClasses'][$classindex];
2243
- }
2244
- }
2245
- else { $lookaheadGlyphs = array(); }
2246
-
2247
-
2248
- $exampleB = array();
2249
- $exampleI = array();
2250
- $exampleL = array();
2251
- $html .= '<div class="context">CONTEXT: ';
2252
- for ($ff=count($backtrackGlyphs)-1;$ff>=0;$ff--) {
2253
- if (!$backtrackGlyphs[$ff]) {
2254
- $html .= '<div>Backtrack #'.$ff.': <span class="unchanged">&nbsp;[NOT '.$this->formatEntityStr($class0excl).']&nbsp;</span></div>';
2255
- $exampleB[] = '[NOT '.$this->formatEntityFirst($class0excl).']';
2256
-
2257
- }
2258
- else {
2259
- $html .= '<div>Backtrack #'.$ff.': <span class="unicode">'.$this->formatUniStr($backtrackGlyphs[$ff]).'</span></div>';
2260
- $exampleB[] = $this->formatEntityFirst($backtrackGlyphs[$ff]);
2261
- }
2262
- }
2263
- for ($ff=0;$ff<count($inputGlyphs);$ff++) {
2264
- if (!$inputGlyphs[$ff]) {
2265
- $html .= '<div>Input #'.$ff.': <span class="unchanged">&nbsp;[NOT '.$this->formatEntityStr($class0excl).']&nbsp;</span></div>';
2266
- $exampleI[] = '[NOT '.$this->formatEntityFirst($class0excl).']';
2267
- }
2268
- else {
2269
- $html .= '<div>Input #'.$ff.': <span class="unchanged">&nbsp;'.$this->formatEntityStr($inputGlyphs[$ff]).'&nbsp;</span></div>';
2270
- $exampleI[] = $this->formatEntityFirst($inputGlyphs[$ff]);
2271
- }
2272
- }
2273
- for ($ff=0;$ff<count($lookaheadGlyphs);$ff++) {
2274
- if (!$lookaheadGlyphs[$ff]) {
2275
- $html .= '<div>Lookahead #'.$ff.': <span class="unchanged">&nbsp;[NOT '.$this->formatEntityStr($class0excl).']&nbsp;</span></div>';
2276
- $exampleL[] = '[NOT '.$this->formatEntityFirst($class0excl).']';
2277
-
2278
- }
2279
- else {
2280
- $html .= '<div>Lookahead #'.$ff.': <span class="unicode">'.$this->formatUniStr($lookaheadGlyphs[$ff]).'</span></div>';
2281
- $exampleL[] = $this->formatEntityFirst($lookaheadGlyphs[$ff]);
2282
- }
2283
- }
2284
- $html .= '</div>';
2285
-
2286
-
2287
- for ($b=0;$b<$rule['SubstCount'];$b++) {
2288
- $lup = $rule['LookupListIndex'][$b];
2289
- $seqIndex = $rule['SequenceIndex'][$b];
2290
-
2291
- // GENERATE exampleB[n] exampleI[<seqIndex] .... exampleI[>seqIndex] exampleL[n]
2292
- $exB = '';
2293
- $exL = '';
2294
- if (count($exampleB)) { $exB .= '<span class="backtrack">'.implode('&#x200d;',$exampleB).'</span>'; }
2295
-
2296
- if ($seqIndex>0) {
2297
- $exB .= '<span class="inputother">';
2298
- for($ip=0;$ip<$seqIndex;$ip++) {
2299
- if (!$inputGlyphs[$ip]) {
2300
- $exB .= '[*]';
2301
- }
2302
- else {
2303
- $exB .= $this->formatEntityFirst($inputGlyphs[$ip]).'&#x200d;';
2304
- }
2305
- }
2306
- $exB .= '</span>';
2307
- }
2308
-
2309
- if (count($inputGlyphs)>($seqIndex+1)) {
2310
- $exL .= '<span class="inputother">';
2311
- for($ip=$seqIndex+1;$ip<count($inputGlyphs);$ip++) {
2312
- if (!$inputGlyphs[$ip]) {
2313
- $exL .= '[*]';
2314
- }
2315
- else {
2316
- $exL .= $this->formatEntityFirst($inputGlyphs[$ip]).'&#x200d;';
2317
- }
2318
- }
2319
- $exL .= '</span>';
2320
- }
2321
-
2322
- if (count($exampleL)) { $exL .= '<span class="lookahead">'.implode('&#x200d;',$exampleL).'</span>'; }
2323
-
2324
- $html .= '<div class="sequenceIndex">Substitution Position: '.$seqIndex.'</div>';
2325
-
2326
- $lul2 = array($lup=>$tag);
2327
-
2328
- // Only apply if the (first) 'Replace' glyph from the
2329
- // Lookup list is in the [inputGlyphs] at ['SequenceIndex']
2330
- // Pass $inputGlyphs[$seqIndex] e.g. 00636|00645|00656
2331
- // to level 2 and only apply if first Replace glyph is in this list
2332
- $html .= $this->_getGSUBarray($Lookup, $lul2, $scripttag, 2, $inputGlyphs[$seqIndex], $exB, $exL);
2333
-
2334
- }
2335
-
2336
- }
2337
- }
2338
-
2339
-
2340
- //print_r($Lookup[$i]['Subtable'][$c]); exit;
2341
-
2342
- }
2343
- // Format 3: Coverage-based Chaining Context Glyph Substitution p259
2344
- else if ($SubstFormat==3) {
2345
- $html .= '<div class="lookuptypesub">Format 3: Coverage-based Chaining Context Glyph Substitution </div>';
2346
- // IgnoreMarks flag set on main Lookup table
2347
- $inputGlyphs = $Lookup[$i]['Subtable'][$c]['CoverageInputGlyphs'];
2348
- $CoverageInputGlyphs = implode('|', $inputGlyphs);
2349
- $nInput = $Lookup[$i]['Subtable'][$c]['InputGlyphCount'];
2350
-
2351
- if ($Lookup[$i]['Subtable'][$c]['BacktrackGlyphCount']) {
2352
- $backtrackGlyphs = $Lookup[$i]['Subtable'][$c]['CoverageBacktrackGlyphs'];
2353
- }
2354
- else { $backtrackGlyphs = array(); }
2355
-
2356
- if ($Lookup[$i]['Subtable'][$c]['LookaheadGlyphCount']) {
2357
- $lookaheadGlyphs = $Lookup[$i]['Subtable'][$c]['CoverageLookaheadGlyphs'];
2358
- }
2359
- else { $lookaheadGlyphs = array(); }
2360
-
2361
-
2362
- $exampleB = array();
2363
- $exampleI = array();
2364
- $exampleL = array();
2365
- $html .= '<div class="context">CONTEXT: ';
2366
- for ($ff=count($backtrackGlyphs)-1;$ff>=0;$ff--) {
2367
- $html .= '<div>Backtrack #'.$ff.': <span class="unicode">'.$this->formatUniStr($backtrackGlyphs[$ff]).'</span></div>';
2368
- $exampleB[] = $this->formatEntityFirst($backtrackGlyphs[$ff]);
2369
- }
2370
- for ($ff=0;$ff<count($inputGlyphs);$ff++) {
2371
- $html .= '<div>Input #'.$ff.': <span class="unchanged">&nbsp;'.$this->formatEntityStr($inputGlyphs[$ff]).'&nbsp;</span></div>';
2372
- $exampleI[] = $this->formatEntityFirst($inputGlyphs[$ff]);
2373
- }
2374
- for ($ff=0;$ff<count($lookaheadGlyphs);$ff++) {
2375
- $html .= '<div>Lookahead #'.$ff.': <span class="unicode">'.$this->formatUniStr($lookaheadGlyphs[$ff]).'</span></div>';
2376
- $exampleL[] = $this->formatEntityFirst($lookaheadGlyphs[$ff]);
2377
- }
2378
- $html .= '</div>';
2379
-
2380
-
2381
- for ($b=0;$b<$Lookup[$i]['Subtable'][$c]['SubstCount'];$b++) {
2382
- $lup = $Lookup[$i]['Subtable'][$c]['SubstLookupRecord'][$b]['LookupListIndex'];
2383
- $seqIndex = $Lookup[$i]['Subtable'][$c]['SubstLookupRecord'][$b]['SequenceIndex'];
2384
-
2385
-
2386
- // GENERATE exampleB[n] exampleI[<seqIndex] .... exampleI[>seqIndex] exampleL[n]
2387
- $exB = '';
2388
- $exL = '';
2389
- if (count($exampleB)) { $exB .= '<span class="backtrack">'.implode('&#x200d;',$exampleB).'</span>'; }
2390
-
2391
- if ($seqIndex>0) {
2392
- $exB .= '<span class="inputother">';
2393
- for($ip=0;$ip<$seqIndex;$ip++) {
2394
- $exB .= $exampleI[$ip].'&#x200d;';
2395
- }
2396
- $exB .= '</span>';
2397
- }
2398
-
2399
- if (count($inputGlyphs)>($seqIndex+1)) {
2400
- $exL .= '<span class="inputother">';
2401
- for($ip=$seqIndex+1;$ip<count($inputGlyphs);$ip++) {
2402
- $exL .= $exampleI[$ip].'&#x200d;';
2403
- }
2404
- $exL .= '</span>';
2405
- }
2406
-
2407
- if (count($exampleL)) { $exL .= '<span class="lookahead">'.implode('&#x200d;',$exampleL).'</span>'; }
2408
-
2409
- $html .= '<div class="sequenceIndex">Substitution Position: '.$seqIndex.'</div>';
2410
-
2411
- $lul2 = array($lup=>$tag);
2412
-
2413
- // Only apply if the (first) 'Replace' glyph from the
2414
- // Lookup list is in the [inputGlyphs] at ['SequenceIndex']
2415
- // Pass $inputGlyphs[$seqIndex] e.g. 00636|00645|00656
2416
- // to level 2 and only apply if first Replace glyph is in this list
2417
- $html .= $this->_getGSUBarray($Lookup, $lul2, $scripttag, 2, $inputGlyphs[$seqIndex], $exB, $exL);
2418
-
2419
- }
2420
- }
2421
- }
2422
- }
2423
- $html .= '</div>';
2424
- }
2425
- if ($level ==1) { $this->mpdf->WriteHTML($html); }
2426
- else { return $html; }
2427
- //print_r($Lookup); exit;
2428
- }
2429
- //=====================================================================================
2430
- //=====================================================================================
2431
- // mPDF 5.7.1
2432
- function _checkGSUBignore($flag, $glyph, $MarkFilteringSet) {
2433
- $ignore = false;
2434
- // Flag & 0x0008 = Ignore Marks
2435
- if ((($flag & 0x0008) == 0x0008) && strpos($this->GlyphClassMarks,$glyph)) { $ignore = true; }
2436
- if ((($flag & 0x0004) == 0x0004) && strpos($this->GlyphClassLigatures,$glyph)) { $ignore = true; }
2437
- if ((($flag & 0x0002) == 0x0002) && strpos($this->GlyphClassBases,$glyph)) { $ignore = true; }
2438
- // Flag & 0xFF?? = MarkAttachmentType
2439
- if (($flag & 0xFF00) && strpos($this->MarkAttachmentType[($flag >> 8)],$glyph)) { $ignore = true; }
2440
- // Flag & 0x0010 = UseMarkFilteringSet
2441
- if (($flag & 0x0010) && strpos($this->MarkGlyphSets[$MarkFilteringSet],$glyph)) { $ignore = true; }
2442
- return $ignore;
2443
- }
2444
-
2445
- function _getGSUBignoreString($flag, $MarkFilteringSet) {
2446
- // If ignoreFlag set, combine all ignore glyphs into -> "((?:(?: FBA1| FBA2| FBA3))*)"
2447
- // else "()"
2448
- // for Input - set on secondary Lookup table if in Context, and set Backtrack and Lookahead on Context Lookup
2449
- $str = "";
2450
- $ignoreflag = 0;
2451
-
2452
- // Flag & 0xFF?? = MarkAttachmentType
2453
- if ($flag & 0xFF00) {
2454
- $MarkAttachmentType = $flag >> 8;
2455
- $ignoreflag = $flag;
2456
- //$str = $this->MarkAttachmentType[$MarkAttachmentType];
2457
- $str = "MarkAttachmentType[".$MarkAttachmentType."] ";
2458
- }
2459
-
2460
- // Flag & 0x0010 = UseMarkFilteringSet
2461
- if ($flag & 0x0010) {
2462
- die("This font ".$this->fontkey." contains MarkGlyphSets");
2463
- $str = "Mark Glyph Set: ";
2464
- $str .= $this->MarkGlyphSets[$MarkFilteringSet];
2465
- }
2466
-
2467
- // If Ignore Marks set, supercedes any above
2468
- // Flag & 0x0008 = Ignore Marks
2469
- if (($flag & 0x0008) == 0x0008) {
2470
- $ignoreflag = 8;
2471
- //$str = $this->GlyphClassMarks;
2472
- $str = "Mark Glyphs ";
2473
- }
2474
-
2475
- // Flag & 0x0004 = Ignore Ligatures
2476
- if (($flag & 0x0004) == 0x0004) {
2477
- $ignoreflag += 4;
2478
- if ($str) { $str .= "|"; }
2479
- //$str .= $this->GlyphClassLigatures;
2480
- $str .= "Ligature Glyphs ";
2481
- }
2482
- // Flag & 0x0002 = Ignore BaseGlyphs
2483
- if (($flag & 0x0002) == 0x0002) {
2484
- $ignoreflag += 2;
2485
- if ($str) { $str .= "|"; }
2486
- //$str .= $this->GlyphClassBases;
2487
- $str .= "Base Glyphs ";
2488
- }
2489
- if ($str) {
2490
- return $str;
2491
- }
2492
- else return "";
2493
- }
2494
-
2495
- // GSUB Patterns
2496
-
2497
- /*
2498
- BACKTRACK INPUT LOOKAHEAD
2499
- ================================== ================== ==================================
2500
- (FEEB|FEEC)(ign) �(FD12|FD13)(ign) �(0612)�(ign) (0613)�(ign) (FD12|FD13)�(ign) (FEEB|FEEC)
2501
- ---------------- ---------------- ----- ------------ --------------- ---------------
2502
- Backtrack 1 Backtrack 2 Input 1 Input 2 Lookahead 1 Lookahead 2
2503
- -------- --- --------- --- ---- --- ---- --- --------- --- -------
2504
- \${1} \${2} \${3} \${4} \${5+} \${6+} \${7+} \${8+}
2505
-
2506
- nBacktrack = 2 nInput = 2 nLookahead = 2
2507
-
2508
- nBsubs = 2xnBack nIsubs = (nBsubs+) nLsubs = (nBsubs+nIsubs+) 2xnLookahead
2509
- "\${1}\${2} " (nInput*2)-1 "\${5+} \${6+}"
2510
- "REPL"
2511
-
2512
- �\${1}\${2} �\${3}\${4} �REPL�\${5+} \${6+}�\${7+} \${8+}�
2513
-
2514
-
2515
- INPUT nInput = 5
2516
- ============================================================
2517
- �(0612)�(ign) (0613)�(ign) (0614)�(ign) (0615)�(ign) (0615)�
2518
- \${1} \${2} \${3} \${4} \${5} \${6} \${7} \${8} \${9} (All backreference numbers are + nBsubs)
2519
- ----- ------------ ------------ ------------ ------------
2520
- Input 1 Input 2 Input 3 Input 4 Input 5
2521
-
2522
- A====== SequenceIndex=1 ; Lookup match nGlyphs=1
2523
- B=================== SequenceIndex=1 ; Lookup match nGlyphs=2
2524
- C=============================== SequenceIndex=1 ; Lookup match nGlyphs=3
2525
- D======================= SequenceIndex=2 ; Lookup match nGlyphs=2
2526
- E===================================== SequenceIndex=2 ; Lookup match nGlyphs=3
2527
- F====================== SequenceIndex=4 ; Lookup match nGlyphs=2
2528
-
2529
- All backreference numbers are + nBsubs
2530
- A - "REPL\${2} \${3}\${4} \${5}\${6} \${7}\${8} \${9}"
2531
- B - "REPL\${2}\${4} \${5}\${6} \${7}\${8} \${9}"
2532
- C - "REPL\${2}\${4}\${6} \${7}\${8} \${9}"
2533
- D - "\${1} REPL\${2}\${4}\${6} \${7}\${8} \${9}"
2534
- E - "\${1} REPL\${2}\${4}\${6}\${8} \${9}"
2535
- F - "\${1}\${2} \${3}\${4} \${5} REPL\${6}\${8}"
2536
- */
2537
-
2538
- function _makeGSUBcontextInputMatch($inputGlyphs, $ignore, $lookupGlyphs, $seqIndex) {
2539
- // $ignore = "((?:(?: FBA1| FBA2| FBA3))*)" or "()"
2540
- // Returns e.g. �(0612)�(ignore) (0613)�(ignore) (0614)�
2541
- // $inputGlyphs = array of glyphs(glyphstrings) making up Input sequence in Context
2542
- // $lookupGlyphs = array of glyphs (single Glyphs) making up Lookup Input sequence
2543
- $mLen = count($lookupGlyphs); // nGlyphs in the secondary Lookup match
2544
- $nInput = count($inputGlyphs); // nGlyphs in the Primary Input sequence
2545
- $str = "";
2546
- for($i=0;$i<$nInput;$i++) {
2547
- if ($i>0) { $str .= $ignore." "; }
2548
- if ($i>=$seqIndex && $i<($seqIndex+$mLen)) { $str .= "".$lookupGlyphs[($i-$seqIndex)].""; }
2549
- else { $str .= "".$inputGlyphs[($i)].""; }
2550
- }
2551
- return $str;
2552
- }
2553
-
2554
- function _makeGSUBinputMatch($inputGlyphs, $ignore) {
2555
- // $ignore = "((?:(?: FBA1| FBA2| FBA3))*)" or "()"
2556
- // Returns e.g. �(0612)�(ignore) (0613)�(ignore) (0614)�
2557
- // $inputGlyphs = array of glyphs(glyphstrings) making up Input sequence in Context
2558
- // $lookupGlyphs = array of glyphs making up Lookup Input sequence - if applicable
2559
- $str = "";
2560
- for($i=1;$i<=count($inputGlyphs);$i++) {
2561
- if ($i>1) { $str .= $ignore." "; }
2562
- $str .= "".$inputGlyphs[($i-1)]."";
2563
- }
2564
- return $str;
2565
- }
2566
-
2567
- function _makeGSUBbacktrackMatch($backtrackGlyphs, $ignore) {
2568
- // $ignore = "((?:(?: FBA1| FBA2| FBA3))*)" or "()"
2569
- // Returns e.g. �(FEEB|FEEC)(ignore) �(FD12|FD13)(ignore) �
2570
- // $backtrackGlyphs = array of glyphstrings making up Backtrack sequence
2571
- // 3 2 1 0
2572
- // each item being e.g. E0AD|E0AF|F1FD
2573
- $str = "";
2574
- for($i=(count($backtrackGlyphs)-1);$i>=0;$i--) {
2575
- $str .= "".$backtrackGlyphs[$i]." ".$ignore." ";
2576
- }
2577
- return $str;
2578
- }
2579
-
2580
- function _makeGSUBlookaheadMatch($lookaheadGlyphs, $ignore) {
2581
- // $ignore = "((?:(?: FBA1| FBA2| FBA3))*)" or "()"
2582
- // Returns e.g. �(ignore) (FD12|FD13)�(ignore) (FEEB|FEEC)�
2583
- // $lookaheadGlyphs = array of glyphstrings making up Lookahead sequence
2584
- // 0 1 2 3
2585
- // each item being e.g. E0AD|E0AF|F1FD
2586
- $str = "";
2587
- for($i=0;$i<count($lookaheadGlyphs);$i++) {
2588
- $str .= $ignore." ".$lookaheadGlyphs[$i]."";
2589
- }
2590
- return $str;
2591
- }
2592
-
2593
-
2594
-
2595
- function _makeGSUBinputReplacement($nInput, $REPL, $ignore, $nBsubs, $mLen, $seqIndex) {
2596
- // Returns e.g. "REPL\${6}\${8}" or "\${1}\${2} \${3} REPL\${4}\${6}\${8} \${9}"
2597
- // $nInput nGlyphs in the Primary Input sequence
2598
- // $REPL replacement glyphs from secondary lookup
2599
- // $ignore = "((?:(?: FBA1| FBA2| FBA3))*)" or "()"
2600
- // $nBsubs Number of Backtrack substitutions (= 2x Number of Backtrack glyphs)
2601
- // $mLen nGlyphs in the secondary Lookup match - if no secondary lookup, should=$nInput
2602
- // $seqIndex Sequence Index to apply the secondary match
2603
- if ($ignore=="()") { $ign = false; }
2604
- else { $ign = true; }
2605
- $str = "";
2606
- if ($nInput == 1) { $str = $REPL; }
2607
- else if ($nInput>1) {
2608
- if ($mLen==$nInput) { // whole string replaced
2609
- $str = $REPL;
2610
- if ($ign) {
2611
- // for every nInput over 1, add another replacement backreference, to move IGNORES after replacement
2612
- for($x=2;$x<=$nInput;$x++) {
2613
- $str .= '\\'.($nBsubs+(2*($x-1)));
2614
- }
2615
- }
2616
- }
2617
- else { // if only part of string replaced:
2618
- for($x=1;$x<($seqIndex+1);$x++) {
2619
- if ($x==1) { $str .= '\\'.($nBsubs + 1); }
2620
- else {
2621
- if ($ign) { $str .= '\\'.($nBsubs+(2*($x-1))); }
2622
- $str .= ' \\'.($nBsubs+1+(2*($x-1)));
2623
- }
2624
- }
2625
- if ($seqIndex>0) { $str .= " "; }
2626
- $str .= $REPL;
2627
- if ($ign) {
2628
- for($x=(max(($seqIndex+1),2));$x<($seqIndex+1+$mLen);$x++) { // move IGNORES after replacement
2629
- $str .= '\\'.($nBsubs+(2*($x-1)));
2630
- }
2631
- }
2632
- for($x=($seqIndex+1+$mLen);$x<=$nInput;$x++) {
2633
- if ($ign) { $str .= '\\'.($nBsubs+(2*($x-1))); }
2634
- $str .= ' \\'.($nBsubs+1+(2*($x-1)));
2635
- }
2636
- }
2637
- }
2638
- return $str;
2639
- }
2640
-
2641
-
2642
-
2643
- //////////////////////////////////////////////////////////////////////////////////
2644
- function _getCoverage($convert2hex=true) {
2645
- $g = array();
2646
- $CoverageFormat= $this->read_ushort();
2647
- if ($CoverageFormat == 1) {
2648
- $CoverageGlyphCount= $this->read_ushort();
2649
- for ($gid=0;$gid<$CoverageGlyphCount;$gid++) {
2650
- $glyphID = $this->read_ushort();
2651
- if ($convert2hex) { $g[] = unicode_hex($this->glyphToChar[$glyphID][0]); }
2652
- else { $g[] = $glyphID; }
2653
- }
2654
- }
2655
- if ($CoverageFormat == 2) {
2656
- $RangeCount= $this->read_ushort();
2657
- for ($r=0;$r<$RangeCount;$r++) {
2658
- $start = $this->read_ushort();
2659
- $end = $this->read_ushort();
2660
- $StartCoverageIndex = $this->read_ushort(); // n/a
2661
- for ($gid=$start;$gid<=$end;$gid++) {
2662
- $glyphID = $gid;
2663
- if ($convert2hex) { $g[] = unicode_hex($this->glyphToChar[$glyphID][0]); }
2664
- else { $g[] = $glyphID; }
2665
- }
2666
- }
2667
- }
2668
- return $g;
2669
- }
2670
-
2671
- //////////////////////////////////////////////////////////////////////////////////
2672
- function _getClasses($offset) {
2673
- $this->seek($offset);
2674
- $ClassFormat = $this->read_ushort();
2675
- $GlyphByClass = array();
2676
- if ($ClassFormat == 1) {
2677
- $StartGlyph = $this->read_ushort();
2678
- $GlyphCount = $this->read_ushort();
2679
- for ($i=0;$i<$GlyphCount;$i++) {
2680
- $startGlyphID = $StartGlyph + $i;
2681
- $endGlyphID = $StartGlyph + $i;
2682
- $class = $this->read_ushort();
2683
- for($g=$startGlyphID;$g<=$endGlyphID;$g++) {
2684
- if ($this->glyphToChar[$g][0]) {
2685
- $GlyphByClass[$class][] = unicode_hex($this->glyphToChar[$g][0]);
2686
- }
2687
- }
2688
- }
2689
- }
2690
- else if ($ClassFormat == 2) {
2691
- $tableCount = $this->read_ushort();
2692
- for ($i=0;$i<$tableCount;$i++) {
2693
- $startGlyphID = $this->read_ushort();
2694
- $endGlyphID = $this->read_ushort();
2695
- $class = $this->read_ushort();
2696
- for($g=$startGlyphID;$g<=$endGlyphID;$g++) {
2697
- if ($this->glyphToChar[$g][0]) {
2698
- $GlyphByClass[$class][] = unicode_hex($this->glyphToChar[$g][0]);
2699
- }
2700
- }
2701
- }
2702
- }
2703
- $gbc = array();
2704
- foreach($GlyphByClass AS $class=>$garr) { $gbc[$class] = implode('|',$garr); }
2705
- return $gbc;
2706
- }
2707
- //////////////////////////////////////////////////////////////////////////////////
2708
- //////////////////////////////////////////////////////////////////////////////////
2709
- //////////////////////////////////////////////////////////////////////////////////
2710
- //////////////////////////////////////////////////////////////////////////////////
2711
- //////////////////////////////////////////////////////////////////////////////////
2712
- function _getGPOStables() {
2713
- ///////////////////////////////////
2714
- // GPOS - Glyph Positioning
2715
- ///////////////////////////////////
2716
- if (isset($this->tables["GPOS"])) {
2717
- $this->mpdf->WriteHTML('<h1>GPOS Tables</h1>');
2718
- $ffeats = array();
2719
- $gpos_offset = $this->seek_table("GPOS");
2720
- $this->skip(4);
2721
- $ScriptList_offset = $gpos_offset + $this->read_ushort();
2722
- $FeatureList_offset = $gpos_offset + $this->read_ushort();
2723
- $LookupList_offset = $gpos_offset + $this->read_ushort();
2724
-
2725
- // ScriptList
2726
- $this->seek($ScriptList_offset );
2727
- $ScriptCount = $this->read_ushort();
2728
- for ($i=0;$i<$ScriptCount;$i++) {
2729
- $ScriptTag = $this->read_tag(); // = "beng", "deva" etc.
2730
- $ScriptTableOffset = $this->read_ushort();
2731
- $ffeats[$ScriptTag] = $ScriptList_offset + $ScriptTableOffset;
2732
- }
2733
-
2734
- // Script Table
2735
- foreach($ffeats AS $t=>$o) {
2736
- $ls = array();
2737
- $this->seek($o);
2738
- $DefLangSys_offset = $this->read_ushort();
2739
- if ($DefLangSys_offset > 0) {
2740
- $ls['DFLT'] = $DefLangSys_offset + $o;
2741
- }
2742
- $LangSysCount = $this->read_ushort();
2743
- for ($i=0;$i<$LangSysCount;$i++) {
2744
- $LangTag = $this->read_tag(); // =
2745
- $LangTableOffset = $this->read_ushort();
2746
- $ls[$LangTag] = $o + $LangTableOffset;
2747
- }
2748
- $ffeats[$t] = $ls;
2749
- }
2750
-
2751
-
2752
- // Get FeatureIndexList
2753
- // LangSys Table - from first listed langsys
2754
- foreach($ffeats AS $st=>$scripts) {
2755
- foreach($scripts AS $t=>$o) {
2756
- $FeatureIndex = array();
2757
- $langsystable_offset = $o;
2758
- $this->seek($langsystable_offset);
2759
- $LookUpOrder = $this->read_ushort(); //==NULL
2760
- $ReqFeatureIndex = $this->read_ushort();
2761
- if ($ReqFeatureIndex != 0xFFFF) { $FeatureIndex[] = $ReqFeatureIndex ; }
2762
- $FeatureCount = $this->read_ushort();
2763
- for ($i=0;$i<$FeatureCount;$i++) {
2764
- $FeatureIndex[] = $this->read_ushort(); // = index of feature
2765
- }
2766
- $ffeats[$st][$t] = $FeatureIndex;
2767
- }
2768
- }
2769
- //print_r($ffeats); exit;
2770
-
2771
-
2772
- // Feauture List => LookupListIndex es
2773
- $this->seek($FeatureList_offset );
2774
- $FeatureCount = $this->read_ushort();
2775
- $Feature = array();
2776
- for ($i=0;$i<$FeatureCount;$i++) {
2777
- $Feature[$i] = array('tag' => $this->read_tag() );
2778
- $Feature[$i]['offset'] = $FeatureList_offset + $this->read_ushort();
2779
- }
2780
- for ($i=0;$i<$FeatureCount;$i++) {
2781
- $this->seek($Feature[$i]['offset']);
2782
- $this->read_ushort(); // null
2783
- $Feature[$i]['LookupCount'] = $Lookupcount = $this->read_ushort();
2784
- $Feature[$i]['LookupListIndex'] = array();
2785
- for ($c=0;$c<$Lookupcount;$c++) {
2786
- $Feature[$i]['LookupListIndex'][] = $this->read_ushort();
2787
- }
2788
- }
2789
-
2790
-
2791
- foreach($ffeats AS $st=>$scripts) {
2792
- foreach($scripts AS $t=>$o) {
2793
- $FeatureIndex = $ffeats[$st][$t];
2794
- foreach($FeatureIndex AS $k=>$fi) {
2795
- $ffeats[$st][$t][$k] = $Feature[$fi];
2796
- }
2797
- }
2798
- }
2799
- //print_r($ffeats); exit;
2800
- //=====================================================================================
2801
- $gpos = array();
2802
- $GPOSScriptLang = array();
2803
- foreach($ffeats AS $st=>$scripts) {
2804
- foreach($scripts AS $t=>$langsys) {
2805
- $lg = array();
2806
- foreach($langsys AS $ft) {
2807
- $lg[$ft['LookupListIndex'][0]] = $ft;
2808
- }
2809
- // list of Lookups in order they need to be run i.e. order listed in Lookup table
2810
- ksort($lg);
2811
- foreach($lg AS $ft) {
2812
- $gpos[$st][$t][$ft['tag']] = $ft['LookupListIndex'];
2813
- }
2814
- if (!isset($GPOSScriptLang[$st])) { $GPOSScriptLang[$st] = ''; }
2815
- $GPOSScriptLang[$st] .= $t.' ';
2816
- }
2817
- }
2818
- if ($this->mode == 'summary') {
2819
- $this->mpdf->WriteHTML('<h3>GPOS Scripts &amp; Languages</h3>');
2820
- $html = '';
2821
- if (count($gpos)) {
2822
- foreach ($gpos AS $st=>$g) {
2823
- $html .= '<h5>'.$st.'</h5>';
2824
- foreach ($g AS $l=>$t) {
2825
- $html .= '<div><a href="font_dump_OTL.php?script='.$st.'&lang='.$l.'">'.$l.'</a></b>: ';
2826
- foreach ($t AS $tag=>$o) {
2827
- $html .= $tag.' ';
2828
- }
2829
- $html .= '</div>';
2830
- }
2831
- }
2832
- }
2833
- else {
2834
- $html .= '<div>No entries in GPOS table.</div>';
2835
- }
2836
- $this->mpdf->WriteHTML($html);
2837
- $this->mpdf->WriteHTML('</div>');
2838
- return 0;
2839
- }
2840
-
2841
-
2842
-
2843
- //=====================================================================================
2844
- // Get metadata and offsets for whole Lookup List table
2845
- $this->seek($LookupList_offset );
2846
- $LookupCount = $this->read_ushort();
2847
- $Lookup = array();
2848
- $Offsets = array();
2849
- $SubtableCount = array();
2850
- for ($i=0;$i<$LookupCount;$i++) {
2851
- $Offsets[$i] = $LookupList_offset + $this->read_ushort();
2852
- }
2853
- for ($i=0;$i<$LookupCount;$i++) {
2854
- $this->seek($Offsets[$i]);
2855
- $Lookup[$i]['Type'] = $this->read_ushort();
2856
- $Lookup[$i]['Flag'] = $flag = $this->read_ushort();
2857
- $Lookup[$i]['SubtableCount'] = $SubtableCount[$i] = $this->read_ushort();
2858
- for ($c=0;$c<$SubtableCount[$i] ;$c++) {
2859
- $Lookup[$i]['Subtables'][$c] = $Offsets[$i] + $this->read_ushort();
2860
-
2861
- }
2862
- // MarkFilteringSet = Index (base 0) into GDEF mark glyph sets structure
2863
- if (($flag & 0x0010) == 0x0010) {
2864
- $Lookup[$i]['MarkFilteringSet'] = $this->read_ushort();
2865
- }
2866
- // else { $Lookup[$i]['MarkFilteringSet'] = ''; }
2867
-
2868
- // Lookup Type 9: Extension
2869
- if ($Lookup[$i]['Type'] == 9) {
2870
- // Overwrites new offset (32-bit) for each subtable, and a new lookup Type
2871
- for ($c=0;$c<$SubtableCount[$i] ;$c++) {
2872
- $this->seek($Lookup[$i]['Subtables'][$c]);
2873
- $ExtensionPosFormat = $this->read_ushort();
2874
- $type = $this->read_ushort();
2875
- $Lookup[$i]['Subtables'][$c] = $Lookup[$i]['Subtables'][$c] + $this->read_ulong();
2876
- }
2877
- $Lookup[$i]['Type'] = $type;
2878
- }
2879
-
2880
- }
2881
-
2882
-
2883
- //=====================================================================================
2884
-
2885
- $st = $this->mpdf->OTLscript;
2886
- $t = $this->mpdf->OTLlang;
2887
- $langsys = $gpos[$st][$t];
2888
-
2889
-
2890
- $lul = array(); // array of LookupListIndexes
2891
- $tags = array(); // corresponding array of feature tags e.g. 'ccmp'
2892
- if (count($langsys)) {
2893
- foreach($langsys AS $tag=>$ft) {
2894
- foreach($ft AS $ll) {
2895
- $lul[$ll] = $tag;
2896
- }
2897
- }
2898
- }
2899
- ksort($lul); // Order the Lookups in the order they are in the GUSB table, regardless of Feature order
2900
- $this->_getGPOSarray($Lookup, $lul, $st);
2901
- //print_r($lul); exit;
2902
-
2903
-
2904
- return array($GPOSScriptLang, $gpos, $Lookup);
2905
-
2906
- } // end if GPOS
2907
- }
2908
-
2909
- //////////////////////////////////////////////////////////////////////////////////
2910
-
2911
- //=====================================================================================
2912
- //=====================================================================================
2913
- //=====================================================================================
2914
- /////////////////////////////////////////////////////////////////////////////////////////
2915
- // GPOS functions
2916
- function _getGPOSarray(&$Lookup, $lul, $scripttag, $level=1, $lcoverage='', $exB='', $exL='') {
2917
- // Process (3) LookupList for specific Script-LangSys
2918
- $html = '';
2919
- if ($level==1) { $html .= '<bookmark level="0" content="GPOS features">'; }
2920
- foreach($lul AS $luli=>$tag) {
2921
- $html .= '<div class="level'.$level.'">';
2922
- $html .= '<h5 class="level'.$level.'">';
2923
- if ($level==1) { $html .= '<bookmark level="1" content="'.$tag.' [#'.$luli.']">'; }
2924
- $html .= 'Lookup #'.$luli.' [tag: <span style="color:#000066;">'.$tag.'</span>]</h5>';
2925
- $ignore = $this->_getGSUBignoreString($Lookup[$luli]['Flag'], $Lookup[$luli]['MarkFilteringSet']);
2926
- if ($ignore) { $html .= '<div class="ignore">Ignoring: '.$ignore.'</div> '; }
2927
-
2928
- $Type = $Lookup[$luli]['Type'];
2929
- $Flag = $Lookup[$luli]['Flag'];
2930
- if (($Flag & 0x0001) == 1) { $dir = 'RTL'; }
2931
- else { $dir = 'LTR'; }
2932
-
2933
- for ($c=0;$c<$Lookup[$luli]['SubtableCount'] ;$c++) {
2934
- $html .= '<div class="subtable">Subtable #'.$c;
2935
- if ($level==1) { $html .= '<bookmark level="2" content="Subtable #'.$c.'">'; }
2936
- $html .= '</div>';
2937
-
2938
- // Lets start
2939
- $subtable_offset = $Lookup[$luli]['Subtables'][$c];
2940
- $this->seek($subtable_offset);
2941
- $PosFormat = $this->read_ushort();
2942
-
2943
- ////////////////////////////////////////////////////////////////////////////////
2944
- // LookupType 1: Single adjustment Adjust position of a single glyph (e.g. SmallCaps/Sups/Subs)
2945
- ////////////////////////////////////////////////////////////////////////////////
2946
- if ($Lookup[$luli]['Type'] == 1) {
2947
- $html .= '<div class="lookuptype">LookupType 1: Single adjustment [Format '.$PosFormat.']</div>';
2948
- //===========
2949
- // Format 1:
2950
- //===========
2951
- if ($PosFormat==1) {
2952
- $Coverage = $subtable_offset + $this->read_ushort();
2953
- $ValueFormat = $this->read_ushort();
2954
- $Value = $this->_getValueRecord($ValueFormat);
2955
-
2956
- $this->seek($Coverage);
2957
- $glyphs = $this->_getCoverage(); // Array of Hex Glyphs
2958
- for($g=0;$g<count($glyphs);$g++) {
2959
- if ($level==2 && strpos($lcoverage, $glyphs[$g])===false) { continue; }
2960
-
2961
- $html .= '<div class="substitution">';
2962
- $html .= '<span class="unicode">'.$this->formatUni($glyphs[$g]).'&nbsp;</span> ';
2963
- if ($level==2 && $exB) { $html .= $exB; }
2964
- $html .= '<span class="unchanged">&nbsp;'.$this->formatEntity($glyphs[$g]).'</span>';
2965
- if ($level==2 && $exL) { $html .= $exL; }
2966
- $html .= '&nbsp; &raquo; &raquo; &nbsp;';
2967
- if ($level==2 && $exB) { $html .= $exB; }
2968
- $html .= '<span class="changed" style="font-feature-settings:\''.$tag.'\' 1;">&nbsp;'.$this->formatEntity($glyphs[$g]).'</span>';
2969
- if ($level==2 && $exL) { $html .= $exL; }
2970
- $html .= ' <span class="unicode">';
2971
- if ($Value['XPlacement']) { $html .= ' Xpl: '.$Value['XPlacement'].';'; }
2972
- if ($Value['YPlacement']) { $html .= ' YPl: '.$Value['YPlacement'].';'; }
2973
- if ($Value['XAdvance']) { $html .= ' Xadv: '.$Value['XAdvance']; }
2974
- $html .= '</span>';
2975
- $html .= '</div>';
2976
- }
2977
-
2978
- }
2979
- //===========
2980
- // Format 2:
2981
- //===========
2982
- else if ($PosFormat==2) {
2983
- $Coverage = $subtable_offset + $this->read_ushort();
2984
- $ValueFormat = $this->read_ushort();
2985
- $ValueCount = $this->read_ushort();
2986
- $Values = array();
2987
- for($v=0;$v<$ValueCount;$v++) {
2988
- $Values[] = $this->_getValueRecord($ValueFormat);
2989
- }
2990
-
2991
- $this->seek($Coverage);
2992
- $glyphs = $this->_getCoverage(); // Array of Hex Glyphs
2993
-
2994
- for($g=0;$g<count($glyphs);$g++) {
2995
- if ($level==2 && strpos($lcoverage, $glyphs[$g])===false) { continue; }
2996
- $Value = $Values[$g];
2997
-
2998
- $html .= '<div class="substitution">';
2999
- $html .= '<span class="unicode">'.$this->formatUni($glyphs[$g]).'&nbsp;</span> ';
3000
- if ($level==2 && $exB) { $html .= $exB; }
3001
- $html .= '<span class="unchanged">&nbsp;'.$this->formatEntity($glyphs[$g]).'</span>';
3002
- if ($level==2 && $exL) { $html .= $exL; }
3003
- $html .= '&nbsp; &raquo; &raquo; &nbsp;';
3004
- if ($level==2 && $exB) { $html .= $exB; }
3005
- $html .= '<span class="changed" style="font-feature-settings:\''.$tag.'\' 1;">&nbsp;'.$this->formatEntity($glyphs[$g]).'</span>';
3006
- if ($level==2 && $exL) { $html .= $exL; }
3007
- $html .= ' <span class="unicode">';
3008
- if ($Value['XPlacement']) { $html .= ' Xpl: '.$Value['XPlacement'].';'; }
3009
- if ($Value['YPlacement']) { $html .= ' YPl: '.$Value['YPlacement'].';'; }
3010
- if ($Value['XAdvance']) { $html .= ' Xadv: '.$Value['XAdvance']; }
3011
- $html .= '</span>';
3012
- $html .= '</div>';
3013
- }
3014
- }
3015
-
3016
-
3017
-
3018
- }
3019
- ////////////////////////////////////////////////////////////////////////////////
3020
- // LookupType 2: Pair adjustment Adjust position of a pair of glyphs (Kerning)
3021
- ////////////////////////////////////////////////////////////////////////////////
3022
- else if ($Lookup[$luli]['Type'] == 2) {
3023
- $html .= '<div class="lookuptype">LookupType 2: Pair adjustment e.g. Kerning [Format '.$PosFormat.']</div>';
3024
- $Coverage = $subtable_offset + $this->read_ushort();
3025
- $ValueFormat1 = $this->read_ushort();
3026
- $ValueFormat2 = $this->read_ushort();
3027
- //===========
3028
- // Format 1:
3029
- //===========
3030
- if ($PosFormat==1) {
3031
- $PairSetCount = $this->read_ushort();
3032
- $PairSetOffset = array();
3033
- for($p=0;$p<$PairSetCount;$p++) {
3034
- $PairSetOffset[] = $subtable_offset + $this->read_ushort();
3035
- }
3036
- $this->seek($Coverage);
3037
- $glyphs = $this->_getCoverage(); // Array of Hex Glyphs
3038
- for($p=0;$p<$PairSetCount;$p++) {
3039
- if ($level==2 && strpos($lcoverage, $glyphs[$p])===false) { continue; }
3040
- $this->seek($PairSetOffset[$p]);
3041
- // First Glyph = $glyphs[$p]
3042
-
3043
- // Takes too long e.g. Calibri font - just list kerning pairs with this:
3044
- $html .= '<div class="glyphs">';
3045
- $html .= '<span class="unchanged">&nbsp;'.$this->formatEntity($glyphs[$p]).' </span>';
3046
-
3047
- //PairSet table
3048
- $PairValueCount = $this->read_ushort();
3049
- for($pv=0;$pv<$PairValueCount;$pv++) {
3050
- //PairValueRecord
3051
- $gid = $this->read_ushort();
3052
- $SecondGlyph = unicode_hex($this->glyphToChar[$gid][0]);
3053
- $Value1 = $this->_getValueRecord($ValueFormat1);
3054
- $Value2 = $this->_getValueRecord($ValueFormat2);
3055
-
3056
- // If RTL pairs, GPOS declares a XPlacement e.g. -180 for an XAdvance of -180 to take
3057
- // account of direction. mPDF does not need the XPlacement adjustment
3058
- if ($dir=='RTL' && $Value1['XPlacement']) {
3059
- $Value1['XPlacement'] -= $Value1['XAdvance'];
3060
- }
3061
-
3062
- if($ValueFormat2) {
3063
- // If RTL pairs, GPOS declares a XPlacement e.g. -180 for an XAdvance of -180 to take
3064
- // account of direction. mPDF does not need the XPlacement adjustment
3065
- if ($dir=='RTL' && $Value2['XPlacement'] && $Value2['XAdvance']) {
3066
- $Value2['XPlacement'] -= $Value2['XAdvance'];
3067
- }
3068
- }
3069
-
3070
- $html .= ' '.$this->formatEntity($SecondGlyph).' ';
3071
-
3072
- /*
3073
- $html .= '<div class="substitution">';
3074
- $html .= '<span class="unicode">'.$this->formatUni($glyphs[$p]).'&nbsp;</span> ';
3075
- if ($level==2 && $exB) { $html .= $exB; }
3076
- $html .= '<span class="unchanged">&nbsp;'.$this->formatEntity($glyphs[$p]).$this->formatEntity($SecondGlyph).'</span>';
3077
- if ($level==2 && $exL) { $html .= $exL; }
3078
- $html .= '&nbsp; &raquo; &raquo; &nbsp;';
3079
- if ($level==2 && $exB) { $html .= $exB; }
3080
- $html .= '<span class="changed" style="font-feature-settings:\''.$tag.'\' 1;">&nbsp;'.$this->formatEntity($glyphs[$p]).$this->formatEntity($SecondGlyph).'</span>';
3081
- if ($level==2 && $exL) { $html .= $exL; }
3082
- $html .= ' <span class="unicode">';
3083
- if ($Value1['XPlacement']) { $html .= ' Xpl[1]: '.$Value1['XPlacement'].';'; }
3084
- if ($Value1['YPlacement']) { $html .= ' YPl[1]: '.$Value1['YPlacement'].';'; }
3085
- if ($Value1['XAdvance']) { $html .= ' Xadv[1]: '.$Value1['XAdvance']; }
3086
- if ($Value2['XPlacement']) { $html .= ' Xpl[2]: '.$Value2['XPlacement'].';'; }
3087
- if ($Value2['YPlacement']) { $html .= ' YPl[2]: '.$Value2['YPlacement'].';'; }
3088
- if ($Value2['XAdvance']) { $html .= ' Xadv[2]: '.$Value2['XAdvance']; }
3089
- $html .= '</span>';
3090
- $html .= '</div>';
3091
- */
3092
-
3093
- }
3094
- $html .= '</div>';
3095
- }
3096
- }
3097
- //===========
3098
- // Format 2:
3099
- //===========
3100
- else if ($PosFormat==2) {
3101
- $ClassDef1 = $subtable_offset + $this->read_ushort();
3102
- $ClassDef2 = $subtable_offset + $this->read_ushort();
3103
- $Class1Count = $this->read_ushort();
3104
- $Class2Count = $this->read_ushort();
3105
-
3106
- $sizeOfPair = ( 2*$this->count_bits($ValueFormat1) ) + ( 2*$this->count_bits($ValueFormat2) );
3107
- $sizeOfValueRecords = $Class1Count * $Class2Count * $sizeOfPair;
3108
-
3109
-
3110
- // NB Class1Count includes Class 0 even though it is not defined by $ClassDef1
3111
- // i.e. Class1Count = 5; Class1 will contain array(indices 1-4);
3112
- $Class1 = $this->_getClassDefinitionTable($ClassDef1);
3113
- $Class2 = $this->_getClassDefinitionTable($ClassDef2);
3114
-
3115
- $this->seek($subtable_offset + 16);
3116
-
3117
- for($i=0;$i<$Class1Count;$i++) {
3118
- for($j=0;$j<$Class2Count;$j++) {
3119
- $Value1 = $this->_getValueRecord($ValueFormat1);
3120
- $Value2 = $this->_getValueRecord($ValueFormat2);
3121
-
3122
- // If RTL pairs, GPOS declares a XPlacement e.g. -180 for an XAdvance of -180
3123
- // of direction. mPDF does not need the XPlacement adjustment
3124
- if ($dir=='RTL' && $Value1['XPlacement'] && $Value1['XAdvance']) {
3125
- $Value1['XPlacement'] -= $Value1['XAdvance'];
3126
- }
3127
- if($ValueFormat2) {
3128
- if ($dir=='RTL' && $Value2['XPlacement'] && $Value2['XAdvance']) {
3129
- $Value2['XPlacement'] -= $Value2['XAdvance'];
3130
- }
3131
- }
3132
-
3133
-
3134
- for($c1=0;$c1<count($Class1[$i]);$c1++) {
3135
-
3136
- $FirstGlyph = $Class1[$i][$c1];
3137
- if ($level==2 && strpos($lcoverage, $FirstGlyph)===false) {
3138
- continue;
3139
- }
3140
-
3141
-
3142
- for($c2=0;$c2<count($Class2[$j]);$c2++) {
3143
- $SecondGlyph = $Class2[$j][$c2];
3144
-
3145
-
3146
- if (!$Value1['XPlacement'] && !$Value1['YPlacement'] && !$Value1['XAdvance'] && !$Value2['XPlacement'] && !$Value2['YPlacement'] && !$Value2['XAdvance']) { continue; }
3147
-
3148
-
3149
- $html .= '<div class="substitution">';
3150
- $html .= '<span class="unicode">'.$this->formatUni($FirstGlyph).'&nbsp;</span> ';
3151
- if ($level==2 && $exB) { $html .= $exB; }
3152
- $html .= '<span class="unchanged">&nbsp;'.$this->formatEntity($FirstGlyph).$this->formatEntity($SecondGlyph).'</span>';
3153
- if ($level==2 && $exL) { $html .= $exL; }
3154
- $html .= '&nbsp; &raquo; &raquo; &nbsp;';
3155
- if ($level==2 && $exB) { $html .= $exB; }
3156
- $html .= '<span class="changed" style="font-feature-settings:\''.$tag.'\' 1;">&nbsp;'.$this->formatEntity($FirstGlyph).$this->formatEntity($SecondGlyph).'</span>';
3157
- if ($level==2 && $exL) { $html .= $exL; }
3158
- $html .= ' <span class="unicode">';
3159
- if ($Value1['XPlacement']) { $html .= ' Xpl[1]: '.$Value1['XPlacement'].';'; }
3160
- if ($Value1['YPlacement']) { $html .= ' YPl[1]: '.$Value1['YPlacement'].';'; }
3161
- if ($Value1['XAdvance']) { $html .= ' Xadv[1]: '.$Value1['XAdvance']; }
3162
- if ($Value2['XPlacement']) { $html .= ' Xpl[2]: '.$Value2['XPlacement'].';'; }
3163
- if ($Value2['YPlacement']) { $html .= ' YPl[2]: '.$Value2['YPlacement'].';'; }
3164
- if ($Value2['XAdvance']) { $html .= ' Xadv[2]: '.$Value2['XAdvance']; }
3165
- $html .= '</span>';
3166
- $html .= '</div>';
3167
-
3168
- }
3169
- }
3170
- }
3171
-
3172
- }
3173
- }
3174
- }
3175
- ////////////////////////////////////////////////////////////////////////////////
3176
- // LookupType 3: Cursive attachment Attach cursive glyphs
3177
- ////////////////////////////////////////////////////////////////////////////////
3178
- else if ($Lookup[$luli]['Type'] == 3) {
3179
- $html .= '<div class="lookuptype">LookupType 3: Cursive attachment </div>';
3180
- $Coverage = $subtable_offset + $this->read_ushort();
3181
- $EntryExitCount = $this->read_ushort();
3182
- $EntryAnchors = array();
3183
- $ExitAnchors = array();
3184
- for($i=0;$i<$EntryExitCount;$i++) {
3185
- $EntryAnchors[$i] = $this->read_ushort();
3186
- $ExitAnchors[$i] = $this->read_ushort();
3187
- }
3188
-
3189
- $this->seek($Coverage);
3190
- $Glyphs = $this->_getCoverage();
3191
- for($i=0;$i<$EntryExitCount;$i++) {
3192
- // Need default XAdvance for glyph
3193
- $pdfWidth = $this->mpdf->_getCharWidth($this->mpdf->fonts[$this->fontkey]['cw'], hexdec($Glyphs[$i]));
3194
- $EntryAnchor = $EntryAnchors[$i] ;
3195
- $ExitAnchor = $ExitAnchors[$i] ;
3196
- $html .= '<div class="glyphs">';
3197
- $html .= '<span class="unchanged">'.$this->formatEntity($Glyphs[$i]).' </span> ';
3198
- $html .= '<span class="unicode"> '.$this->formatUni($Glyphs[$i]).' => ';
3199
-
3200
- if ($EntryAnchor != 0) {
3201
- $EntryAnchor += $subtable_offset;
3202
- list($x,$y) = $this->_getAnchorTable($EntryAnchor);
3203
- if ($dir == 'RTL') {
3204
- if (round($pdfWidth) == round($x * 1000/ $this->mpdf->fonts[$this->fontkey]['desc']['unitsPerEm']) ) {
3205
- $x = 0;
3206
- }
3207
- else { $x = $x - ($pdfWidth * $this->mpdf->fonts[$this->fontkey]['desc']['unitsPerEm']/1000); }
3208
- }
3209
- $html .= " Entry X: ".$x." Y: ".$y."; ";
3210
- }
3211
- if ($ExitAnchor != 0) {
3212
- $ExitAnchor += $subtable_offset;
3213
- list($x,$y) = $this->_getAnchorTable($ExitAnchor);
3214
- if ($dir == 'LTR') {
3215
- if (round($pdfWidth) == round($x * 1000/ $this->mpdf->fonts[$this->fontkey]['desc']['unitsPerEm']) ) {
3216
- $x = 0;
3217
- }
3218
- else { $x = $x - ($pdfWidth * $this->mpdf->fonts[$this->fontkey]['desc']['unitsPerEm']/1000); }
3219
- }
3220
- $html .= " Exit X: ".$x." Y: ".$y."; ";
3221
- }
3222
-
3223
-
3224
- $html .= '</span></div>';
3225
- }
3226
-
3227
- }
3228
- ////////////////////////////////////////////////////////////////////////////////
3229
- // LookupType 4: MarkToBase attachment Attach a combining mark to a base glyph
3230
- ////////////////////////////////////////////////////////////////////////////////
3231
- else if ($Lookup[$luli]['Type'] == 4) {
3232
- $html .= '<div class="lookuptype">LookupType 4: MarkToBase attachment </div>';
3233
- $MarkCoverage = $subtable_offset + $this->read_ushort();
3234
- $BaseCoverage = $subtable_offset + $this->read_ushort();
3235
-
3236
- $this->seek($MarkCoverage);
3237
- $MarkGlyphs = $this->_getCoverage();
3238
-
3239
- $this->seek($BaseCoverage);
3240
- $BaseGlyphs = $this->_getCoverage();
3241
-
3242
- $firstMark = '';
3243
- $html .= '<div class="glyphs">Marks: ';
3244
- for($i=0;$i<count($MarkGlyphs);$i++) {
3245
- if ($level==2 && strpos($lcoverage, $MarkGlyphs[$i])===false) { continue; }
3246
- else {
3247
- if (!$firstMark) { $firstMark = $MarkGlyphs[$i]; }
3248
- }
3249
- $html .= ' '.$this->formatEntity($MarkGlyphs[$i]).' ';
3250
- }
3251
- $html .= '</div>';
3252
- if (!$firstMark) { return; }
3253
-
3254
- $html .= '<div class="glyphs">Bases: ';
3255
- for($j=0;$j<count($BaseGlyphs);$j++) {
3256
- $html .= ' '.$this->formatEntity($BaseGlyphs[$j]).' ';
3257
- }
3258
- $html .= '</div>';
3259
-
3260
- // Example
3261
- $html .= '<div class="glyphs" style="font-feature-settings:\''.$tag.'\' 1;">Example(s): ';
3262
- for ($j=0;$j<min(count($BaseGlyphs),20);$j++) {
3263
- $html .= ' '.$this->formatEntity($BaseGlyphs[$j]).$this->formatEntity($firstMark,true).' &nbsp; ';
3264
- }
3265
- $html .= '</div>';
3266
-
3267
-
3268
- }
3269
- ////////////////////////////////////////////////////////////////////////////////
3270
- // LookupType 5: MarkToLigature attachment Attach a combining mark to a ligature
3271
- ////////////////////////////////////////////////////////////////////////////////
3272
- else if ($Lookup[$luli]['Type'] == 5) {
3273
- $html .= '<div class="lookuptype">LookupType 5: MarkToLigature attachment </div>';
3274
- $MarkCoverage = $subtable_offset + $this->read_ushort();
3275
- //$MarkCoverage is already set in $lcoverage 00065|00073 etc
3276
- $LigatureCoverage = $subtable_offset + $this->read_ushort();
3277
- $ClassCount = $this->read_ushort(); // Number of classes defined for marks = Number of mark glyphs in the MarkCoverage table
3278
- $MarkArray = $subtable_offset + $this->read_ushort(); // Offset to MarkArray table
3279
- $LigatureArray = $subtable_offset + $this->read_ushort(); // Offset to LigatureArray table
3280
-
3281
- $this->seek($MarkCoverage);
3282
- $MarkGlyphs = $this->_getCoverage();
3283
- $this->seek($LigatureCoverage);
3284
- $LigatureGlyphs = $this->_getCoverage();
3285
-
3286
- $firstMark = '';
3287
- $html .= '<div class="glyphs">Marks: <span class="unchanged">';
3288
- $MarkRecord = array();
3289
- for ($i=0;$i<count($MarkGlyphs);$i++) {
3290
- if ($level==2 && strpos($lcoverage, $MarkGlyphs[$i])===false) { continue; }
3291
- else {
3292
- if (!$firstMark) { $firstMark = $MarkGlyphs[$i]; }
3293
- }
3294
- // Get the relevant MarkRecord
3295
- $MarkRecord[$i] = $this->_getMarkRecord($MarkArray, $i);
3296
- //Mark Class is = $MarkRecord[$i]['Class']
3297
- $html .= ' '.$this->formatEntity($MarkGlyphs[$i]).' ';
3298
- }
3299
- $html .= '</span></div>';
3300
- if (!$firstMark) { return; }
3301
-
3302
- $this->seek($LigatureArray);
3303
- $LigatureCount = $this->read_ushort();
3304
- $LigatureAttach = array();
3305
- $html .= '<div class="glyphs">Ligatures: <span class="unchanged">';
3306
- for ($j=0;$j<count($LigatureGlyphs);$j++) {
3307
- // Get the relevant LigatureRecord
3308
- $LigatureAttach[$j] = $LigatureArray + $this->read_ushort();
3309
- $html .= ' '.$this->formatEntity($LigatureGlyphs[$j]).' ';
3310
- }
3311
- $html .= '</span></div>';
3312
-
3313
- /*
3314
- for ($i=0;$i<count($MarkGlyphs);$i++) {
3315
- $html .= '<div class="glyphs">';
3316
- $html .= '<span class="unchanged">'.$this->formatEntity($MarkGlyphs[$i]).'</span>';
3317
-
3318
- for ($j=0;$j<count($LigatureGlyphs);$j++) {
3319
- $this->seek($LigatureAttach[$j]);
3320
- $ComponentCount = $this->read_ushort();
3321
- $html .= '<span class="unchanged">'.$this->formatEntity($LigatureGlyphs[$j]).'</span>';
3322
- $offsets = array();
3323
- for ($comp=0;$comp<$ComponentCount;$comp++) {
3324
- // ComponentRecords
3325
- for ($class=0;$class<$ClassCount;$class++) {
3326
- $offset = $this->read_ushort();
3327
- if ($offset!= 0 && $class == $MarkRecord[$i]['Class']) {
3328
-
3329
- $html .= ' ['.$comp.'] ';
3330
-
3331
- }
3332
- }
3333
- }
3334
- }
3335
- $html .= '</span></div>';
3336
- }
3337
- */
3338
-
3339
-
3340
- }
3341
- ////////////////////////////////////////////////////////////////////////////////
3342
- // LookupType 6: MarkToMark attachment Attach a combining mark to another mark
3343
- ////////////////////////////////////////////////////////////////////////////////
3344
- else if ($Lookup[$luli]['Type'] == 6) {
3345
- $html .= '<div class="lookuptype">LookupType 6: MarkToMark attachment </div>';
3346
- $Mark1Coverage = $subtable_offset + $this->read_ushort(); // Combining Mark
3347
- //$Mark1Coverage is already set in $LuCoverage 0065|0073 etc
3348
- $Mark2Coverage = $subtable_offset + $this->read_ushort(); // Base Mark
3349
- $ClassCount = $this->read_ushort(); // Number of classes defined for marks = No. of Combining mark1 glyphs in the MarkCoverage table
3350
- $this->seek($Mark1Coverage);
3351
- $Mark1Glyphs = $this->_getCoverage();
3352
- $this->seek($Mark2Coverage);
3353
- $Mark2Glyphs = $this->_getCoverage();
3354
-
3355
-
3356
- $firstMark = '';
3357
- $html .= '<div class="glyphs">Marks: <span class="unchanged">';
3358
- for($i=0;$i<count($Mark1Glyphs);$i++) {
3359
- if ($level==2 && strpos($lcoverage, $Mark1Glyphs[$i])===false) { continue; }
3360
- else {
3361
- if (!$firstMark) { $firstMark = $Mark1Glyphs[$i]; }
3362
- }
3363
- $html .= ' '.$this->formatEntity($Mark1Glyphs[$i]).' ';
3364
- }
3365
- $html .= '</span></div>';
3366
-
3367
- if ($firstMark) {
3368
-
3369
- $html .= '<div class="glyphs">Bases: <span class="unchanged">';
3370
- for($j=0;$j<count($Mark2Glyphs);$j++) {
3371
- $html .= ' '.$this->formatEntity($Mark2Glyphs[$j]).' ';
3372
- }
3373
- $html .= '</span></div>';
3374
-
3375
- // Example
3376
- $html .= '<div class="glyphs" style="font-feature-settings:\''.$tag.'\' 1;">Example(s): <span class="changed">';
3377
- for ($j=0;$j<min(count($Mark2Glyphs),20);$j++) {
3378
- $html .= ' '.$this->formatEntity($Mark2Glyphs[$j]).$this->formatEntity($firstMark,true).' &nbsp; ';
3379
- }
3380
- $html .= '</span></div>';
3381
- }
3382
-
3383
- }
3384
- ////////////////////////////////////////////////////////////////////////////////
3385
- // LookupType 7: Context positioning Position one or more glyphs in context
3386
- ////////////////////////////////////////////////////////////////////////////////
3387
- else if ($Lookup[$luli]['Type'] == 7) {
3388
- $html .= '<div class="lookuptype">LookupType 7: Context positioning [Format '.$PosFormat.']</div>';
3389
- //===========
3390
- // Format 1:
3391
- //===========
3392
- if ($PosFormat==1) {
3393
- die("GPOS Lookup Type ".$Type." Format ".$PosFormat." not YET TESTED.");
3394
- }
3395
- //===========
3396
- // Format 2:
3397
- //===========
3398
- else if ($PosFormat==2) {
3399
- die("GPOS Lookup Type ".$Type." Format ".$PosFormat." not YET TESTED.");
3400
- }
3401
- //===========
3402
- // Format 3:
3403
- //===========
3404
- else if ($PosFormat==3) {
3405
- die("GPOS Lookup Type ".$Type." Format ".$PosFormat." not YET TESTED.");
3406
- }
3407
- else {
3408
- die("GPOS Lookup Type ".$Type.", Format ".$PosFormat." not supported.");
3409
- }
3410
- }
3411
- ////////////////////////////////////////////////////////////////////////////////
3412
- // LookupType 8: Chained Context positioning Position one or more glyphs in chained context
3413
- ////////////////////////////////////////////////////////////////////////////////
3414
- else if ($Lookup[$luli]['Type'] == 8) {
3415
- $html .= '<div class="lookuptype">LookupType 8: Chained Context positioning [Format '.$PosFormat.']</div>';
3416
- //===========
3417
- // Format 1:
3418
- //===========
3419
- if ($PosFormat==1) {
3420
- die("GPOS Lookup Type ".$Type." Format ".$PosFormat." not TESTED YET.");
3421
- }
3422
- //===========
3423
- // Format 2:
3424
- //===========
3425
- else if ($PosFormat==2) {
3426
- $html .= '<div>GPOS Lookup Type 8: Format 2 not yet supported in OTL dump</div>';
3427
- continue;
3428
- /* NB When developing - cf. GSUB 6.2 */
3429
- die("GPOS Lookup Type ".$Type." Format ".$PosFormat." not TESTED YET.");
3430
- }
3431
- //===========
3432
- // Format 3:
3433
- //===========
3434
- else if ($PosFormat==3) {
3435
- $BacktrackGlyphCount = $this->read_ushort();
3436
- $CoverageBacktrackOffset = array();
3437
- for ($b=0;$b<$BacktrackGlyphCount;$b++) {
3438
- $CoverageBacktrackOffset[] = $subtable_offset + $this->read_ushort(); // in glyph sequence order
3439
- }
3440
- $InputGlyphCount = $this->read_ushort();
3441
- $CoverageInputOffset = array();
3442
- for ($b=0;$b<$InputGlyphCount;$b++) {
3443
- $CoverageInputOffset[] = $subtable_offset + $this->read_ushort(); // in glyph sequence order
3444
- }
3445
- $LookaheadGlyphCount = $this->read_ushort();
3446
- $CoverageLookaheadOffset = array();
3447
- for ($b=0;$b<$LookaheadGlyphCount;$b++) {
3448
- $CoverageLookaheadOffset[] = $subtable_offset + $this->read_ushort(); // in glyph sequence order
3449
- }
3450
- $PosCount = $this->read_ushort();
3451
-
3452
- $PosLookupRecord = array();
3453
- for ($p=0;$p<$PosCount;$p++) {
3454
- // PosLookupRecord
3455
- $PosLookupRecord[$p]['SequenceIndex'] = $this->read_ushort();
3456
- $PosLookupRecord[$p]['LookupListIndex'] = $this->read_ushort();
3457
- }
3458
-
3459
- $backtrackGlyphs = array();
3460
- for ($b=0;$b<$BacktrackGlyphCount;$b++) {
3461
- $this->seek($CoverageBacktrackOffset[$b]);
3462
- $backtrackGlyphs[$b] = implode('|',$this->_getCoverage());
3463
- }
3464
- $inputGlyphs = array();
3465
- for ($b=0;$b<$InputGlyphCount;$b++) {
3466
- $this->seek($CoverageInputOffset[$b]);
3467
- $inputGlyphs[$b] = implode('|',$this->_getCoverage());
3468
- }
3469
- $lookaheadGlyphs = array();
3470
- for ($b=0;$b<$LookaheadGlyphCount;$b++) {
3471
- $this->seek($CoverageLookaheadOffset[$b]);
3472
- $lookaheadGlyphs[$b] = implode('|',$this->_getCoverage());
3473
- }
3474
-
3475
- $exampleB = array();
3476
- $exampleI = array();
3477
- $exampleL = array();
3478
- $html .= '<div class="context">CONTEXT: ';
3479
- for ($ff=count($backtrackGlyphs)-1;$ff>=0;$ff--) {
3480
- $html .= '<div>Backtrack #'.$ff.': <span class="unicode">'.$this->formatUniStr($backtrackGlyphs[$ff]).'</span></div>';
3481
- $exampleB[] = $this->formatEntityFirst($backtrackGlyphs[$ff]);
3482
- }
3483
- for ($ff=0;$ff<count($inputGlyphs);$ff++) {
3484
- $html .= '<div>Input #'.$ff.': <span class="unchanged">&nbsp;'.$this->formatEntityStr($inputGlyphs[$ff]).'&nbsp;</span></div>';
3485
- $exampleI[] = $this->formatEntityFirst($inputGlyphs[$ff]);
3486
- }
3487
- for ($ff=0;$ff<count($lookaheadGlyphs);$ff++) {
3488
- $html .= '<div>Lookahead #'.$ff.': <span class="unicode">'.$this->formatUniStr($lookaheadGlyphs[$ff]).'</span></div>';
3489
- $exampleL[] = $this->formatEntityFirst($lookaheadGlyphs[$ff]);
3490
- }
3491
- $html .= '</div>';
3492
-
3493
-
3494
- for ($p=0;$p<$PosCount;$p++) {
3495
- $lup = $PosLookupRecord[$p]['LookupListIndex'] ;
3496
- $seqIndex = $PosLookupRecord[$p]['SequenceIndex'] ;
3497
-
3498
- // GENERATE exampleB[n] exampleI[<seqIndex] .... exampleI[>seqIndex] exampleL[n]
3499
- $exB = '';
3500
- $exL = '';
3501
- if (count($exampleB)) { $exB .= '<span class="backtrack">'.implode('&#x200d;',$exampleB).'</span>'; }
3502
-
3503
- if ($seqIndex>0) {
3504
- $exB .= '<span class="inputother">';
3505
- for($ip=0;$ip<$seqIndex;$ip++) {
3506
- $exB .= $exampleI[$ip].'&#x200d;';
3507
- }
3508
- $exB .= '</span>';
3509
- }
3510
-
3511
- if (count($inputGlyphs)>($seqIndex+1)) {
3512
- $exL .= '<span class="inputother">';
3513
- for($ip=$seqIndex+1;$ip<count($inputGlyphs);$ip++) {
3514
- $exL .= '&#x200d;'.$exampleI[$ip];
3515
- }
3516
- $exL .= '</span>';
3517
- }
3518
-
3519
- if (count($exampleL)) { $exL .= '<span class="lookahead">'.implode('&#x200d;',$exampleL).'</span>'; }
3520
-
3521
- $html .= '<div class="sequenceIndex">Substitution Position: '.$seqIndex.'</div>';
3522
-
3523
- $lul2 = array($lup=>$tag);
3524
-
3525
- // Only apply if the (first) 'Replace' glyph from the
3526
- // Lookup list is in the [inputGlyphs] at ['SequenceIndex']
3527
- // Pass $inputGlyphs[$seqIndex] e.g. 00636|00645|00656
3528
- // to level 2 and only apply if first Replace glyph is in this list
3529
- $html .= $this->_getGPOSarray($Lookup, $lul2, $scripttag, 2, $inputGlyphs[$seqIndex], $exB, $exL);
3530
-
3531
- }
3532
- }
3533
- }
3534
-
3535
- }
3536
- $html .= '</div>';
3537
- }
3538
- if ($level ==1) { $this->mpdf->WriteHTML($html); }
3539
- else { return $html; }
3540
- //print_r($Lookup); exit;
3541
- }
3542
- //=====================================================================================
3543
- //=====================================================================================
3544
- // GPOS FUNCTIONS
3545
- //=====================================================================================
3546
-
3547
- function count_bits($n) {
3548
- for ($c=0; $n; $c++) {
3549
- $n &= $n - 1; // clear the least significant bit set
3550
- }
3551
- return $c;
3552
- }
3553
-
3554
- function _getValueRecord($ValueFormat) { // Common ValueRecord for GPOS
3555
- // Only returns 3 possible: $vra['XPlacement'] $vra['YPlacement'] $vra['XAdvance']
3556
- $vra = array();
3557
- // Horizontal adjustment for placement-in design units
3558
- if (($ValueFormat & 0x0001) == 0x0001) { $vra['XPlacement'] = $this->read_short(); }
3559
- // Vertical adjustment for placement-in design units
3560
- if (($ValueFormat & 0x0002) == 0x0002) { $vra['YPlacement'] = $this->read_short(); }
3561
- // Horizontal adjustment for advance-in design units (only used for horizontal writing)
3562
- if (($ValueFormat & 0x0004) == 0x0004) { $vra['XAdvance'] = $this->read_short(); }
3563
- // Vertical adjustment for advance-in design units (only used for vertical writing)
3564
- if (($ValueFormat & 0x0008) == 0x0008) { $this->read_short(); }
3565
- // Offset to Device table for horizontal placement-measured from beginning of PosTable (may be NULL)
3566
- if (($ValueFormat & 0x0010) == 0x0010) { $this->read_ushort(); }
3567
- // Offset to Device table for vertical placement-measured from beginning of PosTable (may be NULL)
3568
- if (($ValueFormat & 0x0020) == 0x0020) { $this->read_ushort(); }
3569
- // Offset to Device table for horizontal advance-measured from beginning of PosTable (may be NULL)
3570
- if (($ValueFormat & 0x0040) == 0x0040) { $this->read_ushort(); }
3571
- // Offset to Device table for vertical advance-measured from beginning of PosTable (may be NULL)
3572
- if (($ValueFormat & 0x0080) == 0x0080) { $this->read_ushort(); }
3573
- return $vra;
3574
- }
3575
-
3576
- function _getAnchorTable($offset=0) {
3577
- if ($offset) { $this->seek($offset); }
3578
- $AnchorFormat = $this->read_ushort();
3579
- $XCoordinate = $this->read_short();
3580
- $YCoordinate = $this->read_short();
3581
- // Format 2 specifies additional link to contour point; Format 3 additional Device table
3582
- return array($XCoordinate, $YCoordinate);
3583
- }
3584
-
3585
- function _getMarkRecord($offset, $MarkPos) {
3586
- $this->seek($offset);
3587
- $MarkCount = $this->read_ushort();
3588
- $this->skip($MarkPos*4);
3589
- $Class = $this->read_ushort();
3590
- $MarkAnchor = $offset + $this->read_ushort(); // = Offset to anchor table
3591
- list($x,$y) = $this->_getAnchorTable($MarkAnchor );
3592
- $MarkRecord = array('Class'=>$Class, 'AnchorX'=>$x, 'AnchorY'=>$y);
3593
- return $MarkRecord;
3594
- }
3595
-
3596
-
3597
- //////////////////////////////////////////////////////////////////////////////////
3598
- // Recursively get composite glyph data
3599
- function getGlyphData($originalGlyphIdx, &$maxdepth, &$depth, &$points, &$contours) {
3600
- $depth++;
3601
- $maxdepth = max($maxdepth, $depth);
3602
- if (count($this->glyphdata[$originalGlyphIdx]['compGlyphs'])) {
3603
- foreach($this->glyphdata[$originalGlyphIdx]['compGlyphs'] AS $glyphIdx) {
3604
- $this->getGlyphData($glyphIdx, $maxdepth, $depth, $points, $contours);
3605
- }
3606
- }
3607
- else if (($this->glyphdata[$originalGlyphIdx]['nContours'] > 0) && $depth > 0) { // simple
3608
- $contours += $this->glyphdata[$originalGlyphIdx]['nContours'];
3609
- $points += $this->glyphdata[$originalGlyphIdx]['nPoints'];
3610
- }
3611
- $depth--;
3612
- }
3613
-
3614
-
3615
- //////////////////////////////////////////////////////////////////////////////////
3616
- // Recursively get composite glyphs
3617
- function getGlyphs($originalGlyphIdx, &$start, &$glyphSet, &$subsetglyphs) {
3618
- $glyphPos = $this->glyphPos[$originalGlyphIdx];
3619
- $glyphLen = $this->glyphPos[$originalGlyphIdx + 1] - $glyphPos;
3620
- if (!$glyphLen) {
3621
- return;
3622
- }
3623
- $this->seek($start + $glyphPos);
3624
- $numberOfContours = $this->read_short();
3625
- if ($numberOfContours < 0) {
3626
- $this->skip(8);
3627
- $flags = GF_MORE;
3628
- while ($flags & GF_MORE) {
3629
- $flags = $this->read_ushort();
3630
- $glyphIdx = $this->read_ushort();
3631
- if (!isset($glyphSet[$glyphIdx])) {
3632
- $glyphSet[$glyphIdx] = count($subsetglyphs); // old glyphID to new glyphID
3633
- $subsetglyphs[$glyphIdx] = true;
3634
- }
3635
- $savepos = ftell($this->fh);
3636
- $this->getGlyphs($glyphIdx, $start, $glyphSet, $subsetglyphs);
3637
- $this->seek($savepos);
3638
- if ($flags & GF_WORDS)
3639
- $this->skip(4);
3640
- else
3641
- $this->skip(2);
3642
- if ($flags & GF_SCALE)
3643
- $this->skip(2);
3644
- else if ($flags & GF_XYSCALE)
3645
- $this->skip(4);
3646
- else if ($flags & GF_TWOBYTWO)
3647
- $this->skip(8);
3648
- }
3649
- }
3650
- }
3651
-
3652
- //////////////////////////////////////////////////////////////////////////////////
3653
-
3654
- function getHMTX($numberOfHMetrics, $numGlyphs, &$glyphToChar, $scale) {
3655
- $start = $this->seek_table("hmtx");
3656
- $aw = 0;
3657
- $this->charWidths = str_pad('', 256*256*2, "\x00");
3658
- if ($this->maxUniChar > 65536) { $this->charWidths .= str_pad('', 256*256*2, "\x00"); } // Plane 1 SMP
3659
- if ($this->maxUniChar > 131072) { $this->charWidths .= str_pad('', 256*256*2, "\x00"); } // Plane 2 SMP
3660
- $nCharWidths = 0;
3661
- if (($numberOfHMetrics*4) < $this->maxStrLenRead) {
3662
- $data = $this->get_chunk($start,($numberOfHMetrics*4));
3663
- $arr = unpack("n*", $data);
3664
- }
3665
- else { $this->seek($start); }
3666
- for( $glyph=0; $glyph<$numberOfHMetrics; $glyph++) {
3667
- if (($numberOfHMetrics*4) < $this->maxStrLenRead) {
3668
- $aw = $arr[($glyph*2)+1];
3669
- }
3670
- else {
3671
- $aw = $this->read_ushort();
3672
- $lsb = $this->read_ushort();
3673
- }
3674
- if (isset($glyphToChar[$glyph]) || $glyph == 0) {
3675
-
3676
- if ($aw >= (1 << 15) ) { $aw = 0; } // 1.03 Some (arabic) fonts have -ve values for width
3677
- // although should be unsigned value - comes out as e.g. 65108 (intended -50)
3678
- if ($glyph == 0) {
3679
- $this->defaultWidth = $scale*$aw;
3680
- continue;
3681
- }
3682
- foreach($glyphToChar[$glyph] AS $char) {
3683
- //$this->charWidths[$char] = intval(round($scale*$aw));
3684
- if ($char != 0 && $char != 65535) {
3685
- $w = intval(round($scale*$aw));
3686
- if ($w == 0) { $w = 65535; }
3687
- if ($char < 196608) {
3688
- $this->charWidths[$char*2] = chr($w >> 8);
3689
- $this->charWidths[$char*2 + 1] = chr($w & 0xFF);
3690
- $nCharWidths++;
3691
- }
3692
- }
3693
- }
3694
- }
3695
- }
3696
- $data = $this->get_chunk(($start+$numberOfHMetrics*4),($numGlyphs*2));
3697
- $arr = unpack("n*", $data);
3698
- $diff = $numGlyphs-$numberOfHMetrics;
3699
- $w = intval(round($scale*$aw));
3700
- if ($w == 0) { $w = 65535; }
3701
- for( $pos=0; $pos<$diff; $pos++) {
3702
- $glyph = $pos + $numberOfHMetrics;
3703
- if (isset($glyphToChar[$glyph])) {
3704
- foreach($glyphToChar[$glyph] AS $char) {
3705
- if ($char != 0 && $char != 65535) {
3706
- if ($char < 196608) {
3707
- $this->charWidths[$char*2] = chr($w >> 8);
3708
- $this->charWidths[$char*2 + 1] = chr($w & 0xFF);
3709
- $nCharWidths++;
3710
- }
3711
- }
3712
- }
3713
- }
3714
- }
3715
- // NB 65535 is a set width of 0
3716
- // First bytes define number of chars in font
3717
- $this->charWidths[0] = chr($nCharWidths >> 8);
3718
- $this->charWidths[1] = chr($nCharWidths & 0xFF);
3719
- }
3720
-
3721
-
3722
-
3723
-
3724
-
3725
- function getHMetric($numberOfHMetrics, $gid) {
3726
- $start = $this->seek_table("hmtx");
3727
- if ($gid < $numberOfHMetrics) {
3728
- $this->seek($start+($gid*4));
3729
- $hm = fread($this->fh,4);
3730
- }
3731
- else {
3732
- $this->seek($start+(($numberOfHMetrics-1)*4));
3733
- $hm = fread($this->fh,2);
3734
- $this->seek($start+($numberOfHMetrics*2)+($gid*2));
3735
- $hm .= fread($this->fh,2);
3736
- }
3737
- return $hm;
3738
- }
3739
-
3740
- function getLOCA($indexToLocFormat, $numGlyphs) {
3741
- $start = $this->seek_table('loca');
3742
- $this->glyphPos = array();
3743
- if ($indexToLocFormat == 0) {
3744
- $data = $this->get_chunk($start,($numGlyphs*2)+2);
3745
- $arr = unpack("n*", $data);
3746
- for ($n=0; $n<=$numGlyphs; $n++) {
3747
- $this->glyphPos[] = ($arr[$n+1] * 2);
3748
- }
3749
- }
3750
- else if ($indexToLocFormat == 1) {
3751
- $data = $this->get_chunk($start,($numGlyphs*4)+4);
3752
- $arr = unpack("N*", $data);
3753
- for ($n=0; $n<=$numGlyphs; $n++) {
3754
- $this->glyphPos[] = ($arr[$n+1]);
3755
- }
3756
- }
3757
- else
3758
- die('Unknown location table format '.$indexToLocFormat);
3759
- }
3760
-
3761
-
3762
- // CMAP Format 4
3763
- function getCMAP4($unicode_cmap_offset, &$glyphToChar, &$charToGlyph ) {
3764
- $this->maxUniChar = 0;
3765
- $this->seek($unicode_cmap_offset + 2);
3766
- $length = $this->read_ushort();
3767
- $limit = $unicode_cmap_offset + $length;
3768
- $this->skip(2);
3769
-
3770
- $segCount = $this->read_ushort() / 2;
3771
- $this->skip(6);
3772
- $endCount = array();
3773
- for($i=0; $i<$segCount; $i++) { $endCount[] = $this->read_ushort(); }
3774
- $this->skip(2);
3775
- $startCount = array();
3776
- for($i=0; $i<$segCount; $i++) { $startCount[] = $this->read_ushort(); }
3777
- $idDelta = array();
3778
- for($i=0; $i<$segCount; $i++) { $idDelta[] = $this->read_short(); } // ???? was unsigned short
3779
- $idRangeOffset_start = $this->_pos;
3780
- $idRangeOffset = array();
3781
- for($i=0; $i<$segCount; $i++) { $idRangeOffset[] = $this->read_ushort(); }
3782
-
3783
- for ($n=0;$n<$segCount;$n++) {
3784
- $endpoint = ($endCount[$n] + 1);
3785
- for ($unichar=$startCount[$n];$unichar<$endpoint;$unichar++) {
3786
- if ($idRangeOffset[$n] == 0)
3787
- $glyph = ($unichar + $idDelta[$n]) & 0xFFFF;
3788
- else {
3789
- $offset = ($unichar - $startCount[$n]) * 2 + $idRangeOffset[$n];
3790
- $offset = $idRangeOffset_start + 2 * $n + $offset;
3791
- if ($offset >= $limit)
3792
- $glyph = 0;
3793
- else {
3794
- $glyph = $this->get_ushort($offset);
3795
- if ($glyph != 0)
3796
- $glyph = ($glyph + $idDelta[$n]) & 0xFFFF;
3797
- }
3798
- }
3799
- $charToGlyph[$unichar] = $glyph;
3800
- if ($unichar < 196608) { $this->maxUniChar = max($unichar,$this->maxUniChar); }
3801
- $glyphToChar[$glyph][] = $unichar;
3802
- }
3803
- }
3804
-
3805
- }
3806
-
3807
- function formatUni($char) {
3808
- $x = preg_replace('/^[0]*/','',$char);
3809
- $x = str_pad($x, 4, '0', STR_PAD_LEFT);
3810
- $d = hexdec($x);
3811
- if (($d>57343 && $d<63744) || ($d>122879 && $d<126977)) { $id = 'M'; } // E000 - F8FF, 1E000-1F000
3812
- else { $id = 'U'; }
3813
- return $id .'+'.$x;
3814
- }
3815
- function formatEntity($char, $allowjoining=false) {
3816
- $char = preg_replace('/^[0]/','',$char);
3817
- $x = '&#x'.$char.';';
3818
- if (strpos($this->GlyphClassMarks, $char)!==false) {
3819
- if (!$allowjoining) {
3820
- $x = '&#x25cc;'.$x;
3821
- }
3822
- }
3823
- return $x;
3824
- }
3825
- function formatUniArr($arr) {
3826
- $s = array();
3827
- foreach($arr AS $c) {
3828
- $x = preg_replace('/^[0]*/','',$c);
3829
- $d = hexdec($x);
3830
- if (($d>57343 && $d<63744) || ($d>122879 && $d<126977)) { $id = 'M'; } // E000 - F8FF, 1E000-1F000
3831
- else { $id = 'U'; }
3832
- $s[] = $id .'+'.str_pad($x, 4, '0', STR_PAD_LEFT);
3833
- }
3834
- return implode(', ',$s);
3835
- }
3836
- function formatEntityArr($arr) {
3837
- $s = array();
3838
- foreach($arr AS $c) {
3839
- $c = preg_replace('/^[0]/','',$c);
3840
- $x = '&#x'.$c.';';
3841
- if (strpos($this->GlyphClassMarks, $c)!==false) {
3842
- $x = '&#x25cc;'.$x;
3843
- }
3844
- $s[] = $x;
3845
- }
3846
- return implode(' ',$s); // ZWNJ? &#x200d;
3847
- }
3848
- function formatClassArr($arr) {
3849
- $s = array();
3850
- foreach($arr AS $c) {
3851
- $x = preg_replace('/^[0]*/','',$c);
3852
- $d = hexdec($x);
3853
- if (($d>57343 && $d<63744) || ($d>122879 && $d<126977)) { $id = 'M'; } // E000 - F8FF, 1E000-1F000
3854
- else { $id = 'U'; }
3855
- $s[] = $id .'+'.str_pad($x, 4, '0', STR_PAD_LEFT);
3856
- }
3857
- return implode(', ',$s);
3858
- }
3859
- function formatUniStr($str) {
3860
- $s = array();
3861
- $arr = explode('|',$str);
3862
- foreach($arr AS $c) {
3863
- $x = preg_replace('/^[0]*/','',$c);
3864
- $d = hexdec($x);
3865
- if (($d>57343 && $d<63744) || ($d>122879 && $d<126977)) { $id = 'M'; } // E000 - F8FF, 1E000-1F000
3866
- else { $id = 'U'; }
3867
- $s[] = $id .'+'.str_pad($x, 4, '0', STR_PAD_LEFT);
3868
- }
3869
- return implode(', ',$s);
3870
- }
3871
- function formatEntityStr($str) {
3872
- $s = array();
3873
- $arr = explode('|',$str);
3874
- foreach($arr AS $c) {
3875
- $c = preg_replace('/^[0]/','',$c);
3876
- $x = '&#x'.$c.';';
3877
- if (strpos($this->GlyphClassMarks, $c)!==false) {
3878
- $x = '&#x25cc;'.$x;
3879
- }
3880
- $s[] = $x;
3881
- }
3882
- return implode(' ',$s); // ZWNJ? &#x200d;
3883
- }
3884
- function formatEntityFirst($str) {
3885
- $arr = explode('|',$str);
3886
- $char = preg_replace('/^[0]/','',$arr[0]);
3887
- $x = '&#x'.$char.';';
3888
- if (strpos($this->GlyphClassMarks, $char)!==false) {
3889
- $x = '&#x25cc;'.$x;
3890
- }
3891
- return $x;
3892
- }
3893
-
3894
- }
3895
-
3896
-
3897
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/mpdf/classes/sea.php DELETED
@@ -1,349 +0,0 @@
1
- <?php
2
-
3
-
4
- class SEA {
5
-
6
- // South East Asian shaper
7
-
8
- // sea_category
9
- const OT_X = 0;
10
- const OT_C = 1;
11
- const OT_IV = 2; # Independent Vowel
12
- const OT_T = 3; # Tone Marks
13
- const OT_H = 4; # Halant
14
- const OT_A = 10; # Anusvara
15
- const OT_GB = 12; # Generic Base (OT_DOTTEDCIRCLE in Indic)
16
- const OT_CM = 17; # Consonant Medial
17
- const OT_MR = 22; # Medial Ra
18
- const OT_VAbv = 26;
19
- const OT_VBlw = 27;
20
- const OT_VPre = 28;
21
- const OT_VPst = 29;
22
- // ? From Indic categories
23
- const OT_ZWNJ = 5;
24
- const OT_ZWJ = 6;
25
- const OT_M = 7;
26
- const OT_SM = 8;
27
- const OT_VD = 9;
28
- const OT_NBSP = 11;
29
- const OT_RS = 13;
30
- const OT_Coeng = 14;
31
- const OT_Repha = 15;
32
- const OT_Ra = 16;
33
-
34
- // Based on sea_category used to make string to find syllables
35
- // OT_ to string character (using e.g. OT_C from INDIC) hb-ot-shape-complex-sea-private.hh
36
- public static $sea_category_char = array(
37
- 'x',
38
- 'C',
39
- 'V',
40
- 'T',
41
- 'H',
42
- 'x',
43
- 'x',
44
- 'x',
45
- 'x',
46
- 'x',
47
- 'A',
48
- 'x',
49
- 'G',
50
- 'x',
51
- 'x',
52
- 'x',
53
- 'x',
54
- 'M',
55
- 'x',
56
- 'x',
57
- 'x',
58
- 'x',
59
- 'R',
60
- 'x',
61
- 'x',
62
- 'x',
63
- 'a',
64
- 'b',
65
- 'p',
66
- 't',
67
- );
68
-
69
-
70
- /* Visual positions in a syllable from left to right. */
71
- // sea_position
72
- const POS_START = 0;
73
-
74
- const POS_RA_TO_BECOME_REPH = 1;
75
- const POS_PRE_M = 2;
76
- const POS_PRE_C = 3;
77
-
78
- const POS_BASE_C = 4;
79
- const POS_AFTER_MAIN = 5;
80
-
81
- const POS_ABOVE_C = 6;
82
-
83
- const POS_BEFORE_SUB = 7;
84
- const POS_BELOW_C = 8;
85
- const POS_AFTER_SUB = 9;
86
-
87
- const POS_BEFORE_POST = 10;
88
- const POS_POST_C = 11;
89
- const POS_AFTER_POST = 12;
90
-
91
- const POS_FINAL_C = 13;
92
- const POS_SMVD = 14;
93
-
94
- const POS_END = 15;
95
-
96
-
97
-
98
- public static function set_sea_properties(&$info, $scriptblock ) {
99
- $u = $info['uni'];
100
- $type = self::sea_get_categories($u);
101
- $cat = ($type & 0x7F);
102
- $pos = ($type >> 8);
103
-
104
- /*
105
- * Re-assign category
106
- */
107
- // Medial Ra
108
- if ($u == 0x1A55 || $u == 0xAA34) { $cat = self::OT_MR; }
109
-
110
- /*
111
- * Re-assign position.
112
- */
113
- if ($cat == self::OT_M) { // definitely "OT_M" in HarfBuzz - although this does not seem to have been defined ? should be OT_MR
114
- switch ($pos) {
115
- case self::POS_PRE_C: $cat = self::OT_VPre; break;
116
- case self::POS_ABOVE_C: $cat = self::OT_VAbv; break;
117
- case self::POS_BELOW_C: $cat = self::OT_VBlw; break;
118
- case self::POS_POST_C: $cat = self::OT_VPst; break;
119
- }
120
- }
121
-
122
- $info['sea_category'] = $cat;
123
- $info['sea_position'] = $pos;
124
- }
125
-
126
- // syllable_type
127
- const CONSONANT_SYLLABLE = 0;
128
- const BROKEN_CLUSTER = 1;
129
- const NON_SEA_CLUSTER = 2;
130
-
131
-
132
-
133
- public static function set_syllables(&$o, $s, &$broken_syllables) {
134
- $ptr = 0;
135
- $syllable_serial = 1;
136
- $broken_syllables = false;
137
- while($ptr < strlen($s)) {
138
- $match = '';
139
- $syllable_length = 1;
140
- $syllable_type = self::NON_SEA_CLUSTER ;
141
-
142
- // CONSONANT_SYLLABLE Consonant syllable
143
- if (preg_match('/^(C|V|G)(p|a|b|t|HC|M|R|T|A)*/', substr($s,$ptr), $ma)) {
144
- $syllable_length = strlen($ma[0]);
145
- $syllable_type = self::CONSONANT_SYLLABLE ;
146
- }
147
- // BROKEN_CLUSTER syllable
148
- else if (preg_match('/^(p|a|b|t|HC|M|R|T|A)+/', substr($s,$ptr), $ma)) {
149
- $syllable_length = strlen($ma[0]);
150
- $syllable_type = self::BROKEN_CLUSTER ;
151
- $broken_syllables = true;
152
- }
153
-
154
- for ($i = $ptr; $i < $ptr+$syllable_length; $i++) { $o[$i]['syllable'] = ($syllable_serial << 4) | $syllable_type; }
155
- $ptr += $syllable_length ;
156
- $syllable_serial++;
157
- if ($syllable_serial == 16) $syllable_serial = 1;
158
- }
159
- }
160
-
161
- public static function initial_reordering(&$info, $GSUBdata, $broken_syllables, $scriptblock, $dottedcircle) {
162
-
163
- if ($broken_syllables && $dottedcircle) { self::insert_dotted_circles ($info, $dottedcircle); }
164
-
165
- $count = count($info);
166
- if (!$count) return;
167
- $last = 0;
168
- $last_syllable = $info[0]['syllable'];
169
- for ($i = 1; $i < $count; $i++) {
170
- if ($last_syllable != $info[$i]['syllable']) {
171
- self::initial_reordering_syllable ($info, $GSUBdata, $scriptblock, $last, $i);
172
- $last = $i;
173
- $last_syllable = $info[$last]['syllable'];
174
- }
175
- }
176
- self::initial_reordering_syllable($info, $GSUBdata, $scriptblock, $last, $count);
177
- }
178
-
179
- public static function insert_dotted_circles(&$info, $dottedcircle) {
180
- $idx = 0;
181
- $last_syllable = 0;
182
- while ($idx < count($info)) {
183
- $syllable = $info[$idx]['syllable'];
184
- $syllable_type = ($syllable & 0x0F);
185
- if ($last_syllable != $syllable && $syllable_type == self::BROKEN_CLUSTER) {
186
- $last_syllable = $syllable;
187
- $dottedcircle[0]['syllable'] = $info[$idx]['syllable'];
188
- array_splice($info, $idx, 0, $dottedcircle);
189
- }
190
- else
191
- $idx++;
192
- }
193
- }
194
-
195
-
196
-
197
-
198
- public static function initial_reordering_syllable (&$info, $GSUBdata, $scriptblock, $start, $end) {
199
- /* broken_cluster: We already inserted dotted-circles, so just call the standalone_cluster. */
200
-
201
- $syllable_type = ($info[$start]['syllable'] & 0x0F);
202
- if ($syllable_type==self::NON_SEA_CLUSTER ) { return; }
203
- if ($syllable_type==self::BROKEN_CLUSTER) {
204
- /* For dotted-circle, this is what Uniscribe does:
205
- * If dotted-circle is the last glyph, it just does nothing. */
206
- if ($info[$end - 1]['sea_category'] == self::OT_GB) {
207
- return;
208
- }
209
- }
210
-
211
- $base = $start;
212
- $i = $start;
213
- for (; $i < $base; $i++)
214
- $info[$i]['sea_position'] = self::POS_PRE_C;
215
- if ($i < $end) {
216
- $info[$i]['sea_position'] = self::POS_BASE_C;
217
- $i++;
218
- }
219
- for (; $i < $end; $i++) {
220
- if ($info[$i]['sea_category'] == self::OT_MR) { /* Pre-base reordering */
221
- $info[$i]['sea_position'] = self::POS_PRE_C;
222
- continue;
223
- }
224
- if ($info[$i]['sea_category'] == self::OT_VPre) { /* Left matra */
225
- $info[$i]['sea_position'] = self::POS_PRE_M;
226
- continue;
227
- }
228
- $info[$i]['sea_position'] = self::POS_AFTER_MAIN;
229
- }
230
-
231
- /* Sit tight, rock 'n roll! */
232
- self::bubble_sort ($info, $start, $end - $start);
233
-
234
- }
235
-
236
- public static function final_reordering (&$info, $GSUBdata, $scriptblock) {
237
- $count = count($info);
238
- if (!$count) return;
239
- $last = 0;
240
- $last_syllable = $info[0]['syllable'];
241
- for ($i = 1; $i < $count; $i++) {
242
- if ($last_syllable != $info[$i]['syllable']) {
243
- self::final_reordering_syllable ($info, $GSUBdata, $scriptblock, $last, $i);
244
- $last = $i;
245
- $last_syllable = $info[$last]['syllable'];
246
- }
247
- }
248
- self::final_reordering_syllable ($info, $GSUBdata, $scriptblock, $last, $count);
249
-
250
- }
251
-
252
- public static function final_reordering_syllable (&$info, $GSUBdata, $scriptblock, $start, $end) {
253
- /*
254
- * Nothing to do here at present!
255
- */
256
-
257
- }
258
-
259
-
260
-
261
-
262
- public static $sea_table = array(
263
-
264
- /* New Tai Lue (1980..19DF) */
265
-
266
- /* 1980 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
267
- /* 1988 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
268
- /* 1990 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
269
- /* 1998 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
270
- /* 19A0 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
271
- /* 19A8 */ 3841, 3841, 3841, 3841, 3840, 3840, 3840, 3840,
272
- /* 19B0 */ 2823, 2823, 2823, 2823, 2823, 775, 775, 775,
273
- /* 19B8 */ 2823, 2823, 775, 2823, 2823, 2823, 2823, 2823,
274
- /* 19C0 */ 2823, 3857, 3857, 3857, 3857, 3857, 3857, 3857,
275
- /* 19C8 */ 3843, 3843, 3840, 3840, 3840, 3840, 3840, 3840,
276
- /* 19D0 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
277
- /* 19D8 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
278
-
279
- /* Tai Tham (1A20..1AAF) */
280
-
281
- /* 1A20 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
282
- /* 1A28 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
283
- /* 1A30 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
284
- /* 1A38 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
285
- /* 1A40 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
286
- /* 1A48 */ 3841, 3841, 3841, 3841, 3841, 3842, 3842, 3842,
287
- /* 1A50 */3842, 3842, 3842, 3841, 3841, 3857, 3857, 3857,
288
- /* 1A58 */ 3857, 3857, 3857, 3857, 3857, 3857, 3857, 3840,
289
- /* 1A60 */ 3844, 2823, 1543, 2823, 2823, 1543, 1543, 1543,
290
- /* 1A68 */ 1543, 2055, 2055, 1543, 2055, 2823, 775, 775,
291
- /* 1A70 */ 775, 775, 775, 1543, 1543, 3843, 3843, 3843,
292
- /* 1A78 */ 3843, 3843, 3840, 3840, 3840, 3840, 3840, 3840,
293
- /* 1A80 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
294
- /* 1A88 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
295
- /* 1A90 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
296
- /* 1A98 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
297
- /* 1AA0 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
298
- /* 1AA8 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
299
-
300
- /* Cham (AA00..AA5F) */
301
-
302
- /* AA00 */ 3842, 3842, 3842, 3842, 3842, 3842, 3841, 3841,
303
- /* AA08 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
304
- /* AA10 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
305
- /* AA18 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
306
- /* AA20 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
307
- /* AA28 */ 3841, 1543, 1543, 1543, 1543, 2055, 1543, 775,
308
- /* AA30 */ 775, 1543, 2055, 3857, 3857, 3857, 3857, 3840,
309
- /* AA38 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
310
- /* AA40 */ 3857, 3857, 3857, 3857, 3857, 3857, 3857, 3857,
311
- /* AA48 */ 3857, 3857, 3857, 3857, 3857, 3857, 3840, 3840,
312
- /* AA50 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
313
- /* AA58 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
314
-
315
- );
316
-
317
-
318
-
319
- public static function sea_get_categories ($u) {
320
- if (0x1980 <= $u && $u <= 0x19DF) return self::$sea_table[$u - 0x1980]; // offset 0 for New Tai Lue
321
- if (0x1A20 <= $u && $u <= 0x1AAF) return self::$sea_table[$u - 0x1A20 + 96]; // offset for Tai Tham
322
- if (0xAA00 <= $u && $u <= 0xAA5F) return self::$sea_table[$u - 0xAA00 + 96 + 144]; // Cham
323
- if ($u == 0x00A0) return 3851; // (ISC_CP | (IMC_x << 8))
324
- if ($u == 0x25CC) return 3851; // (ISC_CP | (IMC_x << 8))
325
- return 3840; // (ISC_x | (IMC_x << 8))
326
- }
327
-
328
-
329
- public static function bubble_sort(&$arr, $start, $len) {
330
- if ($len<2) { return;}
331
- $k = $start+$len-2;
332
- while ($k >= $start) {
333
- for ($j=$start; $j<=$k; $j++) {
334
- if ($arr[$j]['sea_position'] > $arr[$j + 1]['sea_position']) {
335
- $t = $arr[$j];
336
- $arr[$j] = $arr[$j + 1];
337
- $arr[$j + 1] = $t;
338
- }
339
- }
340
- $k--;
341
- }
342
- }
343
-
344
-
345
-
346
-
347
- } // end Class
348
-
349
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/mpdf/classes/svg.php DELETED
@@ -1,3441 +0,0 @@
1
- <?php
2
- // svg class modified for mPDF version 6.0 by Ian Back: based on -
3
- // svg2pdf fpdf class
4
- // sylvain briand (syb@godisaduck.com), modified by rick trevino (rtrevino1@yahoo.com)
5
- // http://www.godisaduck.com/svg2pdf_with_fpdf
6
- // http://rhodopsin.blogspot.com
7
- //
8
- // cette class etendue est open source, toute modification devra cependant etre repertori�e~
9
-
10
-
11
- // If you wish to use Automatic Font selection within SVG's. change this definition to true.
12
- // This selects different fonts for different scripts used in text.
13
- // This can be enabled/disabled independently of the use of Automatic Font selection within mPDF generally.
14
- // Choice of font is determined by the config_script2lang.php and config_lang2fonts.php files, the same as for mPDF generally.
15
- if (!defined("_SVG_AUTOFONT")) { define("_SVG_AUTOFONT", false); }
16
-
17
- // Enable a limited use of classes within SVG <text> elements by setting this to true.
18
- // This allows recognition of a "class" attribute on a <text> element.
19
- // The CSS style for that class should be outside the SVG, and cannot use any other selectors (i.e. only .class {} can be defined)
20
- // <style> definitions within the SVG code will be recognised if the SVG is included as an inline item within the HTML code passed to mPDF.
21
- // The style property should be pertinent to SVG e.g. use fill:red rather than color:red
22
- // Only the properties currently supported for SVG text can be specified:
23
- // fill, fill-opacity, stroke, stroke-opacity, stroke-linecap, stroke-linejoin, stroke-width, stroke-dasharray, stroke-dashoffset
24
- // font-family, font-size, font-weight, font-variant, font-style, opacity, text-anchor
25
- if (!defined("_SVG_CLASSES")) { define("_SVG_CLASSES", false); }
26
-
27
-
28
-
29
-
30
- // NB UNITS - Works in pixels as main units - converting to PDF units when outputing to PDF string
31
- // and on returning size
32
-
33
- class SVG {
34
-
35
- var $svg_font; // array - holds content of SVG fonts defined in image // mPDF 6
36
- var $svg_gradient; // array - contient les infos sur les gradient fill du svg class� par id du svg
37
- var $svg_shadinglist; // array - contient les ids des objet shading
38
- var $svg_info; // array contenant les infos du svg voulue par l'utilisateur
39
- var $svg_attribs; // array - holds all attributes of root <svg> tag
40
- var $svg_style; // array contenant les style de groupes du svg
41
- var $svg_string; // String contenant le tracage du svg en lui m�me.
42
- var $txt_data; // array - holds string info to write txt to image
43
- var $txt_style; // array - current text style
44
- var $mpdf_ref;
45
- var $xbase;
46
- var $ybase;
47
- var $svg_error;
48
- var $subPathInit;
49
- var $spxstart;
50
- var $spystart;
51
- var $kp; // convert pixels to PDF units
52
- var $pathBBox;
53
-
54
- var $script2lang;
55
- var $viet;
56
- var $pashto;
57
- var $urdu;
58
- var $persian;
59
- var $sindhi;
60
-
61
- var $textlength; // mPDF 5.7.4
62
- var $texttotallength; // mPDF 5.7.4
63
- var $textoutput; // mPDF 5.7.4
64
- var $textanchor; // mPDF 5.7.4
65
- var $textXorigin; // mPDF 5.7.4
66
- var $textYorigin; // mPDF 5.7.4
67
- var $textjuststarted; // mPDF 5.7.4
68
- var $intext; // mPDF 5.7.4
69
-
70
- function SVG(&$mpdf){
71
- $this->svg_font = array(); // mPDF 6
72
- $this->svg_gradient = array();
73
- $this->svg_shadinglist = array();
74
- $this->txt_data = array();
75
- $this->svg_string = '';
76
- $this->svg_info = array();
77
- $this->svg_attribs = array();
78
- $this->xbase = 0;
79
- $this->ybase = 0;
80
- $this->svg_error = false;
81
- $this->subPathInit = false;
82
- $this->dashesUsed = false;
83
- $this->mpdf_ref =& $mpdf;
84
-
85
- $this->textlength = 0; // mPDF 5.7.4
86
- $this->texttotallength = 0; // mPDF 5.7.4
87
- $this->textoutput = ''; // mPDF 5.7.4
88
- $this->textanchor = 'start'; // mPDF 5.7.4
89
- $this->textXorigin = 0; // mPDF 5.7.4
90
- $this->textYorigin = 0; // mPDF 5.7.4
91
- $this->textjuststarted = false; // mPDF 5.7.4
92
- $this->intext = false; // mPDF 5.7.4
93
-
94
- $this->kp = 72 / $mpdf->img_dpi; // constant To convert pixels to pts/PDF units
95
- $this->kf = 1; // constant To convert font size if re-mapped
96
- $this->pathBBox = array();
97
-
98
- $this->svg_style = array(
99
- array(
100
- 'fill' => 'black',
101
- 'fill-opacity' => 1, // remplissage opaque par defaut
102
- 'fill-rule' => 'nonzero', // mode de remplissage par defaut
103
- 'stroke' => 'none', // pas de trait par defaut
104
- 'stroke-linecap' => 'butt', // style de langle par defaut
105
- 'stroke-linejoin' => 'miter',
106
- 'stroke-miterlimit' => 4, // limite de langle par defaut
107
- 'stroke-opacity' => 1, // trait opaque par defaut
108
- 'stroke-width' => 1,
109
- 'stroke-dasharray' => 0,
110
- 'stroke-dashoffset' => 0,
111
- 'color' => ''
112
- )
113
- );
114
-
115
- $this->txt_style = array(
116
- array(
117
- 'fill' => 'black', // pas de remplissage par defaut
118
- 'font-family' => $mpdf->default_font,
119
- 'font-size' => $mpdf->default_font_size, // ****** this is pts
120
- 'font-weight' => 'normal', // normal | bold
121
- 'font-style' => 'normal', // italic | normal
122
- 'text-anchor' => 'start', // alignment: start, middle, end
123
- 'fill-opacity' => 1, // remplissage opaque par defaut
124
- 'fill-rule' => 'nonzero', // mode de remplissage par defaut
125
- 'stroke' => 'none', // pas de trait par defaut
126
- 'stroke-opacity' => 1, // trait opaque par defaut
127
- 'stroke-width' => 1,
128
- 'color' => ''
129
- )
130
- );
131
-
132
-
133
-
134
- }
135
-
136
- // mPDF 5.7.4 Embedded image
137
- function svgImage($attribs) {
138
- // x and y are coordinates
139
- $x = (isset($attribs['x']) ? $attribs['x'] : 0);
140
- $y = (isset($attribs['y']) ? $attribs['y'] : 0);
141
- // preserveAspectRatio
142
- $par = (isset($attribs['preserveAspectRatio']) ? $attribs['preserveAspectRatio'] : 'xMidYMid meet');
143
- // width and height are <lengths> - Required attributes
144
- $wset = (isset($attribs['width']) ? $attribs['width'] : 0);
145
- $hset = (isset($attribs['height']) ? $attribs['height'] : 0);
146
- $w = $this->mpdf_ref->ConvertSize($wset,$this->svg_info['w']*(25.4/$this->mpdf_ref->dpi),$this->mpdf_ref->FontSize,false);
147
- $h = $this->mpdf_ref->ConvertSize($hset,$this->svg_info['h']*(25.4/$this->mpdf_ref->dpi),$this->mpdf_ref->FontSize,false);
148
- if ($w==0 || $h==0) { return; }
149
- // Convert to pixels = SVG units
150
- $w *= 1/(25.4/$this->mpdf_ref->dpi);
151
- $h *= 1/(25.4/$this->mpdf_ref->dpi);
152
-
153
- $srcpath = $attribs['xlink:href'];
154
- $orig_srcpath = '';
155
- if (trim($srcpath) != '' && substr($srcpath,0,4)=='var:') {
156
- $orig_srcpath = $srcpath;
157
- $this->mpdf_ref->GetFullPath($srcpath);
158
- }
159
-
160
- // Image file (does not allow vector images i.e. WMF/SVG)
161
- // mPDF 6 Added $this->mpdf_ref->interpolateImages
162
- $info = $this->mpdf_ref->_getImage($srcpath, true, false, $orig_srcpath, $this->mpdf_ref->interpolateImages);
163
- if(!$info) return;
164
-
165
- // x,y,w,h define the reference rectangle
166
- $img_h = $h;
167
- $img_w = $w;
168
- $img_x = $x;
169
- $img_y = $y;
170
- $meetOrSlice = 'meet';
171
-
172
- // preserveAspectRatio
173
- $ar = preg_split('/\s+/', strtolower($par));
174
- if ($ar[0]!='none') { // If "none" need to do nothing
175
- // Force uniform scaling
176
- if (isset($ar[1]) && $ar[1]=='slice') { $meetOrSlice = 'slice'; }
177
- else { $meetOrSlice = 'meet'; }
178
- if ($info['h']/$info['w'] > $h/$w) {
179
- if ($meetOrSlice == 'meet') { // the entire viewBox is visible within the viewport
180
- $img_w = $img_h * $info['w']/$info['h'];
181
- }
182
- else { // the entire viewport is covered by the viewBox
183
- $img_h = $img_w * $info['h']/$info['w'];
184
- }
185
- }
186
- else if ($info['h']/$info['w'] < $h/$w) {
187
- if ($meetOrSlice == 'meet') { // the entire viewBox is visible within the viewport
188
- $img_h = $img_w * $info['h']/$info['w'];
189
- }
190
- else { // the entire viewport is covered by the viewBox
191
- $img_w = $img_h * $info['w']/$info['h'];
192
- }
193
- }
194
- if ($ar[0]=='xminymin') {
195
- // do nothing to x
196
- // do nothing to y
197
- }
198
- else if ($ar[0]=='xmidymin') {
199
- $img_x += $w/2 - $img_w/2; // xMid
200
- // do nothing to y
201
- }
202
- else if ($ar[0]=='xmaxymin') {
203
- $img_x += $w - $img_w; // xMax
204
- // do nothing to y
205
- }
206
- else if ($ar[0]=='xminymid') {
207
- // do nothing to x
208
- $img_y += $h/2 - $img_h/2; // yMid
209
- }
210
- else if ($ar[0]=='xmaxymid') {
211
- $img_x += $w - $img_w; // xMax
212
- $img_y += $h/2 - $img_h/2; // yMid
213
- }
214
- else if ($ar[0]=='xminymax') {
215
- // do nothing to x
216
- $img_y += $h - $img_h; // yMax
217
- }
218
- else if ($ar[0]=='xmidymax') {
219
- $img_x += $w/2 - $img_w/2; // xMid
220
- $img_y += $h - $img_h; // yMax
221
- }
222
- else if ($ar[0]=='xmaxymax') {
223
- $img_x += $w - $img_w; // xMax
224
- $img_y += $h - $img_h; // yMax
225
- }
226
- else { // xMidYMid (the default)
227
- $img_x += $w/2 - $img_w/2; // xMid
228
- $img_y += $h/2 - $img_h/2; // yMid
229
- }
230
- }
231
-
232
- // Output
233
- if ($meetOrSlice == 'slice') { // need to add a clipping path to reference rectangle
234
- $s = ' q 0 w '; // Line width=0
235
- $s .= sprintf('%.3F %.3F m ', ($x)*$this->kp, (-($y+$h))*$this->kp); // start point TL before the arc
236
- $s .= sprintf('%.3F %.3F l ', ($x)*$this->kp, (-($y))*$this->kp); // line to BL
237
- $s .= sprintf('%.3F %.3F l ', ($x+$w)*$this->kp, (-($y))*$this->kp); // line to BR
238
- $s .= sprintf('%.3F %.3F l ', ($x+$w)*$this->kp, (-($y+$h))*$this->kp); // line to TR
239
- $s .= sprintf('%.3F %.3F l ', ($x)*$this->kp, (-($y+$h))*$this->kp); // line to TL
240
- $s .= ' W n '; // Ends path no-op & Sets the clipping path
241
- $this->svgWriteString($s);
242
- }
243
-
244
- $outstring = sprintf(" q %.3F 0 0 %.3F %.3F %.3F cm /I%d Do Q ",$img_w*$this->kp, $img_h*$this->kp, $img_x*$this->kp, -($img_y+$img_h)*$this->kp, $info['i'] );
245
- $this->svgWriteString($outstring);
246
-
247
- if ($meetOrSlice == 'slice') { // need to end clipping path
248
- $this->svgWriteString(' Q ');
249
- }
250
- }
251
-
252
-
253
- function svgGradient($gradient_info, $attribs, $element){
254
- $n = count($this->mpdf_ref->gradients)+1;
255
-
256
- // Get bounding dimensions of element
257
- $w = 100;
258
- $h = 100;
259
- $x_offset = 0;
260
- $y_offset = 0;
261
- if ($element=='rect') {
262
- $w = $attribs['width'];
263
- $h = $attribs['height'];
264
- $x_offset = $attribs['x'];
265
- $y_offset = $attribs['y'];
266
- }
267
- else if ($element=='ellipse') {
268
- $w = $attribs['rx']*2;
269
- $h = $attribs['ry']*2;
270
- $x_offset = $attribs['cx']-$attribs['rx'];
271
- $y_offset = $attribs['cy']-$attribs['ry'];
272
- }
273
- else if ($element=='circle') {
274
- $w = $attribs['r']*2;
275
- $h = $attribs['r']*2;
276
- $x_offset = $attribs['cx']-$attribs['r'];
277
- $y_offset = $attribs['cy']-$attribs['r'];
278
- }
279
- else if ($element=='polygon') {
280
- $pts = preg_split('/[ ,]+/', trim($attribs['points']));
281
- $maxr=$maxb=0;
282
- $minl=$mint=999999;
283
- for ($i=0;$i<count($pts); $i++) {
284
- if ($i % 2 == 0) { // x values
285
- $minl = min($minl,$pts[$i]);
286
- $maxr = max($maxr,$pts[$i]);
287
- }
288
- else { // y values
289
- $mint = min($mint,$pts[$i]);
290
- $maxb = max($maxb,$pts[$i]);
291
- }
292
- }
293
- $w = $maxr-$minl;
294
- $h = $maxb-$mint;
295
- $x_offset = $minl;
296
- $y_offset = $mint;
297
- }
298
- else if ($element=='path') {
299
- if (is_array($this->pathBBox) && $this->pathBBox[2]>0) {
300
- $w = $this->pathBBox[2];
301
- $h = $this->pathBBox[3];
302
- $x_offset = $this->pathBBox[0];
303
- $y_offset = $this->pathBBox[1];
304
- }
305
- else {
306
- preg_match_all('/([a-z]|[A-Z])([ ,\-.\d]+)*/', $attribs['d'], $commands, PREG_SET_ORDER);
307
- $maxr=$maxb=0;
308
- $minl=$mint=999999;
309
- foreach($commands as $c){
310
- if(count($c)==3){
311
- list($tmp, $cmd, $arg) = $c;
312
- if ($cmd=='M' || $cmd=='L' || $cmd=='C' || $cmd=='S' || $cmd=='Q' || $cmd=='T') {
313
- $pts = preg_split('/[ ,]+/', trim($arg));
314
- for ($i=0;$i<count($pts); $i++) {
315
- if ($i % 2 == 0) { // x values
316
- $minl = min($minl,$pts[$i]);
317
- $maxr = max($maxr,$pts[$i]);
318
- }
319
- else { // y values
320
- $mint = min($mint,$pts[$i]);
321
- $maxb = max($maxb,$pts[$i]);
322
- }
323
- }
324
- }
325
- if ($cmd=='H') { // sets new x
326
- $minl = min($minl,$arg);
327
- $maxr = max($maxr,$arg);
328
- }
329
- if ($cmd=='V') { // sets new y
330
- $mint = min($mint,$arg);
331
- $maxb = max($maxb,$arg);
332
- }
333
- }
334
- }
335
- $w = $maxr-$minl;
336
- $h = $maxb-$mint;
337
- $x_offset = $minl;
338
- $y_offset = $mint;
339
- }
340
- }
341
- if (!$w || $w==-999999) { $w = 100; }
342
- if (!$h || $h==-999999) { $h = 100; }
343
- if ($x_offset==999999) { $x_offset = 0; }
344
- if ($y_offset==999999) { $y_offset = 0; }
345
-
346
- // TRANSFORMATIONS
347
- $transformations = '';
348
- if (isset($gradient_info['transform'])){
349
- preg_match_all('/(matrix|translate|scale|rotate|skewX|skewY)\((.*?)\)/is',$gradient_info['transform'],$m);
350
- if (count($m[0])) {
351
- for($i=0; $i<count($m[0]); $i++) {
352
- $c = strtolower($m[1][$i]);
353
- $v = trim($m[2][$i]);
354
- $vv = preg_split('/[ ,]+/',$v);
355
- if ($c=='matrix' && count($vv)==6) {
356
- // Note angle of rotation is reversed (from SVG to PDF), so vv[1] and vv[2] are negated
357
- // cf svgDefineStyle()
358
- $transformations .= sprintf(' %.3F %.3F %.3F %.3F %.3F %.3F cm ', $vv[0], -$vv[1], -$vv[2], $vv[3], $vv[4]*$this->kp, -$vv[5]*$this->kp);
359
- }
360
- else if ($c=='translate' && count($vv)) {
361
- $tm[4] = $vv[0];
362
- if (count($vv)==2) { $t_y = -$vv[1]; }
363
- else { $t_y = 0; }
364
- $tm[5] = $t_y;
365
- $transformations .= sprintf(' 1 0 0 1 %.3F %.3F cm ', $tm[4]*$this->kp, $tm[5]*$this->kp);
366
- }
367
- else if ($c=='scale' && count($vv)) {
368
- if (count($vv)==2) { $s_y = $vv[1]; }
369
- else { $s_y = $vv[0]; }
370
- $tm[0] = $vv[0];
371
- $tm[3] = $s_y;
372
- $transformations .= sprintf(' %.3F 0 0 %.3F 0 0 cm ', $tm[0], $tm[3]);
373
- }
374
- else if ($c=='rotate' && count($vv)) {
375
- $tm[0] = cos(deg2rad(-$vv[0]));
376
- $tm[1] = sin(deg2rad(-$vv[0]));
377
- $tm[2] = -$tm[1];
378
- $tm[3] = $tm[0];
379
- if (count($vv)==3) {
380
- $transformations .= sprintf(' 1 0 0 1 %.3F %.3F cm ', $vv[1]*$this->kp, -$vv[2]*$this->kp);
381
- }
382
- $transformations .= sprintf(' %.3F %.3F %.3F %.3F 0 0 cm ', $tm[0], $tm[1], $tm[2], $tm[3]);
383
- if (count($vv)==3) {
384
- $transformations .= sprintf(' 1 0 0 1 %.3F %.3F cm ', -$vv[1]*$this->kp, $vv[2]*$this->kp);
385
- }
386
- }
387
- else if ($c=='skewx' && count($vv)) {
388
- $tm[2] = tan(deg2rad(-$vv[0]));
389
- $transformations .= sprintf(' 1 0 %.3F 1 0 0 cm ', $tm[2]);
390
- }
391
- else if ($c=='skewy' && count($vv)) {
392
- $tm[1] = tan(deg2rad(-$vv[0]));
393
- $transformations .= sprintf(' 1 %.3F 0 1 0 0 cm ', $tm[1]);
394
- }
395
-
396
- }
397
- }
398
- }
399
-
400
-
401
- $return = "";
402
-
403
- if (isset($gradient_info['units']) && strtolower($gradient_info['units'])=='userspaceonuse') {
404
- if ($transformations) { $return .= $transformations; }
405
- }
406
- $spread = 'P'; // pad
407
- if (isset($gradient_info['spread'])) {
408
- if (strtolower($gradient_info['spread'])=='reflect') { $spread = 'F'; } // reflect
409
- else if (strtolower($gradient_info['spread'])=='repeat') { $spread = 'R'; } // repeat
410
- }
411
-
412
-
413
- for ($i=0; $i<(count($gradient_info['color'])); $i++) {
414
- if (stristr($gradient_info['color'][$i]['offset'], '%')!== false) { $gradient_info['color'][$i]['offset'] = ($gradient_info['color'][$i]['offset']+0)/100; }
415
- if (isset($gradient_info['color'][($i+1)]['offset']) && stristr($gradient_info['color'][($i+1)]['offset'], '%')!== false) { $gradient_info['color'][($i+1)]['offset'] = ($gradient_info['color'][($i+1)]['offset']+0)/100; }
416
- if ($gradient_info['color'][$i]['offset']<0) { $gradient_info['color'][$i]['offset'] = 0; }
417
- if ($gradient_info['color'][$i]['offset']>1) { $gradient_info['color'][$i]['offset'] = 1; }
418
- if ($i>0) {
419
- if ($gradient_info['color'][$i]['offset']<$gradient_info['color'][($i-1)]['offset']) {
420
- $gradient_info['color'][$i]['offset']=$gradient_info['color'][($i-1)]['offset'];
421
- }
422
- }
423
- }
424
-
425
- if (isset($gradient_info['color'][0]['offset']) && $gradient_info['color'][0]['offset']>0) {
426
- array_unshift($gradient_info['color'], $gradient_info['color'][0]);
427
- $gradient_info['color'][0]['offset'] = 0;
428
- }
429
- $ns = count($gradient_info['color']);
430
- if (isset($gradient_info['color'][($ns-1)]['offset']) && $gradient_info['color'][($ns-1)]['offset']<1) {
431
- $gradient_info['color'][] = $gradient_info['color'][($ns-1)];
432
- $gradient_info['color'][($ns)]['offset'] = 1;
433
- }
434
- $ns = count($gradient_info['color']);
435
-
436
-
437
-
438
-
439
- if ($gradient_info['type'] == 'linear'){
440
- // mPDF 4.4.003
441
- if (isset($gradient_info['units']) && strtolower($gradient_info['units'])=='userspaceonuse') {
442
- if (isset($gradient_info['info']['x1'])) { $gradient_info['info']['x1'] = ($gradient_info['info']['x1']-$x_offset) / $w; }
443
- if (isset($gradient_info['info']['y1'])) { $gradient_info['info']['y1'] = ($gradient_info['info']['y1']-$y_offset) / $h; }
444
- if (isset($gradient_info['info']['x2'])) { $gradient_info['info']['x2'] = ($gradient_info['info']['x2']-$x_offset) / $w; }
445
- if (isset($gradient_info['info']['y2'])) { $gradient_info['info']['y2'] = ($gradient_info['info']['y2']-$y_offset) / $h; }
446
- }
447
- if (isset($gradient_info['info']['x1'])) { $x1 = $gradient_info['info']['x1']; }
448
- else { $x1 = 0; }
449
- if (isset($gradient_info['info']['y1'])) { $y1 = $gradient_info['info']['y1']; }
450
- else { $y1 = 0; }
451
- if (isset($gradient_info['info']['x2'])) { $x2 = $gradient_info['info']['x2']; }
452
- else { $x2 = 1; }
453
- if (isset($gradient_info['info']['y2'])) { $y2 = $gradient_info['info']['y2']; }
454
- else { $y2 = 0; } // mPDF 6
455
-
456
- if (stristr($x1, '%')!== false) { $x1 = ($x1+0)/100; }
457
- if (stristr($x2, '%')!== false) { $x2 = ($x2+0)/100; }
458
- if (stristr($y1, '%')!== false) { $y1 = ($y1+0)/100; }
459
- if (stristr($y2, '%')!== false) { $y2 = ($y2+0)/100; }
460
-
461
- // mPDF 5.0.042
462
- $bboxw = $w;
463
- $bboxh = $h;
464
- $usex = $x_offset;
465
- $usey = $y_offset;
466
- $usew = $bboxw;
467
- $useh = $bboxh;
468
- if (isset($gradient_info['units']) && strtolower($gradient_info['units'])=='userspaceonuse') {
469
- $angle = rad2deg(atan2(($gradient_info['info']['y2']-$gradient_info['info']['y1']), ($gradient_info['info']['x2']-$gradient_info['info']['x1'])));
470
- if ($angle < 0) { $angle += 360; }
471
- else if ($angle > 360) { $angle -= 360; }
472
- if ($angle!=0 && $angle!=360 && $angle!=90 && $angle!=180 && $angle!=270) {
473
- if ($w >= $h) {
474
- $y1 *= $h/$w ;
475
- $y2 *= $h/$w ;
476
- $usew = $useh = $bboxw;
477
- }
478
- else {
479
- $x1 *= $w/$h ;
480
- $x2 *= $w/$h ;
481
- $usew = $useh = $bboxh;
482
- }
483
- }
484
- }
485
- $a = $usew; // width
486
- $d = -$useh; // height
487
- $e = $usex; // x- offset
488
- $f = -$usey; // -y-offset
489
-
490
- $return .= sprintf('%.3F 0 0 %.3F %.3F %.3F cm ', $a*$this->kp, $d*$this->kp, $e*$this->kp, $f*$this->kp);
491
-
492
- if (isset($gradient_info['units']) && strtolower($gradient_info['units'])=='objectboundingbox') {
493
- if ($transformations) { $return .= $transformations; }
494
- }
495
-
496
- $trans = false;
497
-
498
- if ($spread=='R' || $spread=='F') { // Repeat / Reflect
499
- $offs = array();
500
- for($i=0;$i<$ns;$i++) {
501
- $offs[$i] = $gradient_info['color'][$i]['offset'];
502
- }
503
- $gp = 0;
504
- $inside=true;
505
- while($inside) {
506
- $gp++;
507
- for($i=0;$i<$ns;$i++) {
508
- if ($spread=='F' && ($gp % 2) == 1) { // Reflect
509
- $gradient_info['color'][(($ns*$gp)+$i)] = $gradient_info['color'][(($ns*($gp-1))+($ns-$i-1))];
510
- $tmp = $gp+(1-$offs[($ns-$i-1)]) ;
511
- $gradient_info['color'][(($ns*$gp)+$i)]['offset'] = $tmp;
512
- }
513
- else { // Reflect
514
- $gradient_info['color'][(($ns*$gp)+$i)] = $gradient_info['color'][$i];
515
- $tmp = $gp+$offs[$i] ;
516
- $gradient_info['color'][(($ns*$gp)+$i)]['offset'] = $tmp;
517
- }
518
- // IF STILL INSIDE BOX OR STILL VALID
519
- // Point on axis to test
520
- $px1 = $x1 + ($x2-$x1)*$tmp;
521
- $py1 = $y1 + ($y2-$y1)*$tmp;
522
- // Get perpendicular axis
523
- $alpha = atan2($y2-$y1, $x2-$x1);
524
- $alpha += M_PI/2; // rotate 90 degrees
525
- // Get arbitrary point to define line perpendicular to axis
526
- $px2 = $px1+cos($alpha);
527
- $py2 = $py1+sin($alpha);
528
-
529
- $res1 = _testIntersect($px1, $py1, $px2, $py2, 0, 0, 0, 1); // $x=0 vert axis
530
- $res2 = _testIntersect($px1, $py1, $px2, $py2, 1, 0, 1, 1); // $x=1 vert axis
531
- $res3 = _testIntersect($px1, $py1, $px2, $py2, 0, 0, 1, 0); // $y=0 horiz axis
532
- $res4 = _testIntersect($px1, $py1, $px2, $py2, 0, 1, 1, 1); // $y=1 horiz axis
533
- if (!$res1 && !$res2 && !$res3 && !$res4) { $inside = false; }
534
- }
535
- }
536
-
537
- $inside=true;
538
- $gp = 0;
539
- while($inside) {
540
- $gp++;
541
- $newarr = array();
542
- for($i=0;$i<$ns;$i++) {
543
- if ($spread=='F') { // Reflect
544
- $newarr[$i] = $gradient_info['color'][($ns-$i-1)];
545
- if (($gp % 2) == 1) {
546
- $tmp = -$gp+(1-$offs[($ns-$i-1)]);
547
- $newarr[$i]['offset'] = $tmp;
548
- }
549
- else {
550
- $tmp = -$gp+$offs[$i];
551
- $newarr[$i]['offset'] = $tmp;
552
- }
553
- }
554
- else { // Reflect
555
- $newarr[$i] = $gradient_info['color'][$i];
556
- $tmp = -$gp+$offs[$i];
557
- $newarr[$i]['offset'] = $tmp;
558
- }
559
-
560
- // IF STILL INSIDE BOX OR STILL VALID
561
- // Point on axis to test
562
- $px1 = $x1 + ($x2-$x1)*$tmp;
563
- $py1 = $y1 + ($y2-$y1)*$tmp;
564
- // Get perpendicular axis
565
- $alpha = atan2($y2-$y1, $x2-$x1);
566
- $alpha += M_PI/2; // rotate 90 degrees
567
- // Get arbitrary point to define line perpendicular to axis
568
- $px2 = $px1+cos($alpha);
569
- $py2 = $py1+sin($alpha);
570
-
571
- $res1 = _testIntersect($px1, $py1, $px2, $py2, 0, 0, 0, 1); // $x=0 vert axis
572
- $res2 = _testIntersect($px1, $py1, $px2, $py2, 1, 0, 1, 1); // $x=1 vert axis
573
- $res3 = _testIntersect($px1, $py1, $px2, $py2, 0, 0, 1, 0); // $y=0 horiz axis
574
- $res4 = _testIntersect($px1, $py1, $px2, $py2, 0, 1, 1, 1); // $y=1 horiz axis
575
- if (!$res1 && !$res2 && !$res3 && !$res4) { $inside = false; }
576
- }
577
- for($i=($ns-1);$i>=0;$i--) {
578
- if (isset($newarr[$i]['offset'])) array_unshift($gradient_info['color'], $newarr[$i]);
579
- }
580
- }
581
- }
582
-
583
- // Gradient STOPs
584
- $stops = count($gradient_info['color']);
585
- if ($stops < 2) { return ''; }
586
-
587
- $range = $gradient_info['color'][count($gradient_info['color'])-1]['offset']-$gradient_info['color'][0]['offset'];
588
- $min = $gradient_info['color'][0]['offset'];
589
-
590
- for ($i=0; $i<($stops); $i++) {
591
- if (!$gradient_info['color'][$i]['color']) {
592
- if ($gradient_info['colorspace']=='RGB') $gradient_info['color'][$i]['color'] = '0 0 0';
593
- else if ($gradient_info['colorspace']=='Gray') $gradient_info['color'][$i]['color'] = '0';
594
- else if ($gradient_info['colorspace']=='CMYK') $gradient_info['color'][$i]['color'] = '1 1 1 1';
595
- }
596
- $offset = ($gradient_info['color'][$i]['offset'] - $min)/$range;
597
- $this->mpdf_ref->gradients[$n]['stops'][] = array(
598
- 'col' => $gradient_info['color'][$i]['color'],
599
- 'opacity' => $gradient_info['color'][$i]['opacity'],
600
- 'offset' => $offset);
601
- if ($gradient_info['color'][$i]['opacity']<1) { $trans = true; }
602
- }
603
- $grx1 = $x1 + ($x2-$x1)*$gradient_info['color'][0]['offset'];
604
- $gry1 = $y1 + ($y2-$y1)*$gradient_info['color'][0]['offset'];
605
- $grx2 = $x1 + ($x2-$x1)*$gradient_info['color'][count($gradient_info['color'])-1]['offset'];
606
- $gry2 = $y1 + ($y2-$y1)*$gradient_info['color'][count($gradient_info['color'])-1]['offset'];
607
-
608
- $this->mpdf_ref->gradients[$n]['coords']=array($grx1, $gry1, $grx2, $gry2);
609
-
610
- $this->mpdf_ref->gradients[$n]['colorspace'] = $gradient_info['colorspace'];
611
-
612
- $this->mpdf_ref->gradients[$n]['type'] = 2;
613
- $this->mpdf_ref->gradients[$n]['fo'] = true;
614
-
615
- $this->mpdf_ref->gradients[$n]['extend']=array('true','true');
616
- if ($trans) {
617
- $this->mpdf_ref->gradients[$n]['trans'] = true;
618
- $return .= ' /TGS'.($n).' gs ';
619
- }
620
- $return .= ' /Sh'.($n).' sh ';
621
- $return .= " Q\n";
622
- }
623
- else if ($gradient_info['type'] == 'radial'){
624
- if (isset($gradient_info['units']) && strtolower($gradient_info['units'])=='userspaceonuse') {
625
- if ($w > $h) { $h = $w; }
626
- else { $w = $h; }
627
- if (isset($gradient_info['info']['x0'])) { $gradient_info['info']['x0'] = ($gradient_info['info']['x0']-$x_offset) / $w; }
628
- if (isset($gradient_info['info']['y0'])) { $gradient_info['info']['y0'] = ($gradient_info['info']['y0']-$y_offset) / $h; }
629
- if (isset($gradient_info['info']['x1'])) { $gradient_info['info']['x1'] = ($gradient_info['info']['x1']-$x_offset) / $w; }
630
- if (isset($gradient_info['info']['y1'])) { $gradient_info['info']['y1'] = ($gradient_info['info']['y1']-$y_offset) / $h; }
631
- if (isset($gradient_info['info']['r'])) { $gradient_info['info']['rx'] = $gradient_info['info']['r'] / $w; }
632
- if (isset($gradient_info['info']['r'])) { $gradient_info['info']['ry'] = $gradient_info['info']['r'] / $h; }
633
- }
634
-
635
- if (isset($gradient_info['info']['x0'])) { $x0 = $gradient_info['info']['x0']; }
636
- else { $x0 = 0.5; }
637
- if (isset($gradient_info['info']['y0'])) { $y0 = $gradient_info['info']['y0']; }
638
- else { $y0 = 0.5; }
639
- if (isset($gradient_info['info']['rx'])) { $rx = $gradient_info['info']['rx']; }
640
- else if (isset($gradient_info['info']['r'])) { $rx = $gradient_info['info']['r']; }
641
- else { $rx = 0.5; }
642
- if (isset($gradient_info['info']['ry'])) { $ry = $gradient_info['info']['ry']; }
643
- else if (isset($gradient_info['info']['r'])) { $ry = $gradient_info['info']['r']; }
644
- else { $ry = 0.5; }
645
- if (isset($gradient_info['info']['x1'])) { $x1 = $gradient_info['info']['x1']; }
646
- else { $x1 = $x0; }
647
- if (isset($gradient_info['info']['y1'])) { $y1 = $gradient_info['info']['y1']; }
648
- else { $y1 = $y0; }
649
-
650
- if (stristr($x1, '%')!== false) { $x1 = ($x1+0)/100; }
651
- if (stristr($x0, '%')!== false) { $x0 = ($x0+0)/100; }
652
- if (stristr($y1, '%')!== false) { $y1 = ($y1+0)/100; }
653
- if (stristr($y0, '%')!== false) { $y0 = ($y0+0)/100; }
654
- if (stristr($rx, '%')!== false) { $rx = ($rx+0)/100; }
655
- if (stristr($ry, '%')!== false) { $ry = ($ry+0)/100; }
656
-
657
- $bboxw = $w;
658
- $bboxh = $h;
659
- $usex = $x_offset;
660
- $usey = $y_offset;
661
- $usew = $bboxw;
662
- $useh = $bboxh;
663
- if (isset($gradient_info['units']) && strtolower($gradient_info['units'])=='userspaceonuse') {
664
- $angle = rad2deg(atan2(($gradient_info['info']['y0']-$gradient_info['info']['y1']), ($gradient_info['info']['x0']-$gradient_info['info']['x1'])));
665
- if ($angle < 0) { $angle += 360; }
666
- else if ($angle > 360) { $angle -= 360; }
667
- if ($angle!=0 && $angle!=360 && $angle!=90 && $angle!=180 && $angle!=270) {
668
- if ($w >= $h) {
669
- $y1 *= $h/$w ;
670
- $y0 *= $h/$w ;
671
- $rx *= $h/$w ;
672
- $ry *= $h/$w ;
673
- $usew = $useh = $bboxw;
674
- }
675
- else {
676
- $x1 *= $w/$h ;
677
- $x0 *= $w/$h ;
678
- $rx *= $w/$h ;
679
- $ry *= $w/$h ;
680
- $usew = $useh = $bboxh;
681
- }
682
- }
683
- }
684
- $a = $usew; // width
685
- $d = -$useh; // height
686
- $e = $usex; // x- offset
687
- $f = -$usey; // -y-offset
688
-
689
- $r = $rx;
690
-
691
-
692
- $return .= sprintf('%.3F 0 0 %.3F %.3F %.3F cm ', $a*$this->kp, $d*$this->kp, $e*$this->kp, $f*$this->kp);
693
-
694
- // mPDF 5.0.039
695
- if (isset($gradient_info['units']) && strtolower($gradient_info['units'])=='objectboundingbox') {
696
- if ($transformations) { $return .= $transformations; }
697
- }
698
-
699
- // mPDF 5.7.4
700
- // x1 and y1 (fx, fy) should be inside the circle defined by x0 y0 (cx, cy)
701
- // "If the point defined by fx and fy lies outside the circle defined by cx, cy and r, then the user agent shall set
702
- // the focal point to the intersection of the line from (cx, cy) to (fx, fy) with the circle defined by cx, cy and r."
703
- while (pow(($x1-$x0),2) + pow(($y1 - $y0),2) >= pow($r,2)) {
704
- // Gradually move along fx,fy towards cx,cy in 100'ths until meets criteria
705
- $x1 -= ($x1-$x0)/100;
706
- $y1 -= ($y1-$y0)/100;
707
- }
708
-
709
-
710
- if ($spread=='R' || $spread=='F') { // Repeat / Reflect
711
- $offs = array();
712
- for($i=0;$i<$ns;$i++) {
713
- $offs[$i] = $gradient_info['color'][$i]['offset'];
714
- }
715
- $gp = 0;
716
- $inside=true;
717
- while($inside) {
718
- $gp++;
719
- for($i=0;$i<$ns;$i++) {
720
- if ($spread=='F' && ($gp % 2) == 1) { // Reflect
721
- $gradient_info['color'][(($ns*$gp)+$i)] = $gradient_info['color'][(($ns*($gp-1))+($ns-$i-1))];
722
- $tmp = $gp+(1-$offs[($ns-$i-1)]) ;
723
- $gradient_info['color'][(($ns*$gp)+$i)]['offset'] = $tmp;
724
- }
725
- else { // Reflect
726
- $gradient_info['color'][(($ns*$gp)+$i)] = $gradient_info['color'][$i];
727
- $tmp = $gp+$offs[$i] ;
728
- $gradient_info['color'][(($ns*$gp)+$i)]['offset'] = $tmp;
729
- }
730
- // IF STILL INSIDE BOX OR STILL VALID
731
- // TEST IF circle (perimeter) intersects with
732
- // or is enclosed
733
- // Point on axis to test
734
- $px = $x1 + ($x0-$x1)*$tmp;
735
- $py = $y1 + ($y0-$y1)*$tmp;
736
- $pr = $r*$tmp;
737
- $res = _testIntersectCircle($px, $py, $pr);
738
- if (!$res) { $inside = false; }
739
- }
740
- }
741
- }
742
-
743
- // Gradient STOPs
744
- $stops = count($gradient_info['color']);
745
- if ($stops < 2) { return ''; }
746
-
747
- $range = $gradient_info['color'][count($gradient_info['color'])-1]['offset']-$gradient_info['color'][0]['offset'];
748
- $min = $gradient_info['color'][0]['offset'];
749
-
750
- for ($i=0; $i<($stops); $i++) {
751
- if (!$gradient_info['color'][$i]['color']) {
752
- if ($gradient_info['colorspace']=='RGB') $gradient_info['color'][$i]['color'] = '0 0 0';
753
- else if ($gradient_info['colorspace']=='Gray') $gradient_info['color'][$i]['color'] = '0';
754
- else if ($gradient_info['colorspace']=='CMYK') $gradient_info['color'][$i]['color'] = '1 1 1 1';
755
- }
756
- $offset = ($gradient_info['color'][$i]['offset'] - $min)/$range;
757
- $this->mpdf_ref->gradients[$n]['stops'][] = array(
758
- 'col' => $gradient_info['color'][$i]['color'],
759
- 'opacity' => $gradient_info['color'][$i]['opacity'],
760
- 'offset' => $offset);
761
- if ($gradient_info['color'][$i]['opacity']<1) { $trans = true; }
762
- }
763
- $grx1 = $x1 + ($x0-$x1)*$gradient_info['color'][0]['offset'];
764
- $gry1 = $y1 + ($y0-$y1)*$gradient_info['color'][0]['offset'];
765
- $grx2 = $x1 + ($x0-$x1)*$gradient_info['color'][count($gradient_info['color'])-1]['offset'];
766
- $gry2 = $y1 + ($y0-$y1)*$gradient_info['color'][count($gradient_info['color'])-1]['offset'];
767
- $grir = $r*$gradient_info['color'][0]['offset'];
768
- $grr = $r*$gradient_info['color'][count($gradient_info['color'])-1]['offset'];
769
-
770
- $this->mpdf_ref->gradients[$n]['coords']=array($grx1, $gry1, $grx2, $gry2, abs($grr), abs($grir) );
771
-
772
- $this->mpdf_ref->gradients[$n]['colorspace'] = $gradient_info['colorspace'];
773
-
774
- $this->mpdf_ref->gradients[$n]['type'] = 3;
775
- $this->mpdf_ref->gradients[$n]['fo'] = true;
776
-
777
- $this->mpdf_ref->gradients[$n]['extend']=array('true','true');
778
- if (isset($trans) && $trans) {
779
- $this->mpdf_ref->gradients[$n]['trans'] = true;
780
- $return .= ' /TGS'.($n).' gs ';
781
- }
782
- $return .= ' /Sh'.($n).' sh ';
783
- $return .= " Q\n";
784
-
785
-
786
- }
787
-
788
- return $return;
789
- }
790
-
791
-
792
- function svgOffset ($attribs){
793
- // save all <svg> tag attributes
794
- $this->svg_attribs = $attribs;
795
- if(isset($this->svg_attribs['viewBox'])) {
796
- $vb = preg_split('/\s+/is', trim($this->svg_attribs['viewBox']));
797
- if (count($vb)==4) {
798
- $this->svg_info['x'] = $vb[0];
799
- $this->svg_info['y'] = $vb[1];
800
- $this->svg_info['w'] = $vb[2];
801
- $this->svg_info['h'] = $vb[3];
802
- // return;
803
- }
804
- }
805
- $svg_w = 0;
806
- $svg_h = 0;
807
- if (isset($attribs['width']) && $attribs['width']) $svg_w = $this->mpdf_ref->ConvertSize($attribs['width']); // mm (interprets numbers as pixels)
808
- if (isset($attribs['height']) && $attribs['height']) $svg_h = $this->mpdf_ref->ConvertSize($attribs['height']); // mm
809
-
810
- ///*
811
- // mPDF 5.0.005
812
- if (isset($this->svg_info['w']) && $this->svg_info['w']) { // if 'w' set by viewBox
813
- if ($svg_w) { // if width also set, use these values to determine to set size of "pixel"
814
- $this->kp *= ($svg_w/0.2645) / $this->svg_info['w'];
815
- $this->kf = ($svg_w/0.2645) / $this->svg_info['w'];
816
- }
817
- else if ($svg_h) {
818
- $this->kp *= ($svg_h/0.2645) / $this->svg_info['h'];
819
- $this->kf = ($svg_h/0.2645) / $this->svg_info['h'];
820
- }
821
- return;
822
- }
823
- //*/
824
-
825
- // Added to handle file without height or width specified
826
- if (!$svg_w && !$svg_h) { $svg_w = $svg_h = $this->mpdf_ref->blk[$this->mpdf_ref->blklvl]['inner_width'] ; } // DEFAULT
827
- if (!$svg_w) { $svg_w = $svg_h; }
828
- if (!$svg_h) { $svg_h = $svg_w; }
829
-
830
- $this->svg_info['x'] = 0;
831
- $this->svg_info['y'] = 0;
832
- $this->svg_info['w'] = $svg_w/0.2645; // mm->pixels
833
- $this->svg_info['h'] = $svg_h/0.2645; // mm->pixels
834
-
835
- }
836
-
837
-
838
- //
839
- // check if points are within svg, if not, set to max
840
- function svg_overflow($x,$y)
841
- {
842
- $x2 = $x;
843
- $y2 = $y;
844
- if(isset($this->svg_attribs['overflow']))
845
- {
846
- if($this->svg_attribs['overflow'] == 'hidden')
847
- {
848
- // Not sure if this is supposed to strip off units, but since I dont use any I will omlt this step
849
- $svg_w = preg_replace("/([0-9\.]*)(.*)/i","$1",$this->svg_attribs['width']);
850
- $svg_h = preg_replace("/([0-9\.]*)(.*)/i","$1",$this->svg_attribs['height']);
851
-
852
- // $xmax = floor($this->svg_attribs['width']);
853
- $xmax = floor($svg_w);
854
- $xmin = 0;
855
- // $ymax = floor(($this->svg_attribs['height'] * -1));
856
- $ymax = floor(($svg_h * -1));
857
- $ymin = 0;
858
-
859
- if($x > $xmax) $x2 = $xmax; // right edge
860
- if($x < $xmin) $x2 = $xmin; // left edge
861
- if($y < $ymax) $y2 = $ymax; // bottom
862
- if($y > $ymin) $y2 = $ymin; // top
863
-
864
- }
865
- }
866
-
867
-
868
- return array( 'x' => $x2, 'y' => $y2);
869
- }
870
-
871
-
872
-
873
- function svgDefineStyle($critere_style){
874
-
875
- $tmp = count($this->svg_style)-1;
876
- $current_style = $this->svg_style[$tmp];
877
-
878
- unset($current_style['transformations']);
879
-
880
- // TRANSFORM SCALE
881
- $transformations = '';
882
- if (isset($critere_style['transform'])){
883
- preg_match_all('/(matrix|translate|scale|rotate|skewX|skewY)\((.*?)\)/is',$critere_style['transform'],$m);
884
- if (count($m[0])) {
885
- for($i=0; $i<count($m[0]); $i++) {
886
- $c = strtolower($m[1][$i]);
887
- $v = trim($m[2][$i]);
888
- $vv = preg_split('/[ ,]+/',$v);
889
- if ($c=='matrix' && count($vv)==6) {
890
- // mPDF 5.0.039
891
- // Note angle of rotation is reversed (from SVG to PDF), so vv[1] and vv[2] are negated
892
- $transformations .= sprintf(' %.3F %.3F %.3F %.3F %.3F %.3F cm ', $vv[0], -$vv[1], -$vv[2], $vv[3], $vv[4]*$this->kp, -$vv[5]*$this->kp);
893
-
894
- /*
895
- // The long way of doing this??
896
- // need to reverse angle of rotation from SVG to PDF
897
- $sx=sqrt(pow($vv[0],2)+pow($vv[2],2));
898
- if ($vv[0] < 0) { $sx *= -1; } // change sign
899
- $sy=sqrt(pow($vv[1],2)+pow($vv[3],2));
900
- if ($vv[3] < 0) { $sy *= -1; } // change sign
901
-
902
- // rotation angle is
903
- $t=atan2($vv[1],$vv[3]);
904
- $t=atan2(-$vv[2],$vv[0]); // Should be the same value or skew has been applied
905
-
906
- // Reverse angle
907
- $t *= -1;
908
-
909
- // Rebuild matrix
910
- $ma = $sx * cos($t);
911
- $mb = $sy * sin($t);
912
- $mc = -$sx * sin($t);
913
- $md = $sy * cos($t);
914
-
915
- // $transformations .= sprintf(' %.3F %.3F %.3F %.3F %.3F %.3F cm ', $ma, $mb, $mc, $md, $vv[4]*$this->kp, -$vv[5]*$this->kp);
916
- */
917
-
918
- }
919
- else if ($c=='translate' && count($vv)) {
920
- $tm[4] = $vv[0];
921
- if (count($vv)==2) { $t_y = -$vv[1]; }
922
- else { $t_y = 0; }
923
- $tm[5] = $t_y;
924
- $transformations .= sprintf(' 1 0 0 1 %.3F %.3F cm ', $tm[4]*$this->kp, $tm[5]*$this->kp);
925
- }
926
- else if ($c=='scale' && count($vv)) {
927
- if (count($vv)==2) { $s_y = $vv[1]; }
928
- else { $s_y = $vv[0]; }
929
- $tm[0] = $vv[0];
930
- $tm[3] = $s_y;
931
- $transformations .= sprintf(' %.3F 0 0 %.3F 0 0 cm ', $tm[0], $tm[3]);
932
- }
933
- else if ($c=='rotate' && count($vv)) {
934
- $tm[0] = cos(deg2rad(-$vv[0]));
935
- $tm[1] = sin(deg2rad(-$vv[0]));
936
- $tm[2] = -$tm[1];
937
- $tm[3] = $tm[0];
938
- if (count($vv)==3) {
939
- $transformations .= sprintf(' 1 0 0 1 %.3F %.3F cm ', $vv[1]*$this->kp, -$vv[2]*$this->kp);
940
- }
941
- $transformations .= sprintf(' %.3F %.3F %.3F %.3F 0 0 cm ', $tm[0], $tm[1], $tm[2], $tm[3]);
942
- if (count($vv)==3) {
943
- $transformations .= sprintf(' 1 0 0 1 %.3F %.3F cm ', -$vv[1]*$this->kp, $vv[2]*$this->kp);
944
- }
945
- }
946
- else if ($c=='skewx' && count($vv)) {
947
- $tm[2] = tan(deg2rad(-$vv[0]));
948
- $transformations .= sprintf(' 1 0 %.3F 1 0 0 cm ', $tm[2]);
949
- }
950
- else if ($c=='skewy' && count($vv)) {
951
- $tm[1] = tan(deg2rad(-$vv[0]));
952
- $transformations .= sprintf(' 1 %.3F 0 1 0 0 cm ', $tm[1]);
953
- }
954
-
955
- }
956
- }
957
- $current_style['transformations'] = $transformations;
958
- }
959
-
960
- if (isset($critere_style['style'])){
961
- if (preg_match('/fill:\s*rgb\((\d+),\s*(\d+),\s*(\d+)\)/i',$critere_style['style'], $m)) { // mPDF 5.7.2
962
- $current_style['fill'] = '#'.str_pad(dechex($m[1]), 2, "0", STR_PAD_LEFT).str_pad(dechex($m[2]), 2, "0", STR_PAD_LEFT).str_pad(dechex($m[3]), 2, "0", STR_PAD_LEFT);
963
- }
964
- else { $tmp = preg_replace("/(.*)fill:\s*([a-z0-9#_()]*|none)(.*)/i","$2",$critere_style['style']);
965
- if ($tmp && $tmp!='inherit' && $tmp!=$critere_style['style']){ $current_style['fill'] = $tmp; }
966
- }
967
-
968
- // mPDF 5.7.2
969
- if ((preg_match("/[^-]opacity:\s*([a-z0-9.]*|none)/i",$critere_style['style'], $m) ||
970
- preg_match("/^opacity:\s*([a-z0-9.]*|none)/i",$critere_style['style'], $m)) && $m[1]!='inherit') {
971
- $current_style['fill-opacity'] = $m[1];
972
- $current_style['stroke-opacity'] = $m[1];
973
- }
974
-
975
- $tmp = preg_replace("/(.*)fill-opacity:\s*([a-z0-9.]*|none)(.*)/i","$2",$critere_style['style']);
976
- if ($tmp && $tmp!='inherit' && $tmp!=$critere_style['style']){ $current_style['fill-opacity'] = $tmp;}
977
-
978
- $tmp = preg_replace("/(.*)fill-rule:\s*([a-z0-9#]*|none)(.*)/i","$2",$critere_style['style']);
979
- if ($tmp && $tmp!='inherit' && $tmp!=$critere_style['style']){ $current_style['fill-rule'] = $tmp;}
980
-
981
- if (preg_match('/stroke:\s*rgb\((\d+),\s*(\d+),\s*(\d+)\)/',$critere_style['style'], $m)) {
982
- $current_style['stroke'] = '#'.str_pad(dechex($m[1]), 2, "0", STR_PAD_LEFT).str_pad(dechex($m[2]), 2, "0", STR_PAD_LEFT).str_pad(dechex($m[3]), 2, "0", STR_PAD_LEFT);
983
- }
984
- else { $tmp = preg_replace("/(.*)stroke:\s*([a-z0-9#]*|none)(.*)/i","$2",$critere_style['style']);
985
- if ($tmp && $tmp!='inherit' && $tmp!=$critere_style['style']){ $current_style['stroke'] = $tmp; }
986
- }
987
-
988
- $tmp = preg_replace("/(.*)stroke-linecap:\s*([a-z0-9#]*|none)(.*)/i","$2",$critere_style['style']);
989
- if ($tmp && $tmp!='inherit' && $tmp!=$critere_style['style']){ $current_style['stroke-linecap'] = $tmp;}
990
-
991
- $tmp = preg_replace("/(.*)stroke-linejoin:\s*([a-z0-9#]*|none)(.*)/i","$2",$critere_style['style']);
992
- if ($tmp && $tmp!='inherit' && $tmp!=$critere_style['style']){ $current_style['stroke-linejoin'] = $tmp;}
993
-
994
- $tmp = preg_replace("/(.*)stroke-miterlimit:\s*([a-z0-9#]*|none)(.*)/i","$2",$critere_style['style']);
995
- if ($tmp && $tmp!='inherit' && $tmp!=$critere_style['style']){ $current_style['stroke-miterlimit'] = $tmp;}
996
-
997
- $tmp = preg_replace("/(.*)stroke-opacity:\s*([a-z0-9.]*|none)(.*)/i","$2",$critere_style['style']);
998
- if ($tmp && $tmp!='inherit' && $tmp!=$critere_style['style']){ $current_style['stroke-opacity'] = $tmp; }
999
-
1000
- $tmp = preg_replace("/(.*)stroke-width:\s*([a-z0-9.]*|none)(.*)/i","$2",$critere_style['style']);
1001
- if ($tmp && $tmp!='inherit' && $tmp!=$critere_style['style']){ $current_style['stroke-width'] = $tmp;}
1002
-
1003
- $tmp = preg_replace("/(.*)stroke-dasharray:\s*([a-z0-9., ]*|none)(.*)/i","$2",$critere_style['style']);
1004
- if ($tmp && $tmp!='inherit' && $tmp!=$critere_style['style']){ $current_style['stroke-dasharray'] = $tmp;}
1005
-
1006
- $tmp = preg_replace("/(.*)stroke-dashoffset:\s*([a-z0-9.]*|none)(.*)/i","$2",$critere_style['style']);
1007
- if ($tmp && $tmp!='inherit' && $tmp!=$critere_style['style']){ $current_style['stroke-dashoffset'] = $tmp;}
1008
-
1009
- }
1010
- // mPDF 5.7.2
1011
- if(isset($critere_style['opacity']) && $critere_style['opacity']!= 'inherit'){
1012
- $current_style['fill-opacity'] = $critere_style['opacity'];
1013
- $current_style['stroke-opacity'] = $critere_style['opacity'];
1014
- }
1015
-
1016
- if(isset($critere_style['fill']) && $critere_style['fill']!= 'inherit'){
1017
- $current_style['fill'] = $critere_style['fill'];
1018
- }
1019
-
1020
- if(isset($critere_style['fill-opacity']) && $critere_style['fill-opacity']!= 'inherit'){
1021
- $current_style['fill-opacity'] = $critere_style['fill-opacity'];
1022
- }
1023
-
1024
- if(isset($critere_style['fill-rule']) && $critere_style['fill-rule']!= 'inherit'){
1025
- $current_style['fill-rule'] = $critere_style['fill-rule'];
1026
- }
1027
-
1028
- if(isset($critere_style['stroke']) && $critere_style['stroke']!= 'inherit'){
1029
- $current_style['stroke'] = $critere_style['stroke'];
1030
- }
1031
-
1032
- if(isset($critere_style['stroke-linecap']) && $critere_style['stroke-linecap']!= 'inherit'){
1033
- $current_style['stroke-linecap'] = $critere_style['stroke-linecap'];
1034
- }
1035
-
1036
- if(isset($critere_style['stroke-linejoin']) && $critere_style['stroke-linejoin']!= 'inherit'){
1037
- $current_style['stroke-linejoin'] = $critere_style['stroke-linejoin'];
1038
- }
1039
-
1040
- if(isset($critere_style['stroke-miterlimit']) && $critere_style['stroke-miterlimit']!= 'inherit'){
1041
- $current_style['stroke-miterlimit'] = $critere_style['stroke-miterlimit'];
1042
- }
1043
-
1044
- if(isset($critere_style['stroke-opacity']) && $critere_style['stroke-opacity']!= 'inherit'){
1045
- $current_style['stroke-opacity'] = $critere_style['stroke-opacity'];
1046
- }
1047
-
1048
- if(isset($critere_style['stroke-width']) && $critere_style['stroke-width']!= 'inherit'){
1049
- $current_style['stroke-width'] = $critere_style['stroke-width'];
1050
- }
1051
-
1052
- if(isset($critere_style['stroke-dasharray']) && $critere_style['stroke-dasharray']!= 'inherit'){
1053
- $current_style['stroke-dasharray'] = $critere_style['stroke-dasharray'];
1054
- }
1055
- if(isset($critere_style['stroke-dashoffset']) && $critere_style['stroke-dashoffset']!= 'inherit'){
1056
- $current_style['stroke-dashoffset'] = $critere_style['stroke-dashoffset'];
1057
- }
1058
-
1059
- // Used as indirect setting for currentColor
1060
- if(isset($critere_style['color']) && $critere_style['color'] != 'inherit'){
1061
- $current_style['color'] = $critere_style['color'];
1062
- }
1063
-
1064
- return $current_style;
1065
-
1066
- }
1067
-
1068
- //
1069
- // Cette fonction ecrit le style dans le stream svg.
1070
- function svgStyle($critere_style, $attribs, $element){
1071
- $path_style = '';
1072
- $fill_gradient = '';
1073
- $w = '';
1074
- $style = '';
1075
- if (substr_count($critere_style['fill'],'url')>0 && $element != 'line'){
1076
- //
1077
- // couleur degrad�
1078
- $id_gradient = preg_replace("/url\(#([\w_]*)\)/i","$1",$critere_style['fill']);
1079
- if ($id_gradient != $critere_style['fill']) {
1080
- if (isset($this->svg_gradient[$id_gradient])) {
1081
- $fill_gradient = $this->svgGradient($this->svg_gradient[$id_gradient], $attribs, $element);
1082
- if ($fill_gradient) {
1083
- $path_style = "q ";
1084
- $w = "W";
1085
- $style .= 'N';
1086
- }
1087
- }
1088
- }
1089
-
1090
- }
1091
- // Used as indirect setting for currentColor
1092
- else if (strtolower($critere_style['fill']) == 'currentcolor' && $element != 'line'){
1093
- $col =