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 // tokens of the CSS1 parser
25 {
27 
32  CSS1_LENGTH, // absolute length in 1/100 MM
33  CSS1_PIXLENGTH, // length in pixels
37 
49 
51  CSS1_PAGE_SYM, // Feature: PrintExt
52 
54 
57 };
58 
60 {
63 };
64 
66 {
72  CSS1_SELTYPE_PAGE // Feature: PrintExt
73 };
74 
87 {
88  CSS1SelectorType const eType; // the type
89  OUString const aSelector; // the selector itself
90  CSS1Selector *pNext; // the following component
91 
92 public:
93  CSS1Selector( CSS1SelectorType eTyp, const OUString &rSel )
94  : eType(eTyp), aSelector( rSel ), pNext( nullptr )
95  {}
96 
97  ~CSS1Selector();
98 
99  CSS1SelectorType GetType() const { return eType; }
100  const OUString& GetString() const { return aSelector; }
101 
102  void SetNext( CSS1Selector *pNxt ) { pNext = pNxt; }
103  const CSS1Selector *GetNext() const { return pNext; }
104 };
105 
114 {
115  sal_Unicode cOp; // type of the link with its predecessor
116  CSS1Token eType; // type of the expression
117  OUString aValue; // value as string
118  double nValue; // value as number (TWIPs for LENGTH)
119  CSS1Expression *pNext; // the following component
120 
121 public:
122  CSS1Expression( CSS1Token eTyp, const OUString &rVal,
123  double nVal, sal_Unicode cO = 0 )
124  : cOp(cO), eType(eTyp), aValue(rVal), nValue(nVal), pNext(nullptr)
125  {}
126 
127  ~CSS1Expression();
128 
129  inline void Set( CSS1Token eTyp, const OUString &rVal, double nVal );
130 
131  CSS1Token GetType() const { return eType; }
132  const OUString& GetString() const { return aValue; }
133  double GetNumber() const { return nValue; }
134  inline sal_uInt32 GetULength() const;
135  inline sal_Int32 GetSLength() const;
136  sal_Unicode GetOp() const { return cOp; }
137 
138  void GetURL( OUString& rURL ) const;
139  bool GetColor( Color &rRGB ) const;
140 
141  void SetNext( CSS1Expression *pNxt ) { pNext = pNxt; }
142  const CSS1Expression *GetNext() const { return pNext; }
143 };
144 
145 inline void CSS1Expression::Set( CSS1Token eTyp, const OUString &rVal,
146  double nVal )
147 {
148  cOp = 0; eType = eTyp; aValue = rVal; nValue = nVal; pNext = nullptr;
149 }
150 
151 inline sal_uInt32 CSS1Expression::GetULength() const
152 {
153  return nValue < 0. ? 0UL : static_cast<sal_uInt32>(nValue + .5);
154 }
155 
156 inline sal_Int32 CSS1Expression::GetSLength() const
157 {
158  return static_cast<sal_Int32>(nValue + (nValue < 0. ? -.5 : .5 ));
159 }
160 
175 {
176  bool m_bWhiteSpace : 1; // read a whitespace?
177  bool m_bEOF : 1; // is end of "file"?
178 
179  sal_Unicode m_cNextCh; // next character
180 
181  sal_Int32 m_nInPos; // current position in the input string
182 
183  sal_uInt32 m_nlLineNr; // current row number
184  sal_uInt32 m_nlLinePos; // current column number
185 
186  double m_nValue; // value of the token as number
187 
188  CSS1ParserState m_eState; // current state of the parser
189  CSS1Token m_nToken; // the current token
190 
191  OUString m_aIn; // the string to parse
192  OUString m_aToken; // token as string
193 
195  void InitRead( const OUString& rIn );
196 
199 
202 
204  bool IsParserWorking() const { return CSS1_PAR_WORKING == m_eState; }
205 
206  bool IsEOF() const { return m_bEOF; }
207 
208  // parse parts of the grammar
209  void ParseRule();
210  std::unique_ptr<CSS1Selector> ParseSelector();
211  std::unique_ptr<CSS1Expression> ParseDeclaration( OUString& rProperty );
212 
213 protected:
214  void ParseStyleSheet();
215 
223  void ParseStyleSheet( const OUString& rIn );
224 
233  void ParseStyleOption( const OUString& rIn );
234 
240  virtual void SelectorParsed( std::unique_ptr<CSS1Selector> pSelector, bool bFirst );
241 
247  virtual void DeclarationParsed( const OUString& rProperty,
248  std::unique_ptr<CSS1Expression> pExpr );
249 
250 public:
251  CSS1Parser();
252  virtual ~CSS1Parser();
253 };
254 
255 #endif
256 
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Unicode m_cNextCh
Definition: parcss1.hxx:179
double nValue
Definition: parcss1.hxx:118
CSS1Token GetNextToken()
Definition: parcss1.cxx:105
OUString m_aToken
Definition: parcss1.hxx:192
CSS1Expression(CSS1Token eTyp, const OUString &rVal, double nVal, sal_Unicode cO=0)
Definition: parcss1.hxx:122
CSS1ParserState m_eState
Definition: parcss1.hxx:188
void Set(CSS1Token eTyp, const OUString &rVal, double nVal)
Definition: parcss1.hxx:145
const OUString & GetString() const
Definition: parcss1.hxx:100
CSS1Token
Definition: parcss1.hxx:24
sal_Unicode GetOp() const
Definition: parcss1.hxx:136
bool m_bWhiteSpace
Definition: parcss1.hxx:176
bool IsParserWorking() const
Is the parser still working?
Definition: parcss1.hxx:204
sal_Unicode GetNextChar()
Definition: parcss1.cxx:75
a subexpression of a CSS1 declaration
Definition: parcss1.hxx:113
sal_uInt16 sal_Unicode
CSS1SelectorType
Definition: parcss1.hxx:65
void ParseStyleSheet()
Definition: parcss1.cxx:672
sal_Int32 m_nInPos
Definition: parcss1.hxx:181
const CSS1Expression * GetNext() const
Definition: parcss1.hxx:142
CSS1Token eType
Definition: parcss1.hxx:116
double m_nValue
Definition: parcss1.hxx:186
std::unique_ptr< CSS1Selector > ParseSelector()
Definition: parcss1.cxx:823
Parser of a style element/option.
Definition: parcss1.hxx:174
CSS1ParserState
Definition: parcss1.hxx:59
void SetNext(CSS1Expression *pNxt)
Definition: parcss1.hxx:141
CSS1Selector * pNext
Definition: parcss1.hxx:90
sal_uInt32 GetULength() const
Definition: parcss1.hxx:151
void ParseStyleOption(const OUString &rIn)
parse the content of a HTML style option
Definition: parcss1.cxx:1153
sal_Unicode cOp
Definition: parcss1.hxx:115
CSS1Selector(CSS1SelectorType eTyp, const OUString &rSel)
Definition: parcss1.hxx:93
CSS1Token m_nToken
Definition: parcss1.hxx:189
bool IsEOF() const
Definition: parcss1.hxx:206
OUString const aSelector
Definition: parcss1.hxx:89
std::unique_ptr< CSS1Expression > ParseDeclaration(OUString &rProperty)
Definition: parcss1.cxx:991
const CSS1Selector * GetNext() const
Definition: parcss1.hxx:103
const OUString & GetString() const
Definition: parcss1.hxx:132
sal_Int32 GetSLength() const
Definition: parcss1.hxx:156
OUString aValue
Definition: parcss1.hxx:117
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:183
CSS1SelectorType const eType
Definition: parcss1.hxx:88
void ParseRule()
Definition: parcss1.cxx:733
void InitRead(const OUString &rIn)
prepare parsing
Definition: parcss1.cxx:59
CSS1Token GetType() const
Definition: parcss1.hxx:131
CSS1SelectorType GetType() const
Definition: parcss1.hxx:99
OUString m_aIn
Definition: parcss1.hxx:191
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:133
A simple selector.
Definition: parcss1.hxx:86
CSS1Expression * pNext
Definition: parcss1.hxx:119
bool m_bEOF
Definition: parcss1.hxx:177
void SetNext(CSS1Selector *pNxt)
Definition: parcss1.hxx:102
sal_uInt32 m_nlLinePos
Definition: parcss1.hxx:184