Skip to content

Commit

Permalink
load default font when specified does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalpospiech committed Jan 21, 2019
1 parent c3ecd65 commit 5f8f79d
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions lib/Objects/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,8 @@ public function getType0Font()
/**
* Match font to weights and styles - try other weighs/styles if not present.
*
*
* @param bool $custom
*
* @throws \ErrorException
*
* @return string
*/
protected function matchFont(bool $custom = false)
Expand All @@ -557,7 +554,8 @@ protected function matchFont(bool $custom = false)
}
}
if (!$weight) {
throw new \ErrorException('Font file not found: ' . $this->family);
// font file not found return default one
return $this->fontDir . static::$fontFiles['DejaVu Sans'][$this->weight][$this->style];
}
if (isset(static::$customFontFiles[$this->family][$weight][$this->style])) {
return static::$customFontFiles[$this->family][$weight][$this->style];
Expand All @@ -567,7 +565,8 @@ protected function matchFont(bool $custom = false)
if (isset(static::$customFontFiles[$this->family][$weight][$style])) {
return static::$customFontFiles[$this->family][$weight][$style];
}
throw new \ErrorException('Font file not found: ' . $this->family);
// font file not found - get default one
return $this->fontDir . static::$fontFiles['DejaVu Sans'][$this->weight][$this->style];
}

/**
Expand Down Expand Up @@ -619,10 +618,7 @@ public function getFontFileName()
return $path;
}
}
if (isset(static::$customFontFiles[$this->family])) {
return $this->matchFont(true);
}
throw new \ErrorException('Font file not found: ' . $this->family);
return $this->matchFont(true);
}

/**
Expand Down

0 comments on commit 5f8f79d

Please sign in to comment.