forked from synfig/synfig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lyr_freetype.h
166 lines (131 loc) · 5.33 KB
/
lyr_freetype.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/* === S Y N F I G ========================================================= */
/*! \file lyr_freetype.h
** \brief Header file for implementation of the "Text" layer
**
** \legal
** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
** Copyright (c) 2007, 2008 Chris Moore
** Copyright (c) 2012-2013 Carlos López
**
** This file is part of Synfig.
**
** Synfig is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 2 of the License, or
** (at your option) any later version.
**
** Synfig is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Synfig. If not, see <https://www.gnu.org/licenses/>.
** \endlegal
**
** ========================================================================= */
/* === S T A R T =========================================================== */
#ifndef __SYNFIG_LYR_FREETYPE_H
#define __SYNFIG_LYR_FREETYPE_H
/* === H E A D E R S ======================================================= */
#include <synfig/layers/layer_shape.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_GLYPH_H
#if HAVE_HARFBUZZ
#include <hb.h>
#endif
/* === M A C R O S ========================================================= */
/* === T Y P E D E F S ===================================================== */
/* === C L A S S E S & S T R U C T S ======================================= */
class Layer_Freetype : public synfig::Layer_Shape
{
SYNFIG_LAYER_MODULE_EXT
private:
//!Parameter: (synfig::String) text of the layer;
synfig::ValueBase param_text;
//!Parameter: (synfig::String) font family used in the text
synfig::ValueBase param_family;
//!Parameter: (int) style used in the font
synfig::ValueBase param_style;
//!Parameter: (int) weight used in the font
synfig::ValueBase param_weight;
//!Parameter: (int) diretion of the text
synfig::ValueBase param_direction;
//!Parameter: (synfig::Real) horizontal spacing
synfig::ValueBase param_compress;
//!Parameter: (synfig::Real) vertical spacing
synfig::ValueBase param_vcompress;
//!Parameter: (synfig::Vector) size of the text
synfig::ValueBase param_size;
//!Parameter: (synfig::Vector) text orientation
synfig::ValueBase param_orient;
//!Parameter: (synfig::String) font used in the text
synfig::ValueBase param_font;
//!Parameter: (bool)
synfig::ValueBase param_use_kerning;
//!Parameter: (bool)
synfig::ValueBase param_grid_fit;
FT_Face face;
#if HAVE_HARFBUZZ
hb_font_t *font;
#endif
struct TextSpan
{
std::vector<uint32_t> codepoints;
#if HAVE_HARFBUZZ
hb_script_t script;
#endif
};
typedef std::vector<TextSpan> TextLine;
std::vector<TextLine> lines;
bool font_path_from_canvas;
bool old_version;
void sync_vfunc() override;
synfig::Color color_func(const synfig::Point &x, int quality=10, synfig::ColorReal supersample=0)const;
mutable std::mutex mutex;
mutable std::mutex sync_mtx;
public:
Layer_Freetype();
~Layer_Freetype() override = default;
void on_canvas_set() override;
bool set_simple_shape_param(const synfig::String & param, const synfig::ValueBase &value);
bool set_shape_param(const synfig::String & param, const synfig::ValueBase &value) override;
bool set_param(const synfig::String & param, const synfig::ValueBase &value) override;
synfig::ValueBase get_param(const synfig::String & param) const override;
synfig::Color get_color(synfig::Context context, const synfig::Point &pos) const override;
synfig::Layer::Handle hit_check(synfig::Context context, const synfig::Point &point) const override;
synfig::Rect get_bounding_rect() const override;
Vocab get_param_vocab() const override;
bool set_version(const synfig::String &ver) override { if (ver=="0.1") old_version=true; return true; }
void reset_version() override {old_version=false;}
protected:
synfig::rendering::Task::Handle build_composite_task_vfunc(synfig::ContextParams) const override;
private:
/*! The new_font() function try to load a font file
** until it works by simplyfing font style and weight.
** As last resource, it loads "sans serif" with Normal font style and weight.
*/
void new_font(const synfig::String &family, int style=0, int weight=400);
bool new_font_(const synfig::String &family, int style=0, int weight=400);
bool new_face(const synfig::String &newfont);
static std::vector<std::string> get_possible_font_directories(const std::string& canvas_path);
void on_param_text_changed();
static std::vector<TextLine> fetch_text_lines(const std::string& text, int direction);
static void convert_outline_to_contours(const FT_OutlineGlyphRec* glyph, synfig::rendering::Contour::ChunkList& chunks);
static void shift_contour_chunks(synfig::rendering::Contour::ChunkList &chunks, const synfig::Vector &offset);
synfig::Point world_to_contour(const synfig::Point& p) const;
synfig::Point contour_to_world(const synfig::Point& p) const;
enum SyncFlags {
SYNC_FONT,
SYNC_TEXT,
SYNC_DIRECTION,
SYNC_COMPRESS,
SYNC_ORIENTATION,
SYNC_KERNING,
SYNC_GRID_FIT
};
std::atomic<int> need_sync;
};
/* === E N D =============================================================== */
#endif