Mercurial > octave-nkf
annotate libinterp/corefcn/txt-eng-ft.h @ 17272: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 |
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:
12969
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 #if ! defined (txt_eng_ft_h) |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
24 #define txt_eng_ft_h 1 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
25 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
26 #if HAVE_FREETYPE |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
27 |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
28 #include <list> |
12969
6fc2c61660f2
Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents:
12334
diff
changeset
|
29 #include <vector> |
6fc2c61660f2
Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents:
12334
diff
changeset
|
30 |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
31 #include <ft2build.h> |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
32 #include FT_FREETYPE_H |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
33 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
34 #include <dMatrix.h> |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
35 #include <uint8NDArray.h> |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
36 #include "txt-eng.h" |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
37 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
38 class |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
39 OCTINTERP_API |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
40 ft_render : public text_processor |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
41 { |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
42 public: |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
43 enum { |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
44 MODE_BBOX = 0, |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
45 MODE_RENDER = 1 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
46 }; |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
47 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
48 enum { |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
49 ROTATION_0 = 0, |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
50 ROTATION_90 = 1, |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
51 ROTATION_180 = 2, |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
52 ROTATION_270 = 3 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
53 }; |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
54 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
55 public: |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
56 ft_render (void); |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
57 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
58 ~ft_render (void); |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
59 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
60 void visit (text_element_string& e); |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
61 |
17272
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
62 void visit (text_element_list& e); |
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
63 |
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
64 void visit (text_element_subscript& e); |
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
65 |
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
66 void visit (text_element_superscript& e); |
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
67 |
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
68 void visit (text_element_color& e); |
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
69 |
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
70 void visit (text_element_fontsize& e); |
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
71 |
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
72 void visit (text_element_fontname& e); |
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
73 |
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
74 void visit (text_element_fontstyle& e); |
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
75 |
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
76 void visit (text_element_symbol& e); |
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
77 |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
78 void reset (void); |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
79 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
80 uint8NDArray get_pixels (void) const { return pixels; } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
81 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
82 Matrix get_boundingbox (void) const { return bbox; } |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
83 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
84 uint8NDArray render (text_element* elt, Matrix& box, |
10313 | 85 int rotation = ROTATION_0); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
86 |
10402
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10313
diff
changeset
|
87 Matrix get_extent (text_element *elt, double rotation = 0.0); |
17269
5b088598df1d
Add simple TeX parser based on flex/bison.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16892
diff
changeset
|
88 Matrix get_extent (const std::string& txt, double rotation = 0.0, |
5b088598df1d
Add simple TeX parser based on flex/bison.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16892
diff
changeset
|
89 const caseless_str& interpreter = "tex"); |
10402
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10313
diff
changeset
|
90 |
11455
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10402
diff
changeset
|
91 void set_font (const std::string& name, const std::string& weight, |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10402
diff
changeset
|
92 const std::string& angle, double size); |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
93 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
94 void set_color (Matrix c); |
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 void set_mode (int m); |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
97 |
11455
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10402
diff
changeset
|
98 void text_to_pixels (const std::string& txt, |
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10402
diff
changeset
|
99 uint8NDArray& pixels_, Matrix& bbox, |
17269
5b088598df1d
Add simple TeX parser based on flex/bison.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16892
diff
changeset
|
100 int halign, int valign, double rotation, |
5b088598df1d
Add simple TeX parser based on flex/bison.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16892
diff
changeset
|
101 const caseless_str& interpreter = "tex"); |
11455
2be9e22796d2
improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents:
10402
diff
changeset
|
102 |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
103 private: |
10402
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10313
diff
changeset
|
104 int rotation_to_mode (double rotation) const; |
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10313
diff
changeset
|
105 |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
106 // No copying! |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
107 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
108 ft_render (const ft_render&); |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
109 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
110 ft_render& operator = (const ft_render&); |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
111 |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
112 // Class to hold information about fonts and a strong |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
113 // reference to the font objects loaded by freetype. |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
114 class ft_font |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
115 { |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
116 public: |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
117 std::string name; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
118 std::string weight; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
119 std::string angle; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
120 double size; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
121 FT_Face face; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
122 |
17272
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
123 ft_font (void) |
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
124 : name (), weight (), angle (), size (0), face (0) { } |
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
125 |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
126 ft_font (const std::string& nm, const std::string& wt, |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
127 const std::string& ang, double sz, FT_Face f) |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
128 : name (nm), weight (wt), angle (ang), size (sz), face (f) { } |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
129 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
130 ft_font (const ft_font& ft) |
17272
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
131 : name (ft.name), weight (ft.weight), angle (ft.angle), |
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
132 size (ft.size), face (0) |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
133 { |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
134 if (FT_Reference_Face (ft.face) == 0) |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
135 face = ft.face; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
136 } |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
137 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
138 ~ft_font (void) |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
139 { |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
140 if (face) |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
141 FT_Done_Face (face); |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
142 } |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
143 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
144 ft_font& operator = (const ft_font& ft) |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
145 { |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
146 if (&ft != this) |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
147 { |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
148 name = ft.name; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
149 weight = ft.weight; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
150 angle = ft.angle; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
151 size = ft.size; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
152 FT_Done_Face (face); |
17272
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
153 if (FT_Reference_Face (ft.face) == 0) |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
154 face = ft.face; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
155 else |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
156 face = 0; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
157 } |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
158 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
159 return *this; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
160 } |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
161 |
17272
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
162 bool is_valid (void) const { return face; } |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
163 }; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
164 |
17272
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
165 void push_new_line (void); |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
166 |
17272
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
167 void update_line_bbox (void); |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
168 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
169 void compute_bbox (void); |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
170 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
171 int compute_line_xoffset (const Matrix& lb) const; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
172 |
17272
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
173 FT_UInt process_character (FT_ULong code, FT_UInt previous = 0); |
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
174 |
10402
9f2bf537a651
Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10313
diff
changeset
|
175 private: |
17272
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
176 // The current font used by the renderer. |
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
177 ft_font font; |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
178 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
179 // Used to stored the bounding box corresponding to the rendered text. |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
180 // The bounding box has the form [x, y, w, h] where x and y represent the |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
181 // coordinates of the bottom left corner relative to the anchor point of |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
182 // the text (== start of text on the baseline). Due to font descent or |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
183 // multiple lines, the value y is usually negative. |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
184 Matrix bbox; |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
185 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
186 // Used to stored the rendered text. It's a 3D matrix with size MxNx4 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
187 // where M and N are the width and height of the bounding box. |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
188 uint8NDArray pixels; |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
189 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
190 // Used to store the bounding box of each line. This is used to layout |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
191 // multiline text properly. |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
192 std::list<Matrix> line_bbox; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
193 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
194 // The current horizontal alignment. This is used to align multi-line text. |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
195 int halign; |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
196 |
17272
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
197 // The X offset for the next glyph. |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
198 int xoffset; |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
199 |
17272
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
200 // The Y offset of the baseline for the current line. |
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
201 int line_yoffset; |
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
202 |
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
203 // The Y offset of the baseline for the next glyph. The offset is relative |
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
204 // to line_yoffset. The total Y offset is computed with: |
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
205 // line_yoffset + yoffset. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
206 int yoffset; |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
207 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
208 // The current mode of the rendering process (box computing or rendering). |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
209 int mode; |
17271
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
210 |
cb7233cfbf43
Prepare base text rendering code for full TeX support.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17269
diff
changeset
|
211 // The base color of the rendered text. |
17272
8ce6cdd272eb
Support TeX elements in FreeType renderer.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17271
diff
changeset
|
212 uint8NDArray color; |
9403
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
213 }; |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
214 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
215 #endif // HAVE_FREETYPE |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
216 |
4af6e29449c1
[mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
217 #endif |