1 //========================================================================
2 //
3 // DisplayState.cc
4 //
5 // Copyright 2014 Glyph & Cog, LLC
6 //
7 //========================================================================
8 
9 #include <aconf.h>
10 
11 #ifdef USE_GCC_PRAGMAS
12 #pragma implementation
13 #endif
14 
15 #include <stdlib.h>
16 #include "gmempp.h"
17 #include "GString.h"
18 #include "GList.h"
19 #include "TileMap.h"
20 #include "TileCache.h"
21 #include "TileCompositor.h"
22 #include "DisplayState.h"
23 
24 
25 //------------------------------------------------------------------------
26 // DisplayState
27 //------------------------------------------------------------------------
28 
DisplayState(int maxTileWidthA,int maxTileHeightA,int tileCacheSizeA,int nWorkerThreadsA,SplashColorMode colorModeA,int bitmapRowPadA)29 DisplayState::DisplayState(int maxTileWidthA, int maxTileHeightA,
30 			   int tileCacheSizeA, int nWorkerThreadsA,
31 			   SplashColorMode colorModeA, int bitmapRowPadA) {
32   int i;
33 
34   maxTileWidth = maxTileWidthA;
35   maxTileHeight = maxTileHeightA;
36   tileCacheSize = tileCacheSizeA;
37   nWorkerThreads = nWorkerThreadsA;
38   colorMode = colorModeA;
39   bitmapRowPad = bitmapRowPadA;
40 
41   tileMap = NULL;
42   tileCache = NULL;
43   tileCompositor = NULL;
44 
45   for (i = 0; i < splashColorModeNComps[colorMode]; ++i) {
46     paperColor[i] = 0xff;
47     matteColor[i] = 0x80;
48   }
49   if (colorMode == splashModeRGB8 || colorMode == splashModeBGR8) {
50     selectColor[0] = 0x80;
51     selectColor[1] = 0x80;
52     selectColor[2] = 0xff;
53   } else {
54     for (i = 0; i < splashColorModeNComps[colorMode]; ++i) {
55       selectColor[i] = 0xa0;
56     }
57   }
58   reverseVideo = gFalse;
59 
60   doc = NULL;
61 
62   winW = winH = 100;
63   displayMode = displayContinuous;
64   zoom = 100;
65   rotate = 0;
66   scrollPage = 0;
67   scrollX = scrollY = 0;
68 
69   selectRects = NULL;
70 
71 
72 }
73 
~DisplayState()74 DisplayState::~DisplayState() {
75   if (selectRects) {
76     deleteGList(selectRects, SelectRect);
77   }
78 }
79 
setPaperColor(SplashColorPtr paperColorA)80 void DisplayState::setPaperColor(SplashColorPtr paperColorA) {
81   splashColorCopy(paperColor, paperColorA);
82   tileCache->paperColorChanged();
83   tileCompositor->paperColorChanged();
84 }
85 
setMatteColor(SplashColorPtr matteColorA)86 void DisplayState::setMatteColor(SplashColorPtr matteColorA) {
87   splashColorCopy(matteColor, matteColorA);
88   tileCompositor->matteColorChanged();
89 }
90 
setSelectColor(SplashColorPtr selectColorA)91 void DisplayState::setSelectColor(SplashColorPtr selectColorA) {
92   splashColorCopy(selectColor, selectColorA);
93   tileCompositor->selectColorChanged();
94 }
95 
setReverseVideo(GBool reverseVideoA)96 void DisplayState::setReverseVideo(GBool reverseVideoA) {
97   if (reverseVideo != reverseVideoA) {
98     reverseVideo = reverseVideoA;
99     tileCache->reverseVideoChanged();
100     tileCompositor->reverseVideoChanged();
101   }
102 }
103 
setDoc(PDFDoc * docA)104 void DisplayState::setDoc(PDFDoc *docA) {
105   doc = docA;
106   tileMap->docChanged();
107   tileCache->docChanged();
108   tileCompositor->docChanged();
109 }
110 
setWindowSize(int winWA,int winHA)111 void DisplayState::setWindowSize(int winWA, int winHA) {
112   if (winW != winWA || winH != winHA) {
113     winW = winWA;
114     winH = winHA;
115     tileMap->windowSizeChanged();
116     tileCompositor->windowSizeChanged();
117   }
118 }
119 
setDisplayMode(DisplayMode displayModeA)120 void DisplayState::setDisplayMode(DisplayMode displayModeA) {
121   if (displayMode != displayModeA) {
122     displayMode = displayModeA;
123     tileMap->displayModeChanged();
124     tileCompositor->displayModeChanged();
125   }
126 }
127 
setZoom(double zoomA)128 void DisplayState::setZoom(double zoomA) {
129   if (zoom != zoomA) {
130     zoom = zoomA;
131     tileMap->zoomChanged();
132     tileCompositor->zoomChanged();
133   }
134 }
135 
setRotate(int rotateA)136 void DisplayState::setRotate(int rotateA) {
137   if (rotate != rotateA) {
138     rotate = rotateA;
139     tileMap->rotateChanged();
140     tileCompositor->rotateChanged();
141   }
142 }
143 
setScrollPosition(int scrollPageA,int scrollXA,int scrollYA)144 void DisplayState::setScrollPosition(int scrollPageA,
145 				     int scrollXA, int scrollYA) {
146   if (scrollPage != scrollPageA ||
147       scrollX != scrollXA ||
148       scrollY != scrollYA) {
149     scrollPage = scrollPageA;
150     scrollX = scrollXA;
151     scrollY = scrollYA;
152     tileMap->scrollPositionChanged();
153     tileCompositor->scrollPositionChanged();
154   }
155 }
156 
setSelection(int selectPage,double selectX0,double selectY0,double selectX1,double selectY1)157 void DisplayState::setSelection(int selectPage,
158 				double selectX0, double selectY0,
159 				double selectX1, double selectY1) {
160   GList *rects;
161   SelectRect *rect;
162 
163   rect = new SelectRect(selectPage, selectX0, selectY0, selectX1, selectY1);
164   rects = new GList();
165   rects->append(rect);
166   setSelection(rects);
167 }
168 
setSelection(GList * selectRectsA)169 void DisplayState::setSelection(GList *selectRectsA) {
170   SelectRect *rect, *rectA;
171   int i;
172 
173   if (!selectRects && !selectRectsA) {
174     return;
175   }
176   if (selectRects && selectRectsA &&
177       selectRects->getLength() == selectRectsA->getLength()) {
178     for (i = 0; i < selectRects->getLength(); ++i) {
179       rect = (SelectRect *)selectRects->get(i);
180       rectA = (SelectRect *)selectRectsA->get(i);
181       if (*rect != *rectA) {
182 	break;
183       }
184     }
185     if (i == selectRects->getLength()) {
186       deleteGList(selectRectsA, SelectRect);
187       return;
188     }
189   }
190   if (selectRects) {
191     deleteGList(selectRects, SelectRect);
192   }
193   selectRects = selectRectsA;
194   tileCompositor->selectionChanged();
195 }
196 
clearSelection()197 void DisplayState::clearSelection() {
198   setSelection(NULL);
199 }
200 
getNumSelectRects()201 int DisplayState::getNumSelectRects() {
202   if (!selectRects) {
203     return 0;
204   }
205   return selectRects->getLength();
206 }
207 
getSelectRect(int idx)208 SelectRect *DisplayState::getSelectRect(int idx) {
209   return (SelectRect *)selectRects->get(idx);
210 }
211 
optionalContentChanged()212 void DisplayState::optionalContentChanged() {
213   tileCache->optionalContentChanged();
214   tileCompositor->optionalContentChanged();
215 }
216 
217 
218 
forceRedraw()219 void DisplayState::forceRedraw() {
220   tileMap->forceRedraw();
221   tileCache->forceRedraw();
222   tileCompositor->forceRedraw();
223 }
224