LibreOffice Module sw (master) 1
svxcss1.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#ifndef INCLUDED_SW_SOURCE_FILTER_HTML_SVXCSS1_HXX
20#define INCLUDED_SW_SOURCE_FILTER_HTML_SVXCSS1_HXX
21
22#include <svl/itemset.hxx>
23#include <editeng/svxenum.hxx>
24#include <rtl/textenc.h>
25#include "parcss1.hxx"
28
29#include <array>
30#include <map>
31#include <memory>
32#include <vector>
33
34class SfxItemPool;
35class SvxBoxItem;
36class FontList;
37enum class SvxBoxItemLine;
38
40{
41 SVX_CSS1_POS_NONE, // nothing specified
45};
46
48{
49 SVX_CSS1_LTYPE_NONE, // nothing specified
50 SVX_CSS1_LTYPE_AUTO, // automatic
52 SVX_CSS1_LTYPE_PERCENTAGE, // percentage value
53};
54
55// Feature: PrintExt
57{
58 SVX_CSS1_STYPE_NONE, // nothing specified
59 SVX_CSS1_STYPE_AUTO, // automatic
63};
64
66{
67 SVX_CSS1_PBREAK_NONE, // nothing specified
71 SVX_CSS1_PBREAK_LEFT, // next page is a left one
72 SVX_CSS1_PBREAK_RIGHT, // next page is a right one
73};
74
75
76enum class Css1ScriptFlags {
77 Western = 0x01,
78 CJK = 0x02,
79 CTL = 0x04,
80 AllMask = Western | CJK | CTL,
81};
82namespace o3tl {
83 template<> struct typed_flags<Css1ScriptFlags> : is_typed_flags<Css1ScriptFlags, 0x07> {};
84}
85
87{
88 const char *pName; // property value
89 sal_uInt16 nEnum; // and the corresponding value of enum
90};
91
92namespace editeng { class SvxBorderLine; }
93
94#define SVX_CSS1_BORDERINFO_WIDTH 1
95#define SVX_CSS1_BORDERINFO_COLOR 2
96#define SVX_CSS1_BORDERINFO_STYLE 4
97
100{
101 std::array<std::unique_ptr<SvxCSS1BorderInfo>,4> m_aBorderInfos;
102
103 void DestroyBorderInfos();
104
105public:
106 static constexpr sal_uInt16 UNSET_BORDER_DISTANCE = SAL_MAX_UINT16;
107
108 OUString m_aId; // ID for bookmarks, frame, and so
109
110 bool m_bTopMargin : 1;
112
116 bool m_bNumbering : 1;
117 bool m_bBullet : 1;
118
120
122
127
130
131 sal_uInt16 m_nColumnCount;
132
136
139
141
144
145 bool m_bVisible = true;
146
150
151 void Merge( const SvxCSS1PropertyInfo& rProp );
152
153 void Clear();
154
155 SvxCSS1BorderInfo *GetBorderInfo( SvxBoxItemLine nLine, bool bCreate=true );
156 void CopyBorderInfo( SvxBoxItemLine nSrcLine, SvxBoxItemLine nDstLine, sal_uInt16 nWhat );
157 void CopyBorderInfo( sal_uInt16 nCount, sal_uInt16 nWhat );
158
159 void SetBoxItem( SfxItemSet& rItemSet, sal_uInt16 nMinBorderDist,
160 const SvxBoxItem* pDflt=nullptr );
161
162};
163
165{
168
169public:
170 SvxCSS1MapEntry( SfxItemSet aItemSet,
171 const SvxCSS1PropertyInfo& rProp );
172
173 const SfxItemSet& GetItemSet() const { return m_aItemSet; }
175
178};
179
180// Class is processing the CSS1-Parser output by converting the CSS1 properties
181// into SvxItem(Set). Also the selectors together with associated ItemSet are
182// saved.
183// A derived parser can suppress this for certain selectors by overriding
184// the method StyleParsed.
185
187{
188 typedef std::vector<std::unique_ptr<CSS1Selector>> CSS1Selectors;
189 typedef std::map<OUString, std::unique_ptr<SvxCSS1MapEntry>> CSS1Map;
190 CSS1Selectors m_Selectors; // List of "open" Selectors
191
196
197 OUString m_sBaseURL;
198
199 std::unique_ptr<SfxItemSet> m_pSheetItemSet; // item set of Style-Sheet
200 SfxItemSet *m_pItemSet; // current item set
201
202 std::unique_ptr<SvxCSS1PropertyInfo> m_pSheetPropInfo;
204
205 // minimum spacing for fixed line spacing
206 static constexpr sal_uInt16 gnMinFixLineSpace = o3tl::toTwips(25, o3tl::Length::mm10);
207
208 rtl_TextEncoding m_eDefaultEnc;
210 WhichRangesContainer m_aWhichMap; // Which-Map of Parser
211
213
214protected:
215
217
218 // This method is called for every selector with according item set.
219 // For a selector multiple calls are possible.
220 // If true is returned then the item set resp. the selector isn't saved anymore!
221 // The ItemSet may be modified accordingly!
222 // The implementation returns false.
223 virtual void StyleParsed( const CSS1Selector *pSelector,
224 SfxItemSet& rItemSet,
225 SvxCSS1PropertyInfo& rPropInfo );
226
231 virtual void SelectorParsed( std::unique_ptr<CSS1Selector> pSelector, bool bFirst ) override;
232
236 virtual void DeclarationParsed( const OUString& rProperty,
237 std::unique_ptr<CSS1Expression> pExpr ) override;
238
239public:
240
242 OUString aBaseURL,
243 sal_uInt16 const *pWhichIds, sal_uInt16 nWhichIds );
244 virtual ~SvxCSS1Parser() override;
245
247 void SetIgnoreFontFamily( bool bSet ) { m_bIgnoreFontFamily = bSet; }
248
249 // Parse a style sheet. For every found selector a StyleParsed with
250 // according item set is called.
251 virtual bool ParseStyleSheet( const OUString& rIn );
252
253 // Parse style option. Here only the item set is filled.
254 void ParseStyleOption( const OUString& rIn, SfxItemSet& rItemSet,
255 SvxCSS1PropertyInfo& rPropInfo );
256
257 // convert a string to enum value
258 static bool GetEnum( const CSS1PropertyEnum *pPropTable,
259 const OUString& rValue, sal_uInt16 &rEnum );
260
261 static void PixelToTwip( tools::Long &nWidth, tools::Long &nHeight );
262
263 // determine the font height of a certain font size (0-6)
264 virtual sal_uInt32 GetFontHeight( sal_uInt16 nSize ) const;
265
266 virtual const FontList *GetFontList() const;
267
269
270 static void InsertMapEntry( const OUString& rKey, const SfxItemSet& rItemSet,
271 const SvxCSS1PropertyInfo& rProp, CSS1Map& rMap );
272
273 void InsertId( const OUString& rId, const SfxItemSet& rItemSet,
274 const SvxCSS1PropertyInfo& rProp );
275
276 const SvxCSS1MapEntry* GetId( const OUString& rId ) const;
277
278 void InsertClass( const OUString& rClass, const SfxItemSet& rItemSet,
279 const SvxCSS1PropertyInfo& rProp );
280
281 const SvxCSS1MapEntry* GetClass( const OUString& rClass ) const;
282
283 void InsertPage( const OUString& rPage, bool bPseudo,
284 const SfxItemSet& rItemSet,
285 const SvxCSS1PropertyInfo& rProp );
286
287 SvxCSS1MapEntry* GetPage( const OUString& rPage, bool bPseudo );
288
289 void InsertTag( const OUString& rTag, const SfxItemSet& rItemSet,
290 const SvxCSS1PropertyInfo& rProp );
291
292 SvxCSS1MapEntry* GetTag( const OUString& rTag );
293
294 static void MergeStyles( const SfxItemSet& rSrcSet,
295 const SvxCSS1PropertyInfo& rSrcInfo,
296 SfxItemSet& rTargetSet,
297 SvxCSS1PropertyInfo& rTargetInfo,
298 bool bSmart );
299
300 static sal_uInt16 GetMinFixLineSpace() { return gnMinFixLineSpace; }
301
302 virtual void SetDfltEncoding( rtl_TextEncoding eEnc );
303 rtl_TextEncoding GetDfltEncoding() const { return m_eDefaultEnc; }
304
305 const OUString& GetBaseURL() const { return m_sBaseURL;}
306
307};
308
309#endif
310
311/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvxBoxItemLine
Parser of a style element/option.
Definition: parcss1.hxx:181
void ParseStyleSheet()
Definition: parcss1.cxx:670
void ParseStyleOption(const OUString &rIn)
parse the content of a HTML style option
Definition: parcss1.cxx:1152
A simple selector.
Definition: parcss1.hxx:93
SfxItemSet m_aItemSet
Definition: svxcss1.hxx:166
SvxCSS1PropertyInfo & GetPropertyInfo()
Definition: svxcss1.hxx:177
SvxCSS1PropertyInfo m_aPropInfo
Definition: svxcss1.hxx:167
SfxItemSet & GetItemSet()
Definition: svxcss1.hxx:174
SvxCSS1MapEntry(SfxItemSet aItemSet, const SvxCSS1PropertyInfo &rProp)
Definition: svxcss1.cxx:663
const SvxCSS1PropertyInfo & GetPropertyInfo() const
Definition: svxcss1.hxx:176
const SfxItemSet & GetItemSet() const
Definition: svxcss1.hxx:173
std::unique_ptr< SfxItemSet > m_pSheetItemSet
Definition: svxcss1.hxx:199
void InsertPage(const OUString &rPage, bool bPseudo, const SfxItemSet &rItemSet, const SvxCSS1PropertyInfo &rProp)
Definition: svxcss1.cxx:788
void SetIgnoreFontFamily(bool bSet)
Definition: svxcss1.hxx:247
const SvxCSS1MapEntry * GetId(const OUString &rId) const
Definition: svxcss1.cxx:769
void InsertId(const OUString &rId, const SfxItemSet &rItemSet, const SvxCSS1PropertyInfo &rProp)
Definition: svxcss1.cxx:762
void ParseStyleOption(const OUString &rIn, SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo)
Definition: svxcss1.cxx:845
CSS1Map m_Ids
Definition: svxcss1.hxx:192
CSS1Selectors m_Selectors
Definition: svxcss1.hxx:190
bool IsIgnoreFontFamily() const
Definition: svxcss1.hxx:246
CSS1Map m_Pages
Definition: svxcss1.hxx:194
std::unique_ptr< SvxCSS1PropertyInfo > m_pSheetPropInfo
Definition: svxcss1.hxx:202
SvxCSS1MapEntry * GetTag(const OUString &rTag)
Definition: svxcss1.cxx:816
virtual void SetDfltEncoding(rtl_TextEncoding eEnc)
Definition: svxcss1.cxx:979
rtl_TextEncoding GetDfltEncoding() const
Definition: svxcss1.hxx:303
void InsertClass(const OUString &rClass, const SfxItemSet &rItemSet, const SvxCSS1PropertyInfo &rProp)
Definition: svxcss1.cxx:775
static void PixelToTwip(tools::Long &nWidth, tools::Long &nHeight)
Definition: svxcss1.cxx:876
CSS1Map m_Tags
Definition: svxcss1.hxx:195
SfxItemSet * m_pItemSet
Definition: svxcss1.hxx:200
static void InsertMapEntry(const OUString &rKey, const SfxItemSet &rItemSet, const SvxCSS1PropertyInfo &rProp, CSS1Map &rMap)
Definition: svxcss1.cxx:913
virtual void StyleParsed(const CSS1Selector *pSelector, SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo)
Definition: svxcss1.cxx:669
static sal_uInt16 GetMinFixLineSpace()
Definition: svxcss1.hxx:300
OUString m_sBaseURL
Definition: svxcss1.hxx:197
rtl_TextEncoding m_eDefaultEnc
Definition: svxcss1.hxx:208
std::map< OUString, std::unique_ptr< SvxCSS1MapEntry > > CSS1Map
Definition: svxcss1.hxx:189
static void MergeStyles(const SfxItemSet &rSrcSet, const SvxCSS1PropertyInfo &rSrcInfo, SfxItemSet &rTargetSet, SvxCSS1PropertyInfo &rTargetInfo, bool bSmart)
Definition: svxcss1.cxx:931
virtual void DeclarationParsed(const OUString &rProperty, std::unique_ptr< CSS1Expression > pExpr) override
Will be called for every parsed Property.
Definition: svxcss1.cxx:3154
const SvxCSS1MapEntry * GetClass(const OUString &rClass) const
Definition: svxcss1.cxx:782
SvxCSS1MapEntry * GetPage(const OUString &rPage, bool bPseudo)
Definition: svxcss1.cxx:799
virtual sal_uInt32 GetFontHeight(sal_uInt16 nSize) const
Definition: svxcss1.cxx:889
const OUString & GetBaseURL() const
Definition: svxcss1.hxx:305
void ParseStyleSheet()
Definition: parcss1.cxx:670
virtual void SelectorParsed(std::unique_ptr< CSS1Selector > pSelector, bool bFirst) override
Will be called when a Selector is parsed.
Definition: svxcss1.cxx:676
CSS1Map m_Classes
Definition: svxcss1.hxx:193
virtual ~SvxCSS1Parser() override
Definition: svxcss1.cxx:756
std::vector< std::unique_ptr< CSS1Selector > > CSS1Selectors
Definition: svxcss1.hxx:188
SvxCSS1Parser(SfxItemPool &rPool, OUString aBaseURL, sal_uInt16 const *pWhichIds, sal_uInt16 nWhichIds)
Definition: svxcss1.cxx:696
WhichRangesContainer m_aWhichMap
Definition: svxcss1.hxx:210
bool m_bIgnoreFontFamily
Definition: svxcss1.hxx:209
virtual const FontList * GetFontList() const
Definition: svxcss1.cxx:908
static bool GetEnum(const CSS1PropertyEnum *pPropTable, const OUString &rValue, sal_uInt16 &rEnum)
Definition: svxcss1.cxx:859
static constexpr sal_uInt16 gnMinFixLineSpace
Definition: svxcss1.hxx:206
const WhichRangesContainer & GetWhichMap() const
Definition: svxcss1.hxx:268
SvxCSS1PropertyInfo * m_pPropInfo
Definition: svxcss1.hxx:203
void InsertTag(const OUString &rTag, const SfxItemSet &rItemSet, const SvxCSS1PropertyInfo &rProp)
Definition: svxcss1.cxx:809
sal_Unicode m_cBulletChar
Definition: svxcss1.hxx:129
tools::Long m_nHeight
Definition: svxcss1.hxx:134
SvxCSS1PageBreak m_ePageBreakBefore
Definition: svxcss1.hxx:142
tools::Long m_nTop
Definition: svxcss1.hxx:133
void SetBoxItem(SfxItemSet &rItemSet, sal_uInt16 nMinBorderDist, const SvxBoxItem *pDflt=nullptr)
Definition: svxcss1.cxx:583
SvxNumType m_nNumberingType
Definition: svxcss1.hxx:128
sal_uInt16 m_nColumnCount
Definition: svxcss1.hxx:131
SvxCSS1PageBreak m_ePageBreakAfter
Definition: svxcss1.hxx:143
SvxCSS1BorderInfo * GetBorderInfo(SvxBoxItemLine nLine, bool bCreate=true)
Definition: svxcss1.cxx:532
void CopyBorderInfo(SvxBoxItemLine nSrcLine, SvxBoxItemLine nDstLine, sal_uInt16 nWhat)
Definition: svxcss1.cxx:549
SvxCSS1SizeType m_eSizeType
Definition: svxcss1.hxx:140
void DestroyBorderInfos()
Definition: svxcss1.cxx:415
tools::Long m_nRightMargin
Definition: svxcss1.hxx:135
sal_uInt16 m_nBottomBorderDistance
Definition: svxcss1.hxx:124
sal_uInt16 m_nRightBorderDistance
Definition: svxcss1.hxx:126
sal_uInt16 m_nLeftBorderDistance
Definition: svxcss1.hxx:125
SvxCSS1LengthType m_eHeightType
Definition: svxcss1.hxx:138
SvxCSS1Position m_ePosition
Definition: svxcss1.hxx:121
SvxCSS1LengthType m_eWidthType
Definition: svxcss1.hxx:138
void Merge(const SvxCSS1PropertyInfo &rProp)
Definition: svxcss1.cxx:450
tools::Long m_nWidth
Definition: svxcss1.hxx:134
sal_uInt16 m_nTopBorderDistance
Definition: svxcss1.hxx:123
tools::Long m_nLeft
Definition: svxcss1.hxx:133
SvxCSS1LengthType m_eTopType
Definition: svxcss1.hxx:137
SvxAdjust m_eFloat
Definition: svxcss1.hxx:119
static constexpr sal_uInt16 UNSET_BORDER_DISTANCE
Definition: svxcss1.hxx:106
std::array< std::unique_ptr< SvxCSS1BorderInfo >, 4 > m_aBorderInfos
Definition: svxcss1.hxx:101
tools::Long m_nLeftMargin
Definition: svxcss1.hxx:135
SvxCSS1LengthType m_eLeftType
Definition: svxcss1.hxx:137
constexpr auto toTwips(N number, Length from)
long Long
sal_uInt16 nEnum
Definition: svxcss1.hxx:89
const char * pName
Definition: svxcss1.hxx:88
SvxCSS1PageBreak
Definition: svxcss1.hxx:66
@ SVX_CSS1_PBREAK_ALWAYS
Definition: svxcss1.hxx:69
@ SVX_CSS1_PBREAK_AUTO
Definition: svxcss1.hxx:68
@ SVX_CSS1_PBREAK_RIGHT
Definition: svxcss1.hxx:72
@ SVX_CSS1_PBREAK_LEFT
Definition: svxcss1.hxx:71
@ SVX_CSS1_PBREAK_AVOID
Definition: svxcss1.hxx:70
@ SVX_CSS1_PBREAK_NONE
Definition: svxcss1.hxx:67
SvxCSS1SizeType
Definition: svxcss1.hxx:57
@ SVX_CSS1_STYPE_NONE
Definition: svxcss1.hxx:58
@ SVX_CSS1_STYPE_LANDSCAPE
Definition: svxcss1.hxx:61
@ SVX_CSS1_STYPE_TWIP
Definition: svxcss1.hxx:60
@ SVX_CSS1_STYPE_AUTO
Definition: svxcss1.hxx:59
@ SVX_CSS1_STYPE_PORTRAIT
Definition: svxcss1.hxx:62
SvxCSS1Position
Definition: svxcss1.hxx:40
@ SVX_CSS1_POS_NONE
Definition: svxcss1.hxx:41
@ SVX_CSS1_POS_ABSOLUTE
Definition: svxcss1.hxx:43
@ SVX_CSS1_POS_STATIC
Definition: svxcss1.hxx:42
@ SVX_CSS1_POS_RELATIVE
Definition: svxcss1.hxx:44
SvxCSS1LengthType
Definition: svxcss1.hxx:48
@ SVX_CSS1_LTYPE_TWIP
Definition: svxcss1.hxx:51
@ SVX_CSS1_LTYPE_AUTO
Definition: svxcss1.hxx:50
@ SVX_CSS1_LTYPE_PERCENTAGE
Definition: svxcss1.hxx:52
@ SVX_CSS1_LTYPE_NONE
Definition: svxcss1.hxx:49
Css1ScriptFlags
Definition: svxcss1.hxx:76
SvxNumType
SvxAdjust
#define SAL_MAX_UINT16
sal_uInt16 sal_Unicode