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