1 //========================================================================
2 //
3 // SplashState.cc
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) 2009 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 #include <config.h>
22
23 #ifdef USE_GCC_PRAGMAS
24 #pragma implementation
25 #endif
26
27 #include <string.h>
28 #include "goo/gmem.h"
29 #include "SplashPattern.h"
30 #include "SplashScreen.h"
31 #include "SplashClip.h"
32 #include "SplashBitmap.h"
33 #include "SplashState.h"
34
35 //------------------------------------------------------------------------
36 // SplashState
37 //------------------------------------------------------------------------
38
39 // number of components in each color mode
40 int splashColorModeNComps[] = {
41 1, 1, 3, 3, 4
42 #if SPLASH_CMYK
43 ,4
44 #endif
45 };
46
SplashState(int width,int height,GBool vectorAntialias,SplashScreenParams * screenParams)47 SplashState::SplashState(int width, int height, GBool vectorAntialias,
48 SplashScreenParams *screenParams) {
49 SplashColor color;
50
51 matrix[0] = 1; matrix[1] = 0;
52 matrix[2] = 0; matrix[3] = 1;
53 matrix[4] = 0; matrix[5] = 0;
54 memset(&color, 0, sizeof(SplashColor));
55 strokePattern = new SplashSolidColor(color);
56 fillPattern = new SplashSolidColor(color);
57 screen = new SplashScreen(screenParams);
58 blendFunc = NULL;
59 strokeAlpha = 1;
60 fillAlpha = 1;
61 lineWidth = 0;
62 lineCap = splashLineCapButt;
63 lineJoin = splashLineJoinMiter;
64 miterLimit = 10;
65 flatness = 1;
66 lineDash = NULL;
67 lineDashLength = 0;
68 lineDashPhase = 0;
69 strokeAdjust = gFalse;
70 clip = new SplashClip(0, 0, width - 0.001, height - 0.001, vectorAntialias);
71 softMask = NULL;
72 deleteSoftMask = gFalse;
73 inNonIsolatedGroup = gFalse;
74 next = NULL;
75 }
76
SplashState(int width,int height,GBool vectorAntialias,SplashScreen * screenA)77 SplashState::SplashState(int width, int height, GBool vectorAntialias,
78 SplashScreen *screenA) {
79 SplashColor color;
80
81 matrix[0] = 1; matrix[1] = 0;
82 matrix[2] = 0; matrix[3] = 1;
83 matrix[4] = 0; matrix[5] = 0;
84 memset(&color, 0, sizeof(SplashColor));
85 strokePattern = new SplashSolidColor(color);
86 fillPattern = new SplashSolidColor(color);
87 screen = screenA->copy();
88 blendFunc = NULL;
89 strokeAlpha = 1;
90 fillAlpha = 1;
91 lineWidth = 0;
92 lineCap = splashLineCapButt;
93 lineJoin = splashLineJoinMiter;
94 miterLimit = 10;
95 flatness = 1;
96 lineDash = NULL;
97 lineDashLength = 0;
98 lineDashPhase = 0;
99 strokeAdjust = gFalse;
100 clip = new SplashClip(0, 0, width - 0.001, height - 0.001, vectorAntialias);
101 softMask = NULL;
102 deleteSoftMask = gFalse;
103 inNonIsolatedGroup = gFalse;
104 next = NULL;
105 }
106
SplashState(SplashState * state)107 SplashState::SplashState(SplashState *state) {
108 memcpy(matrix, state->matrix, 6 * sizeof(SplashCoord));
109 strokePattern = state->strokePattern->copy();
110 fillPattern = state->fillPattern->copy();
111 screen = state->screen->copy();
112 blendFunc = state->blendFunc;
113 strokeAlpha = state->strokeAlpha;
114 fillAlpha = state->fillAlpha;
115 lineWidth = state->lineWidth;
116 lineCap = state->lineCap;
117 lineJoin = state->lineJoin;
118 miterLimit = state->miterLimit;
119 flatness = state->flatness;
120 if (state->lineDash) {
121 lineDashLength = state->lineDashLength;
122 lineDash = (SplashCoord *)gmallocn(lineDashLength, sizeof(SplashCoord));
123 memcpy(lineDash, state->lineDash, lineDashLength * sizeof(SplashCoord));
124 } else {
125 lineDash = NULL;
126 lineDashLength = 0;
127 }
128 lineDashPhase = state->lineDashPhase;
129 strokeAdjust = state->strokeAdjust;
130 clip = state->clip->copy();
131 softMask = state->softMask;
132 deleteSoftMask = gFalse;
133 inNonIsolatedGroup = state->inNonIsolatedGroup;
134 next = NULL;
135 }
136
~SplashState()137 SplashState::~SplashState() {
138 delete strokePattern;
139 delete fillPattern;
140 delete screen;
141 gfree(lineDash);
142 delete clip;
143 if (deleteSoftMask && softMask) {
144 delete softMask;
145 }
146 }
147
setStrokePattern(SplashPattern * strokePatternA)148 void SplashState::setStrokePattern(SplashPattern *strokePatternA) {
149 delete strokePattern;
150 strokePattern = strokePatternA;
151 }
152
setFillPattern(SplashPattern * fillPatternA)153 void SplashState::setFillPattern(SplashPattern *fillPatternA) {
154 delete fillPattern;
155 fillPattern = fillPatternA;
156 }
157
setScreen(SplashScreen * screenA)158 void SplashState::setScreen(SplashScreen *screenA) {
159 delete screen;
160 screen = screenA;
161 }
162
setLineDash(SplashCoord * lineDashA,int lineDashLengthA,SplashCoord lineDashPhaseA)163 void SplashState::setLineDash(SplashCoord *lineDashA, int lineDashLengthA,
164 SplashCoord lineDashPhaseA) {
165 gfree(lineDash);
166 lineDashLength = lineDashLengthA;
167 if (lineDashLength > 0) {
168 lineDash = (SplashCoord *)gmallocn(lineDashLength, sizeof(SplashCoord));
169 memcpy(lineDash, lineDashA, lineDashLength * sizeof(SplashCoord));
170 } else {
171 lineDash = NULL;
172 }
173 lineDashPhase = lineDashPhaseA;
174 }
175
setSoftMask(SplashBitmap * softMaskA)176 void SplashState::setSoftMask(SplashBitmap *softMaskA) {
177 if (deleteSoftMask) {
178 delete softMask;
179 }
180 softMask = softMaskA;
181 deleteSoftMask = gTrue;
182 }
183