SplashClip.h 4.34 KB
Newer Older
Kristian Høgsberg's avatar
Kristian Høgsberg committed
1 2 3 4 5 6
//========================================================================
//
// SplashClip.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
//
14
// Copyright (C) 2010, 2018 Albert Astals Cid <aacid@kde.org>
15
// Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
16 17 18 19 20 21
//
// 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
22 23 24 25 26 27 28 29
#ifndef SPLASHCLIP_H
#define SPLASHCLIP_H

#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif

#include "SplashTypes.h"
30
#include "SplashMath.h"
31
#include "SplashXPathScanner.h"
Kristian Høgsberg's avatar
Kristian Høgsberg committed
32 33 34

class SplashPath;
class SplashXPath;
35
class SplashBitmap;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

//------------------------------------------------------------------------

enum SplashClipResult {
  splashClipAllInside,
  splashClipAllOutside,
  splashClipPartial
};

//------------------------------------------------------------------------
// SplashClip
//------------------------------------------------------------------------

class SplashClip {
public:

  // Create a clip, for the given rectangle.
  SplashClip(SplashCoord x0, SplashCoord y0,
54 55
	     SplashCoord x1, SplashCoord y1,
	     GBool antialiasA);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
56 57 58 59 60 61

  // Copy a clip.
  SplashClip *copy() { return new SplashClip(this); }

  ~SplashClip();

62 63 64
  SplashClip(const SplashClip &) = delete;
  SplashClip& operator=(const SplashClip &) = delete;

Kristian Høgsberg's avatar
Kristian Høgsberg committed
65 66 67 68 69 70 71 72 73
  // Reset the clip to a rectangle.
  void resetToRect(SplashCoord x0, SplashCoord y0,
		   SplashCoord x1, SplashCoord y1);

  // Intersect the clip with a rectangle.
  SplashError clipToRect(SplashCoord x0, SplashCoord y0,
			 SplashCoord x1, SplashCoord y1);

  // Interesect the clip with <path>.
74 75
  SplashError clipToPath(SplashPath *path, SplashCoord *matrix,
			 SplashCoord flatness, GBool eo);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
76 77

  // Returns true if (<x>,<y>) is inside the clip.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
  GBool test(int x, int y)
  {
    int i;

    // check the rectangle
    if (x < xMinI || x > xMaxI || y < yMinI || y > yMaxI) {
      return gFalse;
    }

    // check the paths
    if (antialias) {
      for (i = 0; i < length; ++i) {
        if (!scanners[i]->test(x * splashAASize, y * splashAASize)) {
	  return gFalse;
        }
      }
    } else {
      for (i = 0; i < length; ++i) {
        if (!scanners[i]->test(x, y)) {
	  return gFalse;
        }
      }
    }

    return gTrue;
  }
Kristian Høgsberg's avatar
Kristian Høgsberg committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119

  // Tests a rectangle against the clipping region.  Returns one of:
  //   - splashClipAllInside if the entire rectangle is inside the
  //     clipping region, i.e., all pixels in the rectangle are
  //     visible
  //   - splashClipAllOutside if the entire rectangle is outside the
  //     clipping region, i.e., all the pixels in the rectangle are
  //     clipped
  //   - splashClipPartial if the rectangle is part inside and part
  //     outside the clipping region
  SplashClipResult testRect(int rectXMin, int rectYMin,
			    int rectXMax, int rectYMax);

  // Similar to testRect, but tests a horizontal span.
  SplashClipResult testSpan(int spanXMin, int spanXMax, int spanY);

120 121 122
  // 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>.
123 124
  void clipAALine(SplashBitmap *aaBuf, int *x0, int *x1, int y,
    GBool adjustVertLine = gFalse);
125

126 127 128 129 130 131
  // Get the rectangle part of the clip region.
  SplashCoord getXMin() { return xMin; }
  SplashCoord getXMax() { return xMax; }
  SplashCoord getYMin() { return yMin; }
  SplashCoord getYMax() { return yMax; }

132 133 134 135 136
  // Get the rectangle part of the clip region, in integer coordinates.
  int getXMinI() { return xMinI; }
  int getXMaxI() { return xMaxI; }
  int getYMinI() { return yMinI; }
  int getYMaxI() { return yMaxI; }
137 138 139 140

  // Get the number of arbitrary paths used by the clip region.
  int getNumPaths() { return length; }

141
protected:
Kristian Høgsberg's avatar
Kristian Høgsberg committed
142 143 144 145

  SplashClip(SplashClip *clip);
  void grow(int nPaths);

146 147 148
  GBool antialias;
  SplashCoord xMin, yMin, xMax, yMax;
  int xMinI, yMinI, xMaxI, yMaxI;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
149 150 151 152 153 154 155
  SplashXPath **paths;
  Guchar *flags;
  SplashXPathScanner **scanners;
  int length, size;
};

#endif