From e23b67ee58d88a2451b953d229732f732581c682 Mon Sep 17 00:00:00 2001
From: Drave Robber <DraveRobber@984338.no-reply.drupal.org>
Date: Wed, 18 Jul 2012 11:37:03 +0300
Subject: [PATCH] Make @font-your-face support non-latin subsets with Google Webfont
 Loader API enabled.

---
 modules/google_fonts_api/google_fonts_api.module |   33 ++++++++++++---------
 1 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/modules/google_fonts_api/google_fonts_api.module b/modules/google_fonts_api/google_fonts_api.module
index fb060a3..f2d843a 100644
--- a/modules/google_fonts_api/google_fonts_api.module
+++ b/modules/google_fonts_api/google_fonts_api.module
@@ -67,17 +67,19 @@ function google_fonts_api_preprocess_html(&$vars) {
         $metadata = unserialize($used_font->metadata);
 
         $path_parts = explode(':', $metadata['path']);
-        $subsets[$metadata['subset']] = $metadata['subset'];
+
+        $subsets[$path_parts[0]][$metadata['subset']] = $metadata['subset'];
+        $all_subsets[$metadata['subset']] = $metadata['subset'];
 
         if (!isset($paths[$path_parts[0]])) {
           $paths[$path_parts[0]] = array();
         } // if
 
         if (count($path_parts) > 1) {
-          $paths[$path_parts[0]][] = $path_parts[1];
+          $paths[$path_parts[0]][$path_parts[1]] = $path_parts[1];
         } // if
         else {
-          $paths[$path_parts[0]][] = 'regular';
+          $paths[$path_parts[0]]['regular'] = 'regular';
         } // else
 
       } // if
@@ -89,24 +91,16 @@ function google_fonts_api_preprocess_html(&$vars) {
       $families = array();
 
       foreach ($paths as $family => $variants) {
-        $families[] = urlencode($family) . ':' . implode(',', $variants);
+        $families[$family] = urlencode($family) . ':' . implode(',', $variants);
       } // foreach
 
-      $base = 'http://fonts.googleapis.com/css?family=';
-
-      if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
-        $base = 'https://fonts.googleapis.com/css?family=';
-      } // if
-
-      $url = $base . implode('|', $families) . '&subset=' . implode(',', $subsets);
-      
       if (module_exists('google_webfont_loader_api')) {
 
-        foreach ($families as $family) {
+        foreach ($families as $family => $family_with_variants) {
 
           $font_info = array(
             'name' => 'Google ' . $family,
-            'google_families' => array($family),
+            'google_families' => array($family_with_variants . ':' . implode(',', $subsets[$family])),
           );
 
           _google_webfont_loader_api_load_font($font_info);
@@ -114,8 +108,19 @@ function google_fonts_api_preprocess_html(&$vars) {
         } // foreach
 
       } // if
+
       else {
+
+        $base = 'http://fonts.googleapis.com/css?family=';
+
+        if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
+          $base = 'https://fonts.googleapis.com/css?family=';
+        } // if
+
+        $url = $base . implode('|', $families) . '&subset=' . implode(',', $all_subsets);
+      
         fontyourface_add_css_in_preprocess($vars, $url, 'remote');
+
       } // else
 
     } // if
-- 
1.7.4.1

