00001 /// \file 00002 /// Implémentation de la classe EPSWriter pour générer des fichiers PostScript 00003 #include "EPSWriter.hpp" 00004 /// Constructeur 00005 /// Initialise la classe et dessine un rectangle autour du dessin produit 00006 EPSWriter::EPSWriter(string fileName, int _width, int _height): 00007 file(fileName.c_str()), 00008 width(_width), 00009 height(_height){ 00010 xScale = yScale = 2; 00011 file << "newpath " << endl; 00012 file << "0 0 0 setrgbcolor " << endl; 00013 file << "0 setlinewidth " << endl; 00014 file << "0 0 moveto " << endl; 00015 file << (width * xScale) << " 0 lineto " << endl; 00016 file << (width * xScale) << " " << (height * yScale) << " lineto " << endl; 00017 file << "0 " << (height * yScale) << " lineto " << endl; 00018 file << "stroke " << endl; 00019 } 00020 void EPSWriter::setScale(int _xScale, int _yScale){ 00021 xScale = _xScale; 00022 yScale = _yScale; 00023 } 00024 void EPSWriter::setColor(Color _color){ 00025 color = _color; 00026 } 00027 void EPSWriter::drawRound(int x1, int y1){ 00028 file << "newpath " << endl; 00029 file << (color.getRed() / 255.0) << " " << (color.getGreen() / 255.0) 00030 << " " << (color.getBlue() / 255.0) << " setrgbcolor " << endl; 00031 file << "1 setlinewidth " << endl; 00032 file << (x1 * xScale) << " " << (y1 * yScale) << " " << " 1 0 360 arc " << endl; 00033 file << "stroke " << endl; 00034 } 00035 void EPSWriter::drawLine(int x1, int y1, int x2, int y2){ 00036 file << "newpath " << endl; 00037 file << "0 0 0 setrgbcolor " << endl; 00038 file << "1 setlinewidth " << endl; 00039 file << (x1 * xScale) << " " << (y1 * yScale) << " moveto " << endl; 00040 file << (x2 * xScale) << " " << (y2 * yScale) << " lineto " << endl; 00041 file << "stroke " << endl; 00042 } 00043 void EPSWriter::write(){ 00044 file.close(); 00045 }