GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
text-renderer.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2009-2025 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 "error.h"
32#include "errwarn.h"
33#include "ft-text-renderer.h"
34#include "latex-text-renderer.h"
35#include "text-renderer.h"
36
38
40 : m_rep (make_ft_text_renderer ()),
41 m_latex_rep (make_latex_text_renderer ())
42{ }
43
45{
46 delete m_rep;
47 delete m_latex_rep;
48}
49
50bool
52{
53 static bool warned = false;
54
55 if (! m_rep)
56 {
57 if (! warned)
58 {
59 warn_disabled_feature ("opengl_renderer::render_text",
60 "rendering text (FreeType)");
61
62 warned = true;
63 }
64 }
65
66 return m_rep != nullptr;
67}
68
71{
72 static Matrix empty_extent (1, 4, 0.0);
73
74 return ok () ? m_rep->get_extent (elt, rotation) : empty_extent;
75}
76
78text_renderer::get_extent (const std::string& txt, double rotation,
80{
81 static Matrix retval (1, 4, 0.0);
82
83 if (interpreter == "latex" && m_latex_rep->ok ())
84 retval = m_latex_rep->get_extent (txt, rotation, interpreter);
85 else if (ok ())
86 retval = m_rep->get_extent (txt, rotation, interpreter);
87
88 return retval;
89}
90
91void
93{
94 if (ok ())
95 m_rep->set_anti_aliasing (val);
96}
97
100{
101 octave_map retval;
102
103 if (ok ())
104 retval = m_rep->get_system_fonts ();
105
106 return retval;
107}
108
109void
110text_renderer::set_font (const std::string& name, const std::string& weight,
111 const std::string& angle, double size)
112{
113 if (ok ())
114 {
115 m_rep->set_font (name, weight, angle, size);
116 m_latex_rep->set_font (name, weight, angle, size);
117 }
118}
119
120void
122{
123 if (ok ())
124 {
125 m_rep->set_color (c);
126 m_latex_rep->set_color (c);
127 }
128}
129
130void
131text_renderer::text_to_pixels (const std::string& txt,
132 uint8NDArray& pxls, Matrix& bbox,
133 int halign, int valign, double rotation,
135 bool handle_rotation)
136{
137 static Matrix empty_bbox (1, 4, 0.0);
138 static uint8NDArray empty_pxls;
139
140 if (interpreter == "latex" && m_latex_rep->ok ())
141 m_latex_rep->text_to_pixels (txt, pxls, bbox, halign, valign, rotation,
142 interpreter, handle_rotation);
143 else if (ok ())
144 m_rep->text_to_pixels (txt, pxls, bbox, halign, valign, rotation,
145 interpreter, handle_rotation);
146 else
147 {
148 bbox = empty_bbox;
149 pxls = empty_pxls;
150 }
151}
152
153void
154text_renderer::text_to_strlist (const std::string& txt,
155 std::list<text_renderer::string>& lst,
156 Matrix& bbox, int halign, int valign,
157 double rotation,
159{
160 static Matrix empty_bbox (1, 4, 0.0);
161 static std::list<text_renderer::string> empty_lst;
162
163 if (interpreter == "latex" && m_latex_rep->ok ())
164 m_latex_rep->text_to_strlist (txt, lst, bbox, halign, valign, rotation,
166 else if (ok ())
167 m_rep->text_to_strlist (txt, lst, bbox, halign, valign, rotation,
169 else
170 {
171 bbox = empty_bbox;
172 lst = empty_lst;
173 }
174}
175
176OCTAVE_END_NAMESPACE(octave)
virtual Matrix get_extent(text_element *elt, double rotation)=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
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 void set_color(const Matrix &c)=0
virtual void set_anti_aliasing(bool val)=0
virtual octave_map get_system_fonts()=0
virtual void set_font(const std::string &name, const std::string &weight, const std::string &angle, double size)=0
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 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() const
void set_anti_aliasing(bool val)
octave_map get_system_fonts()
Matrix get_extent(text_element *elt, double rotation=0.0)
void set_color(const Matrix &c)
void set_font(const std::string &name, const std::string &weight, const std::string &angle, double size)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void warn_disabled_feature(const std::string &fcn, const std::string &feature, const std::string &pkg)
Definition errwarn.cc:318
base_text_renderer * make_ft_text_renderer()
base_text_renderer * make_latex_text_renderer()