1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
10 #include "QRCodeContext.hxx"
12 #include <com/sun/star/beans/XPropertySet.hpp>
13 #include <com/sun/star/drawing/BarCode.hpp>
14 #include <com/sun/star/drawing/BarCodeErrorCorrection.hpp>
16 #include <xmloff/xmltoken.hxx>
17 #include <xmloff/xmlimp.hxx>
18 #include <xmloff/xmlnamespace.hxx>
19 #include <sax/tools/converter.hxx>
21 #include <rtl/ustring.hxx>
24 using namespace css::xml::sax
;
25 using namespace css::uno
;
26 using namespace css::drawing
;
27 using namespace xmloff::token
;
29 QRCodeContext::QRCodeContext(SvXMLImport
& rImport
, sal_Int32
/*nElement*/,
30 const Reference
<XFastAttributeList
>& xAttrList
,
31 const Reference
<XShape
>& rxShape
)
32 : SvXMLImportContext(rImport
)
34 Reference
<beans::XPropertySet
> xPropSet(rxShape
, UNO_QUERY_THROW
);
36 css::drawing::BarCode aBarCode
;
38 for (auto& aIter
: sax_fastparser::castToFastAttributeList(xAttrList
))
40 switch (aIter
.getToken())
42 case XML_ELEMENT(LO_EXT
, XML_QRCODE_ERROR_CORRECTION
):
44 OUString aErrorCorrValue
= aIter
.toString();
46 if (aErrorCorrValue
== "low")
47 aBarCode
.ErrorCorrection
= css::drawing::BarCodeErrorCorrection::LOW
;
48 else if (aErrorCorrValue
== "medium")
49 aBarCode
.ErrorCorrection
= css::drawing::BarCodeErrorCorrection::MEDIUM
;
50 else if (aErrorCorrValue
== "quartile")
51 aBarCode
.ErrorCorrection
= css::drawing::BarCodeErrorCorrection::QUARTILE
;
53 aBarCode
.ErrorCorrection
= css::drawing::BarCodeErrorCorrection::HIGH
;
56 case XML_ELEMENT(LO_EXT
, XML_QRCODE_BORDER
):
59 if (sax::Converter::convertNumber(nAttrVal
, aIter
.toView(), 0))
60 aBarCode
.Border
= nAttrVal
;
63 case XML_ELEMENT(OFFICE
, XML_STRING_VALUE
):
65 aBarCode
.Payload
= aIter
.toString();
68 case XML_ELEMENT(LO_EXT
, XML_QRCODE_TYPE
):
71 if (sax::Converter::convertNumber(nAttrVal
, aIter
.toView(), 0))
72 aBarCode
.Type
= nAttrVal
;
76 XMLOFF_WARN_UNKNOWN("xmloff", aIter
);
79 xPropSet
->setPropertyValue(u
"BarCodeProperties"_ustr
, Any(aBarCode
));
82 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */