Skip to content

Commit 49224c6

Browse files
committed
Add basic support for EOT font pasing (only header and basic info like name, version...)
Add various getters for font name, full name, copyright, version, etc
1 parent 7c15d5c commit 49224c6

File tree

6 files changed

+522
-275
lines changed

6 files changed

+522
-275
lines changed

classes/adobe_font_metrics.cls.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ function write($file, $encoding = null){
5252

5353
$records = $font->getData("name", "records");
5454
foreach($records as $id => $record) {
55-
if (!isset(Font_TrueType::$nameIdCodes[$id]) || preg_match("/[\r\n]/", $record->string)) {
55+
if (!isset(Font_Table_name::$nameIdCodes[$id]) || preg_match("/[\r\n]/", $record->string)) {
5656
continue;
5757
}
5858

59-
$this->addPair(Font_TrueType::$nameIdCodes[$id], $record->string);
59+
$this->addPair(Font_Table_name::$nameIdCodes[$id], $record->string);
6060
}
6161

6262
$os2 = $font->getData("OS/2");

classes/font_eot.cls.php

Lines changed: 79 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
require_once dirname(__FILE__)."/font_truetype.cls.php";
10+
require_once dirname(__FILE__)."/font_eot_header.cls.php";
1011

1112
/**
1213
* EOT font file.
@@ -16,43 +17,27 @@
1617
class Font_EOT extends Font_TrueType {
1718
private $origF;
1819
private $fileOffset = 0;
19-
20+
21+
/**
22+
* @var Font_EOT_Header
23+
*/
2024
public $header;
2125

2226
function parseHeader(){
23-
$this->header = $this->unpack(array(
24-
"EOTSize" => self::uint32,
25-
"FontDataSize" => self::uint32,
26-
"Version" => self::uint32,
27-
"Flags" => self::uint32,
28-
));
29-
30-
$this->header["FontPANOSE"] = $this->read(10);
31-
32-
$this->header += $this->unpack(array(
33-
"Charset" => self::uint8,
34-
"Italic" => self::uint8,
35-
"Weight" => self::uint32,
36-
"fsType" => self::uint16,
37-
"MagicNumber" => self::uint16,
38-
"UnicodeRange1" => self::uint32,
39-
"UnicodeRange2" => self::uint32,
40-
"UnicodeRange3" => self::uint32,
41-
"UnicodeRange4" => self::uint32,
42-
"CodePageRange1" => self::uint32,
43-
"CodePageRange2" => self::uint32,
44-
"CheckSumAdjustment" => self::uint32,
45-
"Reserved1" => self::uint32,
46-
"Reserved2" => self::uint32,
47-
"Reserved3" => self::uint32,
48-
"Reserved4" => self::uint32,
49-
"Padding1" => self::uint16,
50-
"FamilyNameSize" => self::uint16,
51-
));
27+
if (!empty($this->header)) {
28+
return;
29+
}
30+
31+
$this->seek(0);
32+
33+
$this->header = new Font_EOT_Header($this);
34+
$this->header->parse();
5235
}
5336

5437
function parse() {
55-
exit("EOT not supported yet");
38+
$this->parseHeader();
39+
40+
// TODO
5641
}
5742

5843
public function readUInt16() {
@@ -64,4 +49,67 @@ public function readUInt32() {
6449
$a = unpack('VV', $this->read(4));
6550
return $a['V'];
6651
}
52+
53+
/**
54+
* Get font copyright
55+
*
56+
* @return string|null
57+
*/
58+
function getFontCopyright(){
59+
return null;
60+
}
61+
62+
/**
63+
* Get font name
64+
*
65+
* @return string|null
66+
*/
67+
function getFontName(){
68+
return $this->header->data["FullName"];
69+
}
70+
71+
/**
72+
* Get font subfamily
73+
*
74+
* @return string|null
75+
*/
76+
function getFontSubfamily(){
77+
return $this->header->data["FamilyName"];
78+
}
79+
80+
/**
81+
* Get font subfamily ID
82+
*
83+
* @return string|null
84+
*/
85+
function getFontSubfamilyID(){
86+
return $this->header->data["FamilyName"];
87+
}
88+
89+
/**
90+
* Get font full name
91+
*
92+
* @return string|null
93+
*/
94+
function getFontFullName(){
95+
return $this->header->data["FullName"];
96+
}
97+
98+
/**
99+
* Get font version
100+
*
101+
* @return string|null
102+
*/
103+
function getFontVersion(){
104+
return $this->header->data["VersionName"];
105+
}
106+
107+
/**
108+
* Get font Postscript name
109+
*
110+
* @return string|null
111+
*/
112+
function getFontPostscriptName(){
113+
return null;
114+
}
67115
}

classes/font_eot_header.cls.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* @package php-font-lib
4+
* @link https://github.com/PhenX/php-font-lib
5+
* @author Fabien Ménager <[email protected]>
6+
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
7+
*/
8+
9+
require_once dirname(__FILE__)."/font_header.cls.php";
10+
11+
/**
12+
* TrueType font file header.
13+
*
14+
* @package php-font-lib
15+
*/
16+
class Font_EOT_Header extends Font_Header {
17+
protected $def = array(
18+
"format" => self::uint32,
19+
"numTables" => self::uint16,
20+
"searchRange" => self::uint16,
21+
"entrySelector" => self::uint16,
22+
"rangeShift" => self::uint16,
23+
);
24+
25+
public function parse(){
26+
$font = $this->font;
27+
28+
$this->data = $font->unpack(array(
29+
"EOTSize" => self::uint32,
30+
"FontDataSize" => self::uint32,
31+
"Version" => self::uint32,
32+
"Flags" => self::uint32,
33+
));
34+
35+
$this->data["FontPANOSE"] = $font->read(10);
36+
37+
$this->data += $font->unpack(array(
38+
"Charset" => self::uint8,
39+
"Italic" => self::uint8,
40+
"Weight" => self::uint32,
41+
"fsType" => self::uint16,
42+
"MagicNumber" => self::uint16,
43+
"UnicodeRange1" => self::uint32,
44+
"UnicodeRange2" => self::uint32,
45+
"UnicodeRange3" => self::uint32,
46+
"UnicodeRange4" => self::uint32,
47+
"CodePageRange1" => self::uint32,
48+
"CodePageRange2" => self::uint32,
49+
"CheckSumAdjustment" => self::uint32,
50+
"Reserved1" => self::uint32,
51+
"Reserved2" => self::uint32,
52+
"Reserved3" => self::uint32,
53+
"Reserved4" => self::uint32,
54+
"Padding1" => self::uint16,
55+
));
56+
57+
$this->readString("FamilyName");
58+
$this->data["Padding2"] = $font->readUInt16();
59+
$this->readString("StyleName");
60+
$this->data["Padding3"] = $font->readUInt16();
61+
$this->readString("VersionName");
62+
$this->data["Padding4"] = $font->readUInt16();
63+
$this->readString("FullName");
64+
}
65+
66+
private function readString($name) {
67+
$font = $this->font;
68+
$size = $font->readUInt16();
69+
70+
$this->data["{$name}Size"] = $size;
71+
$this->data[$name] = $font->read($size);
72+
}
73+
74+
public function encode(){
75+
//return $this->font->pack($this->def, $this->data);
76+
}
77+
}

classes/font_table_name.cls.php

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,117 @@ class Font_Table_name extends Font_Table {
1919
"count" => self::uint16,
2020
"stringOffset" => self::uint16,
2121
);
22+
23+
const NAME_COPYRIGHT = 0;
24+
const NAME_NAME = 1;
25+
const NAME_SUBFAMILY = 2;
26+
const NAME_SUBFAMILY_ID = 3;
27+
const NAME_FULL_NAME = 4;
28+
const NAME_VERSION = 5;
29+
const NAME_POSTSCRIPT_NAME = 6;
30+
const NAME_TRADEMARK = 7;
31+
const NAME_MANUFACTURER = 8;
32+
const NAME_DESIGNER = 9;
33+
const NAME_DESCRIPTION = 10;
34+
const NAME_VENDOR_URL = 11;
35+
const NAME_DESIGNER_URL = 12;
36+
const NAME_LICENSE = 13;
37+
const NAME_LICENSE_URL = 14;
38+
const NAME_PREFERRE_FAMILY = 16;
39+
const NAME_PREFERRE_SUBFAMILY = 17;
40+
const NAME_COMPAT_FULL_NAME = 18;
41+
const NAME_SAMPLE_TEXT = 18;
42+
43+
static $nameIdCodes = array(
44+
0 => "Copyright",
45+
1 => "FontName",
46+
2 => "FontSubfamily",
47+
3 => "UniqueID",
48+
4 => "FullName",
49+
5 => "Version",
50+
6 => "PostScriptName",
51+
7 => "Trademark",
52+
8 => "Manufacturer",
53+
9 => "Designer",
54+
10 => "Description",
55+
11 => "FontVendorURL",
56+
12 => "FontDesignerURL",
57+
13 => "LicenseDescription",
58+
14 => "LicenseURL",
59+
// 15
60+
16 => "PreferredFamily",
61+
17 => "PreferredSubfamily",
62+
18 => "CompatibleFullName",
63+
19 => "SampleText",
64+
);
65+
66+
static $platforms = array(
67+
0 => "Unicode",
68+
1 => "Macintosh",
69+
// 2 => Reserved
70+
3 => "Microsoft",
71+
);
72+
73+
static $plaformSpecific = array(
74+
// Unicode
75+
0 => array(
76+
0 => "Default semantics",
77+
1 => "Version 1.1 semantics",
78+
2 => "ISO 10646 1993 semantics (deprecated)",
79+
3 => "Unicode 2.0 or later semantics",
80+
),
81+
82+
// Macintosh
83+
1 => array(
84+
0 => "Roman",
85+
1 => "Japanese",
86+
2 => "Traditional Chinese",
87+
3 => "Korean",
88+
4 => "Arabic",
89+
5 => "Hebrew",
90+
6 => "Greek",
91+
7 => "Russian",
92+
8 => "RSymbol",
93+
9 => "Devanagari",
94+
10 => "Gurmukhi",
95+
11 => "Gujarati",
96+
12 => "Oriya",
97+
13 => "Bengali",
98+
14 => "Tamil",
99+
15 => "Telugu",
100+
16 => "Kannada",
101+
17 => "Malayalam",
102+
18 => "Sinhalese",
103+
19 => "Burmese",
104+
20 => "Khmer",
105+
21 => "Thai",
106+
22 => "Laotian",
107+
23 => "Georgian",
108+
24 => "Armenian",
109+
25 => "Simplified Chinese",
110+
26 => "Tibetan",
111+
27 => "Mongolian",
112+
28 => "Geez",
113+
29 => "Slavic",
114+
30 => "Vietnamese",
115+
31 => "Sindhi",
116+
),
117+
118+
// Microsoft
119+
3 => array(
120+
0 => "Symbol",
121+
1 => "Unicode BMP (UCS-2)",
122+
2 => "ShiftJIS",
123+
3 => "PRC",
124+
4 => "Big5",
125+
5 => "Wansung",
126+
6 => "Johab",
127+
// 7 => Reserved
128+
// 8 => Reserved
129+
// 9 => Reserved
130+
10 => "Unicode UCS-4",
131+
),
132+
);
22133

23134
protected function _parse(){
24135
$font = $this->getFont();

0 commit comments

Comments
 (0)