Skip to content

Commit

Permalink
Update Font Code Style
Browse files Browse the repository at this point in the history
  • Loading branch information
sonvnn committed Oct 10, 2022
1 parent 9dba5e2 commit b69ae94
Showing 1 changed file with 24 additions and 35 deletions.
59 changes: 24 additions & 35 deletions framework/library/astroid/Helper/Font.php
Expand Up @@ -114,50 +114,39 @@ public static function getUploadedFonts($template)
return [];
}
$fonts = [];
$font_extensions = ['otf', 'ttf', 'woff'];
if (file_exists($template_media_fonts_path) || file_exists($template_fonts_path)) {
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);
if (in_array($pathinfo['extension'], $font_extensions)) {
$font = \FontLib\Font::load($template_fonts_path . '/' . $font_path);
$font->parse();
$fontname = $font->getFontFullName();
$fontid = 'library-font-' . Helper::slugify($fontname);
if (!isset($fonts[$fontid])) {
$fonts[$fontid] = [];
$fonts[$fontid]['id'] = $fontid;
$fonts[$fontid]['name'] = $fontname;
$fonts[$fontid]['files'] = [];
}
$fonts[$fontid]['files'][] = $font_path;
}
}
}
$fonts = self::getLocalFonts($template_fonts_path);
}

if (file_exists($template_custom_fonts_path)) {
foreach (scandir($template_custom_fonts_path) as $font_path) {
if (is_file($template_custom_fonts_path . '/' . $font_path)) {
$pathinfo = pathinfo($template_custom_fonts_path . '/' . $font_path);
if (in_array($pathinfo['extension'], $font_extensions)) {
$font = \FontLib\Font::load($template_custom_fonts_path . '/' . $font_path);
$font->parse();
$fontname = $font->getFontFullName();
$fontid = 'library-font-' . Helper::slugify($fontname);
if (!isset($fonts[$fontid])) {
$fonts[$fontid] = [];
$fonts[$fontid]['id'] = $fontid;
$fonts[$fontid]['name'] = $fontname;
$fonts[$fontid]['files'] = [];
}
$fonts[$fontid]['files'][] = $font_path;
$fonts = array_merge($fonts, self::getLocalFonts($template_custom_fonts_path));
}
Framework::getDebugger()->stop('local-fonts');
return $fonts;
}

public static function getLocalFonts($template_fonts_path) {
$fonts = [];
$font_extensions = ['otf', 'ttf', 'woff'];
foreach (scandir($template_fonts_path) as $font_path) {
if (is_file($template_fonts_path . '/' . $font_path)) {
$pathinfo = pathinfo($template_fonts_path . '/' . $font_path);
if (in_array($pathinfo['extension'], $font_extensions)) {
$font = \FontLib\Font::load($template_fonts_path . '/' . $font_path);
$font->parse();
$fontname = $font->getFontFullName();
$fontid = 'library-font-' . Helper::slugify($fontname);
if (!isset($fonts[$fontid])) {
$fonts[$fontid] = [];
$fonts[$fontid]['id'] = $fontid;
$fonts[$fontid]['name'] = $fontname;
$fonts[$fontid]['files'] = [];
}
$fonts[$fontid]['files'][] = $font_path;
}
}
}
Framework::getDebugger()->stop('local-fonts');
return $fonts;
}

Expand Down

0 comments on commit b69ae94

Please sign in to comment.