Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / xmloff / source / style / xmltabi.cxx
blob601c3f5fd1919dadb4aeab7fb235174c0fe30ef9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/style/TabAlign.hpp>
21 #include <sal/log.hxx>
22 #include <xmloff/xmltkmap.hxx>
23 #include <xmloff/namespacemap.hxx>
24 #include <xmloff/xmlnamespace.hxx>
25 #include <xmloff/xmlimp.hxx>
26 #include <com/sun/star/style/TabStop.hpp>
27 #include <xmloff/xmltoken.hxx>
28 #include <xmloff/xmluconv.hxx>
29 #include <xmltabi.hxx>
32 using namespace ::com::sun::star;
33 using namespace ::xmloff::token;
35 class SvxXMLTabStopContext_Impl : public SvXMLImportContext
37 private:
38 style::TabStop aTabStop;
40 public:
42 SvxXMLTabStopContext_Impl( SvXMLImport& rImport, sal_Int32 nElement,
43 const uno::Reference< xml::sax::XFastAttributeList > & xAttrList );
45 const style::TabStop& getTabStop() const { return aTabStop; }
49 SvxXMLTabStopContext_Impl::SvxXMLTabStopContext_Impl(
50 SvXMLImport& rImport, sal_Int32 /*nElement*/,
51 const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
52 : SvXMLImportContext( rImport )
54 aTabStop.Position = 0;
55 aTabStop.Alignment = style::TabAlign_LEFT;
56 aTabStop.DecimalChar = ',';
57 aTabStop.FillChar = ' ';
58 sal_Unicode cTextFillChar = 0;
60 for (auto &aIter : sax_fastparser::castToFastAttributeList(xAttrList))
62 sal_Int32 nVal;
63 switch( aIter.getToken() )
65 case XML_ELEMENT(STYLE, XML_POSITION):
66 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
67 nVal, aIter.toView()))
69 aTabStop.Position = nVal;
71 break;
72 case XML_ELEMENT(STYLE, XML_TYPE):
73 if( IsXMLToken( aIter, XML_LEFT ) )
75 aTabStop.Alignment = style::TabAlign_LEFT;
77 else if( IsXMLToken( aIter, XML_RIGHT ) )
79 aTabStop.Alignment = style::TabAlign_RIGHT;
81 else if( IsXMLToken( aIter, XML_CENTER ) )
83 aTabStop.Alignment = style::TabAlign_CENTER;
85 else if( IsXMLToken( aIter, XML_CHAR ) )
87 aTabStop.Alignment = style::TabAlign_DECIMAL;
89 else if( IsXMLToken( aIter, XML_DEFAULT ) )
91 aTabStop.Alignment = style::TabAlign_DEFAULT;
93 break;
94 case XML_ELEMENT(STYLE, XML_CHAR):
95 if( !aIter.isEmpty() )
96 aTabStop.DecimalChar = aIter.toString()[0];
97 break;
98 case XML_ELEMENT(STYLE, XML_LEADER_STYLE):
99 if( IsXMLToken( aIter, XML_NONE ) )
100 aTabStop.FillChar = ' ';
101 else if( IsXMLToken( aIter, XML_DOTTED ) )
102 aTabStop.FillChar = '.';
103 else
104 aTabStop.FillChar = '_';
105 break;
106 case XML_ELEMENT(STYLE, XML_LEADER_TEXT):
107 if( !aIter.isEmpty() )
108 cTextFillChar = aIter.toString()[0];
109 break;
110 default:
111 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
115 if( cTextFillChar != 0 && aTabStop.FillChar != ' ' )
116 aTabStop.FillChar = cTextFillChar;
120 SvxXMLTabStopImportContext::SvxXMLTabStopImportContext(
121 SvXMLImport& rImport, sal_Int32 nElement,
122 const XMLPropertyState& rProp,
123 ::std::vector< XMLPropertyState > &rProps )
124 : XMLElementPropertyContext( rImport, nElement, rProp, rProps )
128 css::uno::Reference< css::xml::sax::XFastContextHandler > SvxXMLTabStopImportContext::createFastChildContext(
129 sal_Int32 nElement,
130 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList)
132 if( nElement == XML_ELEMENT(STYLE, XML_TAB_STOP) )
134 // create new tabstop import context
135 const rtl::Reference<SvxXMLTabStopContext_Impl> xTabStopContext{
136 new SvxXMLTabStopContext_Impl( GetImport(), nElement, xAttrList )};
138 // add new tabstop to array of tabstops
139 if( !mpTabStops )
140 mpTabStops = std::make_unique<SvxXMLTabStopArray_Impl>();
142 mpTabStops->push_back( xTabStopContext );
144 return xTabStopContext;
146 else
147 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
149 return nullptr;
152 void SvxXMLTabStopImportContext::endFastElement(sal_Int32 nElement)
154 sal_uInt16 nCount = mpTabStops ? mpTabStops->size() : 0;
155 uno::Sequence< style::TabStop> aSeq( nCount );
157 if( mpTabStops )
159 sal_uInt16 nNewCount = 0;
161 style::TabStop* pTabStops = aSeq.getArray();
162 for( sal_uInt16 i=0; i < nCount; i++ )
164 SvxXMLTabStopContext_Impl *pTabStopContext = (*mpTabStops)[i].get();
165 const style::TabStop& rTabStop = pTabStopContext->getTabStop();
166 bool bDflt = style::TabAlign_DEFAULT == rTabStop.Alignment;
167 if( !bDflt || 0==i )
169 *pTabStops++ = pTabStopContext->getTabStop();
170 nNewCount++;
172 if( bDflt && 0==i )
173 break;
176 if( nCount != nNewCount )
177 aSeq.realloc( nNewCount );
179 aProp.maValue <<= aSeq;
181 SetInsert( true );
182 XMLElementPropertyContext::endFastElement(nElement);
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */