Skip to content

Commit

Permalink
SDL: address comments on #17780
Browse files Browse the repository at this point in the history
  • Loading branch information
hch12907 committed Jul 30, 2023
1 parent aaa7e90 commit c56f302
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
14 changes: 4 additions & 10 deletions Common/Render/Text/draw_text_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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_;
Expand Down Expand Up @@ -359,13 +359,7 @@ void TextDrawerSDL::DrawStringBitmap(std::vector<uint8_t> &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(' ');
Expand Down
2 changes: 1 addition & 1 deletion Common/Render/Text/draw_text_sdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down

0 comments on commit c56f302

Please sign in to comment.