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 12 : 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 12 : s_aTableRowStyles( "row" ),s_aTableColStyles( "col" ),s_pOutlineStyle(NULL)
68 : {
69 12 : }
70 :
71 24 : XFStyleManager::~XFStyleManager()
72 : {
73 12 : Reset();
74 12 : }
75 :
76 12 : void XFStyleManager::Reset()
77 : {
78 12 : if( s_pOutlineStyle )
79 : {
80 0 : delete s_pOutlineStyle;
81 0 : s_pOutlineStyle = NULL;
82 : }
83 :
84 12 : s_aStdTextStyles.Reset();
85 12 : s_aStdParaStyles.Reset();
86 12 : s_aStdStrokeDashStyles.Reset();
87 12 : s_aStdAreaStyles.Reset();
88 12 : s_aStdArrowStyles.Reset();
89 12 : s_aTextStyles.Reset();
90 12 : s_aParaStyles.Reset();
91 12 : s_aListStyles.Reset();
92 12 : s_aSectionStyles.Reset();
93 12 : s_aPageMasters.Reset();
94 12 : s_aMasterpages.Reset();
95 12 : s_aDateStyles.Reset();
96 12 : s_aGraphicsStyles.Reset();
97 12 : s_aConfigManager.Reset();
98 : //must clear all static containers.
99 12 : s_aFontDecls.clear();
100 12 : }
101 :
102 44 : void XFStyleManager::AddFontDecl(XFFontDecl& aFontDecl)
103 : {
104 44 : s_aFontDecls.push_back(aFontDecl);
105 44 : }
106 :
107 1240 : IXFStyle* XFStyleManager::AddStyle(IXFStyle *pStyle)
108 : {
109 : assert(pStyle);
110 1240 : OUString name;
111 1240 : IXFStyle *pStyleRet = NULL;
112 :
113 1240 : if( !pStyle )
114 0 : return NULL;
115 1240 : name = pStyle->GetStyleName();
116 :
117 1240 : if( pStyle->GetStyleFamily() == enumXFStyleText )
118 : {
119 360 : if( !name.isEmpty() )
120 : {
121 0 : pStyleRet = s_aStdTextStyles.AddStyle(pStyle);
122 : }
123 : else
124 360 : pStyleRet = s_aTextStyles.AddStyle(pStyle);
125 : }
126 880 : else if( pStyle->GetStyleFamily() == enumXFStylePara )
127 : {
128 514 : if( !name.isEmpty() )
129 : {
130 136 : pStyleRet = s_aStdParaStyles.AddStyle(pStyle);
131 : }
132 : else
133 378 : pStyleRet = s_aParaStyles.AddStyle(pStyle);
134 : }
135 366 : else if( pStyle->GetStyleFamily() == enumXFStyleDefaultPara )
136 : {
137 8 : pStyleRet = s_aStdParaStyles.AddStyle(pStyle);
138 : }
139 358 : else if( pStyle->GetStyleFamily() == enumXFStyleList )
140 : {
141 28 : pStyleRet = s_aListStyles.AddStyle(pStyle);
142 : }
143 330 : else if( pStyle->GetStyleFamily() == enumXFStyleSection )
144 : {
145 0 : pStyleRet = s_aSectionStyles.AddStyle(pStyle);
146 : }
147 330 : else if( pStyle->GetStyleFamily() == enumXFStylePageMaster )
148 : {
149 16 : pStyleRet = s_aPageMasters.AddStyle(pStyle);
150 : }
151 314 : else if( pStyle->GetStyleFamily() == enumXFStyleMasterPage )
152 : {
153 : //Master page don't need name.
154 16 : pStyleRet = s_aMasterpages.AddStyle(pStyle);
155 : }
156 298 : else if( pStyle->GetStyleFamily() == enumXFStyleDate )
157 : {
158 6 : pStyleRet = s_aDateStyles.AddStyle(pStyle);
159 : }
160 292 : else if( pStyle->GetStyleFamily() == enumXFStyleTime )
161 : {
162 0 : pStyleRet = s_aDateStyles.AddStyle(pStyle);
163 : }
164 292 : else if( pStyle->GetStyleFamily() == enumXFStyleNumber )
165 : {
166 48 : pStyleRet = s_aDateStyles.AddStyle(pStyle);
167 : }
168 244 : else if( pStyle->GetStyleFamily() == enumXFStylePercent )
169 : {
170 0 : pStyleRet = s_aDateStyles.AddStyle(pStyle);
171 : }
172 244 : else if( pStyle->GetStyleFamily() == enumXFStyleCurrency )
173 : {
174 0 : pStyleRet = s_aDateStyles.AddStyle(pStyle);
175 : }
176 244 : else if( pStyle->GetStyleFamily() == enumXFStyleGraphics )
177 : {
178 62 : pStyleRet = s_aGraphicsStyles.AddStyle(pStyle);
179 : }
180 182 : else if( pStyle->GetStyleFamily() == enumXFStyleTable )
181 : {
182 2 : pStyleRet = s_aTableStyles.AddStyle(pStyle);
183 : }
184 180 : else if( pStyle->GetStyleFamily() == enumXFStyleTableCell )
185 : {
186 144 : pStyleRet = s_aTableCellStyles.AddStyle(pStyle);
187 : }
188 36 : else if( pStyle->GetStyleFamily() == enumXFStyleTableRow )
189 : {
190 2 : pStyleRet = s_aTableRowStyles.AddStyle(pStyle);
191 : }
192 34 : else if( pStyle->GetStyleFamily() == enumXFStyleTableCol )
193 : {
194 2 : pStyleRet = s_aTableColStyles.AddStyle(pStyle);
195 : }
196 32 : else if( pStyle->GetStyleFamily() == enumXFStyleOutline )
197 : {
198 0 : if( s_pOutlineStyle )
199 0 : delete s_pOutlineStyle;
200 0 : s_pOutlineStyle = pStyle;
201 : }
202 32 : else if( pStyle->GetStyleFamily() == enumXFStyleStrokeDash )
203 : {
204 0 : pStyleRet = s_aStdStrokeDashStyles.AddStyle(pStyle);
205 : }
206 32 : else if( pStyle->GetStyleFamily() == enumXFStyleArea )
207 : {
208 0 : pStyleRet = s_aStdAreaStyles.AddStyle(pStyle);
209 : }
210 32 : else if( pStyle->GetStyleFamily() == enumXFStyleArrow )
211 : {
212 32 : pStyleRet = s_aStdArrowStyles.AddStyle(pStyle);
213 : }
214 0 : else if (pStyle->GetStyleFamily() == enumXFStyleRuby)
215 : {
216 0 : pStyleRet = s_aRubyStyles.AddStyle(pStyle);
217 : }
218 :
219 1240 : return pStyleRet;
220 : }
221 :
222 16 : IXFStyle* XFStyleManager::FindStyle(const OUString& name)
223 : {
224 16 : IXFStyle *pStyle = (IXFStyle*)FindParaStyle(name);
225 16 : if( pStyle )
226 0 : return pStyle;
227 16 : pStyle = (IXFStyle*)FindTextStyle(name);
228 16 : if( pStyle )
229 0 : return pStyle;
230 16 : pStyle = s_aListStyles.FindStyle(name);
231 16 : if( pStyle )
232 0 : return pStyle;
233 16 : pStyle = s_aSectionStyles.FindStyle(name);
234 16 : if( pStyle )
235 0 : return pStyle;
236 16 : pStyle = s_aPageMasters.FindStyle(name);
237 16 : if( pStyle )
238 0 : return pStyle;
239 16 : pStyle = s_aMasterpages.FindStyle(name);
240 16 : if( pStyle )
241 0 : return pStyle;
242 16 : pStyle = s_aDateStyles.FindStyle(name);
243 16 : if( pStyle )
244 0 : return pStyle;
245 16 : pStyle = s_aGraphicsStyles.FindStyle(name);
246 16 : if( pStyle )
247 0 : return pStyle;
248 16 : pStyle = s_aTableStyles.FindStyle(name);
249 16 : if( pStyle )
250 0 : return pStyle;
251 16 : pStyle = s_aTableCellStyles.FindStyle(name);
252 16 : if( pStyle )
253 0 : return pStyle;
254 16 : pStyle = s_aTableRowStyles.FindStyle(name);
255 16 : if( pStyle )
256 0 : return pStyle;
257 16 : pStyle = s_aTableColStyles.FindStyle(name);
258 16 : if( pStyle )
259 0 : return pStyle;
260 16 : if(s_pOutlineStyle && s_pOutlineStyle->GetStyleName() == name )
261 0 : return s_pOutlineStyle;
262 16 : pStyle = s_aStdStrokeDashStyles.FindStyle(name);
263 16 : if( pStyle )
264 0 : return pStyle;
265 16 : pStyle = s_aStdAreaStyles.FindStyle(name);
266 16 : if( pStyle )
267 0 : return pStyle;
268 16 : pStyle = s_aStdArrowStyles.FindStyle(name);
269 16 : if( pStyle )
270 0 : return pStyle;
271 :
272 16 : return NULL;
273 : }
274 :
275 642 : XFParaStyle* XFStyleManager::FindParaStyle(const OUString& name)
276 : {
277 642 : IXFStyle *pStyle = s_aParaStyles.FindStyle(name);
278 642 : if( pStyle )
279 394 : return (XFParaStyle*)pStyle;
280 : else
281 248 : return (XFParaStyle*)s_aStdParaStyles.FindStyle(name);
282 : }
283 :
284 16 : XFTextStyle* XFStyleManager::FindTextStyle(const OUString& name)
285 : {
286 16 : IXFStyle *pStyle = s_aTextStyles.FindStyle(name);
287 16 : if( pStyle )
288 0 : return (XFTextStyle*)pStyle;
289 : else
290 16 : 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 8 : void XFStyleManager::SetFootnoteConfig(XFFootnoteConfig *pFNConfig)
299 : {
300 8 : s_aConfigManager.SetFootnoteConfig(pFNConfig);
301 8 : }
302 :
303 8 : void XFStyleManager::SetEndnoteConfig(XFEndnoteConfig *pENConfig)
304 : {
305 8 : s_aConfigManager.SetEndnoteConfig(pENConfig);
306 8 : }
307 :
308 6 : void XFStyleManager::ToXml(IXFStream *pStrm)
309 : {
310 6 : std::vector<XFFontDecl>::iterator itDecl;
311 6 : IXFAttrList *pAttrList = pStrm->GetAttrList();
312 :
313 6 : pAttrList->Clear();
314 6 : pStrm->StartElement( "office:font-decls" );
315 :
316 : //font declarations:
317 40 : for( itDecl = s_aFontDecls.begin(); itDecl != s_aFontDecls.end(); ++itDecl )
318 : {
319 34 : XFFontDecl &f = *itDecl;
320 :
321 34 : pAttrList->Clear();
322 34 : pAttrList->AddAttribute( "style:name", f.GetFontName() );
323 34 : pAttrList->AddAttribute( "fo:font-family", f.GetFontFamily() );
324 34 : if( f.GetFontPitchFixed() )
325 0 : pAttrList->AddAttribute( "style:font-pitch", "fixed" );
326 : else
327 34 : pAttrList->AddAttribute( "style:font-pitch", "variable" );
328 34 : pStrm->StartElement( "style:font-decl" );
329 34 : pStrm->EndElement( "style:font-decl" );
330 : }
331 :
332 6 : pStrm->EndElement( "office:font-decls" );
333 :
334 : //office:styles:
335 6 : pAttrList->Clear();
336 6 : pStrm->StartElement( "office:styles" );
337 :
338 6 : s_aStdParaStyles.ToXml(pStrm);
339 6 : s_aStdTextStyles.ToXml(pStrm);
340 6 : s_aStdStrokeDashStyles.ToXml(pStrm);
341 6 : s_aStdAreaStyles.ToXml(pStrm);
342 6 : s_aStdArrowStyles.ToXml(pStrm);
343 : //date,time styles:
344 6 : s_aDateStyles.ToXml(pStrm);
345 6 : s_aConfigManager.ToXml(pStrm);
346 : //for optimist.
347 6 : s_aListStyles.ToXml(pStrm);
348 :
349 6 : if( s_pOutlineStyle )
350 0 : s_pOutlineStyle->ToXml(pStrm);
351 :
352 6 : pStrm->EndElement( "office:styles" );
353 :
354 : //automatic styles:
355 6 : pAttrList->Clear();
356 6 : pStrm->StartElement( "office:automatic-styles" );
357 :
358 6 : s_aTableStyles.ToXml(pStrm);
359 6 : s_aTableCellStyles.ToXml(pStrm);
360 6 : s_aTableRowStyles.ToXml(pStrm);
361 6 : s_aTableColStyles.ToXml(pStrm);
362 6 : s_aParaStyles.ToXml(pStrm);
363 6 : s_aTextStyles.ToXml(pStrm);
364 6 : s_aSectionStyles.ToXml(pStrm);
365 6 : s_aPageMasters.ToXml(pStrm);
366 6 : s_aRubyStyles.ToXml(pStrm);
367 : //graphics:
368 6 : s_aGraphicsStyles.ToXml(pStrm);
369 :
370 6 : pStrm->EndElement( "office:automatic-styles" );
371 :
372 : //master:styles
373 6 : pAttrList->Clear();
374 6 : pStrm->StartElement( "office:master-styles" );
375 : //masters pages:
376 6 : s_aMasterpages.ToXml(pStrm);
377 :
378 6 : pStrm->EndElement( "office:master-styles" );
379 6 : }
380 :
381 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|