You are here

function textactions_find_font in ImageCache Actions 6

Same name and namespace in other branches
  1. 5.3 textactions.inc \textactions_find_font()
  2. 5.2 textactions.inc \textactions_find_font()

Given a font name or path, return the full real path. Because the toolkit doesn't scan too well, we need to look ahead to avoid problems and validate.

Look for the named font file relative to Drupal, the module, and the files dir.

Parameters

$fontpath a font file name, eg 'arial.ttf':

$strict bool. if set, the func will return nothing on failure. Normal: behaviour is to return the input fontfile name, trusting the system to be able to find it for you. Strict is used to trigger a validation alert.

Return value

the FULL filepath of the font so the image toolkit knows exactly where it is.

2 calls to textactions_find_font()
textactions_text2canvas_image in ./textactions.inc
Place the source image on the current background
textactions_text2canvas_validate_fontfile in ./textactions.inc
Check if the named font is available

File

./textactions.inc, line 414
Helper functions for imagecache_textactions

Code

function textactions_find_font($fontpath, $strict = FALSE) {

  // Track down the font.
  if (is_file($fontpath)) {
    return realpath($fontpath);
  }
  $fontpath = ltrim($fontpath, '/');

  // Try local
  $tryfontpath = drupal_get_path('module', 'imagecache_textactions') . '/fonts/' . $fontpath;
  if (is_file($tryfontpath)) {
    return realpath($tryfontpath);
  }

  // Try in the files directory
  $tryfontpath = file_create_path($fontpath);
  if (is_file($tryfontpath)) {
    return realpath($tryfontpath);
  }
  if ($strict) {
    return FALSE;
  }

  // otherwise, just return what we had and hope it's in a system library
  return $fontpath;
}