Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_07_rc3 / src / modules / lyr_freetype / lyr_freetype.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file lyr_freetype.h
3 **      \brief Template Header
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 **
22 ** === N O T E S ===========================================================
23 **
24 ** ========================================================================= */
25
26 /* === S T A R T =========================================================== */
27
28 #ifndef __SYNFIG_LYR_FREETYPE_H
29 #define __SYNFIG_LYR_FREETYPE_H
30
31 /* === H E A D E R S ======================================================= */
32
33 //#ifdef __APPLE__
34 //#define USE_MAC_FT_FUNCS      (1)
35 //#endif
36
37 #include <synfig/layer_composite.h>
38 #include <synfig/vector.h>
39 #include <synfig/color.h>
40 #include <synfig/string.h>
41
42 #include <ft2build.h>
43 #include FT_FREETYPE_H
44 #include FT_GLYPH_H
45 #include <vector>
46
47 #include <synfig/string.h>
48 #include <synfig/time.h>
49 #include <synfig/context.h>
50 #include <synfig/paramdesc.h>
51 #include <synfig/renddesc.h>
52 #include <synfig/surface.h>
53 #include <synfig/value.h>
54 #include <synfig/valuenode.h>
55 #include <synfig/canvas.h>
56
57
58 #include <ETL/misc>
59
60 #ifdef USE_MAC_FT_FUNCS
61         #include <CoreServices/CoreServices.h>
62         #include FT_MAC_H
63 #endif
64
65 /* === M A C R O S ========================================================= */
66
67 /* === T Y P E D E F S ===================================================== */
68
69 /* === C L A S S E S & S T R U C T S ======================================= */
70
71 using namespace synfig;
72 using namespace std;
73 using namespace etl;
74
75
76 struct Glyph
77 {
78         FT_Glyph glyph;
79         FT_Vector pos;
80         //int width;
81 };
82 struct TextLine
83 {
84         int width;
85         std::vector<Glyph> glyph_table;
86
87         TextLine():width(0) { }
88         void clear_and_free();
89
90         int actual_height()const
91         {
92                 int height(0);
93
94                 std::vector<Glyph>::const_iterator iter;
95                 for(iter=glyph_table.begin();iter!=glyph_table.end();++iter)
96                 {
97                         FT_BBox   glyph_bbox;
98
99                         //FT_Glyph_Get_CBox( glyphs[n], ft_glyph_bbox_pixels, &glyph_bbox );
100                         FT_Glyph_Get_CBox( iter->glyph, ft_glyph_bbox_subpixels, &glyph_bbox );
101
102                         if(glyph_bbox.yMax>height)
103                                 height=glyph_bbox.yMax;
104                 }
105                 return height;
106         }
107 };
108
109
110 class Layer_Freetype : public synfig::Layer_Composite, public synfig::Layer_NoDeform
111 {
112         SYNFIG_LAYER_MODULE_EXT
113 private:
114
115         FT_Face face;
116         synfig::String font;
117         synfig::String family;
118         synfig::String text;
119         synfig::Vector size;
120         synfig::Vector orient;
121         synfig::Color color;
122         synfig::Point pos;
123         synfig::Real compress;
124         synfig::Real vcompress;
125
126         int style;
127         int weight;
128         bool use_kerning;
129         bool grid_fit;
130         bool invert;
131
132         bool old_version;
133         bool needs_sync_;
134
135         void sync();
136
137         mutable synfig::Mutex mutex;
138
139 public:
140         Layer_Freetype();
141         virtual ~Layer_Freetype();
142
143         virtual bool set_param(const String & param, const synfig::ValueBase &value);
144         virtual ValueBase get_param(const String & param)const;
145         virtual Color get_color(Context context, const synfig::Point &pos)const;
146         virtual bool accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const;
147
148         virtual Vocab get_param_vocab()const;
149
150         virtual bool set_version(const String &ver){if(ver=="0.1")old_version=true;return true;}
151         virtual void reset_version(){old_version=false;}
152
153         virtual synfig::Rect get_bounding_rect()const;
154
155 private:
156         void new_font(const synfig::String &family, int style=0, int weight=400);
157         bool new_font_(const synfig::String &family, int style=0, int weight=400);
158         bool new_face(const synfig::String &newfont);
159 };
160
161 extern FT_Library ft_library;
162
163 /* === E N D =============================================================== */
164
165 #endif