summaryrefslogtreecommitdiff
path: root/xfa/fde/css/fde_cssdatatable.h
blob: a44c24b614280dd4ec980d05a221fb046b57d378 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef XFA_FDE_CSS_FDE_CSSDATATABLE_H_
#define XFA_FDE_CSS_FDE_CSSDATATABLE_H_

#include "core/fxcrt/include/fx_system.h"
#include "xfa/fde/css/fde_css.h"
#include "xfa/fgas/crt/fgas_memory.h"

class CFDE_CSSFunction : public CFX_Target {
 public:
  CFDE_CSSFunction(const FX_WCHAR* pszFuncName, IFDE_CSSValueList* pArgList)
      : m_pArgList(pArgList), m_pszFuncName(pszFuncName) {
    FXSYS_assert(pArgList != NULL);
  }
  int32_t CountArgs() const { return m_pArgList->CountValues(); }
  IFDE_CSSValue* GetArgs(int32_t index) const {
    return m_pArgList->GetValue(index);
  }
  const FX_WCHAR* GetFuncName() const { return m_pszFuncName; }

 protected:
  IFDE_CSSValueList* m_pArgList;
  const FX_WCHAR* m_pszFuncName;
};
class CFDE_CSSPrimitiveValue : public IFDE_CSSPrimitiveValue,
                               public CFX_Target {
 public:
  CFDE_CSSPrimitiveValue(const CFDE_CSSPrimitiveValue& src) { *this = src; }
  CFDE_CSSPrimitiveValue(FX_ARGB color)
      : m_eType(FDE_CSSPRIMITIVETYPE_RGB), m_dwColor(color) {}
  CFDE_CSSPrimitiveValue(FDE_CSSPROPERTYVALUE eValue)
      : m_eType(FDE_CSSPRIMITIVETYPE_Enum), m_eEnum(eValue) {}
  CFDE_CSSPrimitiveValue(FDE_CSSPRIMITIVETYPE eType, FX_FLOAT fValue)
      : m_eType(eType), m_fNumber(fValue) {}
  CFDE_CSSPrimitiveValue(FDE_CSSPRIMITIVETYPE eType, const FX_WCHAR* pValue)
      : m_eType(eType), m_pString(pValue) {
    FXSYS_assert(m_pString != NULL);
  }
  CFDE_CSSPrimitiveValue(CFDE_CSSFunction* pFunction)
      : m_eType(FDE_CSSPRIMITIVETYPE_Function), m_pFunction(pFunction) {}

  virtual FDE_CSSPRIMITIVETYPE GetPrimitiveType() const { return m_eType; }

  virtual FX_ARGB GetRGBColor() const {
    FXSYS_assert(m_eType == FDE_CSSPRIMITIVETYPE_RGB);
    return m_dwColor;
  }
  virtual FX_FLOAT GetFloat() const {
    FXSYS_assert(m_eType >= FDE_CSSPRIMITIVETYPE_Number &&
                 m_eType <= FDE_CSSPRIMITIVETYPE_PC);
    return m_fNumber;
  }
  virtual const FX_WCHAR* GetString(int32_t& iLength) const {
    FXSYS_assert(m_eType >= FDE_CSSPRIMITIVETYPE_String &&
                 m_eType <= FDE_CSSPRIMITIVETYPE_URI);
    iLength = FXSYS_wcslen(m_pString);
    return m_pString;
  }
  virtual FDE_CSSPROPERTYVALUE GetEnum() const {
    FXSYS_assert(m_eType == FDE_CSSPRIMITIVETYPE_Enum);
    return m_eEnum;
  }
  virtual const FX_WCHAR* GetFuncName() const {
    FXSYS_assert(m_eType == FDE_CSSPRIMITIVETYPE_Function);
    return m_pFunction->GetFuncName();
  }
  virtual int32_t CountArgs() const {
    FXSYS_assert(m_eType == FDE_CSSPRIMITIVETYPE_Function);
    return m_pFunction->CountArgs();
  }
  virtual IFDE_CSSValue* GetArgs(int32_t index) const {
    FXSYS_assert(m_eType == FDE_CSSPRIMITIVETYPE_Function);
    return m_pFunction->GetArgs(index);
  }

  FDE_CSSPRIMITIVETYPE m_eType;
  union {
    FX_ARGB m_dwColor;
    FX_FLOAT m_fNumber;
    const FX_WCHAR* m_pString;
    FDE_CSSPROPERTYVALUE m_eEnum;
    CFDE_CSSFunction* m_pFunction;
  };
};
typedef CFX_ArrayTemplate<IFDE_CSSPrimitiveValue*> CFDE_CSSPrimitiveArray;
typedef CFX_ArrayTemplate<IFDE_CSSValue*> CFDE_CSSValueArray;
class CFDE_CSSValueList : public IFDE_CSSValueList, public CFX_Target {
 public:
  CFDE_CSSValueList(IFX_MEMAllocator* pStaticStore,
                    const CFDE_CSSValueArray& list);
  virtual int32_t CountValues() const { return m_iCount; }
  virtual IFDE_CSSValue* GetValue(int32_t index) const {
    return m_ppList[index];
  }

 protected:
  IFDE_CSSValue** m_ppList;
  int32_t m_iCount;
};
class CFDE_CSSValueListParser : public CFX_Target {
 public:
  CFDE_CSSValueListParser(const FX_WCHAR* psz, int32_t iLen, FX_WCHAR separator)
      : m_Separator(separator), m_pCur(psz), m_pEnd(psz + iLen) {
    FXSYS_assert(psz != NULL && iLen > 0);
  }
  FX_BOOL NextValue(FDE_CSSPRIMITIVETYPE& eType,
                    const FX_WCHAR*& pStart,
                    int32_t& iLength);
  FX_WCHAR m_Separator;

 protected:
  int32_t SkipTo(FX_WCHAR wch,
                 FX_BOOL bWSSeparator = FALSE,
                 FX_BOOL bBrContinue = FALSE);
  const FX_WCHAR* m_pCur;
  const FX_WCHAR* m_pEnd;
};

#define FDE_CSSVALUETYPE_MaybeNumber 0x0100
#define FDE_CSSVALUETYPE_MaybeEnum 0x0200
#define FDE_CSSVALUETYPE_MaybeURI 0x0400
#define FDE_CSSVALUETYPE_MaybeString 0x0800
#define FDE_CSSVALUETYPE_MaybeColor 0x1000
#define FDE_CSSVALUETYPE_MaybeFunction 0x2000
#define FDE_IsOnlyValue(type, enum) \
  (((type) & ~(enum)) == FDE_CSSVALUETYPE_Primitive)
struct FDE_CSSPROPERTYTABLE {
  FDE_CSSPROPERTY eName;
  const FX_WCHAR* pszName;
  FX_DWORD dwHash;
  FX_DWORD dwType;
};
typedef FDE_CSSPROPERTYTABLE const* FDE_LPCCSSPROPERTYTABLE;

FDE_LPCCSSPROPERTYTABLE FDE_GetCSSPropertyByName(const FX_WCHAR* pszName,
                                                 int32_t iLength);
FDE_LPCCSSPROPERTYTABLE FDE_GetCSSPropertyByEnum(FDE_CSSPROPERTY eName);
struct FDE_CSSPROPERTYVALUETABLE {
  FDE_CSSPROPERTYVALUE eName;
  const FX_WCHAR* pszName;
  FX_DWORD dwHash;
};
typedef FDE_CSSPROPERTYVALUETABLE const* FDE_LPCCSSPROPERTYVALUETABLE;

FDE_LPCCSSPROPERTYVALUETABLE FDE_GetCSSPropertyValueByName(
    const FX_WCHAR* pszName,
    int32_t iLength);
FDE_LPCCSSPROPERTYVALUETABLE FDE_GetCSSPropertyValueByEnum(
    FDE_CSSPROPERTYVALUE eName);
struct FDE_CSSMEDIATYPETABLE {
  uint16_t wHash;
  uint16_t wValue;
};
typedef FDE_CSSMEDIATYPETABLE const* FDE_LPCCSSMEDIATYPETABLE;
FDE_LPCCSSMEDIATYPETABLE FDE_GetCSSMediaTypeByName(const FX_WCHAR* pszName,
                                                   int32_t iLength);
struct FDE_CSSLENGTHUNITTABLE {
  uint16_t wHash;
  uint16_t wValue;
};
typedef FDE_CSSLENGTHUNITTABLE const* FDE_LPCCSSLENGTHUNITTABLE;
FDE_LPCCSSLENGTHUNITTABLE FDE_GetCSSLengthUnitByName(const FX_WCHAR* pszName,
                                                     int32_t iLength);
struct FDE_CSSCOLORTABLE {
  FX_DWORD dwHash;
  FX_ARGB dwValue;
};
typedef FDE_CSSCOLORTABLE const* FDE_LPCCSSCOLORTABLE;
FDE_LPCCSSCOLORTABLE FDE_GetCSSColorByName(const FX_WCHAR* pszName,
                                           int32_t iLength);
struct FDE_CSSPERSUDOTABLE {
  FDE_CSSPERSUDO eName;
  const FX_WCHAR* pszName;
  FX_DWORD dwHash;
};
typedef FDE_CSSPERSUDOTABLE const* FDE_LPCCSSPERSUDOTABLE;

FDE_LPCCSSPERSUDOTABLE FDE_GetCSSPersudoByEnum(FDE_CSSPERSUDO ePersudo);
FX_BOOL FDE_ParseCSSNumber(const FX_WCHAR* pszValue,
                           int32_t iValueLen,
                           FX_FLOAT& fValue,
                           FDE_CSSPRIMITIVETYPE& eUnit);
FX_BOOL FDE_ParseCSSString(const FX_WCHAR* pszValue,
                           int32_t iValueLen,
                           int32_t& iOffset,
                           int32_t& iLength);
FX_BOOL FDE_ParseCSSColor(const FX_WCHAR* pszValue,
                          int32_t iValueLen,
                          FX_ARGB& dwColor);
FX_BOOL FDE_ParseCSSURI(const FX_WCHAR* pszValue,
                        int32_t iValueLen,
                        int32_t& iOffset,
                        int32_t& iLength);

#endif  // XFA_FDE_CSS_FDE_CSSDATATABLE_H_