LibreOffice Module xmloff (master)  1
QRCodeContext.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 
10 #include "QRCodeContext.hxx"
11 
12 #include <com/sun/star/beans/XPropertySet.hpp>
13 #include <com/sun/star/embed/XStorage.hpp>
14 #include <com/sun/star/frame/XStorable.hpp>
15 #include <com/sun/star/graphic/XGraphic.hpp>
16 #include <com/sun/star/drawing/QRCode.hpp>
17 #include <com/sun/star/drawing/QRCodeErrorCorrection.hpp>
18 #include <com/sun/star/xml/sax/XAttributeList.hpp>
19 
20 #include <xmloff/xmltoken.hxx>
21 #include <xmloff/xmlimp.hxx>
22 #include <xmloff/xmlnmspe.hxx>
23 #include <xmloff/nmspmap.hxx>
24 #include <sax/tools/converter.hxx>
25 
26 #include <rtl/ustring.hxx>
27 
28 using namespace css;
29 using namespace css::xml::sax;
30 using namespace css::uno;
31 using namespace css::drawing;
32 using namespace css::embed;
33 using namespace css::frame;
34 using namespace css::io;
35 using namespace css::graphic;
36 using namespace xmloff::token;
37 
38 QRCodeContext::QRCodeContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName,
39  const Reference<XAttributeList>& xAttrList,
40  const Reference<XShape>& rxShape)
41  : SvXMLImportContext(rImport, nPrfx, rLocalName)
42 {
43  Reference<beans::XPropertySet> xPropSet(rxShape, UNO_QUERY_THROW);
44 
45  css::drawing::QRCode aQRCode;
46  const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
47 
48  for (sal_Int16 i = 0; i < nAttrCount; i++)
49  {
50  OUString sAttrName = xAttrList->getNameByIndex(i);
51  OUString aLocalName;
52  sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(sAttrName, &aLocalName);
53  OUString sValue = xAttrList->getValueByIndex(i);
54 
55  switch (nPrefix)
56  {
58  if (IsXMLToken(aLocalName, XML_QRCODE_ERROR_CORRECTION))
59  {
60  OUString aErrorCorrValue = sValue;
61 
62  if (aErrorCorrValue == "low")
63  aQRCode.ErrorCorrection = css::drawing::QRCodeErrorCorrection::LOW;
64  else if (aErrorCorrValue == "medium")
65  aQRCode.ErrorCorrection = css::drawing::QRCodeErrorCorrection::MEDIUM;
66  else if (aErrorCorrValue == "quartile")
67  aQRCode.ErrorCorrection = css::drawing::QRCodeErrorCorrection::QUARTILE;
68  else
69  aQRCode.ErrorCorrection = css::drawing::QRCodeErrorCorrection::HIGH;
70  }
71 
72  if (IsXMLToken(aLocalName, XML_QRCODE_BORDER))
73  {
74  sal_Int32 nAttrVal;
75  if (sax::Converter::convertNumber(nAttrVal, sValue, 0))
76  aQRCode.Border = nAttrVal;
77  }
78  break;
79 
81  if (IsXMLToken(aLocalName, XML_STRING_VALUE))
82  {
83  aQRCode.Payload = sValue;
84  }
85  }
86  }
87  xPropSet->setPropertyValue("QRCodeProperties", Any(aQRCode));
88 }
89 
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
constexpr sal_uInt16 XML_NAMESPACE_LO_EXT
Definition: xmlnmspe.hxx:80
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3422
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
SvXMLNamespaceMap & GetNamespaceMap()
Definition: xmlimp.hxx:397
sal_uInt16 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
Definition: nmspmap.cxx:437
QRCodeContext(SvXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList, const css::uno::Reference< css::drawing::XShape > &rxShape)
int i
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
Handling of tokens in XML:
constexpr sal_uInt16 XML_NAMESPACE_OFFICE
Definition: xmlnmspe.hxx:29
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)