Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //========================================================================
0002 //
0003 // SplashXPathScanner.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) 2013, 2014, 2021 Thomas Freitag <Thomas.Freitag@alfa.de>
0015 // Copyright (C) 2018, 2021 Albert Astals Cid <aacid@kde.org>
0016 // Copyright (C) 2018 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 SPLASHXPATHSCANNER_H
0024 #define SPLASHXPATHSCANNER_H
0025 
0026 #include "SplashTypes.h"
0027 
0028 #include <poppler-config.h>
0029 
0030 #ifdef USE_BOOST_HEADERS
0031 #    include <boost/container/small_vector.hpp>
0032 #endif
0033 
0034 #include <vector>
0035 
0036 class SplashXPath;
0037 class SplashBitmap;
0038 
0039 struct SplashIntersect
0040 {
0041     int y;
0042     int x0, x1; // intersection of segment with [y, y+1)
0043     int count; // EO/NZWN counter increment
0044 };
0045 
0046 //------------------------------------------------------------------------
0047 // SplashXPathScanner
0048 //------------------------------------------------------------------------
0049 
0050 class SplashXPathScanner
0051 {
0052 public:
0053     // Create a new SplashXPathScanner object.  <xPathA> must be sorted.
0054     SplashXPathScanner(const SplashXPath &xPath, bool eoA, int clipYMin, int clipYMax);
0055 
0056     ~SplashXPathScanner();
0057 
0058     SplashXPathScanner(const SplashXPathScanner &) = delete;
0059     SplashXPathScanner &operator=(const SplashXPathScanner &) = delete;
0060 
0061     // Return the path's bounding box.
0062     void getBBox(int *xMinA, int *yMinA, int *xMaxA, int *yMaxA) const
0063     {
0064         *xMinA = xMin;
0065         *yMinA = yMin;
0066         *xMaxA = xMax;
0067         *yMaxA = yMax;
0068     }
0069 
0070     // Return the path's bounding box.
0071     void getBBoxAA(int *xMinA, int *yMinA, int *xMaxA, int *yMaxA) const;
0072 
0073     // Returns true if at least part of the path was outside the
0074     // clipYMin/clipYMax bounds passed to the constructor.
0075     bool hasPartialClip() const { return partialClip; }
0076 
0077     // Return the min/max x values for the span at <y>.
0078     void getSpanBounds(int y, int *spanXMin, int *spanXMax) const;
0079 
0080     // Returns true if (<x>,<y>) is inside the path.
0081     bool test(int x, int y) const;
0082 
0083     // Returns true if the entire span ([<x0>,<x1>], <y>) is inside the
0084     // path.
0085     bool testSpan(int x0, int x1, int y) const;
0086 
0087     // Renders one anti-aliased line into <aaBuf>.  Returns the min and
0088     // max x coordinates with non-zero pixels in <x0> and <x1>.
0089     void renderAALine(SplashBitmap *aaBuf, int *x0, int *x1, int y, bool adjustVertLine = false) const;
0090 
0091     // Clips an anti-aliased line by setting pixels to zero.  On entry,
0092     // all non-zero pixels are between <x0> and <x1>.  This function
0093     // will update <x0> and <x1>.
0094     void clipAALine(SplashBitmap *aaBuf, int *x0, int *x1, int y) const;
0095 
0096 private:
0097     void computeIntersections(const SplashXPath &xPath);
0098     bool addIntersection(double segYMin, double segYMax, int y, int x0, int x1, int count);
0099 
0100     bool eo;
0101     int xMin, yMin, xMax, yMax;
0102     bool partialClip;
0103 
0104 #ifdef USE_BOOST_HEADERS
0105     typedef boost::container::small_vector<SplashIntersect, 4> IntersectionLine;
0106 #else
0107     typedef std::vector<SplashIntersect> IntersectionLine;
0108 #endif
0109     std::vector<IntersectionLine> allIntersections;
0110 
0111     friend class SplashXPathScanIterator;
0112 };
0113 
0114 class SplashXPathScanIterator
0115 {
0116 public:
0117     SplashXPathScanIterator(const SplashXPathScanner &scanner, int y);
0118 
0119     // Returns the next span inside the path at the current y position
0120     // Returns false if there are no more spans.
0121     bool getNextSpan(int *x0, int *x1);
0122 
0123 private:
0124 #ifdef USE_BOOST_HEADERS
0125     typedef boost::container::small_vector<SplashIntersect, 4> IntersectionLine;
0126 #else
0127     typedef std::vector<SplashIntersect> IntersectionLine;
0128 #endif
0129     const IntersectionLine &line;
0130 
0131     size_t interIdx; // current index into <line>
0132     int interCount; // current EO/NZWN counter
0133     const bool eo;
0134 };
0135 
0136 #endif