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 Albert Astals Cid <aacid@kde.org> |
15 | // Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de> |
16 | // Copyright (C) 2019 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 "SplashTypes.h" |
27 | |
28 | #include <memory> |
29 | #include <vector> |
30 | |
31 | class SplashPath; |
32 | class SplashXPath; |
33 | class SplashXPathScanner; |
34 | class SplashBitmap; |
35 | |
36 | //------------------------------------------------------------------------ |
37 | |
38 | enum SplashClipResult |
39 | { |
40 | splashClipAllInside, |
41 | splashClipAllOutside, |
42 | splashClipPartial |
43 | }; |
44 | |
45 | //------------------------------------------------------------------------ |
46 | // SplashClip |
47 | //------------------------------------------------------------------------ |
48 | |
49 | class SplashClip |
50 | { |
51 | public: |
52 | // Create a clip, for the given rectangle. |
53 | SplashClip(SplashCoord x0, SplashCoord y0, SplashCoord x1, SplashCoord y1, bool antialiasA); |
54 | |
55 | // Copy a clip. |
56 | SplashClip *copy() const { return new SplashClip(this); } |
57 | |
58 | ~SplashClip(); |
59 | |
60 | SplashClip(const SplashClip &) = delete; |
61 | SplashClip &operator=(const SplashClip &) = delete; |
62 | |
63 | // Reset the clip to a rectangle. |
64 | void resetToRect(SplashCoord x0, SplashCoord y0, SplashCoord x1, SplashCoord y1); |
65 | |
66 | // Intersect the clip with a rectangle. |
67 | SplashError clipToRect(SplashCoord x0, SplashCoord y0, SplashCoord x1, SplashCoord y1); |
68 | |
69 | // Intersect the clip with <path>. |
70 | SplashError clipToPath(SplashPath *path, SplashCoord *matrix, SplashCoord flatness, bool eo); |
71 | |
72 | // Returns true if (<x>,<y>) is inside the clip. |
73 | bool test(int x, int y) |
74 | { |
75 | // check the rectangle |
76 | if (x < xMinI || x > xMaxI || y < yMinI || y > yMaxI) { |
77 | return false; |
78 | } |
79 | |
80 | // check the paths |
81 | return testClipPaths(x, y); |
82 | } |
83 | |
84 | // Tests a rectangle against the clipping region. Returns one of: |
85 | // - splashClipAllInside if the entire rectangle is inside the |
86 | // clipping region, i.e., all pixels in the rectangle are |
87 | // visible |
88 | // - splashClipAllOutside if the entire rectangle is outside the |
89 | // clipping region, i.e., all the pixels in the rectangle are |
90 | // clipped |
91 | // - splashClipPartial if the rectangle is part inside and part |
92 | // outside the clipping region |
93 | SplashClipResult testRect(int rectXMin, int rectYMin, int rectXMax, int rectYMax); |
94 | |
95 | // Similar to testRect, but tests a horizontal span. |
96 | SplashClipResult testSpan(int spanXMin, int spanXMax, int spanY); |
97 | |
98 | // Clips an anti-aliased line by setting pixels to zero. On entry, |
99 | // all non-zero pixels are between <x0> and <x1>. This function |
100 | // will update <x0> and <x1>. |
101 | void clipAALine(SplashBitmap *aaBuf, int *x0, int *x1, int y, bool adjustVertLine = false); |
102 | |
103 | // Get the rectangle part of the clip region. |
104 | SplashCoord getXMin() { return xMin; } |
105 | SplashCoord getXMax() { return xMax; } |
106 | SplashCoord getYMin() { return yMin; } |
107 | SplashCoord getYMax() { return yMax; } |
108 | |
109 | // Get the rectangle part of the clip region, in integer coordinates. |
110 | int getXMinI() { return xMinI; } |
111 | int getXMaxI() { return xMaxI; } |
112 | int getYMinI() { return yMinI; } |
113 | int getYMaxI() { return yMaxI; } |
114 | |
115 | // Get the number of arbitrary paths used by the clip region. |
116 | int getNumPaths() { return length; } |
117 | |
118 | protected: |
119 | explicit SplashClip(const SplashClip *clip); |
120 | void grow(int nPaths); |
121 | bool testClipPaths(int x, int y); |
122 | |
123 | bool antialias; |
124 | SplashCoord xMin, yMin, xMax, yMax; |
125 | int xMinI, yMinI, xMaxI, yMaxI; |
126 | unsigned char *flags; |
127 | std::vector<std::shared_ptr<SplashXPathScanner>> scanners; |
128 | int length, size; |
129 | }; |
130 | |
131 | #endif |
132 | |