bpp-core3  3.0.0
SvgGraphicDevice.h
Go to the documentation of this file.
1 //
2 // File: SvgGraphicDevice.h
3 // Authors:
4 // Julien Dutheil
5 // Created: 2008-03-10 00:00:00
6 //
7 
8 /*
9  Copyright or © or Copr. CNRS, (November 16, 2006)
10 
11  This software is a computer program whose purpose is to provide utilitary
12  classes. This file belongs to the Bio++ Project.
13 
14  This software is governed by the CeCILL license under French law and
15  abiding by the rules of distribution of free software. You can use,
16  modify and/ or redistribute the software under the terms of the CeCILL
17  license as circulated by CEA, CNRS and INRIA at the following URL
18  "http://www.cecill.info".
19 
20  As a counterpart to the access to the source code and rights to copy,
21  modify and redistribute granted by the license, users are provided only
22  with a limited warranty and the software's author, the holder of the
23  economic rights, and the successive licensors have only limited
24  liability.
25 
26  In this respect, the user's attention is drawn to the risks associated
27  with loading, using, modifying and/or developing or reproducing the
28  software by the user in light of its specific status of free software,
29  that may mean that it is complicated to manipulate, and that also
30  therefore means that it is reserved for developers and experienced
31  professionals having in-depth computer knowledge. Users are therefore
32  encouraged to load and test the software's suitability as regards their
33  requirements in conditions enabling the security of their systems and/or
34  data to be ensured and, more generally, to use and operate it in the
35  same conditions as regards security.
36 
37  The fact that you are presently reading this means that you have had
38  knowledge of the CeCILL license and that you accept its terms.
39 */
40 
41 #ifndef BPP_GRAPHICS_SVG_SVGGRAPHICDEVICE_H
42 #define BPP_GRAPHICS_SVG_SVGGRAPHICDEVICE_H
43 
44 
45 #include "../AbstractGraphicDevice.h"
46 #include "../ColorTools.h"
47 
48 // From the STL:
49 #include <map>
50 
51 namespace bpp
52 {
58 {
59 private:
60  std::ostream& out_;
61  std::map<int, std::vector<std::string>, std::greater<int> > layers_; // Layer display as in xfig
63  double minx_, maxx_, miny_, maxy_;
64  std::map<short int, std::string> fontStyles_;
65  std::map<short int, std::string> fontWeights_;
66 
67 public:
68  SvgGraphicDevice(std::ostream& out, bool inkscapeEnabled = false) :
69  out_(out),
70  layers_(),
71  inkscapeEnabled_(inkscapeEnabled),
72  minx_(0), maxx_(0), miny_(0), maxy_(0),
74  {
76  fontStyles_[Font::STYLE_ITALIC] = "italic";
79  }
80 
81  virtual ~SvgGraphicDevice() {}
82 
83 public:
84  void begin();
85  void end();
86 
87  void drawLine(double x1, double y1, double x2, double y2);
88  void drawRect(double x, double y, double width, double height, short fill = FILL_EMPTY);
89  void drawCircle(double x, double y, double radius, short fill = FILL_EMPTY);
90  void drawText(double x, double y, const std::string& text, short hpos = TEXT_HORIZONTAL_LEFT, short vpos = TEXT_VERTICAL_BOTTOM, double angle = 0);
91  void comment(const std::string& text)
92  {
93  layers_[getCurrentLayer()].push_back("<!-- " + text + " -->");
94  }
95 
96 public:
97  static std::string colorToText(const RGBColor& color)
98  {
99  return "rgb(" + TextTools::toString(color[0]) + "," + TextTools::toString(color[1]) + "," + TextTools::toString(color[2]) + ")";
100  }
101 };
102 } // end of namespace bpp.
103 #endif // BPP_GRAPHICS_SVG_SVGGRAPHICDEVICE_H
Partial implementation of the GraphicDevice interface.
static const short int STYLE_NORMAL
Definition: Font.h:164
static const short int STYLE_ITALIC
Definition: Font.h:165
static const short int WEIGHT_NORMAL
Definition: Font.h:167
static const short int WEIGHT_BOLD
Definition: Font.h:168
static short TEXT_HORIZONTAL_LEFT
static short FILL_EMPTY
static short TEXT_VERTICAL_BOTTOM
Describe a color according to its red, green and blue componants.
Definition: RgbColor.h:60
SVG plotting format.
void drawCircle(double x, double y, double radius, short fill=FILL_EMPTY)
Draw a circle.
std::map< int, std::vector< std::string >, std::greater< int > > layers_
static std::string colorToText(const RGBColor &color)
void drawLine(double x1, double y1, double x2, double y2)
Draw a line between two points.
void drawRect(double x, double y, double width, double height, short fill=FILL_EMPTY)
Draw a rectangle.
std::map< short int, std::string > fontWeights_
SvgGraphicDevice(std::ostream &out, bool inkscapeEnabled=false)
std::map< short int, std::string > fontStyles_
void drawText(double x, double y, const std::string &text, short hpos=TEXT_HORIZONTAL_LEFT, short vpos=TEXT_VERTICAL_BOTTOM, double angle=0)
Draw some characters.
void begin()
Start the painting.
void end()
End the painting.
void comment(const std::string &text)
Add a comment in the output.
std::string toString(T t)
General template method to convert to a string.
Definition: TextTools.h:153