Mercurial > octave
annotate libinterp/corefcn/txt-eng-ft.cc @ 17270:ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
* libinterp/corefcn/txt-eng-ft.cc (ft_face_destroyed): New static function.
(ft_manager::font_destroyed): New static method.
(ft_manager::do_font_destroyed): New method.
(ft_manager::ft_key, ft_manager::ft_cache): New typedef's.
(ft_manager::cache): New member, storing weak references to loaded fonts.
(ft_manager::do_get_font): Look for font into the cache. Use fontconfig and
freetype if not found. Insert newly loaded fonts into the cache. Install
finalizer to update the cache on font destruction.
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Sun, 18 Aug 2013 16:36:41 -0400 |
parents | 5b088598df1d |
children | cb7233cfbf43 |
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 |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14003
diff
changeset
|
3 Copyright (C) 2009-2012 Michael Goffioul |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
4 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
5 This file is part of Octave. |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
6 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
7 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
|
8 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
|
9 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
|
10 option) any later version. |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
11 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
12 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
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
14 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
|
15 for more details. |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
16 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
17 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
|
18 along with Octave; see the file COPYING. If not, see |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
19 <http://www.gnu.org/licenses/>. |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
20 |
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 #ifdef HAVE_CONFIG_H |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
24 #include <config.h> |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
25 #endif |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
26 |
14003
1555c5a177c9
better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents:
13999
diff
changeset
|
27 #if defined (HAVE_FREETYPE) |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
28 |
14003
1555c5a177c9
better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents:
13999
diff
changeset
|
29 #if defined (HAVE_FONTCONFIG) |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
30 #include <fontconfig/fontconfig.h> |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
31 #endif |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
32 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
33 #include <iostream> |
17270
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
34 #include <map> |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
35 #include <utility> |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
36 |
13992
e1f76bfe0452
apply singleton_cleanup to a few more classes
John W. Eaton <jwe@octave.org>
parents:
13730
diff
changeset
|
37 #include "singleton-cleanup.h" |
e1f76bfe0452
apply singleton_cleanup to a few more classes
John W. Eaton <jwe@octave.org>
parents:
13730
diff
changeset
|
38 |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
39 #include "error.h" |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
40 #include "pr-output.h" |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
41 #include "txt-eng-ft.h" |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
42 |
13317
d2b799e3178a
allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
43 // FIXME -- maybe issue at most one warning per glyph/font/size/weight |
d2b799e3178a
allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
44 // combination. |
d2b799e3178a
allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
45 |
d2b799e3178a
allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
46 static void |
d2b799e3178a
allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
47 gripe_missing_glyph (char c) |
d2b799e3178a
allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
48 { |
d2b799e3178a
allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
49 warning_with_id ("Octave:missing-glyph", |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
50 "ft_render: skipping missing glyph for character '%c'", |
13317
d2b799e3178a
allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
51 c); |
d2b799e3178a
allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
52 } |
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 |
d2b799e3178a
allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
55 gripe_glyph_render (char c) |
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:glyph-render", |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
58 "ft_render: unable to render glyph for character '%c'", |
13317
d2b799e3178a
allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
59 c); |
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 |
13730
a2c74b5c02de
[MSVC] Prevent duplicate symbol.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13317
diff
changeset
|
62 #ifdef _MSC_VER |
a2c74b5c02de
[MSVC] Prevent duplicate symbol.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13317
diff
changeset
|
63 // This is just a trick to avoid multiply symbols definition. |
a2c74b5c02de
[MSVC] Prevent duplicate symbol.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13317
diff
changeset
|
64 // PermMatrix.h contains a dllexport'ed Array<octave_idx_type> |
a2c74b5c02de
[MSVC] Prevent duplicate symbol.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13317
diff
changeset
|
65 // that will make MSVC not to generate new instantiation and |
a2c74b5c02de
[MSVC] Prevent duplicate symbol.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13317
diff
changeset
|
66 // use the imported one. |
a2c74b5c02de
[MSVC] Prevent duplicate symbol.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13317
diff
changeset
|
67 #include "PermMatrix.h" |
a2c74b5c02de
[MSVC] Prevent duplicate symbol.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13317
diff
changeset
|
68 #endif |
a2c74b5c02de
[MSVC] Prevent duplicate symbol.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13317
diff
changeset
|
69 |
17270
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
70 // Forward declaration |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
71 static void ft_face_destroyed (void* object); |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
72 |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
73 class |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
74 ft_manager |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
75 { |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
76 public: |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
77 static bool instance_ok (void) |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
78 { |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
79 bool retval = true; |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
80 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
81 if (! instance) |
13992
e1f76bfe0452
apply singleton_cleanup to a few more classes
John W. Eaton <jwe@octave.org>
parents:
13730
diff
changeset
|
82 { |
e1f76bfe0452
apply singleton_cleanup to a few more classes
John W. Eaton <jwe@octave.org>
parents:
13730
diff
changeset
|
83 instance = new ft_manager (); |
e1f76bfe0452
apply singleton_cleanup to a few more classes
John W. Eaton <jwe@octave.org>
parents:
13730
diff
changeset
|
84 |
e1f76bfe0452
apply singleton_cleanup to a few more classes
John W. Eaton <jwe@octave.org>
parents:
13730
diff
changeset
|
85 if (instance) |
e1f76bfe0452
apply singleton_cleanup to a few more classes
John W. Eaton <jwe@octave.org>
parents:
13730
diff
changeset
|
86 singleton_cleanup_list::add (cleanup_instance); |
e1f76bfe0452
apply singleton_cleanup to a few more classes
John W. Eaton <jwe@octave.org>
parents:
13730
diff
changeset
|
87 } |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
88 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
89 if (! instance) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
90 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
91 ::error ("unable to create ft_manager!"); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
92 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
93 retval = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
94 } |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
95 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
96 return retval; |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
97 } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
98 |
13992
e1f76bfe0452
apply singleton_cleanup to a few more classes
John W. Eaton <jwe@octave.org>
parents:
13730
diff
changeset
|
99 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
|
100 |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
101 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
|
102 const std::string& angle, double size) |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
103 { return (instance_ok () |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
104 ? instance->do_get_font (name, weight, angle, size) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
105 : 0); } |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
106 |
17270
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
107 static void font_destroyed (FT_Face face) |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
108 { |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
109 if (instance_ok ()) |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
110 instance->do_font_destroyed (face); |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
111 } |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
112 |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
113 private: |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
114 |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
115 static ft_manager *instance; |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
116 |
17270
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
117 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
|
118 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
|
119 |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
120 // Cache the fonts loaded by freetype. This cache only contains |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
121 // weak references to the fonts, strong references are only present |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
122 // in class ft_render. |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
123 ft_cache cache; |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
124 |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
125 private: |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
126 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
127 // No copying! |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
128 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
129 ft_manager (const ft_manager&); |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
130 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
131 ft_manager& operator = (const ft_manager&); |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
132 |
14003
1555c5a177c9
better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents:
13999
diff
changeset
|
133 ft_manager (void) |
1555c5a177c9
better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents:
13999
diff
changeset
|
134 : library (), freetype_initialized (false), fontconfig_initialized (false) |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
135 { |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
136 if (FT_Init_FreeType (&library)) |
14003
1555c5a177c9
better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents:
13999
diff
changeset
|
137 ::error ("unable to initialize freetype library"); |
1555c5a177c9
better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents:
13999
diff
changeset
|
138 else |
1555c5a177c9
better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents:
13999
diff
changeset
|
139 freetype_initialized = true; |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
140 |
14003
1555c5a177c9
better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents:
13999
diff
changeset
|
141 #if defined (HAVE_FONTCONFIG) |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
142 if (! FcInit ()) |
14003
1555c5a177c9
better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents:
13999
diff
changeset
|
143 ::error ("unable to initialize fontconfig library"); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
144 else |
14003
1555c5a177c9
better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents:
13999
diff
changeset
|
145 fontconfig_initialized = true; |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
146 #endif |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
147 } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
148 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
149 ~ft_manager (void) |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
150 { |
14003
1555c5a177c9
better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents:
13999
diff
changeset
|
151 if (freetype_initialized) |
1555c5a177c9
better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents:
13999
diff
changeset
|
152 FT_Done_FreeType (library); |
1555c5a177c9
better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents:
13999
diff
changeset
|
153 |
1555c5a177c9
better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents:
13999
diff
changeset
|
154 #if defined (HAVE_FONTCONFIG) |
1555c5a177c9
better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents:
13999
diff
changeset
|
155 // FIXME -- Skip the call to FcFini because it can trigger the |
1555c5a177c9
better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents:
13999
diff
changeset
|
156 // assertion |
1555c5a177c9
better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents:
13999
diff
changeset
|
157 // |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
158 // octave: fccache.c:507: FcCacheFini: Assertion 'fcCacheChains[i] == ((void *)0)' failed. |
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 (fontconfig_initialized) |
1555c5a177c9
better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents:
13999
diff
changeset
|
161 // FcFini (); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
162 #endif |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
163 } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
164 |
14003
1555c5a177c9
better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents:
13999
diff
changeset
|
165 |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
166 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
|
167 const std::string& angle, double size) |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
168 { |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
169 FT_Face retval = 0; |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
170 |
17270
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
171 // Look first into the font cache, then use fontconfig. If the font |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
172 // is present in the cache, simply add a reference and return it. |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
173 |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
174 ft_key key (name + ":" + weight + ":" + angle, size); |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
175 ft_cache::const_iterator it = cache.find (key); |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
176 |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
177 if (it != cache.end ()) |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
178 { |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
179 FT_Reference_Face (it->second); |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
180 return it->second; |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
181 } |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
182 |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
183 std::string file; |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
184 |
14003
1555c5a177c9
better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents:
13999
diff
changeset
|
185 #if defined (HAVE_FONTCONFIG) |
1555c5a177c9
better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents:
13999
diff
changeset
|
186 if (fontconfig_initialized) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
187 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
188 int fc_weight, fc_angle; |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
189 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
190 if (weight == "bold") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
191 fc_weight = FC_WEIGHT_BOLD; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
192 else if (weight == "light") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
193 fc_weight = FC_WEIGHT_LIGHT; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
194 else if (weight == "demi") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
195 fc_weight = FC_WEIGHT_DEMIBOLD; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
196 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
197 fc_weight = FC_WEIGHT_NORMAL; |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
198 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
199 if (angle == "italic") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
200 fc_angle = FC_SLANT_ITALIC; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
201 else if (angle == "oblique") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
202 fc_angle = FC_SLANT_OBLIQUE; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
203 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
204 fc_angle = FC_SLANT_ROMAN; |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
205 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
206 FcPattern *pat = FcPatternCreate (); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
207 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
208 FcPatternAddString (pat, FC_FAMILY, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
209 (reinterpret_cast<const FcChar8*> |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
210 (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
|
211 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
212 FcPatternAddInteger (pat, FC_WEIGHT, fc_weight); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
213 FcPatternAddInteger (pat, FC_SLANT, fc_angle); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
214 FcPatternAddDouble (pat, FC_PIXEL_SIZE, size); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
215 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
216 if (FcConfigSubstitute (0, pat, FcMatchPattern)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
217 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
218 FcResult res; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
219 FcPattern *match; |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
220 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
221 FcDefaultSubstitute (pat); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
222 match = FcFontMatch (0, pat, &res); |
9833 | 223 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
224 // FIXME -- originally, this test also required that |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
225 // res != FcResultNoMatch. Is that really needed? |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
226 if (match) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
227 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
228 unsigned char *tmp; |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
229 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
230 FcPatternGetString (match, FC_FILE, 0, &tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
231 file = reinterpret_cast<char*> (tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
232 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
233 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
234 ::warning ("could not match any font: %s-%s-%s-%g", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
235 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
|
236 size); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
237 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
238 if (match) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
239 FcPatternDestroy (match); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
240 } |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
241 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
242 FcPatternDestroy (pat); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
243 } |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
244 #endif |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
245 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
246 if (file.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
247 { |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
248 #ifdef __WIN32__ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
249 file = "C:/WINDOWS/Fonts/verdana.ttf"; |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
250 #else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
251 // FIXME: find a "standard" font for UNIX platforms |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
252 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
253 } |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
254 |
17270
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
255 if (! file.empty ()) |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
256 { |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
257 if (FT_New_Face (library, file.c_str (), 0, &retval)) |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
258 ::warning ("ft_manager: unable to load font: %s", file.c_str ()); |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
259 else |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
260 { |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
261 // Install a finalizer to notify ft_manager that the font is |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
262 // being destroyed. The class ft_manager only keeps weak |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
263 // references to font objects. |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
264 |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
265 retval->generic.data = new ft_key (key); |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
266 retval->generic.finalizer = ft_face_destroyed; |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
267 |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
268 // Insert loaded font into the cache. |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
269 |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
270 cache[key] = retval; |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
271 } |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
272 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
273 |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
274 return retval; |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
275 } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
276 |
17270
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
277 void do_font_destroyed (FT_Face face) |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
278 { |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
279 if (face->generic.data) |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
280 { |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
281 ft_key* pkey = |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
282 reinterpret_cast<ft_key*> (face->generic.data); |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
283 |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
284 cache.erase (*pkey); |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
285 delete pkey; |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
286 face->generic.data = 0; |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
287 } |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
288 } |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
289 |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
290 private: |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
291 FT_Library library; |
14003
1555c5a177c9
better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents:
13999
diff
changeset
|
292 bool freetype_initialized; |
1555c5a177c9
better fix for fontconfig segfault
John W. Eaton <jwe@octave.org>
parents:
13999
diff
changeset
|
293 bool fontconfig_initialized; |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
294 }; |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
295 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
296 ft_manager* ft_manager::instance = 0; |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
297 |
17270
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
298 static void |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
299 ft_face_destroyed (void* object) |
ba865ea9c7e9
Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
300 { 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
|
301 |
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 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
304 ft_render::ft_render (void) |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
305 : text_processor (), face (0), bbox (1, 4, 0.0), |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12969
diff
changeset
|
306 xoffset (0), yoffset (0), multiline_halign (0), |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
307 multiline_align_xoffsets (), mode (MODE_BBOX), |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
308 red (0), green (0), blue (0) |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
309 { |
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 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
312 ft_render::~ft_render (void) |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
313 { |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
314 if (face) |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
315 FT_Done_Face (face); |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
316 } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
317 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
318 void |
11455
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
319 ft_render::set_font (const std::string& name, const std::string& weight, |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
320 const std::string& angle, double size) |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
321 { |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
322 if (face) |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
323 FT_Done_Face (face); |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
324 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
325 // FIXME: take "fontunits" into account |
11455
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
326 face = ft_manager::get_font (name, weight, angle, size); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
327 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
328 if (face) |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
329 { |
11455
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
330 if (FT_Set_Char_Size (face, 0, size*64, 0, 0)) |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
331 ::warning ("ft_render: unable to set font size to %d", size); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
332 } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
333 else |
9616
2093499ec9f4
avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents:
9406
diff
changeset
|
334 ::warning ("ft_render: unable to load appropriate font"); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
335 } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
336 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
337 void |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
338 ft_render::set_mode (int m) |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
339 { |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
340 mode = m; |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
341 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
342 switch (mode) |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
343 { |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
344 case MODE_BBOX: |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
345 xoffset = yoffset = 0; |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
346 bbox = Matrix (1, 4, 0.0); |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
347 break; |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
348 case MODE_RENDER: |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
349 if (bbox.numel () != 4) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
350 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
351 ::warning ("ft_render: invalid bounding box, cannot render"); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
352 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
353 xoffset = yoffset = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
354 pixels = uint8NDArray (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
355 } |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
356 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
357 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
358 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
|
359 static_cast<uint8_t> (0)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
360 xoffset = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
361 yoffset = -bbox(1)-1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
362 } |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
363 break; |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
364 default: |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
365 ::error ("ft_render: invalid mode '%d'", mode); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
366 break; |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
367 } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
368 } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
369 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
370 void |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
371 ft_render::visit (text_element_string& e) |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
372 { |
9616
2093499ec9f4
avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents:
9406
diff
changeset
|
373 if (face) |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
374 { |
12969
6fc2c61660f2
Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents:
12965
diff
changeset
|
375 int line_index = 0; |
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
|
376 FT_UInt box_line_width = 0; |
9616
2093499ec9f4
avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents:
9406
diff
changeset
|
377 std::string str = e.string_value (); |
2093499ec9f4
avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents:
9406
diff
changeset
|
378 FT_UInt glyph_index, previous = 0; |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
379 |
12969
6fc2c61660f2
Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents:
12965
diff
changeset
|
380 if (mode == MODE_BBOX) |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
381 multiline_align_xoffsets.clear (); |
12969
6fc2c61660f2
Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents:
12965
diff
changeset
|
382 else if (mode == MODE_RENDER) |
6fc2c61660f2
Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents:
12965
diff
changeset
|
383 xoffset += multiline_align_xoffsets[line_index]; |
6fc2c61660f2
Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents:
12965
diff
changeset
|
384 |
10553 | 385 for (size_t i = 0; i < str.length (); i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
386 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
387 glyph_index = FT_Get_Char_Index (face, str[i]); |
9616
2093499ec9f4
avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents:
9406
diff
changeset
|
388 |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12969
diff
changeset
|
389 if (str[i] != '\n' |
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
|
390 && (! glyph_index |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
391 || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT))) |
13317
d2b799e3178a
allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
392 gripe_missing_glyph (str[i]); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
393 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
394 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
395 switch (mode) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
396 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
397 case MODE_RENDER: |
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
|
398 if (str[i] == '\n') |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
399 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
400 glyph_index = FT_Get_Char_Index (face, ' '); |
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
|
401 if (!glyph_index || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT)) |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
402 { |
13317
d2b799e3178a
allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
403 gripe_missing_glyph (' '); |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12969
diff
changeset
|
404 } |
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12969
diff
changeset
|
405 else |
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
|
406 { |
12969
6fc2c61660f2
Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents:
12965
diff
changeset
|
407 line_index++; |
6fc2c61660f2
Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents:
12965
diff
changeset
|
408 xoffset = multiline_align_xoffsets[line_index]; |
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
|
409 yoffset -= (face->size->metrics.height >> 6); |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
410 } |
13317
d2b799e3178a
allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
411 } |
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
|
412 else if (FT_Render_Glyph (face->glyph, FT_RENDER_MODE_NORMAL)) |
13317
d2b799e3178a
allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
413 { |
d2b799e3178a
allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
414 gripe_glyph_render (str[i]); |
d2b799e3178a
allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
415 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
416 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
417 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
418 FT_Bitmap& bitmap = face->glyph->bitmap; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
419 int x0, y0; |
9616
2093499ec9f4
avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents:
9406
diff
changeset
|
420 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
421 if (previous) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
422 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
423 FT_Vector delta; |
9616
2093499ec9f4
avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents:
9406
diff
changeset
|
424 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
425 FT_Get_Kerning (face, previous, glyph_index, FT_KERNING_DEFAULT, &delta); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
426 xoffset += (delta.x >> 6); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
427 } |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
428 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
429 x0 = xoffset+face->glyph->bitmap_left; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
430 y0 = yoffset+face->glyph->bitmap_top; |
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
|
431 |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
432 // 'w' seems to have a negative -1 |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
433 // face->glyph->bitmap_left, this is so we don't |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
434 // index out of bound, and assumes we we allocated |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
435 // the right amount of horizontal space in the bbox. |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
436 if (x0 < 0) |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
437 x0 = 0; |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
438 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
439 for (int r = 0; r < bitmap.rows; r++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
440 for (int c = 0; c < bitmap.width; c++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
441 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
442 unsigned char pix = bitmap.buffer[r*bitmap.width+c]; |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
443 if (x0+c < 0 || x0+c >= pixels.dim2 () |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
444 || y0-r < 0 || y0-r >= pixels.dim3 ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
445 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
446 //::error ("out-of-bound indexing!!"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
447 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
448 else if (pixels(3, x0+c, y0-r).value () == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
449 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
450 pixels(0, x0+c, y0-r) = red; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
451 pixels(1, x0+c, y0-r) = green; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
452 pixels(2, x0+c, y0-r) = blue; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
453 pixels(3, x0+c, y0-r) = pix; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
454 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
455 } |
9616
2093499ec9f4
avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents:
9406
diff
changeset
|
456 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
457 xoffset += (face->glyph->advance.x >> 6); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
458 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
459 break; |
9616
2093499ec9f4
avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents:
9406
diff
changeset
|
460 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
461 case MODE_BBOX: |
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
|
462 if (str[i] == '\n') |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
463 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
464 glyph_index = FT_Get_Char_Index (face, ' '); |
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
|
465 if (! glyph_index |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
466 || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT)) |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
467 { |
13317
d2b799e3178a
allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
468 gripe_missing_glyph (' '); |
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
|
469 } |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
470 else |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
471 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
472 multiline_align_xoffsets.push_back (box_line_width); |
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
|
473 // Reset the pixel width for this newline, so we don't |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
474 // allocate a bounding box larger than the horizontal |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
475 // width of the multi-line |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12969
diff
changeset
|
476 box_line_width = 0; |
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
|
477 bbox(1) -= (face->size->metrics.height >> 6); |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
478 } |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12969
diff
changeset
|
479 } |
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12969
diff
changeset
|
480 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
481 { |
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
|
482 // width |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
483 if (previous) |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
484 { |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
485 FT_Vector delta; |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
486 |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
487 FT_Get_Kerning (face, previous, glyph_index, |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
488 FT_KERNING_DEFAULT, &delta); |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
489 |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
490 box_line_width += (delta.x >> 6); |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
491 } |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
492 |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
493 box_line_width += (face->glyph->advance.x >> 6); |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
494 |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
495 int asc, desc; |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
496 |
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
|
497 if (false /*tight*/) |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
498 { |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
499 desc = face->glyph->metrics.horiBearingY - face->glyph->metrics.height; |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
500 asc = face->glyph->metrics.horiBearingY; |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
501 } |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
502 else |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
503 { |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
504 asc = face->size->metrics.ascender; |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
505 desc = face->size->metrics.descender; |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
506 } |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
507 |
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
|
508 asc = yoffset + (asc >> 6); |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
509 desc = yoffset + (desc >> 6); |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
510 |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
511 if (desc < bbox(1)) |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
512 { |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
513 bbox(3) += (bbox(1) - desc); |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
514 bbox(1) = desc; |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
515 } |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
516 if (asc > (bbox(3)+bbox(1))) |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
517 bbox(3) = asc-bbox(1); |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
518 if (bbox(2) < box_line_width) |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
519 bbox(2) = box_line_width; |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
520 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
521 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
522 } |
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
|
523 if (str[i] == '\n') |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
524 previous = 0; |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
525 else |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
526 previous = glyph_index; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
527 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
528 } |
12969
6fc2c61660f2
Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents:
12965
diff
changeset
|
529 if (mode == MODE_BBOX) |
6fc2c61660f2
Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents:
12965
diff
changeset
|
530 { |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12969
diff
changeset
|
531 /* Push last the width associated with the last line */ |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
532 multiline_align_xoffsets.push_back (box_line_width); |
12969
6fc2c61660f2
Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents:
12965
diff
changeset
|
533 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
534 for (unsigned int i = 0; i < multiline_align_xoffsets.size (); i++) |
12969
6fc2c61660f2
Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents:
12965
diff
changeset
|
535 { |
6fc2c61660f2
Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents:
12965
diff
changeset
|
536 /* Center align */ |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12969
diff
changeset
|
537 if (multiline_halign == 1) |
12969
6fc2c61660f2
Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents:
12965
diff
changeset
|
538 multiline_align_xoffsets[i] = (bbox(2) - multiline_align_xoffsets[i])/2; |
6fc2c61660f2
Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents:
12965
diff
changeset
|
539 /* Right align */ |
6fc2c61660f2
Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents:
12965
diff
changeset
|
540 else if (multiline_halign == 2) |
6fc2c61660f2
Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents:
12965
diff
changeset
|
541 multiline_align_xoffsets[i] = (bbox(2) - multiline_align_xoffsets[i]); |
6fc2c61660f2
Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents:
12965
diff
changeset
|
542 /* Left align */ |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12969
diff
changeset
|
543 else |
12969
6fc2c61660f2
Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents:
12965
diff
changeset
|
544 multiline_align_xoffsets[i] = 0; |
6fc2c61660f2
Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents:
12965
diff
changeset
|
545 } |
6fc2c61660f2
Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents:
12965
diff
changeset
|
546 } |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
547 } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
548 } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
549 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
550 void |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
551 ft_render::reset (void) |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
552 { |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
553 set_mode (MODE_BBOX); |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
554 set_color (Matrix (1, 3, 0.0)); |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
555 } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
556 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
557 void |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
558 ft_render::set_color (Matrix c) |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
559 { |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
560 if (c.numel () == 3) |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
561 { |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
562 red = static_cast<uint8_t> (c(0)*255); |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
563 green = static_cast<uint8_t> (c(1)*255); |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
564 blue = static_cast<uint8_t> (c(2)*255); |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
565 } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
566 else |
9616
2093499ec9f4
avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents:
9406
diff
changeset
|
567 ::warning ("ft_render::set_color: invalid color"); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
568 } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
569 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
570 uint8NDArray |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
571 ft_render::render (text_element* elt, Matrix& box, int rotation) |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
572 { |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
573 set_mode (MODE_BBOX); |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
574 elt->accept (*this); |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
575 box = bbox; |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
576 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
577 set_mode (MODE_RENDER); |
9406
c0c23dbbade7
Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
9405
diff
changeset
|
578 if (pixels.numel () > 0) |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
579 { |
9406
c0c23dbbade7
Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
9405
diff
changeset
|
580 elt->accept (*this); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
581 |
9406
c0c23dbbade7
Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
9405
diff
changeset
|
582 switch (rotation) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
583 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
584 case ROTATION_0: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
585 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
586 case ROTATION_90: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
587 { |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
588 Array<octave_idx_type> perm (dim_vector (3, 1)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
589 perm(0) = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
590 perm(1) = 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
591 perm(2) = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
592 pixels = pixels.permute (perm); |
9406
c0c23dbbade7
Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
9405
diff
changeset
|
593 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
594 Array<idx_vector> idx (dim_vector (3, 1)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
595 idx(0) = idx_vector (':'); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
596 idx(1) = idx_vector (pixels.dim2 ()-1, -1, -1); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
597 idx(2) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
598 pixels = uint8NDArray (pixels.index (idx)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
599 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
600 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
601 case ROTATION_180: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
602 { |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
603 Array<idx_vector> idx (dim_vector (3, 1)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
604 idx(0) = idx_vector (':'); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
605 idx(1) = idx_vector (pixels.dim2 ()-1, -1, -1); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
606 idx(2)= idx_vector (pixels.dim3 ()-1, -1, -1); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
607 pixels = uint8NDArray (pixels.index (idx)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
608 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
609 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
610 case ROTATION_270: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
611 { |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
612 Array<octave_idx_type> perm (dim_vector (3, 1)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
613 perm(0) = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
614 perm(1) = 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
615 perm(2) = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
616 pixels = pixels.permute (perm); |
9406
c0c23dbbade7
Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
9405
diff
changeset
|
617 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
618 Array<idx_vector> idx (dim_vector (3, 1)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
619 idx(0) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
620 idx(1) = idx_vector (':'); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
621 idx(2) = idx_vector (pixels.dim3 ()-1, -1, -1); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
622 pixels = uint8NDArray (pixels.index (idx)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
623 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
624 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
625 } |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
626 } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
627 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
628 return pixels; |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
629 } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
630 |
16201
2338a92e9782
Fix spacing between ylabel and y-axis (bug #38461)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
631 // Note: |
2338a92e9782
Fix spacing between ylabel and y-axis (bug #38461)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
632 // 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
|
633 // 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
|
634 // 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
|
635 |
10402
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
636 Matrix |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
637 ft_render::get_extent (text_element *elt, double rotation) |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
638 { |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
639 set_mode (MODE_BBOX); |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
640 elt->accept (*this); |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
641 |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
642 Matrix extent (1, 2, 0.0); |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
643 |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
644 switch (rotation_to_mode (rotation)) |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
645 { |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
646 case ROTATION_0: |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
647 case ROTATION_180: |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
648 extent(0) = bbox(2); |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
649 extent(1) = bbox(3); |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
650 break; |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
651 case ROTATION_90: |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
652 case ROTATION_270: |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
653 extent(0) = bbox(3); |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
654 extent(1) = bbox(2); |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
655 } |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
656 |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
657 return extent; |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
658 } |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
659 |
12334
63dc132a1000
Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents:
12225
diff
changeset
|
660 Matrix |
17269
5b088598df1d
Add simple TeX parser based on flex/bison.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16892
diff
changeset
|
661 ft_render::get_extent (const std::string& txt, double rotation, |
5b088598df1d
Add simple TeX parser based on flex/bison.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16892
diff
changeset
|
662 const caseless_str& interpreter) |
12334
63dc132a1000
Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents:
12225
diff
changeset
|
663 { |
17269
5b088598df1d
Add simple TeX parser based on flex/bison.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16892
diff
changeset
|
664 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
|
665 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
|
666 delete elt; |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12969
diff
changeset
|
667 |
12334
63dc132a1000
Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents:
12225
diff
changeset
|
668 return extent; |
63dc132a1000
Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents:
12225
diff
changeset
|
669 } |
63dc132a1000
Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents:
12225
diff
changeset
|
670 |
10402
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
671 int |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
672 ft_render::rotation_to_mode (double rotation) const |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
673 { |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
674 if (rotation == 0.0) |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
675 return ROTATION_0; |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
676 else if (rotation == 90.0) |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
677 return ROTATION_90; |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
678 else if (rotation == 180.0) |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
679 return ROTATION_180; |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
680 else if (rotation == 270.0) |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
681 return ROTATION_270; |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
682 else |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
683 return ROTATION_0; |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
684 } |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
685 |
11455
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
686 void |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
687 ft_render::text_to_pixels (const std::string& txt, |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
688 uint8NDArray& pixels_, Matrix& box, |
17269
5b088598df1d
Add simple TeX parser based on flex/bison.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16892
diff
changeset
|
689 int halign, int valign, double rotation, |
5b088598df1d
Add simple TeX parser based on flex/bison.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16892
diff
changeset
|
690 const caseless_str& interpreter) |
11455
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
691 { |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
692 // FIXME: clip "rotation" between 0 and 360 |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
693 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
|
694 |
12969
6fc2c61660f2
Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents:
12965
diff
changeset
|
695 multiline_halign = halign; |
11455
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
696 |
17269
5b088598df1d
Add simple TeX parser based on flex/bison.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16892
diff
changeset
|
697 text_element *elt = text_parser::parse (txt, interpreter); |
11455
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
698 pixels_ = render (elt, box, rot_mode); |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
699 delete elt; |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
700 |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
701 if (pixels_.numel () == 0) |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
702 { |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
703 // nothing to render |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
704 return; |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
705 } |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
706 |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
707 switch (halign) |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
708 { |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
709 default: box(0) = 0; break; |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
710 case 1: box(0) = -box(2)/2; break; |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
711 case 2: box(0) = -box(2); break; |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
712 } |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
713 switch (valign) |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
714 { |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
715 default: box(1) = 0; break; |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
716 case 1: box(1) = -box(3)/2; break; |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
717 case 2: box(1) = -box(3); break; |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
718 case 3: break; |
16206
9ba5c5ed3aeb
Add new verticalalignment option 'cap' for OpenGL plotting.
Rik <rik@octave.org>
parents:
16201
diff
changeset
|
719 case 4: box(1) = -box(3)-box(1); break; |
11455
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
720 } |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
721 |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
722 switch (rot_mode) |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
723 { |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
724 case ROTATION_90: |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
725 std::swap (box(0), box(1)); |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
726 std::swap (box(2), box(3)); |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
727 box(0) = -box(0)-box(2); |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
728 break; |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
729 case ROTATION_180: |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
730 box(0) = -box(0)-box(2); |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
731 box(1) = -box(1)-box(3); |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
732 break; |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
733 case ROTATION_270: |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
734 std::swap (box(0), box(1)); |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
735 std::swap (box(2), box(3)); |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
736 box(1) = -box(1)-box(3); |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
737 break; |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
738 } |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
739 } |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
740 |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
741 #endif // HAVE_FREETYPE |