Skip to content

Commit

Permalink
If glyph were not in the font when doing font subset, warnings were t…
Browse files Browse the repository at this point in the history
…hrown
  • Loading branch information
PhenX committed Feb 4, 2012
1 parent a55c5ca commit 115e2c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions classes/font.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* @package php-font-lib
*/
class Font {
static $debug = false;

/**
* @param string $file The font file
* @return Font_TrueType $file
Expand Down Expand Up @@ -56,6 +58,7 @@ public static function load($file) {
}

static function d($str) {
if (!self::$debug) return;
echo "$str\n";
}

Expand Down
18 changes: 13 additions & 5 deletions classes/font_truetype.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ function parse() {

function utf8toUnicode($str) {
$len = strlen($str);
$out = array();

for ($i = 0; $i < $len; $i++) {
$uni = -1;
Expand Down Expand Up @@ -292,8 +293,8 @@ function lookupGlyph($gid, &$gids, &$newGlyphOffsets, $glyfOffset, $indexToLoc,
}

function setSubset($subset) {
if ( is_array($subset) ) {
$subset = implode("", $subset);
if ( !is_array($subset) ) {
$subset = $this->utf8toUnicode($subset);
}

$subtable = null;
Expand All @@ -307,9 +308,11 @@ function setSubset($subset) {
if (!$subtable) return;

$gids = array();

$chars = $this->utf8toUnicode($subset);
foreach($chars as $code) {
foreach($subset as $code) {
if (!isset($subtable["glyphIndexArray"][$code])) {
continue;
}

$gids[$code] = $subtable["glyphIndexArray"][$code];
}

Expand All @@ -321,6 +324,11 @@ function setSubset($subset) {
$newGlyphOffsets = array();

foreach($gids as $code => $gid) {
if ($gid === null) {
unset($gids[$code]);
continue;
}

$_newGlyphOffsets = array();
$this->lookupGlyph($gid, $gids, $_newGlyphOffsets, $glyfOffset, $indexToLoc, $gidToCid);

Expand Down

0 comments on commit 115e2c3

Please sign in to comment.