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_CSSSYNTAX_H_ | |
8 #define XFA_SRC_FDE_CSS_FDE_CSSSYNTAX_H_ | |
9 | |
10 #include "xfa/src/fde/css/fde_css.h" | |
11 #include "xfa/src/fgas/crt/fgas_memory.h" | |
12 #include "xfa/src/fgas/crt/fgas_stream.h" | |
13 | |
14 class CFDE_CSSTextBuf : public CFX_Target { | |
15 public: | |
16 CFDE_CSSTextBuf(); | |
17 ~CFDE_CSSTextBuf(); | |
18 FX_BOOL AttachBuffer(const FX_WCHAR* pBuffer, int32_t iBufLen); | |
19 FX_BOOL EstimateSize(int32_t iAllocSize); | |
20 int32_t LoadFromStream(IFX_Stream* pTxtStream, | |
21 int32_t iStreamOffset, | |
22 int32_t iMaxChars, | |
23 FX_BOOL& bEOS); | |
24 FX_BOOL AppendChar(FX_WCHAR wch) { | |
25 if (m_iDatLen >= m_iBufLen && !ExpandBuf(m_iBufLen * 2)) { | |
26 return FALSE; | |
27 } | |
28 return (m_pBuffer[m_iDatLen++] = wch), TRUE; | |
29 } | |
30 void Clear() { m_iDatPos = m_iDatLen = 0; } | |
31 void Reset(); | |
32 int32_t TrimEnd() { | |
33 while (m_iDatLen > 0 && m_pBuffer[m_iDatLen - 1] <= ' ') { | |
34 --m_iDatLen; | |
35 } | |
36 AppendChar(0); | |
37 return --m_iDatLen; | |
38 } | |
39 void Subtract(int32_t iStart, int32_t iLength); | |
40 FX_BOOL IsEOF() const { return m_iDatPos >= m_iDatLen; } | |
41 FX_WCHAR GetAt(int32_t index) const { return m_pBuffer[index]; } | |
42 FX_WCHAR GetChar() const { return m_pBuffer[m_iDatPos]; } | |
43 FX_WCHAR GetNextChar() const { | |
44 return (m_iDatPos + 1 >= m_iDatLen) ? 0 : m_pBuffer[m_iDatPos + 1]; | |
45 } | |
46 void MoveNext() { m_iDatPos++; } | |
47 int32_t GetLength() const { return m_iDatLen; } | |
48 const FX_WCHAR* GetBuffer() const { return m_pBuffer; } | |
49 | |
50 protected: | |
51 FX_BOOL ExpandBuf(int32_t iDesiredSize); | |
52 FX_BOOL m_bExtBuf; | |
53 FX_WCHAR* m_pBuffer; | |
54 int32_t m_iBufLen; | |
55 int32_t m_iDatLen; | |
56 int32_t m_iDatPos; | |
57 }; | |
58 | |
59 #define FDE_CSSSYNTAXCHECK_AllowCharset 1 | |
60 #define FDE_CSSSYNTAXCHECK_AllowImport 2 | |
61 | |
62 enum FDE_CSSSYNTAXMODE { | |
63 FDE_CSSSYNTAXMODE_RuleSet, | |
64 FDE_CSSSYNTAXMODE_Comment, | |
65 FDE_CSSSYNTAXMODE_AtRule, | |
66 FDE_CSSSYNTAXMODE_UnknownRule, | |
67 FDE_CSSSYNTAXMODE_Charset, | |
68 FDE_CSSSYNTAXMODE_Import, | |
69 FDE_CSSSYNTAXMODE_MediaRule, | |
70 FDE_CSSSYNTAXMODE_URI, | |
71 FDE_CSSSYNTAXMODE_MediaType, | |
72 FDE_CSSSYNTAXMODE_Selector, | |
73 FDE_CSSSYNTAXMODE_PropertyName, | |
74 FDE_CSSSYNTAXMODE_PropertyValue, | |
75 }; | |
76 | |
77 class CFDE_CSSSyntaxParser : public IFDE_CSSSyntaxParser, public CFX_Target { | |
78 public: | |
79 CFDE_CSSSyntaxParser(); | |
80 ~CFDE_CSSSyntaxParser(); | |
81 virtual void Release() { delete this; } | |
82 virtual FX_BOOL Init(IFX_Stream* pStream, | |
83 int32_t iCSSPlaneSize, | |
84 int32_t iTextDataSize = 32, | |
85 FX_BOOL bOnlyDeclaration = FALSE); | |
86 virtual FX_BOOL Init(const FX_WCHAR* pBuffer, | |
87 int32_t iBufferSize, | |
88 int32_t iTextDatSize = 32, | |
89 FX_BOOL bOnlyDeclaration = FALSE); | |
90 virtual FDE_CSSSYNTAXSTATUS DoSyntaxParse(); | |
91 virtual const FX_WCHAR* GetCurrentString(int32_t& iLength) const; | |
92 | |
93 protected: | |
94 void Reset(FX_BOOL bOnlyDeclaration); | |
95 void SwitchMode(FDE_CSSSYNTAXMODE eMode); | |
96 int32_t SwitchToComment(); | |
97 | |
98 FX_BOOL RestoreMode(); | |
99 FX_BOOL AppendChar(FX_WCHAR wch); | |
100 int32_t SaveTextData(); | |
101 FX_BOOL IsCharsetEnabled() const { | |
102 return (m_dwCheck & FDE_CSSSYNTAXCHECK_AllowCharset) != 0; | |
103 } | |
104 void DisableCharset() { m_dwCheck = FDE_CSSSYNTAXCHECK_AllowImport; } | |
105 FX_BOOL IsImportEnabled() const; | |
106 void DisableImport() { m_dwCheck = 0; } | |
107 IFX_Stream* m_pStream; | |
108 int32_t m_iStreamPos; | |
109 int32_t m_iPlaneSize; | |
110 CFDE_CSSTextBuf m_TextData; | |
111 CFDE_CSSTextBuf m_TextPlane; | |
112 int32_t m_iTextDatLen; | |
113 FX_DWORD m_dwCheck; | |
114 FDE_CSSSYNTAXMODE m_eMode; | |
115 FDE_CSSSYNTAXSTATUS m_eStatus; | |
116 CFX_StackTemplate<FDE_CSSSYNTAXMODE> m_ModeStack; | |
117 }; | |
118 | |
119 #endif // XFA_SRC_FDE_CSS_FDE_CSSSYNTAX_H_ | |
OLD | NEW |