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 : sal_uInt16 nColumnCount;
123 :
124 : long nLeft, nTop;
125 : long nWidth, nHeight;
126 : long nLeftMargin, nRightMargin;
127 :
128 : SvxCSS1LengthType eLeftType, eTopType;
129 : SvxCSS1LengthType eWidthType, eHeightType;
130 :
131 : // Feature: PrintExt
132 : SvxCSS1SizeType eSizeType;
133 :
134 : SvxCSS1PageBreak ePageBreakBefore;
135 : SvxCSS1PageBreak ePageBreakAfter;
136 : // /Feature: PrintExt
137 :
138 : SvxCSS1PropertyInfo();
139 : SvxCSS1PropertyInfo( const SvxCSS1PropertyInfo& rProp );
140 : ~SvxCSS1PropertyInfo();
141 :
142 : void Merge( const SvxCSS1PropertyInfo& rProp );
143 :
144 : void Clear();
145 :
146 : SvxCSS1BorderInfo *GetBorderInfo( sal_uInt16 nLine, sal_Bool bCreate=sal_True );
147 : void CopyBorderInfo( sal_uInt16 nSrcLine, sal_uInt16 nDstLine, sal_uInt16 nWhat );
148 : void CopyBorderInfo( sal_uInt16 nCount, sal_uInt16 nWhat );
149 :
150 : void SetBoxItem( SfxItemSet& rItemSet, sal_uInt16 nMinBorderDist,
151 : const SvxBoxItem* pDflt=0, bool bTable = false );
152 :
153 : };
154 :
155 1 : class SvxCSS1MapEntry
156 : {
157 : String aKey;
158 : SfxItemSet aItemSet;
159 : SvxCSS1PropertyInfo aPropInfo;
160 :
161 : public:
162 :
163 1 : SvxCSS1MapEntry( SfxItemPool& rPool, const sal_uInt16 *pWhichMap ) :
164 1 : aItemSet( rPool, pWhichMap )
165 1 : {}
166 :
167 : SvxCSS1MapEntry( const String& rKey, const SfxItemSet& rItemSet,
168 : const SvxCSS1PropertyInfo& rProp );
169 :
170 :
171 0 : const SfxItemSet& GetItemSet() const { return aItemSet; }
172 0 : SfxItemSet& GetItemSet() { return aItemSet; }
173 :
174 0 : const SvxCSS1PropertyInfo& GetPropertyInfo() const { return aPropInfo; }
175 0 : SvxCSS1PropertyInfo& GetPropertyInfo() { return aPropInfo; }
176 :
177 : const String& GetKey() const { return aKey; }
178 : // TODO: ToUpperAscii -> ???
179 : void SetKey( const String& rKey ) { aKey = rKey; aKey.ToUpperAscii(); }
180 :
181 : friend sal_Bool operator==( const SvxCSS1MapEntry& rE1,
182 : const SvxCSS1MapEntry& rE2 );
183 : friend sal_Bool operator<( const SvxCSS1MapEntry& rE1,
184 : const SvxCSS1MapEntry& rE2 );
185 : };
186 :
187 : inline sal_Bool operator==( const SvxCSS1MapEntry& rE1, const SvxCSS1MapEntry& rE2 )
188 : {
189 : return rE1.aKey==rE2.aKey;
190 : }
191 :
192 : inline sal_Bool operator<( const SvxCSS1MapEntry& rE1, const SvxCSS1MapEntry& rE2 )
193 : {
194 : return rE1.aKey<rE2.aKey;
195 : }
196 :
197 : // Diese Klasse bereitet den Output des CSS1-Parsers auf,
198 : // indem die CSS1-Properties in SvxItem(Set)s umgewandelt werden.
199 : // Ausserdem werden die Selektoren samt zugehoeriger Item-Set
200 : // gespeichert.
201 : // Ein abgeleiteter Parser kann dies fuer einzelne Selektoren unterdruecken,
202 : // indem er die Methode StyleParsed ueberlaed.
203 :
204 : class SvxCSS1Parser : public CSS1Parser
205 : {
206 : typedef ::boost::ptr_vector<CSS1Selector> CSS1Selectors;
207 : typedef ::boost::ptr_map<String, SvxCSS1MapEntry> CSS1Map;
208 : CSS1Selectors aSelectors; // Liste der "offenen" Selectoren
209 :
210 : CSS1Map aIds;
211 : CSS1Map aClasses;
212 : CSS1Map aPages;
213 : CSS1Map aTags;
214 :
215 : String sBaseURL;
216 :
217 : SfxItemSet *pSheetItemSet; // der Item-Set fuer Style-Sheets
218 : SfxItemSet *pItemSet; // der aktuelle Item-Set
219 : SvxCSS1MapEntry *pSearchEntry;
220 :
221 : SvxCSS1PropertyInfo *pSheetPropInfo;
222 : SvxCSS1PropertyInfo *pPropInfo;
223 :
224 : sal_uInt16 nMinFixLineSpace; // Mindest-Abstand fuer festen Zeilenabstand
225 :
226 : rtl_TextEncoding eDfltEnc;
227 : sal_uInt16 nScriptFlags;
228 :
229 : sal_Bool bIgnoreFontFamily;
230 :
231 : void ParseProperty( const String& rProperty,
232 : const CSS1Expression *pExpr );
233 :
234 : std::vector<sal_uInt16> aWhichMap; // Which-Map des Parser
235 :
236 : using CSS1Parser::ParseStyleOption;
237 :
238 : protected:
239 :
240 : using CSS1Parser::ParseStyleSheet;
241 :
242 : // Diese Methode wird fuer jeden Selektor mit dem zugehoerigen
243 : // Item-Set aufgerufen. Fuer einen Selektor koennen mehrere
244 : // Aufrufe erfolgen.
245 : // wenn sal_True zuruckgegeben wird, wird der Item-Set bzw. der
246 : // Selektor nicht mehr gespeichert!
247 : // Der ItemSet darf entsprechend modifiziert werden!
248 : // Die Implementierung dieser Methode gibt sal_False zurueck.
249 : virtual sal_Bool StyleParsed( const CSS1Selector *pSelector,
250 : SfxItemSet& rItemSet,
251 : SvxCSS1PropertyInfo& rPropInfo );
252 :
253 : // Diese Methode wird aufgerufen, wenn ein Selektor geparst wurde
254 : // Wenn bFirst gesetzt ist, wird der Inhalt von aItemSet in alle
255 : // zuletzt angelegten Styles kopiert.
256 : // Diese Methode sollte in abgleiteten Parsern nicht mehr
257 : // ueberladen werden!
258 : virtual bool SelectorParsed( CSS1Selector *pSelector, bool bFirst );
259 :
260 : // Diese Methode wird fuer jede geparste Property aufgerufen
261 : // sie fuegt das Item in den ItemSet 'pItemSet' ein
262 : // Sie sollte in abgeleiteten Parsern nicht mehr ueberladen werden!
263 : virtual sal_Bool DeclarationParsed( const String& rProperty,
264 : const CSS1Expression *pExpr );
265 :
266 : public:
267 :
268 :
269 : SvxCSS1Parser( SfxItemPool& rPool,
270 : const String& rBaseURL,
271 : sal_uInt16 nMinFixLineSp,
272 : sal_uInt16 *pWhichIds=0, sal_uInt16 nWhichIds=0 );
273 : virtual ~SvxCSS1Parser();
274 :
275 0 : sal_Bool IsIgnoreFontFamily() const { return bIgnoreFontFamily; }
276 1 : void SetIgnoreFontFamily( sal_Bool bSet ) { bIgnoreFontFamily = bSet; }
277 :
278 : // Parsen eines Style-Sheets. Fuer jeden gefundenen Selektor
279 : // wird StyleParsed mit dem entsprechenem Item-Set aufgerufen
280 : virtual sal_Bool ParseStyleSheet( const String& rIn );
281 :
282 : // Parsen einer Style-Option. Hier wird einfach nur der Item-Set
283 : // gefuellt.
284 : sal_Bool ParseStyleOption( const String& rIn, SfxItemSet& rItemSet,
285 : SvxCSS1PropertyInfo& rPropInfo );
286 :
287 : // Umwandeln eines Strings in den Wert eines Enums
288 : static sal_Bool GetEnum( const CSS1PropertyEnum *pPropTable,
289 : const String& rValue, sal_uInt16 &rEnum );
290 :
291 : // Pixel in Twips wandeln
292 : static void PixelToTwip( long &nWidth, long &nHeight );
293 :
294 : // Die Font-Hoehe fuer eine bestimmte Font-Groesse (0-6) ermitteln
295 : virtual sal_uInt32 GetFontHeight( sal_uInt16 nSize ) const;
296 :
297 : virtual const FontList *GetFontList() const;
298 :
299 1 : const sal_uInt16 *GetWhichMap() const { return &aWhichMap[0]; }
300 :
301 : void InsertMapEntry( const String& rKey, const SfxItemSet& rItemSet,
302 : const SvxCSS1PropertyInfo& rProp, CSS1Map& rMap );
303 :
304 : void InsertId( const String& rId, const SfxItemSet& rItemSet,
305 : const SvxCSS1PropertyInfo& rProp );
306 :
307 : const SvxCSS1MapEntry* GetId( const String& rId ) const;
308 :
309 : void InsertClass( const String& rClass, const SfxItemSet& rItemSet,
310 : const SvxCSS1PropertyInfo& rProp );
311 :
312 : const SvxCSS1MapEntry* GetClass( const String& rClass ) const;
313 :
314 : void InsertPage( const String& rPage, sal_Bool bPseudo,
315 : const SfxItemSet& rItemSet,
316 : const SvxCSS1PropertyInfo& rProp );
317 :
318 : SvxCSS1MapEntry* GetPage( const String& rPage, bool bPseudo );
319 :
320 : void InsertTag( const String& rTag, const SfxItemSet& rItemSet,
321 : const SvxCSS1PropertyInfo& rProp );
322 :
323 : SvxCSS1MapEntry* GetTag( const String& rTag );
324 :
325 : void MergeStyles( const SfxItemSet& rSrcSet,
326 : const SvxCSS1PropertyInfo& rSrcInfo,
327 : SfxItemSet& rTargetSet,
328 : SvxCSS1PropertyInfo& rTargetInfo,
329 : sal_Bool bSmart );
330 :
331 0 : sal_uInt16 GetMinFixLineSpace() const { return nMinFixLineSpace; }
332 :
333 : virtual void SetDfltEncoding( rtl_TextEncoding eEnc );
334 1 : rtl_TextEncoding GetDfltEncoding() const { return eDfltEnc; }
335 :
336 0 : bool IsSetWesternProps() const { return (nScriptFlags & CSS1_SCRIPT_WESTERN) != 0; }
337 0 : bool IsSetCJKProps() const { return (nScriptFlags & CSS1_SCRIPT_CJK) != 0; }
338 0 : bool IsSetCTLProps() const { return (nScriptFlags & CSS1_SCRIPT_CTL) != 0; }
339 :
340 0 : const String& GetBaseURL() const { return sBaseURL;}
341 :
342 : };
343 :
344 : #endif
345 :
346 :
347 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|