LibreOffice Module sc (master) 1
stylesfragment.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <stylesfragment.hxx>
21#include <biffhelper.hxx>
22
24#include <oox/token/namespaces.hxx>
25#include <oox/token/tokens.hxx>
26
27namespace oox::xls {
28
29using namespace ::oox::core;
30
32 WorkbookContextBase( rFragment )
33{
34}
35
37{
38 switch( getCurrentElement() )
39 {
40 case XLS_TOKEN( indexedColors ):
41 if( nElement == XLS_TOKEN( rgbColor ) ) getStyles().importPaletteColor( rAttribs );
42 break;
43 }
44 return nullptr;
45}
46
48{
49 switch( getCurrentElement() )
50 {
53 break;
54 }
55 return nullptr;
56}
57
58ContextHandlerRef FontContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
59{
60 if( mxFont )
61 mxFont->importAttribs( nElement, rAttribs );
62 return nullptr;
63}
64
66{
67 if( mxBorder && (getCurrentElement() == XLS_TOKEN( border )) )
68 mxBorder->importBorder( rAttribs );
69}
70
72{
73 if( mxBorder ) switch( getCurrentElement() )
74 {
75 case XLS_TOKEN( border ):
76 mxBorder->importStyle( nElement, rAttribs );
77 return this;
78
79 default:
80 if( nElement == XLS_TOKEN( color ) )
81 mxBorder->importColor( getCurrentElement(), rAttribs );
82 }
83 return nullptr;
84}
85
86ContextHandlerRef FillContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
87{
88 if( mxFill ) switch( getCurrentElement() )
89 {
90 case XLS_TOKEN( fill ):
91 switch( nElement )
92 {
93 case XLS_TOKEN( patternFill ): mxFill->importPatternFill( rAttribs ); return this;
94 case XLS_TOKEN( gradientFill ): mxFill->importGradientFill( rAttribs ); return this;
95 }
96 break;
97 case XLS_TOKEN( patternFill ):
98 switch( nElement )
99 {
100 case XLS_TOKEN( fgColor ): mxFill->importFgColor( rAttribs ); break;
101 case XLS_TOKEN( bgColor ): mxFill->importBgColor( rAttribs ); break;
102 }
103 break;
104 case XLS_TOKEN( gradientFill ):
105 if( nElement == XLS_TOKEN( stop ) )
106 {
107 mfGradPos = rAttribs.getDouble( XML_position, -1.0 );
108 return this;
109 }
110 break;
111 case XLS_TOKEN( stop ):
112 if( nElement == XLS_TOKEN( color ) )
113 mxFill->importColor( rAttribs, mfGradPos );
114 break;
115 }
116 return nullptr;
117}
118
120{
121 if( mxXf && (getCurrentElement() == XLS_TOKEN( xf )) )
122 mxXf->importXf( rAttribs, mbCellXf );
123}
124
125ContextHandlerRef XfContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
126{
127 if( mxXf ) switch( getCurrentElement() )
128 {
129 case XLS_TOKEN( xf ):
130 switch( nElement )
131 {
132 case XLS_TOKEN( alignment ): mxXf->importAlignment( rAttribs ); break;
133 case XLS_TOKEN( protection ): mxXf->importProtection( rAttribs ); break;
134 }
135 break;
136 }
137 return nullptr;
138}
139
140ContextHandlerRef DxfContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
141{
142 if( mxDxf ) switch( getCurrentElement() )
143 {
144 case XLS_TOKEN( dxf ):
145 switch( nElement )
146 {
147 case XLS_TOKEN( font ): return new FontContext( *this, mxDxf->createFont() );
148 case XLS_TOKEN( border ): return new BorderContext( *this, mxDxf->createBorder() );
149 case XLS_TOKEN( fill ): return new FillContext( *this, mxDxf->createFill() );
150
151 case XLS_TOKEN( numFmt ): mxDxf->importNumFmt( rAttribs ); break;
152#if 0
153 case XLS_TOKEN( alignment ): mxDxf->importAlignment( rAttribs ); break;
154 case XLS_TOKEN( protection ): mxDxf->importProtection( rAttribs ); break;
155#endif
156 }
157 break;
158 }
159
160 if( mxExtDxf ) switch( getCurrentElement() )
161 {
162 case XLS14_TOKEN( dxf ):
163 switch( nElement )
164 {
165 case XLS_TOKEN( font ): return new FontContext( *this, mxExtDxf->createFont() );
166 case XLS_TOKEN( border ): return new BorderContext( *this, mxExtDxf->createBorder() );
167 case XLS_TOKEN( fill ): return new FillContext( *this, mxExtDxf->createFill() );
168 case XLS_TOKEN( numFmt ): mxExtDxf->importNumFmt( rAttribs ); break;
169 }
170 break;
171 }
172 return nullptr;
173}
174
175StylesFragment::StylesFragment( const WorkbookHelper& rHelper, const OUString& rFragmentPath ) :
176 WorkbookFragmentBase( rHelper, rFragmentPath )
177{
178}
179
181{
182 switch( getCurrentElement() )
183 {
184 case XML_ROOT_CONTEXT:
185 if( nElement == XLS_TOKEN( styleSheet ) ) return this;
186 break;
187
188 case XLS_TOKEN( styleSheet ):
189 switch( nElement )
190 {
191 case XLS_TOKEN( colors ):
192 case XLS_TOKEN( numFmts ):
193 case XLS_TOKEN( fonts ):
194 case XLS_TOKEN( borders ):
195 case XLS_TOKEN( fills ):
196 case XLS_TOKEN( cellXfs ):
197 case XLS_TOKEN( cellStyleXfs ):
198 case XLS_TOKEN( dxfs ):
199 case XLS_TOKEN( cellStyles ): return this;
200 }
201 break;
202
203 case XLS_TOKEN( colors ):
204 if( nElement == XLS_TOKEN( indexedColors ) ) return new IndexedColorsContext( *this );
205 break;
206 case XLS_TOKEN( numFmts ):
207 if( nElement == XLS_TOKEN( numFmt ) ) getStyles().importNumFmt( rAttribs );
208 break;
209 case XLS_TOKEN( fonts ):
210 if( nElement == XLS_TOKEN( font ) ) return new FontContext( *this, getStyles().createFont() );
211 break;
212 case XLS_TOKEN( borders ):
213 if( nElement == XLS_TOKEN( border ) ) return new BorderContext( *this, getStyles().createBorder() );
214 break;
215 case XLS_TOKEN( fills ):
216 if( nElement == XLS_TOKEN( fill ) ) return new FillContext( *this, getStyles().createFill() );
217 break;
218 case XLS_TOKEN( cellXfs ):
219 if( nElement == XLS_TOKEN( xf ) ) return new XfContext( *this, getStyles().createCellXf(), true );
220 break;
221 case XLS_TOKEN( cellStyleXfs ):
222 if( nElement == XLS_TOKEN( xf ) ) return new XfContext( *this, getStyles().createStyleXf(), false );
223 break;
224 case XLS_TOKEN( dxfs ):
225 if( nElement == XLS_TOKEN( dxf ) ) return new DxfContext( *this, getStyles().createDxf() );
226 break;
227 case XLS_TOKEN( cellStyles ):
228 if( nElement == XLS_TOKEN( cellStyle ) ) getStyles().importCellStyle( rAttribs );
229 break;
230 }
231 return nullptr;
232}
233
235{
236 switch( getCurrentElement() )
237 {
238 case XML_ROOT_CONTEXT:
239 if( nRecId == BIFF12_ID_STYLESHEET ) return this;
240 break;
241
243 switch( nRecId )
244 {
245 case BIFF12_ID_COLORS:
247 case BIFF12_ID_FONTS:
249 case BIFF12_ID_FILLS:
252 case BIFF12_ID_DXFS:
253 case BIFF12_ID_CELLSTYLES: return this;
254 }
255 break;
256
257 case BIFF12_ID_COLORS:
258 if( nRecId == BIFF12_ID_INDEXEDCOLORS ) return new IndexedColorsContext( *this );
259 break;
261 if( nRecId == BIFF12_ID_NUMFMT ) getStyles().importNumFmt( rStrm );
262 break;
263 case BIFF12_ID_FONTS:
264 if( nRecId == BIFF12_ID_FONT ) getStyles().createFont()->importFont( rStrm );
265 break;
267 if( nRecId == BIFF12_ID_BORDER ) getStyles().createBorder()->importBorder( rStrm );
268 break;
269 case BIFF12_ID_FILLS:
270 if( nRecId == BIFF12_ID_FILL ) getStyles().createFill()->importFill( rStrm );
271 break;
273 if( nRecId == BIFF12_ID_XF ) getStyles().createCellXf()->importXf( rStrm, true );
274 break;
276 if( nRecId == BIFF12_ID_XF ) getStyles().createStyleXf()->importXf( rStrm, false );
277 break;
278 case BIFF12_ID_DXFS:
279 if( nRecId == BIFF12_ID_DXF ) getStyles().createDxf()->importDxf( rStrm );
280 break;
283 break;
284 }
285 return nullptr;
286}
287
288const RecordInfo* StylesFragment::getRecordInfos() const
289{
290 static const RecordInfo spRecInfos[] =
291 {
305 { -1, -1 }
306 };
307 return spRecInfos;
308}
309
311{
313}
314
315} // namespace oox::xls
316
317/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::optional< double > getDouble(sal_Int32 nAttrToken) const
sal_Int32 getCurrentElement() const
virtual void onStartElement(const AttributeList &rAttribs) override
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
IndexedColorsContext(WorkbookFragmentBase &rFragment)
virtual ::oox::core::ContextHandlerRef onCreateRecordContext(sal_Int32 nRecId, SequenceInputStream &rStrm) override
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
CellStyleRef importCellStyle(const AttributeList &rAttribs)
Appends and returns a new named cell style object.
FontRef createFont()
Creates a new empty font object.
BorderRef createBorder()
Creates a new empty border object.
XfRef createCellXf()
Creates a new empty cell formatting object.
NumberFormatRef importNumFmt(const AttributeList &rAttribs)
Inserts a new number format code.
FillRef createFill()
Creates a new empty fill object.
XfRef createStyleXf()
Creates a new empty style formatting object.
DxfRef createDxf()
Creates a new empty differential formatting object.
void finalizeImport()
Final processing after import of all style settings.
void importPaletteColor(const AttributeList &rAttribs)
Appends a new color to the color palette.
StylesFragment(const WorkbookHelper &rHelper, const OUString &rFragmentPath)
virtual void finalizeImport() override
virtual const ::oox::core::RecordInfo * getRecordInfos() const override
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
virtual ::oox::core::ContextHandlerRef onCreateRecordContext(sal_Int32 nRecId, SequenceInputStream &rStrm) override
Context handler derived from the WorkbookHelper helper class.
Fragment handler derived from the WorkbookHelper helper class.
Helper class to provide access to global workbook data.
StylesBuffer & getStyles() const
Returns all cell formatting objects read from the styles substream.
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
virtual void onStartElement(const AttributeList &rAttribs) override
def stop(arg=None)
fonts
void SvStream & rStrm
const sal_Int32 XML_ROOT_CONTEXT
const sal_Int32 BIFF12_ID_MRUCOLORS
Definition: biffhelper.hxx:138
const sal_Int32 BIFF12_ID_CELLXFS
Definition: biffhelper.hxx:52
const sal_Int32 BIFF12_ID_XF
Definition: biffhelper.hxx:242
const sal_Int32 BIFF12_ID_NUMFMT
Definition: biffhelper.hxx:147
const sal_Int32 BIFF12_ID_NUMFMTS
Definition: biffhelper.hxx:148
const sal_Int32 BIFF12_ID_FILLS
Definition: biffhelper.hxx:120
const sal_Int32 BIFF12_ID_TABLESTYLES
Definition: biffhelper.hxx:229
const sal_Int32 BIFF12_ID_BORDERS
Definition: biffhelper.hxx:38
const sal_Int32 BIFF12_ID_DXF
Definition: biffhelper.hxx:98
const sal_Int32 BIFF12_ID_FILL
Definition: biffhelper.hxx:119
const sal_Int32 BIFF12_ID_STYLESHEET
Definition: biffhelper.hxx:224
const sal_Int32 BIFF12_ID_COLORS
Definition: biffhelper.hxx:63
const sal_Int32 BIFF12_ID_CELLSTYLEXFS
Definition: biffhelper.hxx:51
const sal_Int32 BIFF12_ID_RGBCOLOR
Definition: biffhelper.hxx:207
const sal_Int32 BIFF12_ID_BORDER
Definition: biffhelper.hxx:37
const sal_Int32 BIFF12_ID_DXFS
Definition: biffhelper.hxx:99
const sal_Int32 BIFF12_ID_CELLSTYLES
Definition: biffhelper.hxx:50
const sal_Int32 BIFF12_ID_CELLSTYLE
Definition: biffhelper.hxx:49
const sal_Int32 BIFF12_ID_INDEXEDCOLORS
Definition: biffhelper.hxx:133
const sal_Int32 BIFF12_ID_FONTS
Definition: biffhelper.hxx:123
const sal_Int32 BIFF12_ID_FONT
Definition: biffhelper.hxx:122