You are here

function textactions_find_font in ImageCache Actions 5.2

Same name and namespace in other branches
  1. 5.3 textactions.inc \textactions_find_font()
  2. 6 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 in ./textactions.inc
TODO Validation will not trigger in D6 unless imagecache.module applies a patch first.

File

./textactions.inc, line 365

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_canvasactions') . '/' . $fontpath;
  if (is_file($tryfontpath)) {
    return realpath($tryfontpath);
  }

  // Try files
  $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;
}