GNU Octave  8.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-2023 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 (void);
51 
52  // No copying!
53 
54  text_renderer (const text_renderer&) = delete;
55 
56  text_renderer& operator = (const text_renderer&) = delete;
57 
58  ~text_renderer (void);
59 
60  bool ok (void) const;
61 
62  Matrix get_extent (text_element *elt, double rotation = 0.0);
63 
64  Matrix get_extent (const std::string& txt, double rotation = 0.0,
65  const caseless_str& interpreter = "tex");
66 
67  void set_anti_aliasing (bool val);
68 
69  void set_font (const std::string& name, const std::string& weight,
70  const std::string& angle, double size);
71 
72  octave_map get_system_fonts (void);
73 
74  void set_color (const Matrix& c);
75 
76  void text_to_pixels (const std::string& txt,
77  uint8NDArray& pxls, Matrix& bbox,
78  int halign, int valign, double rotation = 0.0,
79  const caseless_str& interpreter = "tex",
80  bool handle_rotation = true);
81 
82  class font
83  {
84  public:
85 
86  font (void)
87  : m_name (), m_weight (), m_angle (), m_size (0)
88  { }
89 
90  font (const std::string& nm, const std::string& wt,
91  const std::string& ang, double sz)
92  : m_name (nm), m_weight (wt), m_angle (ang), m_size (sz)
93  { }
94 
95  font (const font& ft)
96  : m_name (ft.m_name), m_weight (ft.m_weight), m_angle (ft.m_angle),
97  m_size (ft.m_size)
98  { }
99 
100  ~font (void) = default;
101 
102  font& operator = (const font& ft)
103  {
104  if (&ft != this)
105  {
106  m_name = ft.m_name;
107  m_weight = ft.m_weight;
108  m_angle = ft.m_angle;
109  m_size = ft.m_size;
110  }
111 
112  return *this;
113  }
114 
115  std::string get_name (void) const { return m_name; }
116 
117  std::string get_weight (void) const { return m_weight; }
118 
119  std::string get_angle (void) const { return m_angle; }
120 
121  double get_size (void) const { return m_size; }
122 
123  protected:
124 
125  std::string m_name;
126  std::string m_weight;
127  std::string m_angle;
128  double m_size;
129  };
130 
131  // Container for substrings after parsing.
132 
133  class string
134  {
135  public:
136 
137  string (const std::string& s, font& f, const double x, const double y)
138  : m_str (s), m_family (f.get_name ()), m_fnt (f), m_x (x), m_y (y),
139  m_z (0.0), m_xdata (), m_code (0), m_color (Matrix (1, 3, 0.0)),
140  m_svg_element ()
141  { }
142 
143  string (const string& s)
144  : m_str (s.m_str), m_family (s.m_family), m_fnt (s.m_fnt), m_x (s.m_x),
145  m_y (s.m_y), m_z (s.m_z), m_xdata (s.m_xdata), m_code (s.m_code),
146  m_color (s.m_color), m_svg_element (s.m_svg_element)
147  { }
148 
149  ~string (void) = default;
150 
151  string& operator = (const string& s)
152  {
153  if (&s != this)
154  {
155  m_str = s.m_str;
156  m_family = s.m_family;
157  m_fnt = s.m_fnt;
158  m_x = s.m_x;
159  m_y = s.m_y;
160  m_z = s.m_z;
161  m_xdata = s.m_xdata;
162  m_code = s.m_code;
163  m_color = s.m_color;
164  }
165 
166  return *this;
167  }
168 
169  void set_string (const std::string& s) { m_str = s; }
170 
171  std::string get_string (void) const { return m_str; }
172 
173  std::string get_name (void) const { return m_fnt.get_name (); }
174 
175  std::string get_family (void) const { return m_family; }
176 
177  void set_family (const std::string& nm) { m_family = nm; }
178 
179  std::string get_weight (void) const { return m_fnt.get_weight (); }
180 
181  std::string get_angle (void) const { return m_fnt.get_angle (); }
182 
183  double get_size (void) const { return m_fnt.get_size (); }
184 
185  void set_x (const double x) { m_x = x; }
186 
187  double get_x (void) const { return m_x; }
188 
189  void set_xdata (const std::vector<double>& x) { m_xdata = x; }
190 
191  std::vector<double> get_xdata (void) const { return m_xdata; }
192 
193  void set_y (const double y) { m_y = y; }
194 
195  double get_y (void) const { return m_y; }
196 
197  void set_z (const double z) { m_z = z; }
198 
199  double get_z (void) const { return m_z; }
200 
201  void set_code (const uint32_t code) { m_code = code; }
202 
203  uint32_t get_code (void) const { return m_code; }
204 
205  void set_svg_element (const std::string& svg) { m_svg_element = svg; }
206 
207  std::string get_svg_element (void) const { return m_svg_element; }
208 
209  void set_color (const uint8NDArray& c)
210  {
211  m_color(0) = static_cast<double> (c(0)) / 255;
212  m_color(1) = static_cast<double> (c(1)) / 255;
213  m_color(2) = static_cast<double> (c(2)) / 255;
214  }
215 
216  Matrix get_color (void) const { return m_color; }
217 
218  private:
219 
220  std::string m_str;
221  std::string m_family;
223  double m_x, m_y, m_z;
224  std::vector<double> m_xdata;
225  uint32_t m_code;
227  std::string m_svg_element;
228  };
229 
230  void text_to_strlist (const std::string& txt,
231  std::list<string>& lst, Matrix& box,
232  int halign, int valign, double rotation = 0.0,
233  const caseless_str& interpreter = "tex");
234 
235 private:
236 
239 };
240 
242 
243 #endif
OCTAVE_END_NAMESPACE(octave)
Definition: dMatrix.h:42
font(const std::string &nm, const std::string &wt, const std::string &ang, double sz)
Definition: text-renderer.h:90
font(const font &ft)
Definition: text-renderer.h:95
std::string m_weight
std::string get_angle(void) const
std::string get_name(void) const
~font(void)=default
double get_size(void) const
std::string get_weight(void) const
std::string get_weight(void) const
Matrix get_color(void) const
void set_z(const double z)
~string(void)=default
std::string get_svg_element(void) const
std::vector< double > m_xdata
std::string get_name(void) const
string(const std::string &s, font &f, const double x, const double y)
void set_string(const std::string &s)
void set_svg_element(const std::string &svg)
void set_xdata(const std::vector< double > &x)
void set_y(const double y)
std::string get_family(void) const
double get_z(void) const
string(const string &s)
double get_x(void) const
std::string get_string(void) const
std::string m_svg_element
std::vector< double > get_xdata(void) const
double get_y(void) const
void set_x(const double x)
void set_family(const std::string &nm)
double get_size(void) const
std::string get_angle(void) const
uint32_t get_code(void) const
void set_code(const uint32_t code)
void set_color(const uint8NDArray &c)
base_text_renderer * m_latex_rep
base_text_renderer * m_rep
text_renderer(const text_renderer &)=delete
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
static octave_value box(JNIEnv *jni_env, void *jobj, void *jcls_arg=nullptr)