Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * The Contents of this file are made available subject to the terms of
5 : * either of the following licenses
6 : *
7 : * - GNU Lesser General Public License Version 2.1
8 : * - Sun Industry Standards Source License Version 1.1
9 : *
10 : * Sun Microsystems Inc., October, 2000
11 : *
12 : * GNU Lesser General Public License Version 2.1
13 : * =============================================
14 : * Copyright 2000 by Sun Microsystems, Inc.
15 : * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 : *
17 : * This library is free software; you can redistribute it and/or
18 : * modify it under the terms of the GNU Lesser General Public
19 : * License version 2.1, as published by the Free Software Foundation.
20 : *
21 : * This library is distributed in the hope that it will be useful,
22 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 : * Lesser General Public License for more details.
25 : *
26 : * You should have received a copy of the GNU Lesser General Public
27 : * License along with this library; if not, write to the Free Software
28 : * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 : * MA 02111-1307 USA
30 : *
31 : *
32 : * Sun Industry Standards Source License Version 1.1
33 : * =================================================
34 : * The contents of this file are subject to the Sun Industry Standards
35 : * Source License Version 1.1 (the "License"); You may not use this file
36 : * except in compliance with the License. You may obtain a copy of the
37 : * License at http://www.openoffice.org/license.html.
38 : *
39 : * Software provided under this License is provided on an "AS IS" basis,
40 : * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 : * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 : * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 : * See the License for the specific provisions governing your rights and
44 : * obligations concerning the Software.
45 : *
46 : * The Initial Developer of the Original Code is: IBM Corporation
47 : *
48 : * Copyright: 2008 by IBM Corporation
49 : *
50 : * All Rights Reserved.
51 : *
52 : * Contributor(s): _______________________________________
53 : *
54 : *
55 : ************************************************************************/
56 : /*************************************************************************
57 : * @file
58 : * Style manager for the filter.
59 : ************************************************************************/
60 : #include "xfstylemanager.hxx"
61 : #include "ixfstyle.hxx"
62 :
63 6 : XFStyleManager::XFStyleManager() : s_aStdArrowStyles( "arrow" ), s_aTextStyles( "T" ),
64 : s_aParaStyles( "P" ),s_aListStyles( "L" ),s_aSectionStyles( "Sect" ),
65 : s_aPageMasters( "PM" ),s_aMasterpages( "MP" ),s_aDateStyles( "N" ),
66 : s_aGraphicsStyles( "fr" ),s_aTableStyles( "table" ),s_aTableCellStyles( "cell" ),
67 6 : s_aTableRowStyles( "row" ),s_aTableColStyles( "col" ),s_pOutlineStyle(NULL)
68 : {
69 6 : }
70 :
71 12 : XFStyleManager::~XFStyleManager()
72 : {
73 6 : Reset();
74 6 : }
75 :
76 6 : void XFStyleManager::Reset()
77 : {
78 6 : if( s_pOutlineStyle )
79 : {
80 0 : delete s_pOutlineStyle;
81 0 : s_pOutlineStyle = NULL;
82 : }
83 :
84 6 : s_aStdTextStyles.Reset();
85 6 : s_aStdParaStyles.Reset();
86 6 : s_aStdStrokeDashStyles.Reset();
87 6 : s_aStdAreaStyles.Reset();
88 6 : s_aStdArrowStyles.Reset();
89 6 : s_aTextStyles.Reset();
90 6 : s_aParaStyles.Reset();
91 6 : s_aListStyles.Reset();
92 6 : s_aSectionStyles.Reset();
93 6 : s_aPageMasters.Reset();
94 6 : s_aMasterpages.Reset();
95 6 : s_aDateStyles.Reset();
96 6 : s_aGraphicsStyles.Reset();
97 6 : s_aConfigManager.Reset();
98 : //must clear all static containers.
99 6 : s_aFontDecls.clear();
100 6 : }
101 :
102 22 : void XFStyleManager::AddFontDecl(XFFontDecl& aFontDecl)
103 : {
104 22 : s_aFontDecls.push_back(aFontDecl);
105 22 : }
106 :
107 634 : IXFStyle* XFStyleManager::AddStyle(IXFStyle *pStyle)
108 : {
109 : assert(pStyle);
110 634 : OUString name;
111 634 : IXFStyle *pStyleRet = NULL;
112 :
113 634 : if( !pStyle )
114 0 : return NULL;
115 634 : name = pStyle->GetStyleName();
116 :
117 634 : if( pStyle->GetStyleFamily() == enumXFStyleText )
118 : {
119 180 : if( !name.isEmpty() )
120 : {
121 0 : pStyleRet = s_aStdTextStyles.AddStyle(pStyle);
122 : }
123 : else
124 180 : pStyleRet = s_aTextStyles.AddStyle(pStyle);
125 : }
126 454 : else if( pStyle->GetStyleFamily() == enumXFStylePara )
127 : {
128 260 : if( !name.isEmpty() )
129 : {
130 68 : pStyleRet = s_aStdParaStyles.AddStyle(pStyle);
131 : }
132 : else
133 192 : pStyleRet = s_aParaStyles.AddStyle(pStyle);
134 : }
135 194 : else if( pStyle->GetStyleFamily() == enumXFStyleDefaultPara )
136 : {
137 4 : pStyleRet = s_aStdParaStyles.AddStyle(pStyle);
138 : }
139 190 : else if( pStyle->GetStyleFamily() == enumXFStyleList )
140 : {
141 14 : pStyleRet = s_aListStyles.AddStyle(pStyle);
142 : }
143 176 : else if( pStyle->GetStyleFamily() == enumXFStyleSection )
144 : {
145 0 : pStyleRet = s_aSectionStyles.AddStyle(pStyle);
146 : }
147 176 : else if( pStyle->GetStyleFamily() == enumXFStylePageMaster )
148 : {
149 8 : pStyleRet = s_aPageMasters.AddStyle(pStyle);
150 : }
151 168 : else if( pStyle->GetStyleFamily() == enumXFStyleMasterPage )
152 : {
153 : //Master page don't need name.
154 8 : pStyleRet = s_aMasterpages.AddStyle(pStyle);
155 : }
156 160 : else if( pStyle->GetStyleFamily() == enumXFStyleDate )
157 : {
158 3 : pStyleRet = s_aDateStyles.AddStyle(pStyle);
159 : }
160 157 : else if( pStyle->GetStyleFamily() == enumXFStyleTime )
161 : {
162 0 : pStyleRet = s_aDateStyles.AddStyle(pStyle);
163 : }
164 157 : else if( pStyle->GetStyleFamily() == enumXFStyleNumber )
165 : {
166 27 : pStyleRet = s_aDateStyles.AddStyle(pStyle);
167 : }
168 130 : else if( pStyle->GetStyleFamily() == enumXFStylePercent )
169 : {
170 0 : pStyleRet = s_aDateStyles.AddStyle(pStyle);
171 : }
172 130 : else if( pStyle->GetStyleFamily() == enumXFStyleCurrency )
173 : {
174 0 : pStyleRet = s_aDateStyles.AddStyle(pStyle);
175 : }
176 130 : else if( pStyle->GetStyleFamily() == enumXFStyleGraphics )
177 : {
178 31 : pStyleRet = s_aGraphicsStyles.AddStyle(pStyle);
179 : }
180 99 : else if( pStyle->GetStyleFamily() == enumXFStyleTable )
181 : {
182 1 : pStyleRet = s_aTableStyles.AddStyle(pStyle);
183 : }
184 98 : else if( pStyle->GetStyleFamily() == enumXFStyleTableCell )
185 : {
186 75 : pStyleRet = s_aTableCellStyles.AddStyle(pStyle);
187 : }
188 23 : else if( pStyle->GetStyleFamily() == enumXFStyleTableRow )
189 : {
190 6 : pStyleRet = s_aTableRowStyles.AddStyle(pStyle);
191 : }
192 17 : else if( pStyle->GetStyleFamily() == enumXFStyleTableCol )
193 : {
194 1 : pStyleRet = s_aTableColStyles.AddStyle(pStyle);
195 : }
196 16 : else if( pStyle->GetStyleFamily() == enumXFStyleOutline )
197 : {
198 0 : if( s_pOutlineStyle )
199 0 : delete s_pOutlineStyle;
200 0 : s_pOutlineStyle = pStyle;
201 : }
202 16 : else if( pStyle->GetStyleFamily() == enumXFStyleStrokeDash )
203 : {
204 0 : pStyleRet = s_aStdStrokeDashStyles.AddStyle(pStyle);
205 : }
206 16 : else if( pStyle->GetStyleFamily() == enumXFStyleArea )
207 : {
208 0 : pStyleRet = s_aStdAreaStyles.AddStyle(pStyle);
209 : }
210 16 : else if( pStyle->GetStyleFamily() == enumXFStyleArrow )
211 : {
212 16 : pStyleRet = s_aStdArrowStyles.AddStyle(pStyle);
213 : }
214 0 : else if (pStyle->GetStyleFamily() == enumXFStyleRuby)
215 : {
216 0 : pStyleRet = s_aRubyStyles.AddStyle(pStyle);
217 : }
218 :
219 634 : return pStyleRet;
220 : }
221 :
222 8 : IXFStyle* XFStyleManager::FindStyle(const OUString& name)
223 : {
224 8 : IXFStyle *pStyle = (IXFStyle*)FindParaStyle(name);
225 8 : if( pStyle )
226 0 : return pStyle;
227 8 : pStyle = (IXFStyle*)FindTextStyle(name);
228 8 : if( pStyle )
229 0 : return pStyle;
230 8 : pStyle = s_aListStyles.FindStyle(name);
231 8 : if( pStyle )
232 0 : return pStyle;
233 8 : pStyle = s_aSectionStyles.FindStyle(name);
234 8 : if( pStyle )
235 0 : return pStyle;
236 8 : pStyle = s_aPageMasters.FindStyle(name);
237 8 : if( pStyle )
238 0 : return pStyle;
239 8 : pStyle = s_aMasterpages.FindStyle(name);
240 8 : if( pStyle )
241 0 : return pStyle;
242 8 : pStyle = s_aDateStyles.FindStyle(name);
243 8 : if( pStyle )
244 0 : return pStyle;
245 8 : pStyle = s_aGraphicsStyles.FindStyle(name);
246 8 : if( pStyle )
247 0 : return pStyle;
248 8 : pStyle = s_aTableStyles.FindStyle(name);
249 8 : if( pStyle )
250 0 : return pStyle;
251 8 : pStyle = s_aTableCellStyles.FindStyle(name);
252 8 : if( pStyle )
253 0 : return pStyle;
254 8 : pStyle = s_aTableRowStyles.FindStyle(name);
255 8 : if( pStyle )
256 0 : return pStyle;
257 8 : pStyle = s_aTableColStyles.FindStyle(name);
258 8 : if( pStyle )
259 0 : return pStyle;
260 8 : if(s_pOutlineStyle && s_pOutlineStyle->GetStyleName() == name )
261 0 : return s_pOutlineStyle;
262 8 : pStyle = s_aStdStrokeDashStyles.FindStyle(name);
263 8 : if( pStyle )
264 0 : return pStyle;
265 8 : pStyle = s_aStdAreaStyles.FindStyle(name);
266 8 : if( pStyle )
267 0 : return pStyle;
268 8 : pStyle = s_aStdArrowStyles.FindStyle(name);
269 8 : if( pStyle )
270 0 : return pStyle;
271 :
272 8 : return NULL;
273 : }
274 :
275 327 : XFParaStyle* XFStyleManager::FindParaStyle(const OUString& name)
276 : {
277 327 : IXFStyle *pStyle = s_aParaStyles.FindStyle(name);
278 327 : if( pStyle )
279 200 : return (XFParaStyle*)pStyle;
280 : else
281 127 : return (XFParaStyle*)s_aStdParaStyles.FindStyle(name);
282 : }
283 :
284 8 : XFTextStyle* XFStyleManager::FindTextStyle(const OUString& name)
285 : {
286 8 : IXFStyle *pStyle = s_aTextStyles.FindStyle(name);
287 8 : if( pStyle )
288 0 : return (XFTextStyle*)pStyle;
289 : else
290 8 : return (XFTextStyle*)s_aStdTextStyles.FindStyle(name);
291 : }
292 :
293 0 : void XFStyleManager::SetLineNumberConfig(XFLineNumberConfig *pLNConf)
294 : {
295 0 : s_aConfigManager.SetLineNumberConfig(pLNConf);
296 0 : }
297 :
298 4 : void XFStyleManager::SetFootnoteConfig(XFFootnoteConfig *pFNConfig)
299 : {
300 4 : s_aConfigManager.SetFootnoteConfig(pFNConfig);
301 4 : }
302 :
303 4 : void XFStyleManager::SetEndnoteConfig(XFEndnoteConfig *pENConfig)
304 : {
305 4 : s_aConfigManager.SetEndnoteConfig(pENConfig);
306 4 : }
307 :
308 3 : void XFStyleManager::ToXml(IXFStream *pStrm)
309 : {
310 3 : std::vector<XFFontDecl>::iterator itDecl;
311 3 : IXFAttrList *pAttrList = pStrm->GetAttrList();
312 :
313 3 : pAttrList->Clear();
314 3 : pStrm->StartElement( "office:font-decls" );
315 :
316 : //font declarations:
317 20 : for( itDecl = s_aFontDecls.begin(); itDecl != s_aFontDecls.end(); ++itDecl )
318 : {
319 17 : XFFontDecl &f = *itDecl;
320 :
321 17 : pAttrList->Clear();
322 17 : pAttrList->AddAttribute( "style:name", f.GetFontName() );
323 17 : pAttrList->AddAttribute( "fo:font-family", f.GetFontFamily() );
324 17 : if( f.GetFontPitchFixed() )
325 0 : pAttrList->AddAttribute( "style:font-pitch", "fixed" );
326 : else
327 17 : pAttrList->AddAttribute( "style:font-pitch", "variable" );
328 17 : pStrm->StartElement( "style:font-decl" );
329 17 : pStrm->EndElement( "style:font-decl" );
330 : }
331 :
332 3 : pStrm->EndElement( "office:font-decls" );
333 :
334 : //office:styles:
335 3 : pAttrList->Clear();
336 3 : pStrm->StartElement( "office:styles" );
337 :
338 3 : s_aStdParaStyles.ToXml(pStrm);
339 3 : s_aStdTextStyles.ToXml(pStrm);
340 3 : s_aStdStrokeDashStyles.ToXml(pStrm);
341 3 : s_aStdAreaStyles.ToXml(pStrm);
342 3 : s_aStdArrowStyles.ToXml(pStrm);
343 : //date,time styles:
344 3 : s_aDateStyles.ToXml(pStrm);
345 3 : s_aConfigManager.ToXml(pStrm);
346 : //for optimist.
347 3 : s_aListStyles.ToXml(pStrm);
348 :
349 3 : if( s_pOutlineStyle )
350 0 : s_pOutlineStyle->ToXml(pStrm);
351 :
352 3 : pStrm->EndElement( "office:styles" );
353 :
354 : //automatic styles:
355 3 : pAttrList->Clear();
356 3 : pStrm->StartElement( "office:automatic-styles" );
357 :
358 3 : s_aTableStyles.ToXml(pStrm);
359 3 : s_aTableCellStyles.ToXml(pStrm);
360 3 : s_aTableRowStyles.ToXml(pStrm);
361 3 : s_aTableColStyles.ToXml(pStrm);
362 3 : s_aParaStyles.ToXml(pStrm);
363 3 : s_aTextStyles.ToXml(pStrm);
364 3 : s_aSectionStyles.ToXml(pStrm);
365 3 : s_aPageMasters.ToXml(pStrm);
366 3 : s_aRubyStyles.ToXml(pStrm);
367 : //graphics:
368 3 : s_aGraphicsStyles.ToXml(pStrm);
369 :
370 3 : pStrm->EndElement( "office:automatic-styles" );
371 :
372 : //master:styles
373 3 : pAttrList->Clear();
374 3 : pStrm->StartElement( "office:master-styles" );
375 : //masters pages:
376 3 : s_aMasterpages.ToXml(pStrm);
377 :
378 3 : pStrm->EndElement( "office:master-styles" );
379 3 : }
380 :
381 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|