Coverage Report

Created: 2026-06-07 08:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/poppler/splash/SplashClip.h
Line
Count
Source
1
//========================================================================
2
//
3
// SplashClip.h
4
//
5
//========================================================================
6
7
//========================================================================
8
//
9
// Modified under the Poppler project - http://poppler.freedesktop.org
10
//
11
// All changes made under the Poppler project to this file are licensed
12
// under GPL version 2 or later
13
//
14
// Copyright (C) 2010, 2018, 2021, 2025, 2026 Albert Astals Cid <aacid@kde.org>
15
// Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
16
// Copyright (C) 2019, 2025 Stefan BrĂ¼ns <stefan.bruens@rwth-aachen.de>
17
//
18
// To see a description of the changes please see the Changelog file that
19
// came with your tarball or type make ChangeLog if you are building from git
20
//
21
//========================================================================
22
23
#ifndef SPLASHCLIP_H
24
#define SPLASHCLIP_H
25
26
#include "SplashErrorCodes.h"
27
#include "SplashTypes.h"
28
29
#include <memory>
30
#include <vector>
31
32
class SplashPath;
33
class SplashXPath;
34
class SplashXPathScanner;
35
class SplashBitmap;
36
37
//------------------------------------------------------------------------
38
39
enum SplashClipResult
40
{
41
    splashClipAllInside,
42
    splashClipAllOutside,
43
    splashClipPartial
44
};
45
46
//------------------------------------------------------------------------
47
// SplashClip
48
//------------------------------------------------------------------------
49
50
class SplashClip
51
{
52
    class PrivateTag
53
    {
54
    };
55
56
public:
57
    // Create a clip, for the given rectangle.
58
    SplashClip(double x0, double y0, double x1, double y1, bool antialiasA);
59
60
    // Copy a clip.
61
3.76M
    std::unique_ptr<SplashClip> copy() const { return std::make_unique<SplashClip>(this); }
62
63
4.16M
    ~SplashClip() = default;
64
65
    SplashClip(const SplashClip &) = delete;
66
    SplashClip &operator=(const SplashClip &) = delete;
67
68
    // Reset the clip to a rectangle.
69
    void resetToRect(double x0, double y0, double x1, double y1);
70
71
    // Intersect the clip with a rectangle.
72
    SplashError clipToRect(double x0, double y0, double x1, double y1);
73
74
    // Intersect the clip with <path>.
75
    SplashError clipToPath(const SplashPath &path, const std::array<double, 6> &matrix, double flatness, bool eo);
76
77
    // Returns true if (<x>,<y>) is inside the clip.
78
    bool test(int x, int y) const
79
3.26G
    {
80
        // check the rectangle
81
3.26G
        if (x < xMinI || x > xMaxI || y < yMinI || y > yMaxI) {
82
494M
            return false;
83
494M
        }
84
85
        // check the paths
86
2.77G
        return testClipPaths(x, y);
87
3.26G
    }
88
89
    // Tests a rectangle against the clipping region.  Returns one of:
90
    //   - splashClipAllInside if the entire rectangle is inside the
91
    //     clipping region, i.e., all pixels in the rectangle are
92
    //     visible
93
    //   - splashClipAllOutside if the entire rectangle is outside the
94
    //     clipping region, i.e., all the pixels in the rectangle are
95
    //     clipped
96
    //   - splashClipPartial if the rectangle is part inside and part
97
    //     outside the clipping region
98
    SplashClipResult testRect(int rectXMin, int rectYMin, int rectXMax, int rectYMax) const;
99
100
    // Similar to testRect, but tests a horizontal span.
101
    SplashClipResult testSpan(int spanXMin, int spanXMax, int spanY);
102
103
    // Clips an anti-aliased line by setting pixels to zero.  On entry,
104
    // all non-zero pixels are between <x0> and <x1>.  This function
105
    // will update <x0> and <x1>.
106
    void clipAALine(SplashBitmap *aaBuf, int *x0, int *x1, int y, bool adjustVertLine = false);
107
108
    // Get the rectangle part of the clip region.
109
26.8k
    double getXMin() const { return xMin; }
110
26.8k
    double getXMax() const { return xMax; }
111
61.3k
    double getYMin() const { return yMin; }
112
79.7k
    double getYMax() const { return yMax; }
113
114
    // Get the rectangle part of the clip region, in integer coordinates.
115
131M
    int getXMinI() const { return xMinI; }
116
132M
    int getXMaxI() const { return xMaxI; }
117
13.0M
    int getYMinI() const { return yMinI; }
118
13.0M
    int getYMaxI() const { return yMaxI; }
119
120
    // Get the number of arbitrary paths used by the clip region.
121
27.9k
    int getNumPaths() { return scanners.size(); }
122
123
    explicit SplashClip(const SplashClip *clip, PrivateTag /*unused*/ = {});
124
125
protected:
126
    bool testClipPaths(int x, int y) const;
127
128
    bool antialias;
129
    double xMin, yMin, xMax, yMax;
130
    int xMinI, yMinI, xMaxI, yMaxI;
131
    std::vector<std::shared_ptr<SplashXPathScanner>> scanners;
132
};
133
134
#endif