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