function _google_fonts_api_convert_api_results in @font-your-face 6.2
Same name and namespace in other branches
- 8.3 modules/google_fonts_api/google_fonts_api.module \_google_fonts_api_convert_api_results()
- 7.2 modules/google_fonts_api/google_fonts_api.module \_google_fonts_api_convert_api_results()
Converts the Google Fonts API JSON results to a generic Fonts object array
Parameters
$json_font_list: Array of Font objects:
1 call to _google_fonts_api_convert_api_results()
- google_fonts_api_fontyourface_import in modules/
google_fonts_api/ google_fonts_api.module - Implements hook_fontyourface_import().
File
- modules/
google_fonts_api/ google_fonts_api.module, line 163
Code
function _google_fonts_api_convert_api_results($json_font_list) {
$fonts = array();
foreach ($json_font_list as $json_font) {
foreach ($json_font->variants as $json_font_variant) {
foreach ($json_font->subsets as $json_font_subset) {
$font_id = $json_font->family . ' ' . $json_font_variant . ' (' . $json_font_subset . ')';
switch ($json_font_variant) {
case 'regular':
$css_style = 'normal';
$css_weight = 'normal';
break;
case 'italic':
$css_style = 'italic';
$css_weight = 'normal';
break;
case 'bold':
$css_style = 'normal';
$css_weight = 'bold';
break;
case 'bolditalic':
$css_style = 'italic';
$css_weight = 'bold';
break;
default:
// For all other cases (eg 400 or 400italic)
if (is_numeric($json_font_variant)) {
// Variant is a number, like 400
$css_style = 'normal';
$css_weight = $json_font_variant;
}
elseif (is_numeric(substr($json_font_variant, 0, 3))) {
// Variant is a combined string of number and string, like 400italic
// The numberic part is always three characters long, so we can split it easily
$css_style = substr($json_font_variant, 3);
$css_weight = substr($json_font_variant, 0, 3);
}
}
//switch
$fonts[$font_id] = new stdClass();
$fonts[$font_id]->name = $font_id;
$fonts[$font_id]->url = 'http://www.google.com/webfonts/family?family=' . $json_font->family . '&subset=' . $json_font_subset . '#' . $json_font_variant;
$fonts[$font_id]->provider = 'google_fonts_api';
$fonts[$font_id]->css_family = $json_font->family;
$fonts[$font_id]->css_style = $css_style;
$fonts[$font_id]->css_weight = $css_weight;
$fonts[$font_id]->foundry = '';
$fonts[$font_id]->foundry_url = '';
$fonts[$font_id]->license = '';
$fonts[$font_id]->license_url = '';
$fonts[$font_id]->metadata = serialize(array(
'path' => $json_font->family . ':' . $json_font_variant,
'subset' => $json_font_subset,
));
$fonts[$font_id]->tags = $json_font->subsets;
}
//foreach
}
//foreach
}
//foreach
return $fonts;
}