Line data Source code
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 <editeng/svxenum.hxx>
24 : #include <rtl/textenc.h>
25 : #include "parcss1.hxx"
26 :
27 : #include <boost/ptr_container/ptr_vector.hpp>
28 : #include <boost/ptr_container/ptr_map.hpp>
29 :
30 : class SfxItemPool;
31 : class SvxBoxItem;
32 : class FontList;
33 :
34 : enum SvxCSS1Position
35 : {
36 : SVX_CSS1_POS_NONE, // nichts angegeben
37 : SVX_CSS1_POS_STATIC, // normal
38 : SVX_CSS1_POS_ABSOLUTE, // absolut
39 : SVX_CSS1_POS_RELATIVE, // relativ
40 : SVX_CSS1_POS_END
41 : };
42 :
43 : enum SvxCSS1LengthType
44 : {
45 : SVX_CSS1_LTYPE_NONE, // nichts angegeben
46 : SVX_CSS1_LTYPE_AUTO, // automatisch
47 : SVX_CSS1_LTYPE_TWIP, // twip
48 : SVX_CSS1_LTYPE_PERCENTAGE, // %-Angabe
49 : SVX_CSS1_LTYPE_END
50 : };
51 :
52 : // Feature: PrintExt
53 : enum SvxCSS1SizeType
54 : {
55 : SVX_CSS1_STYPE_NONE, // nichts angegeben
56 : SVX_CSS1_STYPE_AUTO, // automatisch
57 : SVX_CSS1_STYPE_TWIP, // twip
58 : SVX_CSS1_STYPE_LANDSCAPE, // Landscape
59 : SVX_CSS1_STYPE_PORTRAIT, // Landscape
60 : SVX_CSS1_STYPE_END
61 : };
62 :
63 : enum SvxCSS1PageBreak
64 : {
65 : SVX_CSS1_PBREAK_NONE, // nichts angegeben
66 : SVX_CSS1_PBREAK_AUTO, // automatisch
67 : SVX_CSS1_PBREAK_ALWAYS, // immer
68 : SVX_CSS1_PBREAK_AVOID, // nie
69 : SVX_CSS1_PBREAK_LEFT, // naechste Seite ist eine linke
70 : SVX_CSS1_PBREAK_RIGHT, // naechste Seite ist eine rechte
71 : SVX_CSS1_PBREAK_END
72 : };
73 :
74 : // /Feature: PrintExt
75 :
76 : #define CSS1_SCRIPT_WESTERN 0x01
77 : #define CSS1_SCRIPT_CJK 0x02
78 : #define CSS1_SCRIPT_CTL 0x04
79 : #define CSS1_SCRIPT_ALL 0x07
80 :
81 : struct CSS1PropertyEnum
82 : {
83 : const sal_Char *pName; // Wert einer Property
84 : sal_uInt16 nEnum; // und der dazugehoerige Wert eines Enums
85 : };
86 :
87 : namespace editeng { class SvxBorderLine; }
88 :
89 : #define SVX_CSS1_BORDERINFO_WIDTH 1
90 : #define SVX_CSS1_BORDERINFO_COLOR 2
91 : #define SVX_CSS1_BORDERINFO_STYLE 4
92 :
93 : struct SvxCSS1BorderInfo;
94 : class SvxCSS1PropertyInfo
95 : {
96 : SvxCSS1BorderInfo *aBorderInfos[4];
97 :
98 : void DestroyBorderInfos();
99 :
100 : public:
101 :
102 : OUString aId; // ID fuer Bookmarks, Rahmen etc.
103 :
104 : sal_Bool bTopMargin : 1;
105 : sal_Bool bBottomMargin : 1;
106 :
107 : sal_Bool bLeftMargin : 1;
108 : sal_Bool bRightMargin : 1;
109 : sal_Bool bTextIndent : 1;
110 :
111 : SvxAdjust eFloat;
112 :
113 : SvxCSS1Position ePosition;
114 :
115 : sal_uInt16 nTopBorderDistance;
116 : sal_uInt16 nBottomBorderDistance;
117 : sal_uInt16 nLeftBorderDistance;
118 : sal_uInt16 nRightBorderDistance;
119 :
120 : sal_uInt16 nColumnCount;
121 :
122 : long nLeft, nTop;
123 : long nWidth, nHeight;
124 : long nLeftMargin, nRightMargin;
125 :
126 : SvxCSS1LengthType eLeftType, eTopType;
127 : SvxCSS1LengthType eWidthType, eHeightType;
128 :
129 : // Feature: PrintExt
130 : SvxCSS1SizeType eSizeType;
131 :
132 : SvxCSS1PageBreak ePageBreakBefore;
133 : SvxCSS1PageBreak ePageBreakAfter;
134 : // /Feature: PrintExt
135 :
136 : SvxCSS1PropertyInfo();
137 : SvxCSS1PropertyInfo( const SvxCSS1PropertyInfo& rProp );
138 : ~SvxCSS1PropertyInfo();
139 :
140 : void Merge( const SvxCSS1PropertyInfo& rProp );
141 :
142 : void Clear();
143 :
144 : SvxCSS1BorderInfo *GetBorderInfo( sal_uInt16 nLine, sal_Bool bCreate=sal_True );
145 : void CopyBorderInfo( sal_uInt16 nSrcLine, sal_uInt16 nDstLine, sal_uInt16 nWhat );
146 : void CopyBorderInfo( sal_uInt16 nCount, sal_uInt16 nWhat );
147 :
148 : void SetBoxItem( SfxItemSet& rItemSet, sal_uInt16 nMinBorderDist,
149 : const SvxBoxItem* pDflt=0, bool bTable = false );
150 :
151 : };
152 :
153 9 : class SvxCSS1MapEntry
154 : {
155 : OUString aKey;
156 : SfxItemSet aItemSet;
157 : SvxCSS1PropertyInfo aPropInfo;
158 :
159 : public:
160 :
161 6 : SvxCSS1MapEntry( SfxItemPool& rPool, const sal_uInt16 *pWhichMap ) :
162 6 : aItemSet( rPool, pWhichMap )
163 6 : {}
164 :
165 : SvxCSS1MapEntry( const OUString& rKey, const SfxItemSet& rItemSet,
166 : const SvxCSS1PropertyInfo& rProp );
167 :
168 0 : const SfxItemSet& GetItemSet() const { return aItemSet; }
169 9 : SfxItemSet& GetItemSet() { return aItemSet; }
170 :
171 0 : const SvxCSS1PropertyInfo& GetPropertyInfo() const { return aPropInfo; }
172 8 : SvxCSS1PropertyInfo& GetPropertyInfo() { return aPropInfo; }
173 :
174 : const OUString& GetKey() const { return aKey; }
175 : void SetKey( const OUString& rKey ) { aKey = rKey.toAsciiUpperCase(); }
176 :
177 : friend sal_Bool operator==( const SvxCSS1MapEntry& rE1,
178 : const SvxCSS1MapEntry& rE2 );
179 : friend sal_Bool operator<( const SvxCSS1MapEntry& rE1,
180 : const SvxCSS1MapEntry& rE2 );
181 : };
182 :
183 : inline sal_Bool operator==( const SvxCSS1MapEntry& rE1, const SvxCSS1MapEntry& rE2 )
184 : {
185 : return rE1.aKey==rE2.aKey;
186 : }
187 :
188 : inline sal_Bool operator<( const SvxCSS1MapEntry& rE1, const SvxCSS1MapEntry& rE2 )
189 : {
190 : return rE1.aKey<rE2.aKey;
191 : }
192 :
193 : // Diese Klasse bereitet den Output des CSS1-Parsers auf,
194 : // indem die CSS1-Properties in SvxItem(Set)s umgewandelt werden.
195 : // Ausserdem werden die Selektoren samt zugehoeriger Item-Set
196 : // gespeichert.
197 : // Ein abgeleiteter Parser kann dies fuer einzelne Selektoren unterdruecken,
198 : // indem er die Methode StyleParsed ueberlaed.
199 :
200 : class SvxCSS1Parser : public CSS1Parser
201 : {
202 : typedef ::boost::ptr_vector<CSS1Selector> CSS1Selectors;
203 : typedef ::boost::ptr_map<OUString, SvxCSS1MapEntry> CSS1Map;
204 : CSS1Selectors aSelectors; // Liste der "offenen" Selectoren
205 :
206 : CSS1Map aIds;
207 : CSS1Map aClasses;
208 : CSS1Map aPages;
209 : CSS1Map aTags;
210 :
211 : OUString sBaseURL;
212 :
213 : SfxItemSet *pSheetItemSet; // der Item-Set fuer Style-Sheets
214 : SfxItemSet *pItemSet; // der aktuelle Item-Set
215 : SvxCSS1MapEntry *pSearchEntry;
216 :
217 : SvxCSS1PropertyInfo *pSheetPropInfo;
218 : SvxCSS1PropertyInfo *pPropInfo;
219 :
220 : sal_uInt16 nMinFixLineSpace; // Mindest-Abstand fuer festen Zeilenabstand
221 :
222 : rtl_TextEncoding eDfltEnc;
223 : sal_uInt16 nScriptFlags;
224 :
225 : sal_Bool bIgnoreFontFamily;
226 :
227 : void ParseProperty( const OUString& rProperty,
228 : const CSS1Expression *pExpr );
229 :
230 : std::vector<sal_uInt16> aWhichMap; // Which-Map des Parser
231 :
232 : using CSS1Parser::ParseStyleOption;
233 :
234 : protected:
235 :
236 : using CSS1Parser::ParseStyleSheet;
237 :
238 : // Diese Methode wird fuer jeden Selektor mit dem zugehoerigen
239 : // Item-Set aufgerufen. Fuer einen Selektor koennen mehrere
240 : // Aufrufe erfolgen.
241 : // wenn sal_True zuruckgegeben wird, wird der Item-Set bzw. der
242 : // Selektor nicht mehr gespeichert!
243 : // Der ItemSet darf entsprechend modifiziert werden!
244 : // Die Implementierung dieser Methode gibt sal_False zurueck.
245 : virtual sal_Bool StyleParsed( const CSS1Selector *pSelector,
246 : SfxItemSet& rItemSet,
247 : SvxCSS1PropertyInfo& rPropInfo );
248 :
249 : // Diese Methode wird aufgerufen, wenn ein Selektor geparst wurde
250 : // Wenn bFirst gesetzt ist, wird der Inhalt von aItemSet in alle
251 : // zuletzt angelegten Styles kopiert.
252 : // Diese Methode sollte in abgleiteten Parsern nicht mehr
253 : // ueberladen werden!
254 : virtual bool SelectorParsed( CSS1Selector *pSelector, bool bFirst ) SAL_OVERRIDE;
255 :
256 : // Diese Methode wird fuer jede geparste Property aufgerufen
257 : // sie fuegt das Item in den ItemSet 'pItemSet' ein
258 : // Sie sollte in abgeleiteten Parsern nicht mehr ueberladen werden!
259 : virtual sal_Bool DeclarationParsed( const OUString& rProperty,
260 : const CSS1Expression *pExpr ) SAL_OVERRIDE;
261 :
262 : public:
263 :
264 : SvxCSS1Parser( SfxItemPool& rPool,
265 : const OUString& rBaseURL,
266 : sal_uInt16 nMinFixLineSp,
267 : sal_uInt16 *pWhichIds=0, sal_uInt16 nWhichIds=0 );
268 : virtual ~SvxCSS1Parser();
269 :
270 3 : sal_Bool IsIgnoreFontFamily() const { return bIgnoreFontFamily; }
271 6 : void SetIgnoreFontFamily( sal_Bool bSet ) { bIgnoreFontFamily = bSet; }
272 :
273 : // Parsen eines Style-Sheets. Fuer jeden gefundenen Selektor
274 : // wird StyleParsed mit dem entsprechenem Item-Set aufgerufen
275 : virtual sal_Bool ParseStyleSheet( const OUString& rIn );
276 :
277 : // Parsen einer Style-Option. Hier wird einfach nur der Item-Set
278 : // gefuellt.
279 : sal_Bool ParseStyleOption( const OUString& rIn, SfxItemSet& rItemSet,
280 : SvxCSS1PropertyInfo& rPropInfo );
281 :
282 : // Umwandeln eines Strings in den Wert eines Enums
283 : static sal_Bool GetEnum( const CSS1PropertyEnum *pPropTable,
284 : const OUString& rValue, sal_uInt16 &rEnum );
285 :
286 : // Pixel in Twips wandeln
287 : static void PixelToTwip( long &nWidth, long &nHeight );
288 :
289 : // Die Font-Hoehe fuer eine bestimmte Font-Groesse (0-6) ermitteln
290 : virtual sal_uInt32 GetFontHeight( sal_uInt16 nSize ) const;
291 :
292 : virtual const FontList *GetFontList() const;
293 :
294 559 : const sal_uInt16 *GetWhichMap() const { return &aWhichMap[0]; }
295 :
296 : void InsertMapEntry( const OUString& rKey, const SfxItemSet& rItemSet,
297 : const SvxCSS1PropertyInfo& rProp, CSS1Map& rMap );
298 :
299 : void InsertId( const OUString& rId, const SfxItemSet& rItemSet,
300 : const SvxCSS1PropertyInfo& rProp );
301 :
302 : const SvxCSS1MapEntry* GetId( const OUString& rId ) const;
303 :
304 : void InsertClass( const OUString& rClass, const SfxItemSet& rItemSet,
305 : const SvxCSS1PropertyInfo& rProp );
306 :
307 : const SvxCSS1MapEntry* GetClass( const OUString& rClass ) const;
308 :
309 : void InsertPage( const OUString& rPage, sal_Bool bPseudo,
310 : const SfxItemSet& rItemSet,
311 : const SvxCSS1PropertyInfo& rProp );
312 :
313 : SvxCSS1MapEntry* GetPage( const OUString& rPage, bool bPseudo );
314 :
315 : void InsertTag( const OUString& rTag, const SfxItemSet& rItemSet,
316 : const SvxCSS1PropertyInfo& rProp );
317 :
318 : SvxCSS1MapEntry* GetTag( const OUString& rTag );
319 :
320 : void MergeStyles( const SfxItemSet& rSrcSet,
321 : const SvxCSS1PropertyInfo& rSrcInfo,
322 : SfxItemSet& rTargetSet,
323 : SvxCSS1PropertyInfo& rTargetInfo,
324 : sal_Bool bSmart );
325 :
326 0 : sal_uInt16 GetMinFixLineSpace() const { return nMinFixLineSpace; }
327 :
328 : virtual void SetDfltEncoding( rtl_TextEncoding eEnc );
329 333 : rtl_TextEncoding GetDfltEncoding() const { return eDfltEnc; }
330 :
331 12 : bool IsSetWesternProps() const { return (nScriptFlags & CSS1_SCRIPT_WESTERN) != 0; }
332 12 : bool IsSetCJKProps() const { return (nScriptFlags & CSS1_SCRIPT_CJK) != 0; }
333 12 : bool IsSetCTLProps() const { return (nScriptFlags & CSS1_SCRIPT_CTL) != 0; }
334 :
335 0 : const OUString& GetBaseURL() const { return sBaseURL;}
336 :
337 : };
338 :
339 : #endif
340 :
341 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|