From 001b04fa0004994b72008d32c5a6922be1b89335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20Cesar=20Laura=20Avenda=C3=B1o?= Date: Wed, 2 Sep 2020 22:16:47 +0000 Subject: [PATCH] Fixing some issues found in tests before the first demo --- workflow/engine/bin/tasks/cliWorkspaces.php | 14 ++--------- .../engine/classes/model/OutputDocument.php | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/workflow/engine/bin/tasks/cliWorkspaces.php b/workflow/engine/bin/tasks/cliWorkspaces.php index f01f0b7ea..9176d27f1 100644 --- a/workflow/engine/bin/tasks/cliWorkspaces.php +++ b/workflow/engine/bin/tasks/cliWorkspaces.php @@ -1455,7 +1455,6 @@ function documents_add_font($args, $options) $fontFriendlyName = $args[1] ?? ''; $fontProperties = $args[2] ?? ''; $fontType = $options['font_type'] ?? 'TrueType'; - $name = ''; // Check fonts path OutputDocument::checkTcPdfFontsPath(); @@ -1481,22 +1480,13 @@ function documents_add_font($args, $options) } // Convert TTF file to the format required by TCPDF library - $tcPdfFont = TCPDF_FONTS::addTTFfont(PATH_DATA . 'fonts' . PATH_SEP . $fontFileName, $fontType); + $fontFamilyName = TCPDF_FONTS::addTTFfont(PATH_DATA . 'fonts' . PATH_SEP . $fontFileName, $fontType); // Check if the conversion was successful - if ($tcPdfFont === false) { + if ($fontFamilyName === false) { throw new Exception("The font file '{$fontFileName}' cannot be converted."); } - // Include font definition, in order to use the variable $name - require_once K_PATH_FONTS . $tcPdfFont . '.php'; - - // Build the font family name to be used in the styles - $fontFamilyName = strtolower($name); - $fontFamilyName = str_replace('-', ' ', $fontFamilyName); - $fontFamilyName = str_replace(['bold', 'oblique', 'italic', 'regular'], '', $fontFamilyName); - $fontFamilyName = trim($fontFamilyName); - // Add new font $font = [ 'fileName' => $fontFileName, diff --git a/workflow/engine/classes/model/OutputDocument.php b/workflow/engine/classes/model/OutputDocument.php index e546162e1..e28ce49da 100644 --- a/workflow/engine/classes/model/OutputDocument.php +++ b/workflow/engine/classes/model/OutputDocument.php @@ -928,6 +928,31 @@ class OutputDocument extends BaseOutputDocument // Enable the font sub-setting option $pdf->setFontSubsetting(true); + // Set default unicode font if is required, we need to detect if is chinese, japanese, thai, etc. + if (preg_match('/[\x{30FF}\x{3040}-\x{309F}\x{4E00}-\x{9FFF}\x{0E00}-\x{0E7F}]/u', $content, $matches)) { + // The additional fonts should be in "shared/fonts" folder + $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'); + + // Set the default unicode font for the document + $pdf->SetFont($fontFamilyName); + + // Register the font file if is not present in the JSON file + if (!self::existTcpdfFont('arialuni.ttf')) { + // Add "arialuni.ttf" font + $font = [ + 'fileName' => 'arialuni.ttf', + 'familyName' => $fontFamilyName, + 'friendlyName' => $fontFamilyName, + 'properties' => '' + ]; + self::addTcPdfFont($font); + } + } + } + // Convert the encoding of the content if is UTF-8 if (mb_detect_encoding($content) == 'UTF-8') { $content = mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8');