Added the -fPIC for the DEBUG mode.
[universe.git] / xfig_tracer.cc
1
2 ////////////////////////////////////////////////////////////////////
3 // START_IP_HEADER                                                //
4 //                                                                //
5 // Written by Francois Fleuret                                    //
6 // Contact <francois.fleuret@idiap.ch> for comments & bug reports //
7 //                                                                //
8 // END_IP_HEADER                                                  //
9 ////////////////////////////////////////////////////////////////////
10
11     // ================================================
12     // (3.1) Color Pseudo-objects (user-defined colors)
13     // ================================================
14           // This is used to define arbitrary colors beyond the 32 standard colors.
15           // The color objects must be defined before any other Fig objects.
16
17     // First line:
18         // type    name                    (brief description)
19         // ----    ----                    -------------------
20         // int     object_code             (always 0)
21         // int     color_number            (color number, from 32-543 (512 total))
22         // hex string  rgb values          (hexadecimal string describing red,
23
24 #include "xfig_tracer.h"
25
26 XFigTracer::XFigTracer(const char *name) {
27   _file = new ofstream(name);
28   (*_file) << "#FIG 3.2" << endl;
29   (*_file) << "Portrait" << endl;
30   (*_file) << "Center" << endl;
31   (*_file) << "Metric" << endl;
32   (*_file) << "A4      " << endl;
33   (*_file) << "100.00" << endl;
34   (*_file) << "Single" << endl;
35   (*_file) << "-2" << endl;
36   (*_file) << "1200 2" << endl;
37   _nb_user_colors = 0;
38 }
39
40 XFigTracer::~XFigTracer() {
41   _file->flush();
42   delete _file;
43 }
44
45 int XFigTracer::user_color(int red, int green, int blue) {
46   for(int c = 0; c < _nb_user_colors; c++) {
47     if(red == _palette_red[c] &&
48        green == _palette_green[c] &&
49        blue == _palette_blue[c]) return 32 + c;
50   }
51   cerr << "Unknown color!" << endl;
52   exit(1);
53 }
54
55 void XFigTracer::add_color(int red, int green, int blue) {
56   for(int c = 0; c < _nb_user_colors; c++) {
57     if(red == _palette_red[c] &&
58        green == _palette_green[c] &&
59        blue == _palette_blue[c]) return;
60   }
61   if(_nb_user_colors < max_nb_user_colors) {
62     _palette_red[_nb_user_colors] = red;
63     _palette_green[_nb_user_colors] = green;
64     _palette_blue[_nb_user_colors] = blue;
65     char buffer[2];
66     (*_file) << "0 " << 32 + _nb_user_colors << " #";
67     sprintf(buffer, "%02x", _palette_red[_nb_user_colors]);
68     (*_file) << buffer;
69     sprintf(buffer, "%02x", _palette_green[_nb_user_colors]);
70     (*_file) << buffer;
71     sprintf(buffer, "%02x", _palette_blue[_nb_user_colors]);
72     (*_file) << buffer;
73     (*_file) << endl;
74     _nb_user_colors++;
75   } else {
76     cerr << "Too many colors!" << endl;
77     exit(1);
78   }
79 }
80
81 void XFigTracer::draw_polygon(int red, int green, int blue,
82                               int nb_vertices, scalar_t *x, scalar_t *y) {
83   int c = user_color(red, green, blue);
84   (*_file) << "2 3 0 1 7 " << c << " 50 -1 20 0.000 0 0 -1 0 0 " << nb_vertices + 1 << endl;
85   (*_file) << " ";
86   for(int n = 0; n < nb_vertices; n++) (*_file) << " " << int(x[n]*10) << " " << int(y[n]*10);
87   (*_file) << " " << int(x[0]*10) << " " << int(y[0]*10);
88   (*_file) << endl;
89 }