annotate libinterp/corefcn/ft-text-renderer.cc @ 22326:71dd9d5a5ecd

move more new classes inside octave namespace * base-text-renderer.h, ft-text-renderer.cc, ft-text-renderer.h, gl-render.cc, gl-render.h, gl2ps-print.cc, gl2ps-print.h, oct-stream.cc, text-renderer.cc, text-renderer.h, ov-java.cc, xzip.cc: Move classes inside octave namespace. * GLCanvas.cc, gl-select.cc, gl-select.h, graphics.cc, graphics.in.h, __init_fltk__.cc, __osmesa_print__.cc: Update.
author John W. Eaton <jwe@octave.org>
date Wed, 17 Aug 2016 02:57:50 -0400
parents bac0d6f07a3e
children b81b08cc4c83
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1 /*
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
3 Copyright (C) 2016 John W. Eaton
22323
bac0d6f07a3e maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents: 22173
diff changeset
4 Copyright (C) 2009-2016 Michael Goffioul
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
5
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
6 This file is part of Octave.
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
7
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
11 option) any later version.
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
12
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
16 for more details.
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
17
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
19 along with Octave; see the file COPYING. If not, see
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
20 <http://www.gnu.org/licenses/>.
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
21
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
22 */
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
23
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21568
diff changeset
24 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21209
diff changeset
25 # include "config.h"
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
26 #endif
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
27
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
28 #include "base-text-renderer.h"
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
29
14003
1555c5a177c9 better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents: 13999
diff changeset
30 #if defined (HAVE_FREETYPE)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
31
21334
36e75e013849 * ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
32 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
36e75e013849 * ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
33 #pragma GCC diagnostic push
36e75e013849 * ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
34 #pragma GCC diagnostic ignored "-Wold-style-cast"
36e75e013849 * ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
35 #endif
36e75e013849 * ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
36
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
37 #include <ft2build.h>
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
38 #include FT_FREETYPE_H
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
39
14003
1555c5a177c9 better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents: 13999
diff changeset
40 #if defined (HAVE_FONTCONFIG)
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21102
diff changeset
41 # include <fontconfig/fontconfig.h>
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
42 #endif
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
43
21334
36e75e013849 * ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
44 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
36e75e013849 * ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
45 #pragma GCC diagnostic pop
36e75e013849 * ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
46 #endif
36e75e013849 * ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
47
17352
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
48 #include <clocale>
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
49 #include <cwchar>
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
50 #include <iostream>
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
51 #include <map>
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
52 #include <utility>
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
53
13992
e1f76bfe0452 apply singleton_cleanup to a few more classes
John W. Eaton <jwe@octave.org>
parents: 13730
diff changeset
54 #include "singleton-cleanup.h"
e1f76bfe0452 apply singleton_cleanup to a few more classes
John W. Eaton <jwe@octave.org>
parents: 13730
diff changeset
55
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
56 #include "error.h"
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
57 #include "pr-output.h"
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
58 #include "text-renderer.h"
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
59
17377
15e2ad6372f7 maint: Tweaks to remove compiler warnings.
Rik <rik@octave.org>
parents: 17352
diff changeset
60 // FIXME: maybe issue at most one warning per glyph/font/size/weight
15e2ad6372f7 maint: Tweaks to remove compiler warnings.
Rik <rik@octave.org>
parents: 17352
diff changeset
61 // combination.
13317
d2b799e3178a allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents: 13141
diff changeset
62
d2b799e3178a allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents: 13141
diff changeset
63 static void
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 20974
diff changeset
64 warn_missing_glyph (FT_ULong c)
13317
d2b799e3178a allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents: 13141
diff changeset
65 {
d2b799e3178a allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents: 13141
diff changeset
66 warning_with_id ("Octave:missing-glyph",
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
67 "text_renderer: skipping missing glyph for character '%x'", c);
13317
d2b799e3178a allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents: 13141
diff changeset
68 }
d2b799e3178a allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents: 13141
diff changeset
69
d2b799e3178a allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents: 13141
diff changeset
70 static void
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 20974
diff changeset
71 warn_glyph_render (FT_ULong c)
13317
d2b799e3178a allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents: 13141
diff changeset
72 {
d2b799e3178a allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents: 13141
diff changeset
73 warning_with_id ("Octave:glyph-render",
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
74 "text_renderer: unable to render glyph for character '%x'", c);
13317
d2b799e3178a allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents: 13141
diff changeset
75 }
d2b799e3178a allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents: 13141
diff changeset
76
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
77 #if defined (_MSC_VER)
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
78 // FIXME: is this really needed?
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
79 //
17377
15e2ad6372f7 maint: Tweaks to remove compiler warnings.
Rik <rik@octave.org>
parents: 17352
diff changeset
80 // This is just a trick to avoid multiple symbol definitions.
13730
a2c74b5c02de [MSVC] Prevent duplicate symbol.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13317
diff changeset
81 // PermMatrix.h contains a dllexport'ed Array<octave_idx_type>
17377
15e2ad6372f7 maint: Tweaks to remove compiler warnings.
Rik <rik@octave.org>
parents: 17352
diff changeset
82 // that will cause MSVC not to generate a new instantiation and
15e2ad6372f7 maint: Tweaks to remove compiler warnings.
Rik <rik@octave.org>
parents: 17352
diff changeset
83 // use the imported one instead.
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
84 # include "PermMatrix.h"
13730
a2c74b5c02de [MSVC] Prevent duplicate symbol.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13317
diff changeset
85 #endif
a2c74b5c02de [MSVC] Prevent duplicate symbol.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13317
diff changeset
86
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
87 // Forward declaration
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
88 static void ft_face_destroyed (void *object);
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
89
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
90 namespace octave
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
91 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
92
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
93 class
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
94 ft_manager
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
95 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
96 public:
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
97 static bool instance_ok (void)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
98 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
99 bool retval = true;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
100
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
101 if (! instance)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
102 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
103 instance = new ft_manager ();
13992
e1f76bfe0452 apply singleton_cleanup to a few more classes
John W. Eaton <jwe@octave.org>
parents: 13730
diff changeset
104
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
105 if (instance)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
106 singleton_cleanup_list::add (cleanup_instance);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
107 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
108
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
109 if (! instance)
20956
850e3d2533d4 maint: Eliminate more useless statements after error().
Rik <rik@octave.org>
parents: 20945
diff changeset
110 error ("unable to create ft_manager!");
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
111
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
112 return retval;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
113 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
114
13992
e1f76bfe0452 apply singleton_cleanup to a few more classes
John W. Eaton <jwe@octave.org>
parents: 13730
diff changeset
115 static void cleanup_instance (void) { delete instance; instance = 0; }
e1f76bfe0452 apply singleton_cleanup to a few more classes
John W. Eaton <jwe@octave.org>
parents: 13730
diff changeset
116
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
117 static FT_Face get_font (const std::string& name, const std::string& weight,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
118 const std::string& angle, double size)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
119 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
120 return (instance_ok ()
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
121 ? instance->do_get_font (name, weight, angle, size)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
122 : 0);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
123 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
124
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
125 static void font_destroyed (FT_Face face)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
126 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
127 if (instance_ok ())
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
128 instance->do_font_destroyed (face);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
129 }
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
130
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
131 private:
12122
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
132
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
133 static ft_manager *instance;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
134
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
135 typedef std::pair<std::string, double> ft_key;
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
136 typedef std::map<ft_key, FT_Face> ft_cache;
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
137
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
138 // Cache the fonts loaded by FreeType. This cache only contains
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
139 // weak references to the fonts, strong references are only present
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
140 // in class text_renderer.
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
141 ft_cache cache;
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
142
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
143 private:
12122
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
144
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
145 // No copying!
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
146
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
147 ft_manager (const ft_manager&);
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
148
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
149 ft_manager& operator = (const ft_manager&);
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
150
14003
1555c5a177c9 better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents: 13999
diff changeset
151 ft_manager (void)
1555c5a177c9 better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents: 13999
diff changeset
152 : library (), freetype_initialized (false), fontconfig_initialized (false)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
153 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
154 if (FT_Init_FreeType (&library))
20428
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 19697
diff changeset
155 error ("unable to initialize FreeType library");
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
156 else
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
157 freetype_initialized = true;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
158
14003
1555c5a177c9 better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents: 13999
diff changeset
159 #if defined (HAVE_FONTCONFIG)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
160 if (! FcInit ())
20428
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 19697
diff changeset
161 error ("unable to initialize fontconfig library");
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
162 else
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
163 fontconfig_initialized = true;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
164 #endif
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
165 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
166
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
167 ~ft_manager (void)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
168 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
169 if (freetype_initialized)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
170 FT_Done_FreeType (library);
14003
1555c5a177c9 better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents: 13999
diff changeset
171
1555c5a177c9 better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents: 13999
diff changeset
172 #if defined (HAVE_FONTCONFIG)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
173 // FIXME: Skip the call to FcFini because it can trigger the assertion
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
174 //
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
175 // octave: fccache.c:507: FcCacheFini: Assertion 'fcCacheChains[i] == ((void *)0)' failed.
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
176 //
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
177 // if (fontconfig_initialized)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
178 // FcFini ();
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
179 #endif
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
180 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
181
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
182 FT_Face do_get_font (const std::string& name, const std::string& weight,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
183 const std::string& angle, double size)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
184 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
185 FT_Face retval = 0;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
186
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
187 #if defined (HAVE_FT_REFERENCE_FACE)
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
188 // Look first into the font cache, then use fontconfig. If the font
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
189 // is present in the cache, simply add a reference and return it.
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
190
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
191 ft_key key (name + ":" + weight + ":" + angle, size);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
192 ft_cache::const_iterator it = cache.find (key);
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
193
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
194 if (it != cache.end ())
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
195 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
196 FT_Reference_Face (it->second);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
197 return it->second;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
198 }
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
199 #endif
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
200
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
201 std::string file;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
202
14003
1555c5a177c9 better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents: 13999
diff changeset
203 #if defined (HAVE_FONTCONFIG)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
204 if (fontconfig_initialized)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
205 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
206 int fc_weight, fc_angle;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
207
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
208 if (weight == "bold")
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
209 fc_weight = FC_WEIGHT_BOLD;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
210 else if (weight == "light")
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
211 fc_weight = FC_WEIGHT_LIGHT;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
212 else if (weight == "demi")
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
213 fc_weight = FC_WEIGHT_DEMIBOLD;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
214 else
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
215 fc_weight = FC_WEIGHT_NORMAL;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
216
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
217 if (angle == "italic")
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
218 fc_angle = FC_SLANT_ITALIC;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
219 else if (angle == "oblique")
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
220 fc_angle = FC_SLANT_OBLIQUE;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
221 else
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
222 fc_angle = FC_SLANT_ROMAN;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
223
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
224 FcPattern *pat = FcPatternCreate ();
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
225
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
226 FcPatternAddString (pat, FC_FAMILY,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
227 (reinterpret_cast<const FcChar8*>
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
228 (name == "*" ? "sans" : name.c_str ())));
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
229
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
230 FcPatternAddInteger (pat, FC_WEIGHT, fc_weight);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
231 FcPatternAddInteger (pat, FC_SLANT, fc_angle);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
232 FcPatternAddDouble (pat, FC_PIXEL_SIZE, size);
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
233
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
234 if (FcConfigSubstitute (0, pat, FcMatchPattern))
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
235 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
236 FcResult res;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
237 FcPattern *match;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
238
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
239 FcDefaultSubstitute (pat);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
240 match = FcFontMatch (0, pat, &res);
9833
637fa784d102 Allow more font matches
godfrey@isl.Stanford.EDU
parents: 9619
diff changeset
241
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
242 // FIXME: originally, this test also required that
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
243 // res != FcResultNoMatch. Is that really needed?
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
244 if (match)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
245 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
246 unsigned char *tmp;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
247
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
248 FcPatternGetString (match, FC_FILE, 0, &tmp);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
249 file = reinterpret_cast<char*> (tmp);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
250 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
251 else
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
252 ::warning ("could not match any font: %s-%s-%s-%g",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
253 name.c_str (), weight.c_str (), angle.c_str (),
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
254 size);
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
255
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
256 if (match)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
257 FcPatternDestroy (match);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
258 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
259
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
260 FcPatternDestroy (pat);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
261 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
262 #endif
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
263
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
264 if (file.empty ())
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
265 {
21979
d04da18a407a use OCTAVE_USE_WINDOWS_API more consistently
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
266 #if defined (OCTAVE_USE_WINDOWS_API)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
267 file = "C:/WINDOWS/Fonts/verdana.ttf";
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
268 #else
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
269 // FIXME: find a "standard" font for UNIX platforms
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
270 #endif
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
271 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
272
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
273 if (! file.empty ())
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
274 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
275 if (FT_New_Face (library, file.c_str (), 0, &retval))
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
276 ::warning ("ft_manager: unable to load font: %s", file.c_str ());
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
277 #if defined (HAVE_FT_REFERENCE_FACE)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
278 else
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
279 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
280 // Install a finalizer to notify ft_manager that the font is
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
281 // being destroyed. The class ft_manager only keeps weak
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
282 // references to font objects.
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
283
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
284 retval->generic.data = new ft_key (key);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
285 retval->generic.finalizer = ft_face_destroyed;
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
286
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
287 // Insert loaded font into the cache.
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
288
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
289 cache[key] = retval;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
290 }
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
291 #endif
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
292 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
293
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
294 return retval;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
295 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
296
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
297 void do_font_destroyed (FT_Face face)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
298 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
299 if (face->generic.data)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
300 {
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
301 ft_key *pkey = reinterpret_cast<ft_key*> (face->generic.data);
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
302
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
303 cache.erase (*pkey);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
304 delete pkey;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
305 face->generic.data = 0;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
306 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
307 }
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
308
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
309 private:
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
310 FT_Library library;
14003
1555c5a177c9 better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents: 13999
diff changeset
311 bool freetype_initialized;
1555c5a177c9 better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents: 13999
diff changeset
312 bool fontconfig_initialized;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
313 };
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
314
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
315 ft_manager *ft_manager::instance = 0;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
316
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
317 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
318
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
319 static void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
320 ft_face_destroyed (void *object)
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
321 {
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
322 octave::ft_manager::font_destroyed (reinterpret_cast<FT_Face> (object));
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
323 }
17270
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17269
diff changeset
324
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
325 namespace octave
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
326 {
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
327
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
328 class
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
329 OCTINTERP_API
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
330 ft_text_renderer : public base_text_renderer
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
331 {
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
332 public:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
333
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
334 enum
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
335 {
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
336 MODE_BBOX = 0,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
337 MODE_RENDER = 1
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
338 };
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
339
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
340 enum
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
341 {
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
342 ROTATION_0 = 0,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
343 ROTATION_90 = 1,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
344 ROTATION_180 = 2,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
345 ROTATION_270 = 3
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
346 };
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
347
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
348 public:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
349
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
350 ft_text_renderer (void)
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
351 : base_text_renderer (), font (), bbox (1, 4, 0.0), halign (0),
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
352 xoffset (0), line_yoffset (0), yoffset (0), mode (MODE_BBOX),
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
353 color (dim_vector (1, 3), 0)
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
354 { }
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
355
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
356 ~ft_text_renderer (void) { }
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
357
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
358 void visit (text_element_string& e);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
359
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
360 void visit (text_element_list& e);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
361
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
362 void visit (text_element_subscript& e);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
363
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
364 void visit (text_element_superscript& e);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
365
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
366 void visit (text_element_color& e);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
367
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
368 void visit (text_element_fontsize& e);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
369
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
370 void visit (text_element_fontname& e);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
371
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
372 void visit (text_element_fontstyle& e);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
373
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
374 void visit (text_element_symbol& e);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
375
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
376 void visit (text_element_combined& e);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
377
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
378 void reset (void);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
379
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
380 uint8NDArray get_pixels (void) const { return pixels; }
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
381
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
382 Matrix get_boundingbox (void) const { return bbox; }
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
383
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
384 uint8NDArray render (text_element *elt, Matrix& box,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
385 int rotation = ROTATION_0);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
386
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
387 Matrix get_extent (text_element *elt, double rotation = 0.0);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
388 Matrix get_extent (const std::string& txt, double rotation,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
389 const caseless_str& interpreter);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
390
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
391 void set_font (const std::string& name, const std::string& weight,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
392 const std::string& angle, double size);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
393
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
394 void set_color (const Matrix& c);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
395
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
396 void set_mode (int m);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
397
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
398 void text_to_pixels (const std::string& txt,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
399 uint8NDArray& pxls, Matrix& bbox,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
400 int halign, int valign, double rotation,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
401 const caseless_str& interpreter,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
402 bool handle_rotation);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
403
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
404 private:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
405
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
406 int rotation_to_mode (double rotation) const;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
407
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
408 // No copying!
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
409
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
410 ft_text_renderer (const ft_text_renderer&);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
411
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
412 ft_text_renderer& operator = (const ft_text_renderer&);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
413
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
414 // Class to hold information about fonts and a strong
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
415 // reference to the font objects loaded by FreeType.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
416
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
417 class ft_font : public text_renderer::font
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
418 {
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
419 public:
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
420
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
421 ft_font (void)
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
422 : text_renderer::font (), face (0) { }
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
423
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
424 ft_font (const std::string& nm, const std::string& wt,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
425 const std::string& ang, double sz, FT_Face f = 0)
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
426 : text_renderer::font (nm, wt, ang, sz), face (f)
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
427 { }
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
428
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
429 ft_font (const ft_font& ft);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
430
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
431 ~ft_font (void)
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
432 {
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
433 if (face)
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
434 FT_Done_Face (face);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
435 }
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
436
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
437 ft_font& operator = (const ft_font& ft);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
438
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
439 bool is_valid (void) const { return get_face (); }
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
440
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
441 FT_Face get_face (void) const;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
442
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
443 private:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
444
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
445 mutable FT_Face face;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
446 };
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
447
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
448 void push_new_line (void);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
449
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
450 void update_line_bbox (void);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
451
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
452 void compute_bbox (void);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
453
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
454 int compute_line_xoffset (const Matrix& lb) const;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
455
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
456 FT_UInt process_character (FT_ULong code, FT_UInt previous = 0);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
457
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
458 public:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
459
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
460 void text_to_strlist (const std::string& txt,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
461 std::list<text_renderer::string>& lst, Matrix& bbox,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
462 int halign, int valign, double rotation,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
463 const caseless_str& interp);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
464
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
465 private:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
466
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
467 // The current font used by the renderer.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
468 ft_font font;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
469
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
470 // Used to stored the bounding box corresponding to the rendered text.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
471 // The bounding box has the form [x, y, w, h] where x and y represent the
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
472 // coordinates of the bottom left corner relative to the anchor point of
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
473 // the text (== start of text on the baseline). Due to font descent or
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
474 // multiple lines, the value y is usually negative.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
475 Matrix bbox;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
476
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
477 // Used to stored the rendered text. It's a 3D matrix with size MxNx4
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
478 // where M and N are the width and height of the bounding box.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
479 uint8NDArray pixels;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
480
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
481 // Used to store the bounding box of each line. This is used to layout
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
482 // multiline text properly.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
483 std::list<Matrix> line_bbox;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
484
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
485 // The current horizontal alignment. This is used to align multi-line text.
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
486 int halign;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
487
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
488 // The X offset for the next glyph.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
489 int xoffset;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
490
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
491 // The Y offset of the baseline for the current line.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
492 int line_yoffset;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
493
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
494 // The Y offset of the baseline for the next glyph. The offset is relative
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
495 // to line_yoffset. The total Y offset is computed with:
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
496 // line_yoffset + yoffset.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
497 int yoffset;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
498
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
499 // The current mode of the rendering process (box computing or rendering).
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
500 int mode;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
501
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
502 // The base color of the rendered text.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
503 uint8NDArray color;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
504
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
505 // A list of parsed strings to be used for printing.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
506 std::list<text_renderer::string> strlist;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
507
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
508 // The X offset of the baseline for the current line.
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
509 int line_xoffset;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
510
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
511 };
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
512
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
513 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
514 ft_text_renderer::set_font (const std::string& name, const std::string& weight,
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
515 const std::string& angle, double size)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
516 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
517 // FIXME: take "fontunits" into account
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
518
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
519 font = ft_font (name, weight, angle, size, 0);
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
520 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
521
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
522 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
523 ft_text_renderer::push_new_line (void)
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
524 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
525 switch (mode)
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
526 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
527 case MODE_BBOX:
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
528 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
529 // Create a new bbox entry based on the current font.
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
530
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
531 FT_Face face = font.get_face ();
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
532
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
533 if (face)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
534 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
535 int asc = face->size->metrics.ascender >> 6;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
536 int desc = face->size->metrics.descender >> 6;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
537 int h = face->size->metrics.height >> 6;
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
538
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
539 Matrix bb (1, 5, 0.0);
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
540
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
541 bb(1) = desc;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
542 bb(3) = asc - desc;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
543 bb(4) = h;
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
544
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
545 line_bbox.push_back (bb);
17274
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
546
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
547 xoffset = yoffset = 0;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
548 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
549 }
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
550 break;
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
551
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
552 case MODE_RENDER:
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
553 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
554 // Move to the next line bbox, adjust xoffset based on alignment
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
555 // and yoffset based on the old and new line bbox.
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
556
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
557 Matrix old_bbox = line_bbox.front ();
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
558 line_bbox.pop_front ();
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
559 Matrix new_bbox = line_bbox.front ();
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
560
20622
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
561 xoffset = line_xoffset = compute_line_xoffset (new_bbox);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
562 line_yoffset += (old_bbox(1) - (new_bbox(1) + new_bbox(3)));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
563 yoffset = 0;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
564 }
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
565 break;
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
566 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
567 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
568
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
569 int
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
570 ft_text_renderer::compute_line_xoffset (const Matrix& lb) const
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
571 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
572 if (! bbox.is_empty ())
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
573 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
574 switch (halign)
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
575 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
576 case 0:
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
577 return 0;
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
578 case 1:
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
579 return (bbox(2) - lb(2)) / 2;
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
580 case 2:
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
581 return (bbox(2) - lb(2));
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
582 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
583 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
584
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
585 return 0;
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
586 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
587
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
588 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
589 ft_text_renderer::compute_bbox (void)
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
590 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
591 // Stack the various line bbox together and compute the final
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
592 // bounding box for the entire text string.
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
593
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
594 bbox = Matrix ();
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
595
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
596 switch (line_bbox.size ())
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
597 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
598 case 0:
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
599 break;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
600
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
601 case 1:
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
602 bbox = line_bbox.front ().extract (0, 0, 0, 3);
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
603 break;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
604
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
605 default:
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
606 for (std::list<Matrix>::const_iterator it = line_bbox.begin ();
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
607 it != line_bbox.end (); ++it)
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
608 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
609 if (bbox.is_empty ())
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
610 bbox = it->extract (0, 0, 0, 3);
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
611 else
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
612 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
613 bbox(1) -= (*it)(3);
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
614 bbox(3) += (*it)(3);
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
615 bbox(2) = octave::math::max (bbox(2), (*it)(2));
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
616 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
617 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
618 break;
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
619 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
620 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
621
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
622 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
623 ft_text_renderer::update_line_bbox (void)
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
624 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
625 // Called after a font change, when in MODE_BBOX mode, to update the
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
626 // current line bbox with the new font metrics. This also includes the
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
627 // current yoffset, that is the offset of the current glyph's baseline
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
628 // the line's baseline.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
629
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
630 if (mode == MODE_BBOX)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
631 {
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
632 int asc = font.get_face ()->size->metrics.ascender >> 6;
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
633 int desc = font.get_face ()->size->metrics.descender >> 6;
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
634
20471
25caa0deaabb Fix multi-line text bounding box when using subscripts (bug #45508)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20454
diff changeset
635 Matrix& bb = line_bbox.back ();
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
636
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
637 if ((yoffset + desc) < bb(1))
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
638 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
639 // The new font goes below the bottom of the current bbox.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
640
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
641 int delta = bb(1) - (yoffset + desc);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
642
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
643 bb(1) -= delta;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
644 bb(3) += delta;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
645 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
646
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
647 if ((yoffset + asc) > (bb(1) + bb(3)))
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
648 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
649 // The new font goes above the top of the current bbox.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
650
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
651 int delta = (yoffset + asc) - (bb(1) + bb(3));
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
652
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
653 bb(3) += delta;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
654 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
655 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
656 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
657
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
658 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
659 ft_text_renderer::set_mode (int m)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
660 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
661 mode = m;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
662
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
663 switch (mode)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
664 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
665 case MODE_BBOX:
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
666 xoffset = line_yoffset = yoffset = 0;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
667 bbox = Matrix (1, 4, 0.0);
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
668 line_bbox.clear ();
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
669 push_new_line ();
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
670 break;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
671
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
672 case MODE_RENDER:
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
673 if (bbox.numel () != 4)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
674 {
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
675 ::warning ("ft_text_renderer: invalid bounding box, cannot render");
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
676
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
677 xoffset = line_yoffset = yoffset = 0;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
678 pixels = uint8NDArray ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
679 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
680 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
681 {
22059
b1256fb38777 dim_vector: replace 7 constructors with single variadic template (patch #9030).
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
682 dim_vector d (4, octave_idx_type (bbox(2)),
b1256fb38777 dim_vector: replace 7 constructors with single variadic template (patch #9030).
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
683 octave_idx_type (bbox(3)));
b1256fb38777 dim_vector: replace 7 constructors with single variadic template (patch #9030).
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
684 pixels = uint8NDArray (d, static_cast<uint8_t> (0));
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
685 xoffset = compute_line_xoffset (line_bbox.front ());
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
686 line_yoffset = -bbox(1)-1;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
687 yoffset = 0;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
688 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
689 break;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
690
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
691 default:
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
692 error ("ft_text_renderer: invalid mode '%d'", mode);
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
693 break;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
694 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
695 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
696
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
697 FT_UInt
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
698 ft_text_renderer::process_character (FT_ULong code, FT_UInt previous)
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
699 {
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
700 FT_Face face = font.get_face ();
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
701 FT_UInt glyph_index = 0;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
702
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
703 if (face)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
704 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
705 glyph_index = FT_Get_Char_Index (face, code);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
706
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
707 if (code != '\n'
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
708 && (! glyph_index
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
709 || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT)))
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
710 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
711 glyph_index = 0;
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 20974
diff changeset
712 warn_missing_glyph (code);
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
713 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
714 else
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
715 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
716 switch (mode)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
717 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
718 case MODE_RENDER:
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
719 if (code == '\n')
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
720 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
721 glyph_index = FT_Get_Char_Index (face, ' ');
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
722 if (! glyph_index
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
723 || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT))
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
724 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
725 glyph_index = 0;
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 20974
diff changeset
726 warn_missing_glyph (' ');
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
727 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
728 else
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
729 push_new_line ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
730 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
731 else if (FT_Render_Glyph (face->glyph, FT_RENDER_MODE_NORMAL))
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
732 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
733 glyph_index = 0;
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 20974
diff changeset
734 warn_glyph_render (code);
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
735 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
736 else
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
737 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
738 FT_Bitmap& bitmap = face->glyph->bitmap;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
739 int x0, y0;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
740
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
741 if (previous)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
742 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
743 FT_Vector delta;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
744
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
745 FT_Get_Kerning (face, previous, glyph_index,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
746 FT_KERNING_DEFAULT, &delta);
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
747 xoffset += (delta.x >> 6);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
748 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
749
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
750 x0 = xoffset + face->glyph->bitmap_left;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
751 y0 = line_yoffset + yoffset + face->glyph->bitmap_top;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
752
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
753 // 'w' seems to have a negative -1
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
754 // face->glyph->bitmap_left, this is so we don't
22173
8de49f15e182 doc: Fix "doubled words" typos (\b(\w+)\s+\1\b)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 22059
diff changeset
755 // index out of bound, and assumes we've allocated
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
756 // the right amount of horizontal space in the bbox.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
757 if (x0 < 0)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
758 x0 = 0;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
759
20454
1a22083b5929 use different approach to avoid unsigned/signed comparison warning
John W. Eaton <jwe@octave.org>
parents: 20451
diff changeset
760 for (int r = 0; static_cast<unsigned int> (r) < bitmap.rows; r++)
1a22083b5929 use different approach to avoid unsigned/signed comparison warning
John W. Eaton <jwe@octave.org>
parents: 20451
diff changeset
761 for (int c = 0; static_cast<unsigned int> (c) < bitmap.width; c++)
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
762 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
763 unsigned char pix = bitmap.buffer[r*bitmap.width+c];
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
764 if (x0+c < 0 || x0+c >= pixels.dim2 ()
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
765 || y0-r < 0 || y0-r >= pixels.dim3 ())
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
766 {
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
767 //::warning ("ft_text_renderer: pixel out of bound (char=%d, (x,y)=(%d,%d), (w,h)=(%d,%d)",
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
768 // str[i], x0+c, y0-r, pixels.dim2 (), pixels.dim3 ());
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
769 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
770 else if (pixels(3, x0+c, y0-r).value () == 0)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
771 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
772 pixels(0, x0+c, y0-r) = color(0);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
773 pixels(1, x0+c, y0-r) = color(1);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
774 pixels(2, x0+c, y0-r) = color(2);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
775 pixels(3, x0+c, y0-r) = pix;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
776 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
777 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
778
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
779 xoffset += (face->glyph->advance.x >> 6);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
780 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
781 break;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
782
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
783 case MODE_BBOX:
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
784 if (code == '\n')
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
785 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
786 glyph_index = FT_Get_Char_Index (face, ' ');
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
787 if (! glyph_index
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
788 || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT))
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
789 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
790 glyph_index = 0;
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 20974
diff changeset
791 warn_missing_glyph (' ');
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
792 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
793 else
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
794 push_new_line ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
795 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
796 else
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
797 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
798 Matrix& bb = line_bbox.back ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
799
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
800 // If we have a previous glyph, use kerning information.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
801 // This usually means moving a bit backward before adding
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
802 // the next glyph. That is, "delta.x" is usually < 0.
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
803 if (previous)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
804 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
805 FT_Vector delta;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
806
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
807 FT_Get_Kerning (face, previous, glyph_index,
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
808 FT_KERNING_DEFAULT, &delta);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
809
17274
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
810 xoffset += (delta.x >> 6);
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
811 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
812
17274
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
813 // Extend current X offset box by the width of the current
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
814 // glyph. Then extend the line bounding box if necessary.
17274
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
815
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
816 xoffset += (face->glyph->advance.x >> 6);
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
817 bb(2) = octave::math::max (bb(2), xoffset);
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
818 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
819 break;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
820 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
821 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
822 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
823
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
824 return glyph_index;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
825 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
826
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
827 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
828 ft_text_renderer::text_to_strlist (const std::string& txt,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
829 std::list<text_renderer::string>& lst,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
830 Matrix& box,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
831 int ha, int va, double rot,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
832 const caseless_str& interp)
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
833 {
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
834 uint8NDArray pxls;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
835
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
836 // First run text_to_pixels which will also build the string list
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
837
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
838 text_to_pixels (txt, pxls, box, ha, va, rot, interp, false);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
839
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
840 lst = strlist;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
841 }
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
842
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
843 void
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
844 ft_text_renderer::visit (text_element_string& e)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
845 {
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
846 if (font.is_valid ())
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
847 {
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
848 FT_UInt glyph_index, previous = 0;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
849
17352
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
850 std::string str = e.string_value ();
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17898
diff changeset
851 size_t n = str.length ();
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17898
diff changeset
852 size_t curr = 0;
20622
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
853 size_t idx = 0;
17377
15e2ad6372f7 maint: Tweaks to remove compiler warnings.
Rik <rik@octave.org>
parents: 17352
diff changeset
854 mbstate_t ps;
15e2ad6372f7 maint: Tweaks to remove compiler warnings.
Rik <rik@octave.org>
parents: 17352
diff changeset
855 memset (&ps, 0, sizeof (ps)); // Initialize state to 0.
17352
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
856 wchar_t wc;
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
857
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
858 text_renderer::string fs (str, font, xoffset, yoffset);
20622
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
859
17352
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
860 while (n > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
861 {
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
862 size_t r = std::mbrtowc (&wc, str.data () + curr, n, &ps);
17352
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
863
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
864 if (r > 0
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
865 && r != static_cast<size_t> (-1)
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
866 && r != static_cast<size_t> (-2))
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
867 {
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
868 n -= r;
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
869 curr += r;
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
870
20622
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
871 if (wc == L'\n')
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
872 {
20715
5b7643257978 Remove trailing whitespace at end of lines.
Rik <rik@octave.org>
parents: 20622
diff changeset
873 // Finish previous string in srtlist before processing
20622
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
874 // the newline character
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
875 fs.set_y (line_yoffset + yoffset);
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
876 fs.set_color (color);
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
877 std::string s = str.substr (idx, curr - idx - 1);
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
878 if (! s.empty ())
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
879 {
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
880 fs.set_string (s);
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
881 strlist.push_back (fs);
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
882 }
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
883 }
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
884
17352
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
885 glyph_index = process_character (wc, previous);
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
886
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
887 if (wc == L'\n')
20622
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
888 {
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
889 previous = 0;
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
890 // Start a new string in strlist
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
891 idx = curr;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
892 fs = text_renderer::string (str.substr (idx), font,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
893 line_xoffset, yoffset);
20715
5b7643257978 Remove trailing whitespace at end of lines.
Rik <rik@octave.org>
parents: 20622
diff changeset
894
20622
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
895 }
17352
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
896 else
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
897 previous = glyph_index;
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
898 }
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
899 else
17352
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
900 {
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
901 if (r != 0)
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
902 ::warning ("ft_text_renderer: failed to decode string `%s' with "
17352
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
903 "locale `%s'", str.c_str (),
17898
8c33abdd2f9a maint: Avoid using NULL in C++ code.
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
904 std::setlocale (LC_CTYPE, 0));
17352
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
905 break;
4a348443de9b Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17330
diff changeset
906 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
907 }
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
908
20622
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
909 if (! fs.get_string ().empty ())
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
910 {
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
911 fs.set_y (line_yoffset + yoffset);
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
912 fs.set_color (color);
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
913 strlist.push_back (fs);
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
914 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
915 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
916 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
917
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
918 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
919 ft_text_renderer::visit (text_element_list& e)
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
920 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
921 // Save and restore (after processing the list) the current font and color.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
922
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
923 ft_font saved_font (font);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
924 uint8NDArray saved_color (color);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
925
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
926 text_processor::visit (e);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
927
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
928 font = saved_font;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
929 color = saved_color;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
930 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
931
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
932 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
933 ft_text_renderer::visit (text_element_subscript& e)
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
934 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
935 ft_font saved_font (font);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
936 int saved_line_yoffset = line_yoffset;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
937 int saved_yoffset = yoffset;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
938
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
939 set_font (font.get_name (), font.get_weight (), font.get_angle (),
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
940 font.get_size () - 2);
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
941
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
942 if (font.is_valid ())
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
943 {
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
944 int h = font.get_face ()->size->metrics.height >> 6;
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
945
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
946 // Shifting the baseline by 2/3 the font height seems to produce
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
947 // decent result.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
948 yoffset -= (h * 2) / 3;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
949
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
950 if (mode == MODE_BBOX)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
951 update_line_bbox ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
952 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
953
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
954 text_processor::visit (e);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
955
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
956 font = saved_font;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
957 // If line_yoffset changed, this means we moved to a new line; hence yoffset
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
958 // cannot be restored, because the saved value is not relevant anymore.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
959 if (line_yoffset == saved_line_yoffset)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
960 yoffset = saved_yoffset;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
961 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
962
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
963 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
964 ft_text_renderer::visit (text_element_superscript& e)
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
965 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
966 ft_font saved_font (font);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
967 int saved_line_yoffset = line_yoffset;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
968 int saved_yoffset = yoffset;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
969
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
970 set_font (font.get_name (), font.get_weight (), font.get_angle (),
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
971 font.get_size () - 2);
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
972
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
973 if (saved_font.is_valid ())
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
974 {
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
975 int s_asc = saved_font.get_face ()->size->metrics.ascender >> 6;
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
976
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
977 // Shifting the baseline by 2/3 base font ascender seems to produce
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
978 // decent result.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
979 yoffset += (s_asc * 2) / 3;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
980
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
981 if (mode == MODE_BBOX)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
982 update_line_bbox ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
983 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
984
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
985 text_processor::visit (e);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
986
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
987 font = saved_font;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
988 // If line_yoffset changed, this means we moved to a new line; hence yoffset
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
989 // cannot be restored, because the saved value is not relevant anymore.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
990 if (line_yoffset == saved_line_yoffset)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
991 yoffset = saved_yoffset;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
992 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
993
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
994 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
995 ft_text_renderer::visit (text_element_color& e)
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
996 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
997 if (mode == MODE_RENDER)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
998 set_color (e.get_color ());
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
999 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1000
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1001 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1002 ft_text_renderer::visit (text_element_fontsize& e)
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1003 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1004 double sz = e.get_fontsize ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1005
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1006 // FIXME: Matlab documentation says that the font size is expressed
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1007 // in the text object FontUnit.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1008
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1009 set_font (font.get_name (), font.get_weight (), font.get_angle (), sz);
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1010
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1011 if (mode == MODE_BBOX)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1012 update_line_bbox ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1013 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1014
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1015 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1016 ft_text_renderer::visit (text_element_fontname& e)
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1017 {
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1018 set_font (e.get_fontname (), font.get_weight (), font.get_angle (),
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1019 font.get_size ());
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1020
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1021 if (mode == MODE_BBOX)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1022 update_line_bbox ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1023 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1024
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1025 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1026 ft_text_renderer::visit (text_element_fontstyle& e)
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1027 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1028 switch (e.get_fontstyle ())
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1029 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1030 case text_element_fontstyle::normal:
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1031 set_font (font.get_name (), "normal", "normal", font.get_size ());
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1032 break;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1033
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1034 case text_element_fontstyle::bold:
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1035 set_font (font.get_name (), "bold", "normal", font.get_size ());
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1036 break;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1037
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1038 case text_element_fontstyle::italic:
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1039 set_font (font.get_name (), "normal", "italic", font.get_size ());
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1040 break;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1041
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1042 case text_element_fontstyle::oblique:
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1043 set_font (font.get_name (), "normal", "oblique", font.get_size ());
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1044 break;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1045 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1046
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1047 if (mode == MODE_BBOX)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1048 update_line_bbox ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1049 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1050
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1051 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1052 ft_text_renderer::visit (text_element_symbol& e)
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1053 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1054 uint32_t code = e.get_symbol_code ();
20715
5b7643257978 Remove trailing whitespace at end of lines.
Rik <rik@octave.org>
parents: 20622
diff changeset
1055
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1056 text_renderer::string fs (std::string ("-"), font, xoffset, yoffset);
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1057
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1058 if (code != text_element_symbol::invalid_code && font.is_valid ())
20622
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1059 {
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1060 process_character (code);
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1061 fs.set_code (code);
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1062 }
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1063 else if (font.is_valid ())
17327
fe6518a1d87c Move TeX symbol decoding into the lexer (bug #39831).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17324
diff changeset
1064 ::warning ("ignoring unknown symbol: %d", e.get_symbol ());
20622
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1065
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1066 if (fs.get_code ())
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1067 {
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1068 fs.set_y (line_yoffset + yoffset);
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1069 fs.set_color (color);
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1070 strlist.push_back (fs);
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1071 }
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1072 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1073
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1074 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1075 ft_text_renderer::visit (text_element_combined& e)
17274
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1076 {
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1077 int saved_xoffset = xoffset;
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1078 int max_xoffset = xoffset;
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1079
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1080 for (text_element_combined::iterator it = e.begin (); it != e.end (); ++it)
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1081 {
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1082 xoffset = saved_xoffset;
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1083 (*it)->accept (*this);
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1084 max_xoffset = octave::math::max (xoffset, max_xoffset);
17274
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1085 }
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1086
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1087 xoffset = max_xoffset;
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1088 }
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1089
0a09d4b40767 Combine successive TeX super- and subscript elements.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17272
diff changeset
1090 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1091 ft_text_renderer::reset (void)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1092 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1093 set_mode (MODE_BBOX);
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1094 set_color (Matrix (1, 3, 0.0));
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1095 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1096
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1097 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1098 ft_text_renderer::set_color (const Matrix& c)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1099 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1100 if (c.numel () == 3)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1101 {
17272
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1102 color(0) = static_cast<uint8_t> (c(0)*255);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1103 color(1) = static_cast<uint8_t> (c(1)*255);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17271
diff changeset
1104 color(2) = static_cast<uint8_t> (c(2)*255);
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1105 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1106 else
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1107 ::warning ("ft_text_renderer::set_color: invalid color");
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1108 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1109
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1110 uint8NDArray
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1111 ft_text_renderer::render (text_element *elt, Matrix& box, int rotation)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1112 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1113 set_mode (MODE_BBOX);
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1114 elt->accept (*this);
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
1115 compute_bbox ();
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1116 box = bbox;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1117
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1118 set_mode (MODE_RENDER);
20622
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1119 // Clear the list of parsed strings
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1120 strlist.clear ();
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1121
9406
c0c23dbbade7 Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9405
diff changeset
1122 if (pixels.numel () > 0)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1123 {
9406
c0c23dbbade7 Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9405
diff changeset
1124 elt->accept (*this);
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1125
9406
c0c23dbbade7 Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9405
diff changeset
1126 switch (rotation)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
1127 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
1128 case ROTATION_0:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
1129 break;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1130
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
1131 case ROTATION_90:
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1132 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1133 Array<octave_idx_type> perm (dim_vector (3, 1));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1134 perm(0) = 0;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1135 perm(1) = 2;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1136 perm(2) = 1;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1137 pixels = pixels.permute (perm);
9406
c0c23dbbade7 Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9405
diff changeset
1138
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1139 Array<idx_vector> idx (dim_vector (3, 1));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1140 idx(0) = idx_vector (':');
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1141 idx(1) = idx_vector (pixels.dim2 ()-1, -1, -1);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1142 idx(2) = idx_vector (':');
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1143 pixels = uint8NDArray (pixels.index (idx));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1144 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
1145 break;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1146
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
1147 case ROTATION_180:
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1148 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1149 Array<idx_vector> idx (dim_vector (3, 1));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1150 idx(0) = idx_vector (':');
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1151 idx(1) = idx_vector (pixels.dim2 ()-1, -1, -1);
21568
3d60ed163b70 maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents: 21334
diff changeset
1152 idx(2) = idx_vector (pixels.dim3 ()-1, -1, -1);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1153 pixels = uint8NDArray (pixels.index (idx));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1154 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
1155 break;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1156
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
1157 case ROTATION_270:
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1158 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1159 Array<octave_idx_type> perm (dim_vector (3, 1));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1160 perm(0) = 0;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1161 perm(1) = 2;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1162 perm(2) = 1;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1163 pixels = pixels.permute (perm);
9406
c0c23dbbade7 Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9405
diff changeset
1164
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1165 Array<idx_vector> idx (dim_vector (3, 1));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1166 idx(0) = idx_vector (':');
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1167 idx(1) = idx_vector (':');
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1168 idx(2) = idx_vector (pixels.dim3 ()-1, -1, -1);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1169 pixels = uint8NDArray (pixels.index (idx));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1170 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
1171 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
1172 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1173 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1174
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1175 return pixels;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1176 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1177
16201
2338a92e9782 Fix spacing between ylabel and y-axis (bug #38461)
Rik <rik@octave.org>
parents: 15467
diff changeset
1178 // Note:
2338a92e9782 Fix spacing between ylabel and y-axis (bug #38461)
Rik <rik@octave.org>
parents: 15467
diff changeset
1179 // x-extent accurately measures width of glyphs.
2338a92e9782 Fix spacing between ylabel and y-axis (bug #38461)
Rik <rik@octave.org>
parents: 15467
diff changeset
1180 // y-extent is overly large because it is measured from baseline-to-baseline.
2338a92e9782 Fix spacing between ylabel and y-axis (bug #38461)
Rik <rik@octave.org>
parents: 15467
diff changeset
1181 // Calling routines, such as ylabel, may need to account for this mismatch.
2338a92e9782 Fix spacing between ylabel and y-axis (bug #38461)
Rik <rik@octave.org>
parents: 15467
diff changeset
1182
10402
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1183 Matrix
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1184 ft_text_renderer::get_extent (text_element *elt, double rotation)
10402
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1185 {
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1186 set_mode (MODE_BBOX);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1187 elt->accept (*this);
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
1188 compute_bbox ();
10402
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1189
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1190 Matrix extent (1, 2, 0.0);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1191
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1192 switch (rotation_to_mode (rotation))
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1193 {
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1194 case ROTATION_0:
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1195 case ROTATION_180:
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1196 extent(0) = bbox(2);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1197 extent(1) = bbox(3);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1198 break;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1199
10402
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1200 case ROTATION_90:
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1201 case ROTATION_270:
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1202 extent(0) = bbox(3);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1203 extent(1) = bbox(2);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1204 }
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1205
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1206 return extent;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1207 }
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1208
12334
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
1209 Matrix
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1210 ft_text_renderer::get_extent (const std::string& txt, double rotation,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1211 const caseless_str& interpreter)
12334
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
1212 {
17269
5b088598df1d Add simple TeX parser based on flex/bison.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16892
diff changeset
1213 text_element *elt = text_parser::parse (txt, interpreter);
12334
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
1214 Matrix extent = get_extent (elt, rotation);
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
1215 delete elt;
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 12969
diff changeset
1216
12334
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
1217 return extent;
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
1218 }
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
1219
10402
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1220 int
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1221 ft_text_renderer::rotation_to_mode (double rotation) const
10402
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1222 {
17526
4f1dd8a980df Clip OpenGL text rotations to range [0,360].
Rik <rik@octave.org>
parents: 17377
diff changeset
1223 // Clip rotation to range [0, 360]
4f1dd8a980df Clip OpenGL text rotations to range [0,360].
Rik <rik@octave.org>
parents: 17377
diff changeset
1224 while (rotation < 0)
4f1dd8a980df Clip OpenGL text rotations to range [0,360].
Rik <rik@octave.org>
parents: 17377
diff changeset
1225 rotation += 360.0;
4f1dd8a980df Clip OpenGL text rotations to range [0,360].
Rik <rik@octave.org>
parents: 17377
diff changeset
1226 while (rotation > 360.0)
4f1dd8a980df Clip OpenGL text rotations to range [0,360].
Rik <rik@octave.org>
parents: 17377
diff changeset
1227 rotation -= 360.0;
4f1dd8a980df Clip OpenGL text rotations to range [0,360].
Rik <rik@octave.org>
parents: 17377
diff changeset
1228
10402
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1229 if (rotation == 0.0)
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1230 return ROTATION_0;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1231 else if (rotation == 90.0)
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1232 return ROTATION_90;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1233 else if (rotation == 180.0)
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1234 return ROTATION_180;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1235 else if (rotation == 270.0)
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1236 return ROTATION_270;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1237 else
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1238 return ROTATION_0;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1239 }
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
1240
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1241 void
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1242 ft_text_renderer::text_to_pixels (const std::string& txt,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1243 uint8NDArray& pxls, Matrix& box,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1244 int _halign, int valign, double rotation,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1245 const caseless_str& interpreter,
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1246 bool handle_rotation)
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1247 {
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1248 int rot_mode = rotation_to_mode (rotation);
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 12969
diff changeset
1249
17271
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17270
diff changeset
1250 halign = _halign;
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1251
17269
5b088598df1d Add simple TeX parser based on flex/bison.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16892
diff changeset
1252 text_element *elt = text_parser::parse (txt, interpreter);
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1253 pxls = render (elt, box, rot_mode);
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1254 delete elt;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1255
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1256 if (pxls.is_empty ())
20974
1edf15793cac maint: Use is_empty rather than "numel () == 0" for clarity.
Rik <rik@octave.org>
parents: 20956
diff changeset
1257 return; // nothing to render
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1258
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1259 switch (halign)
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1260 {
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1261 case 1:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1262 box(0) = -box(2)/2;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1263 break;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1264
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1265 case 2:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1266 box(0) = -box(2);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1267 break;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1268
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1269 default:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1270 box(0) = 0;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1271 break;
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1272 }
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1273
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1274 switch (valign)
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1275 {
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1276 case 1:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1277 box(1) = -box(3)/2;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1278 break;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1279
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1280 case 2:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1281 box(1) = -box(3);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1282 break;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1283
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1284 case 3:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1285 break;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1286
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1287 case 4:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1288 box(1) = -box(3)-box(1);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1289 break;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1290
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1291 default:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1292 box(1) = 0;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1293 break;
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1294 }
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1295
20622
caa5dabc7913 Let the freetype renderer return a list of parsed substrings (bug #31468)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20471
diff changeset
1296 if (handle_rotation)
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1297 {
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1298 switch (rot_mode)
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1299 {
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1300 case ROTATION_90:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1301 std::swap (box(0), box(1));
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1302 std::swap (box(2), box(3));
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1303 box(0) = -box(0)-box(2);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1304 break;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1305
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1306 case ROTATION_180:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1307 box(0) = -box(0)-box(2);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1308 box(1) = -box(1)-box(3);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1309 break;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1310
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1311 case ROTATION_270:
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1312 std::swap (box(0), box(1));
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1313 std::swap (box(2), box(3));
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1314 box(1) = -box(1)-box(3);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1315 break;
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1316 }
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1317 }
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1318 }
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
1319
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1320 ft_text_renderer::ft_font::ft_font (const ft_font& ft)
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1321 : text_renderer::font (ft), face (0)
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1322 {
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1323 #if defined (HAVE_FT_REFERENCE_FACE)
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1324 FT_Face ft_face = ft.get_face ();
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1325
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1326 if (ft_face && FT_Reference_Face (ft_face) == 0)
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1327 face = ft_face;
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1328 #endif
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1329 }
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1330
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1331 ft_text_renderer::ft_font&
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1332 ft_text_renderer::ft_font::operator = (const ft_font& ft)
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1333 {
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1334 if (&ft != this)
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1335 {
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1336 text_renderer::font::operator = (ft);
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1337
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1338 if (face)
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1339 {
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1340 FT_Done_Face (face);
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1341 face = 0;
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1342 }
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1343
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1344 #if defined (HAVE_FT_REFERENCE_FACE)
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1345 FT_Face ft_face = ft.get_face ();
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1346
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1347 if (ft_face && FT_Reference_Face (ft_face) == 0)
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1348 face = ft_face;
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1349 #endif
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1350 }
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1351
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1352 return *this;
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1353 }
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1354
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1355 FT_Face
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1356 ft_text_renderer::ft_font::get_face (void) const
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1357 {
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1358 if (! face && ! name.empty ())
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1359 {
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1360 face = ft_manager::get_font (name, weight, angle, size);
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1361
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1362 if (face)
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1363 {
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1364 if (FT_Set_Char_Size (face, 0, size*64, 0, 0))
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1365 ::warning ("ft_text_renderer: unable to set font size to %g", size);
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1366 }
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1367 else
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1368 ::warning ("ft_text_renderer: unable to load appropriate font");
17330
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1369 }
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1370
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1371 return face;
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1372 }
219552139c18 Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17327
diff changeset
1373
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1374 }
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1375
20945
9d9270e2f98f eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents: 20715
diff changeset
1376 #endif
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1377
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1378 namespace octave
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1379 {
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1380 base_text_renderer *
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1381 make_ft_text_renderer (void)
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1382 {
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1383 #if defined (HAVE_FREETYPE)
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1384 return new ft_text_renderer ();
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1385 #else
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1386 return 0;
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1387 #endif
22326
71dd9d5a5ecd move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1388 }
21209
67d2965af0b5 revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1389 }