annotate libinterp/corefcn/base-text-renderer.h @ 29470:2ae4764180c6

Initial implementation of a LaTeX interpreter (bug #59546). * NEWS: Announce basic support for "latex" interpreter. * plot.txi: Restructure the "Use of the interpreter Property" section to include 3 subsections, one for each interpreter type. In "Printing and Saving Plots" describe the new behavior. * print.m: Document new behavior. * contributors.in: Add Andrej Lojdl, a former GSoC student that worked on this subject. Even though there is not much left of his original work, it served as a very useful starting point. * base-text-renderer.h, base-text-renderer.cc: New enum to store symbolic constants for rotation angles. (base_text_renderer::rotate_pixels): New utility method. Code extracted from ft_text_renderer::render. (base_text_renderer::rotation_to_mode): Moved from ft_text_renderer class. (base_text_renderer::fix_bbox_anchor): New utility method. Code extracted from ft_text_renderer::text_to_pixels. * ft_text_renderer.cc (ft_text_renderer::render, ft_text_renderer::text_to_pixels): Make use of base class utility functions. * gl2ps-print.cc: New counter variable m_svg_def_index for safe inclusion of defs coming from dvisvgm. (gl2ps_renderer::format_svg_element): New function to manipulate svg elements obtained from dvisvgm so as to position them properly on the figure and change their color. (gl2ps_renderer::strlist_to_svg): If the str_list object returned from text_to_strlist contains an svg element, use format_svg_element to handle position and color and then return it. Otherwise, use <g> and <text> elements rather than <text> and <tspan> elements which are not supported by Qt's svg renderer (svg-tiny implementation). (gl2ps_renderer::strlist_to_ps): If the str_list object returned from text_to_strlist contains an svg element, raise a warning about the necessity of using -svgconvert. * latex-text-renderer.h, latex-text-renderer.cc: New files to hold the latex_interpreter class. * libinterp/corefcn/module.mk: Add new files to the build system. * text-renderer.h, text-renderer.cc (text_renderer): New data member latex_rep to hold a pointer to an instance of a latex_renderer. (text_renderer::~text_renderer, get_extent, set_anti_aliasing, set_font, set_color, text_to_pixels, text_to_strlist): Duplicate action of the latex_rep. (text_renderer::latex_ok): New method to test the usability of the latex_renderer. (text_renderer::string::svg_element, text_renderer::string::set_svg_element, text_renderer::string::get_svg_element): New string data member to hold preformated svg element. Provide accessor methods. * acinclude.m4: Add QtSvg to the list of imported QT_MODULES. * octave-svgconvert.cc: Overhaul program to make use of Qt's QSvgRenderer when rendering to PDF.
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Mon, 22 Mar 2021 21:32:54 +0100
parents 0a5b15007766
children af41ebf3d1b3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
29358
0a5b15007766 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
3 // Copyright (C) 2009-2021 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 #if ! defined (octave_base_text_renderer_h)
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 #define octave_base_text_renderer_h 1
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28
21244
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21209
diff changeset
29 #include "octave-config.h"
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21209
diff changeset
30
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 #include <list>
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 #include <string>
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 #include "dMatrix.h"
27623
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26858
diff changeset
35 #include "oct-map.h"
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 #include "uint8NDArray.h"
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37
25643
afb5288a25ad move text engine classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
38 #include "text-engine.h"
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 #include "text-renderer.h"
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
41 namespace octave
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
42 {
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
43 class
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
44 base_text_renderer : public text_processor
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
45 {
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
46 public:
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
47
29470
2ae4764180c6 Initial implementation of a LaTeX interpreter (bug #59546).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29358
diff changeset
48 enum
2ae4764180c6 Initial implementation of a LaTeX interpreter (bug #59546).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29358
diff changeset
49 {
2ae4764180c6 Initial implementation of a LaTeX interpreter (bug #59546).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29358
diff changeset
50 ROTATION_0 = 0,
2ae4764180c6 Initial implementation of a LaTeX interpreter (bug #59546).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29358
diff changeset
51 ROTATION_90 = 1,
2ae4764180c6 Initial implementation of a LaTeX interpreter (bug #59546).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29358
diff changeset
52 ROTATION_180 = 2,
2ae4764180c6 Initial implementation of a LaTeX interpreter (bug #59546).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29358
diff changeset
53 ROTATION_270 = 3
2ae4764180c6 Initial implementation of a LaTeX interpreter (bug #59546).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29358
diff changeset
54 };
2ae4764180c6 Initial implementation of a LaTeX interpreter (bug #59546).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29358
diff changeset
55
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
56 base_text_renderer (void) : text_processor () { }
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57
22869
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
58 // No copying!
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
59
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
60 base_text_renderer (const base_text_renderer&) = delete;
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
61
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
62 base_text_renderer& operator = (const base_text_renderer&) = delete;
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22868
diff changeset
63
22868
87e3163f6c87 use c++11 "= default" syntax for declaration of trivial destructors
John W. Eaton <jwe@octave.org>
parents: 22865
diff changeset
64 virtual ~base_text_renderer (void) = default;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65
26858
0adb232f93b9 Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26376
diff changeset
66 virtual void
0adb232f93b9 Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26376
diff changeset
67 set_anti_aliasing (bool val) = 0;
0adb232f93b9 Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26376
diff changeset
68
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
69 virtual Matrix
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
70 get_extent (text_element *elt, double rotation) = 0;
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 virtual Matrix
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
73 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
74 const caseless_str& interpreter) = 0;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
76 virtual void
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
77 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
78 const std::string& angle, double size) = 0;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79
27623
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26858
diff changeset
80 virtual octave_map
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26858
diff changeset
81 get_system_fonts (void) = 0;
698c8b08fe8c New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26858
diff changeset
82
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
83 virtual void set_color (const Matrix& c) = 0;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
85 virtual void
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
86 text_to_pixels (const std::string& txt, uint8NDArray& pxls,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
87 Matrix& bbox, int halign, int valign, double rotation,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
88 const caseless_str& interpreter,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
89 bool handle_rotation) = 0;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
91 virtual void
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
92 text_to_strlist (const std::string& txt,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
93 std::list<text_renderer::string>& lst,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
94 Matrix& box, int halign, int valign, double rotation,
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
95 const caseless_str& interpreter = "tex") = 0;
29470
2ae4764180c6 Initial implementation of a LaTeX interpreter (bug #59546).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29358
diff changeset
96
2ae4764180c6 Initial implementation of a LaTeX interpreter (bug #59546).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29358
diff changeset
97 void rotate_pixels (uint8NDArray& pixels, int rot_mode) const;
2ae4764180c6 Initial implementation of a LaTeX interpreter (bug #59546).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29358
diff changeset
98
2ae4764180c6 Initial implementation of a LaTeX interpreter (bug #59546).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29358
diff changeset
99 int rotation_to_mode (double rotation) const;
2ae4764180c6 Initial implementation of a LaTeX interpreter (bug #59546).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29358
diff changeset
100
2ae4764180c6 Initial implementation of a LaTeX interpreter (bug #59546).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29358
diff changeset
101 void fix_bbox_anchor (Matrix& bbox, int halign,
2ae4764180c6 Initial implementation of a LaTeX interpreter (bug #59546).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29358
diff changeset
102 int valign, int rot_mode,
2ae4764180c6 Initial implementation of a LaTeX interpreter (bug #59546).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29358
diff changeset
103 bool handle_rotation) const;
2ae4764180c6 Initial implementation of a LaTeX interpreter (bug #59546).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 29358
diff changeset
104
22331
b81b08cc4c83 maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents: 22326
diff changeset
105 };
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
106 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
107
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108 #endif