/var/www/hkosl.com/imusiccircle/webadmin/libraies/phenx/php-font-lib/classes/Font_Table_name.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
/**
 * @package php-font-lib
 * @link    https://github.com/PhenX/php-font-lib
 * @author  Fabien Ménager <fabien.menager@gmail.com>
 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
 */

require_once dirname(__FILE__) . "/Font_Table_name_Record.php";

/**
 * `name` font table.
 * 
 * @package php-font-lib
 */
class Font_Table_name extends Font_Table {
  private static 
$header_format = array(
    
"format"       => self::uint16,
    
"count"        => self::uint16,
    
"stringOffset" => self::uint16,
  );

  const 
NAME_COPYRIGHT          0;
  const 
NAME_NAME               1;
  const 
NAME_SUBFAMILY          2;
  const 
NAME_SUBFAMILY_ID       3;
  const 
NAME_FULL_NAME          4;
  const 
NAME_VERSION            5;
  const 
NAME_POSTSCRIPT_NAME    6;
  const 
NAME_TRADEMARK          7;
  const 
NAME_MANUFACTURER       8;
  const 
NAME_DESIGNER           9;
  const 
NAME_DESCRIPTION        10;
  const 
NAME_VENDOR_URL         11;
  const 
NAME_DESIGNER_URL       12;
  const 
NAME_LICENSE            13;
  const 
NAME_LICENSE_URL        14;
  const 
NAME_PREFERRE_FAMILY    16;
  const 
NAME_PREFERRE_SUBFAMILY 17;
  const 
NAME_COMPAT_FULL_NAME   18;
  const 
NAME_SAMPLE_TEXT        19;

  static 
$nameIdCodes = array(
    
0  => "Copyright",
    
1  => "FontName",
    
2  => "FontSubfamily",
    
3  => "UniqueID",
    
4  => "FullName",
    
5  => "Version",
    
6  => "PostScriptName",
    
7  => "Trademark",
    
8  => "Manufacturer",
    
9  => "Designer",
    
10 => "Description",
    
11 => "FontVendorURL",
    
12 => "FontDesignerURL",
    
13 => "LicenseDescription",
    
14 => "LicenseURL",
    
// 15
    
16 => "PreferredFamily",
    
17 => "PreferredSubfamily",
    
18 => "CompatibleFullName",
    
19 => "SampleText",
  );

  static 
$platforms = array(
    
=> "Unicode",
    
=> "Macintosh",
    
// 2 =>  Reserved
    
=> "Microsoft",
  );

  static 
$plaformSpecific = array(
    
// Unicode
    
=> array(
      
=> "Default semantics",
      
=> "Version 1.1 semantics",
      
=> "ISO 10646 1993 semantics (deprecated)",
      
=> "Unicode 2.0 or later semantics",
    ),

    
// Macintosh
    
=> array(
      
=> "Roman",
      
=> "Japanese",
      
=> "Traditional Chinese",
      
=> "Korean",
      
=> "Arabic",
      
=> "Hebrew",
      
=> "Greek",
      
=> "Russian",
      
=> "RSymbol",
      
=> "Devanagari",
      
10 => "Gurmukhi",
      
11 => "Gujarati",
      
12 => "Oriya",
      
13 => "Bengali",
      
14 => "Tamil",
      
15 => "Telugu",
      
16 => "Kannada",
      
17 => "Malayalam",
      
18 => "Sinhalese",
      
19 => "Burmese",
      
20 => "Khmer",
      
21 => "Thai",
      
22 => "Laotian",
      
23 => "Georgian",
      
24 => "Armenian",
      
25 => "Simplified Chinese",
      
26 => "Tibetan",
      
27 => "Mongolian",
      
28 => "Geez",
      
29 => "Slavic",
      
30 => "Vietnamese",
      
31 => "Sindhi",
    ),

    
// Microsoft
    
=> array(
      
=> "Symbol",
      
=> "Unicode BMP (UCS-2)",
      
=> "ShiftJIS",
      
=> "PRC",
      
=> "Big5",
      
=> "Wansung",
      
=> "Johab",
      
//  7 => Reserved
      //  8 => Reserved
      //  9 => Reserved
      
10 => "Unicode UCS-4",
    ),
  );
  
  protected function 
_parse(){
    
$font $this->getFont();
    
    
$tableOffset $font->pos();
    
    
$data $font->unpack(self::$header_format);
    
    
$records = array();
    for(
$i 0$i $data["count"]; $i++) {
      
$record = new Font_Table_name_Record();
      
$record_data $font->unpack(Font_Table_name_Record::$format);
      
$record->map($record_data);
      
      
$records[] = $record;
    }
    
    
$names = array();
    foreach(
$records as $record) {
      
$font->seek($tableOffset $data["stringOffset"] + $record->offset);
      
$s $font->read($record->length);
      
$record->string Font::UTF16ToUTF8($s);
      
$names[$record->nameID] = $record;
    }
    
    
$data["records"] = $names;
    
    
$this->data $data;
  }
  
  protected function 
_encode(){
    
$font $this->getFont();

    
/** @var Font_Table_name_Record[] $records */
    
$records $this->data["records"];
    
$count_records count($records);
    
    
$this->data["count"] = $count_records;
    
$this->data["stringOffset"] = $count_records 12// 6 => uint16 * 3, 12 => sizeof self::$record_format
    
    
$length $font->pack(self::$header_format$this->data);
    
    
$offset 0;
    foreach(
$records as $record) {
      
$record->length mb_strlen($record->getUTF16(), "8bit");
      
$record->offset $offset;
      
$offset += $record->length;
      
$length += $font->pack(Font_Table_name_Record::$format, (array)$record);
    }
    
    foreach(
$records as $record) {
      
$str $record->getUTF16();
      
$length += $font->write($strmb_strlen($str"8bit"));
    }
    
    return 
$length;
  }
}