]> www.fi.muni.cz Git - evince.git/blob - pdf/splash/SplashState.cc
added.
[evince.git] / pdf / splash / SplashState.cc
1 //========================================================================
2 //
3 // SplashState.cc
4 //
5 //========================================================================
6
7 #include <aconf.h>
8
9 #ifdef USE_GCC_PRAGMAS
10 #pragma implementation
11 #endif
12
13 #include <string.h>
14 #include "gmem.h"
15 #include "SplashPattern.h"
16 #include "SplashScreen.h"
17 #include "SplashClip.h"
18 #include "SplashState.h"
19
20 //------------------------------------------------------------------------
21 // SplashState
22 //------------------------------------------------------------------------
23
24 SplashState::SplashState(int width, int height) {
25   SplashColor color;
26
27   memset(&color, 0, sizeof(SplashColor));
28   strokePattern = new SplashSolidColor(color);
29   fillPattern = new SplashSolidColor(color);
30   screen = new SplashScreen(10);
31   lineWidth = 0;
32   lineCap = splashLineCapButt;
33   lineJoin = splashLineJoinMiter;
34   miterLimit = 10;
35   flatness = 1;
36   lineDash = NULL;
37   lineDashLength = 0;
38   lineDashPhase = 0;
39   clip = new SplashClip(0, 0, width - 1, height - 1);
40   next = NULL;
41 }
42
43 SplashState::SplashState(SplashState *state) {
44   strokePattern = state->strokePattern->copy();
45   fillPattern = state->fillPattern->copy();
46   screen = state->screen->copy();
47   lineWidth = state->lineWidth;
48   lineCap = state->lineCap;
49   lineJoin = state->lineJoin;
50   miterLimit = state->miterLimit;
51   flatness = state->flatness;
52   if (state->lineDash) {
53     lineDashLength = state->lineDashLength;
54     lineDash = (SplashCoord *)gmalloc(lineDashLength * sizeof(SplashCoord));
55     memcpy(lineDash, state->lineDash, lineDashLength * sizeof(SplashCoord));
56   } else {
57     lineDash = NULL;
58     lineDashLength = 0;
59   }
60   lineDashPhase = state->lineDashPhase;
61   clip = state->clip->copy();
62   next = NULL;
63 }
64
65 SplashState::~SplashState() {
66   delete strokePattern;
67   delete fillPattern;
68   delete screen;
69   gfree(lineDash);
70   delete clip;
71 }
72
73 void SplashState::setStrokePattern(SplashPattern *strokePatternA) {
74   delete strokePattern;
75   strokePattern = strokePatternA;
76 }
77
78 void SplashState::setFillPattern(SplashPattern *fillPatternA) {
79   delete fillPattern;
80   fillPattern = fillPatternA;
81 }
82
83 void SplashState::setScreen(SplashScreen *screenA) {
84   delete screen;
85   screen = screenA;
86 }
87
88 void SplashState::setLineDash(SplashCoord *lineDashA, int lineDashLengthA,
89                               SplashCoord lineDashPhaseA) {
90   gfree(lineDash);
91   lineDashLength = lineDashLengthA;
92   if (lineDashLength > 0) {
93     lineDash = (SplashCoord *)gmalloc(lineDashLength * sizeof(SplashCoord));
94     memcpy(lineDash, lineDashA, lineDashLength * sizeof(SplashCoord));
95   } else {
96     lineDash = NULL;
97   }
98   lineDashPhase = lineDashPhaseA;
99 }