You are here

public static function PdfTemplate::getAvailableFonts in Views PDF 7

Same name and namespace in other branches
  1. 6 views_pdf_template.php \PdfTemplate::getAvailableFonts()
  2. 7.3 views_pdf_template.php \PdfTemplate::getAvailableFonts()
  3. 7.2 views_pdf_template.php \PdfTemplate::getAvailableFonts()

This method returns a list of available fonts.

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

File

./views_pdf_template.php, line 1084
PDF Class to generate PDFs with native PHP. This class based on FPDF and FPDI.

Class

PdfTemplate
The main class to generate the 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(K_PATH_FONTS, '/.php$/', array(
    'nomask' => '/(\\.\\.?|CVS)$/',
    'recurse' => FALSE,
  ), 1);
  $cache = 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);
  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;
}