[Complex Text Layouts] Provide access to glyph contour points.

This commit is contained in:
bruvzg
2021-03-31 09:32:14 +03:00
parent 2a66714bfb
commit 0d3fa2a125
16 changed files with 141 additions and 2 deletions
@@ -680,6 +680,29 @@ Vector2 DynamicFontDataFallback::draw_glyph_outline(RID p_canvas, int p_size, in
return advance;
}
bool DynamicFontDataFallback::get_glyph_contours(int p_size, uint32_t p_index, Vector<Vector3> &r_points, Vector<int32_t> &r_contours, bool &r_orientation) const {
_THREAD_SAFE_METHOD_
DataAtSize *fds = const_cast<DynamicFontDataFallback *>(this)->get_data_for_size(p_size);
ERR_FAIL_COND_V(fds == nullptr, false);
int error = FT_Load_Glyph(fds->face, p_index, FT_LOAD_NO_BITMAP | (force_autohinter ? FT_LOAD_FORCE_AUTOHINT : 0));
ERR_FAIL_COND_V(error, false);
r_points.clear();
r_contours.clear();
float h = fds->ascent;
float scale = (1.0 / 64.0) / oversampling * fds->scale_color_font;
for (short i = 0; i < fds->face->glyph->outline.n_points; i++) {
r_points.push_back(Vector3(fds->face->glyph->outline.points[i].x * scale, h - fds->face->glyph->outline.points[i].y * scale, FT_CURVE_TAG(fds->face->glyph->outline.tags[i])));
}
for (short i = 0; i < fds->face->glyph->outline.n_contours; i++) {
r_contours.push_back(fds->face->glyph->outline.contours[i]);
}
r_orientation = (FT_Outline_Get_Orientation(&fds->face->glyph->outline) == FT_ORIENTATION_FILL_RIGHT);
return true;
}
DynamicFontDataFallback::~DynamicFontDataFallback() {
clear_cache();
if (library != nullptr) {