Mercurial > octave
annotate libinterp/corefcn/txt-eng-ft.cc @ 17271:cb7233cfbf43
Prepare base text rendering code for full TeX support.
* libinterp/corefcm/oct-tex-lexer.ll: Include newlines in string
characters.
* libinterp/corefcn/txt-eng-ft.h (list): New include.
(class ft_render::ft_font): New class.
(ft_render::current_face, ft_render::push_new_line,
ft_render::compute_bbox, ft_render::compute_line_xoffset): New methods.
(ft_render::fonts): New member, replaces obsolete face.
(ft_render::line_bbox): New member.
(ft_render::halign): New member, replaces obsolete multiline_halign.
(ft_render::multiline_align_xoffsets): Remove member.
(class ft_render): Add comments for each class member.
* libinterp/corefcn/txt-eng-ft.cc (ft_render::text_to_pixels): Use halig
instead of multiline_halign.
(ft_render::ft_render): Adapt to added/removed members.
(ft_render::~ft_render): Likewise.
(ft_render::set_font): Use fonts member instead of face.
(ft_render::push_new_line, ft_render::compute_bbox,
ft_render::compute_line_xoffset): New methods.
(ft_render::render, ft_render::get_extent): Call compute_bbox.
(ft_render::visit(text_element_string)): Remove code for handling
newlines, call push_new_line instead. Remove code related to
multiline_align_xoffsets.
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Sun, 18 Aug 2013 16:36:44 -0400 |
parents | ba865ea9c7e9 |
children | 8ce6cdd272eb |
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) |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
305 : text_processor (), fonts (), bbox (1, 4, 0.0), halign (0), xoffset (0), |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
306 yoffset (0), mode (MODE_BBOX), red (0), green (0), blue (0) |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
307 { |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
308 } |
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 ft_render::~ft_render (void) |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
311 { |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
312 fonts.clear (); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
313 } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
314 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
315 void |
11455
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
316 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
|
317 const std::string& angle, double size) |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
318 { |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
319 if (fonts.size () > 1) |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
320 ::warning ("ft_render: resetting font parameters while the font stack " |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
321 "contains more than 1 element."); |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
322 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
323 // In all cases, we only replace the first/bottom font in the stack, if any. |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
324 // Calling this method while there's more than 1 font in the stack does |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
325 // not make sense: we're not gonna reconstruct the entire font stack. |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
326 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
327 if (fonts.size ()) |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
328 fonts.pop_front (); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
329 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
330 // FIXME: take "fontunits" into account |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
331 FT_Face face = ft_manager::get_font (name, weight, angle, 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 if (face) |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
334 { |
11455
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
335 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
|
336 ::warning ("ft_render: unable to set font size to %d", size); |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
337 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
338 fonts.push_front (ft_font (name, weight, angle, size, face)); |
9403
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 else |
9616
2093499ec9f4
avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents:
9406
diff
changeset
|
341 ::warning ("ft_render: unable to load appropriate font"); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
342 } |
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 void |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
345 ft_render::push_new_line (void) |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
346 { |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
347 switch (mode) |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
348 { |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
349 case MODE_BBOX: |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
350 { |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
351 // Create a new bbox entry based on the current font. |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
352 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
353 FT_Face face = current_face (); |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
354 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
355 if (face) |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
356 { |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
357 int asc = face->size->metrics.ascender >> 6; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
358 int desc = face->size->metrics.descender >> 6; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
359 int h = face->size->metrics.height >> 6; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
360 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
361 Matrix bb (1, 5, 0.0); |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
362 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
363 bb(1) = desc; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
364 bb(3) = asc - desc; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
365 bb(4) = h; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
366 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
367 line_bbox.push_back (bb); |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
368 } |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
369 } |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
370 break; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
371 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
372 case MODE_RENDER: |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
373 { |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
374 // Move to the next line bbox, adjust xoffset based on alignment |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
375 // and yoffset based on the old and new line bbox. |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
376 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
377 Matrix old_bbox = line_bbox.front (); |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
378 line_bbox.pop_front (); |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
379 Matrix new_bbox = line_bbox.front (); |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
380 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
381 xoffset = compute_line_xoffset (new_bbox); |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
382 yoffset += (old_bbox(1) - (new_bbox(1) + new_bbox(3))); |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
383 } |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
384 break; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
385 } |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
386 } |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
387 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
388 int |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
389 ft_render::compute_line_xoffset (const Matrix& lb) const |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
390 { |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
391 if (! bbox.is_empty ()) |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
392 { |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
393 switch (halign) |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
394 { |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
395 case 0: |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
396 return 0; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
397 case 1: |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
398 return (bbox(2) - lb(2)) / 2; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
399 case 2: |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
400 return (bbox(2) - lb(2)); |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
401 } |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
402 } |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
403 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
404 return 0; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
405 } |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
406 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
407 void |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
408 ft_render::compute_bbox (void) |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
409 { |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
410 // Stack the various line bbox together and compute the final |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
411 // bounding box for the entire text string. |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
412 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
413 bbox = Matrix (); |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
414 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
415 switch (line_bbox.size ()) |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
416 { |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
417 case 0: |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
418 break; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
419 case 1: |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
420 bbox = line_bbox.front ().extract (0, 0, 0, 3); |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
421 break; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
422 default: |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
423 for (std::list<Matrix>::const_iterator it = line_bbox.begin (); |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
424 it != line_bbox.end (); ++it) |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
425 { |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
426 if (bbox.is_empty ()) |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
427 bbox = it->extract (0, 0, 0, 3); |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
428 else |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
429 { |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
430 bbox(1) -= (*it)(3); |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
431 bbox(3) += (*it)(3); |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
432 bbox(2) = xmax (bbox(2), (*it)(2)); |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
433 } |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
434 } |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
435 break; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
436 } |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
437 } |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
438 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
439 void |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
440 ft_render::set_mode (int m) |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
441 { |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
442 mode = m; |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
443 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
444 switch (mode) |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
445 { |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
446 case MODE_BBOX: |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
447 xoffset = yoffset = 0; |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
448 bbox = Matrix (1, 4, 0.0); |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
449 line_bbox.clear (); |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
450 push_new_line (); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
451 break; |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
452 case MODE_RENDER: |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
453 if (bbox.numel () != 4) |
10315
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 ::warning ("ft_render: invalid bounding box, cannot render"); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
456 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
457 xoffset = yoffset = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
458 pixels = uint8NDArray (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
459 } |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
460 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
461 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
462 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
|
463 static_cast<uint8_t> (0)); |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
464 xoffset = compute_line_xoffset (line_bbox.front ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
465 yoffset = -bbox(1)-1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
466 } |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
467 break; |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
468 default: |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
469 ::error ("ft_render: invalid mode '%d'", mode); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
470 break; |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
471 } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
472 } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
473 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
474 void |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
475 ft_render::visit (text_element_string& e) |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
476 { |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
477 FT_Face face = current_face (); |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
478 |
9616
2093499ec9f4
avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents:
9406
diff
changeset
|
479 if (face) |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
480 { |
9616
2093499ec9f4
avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents:
9406
diff
changeset
|
481 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
|
482 FT_UInt glyph_index, previous = 0; |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
483 |
10553 | 484 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
|
485 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
486 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
|
487 |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12969
diff
changeset
|
488 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
|
489 && (! 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
|
490 || 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
|
491 gripe_missing_glyph (str[i]); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
492 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
493 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
494 switch (mode) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
495 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
496 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
|
497 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
|
498 { |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
499 glyph_index = FT_Get_Char_Index (face, ' '); |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
500 if (!glyph_index || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT)) |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
501 { |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
502 gripe_missing_glyph (' '); |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
503 } |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
504 else |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
505 push_new_line (); |
13317
d2b799e3178a
allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
506 } |
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
|
507 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
|
508 { |
d2b799e3178a
allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
509 gripe_glyph_render (str[i]); |
d2b799e3178a
allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
510 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
511 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
512 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
513 FT_Bitmap& bitmap = face->glyph->bitmap; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
514 int x0, y0; |
9616
2093499ec9f4
avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents:
9406
diff
changeset
|
515 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
516 if (previous) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
517 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
518 FT_Vector delta; |
9616
2093499ec9f4
avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents:
9406
diff
changeset
|
519 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
520 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
|
521 xoffset += (delta.x >> 6); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
522 } |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
523 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
524 x0 = xoffset+face->glyph->bitmap_left; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
525 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
|
526 |
22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents:
12334
diff
changeset
|
527 // '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
|
528 // 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
|
529 // 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
|
530 // 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
|
531 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
|
532 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
|
533 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
534 for (int r = 0; r < bitmap.rows; r++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
535 for (int c = 0; c < bitmap.width; c++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
536 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
537 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
|
538 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
|
539 || y0-r < 0 || y0-r >= pixels.dim3 ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
540 { |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
541 //::warning ("ft_render: pixel out of bound (char=%d, (x,y)=(%d,%d), (w,h)=(%d,%d)", |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
542 // str[i], x0+c, y0-r, pixels.dim2 (), pixels.dim3 ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
543 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
544 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
|
545 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
546 pixels(0, x0+c, y0-r) = red; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
547 pixels(1, x0+c, y0-r) = green; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
548 pixels(2, x0+c, y0-r) = blue; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
549 pixels(3, x0+c, y0-r) = pix; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
550 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
551 } |
9616
2093499ec9f4
avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents:
9406
diff
changeset
|
552 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
553 xoffset += (face->glyph->advance.x >> 6); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
554 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
555 break; |
9616
2093499ec9f4
avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents:
9406
diff
changeset
|
556 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
557 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
|
558 if (str[i] == '\n') |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
559 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
560 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
|
561 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
|
562 || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT)) |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
563 { |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
564 gripe_missing_glyph (' '); |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
565 } |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
566 else |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
567 push_new_line (); |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12969
diff
changeset
|
568 } |
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12969
diff
changeset
|
569 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
570 { |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
571 Matrix& bb = line_bbox.back (); |
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
|
572 |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
573 // If we have a previous glyph, use kerning information. |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
574 // This usually means moving a bit backward before adding |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
575 // the next glyph. That is, "delta.x" is usually < 0. |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
576 if (previous) |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
577 { |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
578 FT_Vector delta; |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
579 |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
580 FT_Get_Kerning (face, previous, glyph_index, |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
581 FT_KERNING_DEFAULT, &delta); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
582 |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
583 bb(2) += (delta.x >> 6); |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
584 } |
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
|
585 |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
586 // Extend current line bounding box by the width of the |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
587 // current glyph. |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
588 bb(2) += (face->glyph->advance.x >> 6); |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
589 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
590 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
591 } |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
592 |
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
|
593 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
|
594 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
|
595 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
|
596 previous = glyph_index; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
597 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
598 } |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
599 } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
600 } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
601 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
602 void |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
603 ft_render::reset (void) |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
604 { |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
605 set_mode (MODE_BBOX); |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
606 set_color (Matrix (1, 3, 0.0)); |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
607 } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
608 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
609 void |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
610 ft_render::set_color (Matrix c) |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
611 { |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
612 if (c.numel () == 3) |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
613 { |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
614 red = static_cast<uint8_t> (c(0)*255); |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
615 green = static_cast<uint8_t> (c(1)*255); |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
616 blue = static_cast<uint8_t> (c(2)*255); |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
617 } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
618 else |
9616
2093499ec9f4
avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents:
9406
diff
changeset
|
619 ::warning ("ft_render::set_color: invalid color"); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
620 } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
621 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
622 uint8NDArray |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
623 ft_render::render (text_element* elt, Matrix& box, int rotation) |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
624 { |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
625 set_mode (MODE_BBOX); |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
626 elt->accept (*this); |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
627 compute_bbox (); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
628 box = bbox; |
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 set_mode (MODE_RENDER); |
9406
c0c23dbbade7
Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
9405
diff
changeset
|
631 if (pixels.numel () > 0) |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
632 { |
9406
c0c23dbbade7
Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
9405
diff
changeset
|
633 elt->accept (*this); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
634 |
9406
c0c23dbbade7
Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
9405
diff
changeset
|
635 switch (rotation) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
636 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
637 case ROTATION_0: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
638 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
639 case ROTATION_90: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
640 { |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
641 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
|
642 perm(0) = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
643 perm(1) = 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
644 perm(2) = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
645 pixels = pixels.permute (perm); |
9406
c0c23dbbade7
Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
9405
diff
changeset
|
646 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
647 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
|
648 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
|
649 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
|
650 idx(2) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
651 pixels = uint8NDArray (pixels.index (idx)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
652 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
653 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
654 case ROTATION_180: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
655 { |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
656 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
|
657 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
|
658 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
|
659 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
|
660 pixels = uint8NDArray (pixels.index (idx)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
661 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
662 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
663 case ROTATION_270: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
664 { |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
665 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
|
666 perm(0) = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
667 perm(1) = 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
668 perm(2) = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
669 pixels = pixels.permute (perm); |
9406
c0c23dbbade7
Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
9405
diff
changeset
|
670 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
671 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
|
672 idx(0) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
673 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
|
674 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
|
675 pixels = uint8NDArray (pixels.index (idx)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
676 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
677 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9833
diff
changeset
|
678 } |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
679 } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
680 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
681 return pixels; |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
682 } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
683 |
16201
2338a92e9782
Fix spacing between ylabel and y-axis (bug #38461)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
684 // Note: |
2338a92e9782
Fix spacing between ylabel and y-axis (bug #38461)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
685 // 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
|
686 // 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
|
687 // 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
|
688 |
10402
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
689 Matrix |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
690 ft_render::get_extent (text_element *elt, double rotation) |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
691 { |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
692 set_mode (MODE_BBOX); |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
693 elt->accept (*this); |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
694 compute_bbox (); |
10402
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
695 |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
696 Matrix extent (1, 2, 0.0); |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
697 |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
698 switch (rotation_to_mode (rotation)) |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
699 { |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
700 case ROTATION_0: |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
701 case ROTATION_180: |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
702 extent(0) = bbox(2); |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
703 extent(1) = bbox(3); |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
704 break; |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
705 case ROTATION_90: |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
706 case ROTATION_270: |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
707 extent(0) = bbox(3); |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
708 extent(1) = bbox(2); |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
709 } |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
710 |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
711 return extent; |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
712 } |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
713 |
12334
63dc132a1000
Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents:
12225
diff
changeset
|
714 Matrix |
17269
5b088598df1d
Add simple TeX parser based on flex/bison.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16892
diff
changeset
|
715 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
|
716 const caseless_str& interpreter) |
12334
63dc132a1000
Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents:
12225
diff
changeset
|
717 { |
17269
5b088598df1d
Add simple TeX parser based on flex/bison.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16892
diff
changeset
|
718 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
|
719 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
|
720 delete elt; |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12969
diff
changeset
|
721 |
12334
63dc132a1000
Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents:
12225
diff
changeset
|
722 return extent; |
63dc132a1000
Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents:
12225
diff
changeset
|
723 } |
63dc132a1000
Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents:
12225
diff
changeset
|
724 |
10402
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
725 int |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
726 ft_render::rotation_to_mode (double rotation) const |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
727 { |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
728 if (rotation == 0.0) |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
729 return ROTATION_0; |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
730 else if (rotation == 90.0) |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
731 return ROTATION_90; |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
732 else if (rotation == 180.0) |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
733 return ROTATION_180; |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
734 else if (rotation == 270.0) |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
735 return ROTATION_270; |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
736 else |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
737 return ROTATION_0; |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
738 } |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10350
diff
changeset
|
739 |
11455
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
740 void |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
741 ft_render::text_to_pixels (const std::string& txt, |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
742 uint8NDArray& pixels_, Matrix& box, |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
743 int _halign, int valign, double rotation, |
17269
5b088598df1d
Add simple TeX parser based on flex/bison.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16892
diff
changeset
|
744 const caseless_str& interpreter) |
11455
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
745 { |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
746 // FIXME: clip "rotation" between 0 and 360 |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
747 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
|
748 |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17270
diff
changeset
|
749 halign = _halign; |
11455
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
750 |
17269
5b088598df1d
Add simple TeX parser based on flex/bison.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16892
diff
changeset
|
751 text_element *elt = text_parser::parse (txt, interpreter); |
11455
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
752 pixels_ = render (elt, box, rot_mode); |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
753 delete elt; |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
754 |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
755 if (pixels_.numel () == 0) |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
756 { |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
757 // nothing to render |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
758 return; |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
759 } |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
760 |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
761 switch (halign) |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
762 { |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
763 default: box(0) = 0; break; |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
764 case 1: box(0) = -box(2)/2; break; |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
765 case 2: box(0) = -box(2); break; |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
766 } |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
767 switch (valign) |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
768 { |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
769 default: box(1) = 0; break; |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
770 case 1: box(1) = -box(3)/2; break; |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
771 case 2: box(1) = -box(3); break; |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
772 case 3: break; |
16206
9ba5c5ed3aeb
Add new verticalalignment option 'cap' for OpenGL plotting.
Rik <rik@octave.org>
parents:
16201
diff
changeset
|
773 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
|
774 } |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
775 |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
776 switch (rot_mode) |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
777 { |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
778 case ROTATION_90: |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
779 std::swap (box(0), box(1)); |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
780 std::swap (box(2), box(3)); |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
781 box(0) = -box(0)-box(2); |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
782 break; |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
783 case ROTATION_180: |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
784 box(0) = -box(0)-box(2); |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
785 box(1) = -box(1)-box(3); |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
786 break; |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
787 case ROTATION_270: |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
788 std::swap (box(0), box(1)); |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
789 std::swap (box(2), box(3)); |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
790 box(1) = -box(1)-box(3); |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
791 break; |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
792 } |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
793 } |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10553
diff
changeset
|
794 |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
795 #endif // HAVE_FREETYPE |