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