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