Skip to content

Commit 24ac4ef

Browse files
committed
Add platformID/platformSpecificID/languageID support to getNameTableString
1 parent a1681e9 commit 24ac4ef

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

src/FontLib/AdobeFontMetrics.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ function write($file, $encoding = null) {
5454
$this->addPair("EncodingScheme", $encoding_scheme);
5555

5656
$records = $font->getData("name", "records");
57-
foreach ($records as $id => $record) {
57+
foreach ($records as $uniqueIdentifier => $record) {
58+
$id = end(explode(',', $uniqueIdentifier));
5859
if (!isset(name::$nameIdCodes[$id]) || preg_match("/[\r\n]/", $record->string)) {
5960
continue;
6061
}

src/FontLib/Table/Type/name.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,16 @@ protected function _parse() {
160160

161161
$encoding = null;
162162
switch ($record->platformID) {
163+
case 1:
164+
$encoding = mb_detect_encoding($record->stringRaw, array('UTF-8', 'ASCII', 'GB2312', 'GB18030', 'GBK', 'SJIS', 'BIG-5'));
165+
break;
163166
case 3:
164167
switch ($record->platformSpecificID) {
168+
case 1:
169+
if (\array_key_exists("GBK", $system_encodings)) {
170+
$encoding = "GBK";
171+
}
172+
break;
165173
case 2:
166174
if (\array_key_exists("SJIS", $system_encodings)) {
167175
$encoding = "SJIS";
@@ -185,19 +193,19 @@ protected function _parse() {
185193
}
186194
break;
187195
}
188-
if ($encoding === null) {
196+
if ($encoding === null || $encoding === false) {
189197
$encoding = "UTF-16";
190198
}
191199

192200
$record->string = mb_convert_encoding($record->stringRaw, "UTF-8", $encoding);
201+
193202
if (strpos($record->string, "\0") !== false) {
194203
$record->string = str_replace("\0", "", $record->string);
195204
}
196-
$names[$record->nameID] = $record;
205+
$names["{$record->platformID},{$record->platformSpecificID},{$record->languageID},{$record->nameID}"] = $record;
197206
}
198207

199208
$data["records"] = $names;
200-
201209
$this->data = $data;
202210
}
203211

src/FontLib/TrueType/File.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ private function uniord (string $c, string $encoding = null) {
169169

170170
function getTable() {
171171
$this->parseTableEntries();
172-
173172
return $this->directory;
174173
}
175174

@@ -392,7 +391,6 @@ function parseTableEntries() {
392391
if (!empty($this->directory)) {
393392
return;
394393
}
395-
396394
if (empty($this->header->data["numTables"])) {
397395
return;
398396
}
@@ -504,53 +502,53 @@ function getNameTableString($nameID) {
504502
*
505503
* @return string|null
506504
*/
507-
function getFontCopyright() {
508-
return $this->getNameTableString(name::NAME_COPYRIGHT);
505+
function getFontCopyright($platformID, $platformSpecificID, $languageID) {
506+
return $this->getNameTableString("{$platformID},{$platformSpecificID},{$languageID}," . name::NAME_COPYRIGHT);
509507
}
510508

511509
/**
512510
* Get font name
513511
*
514512
* @return string|null
515513
*/
516-
function getFontName() {
517-
return $this->getNameTableString(name::NAME_NAME);
514+
function getFontName($platformID, $platformSpecificID, $languageID) {
515+
return $this->getNameTableString("{$platformID},{$platformSpecificID},{$languageID}," . name::NAME_NAME);
518516
}
519517

520518
/**
521519
* Get font subfamily
522520
*
523521
* @return string|null
524522
*/
525-
function getFontSubfamily() {
526-
return $this->getNameTableString(name::NAME_SUBFAMILY);
523+
function getFontSubfamily($platformID, $platformSpecificID, $languageID) {
524+
return $this->getNameTableString("{$platformID},{$platformSpecificID},{$languageID}," . name::NAME_SUBFAMILY);
527525
}
528526

529527
/**
530528
* Get font subfamily ID
531529
*
532530
* @return string|null
533531
*/
534-
function getFontSubfamilyID() {
535-
return $this->getNameTableString(name::NAME_SUBFAMILY_ID);
532+
function getFontSubfamilyID($platformID, $platformSpecificID, $languageID) {
533+
return $this->getNameTableString("{$platformID},{$platformSpecificID},{$languageID}," . name::NAME_SUBFAMILY_ID);
536534
}
537535

538536
/**
539537
* Get font full name
540538
*
541539
* @return string|null
542540
*/
543-
function getFontFullName() {
544-
return $this->getNameTableString(name::NAME_FULL_NAME);
541+
function getFontFullName($platformID, $platformSpecificID, $languageID) {
542+
return $this->getNameTableString("{$platformID},{$platformSpecificID},{$languageID}," . name::NAME_FULL_NAME);
545543
}
546544

547545
/**
548546
* Get font version
549547
*
550548
* @return string|null
551549
*/
552-
function getFontVersion() {
553-
return $this->getNameTableString(name::NAME_VERSION);
550+
function getFontVersion($platformID, $platformSpecificID, $languageID) {
551+
return $this->getNameTableString("{$platformID},{$platformSpecificID},{$languageID}," . name::NAME_VERSION);
554552
}
555553

556554
/**
@@ -567,8 +565,8 @@ function getFontWeight() {
567565
*
568566
* @return string|null
569567
*/
570-
function getFontPostscriptName() {
571-
return $this->getNameTableString(name::NAME_POSTSCRIPT_NAME);
568+
function getFontPostscriptName($platformID, $platformSpecificID, $languageID) {
569+
return $this->getNameTableString("{$platformID},{$platformSpecificID},{$languageID}," . name::NAME_POSTSCRIPT_NAME);
572570
}
573571

574572
function reduce() {

0 commit comments

Comments
 (0)