- Main Page
- Related Pages
- Namespaces
- Classes
- Files

# lyr_freetype.h

Go to the documentation of this file.

    00001 /* === S Y N F I G ========================================================= */
    00026 /* === S T A R T =========================================================== */
    00027
    00028 #ifndef __SYNFIG_LYR_FREETYPE_H
    00029 #define __SYNFIG_LYR_FREETYPE_H
    00030
    00031 /* === H E A D E R S ======================================================= */
    00032
    00033 //#ifdef __APPLE__
    00034 //#define USE_MAC_FT_FUNCS  (1)
    00035 //#endif
    00036
    00037 #include <synfig/layer_composite.h>
    00038 #include <synfig/vector.h>
    00039 #include <synfig/color.h>
    00040 #include <synfig/string.h>
    00041
    00042 #include <ft2build.h>
    00043 #include FT_FREETYPE_H
    00044 #include FT_GLYPH_H
    00045 #include <vector>
    00046
    00047 #include <synfig/string.h>
    00048 #include <synfig/time.h>
    00049 #include <synfig/context.h>
    00050 #include <synfig/paramdesc.h>
    00051 #include <synfig/renddesc.h>
    00052 #include <synfig/surface.h>
    00053 #include <synfig/value.h>
    00054 #include <synfig/valuenode.h>
    00055 #include <synfig/canvas.h>
    00056
    00057
    00058 #include <ETL/misc>
    00059
    00060 #ifdef USE_MAC_FT_FUNCS
    00061     #include <CoreServices/CoreServices.h>
    00062     #include FT_MAC_H
    00063 #endif
    00064
    00065 /* === M A C R O S ========================================================= */
    00066
    00067 /* === T Y P E D E F S ===================================================== */
    00068
    00069 /* === C L A S S E S & S T R U C T S ======================================= */
    00070
    00071 using namespace synfig;
    00072 using namespace std;
    00073 using namespace etl;
    00074
    00075
    00076 struct Glyph
    00077 {
    00078     FT_Glyph glyph;
    00079     FT_Vector pos;
    00080     //int width;
    00081 };
    00082 struct TextLine
    00083 {
    00084     int width;
    00085     std::vector<Glyph> glyph_table;
    00086
    00087     TextLine():width(0) { }
    00088     void clear_and_free();
    00089
    00090     int actual_height()const
    00091     {
    00092         int height(0);
    00093
    00094         std::vector<Glyph>::const_iterator iter;
    00095         for(iter=glyph_table.begin();iter!=glyph_table.end();++iter)
    00096         {
    00097             FT_BBox   glyph_bbox;
    00098
    00099             //FT_Glyph_Get_CBox( glyphs[n], ft_glyph_bbox_pixels, &glyph_bbox );
    00100             FT_Glyph_Get_CBox( iter->glyph, ft_glyph_bbox_subpixels, &glyph_bbox );
    00101
    00102             if(glyph_bbox.yMax>height)
    00103                 height=glyph_bbox.yMax;
    00104         }
    00105         return height;
    00106     }
    00107 };
    00108
    00109
    00110 class Layer_Freetype : public synfig::Layer_Composite, public synfig::Layer_NoDeform
    00111 {
    00112     SYNFIG_LAYER_MODULE_EXT
    00113 private:
    00114
    00115     FT_Face face;
    00116     synfig::String font;
    00117     synfig::String family;
    00118     synfig::String text;
    00119     synfig::Vector size;
    00120     synfig::Vector orient;
    00121     synfig::Color color;
    00122     synfig::Point origin;
    00123     synfig::Real compress;
    00124     synfig::Real vcompress;
    00125
    00126     int style;
    00127     int weight;
    00128     bool use_kerning;
    00129     bool grid_fit;
    00130     bool invert;
    00131
    00132     bool old_version;
    00133     bool needs_sync_;
    00134
    00135     void sync();
    00136
    00137     synfig::Color color_func(const synfig::Point &x, int quality=10, float supersample=0)const;
    00138
    00139     mutable synfig::Mutex mutex;
    00140
    00141 public:
    00142     Layer_Freetype();
    00143     virtual ~Layer_Freetype();
    00144
    00145     virtual bool set_param(const String & param, const synfig::ValueBase &value);
    00146     virtual ValueBase get_param(const String & param)const;
    00147     virtual Color get_color(Context context, const synfig::Point &pos)const;
    00148     virtual bool accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const;
    00149
    00150     virtual Vocab get_param_vocab()const;
    00151
    00152     virtual bool set_version(const String &ver){if(ver=="0.1")old_version=true;return true;}
    00153     virtual void reset_version(){old_version=false;}
    00154
    00155     virtual synfig::Rect get_bounding_rect()const;
    00156
    00157 private:
    00158     void new_font(const synfig::String &family, int style=0, int weight=400);
    00159     bool new_font_(const synfig::String &family, int style=0, int weight=400);
    00160     bool new_face(const synfig::String &newfont);
    00161 };
    00162
    00163 extern FT_Library ft_library;
    00164
    00165 /* === E N D =============================================================== */
    00166
    00167 #endif