#!/usr/bin/php * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library in the file LICENSE.LGPL; if not, write to the * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA * * Alternatively, you may distribute this software under the terms of the * PHP License, version 3.0 or later. A copy of this license should have * been distributed with this file in the file LICENSE.PHP . If this is not * the case, you can obtain a copy at http://www.php.net/license/3_0.txt. * * The latest version of DOMPDF might be available at: * http://www.dompdf.com/ * * @link http://www.dompdf.com/ * @copyright 2004 Benj Carson * @author Benj Carson * @package dompdf */ require_once("dompdf_config.inc.php"); /** * @access private */ define("_TTF2AFM", escapeshellarg(TTF2AFM) . " -a -GAef -OW "); if ( !file_exists(TTF2AFM) ) { die("Unable to locate the ttf2afm / ttf2pt1 executable (checked " . TTF2AFM . ").\n"); } /** * Display command line usage * */ function usage() { echo << 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(); if ( $ext === ".pfb" || $ext === ".ttf" || $ext === ".otf" ) { // Copy the files to the font directory. foreach ($fonts as $var => $src) { if ( is_null($src) ) { $entry[$var] = DOMPDF_FONT_DIR . basename($normal); continue; } // Verify that the fonts exist and are readable if ( !is_readable($src) ) throw new DOMPDF_Exception("Requested font '$pathname' 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 '" . DOMPDF_FONT_DIR . "$dest'."); $entry[$var] = $dest; } } else throw new DOMPDF_Exception("Unable to process fonts of type '$ext'."); // If the extension is a ttf, try and convert the fonts to afm too if ( $ext === ".ttf" || $ext === ".otf" ) { foreach ($fonts as $var => $font) { if ( is_null($font) ) { $entry[$var] = DOMPDF_FONT_DIR . mb_substr(basename($normal), 0, -4); continue; } $dest = DOMPDF_FONT_DIR . mb_substr(basename($font), 0 , -4); $stdout = ( ( strpos(PHP_OS, "WIN") === false ) ? " >/dev/null" : " 2>&1" ); $command = _TTF2AFM . " " . escapeshellarg($font) . " " . escapeshellarg($dest) . $stdout; echo "Generating .afm for $font...\n"; //echo $command . "\n"; exec( $command, $output, $ret ); $entry[$var] = $dest; } } // FIXME: how to generate afms from pfb? // Store the fonts in the lookup table Font_Metrics::set_font_family($fontname, $entry); // Save the changes Font_Metrics::save_font_families(); } // If installing system fonts (may take a long time) if ( $_SERVER["argv"][1] === "system_fonts" ) { $fonts = Font_Metrics::get_system_fonts(); var_dump($fonts); foreach ( $fonts as $family => $files ) { echo " >> Installing '$family'... \n"; if ( !isset($files["normal"]) ) { echo "No 'normal' style font file\n"; } else { install_font_family( $family, @$files["normal"], @$files["bold"], @$files["italic"], @$files["bold_italic"]); echo "Done !\n"; } echo "\n"; } } else { call_user_func_array("install_font_family", array_slice($_SERVER["argv"], 1)); }