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 .
21 #include "XMLIndexTabStopEntryContext.hxx"
23 #include <sax/tools/converter.hxx>
25 #include "XMLIndexTemplateContext.hxx"
26 #include <xmloff/xmlimp.hxx>
27 #include <xmloff/namespacemap.hxx>
28 #include <xmloff/xmlnamespace.hxx>
29 #include <xmloff/xmltoken.hxx>
30 #include <xmloff/xmluconv.hxx>
31 #include <rtl/ustring.hxx>
32 #include <sal/log.hxx>
34 using namespace ::xmloff::token
;
36 using ::com::sun::star::uno::Sequence
;
37 using ::com::sun::star::uno::Reference
;
38 using ::com::sun::star::beans::PropertyValue
;
39 using ::com::sun::star::xml::sax::XAttributeList
;
42 XMLIndexTabStopEntryContext::XMLIndexTabStopEntryContext(
44 XMLIndexTemplateContext
& rTemplate
) :
45 XMLIndexSimpleEntryContext(rImport
, "TokenTabStop",
48 bTabPositionOK(false),
49 bTabRightAligned(false),
51 bWithTab(true) // #i21237#
55 XMLIndexTabStopEntryContext::~XMLIndexTabStopEntryContext()
59 void XMLIndexTabStopEntryContext::startFastElement(
61 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
63 // process three attributes: type, position, leader char
64 for( auto& aIter
: sax_fastparser::castToFastAttributeList(xAttrList
) )
66 switch(aIter
.getToken())
68 case XML_ELEMENT(STYLE
, XML_TYPE
):
70 // if it's neither left nor right, value is
71 // ignored. Since left is default, we only need to
73 bTabRightAligned
= IsXMLToken( aIter
, XML_RIGHT
);
76 case XML_ELEMENT(STYLE
, XML_POSITION
):
79 if (GetImport().GetMM100UnitConverter().
80 convertMeasureToCore(nTmp
, aIter
.toView()))
83 bTabPositionOK
= true;
87 case XML_ELEMENT(STYLE
, XML_LEADER_CHAR
):
89 sLeaderChar
= aIter
.toString();
90 // valid only, if we have a char!
91 bLeaderCharOK
= !sLeaderChar
.isEmpty();
94 case XML_ELEMENT(STYLE
, XML_WITH_TAB
):
98 if (::sax::Converter::convertBool(bTmp
, aIter
.toView()))
103 XMLOFF_WARN_UNKNOWN("xmloff", aIter
);
104 // else: unknown style: attribute -> ignore
108 // how many entries? #i21237#
109 m_nValues
+= 2 + (bTabPositionOK
? 1 : 0) + (bLeaderCharOK
? 1 : 0);
111 // now try parent class (for character style)
112 XMLIndexSimpleEntryContext::startFastElement( nElement
, xAttrList
);
115 void XMLIndexTabStopEntryContext::FillPropertyValues(
116 Sequence
<PropertyValue
> & rValues
)
118 // fill values from parent class (type + style name)
119 XMLIndexSimpleEntryContext::FillPropertyValues(rValues
);
121 // get values array and next entry to be written;
122 sal_Int32 nNextEntry
= m_bCharStyleNameOK
? 2 : 1;
123 PropertyValue
* pValues
= rValues
.getArray();
126 pValues
[nNextEntry
].Name
= "TabStopRightAligned";
127 pValues
[nNextEntry
].Value
<<= bTabRightAligned
;
133 pValues
[nNextEntry
].Name
= "TabStopPosition";
134 pValues
[nNextEntry
].Value
<<= nTabPosition
;
141 pValues
[nNextEntry
].Name
= "TabStopFillCharacter";
142 pValues
[nNextEntry
].Value
<<= sLeaderChar
;
146 // tab character #i21237#
147 pValues
[nNextEntry
].Name
= "WithTab";
148 pValues
[nNextEntry
].Value
<<= bWithTab
;
151 // check whether we really filled all elements of the sequence
152 SAL_WARN_IF( nNextEntry
!= rValues
.getLength(), "xmloff",
153 "length incorrectly precomputed!" );
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */