xref: /trunk/main/sw/source/filter/html/swcss1.hxx (revision 1d2dbeb0)
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 
24 #ifndef _SWCSS1_HXX
25 #define _SWCSS1_HXX
26 
27 #include "poolfmt.hxx"
28 
29 #include "svxcss1.hxx"
30 
31 class SwDoc;
32 class SwFmt;
33 class SwCharFmt;
34 class SwTxtFmtColl;
35 class SvxBrushItem;
36 class SwFmtDrop;
37 class SwPageDesc;
38 
39 // Dieser Header seiht zwar harmlos aus, included aber eben doch
40 // ganz unauffaellig das ein oder andere! Andererseits wird diese
41 // Klasse recht selten benoetigt. Deshalb ein eigener Header.
42 
43 
44 class SwCSS1Parser : public SvxCSS1Parser
45 {
46 	SwDoc *pDoc;
47 
48 	sal_uLong aFontHeights[7];
49 
50 	sal_uInt16 nDropCapCnt;
51 
52 	sal_Bool bIsNewDoc : 1;
53 
54 	sal_Bool bBodyBGColorSet : 1;
55 	sal_Bool bBodyBackgroundSet : 1;
56 	sal_Bool bBodyTextSet : 1;
57 	sal_Bool bBodyLinkSet : 1;
58 	sal_Bool bBodyVLinkSet : 1;
59 
60 	sal_Bool bSetFirstPageDesc : 1;
61 	sal_Bool bSetRightPageDesc : 1;
62 
63 	sal_Bool bTableHeaderTxtCollSet : 1;
64 	sal_Bool bTableTxtCollSet : 1;
65 
66 	sal_Bool bLinkCharFmtsSet : 1;
67 
68 	// die Vorlagen fuer DL anlegen
69 	SwTxtFmtColl* GetDefListTxtFmtColl( sal_uInt16 nCollId, sal_uInt16 nDeep );
70 
71 	const SwPageDesc* GetPageDesc( sal_uInt16 nPoolId, sal_Bool bCreate );
72 
73 	void SetTableTxtColl( sal_Bool bHeader );
74 	void SetLinkCharFmts();
75 
76 protected:
77 	virtual sal_Bool StyleParsed( const CSS1Selector *pSelector,
78 							  SfxItemSet& rItemSet,
79 							  SvxCSS1PropertyInfo& rPropInfo );
80 
81 	using CSS1Parser::ParseStyleSheet;
82 
83 public:
84     SwCSS1Parser( SwDoc *pDoc, sal_uInt32 aFHeight[7], const String& rBaseURL, sal_Bool bNewDoc );
85 	virtual ~SwCSS1Parser();
86 
87 	virtual sal_Bool ParseStyleSheet( const String& rIn );
88 
89 	// Die Font-Hoehe fuer eine bestimmte Font-Groesse (0-6) ermitteln
90 	virtual sal_uInt32 GetFontHeight( sal_uInt16 nSize ) const;
91 
92 	// Die aktuelle Font-Liste holen (auch 0 ist erlaubt)
93 	virtual const FontList *GetFontList() const;
94 
95 	// das Zeichen-Format zu einem Token und einer ggf leeren Klasse
96 	// ermitteln
97 	SwCharFmt* GetChrFmt( sal_uInt16 nToken, const String& rClass ) const;
98 
99 	// eine TextFmtColl zu einer Pool-Id ermitteln
100 	SwTxtFmtColl *GetTxtFmtColl( sal_uInt16 nTxtColl, const String& rClass );
101 
102 	// This methods do the same as the one of SwDoc, but change the
103 	// encoding if required.
104 	SwTxtFmtColl *GetTxtCollFromPool( sal_uInt16 nPoolId ) const;
105 	SwCharFmt *GetCharFmtFromPool( sal_uInt16 nPoolId ) const;
106 
107 	// Die linke oder rechte Seiten-Vorlage holen. In Dokumenten mit nur
108 	// einer Vorlage gibt es nur eine rechtee Seite.
109 	// Ansonsten ist die rechte Seite die HTML-Poolvorlage und die linke
110 	// eine Benutzter-Vorlage, die on-demand angelegt wird, wenn
111 	// bCreate gesetzt ist.
112 	SwPageDesc* GetMasterPageDesc();
113 	inline const SwPageDesc* GetFirstPageDesc( sal_Bool bCreate=sal_False );
114 	inline const SwPageDesc* GetRightPageDesc( sal_Bool bCreate=sal_False );
115 	inline const SwPageDesc* GetLeftPageDesc( sal_Bool bCreate=sal_False );
116 
117 	// Attribute an der HTML-Seitenvorlage setzen (gesetzte Attribute
118 	// werden aus dem Item-Set geloescht ). Wird fuer's BODY-Tag
119 	// aufgerufen.
120 	void SetPageDescAttrs( const SvxBrushItem *pBrush,
121 						   SfxItemSet *pItemSet=0 );
122 
123 	void ChgPageDesc( const SwPageDesc *pPageDesc,
124 					  const SwPageDesc& rNewPageDesc );
125 
126 	// Wird fuer @page aufgerufen.
127 	void SetPageDescAttrs( const SwPageDesc *pPageDesc, SfxItemSet& rItemSet,
128 						   const SvxCSS1PropertyInfo& rPropInfo );
129 
130 	// Fuellen eines DropCap-Attributs
131 	void FillDropCap( SwFmtDrop& rDrop,	SfxItemSet& rItemSet,
132 					  const String *pName=0 );
133 
134 	sal_Bool SetFmtBreak( SfxItemSet& rItemSet,
135 					  const SvxCSS1PropertyInfo& rPropInfo );
136 
137 
138 	static void AddClassName( String& rFmtName, const String& rClass );
139 
140 	static inline void AddFirstLetterExt( String& rFmtName );
141 
142 	static sal_Bool MayBePositioned( const SvxCSS1PropertyInfo& rPropInfo,
143 								 sal_Bool bAutoWidth=sal_False );
144 
145 	static sal_uInt16 GetScriptFromClass( String& rClass,
146 									  sal_Bool bSubClassOnly = sal_True );
147 
IsBodyBGColorSet() const148 	sal_Bool IsBodyBGColorSet() const { return bBodyBGColorSet; }
IsBodyBackgroundSet() const149 	sal_Bool IsBodyBackgroundSet() const { return bBodyBackgroundSet; }
IsBodyTextSet() const150 	sal_Bool IsBodyTextSet() const { return bBodyTextSet; }
IsBodyLinkSet() const151 	sal_Bool IsBodyLinkSet() const { return bBodyLinkSet; }
IsBodyVLinkSet() const152 	sal_Bool IsBodyVLinkSet() const { return bBodyVLinkSet; }
153 
IsSetFirstPageDesc() const154 	sal_Bool IsSetFirstPageDesc() const { return bSetFirstPageDesc; }
IsSetRightPageDesc() const155 	sal_Bool IsSetRightPageDesc() const { return bSetRightPageDesc; }
156 
SetBodyBGColorSet()157 	void SetBodyBGColorSet() { bBodyBGColorSet = sal_True; }
SetBodyBackgroundSet()158 	void SetBodyBackgroundSet() { bBodyBackgroundSet = sal_True; }
SetBodyTextSet()159 	void SetBodyTextSet() { bBodyTextSet = sal_True; }
SetBodyLinkSet()160 	void SetBodyLinkSet() { bBodyLinkSet = sal_True; }
SetBodyVLinkSet()161 	void SetBodyVLinkSet() { bBodyVLinkSet = sal_True; }
162 
163 	const SvxBrushItem& GetPageDescBackground() const;
164 
165 	inline void SetTHTagStyles();
166 	inline void SetTDTagStyles();
167 	inline void SetATagStyles();
168 	inline void SetDelayedStyles();
169 
170 	virtual void SetDfltEncoding( rtl_TextEncoding eEnc );
171 };
172 
173 
AddFirstLetterExt(String & rFmtName)174 inline void SwCSS1Parser::AddFirstLetterExt( String& rFmtName )
175 {
176 	rFmtName.AppendAscii( ".FL", 3 );	// first letter
177 }
178 
GetFirstPageDesc(sal_Bool bCreate)179 inline const SwPageDesc* SwCSS1Parser::GetFirstPageDesc( sal_Bool bCreate )
180 {
181 	return GetPageDesc( RES_POOLPAGE_FIRST, bCreate );
182 }
183 
GetRightPageDesc(sal_Bool bCreate)184 inline const SwPageDesc* SwCSS1Parser::GetRightPageDesc( sal_Bool bCreate )
185 {
186 	return GetPageDesc( RES_POOLPAGE_RIGHT, bCreate );
187 }
188 
GetLeftPageDesc(sal_Bool bCreate)189 inline const SwPageDesc* SwCSS1Parser::GetLeftPageDesc( sal_Bool bCreate )
190 {
191 	return GetPageDesc( RES_POOLPAGE_LEFT, bCreate );
192 }
193 
SetTHTagStyles()194 inline void SwCSS1Parser::SetTHTagStyles()
195 {
196 	if( !bTableHeaderTxtCollSet )
197 		SetTableTxtColl( sal_True );
198 }
199 
SetTDTagStyles()200 inline void SwCSS1Parser::SetTDTagStyles()
201 {
202 	if( !bTableTxtCollSet )
203 		SetTableTxtColl( sal_False );
204 }
205 
206 
SetATagStyles()207 inline void SwCSS1Parser::SetATagStyles()
208 {
209 	if( !bLinkCharFmtsSet )
210 		SetLinkCharFmts();
211 }
212 
SetDelayedStyles()213 inline void SwCSS1Parser::SetDelayedStyles()
214 {
215 	SetTHTagStyles();
216 	SetTDTagStyles();
217 	SetATagStyles();
218 }
219 
220 
221 #endif
222 
223 
224