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