LibreOffice Module sw (master)  1
parcss1.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_SW_SOURCE_FILTER_HTML_PARCSS1_HXX
21 #define INCLUDED_SW_SOURCE_FILTER_HTML_PARCSS1_HXX
22 
23 #include <rtl/ustring.hxx>
24 #include <tools/color.hxx>
25 
26 #include <memory>
27 
28 // tokens of the CSS1 parser
30 {
32 
37  CSS1_LENGTH, // absolute length in 1/100 MM
38  CSS1_PIXLENGTH, // length in pixels
42 
54 
56  CSS1_PAGE_SYM, // Feature: PrintExt
57 
59 
62 };
63 
65 {
68 };
69 
71 {
77  CSS1_SELTYPE_PAGE // Feature: PrintExt
78 };
79 
92 {
93  CSS1SelectorType const eType; // the type
94  OUString const aSelector; // the selector itself
95  CSS1Selector *pNext; // the following component
96 
97 public:
98  CSS1Selector( CSS1SelectorType eTyp, const OUString &rSel )
99  : eType(eTyp), aSelector( rSel ), pNext( nullptr )
100  {}
101 
102  ~CSS1Selector();
103 
104  CSS1SelectorType GetType() const { return eType; }
105  const OUString& GetString() const { return aSelector; }
106 
107  void SetNext( CSS1Selector *pNxt ) { pNext = pNxt; }
108  const CSS1Selector *GetNext() const { return pNext; }
109 };
110 
119 {
120  sal_Unicode cOp; // type of the link with its predecessor
121  CSS1Token eType; // type of the expression
122  OUString aValue; // value as string
123  double nValue; // value as number (TWIPs for LENGTH)
124  CSS1Expression *pNext; // the following component
125 
126 public:
127  CSS1Expression( CSS1Token eTyp, const OUString &rVal,
128  double nVal, sal_Unicode cO = 0 )
129  : cOp(cO), eType(eTyp), aValue(rVal), nValue(nVal), pNext(nullptr)
130  {}
131 
132  ~CSS1Expression();
133 
134  inline void Set( CSS1Token eTyp, const OUString &rVal, double nVal );
135 
136  CSS1Token GetType() const { return eType; }
137  const OUString& GetString() const { return aValue; }
138  double GetNumber() const { return nValue; }
139  inline sal_uInt32 GetULength() const;
140  inline sal_Int32 GetSLength() const;
141  sal_Unicode GetOp() const { return cOp; }
142 
143  void GetURL( OUString& rURL ) const;
144  bool GetColor( Color &rRGB ) const;
145 
146  void SetNext( CSS1Expression *pNxt ) { pNext = pNxt; }
147  const CSS1Expression *GetNext() const { return pNext; }
148 };
149 
150 inline void CSS1Expression::Set( CSS1Token eTyp, const OUString &rVal,
151  double nVal )
152 {
153  cOp = 0; eType = eTyp; aValue = rVal; nValue = nVal; pNext = nullptr;
154 }
155 
156 inline sal_uInt32 CSS1Expression::GetULength() const
157 {
158  return nValue < 0. ? 0UL : static_cast<sal_uInt32>(nValue + .5);
159 }
160 
161 inline sal_Int32 CSS1Expression::GetSLength() const
162 {
163  return static_cast<sal_Int32>(nValue + (nValue < 0. ? -.5 : .5 ));
164 }
165 
180 {
181  bool m_bWhiteSpace : 1; // read a whitespace?
182  bool m_bEOF : 1; // is end of "file"?
183 
184  sal_Unicode m_cNextCh; // next character
185 
186  sal_Int32 m_nInPos; // current position in the input string
187 
188  sal_uInt32 m_nlLineNr; // current row number
189  sal_uInt32 m_nlLinePos; // current column number
190 
191  double m_nValue; // value of the token as number
192 
193  CSS1ParserState m_eState; // current state of the parser
194  CSS1Token m_nToken; // the current token
195 
196  OUString m_aIn; // the string to parse
197  OUString m_aToken; // token as string
198 
200  void InitRead( const OUString& rIn );
201 
204 
207 
209  bool IsParserWorking() const { return CSS1_PAR_WORKING == m_eState; }
210 
211  bool IsEOF() const { return m_bEOF; }
212 
213  // parse parts of the grammar
214  void ParseRule();
215  std::unique_ptr<CSS1Selector> ParseSelector();
216  std::unique_ptr<CSS1Expression> ParseDeclaration( OUString& rProperty );
217 
218 protected:
219  void ParseStyleSheet();
220 
228  void ParseStyleSheet( const OUString& rIn );
229 
238  void ParseStyleOption( const OUString& rIn );
239 
245  virtual void SelectorParsed( std::unique_ptr<CSS1Selector> pSelector, bool bFirst );
246 
252  virtual void DeclarationParsed( const OUString& rProperty,
253  std::unique_ptr<CSS1Expression> pExpr );
254 
255 public:
256  CSS1Parser();
257  virtual ~CSS1Parser();
258 };
259 
260 #endif
261 
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Unicode m_cNextCh
Definition: parcss1.hxx:184
double nValue
Definition: parcss1.hxx:123
CSS1Token GetNextToken()
Definition: parcss1.cxx:105
OUString m_aToken
Definition: parcss1.hxx:197
CSS1Expression(CSS1Token eTyp, const OUString &rVal, double nVal, sal_Unicode cO=0)
Definition: parcss1.hxx:127
CSS1ParserState m_eState
Definition: parcss1.hxx:193
void Set(CSS1Token eTyp, const OUString &rVal, double nVal)
Definition: parcss1.hxx:150
const OUString & GetString() const
Definition: parcss1.hxx:105
CSS1Token
Definition: parcss1.hxx:29
sal_Unicode GetOp() const
Definition: parcss1.hxx:141
bool m_bWhiteSpace
Definition: parcss1.hxx:181
bool IsParserWorking() const
Is the parser still working?
Definition: parcss1.hxx:209
sal_Unicode GetNextChar()
Definition: parcss1.cxx:75
a subexpression of a CSS1 declaration
Definition: parcss1.hxx:118
sal_uInt16 sal_Unicode
CSS1SelectorType
Definition: parcss1.hxx:70
void ParseStyleSheet()
Definition: parcss1.cxx:672
sal_Int32 m_nInPos
Definition: parcss1.hxx:186
const CSS1Expression * GetNext() const
Definition: parcss1.hxx:147
CSS1Token eType
Definition: parcss1.hxx:121
double m_nValue
Definition: parcss1.hxx:191
std::unique_ptr< CSS1Selector > ParseSelector()
Definition: parcss1.cxx:823
Parser of a style element/option.
Definition: parcss1.hxx:179
CSS1ParserState
Definition: parcss1.hxx:64
void SetNext(CSS1Expression *pNxt)
Definition: parcss1.hxx:146
CSS1Selector * pNext
Definition: parcss1.hxx:95
sal_uInt32 GetULength() const
Definition: parcss1.hxx:156
void ParseStyleOption(const OUString &rIn)
parse the content of a HTML style option
Definition: parcss1.cxx:1153
sal_Unicode cOp
Definition: parcss1.hxx:120
CSS1Selector(CSS1SelectorType eTyp, const OUString &rSel)
Definition: parcss1.hxx:98
CSS1Token m_nToken
Definition: parcss1.hxx:194
bool IsEOF() const
Definition: parcss1.hxx:211
OUString const aSelector
Definition: parcss1.hxx:94
std::unique_ptr< CSS1Expression > ParseDeclaration(OUString &rProperty)
Definition: parcss1.cxx:991
const CSS1Selector * GetNext() const
Definition: parcss1.hxx:108
const OUString & GetString() const
Definition: parcss1.hxx:137
sal_Int32 GetSLength() const
Definition: parcss1.hxx:161
OUString aValue
Definition: parcss1.hxx:122
virtual void SelectorParsed(std::unique_ptr< CSS1Selector > pSelector, bool bFirst)
Called after a selector was parsed.
Definition: parcss1.cxx:1194
bool GetColor(Color &rRGB) const
Definition: parcss1.cxx:1239
sal_uInt32 m_nlLineNr
Definition: parcss1.hxx:188
CSS1SelectorType const eType
Definition: parcss1.hxx:93
void ParseRule()
Definition: parcss1.cxx:733
void InitRead(const OUString &rIn)
prepare parsing
Definition: parcss1.cxx:59
CSS1Token GetType() const
Definition: parcss1.hxx:136
CSS1SelectorType GetType() const
Definition: parcss1.hxx:104
OUString m_aIn
Definition: parcss1.hxx:196
void GetURL(OUString &rURL) const
Definition: parcss1.cxx:1213
virtual void DeclarationParsed(const OUString &rProperty, std::unique_ptr< CSS1Expression > pExpr)
Called after a declaration or property was parsed.
Definition: parcss1.cxx:1198
virtual ~CSS1Parser()
Definition: parcss1.cxx:1119
double GetNumber() const
Definition: parcss1.hxx:138
A simple selector.
Definition: parcss1.hxx:91
CSS1Expression * pNext
Definition: parcss1.hxx:124
bool m_bEOF
Definition: parcss1.hxx:182
void SetNext(CSS1Selector *pNxt)
Definition: parcss1.hxx:107
sal_uInt32 m_nlLinePos
Definition: parcss1.hxx:189