Example #1
0
function GetInfoFromTrueType($file, $embed, $subset, $map)
{
    // Return information from a TrueType font
    try {
        $ttf = new TTFParser($file);
        $ttf->Parse();
    } catch (Exception $e) {
        Error($e->getMessage());
    }
    if ($embed) {
        if (!$ttf->embeddable) {
            Error('Font license does not allow embedding');
        }
        if ($subset) {
            $chars = array();
            foreach ($map as $v) {
                if ($v['name'] != '.notdef') {
                    $chars[] = $v['uv'];
                }
            }
            $ttf->Subset($chars);
            $info['Data'] = $ttf->Build();
        } else {
            $info['Data'] = file_get_contents($file);
        }
        $info['OriginalSize'] = strlen($info['Data']);
    }
    $k = 1000 / $ttf->unitsPerEm;
    $info['FontName'] = $ttf->postScriptName;
    $info['Bold'] = $ttf->bold;
    $info['ItalicAngle'] = $ttf->italicAngle;
    $info['IsFixedPitch'] = $ttf->isFixedPitch;
    $info['Ascender'] = round($k * $ttf->typoAscender);
    $info['Descender'] = round($k * $ttf->typoDescender);
    $info['UnderlineThickness'] = round($k * $ttf->underlineThickness);
    $info['UnderlinePosition'] = round($k * $ttf->underlinePosition);
    $info['FontBBox'] = array(round($k * $ttf->xMin), round($k * $ttf->yMin), round($k * $ttf->xMax), round($k * $ttf->yMax));
    $info['CapHeight'] = round($k * $ttf->capHeight);
    $info['MissingWidth'] = round($k * $ttf->glyphs[0]['w']);
    $widths = array_fill(0, 256, $info['MissingWidth']);
    foreach ($map as $c => $v) {
        if ($v['name'] != '.notdef') {
            if (isset($ttf->chars[$v['uv']])) {
                $id = $ttf->chars[$v['uv']];
                $w = $ttf->glyphs[$id]['w'];
                $widths[$c] = round($k * $w);
            } else {
                Warning('Character ' . $v['name'] . ' is missing');
            }
        }
    }
    $info['Widths'] = $widths;
    return $info;
}
Example #2
0
function GetInfoFromTrueType($file, $embed, $map)
{
    // Return informations from a TrueType font
    $ttf = new TTFParser();
    $ttf->Parse($file);
    if ($embed) {
        if (!$ttf->Embeddable) {
            Error('Font license does not allow embedding');
        }
        $info['Data'] = file_get_contents($file);
        $info['OriginalSize'] = filesize($file);
    }
    $k = 1000 / $ttf->unitsPerEm;
    $info['FontName'] = $ttf->postScriptName;
    $info['Bold'] = $ttf->Bold;
    $info['ItalicAngle'] = $ttf->italicAngle;
    $info['IsFixedPitch'] = $ttf->isFixedPitch;
    $info['Ascender'] = round($k * $ttf->typoAscender);
    $info['Descender'] = round($k * $ttf->typoDescender);
    $info['UnderlineThickness'] = round($k * $ttf->underlineThickness);
    $info['UnderlinePosition'] = round($k * $ttf->underlinePosition);
    $info['FontBBox'] = array(round($k * $ttf->xMin), round($k * $ttf->yMin), round($k * $ttf->xMax), round($k * $ttf->yMax));
    $info['CapHeight'] = round($k * $ttf->capHeight);
    $info['MissingWidth'] = round($k * $ttf->widths[0]);
    $widths = array_fill(0, 256, $info['MissingWidth']);
    for ($c = 0; $c <= 255; $c++) {
        if ($map[$c]['name'] != '.notdef') {
            $uv = $map[$c]['uv'];
            if (isset($ttf->chars[$uv])) {
                $w = $ttf->widths[$ttf->chars[$uv]];
                $widths[$c] = round($k * $w);
            } else {
                Warning('Character ' . $map[$c]['name'] . ' is missing');
            }
        }
    }
    $info['Widths'] = $widths;
    return $info;
}