Bump version to 24.04.3.4
[LibreOffice.git] / xmloff / source / draw / QRCodeContext.cxx
blob597838f78cad4eefa3b4d63e842ae9432a41112b
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.
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 */
10 #include "QRCodeContext.hxx"
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/BarCode.hpp>
17 #include <com/sun/star/drawing/BarCodeErrorCorrection.hpp>
18 #include <com/sun/star/xml/sax/XAttributeList.hpp>
20 #include <xmloff/xmltoken.hxx>
21 #include <xmloff/xmlimp.hxx>
22 #include <xmloff/xmlnamespace.hxx>
23 #include <xmloff/namespacemap.hxx>
24 #include <sax/tools/converter.hxx>
26 #include <rtl/ustring.hxx>
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;
38 QRCodeContext::QRCodeContext(SvXMLImport& rImport, sal_Int32 /*nElement*/,
39 const Reference<XFastAttributeList>& xAttrList,
40 const Reference<XShape>& rxShape)
41 : SvXMLImportContext(rImport)
43 Reference<beans::XPropertySet> xPropSet(rxShape, UNO_QUERY_THROW);
45 css::drawing::BarCode aBarCode;
47 for (auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList))
49 switch (aIter.getToken())
51 case XML_ELEMENT(LO_EXT, XML_QRCODE_ERROR_CORRECTION):
53 OUString aErrorCorrValue = aIter.toString();
55 if (aErrorCorrValue == "low")
56 aBarCode.ErrorCorrection = css::drawing::BarCodeErrorCorrection::LOW;
57 else if (aErrorCorrValue == "medium")
58 aBarCode.ErrorCorrection = css::drawing::BarCodeErrorCorrection::MEDIUM;
59 else if (aErrorCorrValue == "quartile")
60 aBarCode.ErrorCorrection = css::drawing::BarCodeErrorCorrection::QUARTILE;
61 else
62 aBarCode.ErrorCorrection = css::drawing::BarCodeErrorCorrection::HIGH;
63 break;
65 case XML_ELEMENT(LO_EXT, XML_QRCODE_BORDER):
67 sal_Int32 nAttrVal;
68 if (sax::Converter::convertNumber(nAttrVal, aIter.toView(), 0))
69 aBarCode.Border = nAttrVal;
70 break;
72 case XML_ELEMENT(OFFICE, XML_STRING_VALUE):
74 aBarCode.Payload = aIter.toString();
75 break;
77 case XML_ELEMENT(LO_EXT, XML_QRCODE_TYPE):
79 sal_Int32 nAttrVal;
80 if (sax::Converter::convertNumber(nAttrVal, aIter.toView(), 0))
81 aBarCode.Type = nAttrVal;
82 break;
84 default:
85 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
88 xPropSet->setPropertyValue("BarCodeProperties", Any(aBarCode));
91 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */