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