1 //========================================================================
2 //
3 // SplashXPathScanner.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) 2013, 2014 Thomas Freitag <Thomas.Freitag@alfa.de>
15 //
16 // To see a description of the changes please see the Changelog file that
17 // came with your tarball or type make ChangeLog if you are building from git
18 //
19 //========================================================================
20 
21 #ifndef SPLASHXPATHSCANNER_H
22 #define SPLASHXPATHSCANNER_H
23 
24 #ifdef USE_GCC_PRAGMAS
25 #pragma interface
26 #endif
27 
28 #include "SplashTypes.h"
29 
30 class SplashXPath;
31 class SplashBitmap;
32 struct SplashIntersect;
33 
34 //------------------------------------------------------------------------
35 // SplashXPathScanner
36 //------------------------------------------------------------------------
37 
38 class SplashXPathScanner {
39 public:
40 
41   // Create a new SplashXPathScanner object.  <xPathA> must be sorted.
42   SplashXPathScanner(SplashXPath *xPathA, GBool eoA,
43 		     int clipYMin, int clipYMax);
44 
45   ~SplashXPathScanner();
46 
47   // Return the path's bounding box.
getBBox(int * xMinA,int * yMinA,int * xMaxA,int * yMaxA)48   void getBBox(int *xMinA, int *yMinA, int *xMaxA, int *yMaxA)
49     { *xMinA = xMin; *yMinA = yMin; *xMaxA = xMax; *yMaxA = yMax; }
50 
51   // Return the path's bounding box.
52   void getBBoxAA(int *xMinA, int *yMinA, int *xMaxA, int *yMaxA);
53 
54   // Returns true if at least part of the path was outside the
55   // clipYMin/clipYMax bounds passed to the constructor.
hasPartialClip()56   GBool hasPartialClip() { return partialClip; }
57 
58   // Return the min/max x values for the span at <y>.
59   void getSpanBounds(int y, int *spanXMin, int *spanXMax);
60 
61   // Returns true if (<x>,<y>) is inside the path.
62   GBool test(int x, int y);
63 
64   // Returns true if the entire span ([<x0>,<x1>], <y>) is inside the
65   // path.
66   GBool testSpan(int x0, int x1, int y);
67 
68   // Returns the next span inside the path at <y>.  If <y> is
69   // different than the previous call to getNextSpan, this returns the
70   // first span at <y>; otherwise it returns the next span (relative
71   // to the previous call to getNextSpan).  Returns false if there are
72   // no more spans at <y>.
73   GBool getNextSpan(int y, int *x0, int *x1);
74 
75   // Renders one anti-aliased line into <aaBuf>.  Returns the min and
76   // max x coordinates with non-zero pixels in <x0> and <x1>.
77   void renderAALine(SplashBitmap *aaBuf, int *x0, int *x1, int y,
78     GBool adjustVertLine = gFalse);
79 
80   // Clips an anti-aliased line by setting pixels to zero.  On entry,
81   // all non-zero pixels are between <x0> and <x1>.  This function
82   // will update <x0> and <x1>.
83   void clipAALine(SplashBitmap *aaBuf, int *x0, int *x1, int y);
84 
85 private:
86 
87   void computeIntersections();
88   GBool addIntersection(double segYMin, double segYMax,
89 		       Guint segFlags,
90 		       int y, int x0, int x1);
91 
92   SplashXPath *xPath;
93   GBool eo;
94   int xMin, yMin, xMax, yMax;
95   GBool partialClip;
96 
97   SplashIntersect *allInter;	// array of intersections
98   int allInterLen;		// number of intersections in <allInter>
99   int allInterSize;		// size of the <allInter> array
100   int *inter;			// indexes into <allInter> for each y value
101   int interY;			// current y value - used by getNextSpan
102   int interIdx;			// current index into <inter> - used by
103 				//   getNextSpan
104   int interCount;		// current EO/NZWN counter - used by
105 				//   getNextSpan
106 };
107 
108 #endif
109