Skip to content

Commit

Permalink
Update Issue load Local Font
Browse files Browse the repository at this point in the history
  • Loading branch information
sonvnn committed Oct 8, 2022
1 parent a54d417 commit 2cd14d0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 3 additions & 1 deletion framework/helper.php
Expand Up @@ -613,11 +613,13 @@ public static function getUploadedFonts($template)
{
require_once JPATH_LIBRARIES . '/' . 'astroid' . '/' . 'framework' . '/' . 'library' . '/' . 'FontLib' . '/' . 'Autoloader.php';
$template_fonts_path = JPATH_SITE . "/templates/{$template}/fonts";
if (!file_exists($template_fonts_path)) {
$template_media_fonts_path = JPATH_SITE . "/media/templates/site/{$template}/fonts";
if (!file_exists($template_fonts_path) && !file_exists($template_media_fonts_path)) {
return [];
}
$fonts = [];
$font_extensions = ['otf', 'ttf', 'woff'];
if (file_exists($template_media_fonts_path)) $template_fonts_path = $template_media_fonts_path;
foreach (scandir($template_fonts_path) as $font_path) {
if (is_file($template_fonts_path . '/' . $font_path)) {
$pathinfo = pathinfo($template_fonts_path . '/' . $font_path);
Expand Down
14 changes: 11 additions & 3 deletions framework/library/astroid/Helper/Font.php
Expand Up @@ -107,12 +107,14 @@ public static function getUploadedFonts($template)
return [];
}
require_once JPATH_LIBRARIES . '/' . 'astroid' . '/' . 'framework' . '/' . 'library' . '/' . 'FontLib' . '/' . 'Autoloader.php';
$template_fonts_path = JPATH_SITE . "/media/templates/site/{$template}/fonts";
if (!file_exists($template_fonts_path)) {
$template_fonts_path = JPATH_SITE . "/templates/{$template}/fonts";
$template_media_fonts_path = JPATH_SITE . "/media/templates/site/{$template}/fonts";
if (!file_exists($template_fonts_path) && !file_exists($template_media_fonts_path)) {
return [];
}
$fonts = [];
$font_extensions = ['otf', 'ttf', 'woff'];
if (file_exists($template_media_fonts_path)) $template_fonts_path = $template_media_fonts_path;
foreach (scandir($template_fonts_path) as $font_path) {
if (is_file($template_fonts_path . '/' . $font_path)) {
$pathinfo = pathinfo($template_fonts_path . '/' . $font_path);
Expand Down Expand Up @@ -240,11 +242,17 @@ public static function loadLocalFont($value)
$template = Framework::getTemplate();
$document = Framework::getDocument();
$uploaded_fonts = $template->getFonts();
$template_media_fonts_path = JPATH_SITE . "/media/templates/site/{$template->template}/fonts";
if (file_exists($template_media_fonts_path)) {
$font_path = \JURI::root() . "media/templates/site/{$template->template}/fonts/";
} else {
$font_path = \JURI::root() . "templates/{$template->template}/fonts/";
}
if (isset($uploaded_fonts[$value])) {
$files = $uploaded_fonts[$value]['files'];
$value = $uploaded_fonts[$value]['name'];
foreach ($files as $file) {
$document->addStyleDeclaration('@font-face { font-family: "' . $value . '"; src: url("' . \JURI::root() . "templates/{$template->template}/fonts/" . $file . '");}');
$document->addStyleDeclaration('@font-face { font-family: "' . $value . '"; src: url("' . $font_path . $file . '");}');
}
}
return $value;
Expand Down

0 comments on commit 2cd14d0

Please sign in to comment.