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
141
143
146
147 bool m_bVisible = true;
148
152
153 void Merge( const SvxCSS1PropertyInfo& rProp );
154
155 void Clear();
156
157 SvxCSS1BorderInfo *GetBorderInfo( SvxBoxItemLine nLine, bool bCreate=true );
158 void CopyBorderInfo( SvxBoxItemLine nSrcLine, SvxBoxItemLine nDstLine, sal_uInt16 nWhat );
159 void CopyBorderInfo( sal_uInt16 nCount, sal_uInt16 nWhat );
160
161 void SetBoxItem( SfxItemSet& rItemSet, sal_uInt16 nMinBorderDist,
162 const SvxBoxItem* pDflt=nullptr );
163
164};
165
167{
170
171public:
172 SvxCSS1MapEntry( SfxItemSet aItemSet,
173 const SvxCSS1PropertyInfo& rProp );
174
175 const SfxItemSet& GetItemSet() const { return m_aItemSet; }
177
180};
181
182// Class is processing the CSS1-Parser output by converting the CSS1 properties
183// into SvxItem(Set). Also the selectors together with associated ItemSet are
184// saved.
185// A derived parser can suppress this for certain selectors by overriding
186// the method StyleParsed.
187
189{
190 typedef std::vector<std::unique_ptr<CSS1Selector>> CSS1Selectors;
191 typedef std::map<OUString, std::unique_ptr<SvxCSS1MapEntry>> CSS1Map;
192 CSS1Selectors m_Selectors; // List of "open" Selectors
193
198
199 OUString m_sBaseURL;
200
201 std::unique_ptr<SfxItemSet> m_pSheetItemSet; // item set of Style-Sheet
202 SfxItemSet *m_pItemSet; // current item set
203
204 std::unique_ptr<SvxCSS1PropertyInfo> m_pSheetPropInfo;
206
207 // minimum spacing for fixed line spacing
208 static constexpr sal_uInt16 gnMinFixLineSpace = o3tl::toTwips(25, o3tl::Length::mm10);
209
210 rtl_TextEncoding m_eDefaultEnc;
212 WhichRangesContainer m_aWhichMap; // Which-Map of Parser
213
215
216protected:
217
219
220 // This method is called for every selector with according item set.
221 // For a selector multiple calls are possible.
222 // If true is returned then the item set resp. the selector isn't saved anymore!
223 // The ItemSet may be modified accordingly!
224 // The implementation returns false.
225 virtual void StyleParsed( const CSS1Selector *pSelector,
226 SfxItemSet& rItemSet,
227 SvxCSS1PropertyInfo& rPropInfo );
228
233 virtual void SelectorParsed( std::unique_ptr<CSS1Selector> pSelector, bool bFirst ) override;
234
238 virtual void DeclarationParsed( const OUString& rProperty,
239 std::unique_ptr<CSS1Expression> pExpr ) override;
240
241public:
242
244 OUString aBaseURL,
245 sal_uInt16 const *pWhichIds, sal_uInt16 nWhichIds );
246 virtual ~SvxCSS1Parser() override;
247
249 void SetIgnoreFontFamily( bool bSet ) { m_bIgnoreFontFamily = bSet; }
250
251 // Parse a style sheet. For every found selector a StyleParsed with
252 // according item set is called.
253 virtual bool ParseStyleSheet( const OUString& rIn );
254
255 // Parse style option. Here only the item set is filled.
256 void ParseStyleOption( const OUString& rIn, SfxItemSet& rItemSet,
257 SvxCSS1PropertyInfo& rPropInfo );
258
259 // convert a string to enum value
260 static bool GetEnum( const CSS1PropertyEnum *pPropTable,
261 std::u16string_view rValue, sal_uInt16 &rEnum );
262
263 static void PixelToTwip( tools::Long &nWidth, tools::Long &nHeight );
264
265 // determine the font height of a certain font size (0-6)
266 virtual sal_uInt32 GetFontHeight( sal_uInt16 nSize ) const;
267
268 virtual const FontList *GetFontList() const;
269
271
272 static void InsertMapEntry( const OUString& rKey, const SfxItemSet& rItemSet,
273 const SvxCSS1PropertyInfo& rProp, CSS1Map& rMap );
274
275 void InsertId( const OUString& rId, const SfxItemSet& rItemSet,
276 const SvxCSS1PropertyInfo& rProp );
277
278 const SvxCSS1MapEntry* GetId( const OUString& rId ) const;
279
280 void InsertClass( const OUString& rClass, const SfxItemSet& rItemSet,
281 const SvxCSS1PropertyInfo& rProp );
282
283 const SvxCSS1MapEntry* GetClass( const OUString& rClass ) const;
284
285 void InsertPage( const OUString& rPage, bool bPseudo,
286 const SfxItemSet& rItemSet,
287 const SvxCSS1PropertyInfo& rProp );
288
289 SvxCSS1MapEntry* GetPage( const OUString& rPage, bool bPseudo );
290
291 void InsertTag( const OUString& rTag, const SfxItemSet& rItemSet,
292 const SvxCSS1PropertyInfo& rProp );
293
294 SvxCSS1MapEntry* GetTag( const OUString& rTag );
295
296 static void MergeStyles( const SfxItemSet& rSrcSet,
297 const SvxCSS1PropertyInfo& rSrcInfo,
298 SfxItemSet& rTargetSet,
299 SvxCSS1PropertyInfo& rTargetInfo,
300 bool bSmart );
301
302 static sal_uInt16 GetMinFixLineSpace() { return gnMinFixLineSpace; }
303
304 virtual void SetDfltEncoding( rtl_TextEncoding eEnc );
305 rtl_TextEncoding GetDfltEncoding() const { return m_eDefaultEnc; }
306
307 const OUString& GetBaseURL() const { return m_sBaseURL;}
308
309};
310
311#endif
312
313/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvxBoxItemLine
Parser of a style element/option.
Definition: parcss1.hxx:182
void ParseStyleSheet()
Definition: parcss1.cxx:691
void ParseStyleOption(const OUString &rIn)
parse the content of a HTML style option
Definition: parcss1.cxx:1173
A simple selector.
Definition: parcss1.hxx:93
SfxItemSet m_aItemSet
Definition: svxcss1.hxx:168
SvxCSS1PropertyInfo & GetPropertyInfo()
Definition: svxcss1.hxx:179
SvxCSS1PropertyInfo m_aPropInfo
Definition: svxcss1.hxx:169
SfxItemSet & GetItemSet()
Definition: svxcss1.hxx:176
SvxCSS1MapEntry(SfxItemSet aItemSet, const SvxCSS1PropertyInfo &rProp)
Definition: svxcss1.cxx:670
const SvxCSS1PropertyInfo & GetPropertyInfo() const
Definition: svxcss1.hxx:178
const SfxItemSet & GetItemSet() const
Definition: svxcss1.hxx:175
std::unique_ptr< SfxItemSet > m_pSheetItemSet
Definition: svxcss1.hxx:201
void InsertPage(const OUString &rPage, bool bPseudo, const SfxItemSet &rItemSet, const SvxCSS1PropertyInfo &rProp)
Definition: svxcss1.cxx:798
void SetIgnoreFontFamily(bool bSet)
Definition: svxcss1.hxx:249
const SvxCSS1MapEntry * GetId(const OUString &rId) const
Definition: svxcss1.cxx:779
void InsertId(const OUString &rId, const SfxItemSet &rItemSet, const SvxCSS1PropertyInfo &rProp)
Definition: svxcss1.cxx:772
void ParseStyleOption(const OUString &rIn, SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo)
Definition: svxcss1.cxx:855
CSS1Map m_Ids
Definition: svxcss1.hxx:194
CSS1Selectors m_Selectors
Definition: svxcss1.hxx:192
bool IsIgnoreFontFamily() const
Definition: svxcss1.hxx:248
CSS1Map m_Pages
Definition: svxcss1.hxx:196
std::unique_ptr< SvxCSS1PropertyInfo > m_pSheetPropInfo
Definition: svxcss1.hxx:204
SvxCSS1MapEntry * GetTag(const OUString &rTag)
Definition: svxcss1.cxx:826
virtual void SetDfltEncoding(rtl_TextEncoding eEnc)
Definition: svxcss1.cxx:986
rtl_TextEncoding GetDfltEncoding() const
Definition: svxcss1.hxx:305
void InsertClass(const OUString &rClass, const SfxItemSet &rItemSet, const SvxCSS1PropertyInfo &rProp)
Definition: svxcss1.cxx:785
static void PixelToTwip(tools::Long &nWidth, tools::Long &nHeight)
Definition: svxcss1.cxx:886
CSS1Map m_Tags
Definition: svxcss1.hxx:197
SfxItemSet * m_pItemSet
Definition: svxcss1.hxx:202
static void InsertMapEntry(const OUString &rKey, const SfxItemSet &rItemSet, const SvxCSS1PropertyInfo &rProp, CSS1Map &rMap)
Definition: svxcss1.cxx:923
virtual void StyleParsed(const CSS1Selector *pSelector, SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo)
Definition: svxcss1.cxx:676
static sal_uInt16 GetMinFixLineSpace()
Definition: svxcss1.hxx:302
OUString m_sBaseURL
Definition: svxcss1.hxx:199
rtl_TextEncoding m_eDefaultEnc
Definition: svxcss1.hxx:210
std::map< OUString, std::unique_ptr< SvxCSS1MapEntry > > CSS1Map
Definition: svxcss1.hxx:191
static void MergeStyles(const SfxItemSet &rSrcSet, const SvxCSS1PropertyInfo &rSrcInfo, SfxItemSet &rTargetSet, SvxCSS1PropertyInfo &rTargetInfo, bool bSmart)
Definition: svxcss1.cxx:939
virtual void DeclarationParsed(const OUString &rProperty, std::unique_ptr< CSS1Expression > pExpr) override
Will be called for every parsed Property.
Definition: svxcss1.cxx:3129
const SvxCSS1MapEntry * GetClass(const OUString &rClass) const
Definition: svxcss1.cxx:792
SvxCSS1MapEntry * GetPage(const OUString &rPage, bool bPseudo)
Definition: svxcss1.cxx:809
virtual sal_uInt32 GetFontHeight(sal_uInt16 nSize) const
Definition: svxcss1.cxx:899
static bool GetEnum(const CSS1PropertyEnum *pPropTable, std::u16string_view rValue, sal_uInt16 &rEnum)
Definition: svxcss1.cxx:869
const OUString & GetBaseURL() const
Definition: svxcss1.hxx:307
void ParseStyleSheet()
Definition: parcss1.cxx:691
virtual void SelectorParsed(std::unique_ptr< CSS1Selector > pSelector, bool bFirst) override
Will be called when a Selector is parsed.
Definition: svxcss1.cxx:683
CSS1Map m_Classes
Definition: svxcss1.hxx:195
virtual ~SvxCSS1Parser() override
Definition: svxcss1.cxx:766
std::vector< std::unique_ptr< CSS1Selector > > CSS1Selectors
Definition: svxcss1.hxx:190
SvxCSS1Parser(SfxItemPool &rPool, OUString aBaseURL, sal_uInt16 const *pWhichIds, sal_uInt16 nWhichIds)
Definition: svxcss1.cxx:703
WhichRangesContainer m_aWhichMap
Definition: svxcss1.hxx:212
bool m_bIgnoreFontFamily
Definition: svxcss1.hxx:211
virtual const FontList * GetFontList() const
Definition: svxcss1.cxx:918
static constexpr sal_uInt16 gnMinFixLineSpace
Definition: svxcss1.hxx:208
const WhichRangesContainer & GetWhichMap() const
Definition: svxcss1.hxx:270
SvxCSS1PropertyInfo * m_pPropInfo
Definition: svxcss1.hxx:205
void InsertTag(const OUString &rTag, const SfxItemSet &rItemSet, const SvxCSS1PropertyInfo &rProp)
Definition: svxcss1.cxx:819
sal_Unicode m_cBulletChar
Definition: svxcss1.hxx:129
tools::Long m_nHeight
Definition: svxcss1.hxx:134
SvxCSS1PageBreak m_ePageBreakBefore
Definition: svxcss1.hxx:144
tools::Long m_nTop
Definition: svxcss1.hxx:133
void SetBoxItem(SfxItemSet &rItemSet, sal_uInt16 nMinBorderDist, const SvxBoxItem *pDflt=nullptr)
Definition: svxcss1.cxx:590
SvxNumType m_nNumberingType
Definition: svxcss1.hxx:128
sal_uInt16 m_nColumnCount
Definition: svxcss1.hxx:131
SvxCSS1PageBreak m_ePageBreakAfter
Definition: svxcss1.hxx:145
SvxCSS1BorderInfo * GetBorderInfo(SvxBoxItemLine nLine, bool bCreate=true)
Definition: svxcss1.cxx:539
void CopyBorderInfo(SvxBoxItemLine nSrcLine, SvxBoxItemLine nDstLine, sal_uInt16 nWhat)
Definition: svxcss1.cxx:556
SvxCSS1SizeType m_eSizeType
Definition: svxcss1.hxx:142
SvxCSS1LengthType m_eRightMarginType
Definition: svxcss1.hxx:140
void DestroyBorderInfos()
Definition: svxcss1.cxx:420
tools::Long m_nRightMargin
Definition: svxcss1.hxx:135
SvxCSS1LengthType m_eLeftMarginType
Definition: svxcss1.hxx:139
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:457
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