GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
text-renderer.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2016-2017 John W. Eaton
4 Copyright (C) 2009-2016 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 the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 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 <http://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 
32 #include "caseless-str.h"
33 #include "dMatrix.h"
34 #include "uint8NDArray.h"
35 
36 #include "txt-eng.h"
37 
38 namespace octave
39 {
40  class base_text_renderer;
41 
42  class
45  {
46  public:
47 
48  text_renderer (void);
49 
50  ~text_renderer (void);
51 
52  bool ok (void) const;
53 
54  Matrix get_extent (text_element *elt, double rotation = 0.0);
55 
56  Matrix get_extent (const std::string& txt, double rotation = 0.0,
57  const caseless_str& interpreter = "tex");
58 
59  void set_font (const std::string& name, const std::string& weight,
60  const std::string& angle, double size);
61 
62  void set_color (const Matrix& c);
63 
64  void text_to_pixels (const std::string& txt,
65  uint8NDArray& pxls, Matrix& bbox,
66  int halign, int valign, double rotation = 0.0,
67  const caseless_str& interpreter = "tex",
68  bool handle_rotation = true);
69 
70  class font
71  {
72  public:
73 
74  font (void)
75  : name (), weight (), angle (), size (0)
76  { }
77 
78  font (const std::string& nm, const std::string& wt,
79  const std::string& ang, double sz)
80  : name (nm), weight (wt), angle (ang), size (sz)
81  { }
82 
83  font (const font& ft)
84  : name (ft.name), weight (ft.weight), angle (ft.angle),
85  size (ft.size)
86  { }
87 
88  ~font (void) { }
89 
90  font& operator = (const font& ft)
91  {
92  if (&ft != this)
93  {
94  name = ft.name;
95  weight = ft.weight;
96  angle = ft.angle;
97  size = ft.size;
98  }
99 
100  return *this;
101  }
102 
103  std::string get_name (void) const { return name; }
104 
105  std::string get_weight (void) const { return weight; }
106 
107  std::string get_angle (void) const { return angle; }
108 
109  double get_size (void) const { return size; }
110 
111  protected:
112 
116  double size;
117  };
118 
119  // Container for substrings after parsing.
120 
121  class string
122  {
123  public:
124 
125  string (const std::string& s, font& f, const double x0, const double y0)
126  : str (s), fnt (f), x (x0), y (y0), z (0.0), code (0),
127  color (Matrix (1,3,0.0))
128  { }
129 
130  string (const string& s)
131  : str (s.str), fnt (s.fnt), x (s.x), y (s.y), code (s.code),
132  color (s.color)
133  { }
134 
135  ~string (void) { }
136 
137  string& operator = (const string& s)
138  {
139  if (&s != this)
140  {
141  str = s.str;
142  fnt = s.fnt;
143  x = s.x;
144  y = s.y;
145  code = s.code;
146  color = s.color;
147  }
148 
149  return *this;
150  }
151 
152  void set_string (const std::string& s) { str = s; }
153 
154  std::string get_string (void) const { return str; }
155 
156  std::string get_name (void) const { return fnt.get_name (); }
157 
158  std::string get_weight (void) const { return fnt.get_weight (); }
159 
160  std::string get_angle (void) const { return fnt.get_angle (); }
161 
162  double get_size (void) const { return fnt.get_size (); }
163 
164  void set_x (const double x0) { x = x0; }
165 
166  double get_x (void) const { return x; }
167 
168  void set_y (const double y0) { y = y0; }
169 
170  double get_y (void) const { return y; }
171 
172  void set_z (const double z0) { z = z0; }
173 
174  double get_z (void) const { return z; }
175 
176  void set_code (const uint32_t c) { code = c; }
177 
178  uint32_t get_code (void) const { return code; }
179 
180  void set_color (const uint8NDArray& c)
181  {
182  color(0) = static_cast<double> (c(0)) / 255;
183  color(1) = static_cast<double> (c(1)) / 255;
184  color(2) = static_cast<double> (c(2)) / 255;
185  }
186 
187  Matrix get_color (void) const { return color; }
188 
189  private:
190 
193  double x, y, z;
194  uint32_t code;
196  };
197 
198  void text_to_strlist (const std::string& txt,
199  std::list<string>& lst, Matrix& box,
200  int halign, int valign, double rotation = 0.0,
201  const caseless_str& interpreter = "tex");
202 
203  private:
204 
206 
207  // No copying!
208 
209  text_renderer (const text_renderer&);
210 
211  text_renderer& operator = (const text_renderer&);
212  };
213 }
214 
215 #endif
Octave interface to the compression and uncompression libraries.
Definition: aepbalance.cc:47
Matrix get_color(void) const
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &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 F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE * f
std::string get_weight(void) const
std::string get_name(void) const
void set_z(const double z0)
uint32_t get_code(void) const
std::string get_string(void) const
s
Definition: file-io.cc:2682
void set_string(const std::string &s)
string(const std::string &s, font &f, const double x0, const double y0)
double get_x(void) const
void set_color(const uint8NDArray &c)
void set_code(const uint32_t c)
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable name
Definition: input.cc:871
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:941
#define OCTINTERP_API
Definition: mexproto.h:69
std::string get_weight(void) const
double get_size(void) const
base_text_renderer * rep
std::string str
Definition: hash.cc:118
do not permute tem code
Definition: balance.cc:90
Definition: dMatrix.h:37
sz
Definition: data.cc:5342
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
std::string get_angle(void) const
std::string get_angle(void) const
void set_x(const double x0)
static octave_value box(JNIEnv *jni_env, void *jobj, void *jcls_arg=0)
Convert the Java object pointed to by jobj_arg with class jcls_arg to an Octave value.
Definition: ov-java.cc:1192
font(const std::string &nm, const std::string &wt, const std::string &ang, double sz)
Definition: text-renderer.h:78
double get_z(void) const
the element is set to zero In other the statement xample y
Definition: data.cc:5342
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable or any other valid Octave code The number of return their size
Definition: input.cc:871
double get_y(void) const
std::string get_name(void) const
void set_y(const double y0)
double get_size(void) const
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:854
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &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 F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE * x