1 /* 2 * Copyright 2011 The Android Open Source Project 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SKFONTCONFIGPARSER_ANDROID_H_ 9 #define SKFONTCONFIGPARSER_ANDROID_H_ 10 11 #include "SkFontMgr_android.h" 12 #include "SkString.h" 13 #include "SkTDArray.h" 14 15 /** \class SkLanguage 16 17 The SkLanguage class represents a human written language, and is used by 18 text draw operations to determine which glyph to draw when drawing 19 characters with variants (ie Han-derived characters). 20 */ 21 class SkLanguage { 22 public: SkLanguage()23 SkLanguage() { } SkLanguage(const SkString & tag)24 SkLanguage(const SkString& tag) : fTag(tag) { } SkLanguage(const char * tag)25 SkLanguage(const char* tag) : fTag(tag) { } SkLanguage(const char * tag,size_t len)26 SkLanguage(const char* tag, size_t len) : fTag(tag, len) { } SkLanguage(const SkLanguage & b)27 SkLanguage(const SkLanguage& b) : fTag(b.fTag) { } 28 29 /** Gets a BCP 47 language identifier for this SkLanguage. 30 @return a BCP 47 language identifier representing this language 31 */ getTag()32 const SkString& getTag() const { return fTag; } 33 34 /** Performs BCP 47 fallback to return an SkLanguage one step more general. 35 @return an SkLanguage one step more general 36 */ 37 SkLanguage getParent() const; 38 39 bool operator==(const SkLanguage& b) const { 40 return fTag == b.fTag; 41 } 42 bool operator!=(const SkLanguage& b) const { 43 return fTag != b.fTag; 44 } 45 SkLanguage& operator=(const SkLanguage& b) { 46 fTag = b.fTag; 47 return *this; 48 } 49 50 private: 51 //! BCP 47 language identifier 52 SkString fTag; 53 }; 54 55 enum FontVariants { 56 kDefault_FontVariant = 0x01, 57 kCompact_FontVariant = 0x02, 58 kElegant_FontVariant = 0x04, 59 kLast_FontVariant = kElegant_FontVariant, 60 }; 61 typedef uint32_t FontVariant; 62 63 // Must remain trivially movable (can be memmoved). 64 struct FontFileInfo { FontFileInfoFontFileInfo65 FontFileInfo() : fIndex(0), fWeight(0), fStyle(Style::kAuto) { } 66 67 SkString fFileName; 68 int fIndex; 69 int fWeight; 70 enum class Style { kAuto, kNormal, kItalic } fStyle; 71 }; 72 73 /** 74 * A font family provides one or more names for a collection of fonts, each of 75 * which has a different style (normal, italic) or weight (thin, light, bold, 76 * etc). 77 * Some fonts may occur in compact variants for use in the user interface. 78 * Android distinguishes "fallback" fonts to support non-ASCII character sets. 79 */ 80 struct FontFamily { FontFamilyFontFamily81 FontFamily(const SkString& basePath, bool isFallbackFont) 82 : fVariant(kDefault_FontVariant) 83 , fOrder(-1) 84 , fIsFallbackFont(isFallbackFont) 85 , fBasePath(basePath) 86 { } 87 88 SkTArray<SkString, true> fNames; 89 SkTArray<FontFileInfo, true> fFonts; 90 SkLanguage fLanguage; 91 FontVariant fVariant; 92 int fOrder; // internal to SkFontConfigParser 93 bool fIsFallbackFont; 94 const SkString fBasePath; 95 }; 96 97 namespace SkFontConfigParser { 98 99 /** Parses system font configuration files and appends result to fontFamilies. */ 100 void GetSystemFontFamilies(SkTDArray<FontFamily*>& fontFamilies); 101 102 /** Parses font configuration files and appends result to fontFamilies. */ 103 void GetCustomFontFamilies(SkTDArray<FontFamily*>& fontFamilies, 104 const SkString& basePath, 105 const char* fontsXml, 106 const char* fallbackFontsXml, 107 const char* langFallbackFontsDir = NULL); 108 109 } // SkFontConfigParser namespace 110 111 #endif /* SKFONTCONFIGPARSER_ANDROID_H_ */ 112