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
9 namespace FontLib\Table\Type;
11 use FontLib\Table\Table;
17 * @package php-font-lib
19 class name extends Table {
20 private static $header_format = array(
21 "format" => self::uint16,
22 "count" => self::uint16,
23 "stringOffset" => self::uint16,
26 const NAME_COPYRIGHT = 0;
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;
46 static $nameIdCodes = array(
53 6 => "PostScriptName",
58 11 => "FontVendorURL",
59 12 => "FontDesignerURL",
60 13 => "LicenseDescription",
63 16 => "PreferredFamily",
64 17 => "PreferredSubfamily",
65 18 => "CompatibleFullName",
69 static $platforms = array(
76 static $platformSpecific = 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",
89 2 => "Traditional Chinese",
112 25 => "Simplified Chinese",
124 1 => "Unicode BMP (UCS-2)",
133 10 => "Unicode UCS-4",
137 protected function _parse() {
138 $font = $this->getFont();
140 $tableOffset = $font->pos();
142 $data = $font->unpack(self::$header_format);
145 for ($i = 0; $i < $data["count"]; $i++) {
146 $record = new nameRecord();
147 $record_data = $font->unpack(nameRecord::$format);
148 $record->map($record_data);
150 $records[] = $record;
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;
161 $data["records"] = $names;
166 protected function _encode() {
167 $font = $this->getFont();
169 /** @var nameRecord[] $records */
170 $records = $this->data["records"];
171 $count_records = count($records);
173 $this->data["count"] = $count_records;
174 $this->data["stringOffset"] = 6 + $count_records * 12; // 6 => uint16 * 3, 12 => sizeof self::$record_format
176 $length = $font->pack(self::$header_format, $this->data);
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);
186 foreach ($records as $record) {
187 $str = $record->getUTF16();
188 $length += $font->write($str, mb_strlen($str, "8bit"));