GNU Octave  4.4.1
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) 2016-2018 John W. Eaton
4 Copyright (C) 2009-2018 Michael Goffioul
5 
6 This file is part of Octave.
7 
8 Octave is free software: you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <https://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if ! defined (octave_text_renderer_h)
25 #define octave_text_renderer_h 1
26 
27 #include "octave-config.h"
28 
29 #include <list>
30 #include <string>
31 #include <vector>
32 
33 #include "caseless-str.h"
34 #include "dMatrix.h"
35 #include "uint8NDArray.h"
36 
37 #include "txt-eng.h"
38 
39 namespace octave
40 {
41  class base_text_renderer;
42 
43  class
44  OCTINTERP_API
46  {
47  public:
48 
49  text_renderer (void);
50 
51  // No copying!
52 
53  text_renderer (const text_renderer&) = delete;
54 
55  text_renderer& operator = (const text_renderer&) = delete;
56 
57  ~text_renderer (void);
58 
59  bool ok (void) const;
60 
61  Matrix get_extent (text_element *elt, double rotation = 0.0);
62 
63  Matrix get_extent (const std::string& txt, double rotation = 0.0,
64  const caseless_str& interpreter = "tex");
65 
66  void set_font (const std::string& name, const std::string& weight,
67  const std::string& angle, double size);
68 
69  void set_color (const Matrix& c);
70 
71  void text_to_pixels (const std::string& txt,
72  uint8NDArray& pxls, Matrix& bbox,
73  int halign, int valign, double rotation = 0.0,
74  const caseless_str& interpreter = "tex",
75  bool handle_rotation = true);
76 
77  class font
78  {
79  public:
80 
81  font (void)
82  : name (), weight (), angle (), size (0)
83  { }
84 
85  font (const std::string& nm, const std::string& wt,
86  const std::string& ang, double sz)
87  : name (nm), weight (wt), angle (ang), size (sz)
88  { }
89 
90  font (const font& ft)
91  : name (ft.name), weight (ft.weight), angle (ft.angle),
92  size (ft.size)
93  { }
94 
95  ~font (void) = default;
96 
97  font& operator = (const font& ft)
98  {
99  if (&ft != this)
100  {
101  name = ft.name;
102  weight = ft.weight;
103  angle = ft.angle;
104  size = ft.size;
105  }
106 
107  return *this;
108  }
109 
110  std::string get_name (void) const { return name; }
111 
112  std::string get_weight (void) const { return weight; }
113 
114  std::string get_angle (void) const { return angle; }
115 
116  double get_size (void) const { return size; }
117 
118  protected:
119 
123  double size;
124  };
125 
126  // Container for substrings after parsing.
127 
128  class string
129  {
130  public:
131 
132  string (const std::string& s, font& f, const double x0, const double y0)
133  : str (s), family (f.get_name ()), fnt (f), x (x0), y (y0), z (0.0),
134  xdata (), code (0), color (Matrix (1,3,0.0))
135  { }
136 
137  string (const string& s)
138  : str (s.str), family (s.family), fnt (s.fnt), x (s.x), y (s.y),
139  xdata (s.xdata), code (s.code), color (s.color)
140  { }
141 
142  ~string (void) = default;
143 
144  string& operator = (const string& s)
145  {
146  if (&s != this)
147  {
148  str = s.str;
149  family = s.family;
150  fnt = s.fnt;
151  x = s.x;
152  y = s.y;
153  xdata = s.xdata;
154  code = s.code;
155  color = s.color;
156  }
157 
158  return *this;
159  }
160 
161  void set_string (const std::string& s) { str = s; }
162 
163  std::string get_string (void) const { return str; }
164 
165  std::string get_name (void) const { return fnt.get_name (); }
166 
167  std::string get_family (void) const { return family; }
168 
169  void set_family (const std::string& nm) { family = nm; }
170 
171  std::string get_weight (void) const { return fnt.get_weight (); }
172 
173  std::string get_angle (void) const { return fnt.get_angle (); }
174 
175  double get_size (void) const { return fnt.get_size (); }
176 
177  void set_x (const double x0) { x = x0; }
178 
179  double get_x (void) const { return x; }
180 
181  void set_xdata (const std::vector<double>& x0) { xdata = x0; }
182 
183  std::vector<double> get_xdata (void) const { return xdata; }
184 
185  void set_y (const double y0) { y = y0; }
186 
187  double get_y (void) const { return y; }
188 
189  void set_z (const double z0) { z = z0; }
190 
191  double get_z (void) const { return z; }
192 
193  void set_code (const uint32_t c) { code = c; }
194 
195  uint32_t get_code (void) const { return code; }
196 
197  void set_color (const uint8NDArray& c)
198  {
199  color(0) = static_cast<double> (c(0)) / 255;
200  color(1) = static_cast<double> (c(1)) / 255;
201  color(2) = static_cast<double> (c(2)) / 255;
202  }
203 
204  Matrix get_color (void) const { return color; }
205 
206  private:
207 
211  double x, y, z;
212  std::vector<double> xdata;
213  uint32_t code;
215  };
216 
217  void text_to_strlist (const std::string& txt,
218  std::list<string>& lst, Matrix& box,
219  int halign, int valign, double rotation = 0.0,
220  const caseless_str& interpreter = "tex");
221 
222  private:
223 
225  };
226 }
227 
228 #endif
double get_size(void) const
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE * f
std::string get_name(void) const
void set_z(const double z0)
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
s
Definition: file-io.cc:2729
void set_string(const std::string &s)
std::string get_weight(void) const
std::vector< double > get_xdata(void) const
string(const std::string &s, font &f, const double x0, const double y0)
void set_color(const uint8NDArray &c)
void set_code(const uint32_t c)
nd deftypefn *std::string name
Definition: sysdep.cc:647
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:975
std::string get_angle(void) const
static octave_value box(JNIEnv *jni_env, void *jobj, void *jcls_arg=nullptr)
void set_xdata(const std::vector< double > &x0)
base_text_renderer * rep
std::string str
Definition: hash.cc:118
std::string get_weight(void) const
do not permute tem code
Definition: balance.cc:90
std::vector< double > xdata
Definition: dMatrix.h:36
sz
Definition: data.cc:5264
std::string get_name(void) const
double get_size(void) const
std::string get_family(void) const
std::string get_angle(void) const
void set_x(const double x0)
font(const std::string &nm, const std::string &wt, const std::string &ang, double sz)
Definition: text-renderer.h:85
the element is set to zero In other the statement xample y
Definition: data.cc:5264
uint32_t get_code(void) const
Matrix get_color(void) const
void set_y(const double y0)
std::string get_string(void) const
void set_family(const std::string &nm)
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE * x