🔧 New "export_pdf_font" config param

This commit is contained in:
Pierre Goiffon
2018-12-31 10:38:44 +01:00
parent 2f5f92ddca
commit bdedd83368
5 changed files with 54 additions and 36 deletions

View File

@@ -1,4 +1,5 @@
<?php
require_once(APPROOT.'application/utils.inc.php');
require_once(APPROOT.'lib/tcpdf/tcpdf.php');
/**
@@ -9,7 +10,7 @@ require_once(APPROOT.'lib/tcpdf/tcpdf.php');
class iTopPDF extends TCPDF
{
protected $sDocumentTitle;
public function SetDocumentTitle($sDocumentTitle)
{
$this->sDocumentTitle = $sDocumentTitle;
@@ -23,20 +24,20 @@ class iTopPDF extends TCPDF
{
// Title
// Set font
$this->SetFont('dejavusans', 'B', 10);
$this->SetFont(self::GetPdfFont(), 'B', 10);
$iPageNumberWidth = 25;
$aMargins = $this->getMargins();
// 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('dejavusans', '', 10);
$this->SetFont(self::GetPdfFont(), '', 10);
// Display the page number (right aligned)
// Warning: the 'R'ight alignment does not work when using placeholders like $this->getAliasNumPage() or $this->getAliasNbPages()
$this->MultiCell($iPageNumberWidth, 15, Dict::Format('Core:BulkExport:PDF:PageNumber' ,$this->page), 0, 'R', false, 0 /* $ln */, '', '', true, 0, false, true, 15, 'M' /* $valign */);
// Branding logo
$sBrandingIcon = APPROOT.'images/itop-logo.png';
if (file_exists(MODULESROOT.'branding/main-logo.png'))
@@ -51,6 +52,17 @@ class iTopPDF extends TCPDF
{
// No footer
}
/**
* @return string font in the config file (export_pdf_font)
*/
public static function GetPdfFont()
{
$oConfig = utils::GetConfig();
$sPdfFont = $oConfig->Get('export_pdf_font');
return $sPdfFont;
}
}
/**
@@ -58,42 +70,39 @@ class iTopPDF extends TCPDF
*/
class PDFPage extends WebPage
{
/**
* Instance of the TCPDF object for creating the PDF
* @var TCPDF
*/
/** @var \iTopPDF Instance of the TCPDF object for creating the PDF */
protected $oPdf;
public function __construct($s_title, $sPageFormat = 'A4', $sPageOrientation = 'L')
{
parent::__construct($s_title);
define(K_PATH_FONTS, APPROOT.'lib/tcpdf/fonts');
$this->oPdf = new iTopPDF($sPageOrientation, 'mm', $sPageFormat, true, 'UTF-8', false);
// set document information
$this->oPdf->SetCreator(PDF_CREATOR);
$this->oPdf->SetAuthor('iTop');
$this->oPdf->SetTitle($s_title);
$this->oPdf->SetDocumentTitle($s_title);
$this->oPdf->setFontSubsetting(true);
// Set font
// dejavusans is a UTF-8 Unicode font. Standard PDF fonts like helvetica or times new roman are NOT UTF-8
$this->oPdf->SetFont('dejavusans', '', 10, '', true);
$this->oPdf->SetFont(iTopPDF::GetPdfFont(), '', 10, '', true);
// set auto page breaks
$this->oPdf->SetAutoPageBreak(true, 15); // 15 mm break margin at the bottom
$this->oPdf->SetTopMargin(15);
// Add a page, we're ready to start
$this->oPdf->AddPage();
$this->SetContentDisposition('inline', $s_title.'.pdf');
$this->SetDefaultStyle();
}
/**
* Sets a default style (suitable for printing) to be included each time $this->oPdf->writeHTML() is called
*/
@@ -124,9 +133,9 @@ td.icon {
width: 30px;
}
EOF
);
);
}
/**
* Get access to the underlying TCPDF object
* @return TCPDF
@@ -136,7 +145,7 @@ EOF
$this->flush();
return $this->oPdf;
}
/**
* Writes the currently buffered HTML content into the PDF. This can be useful:
* - to sync the flow in case you want to access the underlying TCPDF object for some specific/graphic output
@@ -156,7 +165,7 @@ EOF
$this->s_content = '';
}
}
/**
* Whether or not the page is a PDF page
* @return boolean
@@ -165,7 +174,7 @@ EOF
{
return true;
}
/**
* Generates the PDF document and returns the PDF content as a string
* @return string
@@ -185,7 +194,7 @@ EOF
$this->flush();
echo $this->oPdf->Output($this->s_title.'.pdf', 'S');
}
public function get_pdf()
{
$this->flush();

View File

@@ -89,7 +89,8 @@ class Config
* New way to store the settings !
*
* @var array
* @since 2.5 db* variables
* @since 2.5.0 db* variables
* @since 2.7.0 export_pdf_font param
*/
protected $m_aSettings = array(
'app_env_label' => array(
@@ -328,6 +329,14 @@ class Config
'source_of_value' => '',
'show_in_conf_sample' => true,
),
'export_pdf_font' => array( // @since 2.7 PR #49
'type' => 'string',
'description' => 'Font used when generating a PDF file',
'default' => 'DejaVuSans',
'value' => '',
'source_of_value' => '',
'show_in_conf_sample' => false,
),
'access_mode' => array(
'type' => 'integer',
'description' => 'Access mode: ACCESS_READONLY = 0, ACCESS_ADMIN_WRITE = 2, ACCESS_FULL = 3',

View File

@@ -161,8 +161,8 @@ class DisplayableNode extends GraphNode
$idx++;
}
}
$oPdf->SetFont('dejavusans', '', 24 * $fScale, '', true);
$oPdf->SetFont(iTopPDF::GetPdfFont(), '', 24 * $fScale, '', true);
$width = $oPdf->GetStringWidth($this->GetProperty('label'));
$height = $oPdf->GetStringHeight(1000, $this->GetProperty('label'));
$oPdf->setAlpha(0.6 * $Alpha);
@@ -547,9 +547,9 @@ class DisplayableRedundancyNode extends DisplayableNode
$oPdf->Circle($this->x*$fScale, $this->y*$fScale, 16*$fScale, 0, 360, 'DF');
$oPdf->SetTextColor(255, 255, 255);
$oPdf->SetFont('dejavusans', '', 28 * $fScale, '', true);
$oPdf->SetFont(iTopPDF::GetPdfFont(), '', 28 * $fScale, '', true);
$sLabel = (string)$this->GetProperty('label');
$width = $oPdf->GetStringWidth($sLabel, 'dejavusans', 'B', 24*$fScale);
$width = $oPdf->GetStringWidth($sLabel, iTopPDF::GetPdfFont(), 'B', 24 * $fScale);
$height = $oPdf->GetStringHeight(1000, $sLabel);
$xPos = (float)$this->x*$fScale - $width/2;
$yPos = (float)$this->y*$fScale - $height/2;
@@ -794,7 +794,7 @@ 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('dejavusans', '', 24 * $fScale, '', true);
$oPdf->SetFont(iTopPDF::GetPdfFont(), '', 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 +1295,7 @@ class DisplayableGraph extends SimpleGraph
$aIcons = array();
$aContexts = array();
$aContextIcons = array();
$oPdf->SetFont('dejavusans', '', $fFontSize, '', true);
$oPdf->SetFont(iTopPDF::GetPdfFont(), '', $fFontSize, '', true);
foreach($oIterator as $sId => $oNode)
{
if ($sClass = $oNode->GetObjectClass())

View File

@@ -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('dejavusans', '', 8, '', true);
$oPDF->SetFont(iTopPDF::GetPdfFont(), '', 8, '', true);
$oPage->add(file_get_contents($this->aStatusInfo['tmp_file']));
$oPage->add($sData);

View File

@@ -2063,7 +2063,7 @@ EOF
}
$oPage->get_tcpdf()->AddPage();
$oPage->get_tcpdf()->SetFont('dejavusans', '', 10, '', true); // Reset the font size to its default
$oPage->get_tcpdf()->SetFont(iTopPDF::GetPdfFont(), '', 10, '', true); // Reset the font size to its default
$oPage->add('<div class="page_header"><h1>'.Dict::S('UI:RelationshipList').'</h1></div>');
$iLoopTimeLimit = MetaModel::GetConfig()->Get('max_execution_time_per_loop');
foreach($aResults as $sListClass => $aObjects)