| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 The Android Open Source Project | 2 * Copyright 2011 The Android Open Source Project |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SKFONTCONFIGPARSER_ANDROID_H_ | 8 #ifndef SKFONTCONFIGPARSER_ANDROID_H_ |
| 9 #define SKFONTCONFIGPARSER_ANDROID_H_ | 9 #define SKFONTCONFIGPARSER_ANDROID_H_ |
| 10 | 10 |
| 11 #include "SkTypes.h" |
| 12 |
| 13 #include "SkPaintOptionsAndroid.h" |
| 11 #include "SkString.h" | 14 #include "SkString.h" |
| 12 #include "SkTDArray.h" | 15 #include "SkTDArray.h" |
| 13 | 16 |
| 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 { | 17 struct FontFileInfo { |
| 63 FontFileInfo() : fIndex(0), fWeight(0) { } | 18 FontFileInfo() : fIndex(0), fWeight(0) { } |
| 64 | 19 |
| 65 SkString fFileName; | 20 SkString fFileName; |
| 66 int fIndex; | 21 int fIndex; |
| 22 SkPaintOptionsAndroid fPaintOptions; |
| 67 int fWeight; | 23 int fWeight; |
| 68 }; | 24 }; |
| 69 | 25 |
| 70 /** | 26 /** |
| 71 * A font family provides one or more names for a collection of fonts, each of | 27 * 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, | 28 * which has a different style (normal, italic) or weight (thin, light, bold, |
| 73 * etc). | 29 * etc). |
| 74 * Some fonts may occur in compact variants for use in the user interface. | 30 * Some fonts may occur in compact variants for use in the user interface. |
| 75 * Android distinguishes "fallback" fonts to support non-ASCII character sets. | 31 * Android distinguishes "fallback" fonts to support non-ASCII character sets. |
| 76 */ | 32 */ |
| 77 struct FontFamily { | 33 struct FontFamily { |
| 78 FontFamily() | 34 FontFamily() |
| 79 : fVariant(kDefault_FontVariant) | 35 : fVariant(SkPaintOptionsAndroid::kDefault_Variant) |
| 80 , fOrder(-1) | 36 , fOrder(-1) |
| 81 , fIsFallbackFont(false) { } | 37 , fIsFallbackFont(false) { } |
| 82 | 38 |
| 83 SkTArray<SkString> fNames; | 39 SkTArray<SkString> fNames; |
| 84 SkTArray<FontFileInfo> fFonts; | 40 SkTArray<FontFileInfo> fFonts; |
| 85 SkLanguage fLanguage; | 41 SkLanguage fLanguage; |
| 86 FontVariant fVariant; | 42 SkPaintOptionsAndroid::FontVariant fVariant; |
| 87 int fOrder; // internal to SkFontConfigParser | 43 int fOrder; // internal to SkFontConfigParser |
| 88 bool fIsFallbackFont; | 44 bool fIsFallbackFont; |
| 89 }; | 45 }; |
| 90 | 46 |
| 91 namespace SkFontConfigParser { | 47 namespace SkFontConfigParser { |
| 92 | 48 |
| 93 /** | 49 /** |
| 94 * Parses all system font configuration files and returns the results in an | 50 * Parses all system font configuration files and returns the results in an |
| 95 * array of FontFamily structures. | 51 * array of FontFamily structures. |
| 96 */ | 52 */ |
| 97 void GetFontFamilies(SkTDArray<FontFamily*> &fontFamilies); | 53 void GetFontFamilies(SkTDArray<FontFamily*> &fontFamilies); |
| 98 | 54 |
| 99 /** | 55 /** |
| 100 * Parses all test font configuration files and returns the results in an | 56 * Parses all test font configuration files and returns the results in an |
| 101 * array of FontFamily structures. | 57 * array of FontFamily structures. |
| 102 */ | 58 */ |
| 103 void GetTestFontFamilies(SkTDArray<FontFamily*> &fontFamilies, | 59 void GetTestFontFamilies(SkTDArray<FontFamily*> &fontFamilies, |
| 104 const char* testMainConfigFile, | 60 const char* testMainConfigFile, |
| 105 const char* testFallbackConfigFile); | 61 const char* testFallbackConfigFile); |
| 106 | 62 |
| 107 } // SkFontConfigParser namespace | 63 } // SkFontConfigParser namespace |
| 108 | 64 |
| 109 #endif /* SKFONTCONFIGPARSER_ANDROID_H_ */ | 65 #endif /* SKFONTCONFIGPARSER_ANDROID_H_ */ |
| OLD | NEW |