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"
37 SVX_CSS1_POS_NONE
, // nichts angegeben
38 SVX_CSS1_POS_STATIC
, // normal
39 SVX_CSS1_POS_ABSOLUTE
, // absolut
40 SVX_CSS1_POS_RELATIVE
, // relativ
44 enum SvxCSS1LengthType
46 SVX_CSS1_LTYPE_NONE
, // nichts angegeben
47 SVX_CSS1_LTYPE_AUTO
, // automatisch
48 SVX_CSS1_LTYPE_TWIP
, // twip
49 SVX_CSS1_LTYPE_PERCENTAGE
, // %-Angabe
56 SVX_CSS1_STYPE_NONE
, // nichts angegeben
57 SVX_CSS1_STYPE_AUTO
, // automatisch
58 SVX_CSS1_STYPE_TWIP
, // twip
59 SVX_CSS1_STYPE_LANDSCAPE
, // Landscape
60 SVX_CSS1_STYPE_PORTRAIT
, // Landscape
66 SVX_CSS1_PBREAK_NONE
, // nichts angegeben
67 SVX_CSS1_PBREAK_AUTO
, // automatisch
68 SVX_CSS1_PBREAK_ALWAYS
, // immer
69 SVX_CSS1_PBREAK_AVOID
, // nie
70 SVX_CSS1_PBREAK_LEFT
, // naechste Seite ist eine linke
71 SVX_CSS1_PBREAK_RIGHT
, // naechste Seite ist eine rechte
76 #define CSS1_SCRIPT_WESTERN 0x01
77 #define CSS1_SCRIPT_CJK 0x02
78 #define CSS1_SCRIPT_CTL 0x04
79 #define CSS1_SCRIPT_ALL 0x07
81 struct CSS1PropertyEnum
83 const sal_Char
*pName
; // Wert einer Property
84 sal_uInt16 nEnum
; // und der dazugehoerige Wert eines Enums
87 namespace editeng
{ class SvxBorderLine
; }
89 #define SVX_CSS1_BORDERINFO_WIDTH 1
90 #define SVX_CSS1_BORDERINFO_COLOR 2
91 #define SVX_CSS1_BORDERINFO_STYLE 4
93 struct SvxCSS1BorderInfo
;
94 class SvxCSS1PropertyInfo
96 SvxCSS1BorderInfo
*m_aBorderInfos
[4];
98 void DestroyBorderInfos();
102 OUString m_aId
; // ID fuer Bookmarks, Rahmen etc.
104 bool m_bTopMargin
: 1;
105 bool m_bBottomMargin
: 1;
107 bool m_bLeftMargin
: 1;
108 bool m_bRightMargin
: 1;
109 bool m_bTextIndent
: 1;
113 SvxCSS1Position m_ePosition
;
115 sal_uInt16 m_nTopBorderDistance
;
116 sal_uInt16 m_nBottomBorderDistance
;
117 sal_uInt16 m_nLeftBorderDistance
;
118 sal_uInt16 m_nRightBorderDistance
;
120 sal_uInt16 m_nColumnCount
;
122 long m_nLeft
, m_nTop
;
123 long m_nWidth
, m_nHeight
;
124 long m_nLeftMargin
, m_nRightMargin
;
126 SvxCSS1LengthType m_eLeftType
, m_eTopType
;
127 SvxCSS1LengthType m_eWidthType
, m_eHeightType
;
129 SvxCSS1SizeType m_eSizeType
;
131 SvxCSS1PageBreak m_ePageBreakBefore
;
132 SvxCSS1PageBreak m_ePageBreakAfter
;
134 SvxCSS1PropertyInfo();
135 SvxCSS1PropertyInfo( const SvxCSS1PropertyInfo
& rProp
);
136 ~SvxCSS1PropertyInfo();
138 void Merge( const SvxCSS1PropertyInfo
& rProp
);
142 SvxCSS1BorderInfo
*GetBorderInfo( SvxBoxItemLine nLine
, bool bCreate
=true );
143 void CopyBorderInfo( SvxBoxItemLine nSrcLine
, SvxBoxItemLine nDstLine
, sal_uInt16 nWhat
);
144 void CopyBorderInfo( sal_uInt16 nCount
, sal_uInt16 nWhat
);
146 void SetBoxItem( SfxItemSet
& rItemSet
, sal_uInt16 nMinBorderDist
,
147 const SvxBoxItem
* pDflt
=nullptr );
151 class SvxCSS1MapEntry
154 SvxCSS1PropertyInfo aPropInfo
;
157 SvxCSS1MapEntry( SfxItemPool
& rPool
, const sal_uInt16
*pWhichMap
) :
158 aItemSet( rPool
, pWhichMap
)
161 SvxCSS1MapEntry( const SfxItemSet
& rItemSet
,
162 const SvxCSS1PropertyInfo
& rProp
);
164 const SfxItemSet
& GetItemSet() const { return aItemSet
; }
165 SfxItemSet
& GetItemSet() { return aItemSet
; }
167 const SvxCSS1PropertyInfo
& GetPropertyInfo() const { return aPropInfo
; }
168 SvxCSS1PropertyInfo
& GetPropertyInfo() { return aPropInfo
; }
171 // Diese Klasse bereitet den Output des CSS1-Parsers auf,
172 // indem die CSS1-Properties in SvxItem(Set)s umgewandelt werden.
173 // Ausserdem werden die Selektoren samt zugehoeriger Item-Set
175 // Ein abgeleiteter Parser kann dies fuer einzelne Selektoren unterdruecken,
176 // indem er die Methode StyleParsed ueberlaed.
178 class SvxCSS1Parser
: public CSS1Parser
180 typedef std::vector
<std::unique_ptr
<CSS1Selector
>> CSS1Selectors
;
181 typedef std::map
<OUString
, std::unique_ptr
<SvxCSS1MapEntry
>> CSS1Map
;
182 CSS1Selectors m_Selectors
; // List of "open" Selectors
191 SfxItemSet
*pSheetItemSet
; // der Item-Set fuer Style-Sheets
192 SfxItemSet
*pItemSet
; // der aktuelle Item-Set
193 SvxCSS1MapEntry
*pSearchEntry
;
195 SvxCSS1PropertyInfo
*pSheetPropInfo
;
196 SvxCSS1PropertyInfo
*pPropInfo
;
198 sal_uInt16 nMinFixLineSpace
; // Mindest-Abstand fuer festen Zeilenabstand
200 rtl_TextEncoding eDfltEnc
;
201 sal_uInt16 nScriptFlags
;
203 bool bIgnoreFontFamily
;
205 void ParseProperty( const OUString
& rProperty
,
206 const CSS1Expression
*pExpr
);
208 std::vector
<sal_uInt16
> aWhichMap
; // Which-Map des Parser
210 using CSS1Parser::ParseStyleOption
;
214 using CSS1Parser::ParseStyleSheet
;
216 // Diese Methode wird fuer jeden Selektor mit dem zugehoerigen
217 // Item-Set aufgerufen. Fuer einen Selektor koennen mehrere
219 // wenn true zuruckgegeben wird, wird der Item-Set bzw. der
220 // Selektor nicht mehr gespeichert!
221 // Der ItemSet darf entsprechend modifiziert werden!
222 // Die Implementierung dieser Methode gibt false zurueck.
223 virtual void StyleParsed( const CSS1Selector
*pSelector
,
224 SfxItemSet
& rItemSet
,
225 SvxCSS1PropertyInfo
& rPropInfo
);
227 /// Will be called when a Selector is parsed. If bFirst is true,
228 /// the content of the aItemSet will be copied into all recently
230 /// Derived classes should not override this method!
231 virtual bool SelectorParsed( CSS1Selector
*pSelector
, bool bFirst
) override
;
233 /// Will be called for every parsed Property. Adds the item to the
235 /// Derived classes should not override this method!
236 virtual bool DeclarationParsed( const OUString
& rProperty
,
237 const CSS1Expression
*pExpr
) override
;
241 SvxCSS1Parser( SfxItemPool
& rPool
,
242 const OUString
& rBaseURL
,
243 sal_uInt16
*pWhichIds
, sal_uInt16 nWhichIds
=0 );
244 virtual ~SvxCSS1Parser() override
;
246 bool IsIgnoreFontFamily() const { return bIgnoreFontFamily
; }
247 void SetIgnoreFontFamily( bool bSet
) { bIgnoreFontFamily
= bSet
; }
249 // Parsen eines Style-Sheets. Fuer jeden gefundenen Selektor
250 // wird StyleParsed mit dem entsprechenem Item-Set aufgerufen
251 virtual bool ParseStyleSheet( const OUString
& rIn
);
253 // Parsen einer Style-Option. Hier wird einfach nur der Item-Set
255 void ParseStyleOption( const OUString
& rIn
, SfxItemSet
& rItemSet
,
256 SvxCSS1PropertyInfo
& rPropInfo
);
258 // Umwandeln eines Strings in den Wert eines Enums
259 static bool GetEnum( const CSS1PropertyEnum
*pPropTable
,
260 const OUString
& rValue
, sal_uInt16
&rEnum
);
262 // Pixel in Twips wandeln
263 static void PixelToTwip( long &nWidth
, long &nHeight
);
265 // Die Font-Hoehe fuer eine bestimmte Font-Groesse (0-6) ermitteln
266 virtual sal_uInt32
GetFontHeight( sal_uInt16 nSize
) const;
268 virtual const FontList
*GetFontList() const;
270 const sal_uInt16
*GetWhichMap() const { return aWhichMap
.data(); }
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
,
302 sal_uInt16
GetMinFixLineSpace() const { return nMinFixLineSpace
; }
304 virtual void SetDfltEncoding( rtl_TextEncoding eEnc
);
305 rtl_TextEncoding
GetDfltEncoding() const { return eDfltEnc
; }
307 bool IsSetWesternProps() const { return (nScriptFlags
& CSS1_SCRIPT_WESTERN
) != 0; }
308 bool IsSetCJKProps() const { return (nScriptFlags
& CSS1_SCRIPT_CJK
) != 0; }
309 bool IsSetCTLProps() const { return (nScriptFlags
& CSS1_SCRIPT_CTL
) != 0; }
311 const OUString
& GetBaseURL() const { return sBaseURL
;}
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */