xref: /AOO41X/main/sw/source/filter/html/svxcss1.hxx (revision 1d2dbeb0b7301723c6d13094e87a8714ef81a328)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _SVXCSS1_HXX
24 #define _SVXCSS1_HXX
25 
26 #include <tools/string.hxx>
27 #include <svl/itemset.hxx>
28 #include <editeng/svxenum.hxx>
29 
30 #ifndef _SVSTDARR_HXX
31 #define _SVSTDARR_USHORTS
32 #include <svl/svstdarr.hxx>
33 #endif
34 #include <rtl/textenc.h>
35 #include "parcss1.hxx"
36 
37 class SfxItemPool;
38 class SvxBoxItem;
39 class FontList;
40 
41 /*  */
42 
43 enum SvxCSS1Position
44 {
45     SVX_CSS1_POS_NONE,          // nichts angegeben
46     SVX_CSS1_POS_STATIC,        // normal
47     SVX_CSS1_POS_ABSOLUTE,      // absolut
48     SVX_CSS1_POS_RELATIVE,      // relativ
49     SVX_CSS1_POS_END
50 };
51 
52 
53 enum SvxCSS1LengthType
54 {
55     SVX_CSS1_LTYPE_NONE,        // nichts angegeben
56     SVX_CSS1_LTYPE_AUTO,        // automatisch
57     SVX_CSS1_LTYPE_TWIP,        // twip
58     SVX_CSS1_LTYPE_PERCENTAGE,  // %-Angabe
59     SVX_CSS1_LTYPE_END
60 };
61 
62 // Feature: PrintExt
63 enum SvxCSS1SizeType
64 {
65     SVX_CSS1_STYPE_NONE,        // nichts angegeben
66     SVX_CSS1_STYPE_AUTO,        // automatisch
67     SVX_CSS1_STYPE_TWIP,        // twip
68     SVX_CSS1_STYPE_LANDSCAPE,   // Landscape
69     SVX_CSS1_STYPE_PORTRAIT,    // Landscape
70     SVX_CSS1_STYPE_END
71 };
72 
73 enum SvxCSS1PageBreak
74 {
75     SVX_CSS1_PBREAK_NONE,       // nichts angegeben
76     SVX_CSS1_PBREAK_AUTO,       // automatisch
77     SVX_CSS1_PBREAK_ALWAYS,     // immer
78     SVX_CSS1_PBREAK_AVOID,      // nie
79     SVX_CSS1_PBREAK_LEFT,       // naechste Seite ist eine linke
80     SVX_CSS1_PBREAK_RIGHT,      // naechste Seite ist eine rechte
81     SVX_CSS1_PBREAK_END
82 };
83 
84 // /Feature: PrintExt
85 
86 #define CSS1_SCRIPT_WESTERN 0x01
87 #define CSS1_SCRIPT_CJK     0x02
88 #define CSS1_SCRIPT_CTL     0x04
89 #define CSS1_SCRIPT_ALL     0x07
90 
91 /*  */
92 
93 struct CSS1PropertyEnum
94 {
95     const sal_Char *pName;  // Wert einer Property
96     sal_uInt16 nEnum;           // und der dazugehoerige Wert eines Enums
97 };
98 
99 
100 /*  */
101 
102 class SvxBorderLine;
103 
104 SV_DECL_PTRARR_DEL( CSS1Selectors, CSS1Selector*, 1, 1 )
105 
106 #define SVX_CSS1_BORDERINFO_WIDTH 1
107 #define SVX_CSS1_BORDERINFO_COLOR 2
108 #define SVX_CSS1_BORDERINFO_STYLE 4
109 
110 struct SvxCSS1BorderInfo;
111 class SvxCSS1PropertyInfo
112 {
113     SvxCSS1BorderInfo *aBorderInfos[4];
114 
115     void DestroyBorderInfos();
116 
117 public:
118 
119     String aId;             // ID fuer Bookmarks, Rahmen etc.
120 
121     sal_Bool bTopMargin : 1;
122     sal_Bool bBottomMargin : 1;
123 
124     sal_Bool bLeftMargin : 1;
125     sal_Bool bRightMargin : 1;
126     sal_Bool bTextIndent : 1;
127 
128     SvxAdjust eFloat;
129 
130     SvxCSS1Position ePosition;
131 
132     sal_uInt16 nTopBorderDistance;
133     sal_uInt16 nBottomBorderDistance;
134     sal_uInt16 nLeftBorderDistance;
135     sal_uInt16 nRightBorderDistance;
136 
137     long nLeft, nTop;
138     long nWidth, nHeight;
139     long nLeftMargin, nRightMargin;
140 
141     SvxCSS1LengthType eLeftType, eTopType;
142     SvxCSS1LengthType eWidthType, eHeightType;
143 
144 // Feature: PrintExt
145     SvxCSS1SizeType eSizeType;
146 
147     SvxCSS1PageBreak ePageBreakBefore;
148     SvxCSS1PageBreak ePageBreakAfter;
149 // /Feature: PrintExt
150 
151     SvxCSS1PropertyInfo();
152     SvxCSS1PropertyInfo( const SvxCSS1PropertyInfo& rProp );
153     ~SvxCSS1PropertyInfo();
154 
155     void Merge( const SvxCSS1PropertyInfo& rProp );
156 
157     void Clear();
158 
159     SvxCSS1BorderInfo *GetBorderInfo( sal_uInt16 nLine, sal_Bool bCreate=sal_True );
160     void CopyBorderInfo( sal_uInt16 nSrcLine, sal_uInt16 nDstLine, sal_uInt16 nWhat );
161     void CopyBorderInfo( sal_uInt16 nCount, sal_uInt16 nWhat );
162 
163     void SetBoxItem( SfxItemSet& rItemSet, sal_uInt16 nMinBorderDist,
164                      const SvxBoxItem* pDflt=0, sal_Bool bTable = sal_False );
165 
166 };
167 
168 class SvxCSS1MapEntry
169 {
170     String aKey;
171     SfxItemSet aItemSet;
172     SvxCSS1PropertyInfo aPropInfo;
173 
174 public:
175 
SvxCSS1MapEntry(SfxItemPool & rPool,const sal_uInt16 * pWhichMap)176     SvxCSS1MapEntry( SfxItemPool& rPool, const sal_uInt16 *pWhichMap ) :
177         aItemSet( rPool, pWhichMap )
178     {}
179 
180     SvxCSS1MapEntry( const String& rKey, const SfxItemSet& rItemSet,
181                      const SvxCSS1PropertyInfo& rProp );
182 
183 
GetItemSet() const184     const SfxItemSet& GetItemSet() const { return aItemSet; }
GetItemSet()185     SfxItemSet& GetItemSet() { return aItemSet; }
186 
GetPropertyInfo() const187     const SvxCSS1PropertyInfo& GetPropertyInfo() const { return aPropInfo; }
GetPropertyInfo()188     SvxCSS1PropertyInfo& GetPropertyInfo() { return aPropInfo; }
189 
GetKey() const190     const String& GetKey()  const { return aKey; }
191     // TODO: ToUpperAscii -> ???
SetKey(const String & rKey)192     void SetKey( const String& rKey ) { aKey = rKey; aKey.ToUpperAscii(); }
193 
194     friend sal_Bool operator==( const SvxCSS1MapEntry& rE1,
195                             const SvxCSS1MapEntry& rE2 );
196     friend sal_Bool operator<( const SvxCSS1MapEntry& rE1,
197                             const SvxCSS1MapEntry& rE2 );
198 };
199 
200 typedef SvxCSS1MapEntry *SvxCSS1MapEntryPtr;
201 SV_DECL_PTRARR_SORT_DEL( SvxCSS1Map, SvxCSS1MapEntryPtr, 5, 5 )
202 
203 
204 #if !defined( ICC ) && !defined( BLC )
operator ==(const SvxCSS1MapEntry & rE1,const SvxCSS1MapEntry & rE2)205 inline sal_Bool operator==( const SvxCSS1MapEntry& rE1, const SvxCSS1MapEntry& rE2 )
206 {
207     return  rE1.aKey==rE2.aKey;
208 }
209 
operator <(const SvxCSS1MapEntry & rE1,const SvxCSS1MapEntry & rE2)210 inline sal_Bool operator<( const SvxCSS1MapEntry& rE1,  const SvxCSS1MapEntry& rE2 )
211 {
212     return  rE1.aKey<rE2.aKey;
213 }
214 #endif
215 
216 // Diese Klasse bereitet den Output des CSS1-Parsers auf,
217 // indem die CSS1-Properties in SvxItem(Set)s umgewandelt werden.
218 // Ausserdem werden die Selektoren samt zugehoeriger Item-Set
219 // gespeichert.
220 // Ein abgeleiteter Parser kann dies fuer einzelne Selektoren unterdruecken,
221 // indem er die Methode StyleParsed ueberlaed.
222 
223 class SvxCSS1Parser : public CSS1Parser
224 {
225     CSS1Selectors aSelectors;   // Liste der "offenen" Selectoren
226 
227     SvxCSS1Map aIds;
228     SvxCSS1Map aClasses;
229     SvxCSS1Map aPages;
230     SvxCSS1Map aTags;
231 
232     String sBaseURL;
233 
234     SfxItemSet *pSheetItemSet;  // der Item-Set fuer Style-Sheets
235     SfxItemSet *pItemSet;       // der aktuelle Item-Set
236     SvxCSS1MapEntry *pSearchEntry;
237 
238     SvxCSS1PropertyInfo *pSheetPropInfo;
239     SvxCSS1PropertyInfo *pPropInfo;
240 
241     sal_uInt16 nMinFixLineSpace;    // Mindest-Abstand fuer festen Zeilenabstand
242 
243     rtl_TextEncoding    eDfltEnc;
244     sal_uInt16          nScriptFlags;
245 
246     sal_Bool bIgnoreFontFamily;
247 
248     void ParseProperty( const String& rProperty,
249                         const CSS1Expression *pExpr );
250 
251     SvUShorts aWhichMap;        // Which-Map des Parser
252 
253     using CSS1Parser::ParseStyleOption;
254 
255 protected:
256 
257     using CSS1Parser::ParseStyleSheet;
258 
259     // Diese Methode wird fuer jeden Selektor mit dem zugehoerigen
260     // Item-Set aufgerufen. Fuer einen Selektor koennen mehrere
261     // Aufrufe erfolgen.
262     // wenn sal_True zuruckgegeben wird, wird der Item-Set bzw. der
263     // Selektor nicht mehr gespeichert!
264     // Der ItemSet darf entsprechend modifiziert werden!
265     // Die Implementierung dieser Methode gibt sal_False zurueck.
266     virtual sal_Bool StyleParsed( const CSS1Selector *pSelector,
267                               SfxItemSet& rItemSet,
268                               SvxCSS1PropertyInfo& rPropInfo );
269 
270     // Diese Methode wird aufgerufen, wenn ein Selektor geparst wurde
271     // Wenn bFirst gesetzt ist, wird der Inhalt von aItemSet in alle
272     // zuletzt angelegten Styles kopiert.
273     // Diese Methode sollte in abgleiteten Parsern nicht mehr
274     // ueberladen werden!
275     virtual sal_Bool SelectorParsed( const CSS1Selector *pSelector,
276                                  sal_Bool bFirst );
277 
278     // Diese Methode wird fuer jede geparste Property aufgerufen
279     // sie fuegt das Item in den ItemSet 'pItemSet' ein
280     // Sie sollte in abgeleiteten Parsern nicht mehr ueberladen werden!
281     virtual sal_Bool DeclarationParsed( const String& rProperty,
282                                     const CSS1Expression *pExpr );
283 
284 public:
285 
286 
287     SvxCSS1Parser( SfxItemPool& rPool,
288                     const String& rBaseURL,
289                    sal_uInt16 nMinFixLineSp,
290                    sal_uInt16 *pWhichIds=0, sal_uInt16 nWhichIds=0 );
291     virtual ~SvxCSS1Parser();
292 
IsIgnoreFontFamily() const293     sal_Bool IsIgnoreFontFamily() const { return bIgnoreFontFamily; }
SetIgnoreFontFamily(sal_Bool bSet)294     void SetIgnoreFontFamily( sal_Bool bSet ) { bIgnoreFontFamily = bSet; }
295 
296     // Parsen eines Style-Sheets. Fuer jeden gefundenen Selektor
297     // wird StyleParsed mit dem entsprechenem Item-Set aufgerufen
298     virtual sal_Bool ParseStyleSheet( const String& rIn );
299 
300     // Parsen einer Style-Option. Hier wird einfach nur der Item-Set
301     // gefuellt.
302     sal_Bool ParseStyleOption( const String& rIn, SfxItemSet& rItemSet,
303                            SvxCSS1PropertyInfo& rPropInfo );
304 
305     // Umwandeln eines Strings in den Wert eines Enums
306     static sal_Bool GetEnum( const CSS1PropertyEnum *pPropTable,
307                          const String& rValue, sal_uInt16 &rEnum );
308 
309     // Pixel in Twips wandeln
310     static void PixelToTwip( long &nWidth, long &nHeight );
311 
312     // Die Breite einer Umrandung einstellen
313     static void SetBorderWidth( SvxBorderLine& aBorderLine, sal_uInt16 nWidth,
314                                 sal_Bool bDouble, sal_Bool bTable=sal_False );
315 
316     // Die Font-Hoehe fuer eine bestimmte Font-Groesse (0-6) ermitteln
317     virtual sal_uInt32 GetFontHeight( sal_uInt16 nSize ) const;
318 
319     virtual const FontList *GetFontList() const;
320 
GetWhichMap() const321     const sal_uInt16 *GetWhichMap() const { return aWhichMap.GetData(); }
322 
323     SvxCSS1MapEntry *GetMapEntry( const String& rKey,
324                                   const SvxCSS1Map& rMap ) const;
325 
326     void InsertMapEntry( const String& rKey, const SfxItemSet& rItemSet,
327                          const SvxCSS1PropertyInfo& rProp, SvxCSS1Map& rMap );
328 
329     void InsertId( const String& rId, const SfxItemSet& rItemSet,
330                    const SvxCSS1PropertyInfo& rProp );
331 
332     inline SvxCSS1MapEntry *GetId( const String& rId ) const;
333 
334     void InsertClass( const String& rClass, const SfxItemSet& rItemSet,
335                       const SvxCSS1PropertyInfo& rProp );
336 
337     inline SvxCSS1MapEntry *GetClass( const String& rClass ) const;
338 
339     inline void InsertPage( const String& rPage, sal_Bool bPseudo,
340                             const SfxItemSet& rItemSet,
341                             const SvxCSS1PropertyInfo& rProp );
342 
343     inline SvxCSS1MapEntry *GetPage( const String& rPage, sal_Bool bPseudo ) const;
344 
GetPage(sal_uInt16 i) const345     inline SvxCSS1MapEntry *GetPage( sal_uInt16 i ) const { return aPages[i]; }
GetPageCount() const346     sal_uInt16 GetPageCount() const { return aPages.Count(); }
347 
348     void InsertTag( const String& rTag, const SfxItemSet& rItemSet,
349                       const SvxCSS1PropertyInfo& rProp );
350 
351     inline SvxCSS1MapEntry *GetTag( const String& rTag ) const;
352 
353     void MergeStyles( const SfxItemSet& rSrcSet,
354                       const SvxCSS1PropertyInfo& rSrcInfo,
355                       SfxItemSet& rTargetSet,
356                       SvxCSS1PropertyInfo& rTargetInfo,
357                       sal_Bool bSmart );
358 
GetMinFixLineSpace() const359     sal_uInt16 GetMinFixLineSpace() const { return nMinFixLineSpace; }
360 
361     virtual void SetDfltEncoding( rtl_TextEncoding eEnc );
GetDfltEncoding() const362     rtl_TextEncoding GetDfltEncoding() const { return eDfltEnc; }
363 
IsSetWesternProps() const364     sal_Bool IsSetWesternProps() const { return (nScriptFlags & CSS1_SCRIPT_WESTERN) != 0; }
IsSetCJKProps() const365     sal_Bool IsSetCJKProps() const { return (nScriptFlags & CSS1_SCRIPT_CJK) != 0; }
IsSetCTLProps() const366     sal_Bool IsSetCTLProps() const { return (nScriptFlags & CSS1_SCRIPT_CTL) != 0; }
367 
GetBaseURL() const368     const String& GetBaseURL() const { return sBaseURL;}
369 
370 };
371 
InsertId(const String & rId,const SfxItemSet & rItemSet,const SvxCSS1PropertyInfo & rProp)372 inline void SvxCSS1Parser::InsertId( const String& rId,
373                                      const SfxItemSet& rItemSet,
374                                      const SvxCSS1PropertyInfo& rProp )
375 {
376     InsertMapEntry( rId, rItemSet, rProp, aIds );
377 }
378 
GetId(const String & rId) const379 inline SvxCSS1MapEntry *SvxCSS1Parser::GetId( const String& rId ) const
380 {
381     return GetMapEntry( rId, aIds );
382 }
383 
InsertClass(const String & rClass,const SfxItemSet & rItemSet,const SvxCSS1PropertyInfo & rProp)384 inline void SvxCSS1Parser::InsertClass( const String& rClass,
385                                         const SfxItemSet& rItemSet,
386                                         const SvxCSS1PropertyInfo& rProp )
387 {
388     InsertMapEntry( rClass, rItemSet, rProp, aClasses );
389 }
390 
GetClass(const String & rClass) const391 inline SvxCSS1MapEntry *SvxCSS1Parser::GetClass( const String& rClass ) const
392 {
393     return GetMapEntry( rClass, aClasses );
394 }
395 
InsertPage(const String & rPage,sal_Bool bPseudo,const SfxItemSet & rItemSet,const SvxCSS1PropertyInfo & rProp)396 inline void SvxCSS1Parser::InsertPage( const String& rPage,
397                                        sal_Bool bPseudo,
398                                        const SfxItemSet& rItemSet,
399                                        const SvxCSS1PropertyInfo& rProp )
400 {
401     String aKey( rPage );
402     if( bPseudo )
403         aKey.Insert( ':', 0 );
404     InsertMapEntry( aKey, rItemSet, rProp, aPages );
405 }
406 
GetPage(const String & rPage,sal_Bool bPseudo) const407 inline SvxCSS1MapEntry *SvxCSS1Parser::GetPage( const String& rPage,
408                                                 sal_Bool bPseudo ) const
409 {
410     String aKey( rPage );
411     if( bPseudo )
412         aKey.Insert( ':', 0 );
413     return GetMapEntry( aKey, aPages );
414 }
415 
InsertTag(const String & rTag,const SfxItemSet & rItemSet,const SvxCSS1PropertyInfo & rProp)416 inline void SvxCSS1Parser::InsertTag( const String& rTag,
417                                         const SfxItemSet& rItemSet,
418                                         const SvxCSS1PropertyInfo& rProp )
419 {
420     InsertMapEntry( rTag, rItemSet, rProp, aTags );
421 }
422 
GetTag(const String & rTag) const423 inline SvxCSS1MapEntry *SvxCSS1Parser::GetTag( const String& rTag ) const
424 {
425     return GetMapEntry( rTag, aTags );
426 }
427 
428 
429 #endif
430 
431 
432