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