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 "txtdropi.hxx"
23 #include <com/sun/star/style/DropCapFormat.hpp>
25 #include <sal/log.hxx>
26 #include <sax/tools/converter.hxx>
28 #include <xmloff/xmltkmap.hxx>
29 #include <xmloff/xmluconv.hxx>
30 #include <xmloff/namespacemap.hxx>
31 #include <xmloff/xmlnamespace.hxx>
32 #include <xmloff/xmlimp.hxx>
33 #include <xmloff/xmltoken.hxx>
36 using namespace ::com::sun::star
;
37 using namespace ::com::sun::star::uno
;
38 using namespace ::com::sun::star::style
;
39 using namespace ::xmloff::token
;
41 void XMLTextDropCapImportContext::ProcessAttrs(
42 const Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
44 DropCapFormat aFormat
;
45 bool bWholeWord
= false;
48 for (auto &aIter
: sax_fastparser::castToFastAttributeList(xAttrList
))
50 const OUString sValue
= aIter
.toString();
52 switch( aIter
.getToken() )
54 case XML_ELEMENT(STYLE
, XML_LINES
):
55 if (::sax::Converter::convertNumber( nTmp
, sValue
, 0, 255 ))
57 aFormat
.Lines
= nTmp
< 2 ? 0 : static_cast<sal_Int8
>(nTmp
);
61 case XML_ELEMENT(STYLE
, XML_LENGTH
):
62 if( IsXMLToken( sValue
, XML_WORD
) )
66 else if (::sax::Converter::convertNumber( nTmp
, sValue
, 1, 255 ))
69 aFormat
.Count
= static_cast<sal_Int8
>(nTmp
);
73 case XML_ELEMENT(STYLE
, XML_DISTANCE
):
74 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
77 aFormat
.Distance
= static_cast<sal_uInt16
>(nTmp
);
81 case XML_ELEMENT(STYLE
, XML_STYLE_NAME
):
86 XMLOFF_WARN_UNKNOWN("xmloff", aIter
);
90 if( aFormat
.Lines
> 1 && aFormat
.Count
< 1 )
93 aProp
.maValue
<<= aFormat
;
95 aWholeWordProp
.maValue
<<= bWholeWord
;
98 XMLTextDropCapImportContext::XMLTextDropCapImportContext(
99 SvXMLImport
& rImport
, sal_Int32 nElement
,
100 const Reference
< xml::sax::XFastAttributeList
> & xAttrList
,
101 const XMLPropertyState
& rProp
,
102 sal_Int32 nWholeWordIdx
,
103 ::std::vector
< XMLPropertyState
> &rProps
) :
104 XMLElementPropertyContext( rImport
, nElement
, rProp
, rProps
),
105 aWholeWordProp( nWholeWordIdx
)
107 ProcessAttrs( xAttrList
);
110 XMLTextDropCapImportContext::~XMLTextDropCapImportContext()
114 void XMLTextDropCapImportContext::endFastElement(sal_Int32 nElement
)
117 XMLElementPropertyContext::endFastElement(nElement
);
119 if( -1 != aWholeWordProp
.mnIndex
)
120 rProperties
.push_back( aWholeWordProp
);
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */