Clipping for RECT types. Breaks a little.
[ipdf/code.git] / src / main.cpp
1 #include "main.h"
2 #include <unistd.h> // Because we can.
3
4 int main(int argc, char ** argv)
5 {       
6         #ifndef __STDC_IEC_559__
7         Warn("__STDC_IEC_559__ not defined. IEEE 754 floating point not fully supported.\n");
8         #endif
9
10
11         Debug("Compiled with REAL = %d => \"%s\" sizeof(Real) == %d bytes", REAL, g_real_name[REAL], sizeof(Real));
12
13         Document doc;
14         srand(time(NULL));
15
16         enum {OUTPUT_TO_BMP, LOOP} mode = LOOP;
17         
18         
19         Colour c(0,0,0,1);
20         const char * input_bmp = NULL;
21         const char * output_bmp = NULL;
22         const char * input_filename = NULL;
23         float b[4] = {0,0,1,1};
24
25         int i = 0;
26         while (++i < argc)
27         {
28                 if (argv[i][0] != '-')
29                 {
30                         input_filename = argv[i];
31                         continue;               
32                 }
33                 switch (argv[i][1])
34                 {
35                         case 'o':
36                                 mode = OUTPUT_TO_BMP;
37                                 if (++i >= argc)
38                                         Fatal("No input argument following -o switch");
39                                 input_bmp = argv[i];
40                                 if (++i >= argc)
41                                         Fatal("No output argument following -o switch");
42                                 output_bmp = argv[i];
43
44                                 break;
45                         case 'c':
46                         {
47                                 Debug("Reading paint colour");
48                                 for (int j = 1; j <= 4; ++j)
49                                 {
50                                         if (i+j >= argc)
51                                                 Fatal("No %d colour component following -c switch", j);
52                                         char * e;
53                                         float * comp = (j == 1) ? (&c.r) : ((j == 2) ? (&c.g) : ((j == 3) ? (&c.b) : &(c.a)));
54                                         *comp = strtof(argv[i+j], &e);
55                                         if (*e != '\0')
56                                                 Fatal("Colour component %d not a valid float", j); 
57                                 }
58                                 i += 4;
59                                 break;
60                         }
61                         case 'b':
62                         {
63                                 Debug("Reading view bounds");
64                                 for (int j = 1; j <= 4; ++j)
65                                 {
66                                         if (i+j >= argc)
67                                                 Fatal("No %d bounds component following -b switch", j);
68                                         char * e;
69                                         b[j-1] = strtof(argv[i+j], &e);
70                                         if (*e != '\0')
71                                                 Fatal("Bounds component %d not a valid float", j); 
72                                 }
73                                 i += 4;
74                                 break;
75                         }
76                 }       
77         }
78
79         if (input_filename != NULL)
80         {
81                 doc.LoadSVG(input_filename, Rect(0,0,Real(1)/Real(800),Real(1)/Real(600)));
82         }
83         else 
84         {
85 /*              doc.AddBezierData(Bezier(0,0,0,1,1,0));
86                 doc.AddBezierData(Bezier(0,0,1,0,0,1));
87                 doc.AddBezierData(Bezier(0,0,1,1,1,0));
88                 doc.AddBezierData(Bezier(0,1,1,0,0,1));*/
89                 
90         
91                 
92                 doc.AddText("abcde", 0.5, Real(0), Real(1));
93
94                 for(int x = 0; x < 8; ++x)
95                 {
96                         
97                         for (int y = 0; y < 8; ++y)
98                         {
99                                 //doc.Add(static_cast<IPDF::ObjectType>((x^y)%3), Rect(0.2+x-4.0,0.2+y-4.0,0.6,0.6));
100                                 //doc.Add(BEZIER, Rect(0.2+x-4.0, 0.2+y-4.0, 0.6,0.6), (x^y)%3);
101                         }
102                 }
103         /*      doc.Add(BEZIER, Rect(0.1,0.1,0.8,0.8), 0);
104                 doc.Add(BEZIER, Rect(0.1,0.1,0.8,0.8), 1);
105                 doc.Add(BEZIER, Rect(0.1,0.1,0.8,0.8), 2);
106                 doc.Add(BEZIER, Rect(0.1,0.1,0.8,0.8), 3);*/
107                 //doc.Add(CIRCLE_FILLED, Rect(0.1,0.1,0.8,0.8), 0);
108         }
109         Debug("Start!");
110         Rect bounds(b[0],b[1],b[2],b[3]);
111
112         if (mode == LOOP)
113                 MainLoop(doc, bounds, c);
114         else if (mode == OUTPUT_TO_BMP)
115                 OverlayBMP(doc, input_bmp, output_bmp, bounds, c);
116         return 0;
117 }

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