From 5723e9a77e80ea804a9dea6d838bdabe216653cd Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Wed, 2 Jan 2019 14:58:57 +0100 Subject: [PATCH] :art: PDF : new helper method to set only font weight and size --- application/pdfpage.class.inc.php | 22 +++++++++++++++++++--- core/displayablegraph.class.inc.php | 12 ++++++++---- core/pdfbulkexport.class.inc.php | 2 +- pages/ajax.render.php | 2 +- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/application/pdfpage.class.inc.php b/application/pdfpage.class.inc.php index f0705d801..e168da6a6 100644 --- a/application/pdfpage.class.inc.php +++ b/application/pdfpage.class.inc.php @@ -11,6 +11,21 @@ class iTopPDF extends TCPDF { protected $sDocumentTitle; + /** + * Shortcut to set only weight and size + * + * @param string $style + * @param int $size + * + * @uses \TCPDF::SetFont() + * @since 2.7 + */ + public function SetFontParams($style, $size) + { + $siTopFont = self::GetPdfFont(); + $this->SetFont($siTopFont, $style, $size); + } + public function SetDocumentTitle($sDocumentTitle) { $this->sDocumentTitle = $sDocumentTitle; @@ -24,7 +39,7 @@ class iTopPDF extends TCPDF { // Title // Set font - $this->SetFont(self::GetPdfFont(), 'B', 10); + $this->SetFontParams('B', 10); $iPageNumberWidth = 25; $aMargins = $this->getMargins(); @@ -32,7 +47,7 @@ class iTopPDF extends TCPDF // Display the title (centered) $this->SetXY($aMargins['left'] + $iPageNumberWidth, 0); $this->MultiCell($this->getPageWidth() - $aMargins['left'] - $aMargins['right'] - 2*$iPageNumberWidth, 15, $this->sDocumentTitle, 0, 'C', false, 0 /* $ln */, '', '', true, 0, false, true, 15, 'M' /* $valign */); - $this->SetFont(self::GetPdfFont(), '', 10); + $this->SetFontParams('', 10); // Display the page number (right aligned) // Warning: the 'R'ight alignment does not work when using placeholders like $this->getAliasNumPage() or $this->getAliasNbPages() @@ -138,7 +153,8 @@ EOF /** * Get access to the underlying TCPDF object - * @return TCPDF + * + * @return \iTopPDF */ public function get_tcpdf() { diff --git a/core/displayablegraph.class.inc.php b/core/displayablegraph.class.inc.php index ae54f59ab..53b6db893 100644 --- a/core/displayablegraph.class.inc.php +++ b/core/displayablegraph.class.inc.php @@ -162,7 +162,8 @@ class DisplayableNode extends GraphNode } } - $oPdf->SetFont(iTopPDF::GetPdfFont(), '', 24 * $fScale, '', true); + $siTopFont = iTopPDF::GetPdfFont(); + $oPdf->SetFont($siTopFont, '', 24 * $fScale, '', true); $width = $oPdf->GetStringWidth($this->GetProperty('label')); $height = $oPdf->GetStringHeight(1000, $this->GetProperty('label')); $oPdf->setAlpha(0.6 * $Alpha); @@ -547,7 +548,8 @@ class DisplayableRedundancyNode extends DisplayableNode $oPdf->Circle($this->x*$fScale, $this->y*$fScale, 16*$fScale, 0, 360, 'DF'); $oPdf->SetTextColor(255, 255, 255); - $oPdf->SetFont(iTopPDF::GetPdfFont(), '', 28 * $fScale, '', true); + $siTopFont = iTopPDF::GetPdfFont(); + $oPdf->SetFont($siTopFont, '', 28 * $fScale, '', true); $sLabel = (string)$this->GetProperty('label'); $width = $oPdf->GetStringWidth($sLabel, iTopPDF::GetPdfFont(), 'B', 24 * $fScale); $height = $oPdf->GetStringHeight(1000, $sLabel); @@ -794,7 +796,8 @@ class DisplayableGroupNode extends DisplayableNode $oPdf->Image($sIconPath, ($this->x - 17)*$fScale, ($this->y - 17)*$fScale, 16*$fScale, 16*$fScale); $oPdf->Image($sIconPath, ($this->x + 1)*$fScale, ($this->y - 17)*$fScale, 16*$fScale, 16*$fScale); $oPdf->Image($sIconPath, ($this->x -8)*$fScale, ($this->y +1)*$fScale, 16*$fScale, 16*$fScale); - $oPdf->SetFont(iTopPDF::GetPdfFont(), '', 24 * $fScale, '', true); + $siTopFont = iTopPDF::GetPdfFont(); + $oPdf->SetFont($siTopFont, '', 24 * $fScale, '', true); $width = $oPdf->GetStringWidth($this->GetProperty('label')); $oPdf->SetTextColor(0, 0, 0); $oPdf->Text($this->x*$fScale - $width/2, ($this->y + 25)*$fScale, $this->GetProperty('label')); @@ -1295,7 +1298,8 @@ class DisplayableGraph extends SimpleGraph $aIcons = array(); $aContexts = array(); $aContextIcons = array(); - $oPdf->SetFont(iTopPDF::GetPdfFont(), '', $fFontSize, '', true); + $siTopFont = iTopPDF::GetPdfFont(); + $oPdf->SetFont($siTopFont, '', $fFontSize, '', true); foreach($oIterator as $sId => $oNode) { if ($sClass = $oNode->GetObjectClass()) diff --git a/core/pdfbulkexport.class.inc.php b/core/pdfbulkexport.class.inc.php index d5693795f..ec4f9125e 100644 --- a/core/pdfbulkexport.class.inc.php +++ b/core/pdfbulkexport.class.inc.php @@ -180,7 +180,7 @@ EOF require_once(APPROOT.'application/pdfpage.class.inc.php'); $oPage = new PDFPage(Dict::Format('Core:BulkExportOf_Class', MetaModel::GetName($this->oSearch->GetClass())), $this->aStatusInfo['page_size'], $this->aStatusInfo['page_orientation']); $oPDF = $oPage->get_tcpdf(); - $oPDF->SetFont(iTopPDF::GetPdfFont(), '', 8, '', true); + $oPDF->SetFontParams('', 8); $oPage->add(file_get_contents($this->aStatusInfo['tmp_file'])); $oPage->add($sData); diff --git a/pages/ajax.render.php b/pages/ajax.render.php index 1c49b922c..d262e1ca4 100644 --- a/pages/ajax.render.php +++ b/pages/ajax.render.php @@ -2063,7 +2063,7 @@ EOF } $oPage->get_tcpdf()->AddPage(); - $oPage->get_tcpdf()->SetFont(iTopPDF::GetPdfFont(), '', 10, '', true); // Reset the font size to its default + $oPage->get_tcpdf()->SetFontParams('', 10); // Reset the font size to its default $oPage->add(''); $iLoopTimeLimit = MetaModel::GetConfig()->Get('max_execution_time_per_loop'); foreach($aResults as $sListClass => $aObjects)