You are here

public static function ViewsPdfBase::getAvailableFonts in Views PDF 8

This method returns a list of available fonts.

1 call to ViewsPdfBase::getAvailableFonts()
ViewsPdfBase::getAvailableFontsCleanList in src/ViewsPdfBase.php
This method returns a cleaned up version of the font list.

File

src/ViewsPdfBase.php, line 1094
Contains \Drupal\views_pdf\ViewsPdfTemplate.

Class

ViewsPdfBase
The main class to generate the PDF.

Namespace

Drupal\views_pdf

Code

public static function getAvailableFonts() {
  if (self::$fontList !== NULL) {
    return self::$fontList;
  }

  // Get all pdf files with the font list: K_PATH_FONTS
  $fonts = file_scan_directory(self::getKPathFonts(), '/.php$/', [
    'nomask' => '/(\\.\\.?|CVS)$/',
    'recurse' => FALSE,
  ], 1);
  $cache = \Drupal::cache()
    ->get('views_pdf_cached_fonts');
  $cached_font_mapping = NULL;
  if (is_object($cache)) {
    $cached_font_mapping = $cache->data;
  }
  if (is_array($cached_font_mapping)) {
    $font_mapping = array_merge(self::$defaultFontList, $cached_font_mapping);
  }
  else {
    $font_mapping = self::$defaultFontList;
  }
  foreach ($fonts as $font) {
    $name = self::getFontNameByFileName($font->uri);
    if (isset($name)) {
      $font_mapping[$font->name] = $name;
    }
  }
  asort($font_mapping);
  \Drupal::cache()
    ->set('views_pdf_cached_fonts', $font_mapping);

  // Remove all fonts without name
  foreach ($font_mapping as $key => $font) {
    if (empty($font)) {
      unset($font_mapping[$key]);
    }
  }
  self::$fontList = $font_mapping;
  return $font_mapping;
}