Mercurial > octave
annotate libinterp/corefcn/text-renderer.h @ 22323:bac0d6f07a3e
maint: Update copyright notices for 2016.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 17 Aug 2016 01:05:19 -0400 |
parents | 1473547f50f5 |
children | 71dd9d5a5ecd |
rev | line source |
---|---|
21209 | 1 /* |
2 | |
3 Copyright (C) 2016 John W. Eaton | |
22323
bac0d6f07a3e
maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
4 Copyright (C) 2009-2016 Michael Goffioul |
21209 | 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 | |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21209
diff
changeset
|
27 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21209
diff
changeset
|
28 |
21209 | 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 class base_text_renderer; | |
39 | |
40 class | |
41 OCTINTERP_API | |
42 text_renderer | |
43 { | |
44 public: | |
45 | |
46 text_renderer (void); | |
47 | |
48 ~text_renderer (void); | |
49 | |
50 bool ok (void) const; | |
51 | |
52 Matrix get_extent (text_element *elt, double rotation = 0.0); | |
53 | |
54 Matrix get_extent (const std::string& txt, double rotation = 0.0, | |
55 const caseless_str& interpreter = "tex"); | |
56 | |
57 void set_font (const std::string& name, const std::string& weight, | |
58 const std::string& angle, double size); | |
59 | |
60 void set_color (const Matrix& c); | |
61 | |
62 void text_to_pixels (const std::string& txt, | |
63 uint8NDArray& pxls, Matrix& bbox, | |
64 int halign, int valign, double rotation = 0.0, | |
65 const caseless_str& interpreter = "tex", | |
66 bool handle_rotation = true); | |
67 | |
68 class font | |
69 { | |
70 public: | |
71 | |
72 font (void) | |
73 : name (), weight (), angle (), size (0) | |
74 { } | |
75 | |
76 font (const std::string& nm, const std::string& wt, | |
77 const std::string& ang, double sz) | |
78 : name (nm), weight (wt), angle (ang), size (sz) | |
79 { } | |
80 | |
81 font (const font& ft) | |
82 : name (ft.name), weight (ft.weight), angle (ft.angle), | |
83 size (ft.size) | |
84 { } | |
85 | |
86 ~font (void) { } | |
87 | |
88 font& operator = (const font& ft) | |
89 { | |
90 if (&ft != this) | |
91 { | |
92 name = ft.name; | |
93 weight = ft.weight; | |
94 angle = ft.angle; | |
95 size = ft.size; | |
96 } | |
97 | |
98 return *this; | |
99 } | |
100 | |
101 std::string get_name (void) const { return name; } | |
102 | |
103 std::string get_weight (void) const { return weight; } | |
104 | |
105 std::string get_angle (void) const { return angle; } | |
106 | |
107 double get_size (void) const { return size; } | |
108 | |
109 protected: | |
110 | |
111 std::string name; | |
112 std::string weight; | |
113 std::string angle; | |
114 double size; | |
115 }; | |
116 | |
117 // Container for substrings after parsing. | |
118 | |
119 class string | |
120 { | |
121 public: | |
122 | |
123 string (const std::string& s, font& f, const double x0, const double y0) | |
124 : str (s), fnt (f), x (x0), y (y0), z (0.0), code (0), | |
125 color (Matrix (1,3,0.0)) | |
126 { } | |
127 | |
128 string (const string& s) | |
129 : str (s.str), fnt (s.fnt), x (s.x), y (s.y), code (s.code), | |
130 color (s.color) | |
131 { } | |
132 | |
133 ~string (void) { } | |
134 | |
135 string& operator = (const string& s) | |
136 { | |
137 if (&s != this) | |
138 { | |
139 str = s.str; | |
140 fnt = s.fnt; | |
141 x = s.x; | |
142 y = s.y; | |
143 code = s.code; | |
144 color = s.color; | |
145 } | |
146 | |
147 return *this; | |
148 } | |
149 | |
150 void set_string (const std::string& s) { str = s; } | |
151 | |
152 std::string get_string (void) const { return str; } | |
153 | |
154 std::string get_name (void) const { return fnt.get_name (); } | |
155 | |
156 std::string get_weight (void) const { return fnt.get_weight (); } | |
157 | |
158 std::string get_angle (void) const { return fnt.get_angle (); } | |
159 | |
160 double get_size (void) const { return fnt.get_size (); } | |
161 | |
162 void set_x (const double x0) { x = x0; } | |
163 | |
164 double get_x (void) const { return x; } | |
165 | |
166 void set_y (const double y0) { y = y0; } | |
167 | |
168 double get_y (void) const { return y; } | |
169 | |
170 void set_z (const double z0) { z = z0; } | |
171 | |
172 double get_z (void) const { return z; } | |
173 | |
174 void set_code (const uint32_t c) { code = c; } | |
175 | |
176 uint32_t get_code (void) const { return code; } | |
177 | |
178 void set_color (const uint8NDArray& c) | |
179 { | |
180 color(0) = static_cast<double> (c(0)) / 255; | |
181 color(1) = static_cast<double> (c(1)) / 255; | |
182 color(2) = static_cast<double> (c(2)) / 255; | |
183 } | |
184 | |
185 Matrix get_color (void) const { return color; } | |
186 | |
187 private: | |
188 | |
189 std::string str; | |
190 font fnt; | |
191 double x, y, z; | |
192 uint32_t code; | |
193 Matrix color; | |
194 }; | |
195 | |
196 void text_to_strlist (const std::string& txt, | |
197 std::list<string>& lst, Matrix& box, | |
198 int halign, int valign, double rotation = 0.0, | |
199 const caseless_str& interpreter = "tex"); | |
200 | |
201 private: | |
202 | |
203 base_text_renderer *rep; | |
204 | |
205 // No copying! | |
206 | |
207 text_renderer (const text_renderer&); | |
208 | |
209 text_renderer& operator = (const text_renderer&); | |
210 }; | |
211 | |
212 #endif |