• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 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_FDE_CSS_CFDE_CSSSYNTAXPARSER_H_
8 #define XFA_FDE_CSS_CFDE_CSSSYNTAXPARSER_H_
9 
10 #include <stack>
11 
12 #include "xfa/fde/css/cfde_csstextbuf.h"
13 
14 #define FDE_CSSSYNTAXCHECK_AllowCharset 1
15 #define FDE_CSSSYNTAXCHECK_AllowImport 2
16 
17 enum class FDE_CSSSyntaxMode {
18   RuleSet,
19   Comment,
20   UnknownRule,
21   Selector,
22   PropertyName,
23   PropertyValue,
24 };
25 
26 enum class FDE_CSSSyntaxStatus : uint8_t {
27   Error,
28   EOS,
29   None,
30   StyleRule,
31   Selector,
32   DeclOpen,
33   DeclClose,
34   PropertyName,
35   PropertyValue,
36 };
37 
38 class CFDE_CSSSyntaxParser {
39  public:
40   CFDE_CSSSyntaxParser();
41   ~CFDE_CSSSyntaxParser();
42 
43   bool Init(const FX_WCHAR* pBuffer,
44             int32_t iBufferSize,
45             int32_t iTextDatSize = 32,
46             bool bOnlyDeclaration = false);
47   FDE_CSSSyntaxStatus DoSyntaxParse();
48   CFX_WideStringC GetCurrentString() const;
49 
50  protected:
51   void Reset(bool bOnlyDeclaration);
52   void SwitchMode(FDE_CSSSyntaxMode eMode);
53   int32_t SwitchToComment();
54 
55   bool RestoreMode();
56   bool AppendChar(FX_WCHAR wch);
57   int32_t SaveTextData();
IsCharsetEnabled()58   bool IsCharsetEnabled() const {
59     return (m_dwCheck & FDE_CSSSYNTAXCHECK_AllowCharset) != 0;
60   }
DisableCharset()61   void DisableCharset() { m_dwCheck = FDE_CSSSYNTAXCHECK_AllowImport; }
62   bool IsImportEnabled() const;
DisableImport()63   void DisableImport() { m_dwCheck = 0; }
64 
65   CFDE_CSSTextBuf m_TextData;
66   CFDE_CSSTextBuf m_TextPlane;
67   int32_t m_iTextDataLen;
68   uint32_t m_dwCheck;
69   FDE_CSSSyntaxMode m_eMode;
70   FDE_CSSSyntaxStatus m_eStatus;
71   std::stack<FDE_CSSSyntaxMode> m_ModeStack;
72 };
73 
74 #endif  // XFA_FDE_CSS_CFDE_CSSSYNTAXPARSER_H_
75