diff --git a/workflow/engine/bin/tasks/cliWorkspaces.php b/workflow/engine/bin/tasks/cliWorkspaces.php index d3b74a071..f01f0b7ea 100644 --- a/workflow/engine/bin/tasks/cliWorkspaces.php +++ b/workflow/engine/bin/tasks/cliWorkspaces.php @@ -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(<<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); + } +} diff --git a/workflow/engine/classes/model/OutputDocument.php b/workflow/engine/classes/model/OutputDocument.php index 868128ee6..e546162e1 100644 --- a/workflow/engine/classes/model/OutputDocument.php +++ b/workflow/engine/classes/model/OutputDocument.php @@ -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 */ diff --git a/workflow/engine/controllers/designer.php b/workflow/engine/controllers/designer.php index 8bfa64698..db9f52d39 100644 --- a/workflow/engine/controllers/designer.php +++ b/workflow/engine/controllers/designer.php @@ -155,7 +155,7 @@ class Designer extends Controller $font['friendlyName'] = !empty($font['friendlyName']) ? $font['friendlyName'] : $font['familyName']; $tcPdfFonts[$font['friendlyName']] = "{$font['friendlyName']}={$font['familyName']}"; } - ksort($tcPdfFonts, SORT_NATURAL | SORT_FLAG_CASE); + ksort($tcPdfFonts, SORT_NATURAL | SORT_FLAG_CASE); $this->setVar('tcPdfFonts', implode(';', $tcPdfFonts)); //plugin set source path