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 char *pName; // property value
89  sal_uInt16 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 
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 
169 public:
170  SvxCSS1MapEntry( const SfxItemSet& rItemSet,
171  const SvxCSS1PropertyInfo& rProp );
172 
173  const SfxItemSet& GetItemSet() const { return aItemSet; }
175 
176  const SvxCSS1PropertyInfo& GetPropertyInfo() const { return aPropInfo; }
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 
186 class SvxCSS1Parser : public CSS1Parser
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 
192  CSS1Map m_Ids;
193  CSS1Map m_Classes;
194  CSS1Map m_Pages;
195  CSS1Map m_Tags;
196 
197  OUString sBaseURL;
198 
199  std::unique_ptr<SfxItemSet> pSheetItemSet; // item set of Style-Sheet
200  SfxItemSet *pItemSet; // current item set
201 
202  std::unique_ptr<SvxCSS1PropertyInfo> pSheetPropInfo;
204 
205  static constexpr sal_uInt16 gnMinFixLineSpace = MM50/2; // minimum spacing for fixed line spacing
206 
207  rtl_TextEncoding eDfltEnc;
209  std::vector<sal_uInt16> aWhichMap; // Which-Map of Parser
210 
212 
213 protected:
214 
216 
217  // This method is called for every selector with according item set.
218  // For a selector multiple calls are possible.
219  // If true is returned then the item set resp. the selector isn't saved anymore!
220  // The ItemSet may be modified accordingly!
221  // The implementation returns false.
222  virtual void StyleParsed( const CSS1Selector *pSelector,
223  SfxItemSet& rItemSet,
224  SvxCSS1PropertyInfo& rPropInfo );
225 
230  virtual void SelectorParsed( std::unique_ptr<CSS1Selector> pSelector, bool bFirst ) override;
231 
235  virtual void DeclarationParsed( const OUString& rProperty,
236  std::unique_ptr<CSS1Expression> pExpr ) override;
237 
238 public:
239 
240  SvxCSS1Parser( SfxItemPool& rPool,
241  const OUString& rBaseURL,
242  sal_uInt16 const *pWhichIds, sal_uInt16 nWhichIds );
243  virtual ~SvxCSS1Parser() override;
244 
245  bool IsIgnoreFontFamily() const { return bIgnoreFontFamily; }
246  void SetIgnoreFontFamily( bool bSet ) { bIgnoreFontFamily = bSet; }
247 
248  // Parse a style sheet. For every found selector a StyleParsed with
249  // according item set is called.
250  virtual bool ParseStyleSheet( const OUString& rIn );
251 
252  // Parse style option. Here only the item set is filled.
253  void ParseStyleOption( const OUString& rIn, SfxItemSet& rItemSet,
254  SvxCSS1PropertyInfo& rPropInfo );
255 
256  // convert a string to enum value
257  static bool GetEnum( const CSS1PropertyEnum *pPropTable,
258  const OUString& rValue, sal_uInt16 &rEnum );
259 
260  static void PixelToTwip( long &nWidth, long &nHeight );
261 
262  // determine the font height of a certain font size (0-6)
263  virtual sal_uInt32 GetFontHeight( sal_uInt16 nSize ) const;
264 
265  virtual const FontList *GetFontList() const;
266 
267  const sal_uInt16 *GetWhichMap() const { return aWhichMap.data(); }
268 
269  static void InsertMapEntry( const OUString& rKey, const SfxItemSet& rItemSet,
270  const SvxCSS1PropertyInfo& rProp, CSS1Map& rMap );
271 
272  void InsertId( const OUString& rId, const SfxItemSet& rItemSet,
273  const SvxCSS1PropertyInfo& rProp );
274 
275  const SvxCSS1MapEntry* GetId( const OUString& rId ) const;
276 
277  void InsertClass( const OUString& rClass, const SfxItemSet& rItemSet,
278  const SvxCSS1PropertyInfo& rProp );
279 
280  const SvxCSS1MapEntry* GetClass( const OUString& rClass ) const;
281 
282  void InsertPage( const OUString& rPage, bool bPseudo,
283  const SfxItemSet& rItemSet,
284  const SvxCSS1PropertyInfo& rProp );
285 
286  SvxCSS1MapEntry* GetPage( const OUString& rPage, bool bPseudo );
287 
288  void InsertTag( const OUString& rTag, const SfxItemSet& rItemSet,
289  const SvxCSS1PropertyInfo& rProp );
290 
291  SvxCSS1MapEntry* GetTag( const OUString& rTag );
292 
293  static void MergeStyles( const SfxItemSet& rSrcSet,
294  const SvxCSS1PropertyInfo& rSrcInfo,
295  SfxItemSet& rTargetSet,
296  SvxCSS1PropertyInfo& rTargetInfo,
297  bool bSmart );
298 
299  static sal_uInt16 GetMinFixLineSpace() { return gnMinFixLineSpace; }
300 
301  virtual void SetDfltEncoding( rtl_TextEncoding eEnc );
302  rtl_TextEncoding GetDfltEncoding() const { return eDfltEnc; }
303 
304  const OUString& GetBaseURL() const { return sBaseURL;}
305 
306 };
307 
308 #endif
309 
310 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const char * pName
Definition: svxcss1.hxx:88
static void MergeStyles(const SfxItemSet &rSrcSet, const SvxCSS1PropertyInfo &rSrcInfo, SfxItemSet &rTargetSet, SvxCSS1PropertyInfo &rTargetInfo, bool bSmart)
Definition: svxcss1.cxx:928
virtual sal_uInt32 GetFontHeight(sal_uInt16 nSize) const
Definition: svxcss1.cxx:886
const OUString & GetBaseURL() const
Definition: svxcss1.hxx:304
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:451
SvxCSS1LengthType m_eTopType
Definition: svxcss1.hxx:137
std::map< OUString, std::unique_ptr< SvxCSS1MapEntry > > CSS1Map
Definition: svxcss1.hxx:189
virtual void SelectorParsed(std::unique_ptr< CSS1Selector > pSelector, bool bFirst) override
Will be called when a Selector is parsed.
Definition: svxcss1.cxx:677
void ParseStyleOption(const OUString &rIn, SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo)
Definition: svxcss1.cxx:842
virtual void SetDfltEncoding(rtl_TextEncoding eEnc)
Definition: svxcss1.cxx:978
SvxCSS1PropertyInfo aPropInfo
Definition: svxcss1.hxx:167
CSS1Map m_Tags
Definition: svxcss1.hxx:195
virtual void StyleParsed(const CSS1Selector *pSelector, SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo)
Definition: svxcss1.cxx:670
std::array< std::unique_ptr< SvxCSS1BorderInfo >, 4 > m_aBorderInfos
Definition: svxcss1.hxx:101
SvxCSS1BorderInfo * GetBorderInfo(SvxBoxItemLine nLine, bool bCreate=true)
Definition: svxcss1.cxx:533
std::unique_ptr< SfxItemSet > pSheetItemSet
Definition: svxcss1.hxx:199
const SvxCSS1PropertyInfo & GetPropertyInfo() const
Definition: svxcss1.hxx:176
SfxItemSet aItemSet
Definition: svxcss1.hxx:166
virtual const FontList * GetFontList() const
Definition: svxcss1.cxx:905
static void InsertMapEntry(const OUString &rKey, const SfxItemSet &rItemSet, const SvxCSS1PropertyInfo &rProp, CSS1Map &rMap)
Definition: svxcss1.cxx:910
SvxCSS1Parser(SfxItemPool &rPool, const OUString &rBaseURL, sal_uInt16 const *pWhichIds, sal_uInt16 nWhichIds)
Definition: svxcss1.cxx:697
OUString sBaseURL
Definition: svxcss1.hxx:197
SvxCSS1PropertyInfo * pPropInfo
Definition: svxcss1.hxx:203
bool bIgnoreFontFamily
Definition: svxcss1.hxx:208
void CopyBorderInfo(SvxBoxItemLine nSrcLine, SvxBoxItemLine nDstLine, sal_uInt16 nWhat)
Definition: svxcss1.cxx:550
rtl_TextEncoding GetDfltEncoding() const
Definition: svxcss1.hxx:302
void SetBoxItem(SfxItemSet &rItemSet, sal_uInt16 nMinBorderDist, const SvxBoxItem *pDflt=nullptr)
Definition: svxcss1.cxx:584
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:246
SvxCSS1LengthType m_eHeightType
Definition: svxcss1.hxx:138
SvxCSS1SizeType m_eSizeType
Definition: svxcss1.hxx:140
sal_uInt16 sal_Unicode
CSS1Map m_Pages
Definition: svxcss1.hxx:194
#define SAL_MAX_UINT16
bool IsIgnoreFontFamily() const
Definition: svxcss1.hxx:245
virtual void DeclarationParsed(const OUString &rProperty, std::unique_ptr< CSS1Expression > pExpr) override
Will be called for every parsed Property.
Definition: svxcss1.cxx:3161
SvxCSS1PageBreak m_ePageBreakAfter
Definition: svxcss1.hxx:143
CSS1Map m_Ids
Definition: svxcss1.hxx:192
sal_uInt16 nEnum
Definition: svxcss1.hxx:89
SvxCSS1MapEntry * GetTag(const OUString &rTag)
Definition: svxcss1.cxx:813
void ParseStyleSheet()
Definition: parcss1.cxx:669
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:785
virtual ~SvxCSS1Parser() override
Definition: svxcss1.cxx:753
sal_uInt16 m_nLeftBorderDistance
Definition: svxcss1.hxx:125
std::unique_ptr< SvxCSS1PropertyInfo > pSheetPropInfo
Definition: svxcss1.hxx:202
void DestroyBorderInfos()
Definition: svxcss1.cxx:416
SvxCSS1SizeType
Definition: svxcss1.hxx:56
SvxAdjust
sal_uInt16 m_nRightBorderDistance
Definition: svxcss1.hxx:126
rtl_TextEncoding eDfltEnc
Definition: svxcss1.hxx:207
CSS1Map m_Classes
Definition: svxcss1.hxx:193
std::vector< sal_uInt16 > aWhichMap
Definition: svxcss1.hxx:209
static constexpr sal_uInt16 gnMinFixLineSpace
Definition: svxcss1.hxx:205
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:772
SvxCSS1Position m_ePosition
Definition: svxcss1.hxx:121
SvxCSS1MapEntry(const SfxItemSet &rItemSet, const SvxCSS1PropertyInfo &rProp)
Definition: svxcss1.cxx:664
SvxAdjust m_eFloat
Definition: svxcss1.hxx:119
void ParseStyleOption(const OUString &rIn)
parse the content of a HTML style option
Definition: parcss1.cxx:1151
SvxCSS1MapEntry * GetPage(const OUString &rPage, bool bPseudo)
Definition: svxcss1.cxx:796
SvxCSS1LengthType m_eWidthType
Definition: svxcss1.hxx:138
#define MM50
Definition: swtypes.hxx:59
static sal_uInt16 GetMinFixLineSpace()
Definition: svxcss1.hxx:299
SvxBoxItemLine
const SvxCSS1MapEntry * GetId(const OUString &rId) const
Definition: svxcss1.cxx:766
const sal_uInt16 * GetWhichMap() const
Definition: svxcss1.hxx:267
CSS1Selectors m_Selectors
Definition: svxcss1.hxx:190
SfxItemSet * pItemSet
Definition: svxcss1.hxx:200
void InsertTag(const OUString &rTag, const SfxItemSet &rItemSet, const SvxCSS1PropertyInfo &rProp)
Definition: svxcss1.cxx:806
const SfxItemSet & GetItemSet() const
Definition: svxcss1.hxx:173
A simple selector.
Definition: parcss1.hxx:91
SfxItemSet & GetItemSet()
Definition: svxcss1.hxx:174
void InsertId(const OUString &rId, const SfxItemSet &rItemSet, const SvxCSS1PropertyInfo &rProp)
Definition: svxcss1.cxx:759
std::vector< std::unique_ptr< CSS1Selector > > CSS1Selectors
Definition: svxcss1.hxx:188
const SvxCSS1MapEntry * GetClass(const OUString &rClass) const
Definition: svxcss1.cxx:779
static bool GetEnum(const CSS1PropertyEnum *pPropTable, const OUString &rValue, sal_uInt16 &rEnum)
Definition: svxcss1.cxx:856
sal_uInt16 m_nColumnCount
Definition: svxcss1.hxx:131
static void PixelToTwip(long &nWidth, long &nHeight)
Definition: svxcss1.cxx:873
SvxCSS1PageBreak
Definition: svxcss1.hxx:65
sal_uInt16 m_nBottomBorderDistance
Definition: svxcss1.hxx:124
SvxCSS1PropertyInfo & GetPropertyInfo()
Definition: svxcss1.hxx:177