adapt FontConfig to use SK_FONTHOST_USES_FONTMGR

BUG=

Review URL: https://codereview.chromium.org/21331003

git-svn-id: http://skia.googlecode.com/svn/trunk@10463 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gyp/ports.gyp b/gyp/ports.gyp
index fa717e1..fff368d 100644
--- a/gyp/ports.gyp
+++ b/gyp/ports.gyp
@@ -18,6 +18,7 @@
         '../include/xml',
         '../src/core',
         '../src/lazy',
+        '../src/ports',
         '../src/sfnt',
         '../src/utils',
       ],
diff --git a/src/fonts/SkFontMgr_fontconfig.cpp b/src/fonts/SkFontMgr_fontconfig.cpp
index a785752..1c87a72 100644
--- a/src/fonts/SkFontMgr_fontconfig.cpp
+++ b/src/fonts/SkFontMgr_fontconfig.cpp
@@ -8,6 +8,7 @@
 #include "SkFontMgr.h"
 #include "SkFontStyle.h"
 #include "SkFontConfigInterface.h"
+#include "SkFontConfigTypeface.h"
 #include "SkMath.h"
 #include "SkString.h"
 #include "SkTDArray.h"
@@ -267,6 +268,12 @@
     virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) {
         return NULL;
     }
+    
+    virtual SkTypeface* onLegacyCreateTypeface(const char familyName[],
+                                               unsigned styleBits) SK_OVERRIDE {
+        return FontConfigTypeface::LegacyCreateTypeface(NULL, familyName,
+                                                  (SkTypeface::Style)styleBits);
+    }
 };
 
 SkFontMgr* SkFontMgr::Factory() {
diff --git a/src/ports/SkFontConfigTypeface.h b/src/ports/SkFontConfigTypeface.h
index 549e02f..e9f9a13 100644
--- a/src/ports/SkFontConfigTypeface.h
+++ b/src/ports/SkFontConfigTypeface.h
@@ -7,10 +7,10 @@
 
 #include "SkFontConfigInterface.h"
 #include "SkFontHost_FreeType_common.h"
+#include "SkStream.h"
 #include "SkTypefaceCache.h"
 
 class SkFontDescriptor;
-class SkStream;
 
 class FontConfigTypeface : public SkTypeface_FreeType {
     SkFontConfigInterface::FontIdentity fIdentity;
@@ -48,6 +48,10 @@
         return fFamilyName.equals(name);
     }
 
+    static SkTypeface* LegacyCreateTypeface(const SkTypeface* family,
+                                            const char familyName[],
+                                            SkTypeface::Style);
+
 protected:
     friend class SkFontHost;    // hack until we can make public versions
 
@@ -56,6 +60,7 @@
                                   size_t length, void* data) const SK_OVERRIDE;
     virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE;
     virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE;
+    virtual SkTypeface* onRefMatchingStyle(Style) const SK_OVERRIDE;
 
 private:
     typedef SkTypeface_FreeType INHERITED;
diff --git a/src/ports/SkFontHost_fontconfig.cpp b/src/ports/SkFontHost_fontconfig.cpp
index c53328b..75c21c2 100644
--- a/src/ports/SkFontHost_fontconfig.cpp
+++ b/src/ports/SkFontHost_fontconfig.cpp
@@ -72,9 +72,10 @@
     return rec->fStyle == style && fci->isFamilyName(rec->fFamilyName);
 }
 
-SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
-                                       const char familyName[],
-                                       SkTypeface::Style style) {
+SkTypeface* FontConfigTypeface::LegacyCreateTypeface(
+                const SkTypeface* familyFace,
+                const char familyName[],
+                SkTypeface::Style style) {
     SkAutoTUnref<SkFontConfigInterface> fci(RefFCI());
     if (NULL == fci.get()) {
         return NULL;
@@ -107,6 +108,15 @@
     return face;
 }
 
+#ifndef SK_FONTHOST_USES_FONTMGR
+
+SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
+                                       const char familyName[],
+                                       SkTypeface::Style style) {
+    return FontConfigTypeface::LegacyCreateTypeface(familyFace, familyName,
+                                                    style);
+}
+
 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) {
     if (!stream) {
         return NULL;
@@ -130,6 +140,8 @@
     return stream.get() ? CreateTypefaceFromStream(stream) : NULL;
 }
 
+#endif
+
 ///////////////////////////////////////////////////////////////////////////////
 
 SkStream* FontConfigTypeface::onOpenStream(int* ttcIndex) const {
@@ -196,4 +208,8 @@
     *isLocalStream = SkToBool(this->getLocalStream());
 }
 
-///////////////////////////////////////////////////////////////////////////////
+SkTypeface* FontConfigTypeface::onRefMatchingStyle(Style style) const {
+    return LegacyCreateTypeface(this, NULL, style);
+}
+
+