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 <svx/flagsdef.hxx>
24 #include <editeng/svxenum.hxx>
25 #include <rtl/textenc.h>
26 #include "parcss1.hxx"
27 #include <o3tl/typed_flags_set.hxx>
28 
29 #include <array>
30 #include <map>
31 #include <memory>
32 #include <vector>
33 
34 class SfxItemPool;
35 class SvxBoxItem;
36 class FontList;
37 enum class SvxBoxItemLine;
38 
40 {
41  SVX_CSS1_POS_NONE, // nothing specified
43  SVX_CSS1_POS_ABSOLUTE, // absolute
44  SVX_CSS1_POS_RELATIVE, // relative
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
68  SVX_CSS1_PBREAK_AUTO, // automatic
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 
76 enum class Css1ScriptFlags {
77  Western = 0x01,
78  CJK = 0x02,
79  CTL = 0x04,
80  AllMask = Western | CJK | CTL,
81 };
82 namespace o3tl {
83  template<> struct typed_flags<Css1ScriptFlags> : is_typed_flags<Css1ScriptFlags, 0x07> {};
84 }
85 
87 {
88  const sal_Char *pName; // property value
89  sal_uInt16 const nEnum; // and the corresponding value of enum
90 };
91 
92 namespace 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 
98 struct SvxCSS1BorderInfo;
100 {
101  std::array<std::unique_ptr<SvxCSS1BorderInfo>,4> m_aBorderInfos;
102 
103  void DestroyBorderInfos();
104 
105 public:
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;
111  bool m_bBottomMargin : 1;
112 
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;
118 
120 
122 
127 
130 
131  sal_uInt16 m_nColumnCount;
132 
136 
139 
141 
144 
148 
149  void Merge( const SvxCSS1PropertyInfo& rProp );
150 
151  void Clear();
152 
153  SvxCSS1BorderInfo *GetBorderInfo( SvxBoxItemLine nLine, bool bCreate=true );
154  void CopyBorderInfo( SvxBoxItemLine nSrcLine, SvxBoxItemLine nDstLine, sal_uInt16 nWhat );
155  void CopyBorderInfo( sal_uInt16 nCount, sal_uInt16 nWhat );
156 
157  void SetBoxItem( SfxItemSet& rItemSet, sal_uInt16 nMinBorderDist,
158  const SvxBoxItem* pDflt=nullptr );
159 
160 };
161 
163 {
166 
167 public:
168  SvxCSS1MapEntry( const SfxItemSet& rItemSet,
169  const SvxCSS1PropertyInfo& rProp );
170 
171  const SfxItemSet& GetItemSet() const { return aItemSet; }
173 
174  const SvxCSS1PropertyInfo& GetPropertyInfo() const { return aPropInfo; }
176 };
177 
178 // Class is processing the CSS1-Parser output by converting the CSS1 properties
179 // into SvxItem(Set). Also the selectors together with associated ItemSet are
180 // saved.
181 // A derived parser can suppress this for certain selectors by overriding
182 // the method StyleParsed.
183 
184 class SvxCSS1Parser : public CSS1Parser
185 {
186  typedef std::vector<std::unique_ptr<CSS1Selector>> CSS1Selectors;
187  typedef std::map<OUString, std::unique_ptr<SvxCSS1MapEntry>> CSS1Map;
188  CSS1Selectors m_Selectors; // List of "open" Selectors
189 
190  CSS1Map m_Ids;
191  CSS1Map m_Classes;
192  CSS1Map m_Pages;
193  CSS1Map m_Tags;
194 
195  OUString const sBaseURL;
196 
197  std::unique_ptr<SfxItemSet> pSheetItemSet; // item set of Style-Sheet
198  SfxItemSet *pItemSet; // current item set
199 
200  std::unique_ptr<SvxCSS1PropertyInfo> pSheetPropInfo;
202 
203  static constexpr sal_uInt16 gnMinFixLineSpace = MM50/2; // minimum spacing for fixed line spacing
204 
205  rtl_TextEncoding eDfltEnc;
207  std::vector<sal_uInt16> aWhichMap; // Which-Map of Parser
208 
210 
211 protected:
212 
214 
215  // This method is called for every selector with according item set.
216  // For a selector multiple calls are possible.
217  // If true is returned then the item set resp. the selector isn't saved anymore!
218  // The ItemSet may be modified accordingly!
219  // The implementation returns false.
220  virtual void StyleParsed( const CSS1Selector *pSelector,
221  SfxItemSet& rItemSet,
222  SvxCSS1PropertyInfo& rPropInfo );
223 
228  virtual void SelectorParsed( std::unique_ptr<CSS1Selector> pSelector, bool bFirst ) override;
229 
233  virtual void DeclarationParsed( const OUString& rProperty,
234  std::unique_ptr<CSS1Expression> pExpr ) override;
235 
236 public:
237 
238  SvxCSS1Parser( SfxItemPool& rPool,
239  const OUString& rBaseURL,
240  sal_uInt16 const *pWhichIds, sal_uInt16 nWhichIds );
241  virtual ~SvxCSS1Parser() override;
242 
243  bool IsIgnoreFontFamily() const { return bIgnoreFontFamily; }
244  void SetIgnoreFontFamily( bool bSet ) { bIgnoreFontFamily = bSet; }
245 
246  // Parse a style sheet. For every found selector a StyleParsed with
247  // according item set is called.
248  virtual bool ParseStyleSheet( const OUString& rIn );
249 
250  // Parse style option. Here only the item set is filled.
251  void ParseStyleOption( const OUString& rIn, SfxItemSet& rItemSet,
252  SvxCSS1PropertyInfo& rPropInfo );
253 
254  // convert a string to enum value
255  static bool GetEnum( const CSS1PropertyEnum *pPropTable,
256  const OUString& rValue, sal_uInt16 &rEnum );
257 
258  static void PixelToTwip( long &nWidth, long &nHeight );
259 
260  // determine the font height of a certain font size (0-6)
261  virtual sal_uInt32 GetFontHeight( sal_uInt16 nSize ) const;
262 
263  virtual const FontList *GetFontList() const;
264 
265  const sal_uInt16 *GetWhichMap() const { return aWhichMap.data(); }
266 
267  static void InsertMapEntry( const OUString& rKey, const SfxItemSet& rItemSet,
268  const SvxCSS1PropertyInfo& rProp, CSS1Map& rMap );
269 
270  void InsertId( const OUString& rId, const SfxItemSet& rItemSet,
271  const SvxCSS1PropertyInfo& rProp );
272 
273  const SvxCSS1MapEntry* GetId( const OUString& rId ) const;
274 
275  void InsertClass( const OUString& rClass, const SfxItemSet& rItemSet,
276  const SvxCSS1PropertyInfo& rProp );
277 
278  const SvxCSS1MapEntry* GetClass( const OUString& rClass ) const;
279 
280  void InsertPage( const OUString& rPage, bool bPseudo,
281  const SfxItemSet& rItemSet,
282  const SvxCSS1PropertyInfo& rProp );
283 
284  SvxCSS1MapEntry* GetPage( const OUString& rPage, bool bPseudo );
285 
286  void InsertTag( const OUString& rTag, const SfxItemSet& rItemSet,
287  const SvxCSS1PropertyInfo& rProp );
288 
289  SvxCSS1MapEntry* GetTag( const OUString& rTag );
290 
291  static void MergeStyles( const SfxItemSet& rSrcSet,
292  const SvxCSS1PropertyInfo& rSrcInfo,
293  SfxItemSet& rTargetSet,
294  SvxCSS1PropertyInfo& rTargetInfo,
295  bool bSmart );
296 
297  static sal_uInt16 GetMinFixLineSpace() { return gnMinFixLineSpace; }
298 
299  virtual void SetDfltEncoding( rtl_TextEncoding eEnc );
300  rtl_TextEncoding GetDfltEncoding() const { return eDfltEnc; }
301 
302  const OUString& GetBaseURL() const { return sBaseURL;}
303 
304 };
305 
306 #endif
307 
308 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static void MergeStyles(const SfxItemSet &rSrcSet, const SvxCSS1PropertyInfo &rSrcInfo, SfxItemSet &rTargetSet, SvxCSS1PropertyInfo &rTargetInfo, bool bSmart)
Definition: svxcss1.cxx:922
virtual sal_uInt32 GetFontHeight(sal_uInt16 nSize) const
Definition: svxcss1.cxx:880
const OUString & GetBaseURL() const
Definition: svxcss1.hxx:302
SvxCSS1LengthType
Definition: svxcss1.hxx:47
SvxCSS1LengthType m_eLeftType
Definition: svxcss1.hxx:137
Css1ScriptFlags
Definition: svxcss1.hxx:76
void Merge(const SvxCSS1PropertyInfo &rProp)
Definition: svxcss1.cxx:445
SvxCSS1LengthType m_eTopType
Definition: svxcss1.hxx:137
std::map< OUString, std::unique_ptr< SvxCSS1MapEntry > > CSS1Map
Definition: svxcss1.hxx:187
virtual void SelectorParsed(std::unique_ptr< CSS1Selector > pSelector, bool bFirst) override
Will be called when a Selector is parsed.
Definition: svxcss1.cxx:671
void ParseStyleOption(const OUString &rIn, SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo)
Definition: svxcss1.cxx:836
virtual void SetDfltEncoding(rtl_TextEncoding eEnc)
Definition: svxcss1.cxx:972
SvxCSS1PropertyInfo aPropInfo
Definition: svxcss1.hxx:165
CSS1Map m_Tags
Definition: svxcss1.hxx:193
virtual void StyleParsed(const CSS1Selector *pSelector, SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo)
Definition: svxcss1.cxx:664
std::array< std::unique_ptr< SvxCSS1BorderInfo >, 4 > m_aBorderInfos
Definition: svxcss1.hxx:101
SvxCSS1BorderInfo * GetBorderInfo(SvxBoxItemLine nLine, bool bCreate=true)
Definition: svxcss1.cxx:527
std::unique_ptr< SfxItemSet > pSheetItemSet
Definition: svxcss1.hxx:197
const SvxCSS1PropertyInfo & GetPropertyInfo() const
Definition: svxcss1.hxx:174
SfxItemSet aItemSet
Definition: svxcss1.hxx:164
virtual const FontList * GetFontList() const
Definition: svxcss1.cxx:899
static void InsertMapEntry(const OUString &rKey, const SfxItemSet &rItemSet, const SvxCSS1PropertyInfo &rProp, CSS1Map &rMap)
Definition: svxcss1.cxx:904
SvxCSS1Parser(SfxItemPool &rPool, const OUString &rBaseURL, sal_uInt16 const *pWhichIds, sal_uInt16 nWhichIds)
Definition: svxcss1.cxx:691
SvxCSS1PropertyInfo * pPropInfo
Definition: svxcss1.hxx:201
bool bIgnoreFontFamily
Definition: svxcss1.hxx:206
sal_uInt16 const nEnum
Definition: svxcss1.hxx:89
void CopyBorderInfo(SvxBoxItemLine nSrcLine, SvxBoxItemLine nDstLine, sal_uInt16 nWhat)
Definition: svxcss1.cxx:544
rtl_TextEncoding GetDfltEncoding() const
Definition: svxcss1.hxx:300
void SetBoxItem(SfxItemSet &rItemSet, sal_uInt16 nMinBorderDist, const SvxBoxItem *pDflt=nullptr)
Definition: svxcss1.cxx:578
sal_uInt16 m_nTopBorderDistance
Definition: svxcss1.hxx:123
SvxCSS1PageBreak m_ePageBreakBefore
Definition: svxcss1.hxx:142
sal_Unicode m_cBulletChar
Definition: svxcss1.hxx:129
SvxNumType
void SetIgnoreFontFamily(bool bSet)
Definition: svxcss1.hxx:244
SvxCSS1LengthType m_eHeightType
Definition: svxcss1.hxx:138
SvxCSS1SizeType m_eSizeType
Definition: svxcss1.hxx:140
sal_uInt16 sal_Unicode
CSS1Map m_Pages
Definition: svxcss1.hxx:192
#define SAL_MAX_UINT16
bool IsIgnoreFontFamily() const
Definition: svxcss1.hxx:243
char sal_Char
virtual void DeclarationParsed(const OUString &rProperty, std::unique_ptr< CSS1Expression > pExpr) override
Will be called for every parsed Property.
Definition: svxcss1.cxx:3141
SvxCSS1PageBreak m_ePageBreakAfter
Definition: svxcss1.hxx:143
CSS1Map m_Ids
Definition: svxcss1.hxx:190
SvxCSS1MapEntry * GetTag(const OUString &rTag)
Definition: svxcss1.cxx:807
void ParseStyleSheet()
Definition: parcss1.cxx:672
SvxCSS1Position
Definition: svxcss1.hxx:39
SvxNumType m_nNumberingType
Definition: svxcss1.hxx:128
void InsertPage(const OUString &rPage, bool bPseudo, const SfxItemSet &rItemSet, const SvxCSS1PropertyInfo &rProp)
Definition: svxcss1.cxx:779
virtual ~SvxCSS1Parser() override
Definition: svxcss1.cxx:747
sal_uInt16 m_nLeftBorderDistance
Definition: svxcss1.hxx:125
std::unique_ptr< SvxCSS1PropertyInfo > pSheetPropInfo
Definition: svxcss1.hxx:200
void DestroyBorderInfos()
Definition: svxcss1.cxx:410
SvxCSS1SizeType
Definition: svxcss1.hxx:56
SvxAdjust
sal_uInt16 m_nRightBorderDistance
Definition: svxcss1.hxx:126
rtl_TextEncoding eDfltEnc
Definition: svxcss1.hxx:205
CSS1Map m_Classes
Definition: svxcss1.hxx:191
std::vector< sal_uInt16 > aWhichMap
Definition: svxcss1.hxx:207
static constexpr sal_uInt16 gnMinFixLineSpace
Definition: svxcss1.hxx:203
static constexpr sal_uInt16 UNSET_BORDER_DISTANCE
Definition: svxcss1.hxx:106
Parser of a style element/option.
Definition: parcss1.hxx:179
void InsertClass(const OUString &rClass, const SfxItemSet &rItemSet, const SvxCSS1PropertyInfo &rProp)
Definition: svxcss1.cxx:766
SvxCSS1Position m_ePosition
Definition: svxcss1.hxx:121
SvxCSS1MapEntry(const SfxItemSet &rItemSet, const SvxCSS1PropertyInfo &rProp)
Definition: svxcss1.cxx:658
SvxAdjust m_eFloat
Definition: svxcss1.hxx:119
void ParseStyleOption(const OUString &rIn)
parse the content of a HTML style option
Definition: parcss1.cxx:1154
SvxCSS1MapEntry * GetPage(const OUString &rPage, bool bPseudo)
Definition: svxcss1.cxx:790
const sal_Char * pName
Definition: svxcss1.hxx:88
OUString const sBaseURL
Definition: svxcss1.hxx:195
SvxCSS1LengthType m_eWidthType
Definition: svxcss1.hxx:138
#define MM50
Definition: swtypes.hxx:59
static sal_uInt16 GetMinFixLineSpace()
Definition: svxcss1.hxx:297
SvxBoxItemLine
const SvxCSS1MapEntry * GetId(const OUString &rId) const
Definition: svxcss1.cxx:760
const sal_uInt16 * GetWhichMap() const
Definition: svxcss1.hxx:265
CSS1Selectors m_Selectors
Definition: svxcss1.hxx:188
SfxItemSet * pItemSet
Definition: svxcss1.hxx:198
void InsertTag(const OUString &rTag, const SfxItemSet &rItemSet, const SvxCSS1PropertyInfo &rProp)
Definition: svxcss1.cxx:800
const SfxItemSet & GetItemSet() const
Definition: svxcss1.hxx:171
A simple selector.
Definition: parcss1.hxx:91
SfxItemSet & GetItemSet()
Definition: svxcss1.hxx:172
void InsertId(const OUString &rId, const SfxItemSet &rItemSet, const SvxCSS1PropertyInfo &rProp)
Definition: svxcss1.cxx:753
std::vector< std::unique_ptr< CSS1Selector > > CSS1Selectors
Definition: svxcss1.hxx:186
const SvxCSS1MapEntry * GetClass(const OUString &rClass) const
Definition: svxcss1.cxx:773
static bool GetEnum(const CSS1PropertyEnum *pPropTable, const OUString &rValue, sal_uInt16 &rEnum)
Definition: svxcss1.cxx:850
sal_uInt16 m_nColumnCount
Definition: svxcss1.hxx:131
static void PixelToTwip(long &nWidth, long &nHeight)
Definition: svxcss1.cxx:867
SvxCSS1PageBreak
Definition: svxcss1.hxx:65
sal_uInt16 m_nBottomBorderDistance
Definition: svxcss1.hxx:124
SvxCSS1PropertyInfo & GetPropertyInfo()
Definition: svxcss1.hxx:175