tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / xmloff / source / draw / QRCodeContext.cxx
blob3e4c2ea4434f8e07945be3dd53afe4d978d8a8dc
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/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>
23 using namespace css;
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;
52 else
53 aBarCode.ErrorCorrection = css::drawing::BarCodeErrorCorrection::HIGH;
54 break;
56 case XML_ELEMENT(LO_EXT, XML_QRCODE_BORDER):
58 sal_Int32 nAttrVal;
59 if (sax::Converter::convertNumber(nAttrVal, aIter.toView(), 0))
60 aBarCode.Border = nAttrVal;
61 break;
63 case XML_ELEMENT(OFFICE, XML_STRING_VALUE):
65 aBarCode.Payload = aIter.toString();
66 break;
68 case XML_ELEMENT(LO_EXT, XML_QRCODE_TYPE):
70 sal_Int32 nAttrVal;
71 if (sax::Converter::convertNumber(nAttrVal, aIter.toView(), 0))
72 aBarCode.Type = nAttrVal;
73 break;
75 default:
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: */