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