Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / src / ports / SkFontMgr_android.cpp
index 1126b75..508ad4c 100644 (file)
@@ -42,9 +42,9 @@ static const char* gTestFontFilePrefix = NULL;
 class SkTypeface_Android : public SkTypeface_FreeType {
 public:
     SkTypeface_Android(int index,
-                       Style style,
+                       const SkFontStyle& style,
                        bool isFixedPitch,
-                       const SkString familyName)
+                       const SkString& familyName)
         : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch)
         , fIndex(index)
         , fFamilyName(familyName) { }
@@ -63,11 +63,11 @@ private:
 
 class SkTypeface_AndroidSystem : public SkTypeface_Android {
 public:
-    SkTypeface_AndroidSystem(const SkString pathName,
+    SkTypeface_AndroidSystem(const SkString& pathName,
                              int index,
-                             Style style,
+                             const SkFontStyle& style,
                              bool isFixedPitch,
-                             const SkString familyName,
+                             const SkString& familyName,
                              const SkLanguage& lang,
                              FontVariant variantStyle)
         : INHERITED(index, style, isFixedPitch, familyName)
@@ -100,9 +100,9 @@ class SkTypeface_AndroidStream : public SkTypeface_Android {
 public:
     SkTypeface_AndroidStream(SkStream* stream,
                              int index,
-                             Style style,
+                             const SkFontStyle& style,
                              bool isFixedPitch,
-                             const SkString familyName)
+                             const SkString& familyName)
         : INHERITED(index, style, isFixedPitch, familyName)
         , fStream(SkRef(stream)) { }
 
@@ -138,7 +138,9 @@ void get_path_for_sys_fonts(const char* basePath, const SkString& name, SkString
 
 class SkFontStyleSet_Android : public SkFontStyleSet {
 public:
-    explicit SkFontStyleSet_Android(const FontFamily& family, const char* basePath) {
+    explicit SkFontStyleSet_Android(const FontFamily& family, const char* basePath,
+                                    const SkTypeface_FreeType::Scanner& scanner)
+    {
         const SkString* cannonicalFamilyName = NULL;
         if (family.fNames.count() > 0) {
             cannonicalFamilyName = &family.fNames[0];
@@ -158,14 +160,17 @@ public:
 
             const int ttcIndex = fontFile.fIndex;
             SkString familyName;
-            SkTypeface::Style style;
+            SkFontStyle style;
             bool isFixedWidth;
-            if (!SkTypeface_FreeType::ScanFont(stream.get(), ttcIndex,
-                                               &familyName, &style, &isFixedWidth)) {
+            if (!scanner.scanFont(stream.get(), ttcIndex, &familyName, &style, &isFixedWidth)) {
                 DEBUG_FONT(("---- SystemFonts[%d] file=%s (INVALID)", i, pathName.c_str()));
                 continue;
             }
 
+            if (fontFile.fWeight != 0) {
+                style = SkFontStyle(fontFile.fWeight, style.width(), style.slant());
+            }
+
             const SkLanguage& lang = family.fLanguage;
             uint32_t variant = family.fVariant;
             if (kDefault_FontVariant == variant) {
@@ -230,16 +235,7 @@ public:
 
 private:
     SkFontStyle style(int index) {
-        return SkFontStyle(this->weight(index), SkFontStyle::kNormal_Width,
-                           this->slant(index));
-    }
-    SkFontStyle::Weight weight(int index) {
-        if (fStyles[index]->isBold()) return SkFontStyle::kBold_Weight;
-        return SkFontStyle::kNormal_Weight;
-    }
-    SkFontStyle::Slant slant(int index) {
-        if (fStyles[index]->isItalic()) return SkFontStyle::kItalic_Slant;
-        return SkFontStyle::kUpright_Slant;
+        return fStyles[index]->fontStyle();
     }
     static int match_score(const SkFontStyle& pattern, const SkFontStyle& candidate) {
         int score = 0;
@@ -433,9 +429,9 @@ static SkTypeface_AndroidSystem* find_family_style_character(
 
     virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const SK_OVERRIDE {
         bool isFixedPitch;
-        SkTypeface::Style style;
+        SkFontStyle style;
         SkString name;
-        if (!SkTypeface_FreeType::ScanFont(stream, ttcIndex, &name, &style, &isFixedPitch)) {
+        if (!fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch)) {
             return NULL;
         }
         return SkNEW_ARGS(SkTypeface_AndroidStream, (stream, ttcIndex,
@@ -445,14 +441,7 @@ static SkTypeface_AndroidSystem* find_family_style_character(
 
     virtual SkTypeface* onLegacyCreateTypeface(const char familyName[],
                                                unsigned styleBits) const SK_OVERRIDE {
-        SkTypeface::Style oldStyle = (SkTypeface::Style)styleBits;
-        SkFontStyle style = SkFontStyle(oldStyle & SkTypeface::kBold
-                                                 ? SkFontStyle::kBold_Weight
-                                                 : SkFontStyle::kNormal_Weight,
-                                        SkFontStyle::kNormal_Width,
-                                        oldStyle & SkTypeface::kItalic
-                                                 ? SkFontStyle::kItalic_Slant
-                                                 : SkFontStyle::kUpright_Slant);
+        SkFontStyle style = SkFontStyle(styleBits);
 
         if (familyName) {
             // On Android, we must return NULL when we can't find the requested
@@ -467,6 +456,8 @@ static SkTypeface_AndroidSystem* find_family_style_character(
 
 private:
 
+    SkTypeface_FreeType::Scanner fScanner;
+
     SkTArray<SkAutoTUnref<SkFontStyleSet_Android>, true> fFontStyleSets;
     SkFontStyleSet* fDefaultFamily;
     SkTypeface* fDefaultTypeface;
@@ -488,7 +479,8 @@ private:
                 }
             }
 
-            SkFontStyleSet_Android* newSet = SkNEW_ARGS(SkFontStyleSet_Android, (family, basePath));
+            SkFontStyleSet_Android* newSet =
+                SkNEW_ARGS(SkFontStyleSet_Android, (family, basePath, fScanner));
             if (0 == newSet->count()) {
                 SkDELETE(newSet);
                 continue;