GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
text-renderer.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2016-2017 John W. Eaton
4 Copyright (C) 2009-2016 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 
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 != 0;
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
Octave interface to the compression and uncompression libraries.
Definition: aepbalance.cc:47
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)
bool ok(void) const
virtual Matrix get_extent(text_element *elt, double rotation)=0
base_text_renderer * make_ft_text_renderer(void)
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable name
Definition: input.cc:871
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:308
void set_color(const Matrix &c)
Definition: dMatrix.h:37
virtual void set_color(const Matrix &c)=0
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
Matrix get_extent(text_element *elt, double rotation=0.0)
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
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable or any other valid Octave code The number of return their size
Definition: input.cc:871
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:854