GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
text-renderer.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2009-2024 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_text_renderer_h)
27 #define octave_text_renderer_h 1
28 
29 #include "octave-config.h"
30 
31 #include <list>
32 #include <string>
33 #include <vector>
34 
35 #include "caseless-str.h"
36 #include "dMatrix.h"
37 #include "uint8NDArray.h"
38 
40 
41 class base_text_renderer;
42 class text_element;
43 
44 class
45 OCTINTERP_API
47 {
48 public:
49 
50  text_renderer ();
51 
52  OCTAVE_DISABLE_COPY_MOVE (text_renderer)
53 
54  ~text_renderer ();
55 
56  bool ok () const;
57 
58  Matrix get_extent (text_element *elt, double rotation = 0.0);
59 
60  Matrix get_extent (const std::string& txt, double rotation = 0.0,
61  const caseless_str& interpreter = "tex");
62 
63  void set_anti_aliasing (bool val);
64 
65  void set_font (const std::string& name, const std::string& weight,
66  const std::string& angle, double size);
67 
68  octave_map get_system_fonts ();
69 
70  void set_color (const Matrix& c);
71 
72  void text_to_pixels (const std::string& txt,
73  uint8NDArray& pxls, Matrix& bbox,
74  int halign, int valign, double rotation = 0.0,
75  const caseless_str& interpreter = "tex",
76  bool handle_rotation = true);
77 
78  class font
79  {
80  public:
81 
82  font ()
83  : m_name (), m_weight (), m_angle (), m_size (0)
84  { }
85 
86  font (const std::string& nm, const std::string& wt,
87  const std::string& ang, double sz)
88  : m_name (nm), m_weight (wt), m_angle (ang), m_size (sz)
89  { }
90 
91  font (const font& ft)
92  : m_name (ft.m_name), m_weight (ft.m_weight), m_angle (ft.m_angle),
93  m_size (ft.m_size)
94  { }
95 
96  ~font () = default;
97 
98  font& operator = (const font& ft)
99  {
100  if (&ft != this)
101  {
102  m_name = ft.m_name;
103  m_weight = ft.m_weight;
104  m_angle = ft.m_angle;
105  m_size = ft.m_size;
106  }
107 
108  return *this;
109  }
110 
111  std::string get_name () const { return m_name; }
112 
113  std::string get_weight () const { return m_weight; }
114 
115  std::string get_angle () const { return m_angle; }
116 
117  double get_size () const { return m_size; }
118 
119  protected:
120 
121  std::string m_name;
122  std::string m_weight;
123  std::string m_angle;
124  double m_size;
125  };
126 
127  // Container for substrings after parsing.
128 
129  class string
130  {
131  public:
132 
133  string () = delete;
134 
135  string (const std::string& s, const font& f, double x, double y)
136  : m_str (s), m_family (f.get_name ()), m_fnt (f), m_x (x), m_y (y),
137  m_z (0.0), m_xdata (), m_code (0), m_color (Matrix (1, 3, 0.0)),
138  m_svg_element ()
139  { }
140 
141  OCTAVE_DEFAULT_COPY_MOVE_DELETE (string)
142 
143  void set_string (const std::string& s) { m_str = s; }
144 
145  std::string get_string () const { return m_str; }
146 
147  std::string get_name () const { return m_fnt.get_name (); }
148 
149  std::string get_family () const { return m_family; }
150 
151  void set_family (const std::string& nm) { m_family = nm; }
152 
153  std::string get_weight () const { return m_fnt.get_weight (); }
154 
155  std::string get_angle () const { return m_fnt.get_angle (); }
156 
157  double get_size () const { return m_fnt.get_size (); }
158 
159  void set_x (const double x) { m_x = x; }
160 
161  double get_x () const { return m_x; }
162 
163  void set_xdata (const std::vector<double>& x) { m_xdata = x; }
164 
165  std::vector<double> get_xdata () const { return m_xdata; }
166 
167  void set_y (const double y) { m_y = y; }
168 
169  double get_y () const { return m_y; }
170 
171  void set_z (const double z) { m_z = z; }
172 
173  double get_z () const { return m_z; }
174 
175  void set_code (const uint32_t code) { m_code = code; }
176 
177  uint32_t get_code () const { return m_code; }
178 
179  void set_svg_element (const std::string& svg) { m_svg_element = svg; }
180 
181  std::string get_svg_element () const { return m_svg_element; }
182 
183  void set_color (const uint8NDArray& c)
184  {
185  m_color(0) = static_cast<double> (c(0)) / 255;
186  m_color(1) = static_cast<double> (c(1)) / 255;
187  m_color(2) = static_cast<double> (c(2)) / 255;
188  }
189 
190  Matrix get_color () const { return m_color; }
191 
192  private:
193 
194  std::string m_str;
195  std::string m_family;
196  font m_fnt;
197  double m_x, m_y, m_z;
198  std::vector<double> m_xdata;
199  uint32_t m_code;
200  Matrix m_color;
201  std::string m_svg_element;
202  };
203 
204  void text_to_strlist (const std::string& txt,
205  std::list<string>& lst, Matrix& box,
206  int halign, int valign, double rotation = 0.0,
207  const caseless_str& interpreter = "tex");
208 
209 private:
210 
211  base_text_renderer *m_rep;
212  base_text_renderer *m_latex_rep;
213 };
214 
215 OCTAVE_END_NAMESPACE(octave)
216 
217 #endif
Definition: dMatrix.h:42
double get_size() const
std::string get_angle() const
font(const std::string &nm, const std::string &wt, const std::string &ang, double sz)
Definition: text-renderer.h:86
std::string get_weight() const
font(const font &ft)
Definition: text-renderer.h:91
std::string m_weight
std::string get_name() const
void set_z(const double z)
double get_size() const
std::string get_string() const
void set_svg_element(const std::string &svg)
void set_xdata(const std::vector< double > &x)
std::string get_angle() const
void set_y(const double y)
double get_x() const
std::vector< double > get_xdata() const
uint32_t get_code() const
std::string get_weight() const
Matrix get_color() const
string(const std::string &s, const font &f, double x, double y)
void set_x(const double x)
std::string get_svg_element() const
double get_z() const
void set_family(const std::string &nm)
std::string get_family() const
double get_y() const
std::string get_name() const
void set_code(const uint32_t code)
void set_color(const uint8NDArray &c)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
F77_RET_T const F77_DBLE * x
F77_RET_T const F77_DBLE const F77_DBLE * f