mirror of
https://github.com/tiennm99/godot.git
synced 2026-08-06 22:22:22 +00:00
[Complex Text Layouts] Provide access to glyph contour points.
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user