annotate src/txt-eng-ft.cc @ 13141:e81ddf9cacd5

maint: untabify and remove trailing whitespace from source files * bicg.m, gmres.m, pkg.m: Untabify and remove trailing whitespace. * libcruft/Makefile.am, libcruft/blas-xtra/cdotc3.f, libcruft/blas-xtra/cmatm3.f, libcruft/blas-xtra/ddot3.f, libcruft/blas-xtra/dmatm3.f, libcruft/blas-xtra/sdot3.f, libcruft/blas-xtra/smatm3.f, libcruft/blas-xtra/zdotc3.f, libcruft/blas-xtra/zmatm3.f, libcruft/lapack-xtra/crsf2csf.f, libcruft/lapack-xtra/zrsf2csf.f, liboctave/Array.cc, liboctave/DASPK-opts.in, liboctave/DASRT-opts.in, liboctave/DASSL-opts.in, liboctave/LSODE-opts.in, liboctave/Makefile.a,mliboctave/Quad-opts.in, liboctave/Sparse-perm-op-defs.h, scripts/Makefile.a,mscripts/deprecated/glpkmex.m, scripts/general/blkdiag.m, scripts/general/interp1.m, scripts/general/profshow.m, scripts/general/quadl.m, scripts/general/triplequad.m, scripts/help/__makeinfo__.m, scripts/io/strread.m, scripts/io/textread.m, scripts/io/textscan.m, scripts/linear-algebra/rank.m, scripts/miscellaneous/gzip.m, scripts/miscellaneous/private/__xzip__.m, scripts/miscellaneous/tempdir.m, scripts/miscellaneous/unpack.m, scripts/pkg/pkg.m, scripts/plot/allchild.m, scripts/plot/ancestor.m, scripts/plot/cla.m, scripts/plot/clf.m, scripts/plot/findall.m, scripts/plot/findobj.m, scripts/plot/gca.m, scripts/plot/gcf.m, scripts/plot/hggroup.m, scripts/plot/isfigure.m, scripts/plot/ishghandle.m, scripts/plot/legend.m, scripts/plot/line.m, scripts/plot/loglog.m, scripts/plot/patch.m, scripts/plot/print.m, scripts/plot/private/__quiver__.m, scripts/plot/private/__scatter__.m, scripts/plot/rectangle.m, scripts/plot/semilogx.m, scripts/plot/semilogy.m, scripts/plot/surface.m, scripts/plot/text.m, scripts/plot/title.m, scripts/plot/trisurf.m, scripts/plot/view.m, scripts/plot/whitebg.m, scripts/plot/xlabel.m, scripts/plot/xlim.m, scripts/plot/ylabel.m, scripts/plot/ylim.m, scripts/plot/zlabel.m, scripts/plot/zlim.m, scripts/polynomial/mkpp.m, scripts/polynomial/polygcd.m, scripts/polynomial/ppint.m, scripts/polynomial/ppjumps.m, scripts/polynomial/ppval.m, scripts/set/setxor.m, scripts/sparse/bicgstab.m, scripts/sparse/cgs.m, scripts/sparse/spconvert.m, scripts/specfun/nthroot.m, scripts/strings/strmatch.m, scripts/strings/untabify.m, scripts/testfun/demo.m, scripts/testfun/example.m, src/DLD-FUNCTIONS/filter.cc, src/DLD-FUNCTIONS/mgorth.cc, src/DLD-FUNCTIONS/quadcc.cc, src/DLD-FUNCTIONS/str2double.cc, src/Makefile.a,msrc/gl-render.cc, src/gl2ps-renderer.cc, src/graphics.cc, src/octave-config.cc.in, src/octave-config.in, src/ov-class.h, src/ov-fcn.h, src/profiler.cc, src/profiler.h, src/pt-binop.cc, src/pt-unop.cc, src/symtab.cc, src/txt-eng-ft.cc: Remove trailing whitespace.
author John W. Eaton <jwe@octave.org>
date Thu, 15 Sep 2011 12:51:10 -0400
parents 6fc2c61660f2
children d2b799e3178a
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:
12122
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
67
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
68 static ft_manager *instance;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
69
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
70 private:
12122
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
71
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
72 // No copying!
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
73
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
74 ft_manager (const ft_manager&);
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
75
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
76 ft_manager& operator = (const ft_manager&);
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
77
12225
cb4ac5e4d987 txt-eng-ft.cc (ft_manager::ft_manager): omit fc_init_done from init list if fontconfig is missing
John W. Eaton <jwe@octave.org>
parents: 12123
diff changeset
78 ft_manager (void) : library ()
cb4ac5e4d987 txt-eng-ft.cc (ft_manager::ft_manager): omit fc_init_done from init list if fontconfig is missing
John W. Eaton <jwe@octave.org>
parents: 12123
diff changeset
79 #if HAVE_FONTCONFIG
cb4ac5e4d987 txt-eng-ft.cc (ft_manager::ft_manager): omit fc_init_done from init list if fontconfig is missing
John W. Eaton <jwe@octave.org>
parents: 12123
diff changeset
80 , fc_init_done (false)
cb4ac5e4d987 txt-eng-ft.cc (ft_manager::ft_manager): omit fc_init_done from init list if fontconfig is missing
John W. Eaton <jwe@octave.org>
parents: 12123
diff changeset
81 #endif
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
82 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
83 if (FT_Init_FreeType (&library))
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 ::error ("unable to initialize freetype library");
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
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
88 #if HAVE_FONTCONFIG
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
89 fc_init_done = false;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
90 if (! FcInit ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
91 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
92 ::error ("unable to initialize fontconfig library");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
93 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
94 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
95 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
96 fc_init_done = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
97 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
98 #endif
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
99 }
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_manager (void)
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 #if HAVE_FONTCONFIG
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
104 FcFini ();
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
105 fc_init_done = false;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
106 #endif
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
107 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
108
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
109 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
110 const std::string& angle, double size)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
111 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
112 FT_Face retval = 0;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
113
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
114 std::string file;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
115
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
116 #if HAVE_FONTCONFIG
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
117 if (fc_init_done)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
118 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
119 int fc_weight, fc_angle;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
120
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
121 if (weight == "bold")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
122 fc_weight = FC_WEIGHT_BOLD;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
123 else if (weight == "light")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
124 fc_weight = FC_WEIGHT_LIGHT;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
125 else if (weight == "demi")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
126 fc_weight = FC_WEIGHT_DEMIBOLD;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
127 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
128 fc_weight = FC_WEIGHT_NORMAL;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
129
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
130 if (angle == "italic")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
131 fc_angle = FC_SLANT_ITALIC;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
132 else if (angle == "oblique")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
133 fc_angle = FC_SLANT_OBLIQUE;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
134 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
135 fc_angle = FC_SLANT_ROMAN;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
136
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
137 FcPattern *pat = FcPatternCreate ();
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
138
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
139 FcPatternAddString (pat, FC_FAMILY,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
140 (reinterpret_cast<const FcChar8*>
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
141 (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
142
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
143 FcPatternAddInteger (pat, FC_WEIGHT, fc_weight);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
144 FcPatternAddInteger (pat, FC_SLANT, fc_angle);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
145 FcPatternAddDouble (pat, FC_PIXEL_SIZE, size);
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
146
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
147 if (FcConfigSubstitute (0, pat, FcMatchPattern))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
148 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
149 FcResult res;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
150 FcPattern *match;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
151
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
152 FcDefaultSubstitute (pat);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
153 match = FcFontMatch (0, pat, &res);
9833
637fa784d102 Allow more font matches
godfrey@isl.Stanford.EDU
parents: 9619
diff changeset
154
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
155 // FIXME -- originally, this test also required that
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
156 // res != FcResultNoMatch. Is that really needed?
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
157 if (match)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
158 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
159 unsigned char *tmp;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
160
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
161 FcPatternGetString (match, FC_FILE, 0, &tmp);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
162 file = reinterpret_cast<char*> (tmp);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
163 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
164 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
165 ::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
166 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
167 size);
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
168
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
169 if (match)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
170 FcPatternDestroy (match);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
171 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
172
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
173 FcPatternDestroy (pat);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
174 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
175 #endif
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
176
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
177 if (file.empty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
178 {
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
179 #ifdef __WIN32__
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
180 file = "C:/WINDOWS/Fonts/verdana.ttf";
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
181 #else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
182 // FIXME: find a "standard" font for UNIX platforms
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
183 #endif
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
184 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
185
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
186 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
187 ::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
188
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
189 return retval;
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 private:
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
193 FT_Library library;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
194 #if HAVE_FONTCONFIG
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
195 bool fc_init_done;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
196 #endif
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_manager* ft_manager::instance = 0;
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 // ---------------------------------------------------------------------------
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
202
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
203 ft_render::ft_render (void)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
204 : text_processor (), face (0), bbox (1, 4, 0.0),
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 12969
diff changeset
205 xoffset (0), yoffset (0), multiline_halign (0),
12969
6fc2c61660f2 Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents: 12965
diff changeset
206 multiline_align_xoffsets(), mode (MODE_BBOX),
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
207 red (0), green (0), blue (0)
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 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
210
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
211 ft_render::~ft_render (void)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
212 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
213 if (face)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
214 FT_Done_Face (face);
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
215 }
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 void
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
218 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
219 const std::string& angle, double size)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
220 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
221 if (face)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
222 FT_Done_Face (face);
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 // FIXME: take "fontunits" into account
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
225 face = ft_manager::get_font (name, weight, angle, size);
9403
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 if (face)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
228 {
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
229 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
230 ::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
231 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
232 else
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
233 ::warning ("ft_render: unable to load appropriate font");
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
234 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
235
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
236 void
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
237 ft_render::set_mode (int m)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
238 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
239 mode = m;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
240
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
241 switch (mode)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
242 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
243 case MODE_BBOX:
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
244 xoffset = yoffset = 0;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
245 bbox = Matrix (1, 4, 0.0);
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
246 break;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
247 case MODE_RENDER:
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
248 if (bbox.numel () != 4)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
249 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
250 ::warning ("ft_render: invalid bounding box, cannot render");
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
251
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
252 xoffset = yoffset = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
253 pixels = uint8NDArray ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
254 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
255 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
256 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
257 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
258 static_cast<uint8_t> (0));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
259 xoffset = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
260 yoffset = -bbox(1)-1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
261 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
262 break;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
263 default:
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
264 ::error ("ft_render: invalid mode `%d'", mode);
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
265 break;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
266 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
267 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
268
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
269 void
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
270 ft_render::visit (text_element_string& e)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
271 {
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
272 if (face)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
273 {
12969
6fc2c61660f2 Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents: 12965
diff changeset
274 int line_index = 0;
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
275 FT_UInt box_line_width = 0;
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
276 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
277 FT_UInt glyph_index, previous = 0;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
278
12969
6fc2c61660f2 Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents: 12965
diff changeset
279 if (mode == MODE_BBOX)
6fc2c61660f2 Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents: 12965
diff changeset
280 multiline_align_xoffsets.clear();
6fc2c61660f2 Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents: 12965
diff changeset
281 else if (mode == MODE_RENDER)
6fc2c61660f2 Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents: 12965
diff changeset
282 xoffset += multiline_align_xoffsets[line_index];
6fc2c61660f2 Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents: 12965
diff changeset
283
10553
f88e3d5d88e2 avoid GCC warnings
John W. Eaton <jwe@octave.org>
parents: 10402
diff changeset
284 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
285 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
286 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
287
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 12969
diff changeset
288 if (str[i] != '\n'
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
289 && (! glyph_index
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
290 || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT)))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
291 ::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
292 str[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
293 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
294 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
295 switch (mode)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
296 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
297 case MODE_RENDER:
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
298 if (str[i] == '\n')
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
299 {
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
300 glyph_index = FT_Get_Char_Index(face, ' ');
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
301 if (!glyph_index || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT))
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
302 {
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
303 ::warning ("ft_render: skipping missing glyph for character ` '");
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 12969
diff changeset
304 }
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 12969
diff changeset
305 else
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
306 {
12969
6fc2c61660f2 Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents: 12965
diff changeset
307 line_index++;
6fc2c61660f2 Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents: 12965
diff changeset
308 xoffset = multiline_align_xoffsets[line_index];
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
309 yoffset -= (face->size->metrics.height >> 6);
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
310 }
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 12969
diff changeset
311 }
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
312 else if (FT_Render_Glyph (face->glyph, FT_RENDER_MODE_NORMAL))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
313 ::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
314 str[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
315 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
316 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
317 FT_Bitmap& bitmap = face->glyph->bitmap;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
318 int x0, y0;
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
319
10315
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;
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
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 xoffset += (delta.x >> 6);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
326 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
327
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
328 x0 = xoffset+face->glyph->bitmap_left;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
329 y0 = yoffset+face->glyph->bitmap_top;
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
330
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
331 // 'w' seems to have a negative -1
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
332 // face->glyph->bitmap_left, this is so we don't
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
333 // index out of bound, and assumes we we allocated
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
334 // the right amount of horizontal space in the bbox.
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
335 if (x0 < 0)
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
336 x0 = 0;
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
337
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
338 for (int r = 0; r < bitmap.rows; r++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
339 for (int c = 0; c < bitmap.width; c++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
340 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
341 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
342 if (x0+c < 0 || x0+c >= pixels.dim2()
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
343 || y0-r < 0 || y0-r >= pixels.dim3())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
344 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
345 //::error ("out-of-bound indexing!!");
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 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
348 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
349 pixels(0, x0+c, y0-r) = red;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
350 pixels(1, x0+c, y0-r) = green;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
351 pixels(2, x0+c, y0-r) = blue;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
352 pixels(3, x0+c, y0-r) = pix;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
353 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
354 }
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
355
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
356 xoffset += (face->glyph->advance.x >> 6);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
357 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
358 break;
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
359
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
360 case MODE_BBOX:
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
361 if (str[i] == '\n')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
362 {
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
363 glyph_index = FT_Get_Char_Index(face, ' ');
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
364 if (! glyph_index
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
365 || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT))
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
366 {
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
367 ::warning ("ft_render: skipping missing glyph for character ` '");
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
368 }
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
369 else
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
370 {
12969
6fc2c61660f2 Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents: 12965
diff changeset
371 multiline_align_xoffsets.push_back(box_line_width);
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
372 // Reset the pixel width for this newline, so we don't
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
373 // allocate a bounding box larger than the horizontal
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
374 // width of the multi-line
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 12969
diff changeset
375 box_line_width = 0;
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
376 bbox(1) -= (face->size->metrics.height >> 6);
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
377 }
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 12969
diff changeset
378 }
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 12969
diff changeset
379 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
380 {
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
381 // width
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
382 if (previous)
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
383 {
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
384 FT_Vector delta;
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
385
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
386 FT_Get_Kerning (face, previous, glyph_index,
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
387 FT_KERNING_DEFAULT, &delta);
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
388
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
389 box_line_width += (delta.x >> 6);
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
390 }
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
391
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
392 box_line_width += (face->glyph->advance.x >> 6);
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
393
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
394 int asc, desc;
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
395
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
396 if (false /*tight*/)
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
397 {
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
398 desc = face->glyph->metrics.horiBearingY - face->glyph->metrics.height;
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
399 asc = face->glyph->metrics.horiBearingY;
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
400 }
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
401 else
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
402 {
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
403 asc = face->size->metrics.ascender;
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
404 desc = face->size->metrics.descender;
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
405 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
406
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
407 asc = yoffset + (asc >> 6);
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
408 desc = yoffset + (desc >> 6);
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
409
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
410 if (desc < bbox(1))
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
411 {
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
412 bbox(3) += (bbox(1) - desc);
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
413 bbox(1) = desc;
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
414 }
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
415 if (asc > (bbox(3)+bbox(1)))
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
416 bbox(3) = asc-bbox(1);
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
417 if (bbox(2) < box_line_width)
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
418 bbox(2) = box_line_width;
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
419 }
10315
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 }
12965
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
422 if (str[i] == '\n')
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
423 previous = 0;
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
424 else
22bc9ec80c2c allow multi-line string property for text objects using cell arrays or char matrices
Ben Abbott <bpabbott@mac.com>
parents: 12334
diff changeset
425 previous = glyph_index;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
426 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
427 }
12969
6fc2c61660f2 Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents: 12965
diff changeset
428 if (mode == MODE_BBOX)
6fc2c61660f2 Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents: 12965
diff changeset
429 {
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 12969
diff changeset
430 /* Push last the width associated with the last line */
12969
6fc2c61660f2 Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents: 12965
diff changeset
431 multiline_align_xoffsets.push_back(box_line_width);
6fc2c61660f2 Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents: 12965
diff changeset
432
6fc2c61660f2 Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents: 12965
diff changeset
433 for (unsigned int i = 0; i < multiline_align_xoffsets.size(); i++)
6fc2c61660f2 Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents: 12965
diff changeset
434 {
6fc2c61660f2 Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents: 12965
diff changeset
435 /* Center align */
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 12969
diff changeset
436 if (multiline_halign == 1)
12969
6fc2c61660f2 Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents: 12965
diff changeset
437 multiline_align_xoffsets[i] = (bbox(2) - multiline_align_xoffsets[i])/2;
6fc2c61660f2 Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents: 12965
diff changeset
438 /* Right align */
6fc2c61660f2 Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents: 12965
diff changeset
439 else if (multiline_halign == 2)
6fc2c61660f2 Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents: 12965
diff changeset
440 multiline_align_xoffsets[i] = (bbox(2) - multiline_align_xoffsets[i]);
6fc2c61660f2 Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents: 12965
diff changeset
441 /* Left align */
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 12969
diff changeset
442 else
12969
6fc2c61660f2 Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents: 12965
diff changeset
443 multiline_align_xoffsets[i] = 0;
6fc2c61660f2 Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents: 12965
diff changeset
444 }
6fc2c61660f2 Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents: 12965
diff changeset
445 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
446 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
447 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
448
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
449 void
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
450 ft_render::reset (void)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
451 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
452 set_mode (MODE_BBOX);
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
453 set_color (Matrix (1, 3, 0.0));
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
454 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
455
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
456 void
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
457 ft_render::set_color (Matrix c)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
458 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
459 if (c.numel () == 3)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
460 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
461 red = static_cast<uint8_t> (c(0)*255);
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
462 green = static_cast<uint8_t> (c(1)*255);
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
463 blue = static_cast<uint8_t> (c(2)*255);
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
464 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
465 else
9616
2093499ec9f4 avoid crash if default font can't be found
John W. Eaton <jwe@octave.org>
parents: 9406
diff changeset
466 ::warning ("ft_render::set_color: invalid color");
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
467 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
468
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
469 uint8NDArray
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
470 ft_render::render (text_element* elt, Matrix& box, int rotation)
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
471 {
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
472 set_mode (MODE_BBOX);
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
473 elt->accept (*this);
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
474 box = bbox;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
475
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
476 set_mode (MODE_RENDER);
9406
c0c23dbbade7 Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9405
diff changeset
477 if (pixels.numel () > 0)
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
478 {
9406
c0c23dbbade7 Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9405
diff changeset
479 elt->accept (*this);
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
480
9406
c0c23dbbade7 Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9405
diff changeset
481 switch (rotation)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
482 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
483 case ROTATION_0:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
484 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
485 case ROTATION_90:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
486 {
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
487 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
488 perm(0) = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
489 perm(1) = 2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
490 perm(2) = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
491 pixels = pixels.permute (perm);
9406
c0c23dbbade7 Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9405
diff changeset
492
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
493 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
494 idx(0) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
495 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
496 idx(2) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
497 pixels = uint8NDArray (pixels.index (idx));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
498 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
499 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
500 case ROTATION_180:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
501 {
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
502 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
503 idx(0) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
504 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
505 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
506 pixels = uint8NDArray (pixels.index (idx));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
507 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
508 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
509 case ROTATION_270:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
510 {
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
511 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
512 perm(0) = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
513 perm(1) = 2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
514 perm(2) = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
515 pixels = pixels.permute (perm);
9406
c0c23dbbade7 Improve error handling in text rendering.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9405
diff changeset
516
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
517 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
518 idx(0) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
519 idx(1) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
520 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
521 pixels = uint8NDArray (pixels.index (idx));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
522 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
523 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9833
diff changeset
524 }
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
525 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
526
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
527 return pixels;
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
528 }
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
529
10402
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
530 Matrix
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
531 ft_render::get_extent (text_element *elt, double rotation)
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
532 {
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
533 set_mode (MODE_BBOX);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
534 elt->accept (*this);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
535
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
536 Matrix extent (1, 2, 0.0);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
537
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
538 switch (rotation_to_mode (rotation))
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
539 {
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
540 case ROTATION_0:
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
541 case ROTATION_180:
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
542 extent(0) = bbox(2);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
543 extent(1) = bbox(3);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
544 break;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
545 case ROTATION_90:
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
546 case ROTATION_270:
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
547 extent(0) = bbox(3);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
548 extent(1) = bbox(2);
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
549 }
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
550
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
551 return extent;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
552 }
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
553
12334
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
554 Matrix
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
555 ft_render::get_extent (const std::string& txt, double rotation)
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
556 {
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
557 text_element *elt = text_parser_none ().parse (txt);
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
558 Matrix extent = get_extent (elt, rotation);
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
559 delete elt;
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 12969
diff changeset
560
12334
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
561 return extent;
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
562 }
63dc132a1000 Move axes labels and title positioning to axes::properties
Konstantinos Poulios <logari81@gmail.com>
parents: 12225
diff changeset
563
10402
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
564 int
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
565 ft_render::rotation_to_mode (double rotation) const
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
566 {
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
567 if (rotation == 0.0)
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
568 return ROTATION_0;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
569 else if (rotation == 90.0)
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
570 return ROTATION_90;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
571 else if (rotation == 180.0)
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
572 return ROTATION_180;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
573 else if (rotation == 270.0)
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
574 return ROTATION_270;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
575 else
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
576 return ROTATION_0;
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
577 }
9f2bf537a651 Implement text extent property
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10350
diff changeset
578
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
579 void
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
580 ft_render::text_to_pixels (const std::string& txt,
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
581 uint8NDArray& pixels_, Matrix& box,
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
582 int halign, int valign, double rotation)
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
583 {
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
584 // FIXME: clip "rotation" between 0 and 360
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
585 int rot_mode = rotation_to_mode (rotation);
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 12969
diff changeset
586
12969
6fc2c61660f2 Native multi-line text alignment.
Vanya Sergeev <vsergeev@gmail.com>
parents: 12965
diff changeset
587 multiline_halign = halign;
11455
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
588
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
589 text_element *elt = text_parser_none ().parse (txt);
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
590 pixels_ = render (elt, box, rot_mode);
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
591 delete elt;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
592
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
593 if (pixels_.numel () == 0)
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
594 {
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
595 // nothing to render
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
596 return;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
597 }
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
598
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
599 switch (halign)
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
600 {
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
601 default: box(0) = 0; break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
602 case 1: box(0) = -box(2)/2; break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
603 case 2: box(0) = -box(2); break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
604 }
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
605 switch (valign)
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
606 {
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
607 default: box(1) = 0; break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
608 case 1: box(1) = -box(3)/2; break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
609 case 2: box(1) = -box(3); break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
610 case 3: break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
611 }
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
612
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
613 switch (rot_mode)
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
614 {
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
615 case ROTATION_90:
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
616 std::swap (box(0), box(1));
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
617 std::swap (box(2), box(3));
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
618 box(0) = -box(0)-box(2);
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
619 break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
620 case ROTATION_180:
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
621 box(0) = -box(0)-box(2);
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
622 box(1) = -box(1)-box(3);
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
623 break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
624 case ROTATION_270:
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
625 std::swap (box(0), box(1));
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
626 std::swap (box(2), box(3));
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
627 box(1) = -box(1)-box(3);
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
628 break;
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
629 }
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
630 }
2be9e22796d2 improvements in text-extent calculation
Konstantinos Poulios <logari81@googlemail.com>
parents: 10553
diff changeset
631
9403
4af6e29449c1 [mq]: graphics_text_engine
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
632 #endif // HAVE_FREETYPE