File: DrawTextFT.h

package info (click to toggle)
rdkit 202503.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 220,160 kB
  • sloc: cpp: 399,240; python: 77,453; ansic: 25,517; java: 8,173; javascript: 4,005; sql: 2,389; yacc: 1,565; lex: 1,263; cs: 1,081; makefile: 580; xml: 229; fortran: 183; sh: 105
file content (99 lines) | stat: -rw-r--r-- 3,550 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//
//  Copyright (C) 2020-2022 David Cosgrove and other RDKit contributors
//
//   @@ 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).
//
// This is an abstract base class derived from DrawText that does drawing
// using FreeType.

#ifndef RDKIT_DRAWTEXTFT_H
#define RDKIT_DRAWTEXTFT_H

#include <string>

#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_BBOX_H
#include FT_OUTLINE_H

#include <RDGeneral/export.h>
#include <GraphMol/MolDraw2D/DrawText.h>

namespace RDKit {

struct StringRect;

namespace MolDraw2D_detail {

// ****************************************************************************
class RDKIT_MOLDRAW2D_EXPORT DrawTextFT : public DrawText {
 public:
  virtual ~DrawTextFT() override;
  virtual int MoveToFunctionImpl(const FT_Vector *to) = 0;
  virtual int LineToFunctionImpl(const FT_Vector *to) = 0;
  virtual int ConicToFunctionImpl(const FT_Vector *control,
                                  const FT_Vector *to) = 0;
  virtual int CubicToFunctionImpl(const FT_Vector *controlOne,
                                  const FT_Vector *controlTwo,
                                  const FT_Vector *to) = 0;

  DrawTextFT(double max_fnt_sz, double min_fnt_sz,
             const std::string &font_file);
  DrawTextFT(const DrawTextFT &) = delete;
  DrawTextFT(DrawTextFT &&) = delete;
  DrawTextFT &operator=(const DrawTextFT &) = delete;
  DrawTextFT &operator=(DrawTextFT &&) = delete;

  void drawChar(char c, const Point2D &cds) override;

  // unless over-ridden by the c'tor, this will return a hard-coded
  // file from $RDBASE.
  std::string getFontFile() const override;
  void setFontFile(const std::string &font_file) override;

  double fontCoordToDrawCoord(FT_Pos fc) const;
  void fontPosToDrawPos(FT_Pos fx, FT_Pos fy, double &dx, double &dy) const;
  // adds x_trans_ and y_trans_ to coords returns x advance distance
  virtual double extractOutline();

  FT_Library library_;
  FT_Face face_;
  std::string font_file_;  // over-rides default if not empty.
  double x_trans_, y_trans_;
  mutable FT_Pos
      string_y_max_;  // maximum y value of string drawn, for inverting y
  double em_scale_;

  // return a vector of StringRects, one for each char in text, with
  // super- and subscripts taken into account.  Sizes in pixel coords,
  // i.e. scaled by fontScale().
  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;

  // calculate the bounding box of the glyph for c in
  // font units (0 -> face_->units_per_EM (2048 for roboto font).
  void calcGlyphBBox(char c, FT_Pos &x_min, FT_Pos &y_min, FT_Pos &x_max,
                     FT_Pos &y_max, FT_Pos &advance) const;
};

// Callbacks for FT_Outline_Decompose.  user should be a pointer to
// an instance of DrawTextFT.
int moveToFunction(const FT_Vector *to, void *user);
int lineToFunction(const FT_Vector *to, void *user);
int conicToFunction(const FT_Vector *control, const FT_Vector *to, void *user);
int cubicToFunction(const FT_Vector *controlOne, const FT_Vector *controlTwo,
                    const FT_Vector *to, void *user);

}  // namespace MolDraw2D_detail
}  // namespace RDKit

#endif  // RDKIT_DRAWTEXTFT_H