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{
121 sal_Unicode cOp; // type of the link with its predecessor
122 CSS1Token eType; // type of the expression
123 OUString aValue; // value as string
124 double nValue; // value as number (TWIPs for LENGTH)
125 CSS1Expression *pNext; // the following component
126
127public:
128 CSS1Expression( CSS1Token eTyp, OUString aVal,
129 double nVal, sal_Unicode cO = 0 )
130 : cOp(cO), eType(eTyp), aValue(std::move(aVal)), nValue(nVal), pNext(nullptr)
131 {}
132
134
135 inline void Set( CSS1Token eTyp, const OUString &rVal, double nVal );
136
137 CSS1Token GetType() const { return eType; }
138 const OUString& GetString() const { return aValue; }
139 double GetNumber() const { return nValue; }
140 inline sal_uInt32 GetULength() const;
141 inline sal_Int32 GetSLength() const;
142 sal_Unicode GetOp() const { return cOp; }
143
144 void GetURL( OUString& rURL ) const;
145 bool GetColor( Color &rRGB ) const;
146
147 void SetNext( CSS1Expression *pNxt ) { pNext = pNxt; }
148 const CSS1Expression *GetNext() const { return pNext; }
149};
150
151inline void CSS1Expression::Set( CSS1Token eTyp, const OUString &rVal,
152 double nVal )
153{
154 cOp = 0; eType = eTyp; aValue = rVal; nValue = nVal; pNext = nullptr;
155}
156
157inline sal_uInt32 CSS1Expression::GetULength() const
158{
159 return nValue < 0. ? 0UL : static_cast<sal_uInt32>(nValue + .5);
160}
161
162inline sal_Int32 CSS1Expression::GetSLength() const
163{
164 return static_cast<sal_Int32>(nValue + (nValue < 0. ? -.5 : .5 ));
165}
166
181{
182 bool m_bWhiteSpace : 1; // read a whitespace?
183 bool m_bEOF : 1; // is end of "file"?
184
185 sal_Unicode m_cNextCh; // next character
186
187 sal_Int32 m_nInPos; // current position in the input string
188
189 sal_uInt32 m_nlLineNr; // current row number
190 sal_uInt32 m_nlLinePos; // current column number
191
192 double m_nValue; // value of the token as number
193
194 CSS1ParserState m_eState; // current state of the parser
195 CSS1Token m_nToken; // the current token
196
197 OUString m_aIn; // the string to parse
198 OUString m_aToken; // token as string
199
201 void InitRead( const OUString& rIn );
202
205
208
210 bool IsParserWorking() const { return CSS1_PAR_WORKING == m_eState; }
211
212 bool IsEOF() const { return m_bEOF; }
213
214 // parse parts of the grammar
215 void ParseRule();
216 std::unique_ptr<CSS1Selector> ParseSelector();
217 std::unique_ptr<CSS1Expression> ParseDeclaration( OUString& rProperty );
218
219protected:
220 void ParseStyleSheet();
221
229 void ParseStyleSheet( const OUString& rIn );
230
239 void ParseStyleOption( const OUString& rIn );
240
246 virtual void SelectorParsed( std::unique_ptr<CSS1Selector> pSelector, bool bFirst );
247
253 virtual void DeclarationParsed( const OUString& rProperty,
254 std::unique_ptr<CSS1Expression> pExpr );
255
256public:
257 CSS1Parser();
258 virtual ~CSS1Parser();
259};
260
261#endif
262
263/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Parser of a style element/option.
Definition: parcss1.hxx:181
bool IsParserWorking() const
Is the parser still working?
Definition: parcss1.hxx:210
double m_nValue
Definition: parcss1.hxx:192
CSS1Token GetNextToken()
Definition: parcss1.cxx:103
virtual ~CSS1Parser()
Definition: parcss1.cxx:1118
bool m_bEOF
Definition: parcss1.hxx:183
bool IsEOF() const
Definition: parcss1.hxx:212
sal_uInt32 m_nlLineNr
Definition: parcss1.hxx:189
bool m_bWhiteSpace
Definition: parcss1.hxx:182
OUString m_aIn
Definition: parcss1.hxx:197
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:1193
virtual void DeclarationParsed(const OUString &rProperty, std::unique_ptr< CSS1Expression > pExpr)
Called after a declaration or property was parsed.
Definition: parcss1.cxx:1197
sal_Unicode GetNextChar()
Definition: parcss1.cxx:73
std::unique_ptr< CSS1Expression > ParseDeclaration(OUString &rProperty)
Definition: parcss1.cxx:990
sal_Unicode m_cNextCh
Definition: parcss1.hxx:185
void ParseRule()
Definition: parcss1.cxx:731
OUString m_aToken
Definition: parcss1.hxx:198
void ParseStyleSheet()
Definition: parcss1.cxx:670
sal_uInt32 m_nlLinePos
Definition: parcss1.hxx:190
CSS1Token m_nToken
Definition: parcss1.hxx:195
CSS1ParserState m_eState
Definition: parcss1.hxx:194
void ParseStyleOption(const OUString &rIn)
parse the content of a HTML style option
Definition: parcss1.cxx:1152
sal_Int32 m_nInPos
Definition: parcss1.hxx:187
std::unique_ptr< CSS1Selector > ParseSelector()
Definition: parcss1.cxx:821
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:125
double GetNumber() const
Definition: parcss1.hxx:139
void SetNext(CSS1Expression *pNxt)
Definition: parcss1.hxx:147
CSS1Expression(CSS1Token eTyp, OUString aVal, double nVal, sal_Unicode cO=0)
Definition: parcss1.hxx:128
const CSS1Expression * GetNext() const
Definition: parcss1.hxx:148
OUString aValue
Definition: parcss1.hxx:123
CSS1Token GetType() const
Definition: parcss1.hxx:137
void Set(CSS1Token eTyp, const OUString &rVal, double nVal)
Definition: parcss1.hxx:151
void GetURL(OUString &rURL) const
Definition: parcss1.cxx:1212
double nValue
Definition: parcss1.hxx:124
sal_uInt32 GetULength() const
Definition: parcss1.hxx:157
sal_Unicode cOp
Definition: parcss1.hxx:121
CSS1Token eType
Definition: parcss1.hxx:122
sal_Unicode GetOp() const
Definition: parcss1.hxx:142
const OUString & GetString() const
Definition: parcss1.hxx:138
sal_Int32 GetSLength() const
Definition: parcss1.hxx:162
bool GetColor(Color &rRGB) const
Definition: parcss1.cxx:1238
sal_uInt16 sal_Unicode