Coverage Report

Created: 2024-09-08 06:05

/src/qpdf/libqpdf/ResourceFinder.cc
Line
Count
Source (jump to first uncovered line)
1
#include <qpdf/ResourceFinder.hh>
2
3
ResourceFinder::ResourceFinder() :
4
    last_name_offset(0)
5
0
{
6
0
}
7
8
void
9
ResourceFinder::handleObject(QPDFObjectHandle obj, size_t offset, size_t)
10
0
{
11
0
    if (obj.isOperator() && (!this->last_name.empty())) {
12
0
        static std::map<std::string, std::string> op_to_rtype = {
13
0
            {"CS", "/ColorSpace"},
14
0
            {"cs", "/ColorSpace"},
15
0
            {"gs", "/ExtGState"},
16
0
            {"Tf", "/Font"},
17
0
            {"SCN", "/Pattern"},
18
0
            {"scn", "/Pattern"},
19
0
            {"BDC", "/Properties"},
20
0
            {"DP", "/Properties"},
21
0
            {"sh", "/Shading"},
22
0
            {"Do", "/XObject"},
23
0
        };
24
0
        std::string op = obj.getOperatorValue();
25
0
        std::string resource_type;
26
0
        auto iter = op_to_rtype.find(op);
27
0
        if (iter != op_to_rtype.end()) {
28
0
            resource_type = iter->second;
29
0
        }
30
0
        if (!resource_type.empty()) {
31
0
            this->names.insert(this->last_name);
32
0
            this->names_by_resource_type[resource_type][this->last_name].insert(
33
0
                this->last_name_offset);
34
0
        }
35
0
    } else if (obj.isName()) {
36
0
        this->last_name = obj.getName();
37
0
        this->last_name_offset = offset;
38
0
    }
39
0
}
40
41
void
42
ResourceFinder::handleEOF()
43
0
{
44
0
}
45
46
std::set<std::string> const&
47
ResourceFinder::getNames() const
48
0
{
49
0
    return this->names;
50
0
}
51
52
std::map<std::string, std::map<std::string, std::set<size_t>>> const&
53
ResourceFinder::getNamesByResourceType() const
54
0
{
55
0
    return this->names_by_resource_type;
56
0
}