bpp-core3  3.0.0
SvgGraphicDevice.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_GRAPHICS_SVG_SVGGRAPHICDEVICE_H
6 #define BPP_GRAPHICS_SVG_SVGGRAPHICDEVICE_H
7 
8 
9 #include "../AbstractGraphicDevice.h"
10 #include "../ColorTools.h"
11 
12 // From the STL:
13 #include <map>
14 
15 namespace bpp
16 {
22 {
23 private:
24  std::ostream& out_;
25  std::map<int, std::vector<std::string>, std::greater<int>> layers_; // Layer display as in xfig
27  double minx_, maxx_, miny_, maxy_;
28  std::map<short int, std::string> fontStyles_;
29  std::map<short int, std::string> fontWeights_;
30 
31 public:
32  SvgGraphicDevice(std::ostream& out, bool inkscapeEnabled = false) :
33  out_(out),
34  layers_(),
35  inkscapeEnabled_(inkscapeEnabled),
36  minx_(0), maxx_(0), miny_(0), maxy_(0),
37  fontStyles_(), fontWeights_()
38  {
39  fontStyles_[Font::STYLE_NORMAL] = "";
40  fontStyles_[Font::STYLE_ITALIC] = "italic";
41  fontWeights_[Font::WEIGHT_NORMAL] = "";
42  fontWeights_[Font::WEIGHT_BOLD] = "bold";
43  }
44 
45  virtual ~SvgGraphicDevice() {}
46 
47 public:
48  void begin();
49  void end();
50 
51  void drawLine(double x1, double y1, double x2, double y2);
52  void drawRect(double x, double y, double width, double height, short fill = FILL_EMPTY);
53  void drawCircle(double x, double y, double radius, short fill = FILL_EMPTY);
54  void drawText(double x, double y, const std::string& text, short hpos = TEXT_HORIZONTAL_LEFT, short vpos = TEXT_VERTICAL_BOTTOM, double angle = 0);
55  void comment(const std::string& text)
56  {
57  layers_[getCurrentLayer()].push_back("<!-- " + text + " -->");
58  }
59 
60 public:
61  static std::string colorToText(const RGBColor& color)
62  {
63  return "rgb(" + TextTools::toString(color[0]) + "," + TextTools::toString(color[1]) + "," + TextTools::toString(color[2]) + ")";
64  }
65 };
66 } // end of namespace bpp.
67 #endif // BPP_GRAPHICS_SVG_SVGGRAPHICDEVICE_H
static const short int WEIGHT_NORMAL
Definition: Font.h:131
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:128
void drawRect(double x, double y, double width, double height, short fill=FILL_EMPTY)
Draw a rectangle.
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)
Describe a color according to its red, green and blue componants.
Definition: RgbColor.h:21
static const short int STYLE_ITALIC
Definition: Font.h:129
static const short int WEIGHT_BOLD
Definition: Font.h:132
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_
std::string toString(T t)
General template method to convert to a string.
Definition: TextTools.h:115
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