annotate libinterp/corefcn/text-renderer.cc @ 26376:00f796120a6d stable

maint: Update copyright dates in all source files.
author John W. Eaton <jwe@octave.org>
date Wed, 02 Jan 2019 16:32:43 -0500
parents 6652d3823428
children 0adb232f93b9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 /*
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
3 Copyright (C) 2016-2019 John W. Eaton
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
4 Copyright (C) 2009-2019 Michael Goffioul
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 This file is part of Octave.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23795
diff changeset
8 Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
9 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23795
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
11 (at your option) any later version.
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
13 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
14 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
16 GNU General Public License for more details.
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23795
diff changeset
20 <https://www.gnu.org/licenses/>.
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22 */
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
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
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 #endif
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 #include "base-text-renderer.h"
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 #include "errwarn.h"
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 #include "ft-text-renderer.h"
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 #include "text-renderer.h"
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
33 static octave::base_text_renderer *
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 make_text_renderer (void)
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 {
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 // Allow the possibility of choosing different text rendering
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 // implementations.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
39 return octave::make_ft_text_renderer ();
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 }
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
42 namespace octave
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
43 {
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
44 text_renderer::text_renderer (void)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
45 : rep (make_text_renderer ())
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
46 { }
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
48 text_renderer::~text_renderer (void)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
49 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
50 delete rep;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
51 }
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
53 bool
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
54 text_renderer::ok (void) const
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
55 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
56 static bool warned = false;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
58 if (! rep)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
59 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
60 if (! warned)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
61 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
62 warn_disabled_feature ("opengl_renderer::render_text",
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
63 "rendering text (FreeType)");
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
65 warned = true;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
66 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
67 }
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23220
diff changeset
69 return rep != nullptr;
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
70 }
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
72 Matrix
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
73 text_renderer::get_extent (text_element *elt, double rotation)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
74 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
75 static Matrix empty_extent (1, 4, 0.0);
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
77 return ok () ? rep->get_extent (elt, rotation) : empty_extent;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
78 }
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
80 Matrix
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
81 text_renderer::get_extent (const std::string& txt, double rotation,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
82 const caseless_str& interpreter)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
83 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
84 static Matrix empty_extent (1, 4, 0.0);
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
86 return ok () ? rep->get_extent (txt, rotation, interpreter) : empty_extent;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
87 }
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
89 void
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
90 text_renderer::set_font (const std::string& name, const std::string& weight,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
91 const std::string& angle, double size)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
92 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
93 if (ok ())
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
94 rep->set_font (name, weight, angle, size);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
95 }
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
97 void
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
98 text_renderer::set_color (const Matrix& c)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
99 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
100 if (ok ())
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
101 rep->set_color (c);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
102 }
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
104 void
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
105 text_renderer::text_to_pixels (const std::string& txt,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
106 uint8NDArray& pxls, Matrix& bbox,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
107 int halign, int valign, double rotation,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
108 const caseless_str& interpreter,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
109 bool handle_rotation)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
110 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
111 static Matrix empty_bbox (1, 4, 0.0);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
112 static uint8NDArray empty_pxls;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
113
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
114 if (ok ())
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
115 rep->text_to_pixels (txt, pxls, bbox, halign, valign, rotation,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
116 interpreter, handle_rotation);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
117 else
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
118 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
119 bbox = empty_bbox;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
120 pxls = empty_pxls;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
121 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
122 }
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
123
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
124 void
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
125 text_renderer::text_to_strlist (const std::string& txt,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
126 std::list<text_renderer::string>& lst,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
127 Matrix& bbox, int halign, int valign,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
128 double rotation,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
129 const caseless_str& interpreter)
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
130 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
131 static Matrix empty_bbox (1, 4, 0.0);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
132 static std::list<text_renderer::string> empty_lst;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
134 if (ok ())
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
135 rep->text_to_strlist (txt, lst, bbox, halign, valign, rotation,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
136 interpreter);
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
137 else
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
138 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
139 bbox = empty_bbox;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
140 lst = empty_lst;
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
141 }
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
142 }
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
143 }