Skip to content

Commit a67b76e

Browse files
committed
Improve EOT values
All composite glyphs were not drawn completely Add a zoom on the glyphs view Add $font->getWeight for OpenType and EOT
1 parent e2e68fc commit a67b76e

File tree

5 files changed

+63
-32
lines changed

5 files changed

+63
-32
lines changed

classes/Font_EOT.php

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
* @package php-font-lib
1616
*/
1717
class Font_EOT extends Font_TrueType {
18+
const TTEMBED_SUBSET = 0x00000001;
19+
const TTEMBED_TTCOMPRESSED = 0x00000004;
20+
const TTEMBED_FAILIFVARIATIONSIMULATED = 0x00000010;
21+
const TTMBED_EMBEDEUDC = 0x00000020;
22+
const TTEMBED_VALIDATIONTESTS = 0x00000040; // Deprecated
23+
const TTEMBED_WEBOBJECT = 0x00000080;
24+
const TTEMBED_XORENCRYPTDATA = 0x10000000;
25+
1826
/**
1927
* @var Font_EOT_Header
2028
*/
@@ -32,7 +40,28 @@ function parseHeader(){
3240
function parse() {
3341
$this->parseHeader();
3442

35-
// TODO
43+
$flags = $this->header->data["Flags"];
44+
45+
if ($flags & self::TTEMBED_TTCOMPRESSED) {
46+
$mtx_version = $this->readUInt8();
47+
$mtx_copy_limit = $this->readUInt8() << 16 | $this->readUInt8() << 8 | $this->readUInt8();
48+
$mtx_offset_1 = $this->readUInt8() << 16 | $this->readUInt8() << 8 | $this->readUInt8();
49+
$mtx_offset_2 = $this->readUInt8() << 16 | $this->readUInt8() << 8 | $this->readUInt8();
50+
51+
/*
52+
var_dump("$mtx_version $mtx_copy_limit $mtx_offset_1 $mtx_offset_2");
53+
54+
$pos = $this->pos();
55+
$size = $mtx_offset_1 - $pos;
56+
var_dump("pos: $pos");
57+
var_dump("size: $size");*/
58+
}
59+
60+
if ($flags & self::TTEMBED_XORENCRYPTDATA) {
61+
// Process XOR
62+
}
63+
64+
// TODO Read font data ...
3665
}
3766

3867
/**
@@ -70,7 +99,7 @@ function getFontCopyright(){
7099
* @return string|null
71100
*/
72101
function getFontName(){
73-
return $this->header->data["FullName"];
102+
return $this->header->data["FamilyName"];
74103
}
75104

76105
/**
@@ -79,7 +108,7 @@ function getFontName(){
79108
* @return string|null
80109
*/
81110
function getFontSubfamily(){
82-
return $this->header->data["FamilyName"];
111+
return $this->header->data["StyleName"];
83112
}
84113

85114
/**
@@ -88,7 +117,7 @@ function getFontSubfamily(){
88117
* @return string|null
89118
*/
90119
function getFontSubfamilyID(){
91-
return $this->header->data["FamilyName"];
120+
return $this->header->data["StyleName"];
92121
}
93122

94123
/**
@@ -109,6 +138,15 @@ function getFontVersion(){
109138
return $this->header->data["VersionName"];
110139
}
111140

141+
/**
142+
* Get font weight
143+
*
144+
* @return string|null
145+
*/
146+
function getFontWeight(){
147+
return $this->header->data["Weight"];
148+
}
149+
112150
/**
113151
* Get font Postscript name
114152
*

classes/Font_EOT_Header.php

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@
1616
* @property Font_EOT $font
1717
*/
1818
class Font_EOT_Header extends Font_Header {
19-
const TTEMBED_SUBSET = 0x00000001;
20-
const TTEMBED_TTCOMPRESSED = 0x00000004;
21-
const TTEMBED_FAILIFVARIATIONSIMULATED = 0x00000010;
22-
const TTMBED_EMBEDEUDC = 0x00000020;
23-
const TTEMBED_VALIDATIONTESTS = 0x00000040; // Deprecated
24-
const TTEMBED_WEBOBJECT = 0x00000080;
25-
const TTEMBED_XORENCRYPTDATA = 0x10000000;
26-
2719
protected $def = array(
2820
"format" => self::uint32,
2921
"numTables" => self::uint16,
@@ -102,21 +94,6 @@ public function parse(){
10294
if (!empty($this->data["RootString"])) {
10395
$this->data["RootString"] = explode("\0", $this->data["RootString"]);
10496
}
105-
106-
$flags = $this->data["Flags"];
107-
108-
if ($flags & self::TTEMBED_TTCOMPRESSED) {
109-
$mtx_version = $font->readUInt8();
110-
$mtx_copy_limit = $font->readUInt8() << 16 | $font->readUInt8() << 8 | $font->readUInt8();
111-
$mtx_offset_1 = $font->readUInt8() << 16 | $font->readUInt8() << 8 | $font->readUInt8();
112-
$mtx_offset_2 = $font->readUInt8() << 16 | $font->readUInt8() << 8 | $font->readUInt8();
113-
}
114-
115-
if ($flags & self::TTEMBED_XORENCRYPTDATA) {
116-
// Process XOR
117-
}
118-
119-
// TODO Read font data ...
12097
}
12198

12299
private function readString($name) {

classes/Font_Glyph_Outline_Simple.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ public function getSVGContours($points = null){
255255
$path = "";
256256

257257
if (!$points) {
258+
if (empty($this->points)) {
259+
$this->parseData();
260+
}
261+
258262
$points = $this->points;
259263
}
260264

classes/Font_Table_glyf.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,15 @@ public function toHTML(){
7676
$s = "<h3>"."Only the first $n simple glyphs are shown (".count($this->data)." total)
7777
<div class='glyph-view simple'>Simple glyph</div>
7878
<div class='glyph-view composite'>Composite glyph</div>
79+
Zoom: <input type='range' value='100' max='400' onchange='Glyph.resize(this.value)' />
7980
</h3>
8081
<script>
81-
Glyph.ratio = $ratio;
82-
Glyph.head = $head_json;
83-
Glyph.os2 = $os2_json;
84-
Glyph.hmtx = $hmtx_json;
82+
Glyph.ratio = $ratio;
83+
Glyph.head = $head_json;
84+
Glyph.os2 = $os2_json;
85+
Glyph.hmtx = $hmtx_json;
86+
Glyph.width = $width;
87+
Glyph.height = $height;
8588
</script>";
8689

8790
foreach($this->data as $g => $glyph) {
@@ -112,7 +115,7 @@ public function toHTML(){
112115
<br />
113116
<canvas width='$width' height='$height' id='glyph-$g'></canvas>
114117
</div>
115-
<script>Glyph.draw(\$('#glyph-$g'), $shape_json, $g)</script>";
118+
<script>Glyph.glyphs.push([$g,$shape_json]);</script>";
116119
}
117120

118121
return $s;

classes/Font_TrueType.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,15 @@ function getFontVersion(){
432432
return $this->getNameTableString(Font_Table_name::NAME_VERSION);
433433
}
434434

435+
/**
436+
* Get font weight
437+
*
438+
* @return string|null
439+
*/
440+
function getFontWeight(){
441+
return $this->getTableObject("OS/2")->data["usWeightClass"];
442+
}
443+
435444
/**
436445
* Get font Postscript name
437446
*

0 commit comments

Comments
 (0)