You are here

function _fontsquirrel_api_generate_fontfamily_css_stylesheet in @font-your-face 8.3

Generates CSS to load font.

Parameters

string $css_family: Font entity with downloaded package.

array $files: Font files keyed by file type.

Return value

string CSS Definition for @font-face.

1 call to _fontsquirrel_api_generate_fontfamily_css_stylesheet()
fontsquirrel_api_entity_presave in modules/fontsquirrel_api/fontsquirrel_api.module
Implements hook_entity_presave().

File

modules/fontsquirrel_api/fontsquirrel_api.module, line 291
Font Squirrel API module file.

Code

function _fontsquirrel_api_generate_fontfamily_css_stylesheet($css_family, array $files) {
  $data = "@font-face {\n";
  $data .= "font-family: '{$css_family}';\n";
  $lines = [];
  if ($files['eot']) {
    $data .= "src: url('{$files['eot']}');\n";
    $lines[] = "url('{$files['eot']}?#iefix') format('embedded-opentype')";
  }
  if ($files['ttf']) {
    $lines[] = "url('{$files['ttf']}') format('truetype')";
  }
  if ($files['woff']) {
    $lines[] = "url('{$files['woff']}') format('woff')";
  }
  if ($files['svg']) {
    $lines[] = "url('{$files['svg']}#{$css_family}') format('svg')";
  }
  $data .= 'src: ' . implode(', ', $lines) . ";\n";
  $data .= "font-weight: normal;\n";
  $data .= "font-style: normal;\n";
  return $data . "}\n";
}