Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-11 10:26:10

0001 //========================================================================
0002 //
0003 // SplashClip.h
0004 //
0005 //========================================================================
0006 
0007 //========================================================================
0008 //
0009 // Modified under the Poppler project - http://poppler.freedesktop.org
0010 //
0011 // All changes made under the Poppler project to this file are licensed
0012 // under GPL version 2 or later
0013 //
0014 // Copyright (C) 2010, 2018, 2021 Albert Astals Cid <aacid@kde.org>
0015 // Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
0016 // Copyright (C) 2019 Stefan BrĂ¼ns <stefan.bruens@rwth-aachen.de>
0017 //
0018 // To see a description of the changes please see the Changelog file that
0019 // came with your tarball or type make ChangeLog if you are building from git
0020 //
0021 //========================================================================
0022 
0023 #ifndef SPLASHCLIP_H
0024 #define SPLASHCLIP_H
0025 
0026 #include "SplashTypes.h"
0027 
0028 #include <memory>
0029 #include <vector>
0030 
0031 class SplashPath;
0032 class SplashXPath;
0033 class SplashXPathScanner;
0034 class SplashBitmap;
0035 
0036 //------------------------------------------------------------------------
0037 
0038 enum SplashClipResult
0039 {
0040     splashClipAllInside,
0041     splashClipAllOutside,
0042     splashClipPartial
0043 };
0044 
0045 //------------------------------------------------------------------------
0046 // SplashClip
0047 //------------------------------------------------------------------------
0048 
0049 class SplashClip
0050 {
0051 public:
0052     // Create a clip, for the given rectangle.
0053     SplashClip(SplashCoord x0, SplashCoord y0, SplashCoord x1, SplashCoord y1, bool antialiasA);
0054 
0055     // Copy a clip.
0056     SplashClip *copy() const { return new SplashClip(this); }
0057 
0058     ~SplashClip();
0059 
0060     SplashClip(const SplashClip &) = delete;
0061     SplashClip &operator=(const SplashClip &) = delete;
0062 
0063     // Reset the clip to a rectangle.
0064     void resetToRect(SplashCoord x0, SplashCoord y0, SplashCoord x1, SplashCoord y1);
0065 
0066     // Intersect the clip with a rectangle.
0067     SplashError clipToRect(SplashCoord x0, SplashCoord y0, SplashCoord x1, SplashCoord y1);
0068 
0069     // Intersect the clip with <path>.
0070     SplashError clipToPath(SplashPath *path, SplashCoord *matrix, SplashCoord flatness, bool eo);
0071 
0072     // Returns true if (<x>,<y>) is inside the clip.
0073     bool test(int x, int y)
0074     {
0075         // check the rectangle
0076         if (x < xMinI || x > xMaxI || y < yMinI || y > yMaxI) {
0077             return false;
0078         }
0079 
0080         // check the paths
0081         return testClipPaths(x, y);
0082     }
0083 
0084     // Tests a rectangle against the clipping region.  Returns one of:
0085     //   - splashClipAllInside if the entire rectangle is inside the
0086     //     clipping region, i.e., all pixels in the rectangle are
0087     //     visible
0088     //   - splashClipAllOutside if the entire rectangle is outside the
0089     //     clipping region, i.e., all the pixels in the rectangle are
0090     //     clipped
0091     //   - splashClipPartial if the rectangle is part inside and part
0092     //     outside the clipping region
0093     SplashClipResult testRect(int rectXMin, int rectYMin, int rectXMax, int rectYMax);
0094 
0095     // Similar to testRect, but tests a horizontal span.
0096     SplashClipResult testSpan(int spanXMin, int spanXMax, int spanY);
0097 
0098     // Clips an anti-aliased line by setting pixels to zero.  On entry,
0099     // all non-zero pixels are between <x0> and <x1>.  This function
0100     // will update <x0> and <x1>.
0101     void clipAALine(SplashBitmap *aaBuf, int *x0, int *x1, int y, bool adjustVertLine = false);
0102 
0103     // Get the rectangle part of the clip region.
0104     SplashCoord getXMin() { return xMin; }
0105     SplashCoord getXMax() { return xMax; }
0106     SplashCoord getYMin() { return yMin; }
0107     SplashCoord getYMax() { return yMax; }
0108 
0109     // Get the rectangle part of the clip region, in integer coordinates.
0110     int getXMinI() { return xMinI; }
0111     int getXMaxI() { return xMaxI; }
0112     int getYMinI() { return yMinI; }
0113     int getYMaxI() { return yMaxI; }
0114 
0115     // Get the number of arbitrary paths used by the clip region.
0116     int getNumPaths() { return length; }
0117 
0118 protected:
0119     explicit SplashClip(const SplashClip *clip);
0120     void grow(int nPaths);
0121     bool testClipPaths(int x, int y);
0122 
0123     bool antialias;
0124     SplashCoord xMin, yMin, xMax, yMax;
0125     int xMinI, yMinI, xMaxI, yMaxI;
0126     unsigned char *flags;
0127     std::vector<std::shared_ptr<SplashXPathScanner>> scanners;
0128     int length, size;
0129 };
0130 
0131 #endif