GNU Octave  6.2.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-2021 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 
39 namespace octave
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  : name (), weight (), angle (), size (0)
88  { }
89 
90  font (const std::string& nm, const std::string& wt,
91  const std::string& ang, double sz)
92  : name (nm), weight (wt), angle (ang), size (sz)
93  { }
94 
95  font (const font& ft)
96  : name (ft.name), weight (ft.weight), angle (ft.angle),
97  size (ft.size)
98  { }
99 
100  ~font (void) = default;
101 
102  font& operator = (const font& ft)
103  {
104  if (&ft != this)
105  {
106  name = ft.name;
107  weight = ft.weight;
108  angle = ft.angle;
109  size = ft.size;
110  }
111 
112  return *this;
113  }
114 
115  std::string get_name (void) const { return name; }
116 
117  std::string get_weight (void) const { return weight; }
118 
119  std::string get_angle (void) const { return angle; }
120 
121  double get_size (void) const { return size; }
122 
123  protected:
124 
125  std::string name;
126  std::string weight;
127  std::string angle;
128  double 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 x0, const double y0)
138  : str (s), family (f.get_name ()), fnt (f), x (x0), y (y0), z (0.0),
139  xdata (), code (0), color (Matrix (1,3,0.0))
140  { }
141 
142  string (const string& s)
143  : str (s.str), family (s.family), fnt (s.fnt), x (s.x), y (s.y),
144  z (s.z), xdata (s.xdata), code (s.code), color (s.color)
145  { }
146 
147  ~string (void) = default;
148 
149  string& operator = (const string& s)
150  {
151  if (&s != this)
152  {
153  str = s.str;
154  family = s.family;
155  fnt = s.fnt;
156  x = s.x;
157  y = s.y;
158  z = s.z;
159  xdata = s.xdata;
160  code = s.code;
161  color = s.color;
162  }
163 
164  return *this;
165  }
166 
167  void set_string (const std::string& s) { str = s; }
168 
169  std::string get_string (void) const { return str; }
170 
171  std::string get_name (void) const { return fnt.get_name (); }
172 
173  std::string get_family (void) const { return family; }
174 
175  void set_family (const std::string& nm) { family = nm; }
176 
177  std::string get_weight (void) const { return fnt.get_weight (); }
178 
179  std::string get_angle (void) const { return fnt.get_angle (); }
180 
181  double get_size (void) const { return fnt.get_size (); }
182 
183  void set_x (const double x0) { x = x0; }
184 
185  double get_x (void) const { return x; }
186 
187  void set_xdata (const std::vector<double>& x0) { xdata = x0; }
188 
189  std::vector<double> get_xdata (void) const { return xdata; }
190 
191  void set_y (const double y0) { y = y0; }
192 
193  double get_y (void) const { return y; }
194 
195  void set_z (const double z0) { z = z0; }
196 
197  double get_z (void) const { return z; }
198 
199  void set_code (const uint32_t c) { code = c; }
200 
201  uint32_t get_code (void) const { return code; }
202 
203  void set_color (const uint8NDArray& c)
204  {
205  color(0) = static_cast<double> (c(0)) / 255;
206  color(1) = static_cast<double> (c(1)) / 255;
207  color(2) = static_cast<double> (c(2)) / 255;
208  }
209 
210  Matrix get_color (void) const { return color; }
211 
212  private:
213 
214  std::string str;
215  std::string family;
217  double x, y, z;
218  std::vector<double> xdata;
219  uint32_t code;
221  };
222 
223  void text_to_strlist (const std::string& txt,
224  std::list<string>& lst, Matrix& box,
225  int halign, int valign, double rotation = 0.0,
226  const caseless_str& interpreter = "tex");
227 
228  private:
229 
231  };
232 }
233 
234 #endif
Definition: dMatrix.h:42
std::string get_angle(void) const
double get_size(void) const
font(const std::string &nm, const std::string &wt, const std::string &ang, double sz)
Definition: text-renderer.h:90
std::string get_weight(void) const
std::string get_name(void) const
void set_family(const std::string &nm)
void set_string(const std::string &s)
std::vector< double > get_xdata(void) const
void set_code(const uint32_t c)
void set_xdata(const std::vector< double > &x0)
std::vector< double > xdata
double get_size(void) const
void set_z(const double z0)
std::string get_name(void) const
void set_y(const double y0)
std::string get_angle(void) const
std::string get_string(void) const
std::string get_weight(void) const
std::string get_family(void) const
uint32_t get_code(void) const
string(const std::string &s, font &f, const double x0, const double y0)
Matrix get_color(void) const
void set_x(const double x0)
void set_color(const uint8NDArray &c)
text_renderer(const text_renderer &)=delete
base_text_renderer * rep
QString name
F77_RET_T const F77_DBLE * x
static double f(double k, double l_nu, double c_pm)
Definition: randpoisson.cc:118
static octave_value box(JNIEnv *jni_env, void *jobj, void *jcls_arg=nullptr)