LibreOffice Module xmloff (master)  1
txtdropi.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 
21 #include "txtdropi.hxx"
22 
23 #include <com/sun/star/style/DropCapFormat.hpp>
24 
25 #include <sal/log.hxx>
26 #include <sax/tools/converter.hxx>
27 
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>
34 
35 
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;
40 
41 namespace {
42 
44 {
45  XML_TOK_DROP_LINES,
46  XML_TOK_DROP_LENGTH,
47  XML_TOK_DROP_DISTANCE,
48  XML_TOK_DROP_STYLE
49 };
50 
51 }
52 
54 {
55  { XML_NAMESPACE_STYLE, XML_LINES, XML_TOK_DROP_LINES },
56  { XML_NAMESPACE_STYLE, XML_LENGTH, XML_TOK_DROP_LENGTH },
57  { XML_NAMESPACE_STYLE, XML_DISTANCE, XML_TOK_DROP_DISTANCE },
58  { XML_NAMESPACE_STYLE, XML_STYLE_NAME, XML_TOK_DROP_STYLE },
60 };
61 
63  const Reference< xml::sax::XFastAttributeList >& xAttrList )
64 {
65  DropCapFormat aFormat;
66  bool bWholeWord = false;
67 
68  sal_Int32 nTmp;
69  for (auto &aIter : sax_fastparser::castToFastAttributeList(xAttrList))
70  {
71  const OUString sValue = aIter.toString();
72 
73  switch( aIter.getToken() )
74  {
76  if (::sax::Converter::convertNumber( nTmp, sValue, 0, 255 ))
77  {
78  aFormat.Lines = nTmp < 2 ? 0 : static_cast<sal_Int8>(nTmp);
79  }
80  break;
81 
83  if( IsXMLToken( sValue, XML_WORD ) )
84  {
85  bWholeWord = true;
86  }
87  else if (::sax::Converter::convertNumber( nTmp, sValue, 1, 255 ))
88  {
89  bWholeWord = false;
90  aFormat.Count = static_cast<sal_Int8>(nTmp);
91  }
92  break;
93 
95  if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
96  nTmp, sValue, 0 ))
97  {
98  aFormat.Distance = static_cast<sal_uInt16>(nTmp);
99  }
100  break;
101 
103  sStyleName = sValue;
104  break;
105 
106  default:
107  SAL_WARN("xmloff", "unknown attribute " << SvXMLImport::getPrefixAndNameFromToken(aIter.getToken()) << "=" << sValue);
108  }
109  }
110 
111  if( aFormat.Lines > 1 && aFormat.Count < 1 )
112  aFormat.Count = 1;
113 
114  aProp.maValue <<= aFormat;
115 
116  aWholeWordProp.maValue <<= bWholeWord;
117 }
118 
120  SvXMLImport& rImport, sal_Int32 nElement,
121  const Reference< xml::sax::XFastAttributeList > & xAttrList,
122  const XMLPropertyState& rProp,
123  sal_Int32 nWholeWordIdx,
124  ::std::vector< XMLPropertyState > &rProps ) :
125  XMLElementPropertyContext( rImport, nElement, rProp, rProps ),
126  aWholeWordProp( nWholeWordIdx )
127 {
128  ProcessAttrs( xAttrList );
129 }
130 
132 {
133 }
134 
136 {
137  SetInsert( true );
139 
140  if( -1 != aWholeWordProp.mnIndex )
141  rProperties.push_back( aWholeWordProp );
142 }
143 
144 
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3434
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
Definition: txtdropi.cxx:135
signed char sal_Int8
SvXMLTokenMapDropAttrs
Definition: txtdropi.cxx:43
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
sal_Int32 mnIndex
Definition: maptype.hxx:124
const SvXMLTokenMapEntry aDropAttrTokenMap[]
Definition: txtdropi.cxx:53
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
XMLTextDropCapImportContext(SvXMLImport &rImport, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, const XMLPropertyState &rProp, sal_Int32 nWholeWOrdIdx,::std::vector< XMLPropertyState > &rProps)
Definition: txtdropi.cxx:119
#define XML_TOKEN_MAP_END
Definition: xmltkmap.hxx:33
static OUString getPrefixAndNameFromToken(sal_Int32 nToken)
Definition: xmlimp.cxx:2025
void ProcessAttrs(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
Definition: txtdropi.cxx:62
virtual ~XMLTextDropCapImportContext() override
Definition: txtdropi.cxx:131
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
::std::vector< XMLPropertyState > & rProperties
css::uno::Any maValue
Definition: maptype.hxx:125
Handling of tokens in XML:
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:94
Smart struct to transport an Any with an index to the appropriate property-name.
Definition: maptype.hxx:122
#define SAL_WARN(area, stream)
XMLPropertyState aWholeWordProp
Definition: txtdropi.hxx:28
constexpr sal_uInt16 XML_NAMESPACE_STYLE
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)