SplashXPathScanner.h 3.67 KB
Newer Older
Kristian Høgsberg's avatar
Kristian Høgsberg committed
1 2 3 4 5 6
//========================================================================
//
// SplashXPathScanner.h
//
//========================================================================

7 8 9 10 11 12 13
//========================================================================
//
// Modified under the Poppler project - http://poppler.freedesktop.org
//
// All changes made under the Poppler project to this file are licensed
// under GPL version 2 or later
//
Albert Astals Cid's avatar
Albert Astals Cid committed
14
// Copyright (C) 2013, 2014 Thomas Freitag <Thomas.Freitag@alfa.de>
15
// Copyright (C) 2018 Albert Astals Cid <aacid@kde.org>
Albert Astals Cid's avatar
Albert Astals Cid committed
16
// Copyright (C) 2018 Stefan Brüns <stefan.bruens@rwth-aachen.de>
17 18 19 20 21 22
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
//
//========================================================================

Kristian Høgsberg's avatar
Kristian Høgsberg committed
23 24 25 26 27
#ifndef SPLASHXPATHSCANNER_H
#define SPLASHXPATHSCANNER_H

#include "SplashTypes.h"

28 29
#include <vector>

Kristian Høgsberg's avatar
Kristian Høgsberg committed
30
class SplashXPath;
31
class SplashBitmap;
32 33 34 35 36 37

struct SplashIntersect {
  int y;
  int x0, x1;			// intersection of segment with [y, y+1)
  int count;			// EO/NZWN counter increment
};
Kristian Høgsberg's avatar
Kristian Høgsberg committed
38 39 40 41 42 43 44 45 46

//------------------------------------------------------------------------
// SplashXPathScanner
//------------------------------------------------------------------------

class SplashXPathScanner {
public:

  // Create a new SplashXPathScanner object.  <xPathA> must be sorted.
47
  SplashXPathScanner(SplashXPath *xPathA, bool eoA,
48
		     int clipYMin, int clipYMax);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
49 50 51

  ~SplashXPathScanner();

52 53 54
  SplashXPathScanner(const SplashXPathScanner&) = delete;
  SplashXPathScanner& operator=(const SplashXPathScanner&) = delete;

Kristian Høgsberg's avatar
Kristian Høgsberg committed
55 56 57 58
  // Return the path's bounding box.
  void getBBox(int *xMinA, int *yMinA, int *xMaxA, int *yMaxA)
    { *xMinA = xMin; *yMinA = yMin; *xMaxA = xMax; *yMaxA = yMax; }

59 60 61
  // Return the path's bounding box.
  void getBBoxAA(int *xMinA, int *yMinA, int *xMaxA, int *yMaxA);

62 63
  // Returns true if at least part of the path was outside the
  // clipYMin/clipYMax bounds passed to the constructor.
64
  bool hasPartialClip() { return partialClip; }
65

Kristian Høgsberg's avatar
Kristian Høgsberg committed
66 67 68 69
  // Return the min/max x values for the span at <y>.
  void getSpanBounds(int y, int *spanXMin, int *spanXMax);

  // Returns true if (<x>,<y>) is inside the path.
70
  bool test(int x, int y);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
71 72 73

  // Returns true if the entire span ([<x0>,<x1>], <y>) is inside the
  // path.
74
  bool testSpan(int x0, int x1, int y);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
75

76 77
  // Renders one anti-aliased line into <aaBuf>.  Returns the min and
  // max x coordinates with non-zero pixels in <x0> and <x1>.
78
  void renderAALine(SplashBitmap *aaBuf, int *x0, int *x1, int y,
79
    bool adjustVertLine = false);
80 81 82 83 84 85

  // Clips an anti-aliased line by setting pixels to zero.  On entry,
  // all non-zero pixels are between <x0> and <x1>.  This function
  // will update <x0> and <x1>.
  void clipAALine(SplashBitmap *aaBuf, int *x0, int *x1, int y);

Kristian Høgsberg's avatar
Kristian Høgsberg committed
86 87
private:

88
  void computeIntersections();
89
  bool addIntersection(double segYMin, double segYMax,
90
		       int y, int x0, int x1, int count);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
91 92

  SplashXPath *xPath;
93
  bool eo;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
94
  int xMin, yMin, xMax, yMax;
95
  bool partialClip;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
96

97 98
  typedef std::vector<SplashIntersect> IntersectionLine;
  std::vector<IntersectionLine> allIntersections;
99 100 101 102 103 104 105 106 107 108

  friend class SplashXPathScanIterator;
};

class SplashXPathScanIterator {
public:
  SplashXPathScanIterator(const SplashXPathScanner &scanner, int y);

  // Returns the next span inside the path at the current y position
  // Returns false if there are no more spans.
109
  bool getNextSpan(int *x0, int *x1);
110 111

private:
112 113 114 115
  typedef std::vector<SplashIntersect> IntersectionLine;
  const IntersectionLine &line;

  size_t interIdx;	// current index into <line>
116
  int interCount;	// current EO/NZWN counter
117
  const bool eo;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
118 119 120
};

#endif