Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/source/pdf/ResourceDict.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
11
#include <pdf/ResourceDict.hxx>
12
#include <pdf/COSWriter.hxx>
13
14
namespace vcl::pdf
15
{
16
namespace
17
{
18
void appendResourceMap(OStringBuffer& rBuf, const char* pPrefix,
19
                       std::map<OString, sal_Int32> const& rList)
20
15.7k
{
21
15.7k
    if (rList.empty())
22
15.7k
        return;
23
12
    rBuf.append('/');
24
12
    rBuf.append(pPrefix);
25
12
    rBuf.append("<<");
26
12
    int ni = 0;
27
12
    for (auto const& item : rList)
28
12
    {
29
12
        if (!item.first.isEmpty() && item.second > 0)
30
12
        {
31
12
            rBuf.append('/');
32
12
            rBuf.append(item.first);
33
12
            rBuf.append(' ');
34
12
            rBuf.append(item.second);
35
12
            rBuf.append(" 0 R");
36
12
            if (((++ni) & 7) == 0)
37
0
                rBuf.append('\n');
38
12
        }
39
12
    }
40
12
    rBuf.append(">>\n");
41
12
}
42
}
43
44
void ResourceDict::append(OStringBuffer& rBuf, sal_Int32 nFontDictObject,
45
                          PDFWriter::PDFVersion eVersion)
46
3.93k
{
47
3.93k
    COSWriter aWriter(rBuf);
48
3.93k
    aWriter.startDict();
49
3.93k
    if (nFontDictObject)
50
3.93k
        aWriter.writeKeyAndReference("/Font", nFontDictObject);
51
3.93k
    appendResourceMap(rBuf, "XObject", m_aXObjects);
52
3.93k
    appendResourceMap(rBuf, "ExtGState", m_aExtGStates);
53
3.93k
    appendResourceMap(rBuf, "Shading", m_aShadings);
54
3.93k
    appendResourceMap(rBuf, "Pattern", m_aPatterns);
55
56
3.93k
    if (eVersion < PDFWriter::PDFVersion::PDF_2_0)
57
3.93k
    {
58
3.93k
        rBuf.append("/ProcSet");
59
3.93k
        rBuf.append("[");
60
3.93k
        rBuf.append("/PDF/Text");
61
3.93k
        if (!m_aXObjects.empty())
62
6
            rBuf.append("/ImageC/ImageI/ImageB");
63
3.93k
        rBuf.append("]\n");
64
3.93k
    }
65
3.93k
    aWriter.endDict();
66
3.93k
}
67
68
} // end vcl::pdf
69
70
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */