LibreOffice Module xmloff (master) 1
xmltabi.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 <com/sun/star/style/TabAlign.hpp>
21#include <sal/log.hxx>
22#include <xmloff/xmltkmap.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>
30
31
32using namespace ::com::sun::star;
33using namespace ::xmloff::token;
34
36{
37private:
38 style::TabStop aTabStop;
39
40public:
41
42 SvxXMLTabStopContext_Impl( SvXMLImport& rImport, sal_Int32 nElement,
43 const uno::Reference< xml::sax::XFastAttributeList > & xAttrList );
44
45 const style::TabStop& getTabStop() const { return aTabStop; }
46};
47
48
50 SvXMLImport& rImport, sal_Int32 /*nElement*/,
51 const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
52: SvXMLImportContext( rImport )
53{
54 aTabStop.Position = 0;
55 aTabStop.Alignment = style::TabAlign_LEFT;
56 aTabStop.DecimalChar = ',';
57 aTabStop.FillChar = ' ';
58 sal_Unicode cTextFillChar = 0;
59
60 for (auto &aIter : sax_fastparser::castToFastAttributeList(xAttrList))
61 {
62 sal_Int32 nVal;
63 switch( aIter.getToken() )
64 {
66 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
67 nVal, aIter.toView()))
68 {
69 aTabStop.Position = nVal;
70 }
71 break;
73 if( IsXMLToken( aIter, XML_LEFT ) )
74 {
75 aTabStop.Alignment = style::TabAlign_LEFT;
76 }
77 else if( IsXMLToken( aIter, XML_RIGHT ) )
78 {
79 aTabStop.Alignment = style::TabAlign_RIGHT;
80 }
81 else if( IsXMLToken( aIter, XML_CENTER ) )
82 {
83 aTabStop.Alignment = style::TabAlign_CENTER;
84 }
85 else if( IsXMLToken( aIter, XML_CHAR ) )
86 {
87 aTabStop.Alignment = style::TabAlign_DECIMAL;
88 }
89 else if( IsXMLToken( aIter, XML_DEFAULT ) )
90 {
91 aTabStop.Alignment = style::TabAlign_DEFAULT;
92 }
93 break;
95 if( !aIter.isEmpty() )
96 aTabStop.DecimalChar = aIter.toString()[0];
97 break;
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;
107 if( !aIter.isEmpty() )
108 cTextFillChar = aIter.toString()[0];
109 break;
110 default:
111 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
112 }
113 }
114
115 if( cTextFillChar != 0 && aTabStop.FillChar != ' ' )
116 aTabStop.FillChar = cTextFillChar;
117}
118
119
121 SvXMLImport& rImport, sal_Int32 nElement,
122 const XMLPropertyState& rProp,
123 ::std::vector< XMLPropertyState > &rProps )
124: XMLElementPropertyContext( rImport, nElement, rProp, rProps )
125{
126}
127
128css::uno::Reference< css::xml::sax::XFastContextHandler > SvxXMLTabStopImportContext::createFastChildContext(
129 sal_Int32 nElement,
130 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList)
131{
132 if( nElement == XML_ELEMENT(STYLE, XML_TAB_STOP) )
133 {
134 // create new tabstop import context
135 const rtl::Reference<SvxXMLTabStopContext_Impl> xTabStopContext{
136 new SvxXMLTabStopContext_Impl( GetImport(), nElement, xAttrList )};
137
138 // add new tabstop to array of tabstops
139 maTabStops.push_back( xTabStopContext );
140
141 return xTabStopContext;
142 }
143 else
144 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
145
146 return nullptr;
147}
148
150{
151 sal_uInt16 nCount = maTabStops.size();
152 uno::Sequence< style::TabStop> aSeq( nCount );
153
154 if( nCount )
155 {
156 sal_uInt16 nNewCount = 0;
157
158 style::TabStop* pTabStops = aSeq.getArray();
159 for( sal_uInt16 i=0; i < nCount; i++ )
160 {
161 SvxXMLTabStopContext_Impl *pTabStopContext = maTabStops[i].get();
162 const style::TabStop& rTabStop = pTabStopContext->getTabStop();
163 bool bDflt = style::TabAlign_DEFAULT == rTabStop.Alignment;
164 if( !bDflt || 0==i )
165 {
166 *pTabStops++ = pTabStopContext->getTabStop();
167 nNewCount++;
168 }
169 if( bDflt && 0==i )
170 break;
171 }
172
173 if( nCount != nNewCount )
174 aSeq.realloc( nNewCount );
175 }
176 aProp.maValue <<= aSeq;
177
178 SetInsert( true );
180}
181
182
183/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This class deliberately does not support XWeak, to improve performance when loading large documents.
Definition: xmlictxt.hxx:48
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:60
friend class SvXMLImport
Definition: xmlictxt.hxx:49
SvxXMLTabStopContext_Impl(SvXMLImport &rImport, sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList > &xAttrList)
Definition: xmltabi.cxx:49
const style::TabStop & getTabStop() const
Definition: xmltabi.cxx:45
style::TabStop aTabStop
Definition: xmltabi.cxx:38
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
Definition: xmltabi.cxx:149
SvxXMLTabStopImportContext(SvXMLImport &rImport, sal_Int32 nElement, const XMLPropertyState &rProp, ::std::vector< XMLPropertyState > &rProps)
Definition: xmltabi.cxx:120
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
Definition: xmltabi.cxx:128
std::vector< rtl::Reference< SvxXMLTabStopContext_Impl > > maTabStops
Definition: xmltabi.hxx:32
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
int nCount
Sequence< sal_Int8 > aSeq
int i
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
Handling of tokens in XML:
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3597
Smart struct to transport an Any with an index to the appropriate property-name.
Definition: maptype.hxx:140
css::uno::Any maValue
Definition: maptype.hxx:142
sal_uInt16 sal_Unicode
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
Definition: xmlictxt.hxx:120
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:114
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97