GNU Octave  4.4.1
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) 2016-2018 John W. Eaton
4 Copyright (C) 2009-2018 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
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License 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 <https://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if defined (HAVE_CONFIG_H)
25 # include "config.h"
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 
35 {
36  // Allow the possibility of choosing different text rendering
37  // implementations.
38 
40 }
41 
42 namespace octave
43 {
45  : rep (make_text_renderer ())
46  { }
47 
49  {
50  delete rep;
51  }
52 
53  bool
54  text_renderer::ok (void) const
55  {
56  static bool warned = false;
57 
58  if (! rep)
59  {
60  if (! warned)
61  {
62  warn_disabled_feature ("opengl_renderer::render_text",
63  "rendering text (FreeType)");
64 
65  warned = true;
66  }
67  }
68 
69  return rep != nullptr;
70  }
71 
72  Matrix
73  text_renderer::get_extent (text_element *elt, double rotation)
74  {
75  static Matrix empty_extent (1, 4, 0.0);
76 
77  return ok () ? rep->get_extent (elt, rotation) : empty_extent;
78  }
79 
80  Matrix
81  text_renderer::get_extent (const std::string& txt, double rotation,
83  {
84  static Matrix empty_extent (1, 4, 0.0);
85 
86  return ok () ? rep->get_extent (txt, rotation, interpreter) : empty_extent;
87  }
88 
89  void
91  const std::string& angle, double size)
92  {
93  if (ok ())
94  rep->set_font (name, weight, angle, size);
95  }
96 
97  void
99  {
100  if (ok ())
101  rep->set_color (c);
102  }
103 
104  void
106  uint8NDArray& pxls, Matrix& bbox,
107  int halign, int valign, double rotation,
108  const caseless_str& interpreter,
109  bool handle_rotation)
110  {
111  static Matrix empty_bbox (1, 4, 0.0);
112  static uint8NDArray empty_pxls;
113 
114  if (ok ())
115  rep->text_to_pixels (txt, pxls, bbox, halign, valign, rotation,
116  interpreter, handle_rotation);
117  else
118  {
119  bbox = empty_bbox;
120  pxls = empty_pxls;
121  }
122  }
123 
124  void
126  std::list<text_renderer::string>& lst,
127  Matrix& bbox, int halign, int valign,
128  double rotation,
129  const caseless_str& interpreter)
130  {
131  static Matrix empty_bbox (1, 4, 0.0);
132  static std::list<text_renderer::string> empty_lst;
133 
134  if (ok ())
135  rep->text_to_strlist (txt, lst, bbox, halign, valign, rotation,
136  interpreter);
137  else
138  {
139  bbox = empty_bbox;
140  lst = empty_lst;
141  }
142  }
143 }
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
static octave::base_text_renderer * make_text_renderer(void)
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)
virtual Matrix get_extent(text_element *elt, double rotation)=0
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
base_text_renderer * make_ft_text_renderer(void)
nd deftypefn *std::string name
Definition: sysdep.cc:647
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")
void set_font(const std::string &name, const std::string &weight, const std::string &angle, double size)
base_text_renderer * rep
void warn_disabled_feature(const std::string &fcn, const std::string &feature, const std::string &pkg)
Definition: errwarn.cc:314
void set_color(const Matrix &c)
Definition: dMatrix.h:36
virtual void set_color(const Matrix &c)=0
Matrix get_extent(text_element *elt, double rotation=0.0)
bool ok(void) const
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
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888