PMCORE-2098
This commit is contained in:
@@ -403,6 +403,17 @@ CLI::taskArg('friendlyName', true);
|
||||
CLI::taskArg('fontProperties', true);
|
||||
CLI::taskRun('documents_add_font');
|
||||
|
||||
/**
|
||||
* Remove a font used in Documents generation (TinyMCE editor and TCPDF library for now)
|
||||
*/
|
||||
CLI::taskName('documents-remove-font');
|
||||
CLI::taskDescription(<<<EOT
|
||||
Remove a font used in Documents generation (TinyMCE editor and TCPDF library for now).
|
||||
EOT
|
||||
);
|
||||
CLI::taskArg('fontFileName', false);
|
||||
CLI::taskRun('documents_remove_font');
|
||||
|
||||
/**
|
||||
* Function run_info
|
||||
*
|
||||
@@ -1502,3 +1513,54 @@ function documents_add_font($args, $options)
|
||||
CLI::logging($e->getMessage() . PHP_EOL . PHP_EOL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a font used in Documents generation (TinyMCE editor and TCPDF library for now)
|
||||
*
|
||||
* @param array $args
|
||||
*/
|
||||
function documents_remove_font($args)
|
||||
{
|
||||
try {
|
||||
// Validate the main required argument
|
||||
if (empty($args)) {
|
||||
throw new Exception('Please send the font filename.');
|
||||
}
|
||||
|
||||
// Load arguments
|
||||
$fontFileName = $args[0];
|
||||
|
||||
// Check fonts path
|
||||
OutputDocument::checkTcPdfFontsPath();
|
||||
|
||||
// Check if the font file exist
|
||||
if (!file_exists(PATH_DATA . 'fonts' . PATH_SEP . $fontFileName)) {
|
||||
throw new Exception("Font '{$fontFileName}' not exists.");
|
||||
}
|
||||
|
||||
// Check if the font file was registered
|
||||
if (!OutputDocument::existTcpdfFont($fontFileName)) {
|
||||
throw new Exception("Font '{$fontFileName}' was not registered.");
|
||||
}
|
||||
|
||||
// This line get the filename of the previous converted font
|
||||
$tcPdfFont = TCPDF_FONTS::addTTFfont(PATH_DATA . 'fonts' . PATH_SEP . $fontFileName);
|
||||
|
||||
// Remove TCPDF font files
|
||||
$extensions = ['ctg.z', 'php', 'z'];
|
||||
foreach ($extensions as $extension) {
|
||||
if (file_exists(PATH_DATA . 'fonts' . PATH_SEP . 'tcpdf' . PATH_SEP . $tcPdfFont . '.' . $extension)) {
|
||||
unlink(PATH_DATA . 'fonts' . PATH_SEP . 'tcpdf' . PATH_SEP . $tcPdfFont . '.' . $extension);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove font
|
||||
OutputDocument::removeTcPdfFont($fontFileName);
|
||||
|
||||
// Print finalization message
|
||||
CLI::logging("Font '{$fontFileName}' removed successfully." . PHP_EOL . PHP_EOL);
|
||||
} catch (Exception $e) {
|
||||
// Display the error message
|
||||
CLI::logging($e->getMessage() . PHP_EOL . PHP_EOL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1285,6 +1285,26 @@ class OutputDocument extends BaseOutputDocument
|
||||
self::generateCssFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a custom font used in TCPDF library
|
||||
*
|
||||
* @param string $fileName
|
||||
*/
|
||||
public static function removeTcPdfFont($fileName)
|
||||
{
|
||||
// Load the custom fonts list
|
||||
$fonts = self::loadTcPdfFontsList();
|
||||
|
||||
// Add the font
|
||||
unset($fonts[$fileName]);
|
||||
|
||||
// Save the fonts list
|
||||
self::saveTcPdfFontsList($fonts);
|
||||
|
||||
// Re-generate CSS file
|
||||
self::generateCssFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate CSS with the fonts definition to be used by TinyMCE editor
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user