diff --git a/config-dist.php b/config-dist.php index 0803045c7a7..4b80cef54bb 100644 --- a/config-dist.php +++ b/config-dist.php @@ -572,6 +572,12 @@ $CFG->admin = 'admin'; // // $CFG->upgradekey = 'put_some_password-like_value_here'; // +// Font used in exported PDF files. When generating a PDF, Moodle embeds a subset of +// the font in the PDF file so it will be readable on the widest range of devices. +// The default font is 'freesans' which is part of the GNU FreeFont collection. +// +// $CFG->pdfexportfont = 'freesans'; +// //========================================================================= // 7. SETTINGS FOR DEVELOPMENT SERVERS - not intended for production use!!! //========================================================================= diff --git a/mod/assign/feedback/editpdf/classes/pdf.php b/mod/assign/feedback/editpdf/classes/pdf.php index 5a0e147dc5b..fc157496b7d 100644 --- a/mod/assign/feedback/editpdf/classes/pdf.php +++ b/mod/assign/feedback/editpdf/classes/pdf.php @@ -71,6 +71,23 @@ class pdf extends \FPDI { /** Blank PDF file used during error. */ const BLANK_PDF = '/mod/assign/feedback/editpdf/fixtures/blank.pdf'; + /** + * Get the name of the font to use in generated PDF files. + * If $CFG->pdfexportfont is set - use it, otherwise use "freesans" as this + * open licensed font has wide support for different language charsets. + * + * @return string + */ + private function get_export_font_name() { + global $CFG; + + $fontname = 'freesans'; + if (!empty($CFG->pdfexportfont)) { + $fontname = $CFG->pdfexportfont; + } + return $fontname; + } + /** * Combine the given PDF files into a single PDF. Optionally add a coversheet and coversheet fields. * @param string[] $pdflist the filenames of the files to combine @@ -86,7 +103,8 @@ class pdf extends \FPDI { $this->setPrintHeader(false); $this->setPrintFooter(false); $this->scale = 72.0 / 100.0; - $this->SetFont('helvetica', '', 16.0 * $this->scale); + // Use font supporting the widest range of characters. + $this->SetFont($this->get_export_font_name(), '', 16.0 * $this->scale, '', true); $this->SetTextColor(0, 0, 0); $totalpagecount = 0; @@ -133,7 +151,7 @@ class pdf extends \FPDI { $this->setPageUnit('pt'); $this->scale = 72.0 / 100.0; - $this->SetFont('helvetica', '', 16.0 * $this->scale); + $this->SetFont($this->get_export_font_name(), '', 16.0 * $this->scale, '', true); $this->SetFillColor(255, 255, 176); $this->SetDrawColor(0, 0, 0); $this->SetLineWidth(1.0 * $this->scale); @@ -226,7 +244,7 @@ class pdf extends \FPDI { $this->SetFontSize(12 * $this->scale); $this->SetMargins(100 * $this->scale, 120 * $this->scale, -1, true); $this->SetAutoPageBreak(true, 100 * $this->scale); - $this->setHeaderFont(array('helvetica', '', 24 * $this->scale)); + $this->setHeaderFont(array($this->get_export_font_name(), '', 24 * $this->scale, '', true)); $this->setHeaderMargin(24 * $this->scale); $this->setHeaderData('', 0, '', get_string('commentindex', 'assignfeedback_editpdf')); diff --git a/mod/assign/feedback/editpdf/tests/editpdf_test.php b/mod/assign/feedback/editpdf/tests/editpdf_test.php index db5d8d1b2be..e40b554ce21 100644 --- a/mod/assign/feedback/editpdf/tests/editpdf_test.php +++ b/mod/assign/feedback/editpdf/tests/editpdf_test.php @@ -258,7 +258,8 @@ class assignfeedback_editpdf_testcase extends advanced_testcase { $comment = new comment(); - $comment->rawtext = 'Comment text'; + // Use some different charset in the comment text. + $comment->rawtext = 'Testing example: בקלות ואמנות'; $comment->width = 100; $comment->x = 100; $comment->y = 100;