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#include <utility>
28
29// tokens of the CSS1 parser
31{
33
38 CSS1_LENGTH, // absolute length in 1/100 MM
39 CSS1_PIXLENGTH, // length in pixels
43
55
57 CSS1_PAGE_SYM, // Feature: PrintExt
58
60
63};
64
66{
69};
70
72{
78 CSS1_SELTYPE_PAGE // Feature: PrintExt
79};
80
93{
95 OUString m_aSelector; // the selector itself
96 CSS1Selector *m_pNext; // the following component
97
98public:
99 CSS1Selector( CSS1SelectorType eTyp, OUString aSel )
100 : m_eType(eTyp), m_aSelector(std::move( aSel )), m_pNext( nullptr )
101 {}
102
104
105 CSS1SelectorType GetType() const { return m_eType; }
106 const OUString& GetString() const { return m_aSelector; }
107
108 void SetNext( CSS1Selector *pNxt ) { m_pNext = pNxt; }
109 const CSS1Selector *GetNext() const { return m_pNext; }
110};
111
120{
121private:
122 sal_Unicode cOp; // type of the link with its predecessor
123 CSS1Token eType; // type of the expression
124 OUString aValue; // value as string
125 double nValue; // value as number (TWIPs for LENGTH)
126 CSS1Expression *pNext; // the following component
127
128public:
129 CSS1Expression( CSS1Token eTyp, OUString aVal,
130 double nVal, sal_Unicode cO = 0 )
131 : cOp(cO), eType(eTyp), aValue(std::move(aVal)), nValue(nVal), pNext(nullptr)
132 {}
133
135
136 inline void Set( CSS1Token eTyp, const OUString &rVal, double nVal );
137
138 CSS1Token GetType() const { return eType; }
139 const OUString& GetString() const { return aValue; }
140 double GetNumber() const { return nValue; }
141 inline sal_uInt32 GetULength() const;
142 inline sal_Int32 GetSLength() const;
143 sal_Unicode GetOp() const { return cOp; }
144
145 void GetURL( OUString& rURL ) const;
146 bool GetColor( Color &rRGB ) const;
147
148 void SetNext( CSS1Expression *pNxt ) { pNext = pNxt; }
149 const CSS1Expression *GetNext() const { return pNext; }
150};
151
152inline void CSS1Expression::Set( CSS1Token eTyp, const OUString &rVal,
153 double nVal )
154{
155 cOp = 0; eType = eTyp; aValue = rVal; nValue = nVal; pNext = nullptr;
156}
157
158inline sal_uInt32 CSS1Expression::GetULength() const
159{
160 return nValue < 0. ? 0UL : static_cast<sal_uInt32>(nValue + .5);
161}
162
163inline sal_Int32 CSS1Expression::GetSLength() const
164{
165 return static_cast<sal_Int32>(nValue + (nValue < 0. ? -.5 : .5 ));
166}
167
182{
183 bool m_bWhiteSpace : 1; // read a whitespace?
184 bool m_bEOF : 1; // is end of "file"?
185
186 sal_Unicode m_cNextCh; // next character
187
188 sal_Int32 m_nInPos; // current position in the input string
189
190 sal_uInt32 m_nlLineNr; // current row number
191 sal_uInt32 m_nlLinePos; // current column number
192
193 double m_nValue; // value of the token as number
194
195 CSS1ParserState m_eState; // current state of the parser
196 CSS1Token m_nToken; // the current token
197
198 OUString m_aIn; // the string to parse
199 OUString m_aToken; // token as string
200
202 void InitRead( const OUString& rIn );
203
206
209
211 bool IsParserWorking() const { return CSS1_PAR_WORKING == m_eState; }
212
213 bool IsEOF() const { return m_bEOF; }
214
215 // parse parts of the grammar
216 void ParseRule();
217 std::unique_ptr<CSS1Selector> ParseSelector();
218 std::unique_ptr<CSS1Expression> ParseDeclaration( OUString& rProperty );
219
220protected:
221 void ParseStyleSheet();
222
230 void ParseStyleSheet( const OUString& rIn );
231
240 void ParseStyleOption( const OUString& rIn );
241
247 virtual void SelectorParsed( std::unique_ptr<CSS1Selector> pSelector, bool bFirst );
248
254 virtual void DeclarationParsed( const OUString& rProperty,
255 std::unique_ptr<CSS1Expression> pExpr );
256
257public:
258 CSS1Parser();
259 virtual ~CSS1Parser();
260};
261
262#endif
263
264/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Parser of a style element/option.
Definition: parcss1.hxx:182
bool IsParserWorking() const
Is the parser still working?
Definition: parcss1.hxx:211
double m_nValue
Definition: parcss1.hxx:193
CSS1Token GetNextToken()
Definition: parcss1.cxx:103
virtual ~CSS1Parser()
Definition: parcss1.cxx:1139
bool m_bEOF
Definition: parcss1.hxx:184
bool IsEOF() const
Definition: parcss1.hxx:213
sal_uInt32 m_nlLineNr
Definition: parcss1.hxx:190
bool m_bWhiteSpace
Definition: parcss1.hxx:183
OUString m_aIn
Definition: parcss1.hxx:198
void InitRead(const OUString &rIn)
prepare parsing
Definition: parcss1.cxx:57
virtual void SelectorParsed(std::unique_ptr< CSS1Selector > pSelector, bool bFirst)
Called after a selector was parsed.
Definition: parcss1.cxx:1214
virtual void DeclarationParsed(const OUString &rProperty, std::unique_ptr< CSS1Expression > pExpr)
Called after a declaration or property was parsed.
Definition: parcss1.cxx:1218
sal_Unicode GetNextChar()
Definition: parcss1.cxx:73
std::unique_ptr< CSS1Expression > ParseDeclaration(OUString &rProperty)
Definition: parcss1.cxx:1011
sal_Unicode m_cNextCh
Definition: parcss1.hxx:186
void ParseRule()
Definition: parcss1.cxx:752
OUString m_aToken
Definition: parcss1.hxx:199
void ParseStyleSheet()
Definition: parcss1.cxx:691
sal_uInt32 m_nlLinePos
Definition: parcss1.hxx:191
CSS1Token m_nToken
Definition: parcss1.hxx:196
CSS1ParserState m_eState
Definition: parcss1.hxx:195
void ParseStyleOption(const OUString &rIn)
parse the content of a HTML style option
Definition: parcss1.cxx:1173
sal_Int32 m_nInPos
Definition: parcss1.hxx:188
std::unique_ptr< CSS1Selector > ParseSelector()
Definition: parcss1.cxx:842
A simple selector.
Definition: parcss1.hxx:93
CSS1SelectorType GetType() const
Definition: parcss1.hxx:105
void SetNext(CSS1Selector *pNxt)
Definition: parcss1.hxx:108
const OUString & GetString() const
Definition: parcss1.hxx:106
CSS1SelectorType m_eType
Definition: parcss1.hxx:94
OUString m_aSelector
Definition: parcss1.hxx:95
CSS1Selector(CSS1SelectorType eTyp, OUString aSel)
Definition: parcss1.hxx:99
CSS1Selector * m_pNext
Definition: parcss1.hxx:96
const CSS1Selector * GetNext() const
Definition: parcss1.hxx:109
CSS1SelectorType
Definition: parcss1.hxx:72
@ CSS1_SELTYPE_ELEM_CLASS
Definition: parcss1.hxx:74
@ CSS1_SELTYPE_CLASS
Definition: parcss1.hxx:75
@ CSS1_SELTYPE_PAGE
Definition: parcss1.hxx:78
@ CSS1_SELTYPE_PSEUDO
Definition: parcss1.hxx:77
@ CSS1_SELTYPE_ELEMENT
Definition: parcss1.hxx:73
@ CSS1_SELTYPE_ID
Definition: parcss1.hxx:76
CSS1ParserState
Definition: parcss1.hxx:66
@ CSS1_PAR_ACCEPTED
Definition: parcss1.hxx:67
@ CSS1_PAR_WORKING
Definition: parcss1.hxx:68
CSS1Token
Definition: parcss1.hxx:31
@ CSS1_PAGE_SYM
Definition: parcss1.hxx:57
@ CSS1_MINUS
Definition: parcss1.hxx:49
@ CSS1_SEMICOLON
Definition: parcss1.hxx:52
@ CSS1_DOT_W_WS
Definition: parcss1.hxx:44
@ CSS1_OBRACE
Definition: parcss1.hxx:50
@ CSS1_PIXLENGTH
Definition: parcss1.hxx:39
@ CSS1_HASH
Definition: parcss1.hxx:54
@ CSS1_COLON
Definition: parcss1.hxx:46
@ CSS1_DOT_WO_WS
Definition: parcss1.hxx:45
@ CSS1_NUMBER
Definition: parcss1.hxx:36
@ CSS1_EMX
Definition: parcss1.hxx:41
@ CSS1_IMPORTANT_SYM
Definition: parcss1.hxx:59
@ CSS1_SLASH
Definition: parcss1.hxx:47
@ CSS1_IMPORT_SYM
Definition: parcss1.hxx:56
@ CSS1_RGB
Definition: parcss1.hxx:62
@ CSS1_PERCENTAGE
Definition: parcss1.hxx:37
@ CSS1_URL
Definition: parcss1.hxx:61
@ CSS1_COMMA
Definition: parcss1.hxx:53
@ CSS1_STRING
Definition: parcss1.hxx:35
@ CSS1_LENGTH
Definition: parcss1.hxx:38
@ CSS1_CBRACE
Definition: parcss1.hxx:51
@ CSS1_NULL
Definition: parcss1.hxx:32
@ CSS1_EMS
Definition: parcss1.hxx:40
@ CSS1_HEXCOLOR
Definition: parcss1.hxx:42
@ CSS1_IDENT
Definition: parcss1.hxx:34
@ CSS1_PLUS
Definition: parcss1.hxx:48
a subexpression of a CSS1 declaration
Definition: parcss1.hxx:120
CSS1Expression * pNext
Definition: parcss1.hxx:126
double GetNumber() const
Definition: parcss1.hxx:140
void SetNext(CSS1Expression *pNxt)
Definition: parcss1.hxx:148
CSS1Expression(CSS1Token eTyp, OUString aVal, double nVal, sal_Unicode cO=0)
Definition: parcss1.hxx:129
const CSS1Expression * GetNext() const
Definition: parcss1.hxx:149
OUString aValue
Definition: parcss1.hxx:124
CSS1Token GetType() const
Definition: parcss1.hxx:138
void Set(CSS1Token eTyp, const OUString &rVal, double nVal)
Definition: parcss1.hxx:152
void GetURL(OUString &rURL) const
Definition: parcss1.cxx:1233
double nValue
Definition: parcss1.hxx:125
sal_uInt32 GetULength() const
Definition: parcss1.hxx:158
sal_Unicode cOp
Definition: parcss1.hxx:122
CSS1Token eType
Definition: parcss1.hxx:123
sal_Unicode GetOp() const
Definition: parcss1.hxx:143
const OUString & GetString() const
Definition: parcss1.hxx:139
sal_Int32 GetSLength() const
Definition: parcss1.hxx:163
bool GetColor(Color &rRGB) const
Definition: parcss1.cxx:1259
sal_uInt16 sal_Unicode