OLD | NEW |
(Empty) | |
| 1 |
| 2 /* |
| 3 * Copyright 2012 The Android Open Source Project |
| 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. |
| 7 */ |
| 8 |
| 9 |
| 10 #ifndef SkPaintOptionsAndroid_DEFINED |
| 11 #define SkPaintOptionsAndroid_DEFINED |
| 12 |
| 13 #include "SkTypes.h" |
| 14 |
| 15 #ifdef SK_BUILD_FOR_ANDROID |
| 16 |
| 17 #include "SkString.h" |
| 18 |
| 19 struct SkLanguageInfo { |
| 20 SkLanguageInfo(const char* tag) : fTag(tag) { } |
| 21 SkString fTag; //! BCP 47 language identifier |
| 22 }; |
| 23 |
| 24 /** \class SkLanguage |
| 25 |
| 26 The SkLanguage class represents a human written language, and is used by |
| 27 text draw operations to determine which glyph to draw when drawing |
| 28 characters with variants (ie Han-derived characters). |
| 29 */ |
| 30 class SkLanguage { |
| 31 public: |
| 32 SkLanguage() : fInfo(getInfo("")) { } |
| 33 SkLanguage(const char* tag) : fInfo(getInfo(tag)) { } |
| 34 SkLanguage(const SkLanguage& b) : fInfo(b.fInfo) { } |
| 35 |
| 36 /** Gets a BCP 47 language identifier for this SkLanguage. |
| 37 @return a BCP 47 language identifier representing this language |
| 38 */ |
| 39 const SkString& getTag() const { return fInfo->fTag; } |
| 40 |
| 41 /** Performs BCP 47 fallback to return an SkLanguage one step more general. |
| 42 @return an SkLanguage one step more general |
| 43 */ |
| 44 SkLanguage getParent() const; |
| 45 |
| 46 bool operator==(const SkLanguage& b) const { |
| 47 return fInfo == b.fInfo; |
| 48 } |
| 49 bool operator!=(const SkLanguage& b) const { |
| 50 return fInfo != b.fInfo; |
| 51 } |
| 52 bool operator<(const SkLanguage& b) const { |
| 53 return fInfo < b.fInfo; |
| 54 } |
| 55 bool operator>(const SkLanguage& b) const { |
| 56 return fInfo > b.fInfo; |
| 57 } |
| 58 SkLanguage& operator=(const SkLanguage& b) { |
| 59 fInfo = b.fInfo; |
| 60 return *this; |
| 61 } |
| 62 |
| 63 private: |
| 64 const SkLanguageInfo* fInfo; |
| 65 |
| 66 static const SkLanguageInfo* getInfo(const char* tag); |
| 67 }; |
| 68 |
| 69 class SkPaintOptionsAndroid { |
| 70 public: |
| 71 SkPaintOptionsAndroid() { |
| 72 fFontVariant = kDefault_Variant; |
| 73 } |
| 74 |
| 75 /** Return the paint's language value used for drawing text. |
| 76 @return the paint's language value used for drawing text. |
| 77 */ |
| 78 const SkLanguage& getLanguage() const { return fLanguage; } |
| 79 |
| 80 /** Set the paint's language value used for drawing text. |
| 81 @param language set the paint's language value for drawing text. |
| 82 */ |
| 83 void setLanguage(const SkLanguage& language) { fLanguage = language; } |
| 84 |
| 85 enum FontVariant { |
| 86 kDefault_Variant, // Currently setting yourself to Default gives you Comp
act Variant |
| 87 kCompact_Variant, |
| 88 kElegant_Variant, |
| 89 kLast_Variant = kElegant_Variant, |
| 90 }; |
| 91 |
| 92 /** Return the font variant |
| 93 @return the font variant used by this paint object |
| 94 */ |
| 95 FontVariant getFontVariant() const { return fFontVariant; } |
| 96 |
| 97 /** Set the font variant |
| 98 @param fontVariant set the paint's font variant for choosing fonts |
| 99 */ |
| 100 void setFontVariant(FontVariant fontVariant) { |
| 101 SkASSERT((unsigned)fontVariant <= kLast_Variant); |
| 102 fFontVariant = fontVariant; |
| 103 } |
| 104 |
| 105 private: |
| 106 SkLanguage fLanguage; |
| 107 FontVariant fFontVariant; |
| 108 }; |
| 109 |
| 110 #endif // #ifdef SK_BUILD_FOR_ANDROID |
| 111 #endif // #ifndef SkPaintOptionsAndroid_DEFINED |
OLD | NEW |