14 #include FT_FREETYPE_H
43 const float scale = vfd->
scale;
44 const float eps = 0.0001f;
45 const float eps_sq =
eps *
eps;
56 int j, k,
l, l_first = 0;
62 glyph_index = FT_Get_Char_Index(face, charcode);
63 err = FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP);
76 ftoutline =
glyph->outline;
79 che->
index = charcode;
85 onpoints = (
int *)
MEM_callocN((ftoutline.n_contours) *
sizeof(int),
"onpoints");
88 for (j = 0, contour_prev = -1; j < ftoutline.n_contours; j++) {
89 const int n = ftoutline.contours[j] - contour_prev;
90 contour_prev = ftoutline.contours[j];
92 for (k = 0; k < n; k++) {
93 l = (j > 0) ? (k + ftoutline.contours[j - 1] + 1) : k;
98 if (ftoutline.tags[
l] == FT_Curve_Tag_On) {
103 const int l_next = (k < n - 1) ? (
l + 1) : l_first;
104 if (ftoutline.tags[
l] == FT_Curve_Tag_Conic &&
105 ftoutline.tags[l_next] == FT_Curve_Tag_Conic) {
113 for (j = 0, contour_prev = -1; j < ftoutline.n_contours; j++) {
114 const int n = ftoutline.contours[j] - contour_prev;
115 contour_prev = ftoutline.contours[j];
123 nu->
pntsu = onpoints[j];
129 for (k = 0; k < n; k++) {
130 l = (j > 0) ? (k + ftoutline.contours[j - 1] + 1) : k;
137 const int l_next = (k < n - 1) ? (
l + 1) : l_first;
138 if (ftoutline.tags[
l] == FT_Curve_Tag_Conic &&
139 ftoutline.tags[l_next] == FT_Curve_Tag_Conic) {
140 dx = (ftoutline.points[
l].x + ftoutline.points[l_next].x) * scale / 2.0f;
141 dy = (ftoutline.points[
l].y + ftoutline.points[l_next].y) * scale / 2.0f;
144 bezt->
vec[0][0] = (dx + (2 * ftoutline.points[
l].x) * scale) / 3.0f;
145 bezt->
vec[0][1] = (dy + (2 * ftoutline.points[
l].y) * scale) / 3.0f;
148 bezt->
vec[1][0] = dx;
149 bezt->
vec[1][1] = dy;
152 bezt->
vec[2][0] = (dx + (2 * ftoutline.points[l_next].x) * scale) / 3.0f;
153 bezt->
vec[2][1] = (dy + (2 * ftoutline.points[l_next].y) * scale) / 3.0f;
162 if (ftoutline.tags[
l] == FT_Curve_Tag_On) {
163 const int l_prev = (k > 0) ? (
l - 1) : ftoutline.contours[j];
164 const int l_next = (k < n - 1) ? (
l + 1) : l_first;
167 if (ftoutline.tags[l_prev] == FT_Curve_Tag_Cubic) {
168 bezt->
vec[0][0] = ftoutline.points[l_prev].x * scale;
169 bezt->
vec[0][1] = ftoutline.points[l_prev].y * scale;
172 else if (ftoutline.tags[l_prev] == FT_Curve_Tag_Conic) {
173 bezt->
vec[0][0] = (ftoutline.points[
l].x + (2 * ftoutline.points[l_prev].x)) * scale /
175 bezt->
vec[0][1] = (ftoutline.points[
l].y + (2 * ftoutline.points[l_prev].y)) * scale /
180 bezt->
vec[0][0] = ftoutline.points[
l].x * scale -
181 (ftoutline.points[
l].x - ftoutline.points[l_prev].x) * scale / 3.0f;
182 bezt->
vec[0][1] = ftoutline.points[
l].y * scale -
183 (ftoutline.points[
l].y - ftoutline.points[l_prev].y) * scale / 3.0f;
188 bezt->
vec[1][0] = ftoutline.points[
l].x * scale;
189 bezt->
vec[1][1] = ftoutline.points[
l].y * scale;
192 if (ftoutline.tags[l_next] == FT_Curve_Tag_Cubic) {
193 bezt->
vec[2][0] = ftoutline.points[l_next].x * scale;
194 bezt->
vec[2][1] = ftoutline.points[l_next].y * scale;
197 else if (ftoutline.tags[l_next] == FT_Curve_Tag_Conic) {
198 bezt->
vec[2][0] = (ftoutline.points[
l].x + (2 * ftoutline.points[l_next].x)) * scale /
200 bezt->
vec[2][1] = (ftoutline.points[
l].y + (2 * ftoutline.points[l_next].y)) * scale /
205 bezt->
vec[2][0] = ftoutline.points[
l].x * scale -
206 (ftoutline.points[
l].x - ftoutline.points[l_next].x) * scale / 3.0f;
207 bezt->
vec[2][1] = ftoutline.points[
l].y * scale -
208 (ftoutline.points[
l].y - ftoutline.points[l_next].y) * scale / 3.0f;
220 (0.001f * 0.001f)) &&
273 const FT_ULong charcode_reserve = 256;
274 FT_ULong charcode = 0, lcode;
289 if (face->family_name) {
295 err = FT_Select_Charmap(face, FT_ENCODING_UNICODE);
297 err = FT_Select_Charmap(face, FT_ENCODING_APPLE_ROMAN);
299 if (
err && face->num_charmaps > 0) {
300 err = FT_Select_Charmap(face, face->charmaps[0]->encoding);
309 lcode = charcode = FT_Get_First_Char(face, &glyph_index);
312 const bool complete_font = (face->ascender != 0) && (face->descender != 0) &&
313 (face->ascender != face->descender);
318 vfd->
ascender = (
float)face->ascender / (face->ascender - face->descender);
326 if (face->bbox.yMax != face->bbox.yMin) {
327 vfd->
scale = (
float)(1.0 / (
double)(face->bbox.yMax - face->bbox.yMin));
331 (face->bbox.yMax - face->bbox.yMin);
335 vfd->
scale = 1.0f / 1000.0f;
341 while (charcode < charcode_reserve) {
346 charcode = FT_Get_Next_Char(face, charcode, &glyph_index);
349 if (charcode <= lcode) {
361 FT_UInt glyph_index = 0;
362 bool success =
false;
370 FT_Get_First_Char(face, &glyph_index);
372 err = FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP);
374 success = (face->glyph->format == ft_glyph_format_outline);
typedef float(TangentPoint)[2]
void BKE_nurbList_duplicate(struct ListBase *lb1, const struct ListBase *lb2)
A structure to represent vector fonts, and to load them from PostScript fonts.
GHash * BLI_ghash_int_new_ex(const char *info, unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
GHash * BLI_ghash_copy(const GHash *gh, GHashKeyCopyFP keycopyfp, GHashValCopyFP valcopyfp) 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
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
int BLI_str_utf8_invalid_strip(char *str, size_t length) ATTR_NONNULL(1)
#define POINTER_FROM_UINT(i)
struct BezTriple BezTriple
Read Guarded memory(de)allocation.
ATTR_WARN_UNUSED_RESULT const BMLoop * l
SyclQueue void void * src
#define pf(_x, _i)
Prefetch 64.
flat(Type::VEC4, "color_flat") .no_perspective(Type col offset fragColor glyph
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
static bool check_freetypefont(PackedFile *pf)
VFontData * BKE_vfontdata_from_freetypefont(PackedFile *pf)
static VChar * objchr_to_ftvfontdata(VFont *vfont, FT_ULong charcode)
VChar * BKE_vfontdata_char_copy(const VChar *vchar_src)
VFontData * BKE_vfontdata_copy(const VFontData *vfont_src, const int UNUSED(flag))
static void * vfontdata_copy_characters_value_cb(const void *src)
static FT_Library library
VChar * BKE_vfontdata_char_from_freetypefont(VFont *vfont, unsigned long character)
static VFontData * objfnt_to_ftvfontdata(PackedFile *pf)
static VChar * freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vfd)