N°7175 TCPDF fonts : keep only the minimum necessary files

This commit is contained in:
Pierre Goiffon
2024-02-01 15:29:18 +01:00
parent 0a9c5250f8
commit 216ea34a3c
142 changed files with 158 additions and 31013 deletions

View File

@@ -1,38 +0,0 @@
<?php
/**
* This script will copy custom fonts in the TCPDF lib fonts directory.
* If you need to add other files :
* - add the corresponding files in this script directory
* - modify this script to copy also your files
*
* @since 2.7.0 N°1947 add DroidSansFallback font (see also PR #49 in the links below)
* @since 2.7.0 N°2435 TCPPDF lib forked and added in composer.json (at that time the lib was announced as deprecated and rewritten in tecnickcom/tc-lib-pdf)
* @since 3.2.0 N°7175 switch back to TCPDF original lib (which is finally still maintained, tecnickcom/tc-lib-pdf us still under dev), script creation to keep custom DroidSansFallback font
*
* @link https://github.com/Combodo/iTop/pull/49 add DroidSansFallback font
* @link https://github.com/tecnickcom/TCPDF?tab=readme-ov-file#note TCPDF is in support only mode
*/
$sItopRootFolder = realpath(__DIR__ . "/../../../");
$sCurrentScriptFileName = basename(__FILE__);
require_once ("$sItopRootFolder/lib/autoload.php");
$sTcPdfRootFolder = $sItopRootFolder.'/lib/tecnickcom/tcpdf';
if (false === file_exists($sTcPdfRootFolder)) {
echo $sCurrentScriptFileName.": No TCPDF lib detected, exiting !\n";
return;
}
$aFontFilesToCopy = glob(__DIR__.'\droidsansfallback.*');
$sTcPdfFontFolder = $sTcPdfRootFolder.'/Fonts/';
echo $sCurrentScriptFileName.": Copying font files to TCPDF ($sTcPdfFontFolder)...\n";
foreach ($aFontFilesToCopy as $sFontFileToCopy) {
$sFontFileName = basename($sFontFileToCopy);
echo $sCurrentScriptFileName.': copying '.$sFontFileName."\n";
copy($sFontFileToCopy, $sTcPdfFontFolder.$sFontFileName);
}
echo $sCurrentScriptFileName.": Done !\n";

View File

@@ -0,0 +1,56 @@
courier.php
courierb.php
courierbi.php
courieri.php
dejavusans.ctg.z
dejavusans.php
dejavusans.z
dejavusansb.ctg.z
dejavusansb.php
dejavusansb.z
dejavusansbi.ctg.z
dejavusansbi.php
dejavusansbi.z
dejavusanscondensed.ctg.z
dejavusanscondensed.php
dejavusanscondensed.z
dejavusanscondensedb.ctg.z
dejavusanscondensedb.php
dejavusanscondensedb.z
dejavusanscondensedbi.ctg.z
dejavusanscondensedbi.php
dejavusanscondensedbi.z
dejavusanscondensedi.ctg.z
dejavusanscondensedi.php
dejavusanscondensedi.z
dejavusansextralight.ctg.z
dejavusansextralight.php
dejavusansextralight.z
dejavusansi.ctg.z
dejavusansi.php
dejavusansi.z
dejavusansmono.ctg.z
dejavusansmono.php
dejavusansmono.z
dejavusansmonob.ctg.z
dejavusansmonob.php
dejavusansmonob.z
dejavusansmonobi.ctg.z
dejavusansmonobi.php
dejavusansmonobi.z
dejavusansmonoi.ctg.z
dejavusansmonoi.php
dejavusansmonoi.z
droidsansfallback.ctg.z
droidsansfallback.php
droidsansfallback.z
helvetica.php
helveticab.php
helveticabi.php
helveticai.php
symbol.php
times.php
timesb.php
timesbi.php
timesi.php
zapfdingbats.php

View File

@@ -0,0 +1,101 @@
<?php
/**
* This script will copy custom fonts in the TCPDF lib fonts directory.
* If you need to add other files :
* - add the corresponding files in this script directory
* - modify this script to copy also your files
*
* @since 2.7.0 N°1947 add DroidSansFallback font (see also PR #49 in the links below)
* @since 2.7.0 N°2435 TCPPDF lib forked and added in composer.json (at that time the lib was announced as deprecated and rewritten in tecnickcom/tc-lib-pdf)
* @since 3.2.0 N°7175 switch back to TCPDF original lib (which is finally still maintained, tecnickcom/tc-lib-pdf us still under dev), script creation to keep custom DroidSansFallback font
*
* @link https://github.com/Combodo/iTop/pull/49 add DroidSansFallback font
* @link https://github.com/tecnickcom/TCPDF?tab=readme-ov-file#note TCPDF is in support only mode
*/
$sItopRootFolder = realpath(__DIR__ . "/../../../");
$sCurrentScriptFileName = basename(__FILE__);
require_once ("$sItopRootFolder/lib/autoload.php");
$sTcPdfRootFolder = $sItopRootFolder.'/lib/tecnickcom/tcpdf';
if (false === file_exists($sTcPdfRootFolder)) {
echo $sCurrentScriptFileName.": No TCPDF lib detected, exiting !\n";
return;
}
$sTcPdfFontsFolder = $sTcPdfRootFolder.'/Fonts/';
/**
* 1) Cleaning up the fonts directory to keep only the ones we want in iTop
*/
echo $sCurrentScriptFileName.": ---1) Cleaning up the fonts files\n";
$aTcpdfDefaultFontsToKeepInItop = file(__DIR__.'/tcpdfDefaultFontsToKeepInItop.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$aTcpdfFontsDirContent = scandir($sTcPdfFontsFolder);
foreach ($aTcpdfFontsDirContent as $sTcpdfFontResourceName) {
if ($sTcpdfFontResourceName === '.') {
continue;
}
if ($sTcpdfFontResourceName === '..') {
continue;
}
if (!in_array($sTcpdfFontResourceName, $aTcpdfDefaultFontsToKeepInItop, true)) {
echo $sCurrentScriptFileName.": Removing $sTcpdfFontResourceName !\n";
$sTcpdfFontResourceFullPath = $sTcPdfFontsFolder.$sTcpdfFontResourceName;
if (is_file($sTcpdfFontResourceFullPath)) {
unlink($sTcpdfFontResourceFullPath);
} elseif (is_dir($sTcpdfFontResourceFullPath)) {
rrmdir($sTcpdfFontResourceFullPath);
}
}
}
/**
* 2) Then adding the DroidSansFallback font (useful for CJK data for example)
*/
echo $sCurrentScriptFileName.": ---2) Copying font files to TCPDF ($sTcPdfFontsFolder)...\n";
$aFontFilesToCopy = glob(__DIR__.'\droidsansfallback.*');
foreach ($aFontFilesToCopy as $sFontFileToCopy) {
$sFontFileName = basename($sFontFileToCopy);
echo $sCurrentScriptFileName.': copying '.$sFontFileName."\n";
copy($sFontFileToCopy, $sTcPdfFontsFolder.$sFontFileName);
}
echo $sCurrentScriptFileName.": Done !\n";
/*-----------------------------------------------------------------------------------------------*/
/**
* Recursively delete a directory and its content
*
* @param $sDirToRemovePath
*
* @return void
*/
function rrmdir($sDirToRemovePath):void
{
if (is_dir($sDirToRemovePath)) {
$objects = scandir($sDirToRemovePath);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($sDirToRemovePath."/".$object) == "dir") {
rrmdir($sDirToRemovePath."/".$object);
} else {
unlink($sDirToRemovePath."/".$object);
}
}
}
reset($objects);
rmdir($sDirToRemovePath);
}
}