1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
38 style::TabStop aTabStop
;
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
))
63 switch( aIter
.getToken() )
65 case XML_ELEMENT(STYLE
, XML_POSITION
):
66 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
67 nVal
, aIter
.toView()))
69 aTabStop
.Position
= nVal
;
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
;
94 case XML_ELEMENT(STYLE
, XML_CHAR
):
95 if( !aIter
.isEmpty() )
96 aTabStop
.DecimalChar
= aIter
.toString()[0];
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
= '.';
104 aTabStop
.FillChar
= '_';
106 case XML_ELEMENT(STYLE
, XML_LEADER_TEXT
):
107 if( !aIter
.isEmpty() )
108 cTextFillChar
= aIter
.toString()[0];
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(
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 maTabStops
.push_back( xTabStopContext
);
141 return xTabStopContext
;
144 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement
);
149 void SvxXMLTabStopImportContext::endFastElement(sal_Int32 nElement
)
151 sal_uInt16 nCount
= maTabStops
.size();
152 uno::Sequence
< style::TabStop
> aSeq( nCount
);
156 sal_uInt16 nNewCount
= 0;
158 style::TabStop
* pTabStops
= aSeq
.getArray();
159 for( sal_uInt16 i
=0; i
< nCount
; i
++ )
161 SvxXMLTabStopContext_Impl
*pTabStopContext
= maTabStops
[i
].get();
162 const style::TabStop
& rTabStop
= pTabStopContext
->getTabStop();
163 bool bDflt
= style::TabAlign_DEFAULT
== rTabStop
.Alignment
;
166 *pTabStops
++ = pTabStopContext
->getTabStop();
173 if( nCount
!= nNewCount
)
174 aSeq
.realloc( nNewCount
);
176 aProp
.maValue
<<= aSeq
;
179 XMLElementPropertyContext::endFastElement(nElement
);
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */