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 _FDE_CSSDATATABLE 8 #define _FDE_CSSDATATABLE 9 class CFDE_CSSFunction : public CFX_Target { 10 public: CFDE_CSSFunction(const FX_WCHAR * pszFuncName,IFDE_CSSValueList * pArgList)11 CFDE_CSSFunction(const FX_WCHAR* pszFuncName, IFDE_CSSValueList* pArgList) 12 : m_pArgList(pArgList), m_pszFuncName(pszFuncName) { 13 FXSYS_assert(pArgList != NULL); 14 } CountArgs()15 int32_t CountArgs() const { return m_pArgList->CountValues(); } GetArgs(int32_t index)16 IFDE_CSSValue* GetArgs(int32_t index) const { 17 return m_pArgList->GetValue(index); 18 } GetFuncName()19 const FX_WCHAR* GetFuncName() const { return m_pszFuncName; }; 20 21 protected: 22 IFDE_CSSValueList* m_pArgList; 23 const FX_WCHAR* m_pszFuncName; 24 }; 25 class CFDE_CSSPrimitiveValue : public IFDE_CSSPrimitiveValue, 26 public CFX_Target { 27 public: CFDE_CSSPrimitiveValue(const CFDE_CSSPrimitiveValue & src)28 CFDE_CSSPrimitiveValue(const CFDE_CSSPrimitiveValue& src) { *this = src; } CFDE_CSSPrimitiveValue(FX_ARGB color)29 CFDE_CSSPrimitiveValue(FX_ARGB color) 30 : m_eType(FDE_CSSPRIMITIVETYPE_RGB), m_dwColor(color) {} CFDE_CSSPrimitiveValue(FDE_CSSPROPERTYVALUE eValue)31 CFDE_CSSPrimitiveValue(FDE_CSSPROPERTYVALUE eValue) 32 : m_eType(FDE_CSSPRIMITIVETYPE_Enum), m_eEnum(eValue) {} CFDE_CSSPrimitiveValue(FDE_CSSPRIMITIVETYPE eType,FX_FLOAT fValue)33 CFDE_CSSPrimitiveValue(FDE_CSSPRIMITIVETYPE eType, FX_FLOAT fValue) 34 : m_eType(eType), m_fNumber(fValue) {} CFDE_CSSPrimitiveValue(FDE_CSSPRIMITIVETYPE eType,const FX_WCHAR * pValue)35 CFDE_CSSPrimitiveValue(FDE_CSSPRIMITIVETYPE eType, const FX_WCHAR* pValue) 36 : m_eType(eType), m_pString(pValue) { 37 FXSYS_assert(m_pString != NULL); 38 } CFDE_CSSPrimitiveValue(CFDE_CSSFunction * pFunction)39 CFDE_CSSPrimitiveValue(CFDE_CSSFunction* pFunction) 40 : m_eType(FDE_CSSPRIMITIVETYPE_Function), m_pFunction(pFunction) {} 41 GetPrimitiveType()42 virtual FDE_CSSPRIMITIVETYPE GetPrimitiveType() const { return m_eType; } 43 GetRGBColor()44 virtual FX_ARGB GetRGBColor() const { 45 FXSYS_assert(m_eType == FDE_CSSPRIMITIVETYPE_RGB); 46 return m_dwColor; 47 } GetFloat()48 virtual FX_FLOAT GetFloat() const { 49 FXSYS_assert(m_eType >= FDE_CSSPRIMITIVETYPE_Number && 50 m_eType <= FDE_CSSPRIMITIVETYPE_PC); 51 return m_fNumber; 52 } GetString(int32_t & iLength)53 virtual const FX_WCHAR* GetString(int32_t& iLength) const { 54 FXSYS_assert(m_eType >= FDE_CSSPRIMITIVETYPE_String && 55 m_eType <= FDE_CSSPRIMITIVETYPE_URI); 56 iLength = FXSYS_wcslen(m_pString); 57 return m_pString; 58 } GetEnum()59 virtual FDE_CSSPROPERTYVALUE GetEnum() const { 60 FXSYS_assert(m_eType == FDE_CSSPRIMITIVETYPE_Enum); 61 return m_eEnum; 62 } GetFuncName()63 virtual const FX_WCHAR* GetFuncName() const { 64 FXSYS_assert(m_eType == FDE_CSSPRIMITIVETYPE_Function); 65 return m_pFunction->GetFuncName(); 66 } CountArgs()67 virtual int32_t CountArgs() const { 68 FXSYS_assert(m_eType == FDE_CSSPRIMITIVETYPE_Function); 69 return m_pFunction->CountArgs(); 70 } GetArgs(int32_t index)71 virtual IFDE_CSSValue* GetArgs(int32_t index) const { 72 FXSYS_assert(m_eType == FDE_CSSPRIMITIVETYPE_Function); 73 return m_pFunction->GetArgs(index); 74 } 75 76 FDE_CSSPRIMITIVETYPE m_eType; 77 union { 78 FX_ARGB m_dwColor; 79 FX_FLOAT m_fNumber; 80 const FX_WCHAR* m_pString; 81 FDE_CSSPROPERTYVALUE m_eEnum; 82 CFDE_CSSFunction* m_pFunction; 83 }; 84 }; 85 typedef CFX_ArrayTemplate<IFDE_CSSPrimitiveValue*> CFDE_CSSPrimitiveArray; 86 typedef CFX_ArrayTemplate<IFDE_CSSValue*> CFDE_CSSValueArray; 87 class CFDE_CSSValueList : public IFDE_CSSValueList, public CFX_Target { 88 public: 89 CFDE_CSSValueList(IFX_MEMAllocator* pStaticStore, 90 const CFDE_CSSValueArray& list); CountValues()91 virtual int32_t CountValues() const { return m_iCount; } GetValue(int32_t index)92 virtual IFDE_CSSValue* GetValue(int32_t index) const { 93 return m_ppList[index]; 94 } 95 96 protected: 97 IFDE_CSSValue** m_ppList; 98 int32_t m_iCount; 99 }; 100 class CFDE_CSSValueListParser : public CFX_Target { 101 public: CFDE_CSSValueListParser(const FX_WCHAR * psz,int32_t iLen,FX_WCHAR separator)102 CFDE_CSSValueListParser(const FX_WCHAR* psz, int32_t iLen, FX_WCHAR separator) 103 : m_Separator(separator), m_pCur(psz), m_pEnd(psz + iLen) { 104 FXSYS_assert(psz != NULL && iLen > 0); 105 } 106 FX_BOOL NextValue(FDE_CSSPRIMITIVETYPE& eType, 107 const FX_WCHAR*& pStart, 108 int32_t& iLength); 109 FX_WCHAR m_Separator; 110 111 protected: 112 int32_t SkipTo(FX_WCHAR wch, 113 FX_BOOL bWSSeparator = FALSE, 114 FX_BOOL bBrContinue = FALSE); 115 const FX_WCHAR* m_pCur; 116 const FX_WCHAR* m_pEnd; 117 }; 118 119 #define FDE_CSSVALUETYPE_MaybeNumber 0x0100 120 #define FDE_CSSVALUETYPE_MaybeEnum 0x0200 121 #define FDE_CSSVALUETYPE_MaybeURI 0x0400 122 #define FDE_CSSVALUETYPE_MaybeString 0x0800 123 #define FDE_CSSVALUETYPE_MaybeColor 0x1000 124 #define FDE_CSSVALUETYPE_MaybeFunction 0x2000 125 #define FDE_IsOnlyValue(type, enum) \ 126 (((type) & ~(enum)) == FDE_CSSVALUETYPE_Primitive) 127 struct FDE_CSSPROPERTYTABLE { 128 FDE_CSSPROPERTY eName; 129 const FX_WCHAR* pszName; 130 FX_DWORD dwHash; 131 FX_DWORD dwType; 132 }; 133 typedef FDE_CSSPROPERTYTABLE const* FDE_LPCCSSPROPERTYTABLE; 134 135 FDE_LPCCSSPROPERTYTABLE FDE_GetCSSPropertyByName(const FX_WCHAR* pszName, 136 int32_t iLength); 137 FDE_LPCCSSPROPERTYTABLE FDE_GetCSSPropertyByEnum(FDE_CSSPROPERTY eName); 138 struct FDE_CSSPROPERTYVALUETABLE { 139 FDE_CSSPROPERTYVALUE eName; 140 const FX_WCHAR* pszName; 141 FX_DWORD dwHash; 142 }; 143 typedef FDE_CSSPROPERTYVALUETABLE const* FDE_LPCCSSPROPERTYVALUETABLE; 144 145 FDE_LPCCSSPROPERTYVALUETABLE FDE_GetCSSPropertyValueByName( 146 const FX_WCHAR* pszName, 147 int32_t iLength); 148 FDE_LPCCSSPROPERTYVALUETABLE FDE_GetCSSPropertyValueByEnum( 149 FDE_CSSPROPERTYVALUE eName); 150 struct FDE_CSSMEDIATYPETABLE { 151 FX_WORD wHash; 152 FX_WORD wValue; 153 }; 154 typedef FDE_CSSMEDIATYPETABLE const* FDE_LPCCSSMEDIATYPETABLE; 155 FDE_LPCCSSMEDIATYPETABLE FDE_GetCSSMediaTypeByName(const FX_WCHAR* pszName, 156 int32_t iLength); 157 struct FDE_CSSLENGTHUNITTABLE { 158 FX_WORD wHash; 159 FX_WORD wValue; 160 }; 161 typedef FDE_CSSLENGTHUNITTABLE const* FDE_LPCCSSLENGTHUNITTABLE; 162 FDE_LPCCSSLENGTHUNITTABLE FDE_GetCSSLengthUnitByName(const FX_WCHAR* pszName, 163 int32_t iLength); 164 struct FDE_CSSCOLORTABLE { 165 FX_DWORD dwHash; 166 FX_ARGB dwValue; 167 }; 168 typedef FDE_CSSCOLORTABLE const* FDE_LPCCSSCOLORTABLE; 169 FDE_LPCCSSCOLORTABLE FDE_GetCSSColorByName(const FX_WCHAR* pszName, 170 int32_t iLength); 171 struct FDE_CSSPERSUDOTABLE { 172 FDE_CSSPERSUDO eName; 173 const FX_WCHAR* pszName; 174 FX_DWORD dwHash; 175 }; 176 typedef FDE_CSSPERSUDOTABLE const* FDE_LPCCSSPERSUDOTABLE; 177 178 FDE_LPCCSSPERSUDOTABLE FDE_GetCSSPersudoByEnum(FDE_CSSPERSUDO ePersudo); 179 FX_BOOL FDE_ParseCSSNumber(const FX_WCHAR* pszValue, 180 int32_t iValueLen, 181 FX_FLOAT& fValue, 182 FDE_CSSPRIMITIVETYPE& eUnit); 183 FX_BOOL FDE_ParseCSSString(const FX_WCHAR* pszValue, 184 int32_t iValueLen, 185 int32_t& iOffset, 186 int32_t& iLength); 187 FX_BOOL FDE_ParseCSSColor(const FX_WCHAR* pszValue, 188 int32_t iValueLen, 189 FX_ARGB& dwColor); 190 FX_BOOL FDE_ParseCSSURI(const FX_WCHAR* pszValue, 191 int32_t iValueLen, 192 int32_t& iOffset, 193 int32_t& iLength); 194 195 #endif 196