1 // Copyright 2014 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef XFA_FGAS_LOCALIZATION_FGAS_LOCALE_H_ 8 #define XFA_FGAS_LOCALIZATION_FGAS_LOCALE_H_ 9 10 #include <memory> 11 12 #include "core/fxcrt/fx_xml.h" 13 #include "xfa/fgas/localization/fgas_datetime.h" 14 15 class CFX_Unitime; 16 17 enum FX_LOCALENUMSYMBOL { 18 FX_LOCALENUMSYMBOL_Decimal, 19 FX_LOCALENUMSYMBOL_Grouping, 20 FX_LOCALENUMSYMBOL_Percent, 21 FX_LOCALENUMSYMBOL_Minus, 22 FX_LOCALENUMSYMBOL_Zero, 23 FX_LOCALENUMSYMBOL_CurrencySymbol, 24 FX_LOCALENUMSYMBOL_CurrencyName, 25 }; 26 enum FX_LOCALEDATETIMESUBCATEGORY { 27 FX_LOCALEDATETIMESUBCATEGORY_Default, 28 FX_LOCALEDATETIMESUBCATEGORY_Short, 29 FX_LOCALEDATETIMESUBCATEGORY_Medium, 30 FX_LOCALEDATETIMESUBCATEGORY_Full, 31 FX_LOCALEDATETIMESUBCATEGORY_Long, 32 }; 33 enum FX_LOCALENUMSUBCATEGORY { 34 FX_LOCALENUMPATTERN_Percent, 35 FX_LOCALENUMPATTERN_Currency, 36 FX_LOCALENUMPATTERN_Decimal, 37 FX_LOCALENUMPATTERN_Integer, 38 }; 39 enum FX_LOCALECATEGORY { 40 FX_LOCALECATEGORY_Unknown, 41 FX_LOCALECATEGORY_Date, 42 FX_LOCALECATEGORY_Time, 43 FX_LOCALECATEGORY_DateTime, 44 FX_LOCALECATEGORY_Num, 45 FX_LOCALECATEGORY_Text, 46 FX_LOCALECATEGORY_Zero, 47 FX_LOCALECATEGORY_Null, 48 }; 49 enum FX_DATETIMETYPE { 50 FX_DATETIMETYPE_Unknown, 51 FX_DATETIMETYPE_Date, 52 FX_DATETIMETYPE_Time, 53 FX_DATETIMETYPE_DateTime, 54 FX_DATETIMETYPE_TimeDate, 55 }; 56 57 class IFX_Locale { 58 public: ~IFX_Locale()59 virtual ~IFX_Locale() {} 60 61 virtual CFX_WideString GetName() const = 0; 62 virtual void GetNumbericSymbol(FX_LOCALENUMSYMBOL eType, 63 CFX_WideString& wsNumSymbol) const = 0; 64 virtual void GetDateTimeSymbols(CFX_WideString& wsDtSymbol) const = 0; 65 virtual void GetMonthName(int32_t nMonth, 66 CFX_WideString& wsMonthName, 67 bool bAbbr = true) const = 0; 68 virtual void GetDayName(int32_t nWeek, 69 CFX_WideString& wsDayName, 70 bool bAbbr = true) const = 0; 71 virtual void GetMeridiemName(CFX_WideString& wsMeridiemName, 72 bool bAM = true) const = 0; 73 virtual void GetTimeZone(FX_TIMEZONE* tz) const = 0; 74 virtual void GetEraName(CFX_WideString& wsEraName, bool bAD = true) const = 0; 75 virtual void GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY eType, 76 CFX_WideString& wsPattern) const = 0; 77 virtual void GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY eType, 78 CFX_WideString& wsPattern) const = 0; 79 virtual void GetNumPattern(FX_LOCALENUMSUBCATEGORY eType, 80 CFX_WideString& wsPattern) const = 0; 81 }; 82 83 class IFX_LocaleMgr { 84 public: ~IFX_LocaleMgr()85 virtual ~IFX_LocaleMgr() {} 86 87 virtual uint16_t GetDefLocaleID() const = 0; 88 virtual IFX_Locale* GetDefLocale() = 0; 89 virtual IFX_Locale* GetLocaleByName(const CFX_WideString& wsLocaleName) = 0; 90 91 protected: 92 virtual std::unique_ptr<IFX_Locale> GetLocale(uint16_t lcid) = 0; 93 }; 94 95 bool FX_DateFromCanonical(const CFX_WideString& wsDate, CFX_Unitime& datetime); 96 bool FX_TimeFromCanonical(const CFX_WideStringC& wsTime, 97 CFX_Unitime& datetime, 98 IFX_Locale* pLocale); 99 class CFX_Decimal { 100 public: 101 CFX_Decimal(); 102 explicit CFX_Decimal(uint32_t val); 103 explicit CFX_Decimal(uint64_t val); 104 explicit CFX_Decimal(int32_t val); 105 explicit CFX_Decimal(int64_t val); 106 explicit CFX_Decimal(FX_FLOAT val, uint8_t scale = 3); 107 explicit CFX_Decimal(const CFX_WideStringC& str); 108 explicit CFX_Decimal(const CFX_ByteStringC& str); 109 operator CFX_WideString() const; 110 operator double() const; 111 bool operator==(const CFX_Decimal& val) const; 112 bool operator<=(const CFX_Decimal& val) const; 113 bool operator>=(const CFX_Decimal& val) const; 114 bool operator!=(const CFX_Decimal& val) const; 115 bool operator<(const CFX_Decimal& val) const; 116 bool operator>(const CFX_Decimal& val) const; 117 CFX_Decimal operator+(const CFX_Decimal& val) const; 118 CFX_Decimal operator-(const CFX_Decimal& val) const; 119 CFX_Decimal operator*(const CFX_Decimal& val) const; 120 CFX_Decimal operator/(const CFX_Decimal& val) const; 121 CFX_Decimal operator%(const CFX_Decimal& val) const; 122 void SetScale(uint8_t newScale); 123 uint8_t GetScale(); 124 void SetAbs(); 125 void SetNegate(); 126 void SetFloor(); 127 void SetCeiling(); 128 void SetTruncate(); 129 130 protected: 131 CFX_Decimal(uint32_t hi, uint32_t mid, uint32_t lo, bool neg, uint8_t scale); IsNotZero()132 inline bool IsNotZero() const { return m_uHi || m_uMid || m_uLo; } 133 inline int8_t Compare(const CFX_Decimal& val) const; 134 inline void Swap(CFX_Decimal& val); 135 inline void FloorOrCeil(bool bFloor); 136 CFX_Decimal AddOrMinus(const CFX_Decimal& val, bool isAdding) const; 137 CFX_Decimal Multiply(const CFX_Decimal& val) const; 138 CFX_Decimal Divide(const CFX_Decimal& val) const; 139 CFX_Decimal Modulus(const CFX_Decimal& val) const; 140 uint32_t m_uFlags; 141 uint32_t m_uHi; 142 uint32_t m_uLo; 143 uint32_t m_uMid; 144 }; 145 146 #endif // XFA_FGAS_LOCALIZATION_FGAS_LOCALE_H_ 147