Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / filter / html / svxcss1.hxx
blob985f98a079b76bb3f17efe94d225a5063268ef2b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
29 #include <array>
30 #include <map>
31 #include <memory>
32 #include <vector>
34 class SfxItemPool;
35 class SvxBoxItem;
36 class FontList;
37 enum class SvxBoxItemLine;
39 enum SvxCSS1Position
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
55 // Feature: PrintExt
56 enum SvxCSS1SizeType
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
65 enum SvxCSS1PageBreak
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 {
77 Western = 0x01,
78 CJK = 0x02,
79 CTL = 0x04,
80 AllMask = Western | CJK | CTL,
82 namespace o3tl {
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();
105 public:
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;
117 bool m_bBullet : 1;
119 SvxAdjust m_eFloat;
121 SvxCSS1Position m_ePosition;
123 sal_uInt16 m_nTopBorderDistance;
124 sal_uInt16 m_nBottomBorderDistance;
125 sal_uInt16 m_nLeftBorderDistance;
126 sal_uInt16 m_nRightBorderDistance;
128 SvxNumType m_nNumberingType;
129 sal_Unicode m_cBulletChar;
131 sal_uInt16 m_nColumnCount;
133 tools::Long m_nLeft, m_nTop;
134 tools::Long m_nWidth, m_nHeight;
135 tools::Long m_nLeftMargin, m_nRightMargin;
137 SvxCSS1LengthType m_eLeftType, m_eTopType;
138 SvxCSS1LengthType m_eWidthType, m_eHeightType;
139 SvxCSS1LengthType m_eLeftMarginType;
140 SvxCSS1LengthType m_eRightMarginType;
142 SvxCSS1SizeType m_eSizeType;
144 SvxCSS1PageBreak m_ePageBreakBefore;
145 SvxCSS1PageBreak m_ePageBreakAfter;
147 bool m_bVisible = true;
149 SvxCSS1PropertyInfo();
150 SvxCSS1PropertyInfo( const SvxCSS1PropertyInfo& rProp );
151 ~SvxCSS1PropertyInfo();
153 void Merge( const SvxCSS1PropertyInfo& rProp );
155 void Clear();
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 );
161 void SetBoxItem( SfxItemSet& rItemSet, sal_uInt16 nMinBorderDist,
162 const SvxBoxItem* pDflt=nullptr );
166 class SvxCSS1MapEntry
168 SfxItemSet m_aItemSet;
169 SvxCSS1PropertyInfo m_aPropInfo;
171 public:
172 SvxCSS1MapEntry( SfxItemSet aItemSet,
173 const SvxCSS1PropertyInfo& rProp );
175 const SfxItemSet& GetItemSet() const { return m_aItemSet; }
176 SfxItemSet& GetItemSet() { return m_aItemSet; }
178 const SvxCSS1PropertyInfo& GetPropertyInfo() const { return m_aPropInfo; }
179 SvxCSS1PropertyInfo& GetPropertyInfo() { return m_aPropInfo; }
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.
188 class SvxCSS1Parser : public CSS1Parser
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
194 CSS1Map m_Ids;
195 CSS1Map m_Classes;
196 CSS1Map m_Pages;
197 CSS1Map m_Tags;
199 OUString m_sBaseURL;
201 std::unique_ptr<SfxItemSet> m_pSheetItemSet; // item set of Style-Sheet
202 SfxItemSet *m_pItemSet; // current item set
204 std::unique_ptr<SvxCSS1PropertyInfo> m_pSheetPropInfo;
205 SvxCSS1PropertyInfo *m_pPropInfo;
207 // minimum spacing for fixed line spacing
208 static constexpr sal_uInt16 gnMinFixLineSpace = o3tl::toTwips(25, o3tl::Length::mm10);
210 rtl_TextEncoding m_eDefaultEnc;
211 bool m_bIgnoreFontFamily;
212 WhichRangesContainer m_aWhichMap; // Which-Map of Parser
214 using CSS1Parser::ParseStyleOption;
216 protected:
218 using CSS1Parser::ParseStyleSheet;
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 );
229 /// Will be called when a Selector is parsed. If bFirst is true,
230 /// the content of the aItemSet will be copied into all recently
231 /// created Styles.
232 /// Derived classes should not override this method!
233 virtual void SelectorParsed( std::unique_ptr<CSS1Selector> pSelector, bool bFirst ) override;
235 /// Will be called for every parsed Property. Adds the item to the
236 /// pItemSet.
237 /// Derived classes should not override this method!
238 virtual void DeclarationParsed( const OUString& rProperty,
239 std::unique_ptr<CSS1Expression> pExpr ) override;
241 public:
243 SvxCSS1Parser( SfxItemPool& rPool,
244 OUString aBaseURL,
245 sal_uInt16 const *pWhichIds, sal_uInt16 nWhichIds );
246 virtual ~SvxCSS1Parser() override;
248 bool IsIgnoreFontFamily() const { return m_bIgnoreFontFamily; }
249 void SetIgnoreFontFamily( bool bSet ) { m_bIgnoreFontFamily = bSet; }
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 );
255 // Parse style option. Here only the item set is filled.
256 void ParseStyleOption( const OUString& rIn, SfxItemSet& rItemSet,
257 SvxCSS1PropertyInfo& rPropInfo );
259 // convert a string to enum value
260 static bool GetEnum( const CSS1PropertyEnum *pPropTable,
261 std::u16string_view rValue, sal_uInt16 &rEnum );
263 static void PixelToTwip( tools::Long &nWidth, tools::Long &nHeight );
265 // determine the font height of a certain font size (0-6)
266 virtual sal_uInt32 GetFontHeight( sal_uInt16 nSize ) const;
268 virtual const FontList *GetFontList() const;
270 const WhichRangesContainer& GetWhichMap() const { return m_aWhichMap; }
272 static void InsertMapEntry( const OUString& rKey, const SfxItemSet& rItemSet,
273 const SvxCSS1PropertyInfo& rProp, CSS1Map& rMap );
275 void InsertId( const OUString& rId, const SfxItemSet& rItemSet,
276 const SvxCSS1PropertyInfo& rProp );
278 const SvxCSS1MapEntry* GetId( const OUString& rId ) const;
280 void InsertClass( const OUString& rClass, const SfxItemSet& rItemSet,
281 const SvxCSS1PropertyInfo& rProp );
283 const SvxCSS1MapEntry* GetClass( const OUString& rClass ) const;
285 void InsertPage( const OUString& rPage, bool bPseudo,
286 const SfxItemSet& rItemSet,
287 const SvxCSS1PropertyInfo& rProp );
289 SvxCSS1MapEntry* GetPage( const OUString& rPage, bool bPseudo );
291 void InsertTag( const OUString& rTag, const SfxItemSet& rItemSet,
292 const SvxCSS1PropertyInfo& rProp );
294 SvxCSS1MapEntry* GetTag( const OUString& rTag );
296 static void MergeStyles( const SfxItemSet& rSrcSet,
297 const SvxCSS1PropertyInfo& rSrcInfo,
298 SfxItemSet& rTargetSet,
299 SvxCSS1PropertyInfo& rTargetInfo,
300 bool bSmart );
302 static sal_uInt16 GetMinFixLineSpace() { return gnMinFixLineSpace; }
304 virtual void SetDfltEncoding( rtl_TextEncoding eEnc );
305 rtl_TextEncoding GetDfltEncoding() const { return m_eDefaultEnc; }
307 const OUString& GetBaseURL() const { return m_sBaseURL;}
311 #endif
313 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */