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 #include "SkString.h" 15 16 class SkReadBuffer; 17 class SkWriteBuffer; 18 19 /** \class SkLanguage 20 21 The SkLanguage class represents a human written language, and is used by 22 text draw operations to determine which glyph to draw when drawing 23 characters with variants (ie Han-derived characters). 24 */ 25 class SkLanguage { 26 public: SkLanguage()27 SkLanguage() { } SkLanguage(const SkString & tag)28 SkLanguage(const SkString& tag) : fTag(tag) { } SkLanguage(const char * tag)29 SkLanguage(const char* tag) : fTag(tag) { } SkLanguage(const char * tag,size_t len)30 SkLanguage(const char* tag, size_t len) : fTag(tag, len) { } SkLanguage(const SkLanguage & b)31 SkLanguage(const SkLanguage& b) : fTag(b.fTag) { } 32 33 /** Gets a BCP 47 language identifier for this SkLanguage. 34 @return a BCP 47 language identifier representing this language 35 */ getTag()36 const SkString& getTag() const { return fTag; } 37 38 /** Performs BCP 47 fallback to return an SkLanguage one step more general. 39 @return an SkLanguage one step more general 40 */ 41 SkLanguage getParent() const; 42 43 bool operator==(const SkLanguage& b) const { 44 return fTag == b.fTag; 45 } 46 bool operator!=(const SkLanguage& b) const { 47 return fTag != b.fTag; 48 } 49 SkLanguage& operator=(const SkLanguage& b) { 50 fTag = b.fTag; 51 return *this; 52 } 53 54 private: 55 //! BCP 47 language identifier 56 SkString fTag; 57 }; 58 59 class SkPaintOptionsAndroid { 60 public: SkPaintOptionsAndroid()61 SkPaintOptionsAndroid() { 62 fFontVariant = kDefault_Variant; 63 fUseFontFallbacks = false; 64 } 65 66 SkPaintOptionsAndroid& operator=(const SkPaintOptionsAndroid& b) { 67 fLanguage = b.fLanguage; 68 fFontVariant = b.fFontVariant; 69 fUseFontFallbacks = b.fUseFontFallbacks; 70 return *this; 71 } 72 73 bool operator==(const SkPaintOptionsAndroid& b) const { 74 return !(*this != b); 75 } 76 77 bool operator!=(const SkPaintOptionsAndroid& b) const { 78 return fLanguage != b.fLanguage || 79 fFontVariant != b.fFontVariant || 80 fUseFontFallbacks != b.fUseFontFallbacks; 81 } 82 83 void flatten(SkWriteBuffer&) const; 84 void unflatten(SkReadBuffer&); 85 86 /** Return the paint's language value used for drawing text. 87 @return the paint's language value used for drawing text. 88 */ getLanguage()89 const SkLanguage& getLanguage() const { return fLanguage; } 90 91 /** Set the paint's language value used for drawing text. 92 @param language set the paint's language value for drawing text. 93 */ setLanguage(const SkLanguage & language)94 void setLanguage(const SkLanguage& language) { fLanguage = language; } setLanguage(const char * languageTag)95 void setLanguage(const char* languageTag) { fLanguage = SkLanguage(languageTag); } 96 97 98 enum FontVariant { 99 kDefault_Variant = 0x01, 100 kCompact_Variant = 0x02, 101 kElegant_Variant = 0x04, 102 kLast_Variant = kElegant_Variant, 103 }; 104 105 /** Return the font variant 106 @return the font variant used by this paint object 107 */ getFontVariant()108 FontVariant getFontVariant() const { return fFontVariant; } 109 110 /** Set the font variant 111 @param fontVariant set the paint's font variant for choosing fonts 112 */ setFontVariant(FontVariant fontVariant)113 void setFontVariant(FontVariant fontVariant) { 114 SkASSERT((unsigned)fontVariant <= kLast_Variant); 115 fFontVariant = fontVariant; 116 } 117 isUsingFontFallbacks()118 bool isUsingFontFallbacks() const { return fUseFontFallbacks; } 119 setUseFontFallbacks(bool useFontFallbacks)120 void setUseFontFallbacks(bool useFontFallbacks) { 121 fUseFontFallbacks = useFontFallbacks; 122 } 123 124 private: 125 SkLanguage fLanguage; 126 FontVariant fFontVariant; 127 bool fUseFontFallbacks; 128 }; 129 130 #endif // #ifndef SkPaintOptionsAndroid_DEFINED 131