Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/draw/QRCodeContext.cxx
Line
Count
Source
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/drawing/BarCode.hpp>
14
#include <com/sun/star/drawing/BarCodeErrorCorrection.hpp>
15
16
#include <xmloff/xmltoken.hxx>
17
#include <xmloff/xmlimp.hxx>
18
#include <xmloff/xmlnamespace.hxx>
19
#include <sax/tools/converter.hxx>
20
21
#include <rtl/ustring.hxx>
22
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;
28
29
QRCodeContext::QRCodeContext(SvXMLImport& rImport, sal_Int32 /*nElement*/,
30
                             const Reference<XFastAttributeList>& xAttrList,
31
                             const Reference<XShape>& rxShape)
32
0
    : SvXMLImportContext(rImport)
33
0
{
34
0
    Reference<beans::XPropertySet> xPropSet(rxShape, UNO_QUERY_THROW);
35
36
0
    css::drawing::BarCode aBarCode;
37
38
0
    for (auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList))
39
0
    {
40
0
        switch (aIter.getToken())
41
0
        {
42
0
            case XML_ELEMENT(LO_EXT, XML_QRCODE_ERROR_CORRECTION):
43
0
            {
44
0
                OUString aErrorCorrValue = aIter.toString();
45
46
0
                if (aErrorCorrValue == "low")
47
0
                    aBarCode.ErrorCorrection = css::drawing::BarCodeErrorCorrection::LOW;
48
0
                else if (aErrorCorrValue == "medium")
49
0
                    aBarCode.ErrorCorrection = css::drawing::BarCodeErrorCorrection::MEDIUM;
50
0
                else if (aErrorCorrValue == "quartile")
51
0
                    aBarCode.ErrorCorrection = css::drawing::BarCodeErrorCorrection::QUARTILE;
52
0
                else
53
0
                    aBarCode.ErrorCorrection = css::drawing::BarCodeErrorCorrection::HIGH;
54
0
                break;
55
0
            }
56
0
            case XML_ELEMENT(LO_EXT, XML_QRCODE_BORDER):
57
0
            {
58
0
                sal_Int32 nAttrVal;
59
0
                if (sax::Converter::convertNumber(nAttrVal, aIter.toView(), 0))
60
0
                    aBarCode.Border = nAttrVal;
61
0
                break;
62
0
            }
63
0
            case XML_ELEMENT(OFFICE, XML_STRING_VALUE):
64
0
            {
65
0
                aBarCode.Payload = aIter.toString();
66
0
                break;
67
0
            }
68
0
            case XML_ELEMENT(LO_EXT, XML_QRCODE_TYPE):
69
0
            {
70
0
                sal_Int32 nAttrVal;
71
0
                if (sax::Converter::convertNumber(nAttrVal, aIter.toView(), 0))
72
0
                    aBarCode.Type = nAttrVal;
73
0
                break;
74
0
            }
75
0
            default:
76
0
                XMLOFF_WARN_UNKNOWN("xmloff", aIter);
77
0
        }
78
0
    }
79
0
    xPropSet->setPropertyValue(u"BarCodeProperties"_ustr, Any(aBarCode));
80
0
}
81
82
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */