You are here

function _fontscom_api_generate_font_css in @font-your-face 8.3

Generates @font-face css for fonts.com font.

Parameters

Drupal\fontyourface\FontInterface $font: Font compatible with FontInterface.

Return value

string CSS to load font.

1 call to _fontscom_api_generate_font_css()
fontscom_api_page_attachments in modules/fontscom_api/fontscom_api.module
Implements hook_page_attachments().

File

modules/fontscom_api/fontscom_api.module, line 603
Fonts.com API module file.

Code

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