From ec5563b7b519df55ece710e6f2dc35320a4a472c Mon Sep 17 00:00:00 2001 From: Drave Robber Date: Fri, 28 Sep 2012 14:06:09 +0300 Subject: [PATCH] Edge Fonts PoC #2 --- modules/edge_fonts/edge_fonts.info | 5 ++ modules/edge_fonts/edge_fonts.install | 16 +++++ modules/edge_fonts/edge_fonts.list.inc | 74 ++++++++++++++++++++++++ modules/edge_fonts/edge_fonts.module | 99 ++++++++++++++++++++++++++++++++ 4 files changed, 194 insertions(+), 0 deletions(-) create mode 100644 modules/edge_fonts/edge_fonts.info create mode 100644 modules/edge_fonts/edge_fonts.install create mode 100644 modules/edge_fonts/edge_fonts.list.inc create mode 100644 modules/edge_fonts/edge_fonts.module diff --git a/modules/edge_fonts/edge_fonts.info b/modules/edge_fonts/edge_fonts.info new file mode 100644 index 0000000..f673c21 --- /dev/null +++ b/modules/edge_fonts/edge_fonts.info @@ -0,0 +1,5 @@ +name = Edge Fonts +description = @font-your-face provider for Edge Fonts. +dependencies[] = fontyourface +package = @font-your-face +core = 7.x diff --git a/modules/edge_fonts/edge_fonts.install b/modules/edge_fonts/edge_fonts.install new file mode 100644 index 0000000..beb18e0 --- /dev/null +++ b/modules/edge_fonts/edge_fonts.install @@ -0,0 +1,16 @@ + array( + 'fontname' => 'Abel', + 'variants' => array('n4'), + ), + 'abril-fatface' => array( + 'fontname' => 'Abril Fatface', + 'variants' => array('n4', 'i4'), + ), + 'aclonica' => array( + 'fontname' => 'Aclonica', + 'variants' => array('n4'), + ), + 'acme' => array( + 'fontname' => 'Acme', + 'variants' => array('n4'), + ), + 'actor' => array( + 'fontname' => 'Actor', + 'variants' => array('n4'), + ), + 'adamina' => array( + 'fontname' => 'Adamina', + 'variants' => array('n4'), + ), + 'advent-pro' => array( + 'fontname' => 'Advent Pro', + 'variants' => array('n1', 'n2', 'n3', 'n4', 'n5', 'n6', 'n7'), + ), + 'aguafina-script' => array( + 'fontname' => 'Aguafina Script', + 'variants' => array('n4'), + ), + 'aladin' => array( + 'fontname' => 'Aladin', + 'variants' => array('n4'), + ), + 'alegreya' => array( + 'fontname' => 'Alegreya', + 'variants' => array('n4', 'i4', 'n7', 'i7', 'n9', 'i9'), + ), + ); +} + +/** + * Helper function - provides human-readable descriptions of weights. + */ +function edge_fonts_weights() { + return array( + '1' => t('Thin'), + '2' => t('Extra-Light'), + '3' => t('Light'), + // 'Normal' is not actually used. + '4' => t('Normal'), + '5' => t('Medium'), + '6' => t('Demi-bold'), + '7' => t('Bold'), + '8' => t('Heavy'), + '9' => t('Black'), + ); +} diff --git a/modules/edge_fonts/edge_fonts.module b/modules/edge_fonts/edge_fonts.module new file mode 100644 index 0000000..0f77949 --- /dev/null +++ b/modules/edge_fonts/edge_fonts.module @@ -0,0 +1,99 @@ + 'Edge Fonts', + 'url' => 'http://www.edgefonts.com/', + 'base_path' => 'http://use.edgefonts.net/', + ); +} + +/** + * Implements hook_fontyourface_import(). + */ +function edge_fonts_fontyourface_import() { + include_once 'edge_fonts.list.inc'; + // Get available fonts. + $families = edge_fonts_list(); + // Get human-readable descriptions of weights. + $weights = edge_fonts_weights(); + foreach ($families as $family_name => $family) { + foreach ($family['variants'] as $variant) { + $font = new stdClass(); + $font->provider = 'edge_fonts'; + $font->name = $family['fontname']; + $font->css_family = $family_name; + if ($variant[1] != '4') { + $font->name .= ' ' . $weights[$variant[1]]; + } + $font->css_weight = $variant[1] . '00'; + if ($variant[0] == 'i') { + $font->css_style = 'italic'; + $font->name .= ' ' . t('Italic'); + } + $metadata = array( + 'variant' => $variant, + ); + $font->metadata = serialize($metadata); + // TODO: replace js URL with something more human-readable just in case + // someone wants to peek at it. + $font->url = 'http://use.edgefonts.net/' . $family_name . ':' . $variant . '.js'; + $font->license = 'Terms of Use'; + $font->license_url = 'http://www.edgefonts.com/#terms'; + fontyourface_save_font($font); + } + } +} + +/** + * Implements template_preprocess_html(). + */ +function edge_fonts_preprocess_html(&$vars) { + if (!empty($vars['fontyourface'])) { + $fonts = array(); + foreach ($vars['fontyourface'] as $active_font) { + if ($active_font->provider == 'edge_fonts') { + $metadata = unserialize($active_font->metadata); + $fonts[$active_font->css_family][] = $metadata['variant']; + } + } + if (count($fonts) > 0) { + // Let us give schema-less URLs a try. + $base = '//use.edgefonts.net/'; + foreach ($fonts as $family => $variants) { + $js = $base . $family . ':' . implode(',', $variants) . '.js'; + drupal_add_js($js, array('type' => 'external')); + } + } + } +} + +/** + * Implements hook_fontyourface_preview(). + */ +function edge_fonts_fontyourface_preview($font, $text = NULL, $size = 18) { + $output = ''; + if ($text == NULL) { + $text = $font->name; + } + if ($size == 'all') { + // Display variety of sizes. + $sizes = array(32, 24, 18, 14, 12, 10); + foreach ($sizes as $size) { + $output .= '
' . $text . '
'; + } + } + else { + // Display single size. + $output = '' . $text . ''; + } + return $output; +} -- 1.7.4.1