Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Check (in a very simlistic way) for file case variations
Browse files Browse the repository at this point in the history
But seriously, we shouldn't be presuming case at all. Full file
path should be recorded where possible and case insensitive
file checking should be done on local files.

Further work on dompdf#988
  • Loading branch information
bsweeney committed Jul 22, 2016
1 parent 0e0261b commit 36d1153
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
36 changes: 17 additions & 19 deletions lib/Cpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -2694,7 +2692,7 @@ function selectFont($fontName, $encoding = '', $set = true)
'FontDescriptor' => $fontDescriptorId
);

if ($fbtype === 'ttf') {
if (strtolower($fbtype) === 'ttf') {
$tmp['SubType'] = 'TrueType';
}

Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/GD.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/Adapter/PDFLib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down

0 comments on commit 36d1153

Please sign in to comment.