beta-0.89.2
[luatex.git] / source / libs / poppler / poppler-src / splash / SplashClip.h
blob5c0fdba99a7de36fc51fcd34407f2d453e7fb143
1 //========================================================================
2 //
3 // SplashClip.h
4 //
5 //========================================================================
7 //========================================================================
8 //
9 // Modified under the Poppler project - http://poppler.freedesktop.org
11 // All changes made under the Poppler project to this file are licensed
12 // under GPL version 2 or later
14 // Copyright (C) 2010 Albert Astals Cid <aacid@kde.org>
15 // Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
17 // To see a description of the changes please see the Changelog file that
18 // came with your tarball or type make ChangeLog if you are building from git
20 //========================================================================
22 #ifndef SPLASHCLIP_H
23 #define SPLASHCLIP_H
25 #ifdef USE_GCC_PRAGMAS
26 #pragma interface
27 #endif
29 #include "SplashTypes.h"
30 #include "SplashMath.h"
31 #include "SplashXPathScanner.h"
33 class SplashPath;
34 class SplashXPath;
35 class SplashBitmap;
37 //------------------------------------------------------------------------
39 enum SplashClipResult {
40 splashClipAllInside,
41 splashClipAllOutside,
42 splashClipPartial
45 //------------------------------------------------------------------------
46 // SplashClip
47 //------------------------------------------------------------------------
49 class SplashClip {
50 public:
52 // Create a clip, for the given rectangle.
53 SplashClip(SplashCoord x0, SplashCoord y0,
54 SplashCoord x1, SplashCoord y1,
55 GBool antialiasA);
57 // Copy a clip.
58 SplashClip *copy() { return new SplashClip(this); }
60 ~SplashClip();
62 // Reset the clip to a rectangle.
63 void resetToRect(SplashCoord x0, SplashCoord y0,
64 SplashCoord x1, SplashCoord y1);
66 // Intersect the clip with a rectangle.
67 SplashError clipToRect(SplashCoord x0, SplashCoord y0,
68 SplashCoord x1, SplashCoord y1);
70 // Interesect the clip with <path>.
71 SplashError clipToPath(SplashPath *path, SplashCoord *matrix,
72 SplashCoord flatness, GBool eo);
74 // Returns true if (<x>,<y>) is inside the clip.
75 GBool test(int x, int y)
77 int i;
79 // check the rectangle
80 if (x < xMinI || x > xMaxI || y < yMinI || y > yMaxI) {
81 return gFalse;
84 // check the paths
85 if (antialias) {
86 for (i = 0; i < length; ++i) {
87 if (!scanners[i]->test(x * splashAASize, y * splashAASize)) {
88 return gFalse;
91 } else {
92 for (i = 0; i < length; ++i) {
93 if (!scanners[i]->test(x, y)) {
94 return gFalse;
99 return gTrue;
102 // Tests a rectangle against the clipping region. Returns one of:
103 // - splashClipAllInside if the entire rectangle is inside the
104 // clipping region, i.e., all pixels in the rectangle are
105 // visible
106 // - splashClipAllOutside if the entire rectangle is outside the
107 // clipping region, i.e., all the pixels in the rectangle are
108 // clipped
109 // - splashClipPartial if the rectangle is part inside and part
110 // outside the clipping region
111 SplashClipResult testRect(int rectXMin, int rectYMin,
112 int rectXMax, int rectYMax);
114 // Similar to testRect, but tests a horizontal span.
115 SplashClipResult testSpan(int spanXMin, int spanXMax, int spanY);
117 // Clips an anti-aliased line by setting pixels to zero. On entry,
118 // all non-zero pixels are between <x0> and <x1>. This function
119 // will update <x0> and <x1>.
120 void clipAALine(SplashBitmap *aaBuf, int *x0, int *x1, int y,
121 GBool adjustVertLine = gFalse);
123 // Get the rectangle part of the clip region.
124 SplashCoord getXMin() { return xMin; }
125 SplashCoord getXMax() { return xMax; }
126 SplashCoord getYMin() { return yMin; }
127 SplashCoord getYMax() { return yMax; }
129 // Get the rectangle part of the clip region, in integer coordinates.
130 int getXMinI() { return xMinI; }
131 int getXMaxI() { return xMaxI; }
132 int getYMinI() { return yMinI; }
133 int getYMaxI() { return yMaxI; }
135 // Get the number of arbitrary paths used by the clip region.
136 int getNumPaths() { return length; }
138 protected:
140 SplashClip(SplashClip *clip);
141 void grow(int nPaths);
143 GBool antialias;
144 SplashCoord xMin, yMin, xMax, yMax;
145 int xMinI, yMinI, xMaxI, yMaxI;
146 SplashXPath **paths;
147 Guchar *flags;
148 SplashXPathScanner **scanners;
149 int length, size;
152 #endif