Mercurial > octave
annotate libinterp/corefcn/ft-text-renderer.cc @ 29655:32f4357ac8d9
maint: merge stable to default.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Wed, 12 May 2021 19:28:54 +0200 |
parents | aef11bb4e6d1 d13d090cb03a |
children | 7511182e5e9b |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
28483
diff
changeset
|
3 // Copyright (C) 2009-2021 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21568
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21209
diff
changeset
|
27 # include "config.h" |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
28 #endif |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
29 |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
30 #include "base-text-renderer.h" |
23462
314d980bee93
maint: Add '#include "XXX.h"' to XXX.cc files.
Rik <rik@octave.org>
parents:
23457
diff
changeset
|
31 #include "ft-text-renderer.h" |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
32 |
14003
1555c5a177c9
better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents:
13999
diff
changeset
|
33 #if defined (HAVE_FREETYPE) |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
34 |
21334
36e75e013849
* ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
35 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC) |
24444
53ca76c5cc8d
maint: Indent pragmas as other preprocessor directives.
John W. Eaton <jwe@octave.org>
parents:
24126
diff
changeset
|
36 # pragma GCC diagnostic push |
53ca76c5cc8d
maint: Indent pragmas as other preprocessor directives.
John W. Eaton <jwe@octave.org>
parents:
24126
diff
changeset
|
37 # pragma GCC diagnostic ignored "-Wold-style-cast" |
21334
36e75e013849
* ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
38 #endif |
36e75e013849
* ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
39 |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
40 #include <ft2build.h> |
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
41 #include FT_FREETYPE_H |
26187
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
42 #include FT_GLYPH_H |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
43 |
14003
1555c5a177c9
better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents:
13999
diff
changeset
|
44 #if defined (HAVE_FONTCONFIG) |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
45 # include <fontconfig/fontconfig.h> |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
46 #endif |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
47 |
21334
36e75e013849
* ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
48 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC) |
24444
53ca76c5cc8d
maint: Indent pragmas as other preprocessor directives.
John W. Eaton <jwe@octave.org>
parents:
24126
diff
changeset
|
49 # pragma GCC diagnostic pop |
21334
36e75e013849
* ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
50 #endif |
36e75e013849
* ft-text-renderer.cc: Use pragma to avoid old-style cast warnings.
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
51 |
17352
4a348443de9b
Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17330
diff
changeset
|
52 #include <clocale> |
4a348443de9b
Support multibyte characters in Freetype-based renderer (bug #31596).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17330
diff
changeset
|
53 #include <cwchar> |
17270
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
54 #include <map> |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
55 #include <utility> |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
56 |
13992
e1f76bfe0452
apply singleton_cleanup to a few more classes
John W. Eaton <jwe@octave.org>
parents:
13730
diff
changeset
|
57 #include "singleton-cleanup.h" |
25362
def1b446ba64
Convert strings to UTF-32 for FreeType (bug #53646).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25336
diff
changeset
|
58 #include "unistr-wrappers.h" |
13992
e1f76bfe0452
apply singleton_cleanup to a few more classes
John W. Eaton <jwe@octave.org>
parents:
13730
diff
changeset
|
59 |
25460
627d6bde9b8d
solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
60 #include "defaults.h" |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
61 #include "error.h" |
24126
2390079a8aed
Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24076
diff
changeset
|
62 #include "file-ops.h" |
2390079a8aed
Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24076
diff
changeset
|
63 #include "oct-env.h" |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
64 #include "pr-output.h" |
29489
ee66869c30d6
Fix loading fonts from path with non-ASCII characters on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29470
diff
changeset
|
65 #include "sysdep.h" |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
66 #include "text-renderer.h" |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
67 |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
68 namespace octave |
13317
d2b799e3178a
allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
69 { |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
70 // FIXME: maybe issue at most one warning per glyph/font/size/weight |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
71 // combination. |
13317
d2b799e3178a
allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
72 |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
73 static void |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
74 warn_missing_glyph (FT_ULong c) |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
75 { |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
76 warning_with_id ("Octave:missing-glyph", |
26152
b68c41cb0f99
Silence compiler warning about incorrect format specifier (bug #55046).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25460
diff
changeset
|
77 "text_renderer: skipping missing glyph for character '%lx'", c); |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
78 } |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
79 |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
80 static void |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
81 warn_glyph_render (FT_ULong c) |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
82 { |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
83 warning_with_id ("Octave:glyph-render", |
26152
b68c41cb0f99
Silence compiler warning about incorrect format specifier (bug #55046).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25460
diff
changeset
|
84 "text_renderer: unable to render glyph for character '%lx'", c); |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
85 } |
13317
d2b799e3178a
allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
86 |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
87 #if defined (_MSC_VER) |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
88 // FIXME: is this really needed? |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
89 // |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
90 // This is just a trick to avoid multiple symbol definitions. |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
91 // PermMatrix.h contains a dllexport'ed Array<octave_idx_type> |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
92 // that will cause MSVC not to generate a new instantiation and |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
93 // use the imported one instead. |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
94 # include "PermMatrix.h" |
13730
a2c74b5c02de
[MSVC] Prevent duplicate symbol.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13317
diff
changeset
|
95 #endif |
a2c74b5c02de
[MSVC] Prevent duplicate symbol.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13317
diff
changeset
|
96 |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
97 // Forward declaration |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
98 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
|
99 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
100 class |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
101 ft_manager |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
102 { |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
103 private: |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
104 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
105 ft_manager (void) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
106 : library (), freetype_initialized (false), fontconfig_initialized (false) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
107 { |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
108 if (FT_Init_FreeType (&library)) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
109 error ("unable to initialize FreeType library"); |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
110 else |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
111 freetype_initialized = true; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
112 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
113 #if defined (HAVE_FONTCONFIG) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
114 if (! FcInit ()) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
115 error ("unable to initialize fontconfig library"); |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
116 else |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
117 fontconfig_initialized = true; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
118 #endif |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
119 } |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
120 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
121 public: |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
122 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
123 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
124 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
125 ft_manager (const ft_manager&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
126 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
127 ft_manager& operator = (const ft_manager&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
128 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
129 private: |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
130 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
131 ~ft_manager (void) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
132 { |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
133 if (freetype_initialized) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
134 FT_Done_FreeType (library); |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
135 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
136 #if defined (HAVE_FONTCONFIG) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
137 // FIXME: Skip the call to FcFini because it can trigger the assertion |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
138 // |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
139 // octave: fccache.c:507: FcCacheFini: Assertion 'fcCacheChains[i] == ((void *)0)' failed. |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
140 // |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
141 // if (fontconfig_initialized) |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
142 // FcFini (); |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
143 #endif |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
144 } |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
145 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
146 public: |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
147 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
148 static bool instance_ok (void) |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
149 { |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
150 bool retval = true; |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
151 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
152 if (! instance) |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
153 { |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
154 instance = new ft_manager (); |
26369
0249ba4c9589
Fix static analyzer detected V668 issues (bug #55347).
Andreas Weber <octave@josoansi.de>
parents:
26340
diff
changeset
|
155 singleton_cleanup_list::add (cleanup_instance); |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
156 } |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
157 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
158 return retval; |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
159 } |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
160 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23696
diff
changeset
|
161 static void cleanup_instance (void) { delete instance; instance = nullptr; } |
13992
e1f76bfe0452
apply singleton_cleanup to a few more classes
John W. Eaton <jwe@octave.org>
parents:
13730
diff
changeset
|
162 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
163 static FT_Face get_font (const std::string& name, const std::string& weight, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
164 const std::string& angle, double size) |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
165 { |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
166 return (instance_ok () |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
167 ? instance->do_get_font (name, weight, angle, size) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23696
diff
changeset
|
168 : nullptr); |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
169 } |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
170 |
27623
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
171 static octave_map get_system_fonts (void) |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
172 { |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
173 return (instance_ok () |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
174 ? instance->do_get_system_fonts () |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
175 : octave_map ()); |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
176 } |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
177 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
178 static void font_destroyed (FT_Face face) |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
179 { |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
180 if (instance_ok ()) |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
181 instance->do_font_destroyed (face); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
182 } |
17270
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
183 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
184 private: |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
185 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
186 static ft_manager *instance; |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
187 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
188 typedef std::pair<std::string, double> ft_key; |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
189 typedef std::map<ft_key, FT_Face> ft_cache; |
17270
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
190 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
191 // Cache the fonts loaded by FreeType. This cache only contains |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
192 // weak references to the fonts, strong references are only present |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
193 // in class text_renderer. |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
194 ft_cache cache; |
17270
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
195 |
27623
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
196 static octave_map do_get_system_fonts (void) |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
197 { |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
198 static octave_map font_map; |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
199 |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
200 if (font_map.isempty ()) |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
201 { |
28483
98889de398dd
* ft-text-renderer.cc: Allow build to succeed if HAVE_FONTCONFIG is undefined.
John W. Eaton <jwe@octave.org>
parents:
28305
diff
changeset
|
202 #if defined (HAVE_FONTCONFIG) |
27623
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
203 FcConfig *config = FcConfigGetCurrent(); |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
204 FcPattern *pat = FcPatternCreate (); |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
205 FcObjectSet *os = FcObjectSetBuild (FC_FAMILY, FC_SLANT, FC_WEIGHT, |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
206 FC_CHARSET, nullptr); |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
207 FcFontSet *fs = FcFontList (config, pat, os); |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
208 |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
209 if (fs->nfont > 0) |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
210 { |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
211 // Mark fonts that have at least all printable ASCII chars |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
212 FcCharSet *minimal_charset = FcCharSetCreate (); |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
213 for (int i = 32; i < 127; i++) |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
214 FcCharSetAddChar (minimal_charset, static_cast<FcChar32> (i)); |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
215 |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
216 string_vector fields (4); |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
217 fields(0) = "family"; |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
218 fields(1) = "angle"; |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
219 fields(2) = "weight"; |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
220 fields(3) = "suitable"; |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
221 |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
222 dim_vector dv (1, fs->nfont); |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
223 Cell families (dv); |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
224 Cell angles (dv); |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
225 Cell weights (dv); |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
226 Cell suitable (dv); |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
227 |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
228 unsigned char *family; |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
229 int val; |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
230 for (int i = 0; fs && i < fs->nfont; i++) |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
231 { |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
232 FcPattern *font = fs->fonts[i]; |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
233 if (FcPatternGetString (font, FC_FAMILY, 0, &family) |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
234 == FcResultMatch) |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
235 families(i) = std::string (reinterpret_cast<char*> (family)); |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
236 else |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
237 families(i) = "unknown"; |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
238 |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
239 if (FcPatternGetInteger (font, FC_SLANT, 0, &val) |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
240 == FcResultMatch) |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
241 angles(i) = (val == FC_SLANT_ITALIC |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
242 || val == FC_SLANT_OBLIQUE) |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
243 ? "italic" : "normal"; |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
244 else |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
245 angles(i) = "unknown"; |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
246 |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
247 if (FcPatternGetInteger (font, FC_WEIGHT, 0, &val) |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
248 == FcResultMatch) |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
249 weights(i) = (val == FC_WEIGHT_BOLD |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
250 || val == FC_WEIGHT_DEMIBOLD) |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
251 ? "bold" : "normal"; |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
252 else |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
253 weights(i) = "unknown"; |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
254 |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
255 FcCharSet *cset; |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
256 if (FcPatternGetCharSet (font, FC_CHARSET, 0, &cset) |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
257 == FcResultMatch) |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
258 suitable(i) = (FcCharSetIsSubset (minimal_charset, cset) |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
259 ? true : false); |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
260 else |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
261 suitable(i) = false; |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
262 } |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
263 |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
264 font_map = octave_map (dv, fields); |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
265 |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
266 font_map.assign ("family", families); |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
267 font_map.assign ("angle", angles); |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
268 font_map.assign ("weight", weights); |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
269 font_map.assign ("suitable", suitable); |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
270 |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
271 if (fs) |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
272 FcFontSetDestroy (fs); |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
273 } |
28483
98889de398dd
* ft-text-renderer.cc: Allow build to succeed if HAVE_FONTCONFIG is undefined.
John W. Eaton <jwe@octave.org>
parents:
28305
diff
changeset
|
274 #endif |
27623
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
275 } |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
276 |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
277 return font_map; |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
278 } |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
279 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
280 FT_Face do_get_font (const std::string& name, const std::string& weight, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
281 const std::string& angle, double size) |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
282 { |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23696
diff
changeset
|
283 FT_Face retval = nullptr; |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
284 |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
285 #if defined (HAVE_FT_REFERENCE_FACE) |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
286 // Look first into the font cache, then use fontconfig. If the font |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
287 // 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
|
288 |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
289 ft_key key (name + ':' + weight + ':' + angle, size); |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
290 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
|
291 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
292 if (it != cache.end ()) |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
293 { |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
294 FT_Reference_Face (it->second); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
295 return it->second; |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
296 } |
17330
219552139c18
Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17327
diff
changeset
|
297 #endif |
17270
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
298 |
24899
1a46d174a483
include a proper definition of Octave's private font fallback directory
Mike Miller <mtmiller@octave.org>
parents:
24722
diff
changeset
|
299 static std::string fonts_dir; |
24126
2390079a8aed
Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24076
diff
changeset
|
300 |
24899
1a46d174a483
include a proper definition of Octave's private font fallback directory
Mike Miller <mtmiller@octave.org>
parents:
24722
diff
changeset
|
301 if (fonts_dir.empty ()) |
24126
2390079a8aed
Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24076
diff
changeset
|
302 { |
24899
1a46d174a483
include a proper definition of Octave's private font fallback directory
Mike Miller <mtmiller@octave.org>
parents:
24722
diff
changeset
|
303 fonts_dir = sys::env::getenv ("OCTAVE_FONTS_DIR"); |
24126
2390079a8aed
Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24076
diff
changeset
|
304 |
24899
1a46d174a483
include a proper definition of Octave's private font fallback directory
Mike Miller <mtmiller@octave.org>
parents:
24722
diff
changeset
|
305 if (fonts_dir.empty ()) |
24900
00d42b86d0a5
configure: new option --with-system-freefont to use system fonts (bug #53348)
Mike Miller <mtmiller@octave.org>
parents:
24899
diff
changeset
|
306 #if defined (SYSTEM_FREEFONT_DIR) |
25460
627d6bde9b8d
solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
307 fonts_dir = SYSTEM_FREEFONT_DIR; |
24900
00d42b86d0a5
configure: new option --with-system-freefont to use system fonts (bug #53348)
Mike Miller <mtmiller@octave.org>
parents:
24899
diff
changeset
|
308 #else |
25460
627d6bde9b8d
solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
309 fonts_dir = config::oct_fonts_dir (); |
24900
00d42b86d0a5
configure: new option --with-system-freefont to use system fonts (bug #53348)
Mike Miller <mtmiller@octave.org>
parents:
24899
diff
changeset
|
310 #endif |
24126
2390079a8aed
Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24076
diff
changeset
|
311 } |
2390079a8aed
Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24076
diff
changeset
|
312 |
2390079a8aed
Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24076
diff
changeset
|
313 |
2390079a8aed
Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24076
diff
changeset
|
314 // Default font file |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
315 std::string file; |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
316 |
24899
1a46d174a483
include a proper definition of Octave's private font fallback directory
Mike Miller <mtmiller@octave.org>
parents:
24722
diff
changeset
|
317 if (! fonts_dir.empty ()) |
24126
2390079a8aed
Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24076
diff
changeset
|
318 { |
25336
389757b7b6af
eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
319 file = fonts_dir + sys::file_ops::dir_sep_str () + "FreeSans"; |
24126
2390079a8aed
Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24076
diff
changeset
|
320 |
2390079a8aed
Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24076
diff
changeset
|
321 if (weight == "bold") |
2390079a8aed
Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24076
diff
changeset
|
322 file += "Bold"; |
2390079a8aed
Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24076
diff
changeset
|
323 |
2390079a8aed
Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24076
diff
changeset
|
324 if (angle == "italic" || angle == "oblique") |
2390079a8aed
Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24076
diff
changeset
|
325 file += "Oblique"; |
2390079a8aed
Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24076
diff
changeset
|
326 |
2390079a8aed
Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24076
diff
changeset
|
327 file += ".otf"; |
2390079a8aed
Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24076
diff
changeset
|
328 } |
2390079a8aed
Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24076
diff
changeset
|
329 |
14003
1555c5a177c9
better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents:
13999
diff
changeset
|
330 #if defined (HAVE_FONTCONFIG) |
24126
2390079a8aed
Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24076
diff
changeset
|
331 if (name != "*" && fontconfig_initialized) |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
332 { |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
333 int fc_weight, fc_angle; |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
334 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
335 if (weight == "bold") |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
336 fc_weight = FC_WEIGHT_BOLD; |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
337 else |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
338 fc_weight = FC_WEIGHT_NORMAL; |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
339 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
340 if (angle == "italic") |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
341 fc_angle = FC_SLANT_ITALIC; |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
342 else if (angle == "oblique") |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
343 fc_angle = FC_SLANT_OBLIQUE; |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
344 else |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
345 fc_angle = FC_SLANT_ROMAN; |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
346 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
347 FcPattern *pat = FcPatternCreate (); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
348 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
349 FcPatternAddString (pat, FC_FAMILY, |
23447
db1fdf4384dd
maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
350 (reinterpret_cast<const FcChar8 *> |
24126
2390079a8aed
Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24076
diff
changeset
|
351 (name.c_str ()))); |
9616
2093499ec9f4
avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents:
9406
diff
changeset
|
352 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
353 FcPatternAddInteger (pat, FC_WEIGHT, fc_weight); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
354 FcPatternAddInteger (pat, FC_SLANT, fc_angle); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
355 FcPatternAddDouble (pat, FC_PIXEL_SIZE, size); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
356 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23696
diff
changeset
|
357 if (FcConfigSubstitute (nullptr, pat, FcMatchPattern)) |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
358 { |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
359 FcResult res; |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
360 FcPattern *match; |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
361 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
362 FcDefaultSubstitute (pat); |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23696
diff
changeset
|
363 match = FcFontMatch (nullptr, pat, &res); |
9833 | 364 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
365 // FIXME: originally, this test also required that |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
366 // res != FcResultNoMatch. Is that really needed? |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
367 if (match) |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
368 { |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
369 unsigned char *tmp; |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
370 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
371 FcPatternGetString (match, FC_FILE, 0, &tmp); |
23447
db1fdf4384dd
maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
372 file = reinterpret_cast<char *> (tmp); |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
373 } |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
374 else |
24126
2390079a8aed
Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24076
diff
changeset
|
375 ::warning ("could not match any font: %s-%s-%s-%g, using default font", |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
376 name.c_str (), weight.c_str (), angle.c_str (), |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
377 size); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
378 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
379 if (match) |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
380 FcPatternDestroy (match); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
381 } |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
382 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
383 FcPatternDestroy (pat); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
384 } |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
385 #endif |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
386 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
387 if (file.empty ()) |
24126
2390079a8aed
Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24076
diff
changeset
|
388 ::warning ("unable to find default font files"); |
2390079a8aed
Provide default font files and use them (bug #52150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24076
diff
changeset
|
389 else |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
390 { |
29489
ee66869c30d6
Fix loading fonts from path with non-ASCII characters on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29470
diff
changeset
|
391 std::string ascii_file = sys::get_ASCII_filename (file); |
ee66869c30d6
Fix loading fonts from path with non-ASCII characters on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29470
diff
changeset
|
392 if (FT_New_Face (library, ascii_file.c_str (), 0, &retval)) |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
393 ::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
|
394 #if defined (HAVE_FT_REFERENCE_FACE) |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
395 else |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
396 { |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
397 // Install a finalizer to notify ft_manager that the font is |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
398 // being destroyed. The class ft_manager only keeps weak |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
399 // 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
|
400 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
401 retval->generic.data = new ft_key (key); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
402 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
|
403 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
404 // Insert loaded font into the cache. |
28206
11d66485fc19
Correctly cache fonts in ft_manager (bug #58150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27923
diff
changeset
|
405 if (FT_Reference_Face (retval) == 0) |
11d66485fc19
Correctly cache fonts in ft_manager (bug #58150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27923
diff
changeset
|
406 cache[key] = retval; |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
407 } |
17330
219552139c18
Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17327
diff
changeset
|
408 #endif |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
409 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
410 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
411 return retval; |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
412 } |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
413 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
414 void do_font_destroyed (FT_Face face) |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
415 { |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
416 if (face->generic.data) |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
417 { |
23447
db1fdf4384dd
maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
418 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
|
419 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
420 cache.erase (*pkey); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
421 delete pkey; |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23696
diff
changeset
|
422 face->generic.data = nullptr; |
28206
11d66485fc19
Correctly cache fonts in ft_manager (bug #58150)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27923
diff
changeset
|
423 FT_Done_Face (face); |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
424 } |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
425 } |
17270
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
426 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
427 private: |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
428 FT_Library library; |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
429 bool freetype_initialized; |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
430 bool fontconfig_initialized; |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
431 }; |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
432 |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23447
diff
changeset
|
433 ft_manager *ft_manager::instance = nullptr; |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
434 |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
435 static void |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
436 ft_face_destroyed (void *object) |
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
437 { |
25336
389757b7b6af
eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
438 ft_manager::font_destroyed (reinterpret_cast<FT_Face> (object)); |
24722
af6c1ed60581
avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
439 } |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
440 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
441 class |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
442 OCTINTERP_API |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
443 ft_text_renderer : public base_text_renderer |
21209
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 public: |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
446 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
447 enum |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
448 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
449 MODE_BBOX = 0, |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
450 MODE_RENDER = 1 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
451 }; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
452 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
453 public: |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
454 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
455 ft_text_renderer (void) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
456 : base_text_renderer (), font (), bbox (1, 4, 0.0), halign (0), |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
457 xoffset (0), line_yoffset (0), yoffset (0), mode (MODE_BBOX), |
26573
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
458 color (dim_vector (1, 3), 0), m_do_strlist (false), m_strlist (), |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
459 line_xoffset (0), m_ymin (0), m_ymax (0), m_deltax (0), |
26858
0adb232f93b9
Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26619
diff
changeset
|
460 m_max_fontsize (0), m_antialias (true) |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22331
diff
changeset
|
461 { } |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
462 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
463 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
464 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
465 ft_text_renderer (const ft_text_renderer&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
466 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
467 ft_text_renderer& operator = (const ft_text_renderer&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
468 |
22868
87e3163f6c87
use c++11 "= default" syntax for declaration of trivial destructors
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
469 ~ft_text_renderer (void) = default; |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
470 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
471 void visit (text_element_string& e); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
472 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
473 void visit (text_element_list& e); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
474 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
475 void visit (text_element_subscript& e); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
476 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
477 void visit (text_element_superscript& e); |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
478 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
479 void visit (text_element_color& e); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
480 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
481 void visit (text_element_fontsize& e); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
482 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
483 void visit (text_element_fontname& e); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
484 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
485 void visit (text_element_fontstyle& e); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
486 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
487 void visit (text_element_symbol& e); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
488 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
489 void visit (text_element_combined& e); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
490 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
491 void reset (void); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
492 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
493 uint8NDArray get_pixels (void) const { return pixels; } |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
494 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
495 Matrix get_boundingbox (void) const { return bbox; } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
496 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
497 uint8NDArray render (text_element *elt, Matrix& box, |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
498 int rotation = ROTATION_0); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
499 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
500 Matrix get_extent (text_element *elt, double rotation = 0.0); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
501 Matrix get_extent (const std::string& txt, double rotation, |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
502 const caseless_str& interpreter); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
503 |
26858
0adb232f93b9
Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26619
diff
changeset
|
504 void set_anti_aliasing (bool val) { m_antialias = val; }; |
0adb232f93b9
Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26619
diff
changeset
|
505 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
506 void set_font (const std::string& name, const std::string& weight, |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
507 const std::string& angle, double size); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
508 |
27623
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
509 octave_map get_system_fonts (void); |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
510 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
511 void set_color (const Matrix& c); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
512 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
513 void set_mode (int m); |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
514 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
515 void text_to_pixels (const std::string& txt, |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
516 uint8NDArray& pxls, Matrix& bbox, |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
517 int halign, int valign, double rotation, |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
518 const caseless_str& interpreter, |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
519 bool handle_rotation); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
520 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
521 private: |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
522 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
523 // Class to hold information about fonts and a strong |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
524 // reference to the font objects loaded by FreeType. |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
525 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
526 class ft_font : public text_renderer::font |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
527 { |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
528 public: |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
529 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
530 ft_font (void) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23696
diff
changeset
|
531 : text_renderer::font (), face (nullptr) { } |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
532 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
533 ft_font (const std::string& nm, const std::string& wt, |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23696
diff
changeset
|
534 const std::string& ang, double sz, FT_Face f = nullptr) |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
535 : text_renderer::font (nm, wt, ang, sz), face (f) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
536 { } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
537 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
538 ft_font (const ft_font& ft); |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
539 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
540 ~ft_font (void) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
541 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
542 if (face) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
543 FT_Done_Face (face); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
544 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
545 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
546 ft_font& operator = (const ft_font& ft); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
547 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
548 bool is_valid (void) const { return get_face (); } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
549 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
550 FT_Face get_face (void) const; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
551 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
552 private: |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
553 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
554 mutable FT_Face face; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
555 }; |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
556 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
557 void push_new_line (void); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
558 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
559 void update_line_bbox (void); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
560 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
561 void compute_bbox (void); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
562 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
563 int compute_line_xoffset (const Matrix& lb) const; |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
564 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
565 FT_UInt process_character (FT_ULong code, FT_UInt previous = 0); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
566 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
567 public: |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
568 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
569 void text_to_strlist (const std::string& txt, |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
570 std::list<text_renderer::string>& lst, Matrix& bbox, |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
571 int halign, int valign, double rotation, |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
572 const caseless_str& interp); |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
573 |
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
574 private: |
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
575 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
576 // The current font used by the renderer. |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
577 ft_font font; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
578 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
579 // Used to stored the bounding box corresponding to the rendered text. |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
580 // The bounding box has the form [x, y, w, h] where x and y represent the |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
581 // coordinates of the bottom left corner relative to the anchor point of |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
582 // the text (== start of text on the baseline). Due to font descent or |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
583 // multiple lines, the value y is usually negative. |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
584 Matrix bbox; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
585 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
586 // Used to stored the rendered text. It's a 3D matrix with size MxNx4 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
587 // where M and N are the width and height of the bounding box. |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
588 uint8NDArray pixels; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
589 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
590 // Used to store the bounding box of each line. This is used to layout |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
591 // multiline text properly. |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
592 std::list<Matrix> line_bbox; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
593 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
594 // The current horizontal alignment. This is used to align multi-line text. |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
595 int halign; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
596 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
597 // The X offset for the next glyph. |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
598 int xoffset; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
599 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
600 // The Y offset of the baseline for the current line. |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
601 int line_yoffset; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
602 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
603 // The Y offset of the baseline for the next glyph. The offset is relative |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
604 // to line_yoffset. The total Y offset is computed with: |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
605 // line_yoffset + yoffset. |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
606 int yoffset; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
607 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
608 // The current mode of the rendering process (box computing or rendering). |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
609 int mode; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
610 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
611 // The base color of the rendered text. |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
612 uint8NDArray color; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
613 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
614 // A list of parsed strings to be used for printing. |
26573
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
615 bool m_do_strlist; |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
616 std::list<text_renderer::string> m_strlist; |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
617 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
618 // The X offset of the baseline for the current line. |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
619 int line_xoffset; |
26617
98afb8bbd1f6
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
26573
diff
changeset
|
620 |
26187
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
621 // Min and max y coordinates of all glyphs in a line. |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
622 FT_Pos m_ymin; |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
623 FT_Pos m_ymax; |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
624 |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
625 // Difference between the advance and the actual extent of the latest glyph |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
626 FT_Pos m_deltax; |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
627 |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
628 // Used for computing the distance between lines. |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
629 double m_max_fontsize; |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
630 |
26858
0adb232f93b9
Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26619
diff
changeset
|
631 // Anti-aliasing. |
0adb232f93b9
Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26619
diff
changeset
|
632 bool m_antialias; |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
633 |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
634 }; |
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
635 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
636 void |
27623
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
637 ft_text_renderer::set_font (const std::string& name, |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
638 const std::string& weight, |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
639 const std::string& angle, double size) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
640 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
641 // FIXME: take "fontunits" into account |
27623
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
642 font = ft_font (name, weight, angle, size, nullptr); |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
643 } |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
644 |
27623
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
645 octave_map |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
646 ft_text_renderer::get_system_fonts (void) |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
647 { |
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
648 return ft_manager::get_system_fonts (); |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
649 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
650 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
651 void |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
652 ft_text_renderer::push_new_line (void) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
653 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
654 switch (mode) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
655 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
656 case MODE_BBOX: |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
657 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
658 // Create a new bbox entry based on the current font. |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
659 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
660 FT_Face face = font.get_face (); |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
661 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
662 if (face) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
663 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
664 Matrix bb (1, 5, 0.0); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
665 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
666 line_bbox.push_back (bb); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
667 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
668 xoffset = yoffset = 0; |
26187
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
669 m_ymin = m_ymax = m_deltax = 0; |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
670 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
671 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
672 break; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
673 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
674 case MODE_RENDER: |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
675 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
676 // Move to the next line bbox, adjust xoffset based on alignment |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
677 // and yoffset based on the old and new line bbox. |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
678 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
679 Matrix old_bbox = line_bbox.front (); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
680 line_bbox.pop_front (); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
681 Matrix new_bbox = line_bbox.front (); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
682 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
683 xoffset = line_xoffset = compute_line_xoffset (new_bbox); |
26221
76ac35f71573
Fix regression in multi-line text rendering (bug #55218)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26187
diff
changeset
|
684 line_yoffset -= (-old_bbox(1) + math::round (0.4 * m_max_fontsize) |
26187
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
685 + (new_bbox(3) + new_bbox(1))); |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
686 yoffset = 0; |
26187
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
687 m_ymin = m_ymax = m_deltax = 0; |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
688 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
689 break; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
690 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
691 } |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
692 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
693 int |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
694 ft_text_renderer::compute_line_xoffset (const Matrix& lb) const |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
695 { |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23462
diff
changeset
|
696 if (! bbox.isempty ()) |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
697 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
698 switch (halign) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
699 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
700 case 0: |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
701 return 0; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
702 case 1: |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
703 return (bbox(2) - lb(2)) / 2; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
704 case 2: |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
705 return (bbox(2) - lb(2)); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
706 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
707 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
708 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
709 return 0; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
710 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
711 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
712 void |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
713 ft_text_renderer::compute_bbox (void) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
714 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
715 // Stack the various line bbox together and compute the final |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
716 // bounding box for the entire text string. |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
717 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
718 bbox = Matrix (); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
719 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
720 switch (line_bbox.size ()) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
721 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
722 case 0: |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
723 break; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
724 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
725 case 1: |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
726 bbox = line_bbox.front ().extract (0, 0, 0, 3); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
727 break; |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
728 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
729 default: |
22862
e365e87371a3
maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
730 for (const auto& lbox : line_bbox) |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
731 { |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23462
diff
changeset
|
732 if (bbox.isempty ()) |
22862
e365e87371a3
maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
733 bbox = lbox.extract (0, 0, 0, 3); |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
734 else |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
735 { |
26221
76ac35f71573
Fix regression in multi-line text rendering (bug #55218)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26187
diff
changeset
|
736 double delta = math::round (0.4 * m_max_fontsize) + lbox(3); |
26187
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
737 bbox(1) -= delta; |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
738 bbox(3) += delta; |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
739 bbox(2) = math::max (bbox(2), lbox(2)); |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
740 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
741 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
742 break; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
743 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
744 } |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
745 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
746 void |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
747 ft_text_renderer::update_line_bbox (void) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
748 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
749 // Called after a font change, when in MODE_BBOX mode, to update the |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
750 // current line bbox with the new font metrics. This also includes the |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
751 // current yoffset, that is the offset of the current glyph's baseline |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
752 // the line's baseline. |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
753 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
754 if (mode == MODE_BBOX) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
755 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
756 Matrix& bb = line_bbox.back (); |
26187
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
757 bb(1) = m_ymin; |
26330
45cf2ada3e39
Make sure text bounding box is high enough (bug #55328).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26221
diff
changeset
|
758 // Add one pixel to the bbox height to avoid occasional text clipping. |
45cf2ada3e39
Make sure text bounding box is high enough (bug #55328).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26221
diff
changeset
|
759 // See bug #55328. |
45cf2ada3e39
Make sure text bounding box is high enough (bug #55328).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26221
diff
changeset
|
760 bb(3) = (m_ymax + 1) - m_ymin; |
26187
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
761 if (m_deltax > 0) |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
762 bb(2) += m_deltax; |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
763 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
764 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
765 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
766 void |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
767 ft_text_renderer::set_mode (int m) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
768 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
769 mode = m; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
770 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
771 switch (mode) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
772 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
773 case MODE_BBOX: |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
774 xoffset = line_yoffset = yoffset = 0; |
26187
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
775 m_max_fontsize = 0.0; |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
776 bbox = Matrix (1, 4, 0.0); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
777 line_bbox.clear (); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
778 push_new_line (); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
779 break; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
780 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
781 case MODE_RENDER: |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
782 if (bbox.numel () != 4) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
783 { |
22515
77b50a83ec11
Error out, rather than segfault, when fontname is "" (bug #49102).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
784 ::error ("ft_text_renderer: invalid bounding box, cannot render"); |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
785 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
786 xoffset = line_yoffset = yoffset = 0; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
787 pixels = uint8NDArray (); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
788 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
789 else |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
790 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
791 dim_vector d (4, octave_idx_type (bbox(2)), |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
792 octave_idx_type (bbox(3))); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
793 pixels = uint8NDArray (d, static_cast<uint8_t> (0)); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
794 xoffset = compute_line_xoffset (line_bbox.front ()); |
26187
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
795 line_yoffset = -bbox(1); |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
796 yoffset = 0; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
797 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
798 break; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
799 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
800 default: |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
801 error ("ft_text_renderer: invalid mode '%d'", mode); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
802 break; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
803 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
804 } |
26858
0adb232f93b9
Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26619
diff
changeset
|
805 bool is_opaque (const FT_GlyphSlot &glyph, const int x, const int y) |
0adb232f93b9
Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26619
diff
changeset
|
806 { |
0adb232f93b9
Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26619
diff
changeset
|
807 // Borrowed from https://stackoverflow.com/questions/14800827/ |
0adb232f93b9
Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26619
diff
changeset
|
808 // indexing-pixels-in-a-monochrome-freetype-glyph-buffer |
0adb232f93b9
Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26619
diff
changeset
|
809 int pitch = std::abs (glyph->bitmap.pitch); |
0adb232f93b9
Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26619
diff
changeset
|
810 unsigned char *row = &glyph->bitmap.buffer[pitch * y]; |
0adb232f93b9
Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26619
diff
changeset
|
811 char cvalue = row[x >> 3]; |
26995
ab5bfee22d18
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
26858
diff
changeset
|
812 |
26858
0adb232f93b9
Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26619
diff
changeset
|
813 return ((cvalue & (128 >> (x & 7))) != 0); |
0adb232f93b9
Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26619
diff
changeset
|
814 } |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
815 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
816 FT_UInt |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
817 ft_text_renderer::process_character (FT_ULong code, FT_UInt previous) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
818 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
819 FT_Face face = font.get_face (); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
820 FT_UInt glyph_index = 0; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
821 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
822 if (face) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
823 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
824 glyph_index = FT_Get_Char_Index (face, code); |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
825 |
25421
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
826 if (code != '\n' && code != '\t' |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
827 && (! glyph_index |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
828 || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT))) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
829 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
830 glyph_index = 0; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
831 warn_missing_glyph (code); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
832 } |
25421
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
833 else if ((code == '\n') || (code == '\t')) |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
834 { |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
835 glyph_index = FT_Get_Char_Index (face, ' '); |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
836 if (! glyph_index |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
837 || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT)) |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
838 { |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
839 glyph_index = 0; |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
840 warn_missing_glyph (' '); |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
841 } |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
842 else if (code == '\n') |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
843 push_new_line (); |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
844 else |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
845 { |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
846 // Advance to next multiple of 4 times the width of the "space" |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
847 // character. |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
848 int x_tab = 4 * (face->glyph->advance.x >> 6); |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
849 xoffset = (1 + std::floor (1. * xoffset / x_tab)) * x_tab; |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
850 } |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
851 } |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
852 else |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
853 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
854 switch (mode) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
855 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
856 case MODE_RENDER: |
26858
0adb232f93b9
Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26619
diff
changeset
|
857 if (FT_Render_Glyph (face->glyph, (m_antialias |
0adb232f93b9
Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26619
diff
changeset
|
858 ? FT_RENDER_MODE_NORMAL |
0adb232f93b9
Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26619
diff
changeset
|
859 : FT_RENDER_MODE_MONO))) |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
860 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
861 glyph_index = 0; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
862 warn_glyph_render (code); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
863 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
864 else |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
865 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
866 FT_Bitmap& bitmap = face->glyph->bitmap; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
867 int x0, y0; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
868 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
869 if (previous) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
870 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
871 FT_Vector delta; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
872 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
873 FT_Get_Kerning (face, previous, glyph_index, |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
874 FT_KERNING_DEFAULT, &delta); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
875 xoffset += (delta.x >> 6); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
876 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
877 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
878 x0 = xoffset + face->glyph->bitmap_left; |
26187
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
879 y0 = line_yoffset + yoffset + (face->glyph->bitmap_top - 1); |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
880 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
881 // 'w' seems to have a negative -1 |
25421
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
882 // face->glyph->bitmap_left, this is so we don't index out |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
883 // of bound, and assumes we've allocated the right amount of |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
884 // horizontal space in the bbox. |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
885 if (x0 < 0) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
886 x0 = 0; |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
887 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
888 for (int r = 0; static_cast<unsigned int> (r) < bitmap.rows; r++) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
889 for (int c = 0; static_cast<unsigned int> (c) < bitmap.width; c++) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
890 { |
26858
0adb232f93b9
Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26619
diff
changeset
|
891 unsigned char pix |
0adb232f93b9
Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26619
diff
changeset
|
892 = (m_antialias |
0adb232f93b9
Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26619
diff
changeset
|
893 ? bitmap.buffer[r*bitmap.width+c] |
0adb232f93b9
Implement axes and text "fontsmoothing" property (bug #55833).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26619
diff
changeset
|
894 : (is_opaque (face->glyph, c, r) ? 255 : 0)); |
26995
ab5bfee22d18
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
26858
diff
changeset
|
895 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
896 if (x0+c < 0 || x0+c >= pixels.dim2 () |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
897 || y0-r < 0 || y0-r >= pixels.dim3 ()) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
898 { |
26187
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
899 // ::warning ("ft_text_renderer: x %d, y %d", |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
900 // x0+c, y0-r); |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
901 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
902 else if (pixels(3, x0+c, y0-r).value () == 0) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
903 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
904 pixels(0, x0+c, y0-r) = color(0); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
905 pixels(1, x0+c, y0-r) = color(1); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
906 pixels(2, x0+c, y0-r) = color(2); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
907 pixels(3, x0+c, y0-r) = pix; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
908 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
909 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
910 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
911 xoffset += (face->glyph->advance.x >> 6); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
912 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
913 break; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
914 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
915 case MODE_BBOX: |
25421
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
916 Matrix& bb = line_bbox.back (); |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
917 |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
918 // If we have a previous glyph, use kerning information. This |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
919 // usually means moving a bit backward before adding the next |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
920 // glyph. That is, "delta.x" is usually < 0. |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
921 if (previous) |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
922 { |
25421
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
923 FT_Vector delta; |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
924 |
25421
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
925 FT_Get_Kerning (face, previous, glyph_index, |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
926 FT_KERNING_DEFAULT, &delta); |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
927 |
25421
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
928 xoffset += (delta.x >> 6); |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
929 } |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
930 |
25421
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
931 // Extend current X offset box by the width of the current |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
932 // glyph. Then extend the line bounding box if necessary. |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
933 |
25421
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
934 xoffset += (face->glyph->advance.x >> 6); |
c335f94766a7
Re-organize to avoid code duplication (bug #54083).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25420
diff
changeset
|
935 bb(2) = math::max (bb(2), xoffset); |
26187
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
936 |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
937 // Store the actual bbox vertical coordinates of this character |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
938 FT_Glyph glyph; |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
939 if (FT_Get_Glyph (face->glyph, &glyph)) |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
940 warn_glyph_render (code); |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
941 else |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
942 { |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
943 FT_BBox glyph_bbox; |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
944 FT_Glyph_Get_CBox (glyph, FT_GLYPH_BBOX_UNSCALED, |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
945 &glyph_bbox); |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
946 m_deltax = (glyph_bbox.xMax - face->glyph->advance.x) >> 6; |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
947 m_ymin = math::min ((glyph_bbox.yMin >> 6) + yoffset, |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
948 m_ymin); |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
949 m_ymax = math::max ((glyph_bbox.yMax >> 6) + yoffset, |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
950 m_ymax); |
26478
6f22d0c91beb
Fix memory leak with FT_Glyph objects (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26376
diff
changeset
|
951 FT_Done_Glyph (glyph); |
26187
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
952 update_line_bbox (); |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
953 } |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
954 break; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
955 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
956 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
957 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
958 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
959 return glyph_index; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
960 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
961 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
962 void |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
963 ft_text_renderer::text_to_strlist (const std::string& txt, |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
964 std::list<text_renderer::string>& lst, |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
965 Matrix& box, |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
966 int ha, int va, double rot, |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
967 const caseless_str& interp) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
968 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
969 uint8NDArray pxls; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
970 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
971 // First run text_to_pixels which will also build the string list |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
972 |
26573
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
973 m_strlist = std::list<text_renderer::string> (); |
26617
98afb8bbd1f6
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
26573
diff
changeset
|
974 |
28857
43ad651cf5a0
eliminate unnecessary uses of octave:: namespace qualifier
John W. Eaton <jwe@octave.org>
parents:
28823
diff
changeset
|
975 unwind_protect_var<bool> restore_var1 (m_do_strlist); |
43ad651cf5a0
eliminate unnecessary uses of octave:: namespace qualifier
John W. Eaton <jwe@octave.org>
parents:
28823
diff
changeset
|
976 unwind_protect_var<std::list<text_renderer::string>> |
28823
26cfccfee9a0
Replace unwind_protect with more efficient constructs (bug #59192).
Rik <rik@octave.org>
parents:
28483
diff
changeset
|
977 restore_var2 (m_strlist); |
28857
43ad651cf5a0
eliminate unnecessary uses of octave:: namespace qualifier
John W. Eaton <jwe@octave.org>
parents:
28823
diff
changeset
|
978 |
26573
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
979 m_do_strlist = true; |
26617
98afb8bbd1f6
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
26573
diff
changeset
|
980 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
981 text_to_pixels (txt, pxls, box, ha, va, rot, interp, false); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
982 |
26573
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
983 lst = m_strlist; |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
984 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
985 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
986 void |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
987 ft_text_renderer::visit (text_element_string& e) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
988 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
989 if (font.is_valid ()) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
990 { |
26187
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
991 m_max_fontsize = std::max (m_max_fontsize, font.get_size ()); |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
992 FT_UInt glyph_index, previous = 0; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
993 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
994 std::string str = e.string_value (); |
26187
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
995 const uint8_t *c = reinterpret_cast<const uint8_t *> (str.c_str ()); |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
996 uint32_t u32_c; |
26617
98afb8bbd1f6
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
26573
diff
changeset
|
997 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
998 std::size_t n = str.size (); |
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
999 std::size_t icurr = 0; |
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
1000 std::size_t ibegin = 0; |
26187
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
1001 |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
1002 // Initialize a new string |
24076
1b7e49a72c62
improve text rendering in svg printout (bug #48567)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23807
diff
changeset
|
1003 std::string fname = font.get_face ()->family_name; |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1004 text_renderer::string fs (str, font, xoffset, yoffset); |
24076
1b7e49a72c62
improve text rendering in svg printout (bug #48567)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23807
diff
changeset
|
1005 std::vector<double> xdata; |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1006 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1007 while (n > 0) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1008 { |
26187
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
1009 // Retrieve the length and the u32 representation of the current |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
1010 // character |
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
1011 int mblen = octave_u8_strmbtouc_wrapper (&u32_c, c + icurr); |
27142
8a07083c8cfc
Use replacement characters to display non UTF-8 strings in figures (bug #55974)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1012 if (mblen < 1) |
8a07083c8cfc
Use replacement characters to display non UTF-8 strings in figures (bug #55974)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1013 { |
8a07083c8cfc
Use replacement characters to display non UTF-8 strings in figures (bug #55974)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1014 // This is not an UTF-8 character, use a replacement character |
8a07083c8cfc
Use replacement characters to display non UTF-8 strings in figures (bug #55974)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1015 mblen = 1; |
8a07083c8cfc
Use replacement characters to display non UTF-8 strings in figures (bug #55974)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1016 u32_c = 0xFFFD; |
8a07083c8cfc
Use replacement characters to display non UTF-8 strings in figures (bug #55974)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1017 } |
27623
698c8b08fe8c
New function uisetfont (bug #57130).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27150
diff
changeset
|
1018 |
26187
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
1019 n -= mblen; |
26573
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1020 |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1021 if (m_do_strlist && mode == MODE_RENDER) |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1022 { |
26573
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1023 if (u32_c == 10) |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1024 { |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1025 // Finish previous string in m_strlist before processing |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1026 // the newline character |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1027 fs.set_y (line_yoffset + yoffset); |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1028 fs.set_color (color); |
26617
98afb8bbd1f6
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
26573
diff
changeset
|
1029 |
26573
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1030 std::string s = str.substr (ibegin, icurr - ibegin); |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1031 if (! s.empty ()) |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1032 { |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1033 fs.set_string (s); |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1034 fs.set_y (line_yoffset + yoffset); |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1035 fs.set_xdata (xdata); |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1036 fs.set_family (fname); |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1037 m_strlist.push_back (fs); |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1038 } |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1039 } |
26573
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1040 else |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1041 xdata.push_back (xoffset); |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1042 } |
25362
def1b446ba64
Convert strings to UTF-32 for FreeType (bug #53646).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25336
diff
changeset
|
1043 |
26187
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
1044 glyph_index = process_character (u32_c, previous); |
25362
def1b446ba64
Convert strings to UTF-32 for FreeType (bug #53646).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25336
diff
changeset
|
1045 |
26187
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
1046 if (u32_c == 10) |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1047 { |
25362
def1b446ba64
Convert strings to UTF-32 for FreeType (bug #53646).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25336
diff
changeset
|
1048 previous = 0; |
26617
98afb8bbd1f6
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
26573
diff
changeset
|
1049 |
26573
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1050 if (m_do_strlist && mode == MODE_RENDER) |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1051 { |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1052 // Start a new string in m_strlist |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1053 ibegin = icurr+1; |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1054 xdata.clear (); |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1055 fs = text_renderer::string (str.substr (ibegin), font, |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1056 line_xoffset, yoffset); |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1057 } |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1058 } |
25362
def1b446ba64
Convert strings to UTF-32 for FreeType (bug #53646).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25336
diff
changeset
|
1059 else |
def1b446ba64
Convert strings to UTF-32 for FreeType (bug #53646).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25336
diff
changeset
|
1060 previous = glyph_index; |
def1b446ba64
Convert strings to UTF-32 for FreeType (bug #53646).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25336
diff
changeset
|
1061 |
26187
8d4f23b7f4eb
Improve text extent calculation when using freetype text renderer (bug #55075)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26152
diff
changeset
|
1062 icurr += mblen; |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1063 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1064 |
26573
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1065 if (m_do_strlist && mode == MODE_RENDER && ! fs.get_string ().empty ()) |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1066 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1067 fs.set_y (line_yoffset + yoffset); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1068 fs.set_color (color); |
24076
1b7e49a72c62
improve text rendering in svg printout (bug #48567)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23807
diff
changeset
|
1069 fs.set_xdata (xdata); |
1b7e49a72c62
improve text rendering in svg printout (bug #48567)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23807
diff
changeset
|
1070 fs.set_family (fname); |
26573
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1071 m_strlist.push_back (fs); |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1072 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1073 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1074 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1075 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1076 void |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1077 ft_text_renderer::visit (text_element_list& e) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1078 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1079 // Save and restore (after processing the list) the current font and color. |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1080 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1081 ft_font saved_font (font); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1082 uint8NDArray saved_color (color); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1083 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1084 text_processor::visit (e); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1085 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1086 font = saved_font; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1087 color = saved_color; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1088 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1089 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1090 void |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1091 ft_text_renderer::visit (text_element_subscript& e) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1092 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1093 ft_font saved_font (font); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1094 int saved_line_yoffset = line_yoffset; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1095 int saved_yoffset = yoffset; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1096 |
28305
6e8d5c99263c
Produce better looking TeX superscript and subscripts (bug #58376).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
28206
diff
changeset
|
1097 double sz = font.get_size (); |
6e8d5c99263c
Produce better looking TeX superscript and subscripts (bug #58376).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
28206
diff
changeset
|
1098 |
6e8d5c99263c
Produce better looking TeX superscript and subscripts (bug #58376).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
28206
diff
changeset
|
1099 // Reducing font size by 70% produces decent results. |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1100 set_font (font.get_name (), font.get_weight (), font.get_angle (), |
28305
6e8d5c99263c
Produce better looking TeX superscript and subscripts (bug #58376).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
28206
diff
changeset
|
1101 std::max (5.0, sz * 0.7)); |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1102 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1103 if (font.is_valid ()) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1104 { |
28305
6e8d5c99263c
Produce better looking TeX superscript and subscripts (bug #58376).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
28206
diff
changeset
|
1105 // Shifting the baseline by 15% of the font size gives decent results. |
6e8d5c99263c
Produce better looking TeX superscript and subscripts (bug #58376).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
28206
diff
changeset
|
1106 yoffset -= std::ceil (sz * 0.15); |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1107 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1108 if (mode == MODE_BBOX) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1109 update_line_bbox (); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1110 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1111 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1112 text_processor::visit (e); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1113 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1114 font = saved_font; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1115 // If line_yoffset changed, this means we moved to a new line; hence yoffset |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1116 // cannot be restored, because the saved value is not relevant anymore. |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1117 if (line_yoffset == saved_line_yoffset) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1118 yoffset = saved_yoffset; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1119 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1120 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1121 void |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1122 ft_text_renderer::visit (text_element_superscript& e) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1123 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1124 ft_font saved_font (font); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1125 int saved_line_yoffset = line_yoffset; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1126 int saved_yoffset = yoffset; |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1127 |
28305
6e8d5c99263c
Produce better looking TeX superscript and subscripts (bug #58376).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
28206
diff
changeset
|
1128 double sz = font.get_size (); |
6e8d5c99263c
Produce better looking TeX superscript and subscripts (bug #58376).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
28206
diff
changeset
|
1129 |
6e8d5c99263c
Produce better looking TeX superscript and subscripts (bug #58376).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
28206
diff
changeset
|
1130 // Reducing font size by 70% produces decent results. |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1131 set_font (font.get_name (), font.get_weight (), font.get_angle (), |
28305
6e8d5c99263c
Produce better looking TeX superscript and subscripts (bug #58376).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
28206
diff
changeset
|
1132 std::max (5.0, sz * 0.7)); |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1133 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1134 if (saved_font.is_valid ()) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1135 { |
28305
6e8d5c99263c
Produce better looking TeX superscript and subscripts (bug #58376).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
28206
diff
changeset
|
1136 // Shifting the baseline by 40% of the font size gives decent results. |
6e8d5c99263c
Produce better looking TeX superscript and subscripts (bug #58376).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
28206
diff
changeset
|
1137 yoffset += std::ceil (sz * 0.4); |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1138 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1139 if (mode == MODE_BBOX) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1140 update_line_bbox (); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1141 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1142 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1143 text_processor::visit (e); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1144 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1145 font = saved_font; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1146 // If line_yoffset changed, this means we moved to a new line; hence yoffset |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1147 // cannot be restored, because the saved value is not relevant anymore. |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1148 if (line_yoffset == saved_line_yoffset) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1149 yoffset = saved_yoffset; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1150 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1151 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1152 void |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1153 ft_text_renderer::visit (text_element_color& e) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1154 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1155 if (mode == MODE_RENDER) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1156 set_color (e.get_color ()); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1157 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1158 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1159 void |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1160 ft_text_renderer::visit (text_element_fontsize& e) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1161 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1162 double sz = e.get_fontsize (); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1163 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1164 // FIXME: Matlab documentation says that the font size is expressed |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1165 // in the text object FontUnit. |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1166 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1167 set_font (font.get_name (), font.get_weight (), font.get_angle (), sz); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1168 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1169 if (mode == MODE_BBOX) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1170 update_line_bbox (); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1171 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1172 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1173 void |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1174 ft_text_renderer::visit (text_element_fontname& e) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1175 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1176 set_font (e.get_fontname (), font.get_weight (), font.get_angle (), |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1177 font.get_size ()); |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1178 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1179 if (mode == MODE_BBOX) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1180 update_line_bbox (); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1181 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1182 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1183 void |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1184 ft_text_renderer::visit (text_element_fontstyle& e) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1185 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1186 switch (e.get_fontstyle ()) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1187 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1188 case text_element_fontstyle::normal: |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1189 set_font (font.get_name (), "normal", "normal", font.get_size ()); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1190 break; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1191 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1192 case text_element_fontstyle::bold: |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1193 set_font (font.get_name (), "bold", "normal", font.get_size ()); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1194 break; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1195 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1196 case text_element_fontstyle::italic: |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1197 set_font (font.get_name (), "normal", "italic", font.get_size ()); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1198 break; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1199 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1200 case text_element_fontstyle::oblique: |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1201 set_font (font.get_name (), "normal", "oblique", font.get_size ()); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1202 break; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1203 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1204 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1205 if (mode == MODE_BBOX) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1206 update_line_bbox (); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1207 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1208 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1209 void |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1210 ft_text_renderer::visit (text_element_symbol& e) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1211 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1212 uint32_t code = e.get_symbol_code (); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1213 |
24076
1b7e49a72c62
improve text rendering in svg printout (bug #48567)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23807
diff
changeset
|
1214 std::vector<double> xdata (1, xoffset); |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
1215 text_renderer::string fs ("-", font, xoffset, yoffset); |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1216 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1217 if (code != text_element_symbol::invalid_code && font.is_valid ()) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1218 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1219 process_character (code); |
26573
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1220 if (m_do_strlist && mode == MODE_RENDER) |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1221 { |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1222 fs.set_code (code); |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1223 fs.set_xdata (xdata); |
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1224 } |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1225 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1226 else if (font.is_valid ()) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1227 ::warning ("ignoring unknown symbol: %d", e.get_symbol ()); |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1228 |
26573
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1229 if (m_do_strlist && mode == MODE_RENDER && fs.get_code ()) |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1230 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1231 fs.set_y (line_yoffset + yoffset); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1232 fs.set_color (color); |
24076
1b7e49a72c62
improve text rendering in svg printout (bug #48567)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23807
diff
changeset
|
1233 fs.set_family (font.get_face ()->family_name); |
26573
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1234 m_strlist.push_back (fs); |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1235 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1236 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1237 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1238 void |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1239 ft_text_renderer::visit (text_element_combined& e) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1240 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1241 int saved_xoffset = xoffset; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1242 int max_xoffset = xoffset; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1243 |
22862
e365e87371a3
maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
1244 for (auto *txt_elt : e) |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1245 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1246 xoffset = saved_xoffset; |
22862
e365e87371a3
maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
1247 txt_elt->accept (*this); |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
1248 max_xoffset = math::max (xoffset, max_xoffset); |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1249 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1250 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1251 xoffset = max_xoffset; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1252 } |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1253 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1254 void |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1255 ft_text_renderer::reset (void) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1256 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1257 set_mode (MODE_BBOX); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1258 set_color (Matrix (1, 3, 0.0)); |
26573
ad70a85f702b
Avoid accumulating data in text_renderer member variable (bug #55287)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26478
diff
changeset
|
1259 m_strlist = std::list<text_renderer::string> (); |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1260 } |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1261 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1262 void |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1263 ft_text_renderer::set_color (const Matrix& c) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1264 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1265 if (c.numel () == 3) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1266 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1267 color(0) = static_cast<uint8_t> (c(0)*255); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1268 color(1) = static_cast<uint8_t> (c(1)*255); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1269 color(2) = static_cast<uint8_t> (c(2)*255); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1270 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1271 else |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1272 ::warning ("ft_text_renderer::set_color: invalid color"); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1273 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1274 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1275 uint8NDArray |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1276 ft_text_renderer::render (text_element *elt, Matrix& box, int rotation) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1277 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1278 set_mode (MODE_BBOX); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1279 elt->accept (*this); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1280 compute_bbox (); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1281 box = bbox; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1282 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1283 set_mode (MODE_RENDER); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1284 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1285 if (pixels.numel () > 0) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1286 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1287 elt->accept (*this); |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1288 |
29470
2ae4764180c6
Initial implementation of a LaTeX interpreter (bug #59546).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
29359
diff
changeset
|
1289 rotate_pixels (pixels, rotation); |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1290 } |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1291 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1292 return pixels; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1293 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1294 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1295 // Note: |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1296 // x-extent accurately measures width of glyphs. |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1297 // y-extent is overly large because it is measured from baseline-to-baseline. |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1298 // Calling routines, such as ylabel, may need to account for this mismatch. |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1299 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1300 Matrix |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1301 ft_text_renderer::get_extent (text_element *elt, double rotation) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1302 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1303 set_mode (MODE_BBOX); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1304 elt->accept (*this); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1305 compute_bbox (); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1306 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1307 Matrix extent (1, 2, 0.0); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1308 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1309 switch (rotation_to_mode (rotation)) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1310 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1311 case ROTATION_0: |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1312 case ROTATION_180: |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1313 extent(0) = bbox(2); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1314 extent(1) = bbox(3); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1315 break; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1316 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1317 case ROTATION_90: |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1318 case ROTATION_270: |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1319 extent(0) = bbox(3); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1320 extent(1) = bbox(2); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1321 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1322 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1323 return extent; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1324 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1325 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1326 Matrix |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1327 ft_text_renderer::get_extent (const std::string& txt, double rotation, |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1328 const caseless_str& interpreter) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1329 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1330 text_element *elt = text_parser::parse (txt, interpreter); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1331 Matrix extent = get_extent (elt, rotation); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1332 delete elt; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1333 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1334 return extent; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1335 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1336 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1337 void |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1338 ft_text_renderer::text_to_pixels (const std::string& txt, |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1339 uint8NDArray& pxls, Matrix& box, |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1340 int _halign, int valign, double rotation, |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1341 const caseless_str& interpreter, |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1342 bool handle_rotation) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1343 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1344 int rot_mode = rotation_to_mode (rotation); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1345 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1346 halign = _halign; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1347 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1348 text_element *elt = text_parser::parse (txt, interpreter); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1349 pxls = render (elt, box, rot_mode); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1350 delete elt; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1351 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23462
diff
changeset
|
1352 if (pxls.isempty ()) |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1353 return; // nothing to render |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1354 |
29470
2ae4764180c6
Initial implementation of a LaTeX interpreter (bug #59546).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
29359
diff
changeset
|
1355 // Move X0 and Y0 depending on alignments and eventually swap all values |
2ae4764180c6
Initial implementation of a LaTeX interpreter (bug #59546).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
29359
diff
changeset
|
1356 // for text rotated 90° 180° or 270° |
2ae4764180c6
Initial implementation of a LaTeX interpreter (bug #59546).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
29359
diff
changeset
|
1357 fix_bbox_anchor (box, halign, valign, rot_mode, handle_rotation); |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1358 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1359 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1360 ft_text_renderer::ft_font::ft_font (const ft_font& ft) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23696
diff
changeset
|
1361 : text_renderer::font (ft), face (nullptr) |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1362 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1363 #if defined (HAVE_FT_REFERENCE_FACE) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1364 FT_Face ft_face = ft.get_face (); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1365 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1366 if (ft_face && FT_Reference_Face (ft_face) == 0) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1367 face = ft_face; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1368 #endif |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1369 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1370 |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1371 ft_text_renderer::ft_font& |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1372 ft_text_renderer::ft_font::operator = (const ft_font& ft) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1373 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1374 if (&ft != this) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1375 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1376 text_renderer::font::operator = (ft); |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
1377 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1378 if (face) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1379 { |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1380 FT_Done_Face (face); |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23696
diff
changeset
|
1381 face = nullptr; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1382 } |
17330
219552139c18
Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17327
diff
changeset
|
1383 |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1384 #if defined (HAVE_FT_REFERENCE_FACE) |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1385 FT_Face ft_face = ft.get_face (); |
17330
219552139c18
Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17327
diff
changeset
|
1386 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1387 if (ft_face && FT_Reference_Face (ft_face) == 0) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1388 face = ft_face; |
17330
219552139c18
Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17327
diff
changeset
|
1389 #endif |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1390 } |
17330
219552139c18
Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17327
diff
changeset
|
1391 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1392 return *this; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1393 } |
17330
219552139c18
Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17327
diff
changeset
|
1394 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1395 FT_Face |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1396 ft_text_renderer::ft_font::get_face (void) const |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1397 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1398 if (! face && ! name.empty ()) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1399 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1400 face = ft_manager::get_font (name, weight, angle, size); |
17330
219552139c18
Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17327
diff
changeset
|
1401 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1402 if (face) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1403 { |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1404 if (FT_Set_Char_Size (face, 0, size*64, 0, 0)) |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1405 ::warning ("ft_text_renderer: unable to set font size to %g", size); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1406 } |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1407 else |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1408 ::warning ("ft_text_renderer: unable to load appropriate font"); |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1409 } |
17330
219552139c18
Allow to compile with older freetype on RHEL5 (bug #39823).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17327
diff
changeset
|
1410 |
22331
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1411 return face; |
b81b08cc4c83
maint: Indent namespaces in more files.
John W. Eaton <jwe@octave.org>
parents:
22326
diff
changeset
|
1412 } |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1413 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1414 |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20715
diff
changeset
|
1415 #endif |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1416 |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1417 namespace octave |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1418 { |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1419 base_text_renderer * |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1420 make_ft_text_renderer (void) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1421 { |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1422 #if defined (HAVE_FREETYPE) |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1423 return new ft_text_renderer (); |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1424 #else |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1425 return 0; |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1426 #endif |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1427 } |
21209
67d2965af0b5
revamp text rendering classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1428 } |