return intval($value); } ?> <a name="setup"> </a> <h2>Font manager</h2> <ul> <li style="list-style-image: url('images/star_02.gif');"><a href="#installed-fonts">Installed fonts</a></li> <li style="list-style-image: url('images/star_02.gif');"><a href="#install-fonts">Install new fonts</a></li> </ul> <h3 id="installed-fonts">Installed fonts</h3> <?php $fonts = Font_Metrics::get_font_families(); $extensions = array("ttf", "afm", "afm.php", "ufm", "ufm.php"); ?> <button onclick="$('#clear-font-cache-message').load('controller.php?cmd=clear-font-cache', function(){ location.reload(); })">Clear font cache</button> <span id="clear-font-cache-message"></span> <table class="setup"> <tr> <th rowspan="2">Font family</th> <th rowspan="2">Variants</th> <th colspan="6">File versions</th> </tr> <tr> <th>TTF</th> <th>AFM</th>
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; }
/** * Class constructor * * @param mixed $paper The size of paper to use either a string (see {@link CPDF_Adapter::$PAPER_SIZES}) or * an array(xmin,ymin,xmax,ymax) * @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 (isset(self::$PAPER_SIZES[mb_strtolower($paper)])) { $size = self::$PAPER_SIZES[$paper]; } else { $size = self::$PAPER_SIZES["letter"]; } } if (mb_strtolower($orientation) == "landscape") { $a = $size[3]; $size[3] = $size[2]; $size[2] = $a; } $this->_width = $size[2] - $size[0]; $this->_height = $size[3] - $size[1]; $this->_pdf = new PDFLib(); if (defined("DOMPDF_PDFLIB_LICENSE")) { $this->_pdf->set_parameter("license", DOMPDF_PDFLIB_LICENSE); } $this->_pdf->set_parameter("textformat", "utf8"); $this->_pdf->set_parameter("fontwarning", "false"); $this->_pdf->set_info("Creator", "DOMPDF Converter"); // Silence pedantic warnings about missing TZ settings if (function_exists("date_default_timezone_get")) { $tz = @date_default_timezone_get(); date_default_timezone_set("UTC"); $this->_pdf->set_info("Date", date("Y-m-d")); date_default_timezone_set($tz); } else { $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->begin_page_ext($this->_width, $this->_height, ""); $this->_page_number = $this->_page_count = 1; $this->_page_text = array(); $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}\\}"); } } }
/** * 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}\\}"); } } }
/** * Class constructor * * @param mixed $paper The size of paper to use either a string (see {@link CPDF_Adapter::$PAPER_SIZES}) or * an array(xmin,ymin,xmax,ymax) * @param string $orientation The orientation of the document (either 'landscape' or 'portrait') * @param DOMPDF $dompdf */ function __construct($paper = "letter", $orientation = "portrait", DOMPDF $dompdf) { if ( is_array($paper) ) { $size = $paper; } else if ( isset(self::$PAPER_SIZES[mb_strtolower($paper)]) ) { $size = self::$PAPER_SIZES[mb_strtolower($paper)]; } else { $size = self::$PAPER_SIZES["letter"]; } if ( mb_strtolower($orientation) === "landscape" ) { list($size[2], $size[3]) = array($size[3], $size[2]); } $this->_width = $size[2] - $size[0]; $this->_height= $size[3] - $size[1]; $this->_dompdf = $dompdf; $this->_pdf = new PDFLib(); if ( defined("DOMPDF_PDFLIB_LICENSE") ) $this->_pdf->set_parameter( "license", DOMPDF_PDFLIB_LICENSE); $this->_pdf->set_parameter("textformat", "utf8"); $this->_pdf->set_parameter("fontwarning", "false"); $this->_pdf->set_info("Creator", "DOMPDF"); // Silence pedantic warnings about missing TZ settings $tz = @date_default_timezone_get(); date_default_timezone_set("UTC"); $this->_pdf->set_info("Date", date("Y-m-d")); date_default_timezone_set($tz); if ( self::$IN_MEMORY ) $this->_pdf->begin_document("",""); else { $tmp_dir = $this->_dompdf->get_options("temp_dir"); $tmp_name = tempnam($tmp_dir, "libdompdf_pdf_"); @unlink($tmp_name); $this->_file = "$tmp_name.pdf"; $this->_pdf->begin_document($this->_file,""); } $this->_pdf->begin_page_ext($this->_width, $this->_height, ""); $this->_page_number = $this->_page_count = 1; $this->_page_text = array(); $this->_imgs = array(); $this->_fonts = array(); $this->_objs = array(); // Set up font paths $families = Font_Metrics::get_font_families(); foreach ($families as $files) { foreach ($files as $file) { $face = basename($file); $afm = null; // Prefer ttfs to afms if ( file_exists("$file.ttf") ) { $outline = "$file.ttf"; } else if ( file_exists("$file.TTF") ) { $outline = "$file.TTF"; } else if ( file_exists("$file.pfb") ) { $outline = "$file.pfb"; if ( file_exists("$file.afm") ) { $afm = "$file.afm"; } } else if ( file_exists("$file.PFB") ) { $outline = "$file.PFB"; if ( file_exists("$file.AFM") ) { $afm = "$file.AFM"; } } else { continue; } $this->_pdf->set_parameter("FontOutline", "\{$face\}=\{$outline\}"); if ( !is_null($afm) ) { $this->_pdf->set_parameter("FontAFM", "\{$face\}=\{$afm\}"); } } } }
function __construct($paper = "letter", $orientation = "portrait") { if (is_array($paper)) { $size = $paper; } else { if (isset(self::$PAPER_SIZES[mb_strtolower($paper)])) { $size = self::$PAPER_SIZES[mb_strtolower($paper)]; } else { $size = self::$PAPER_SIZES["letter"]; } } if (mb_strtolower($orientation) === "landscape") { list($size[2], $size[3]) = array($size[3], $size[2]); } $this->_width = $size[2] - $size[0]; $this->_height = $size[3] - $size[1]; $this->_pdf = new PDFLib(); if (defined("DOMPDF_PDFLIB_LICENSE")) { $this->_pdf->set_parameter("license", DOMPDF_PDFLIB_LICENSE); } $this->_pdf->set_parameter("textformat", "utf8"); $this->_pdf->set_parameter("fontwarning", "false"); $this->_pdf->set_info("Creator", "DOMPDF"); $tz = @date_default_timezone_get(); date_default_timezone_set("UTC"); $this->_pdf->set_info("Date", date("Y-m-d")); date_default_timezone_set($tz); if (self::$IN_MEMORY) { $this->_pdf->begin_document("", ""); } else { $tempname = tempnam(DOMPDF_TEMP_DIR, "libdompdf_pdf_"); @unlink($tempname); $this->_file = "{$tempname}.pdf"; $this->_pdf->begin_document($this->_file, ""); } $this->_pdf->begin_page_ext($this->_width, $this->_height, ""); $this->_page_number = $this->_page_count = 1; $this->_page_text = array(); $this->_imgs = array(); $this->_fonts = array(); $this->_objs = array(); $families = Font_Metrics::get_font_families(); foreach ($families as $family => $files) { foreach ($files as $style => $file) { $face = basename($file); if (file_exists("{$file}.ttf")) { $outline = "{$file}.ttf"; $afm = null; } else { if (file_exists("{$file}.TTF")) { $outline = "{$file}.TTF"; $afm = null; } else { if (file_exists("{$file}.pfb")) { $outline = "{$file}.pfb"; if (file_exists("{$file}.afm")) { $afm = "{$file}.afm"; } } else { if (file_exists("{$file}.PFB")) { $outline = "{$file}.PFB"; if (file_exists("{$file}.AFM")) { $afm = "{$file}.AFM"; } } else { continue; } } } } $this->_pdf->set_parameter("FontOutline", "\\{{$face}\\}=\\{{$outline}\\}"); if (!is_null($afm)) { $this->_pdf->set_parameter("FontAFM", "\\{{$face}\\}=\\{{$afm}\\}"); } } } }