From 9a506b668b706b7ae30a19e656712c22696c4bff Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Fri, 17 May 2013 12:15:01 +0800 Subject: [PATCH] Fixed the rendering of fonts that are either bold, italic or both --- elements/element.class.php | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/elements/element.class.php b/elements/element.class.php index b526ade..f69aa10 100644 --- a/elements/element.class.php +++ b/elements/element.class.php @@ -264,7 +264,7 @@ class customcert_element_base { * @param stdClass $content the content to render */ public function render_content($pdf, $content) { - $pdf->setFont($this->element->font, '', $this->element->size); + $this->set_font($pdf); $fontcolour = TCPDF_COLORS::convertHTMLColorToDec($this->element->colour, $fontcolour); $pdf->SetTextColor($fontcolour['R'], $fontcolour['G'], $fontcolour['B']); $pdf->writeHTMLCell(0, 0, $this->element->posx, $this->element->posy, $content); @@ -282,6 +282,40 @@ class customcert_element_base { return $DB->delete_records('customcert_elements', array('id' => $this->element->id)); } + /** + * Sets the font for the element. + * + * @param stdClass $pdf the pdf object + */ + public function set_font($pdf) { + // Variable for the font. + $font = $this->element->font; + // Get the last two characters of the font name. + $fontlength = strlen($font); + $lastchar = $font[$fontlength - 1]; + $secondlastchar = $font[$fontlength - 2]; + // The attributes of the font. + $attr = ''; + // Check if the last character is 'i'. + if ($lastchar == 'i') { + // Remove the 'i' from the font name. + $font = substr($font, 0, -1); + // Check if the second last char is b. + if ($secondlastchar == 'b') { + // Remove the 'b' from the font name. + $font = substr($font, 0, -1); + $attr .= 'B'; + } + $attr .= 'I'; + } else if ($lastchar == 'b') { + // Remove the 'b' from the font name. + $font = substr($font, 0, -1); + $attr .= 'B'; + } + // Check if this font is going to be bold. + $pdf->setFont($font, $attr, $this->element->size); + } + /** * Validates the colour selected. *