LibreOffice Module lotuswordpro (master) 1
xfstylemanager.cxx
Go to the documentation of this file.
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
61#include <sal/config.h>
62
66#include <xfilter/ixfstyle.hxx>
67
68XFStyleManager::XFStyleManager() : s_aStdArrowStyles( "arrow" ), s_aTextStyles( "T" ),
69 s_aParaStyles( "P" ),s_aListStyles( "L" ),s_aSectionStyles( "Sect" ),
70 s_aPageMasters( "PM" ),s_aMasterpages( "MP" ),s_aDateStyles( "N" ),
71 s_aGraphicsStyles( "fr" ),s_aTableStyles( "table" ),s_aTableCellStyles( "cell" ),
72 s_aTableRowStyles( "row" ),s_aTableColStyles( "col" )
73{
74}
75
77{
78 Reset();
79}
80
82{
83 s_pOutlineStyle.reset();
84
99 //must clear all static containers.
100 s_aFontDecls.clear();
101}
102
104{
105 s_aFontDecls.push_back(aFontDecl);
106}
107
108IXFStyleRet XFStyleManager::AddStyle(std::unique_ptr<IXFStyle> pStyle)
109{
110 IXFStyleRet aRet;
111
112 assert(pStyle);
113 OUString name = pStyle->GetStyleName();
114
115 if( pStyle->GetStyleFamily() == enumXFStyleText )
116 {
117 if( !name.isEmpty() )
118 {
119 aRet = s_aStdTextStyles.AddStyle(std::move(pStyle));
120 }
121 else
122 {
123 aRet = s_aTextStyles.AddStyle(std::move(pStyle));
124 }
125 }
126 else if( pStyle->GetStyleFamily() == enumXFStylePara )
127 {
128 if( !name.isEmpty() )
129 {
130 aRet = s_aStdParaStyles.AddStyle(std::move(pStyle));
131 }
132 else
133 {
134 aRet = s_aParaStyles.AddStyle(std::move(pStyle));
135 }
136 }
137 else if( pStyle->GetStyleFamily() == enumXFStyleDefaultPara )
138 {
139 aRet = s_aStdParaStyles.AddStyle(std::move(pStyle));
140 }
141 else if( pStyle->GetStyleFamily() == enumXFStyleList )
142 {
143 aRet = s_aListStyles.AddStyle(std::move(pStyle));
144 }
145 else if( pStyle->GetStyleFamily() == enumXFStyleSection )
146 {
147 aRet = s_aSectionStyles.AddStyle(std::move(pStyle));
148 }
149 else if( pStyle->GetStyleFamily() == enumXFStylePageMaster )
150 {
151 aRet = s_aPageMasters.AddStyle(std::move(pStyle));
152 }
153 else if( pStyle->GetStyleFamily() == enumXFStyleMasterPage )
154 {
155 //Master page don't need name.
156 aRet = s_aMasterpages.AddStyle(std::move(pStyle));
157 }
158 else if( pStyle->GetStyleFamily() == enumXFStyleDate )
159 {
160 aRet = s_aDateStyles.AddStyle(std::move(pStyle));
161 }
162 else if( pStyle->GetStyleFamily() == enumXFStyleTime )
163 {
164 aRet = s_aDateStyles.AddStyle(std::move(pStyle));
165 }
166 else if( pStyle->GetStyleFamily() == enumXFStyleNumber )
167 {
168 aRet = s_aDateStyles.AddStyle(std::move(pStyle));
169 }
170 else if( pStyle->GetStyleFamily() == enumXFStylePercent )
171 {
172 aRet = s_aDateStyles.AddStyle(std::move(pStyle));
173 }
174 else if( pStyle->GetStyleFamily() == enumXFStyleCurrency )
175 {
176 aRet = s_aDateStyles.AddStyle(std::move(pStyle));
177 }
178 else if( pStyle->GetStyleFamily() == enumXFStyleGraphics )
179 {
180 aRet = s_aGraphicsStyles.AddStyle(std::move(pStyle));
181 }
182 else if( pStyle->GetStyleFamily() == enumXFStyleTable )
183 {
184 aRet = s_aTableStyles.AddStyle(std::move(pStyle));
185 }
186 else if( pStyle->GetStyleFamily() == enumXFStyleTableCell )
187 {
188 aRet = s_aTableCellStyles.AddStyle(std::move(pStyle));
189 }
190 else if( pStyle->GetStyleFamily() == enumXFStyleTableRow )
191 {
192 aRet = s_aTableRowStyles.AddStyle(std::move(pStyle));
193 }
194 else if( pStyle->GetStyleFamily() == enumXFStyleTableCol )
195 {
196 aRet = s_aTableColStyles.AddStyle(std::move(pStyle));
197 }
198 else if( pStyle->GetStyleFamily() == enumXFStyleOutline )
199 {
200 s_pOutlineStyle = std::move(pStyle);
201 }
202 else if( pStyle->GetStyleFamily() == enumXFStyleStrokeDash )
203 {
204 aRet = s_aStdStrokeDashStyles.AddStyle(std::move(pStyle));
205 }
206 else if( pStyle->GetStyleFamily() == enumXFStyleArea )
207 {
208 aRet = s_aStdAreaStyles.AddStyle(std::move(pStyle));
209 }
210 else if( pStyle->GetStyleFamily() == enumXFStyleArrow )
211 {
212 aRet = s_aStdArrowStyles.AddStyle(std::move(pStyle));
213 }
214 else if (pStyle->GetStyleFamily() == enumXFStyleRuby)
215 {
216 aRet = s_aRubyStyles.AddStyle(std::move(pStyle));
217 }
218
219 return aRet;
220}
221
222IXFStyle* XFStyleManager::FindStyle(std::u16string_view name)
223{
224 IXFStyle *pStyle = FindParaStyle(name);
225 if( pStyle )
226 return pStyle;
227 pStyle = FindTextStyle(name);
228 if( pStyle )
229 return pStyle;
230 pStyle = s_aListStyles.FindStyle(name);
231 if( pStyle )
232 return pStyle;
234 if( pStyle )
235 return pStyle;
236 pStyle = s_aPageMasters.FindStyle(name);
237 if( pStyle )
238 return pStyle;
239 pStyle = s_aMasterpages.FindStyle(name);
240 if( pStyle )
241 return pStyle;
242 pStyle = s_aDateStyles.FindStyle(name);
243 if( pStyle )
244 return pStyle;
246 if( pStyle )
247 return pStyle;
248 pStyle = s_aTableStyles.FindStyle(name);
249 if( pStyle )
250 return pStyle;
252 if( pStyle )
253 return pStyle;
255 if( pStyle )
256 return pStyle;
258 if( pStyle )
259 return pStyle;
260 if(s_pOutlineStyle && s_pOutlineStyle->GetStyleName() == name )
261 return s_pOutlineStyle.get();
263 if( pStyle )
264 return pStyle;
266 if( pStyle )
267 return pStyle;
269 if( pStyle )
270 return pStyle;
271
272 return nullptr;
273}
274
276{
278 if( pStyle )
279 return static_cast<XFParaStyle*>(pStyle);
280 else
281 return static_cast<XFParaStyle*>(s_aStdParaStyles.FindStyle(name));
282}
283
285{
287 if( pStyle )
288 return static_cast<XFTextStyle*>(pStyle);
289 else
290 return static_cast<XFTextStyle*>(s_aStdTextStyles.FindStyle(name));
291}
292
294{
296}
297
299{
301}
302
304{
306}
307
309{
310 IXFAttrList *pAttrList = pStrm->GetAttrList();
311
312 pAttrList->Clear();
313 pStrm->StartElement( "office:font-decls" );
314
315 //font declarations:
316 for (const auto & fontDecl : s_aFontDecls)
317 {
318 pAttrList->Clear();
319 pAttrList->AddAttribute( "style:name", fontDecl.GetFontName() );
320 pAttrList->AddAttribute( "fo:font-family", fontDecl.GetFontFamily() );
321 pAttrList->AddAttribute( "style:font-pitch", "variable" );
322 pStrm->StartElement( "style:font-decl" );
323 pStrm->EndElement( "style:font-decl" );
324 }
325
326 pStrm->EndElement( "office:font-decls" );
327
328 //office:styles:
329 pAttrList->Clear();
330 pStrm->StartElement( "office:styles" );
331
332 s_aStdParaStyles.ToXml(pStrm);
333 s_aStdTextStyles.ToXml(pStrm);
335 s_aStdAreaStyles.ToXml(pStrm);
337 //date,time styles:
338 s_aDateStyles.ToXml(pStrm);
339 s_aConfigManager.ToXml(pStrm);
340 //for optimist.
341 s_aListStyles.ToXml(pStrm);
342
343 if( s_pOutlineStyle )
344 s_pOutlineStyle->ToXml(pStrm);
345
346 pStrm->EndElement( "office:styles" );
347
348 //automatic styles:
349 pAttrList->Clear();
350 pStrm->StartElement( "office:automatic-styles" );
351
352 s_aTableStyles.ToXml(pStrm);
356 s_aParaStyles.ToXml(pStrm);
357 s_aTextStyles.ToXml(pStrm);
358 s_aSectionStyles.ToXml(pStrm);
359 s_aPageMasters.ToXml(pStrm);
360 s_aRubyStyles.ToXml(pStrm);
361 //graphics:
363
364 pStrm->EndElement( "office:automatic-styles" );
365
366 //master:styles
367 pAttrList->Clear();
368 pStrm->StartElement( "office:master-styles" );
369 //masters pages:
370 s_aMasterpages.ToXml(pStrm);
371
372 pStrm->EndElement( "office:master-styles" );
373}
374
375/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Attribute list interface for sax writer.
Definition: ixfattrlist.hxx:72
virtual void Clear()=0
@descr: Clear all the attributes in the attribute list.
virtual void AddAttribute(const OUString &name, const OUString &value)=0
@descr: Add an attribute to the attribute list.
Stream wrapper for sax writer.
Definition: ixfstream.hxx:72
virtual IXFAttrList * GetAttrList()=0
@descr return the Attribute list interface.
virtual void StartElement(const OUString &oustr)=0
@descr Wrap XDocumentHandler::startElement()
virtual void EndElement(const OUString &oustr)=0
@descr Wrap XDocumentHandler::endElement()
@descr Interface for all style object.
Definition: ixfstyle.hxx:71
void SetEndnoteConfig(XFEndnoteConfig *pFNConfig)
@descr Set endnote config.
void SetFootnoteConfig(XFFootnoteConfig *pFNConfig)
@descr Set footnote config.
virtual void ToXml(IXFStream *pStrm) override
@descr Output config information.
void SetLineNumberConfig(XFLineNumberConfig *pLNConfig)
@descr Set line number config.
Font declaration in OOo xml file.
Definition: xffontdecl.hxx:72
Style object for aragraph.
Definition: xfparastyle.hxx:93
IXFStyleRet AddStyle(std::unique_ptr< IXFStyle > pStyle)
@descr Add style to container.
Definition: xfstylecont.cxx:83
void Reset()
@descr clear container.
Definition: xfstylecont.cxx:78
virtual void ToXml(IXFStream *pStrm)
@descr Output all style.
IXFStyle * FindStyle(std::u16string_view name)
@descr get style by name.
XFStyleContainer s_aTableCellStyles
XFStyleContainer s_aDateStyles
XFStyleContainer s_aSectionStyles
void Reset()
@descr clear all styles, called before load file.
void SetFootnoteConfig(XFFootnoteConfig *pFNConfig)
void ToXml(IXFStream *strm)
XFStyleContainer s_aGraphicsStyles
XFStyleContainer s_aTableStyles
XFStyleContainer s_aMasterpages
XFStyleContainer s_aPageMasters
XFConfigManager s_aConfigManager
void SetLineNumberConfig(XFLineNumberConfig *pLNConfig)
XFStyleContainer s_aTextStyles
XFStyleContainer s_aStdTextStyles
XFStyleContainer s_aParaStyles
IXFStyle * FindStyle(std::u16string_view name)
IXFStyleRet AddStyle(std::unique_ptr< IXFStyle > pStyle)
XFStyleContainer s_aRubyStyles
std::vector< XFFontDecl > s_aFontDecls
XFParaStyle * FindParaStyle(std::u16string_view name)
XFStyleContainer s_aListStyles
XFStyleContainer s_aTableRowStyles
XFStyleContainer s_aTableColStyles
void AddFontDecl(XFFontDecl const &aFontDecl)
XFStyleContainer s_aStdArrowStyles
XFStyleContainer s_aStdAreaStyles
XFStyleContainer s_aStdParaStyles
XFTextStyle * FindTextStyle(std::u16string_view name)
std::unique_ptr< IXFStyle > s_pOutlineStyle
XFStyleContainer s_aStdStrokeDashStyles
void SetEndnoteConfig(XFEndnoteConfig *pFNConfig)
const char * name
@ enumXFStyleArrow
Definition: xfdefs.hxx:101
@ enumXFStyleDefaultPara
Definition: xfdefs.hxx:103
@ enumXFStyleText
Definition: xfdefs.hxx:82
@ enumXFStylePara
Definition: xfdefs.hxx:83
@ enumXFStyleArea
Definition: xfdefs.hxx:100
@ enumXFStyleMasterPage
Definition: xfdefs.hxx:88
@ enumXFStyleTableCol
Definition: xfdefs.hxx:97
@ enumXFStylePageMaster
Definition: xfdefs.hxx:87
@ enumXFStyleTableCell
Definition: xfdefs.hxx:95
@ enumXFStyleRuby
Definition: xfdefs.hxx:102
@ enumXFStyleGraphics
Definition: xfdefs.hxx:86
@ enumXFStyleTime
Definition: xfdefs.hxx:90
@ enumXFStyleStrokeDash
Definition: xfdefs.hxx:99
@ enumXFStyleTable
Definition: xfdefs.hxx:94
@ enumXFStylePercent
Definition: xfdefs.hxx:91
@ enumXFStyleNumber
Definition: xfdefs.hxx:92
@ enumXFStyleOutline
Definition: xfdefs.hxx:98
@ enumXFStyleSection
Definition: xfdefs.hxx:85
@ enumXFStyleDate
Definition: xfdefs.hxx:89
@ enumXFStyleCurrency
Definition: xfdefs.hxx:93
@ enumXFStyleTableRow
Definition: xfdefs.hxx:96
@ enumXFStyleList
Definition: xfdefs.hxx:84