Added copyright lines for files I've edited this year.
[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 Header file for implementation of the "Text" layer
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007, 2008 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         synfig::Color color_func(const synfig::Point &x, int quality=10, float supersample=0)const;
138
139         mutable synfig::Mutex mutex;
140
141 public:
142         Layer_Freetype();
143         virtual ~Layer_Freetype();
144
145         virtual bool set_param(const String & param, const synfig::ValueBase &value);
146         virtual ValueBase get_param(const String & param)const;
147         virtual Color get_color(Context context, const synfig::Point &pos)const;
148         virtual bool accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const;
149
150         virtual Vocab get_param_vocab()const;
151
152         virtual bool set_version(const String &ver){if(ver=="0.1")old_version=true;return true;}
153         virtual void reset_version(){old_version=false;}
154
155         virtual synfig::Rect get_bounding_rect()const;
156
157 private:
158         void new_font(const synfig::String &family, int style=0, int weight=400);
159         bool new_font_(const synfig::String &family, int style=0, int weight=400);
160         bool new_face(const synfig::String &newfont);
161 };
162
163 extern FT_Library ft_library;
164
165 /* === E N D =============================================================== */
166
167 #endif