diff --git a/workflow/engine/bin/tasks/cliWorkspaces.php b/workflow/engine/bin/tasks/cliWorkspaces.php index 9176d27f1..cb3f5a9ea 100644 --- a/workflow/engine/bin/tasks/cliWorkspaces.php +++ b/workflow/engine/bin/tasks/cliWorkspaces.php @@ -387,28 +387,42 @@ EOT CLI::taskRun("run_artisan"); /** - * Add new font to be used in Documents generation (TinyMCE editor and TCPDF library for now) + * Add a font to be used in Documents generation (TinyMCE editor and/or TCPDF library) */ CLI::taskName('documents-add-font'); CLI::taskDescription(<< $fontFileName, + 'tcPdfFileName' => $tcPdfFileName, 'familyName' => $fontFamilyName, + 'inTinyMce' => $inTinyMce, 'friendlyName' => !empty($fontFriendlyName) ? $fontFriendlyName : $fontFamilyName, 'properties' => $fontProperties ]; @@ -1505,7 +1532,28 @@ function documents_add_font($args, $options) } /** - * Remove a font used in Documents generation (TinyMCE editor and TCPDF library for now) + * List the registered fonts + */ +function documents_list_registered_fonts() +{ + // Check fonts path + OutputDocument::checkTcPdfFontsPath(); + + // Get registered fonts + $fonts = OutputDocument::loadTcPdfFontsList(); + + // Display information + CLI::logging(PHP_EOL); + foreach ($fonts as $fileName => $font) { + $inTinyMce = $font['inTinyMce'] ? 'Yes' : 'No'; + CLI::logging("TTF Filename: {$fileName}" . PHP_EOL); + CLI::logging("TCPDF Filename: {$font['tcPdfFileName']}" . PHP_EOL); + CLI::logging("Display in TinyMCE: {$inTinyMce}" . PHP_EOL . PHP_EOL . PHP_EOL); + } +} + +/** + * Remove a font used in Documents generation (TinyMCE editor and/or TCPDF library) * * @param array $args */ @@ -1533,14 +1581,14 @@ function documents_remove_font($args) 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); + // Get registered font + $font = OutputDocument::loadTcPdfFontsList()[$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); + if (file_exists(PATH_DATA . 'fonts' . PATH_SEP . 'tcpdf' . PATH_SEP . $font['tcPdfFileName'] . '.' . $extension)) { + unlink(PATH_DATA . 'fonts' . PATH_SEP . 'tcpdf' . PATH_SEP . $font['tcPdfFileName'] . '.' . $extension); } } diff --git a/workflow/engine/classes/model/OutputDocument.php b/workflow/engine/classes/model/OutputDocument.php index e28ce49da..f1c3e21c9 100644 --- a/workflow/engine/classes/model/OutputDocument.php +++ b/workflow/engine/classes/model/OutputDocument.php @@ -934,18 +934,20 @@ class OutputDocument extends BaseOutputDocument $fileArialUniTTF = PATH_DATA . 'fonts' . PATH_SEP . 'arialuni.ttf'; if (file_exists($fileArialUniTTF)) { // Convert TTF file to the format required by TCPDF library - $fontFamilyName = TCPDF_FONTS::addTTFfont($fileArialUniTTF, 'TrueTypeUnicode'); + $tcPdfFileName = TCPDF_FONTS::addTTFfont($fileArialUniTTF, 'TrueTypeUnicode'); // Set the default unicode font for the document - $pdf->SetFont($fontFamilyName); + $pdf->SetFont($tcPdfFileName); // Register the font file if is not present in the JSON file if (!self::existTcpdfFont('arialuni.ttf')) { - // Add "arialuni.ttf" font + // Add font "arialuni.ttf" $font = [ 'fileName' => 'arialuni.ttf', - 'familyName' => $fontFamilyName, - 'friendlyName' => $fontFamilyName, + 'tcPdfFileName' => $tcPdfFileName, + 'familyName' => $tcPdfFileName, + 'inTinyMce' => true, + 'friendlyName' => $tcPdfFileName, 'properties' => '' ]; self::addTcPdfFont($font); @@ -1344,7 +1346,10 @@ class OutputDocument extends BaseOutputDocument // Build the CSS content foreach ($fonts as $font) { - $css .= str_replace(['@familyName', '@fileName', '@properties'], [$font['familyName'], $font['fileName'], $font['properties']], $template); + if ($font['inTinyMce']) { + $css .= str_replace(['@familyName', '@fileName', '@properties'], + [$font['familyName'], $font['fileName'], $font['properties']], $template); + } } // Save the CSS file