MolDraw2DCairo.h
Go to the documentation of this file.
//
// Copyright (C) 2015 Greg Landrum
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
// derived from Dave Cosgrove's MolDraw2D
//
// This is a concrete class derived from MolDraw2D that uses RDKit to draw a
// molecule into a cairo drawing context
#ifndef MOLDRAW2DCAIRO_H
#define MOLDRAW2DCAIRO_H
#include <GraphMol/MolDraw2D/MolDraw2D.h>
#include <cairo.h>
// ****************************************************************************
namespace RDKit {
class MolDraw2DCairo : public MolDraw2D {
public :
// does not take ownership of the drawing context
MolDraw2DCairo( int width , int height , cairo_t *cr ) :
MolDraw2D( width , height ) , dp_cr( cr ) {
cairo_reference(dp_cr);
initDrawing(); };
MolDraw2DCairo( int width , int height ) :
MolDraw2D( width , height ) {
cairo_surface_t *surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
dp_cr = cairo_create(surf);
cairo_surface_destroy (surf); // dp_cr has a reference to this now;
initDrawing();
};
~MolDraw2DCairo() {
if(dp_cr) {
if(cairo_get_reference_count(dp_cr)>0){
cairo_destroy(dp_cr);
}
dp_cr=NULL;
}
}
// set font size in molecule coordinate units. That's probably Angstrom for
// RDKit. It will turned into drawing units using scale_, which might be
// changed as a result, to make sure things still appear in the window.
void setFontSize( double new_size );
void setColour( const DrawColour &col );
// not sure if this goes here or if we should do a dtor since initDrawing() is called in the ctor,
// but we'll start here
void finishDrawing();
void drawLine( const Point2D &cds1 ,
const Point2D &cds2 );
void drawChar( char c , const Point2D &cds );
//void drawString( const std::string &str, const Point2D &cds );
void drawPolygon( const std::vector<Point2D > &cds );
void clearDrawing();
// using the current scale, work out the size of the label in molecule coordinates
void getStringSize( const std::string &label , double &label_width ,
double &label_height ) const;
// returns the PNG data in a string
std::string getDrawingText() const;
// writes the PNG data to a file
void writeDrawingText(const std::string &fName) const;
private :
cairo_t *dp_cr;
void initDrawing();
};
}
#endif // MOLDRAW2DCAIRO_H
RDKit::MolDraw2DCairo::drawChar
void drawChar(char c, const Point2D &cds)
RDKit::MolDraw2D::height
virtual int height() const
Definition: MolDraw2D.h:95
RDKit::MolDraw2DCairo::getDrawingText
std::string getDrawingText() const
RDKit::MolDraw2DCairo
Definition: MolDraw2DCairo.h:25
RDKit::MolDraw2DCairo::clearDrawing
void clearDrawing()
RDKit::DrawColour
boost::tuple< float, float, float > DrawColour
Definition: MolDraw2D.h:37
RDGeom::Point2D
Definition: point.h:263
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:39
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:94
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:60
RDKit::MolDraw2DCairo::MolDraw2DCairo
MolDraw2DCairo(int width, int height)
Definition: MolDraw2DCairo.h:32
RDKit::MolDraw2DCairo::drawLine
void drawLine(const Point2D &cds1, const Point2D &cds2)
RDKit::MolDraw2DCairo::writeDrawingText
void writeDrawingText(const std::string &fName) const