annotate src/txt-eng-ft.cc @ 11586:12df7854fa7c

strip trailing whitespace from source files
author John W. Eaton <jwe@octave.org>
date Thu, 20 Jan 2011 17:24:59 -0500
parents 57632dea2446
children f4689107dd8c
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
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 11455
diff changeset
3 Copyright (C) 2009-2011 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
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
27 #if HAVE_FREETYPE
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
28
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
29 #if HAVE_FONTCONFIG
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>
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
34
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
35 #include "error.h"
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
36 #include "pr-output.h"
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
37 #include "txt-eng-ft.h"
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
38
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
39 class
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
40 ft_manager
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 static bool instance_ok (void)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
44 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
45 bool retval = true;
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 if (! instance)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
48 instance = new ft_manager ();
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
49
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
50 if (! instance)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
51 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
52 ::error ("unable to create ft_manager!");
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
53
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
54 retval = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
55 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
56
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
57 return retval;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
58 }
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 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
61 const std::string& angle, double size)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
62 { return (instance_ok ()
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
63 ? instance->do_get_font (name, weight, angle, size)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
64 : 0); }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
65
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
66 private:
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
67 static ft_manager *instance;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
68
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
69 private:
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
70 ft_manager (void)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
71 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
72 if (FT_Init_FreeType (&library))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
73 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
74 ::error ("unable to initialize freetype library");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
75 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
76
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
77 #if HAVE_FONTCONFIG
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
78 fc_init_done = false;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
79 if (! FcInit ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
80 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
81 ::error ("unable to initialize fontconfig library");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
82 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
83 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
84 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
85 fc_init_done = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
86 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
87 #endif
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
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
90 ~ft_manager (void)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
91 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
92 #if HAVE_FONTCONFIG
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
93 FcFini ();
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
94 fc_init_done = false;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
95 #endif
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
96 }
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 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
99 const std::string& angle, double size)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
100 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
101 FT_Face retval = 0;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
102
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
103 std::string file;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
104
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
105 #if HAVE_FONTCONFIG
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
106 if (fc_init_done)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
107 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
108 int fc_weight, fc_angle;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
109
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
110 if (weight == "bold")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
111 fc_weight = FC_WEIGHT_BOLD;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
112 else if (weight == "light")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
113 fc_weight = FC_WEIGHT_LIGHT;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
114 else if (weight == "demi")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
115 fc_weight = FC_WEIGHT_DEMIBOLD;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
116 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
117 fc_weight = FC_WEIGHT_NORMAL;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
118
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
119 if (angle == "italic")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
120 fc_angle = FC_SLANT_ITALIC;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
121 else if (angle == "oblique")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
122 fc_angle = FC_SLANT_OBLIQUE;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
123 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
124 fc_angle = FC_SLANT_ROMAN;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
125
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
126 FcPattern *pat = FcPatternCreate ();
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
127
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
128 FcPatternAddString (pat, FC_FAMILY,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
129 (reinterpret_cast<const FcChar8*>
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
130 (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
131
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
132 FcPatternAddInteger (pat, FC_WEIGHT, fc_weight);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
133 FcPatternAddInteger (pat, FC_SLANT, fc_angle);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
134 FcPatternAddDouble (pat, FC_PIXEL_SIZE, size);
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
135
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
136 if (FcConfigSubstitute (0, pat, FcMatchPattern))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
137 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
138 FcResult res;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
139 FcPattern *match;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
140
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
141 FcDefaultSubstitute (pat);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
142 match = FcFontMatch (0, pat, &res);
9833
637fa784d102 Allow more font matches
godfrey@isl.Stanford.EDU
parents: 9619
diff changeset
143
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
144 // FIXME -- originally, this test also required that
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
145 // res != FcResultNoMatch. Is that really needed?
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
146 if (match)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
147 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
148 unsigned char *tmp;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
149
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
150 FcPatternGetString (match, FC_FILE, 0, &tmp);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
151 file = reinterpret_cast<char*> (tmp);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
152 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
153 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
154 ::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
155 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
156 size);
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
157
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
158 if (match)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
159 FcPatternDestroy (match);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
160 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
161
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
162 FcPatternDestroy (pat);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
163 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
164 #endif
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
165
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
166 if (file.empty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
167 {
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
168 #ifdef __WIN32__
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
169 file = "C:/WINDOWS/Fonts/verdana.ttf";
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
170 #else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
171 // FIXME: find a "standard" font for UNIX platforms
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
172 #endif
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
173 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
174
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
175 if (! file.empty () && FT_New_Face (library, file.c_str (), 0, &retval))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
176 ::warning ("ft_manager: unable to load font: %s", file.c_str ());
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
177
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
178 return retval;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
179 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
180
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
181 private:
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
182 FT_Library library;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
183 #if HAVE_FONTCONFIG
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
184 bool fc_init_done;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
185 #endif
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
186 };
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
187
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
188 ft_manager* ft_manager::instance = 0;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
189
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
190 // ---------------------------------------------------------------------------
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
191
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
192 ft_render::ft_render (void)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
193 : text_processor (), face (0), bbox (1, 4, 0.0),
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
194 xoffset (0), yoffset (0), mode (MODE_BBOX),
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
195 red (0), green (0), blue (0)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
196 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
197 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
198
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
199 ft_render::~ft_render (void)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
200 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
201 if (face)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
202 FT_Done_Face (face);
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
203 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
204
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
205 void
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
206 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
207 const std::string& angle, double size)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
208 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
209 if (face)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
210 FT_Done_Face (face);
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
211
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
212 // FIXME: take "fontunits" into account
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
213 face = ft_manager::get_font (name, weight, angle, size);
9403
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 if (face)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
216 {
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
217 if (FT_Set_Char_Size (face, 0, size*64, 0, 0))
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
218 ::warning ("ft_render: unable to set font size to %d", size);
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
219 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
220 else
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
221 ::warning ("ft_render: unable to load appropriate font");
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
222 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
223
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
224 void
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
225 ft_render::set_mode (int m)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
226 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
227 mode = m;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
228
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
229 switch (mode)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
230 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
231 case MODE_BBOX:
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
232 xoffset = yoffset = 0;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
233 bbox = Matrix (1, 4, 0.0);
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
234 break;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
235 case MODE_RENDER:
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
236 if (bbox.numel () != 4)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
237 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
238 ::warning ("ft_render: invalid bounding box, cannot render");
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
239
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
240 xoffset = yoffset = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
241 pixels = uint8NDArray ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
242 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
243 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
244 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
245 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
246 static_cast<uint8_t> (0));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
247 xoffset = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
248 yoffset = -bbox(1)-1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
249 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
250 break;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
251 default:
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
252 ::error ("ft_render: invalid mode `%d'", mode);
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
253 break;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
254 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
255 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
256
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
257 void
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
258 ft_render::visit (text_element_string& e)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
259 {
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
260 if (face)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
261 {
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
262 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
263 FT_UInt glyph_index, previous = 0;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
264
10553
f88e3d5d88e2 avoid GCC warnings
John W. Eaton <jwe@octave.org>
parents: 10402
diff changeset
265 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
266 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
267 glyph_index = FT_Get_Char_Index (face, str[i]);
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
268
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
269 if (! glyph_index
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
270 || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
271 ::warning ("ft_render: skipping missing glyph for character `%c'",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
272 str[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
273 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
274 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
275 switch (mode)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
276 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
277 case MODE_RENDER:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
278 if (FT_Render_Glyph (face->glyph, FT_RENDER_MODE_NORMAL))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
279 ::warning ("ft_render: unable to render glyph for character `%c'",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
280 str[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
281 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
282 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
283 FT_Bitmap& bitmap = face->glyph->bitmap;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
284 int x0, y0;
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
285
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
286 if (previous)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
287 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
288 FT_Vector delta;
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
289
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
290 FT_Get_Kerning (face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
291 xoffset += (delta.x >> 6);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
292 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
293
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
294 x0 = xoffset+face->glyph->bitmap_left;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
295 y0 = yoffset+face->glyph->bitmap_top;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
296 for (int r = 0; r < bitmap.rows; r++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
297 for (int c = 0; c < bitmap.width; c++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
298 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
299 unsigned char pix = bitmap.buffer[r*bitmap.width+c];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
300 if (x0+c < 0 || x0+c >= pixels.dim2()
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
301 || y0-r < 0 || y0-r >= pixels.dim3())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
302 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
303 //::error ("out-of-bound indexing!!");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
304 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
305 else if (pixels(3, x0+c, y0-r).value () == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
306 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
307 pixels(0, x0+c, y0-r) = red;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
308 pixels(1, x0+c, y0-r) = green;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
309 pixels(2, x0+c, y0-r) = blue;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
310 pixels(3, x0+c, y0-r) = pix;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
311 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
312 }
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
313
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
314 xoffset += (face->glyph->advance.x >> 6);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
315 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
316 break;
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
317
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
318 case MODE_BBOX:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
319 // width
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
320 if (previous)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
321 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
322 FT_Vector delta;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
323
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
324 FT_Get_Kerning (face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
325 bbox(2) += (delta.x >> 6);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
326 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
327 bbox(2) += (face->glyph->advance.x >> 6);
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
328
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
329 int asc, desc;
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
330
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
331 if (false /*tight*/)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
332 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
333 desc = face->glyph->metrics.horiBearingY - face->glyph->metrics.height;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
334 asc = face->glyph->metrics.horiBearingY;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
335 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
336 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
337 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
338 asc = face->size->metrics.ascender;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
339 desc = face->size->metrics.descender;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
340 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
341
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
342 asc = yoffset + (asc >> 6);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
343 desc = yoffset + (desc >> 6);
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
344
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
345 if (desc < bbox(1))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
346 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
347 bbox(3) += (bbox(1) - desc);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
348 bbox(1) = desc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
349 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
350 if (asc > (bbox(3)+bbox(1)))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
351 bbox(3) = asc-bbox(1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
352 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
353 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
354
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
355 previous = glyph_index;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
356 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
357 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
358 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
359 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
360
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
361 void
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
362 ft_render::reset (void)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
363 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
364 set_mode (MODE_BBOX);
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
365 set_color (Matrix (1, 3, 0.0));
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
366 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
367
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
368 void
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
369 ft_render::set_color (Matrix c)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
370 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
371 if (c.numel () == 3)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
372 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
373 red = static_cast<uint8_t> (c(0)*255);
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
374 green = static_cast<uint8_t> (c(1)*255);
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
375 blue = static_cast<uint8_t> (c(2)*255);
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
376 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
377 else
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
378 ::warning ("ft_render::set_color: invalid color");
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
379 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
380
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
381 uint8NDArray
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
382 ft_render::render (text_element* elt, Matrix& box, int rotation)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
383 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
384 set_mode (MODE_BBOX);
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
385 elt->accept (*this);
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
386 box = bbox;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
387
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
388 set_mode (MODE_RENDER);
9406
c0c23dbbade7 Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9405
diff changeset
389 if (pixels.numel () > 0)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
390 {
9406
c0c23dbbade7 Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9405
diff changeset
391 elt->accept (*this);
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
392
9406
c0c23dbbade7 Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9405
diff changeset
393 switch (rotation)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
394 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
395 case ROTATION_0:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
396 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
397 case ROTATION_90:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
398 {
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
399 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
400 perm(0) = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
401 perm(1) = 2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
402 perm(2) = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
403 pixels = pixels.permute (perm);
9406
c0c23dbbade7 Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9405
diff changeset
404
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
405 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
406 idx(0) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
407 idx(1) = idx_vector (pixels.dim2()-1, -1, -1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
408 idx(2) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
409 pixels = uint8NDArray (pixels.index (idx));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
410 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
411 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
412 case ROTATION_180:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
413 {
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
414 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
415 idx(0) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
416 idx(1) = idx_vector (pixels.dim2()-1, -1, -1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
417 idx(2)= idx_vector (pixels.dim3()-1, -1, -1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
418 pixels = uint8NDArray (pixels.index (idx));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
419 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
420 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
421 case ROTATION_270:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
422 {
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
423 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
424 perm(0) = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
425 perm(1) = 2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
426 perm(2) = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
427 pixels = pixels.permute (perm);
9406
c0c23dbbade7 Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9405
diff changeset
428
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
429 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
430 idx(0) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
431 idx(1) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
432 idx(2) = idx_vector (pixels.dim3()-1, -1, -1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
433 pixels = uint8NDArray (pixels.index (idx));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
434 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
435 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
436 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
437 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
438
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
439 return pixels;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
440 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
441
10402
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
442 Matrix
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
443 ft_render::get_extent (text_element *elt, double rotation)
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
444 {
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
445 set_mode (MODE_BBOX);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
446 elt->accept (*this);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
447
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
448 Matrix extent (1, 2, 0.0);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
449
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
450 switch (rotation_to_mode (rotation))
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
451 {
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
452 case ROTATION_0:
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
453 case ROTATION_180:
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
454 extent(0) = bbox(2);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
455 extent(1) = bbox(3);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
456 break;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
457 case ROTATION_90:
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
458 case ROTATION_270:
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
459 extent(0) = bbox(3);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
460 extent(1) = bbox(2);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
461 }
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
462
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
463 return extent;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
464 }
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
465
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
466 int
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
467 ft_render::rotation_to_mode (double rotation) const
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
468 {
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
469 if (rotation == 0.0)
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
470 return ROTATION_0;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
471 else if (rotation == 90.0)
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
472 return ROTATION_90;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
473 else if (rotation == 180.0)
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
474 return ROTATION_180;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
475 else if (rotation == 270.0)
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
476 return ROTATION_270;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
477 else
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
478 return ROTATION_0;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
479 }
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
480
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
481 void
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
482 ft_render::text_to_pixels (const std::string& txt,
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
483 uint8NDArray& pixels_, Matrix& box,
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
484 int halign, int valign, double rotation)
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
485 {
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
486 // FIXME: clip "rotation" between 0 and 360
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
487 int rot_mode = rotation_to_mode (rotation);
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
488
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
489 text_element *elt = text_parser_none ().parse (txt);
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
490 pixels_ = render (elt, box, rot_mode);
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
491 delete elt;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
492
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
493 if (pixels_.numel () == 0)
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
494 {
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
495 // nothing to render
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
496 return;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
497 }
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
498
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
499 switch (halign)
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
500 {
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
501 default: box(0) = 0; break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
502 case 1: box(0) = -box(2)/2; break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
503 case 2: box(0) = -box(2); break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
504 }
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
505 switch (valign)
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
506 {
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
507 default: box(1) = 0; break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
508 case 1: box(1) = -box(3)/2; break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
509 case 2: box(1) = -box(3); break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
510 case 3: break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
511 }
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
512
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
513 switch (rot_mode)
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
514 {
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
515 case ROTATION_90:
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
516 std::swap (box(0), box(1));
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
517 std::swap (box(2), box(3));
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
518 box(0) = -box(0)-box(2);
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
519 break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
520 case ROTATION_180:
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
521 box(0) = -box(0)-box(2);
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
522 box(1) = -box(1)-box(3);
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
523 break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
524 case ROTATION_270:
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
525 std::swap (box(0), box(1));
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
526 std::swap (box(2), box(3));
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
527 box(1) = -box(1)-box(3);
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
528 break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
529 }
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
530 }
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
531
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
532 #endif // HAVE_FREETYPE