From c56f302e515dd77da91511ad3eb16d3f8cfd2f7d Mon Sep 17 00:00:00 2001 From: Hoe Hao Cheng Date: Sun, 30 Jul 2023 16:25:36 +0800 Subject: [PATCH] SDL: address comments on #17780 --- Common/Render/Text/draw_text_sdl.cpp | 14 ++++---------- Common/Render/Text/draw_text_sdl.h | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/Common/Render/Text/draw_text_sdl.cpp b/Common/Render/Text/draw_text_sdl.cpp index 0de2b74397a8..701ecc64c8ce 100644 --- a/Common/Render/Text/draw_text_sdl.cpp +++ b/Common/Render/Text/draw_text_sdl.cpp @@ -58,7 +58,7 @@ void TextDrawerSDL::PrepareFallbackFonts() { }; for (int i = 0; i < ARRAY_SIZE(names); i++) { - FcFontSet *foundFonts = FcFontList(config, names[i], os); + FcFontSet *foundFonts = FcFontList(config, names[i], os); for (int j = 0; foundFonts && j < foundFonts->nfont; ++j) { FcPattern* font = foundFonts->fonts[j]; @@ -133,7 +133,7 @@ void TextDrawerSDL::PrepareFallbackFonts() { #endif } -uint32_t TextDrawerSDL::CheckMissingGlyph(std::string& text) { +uint32_t TextDrawerSDL::CheckMissingGlyph(const std::string& text) { TTF_Font *font = fontMap_.find(fontHash_)->second; UTF8 utf8Decoded(text.c_str()); @@ -293,7 +293,7 @@ void TextDrawerSDL::MeasureStringRect(const char *str, size_t len, const Bounds if (total_w < entry->width) { total_w = entry->width; } - total_h += entry->height; + total_h += TTF_FontLineSkip(font); } *w = total_w * fontScaleX_ * dpiScale_; @@ -359,13 +359,7 @@ void TextDrawerSDL::DrawStringBitmap(std::vector &bitmapData, TextStrin // If a string includes only newlines, SDL2_ttf will refuse to render it // thinking it is empty. Add a space to avoid that. - bool isAllNewline = true; - for (int i = 0; i < processedStr.size(); i++) { - if (processedStr[i] != '\n') { - isAllNewline = false; - break; - } - } + bool isAllNewline = processedStr.find_first_not_of('\n') == std::string::npos; if (isAllNewline) { processedStr.push_back(' '); diff --git a/Common/Render/Text/draw_text_sdl.h b/Common/Render/Text/draw_text_sdl.h index 7c047ee48c41..87c543a66086 100644 --- a/Common/Render/Text/draw_text_sdl.h +++ b/Common/Render/Text/draw_text_sdl.h @@ -29,7 +29,7 @@ class TextDrawerSDL : public TextDrawer { protected: void ClearCache() override; void PrepareFallbackFonts(); - uint32_t CheckMissingGlyph(std::string& text); + uint32_t CheckMissingGlyph(const std::string& text); bool FindFallbackFonts(uint32_t missingGlyph, int ptSize); uint32_t fontHash_;