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 "SkString.h" 12 #include "SkTDArray.h" 13 14 /** \class SkLanguage 15 16 The SkLanguage class represents a human written language, and is used by 17 text draw operations to determine which glyph to draw when drawing 18 characters with variants (ie Han-derived characters). 19 */ 20 class SkLanguage { 21 public: 22 SkLanguage() { } 23 SkLanguage(const SkString& tag) : fTag(tag) { } 24 SkLanguage(const char* tag) : fTag(tag) { } 25 SkLanguage(const char* tag, size_t len) : fTag(tag, len) { } 26 SkLanguage(const SkLanguage& b) : fTag(b.fTag) { } 27 28 /** Gets a BCP 47 language identifier for this SkLanguage. 29 @return a BCP 47 language identifier representing this language 30 */ 31 const SkString& getTag() const { return fTag; } 32 33 /** Performs BCP 47 fallback to return an SkLanguage one step more general. 34 @return an SkLanguage one step more general 35 */ 36 SkLanguage getParent() const; 37 38 bool operator==(const SkLanguage& b) const { 39 return fTag == b.fTag; 40 } 41 bool operator!=(const SkLanguage& b) const { 42 return fTag != b.fTag; 43 } 44 SkLanguage& operator=(const SkLanguage& b) { 45 fTag = b.fTag; 46 return *this; 47 } 48 49 private: 50 //! BCP 47 language identifier 51 SkString fTag; 52 }; 53 54 enum FontVariants { 55 kDefault_FontVariant = 0x01, 56 kCompact_FontVariant = 0x02, 57 kElegant_FontVariant = 0x04, 58 kLast_FontVariant = kElegant_FontVariant, 59 }; 60 typedef uint32_t FontVariant; 61 62 struct FontFileInfo { 63 FontFileInfo() : fIndex(0), fWeight(0) { } 64 65 SkString fFileName; 66 int fIndex; 67 int fWeight; 68 }; 69 70 /** 71 * A font family provides one or more names for a collection of fonts, each of 72 * which has a different style (normal, italic) or weight (thin, light, bold, 73 * etc). 74 * Some fonts may occur in compact variants for use in the user interface. 75 * Android distinguishes "fallback" fonts to support non-ASCII character sets. 76 */ 77 struct FontFamily { 78 FontFamily() 79 : fVariant(kDefault_FontVariant) 80 , fOrder(-1) 81 , fIsFallbackFont(false) { } 82 83 SkTArray<SkString> fNames; 84 SkTArray<FontFileInfo> fFonts; 85 SkLanguage fLanguage; 86 FontVariant fVariant; 87 int fOrder; // internal to SkFontConfigParser 88 bool fIsFallbackFont; 89 }; 90 91 namespace SkFontConfigParser { 92 93 /** 94 * Parses all system font configuration files and returns the results in an 95 * array of FontFamily structures. 96 */ 97 void GetFontFamilies(SkTDArray<FontFamily*> &fontFamilies); 98 99 /** 100 * Parses all test font configuration files and returns the results in an 101 * array of FontFamily structures. 102 */ 103 void GetTestFontFamilies(SkTDArray<FontFamily*> &fontFamilies, 104 const char* testMainConfigFile, 105 const char* testFallbackConfigFile); 106 107 } // SkFontConfigParser namespace 108 109 #endif /* SKFONTCONFIGPARSER_ANDROID_H_ */ 110