~ubuntu-branches/debian/experimental/cups-filters/experimental

« back to all changes in this revision

Viewing changes to filter/pdftoopvp/oprs/OPVPSplashClip.cxx

Tags: upstream-1.0.20
ImportĀ upstreamĀ versionĀ 1.0.20

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <config.h>
 
2
#include "splash/SplashXPathScanner.h"
 
3
#include "OPVPSplashClip.h"
 
4
 
 
5
void OPVPSplashClip::getBBox(int *xMinA, int *yMinA, int *xMaxA, int *yMaxA)
 
6
{
 
7
  int i;
 
8
  int cxMin = splashRound(xMin), cyMin = splashRound(yMin);
 
9
  int cxMax = splashRound(xMax), cyMax = splashRound(yMax);
 
10
  int txMin, tyMin, txMax, tyMax;
 
11
 
 
12
  for (i = 0; i < length; ++i) {
 
13
    scanners[i]->getBBox(&txMin,&tyMin,&txMax,&tyMax);
 
14
    if (txMin > cxMin) cxMin = txMin;
 
15
    if (tyMin > cyMin) cyMin = tyMin;
 
16
    if (txMax < cxMax) cxMax = txMax;
 
17
    if (tyMax < cyMax) cyMax = tyMax;
 
18
  }
 
19
  *xMinA = cxMin;
 
20
  *yMinA = cyMin;
 
21
  *xMaxA = cxMax;
 
22
  *yMaxA = cyMax;
 
23
}
 
24
 
 
25
OPVPSplashPath *OPVPSplashClip::makePath()
 
26
{
 
27
  int i,j;
 
28
  int y, x0, x1;
 
29
  int txMin, tyMin, txMax, tyMax;
 
30
  int tsxMin, tsyMin, tsxMax, tsyMax;
 
31
  Guchar *cbuf,*tbuf;
 
32
  int blen;
 
33
  OPVPSplashPath *p = new OPVPSplashPath();
 
34
 
 
35
  getBBox(&txMin,&tyMin,&txMax,&tyMax);
 
36
  if (txMin > txMax || tyMin > tyMax) return p;
 
37
  blen = txMax-txMin+1;
 
38
  cbuf = new Guchar[blen];
 
39
  tbuf = new Guchar[blen];
 
40
  
 
41
  /* dummy call to clear state */
 
42
  scanners[0]->getBBox(&tsxMin,&tsyMin,&tsxMax,&tsyMax);
 
43
  scanners[0]->getNextSpan(tsyMin-2,&x0,&x1);
 
44
 
 
45
  for (y = tyMin;y <= tyMax;y++) {
 
46
    /* clear buffer */
 
47
    for (i = 0;i < blen;i++) {
 
48
      cbuf[i] = 0;
 
49
    }
 
50
    while (scanners[0]->getNextSpan(y,&x0,&x1)) {
 
51
      if (x0 < txMin) x0 = txMin;
 
52
      if (x1 > txMax) x1 = txMax;
 
53
      for (i = x0;i < x1;i++) {
 
54
        cbuf[i-txMin] = 1;
 
55
      }
 
56
    }
 
57
    for (j = 1; j < length; ++j) {
 
58
      /* clear buffer */
 
59
      for (i = 0;i < blen;i++) {
 
60
        tbuf[i] = 0;
 
61
      }
 
62
      while (scanners[j]->getNextSpan(y,&x0,&x1)) {
 
63
        if (x0 < txMin) x0 = txMin;
 
64
        if (x1 > txMax) x1 = txMax;
 
65
        for (i = x0;i < x1;i++) {
 
66
          tbuf[i-txMin] = 1;
 
67
        }
 
68
      }
 
69
      /* and buffer */
 
70
      for (i = 0;i < blen;i++) {
 
71
        cbuf[i] &= tbuf[i];
 
72
      }
 
73
    }
 
74
    /* scan buffer and add path */
 
75
    for (i = 0;i < blen;i = j) {
 
76
      if (cbuf[i] != 0) {
 
77
        p->moveTo(i+txMin,y);
 
78
        for (j = i+1;j < blen && cbuf[j] != 0;j++);
 
79
        p->lineTo(j-1+txMin,y);
 
80
        p->lineTo(j-1+txMin,y+1);
 
81
        p->lineTo(i+txMin,y+1);
 
82
        p->close();
 
83
      } else {
 
84
        j = i+1;
 
85
      }
 
86
    }
 
87
  }
 
88
  delete[] cbuf;
 
89
  delete[] tbuf;
 
90
  return p;
 
91
}