Coverage Report

Created: 2022-03-21 07:20

/src/xpdf-4.03/splash/SplashState.cc
Line
Count
Source (jump to first uncovered line)
1
//========================================================================
2
//
3
// SplashState.cc
4
//
5
// Copyright 2003-2013 Glyph & Cog, LLC
6
//
7
//========================================================================
8
9
#include <aconf.h>
10
11
#ifdef USE_GCC_PRAGMAS
12
#pragma implementation
13
#endif
14
15
#include <string.h>
16
#include "gmem.h"
17
#include "gmempp.h"
18
#include "SplashPattern.h"
19
#include "SplashScreen.h"
20
#include "SplashClip.h"
21
#include "SplashBitmap.h"
22
#include "SplashState.h"
23
24
//------------------------------------------------------------------------
25
// SplashState
26
//------------------------------------------------------------------------
27
28
// number of components in each color mode
29
int splashColorModeNComps[] = {
30
  1, 1, 3, 3
31
#if SPLASH_CMYK
32
  , 4
33
#endif
34
};
35
36
SplashState::SplashState(int width, int height, GBool vectorAntialias,
37
0
       SplashScreenParams *screenParams) {
38
0
  SplashColor color;
39
0
  int i;
40
41
0
  matrix[0] = 1;  matrix[1] = 0;
42
0
  matrix[2] = 0;  matrix[3] = 1;
43
0
  matrix[4] = 0;  matrix[5] = 0;
44
0
  memset(&color, 0, sizeof(SplashColor));
45
0
  strokePattern = new SplashSolidColor(color);
46
0
  fillPattern = new SplashSolidColor(color);
47
0
  screen = new SplashScreen(screenParams);
48
0
  blendFunc = NULL;
49
0
  strokeAlpha = 1;
50
0
  fillAlpha = 1;
51
0
  lineWidth = 1;
52
0
  lineCap = splashLineCapButt;
53
0
  lineJoin = splashLineJoinMiter;
54
0
  miterLimit = 10;
55
0
  flatness = 1;
56
0
  lineDash = NULL;
57
0
  lineDashLength = 0;
58
0
  lineDashPhase = 0;
59
0
  strokeAdjust = splashStrokeAdjustOff;
60
0
  clip = new SplashClip(0, 0, width, height);
61
0
  clipIsShared = gFalse;
62
0
  softMask = NULL;
63
0
  deleteSoftMask = gFalse;
64
0
  inNonIsolatedGroup = gFalse;
65
0
  inKnockoutGroup = gFalse;
66
0
  for (i = 0; i < 256; ++i) {
67
0
    rgbTransferR[i] = (Guchar)i;
68
0
    rgbTransferG[i] = (Guchar)i;
69
0
    rgbTransferB[i] = (Guchar)i;
70
0
    grayTransfer[i] = (Guchar)i;
71
0
#if SPLASH_CMYK
72
0
    cmykTransferC[i] = (Guchar)i;
73
0
    cmykTransferM[i] = (Guchar)i;
74
0
    cmykTransferY[i] = (Guchar)i;
75
0
    cmykTransferK[i] = (Guchar)i;
76
0
#endif
77
0
  }
78
0
  overprintMask = 0xffffffff;
79
0
  enablePathSimplification = gFalse;
80
0
  next = NULL;
81
0
}
82
83
SplashState::SplashState(int width, int height, GBool vectorAntialias,
84
0
       SplashScreen *screenA) {
85
0
  SplashColor color;
86
0
  int i;
87
88
0
  matrix[0] = 1;  matrix[1] = 0;
89
0
  matrix[2] = 0;  matrix[3] = 1;
90
0
  matrix[4] = 0;  matrix[5] = 0;
91
0
  memset(&color, 0, sizeof(SplashColor));
92
0
  strokePattern = new SplashSolidColor(color);
93
0
  fillPattern = new SplashSolidColor(color);
94
0
  screen = screenA->copy();
95
0
  blendFunc = NULL;
96
0
  strokeAlpha = 1;
97
0
  fillAlpha = 1;
98
0
  lineWidth = 1;
99
0
  lineCap = splashLineCapButt;
100
0
  lineJoin = splashLineJoinMiter;
101
0
  miterLimit = 10;
102
0
  flatness = 1;
103
0
  lineDash = NULL;
104
0
  lineDashLength = 0;
105
0
  lineDashPhase = 0;
106
0
  strokeAdjust = splashStrokeAdjustOff;
107
0
  clip = new SplashClip(0, 0, width, height);
108
0
  clipIsShared = gFalse;
109
0
  softMask = NULL;
110
0
  deleteSoftMask = gFalse;
111
0
  inNonIsolatedGroup = gFalse;
112
0
  inKnockoutGroup = gFalse;
113
0
  for (i = 0; i < 256; ++i) {
114
0
    rgbTransferR[i] = (Guchar)i;
115
0
    rgbTransferG[i] = (Guchar)i;
116
0
    rgbTransferB[i] = (Guchar)i;
117
0
    grayTransfer[i] = (Guchar)i;
118
0
#if SPLASH_CMYK
119
0
    cmykTransferC[i] = (Guchar)i;
120
0
    cmykTransferM[i] = (Guchar)i;
121
0
    cmykTransferY[i] = (Guchar)i;
122
0
    cmykTransferK[i] = (Guchar)i;
123
0
#endif
124
0
  }
125
0
  overprintMask = 0xffffffff;
126
0
  enablePathSimplification = gFalse;
127
0
  next = NULL;
128
0
}
129
130
0
SplashState::SplashState(SplashState *state) {
131
0
  memcpy(matrix, state->matrix, 6 * sizeof(SplashCoord));
132
0
  strokePattern = state->strokePattern->copy();
133
0
  fillPattern = state->fillPattern->copy();
134
0
  screen = state->screen->copy();
135
0
  blendFunc = state->blendFunc;
136
0
  strokeAlpha = state->strokeAlpha;
137
0
  fillAlpha = state->fillAlpha;
138
0
  lineWidth = state->lineWidth;
139
0
  lineCap = state->lineCap;
140
0
  lineJoin = state->lineJoin;
141
0
  miterLimit = state->miterLimit;
142
0
  flatness = state->flatness;
143
0
  if (state->lineDash) {
144
0
    lineDashLength = state->lineDashLength;
145
0
    lineDash = (SplashCoord *)gmallocn(lineDashLength, sizeof(SplashCoord));
146
0
    memcpy(lineDash, state->lineDash, lineDashLength * sizeof(SplashCoord));
147
0
  } else {
148
0
    lineDash = NULL;
149
0
    lineDashLength = 0;
150
0
  }
151
0
  lineDashPhase = state->lineDashPhase;
152
0
  strokeAdjust = state->strokeAdjust;
153
0
  clip = state->clip;
154
0
  clipIsShared = gTrue;
155
0
  softMask = state->softMask;
156
0
  deleteSoftMask = gFalse;
157
0
  inNonIsolatedGroup = state->inNonIsolatedGroup;
158
0
  inKnockoutGroup = state->inKnockoutGroup;
159
0
  memcpy(rgbTransferR, state->rgbTransferR, 256);
160
0
  memcpy(rgbTransferG, state->rgbTransferG, 256);
161
0
  memcpy(rgbTransferB, state->rgbTransferB, 256);
162
0
  memcpy(grayTransfer, state->grayTransfer, 256);
163
0
#if SPLASH_CMYK
164
0
  memcpy(cmykTransferC, state->cmykTransferC, 256);
165
0
  memcpy(cmykTransferM, state->cmykTransferM, 256);
166
0
  memcpy(cmykTransferY, state->cmykTransferY, 256);
167
0
  memcpy(cmykTransferK, state->cmykTransferK, 256);
168
0
#endif
169
0
  overprintMask = state->overprintMask;
170
0
  enablePathSimplification = state->enablePathSimplification;
171
0
  next = NULL;
172
0
}
173
174
0
SplashState::~SplashState() {
175
0
  delete strokePattern;
176
0
  delete fillPattern;
177
0
  delete screen;
178
0
  gfree(lineDash);
179
0
  if (!clipIsShared) {
180
0
    delete clip;
181
0
  }
182
0
  if (deleteSoftMask && softMask) {
183
0
    delete softMask;
184
0
  }
185
0
}
186
187
0
void SplashState::setStrokePattern(SplashPattern *strokePatternA) {
188
0
  delete strokePattern;
189
0
  strokePattern = strokePatternA;
190
0
}
191
192
0
void SplashState::setFillPattern(SplashPattern *fillPatternA) {
193
0
  delete fillPattern;
194
0
  fillPattern = fillPatternA;
195
0
}
196
197
0
void SplashState::setScreen(SplashScreen *screenA) {
198
0
  delete screen;
199
0
  screen = screenA;
200
0
}
201
202
void SplashState::setLineDash(SplashCoord *lineDashA, int lineDashLengthA,
203
0
            SplashCoord lineDashPhaseA) {
204
0
  gfree(lineDash);
205
0
  lineDashLength = lineDashLengthA;
206
0
  if (lineDashLength > 0) {
207
0
    lineDash = (SplashCoord *)gmallocn(lineDashLength, sizeof(SplashCoord));
208
0
    memcpy(lineDash, lineDashA, lineDashLength * sizeof(SplashCoord));
209
0
  } else {
210
0
    lineDash = NULL;
211
0
  }
212
0
  lineDashPhase = lineDashPhaseA;
213
0
}
214
215
0
GBool SplashState::lineDashContainsZeroLengthDashes() {
216
0
  int i;
217
218
0
  if (lineDashLength == 0) {
219
0
    return gFalse;
220
0
  }
221
222
  // if the line dash array has an odd number of elements, we need to
223
  // check all of the elements; if the length is even, we only need to
224
  // check even-number elements
225
0
  if (lineDashLength & 1) {
226
0
    for (i = 0; i < lineDashLength; ++i) {
227
0
      if (lineDash[i] == 0) {
228
0
  return gTrue;
229
0
      }
230
0
    }
231
0
  } else {
232
0
    for (i = 0; i < lineDashLength; i += 2) {
233
0
      if (lineDash[i] == 0) {
234
0
  return gTrue;
235
0
      }
236
0
    }
237
0
  }
238
0
  return gFalse;
239
0
}
240
241
void SplashState::clipResetToRect(SplashCoord x0, SplashCoord y0,
242
0
          SplashCoord x1, SplashCoord y1) {
243
0
  if (clipIsShared) {
244
0
    clip = clip->copy();
245
0
    clipIsShared = gFalse;
246
0
  }
247
0
  clip->resetToRect(x0, y0, x1, y1);
248
0
}
249
250
SplashError SplashState::clipToRect(SplashCoord x0, SplashCoord y0,
251
0
            SplashCoord x1, SplashCoord y1) {
252
0
  if (clipIsShared) {
253
0
    clip = clip->copy();
254
0
    clipIsShared = gFalse;
255
0
  }
256
0
  return clip->clipToRect(x0, y0, x1, y1);
257
0
}
258
259
0
SplashError SplashState::clipToPath(SplashPath *path, GBool eo) {
260
0
  if (clipIsShared) {
261
0
    clip = clip->copy();
262
0
    clipIsShared = gFalse;
263
0
  }
264
0
  return clip->clipToPath(path, matrix, flatness, eo,
265
0
        enablePathSimplification, strokeAdjust);
266
0
}
267
268
0
void SplashState::setSoftMask(SplashBitmap *softMaskA) {
269
0
  if (deleteSoftMask) {
270
0
    delete softMask;
271
0
  }
272
0
  softMask = softMaskA;
273
0
  deleteSoftMask = gTrue;
274
0
}
275
276
void SplashState::setTransfer(Guchar *red, Guchar *green, Guchar *blue,
277
0
            Guchar *gray) {
278
0
#if SPLASH_CMYK
279
0
  int i;
280
0
#endif
281
282
0
  memcpy(rgbTransferR, red, 256);
283
0
  memcpy(rgbTransferG, green, 256);
284
0
  memcpy(rgbTransferB, blue, 256);
285
0
  memcpy(grayTransfer, gray, 256);
286
0
#if SPLASH_CMYK
287
0
  for (i = 0; i < 256; ++i) {
288
0
    cmykTransferC[i] = (Guchar)(255 - rgbTransferR[255 - i]);
289
0
    cmykTransferM[i] = (Guchar)(255 - rgbTransferG[255 - i]);
290
0
    cmykTransferY[i] = (Guchar)(255 - rgbTransferB[255 - i]);
291
0
    cmykTransferK[i] = (Guchar)(255 - grayTransfer[255 - i]);
292
0
  }
293
0
#endif
294
0
}
295