RDKit: DrawTextFT.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
DrawTextFT.h
Go to the documentation of this file.
1//
2// Copyright (C) 2020-2022 David Cosgrove and other RDKit contributors
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//
11// Original author: David Cosgrove (CozChemIx).
12//
13// This is an abstract base class derived from DrawText that does drawing
14// using FreeType.
15
16#ifndef RDKIT_DRAWTEXTFT_H
17#define RDKIT_DRAWTEXTFT_H
18
19#include <string>
20
21#include <ft2build.h>
22#include FT_FREETYPE_H
23#include FT_BBOX_H
24#include FT_OUTLINE_H
25
26#include <RDGeneral/export.h>
27#include <GraphMol/MolDraw2D/DrawText.h>
28
29namespace RDKit {
30
31struct StringRect;
32
33namespace MolDraw2D_detail {
34
35// ****************************************************************************
36 class RDKIT_MOLDRAW2D_EXPORT DrawTextFT : public DrawText {
37 public:
38 ~DrawTextFT() override;
39 virtual int MoveToFunctionImpl(const FT_Vector *to) = 0;
40 virtual int LineToFunctionImpl(const FT_Vector *to) = 0;
41 virtual int ConicToFunctionImpl(const FT_Vector *control,
42 const FT_Vector *to) = 0;
43 virtual int CubicToFunctionImpl(const FT_Vector *controlOne,
44 const FT_Vector *controlTwo,
45 const FT_Vector *to) = 0;
46
47 DrawTextFT(double max_fnt_sz, double min_fnt_sz,
48 const std::string &font_file);
49 DrawTextFT(const DrawTextFT &) = delete;
50 DrawTextFT(DrawTextFT &&) = delete;
51 DrawTextFT &operator=(const DrawTextFT &) = delete;
52 DrawTextFT &operator=(DrawTextFT &&) = delete;
53
54 void drawChar(char c, const Point2D &cds) override;
55
56 // unless over-ridden by the c'tor, this will return a hard-coded
57 // file from $RDBASE.
58 std::string getFontFile() const override;
59 void setFontFile(const std::string &font_file) override;
60
61 double fontCoordToDrawCoord(FT_Pos fc) const;
62 void fontPosToDrawPos(FT_Pos fx, FT_Pos fy, double &dx, double &dy) const;
63 // adds x_trans_ and y_trans_ to coords returns x advance distance
64 virtual double extractOutline();
65
66 FT_Library library_;
67 FT_Face face_;
68 std::string font_file_; // over-rides default if not empty.
69 double x_trans_, y_trans_;
70 mutable FT_Pos
71 string_y_max_; // maximum y value of string drawn, for inverting y
72 double em_scale_;
73
74 // return a vector of StringRects, one for each char in text, with
75 // super- and subscripts taken into account. Sizes in pixel coords,
76 // i.e. scaled by fontScale().
77 void getStringRects(const std::string &text,
78 std::vector<std::shared_ptr<StringRect>> &rects,
79 std::vector<TextDrawType> &draw_modes,
80 std::vector<char> &draw_chars) const override;
81
82 // calculate the bounding box of the glyph for c in
83 // font units (0 -> face_->units_per_EM (2048 for roboto font).
84 void calcGlyphBBox(char c, FT_Pos &x_min, FT_Pos &y_min, FT_Pos &x_max,
85 FT_Pos &y_max, FT_Pos &advance) const;
86};
87
88// Callbacks for FT_Outline_Decompose. user should be a pointer to
89// an instance of DrawTextFT.
90 int moveToFunction(const FT_Vector *to, void *user);
91 int lineToFunction(const FT_Vector *to, void *user);
92 int conicToFunction(const FT_Vector *control, const FT_Vector *to, void *user);
93 int cubicToFunction(const FT_Vector *controlOne, const FT_Vector *controlTwo,
94 const FT_Vector *to, void *user);
95
96} // namespace MolDraw2D_detail
97} // namespace RDKit
98
99#endif // RDKIT_DRAWTEXTFT_H
DrawText.h
RDGeom::Point2D
Definition point.h:284
RDKit::MolDraw2D_detail::DrawTextFT::extractOutline
virtual double extractOutline()
RDKit::MolDraw2D_detail::DrawTextFT::fontPosToDrawPos
void fontPosToDrawPos(FT_Pos fx, FT_Pos fy, double &dx, double &dy) const
RDKit::MolDraw2D_detail::DrawTextFT::x_trans_
double x_trans_
Definition DrawTextFT.h:69
RDKit::MolDraw2D_detail::DrawTextFT::font_file_
std::string font_file_
Definition DrawTextFT.h:68
RDKit::MolDraw2D_detail::DrawTextFT::DrawTextFT
DrawTextFT(DrawTextFT &&)=delete
RDKit::MolDraw2D_detail::DrawTextFT::ConicToFunctionImpl
virtual int ConicToFunctionImpl(const FT_Vector *control, const FT_Vector *to)=0
RDKit::MolDraw2D_detail::DrawTextFT::DrawTextFT
DrawTextFT(double max_fnt_sz, double min_fnt_sz, const std::string &font_file)
RDKit::MolDraw2D_detail::DrawTextFT::setFontFile
void setFontFile(const std::string &font_file) override
RDKit::MolDraw2D_detail::DrawTextFT::LineToFunctionImpl
virtual int LineToFunctionImpl(const FT_Vector *to)=0
RDKit::MolDraw2D_detail::DrawTextFT::string_y_max_
FT_Pos string_y_max_
Definition DrawTextFT.h:71
RDKit::MolDraw2D_detail::DrawTextFT::library_
FT_Library library_
Definition DrawTextFT.h:66
RDKit::MolDraw2D_detail::DrawTextFT::fontCoordToDrawCoord
double fontCoordToDrawCoord(FT_Pos fc) const
RDKit::MolDraw2D_detail::DrawTextFT::getStringRects
void getStringRects(const std::string &text, std::vector< std::shared_ptr< StringRect > > &rects, std::vector< TextDrawType > &draw_modes, std::vector< char > &draw_chars) const override
RDKit::MolDraw2D_detail::DrawTextFT::face_
FT_Face face_
Definition DrawTextFT.h:67
RDKit::MolDraw2D_detail::DrawTextFT::em_scale_
double em_scale_
Definition DrawTextFT.h:72
RDKit::MolDraw2D_detail::DrawTextFT::y_trans_
double y_trans_
Definition DrawTextFT.h:69
RDKit::MolDraw2D_detail::DrawTextFT::~DrawTextFT
~DrawTextFT() override
RDKit::MolDraw2D_detail::DrawTextFT::MoveToFunctionImpl
virtual int MoveToFunctionImpl(const FT_Vector *to)=0
RDKit::MolDraw2D_detail::DrawTextFT::calcGlyphBBox
void calcGlyphBBox(char c, FT_Pos &x_min, FT_Pos &y_min, FT_Pos &x_max, FT_Pos &y_max, FT_Pos &advance) const
RDKit::MolDraw2D_detail::DrawTextFT::DrawTextFT
DrawTextFT(const DrawTextFT &)=delete
RDKit::MolDraw2D_detail::DrawTextFT::drawChar
void drawChar(char c, const Point2D &cds) override
RDKit::MolDraw2D_detail::DrawTextFT::operator=
DrawTextFT & operator=(DrawTextFT &&)=delete
RDKit::MolDraw2D_detail::DrawTextFT::operator=
DrawTextFT & operator=(const DrawTextFT &)=delete
RDKit::MolDraw2D_detail::DrawTextFT::getFontFile
std::string getFontFile() const override
RDKit::MolDraw2D_detail::DrawTextFT::CubicToFunctionImpl
virtual int CubicToFunctionImpl(const FT_Vector *controlOne, const FT_Vector *controlTwo, const FT_Vector *to)=0
RDKit::MolDraw2D_detail::DrawText::DrawText
DrawText(double max_fnt_sz, double min_fnt_sz)
export.h
RDKIT_MOLDRAW2D_EXPORT
#define RDKIT_MOLDRAW2D_EXPORT
Definition export.h:313
RDKit::MolDraw2D_detail
Definition AtomSymbol.h:30
RDKit::MolDraw2D_detail::moveToFunction
int moveToFunction(const FT_Vector *to, void *user)
RDKit::MolDraw2D_detail::cubicToFunction
int cubicToFunction(const FT_Vector *controlOne, const FT_Vector *controlTwo, const FT_Vector *to, void *user)
RDKit::MolDraw2D_detail::conicToFunction
int conicToFunction(const FT_Vector *control, const FT_Vector *to, void *user)
RDKit::MolDraw2D_detail::lineToFunction
int lineToFunction(const FT_Vector *to, void *user)
RDKit
Std stuff.
Definition Abbreviations.h:19