Fixing warnings from doxygen:
[synfig.git] / synfig-core / trunk / 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 **      \legal
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 **      \endlegal
18 **
19 ** === N O T E S ===========================================================
20 **
21 ** ========================================================================= */
22
23 /* === S T A R T =========================================================== */
24
25 #ifndef __SYNFIG_LYR_FREETYPE_H
26 #define __SYNFIG_LYR_FREETYPE_H
27
28 /* === H E A D E R S ======================================================= */
29
30 //#ifdef __APPLE__
31 //#define USE_MAC_FT_FUNCS      (1)
32 //#endif
33
34 #include <synfig/layer_composite.h>
35 #include <synfig/vector.h>
36 #include <synfig/color.h>
37 #include <synfig/string.h>
38
39 #include <ft2build.h>
40 #include FT_FREETYPE_H
41 #include FT_GLYPH_H
42 #include <vector>
43
44 #include <synfig/string.h>
45 #include <synfig/time.h>
46 #include <synfig/context.h>
47 #include <synfig/paramdesc.h>
48 #include <synfig/renddesc.h>
49 #include <synfig/surface.h>
50 #include <synfig/value.h>
51 #include <synfig/valuenode.h>
52 #include <synfig/canvas.h>
53
54
55 #include <ETL/misc>
56
57 #ifdef USE_MAC_FT_FUNCS
58         #include <CoreServices/CoreServices.h>
59         #include FT_MAC_H
60 #endif
61
62 /* === M A C R O S ========================================================= */
63
64 /* === T Y P E D E F S ===================================================== */
65
66 /* === C L A S S E S & S T R U C T S ======================================= */
67
68 using namespace synfig;
69 using namespace std;
70 using namespace etl;
71
72
73 struct Glyph
74 {
75         FT_Glyph glyph;
76         FT_Vector pos;
77         //int width;
78 };
79 struct TextLine
80 {
81         int width;
82         std::vector<Glyph> glyph_table;
83
84         TextLine():width(0) { }
85         void clear_and_free();
86
87         int actual_height()const
88         {
89                 int height(0);
90
91                 std::vector<Glyph>::const_iterator iter;
92                 for(iter=glyph_table.begin();iter!=glyph_table.end();++iter)
93                 {
94                         FT_BBox   glyph_bbox;
95
96                         //FT_Glyph_Get_CBox( glyphs[n], ft_glyph_bbox_pixels, &glyph_bbox );
97                         FT_Glyph_Get_CBox( iter->glyph, ft_glyph_bbox_subpixels, &glyph_bbox );
98
99                         if(glyph_bbox.yMax>height)
100                                 height=glyph_bbox.yMax;
101                 }
102                 return height;
103         }
104 };
105
106
107 class lyr_freetype : public synfig::Layer_Composite, public synfig::Layer_NoDeform
108 {
109         SYNFIG_LAYER_MODULE_EXT
110 private:
111
112         FT_Face face;
113         synfig::String font;
114         synfig::String family;
115         synfig::String text;
116         synfig::Vector size;
117         synfig::Vector orient;
118         synfig::Color color;
119         synfig::Point pos;
120         synfig::Real compress;
121         synfig::Real vcompress;
122
123         int style;
124         int weight;
125         bool use_kerning;
126         bool grid_fit;
127         bool invert;
128
129         bool old_version;
130         bool needs_sync_;
131
132         void sync();
133
134         mutable synfig::Mutex mutex;
135
136 public:
137         lyr_freetype();
138         virtual ~lyr_freetype();
139
140         virtual bool set_param(const String & param, const synfig::ValueBase &value);
141         virtual ValueBase get_param(const String & param)const;
142         virtual Color get_color(Context context, const synfig::Point &pos)const;
143         virtual bool accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const;
144
145         virtual Vocab get_param_vocab()const;
146
147         virtual bool set_version(const String &ver){if(ver=="0.1")old_version=true;return true;}
148         virtual void reset_version(){old_version=false;}
149
150         virtual synfig::Rect get_bounding_rect()const;
151
152 private:
153         void new_font(const synfig::String &family, int style=0, int weight=400);
154         bool new_font_(const synfig::String &family, int style=0, int weight=400);
155         bool new_face(const synfig::String &newfont);
156 };
157
158 extern FT_Library ft_library;
159
160 /* === E N D =============================================================== */
161
162 #endif