Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support autofinding of more variant files #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions load_font.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,25 @@ function install_font_family($dompdf, $fontname, $normal, $bold = null, $italic
}

// Try $file_Bold.$ext etc.
$path = "$dir/$file";

$patterns = array(
"bold" => array("_Bold", "b", "B", "bd", "BD"),
"italic" => array("_Italic", "i", "I"),
"bold_italic" => array("_Bold_Italic", "bi", "BI", "ib", "IB"),
$path = preg_replace('/(:?[_-]?Regular|[_-]R)$/', '', "$dir/$file");
$separators = array("", "_", "-");
$suffixes = array(
"bold" => array("Bold", "b", "B", "bd", "BD"),
"italic" => array("Italic", "i", "I", "RI"),
"bold_italic" => array("BoldItalic", "Bold_Italic", "bi", "BI", "ib", "IB"),
);
foreach ($patterns as $type => $_patterns) {

foreach ($suffixes as $type => $type_suffixes) {
if ( !isset($$type) || !is_readable($$type) ) {
foreach($_patterns as $_pattern) {
if ( is_readable("$path$_pattern$ext") ) {
$$type = "$path$_pattern$ext";
break;
foreach ($type_suffixes as $suffix) {
foreach ($separators as $separator) {
if ( is_readable("$path$separator$suffix$ext") ) {
$$type = "$path$separator$suffix$ext";
break;
}
}
}

if ( is_null($$type) )
echo ("Unable to find $type face file.\n");
}
Expand Down