2 ////////////////////////////////////////////////////////////////////
5 // Written by Francois Fleuret //
6 // Contact <francois.fleuret@idiap.ch> for comments & bug reports //
9 ////////////////////////////////////////////////////////////////////
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.
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,
24 #include "xfig_tracer.h"
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;
40 XFigTracer::~XFigTracer() {
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;
51 cerr << "Unknown color!" << endl;
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;
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;
66 (*_file) << "0 " << 32 + _nb_user_colors << " #";
67 sprintf(buffer, "%02x", _palette_red[_nb_user_colors]);
69 sprintf(buffer, "%02x", _palette_green[_nb_user_colors]);
71 sprintf(buffer, "%02x", _palette_blue[_nb_user_colors]);
76 cerr << "Too many colors!" << endl;
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;
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);