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