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


PHP Font_Metrics类代码示例

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


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

示例1: create_pdf

function create_pdf($data, $filename = '', $stream = TRUE, $papersize = 'letter', $orientation = 'portrait')
{
    require_once "dompdf/dompdf_config.inc.php";
    $dompdf = new DOMPDF();
    $dompdf->load_html(' ');
    $dompdf->render();
    $canvas = $dompdf->get_canvas();
    $font = Font_Metrics::get_font("helvetica");
    $fontBold = Font_Metrics::get_font("helvetica", "bold");
    $row = 1;
    $y = 25;
    for ($i = 0; $i < count($data); $i++) {
        if (strpos($data[$i], "STUDENT") !== FALSE) {
            $canvas->text(40, $y += 15, $data[$i], $fontBold, 10, array(0, 0, 0));
        } elseif (strpos($data[$i], "COLLEGE") !== FALSE || strpos($data[$i], "UNIVERSITY") !== FALSE) {
            $canvas->text(40, $y += 15, $data[$i], $fontBold, 10, array(0, 0, 0));
        } elseif (strpos($data[$i], "__") !== FALSE || $data[$i] == " ") {
            $canvas->text(40, $y += 9, $data[$i], $font, 10, array(0, 0, 0));
        } else {
            $canvas->text(40, $y += 15, $data[$i], $font, 10, array(0, 0, 0));
        }
        if ($y > 730) {
            $dompdf->get_canvas()->new_page();
            $y = 50;
        }
    }
    if ($stream) {
        $dompdf->stream($filename . ".pdf");
    } else {
        return $dompdf->output();
    }
}
开发者ID:google-code-backups,项目名称:upm-oset,代码行数:32,代码来源:dompdf_helper.php

示例2: pdf_create

 function pdf_create($html, $filename, $stream = TRUE)
 {
     $dompdf = new DOMPDF();
     $dompdf->set_paper("A4");
     $dompdf->load_html($html);
     $dompdf->render();
     $canvas = $dompdf->get_canvas();
     // get height and width of page
     $w = $canvas->get_width();
     $h = $canvas->get_height();
     // get font
     $font = Font_Metrics::get_font("helvetica", "normal");
     $txtHeight = Font_Metrics::get_font_height($font, 7);
     //draw line for signature manager
     $mnline = $h - 10 * $txtHeight - 24;
     $colormn = array(0, 0, 0);
     $canvas->line(20, $mnline, $w - 470, $mnline, $colormn, 1);
     //text for signature Requestor/HOD
     $textmn = "Requestor/HOD";
     $widthmn = Font_Metrics::get_text_width($textmn, $font, 12);
     $canvas->text($w - $widthmn - 480, $mnline, $textmn, $font, 12);
     // draw a line along the bottom
     $y = $h - 2 * $txtHeight - 24;
     $color = array(0, 0, 0);
     $canvas->line(16, $y, $w - 16, $y, $color, 1);
     //draw line for GM/Manager
     //$canvas->line(270, $mnline, $w - 240, $mnline, $colormn, 1);
     $canvas->line(330, $mnline, $w - 170, $mnline, $colormn, 1);
     $texthr = "GM/Manager";
     $widthhr = Font_Metrics::get_text_width($texthr, $font, 12);
     $canvas->text($w - $widthmn - 160, $mnline, $texthr, $font, 12);
     //draw line for HR
     //$canvas->line(270, $mnline, $w - 240, $mnline, $colormn, 1);
     $canvas->line(180, $mnline, $w - 310, $mnline, $colormn, 1);
     $texthr = "HR";
     $widthhr = Font_Metrics::get_text_width($texthr, $font, 12);
     $canvas->text($w - $widthmn - 325, $mnline, $texthr, $font, 12);
     //draw line for IT Officer
     $canvas->line(470, $mnline, $w - 20, $mnline, $colormn, 1);
     $textIT = "IT Officer";
     $canvas->text($w - $widthmn - 30, $mnline, $textIT, $font, 12);
     // set page number on the left side
     //$canvas->page_text(16, $y, "Page: {PAGE_NUM} of {PAGE_COUNT}", $font, 8, $color);
     $canvas->page_text($w - 324, $y, "Page: {PAGE_NUM} of {PAGE_COUNT}", $font, 8, $color);
     // set additional text
     $text = "ESRNL PORTAL";
     $width = Font_Metrics::get_text_width($text, $font, 8);
     $canvas->text($w - $width - 16, $y, $text, $font, 8);
     if ($stream) {
         $dompdf->stream($filename . ".pdf");
     } else {
         $CI =& get_instance();
         $CI->load->helper('file');
         write_file($filename, $dompdf->output());
     }
 }
开发者ID:kielnevec,项目名称:PORTAL_Ingress_by_Fingertec,代码行数:56,代码来源:pdf.php

示例3: recalculate_width

 function recalculate_width()
 {
     $style = $this->get_style();
     $text = $this->get_text();
     $size = $style->font_size;
     $font = $style->font_family;
     $word_spacing = $style->length_in_pt($style->word_spacing);
     $char_spacing = $style->length_in_pt($style->letter_spacing);
     return $style->width = Font_Metrics::get_text_width($text, $font, $size, $word_spacing, $char_spacing);
 }
开发者ID:EfncoPlugins,项目名称:web-portal-lite-client-portal-secure-file-sharing-private-messaging,代码行数:10,代码来源:text_frame_decorator.cls.php

示例4: __construct

 /**
  * Class constructor
  *
  * @param Frame  $frame  the frame to decorate
  * @param DOMPDF $dompdf the document's dompdf object (required to resolve relative & remote urls)
  */
 function __construct(Frame $frame, DOMPDF $dompdf)
 {
     parent::__construct($frame, $dompdf);
     $url = $frame->get_node()->getAttribute("src");
     $debug_png = $dompdf->get_option("debug_png");
     if ($debug_png) {
         print '[__construct ' . $url . ']';
     }
     list($this->_image_url, , $this->_image_msg) = Image_Cache::resolve_url($url, $dompdf->get_protocol(), $dompdf->get_host(), $dompdf->get_base_path(), $dompdf);
     if (Image_Cache::is_broken($this->_image_url) && ($alt = $frame->get_node()->getAttribute("alt"))) {
         $style = $frame->get_style();
         $style->width = 4 / 3 * Font_Metrics::get_text_width($alt, $style->font_family, $style->font_size, $style->word_spacing);
         $style->height = Font_Metrics::get_font_height($style->font_family, $style->font_size);
     }
 }
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:21,代码来源:image_frame_decorator.cls.php

示例5: __construct

 /**
  * Class constructor
  *
  * @param Frame $frame the frame to decorate
  * @param DOMPDF $dompdf the document's dompdf object (required to resolve relative & remote urls)
  */
 function __construct(Frame $frame, DOMPDF $dompdf)
 {
     global $_dompdf_warnings;
     parent::__construct($frame, $dompdf);
     $url = $frame->get_node()->getAttribute("src");
     //debugpng
     if (DEBUGPNG) {
         print '[__construct ' . $url . ']';
     }
     list($this->_image_url, $this->_image_ext) = Image_Cache::resolve_url($url, $dompdf->get_protocol(), $dompdf->get_host(), $dompdf->get_base_path());
     if (strrpos($this->_image_url, DOMPDF_LIB_DIR . "/res/broken_image.png", 0) !== false && ($alt = $frame->get_node()->getAttribute("alt"))) {
         $style = $frame->get_style();
         $style->width = 4 / 3 * Font_Metrics::get_text_width($alt, $style->font_family, $style->font_size, $style->word_spacing);
         $style->height = Font_Metrics::get_font_height($style->font_family, $style->font_size);
     }
 }
开发者ID:macconsultinggroup,项目名称:WordPress,代码行数:22,代码来源:image_frame_decorator.cls.php

示例6: __construct

    /**
     * Class constructor
     *
     * @param Frame $frame the frame to decorate
     * @param DOMPDF $dompdf the document's dompdf object (required to resolve relative & remote urls)
     */
    function __construct(Frame $frame, DOMPDF $dompdf)
    {
        global $_dompdf_warnings;

        parent::__construct($frame, $dompdf);
        $url = $frame->get_node()->getAttribute("src");

        //debugpng
        if (DEBUGPNG) print '[__construct ' . $url . ']';

        list($this->_image_url, $type, $this->_image_msg) = Image_Cache::resolve_url($url,
            $dompdf->get_protocol(),
            $dompdf->get_host(),
            $dompdf->get_base_path());

        if (Image_Cache::is_broken($this->_image_url) &&
            $alt = $frame->get_node()->getAttribute("alt")
        ) {
            $style = $frame->get_style();
            $style->width = (4 / 3) * Font_Metrics::get_text_width($alt, $style->font_family, $style->font_size, $style->word_spacing);
            $style->height = Font_Metrics::get_font_height($style->font_family, $style->font_size);
        }
    }
开发者ID:rmuyinda,项目名称:dms-1,代码行数:29,代码来源:image_frame_decorator.cls.php

示例7: utf8_decode

					<p>Recomendaciones al Item de ensayo Nº VARIABLE</p>
					<br /><br />	<br /><br />	<br /><br />
					<section>
					<p>Recomendaciones para el cultivo de cambur  cobrero establecido:</p>
					<br />
					<p>VARIABLE</p>
					</section>

					<p align="center"> Nombre del ing</p>
					<br />
					<p align="center">Los resultados del análisis corresponden únicamente a las muestras consignadas.
 <br />El presente informe no presenta enmienda ni tachadura.</p>
</body>
</html>';
$html = utf8_decode($html);
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$canvas = $dompdf->get_canvas();
$footer = $canvas->open_object();
$w = $canvas->get_width();
$h = $canvas->get_height();
$font = Font_Metrics::get_font("arial", "bold");
$canvas->page_text($w - 553, $h - 78, "____________________________________________________________________________________________________________________________________________________________________", $font, 6, array(0, 0, 0));
$canvas->page_text($w - 550, $h - 70, "El Instituto Nacional de Investigaciones Agrícolas, antes FONAIAP,  es un instituto autónomo adscrito al Ministerio del Poder Popular para la Agricultura y Tierras,  dedicado a la investigación científica", $font, 6, array(0, 0, 0));
$canvas->page_text($w - 530, $h - 63, " agrícola, desarrollo tecnológico, asesoramiento y prestación de servicios especializados.  Dirección: Presidencia: Av. Universidad. Esquina El Chorro. Torre MCT. Piso 08. La Hoyada. Caracas -", $font, 6, array(0, 0, 0));
$canvas->page_text($w - 530, $h - 56, "Venezuela. Teléfonos (58 212) 5646466 - 5640355 - 5643862. Fax (58 212) 2103681.  Gerencia General: Av. Universidad, vía El Limón, Maracay, Estado Aragua, Teléfonos (58 243) 2404911 -", $font, 6, array(0, 0, 0));
$canvas->page_text($w - 500, $h - 49, " 2404642 - 2404772 – 2404762. Fax (58 243) 2404732. INIA Mérida: Av Urdaneta Edif. INIA-Mérida, Mérida estado Mérida. Telefax: (58 274) 2630090 / 2637941 ", $font, 6, array(0, 0, 0));
$canvas->close_object();
$canvas->add_object($footer, "all");
$dompdf->PDF::loadView("ejemplo.php", array("Attachment" => 0));
开发者ID:jorgcastellano,项目名称:inia,代码行数:31,代码来源:ejemplo1.php

示例8: text

  function text($x, $y, $text, $font, $size, $color = array(0,0,0), $word_spacing = 0, $char_spacing = 0, $angle = 0) {
    $fh = $this->_load_font($font);

    $this->_pdf->setfont($fh, $size);
    $this->_set_fill_color($color);

    $y = $this->y($y) - Font_Metrics::get_font_height($font, $size);

    $word_spacing = (float)$word_spacing;
    $char_spacing = (float)$char_spacing;
    $angle        = -(float)$angle;

    $this->_pdf->fit_textline($text, $x, $y, "rotate=$angle wordspacing=$word_spacing charspacing=$char_spacing ");

  }
开发者ID:hendrosteven,项目名称:f3-template,代码行数:15,代码来源:pdflib_adapter.cls.php

示例9: _parse_font_face

 /**
  * parse @font-face{} sections
  * http://www.w3.org/TR/css3-fonts/#the-font-face-rule
  *
  * @param string $str CSS @font-face rules
  *
  * @return Style
  */
 private function _parse_font_face($str)
 {
     $descriptors = $this->_parse_properties($str);
     preg_match_all("/(url|local)\\s*\\([\"\\']?([^\"\\'\\)]+)[\"\\']?\\)\\s*(format\\s*\\([\"\\']?([^\"\\'\\)]+)[\"\\']?\\))?/i", $descriptors->src, $src);
     $sources = array();
     $valid_sources = array();
     foreach ($src[0] as $i => $value) {
         $source = array("local" => strtolower($src[1][$i]) === "local", "uri" => $src[2][$i], "format" => $src[4][$i], "path" => build_url($this->_protocol, $this->_base_host, $this->_base_path, $src[2][$i]));
         if (!$source["local"] && in_array($source["format"], array("", "woff", "opentype", "truetype"))) {
             $valid_sources[] = $source;
         }
         $sources[] = $source;
     }
     // No valid sources
     if (empty($valid_sources)) {
         return;
     }
     $style = array("family" => $descriptors->get_font_family_raw(), "weight" => $descriptors->font_weight, "style" => $descriptors->font_style);
     Font_Metrics::register_font($style, $valid_sources[0]["path"]);
 }
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:28,代码来源:stylesheet.cls.php

示例10: get_min_max_width

 function get_min_max_width()
 {
     $frame = $this->_frame;
     $style = $frame->get_style();
     $this->_block_parent = $frame->find_block_parent();
     $line_width = $frame->get_containing_block("w");
     $str = $text = $frame->get_text();
     $size = $style->font_size;
     $font = $style->font_family;
     $word_spacing = $style->length_in_pt($style->word_spacing);
     $char_spacing = $style->length_in_pt($style->letter_spacing);
     switch ($style->white_space) {
         default:
         case "normal":
             $str = preg_replace(self::$_whitespace_pattern, " ", $str);
         case "pre-wrap":
         case "pre-line":
             $words = array_flip(preg_split("/[\\s-]+/u", $str, -1, PREG_SPLIT_DELIM_CAPTURE));
             array_walk($words, create_function('&$val,$str', '$val = Font_Metrics::get_text_width($str, "' . addslashes($font) . '", ' . $size . ', ' . $word_spacing . ', ' . $char_spacing . ');'));
             arsort($words);
             $min = reset($words);
             break;
         case "pre":
             $lines = array_flip(preg_split("/\n/u", $str));
             array_walk($lines, create_function('&$val,$str', '$val = Font_Metrics::get_text_width($str, "' . addslashes($font) . '", ' . $size . ', ' . $word_spacing . ', ' . $char_spacing . ');'));
             arsort($lines);
             $min = reset($lines);
             break;
         case "nowrap":
             $min = Font_Metrics::get_text_width($this->_collapse_white_space($str), $font, $size, $word_spacing, $char_spacing);
             break;
     }
     switch ($style->white_space) {
         default:
         case "normal":
         case "nowrap":
             $str = preg_replace(self::$_whitespace_pattern, " ", $text);
             break;
         case "pre-line":
             $str = preg_replace("/[ \t]+/u", " ", $text);
         case "pre-wrap":
             $lines = array_flip(preg_split("/\n/", $text));
             array_walk($lines, create_function('&$val,$str', '$val = Font_Metrics::get_text_width($str, "' . $font . '", ' . $size . ', ' . $word_spacing . ', ' . $char_spacing . ');'));
             arsort($lines);
             reset($lines);
             $str = key($lines);
             break;
     }
     $max = Font_Metrics::get_text_width($str, $font, $size, $word_spacing, $char_spacing);
     $delta = $style->length_in_pt(array($style->margin_left, $style->border_left_width, $style->padding_left, $style->padding_right, $style->border_right_width, $style->margin_right), $line_width);
     $min += $delta;
     $max += $delta;
     return $this->_min_max_cache = array($min, $max, "min" => $min, "max" => $max);
 }
开发者ID:EfncoPlugins,项目名称:web-portal-lite-client-portal-secure-file-sharing-private-messaging,代码行数:54,代码来源:text_frame_reflower.cls.php

示例11: text

 function text($x, $y, $text, $font, $size, $color = array(0, 0, 0), $adjust = 0, $angle = 0, $blend = "Normal", $opacity = 1.0)
 {
     list($r, $g, $b) = $color;
     $this->_pdf->setColor($r, $g, $b);
     $this->_set_line_transparency($blend, $opacity);
     $this->_set_fill_transparency($blend, $opacity);
     $font .= ".afm";
     $this->_pdf->selectFont($font);
     $this->_pdf->addText($x, $this->y($y) - Font_Metrics::get_font_height($font, $size), $size, utf8_decode($text), $angle, $adjust);
 }
开发者ID:SkMamtajuddin,项目名称:bamboo-invoice,代码行数:10,代码来源:cpdf_adapter.cls.php

示例12: render

 /**
  * @param Text_Frame_Decorator $frame
  */
 function render(Frame $frame)
 {
     $text = $frame->get_text();
     if (trim($text) === "") {
         return;
     }
     $style = $frame->get_style();
     list($x, $y) = $frame->get_position();
     $cb = $frame->get_containing_block();
     if (($ml = $style->margin_left) === "auto" || $ml === "none") {
         $ml = 0;
     }
     if (($pl = $style->padding_left) === "auto" || $pl === "none") {
         $pl = 0;
     }
     if (($bl = $style->border_left_width) === "auto" || $bl === "none") {
         $bl = 0;
     }
     $x += $style->length_in_pt(array($ml, $pl, $bl), $cb["w"]);
     $font = $style->font_family;
     $size = $frame_font_size = $style->font_size;
     $height = $style->height;
     $word_spacing = $frame->get_text_spacing() + $style->length_in_pt($style->word_spacing);
     $char_spacing = $style->length_in_pt($style->letter_spacing);
     $width = $style->width;
     /*$text = str_replace(
         array("{PAGE_NUM}"),
         array($this->_canvas->get_page_number()), 
         $text
       );*/
     $this->_canvas->text($x, $y, $text, $font, $size, $style->color, $word_spacing, $char_spacing);
     $line = $frame->get_containing_line();
     // FIXME Instead of using the tallest frame to position,
     // the decoration, the text should be well placed
     if (false && $line->tallest_frame) {
         $base_frame = $line->tallest_frame;
         $style = $base_frame->get_style();
         $size = $style->font_size;
         $height = $line->h * ($size / $style->line_height);
     }
     $line_thickness = $size * self::DECO_THICKNESS;
     $underline_offset = $size * self::UNDERLINE_OFFSET;
     $overline_offset = $size * self::OVERLINE_OFFSET;
     $linethrough_offset = $size * self::LINETHROUGH_OFFSET;
     $underline_position = -0.08;
     if ($this->_canvas instanceof CPDF_Adapter) {
         $cpdf_font = $this->_canvas->get_cpdf()->fonts[$style->font_family];
         if (isset($cpdf_font["UnderlinePosition"])) {
             $underline_position = $cpdf_font["UnderlinePosition"] / 1000;
         }
         if (isset($cpdf_font["UnderlineThickness"])) {
             $line_thickness = $size * ($cpdf_font["UnderlineThickness"] / 1000);
         }
     }
     $descent = $size * $underline_position;
     $base = $size;
     // Handle text decoration:
     // http://www.w3.org/TR/CSS21/text.html#propdef-text-decoration
     // Draw all applicable text-decorations.  Start with the root and work our way down.
     $p = $frame;
     $stack = array();
     while ($p = $p->get_parent()) {
         $stack[] = $p;
     }
     while (isset($stack[0])) {
         $f = array_pop($stack);
         if (($text_deco = $f->get_style()->text_decoration) === "none") {
             continue;
         }
         $deco_y = $y;
         //$line->y;
         $color = $f->get_style()->color;
         switch ($text_deco) {
             default:
                 continue;
             case "underline":
                 $deco_y += $base - $descent + $underline_offset + $line_thickness / 2;
                 break;
             case "overline":
                 $deco_y += $overline_offset + $line_thickness / 2;
                 break;
             case "line-through":
                 $deco_y += $base * 0.7 + $linethrough_offset;
                 break;
         }
         $dx = 0;
         $x1 = $x - self::DECO_EXTENSION;
         $x2 = $x + $width + $dx + self::DECO_EXTENSION;
         $this->_canvas->line($x1, $deco_y, $x2, $deco_y, $color, $line_thickness);
     }
     if (DEBUG_LAYOUT && DEBUG_LAYOUT_LINES) {
         $text_width = Font_Metrics::get_text_width($text, $font, $frame_font_size);
         $this->_debug_layout(array($x, $y, $text_width + ($line->wc - 1) * $word_spacing, $frame_font_size), "orange", array(0.5, 0.5));
     }
 }
开发者ID:darshanmodi2010,项目名称:dompdf,代码行数:98,代码来源:text_renderer.cls.php

示例13: __construct

 /**
  * Class constructor
  *
  * @param string $paper The size of paper to use ({@link PDFLib_Adapter::$PAPER_SIZES})
  * @param string $orientation The orientation of the document (either 'landscape' or 'portrait')
  */
 function __construct($paper = "letter", $orientation = "portrait")
 {
     if (is_array($paper)) {
         $size = $paper;
     } else {
         if (array_key_exists(strtolower($paper), self::$PAPER_SIZES)) {
             $size = self::$PAPER_SIZES[$paper];
         } else {
             $size = self::$PAPER_SIZES["letter"];
         }
     }
     if (strtolower($orientation) == "landscape") {
         $a = $size[3];
         $size[3] = $size[2];
         $size[2] = $a;
     }
     $this->_width = $size[2];
     $this->_height = $size[3];
     $this->_pdf = new PDFLib();
     $this->_pdf->set_info("Creator", "DOMPDF Converter");
     $this->_pdf->set_info("Date", date("Y-m-d"));
     if (self::$IN_MEMORY) {
         $this->_pdf->begin_document("", "");
     } else {
         $this->_file = tempnam(DOMPDF_TEMP_DIR, "dompdf_tmp_");
         $this->_pdf->begin_document($this->_file, "");
     }
     $this->_pdf->set_parameter("topdown", "true");
     $this->_pdf->begin_page_ext($this->_width, $this->_height, "");
     $this->_page_number = $this->_page_count = 1;
     $this->_page_text = null;
     $this->_imgs = array();
     $this->_fonts = array();
     $this->_objs = array();
     // Set up font paths
     $families = Font_Metrics::get_font_families();
     foreach ($families as $family => $files) {
         foreach ($files as $style => $file) {
             $face = basename($file);
             // Prefer ttfs to afms
             if (file_exists($file . ".ttf")) {
                 $file .= ".ttf";
             } else {
                 if (file_exists($file . ".TTF")) {
                     $file .= ".TTF";
                 } else {
                     if (file_exists($file . ".pfb")) {
                         $file .= ".pfb";
                     } else {
                         if (file_exists($file . ".PFB")) {
                             $file .= ".PFB";
                         } else {
                             continue;
                         }
                     }
                 }
             }
             $this->_pdf->set_parameter("FontOutline", "\\{{$face}\\}=\\{{$file}\\}");
         }
     }
 }
开发者ID:andrewroth,项目名称:c4c_intranet,代码行数:67,代码来源:pdflib_adapter.cls.php

示例14: 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

示例15: get_font_family

 /**
  * Getter for the 'font-family' CSS property.
  *
  * Uses the {@link Font_Metrics} class to resolve the font family into an
  * actual font file.
  *
  * @link http://www.w3.org/TR/CSS21/fonts.html#propdef-font-family
  * @return string
  */
 function get_font_family()
 {
     // Select the appropriate font.  First determine the subtype, then check
     // the specified font-families for a candidate.
     // Resolve font-weight
     $weight = $this->__get("font_weight");
     if (is_numeric($weight)) {
         if ($weight < 700) {
             $weight = "normal";
         } else {
             $weight = "bold";
         }
     } else {
         if ($weight == "bold" || $weight == "bolder") {
             $weight = "bold";
         } else {
             $weight = "normal";
         }
     }
     // Resolve font-style
     $font_style = $this->__get("font_style");
     if ($weight == "bold" && $font_style == "italic") {
         $subtype = "bold_italic";
     } else {
         if ($weight == "bold" && $font_style != "italic") {
             $subtype = "bold";
         } else {
             if ($weight != "bold" && $font_style == "italic") {
                 $subtype = "italic";
             } else {
                 $subtype = "normal";
             }
         }
     }
     // Resolve the font family
     $families = explode(",", $this->_props["font_family"]);
     reset($families);
     $font = null;
     while (current($families)) {
         list(, $family) = each($families);
         $font = Font_Metrics::get_font($family, $subtype);
         if ($font) {
             return $font;
         }
     }
     throw new DOMPDF_Exception("Unable to find a suitable font replacement for: '" . $this->_props["font_family"] . "'");
 }
开发者ID:artre,项目名称:study,代码行数:56,代码来源:style.cls.php


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