commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / vendor / phenx / php-font-lib / src / FontLib / Table / Type / name.php
1 <?php
2 /**
3 * @package php-font-lib
4 * @link https://github.com/PhenX/php-font-lib
5 * @author Fabien Ménager <fabien.menager@gmail.com>
6 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
7 */
8
9 namespace FontLib\Table\Type;
10
11 use FontLib\Table\Table;
12 use FontLib\Font;
13
14 /**
15 * `name` font table.
16 *
17 * @package php-font-lib
18 */
19 class name extends Table {
20 private static $header_format = array(
21 "format" => self::uint16,
22 "count" => self::uint16,
23 "stringOffset" => self::uint16,
24 );
25
26 const NAME_COPYRIGHT = 0;
27 const NAME_NAME = 1;
28 const NAME_SUBFAMILY = 2;
29 const NAME_SUBFAMILY_ID = 3;
30 const NAME_FULL_NAME = 4;
31 const NAME_VERSION = 5;
32 const NAME_POSTSCRIPT_NAME = 6;
33 const NAME_TRADEMARK = 7;
34 const NAME_MANUFACTURER = 8;
35 const NAME_DESIGNER = 9;
36 const NAME_DESCRIPTION = 10;
37 const NAME_VENDOR_URL = 11;
38 const NAME_DESIGNER_URL = 12;
39 const NAME_LICENSE = 13;
40 const NAME_LICENSE_URL = 14;
41 const NAME_PREFERRE_FAMILY = 16;
42 const NAME_PREFERRE_SUBFAMILY = 17;
43 const NAME_COMPAT_FULL_NAME = 18;
44 const NAME_SAMPLE_TEXT = 19;
45
46 static $nameIdCodes = array(
47 0 => "Copyright",
48 1 => "FontName",
49 2 => "FontSubfamily",
50 3 => "UniqueID",
51 4 => "FullName",
52 5 => "Version",
53 6 => "PostScriptName",
54 7 => "Trademark",
55 8 => "Manufacturer",
56 9 => "Designer",
57 10 => "Description",
58 11 => "FontVendorURL",
59 12 => "FontDesignerURL",
60 13 => "LicenseDescription",
61 14 => "LicenseURL",
62 // 15
63 16 => "PreferredFamily",
64 17 => "PreferredSubfamily",
65 18 => "CompatibleFullName",
66 19 => "SampleText",
67 );
68
69 static $platforms = array(
70 0 => "Unicode",
71 1 => "Macintosh",
72 // 2 => Reserved
73 3 => "Microsoft",
74 );
75
76 static $plaformSpecific = array(
77 // Unicode
78 0 => array(
79 0 => "Default semantics",
80 1 => "Version 1.1 semantics",
81 2 => "ISO 10646 1993 semantics (deprecated)",
82 3 => "Unicode 2.0 or later semantics",
83 ),
84
85 // Macintosh
86 1 => array(
87 0 => "Roman",
88 1 => "Japanese",
89 2 => "Traditional Chinese",
90 3 => "Korean",
91 4 => "Arabic",
92 5 => "Hebrew",
93 6 => "Greek",
94 7 => "Russian",
95 8 => "RSymbol",
96 9 => "Devanagari",
97 10 => "Gurmukhi",
98 11 => "Gujarati",
99 12 => "Oriya",
100 13 => "Bengali",
101 14 => "Tamil",
102 15 => "Telugu",
103 16 => "Kannada",
104 17 => "Malayalam",
105 18 => "Sinhalese",
106 19 => "Burmese",
107 20 => "Khmer",
108 21 => "Thai",
109 22 => "Laotian",
110 23 => "Georgian",
111 24 => "Armenian",
112 25 => "Simplified Chinese",
113 26 => "Tibetan",
114 27 => "Mongolian",
115 28 => "Geez",
116 29 => "Slavic",
117 30 => "Vietnamese",
118 31 => "Sindhi",
119 ),
120
121 // Microsoft
122 3 => array(
123 0 => "Symbol",
124 1 => "Unicode BMP (UCS-2)",
125 2 => "ShiftJIS",
126 3 => "PRC",
127 4 => "Big5",
128 5 => "Wansung",
129 6 => "Johab",
130 // 7 => Reserved
131 // 8 => Reserved
132 // 9 => Reserved
133 10 => "Unicode UCS-4",
134 ),
135 );
136
137 protected function _parse() {
138 $font = $this->getFont();
139
140 $tableOffset = $font->pos();
141
142 $data = $font->unpack(self::$header_format);
143
144 $records = array();
145 for ($i = 0; $i < $data["count"]; $i++) {
146 $record = new nameRecord();
147 $record_data = $font->unpack(nameRecord::$format);
148 $record->map($record_data);
149
150 $records[] = $record;
151 }
152
153 $names = array();
154 foreach ($records as $record) {
155 $font->seek($tableOffset + $data["stringOffset"] + $record->offset);
156 $s = $font->read($record->length);
157 $record->string = Font::UTF16ToUTF8($s);
158 $names[$record->nameID] = $record;
159 }
160
161 $data["records"] = $names;
162
163 $this->data = $data;
164 }
165
166 protected function _encode() {
167 $font = $this->getFont();
168
169 /** @var nameRecord[] $records */
170 $records = $this->data["records"];
171 $count_records = count($records);
172
173 $this->data["count"] = $count_records;
174 $this->data["stringOffset"] = 6 + $count_records * 12; // 6 => uint16 * 3, 12 => sizeof self::$record_format
175
176 $length = $font->pack(self::$header_format, $this->data);
177
178 $offset = 0;
179 foreach ($records as $record) {
180 $record->length = mb_strlen($record->getUTF16(), "8bit");
181 $record->offset = $offset;
182 $offset += $record->length;
183 $length += $font->pack(nameRecord::$format, (array)$record);
184 }
185
186 foreach ($records as $record) {
187 $str = $record->getUTF16();
188 $length += $font->write($str, mb_strlen($str, "8bit"));
189 }
190
191 return $length;
192 }
193 }