|
Carlos Lopez |
a09598 |
/* === S Y N F I G ========================================================= */
|
|
Carlos Lopez |
a09598 |
/*! \file lyr_freetype.h
|
|
Carlos Lopez |
a09598 |
** \brief Header file for implementation of the "Text" layer
|
|
Carlos Lopez |
a09598 |
**
|
|
Carlos Lopez |
a09598 |
** $Id$
|
|
Carlos Lopez |
a09598 |
**
|
|
Carlos Lopez |
a09598 |
** \legal
|
|
Carlos Lopez |
a09598 |
** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
|
|
Carlos Lopez |
a09598 |
** Copyright (c) 2007, 2008 Chris Moore
|
|
Carlos Lopez |
e83454 |
** Copyright (c) 2012-2013 Carlos Lรณpez
|
|
Carlos Lopez |
a09598 |
**
|
|
Carlos Lopez |
a09598 |
** This package is free software; you can redistribute it and/or
|
|
Carlos Lopez |
a09598 |
** modify it under the terms of the GNU General Public License as
|
|
Carlos Lopez |
a09598 |
** published by the Free Software Foundation; either version 2 of
|
|
Carlos Lopez |
a09598 |
** the License, or (at your option) any later version.
|
|
Carlos Lopez |
a09598 |
**
|
|
Carlos Lopez |
a09598 |
** This package is distributed in the hope that it will be useful,
|
|
Carlos Lopez |
a09598 |
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Carlos Lopez |
a09598 |
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Carlos Lopez |
a09598 |
** General Public License for more details.
|
|
Carlos Lopez |
a09598 |
** \endlegal
|
|
Carlos Lopez |
a09598 |
**
|
|
Carlos Lopez |
a09598 |
** === N O T E S ===========================================================
|
|
Carlos Lopez |
a09598 |
**
|
|
Carlos Lopez |
a09598 |
** ========================================================================= */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* === S T A R T =========================================================== */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
#ifndef __SYNFIG_LYR_FREETYPE_H
|
|
Carlos Lopez |
a09598 |
#define __SYNFIG_LYR_FREETYPE_H
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* === H E A D E R S ======================================================= */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
//#ifdef __APPLE__
|
|
Carlos Lopez |
a09598 |
//#define USE_MAC_FT_FUNCS (1)
|
|
Carlos Lopez |
a09598 |
//#endif
|
|
Carlos Lopez |
a09598 |
|
|
Diego Barrios Romero |
dcc14d |
#include <synfig layer_composite.h="" layers=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig vector.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig color.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig string.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
#include <ft2build.h></ft2build.h>
|
|
Carlos Lopez |
a09598 |
#include FT_FREETYPE_H
|
|
Carlos Lopez |
a09598 |
#include FT_GLYPH_H
|
|
Carlos Lopez |
a09598 |
#include <vector></vector>
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
#include <synfig string.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig time.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig context.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig paramdesc.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig renddesc.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig surface.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig value.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig valuenode.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
#include <synfig canvas.h=""></synfig>
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
#include <etl misc=""></etl>
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
#ifdef USE_MAC_FT_FUNCS
|
|
Carlos Lopez |
a09598 |
#include <coreservices coreservices.h=""></coreservices>
|
|
Carlos Lopez |
a09598 |
#include FT_MAC_H
|
|
Carlos Lopez |
a09598 |
#endif
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* === M A C R O S ========================================================= */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* === T Y P E D E F S ===================================================== */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* === C L A S S E S & S T R U C T S ======================================= */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
using namespace synfig;
|
|
Carlos Lopez |
a09598 |
using namespace std;
|
|
Carlos Lopez |
a09598 |
using namespace etl;
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
struct Glyph
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
a09598 |
FT_Glyph glyph;
|
|
Carlos Lopez |
a09598 |
FT_Vector pos;
|
|
Carlos Lopez |
a09598 |
//int width;
|
|
Carlos Lopez |
a09598 |
};
|
|
Carlos Lopez |
a09598 |
struct TextLine
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
a09598 |
int width;
|
|
Carlos Lopez |
a09598 |
std::vector<glyph> glyph_table;</glyph>
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
TextLine():width(0) { }
|
|
Carlos Lopez |
a09598 |
void clear_and_free();
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
int actual_height()const
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
a09598 |
int height(0);
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
std::vector<glyph>::const_iterator iter;</glyph>
|
|
Carlos Lopez |
a09598 |
for(iter=glyph_table.begin();iter!=glyph_table.end();++iter)
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
a09598 |
FT_BBox glyph_bbox;
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
//FT_Glyph_Get_CBox( glyphs[n], ft_glyph_bbox_pixels, &glyph_bbox );
|
|
Carlos Lopez |
a09598 |
FT_Glyph_Get_CBox( iter->glyph, ft_glyph_bbox_subpixels, &glyph_bbox );
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
if(glyph_bbox.yMax>height)
|
|
Carlos Lopez |
a09598 |
height=glyph_bbox.yMax;
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
return height;
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
};
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
class Layer_Freetype : public synfig::Layer_Composite, public synfig::Layer_NoDeform
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
a09598 |
SYNFIG_LAYER_MODULE_EXT
|
|
Carlos Lopez |
a09598 |
private:
|
|
Carlos Lopez |
1d3c5c |
//!Parameter: (synfig::String) text of the layer;
|
|
Carlos Lopez |
1d3c5c |
ValueBase param_text;
|
|
Carlos Lopez |
1d3c5c |
//!Parameter: (synfig::Color) color of the text;
|
|
Carlos Lopez |
1d3c5c |
ValueBase param_color;
|
|
Carlos Lopez |
1d3c5c |
//!Parameter: (synfig::String) font family used in the text
|
|
Carlos Lopez |
1d3c5c |
ValueBase param_family;
|
|
Carlos Lopez |
1d3c5c |
//!Parameter: (int) style used in the font
|
|
Carlos Lopez |
1d3c5c |
ValueBase param_style;
|
|
Carlos Lopez |
1d3c5c |
//!Parameter: (int) weight used in the font
|
|
Carlos Lopez |
1d3c5c |
ValueBase param_weight;
|
|
Carlos Lopez |
1d3c5c |
//!Parameter: (synfig::Real) horizontal spacing
|
|
Carlos Lopez |
1d3c5c |
ValueBase param_compress;
|
|
Carlos Lopez |
1d3c5c |
//!Parameter: (synfig::Real) vertical spacing
|
|
Carlos Lopez |
1d3c5c |
ValueBase param_vcompress;
|
|
Carlos Lopez |
1d3c5c |
//!Parameter: (synfig::Vector) size of the text
|
|
Carlos Lopez |
1d3c5c |
ValueBase param_size;
|
|
Carlos Lopez |
1d3c5c |
//!Parameter: (synfig::Vector) text orientation
|
|
Carlos Lopez |
1d3c5c |
ValueBase param_orient;
|
|
Carlos Lopez |
1d3c5c |
//!Parameter: (synfig::Point) text position
|
|
Carlos Lopez |
1d3c5c |
ValueBase param_origin;
|
|
Carlos Lopez |
1d3c5c |
//!Parameter: (synfig::String) font used in the text
|
|
Carlos Lopez |
1d3c5c |
ValueBase param_font;
|
|
Carlos Lopez |
1d3c5c |
//!Parameter: (bool)
|
|
Carlos Lopez |
1d3c5c |
ValueBase param_use_kerning;
|
|
Carlos Lopez |
1d3c5c |
//!Parameter: (bool)
|
|
Carlos Lopez |
1d3c5c |
ValueBase param_grid_fit;
|
|
Carlos Lopez |
1d3c5c |
//!Parameter: (bool) inverts the rendered text
|
|
Carlos Lopez |
1d3c5c |
ValueBase param_invert;
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
FT_Face face;
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
bool old_version;
|
|
Carlos Lopez |
a09598 |
bool needs_sync_;
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
void sync();
|
|
Carlos Lopez |
a09598 |
|
|
|
82b51f |
synfig::Color color_func(const synfig::Point &x, int quality=10, synfig::ColorReal supersample=0)const;
|
|
Carlos Lopez |
a09598 |
|
|
Rodolfo Ribeiro Gomes |
d18249 |
mutable std::mutex mutex_;
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
public:
|
|
Carlos Lopez |
a09598 |
Layer_Freetype();
|
|
Carlos Lopez |
a09598 |
virtual ~Layer_Freetype();
|
|
Carlos Lopez |
a09598 |
|
|
|
503453 |
virtual void on_canvas_set();
|
|
Carlos Lopez |
a09598 |
virtual bool set_param(const String & param, const synfig::ValueBase &value);
|
|
Carlos Lopez |
a09598 |
virtual ValueBase get_param(const String & param)const;
|
|
Carlos Lopez |
a09598 |
virtual Color get_color(Context context, const synfig::Point &pos)const;
|
|
Carlos Lopez |
a09598 |
virtual bool accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const;
|
|
Carlos Lopez |
43ce6f |
virtual bool accelerated_cairorender(Context context,cairo_t *cr, int quality, const RendDesc &renddesc, ProgressCallback *cb)const;
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
virtual Vocab get_param_vocab()const;
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
virtual bool set_version(const String &ver){if(ver=="0.1")old_version=true;return true;}
|
|
Carlos Lopez |
a09598 |
virtual void reset_version(){old_version=false;}
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
virtual synfig::Rect get_bounding_rect()const;
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
private:
|
|
Carlos Lopez |
a09598 |
void new_font(const synfig::String &family, int style=0, int weight=400);
|
|
Carlos Lopez |
a09598 |
bool new_font_(const synfig::String &family, int style=0, int weight=400);
|
|
Carlos Lopez |
a09598 |
bool new_face(const synfig::String &newfont);
|
|
Carlos Lopez |
a09598 |
};
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
extern FT_Library ft_library;
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* === E N D =============================================================== */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
#endif
|