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