From f851c4aa330e1064a66db50be62db2466f4fb768 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Tue, 5 Apr 2022 13:40:26 +0300 Subject: Fix some issues found by cppcheck. --- modules/text_server_adv/script_iterator.cpp | 4 +-- modules/text_server_adv/text_server_adv.cpp | 48 +++++++++++++---------------- 2 files changed, 24 insertions(+), 28 deletions(-) (limited to 'modules/text_server_adv') diff --git a/modules/text_server_adv/script_iterator.cpp b/modules/text_server_adv/script_iterator.cpp index 06e934c67d..3331254b20 100644 --- a/modules/text_server_adv/script_iterator.cpp +++ b/modules/text_server_adv/script_iterator.cpp @@ -51,7 +51,7 @@ ScriptIterator::ScriptIterator(const String &p_string, int p_start, int p_length } int paren_size = PAREN_STACK_DEPTH; - ParenStackEntry *paren_stack = (ParenStackEntry *)memalloc(paren_size * sizeof(ParenStackEntry)); + ParenStackEntry *paren_stack = static_cast(memalloc(paren_size * sizeof(ParenStackEntry))); int script_start; int script_end = p_start; @@ -77,7 +77,7 @@ ScriptIterator::ScriptIterator(const String &p_string, int p_start, int p_length if (unlikely(paren_sp >= paren_size)) { // If the stack is full, allocate more space to handle deeply nested parentheses. This is unlikely to happen with any real text. paren_size += PAREN_STACK_DEPTH; - paren_stack = (ParenStackEntry *)memrealloc(paren_stack, paren_size * sizeof(ParenStackEntry)); + paren_stack = static_cast(memrealloc(paren_stack, paren_size * sizeof(ParenStackEntry))); } paren_stack[paren_sp].pair_index = ch; paren_stack[paren_sp].script_code = script_code; diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp index ae662a0a9b..0fce54a18a 100644 --- a/modules/text_server_adv/text_server_adv.cpp +++ b/modules/text_server_adv/text_server_adv.cpp @@ -89,12 +89,12 @@ TextServerAdvanced::bmp_font_t *TextServerAdvanced::_bmp_font_create(TextServerA } void TextServerAdvanced::_bmp_font_destroy(void *p_data) { - bmp_font_t *bm_font = reinterpret_cast(p_data); + bmp_font_t *bm_font = static_cast(p_data); memdelete(bm_font); } hb_bool_t TextServerAdvanced::_bmp_get_nominal_glyph(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_unicode, hb_codepoint_t *r_glyph, void *p_user_data) { - const bmp_font_t *bm_font = reinterpret_cast(p_font_data); + const bmp_font_t *bm_font = static_cast(p_font_data); if (!bm_font->face) { return false; @@ -114,7 +114,7 @@ hb_bool_t TextServerAdvanced::_bmp_get_nominal_glyph(hb_font_t *p_font, void *p_ } hb_position_t TextServerAdvanced::_bmp_get_glyph_h_advance(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_glyph, void *p_user_data) { - const bmp_font_t *bm_font = reinterpret_cast(p_font_data); + const bmp_font_t *bm_font = static_cast(p_font_data); if (!bm_font->face) { return 0; @@ -128,7 +128,7 @@ hb_position_t TextServerAdvanced::_bmp_get_glyph_h_advance(hb_font_t *p_font, vo } hb_position_t TextServerAdvanced::_bmp_get_glyph_v_advance(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_glyph, void *p_user_data) { - const bmp_font_t *bm_font = reinterpret_cast(p_font_data); + const bmp_font_t *bm_font = static_cast(p_font_data); if (!bm_font->face) { return 0; @@ -142,7 +142,7 @@ hb_position_t TextServerAdvanced::_bmp_get_glyph_v_advance(hb_font_t *p_font, vo } hb_position_t TextServerAdvanced::_bmp_get_glyph_h_kerning(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_left_glyph, hb_codepoint_t p_right_glyph, void *p_user_data) { - const bmp_font_t *bm_font = reinterpret_cast(p_font_data); + const bmp_font_t *bm_font = static_cast(p_font_data); if (!bm_font->face) { return 0; @@ -156,7 +156,7 @@ hb_position_t TextServerAdvanced::_bmp_get_glyph_h_kerning(hb_font_t *p_font, vo } hb_bool_t TextServerAdvanced::_bmp_get_glyph_v_origin(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_glyph, hb_position_t *r_x, hb_position_t *r_y, void *p_user_data) { - const bmp_font_t *bm_font = reinterpret_cast(p_font_data); + const bmp_font_t *bm_font = static_cast(p_font_data); if (!bm_font->face) { return false; @@ -173,7 +173,7 @@ hb_bool_t TextServerAdvanced::_bmp_get_glyph_v_origin(hb_font_t *p_font, void *p } hb_bool_t TextServerAdvanced::_bmp_get_glyph_extents(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_glyph, hb_glyph_extents_t *r_extents, void *p_user_data) { - const bmp_font_t *bm_font = reinterpret_cast(p_font_data); + const bmp_font_t *bm_font = static_cast(p_font_data); if (!bm_font->face) { return false; @@ -192,7 +192,7 @@ hb_bool_t TextServerAdvanced::_bmp_get_glyph_extents(hb_font_t *p_font, void *p_ } hb_bool_t TextServerAdvanced::_bmp_get_font_h_extents(hb_font_t *p_font, void *p_font_data, hb_font_extents_t *r_metrics, void *p_user_data) { - const bmp_font_t *bm_font = reinterpret_cast(p_font_data); + const bmp_font_t *bm_font = static_cast(p_font_data); if (!bm_font->face) { return false; @@ -910,7 +910,7 @@ static msdfgen::Point2 ft_point2(const FT_Vector &vector) { } static int ft_move_to(const FT_Vector *to, void *user) { - MSContext *context = reinterpret_cast(user); + MSContext *context = static_cast(user); if (!(context->contour && context->contour->edges.empty())) { context->contour = &context->shape->addContour(); } @@ -919,7 +919,7 @@ static int ft_move_to(const FT_Vector *to, void *user) { } static int ft_line_to(const FT_Vector *to, void *user) { - MSContext *context = reinterpret_cast(user); + MSContext *context = static_cast(user); msdfgen::Point2 endpoint = ft_point2(*to); if (endpoint != context->position) { context->contour->addEdge(new msdfgen::LinearSegment(context->position, endpoint)); @@ -929,21 +929,21 @@ static int ft_line_to(const FT_Vector *to, void *user) { } static int ft_conic_to(const FT_Vector *control, const FT_Vector *to, void *user) { - MSContext *context = reinterpret_cast(user); + MSContext *context = static_cast(user); context->contour->addEdge(new msdfgen::QuadraticSegment(context->position, ft_point2(*control), ft_point2(*to))); context->position = ft_point2(*to); return 0; } static int ft_cubic_to(const FT_Vector *control1, const FT_Vector *control2, const FT_Vector *to, void *user) { - MSContext *context = reinterpret_cast(user); + MSContext *context = static_cast(user); context->contour->addEdge(new msdfgen::CubicSegment(context->position, ft_point2(*control1), ft_point2(*control2), ft_point2(*to))); context->position = ft_point2(*to); return 0; } void TextServerAdvanced::_generateMTSDF_threaded(uint32_t y, void *p_td) const { - MSDFThreadData *td = (MSDFThreadData *)p_td; + MSDFThreadData *td = static_cast(p_td); msdfgen::ShapeDistanceFinder> distanceFinder(*td->shape); int row = td->shape->inverseYAxis ? td->output->height() - y - 1 : y; @@ -1860,9 +1860,7 @@ void TextServerAdvanced::font_set_fixed_size(const RID &p_font_rid, int64_t p_fi ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); - if (fd->fixed_size != p_fixed_size) { - fd->fixed_size = p_fixed_size; - } + fd->fixed_size = p_fixed_size; } int64_t TextServerAdvanced::font_get_fixed_size(const RID &p_font_rid) const { @@ -1916,9 +1914,7 @@ void TextServerAdvanced::font_set_subpixel_positioning(const RID &p_font_rid, Te ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); - if (fd->subpixel_positioning != p_subpixel) { - fd->subpixel_positioning = p_subpixel; - } + fd->subpixel_positioning = p_subpixel; } TextServer::SubpixelPositioning TextServerAdvanced::font_get_subpixel_positioning(const RID &p_font_rid) const { @@ -2574,10 +2570,10 @@ Dictionary TextServerAdvanced::font_get_glyph_contours(const RID &p_font_rid, in ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Dictionary()); +#ifdef MODULE_FREETYPE_ENABLED PackedVector3Array points; PackedInt32Array contours; - bool orientation; -#ifdef MODULE_FREETYPE_ENABLED + int32_t index = p_index & 0xffffff; // Remove subpixel shifts. int error = FT_Load_Glyph(fd->cache[size]->face, index, FT_LOAD_NO_BITMAP | (fd->force_autohinter ? FT_LOAD_FORCE_AUTOHINT : 0)); @@ -2594,16 +2590,16 @@ Dictionary TextServerAdvanced::font_get_glyph_contours(const RID &p_font_rid, in for (short i = 0; i < fd->cache[size]->face->glyph->outline.n_contours; i++) { contours.push_back(fd->cache[size]->face->glyph->outline.contours[i]); } - orientation = (FT_Outline_Get_Orientation(&fd->cache[size]->face->glyph->outline) == FT_ORIENTATION_FILL_RIGHT); -#else - return Dictionary(); -#endif + bool orientation = (FT_Outline_Get_Orientation(&fd->cache[size]->face->glyph->outline) == FT_ORIENTATION_FILL_RIGHT); Dictionary out; out["points"] = points; out["contours"] = contours; out["orientation"] = orientation; return out; +#else + return Dictionary(); +#endif } Array TextServerAdvanced::font_get_kerning_list(const RID &p_font_rid, int64_t p_size) const { @@ -3878,9 +3874,9 @@ double TextServerAdvanced::shaped_text_fit_to_width(const RID &p_shaped, double } } } - double adv_remain = 0; if ((space_count > 0) && ((p_jst_flags & JUSTIFICATION_WORD_BOUND) == JUSTIFICATION_WORD_BOUND)) { double delta_width_per_space = (p_width - justification_width) / space_count; + double adv_remain = 0; for (int i = start_pos; i <= end_pos; i++) { Glyph &gl = sd->glyphs.write[i]; if (gl.count > 0) { -- cgit v1.2.3