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