1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SW_SOURCE_FILTER_HTML_SVXCSS1_HXX
20 #define INCLUDED_SW_SOURCE_FILTER_HTML_SVXCSS1_HXX
22 #include <svl/itemset.hxx>
23 #include <editeng/svxenum.hxx>
24 #include <rtl/textenc.h>
25 #include "parcss1.hxx"
26 #include <o3tl/typed_flags_set.hxx>
27 #include <o3tl/unit_conversion.hxx>
37 enum class SvxBoxItemLine
;
41 SVX_CSS1_POS_NONE
, // nothing specified
42 SVX_CSS1_POS_STATIC
, // normal
43 SVX_CSS1_POS_ABSOLUTE
, // absolute
44 SVX_CSS1_POS_RELATIVE
, // relative
47 enum SvxCSS1LengthType
49 SVX_CSS1_LTYPE_NONE
, // nothing specified
50 SVX_CSS1_LTYPE_AUTO
, // automatic
51 SVX_CSS1_LTYPE_TWIP
, // twip
52 SVX_CSS1_LTYPE_PERCENTAGE
, // percentage value
58 SVX_CSS1_STYPE_NONE
, // nothing specified
59 SVX_CSS1_STYPE_AUTO
, // automatic
60 SVX_CSS1_STYPE_TWIP
, // twip
61 SVX_CSS1_STYPE_LANDSCAPE
, // landscape
62 SVX_CSS1_STYPE_PORTRAIT
, // portrait
67 SVX_CSS1_PBREAK_NONE
, // nothing specified
68 SVX_CSS1_PBREAK_AUTO
, // automatic
69 SVX_CSS1_PBREAK_ALWAYS
, // always
70 SVX_CSS1_PBREAK_AVOID
, // never
71 SVX_CSS1_PBREAK_LEFT
, // next page is a left one
72 SVX_CSS1_PBREAK_RIGHT
, // next page is a right one
76 enum class Css1ScriptFlags
{
80 AllMask
= Western
| CJK
| CTL
,
83 template<> struct typed_flags
<Css1ScriptFlags
> : is_typed_flags
<Css1ScriptFlags
, 0x07> {};
86 struct CSS1PropertyEnum
88 const char *pName
; // property value
89 sal_uInt16 nEnum
; // and the corresponding value of enum
92 namespace editeng
{ class SvxBorderLine
; }
94 #define SVX_CSS1_BORDERINFO_WIDTH 1
95 #define SVX_CSS1_BORDERINFO_COLOR 2
96 #define SVX_CSS1_BORDERINFO_STYLE 4
98 struct SvxCSS1BorderInfo
;
99 class SvxCSS1PropertyInfo
101 std::array
<std::unique_ptr
<SvxCSS1BorderInfo
>,4> m_aBorderInfos
;
103 void DestroyBorderInfos();
106 static constexpr sal_uInt16 UNSET_BORDER_DISTANCE
= SAL_MAX_UINT16
;
108 OUString m_aId
; // ID for bookmarks, frame, and so
110 bool m_bTopMargin
: 1;
111 bool m_bBottomMargin
: 1;
113 bool m_bLeftMargin
: 1;
114 bool m_bRightMargin
: 1;
115 bool m_bTextIndent
: 1;
116 bool m_bNumbering
: 1;
118 bool m_bPreserveSpace
: 1 = false;
122 SvxCSS1Position m_ePosition
;
124 sal_uInt16 m_nTopBorderDistance
;
125 sal_uInt16 m_nBottomBorderDistance
;
126 sal_uInt16 m_nLeftBorderDistance
;
127 sal_uInt16 m_nRightBorderDistance
;
129 SvxNumType m_nNumberingType
;
130 sal_Unicode m_cBulletChar
;
132 sal_uInt16 m_nColumnCount
;
134 tools::Long m_nLeft
, m_nTop
;
135 tools::Long m_nWidth
, m_nHeight
;
136 tools::Long m_nLeftMargin
, m_nRightMargin
;
138 SvxCSS1LengthType m_eLeftType
, m_eTopType
;
139 SvxCSS1LengthType m_eWidthType
, m_eHeightType
;
140 SvxCSS1LengthType m_eLeftMarginType
;
141 SvxCSS1LengthType m_eRightMarginType
;
143 SvxCSS1SizeType m_eSizeType
;
145 SvxCSS1PageBreak m_ePageBreakBefore
;
146 SvxCSS1PageBreak m_ePageBreakAfter
;
148 bool m_bVisible
= true;
150 SvxCSS1PropertyInfo();
151 SvxCSS1PropertyInfo( const SvxCSS1PropertyInfo
& rProp
);
152 ~SvxCSS1PropertyInfo();
154 void Merge( const SvxCSS1PropertyInfo
& rProp
);
158 SvxCSS1BorderInfo
*GetBorderInfo( SvxBoxItemLine nLine
, bool bCreate
=true );
159 void CopyBorderInfo( SvxBoxItemLine nSrcLine
, SvxBoxItemLine nDstLine
, sal_uInt16 nWhat
);
160 void CopyBorderInfo( sal_uInt16 nCount
, sal_uInt16 nWhat
);
162 void SetBoxItem( SfxItemSet
& rItemSet
, sal_uInt16 nMinBorderDist
,
163 const SvxBoxItem
* pDflt
=nullptr );
167 class SvxCSS1MapEntry
169 SfxItemSet m_aItemSet
;
170 SvxCSS1PropertyInfo m_aPropInfo
;
173 SvxCSS1MapEntry( SfxItemSet aItemSet
,
174 const SvxCSS1PropertyInfo
& rProp
);
176 const SfxItemSet
& GetItemSet() const { return m_aItemSet
; }
177 SfxItemSet
& GetItemSet() { return m_aItemSet
; }
179 const SvxCSS1PropertyInfo
& GetPropertyInfo() const { return m_aPropInfo
; }
180 SvxCSS1PropertyInfo
& GetPropertyInfo() { return m_aPropInfo
; }
183 // Class is processing the CSS1-Parser output by converting the CSS1 properties
184 // into SvxItem(Set). Also the selectors together with associated ItemSet are
186 // A derived parser can suppress this for certain selectors by overriding
187 // the method StyleParsed.
189 class SvxCSS1Parser
: public CSS1Parser
191 typedef std::vector
<std::unique_ptr
<CSS1Selector
>> CSS1Selectors
;
192 typedef std::map
<OUString
, std::unique_ptr
<SvxCSS1MapEntry
>> CSS1Map
;
193 CSS1Selectors m_Selectors
; // List of "open" Selectors
202 std::unique_ptr
<SfxItemSet
> m_pSheetItemSet
; // item set of Style-Sheet
203 SfxItemSet
*m_pItemSet
; // current item set
205 std::unique_ptr
<SvxCSS1PropertyInfo
> m_pSheetPropInfo
;
206 SvxCSS1PropertyInfo
*m_pPropInfo
;
208 // minimum spacing for fixed line spacing
209 static constexpr sal_uInt16 gnMinFixLineSpace
= o3tl::toTwips(25, o3tl::Length::mm10
);
211 rtl_TextEncoding m_eDefaultEnc
;
212 bool m_bIgnoreFontFamily
;
213 WhichRangesContainer m_aWhichMap
; // Which-Map of Parser
215 using CSS1Parser::ParseStyleOption
;
219 using CSS1Parser::ParseStyleSheet
;
221 // This method is called for every selector with according item set.
222 // For a selector multiple calls are possible.
223 // If true is returned then the item set resp. the selector isn't saved anymore!
224 // The ItemSet may be modified accordingly!
225 // The implementation returns false.
226 virtual void StyleParsed( const CSS1Selector
*pSelector
,
227 SfxItemSet
& rItemSet
,
228 SvxCSS1PropertyInfo
& rPropInfo
);
230 /// Will be called when a Selector is parsed. If bFirst is true,
231 /// the content of the aItemSet will be copied into all recently
233 /// Derived classes should not override this method!
234 virtual void SelectorParsed( std::unique_ptr
<CSS1Selector
> pSelector
, bool bFirst
) override
;
236 /// Will be called for every parsed Property. Adds the item to the
238 /// Derived classes should not override this method!
239 virtual void DeclarationParsed( const OUString
& rProperty
,
240 std::unique_ptr
<CSS1Expression
> pExpr
) override
;
244 SvxCSS1Parser( SfxItemPool
& rPool
,
246 sal_uInt16
const *pWhichIds
, sal_uInt16 nWhichIds
);
247 virtual ~SvxCSS1Parser() override
;
249 bool IsIgnoreFontFamily() const { return m_bIgnoreFontFamily
; }
250 void SetIgnoreFontFamily( bool bSet
) { m_bIgnoreFontFamily
= bSet
; }
252 // Parse a style sheet. For every found selector a StyleParsed with
253 // according item set is called.
254 virtual bool ParseStyleSheet( const OUString
& rIn
);
256 // Parse style option. Here only the item set is filled.
257 void ParseStyleOption( const OUString
& rIn
, SfxItemSet
& rItemSet
,
258 SvxCSS1PropertyInfo
& rPropInfo
);
260 // convert a string to enum value
261 static bool GetEnum( const CSS1PropertyEnum
*pPropTable
,
262 std::u16string_view rValue
, sal_uInt16
&rEnum
);
264 static void PixelToTwip( tools::Long
&nWidth
, tools::Long
&nHeight
);
266 // determine the font height of a certain font size (0-6)
267 virtual sal_uInt32
GetFontHeight( sal_uInt16 nSize
) const;
269 virtual const FontList
*GetFontList() const;
271 const WhichRangesContainer
& GetWhichMap() const { return m_aWhichMap
; }
273 static void InsertMapEntry( const OUString
& rKey
, const SfxItemSet
& rItemSet
,
274 const SvxCSS1PropertyInfo
& rProp
, CSS1Map
& rMap
);
276 void InsertId( const OUString
& rId
, const SfxItemSet
& rItemSet
,
277 const SvxCSS1PropertyInfo
& rProp
);
279 const SvxCSS1MapEntry
* GetId( const OUString
& rId
) const;
281 void InsertClass( const OUString
& rClass
, const SfxItemSet
& rItemSet
,
282 const SvxCSS1PropertyInfo
& rProp
);
284 const SvxCSS1MapEntry
* GetClass( const OUString
& rClass
) const;
286 void InsertPage( const OUString
& rPage
, bool bPseudo
,
287 const SfxItemSet
& rItemSet
,
288 const SvxCSS1PropertyInfo
& rProp
);
290 SvxCSS1MapEntry
* GetPage( const OUString
& rPage
, bool bPseudo
);
292 void InsertTag( const OUString
& rTag
, const SfxItemSet
& rItemSet
,
293 const SvxCSS1PropertyInfo
& rProp
);
295 SvxCSS1MapEntry
* GetTag( const OUString
& rTag
);
297 static void MergeStyles( const SfxItemSet
& rSrcSet
,
298 const SvxCSS1PropertyInfo
& rSrcInfo
,
299 SfxItemSet
& rTargetSet
,
300 SvxCSS1PropertyInfo
& rTargetInfo
,
303 static sal_uInt16
GetMinFixLineSpace() { return gnMinFixLineSpace
; }
305 virtual void SetDfltEncoding( rtl_TextEncoding eEnc
);
306 rtl_TextEncoding
GetDfltEncoding() const { return m_eDefaultEnc
; }
308 const OUString
& GetBaseURL() const { return m_sBaseURL
;}
314 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */