RDKit: MolDraw2DCairo.h Source File

| RDKit Open-source cheminformatics and machine learning.

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

MolDraw2DCairo.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2015 Greg Landrum
3 //
4 // @@ All Rights Reserved @@
5 // This file is part of the RDKit.
6 // The contents are covered by the terms of the BSD license
7 // which is included in the file license.txt, found at the root
8 // of the RDKit source tree.
9 //
10 // derived from Dave Cosgrove's MolDraw2D
11 //
12 // This is a concrete class derived from MolDraw2D that uses RDKit to draw a
13 // molecule into a cairo drawing context
14
15 #ifndef MOLDRAW2DCAIRO_H
16 #define MOLDRAW2DCAIRO_H
17
18 #include <GraphMol/MolDraw2D/MolDraw2D.h>
19 #include <cairo.h>
20
21 // ****************************************************************************
22
23 namespace RDKit {
24
25 class MolDraw2DCairo : public MolDraw2D {
26 public:
27 // does not take ownership of the drawing context
28 MolDraw2DCairo(int width, int height, cairo_t *cr)
29 : MolDraw2D(width, height), dp_cr(cr) {
30 cairo_reference(dp_cr);
31 initDrawing();
32 };
33 MolDraw2DCairo(int width, int height) : MolDraw2D(width, height) {
34 cairo_surface_t *surf =
35 cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
36 dp_cr = cairo_create(surf);
37 cairo_surface_destroy(surf); // dp_cr has a reference to this now;
38 initDrawing();
39 };
40 ~MolDraw2DCairo() {
41 if (dp_cr) {
42 if (cairo_get_reference_count(dp_cr) > 0) {
43 cairo_destroy(dp_cr);
44 }
45 dp_cr = NULL;
46 }
47 }
48
49 // set font size in molecule coordinate units. That's probably Angstrom for
50 // RDKit. It will turned into drawing units using scale_, which might be
51 // changed as a result, to make sure things still appear in the window.
52 void setFontSize(double new_size);
53 void setColour(const DrawColour &col);
54
55 // not sure if this goes here or if we should do a dtor since initDrawing() is
56 // called in the ctor,
57 // but we'll start here
58 void finishDrawing();
59
60 void drawLine(const Point2D &cds1, const Point2D &cds2);
61 void drawChar(char c, const Point2D &cds);
62 // void drawString( const std::string &str, const Point2D &cds );
63 void drawPolygon(const std::vector<Point2D> &cds);
64 void clearDrawing();
65
66 // using the current scale, work out the size of the label in molecule
67 // coordinates
68 void getStringSize(const std::string &label, double &label_width,
69 double &label_height) const;
70
71 // returns the PNG data in a string
72 std::string getDrawingText() const;
73 // writes the PNG data to a file
74 void writeDrawingText(const std::string &fName) const;
75
76 private:
77 cairo_t *dp_cr;
78
79 void initDrawing();
80 };
81 }
82 #endif // MOLDRAW2DCAIRO_H
RDKit::MolDraw2DCairo::drawChar
void drawChar(char c, const Point2D &cds)
RDKit::MolDraw2D::height
virtual int height() const
Definition: MolDraw2D.h:129
RDKit::MolDraw2DCairo::getDrawingText
std::string getDrawingText() const
RDKit::MolDraw2DCairo
Definition: MolDraw2DCairo.h:25
RDKit::MolDraw2DCairo::clearDrawing
void clearDrawing()
RDGeom::Point2D
Definition: point.h:254
RDKit::MolDraw2DCairo::setFontSize
void setFontSize(double new_size)
MolDraw2D.h
RDKit::MolDraw2DCairo::getStringSize
void getStringSize(const std::string &label, double &label_width, double &label_height) const
RDKit::MolDraw2DCairo::~MolDraw2DCairo
~MolDraw2DCairo()
Definition: MolDraw2DCairo.h:40
RDKit
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:28
RDKit::MolDraw2D::width
virtual int width() const
Definition: MolDraw2D.h:128
RDKit::MolDraw2DCairo::finishDrawing
void finishDrawing()
RDKit::MolDraw2DCairo::drawPolygon
void drawPolygon(const std::vector< Point2D > &cds)
RDKit::MolDraw2DCairo::MolDraw2DCairo
MolDraw2DCairo(int width, int height, cairo_t *cr)
Definition: MolDraw2DCairo.h:28
RDKit::MolDraw2DCairo::setColour
void setColour(const DrawColour &col)
RDKit::MolDraw2D
Definition: MolDraw2D.h:76
RDKit::MolDraw2DCairo::MolDraw2DCairo
MolDraw2DCairo(int width, int height)
Definition: MolDraw2DCairo.h:33
RDKit::MolDraw2DCairo::drawLine
void drawLine(const Point2D &cds1, const Point2D &cds2)
RDKit::MolDraw2DCairo::writeDrawingText
void writeDrawingText(const std::string &fName) const
RDKit::DrawColour
boost::tuple< float, float, float > DrawColour
Definition: MolDraw2D.h:37