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