nss: upgrade to release 3.73
[LibreOffice.git] / xmloff / source / style / xmltabi.cxx
blob5c8db3fc89c52621e06081b844125ed0bbe225c1
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 const OUString sValue = aIter.toString();
64 sal_Int32 nVal;
65 switch( aIter.getToken() )
67 case XML_ELEMENT(STYLE, XML_POSITION):
68 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
69 nVal, sValue))
71 aTabStop.Position = nVal;
73 break;
74 case XML_ELEMENT(STYLE, XML_TYPE):
75 if( IsXMLToken( sValue, XML_LEFT ) )
77 aTabStop.Alignment = style::TabAlign_LEFT;
79 else if( IsXMLToken( sValue, XML_RIGHT ) )
81 aTabStop.Alignment = style::TabAlign_RIGHT;
83 else if( IsXMLToken( sValue, XML_CENTER ) )
85 aTabStop.Alignment = style::TabAlign_CENTER;
87 else if( IsXMLToken( sValue, XML_CHAR ) )
89 aTabStop.Alignment = style::TabAlign_DECIMAL;
91 else if( IsXMLToken( sValue, XML_DEFAULT ) )
93 aTabStop.Alignment = style::TabAlign_DEFAULT;
95 break;
96 case XML_ELEMENT(STYLE, XML_CHAR):
97 if( !sValue.isEmpty() )
98 aTabStop.DecimalChar = sValue[0];
99 break;
100 case XML_ELEMENT(STYLE, XML_LEADER_STYLE):
101 if( IsXMLToken( sValue, XML_NONE ) )
102 aTabStop.FillChar = ' ';
103 else if( IsXMLToken( sValue, XML_DOTTED ) )
104 aTabStop.FillChar = '.';
105 else
106 aTabStop.FillChar = '_';
107 break;
108 case XML_ELEMENT(STYLE, XML_LEADER_TEXT):
109 if( !sValue.isEmpty() )
110 cTextFillChar = sValue[0];
111 break;
112 default:
113 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
117 if( cTextFillChar != 0 && aTabStop.FillChar != ' ' )
118 aTabStop.FillChar = cTextFillChar;
122 SvxXMLTabStopImportContext::SvxXMLTabStopImportContext(
123 SvXMLImport& rImport, sal_Int32 nElement,
124 const XMLPropertyState& rProp,
125 ::std::vector< XMLPropertyState > &rProps )
126 : XMLElementPropertyContext( rImport, nElement, rProp, rProps )
130 css::uno::Reference< css::xml::sax::XFastContextHandler > SvxXMLTabStopImportContext::createFastChildContext(
131 sal_Int32 nElement,
132 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList)
134 if( nElement == XML_ELEMENT(STYLE, XML_TAB_STOP) )
136 // create new tabstop import context
137 const rtl::Reference<SvxXMLTabStopContext_Impl> xTabStopContext{
138 new SvxXMLTabStopContext_Impl( GetImport(), nElement, xAttrList )};
140 // add new tabstop to array of tabstops
141 if( !mpTabStops )
142 mpTabStops = std::make_unique<SvxXMLTabStopArray_Impl>();
144 mpTabStops->push_back( xTabStopContext );
146 return xTabStopContext.get();
148 else
149 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
151 return nullptr;
154 void SvxXMLTabStopImportContext::endFastElement(sal_Int32 nElement)
156 sal_uInt16 nCount = mpTabStops ? mpTabStops->size() : 0;
157 uno::Sequence< style::TabStop> aSeq( nCount );
159 if( mpTabStops )
161 sal_uInt16 nNewCount = 0;
163 style::TabStop* pTabStops = aSeq.getArray();
164 for( sal_uInt16 i=0; i < nCount; i++ )
166 SvxXMLTabStopContext_Impl *pTabStopContext = (*mpTabStops)[i].get();
167 const style::TabStop& rTabStop = pTabStopContext->getTabStop();
168 bool bDflt = style::TabAlign_DEFAULT == rTabStop.Alignment;
169 if( !bDflt || 0==i )
171 *pTabStops++ = pTabStopContext->getTabStop();
172 nNewCount++;
174 if( bDflt && 0==i )
175 break;
178 if( nCount != nNewCount )
179 aSeq.realloc( nNewCount );
181 aProp.maValue <<= aSeq;
183 SetInsert( true );
184 XMLElementPropertyContext::endFastElement(nElement);
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */