PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.00.00
E2Pdf – Export Pdf Tool for WordPress v1.00.00
1.32.49 1.32.48 1.32.43 1.32.40 1.32.34 1.32.32 1.32.31 1.32.26 1.32.22 1.32.23 1.32.18 1.32.17 1.32.15 trunk 1.00.00 1.00.13 1.01.01 1.02.02 1.03.07 1.04.07 1.05.03 1.06.02 1.07.11 1.08.00 1.08.06 All 72 releases
e2pdf / classes / model / e2pdf-font.php

e2pdf-font.php in E2Pdf – Export Pdf Tool for WordPress 1.00.00, at classes/model/e2pdf-font.php

201 lines 7.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * E2pdf Font Model
5 *
6 * @copyright Copyright 2017 https://e2pdf.com
7 * @license GPL v2
8 * @version 1
9 * @link https://e2pdf.com
10 * @since 0.00.01
11 */
12 if (!defined('ABSPATH')) {
13 die('Access denied.');
14 }
15
16 class Model_E2pdf_Font extends Model_E2pdf_Model {
17
18 protected $text;
19
20 /**
21 * Initialize functions
22 */
23 function __construct() {
24 parent::__construct();
25 }
26
27 public function get_font_info($font = false, $key = false, $font_path = false) {
28
29 $font_tags = array();
30
31 if (!$font_path) {
32 $font_path = $this->helper->get("fonts_dir") . $font;
33 }
34
35
36 if ($font_path && file_exists($font_path) && filesize($font_path) > 0) {
37
38 $fd = fopen($font_path, "r");
39 $this->text = fread($fd, filesize($font_path));
40 fclose($fd);
41
42 $number_of_tables = hexdec($this->dec2ord($this->text[4]) . $this->dec2ord($this->text[5]));
43
44 for ($i = 0; $i < $number_of_tables; $i++) {
45 $tag = $this->text[12 + $i * 16] . $this->text[12 + $i * 16 + 1] . $this->text[12 + $i * 16 + 2] . $this->text[12 + $i * 16 + 3];
46
47 if ($tag == 'name') {
48 $this->ntOffset = hexdec(
49 $this->dec2ord($this->text[12 + $i * 16 + 8]) . $this->dec2ord($this->text[12 + $i * 16 + 8 + 1]) .
50 $this->dec2ord($this->text[12 + $i * 16 + 8 + 2]) . $this->dec2ord($this->text[12 + $i * 16 + 8 + 3]));
51
52 $offset_storage_dec = hexdec($this->dec2ord($this->text[$this->ntOffset + 4]) . $this->dec2ord($this->text[$this->ntOffset + 5]));
53 $number_name_records_dec = hexdec($this->dec2ord($this->text[$this->ntOffset + 2]) . $this->dec2ord($this->text[$this->ntOffset + 3]));
54 }
55 }
56
57 $storage_dec = $offset_storage_dec + $this->ntOffset;
58 $storage_hex = strtoupper(dechex($storage_dec));
59
60 for ($j = 0; $j < $number_name_records_dec; $j++) {
61 $platform_id_dec = hexdec($this->dec2ord($this->text[$this->ntOffset + 6 + $j * 12 + 0]) . $this->dec2ord($this->text[$this->ntOffset + 6 + $j * 12 + 1]));
62 $name_id_dec = hexdec($this->dec2ord($this->text[$this->ntOffset + 6 + $j * 12 + 6]) . $this->dec2ord($this->text[$this->ntOffset + 6 + $j * 12 + 7]));
63 $string_length_dec = hexdec($this->dec2ord($this->text[$this->ntOffset + 6 + $j * 12 + 8]) . $this->dec2ord($this->text[$this->ntOffset + 6 + $j * 12 + 9]));
64 $string_offset_dec = hexdec($this->dec2ord($this->text[$this->ntOffset + 6 + $j * 12 + 10]) . $this->dec2ord($this->text[$this->ntOffset + 6 + $j * 12 + 11]));
65
66 if (!empty($name_id_dec) and empty($font_tags[$name_id_dec])) {
67 for ($l = 0; $l < $string_length_dec; $l++) {
68 if (ord($this->text[$storage_dec + $string_offset_dec + $l]) == '0') {
69 continue;
70 } else {
71
72 if (!isset($font_tags[$name_id_dec])) {
73 $font_tags[$name_id_dec] = "";
74 }
75
76 $font_tags[$name_id_dec] .= ($this->text[$storage_dec + $string_offset_dec + $l]);
77 }
78 }
79 }
80 }
81 }
82
83 if ($key) {
84 if (!empty($font_tags) && isset($font_tags[$key])) {
85 return $font_tags[$key];
86 } else {
87 return false;
88 }
89 } else {
90 return $font_tags;
91 }
92 }
93
94 public function get_font($font) {
95 $font_path = $this->helper->get('fonts_dir') . $font;
96
97 if (file_exists($font_path)) {
98 return base64_encode(file_get_contents($font_path));
99 }
100 return false;
101 }
102
103 public function get_fonts() {
104
105 $fonts = array();
106 $files = glob($this->helper->get('fonts_dir') . "*");
107 if ($files) {
108 foreach ($files as $key => $value) {
109 if (pathinfo($value, PATHINFO_EXTENSION) == 'ttf') {
110 $font_info = $this->get_font_info(basename($value), 4);
111 if ($font_info) {
112 $fonts[basename($value)] = $font_info;
113 }
114 }
115 }
116 }
117 return $fonts;
118 }
119
120 public function delete_font($font) {
121 $font_path = $this->helper->get('fonts_dir') . $font;
122
123 if (file_exists($font_path)) {
124 unlink($font_path);
125 return true;
126 }
127 return false;
128 }
129
130 function get_element_fonts($el_value, $all_fonts) {
131 $fonts = array();
132 if ($el_value['type'] == 'e2pdf-html' && isset($el_value['value']) && $el_value['value']) {
133 preg_match_all('/font-family:[\s]+?"(.*?)";/', htmlspecialchars_decode($el_value['value']), $matches);
134 if (isset($matches[1]) && !empty($matches[1])) {
135 foreach ($matches[1] as $font_key => $font_value) {
136 $exist = array_search($font_value, $fonts);
137 if (!$exist) {
138 $c_font = array_search($font_value, $all_fonts);
139 if ($c_font) {
140 $fonts[$c_font] = $font_value;
141 }
142 }
143 }
144 }
145 }
146
147 if (isset($el_value['properties']['text_font']) && $el_value['properties']['text_font']) {
148 $font_value = $el_value['properties']['text_font'];
149 $exist = array_search($font_value, $fonts);
150 if (!$exist) {
151 $c_font = array_search($font_value, $all_fonts);
152 if ($c_font) {
153 $fonts[$c_font] = $font_value;
154 }
155 }
156 }
157
158 //action fonts
159 if (isset($el_value['actions']) && !empty($el_value['actions'])) {
160 foreach ($el_value['actions'] as $action) {
161 if (isset($action['property']) && $action['property'] == 'text_font' && isset($action['change']) && $action['change']) {
162 $font_value = $action['change'];
163 $exist = array_search($font_value, $fonts);
164 if (!$exist) {
165 $c_font = array_search($font_value, $all_fonts);
166 if ($c_font) {
167 $fonts[$c_font] = $font_value;
168 }
169 }
170 }
171
172 if ($el_value['type'] == 'e2pdf-html' && isset($action['property']) && $action['property'] == 'value' && isset($action['change']) && $action['change']) {
173 preg_match_all('/font-family:[\s]+?"(.*?)";/', htmlspecialchars_decode($action['change']), $matches);
174 if (isset($matches[1]) && !empty($matches[1])) {
175 foreach ($matches[1] as $font_key => $font_value) {
176 $exist = array_search($font_value, $fonts);
177 if (!$exist) {
178 $c_font = array_search($font_value, $all_fonts);
179 if ($c_font) {
180 $fonts[$c_font] = $font_value;
181 }
182 }
183 }
184 }
185 }
186 }
187 }
188
189 return $fonts;
190 }
191
192 protected function dec2ord($dec) {
193 return $this->dec2hex(ord($dec));
194 }
195
196 protected function dec2hex($dec) {
197 return str_repeat('0', 2 - strlen(($hex = strtoupper(dechex($dec))))) . $hex;
198 }
199
200 }
201