30 #include FT_FREETYPE_H
56 const float scale = vfd->
scale;
57 const float eps = 0.0001f;
58 const float eps_sq =
eps *
eps;
69 int j, k,
l, l_first = 0;
75 glyph_index = FT_Get_Char_Index(face, charcode);
76 err = FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP);
89 ftoutline = glyph->outline;
92 che->
index = charcode;
93 che->
width = glyph->advance.x * scale;
98 onpoints = (
int *)
MEM_callocN((ftoutline.n_contours) *
sizeof(int),
"onpoints");
101 for (j = 0, contour_prev = -1; j < ftoutline.n_contours; j++) {
102 const int n = ftoutline.contours[j] - contour_prev;
103 contour_prev = ftoutline.contours[j];
105 for (k = 0; k < n; k++) {
106 l = (j > 0) ? (k + ftoutline.contours[j - 1] + 1) : k;
111 if (ftoutline.tags[
l] == FT_Curve_Tag_On) {
116 const int l_next = (k < n - 1) ? (
l + 1) : l_first;
117 if (ftoutline.tags[
l] == FT_Curve_Tag_Conic &&
118 ftoutline.tags[l_next] == FT_Curve_Tag_Conic) {
126 for (j = 0, contour_prev = -1; j < ftoutline.n_contours; j++) {
127 const int n = ftoutline.contours[j] - contour_prev;
128 contour_prev = ftoutline.contours[j];
136 nu->
pntsu = onpoints[j];
142 for (k = 0; k < n; k++) {
143 l = (j > 0) ? (k + ftoutline.contours[j - 1] + 1) : k;
150 const int l_next = (k < n - 1) ? (
l + 1) : l_first;
151 if (ftoutline.tags[
l] == FT_Curve_Tag_Conic &&
152 ftoutline.tags[l_next] == FT_Curve_Tag_Conic) {
153 dx = (ftoutline.points[
l].x + ftoutline.points[l_next].x) * scale / 2.0f;
154 dy = (ftoutline.points[
l].y + ftoutline.points[l_next].y) * scale / 2.0f;
157 bezt->
vec[0][0] = (dx + (2 * ftoutline.points[
l].x) * scale) / 3.0f;
158 bezt->
vec[0][1] = (dy + (2 * ftoutline.points[
l].y) * scale) / 3.0f;
161 bezt->
vec[1][0] = dx;
162 bezt->
vec[1][1] = dy;
165 bezt->
vec[2][0] = (dx + (2 * ftoutline.points[l_next].x) * scale) / 3.0f;
166 bezt->
vec[2][1] = (dy + (2 * ftoutline.points[l_next].y) * scale) / 3.0f;
175 if (ftoutline.tags[
l] == FT_Curve_Tag_On) {
176 const int l_prev = (k > 0) ? (
l - 1) : ftoutline.contours[j];
177 const int l_next = (k < n - 1) ? (
l + 1) : l_first;
180 if (ftoutline.tags[l_prev] == FT_Curve_Tag_Cubic) {
181 bezt->
vec[0][0] = ftoutline.points[l_prev].x * scale;
182 bezt->
vec[0][1] = ftoutline.points[l_prev].y * scale;
185 else if (ftoutline.tags[l_prev] == FT_Curve_Tag_Conic) {
186 bezt->
vec[0][0] = (ftoutline.points[
l].x + (2 * ftoutline.points[l_prev].x)) * scale /
188 bezt->
vec[0][1] = (ftoutline.points[
l].y + (2 * ftoutline.points[l_prev].y)) * scale /
193 bezt->
vec[0][0] = ftoutline.points[
l].x * scale -
194 (ftoutline.points[
l].x - ftoutline.points[l_prev].x) * scale / 3.0f;
195 bezt->
vec[0][1] = ftoutline.points[
l].y * scale -
196 (ftoutline.points[
l].y - ftoutline.points[l_prev].y) * scale / 3.0f;
201 bezt->
vec[1][0] = ftoutline.points[
l].x * scale;
202 bezt->
vec[1][1] = ftoutline.points[
l].y * scale;
205 if (ftoutline.tags[l_next] == FT_Curve_Tag_Cubic) {
206 bezt->
vec[2][0] = ftoutline.points[l_next].x * scale;
207 bezt->
vec[2][1] = ftoutline.points[l_next].y * scale;
210 else if (ftoutline.tags[l_next] == FT_Curve_Tag_Conic) {
211 bezt->
vec[2][0] = (ftoutline.points[
l].x + (2 * ftoutline.points[l_next].x)) * scale /
213 bezt->
vec[2][1] = (ftoutline.points[
l].y + (2 * ftoutline.points[l_next].y)) * scale /
218 bezt->
vec[2][0] = ftoutline.points[
l].x * scale -
219 (ftoutline.points[
l].x - ftoutline.points[l_next].x) * scale / 3.0f;
220 bezt->
vec[2][1] = ftoutline.points[
l].y * scale -
221 (ftoutline.points[
l].y - ftoutline.points[l_next].y) * scale / 3.0f;
233 (0.001f * 0.001f)) &&
286 const FT_ULong charcode_reserve = 256;
287 FT_ULong charcode = 0, lcode;
289 const char *fontname;
303 fontname = FT_Get_Postscript_Name(face);
307 lcode = charcode = FT_Get_First_Char(face, &glyph_index);
310 if (glyph_index == 0) {
311 FT_CharMap found =
NULL;
315 for (n = 0; n < face->num_charmaps; n++) {
316 charmap = face->charmaps[n];
317 if (charmap->encoding == FT_ENCODING_APPLE_ROMAN) {
323 err = FT_Set_Charmap(face, found);
329 lcode = charcode = FT_Get_First_Char(face, &glyph_index);
333 const bool complete_font = (face->ascender != 0) && (face->descender != 0) &&
334 (face->ascender != face->descender);
339 vfd->
ascender = (
float)face->ascender / (face->ascender - face->descender);
347 if (face->bbox.yMax != face->bbox.yMin) {
348 vfd->
scale = (
float)(1.0 / (
double)(face->bbox.yMax - face->bbox.yMin));
352 (face->bbox.yMax - face->bbox.yMin);
356 vfd->
scale = 1.0f / 1000.0f;
362 while (charcode < charcode_reserve) {
367 charcode = FT_Get_Next_Char(face, charcode, &glyph_index);
370 if (charcode <= lcode) {
392 glyph_index = FT_Get_Char_Index(face,
'A');
393 err = FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP);
399 if (glyph->format == ft_glyph_format_outline) {
488 #include "../../blenkernel/BKE_curve.h"
typedef float(TangentPoint)[2]
void BKE_nurbList_duplicate(struct ListBase *lb1, const struct ListBase *lb2)
GHash * BLI_ghash_copy(GHash *gh, GHashKeyCopyFP keycopyfp, GHashValCopyFP valcopyfp) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
GHash * BLI_ghash_int_new_ex(const char *info, const unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void BLI_ghash_insert(GHash *gh, void *key, void *val)
BLI_INLINE void BLI_listbase_clear(struct ListBase *lb)
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
MINLINE float max_ff(float a, float b)
float dist_squared_to_line_v2(const float p[2], const float l1[2], const float l2[2])
MINLINE float len_squared_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
#define POINTER_FROM_UINT(i)
A structure to represent vector fonts, and to load them from PostScript fonts.
struct BezTriple BezTriple
Read Guarded memory(de)allocation.
ATTR_WARN_UNUSED_RESULT const BMLoop * l
VChar * BLI_vfontchar_copy(const VChar *vchar_src, const int UNUSED(flag))
static int check_freetypefont(PackedFile *pf)
VChar * BLI_vfontchar_from_freetypefont(VFont *vfont, unsigned long character)
static VChar * objchr_to_ftvfontdata(VFont *vfont, FT_ULong charcode)
VFontData * BLI_vfontdata_from_freetypefont(PackedFile *pf)
static void * vfontdata_copy_characters_value_cb(const void *src)
static FT_Library library
VFontData * BLI_vfontdata_copy(const VFontData *vfont_src, const int UNUSED(flag))
static VFontData * objfnt_to_ftvfontdata(PackedFile *pf)
static VChar * freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vfd)
#define pf(_x, _i)
Prefetch 64.
void(* MEM_freeN)(void *vmemh)
void *(* MEM_dupallocN)(const void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
struct GHash * characters
struct PackedFile * temp_pf