annotate libinterp/corefcn/txt-eng-ft.cc @ 17280:8ce6cdd272eb

Support TeX elements in FreeType renderer. * libinterp/corefcn/txt-eng.cc: New file. Contains mapping from symbol name to character code, in Unicode and MS symbol. * libinterp/corefcn/modules.mk (COREFCN_SRC): Add txt-eng.cc. * libinterp/corefcn/oct-tex-lexer.ll: Add "\n" to rules applicable to ".", as the latter does not include new line characters. * libinterp/corefcn/oct-tex-parser.yy: Remove debug statements. * libinterp/corefcn/txt-eng.ft.cc (gripe_missing_glyph, gripe_glyph_render): Change signature from char to FT_ULong. (ft_render::ft_render): Adapt to new/removed members. (ft_render::~ft_render): Remove use of fonts member. (ft_render::set_font): Likewise. Use font instead. (ft_render::push_new_line): Likewise. Change meaning of yoffset and initialize line_yoffset. (ft_render::update_line_bbox): New method. (ft_render::set_mode): Change meaning of yoffset and initialize line_yoffset. (ft_render::process_character): New method. (ft_render::visit(text_element_string)): Use it. (ft_render::visit(text_element_list), ft_render::visit(text_element_subscript), ft_render::visit(text_element_superscript), ft_render::visit(text_element_color), ft_render::visit(text_element_fontsize), ft_render::visit(text_element_fontname), ft_render::visit(text_element_fontstyle), ft_render::visit(text_element_symbol)): New methods. (ft_render::set_color): Use color member instead of red/green/blue. * libinterp/corefcn/txt-eng-ft.h (ft_render::visit(text_element_list), ft_render::visit(text_element_subscript), ft_render::visit(text_element_superscript), ft_render::visit(text_element_color), ft_render::visit(text_element_fontsize), ft_render::visit(text_element_fontname), ft_render::visit(text_element_fontstyle), ft_render::visit(text_element_symbol)): New methods. (ft_render::update_line_bbox, ft_render::process_character): New methods. (ft_render::current_face): Removed method.i (ft_render::font): New member, replaces obsolete ft_render::fonts. (ft_render::line_yoffset): New member. (ft_render::color): New member, replaces obsolete red, green and blue. (ft_render::ft_font::ft_font()): Implement default constructor. (ft_render::ft_font::operator=): Fix incorrect use of FT_Reference_Face return value. (ft_render::ft_font::is_valid): New method. * libinterp/corefcn/txt-eng.h (class text_element_symbol, class text_element_fontname, class text_element_fontsize, class text_element_fontname, class text_element_fontstyle, class text_element_color): Add forward definition. (text_element_symbol::invalid_code): New enum. (text_element_symbol::code): New member. (text_element_symbol::text_element_symbol): Initialize it. (text_element_symbol::get_symbol_code): New method. (text_element_fontstyle::get_fontstyle): New method. (text_element_fontname::get_fontname): Renamed from fontname. (text_element_fontsize::get_fontsize): Renamed from fontsize.
author Michael Goffioul <michael.goffioul@gmail.com>
date Sun, 18 Aug 2013 16:36:46 -0400
parents cb7233cfbf43
children 0a09d4b40767
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1 /*
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2
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>
17278
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
diff changeset
34 #include <map>
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
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
17280
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
47 gripe_missing_glyph (FT_ULong c)
13317
d2b799e3178a allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents: 13141
diff changeset
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",
17280
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
50 "ft_render: skipping missing glyph for character '%x'",
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
17280
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
55 gripe_glyph_render (FT_ULong c)
13317
d2b799e3178a allow warnings about missing glyphs to be disabled
John W. Eaton <jwe@octave.org>
parents: 13141
diff changeset
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",
17280
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
58 "ft_render: unable to render glyph for character '%x'",
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
17278
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
diff changeset
70 // Forward declaration
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
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: 17277
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
17278
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
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: 17277
diff changeset
108 {
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
diff changeset
109 if (instance_ok ())
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
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: 17277
diff changeset
111 }
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
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
17278
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
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: 17277
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: 17277
diff changeset
119
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
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: 17277
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: 17277
diff changeset
122 // in class ft_render.
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
diff changeset
123 ft_cache cache;
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
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
17278
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
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: 17277
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: 17277
diff changeset
173
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
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: 17277
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: 17277
diff changeset
176
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
diff changeset
177 if (it != cache.end ())
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
diff changeset
178 {
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
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: 17277
diff changeset
180 return it->second;
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
diff changeset
181 }
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
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
637fa784d102 Allow more font matches
godfrey@isl.Stanford.EDU
parents: 9619
diff changeset
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
17278
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
diff changeset
255 if (! file.empty ())
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
diff changeset
256 {
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
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: 17277
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: 17277
diff changeset
259 else
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
diff changeset
260 {
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
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: 17277
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: 17277
diff changeset
263 // references to font objects.
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
diff changeset
264
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
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: 17277
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: 17277
diff changeset
267
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
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: 17277
diff changeset
269
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
diff changeset
270 cache[key] = retval;
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
diff changeset
271 }
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
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
17278
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
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: 17277
diff changeset
278 {
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
diff changeset
279 if (face->generic.data)
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
diff changeset
280 {
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
diff changeset
281 ft_key* pkey =
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
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: 17277
diff changeset
283
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
diff changeset
284 cache.erase (*pkey);
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
diff changeset
285 delete pkey;
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
diff changeset
286 face->generic.data = 0;
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
diff changeset
287 }
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
diff changeset
288 }
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
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
17278
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
diff changeset
298 static void
ba865ea9c7e9 Add simple FreeType font cache in class ft_manager.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17277
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: 17277
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: 17277
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)
17280
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
305 : text_processor (), font (), bbox (1, 4, 0.0), halign (0), xoffset (0),
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
306 line_yoffset (0), yoffset (0), mode (MODE_BBOX),
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
307 color (dim_vector (1, 3), 0)
9403
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
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
311 ft_render::~ft_render (void)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
312 {
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 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
319 // FIXME: take "fontunits" into account
17279
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
320 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
321
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
322 if (face)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
323 {
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
324 if (FT_Set_Char_Size (face, 0, size*64, 0, 0))
17280
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
325 ::warning ("ft_render: unable to set font size to %g", size);
17279
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
326
17280
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
327 font = ft_font (name, weight, angle, size, face);
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
328 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
329 else
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
330 ::warning ("ft_render: unable to load appropriate font");
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
331 }
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 void
17279
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
334 ft_render::push_new_line (void)
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
335 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
336 switch (mode)
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
337 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
338 case MODE_BBOX:
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
339 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
340 // 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: 17278
diff changeset
341
17280
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
342 FT_Face face = font.face;
17279
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
343
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
344 if (face)
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
345 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
346 int asc = face->size->metrics.ascender >> 6;
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
347 int desc = face->size->metrics.descender >> 6;
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
348 int h = face->size->metrics.height >> 6;
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
349
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
350 Matrix bb (1, 5, 0.0);
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
351
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
352 bb(1) = desc;
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
353 bb(3) = asc - desc;
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
354 bb(4) = h;
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
355
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
356 line_bbox.push_back (bb);
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
357 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
358 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
359 break;
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
360
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
361 case MODE_RENDER:
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
362 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
363 // 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: 17278
diff changeset
364 // 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: 17278
diff changeset
365
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
366 Matrix old_bbox = line_bbox.front ();
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
367 line_bbox.pop_front ();
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
368 Matrix new_bbox = line_bbox.front ();
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
369
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
370 xoffset = compute_line_xoffset (new_bbox);
17280
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
371 line_yoffset += (old_bbox(1) - (new_bbox(1) + new_bbox(3)));
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
372 yoffset = 0;
17279
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
373 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
374 break;
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
375 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
376 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
377
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
378 int
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
379 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: 17278
diff changeset
380 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
381 if (! bbox.is_empty ())
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
382 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
383 switch (halign)
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
384 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
385 case 0:
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
386 return 0;
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
387 case 1:
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
388 return (bbox(2) - lb(2)) / 2;
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
389 case 2:
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
390 return (bbox(2) - lb(2));
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
391 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
392 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
393
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
394 return 0;
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
395 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
396
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
397 void
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
398 ft_render::compute_bbox (void)
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
399 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
400 // 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: 17278
diff changeset
401 // bounding box for the entire text string.
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
402
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
403 bbox = Matrix ();
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
404
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
405 switch (line_bbox.size ())
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
406 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
407 case 0:
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
408 break;
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
409 case 1:
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
410 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: 17278
diff changeset
411 break;
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
412 default:
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
413 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: 17278
diff changeset
414 it != line_bbox.end (); ++it)
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
415 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
416 if (bbox.is_empty ())
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
417 bbox = it->extract (0, 0, 0, 3);
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
418 else
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
419 {
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
420 bbox(1) -= (*it)(3);
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
421 bbox(3) += (*it)(3);
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
422 bbox(2) = xmax (bbox(2), (*it)(2));
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
423 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
424 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
425 break;
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
426 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
427 }
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
428
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
429 void
17280
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
430 ft_render::update_line_bbox (void)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
431 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
432 // Called after a font change, when in MODE_BBOX mode, to update the
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
433 // current line bbox with the new font metrics. This also includes the
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
434 // current yoffset, that is the offset of the current glyph's baseline
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
435 // the line's baseline.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
436
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
437 if (mode == MODE_BBOX)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
438 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
439 int asc = font.face->size->metrics.ascender >> 6;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
440 int desc = font.face->size->metrics.descender >> 6;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
441
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
442 Matrix& bb = line_bbox.front ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
443
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
444 if ((yoffset + desc) < bb(1))
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
445 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
446 // The new font goes below the bottom of the current bbox.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
447
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
448 int delta = bb(1) - (yoffset + desc);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
449
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
450 bb(1) -= delta;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
451 bb(3) += delta;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
452 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
453
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
454 if ((yoffset + asc) > (bb(1) + bb(3)))
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
455 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
456 // The new font goes above the top of the current bbox.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
457
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
458 int delta = (yoffset + asc) - (bb(1) + bb(3));
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
459
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
460 bb(3) += delta;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
461 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
462 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
463 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
464
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
465 void
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
466 ft_render::set_mode (int m)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
467 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
468 mode = m;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
469
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
470 switch (mode)
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 case MODE_BBOX:
17280
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
473 xoffset = line_yoffset = yoffset = 0;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
474 bbox = Matrix (1, 4, 0.0);
17279
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
475 line_bbox.clear ();
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
476 push_new_line ();
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
477 break;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
478 case MODE_RENDER:
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
479 if (bbox.numel () != 4)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
480 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
481 ::warning ("ft_render: invalid bounding box, cannot render");
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
482
17280
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
483 xoffset = line_yoffset = yoffset = 0;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
484 pixels = uint8NDArray ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
485 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
486 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
487 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
488 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
489 static_cast<uint8_t> (0));
17279
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
490 xoffset = compute_line_xoffset (line_bbox.front ());
17280
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
491 line_yoffset = -bbox(1)-1;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
492 yoffset = 0;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
493 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
494 break;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
495 default:
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
496 ::error ("ft_render: invalid mode '%d'", mode);
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
497 break;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
498 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
499 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
500
17280
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
501 FT_UInt
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
502 ft_render::process_character (FT_ULong code, FT_UInt previous)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
503 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
504 FT_Face face = font.face;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
505 FT_UInt glyph_index = 0;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
506
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
507 if (face)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
508 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
509 glyph_index = FT_Get_Char_Index (face, code);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
510
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
511 if (code != '\n'
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
512 && (! glyph_index
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
513 || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT)))
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
514 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
515 glyph_index = 0;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
516 gripe_missing_glyph (code);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
517 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
518 else
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
519 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
520 switch (mode)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
521 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
522 case MODE_RENDER:
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
523 if (code == '\n')
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
524 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
525 glyph_index = FT_Get_Char_Index (face, ' ');
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
526 if (!glyph_index || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT))
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
527 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
528 glyph_index = 0;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
529 gripe_missing_glyph (' ');
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
530 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
531 else
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
532 push_new_line ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
533 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
534 else if (FT_Render_Glyph (face->glyph, FT_RENDER_MODE_NORMAL))
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
535 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
536 glyph_index = 0;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
537 gripe_glyph_render (code);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
538 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
539 else
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
540 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
541 FT_Bitmap& bitmap = face->glyph->bitmap;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
542 int x0, y0;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
543
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
544 if (previous)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
545 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
546 FT_Vector delta;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
547
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
548 FT_Get_Kerning (face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
549 xoffset += (delta.x >> 6);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
550 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
551
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
552 x0 = xoffset + face->glyph->bitmap_left;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
553 y0 = line_yoffset + yoffset + face->glyph->bitmap_top;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
554
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
555 // 'w' seems to have a negative -1
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
556 // face->glyph->bitmap_left, this is so we don't
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
557 // index out of bound, and assumes we we allocated
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
558 // the right amount of horizontal space in the bbox.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
559 if (x0 < 0)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
560 x0 = 0;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
561
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
562 for (int r = 0; r < bitmap.rows; r++)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
563 for (int c = 0; c < bitmap.width; c++)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
564 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
565 unsigned char pix = bitmap.buffer[r*bitmap.width+c];
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
566 if (x0+c < 0 || x0+c >= pixels.dim2 ()
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
567 || y0-r < 0 || y0-r >= pixels.dim3 ())
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
568 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
569 //::warning ("ft_render: pixel out of bound (char=%d, (x,y)=(%d,%d), (w,h)=(%d,%d)",
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
570 // str[i], x0+c, y0-r, pixels.dim2 (), pixels.dim3 ());
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
571 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
572 else if (pixels(3, x0+c, y0-r).value () == 0)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
573 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
574 pixels(0, x0+c, y0-r) = color(0);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
575 pixels(1, x0+c, y0-r) = color(1);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
576 pixels(2, x0+c, y0-r) = color(2);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
577 pixels(3, x0+c, y0-r) = pix;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
578 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
579 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
580
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
581 xoffset += (face->glyph->advance.x >> 6);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
582 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
583 break;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
584
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
585 case MODE_BBOX:
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
586 if (code == '\n')
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
587 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
588 glyph_index = FT_Get_Char_Index (face, ' ');
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
589 if (! glyph_index
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
590 || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT))
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
591 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
592 glyph_index = 0;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
593 gripe_missing_glyph (' ');
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
594 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
595 else
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
596 push_new_line ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
597 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
598 else
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
599 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
600 Matrix& bb = line_bbox.back ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
601
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
602 // If we have a previous glyph, use kerning information.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
603 // This usually means moving a bit backward before adding
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
604 // the next glyph. That is, "delta.x" is usually < 0.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
605 if (previous)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
606 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
607 FT_Vector delta;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
608
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
609 FT_Get_Kerning (face, previous, glyph_index,
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
610 FT_KERNING_DEFAULT, &delta);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
611
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
612 bb(2) += (delta.x >> 6);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
613 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
614
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
615 // Extend current line bounding box by the width of the
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
616 // current glyph.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
617 bb(2) += (face->glyph->advance.x >> 6);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
618 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
619 break;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
620 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
621 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
622 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
623
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
624 return glyph_index;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
625 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
626
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
627 void
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
628 ft_render::visit (text_element_string& e)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
629 {
17280
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
630 if (font.is_valid ())
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
631 {
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
632 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
633 FT_UInt glyph_index, previous = 0;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
634
10553
f88e3d5d88e2 avoid GCC warnings
John W. Eaton <jwe@octave.org>
parents: 10402
diff changeset
635 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
636 {
17280
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
637 glyph_index = process_character (str[i], previous);
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
638
17280
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
639 if (str[i] == '\n')
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
640 previous = 0;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
641 else
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
642 previous = glyph_index;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
643 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
644 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
645 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
646
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
647 void
17280
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
648 ft_render::visit (text_element_list& e)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
649 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
650 // Save and restore (after processing the list) the current font and color.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
651
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
652 ft_font saved_font (font);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
653 uint8NDArray saved_color (color);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
654
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
655 text_processor::visit (e);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
656
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
657 font = saved_font;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
658 color = saved_color;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
659 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
660
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
661 void
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
662 ft_render::visit (text_element_subscript& e)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
663 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
664 ft_font saved_font (font);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
665 int saved_line_yoffset = line_yoffset;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
666 int saved_yoffset = yoffset;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
667
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
668 set_font (font.name, font.weight, font.angle, font.size - 2);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
669 if (font.is_valid ())
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
670 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
671 int h = font.face->size->metrics.height >> 6;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
672
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
673 // Shifting the baseline by 2/3 the font height seems to produce
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
674 // decent result.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
675 yoffset -= (h * 2) / 3;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
676
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
677 if (mode == MODE_BBOX)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
678 update_line_bbox ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
679 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
680
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
681 text_processor::visit (e);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
682
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
683 font = saved_font;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
684 // If line_yoffset changed, this means we moved to a new line; hence yoffset
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
685 // cannot be restored, because the saved value is not relevant anymore.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
686 if (line_yoffset == saved_line_yoffset)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
687 yoffset = saved_yoffset;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
688 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
689
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
690 void
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
691 ft_render::visit (text_element_superscript& e)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
692 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
693 ft_font saved_font (font);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
694 int saved_line_yoffset = line_yoffset;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
695 int saved_yoffset = yoffset;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
696
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
697 set_font (font.name, font.weight, font.angle, font.size - 2);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
698 if (saved_font.is_valid () && font.is_valid ())
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
699 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
700 int s_asc = saved_font.face->size->metrics.ascender >> 6;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
701
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
702 // Shifting the baseline by 2/3 base font ascender seems to produce
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
703 // decent result.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
704 yoffset += (s_asc * 2) / 3;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
705
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
706 if (mode == MODE_BBOX)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
707 update_line_bbox ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
708 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
709
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
710 text_processor::visit (e);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
711
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
712 font = saved_font;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
713 // If line_yoffset changed, this means we moved to a new line; hence yoffset
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
714 // cannot be restored, because the saved value is not relevant anymore.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
715 if (line_yoffset == saved_line_yoffset)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
716 yoffset = saved_yoffset;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
717 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
718
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
719 void
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
720 ft_render::visit (text_element_color& e)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
721 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
722 if (mode == MODE_RENDER)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
723 set_color (e.get_color ());
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
724 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
725
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
726 void
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
727 ft_render::visit (text_element_fontsize& e)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
728 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
729 double sz = e.get_fontsize ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
730
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
731 // FIXME: Matlab documentation says that the font size is expressed
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
732 // in the text object FontUnit.
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
733
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
734 set_font (font.name, font.weight, font.angle, sz);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
735
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
736 if (mode == MODE_BBOX)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
737 update_line_bbox ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
738 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
739
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
740 void
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
741 ft_render::visit (text_element_fontname& e)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
742 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
743 set_font (e.get_fontname (), font.weight, font.angle, font.size);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
744
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
745 if (mode == MODE_BBOX)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
746 update_line_bbox ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
747 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
748
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
749 void
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
750 ft_render::visit (text_element_fontstyle& e)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
751 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
752 switch (e.get_fontstyle ())
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
753 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
754 case text_element_fontstyle::normal:
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
755 set_font (font.name, "normal", "normal", font.size);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
756 break;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
757 case text_element_fontstyle::bold:
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
758 set_font (font.name, "bold", "normal", font.size);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
759 break;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
760 case text_element_fontstyle::italic:
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
761 set_font (font.name, "normal", "italic", font.size);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
762 break;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
763 case text_element_fontstyle::oblique:
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
764 set_font (font.name, "normal", "oblique", font.size);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
765 break;
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
766 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
767
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
768 if (mode == MODE_BBOX)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
769 update_line_bbox ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
770 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
771
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
772 void
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
773 ft_render::visit (text_element_symbol& e)
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
774 {
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
775 uint32_t code = e.get_symbol_code ();
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
776
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
777 if (code != text_element_symbol::invalid_code && font.is_valid ())
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
778 process_character (code);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
779 else if (font.is_valid ())
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
780 ::warning ("ignoring unknown symbol: %s", e.string_value ().c_str ());
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
781 }
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
782
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
783 void
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
784 ft_render::reset (void)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
785 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
786 set_mode (MODE_BBOX);
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
787 set_color (Matrix (1, 3, 0.0));
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
788 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
789
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
790 void
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
791 ft_render::set_color (Matrix c)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
792 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
793 if (c.numel () == 3)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
794 {
17280
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
795 color(0) = static_cast<uint8_t> (c(0)*255);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
796 color(1) = static_cast<uint8_t> (c(1)*255);
8ce6cdd272eb Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17279
diff changeset
797 color(2) = static_cast<uint8_t> (c(2)*255);
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
798 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
799 else
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
800 ::warning ("ft_render::set_color: invalid color");
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
801 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
802
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
803 uint8NDArray
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
804 ft_render::render (text_element* elt, Matrix& box, int rotation)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
805 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
806 set_mode (MODE_BBOX);
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
807 elt->accept (*this);
17279
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
808 compute_bbox ();
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
809 box = bbox;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
810
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
811 set_mode (MODE_RENDER);
9406
c0c23dbbade7 Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9405
diff changeset
812 if (pixels.numel () > 0)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
813 {
9406
c0c23dbbade7 Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9405
diff changeset
814 elt->accept (*this);
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
815
9406
c0c23dbbade7 Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9405
diff changeset
816 switch (rotation)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
817 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
818 case ROTATION_0:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
819 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
820 case ROTATION_90:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
821 {
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
822 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
823 perm(0) = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
824 perm(1) = 2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
825 perm(2) = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
826 pixels = pixels.permute (perm);
9406
c0c23dbbade7 Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9405
diff changeset
827
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
828 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
829 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
830 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
831 idx(2) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
832 pixels = uint8NDArray (pixels.index (idx));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
833 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
834 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
835 case ROTATION_180:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
836 {
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
837 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
838 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
839 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
840 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
841 pixels = uint8NDArray (pixels.index (idx));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
842 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
843 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
844 case ROTATION_270:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
845 {
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
846 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
847 perm(0) = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
848 perm(1) = 2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
849 perm(2) = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
850 pixels = pixels.permute (perm);
9406
c0c23dbbade7 Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9405
diff changeset
851
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
852 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
853 idx(0) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
854 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
855 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
856 pixels = uint8NDArray (pixels.index (idx));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
857 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
858 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
859 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
860 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
861
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
862 return pixels;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
863 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
864
16201
2338a92e9782 Fix spacing between ylabel and y-axis (bug #38461)
Rik <rik@octave.org>
parents: 15467
diff changeset
865 // Note:
2338a92e9782 Fix spacing between ylabel and y-axis (bug #38461)
Rik <rik@octave.org>
parents: 15467
diff changeset
866 // 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
867 // 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
868 // 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
869
10402
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
870 Matrix
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
871 ft_render::get_extent (text_element *elt, double rotation)
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
872 {
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
873 set_mode (MODE_BBOX);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
874 elt->accept (*this);
17279
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
875 compute_bbox ();
10402
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
876
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
877 Matrix extent (1, 2, 0.0);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
878
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
879 switch (rotation_to_mode (rotation))
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
880 {
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
881 case ROTATION_0:
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
882 case ROTATION_180:
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
883 extent(0) = bbox(2);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
884 extent(1) = bbox(3);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
885 break;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
886 case ROTATION_90:
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
887 case ROTATION_270:
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
888 extent(0) = bbox(3);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
889 extent(1) = bbox(2);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
890 }
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
891
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
892 return extent;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
893 }
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
894
12334
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
895 Matrix
17277
5b088598df1d Add simple TeX parser based on flex/bison.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16892
diff changeset
896 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
897 const caseless_str& interpreter)
12334
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
898 {
17277
5b088598df1d Add simple TeX parser based on flex/bison.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16892
diff changeset
899 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
900 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
901 delete elt;
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 12969
diff changeset
902
12334
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
903 return extent;
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
904 }
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
905
10402
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
906 int
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
907 ft_render::rotation_to_mode (double rotation) const
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
908 {
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
909 if (rotation == 0.0)
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
910 return ROTATION_0;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
911 else if (rotation == 90.0)
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
912 return ROTATION_90;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
913 else if (rotation == 180.0)
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
914 return ROTATION_180;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
915 else if (rotation == 270.0)
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
916 return ROTATION_270;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
917 else
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
918 return ROTATION_0;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
919 }
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
920
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
921 void
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
922 ft_render::text_to_pixels (const std::string& txt,
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
923 uint8NDArray& pixels_, Matrix& box,
17279
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
924 int _halign, int valign, double rotation,
17277
5b088598df1d Add simple TeX parser based on flex/bison.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16892
diff changeset
925 const caseless_str& interpreter)
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
926 {
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
927 // FIXME: clip "rotation" between 0 and 360
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
928 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
929
17279
cb7233cfbf43 Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17278
diff changeset
930 halign = _halign;
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
931
17277
5b088598df1d Add simple TeX parser based on flex/bison.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16892
diff changeset
932 text_element *elt = text_parser::parse (txt, interpreter);
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
933 pixels_ = render (elt, box, rot_mode);
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
934 delete elt;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
935
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
936 if (pixels_.numel () == 0)
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
937 {
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
938 // nothing to render
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
939 return;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
940 }
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
941
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
942 switch (halign)
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
943 {
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
944 default: box(0) = 0; break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
945 case 1: box(0) = -box(2)/2; break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
946 case 2: box(0) = -box(2); break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
947 }
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
948 switch (valign)
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
949 {
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
950 default: box(1) = 0; break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
951 case 1: box(1) = -box(3)/2; break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
952 case 2: box(1) = -box(3); break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
953 case 3: break;
16206
9ba5c5ed3aeb Add new verticalalignment option 'cap' for OpenGL plotting.
Rik <rik@octave.org>
parents: 16201
diff changeset
954 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
955 }
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
956
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
957 switch (rot_mode)
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
958 {
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
959 case ROTATION_90:
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
960 std::swap (box(0), box(1));
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
961 std::swap (box(2), box(3));
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
962 box(0) = -box(0)-box(2);
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
963 break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
964 case ROTATION_180:
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
965 box(0) = -box(0)-box(2);
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
966 box(1) = -box(1)-box(3);
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
967 break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
968 case ROTATION_270:
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
969 std::swap (box(0), box(1));
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
970 std::swap (box(2), box(3));
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
971 box(1) = -box(1)-box(3);
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
972 break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
973 }
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
974 }
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
975
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
976 #endif // HAVE_FREETYPE