1 /**********************************************************************
2 svgpainter.h - Rendering in SVG
3 
4 Copyright (C) 2009 by Chris Morley
5 
6 This file is part of the Open Babel project.
7 For more information, see <http://openbabel.org/>
8 
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation version 2 of the License.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17 ***********************************************************************/
18 #ifndef OB_SVGPAINTER_H
19 #define OB_SVGPAINTER_H
20 
21 #include <openbabel/babelconfig.h>
22 #include <iostream>
23 #include <set>
24 #include <openbabel/depict/painter.h>
25 
26 namespace OpenBabel
27 {
28   typedef std::pair<OBColor,OBColor> ColorGradient;
29 
30   class OBDEPICT SVGPainter : public OBPainter
31   {
32     public:
33       SVGPainter();
34       SVGPainter(std::ostream& ofs, std::set<ColorGradient> *gradients, bool withViewBox=false,
35         double width=0.0, double height=0.0);
36       ~SVGPainter();
37       //! @name OBPainter methods
38       //@{
39       void NewCanvas(double width, double height);
40       void EndCanvas();
41       bool IsGood() const;
42       void SetFontFamily(const std::string &fontFamily);
43       void SetFontSize(int pointSize);
44       void SetFillColor(const OBColor &color);
45       void SetFillRadial(const OBColor &start, const OBColor &end);
46       void SetPenColor(const OBColor &color);
47       void SetPenWidth(double width);
48       double GetPenWidth();
49       void DrawLine(double x1, double y1, double x2, double y2, const std::vector<double>& dashes=std::vector<double>());
50       void DrawPolygon(const std::vector<std::pair<double,double> > &points);
51       void DrawCircle(double x, double y, double r);
52       void DrawBall(double x, double y, double r, double opacity = 1.0);
53       void DrawText(double x, double y, const std::string &text);
54       OBFontMetrics GetFontMetrics(const std::string &text);
55       void WriteDefs();
56       //@}
57 
58       //! @name CairoPainter specific
59       //@{
60       void WriteImage(const std::string &filename);
61       //@}
62     private:
63       std::string RGBcode(OBColor color);
64       std::string MakeRGB(OBColor color);
65 
66     private:
67       std::ostream& m_ofs;
68       bool m_withViewBox;
69       double m_width, m_height;
70       OBColor m_Pencolor;
71       OBColor m_OrigBondcolor;
72       OBColor m_Fillcolor;
73       ColorGradient m_Gradientcolor;
74       std::set<ColorGradient> *m_Gradients;
75       bool m_isFillcolor;
76       double m_PenWidth;
77       int m_fontPointSize;
78       std::string m_fontFamily;
79   };
80 
81 }
82 
83 #endif
84 
85 //! \file svgpainter.h
86 //! \brief Generate 2D depictions in the SVG vector graphics format.
87