/** * @param array $style * @param string $remoteFile * @param resource $context * @return bool */ public function registerFont($style, $remoteFile, $context = null) { $fontDir = $this->getOptions()->getFontDir(); $fontname = mb_strtolower($style["family"]); $families = $this->getFontFamilies(); $entry = array(); if (isset($families[$fontname])) { $entry = $families[$fontname]; } $localFile = $fontDir . DIRECTORY_SEPARATOR . md5($remoteFile); $localTempFile = $this->options->get('tempDir') . "/" . md5($remoteFile); $cacheEntry = $localFile; $localFile .= "." . strtolower(pathinfo($remoteFile, PATHINFO_EXTENSION)); $styleString = $this->getType("{$style['weight']} {$style['style']}"); if (!isset($entry[$styleString])) { $entry[$styleString] = $cacheEntry; // Download the remote file $remoteFileContent = @Helpers::getFileContent($remoteFile, null, $context); if (false === $remoteFileContent) { return false; } file_put_contents($localTempFile, $remoteFileContent); $font = Font::load($localTempFile); if (!$font) { unlink($localTempFile); return false; } $font->parse(); $font->saveAdobeFontMetrics("{$cacheEntry}.ufm"); $font->close(); if (file_exists($localTempFile)) { unlink($localTempFile); } if (!file_exists("{$cacheEntry}.ufm")) { return false; } // Save the changes file_put_contents($localFile, $remoteFileContent); if (!file_exists($localFile)) { unlink("{$cacheEntry}.ufm"); return false; } $this->setFontFamily($fontname, $entry); $this->saveFontFamilies(); } return true; }
/** * Get the dompdf option value * * @param string $key * @return mixed * @deprecated */ public function get_option($key) { return $this->options->get($key); }