当前位置: 首页>>代码示例>>PHP>>正文


PHP Font::load方法代码示例

本文整理汇总了PHP中Font::load方法的典型用法代码示例。如果您正苦于以下问题:PHP Font::load方法的具体用法?PHP Font::load怎么用?PHP Font::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Font的用法示例。


在下文中一共展示了Font::load方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: register_font

 static function register_font($style, $remote_file)
 {
     $fontname = mb_strtolower($style["family"]);
     $families = Font_Metrics::get_font_families();
     $entry = array();
     if (isset($families[$fontname])) {
         $entry = $families[$fontname];
     }
     $local_file = DOMPDF_FONT_DIR . md5($remote_file);
     $cache_entry = $local_file;
     $local_file .= ".ttf";
     $style_string = Font_Metrics::get_type("{$style['weight']} {$style['style']}");
     if (!isset($entry[$style_string])) {
         $entry[$style_string] = $cache_entry;
         Font_Metrics::set_font_family($fontname, $entry);
         // Download the remote file
         if (!is_file($local_file)) {
             file_put_contents($local_file, file_get_contents($remote_file));
         }
         $font = Font::load($local_file);
         if (!$font) {
             return false;
         }
         $font->parse();
         $font->saveAdobeFontMetrics("{$cache_entry}.ufm");
         // Save the changes
         Font_Metrics::save_font_families();
     }
     return true;
 }
开发者ID:skyosev,项目名称:OpenCart-Overclocked,代码行数:30,代码来源:font_metrics.cls.php

示例2: install_font_family

/**
 * Installs a new font family
 *
 * This function maps a font-family name to a font.  It tries to locate the
 * bold, italic, and bold italic versions of the font as well.  Once the
 * files are located, ttf versions of the font are copied to the fonts
 * directory.  Changes to the font lookup table are saved to the cache.
 *
 * @param string $fontname the font-family name
 * @param string $normal the filename of the normal face font subtype
 * @param string $bold   the filename of the bold face font subtype
 * @param string $italic the filename of the italic face font subtype
 * @param string $bold_italic the filename of the bold italic face font subtype
 */
function install_font_family($fontname, $normal, $bold = null, $italic = null, $bold_italic = null)
{
    Font_Metrics::init();
    // Check if the base filename is readable
    if (!is_readable($normal)) {
        throw new DOMPDF_Exception("Unable to read '{$normal}'.");
    }
    $dir = dirname($normal);
    $basename = basename($normal);
    $last_dot = strrpos($basename, '.');
    if ($last_dot !== false) {
        $file = substr($basename, 0, $last_dot);
        $ext = strtolower(substr($basename, $last_dot));
    } else {
        $file = $basename;
        $ext = '';
    }
    if (!in_array($ext, array(".ttf", ".otf"))) {
        throw new DOMPDF_Exception("Unable to process fonts of type '{$ext}'.");
    }
    // Try $file_Bold.$ext etc.
    $path = "{$dir}/{$file}";
    $patterns = array("bold" => array("_Bold", "b", "B", "bd", "BD"), "italic" => array("_Italic", "i", "I"), "bold_italic" => array("_Bold_Italic", "bi", "BI", "ib", "IB"));
    foreach ($patterns as $type => $_patterns) {
        if (!isset(${$type}) || !is_readable(${$type})) {
            foreach ($_patterns as $_pattern) {
                if (is_readable("{$path}{$_pattern}{$ext}")) {
                    ${$type} = "{$path}{$_pattern}{$ext}";
                    break;
                }
            }
            if (is_null(${$type})) {
                echo "Unable to find {$type} face file.\n";
            }
        }
    }
    $fonts = compact("normal", "bold", "italic", "bold_italic");
    $entry = array();
    // Copy the files to the font directory.
    foreach ($fonts as $var => $src) {
        if (is_null($src)) {
            $entry[$var] = DOMPDF_FONT_DIR . mb_substr(basename($normal), 0, -4);
            continue;
        }
        // Verify that the fonts exist and are readable
        if (!is_readable($src)) {
            throw new DOMPDF_Exception("Requested font '{$src}' is not readable");
        }
        $dest = DOMPDF_FONT_DIR . basename($src);
        if (!is_writeable(dirname($dest))) {
            throw new DOMPDF_Exception("Unable to write to destination '{$dest}'.");
        }
        echo "Copying {$src} to {$dest}...\n";
        if (!copy($src, $dest)) {
            throw new DOMPDF_Exception("Unable to copy '{$src}' to '{$dest}'");
        }
        $entry_name = mb_substr($dest, 0, -4);
        echo "Generating Adobe Font Metrics for {$entry_name}...\n";
        $font_obj = Font::load($dest);
        $font_obj->saveAdobeFontMetrics("{$entry_name}.ufm");
        $entry[$var] = $entry_name;
    }
    // Store the fonts in the lookup table
    Font_Metrics::set_font_family($fontname, $entry);
    // Save the changes
    Font_Metrics::save_font_families();
}
开发者ID:fredcido,项目名称:simuweb,代码行数:81,代码来源:load_font.php

示例3: basename

 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
 */
$fontfile = null;
if (isset($_GET["fontfile"])) {
    $fontfile = basename($_GET["fontfile"]);
    $fontfile = "../fonts/{$fontfile}";
}
if (!file_exists($fontfile)) {
    return;
}
$name = isset($_GET["name"]) ? $_GET["name"] : null;
if (isset($_POST["subset"])) {
    $subset = $_POST["subset"];
    ob_start();
    require_once "../classes/Font.php";
    $font = Font::load($fontfile);
    $font->parse();
    $font->setSubset($subset);
    $font->reduce();
    $new_filename = basename($fontfile);
    $new_filename = substr($new_filename, 0, -4) . "-subset." . substr($new_filename, -3);
    header("Content-Type: font/truetype");
    header("Content-Disposition: attachment; filename=\"{$new_filename}\"");
    $tmp = tempnam(sys_get_temp_dir(), "fnt");
    $font->open($tmp, Font_Binary_Stream::modeWrite);
    $font->encode(array("OS/2"));
    $font->close();
    ob_end_clean();
    readfile($tmp);
    unlink($tmp);
    return;
开发者ID:alvarobfdev,项目名称:applog,代码行数:31,代码来源:make_subset.php

示例4: number_format

  $stream->w($type, $data);
  $stream->seek(0);
  $new_data = $stream->r($type);
  
  if ($new_data !== $data) {
    echo "NOT OK \t $data \t => $new_data<br />";
  }
  else {
    echo "OK $type<br />";
  }
}*/
// font RW
$filename = "../fonts/DejaVuSansMono.ttf";
$filename_out = "{$filename}.2.ttf";
Font::$debug = true;
$font = Font::load($filename);
$font->parse();
$font->setSubset("(.apbiI,mn");
$font->reduce();
$font->open($filename_out, Font_Binary_Stream::modeWrite);
$font->encode(array("OS/2"));
?>

File size: <?php 
echo number_format(filesize($filename_out), 0, ".", " ");
?>
 bytes
Memory: <?php 
echo memory_get_peak_usage(true) / 1024;
?>
KB
开发者ID:hilmysyarif,项目名称:sisfito,代码行数:31,代码来源:test.php

示例5: selectFont


//.........这里部分代码省略.........
                 }
                 $this->addMessage('selectFont: FirstChar = ' . $firstChar);
                 $this->addMessage('selectFont: LastChar = ' . $lastChar);
                 $widthid = -1;
                 if (!$font['isUnicode']) {
                     // With Unicode, widths array isn't used
                     $this->numObj++;
                     $this->o_contents($this->numObj, 'new', 'raw');
                     $this->objects[$this->numObj]['c'] .= '[' . implode(' ', $widths) . ']';
                     $widthid = $this->numObj;
                 }
                 $missing_width = 500;
                 $stemV = 70;
                 if (isset($font['MissingWidth'])) {
                     $missing_width = $font['MissingWidth'];
                 }
                 if (isset($font['StdVW'])) {
                     $stemV = $font['StdVW'];
                 } elseif (isset($font['Weight']) && preg_match('!(bold|black)!i', $font['Weight'])) {
                     $stemV = 120;
                 }
                 // load the pfb file, and put that into an object too.
                 // note that pdf supports only binary format type 1 font files, though there is a
                 // simple utility to convert them from pfa to pfb.
                 if (!$this->isUnicode || $fbtype !== 'ttf' || empty($this->stringSubsets)) {
                     $data = file_get_contents($fbfile);
                 } else {
                     require_once dirname(__FILE__) . "/php-font-lib/classes/font.cls.php";
                     $this->stringSubsets[$fontName][] = 32;
                     // Force space if not in yet
                     $subset = $this->stringSubsets[$fontName];
                     sort($subset);
                     // Load font
                     $font_obj = Font::load($fbfile);
                     $font_obj->parse();
                     // Define subset
                     $font_obj->setSubset($subset);
                     $font_obj->reduce();
                     // Write new font
                     $tmp_name = "{$fbfile}.tmp." . sprintf("%u", crc32(implode($subset)));
                     $font_obj->open($tmp_name, Font_Binary_Stream::modeWrite);
                     $font_obj->encode(array("OS/2"));
                     $font_obj->close();
                     // Parse the new font to get cid2gid and widths
                     $font_obj = Font::load($tmp_name);
                     // Find Unicode char map table
                     $subtable = null;
                     foreach ($font_obj->getData("cmap", "subtables") as $_subtable) {
                         if ($_subtable["platformID"] == 0 || $_subtable["platformID"] == 3 && $_subtable["platformSpecificID"] == 1) {
                             $subtable = $_subtable;
                             break;
                         }
                     }
                     if ($subtable) {
                         $glyphIndexArray = $subtable["glyphIndexArray"];
                         $hmtx = $font_obj->getData("hmtx");
                         unset($glyphIndexArray[0xffff]);
                         $cidtogid = str_pad('', max(array_keys($glyphIndexArray)) * 2 + 1, "");
                         $font['CIDWidths'] = array();
                         foreach ($glyphIndexArray as $cid => $gid) {
                             if ($cid >= 0 && $cid < 0xffff && $gid) {
                                 $cidtogid[$cid * 2] = chr($gid >> 8);
                                 $cidtogid[$cid * 2 + 1] = chr($gid & 0xff);
                             }
                             $width = $font_obj->normalizeFUnit(isset($hmtx[$gid]) ? $hmtx[$gid][0] : $hmtx[0][0]);
                             $font['CIDWidths'][$cid] = $width;
开发者ID:rmuyinda,项目名称:dms-1,代码行数:67,代码来源:class.pdf.php

示例6: install_fonts

 static function install_fonts($files)
 {
     $names = array();
     foreach ($files as $file) {
         $font = Font::load($file);
         $records = $font->getData("name", "records");
         $type = self::get_type($records[2]);
         $names[mb_strtolower($records[1])][$type] = $file;
     }
     return $names;
 }
开发者ID:voks,项目名称:accounting,代码行数:11,代码来源:font_metrics.cls.php

示例7: selectFont


//.........这里部分代码省略.........
                             }
                         }
                     }
                 }
                 if ($font['isUnicode']) {
                     $font['CIDWidths'] = $cid_widths;
                 }
                 $this->addMessage('selectFont: FirstChar = ' . $firstChar);
                 $this->addMessage('selectFont: LastChar = ' . $lastChar);
                 $widthid = -1;
                 if (!$font['isUnicode']) {
                     $this->numObj++;
                     $this->o_contents($this->numObj, 'new', 'raw');
                     $this->objects[$this->numObj]['c'] .= '[' . implode(' ', $widths) . ']';
                     $widthid = $this->numObj;
                 }
                 $missing_width = 500;
                 $stemV = 70;
                 if (isset($font['MissingWidth'])) {
                     $missing_width = $font['MissingWidth'];
                 }
                 if (isset($font['StdVW'])) {
                     $stemV = $font['StdVW'];
                 } elseif (isset($font['Weight']) && preg_match('!(bold|black)!i', $font['Weight'])) {
                     $stemV = 120;
                 }
                 if (!$this->isUnicode || $fbtype !== 'ttf' || empty($this->stringSubsets)) {
                     $data = file_get_contents($fbfile);
                 } else {
                     require_once dirname(__FILE__) . "/php-font-lib/classes/font.cls.php";
                     $this->stringSubsets[$fontName][] = 32;
                     $subset = $this->stringSubsets[$fontName];
                     sort($subset);
                     $font_obj = Font::load($fbfile);
                     $font_obj->parse();
                     $font_obj->setSubset($subset);
                     $font_obj->reduce();
                     $tmp_name = "{$fbfile}.tmp." . sprintf("%u", crc32(implode($subset)));
                     $font_obj->open($tmp_name, Font_Binary_Stream::modeWrite);
                     $font_obj->encode(array("OS/2"));
                     $font_obj->close();
                     $font_obj = Font::load($tmp_name);
                     $subtable = null;
                     foreach ($font_obj->getData("cmap", "subtables") as $_subtable) {
                         if ($_subtable["platformID"] == 0 || $_subtable["platformID"] == 3 && $_subtable["platformSpecificID"] == 1) {
                             $subtable = $_subtable;
                             break;
                         }
                     }
                     if ($subtable) {
                         $glyphIndexArray = $subtable["glyphIndexArray"];
                         $hmtx = $font_obj->getData("hmtx");
                         unset($glyphIndexArray[0xffff]);
                         $cidtogid = str_pad('', max(array_keys($glyphIndexArray)) * 2 + 1, "");
                         $font['CIDWidths'] = array();
                         foreach ($glyphIndexArray as $cid => $gid) {
                             if ($cid >= 0 && $cid < 0xffff && $gid) {
                                 $cidtogid[$cid * 2] = chr($gid >> 8);
                                 $cidtogid[$cid * 2 + 1] = chr($gid & 0xff);
                             }
                             $width = $font_obj->normalizeFUnit(isset($hmtx[$gid]) ? $hmtx[$gid][0] : $hmtx[0][0]);
                             $font['CIDWidths'][$cid] = $width;
                         }
                         $font['CIDtoGID'] = base64_encode(gzcompress($cidtogid));
                         $font['CIDtoGID_Compressed'] = true;
                         $data = file_get_contents($tmp_name);
开发者ID:EfncoPlugins,项目名称:web-portal-lite-client-portal-secure-file-sharing-private-messaging,代码行数:67,代码来源:class.pdf.php


注:本文中的Font::load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。