You are here

function _cufon_find_fonts in Cufón 7.2

Same name and namespace in other branches
  1. 6 cufon.module \_cufon_find_fonts()

_cufon_find_fonts().

Find all installed Cufon fonts.

  • <current_theme>
  • profiles/<profile>/libraries/cufon-fonts/
  • sites/all/libraries/cufon-fonts/
  • sites/<current_site>/libraries/cufon-fonts/
3 calls to _cufon_find_fonts()
cufon_admin in includes/cufon.admin.inc
Administration settings page
cufon_init in ./cufon.module
Implementation of hook_init().
_cufon_selector_form in includes/cufon.admin.inc
@file Provides the administration page for Cufon.

File

./cufon.module, line 182
Adds simple Cufón support to Drupal.

Code

function _cufon_find_fonts($use_cache = TRUE) {
  global $language;

  // Check for a cached fonts
  if ($use_cache && ($cached = cache_get('cufon_fonts'))) {
    return $cached->data;
  }

  // Search all .js files.
  // It is slower tha searching for .font.js only files but will find 3rd party created fonts, too.
  $pattern = '/.*\\.js$/';
  $conf_path = conf_path();

  // Search for fonts in this order:
  // - theme folders (only enabled themes)
  // - site library folder
  // - if you want to use different fonts for different languages put them into <langcode>/ subfolder
  // - default font MUST exist!
  $files = array();
  foreach (list_themes() as $theme) {
    if ($theme->status === '0') {
      continue;
    }
    $files += file_scan_directory(drupal_get_path('theme', $theme->name), $pattern);
  }
  $files += drupal_system_listing($pattern, 'libraries/cufon-fonts', 'name', 0);
  $fonts = array();
  foreach ($files as $file) {

    // Check for language specific font
    if (!empty($language)) {
      $f = dirname($file->uri) . '/' . $language->language . '/' . $file->filename;
      if (file_exists($f)) {
        $file->uri = $f;
      }
    }

    // Resolve font families...
    $families = _cufon_get_font_families($file->uri);
    if (empty($families)) {
      continue;
    }
    foreach ($families as $family) {

      // ... and keep complete file info if not set already
      if (!isset($fonts[$family])) {
        $fonts[$family] = $file;
      }
    }
  }

  // Cache fonts
  cache_set('cufon_fonts', $fonts);
  return $fonts;
}