Skip to content

Commit 8b3d42d

Browse files
committed
Merge remote-tracking branch 'origin/master'
Conflicts: www/font_list.php
2 parents aa930bc + 77938be commit 8b3d42d

16 files changed

+90
-49
lines changed

classes/Font_Glyph_Outline.php

+4
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,8 @@ function encode(){
100100
function getSVGContours() {
101101
// Inherit
102102
}
103+
104+
function getGlyphIDs(){
105+
// Inherit
106+
}
103107
}

classes/Font_Glyph_Outline_Composite.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function parseData(){
126126
function encode(){
127127
$font = $this->getFont();
128128

129-
$gids = array_values($font->getSubset());
129+
$gids = $font->getSubset();
130130

131131
$size = $font->writeInt16(-1);
132132
$size += $font->writeFWord($this->xMin);

classes/Font_Table_cmap.php

+25-12
Original file line numberDiff line numberDiff line change
@@ -115,26 +115,39 @@ protected function _parse(){
115115

116116
function _encode(){
117117
$font = $this->getFont();
118+
118119
$subset = $font->getSubset();
120+
$glyphIndexArray = $font->getUnicodeCharMap();
121+
122+
$newGlyphIndexArray = array();
123+
foreach ($glyphIndexArray as $code => $gid) {
124+
$new_gid = array_search($gid, $subset);
125+
if ($new_gid !== false) {
126+
$newGlyphIndexArray[$code] = $new_gid;
127+
}
128+
}
129+
130+
ksort($newGlyphIndexArray); // Sort by char code
119131

120132
$segments = array();
121-
122-
$i = count($segments)-1;
123-
$j = $i+1;
124-
$prevCode = 0;
125-
$glyphIndexArray = array();
126133

127-
foreach($subset as $code => $gid) {
128-
if ($prevCode + 1 != $code) {
134+
$i = -1;
135+
$prevCode = 0xFFFF;
136+
$prevGid = 0xFFFF;
137+
138+
foreach($newGlyphIndexArray as $code => $gid) {
139+
if (
140+
$prevCode + 1 != $code ||
141+
$prevGid + 1 != $gid
142+
) {
129143
$i++;
130144
$segments[$i] = array();
131145
}
132146

133-
$segments[$i][] = array($code, $j);
147+
$segments[$i][] = array($code, $gid);
134148

135-
$glyphIndexArray[] = $code;
136-
$j++;
137149
$prevCode = $code;
150+
$prevGid = $gid;
138151
}
139152

140153
$segments[][] = array(0xFFFF, 0xFFFF);
@@ -184,7 +197,7 @@ function _encode(){
184197
"endCode" => $endCode,
185198
"idDelta" => $idDelta,
186199
"idRangeOffset" => $idRangeOffset,
187-
"glyphIndexArray" => $glyphIndexArray,
200+
"glyphIndexArray" => $newGlyphIndexArray,
188201
)
189202
);
190203

@@ -217,7 +230,7 @@ function _encode(){
217230
$length += $font->w(array(self::uint16, $segCount), $subtable["startCode"]);
218231
$length += $font->w(array(self::int16, $segCount), $subtable["idDelta"]);
219232
$length += $font->w(array(self::uint16, $segCount), $subtable["idRangeOffset"]);
220-
$length += $font->w(array(self::uint16, $segCount), $subtable["glyphIndexArray"]);
233+
$length += $font->w(array(self::uint16, $segCount), array_values($subtable["glyphIndexArray"]));
221234

222235
$after_subtable = $font->pos();
223236

classes/Font_Table_glyf.php

+12-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function getGlyphIDs($gids = array()){
4242
}
4343
}
4444

45-
return array_merge($gids, $glyphIDs);
45+
return array_unique(array_merge($gids, $glyphIDs));
4646
}
4747

4848
public function toHTML(){
@@ -108,12 +108,20 @@ public function toHTML(){
108108
$name = isset($names[$g]) ? $names[$g] : sprintf("uni%04x", $char);
109109
$char = $char ? "&#{$glyphIndexArray[$g]};" : "";
110110

111-
$s .= "<div"." class='glyph-view $type'>
111+
$s .= "<div class='glyph-view $type' id='glyph-$g'>
112112
<span class='glyph-id'>$g</span>
113113
<span class='char'>$char</span>
114114
<span class='char-name'>$name</span>
115-
<br />
116-
<canvas width='$width' height='$height' id='glyph-$g'></canvas>
115+
";
116+
117+
if ($type == "composite") {
118+
foreach ($glyph->getGlyphIDs() as $_id) {
119+
$s .= "<a href='#glyph-$_id' class='glyph-component-id'>$_id</a> ";
120+
}
121+
}
122+
123+
$s .= "<br />
124+
<canvas width='$width' height='$height' id='glyph-canvas-$g'></canvas>
117125
</div>
118126
<script>Glyph.glyphs.push([$g,$shape_json]);</script>";
119127
}

classes/Font_Table_name.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
77
*/
88

9-
require_once dirname(__FILE__) . "/Font_Table_name_Tecord.php";
9+
require_once dirname(__FILE__) . "/Font_Table_name_Record.php";
1010

1111
/**
1212
* `name` font table.

classes/Font_TrueType.php

+15-26
Original file line numberDiff line numberDiff line change
@@ -169,45 +169,34 @@ function setSubset($subset) {
169169

170170
$subset = array_unique($subset);
171171

172-
$subtable = null;
173-
foreach($this->getData("cmap", "subtables") as $_subtable) {
174-
if ($_subtable["platformID"] == 0 || $_subtable["platformID"] == 3 && $_subtable["platformSpecificID"] == 1) {
175-
$subtable = $_subtable;
176-
break;
177-
}
178-
}
172+
$glyphIndexArray = $this->getUnicodeCharMap();
179173

180-
if (!$subtable) return;
174+
if (!$glyphIndexArray) {
175+
return;
176+
}
181177

182178
$gids = array(
183-
0 => 0 // Required glyph
179+
0, // .notdef
180+
1, // .null
184181
);
182+
185183
foreach($subset as $code) {
186-
if (!isset($subtable["glyphIndexArray"][$code])) {
184+
if (!isset($glyphIndexArray[$code])) {
187185
continue;
188186
}
189-
190-
$gids[$code] = $subtable["glyphIndexArray"][$code];
187+
188+
$gid = $glyphIndexArray[$code];
189+
$gids[$gid] = $gid;
191190
}
192191

193-
// add compound glyphs
194192
/** @var Font_Table_glyf $glyf */
195193
$glyf = $this->getTableObject("glyf");
196194
$gids = $glyf->getGlyphIDs($gids);
197195

198-
$gids_from_codes = array(
199-
0 => 0 // Required glyph
200-
);
201-
foreach ($subtable["glyphIndexArray"] as $code => $gid) {
202-
if (in_array($gid, $gids)) {
203-
$gids_from_codes[$code] = $gid;
204-
}
205-
}
206-
207-
ksort($gids_from_codes);
196+
sort($gids);
208197

209-
$this->glyph_subset = $gids_from_codes;
210-
$this->glyph_all = $subtable["glyphIndexArray"];
198+
$this->glyph_subset = $gids;
199+
$this->glyph_all = array_values($glyphIndexArray); // FIXME
211200
}
212201

213202
function getSubset() {
@@ -284,7 +273,7 @@ function parseTableEntries(){
284273
/** @var Font_Table_Directory_Entry $entry */
285274
$entry = new $class($this);
286275
$entry->parse();
287-
276+
288277
$this->directory[$entry->tag] = $entry;
289278
}
290279
}

www/css/style.css

+11
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,14 @@ hr {
108108
.glyph-view canvas {
109109
background: #fff;
110110
}
111+
112+
.glyph-view:target {
113+
outline: 2px dotted red;
114+
}
115+
.glyph-view:target canvas {
116+
background: #ddffdd;
117+
}
118+
119+
.glyph-view a.glyph-component-id {
120+
font-size: 0.8em;
121+
}

www/font_explorer.html

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4+
<meta charset="utf-8" />
45
<title>PHP font lib - Font explorer</title>
56
</head>
67
<frameset rows="28,*">

www/font_info.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
?><!DOCTYPE html>
99
<html>
1010
<head>
11+
<meta charset="utf-8" />
12+
<title>Font information</title>
1113
<link rel="stylesheet" href="css/style.css" />
1214
<link rel="stylesheet" href="css/blitzer/jquery-ui-1.8.14.custom.css" />
1315
<script type="text/javascript" src="js/jquery-1.5.1.min.js"></script>
1416
<script type="text/javascript" src="js/jquery-ui-1.8.14.custom.min.js"></script>
15-
<script type="text/javascript" src="js/glyph.js?v=4"></script>
17+
<script type="text/javascript" src="js/glyph.js?v=5"></script>
1618
<script type="text/javascript">
1719
$(function() {
1820
$("#tabs").tabs({

www/font_list.php

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
?><!DOCTYPE html>
99
<html>
1010
<head>
11+
<meta charset="utf-8" />
1112
<link rel="stylesheet" href="css/style.css" />
1213
</head>
1314
<body>

www/header.html

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4+
<meta charset="utf-8" />
45
<link rel="stylesheet" href="css/style.css" />
56
</head>
67
<body style="background: #eee;">

www/js/glyph.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ var Glyph = {
155155
},
156156
drawAll: function(){
157157
$.each(Glyph.glyphs, function(i, g){
158-
Glyph.draw($('#glyph-'+g[0]), g[1], g[0]);
158+
Glyph.draw($('#glyph-canvas-'+g[0]), g[1], g[0]);
159159
});
160160
},
161161
resize: function(value){

www/make_subset.php

+12-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
$fontfile = "../fonts/$fontfile";
1313
}
1414

15-
$name = isset($_GET["name"]) ? $_GET["name"] : null;
15+
if (!file_exists($fontfile)) {
16+
return;
17+
}
18+
19+
$name = isset($_GET["name"]) ? $_GET["name"] : null;
1620

1721
if (isset($_POST["subset"])) {
1822
$subset = $_POST["subset"];
@@ -26,9 +30,12 @@
2630

2731
$font->setSubset($subset);
2832
$font->reduce();
33+
34+
$new_filename = basename($fontfile);
35+
$new_filename = substr($new_filename, 0, -4)."-subset.".substr($new_filename, -3);
2936

30-
header('Content-Type: font/truetype');
31-
header('Content-Disposition: attachment; filename="subset.ttf"');
37+
header("Content-Type: font/truetype");
38+
header("Content-Disposition: attachment; filename=\"$new_filename\"");
3239

3340
$tmp = tempnam(sys_get_temp_dir(), "fnt");
3441
$font->open($tmp, Font_Binary_Stream::modeWrite);
@@ -45,6 +52,8 @@
4552
<!DOCTYPE html>
4653
<html>
4754
<head>
55+
<meta charset="utf-8" />
56+
<title>Subset maker</title>
4857
<link rel="stylesheet" href="css/style.css" />
4958
</head>
5059
<body>

www/readme.html

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4+
<meta charset="utf-8" />
45
<link rel="stylesheet" href="css/style.css" />
56
</head>
67
<body>

www/test.php

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4+
<meta charset="utf-8" />
45
<link rel="stylesheet" href="css/style.css" />
56
<link rel="stylesheet" href="css/blitzer/jquery-ui-1.8.14.custom.css" />
67
</head>

0 commit comments

Comments
 (0)