comparison libinterp/corefcn/text-renderer.h @ 21209:67d2965af0b5

revamp text rendering classes * base-text-renderer.h: New file. * ft-text-renderer.h, ft-text-renderer.cc: New files for freetype text rendering classes, adapted from txt-eng-ft.h and txt-eng.cc. * text-renderer.h, text-renderer.cc: New files. Public interface for text rendering. * gl-select.cc, gl-render.cc, gl-render.h, gl2ps-print.cc, graphics.cc, graphics.in.h: Adapt to use new text rendering interface that does not require checking HAVE_FREETYPE. * libinterp/corefcn/module.mk: Update.
author John W. Eaton <jwe@octave.org>
date Sat, 06 Feb 2016 08:15:53 -0500
parents
children 1473547f50f5
comparison
equal deleted inserted replaced
21208:f5e05c11c343 21209:67d2965af0b5
1 /*
2
3 Copyright (C) 2016 John W. Eaton
4 Copyright (C) 2009-2015 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 <list>
28 #include <string>
29
30 #include "caseless-str.h"
31 #include "dMatrix.h"
32 #include "uint8NDArray.h"
33
34 #include "txt-eng.h"
35
36 class base_text_renderer;
37
38 class
39 OCTINTERP_API
40 text_renderer
41 {
42 public:
43
44 text_renderer (void);
45
46 ~text_renderer (void);
47
48 bool ok (void) const;
49
50 Matrix get_extent (text_element *elt, double rotation = 0.0);
51
52 Matrix get_extent (const std::string& txt, double rotation = 0.0,
53 const caseless_str& interpreter = "tex");
54
55 void set_font (const std::string& name, const std::string& weight,
56 const std::string& angle, double size);
57
58 void set_color (const Matrix& c);
59
60 void text_to_pixels (const std::string& txt,
61 uint8NDArray& pxls, Matrix& bbox,
62 int halign, int valign, double rotation = 0.0,
63 const caseless_str& interpreter = "tex",
64 bool handle_rotation = true);
65
66 class font
67 {
68 public:
69
70 font (void)
71 : name (), weight (), angle (), size (0)
72 { }
73
74 font (const std::string& nm, const std::string& wt,
75 const std::string& ang, double sz)
76 : name (nm), weight (wt), angle (ang), size (sz)
77 { }
78
79 font (const font& ft)
80 : name (ft.name), weight (ft.weight), angle (ft.angle),
81 size (ft.size)
82 { }
83
84 ~font (void) { }
85
86 font& operator = (const font& ft)
87 {
88 if (&ft != this)
89 {
90 name = ft.name;
91 weight = ft.weight;
92 angle = ft.angle;
93 size = ft.size;
94 }
95
96 return *this;
97 }
98
99 std::string get_name (void) const { return name; }
100
101 std::string get_weight (void) const { return weight; }
102
103 std::string get_angle (void) const { return angle; }
104
105 double get_size (void) const { return size; }
106
107 protected:
108
109 std::string name;
110 std::string weight;
111 std::string angle;
112 double size;
113 };
114
115 // Container for substrings after parsing.
116
117 class string
118 {
119 public:
120
121 string (const std::string& s, font& f, const double x0, const double y0)
122 : str (s), fnt (f), x (x0), y (y0), z (0.0), code (0),
123 color (Matrix (1,3,0.0))
124 { }
125
126 string (const string& s)
127 : str (s.str), fnt (s.fnt), x (s.x), y (s.y), code (s.code),
128 color (s.color)
129 { }
130
131 ~string (void) { }
132
133 string& operator = (const string& s)
134 {
135 if (&s != this)
136 {
137 str = s.str;
138 fnt = s.fnt;
139 x = s.x;
140 y = s.y;
141 code = s.code;
142 color = s.color;
143 }
144
145 return *this;
146 }
147
148 void set_string (const std::string& s) { str = s; }
149
150 std::string get_string (void) const { return str; }
151
152 std::string get_name (void) const { return fnt.get_name (); }
153
154 std::string get_weight (void) const { return fnt.get_weight (); }
155
156 std::string get_angle (void) const { return fnt.get_angle (); }
157
158 double get_size (void) const { return fnt.get_size (); }
159
160 void set_x (const double x0) { x = x0; }
161
162 double get_x (void) const { return x; }
163
164 void set_y (const double y0) { y = y0; }
165
166 double get_y (void) const { return y; }
167
168 void set_z (const double z0) { z = z0; }
169
170 double get_z (void) const { return z; }
171
172 void set_code (const uint32_t c) { code = c; }
173
174 uint32_t get_code (void) const { return code; }
175
176 void set_color (const uint8NDArray& c)
177 {
178 color(0) = static_cast<double> (c(0)) / 255;
179 color(1) = static_cast<double> (c(1)) / 255;
180 color(2) = static_cast<double> (c(2)) / 255;
181 }
182
183 Matrix get_color (void) const { return color; }
184
185 private:
186
187 std::string str;
188 font fnt;
189 double x, y, z;
190 uint32_t code;
191 Matrix color;
192 };
193
194 void text_to_strlist (const std::string& txt,
195 std::list<string>& lst, Matrix& box,
196 int halign, int valign, double rotation = 0.0,
197 const caseless_str& interpreter = "tex");
198
199 private:
200
201 base_text_renderer *rep;
202
203 // No copying!
204
205 text_renderer (const text_renderer&);
206
207 text_renderer& operator = (const text_renderer&);
208 };
209
210 #endif