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 SkLanguage_DEFINED 11#define SkLanguage_DEFINED 12 13#include "SkTypes.h" 14 15#ifdef SK_BUILD_FOR_ANDROID 16 17#include "SkString.h" 18 19struct 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*/ 30class SkLanguage { 31public: 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 63private: 64 const SkLanguageInfo* fInfo; 65 66 static const SkLanguageInfo* getInfo(const char* tag); 67}; 68 69#endif // #ifdef SK_BUILD_FOR_ANDROID 70#endif // #ifndef SkLanguage_DEFINED 71