diff --git a/lib/Cpdf.php b/lib/Cpdf.php index 5ffc4ab47..3a52a26ed 100644 --- a/lib/Cpdf.php +++ b/lib/Cpdf.php @@ -2433,18 +2433,20 @@ function selectFont($fontName, $encoding = '', $set = true) $this->o_font($this->numObj, 'new', $options); $font['fontNum'] = $this->numFonts; - // if this is a '.afm' font, and there is a '.pfa' file to go with it ( as there + // if this is a '.afm' font, and there is a '.pfa' file to go with it (as there // should be for all non-basic fonts), then load it into an object and put the // references into the font object $basefile = $fontName; $fbtype = ''; - if (file_exists("$basefile.pfb")) { + if (file_exists("$basefile.ttf")) { + $fbtype = 'ttf'; + } elseif (file_exists("$basefile.TTF")) { + $fbtype = 'TTF'; + } elseif (file_exists("$basefile.pfb")) { $fbtype = 'pfb'; - } else { - if (file_exists("$basefile.ttf")) { - $fbtype = 'ttf'; - } + } elseif (file_exists("$basefile.PFB")) { + $fbtype = 'PFB'; } $fbfile = "$basefile.$fbtype"; @@ -2550,7 +2552,7 @@ function selectFont($fontName, $encoding = '', $set = true) // note that pdf supports only binary format type 1 font files, though there is a // simple utility to convert them from pfa to pfb. // FIXME: should we move font subset creation to CPDF::output? See notes in issue #750. - if (!$this->isUnicode || $fbtype !== 'ttf' || empty($this->stringSubsets)) { + if (!$this->isUnicode || strtolower($fbtype) !== 'ttf' || empty($this->stringSubsets)) { $data = file_get_contents($fbfile); } else { $this->stringSubsets[$fontName][] = 32; // Force space if not in yet @@ -2653,12 +2655,10 @@ function selectFont($fontName, $encoding = '', $set = true) } } - if ($fbtype === 'pfb') { + if (strtolower($fbtype) === 'pfb') { $fdopt['FontFile'] = $pfbid; - } else { - if ($fbtype === 'ttf') { - $fdopt['FontFile2'] = $pfbid; - } + } elseif (strtolower($fbtype) === 'ttf') { + $fdopt['FontFile2'] = $pfbid; } $this->o_fontDescriptor($fontDescriptorId, 'new', $fdopt); @@ -2668,7 +2668,7 @@ function selectFont($fontName, $encoding = '', $set = true) $this->objects[$pfbid]['c'] .= $data; // determine the cruicial lengths within this file - if ($fbtype === 'pfb') { + if (strtolower($fbtype) === 'pfb') { $l1 = strpos($data, 'eexec') + 6; $l2 = strpos($data, '00000000') - $l1; $l3 = mb_strlen($data, '8bit') - $l2 - $l1; @@ -2677,11 +2677,9 @@ function selectFont($fontName, $encoding = '', $set = true) 'add', array('Length1' => $l1, 'Length2' => $l2, 'Length3' => $l3) ); - } else { - if ($fbtype == 'ttf') { - $l1 = mb_strlen($data, '8bit'); - $this->o_contents($this->numObj, 'add', array('Length1' => $l1)); - } + } elseif (strtolower($fbtype) == 'ttf') { + $l1 = mb_strlen($data, '8bit'); + $this->o_contents($this->numObj, 'add', array('Length1' => $l1)); } // tell the font object about all this new stuff @@ -2694,7 +2692,7 @@ function selectFont($fontName, $encoding = '', $set = true) 'FontDescriptor' => $fontDescriptorId ); - if ($fbtype === 'ttf') { + if (strtolower($fbtype) === 'ttf') { $tmp['SubType'] = 'TrueType'; } diff --git a/src/Adapter/GD.php b/src/Adapter/GD.php index 9af546313..7589e7a2a 100644 --- a/src/Adapter/GD.php +++ b/src/Adapter/GD.php @@ -831,7 +831,7 @@ function get_text_width($text, $font, $size, $word_spacing = 0.0, $char_spacing function get_ttf_file($font) { - if (strpos($font, '.ttf') === false) + if (stripos($font, '.ttf') === false) $font .= ".ttf"; /*$filename = substr(strtolower(basename($font)), 0, -4); diff --git a/src/Adapter/PDFLib.php b/src/Adapter/PDFLib.php index 09bc595b8..896c2ddf9 100644 --- a/src/Adapter/PDFLib.php +++ b/src/Adapter/PDFLib.php @@ -584,7 +584,6 @@ protected function _load_font($font, $encoding = null, $options = "") } else if (file_exists("$file.pfb")) { $outline = "$file.pfb"; - if (file_exists("$file.afm")) { $afm = "$file.afm"; }