GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
text-renderer.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2009-2021 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 (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include "base-text-renderer.h"
31 #include "errwarn.h"
32 #include "ft-text-renderer.h"
33 #include "text-renderer.h"
34 
35 namespace octave
36 {
37  static base_text_renderer *
39  {
40  // Allow the possibility of choosing different text rendering
41  // implementations.
42 
43  return make_ft_text_renderer ();
44  }
45 
47  : rep (make_text_renderer ())
48  { }
49 
51  {
52  delete rep;
53  }
54 
55  bool
56  text_renderer::ok (void) const
57  {
58  static bool warned = false;
59 
60  if (! rep)
61  {
62  if (! warned)
63  {
64  warn_disabled_feature ("opengl_renderer::render_text",
65  "rendering text (FreeType)");
66 
67  warned = true;
68  }
69  }
70 
71  return rep != nullptr;
72  }
73 
74  Matrix
75  text_renderer::get_extent (text_element *elt, double rotation)
76  {
77  static Matrix empty_extent (1, 4, 0.0);
78 
79  return ok () ? rep->get_extent (elt, rotation) : empty_extent;
80  }
81 
82  Matrix
83  text_renderer::get_extent (const std::string& txt, double rotation,
85  {
86  static Matrix empty_extent (1, 4, 0.0);
87 
88  return ok () ? rep->get_extent (txt, rotation, interpreter) : empty_extent;
89  }
90 
91  void
93  {
94  if (ok ())
95  rep->set_anti_aliasing (val);
96  }
97 
100  {
102 
103  if (ok ())
105 
106  return retval;
107  }
108 
109  void
110  text_renderer::set_font (const std::string& name, const std::string& weight,
111  const std::string& angle, double size)
112  {
113  if (ok ())
114  rep->set_font (name, weight, angle, size);
115  }
116 
117  void
119  {
120  if (ok ())
121  rep->set_color (c);
122  }
123 
124  void
125  text_renderer::text_to_pixels (const std::string& txt,
126  uint8NDArray& pxls, Matrix& bbox,
127  int halign, int valign, double rotation,
128  const caseless_str& interpreter,
129  bool handle_rotation)
130  {
131  static Matrix empty_bbox (1, 4, 0.0);
132  static uint8NDArray empty_pxls;
133 
134  if (ok ())
135  rep->text_to_pixels (txt, pxls, bbox, halign, valign, rotation,
136  interpreter, handle_rotation);
137  else
138  {
139  bbox = empty_bbox;
140  pxls = empty_pxls;
141  }
142  }
143 
144  void
145  text_renderer::text_to_strlist (const std::string& txt,
146  std::list<text_renderer::string>& lst,
147  Matrix& bbox, int halign, int valign,
148  double rotation,
149  const caseless_str& interpreter)
150  {
151  static Matrix empty_bbox (1, 4, 0.0);
152  static std::list<text_renderer::string> empty_lst;
153 
154  if (ok ())
155  rep->text_to_strlist (txt, lst, bbox, halign, valign, rotation,
156  interpreter);
157  else
158  {
159  bbox = empty_bbox;
160  lst = empty_lst;
161  }
162  }
163 }
Definition: dMatrix.h:42
virtual void text_to_strlist(const std::string &txt, std::list< text_renderer::string > &lst, Matrix &box, int halign, int valign, double rotation, const caseless_str &interpreter="tex")=0
virtual octave_map get_system_fonts(void)=0
virtual Matrix get_extent(text_element *elt, double rotation)=0
virtual void set_anti_aliasing(bool val)=0
virtual void set_color(const Matrix &c)=0
virtual void set_font(const std::string &name, const std::string &weight, const std::string &angle, double size)=0
virtual void text_to_pixels(const std::string &txt, uint8NDArray &pxls, Matrix &bbox, int halign, int valign, double rotation, const caseless_str &interpreter, bool handle_rotation)=0
void set_anti_aliasing(bool val)
bool ok(void) const
octave_map get_system_fonts(void)
void text_to_strlist(const std::string &txt, std::list< string > &lst, Matrix &box, int halign, int valign, double rotation=0.0, const caseless_str &interpreter="tex")
Matrix get_extent(text_element *elt, double rotation=0.0)
base_text_renderer * rep
void text_to_pixels(const std::string &txt, uint8NDArray &pxls, Matrix &bbox, int halign, int valign, double rotation=0.0, const caseless_str &interpreter="tex", bool handle_rotation=true)
void set_color(const Matrix &c)
void set_font(const std::string &name, const std::string &weight, const std::string &angle, double size)
void warn_disabled_feature(const std::string &fcn, const std::string &feature, const std::string &pkg)
Definition: errwarn.cc:318
QString name
base_text_renderer * make_ft_text_renderer(void)
static base_text_renderer * make_text_renderer(void)
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811