Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / src / fonts / SkFontMgr_fontconfig.cpp
index 0b4accd..bd4c8dd 100644 (file)
 #include <fontconfig/fontconfig.h>
 #include <unistd.h>
 
+// Defined in SkFontHost_FreeType.cpp
+bool find_name_and_attributes(SkStream* stream, SkString* name,
+                              SkTypeface::Style* style, bool* isFixedWidth);
+
 // borrow this global from SkFontHost_fontconfig. eventually that file should
 // go away, and be replaced with this one.
 extern SkFontConfigInterface* SkFontHost_fontconfig_ref_global();
@@ -180,40 +184,30 @@ class SkFontMgr_fontconfig : public SkFontMgr {
     SkAutoTUnref<SkFontConfigInterface> fFCI;
     SkDataTable* fFamilyNames;
 
-    void init() {
-        if (!fFamilyNames) {
-            fFamilyNames = fFCI->getFamilyNames();
-        }
-    }
 
 public:
     SkFontMgr_fontconfig(SkFontConfigInterface* fci)
         : fFCI(fci)
-        , fFamilyNames(NULL) {}
+        , fFamilyNames(fFCI->getFamilyNames()) {}
 
     virtual ~SkFontMgr_fontconfig() {
         SkSafeUnref(fFamilyNames);
     }
 
 protected:
-    virtual int onCountFamilies() {
-        this->init();
+    virtual int onCountFamilies() const SK_OVERRIDE {
         return fFamilyNames->count();
     }
 
-    virtual void onGetFamilyName(int index, SkString* familyName) {
-        this->init();
+    virtual void onGetFamilyName(int index, SkString* familyName) const SK_OVERRIDE {
         familyName->set(fFamilyNames->atStr(index));
     }
 
-    virtual SkFontStyleSet* onCreateStyleSet(int index) {
-        this->init();
+    virtual SkFontStyleSet* onCreateStyleSet(int index) const SK_OVERRIDE {
         return this->onMatchFamily(fFamilyNames->atStr(index));
     }
 
-    virtual SkFontStyleSet* onMatchFamily(const char familyName[]) {
-        this->init();
-
+    virtual SkFontStyleSet* onMatchFamily(const char familyName[]) const SK_OVERRIDE {
         FcPattern* pattern = FcPatternCreate();
 
         FcPatternAddString(pattern, FC_FAMILY, (FcChar8*)familyName);
@@ -257,13 +251,13 @@ protected:
     }
 
     virtual SkTypeface* onMatchFamilyStyle(const char familyName[],
-                                           const SkFontStyle&) { return NULL; }
+                                           const SkFontStyle&) const SK_OVERRIDE { return NULL; }
     virtual SkTypeface* onMatchFaceStyle(const SkTypeface*,
-                                         const SkFontStyle&) { return NULL; }
+                                         const SkFontStyle&) const SK_OVERRIDE { return NULL; }
 
-    virtual SkTypeface* onCreateFromData(SkData*, int ttcIndex) { return NULL; }
+    virtual SkTypeface* onCreateFromData(SkData*, int ttcIndex) const SK_OVERRIDE { return NULL; }
 
-    virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) {
+    virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const SK_OVERRIDE {
         const size_t length = stream->getLength();
         if (!length) {
             return NULL;
@@ -274,17 +268,22 @@ protected:
 
         // TODO should the caller give us the style or should we get it from freetype?
         SkTypeface::Style style = SkTypeface::kNormal;
-        SkTypeface* face = SkNEW_ARGS(FontConfigTypeface, (style, false, stream));
+        bool isFixedWidth = false;
+        if (!find_name_and_attributes(stream, NULL, &style, &isFixedWidth)) {
+            return NULL;
+        }
+
+        SkTypeface* face = SkNEW_ARGS(FontConfigTypeface, (style, isFixedWidth, stream));
         return face;
     }
 
-    virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) {
+    virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERRIDE {
         SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
         return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL;
     }
 
     virtual SkTypeface* onLegacyCreateTypeface(const char familyName[],
-                                               unsigned styleBits) SK_OVERRIDE {
+                                               unsigned styleBits) const SK_OVERRIDE {
         return FontConfigTypeface::LegacyCreateTypeface(NULL, familyName,
                                                   (SkTypeface::Style)styleBits);
     }