MDL-45301 assign: Add font options for EditPDF

This commit is contained in:
Tomo Tsuyuki 2023-02-17 15:30:25 +11:00
parent 8503f2cfd8
commit 9e725bc168
19 changed files with 160 additions and 9 deletions

View file

@ -250,4 +250,32 @@ class pdf extends TCPDF {
return $families;
}
/**
* Get font list from config.
* @return array|string[]
*/
public function get_export_fontlist(): array {
global $CFG;
$fontlist = [];
if (!empty($CFG->pdfexportfont)) {
if (is_array($CFG->pdfexportfont)) {
$fontlist = $CFG->pdfexportfont;
} else {
$fontlist[$CFG->pdfexportfont] = $CFG->pdfexportfont;
}
}
// Verify fonts.
$availablefonts = $this->get_font_families();
foreach ($fontlist as $key => $value) {
if (empty($availablefonts[$key])) {
unset($fontlist[$key]);
}
}
if (empty($fontlist)) {
// Default font if there is no value set in CFG.
$fontlist = ['freesans' => 'FreeSans'];
}
return $fontlist;
}
}