Add loadsvg script command, fix ParanoidNumber size limiting*
[ipdf/code.git] / src / debugscript.cpp
1 #include "debugscript.h"
2
3 #include <string>
4
5 using namespace IPDF;
6
7 void DebugScript::ParseAction()
8 {
9         std::string actionType;
10         inp >> actionType;
11         // Skip comments
12         while (actionType[0] == '#')
13         {
14                 std::string tmp;
15                 std::getline(inp, tmp);
16                 inp >> std::ws >> actionType;
17         }
18         if (actionType == "loop")
19         {
20                 inp >> currentAction.loops >> actionType;
21         }
22         else
23         {
24                 currentAction.loops = 1;
25         }
26
27         if (actionType == "wait")
28         {
29                 currentAction.type = AT_WaitFrame;
30                 return;
31         }
32         else if (actionType == "translate")
33         {
34                 std::string _x, _y;
35                 inp >> _x >> _y;
36                 currentAction.type = AT_Translate;
37                 currentAction.x = RealFromStr(_x.c_str());
38                 currentAction.y = RealFromStr(_y.c_str());
39                 return;
40         }
41         else if (actionType == "zoom")
42         {
43                 std::string _x, _y, _z;
44                 inp >> _x >> _y >> _z;
45                 currentAction.type = AT_Zoom;
46                 currentAction.x = RealFromStr(_x.c_str());
47                 currentAction.y = RealFromStr(_y.c_str());
48                 currentAction.z = RealFromStr(_z.c_str());
49                 return;
50         }
51         else if (actionType == "pxtranslate")
52         {
53                 inp >> currentAction.ix >> currentAction.iy;
54                 currentAction.type = AT_TranslatePx;
55                 return;
56         }
57         else if (actionType == "pxzoom")
58         {
59                 inp >> currentAction.ix >> currentAction.iy >> currentAction.iz;
60                 currentAction.type = AT_ZoomPx;
61                 return;
62         }
63         else if (actionType == "gpu")
64         {
65                 currentAction.type = AT_SetGPURendering;
66                 return;
67         }
68         else if (actionType == "cpu")
69         {
70                 currentAction.type = AT_SetCPURendering;
71                 return;
72         }
73         else if (actionType == "lazy")
74         {
75                 currentAction.type = AT_EnableLazyRendering;
76                 return;
77         }
78         else if (actionType == "nolazy")
79         {
80                 currentAction.type = AT_DisableLazyRendering;
81                 return;
82         }
83         else if (actionType == "quit")
84         {
85                 currentAction.type = AT_Quit;
86         }
87         else if (actionType == "loadsvg")
88         {
89                 currentAction.type = AT_LoadSVG;
90                 inp >> currentAction.filename;
91         }
92 }
93
94 bool DebugScript::Execute(View *view, Screen *scr)
95 {
96         if (currentAction.loops == 0)
97                 ParseAction();
98
99         switch(currentAction.type)
100         {
101         case AT_Quit:
102                 return true;
103         case AT_WaitFrame:
104                 break;
105         case AT_Translate:
106                 view->Translate(currentAction.x, currentAction.y);
107                 break;
108         case AT_TranslatePx:
109                 view->Translate(Real(currentAction.ix)/Real(scr->ViewportWidth()), Real(currentAction.iy)/Real(scr->ViewportHeight()));
110                 break;
111         case AT_Zoom:
112                 view->ScaleAroundPoint(currentAction.x, currentAction.y, currentAction.z);
113                 break;
114         case AT_ZoomPx:
115                 view->ScaleAroundPoint(Real(currentAction.ix)/Real(scr->ViewportWidth()),Real(currentAction.iy)/Real(scr->ViewportHeight()), Real(expf(-currentAction.iz/20.f)));
116                 break;
117         case AT_SetGPURendering:
118                 view->SetGPURendering(true);
119                 break;
120         case AT_SetCPURendering:
121                 view->SetGPURendering(false);
122                 break;
123         case AT_EnableLazyRendering:
124                 view->SetLazyRendering(true);
125                 break;
126         case AT_DisableLazyRendering:
127                 view->SetLazyRendering(false);
128                 break;
129         case AT_LoadSVG:
130                 #ifdef TRANSFORM_OBJECTS_NOT_VIEW
131                         view->Doc().LoadSVG(currentAction.filename, Rect(Real(1)/Real(2),Real(1)/Real(2),Real(1)/Real(800),Real(1)/Real(600))); 
132                 #else
133                         Rect & bounds = view->GetBounds();
134                         view->Doc().LoadSVG(currentAction.filename, Rect(bounds.x+bounds.w/Real(2),bounds.y+bounds.h/Real(2),bounds.w/Real(800),bounds.h/Real(600)));
135                 #endif
136                 currentAction.type = AT_WaitFrame;
137                 view->ForceRenderDirty();
138                 view->ForceBufferDirty();
139                 view->ForceBoundsDirty();
140                 currentAction.loops = 0;
141                 break;
142         default:
143                 Fatal("Unknown script command in queue.");
144         }
145         currentAction.loops--;
146         return false;
147 }

UCC git Repository :: git.ucc.asn.au