Files
rdkit/Code/GraphMol/MolDraw2D/DrawTextFTSVG.cpp
David Cosgrove bc9e4d6478 Support using FreeType for text rendering (#3237)
* First working version with DrawText classes, original functionality only.  No font scaling.

* Added font scaling.

* Added atom colours.

* First stab at freetype text drawing.  A stash prior to major surgery.

* Freetype seems to be working.  On to whack-a-mole.

* Added class flag to atom labels and annotations.

* Another intermim commit whilst re-factoring all string drawing code from MolDraw2D.

* Fixed scaling and implemented max font size.

* Fixed bugs in non-FT Cairo and SVG drawing.

* More re-factoring of drawStrings - now creates StringRwct for each char in all strings.

* More re-factoring of string drawing - all mentions removed from MolDraw2D, I think..

* Working native Cairo, simple tests.

* Working native Cairo, simple tests.

* Padding roumd rectangles.

* Working FT Cairo, FT SVG, native SVG, simple tests.

* Two line labels mostly sorted. Native SVG wrong.

* Two line SVG labels sorted.

* Two line SVG labels sorted.

* Tidied out debug writes.

* Tweaked merge.

* Annotations working, radicals now failing.

* Fixed radicals crash.

* All tests passed for freetype drawings.  Grid drawings not right.

* Fixed bug in grid drawings.

* Better font size.

* Fixed legends in grids.

* Fixed rect intersection bug.

* Tidied up font sizes.

* moldraw2DTest1 all passing.

* All catch tests pass.

* Few rixes, and reactions look ok.

* Added minimum font size.

* Fixed radical drawing when max/min font size hit.

* Interim cmmmit, most test1.cpp working.

* Fixed uninitialised min_font_size_ in DrawText.  Took out use of MolDraw2D::setFontSize() which probably needs to go back in at some point.

* More test1.cpp passing.

* test1.cpp all pass, freetype and non-freetype

* Fixed superscripts hitting min font size in test860.  Made superscripts and subscripts same size.

* testc.pp all pass.

* Fixed bug in freetype text. All testt1.cpp pass.

* All tests passed.d

* Added option for different font.

* Added option for explicit terminal methyls.

* Added option to explicitly not use Freetype in drawers.  Used same in catch_tests.cpp.

* Got sense of NO_FREETYPE wrong in catch_tests.cpp.  D'oh!

* Fixed Python draw tests.

* Added new options to JSON interpreter.

* Fixed scale of text in contoured plots.

* Added optional molecule to grid drawer to help set scale.

* Fixed Python wrappers  for drawing 2D grids .

* Added Greg's CMakeLists.txt

* Moved fonts out of code tree.
Improved handling of font files not found, including logging to rdWarningLog.

* Interim commit.

* Tidied up some namespace std issues.

* Reverted to previous version.
Took out 'using namespace std;'

* update expected java results

* Added multi-line legends.  Also carves out a reserved bit for the legend, and sets the font size so the legend will fit.

* enable annotations on windows with freetype

* Removed stray font file.

* Removed stray font file.

* Re-instanted fontSize() and setFontSize(), though with change of units.

* Added RDK_BUILD_FREETYPE_SUPPORT to cmake.

* re-expose the fontsize controls to python.
document API change w.r.t. font size

* Update ReleaseNotes.md

Co-authored-by: David Cosgrove <david@cozchemix.co.uk>
Co-authored-by: greg landrum <greg.landrum@gmail.com>
2020-06-23 17:31:50 +02:00

101 lines
2.9 KiB
C++

//
// @@ 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.
//
// Original author: David Cosgrove (CozChemIx) on 08/05/2020.
//
#include <GraphMol/MolDraw2D/DrawTextFTSVG.h>
namespace RDKit {
std::string DrawColourToSVG(const RDKit::DrawColour &col);
// ****************************************************************************
DrawTextFTSVG::DrawTextFTSVG(double max_fnt_sz, double min_fnt_sz,
const std::string &font_file,
std::ostream &oss, std::string &d_act_class)
: DrawTextFT(max_fnt_sz, min_fnt_sz, font_file),
oss_(oss), d_active_class_(d_act_class) {
}
// ****************************************************************************
double DrawTextFTSVG::extractOutline() {
std::string col = DrawColourToSVG(colour());
oss_ << "<path ";
if (!d_active_class_.empty()) {
oss_ << " class='" << d_active_class_ << "'" << " d='";
} else {
oss_ << " d='";
}
double adv = DrawTextFT::extractOutline();
oss_ << "' fill='" << col << "'/>" << std::endl;
return adv;
}
// ****************************************************************************
int DrawTextFTSVG::MoveToFunctionImpl(const FT_Vector *to) {
double dx, dy;
fontPosToDrawPos(to->x, to->y, dx, dy);
oss_ << "M " << dx << ' ' << dy << std::endl;
return 0;
}
// ****************************************************************************
int DrawTextFTSVG::LineToFunctionImpl(const FT_Vector *to) {
double dx, dy;
fontPosToDrawPos(to->x, to->y, dx, dy);
oss_ << "L " << dx << ' ' << dy << std::endl;
return 0;
}
// ****************************************************************************
int DrawTextFTSVG::ConicToFunctionImpl(const FT_Vector *control,
const FT_Vector *to) {
double controlX, controlY;
fontPosToDrawPos(control->x, control->y, controlX, controlY);
double dx, dy;
fontPosToDrawPos(to->x, to->y, dx, dy);
oss_ << "Q " << controlX << ' ' << controlY << ", "
<< dx << ' ' << dy << std::endl;
return 0;
}
// ****************************************************************************
int DrawTextFTSVG::CubicToFunctionImpl(const FT_Vector *controlOne,
const FT_Vector *controlTwo,
const FT_Vector *to) {
double controlOneX, controlOneY;
fontPosToDrawPos(controlOne->x, controlOne->y, controlOneX, controlOneY);
double controlTwoX, controlTwoY;
fontPosToDrawPos(controlTwo->x, controlTwo->y, controlTwoX, controlTwoY);
double dx, dy;
fontPosToDrawPos(to->x, to->y, dx, dy);
oss_ << "C " << controlOneX << ' ' << controlOneY << ", "
<< controlTwoX << ' ' << controlTwoY << ", "
<< dx << ' ' << dy << std::endl;
return 0;
}
} // namespace RDKit