Mercurial > octave
annotate libinterp/corefcn/text-renderer.cc @ 22003:2d3972b802ff
use consistent style for including config.h in source files
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 30 Jun 2016 11:41:49 -0400 |
parents | aba2e6293dd8 |
children | bac0d6f07a3e |
rev | line source |
---|---|
21209 | 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 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
24 #if defined (HAVE_CONFIG_H) |
22003
2d3972b802ff
use consistent style for including config.h in source files
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
25 # include "config.h" |
21209 | 26 #endif |
27 | |
28 #include "base-text-renderer.h" | |
29 #include "errwarn.h" | |
30 #include "ft-text-renderer.h" | |
31 #include "text-renderer.h" | |
32 | |
33 static base_text_renderer * | |
34 make_text_renderer (void) | |
35 { | |
36 // Allow the possibility of choosing different text rendering | |
37 // implementations. | |
38 | |
39 return make_ft_text_renderer (); | |
40 } | |
41 | |
42 text_renderer::text_renderer (void) | |
43 : rep (make_text_renderer ()) | |
44 { } | |
45 | |
46 text_renderer::~text_renderer (void) | |
47 { | |
48 delete rep; | |
49 } | |
50 | |
51 bool | |
52 text_renderer::ok (void) const | |
53 { | |
54 static bool warned = false; | |
55 | |
56 if (! rep) | |
57 { | |
58 if (! warned) | |
59 { | |
60 warn_disabled_feature ("opengl_renderer::render_text", | |
61 "rendering text (FreeType)"); | |
62 | |
63 warned = true; | |
64 } | |
65 } | |
66 | |
67 return rep != 0; | |
68 } | |
69 | |
70 Matrix | |
71 text_renderer::get_extent (text_element *elt, double rotation) | |
72 { | |
73 static Matrix empty_extent (1, 4, 0.0); | |
74 | |
75 return ok () ? rep->get_extent (elt, rotation) : empty_extent; | |
76 } | |
77 | |
78 Matrix | |
79 text_renderer::get_extent (const std::string& txt, double rotation, | |
80 const caseless_str& interpreter) | |
81 { | |
82 static Matrix empty_extent (1, 4, 0.0); | |
83 | |
84 return ok () ? rep->get_extent (txt, rotation, interpreter) : empty_extent; | |
85 } | |
86 | |
87 void | |
88 text_renderer::set_font (const std::string& name, const std::string& weight, | |
89 const std::string& angle, double size) | |
90 { | |
91 if (ok ()) | |
92 rep->set_font (name, weight, angle, size); | |
93 } | |
94 | |
95 void | |
96 text_renderer::set_color (const Matrix& c) | |
97 { | |
98 if (ok ()) | |
99 rep->set_color (c); | |
100 } | |
101 | |
102 void | |
103 text_renderer::text_to_pixels (const std::string& txt, | |
104 uint8NDArray& pxls, Matrix& bbox, | |
105 int halign, int valign, double rotation, | |
106 const caseless_str& interpreter, | |
107 bool handle_rotation) | |
108 { | |
109 static Matrix empty_bbox (1, 4, 0.0); | |
110 static uint8NDArray empty_pxls; | |
111 | |
112 if (ok ()) | |
113 rep->text_to_pixels (txt, pxls, bbox, halign, valign, rotation, | |
114 interpreter, handle_rotation); | |
115 else | |
116 { | |
117 bbox = empty_bbox; | |
118 pxls = empty_pxls; | |
119 } | |
120 } | |
121 | |
122 void | |
123 text_renderer::text_to_strlist (const std::string& txt, | |
124 std::list<text_renderer::string>& lst, | |
125 Matrix& bbox, int halign, int valign, | |
126 double rotation, | |
127 const caseless_str& interpreter) | |
128 { | |
129 static Matrix empty_bbox (1, 4, 0.0); | |
130 static std::list<text_renderer::string> empty_lst; | |
131 | |
132 if (ok ()) | |
133 rep->text_to_strlist (txt, lst, bbox, halign, valign, rotation, | |
134 interpreter); | |
135 else | |
136 { | |
137 bbox = empty_bbox; | |
138 lst = empty_lst; | |
139 } | |
140 } |